dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.83k stars 1.67k forks source link

Improve font autoscaling flexibility #14438

Open Qythyx opened 1 year ago

Qythyx commented 1 year ago

Description

The current font autoscaling is nice in that it makes scaling to match the user's system setting a lot easier, but there are some key features missing.

  1. It would be useful to limit the maximum and minimum actual font size in some cases. Specifically, if the system scale makes the font quite large, that can break many UIs. I also can imagine some fonts could scale too small to be readable, so setting a minimum would be useful too.
  2. There are many cases where it would be useful to know the actual pixel size of a certain font size. In my specific case I would like to show an icon image and have it the same height as a label. Currently I need to do some complicated logic to get the height of the label after it is rendered. Even that is problematic, because maybe the label has margin or something and I really just want the height of the text in the label.
  3. It is not currently easy to detect if the systems font scale changes.

Public API Changes

I'm not sure of the best APIs for these two requests. Maybe there should be some new FontManager class that exposes functionality.

public void MaximumFontSize { get; set; }

public void MinimumFontSize { get; set; }

public Microsoft.Maui.Graphics.Size MeasureString(string fontName, FontAttributes attributes, string text);

public event EventHandler? FontScaleChanged;

Intended Use-Case

I would like to show an icon image and have it the same height as a label and automatically change size if the system font scale changes.

ghost commented 1 year ago

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

rudyspano commented 1 month ago

I'm working on workaround to limit FontSizeScaling (by implementing IFontManager). In my opinion, it will be really more convenient to propose an Api that limit the maximum scale supported similarly to https://developer.apple.com/documentation/uikit/uiview/3750923-maximumcontentsizecategory