Uno.Themes icon indicating copy to clipboard operation
Uno.Themes copied to clipboard

Font Override wont work for all controls (probably due to this...)

Open iurycarlos opened this issue 1 year ago • 2 comments

Current behavior

Font overriding is not working for all controls.

For instance:

If we try to override the "LabelLargeFontFamily", it will work fine for Textblocks. However, Buttons will not reproduce the same override as expected since the font they use is "LabelLargeFontFamily".

Taking a look at themes code, I found:

In Typography.xaml , the following line:   <StaticResource x:Key="LabelLargeFontFamily" ResourceKey="MaterialMediumFontFamily" />

And in Button.xaml , its font definition:

So, since it is not referencing directly "LabelLargeFontFamily", I suppose it will never reproduce the override.

Expected behavior

Font Override should work everywhere.

How to reproduce it (as minimally and precisely as possible)

Just use Figma Plugin for example or a new app and try to override the referred font.

 <FontFamily x:Key="LabelLargeFontFamily">Rock Salt</FontFamily>
  <!--The font Rock Salt has been found on Google Fonts at the following url: https://fonts.google.com/specimen/Rock+Salt -->
  <!--And its source can be downloaded directly from: https://fonts.gstatic.com/s/rocksalt/v22/MwQ0bhv11fWD6QsAVOZbsEk7hbBWrA.ttf -->
 

image

Environment

Nuget Package:

Package Version(s):

Affected platform(s):

  • [ ] iOS
  • [ ] Android
  • [ ] WebAssembly
  • [ ] UWP
  • [ ] MacOS

Anything else we need to know?

iurycarlos avatar Nov 24 '23 14:11 iurycarlos

There's a tradeoff here that we have to figure out, either you have fontfamily specific resource keys for each control or they use the ones coming directly from Typography.xaml.

If we make the control styles use the ones from Typography.xaml instead of having things like OutlineButtonFamilyFamily then we lose the ability to customize fonts for specific controls/styles and are limited to only overriding the font family globally.

Due to how resource aliasing works, you can have Resource B be an alias for Resource A and then expect B to change if A is overridden at a later point in time.

So we may need to change things like this: https://github.com/unoplatform/Uno.Themes/blob/0b2a7a98bca04d84285747390d046709347f335d/src/library/Uno.Material/Styles/Controls/v2/CheckBox.xaml#L104-L107

Which will be a breaking change

FYI @Xiaoy312 / @agneszitte

kazo0 avatar Nov 25 '23 14:11 kazo0

@carldebilly FYI

iurycarlos avatar Dec 05 '23 10:12 iurycarlos