Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] FontImageSource defaults and style #13474

Open
StepKie opened this issue Feb 21, 2023 · 13 comments
Open

[Enhancement] FontImageSource defaults and style #13474

StepKie opened this issue Feb 21, 2023 · 13 comments
Labels
area-fonts Custom fonts and Font related API's fixed-in-9.0.0-rc.2.24503.2 proposal/open t/enhancement ☀️ New feature or request
Milestone

Comments

@StepKie
Copy link

StepKie commented Feb 21, 2023

Description

This is a reproduction of a highly voted on feature request from Xamarin.Forms
Description, Public API changes and Intended Use case are copied from the original ticket:

Summary

FontImageSource is amazing! Well done team for the implementation.

Now that we're in it and using it, I'd like to propose that there be the ability to set the FontFamily and Color defaults and also make it styleable.

note: i do recognize that making it styleable might negate the need for the default statics, but I thought it might be nice akin to Color.SetAccent(Color accent);

Public API Changes

public class FontImageSource : ImageSource, IStyleElement
{
    public static readonly BindableProperty StyleProperty = BindableProperty.Create(nameof (Style), typeof (Style), typeof (FontImageSource), (object) null, BindingMode.OneWay, (BindableProperty.ValidateValueDelegate) null, (BindableProperty.BindingPropertyChangedDelegate) ((bindable, oldvalue, newvalue) => ((FontImageSource) bindable)._mergedStyle.Style = (IStyle) newvalue), (BindableProperty.BindingPropertyChangingDelegate) null, (BindableProperty.CoerceValueDelegate) null, (BindableProperty.CreateDefaultValueDelegate) null);

    /// <summary>Gets or sets the Style to apply to the FontImageSource.</summary>
    /// <value>To be added.</value>
    /// <remarks>To be added.</remarks>
    public Style Style
    {
      get => (Style) this.GetValue(FontImageSource.StyleProperty);
      set => this.SetValue(FontImageSource.StyleProperty, (object) value);
    }

     public static void SetDefaultFontFamily(string fontFamily)
    {
        DefaultFontFamily = fontFamily;
    }

    public static void SetDefaultColor(Color color)
    {
        DefaultColor = color;
    }
}

Intended Use-Case

Styling would make it far simpler to make reusable font images without having to define them one for each style.

Static default methods will make it so that we only have to define FontFamily or (less important) Color once at startup and we can use that FontFamily as the default throughout the app.

@Eilon Eilon added the area-fonts Custom fonts and Font related API's label Feb 21, 2023
@rachelkang rachelkang added this to the Backlog milestone Feb 22, 2023
@ghost
Copy link

ghost commented Feb 22, 2023

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@KannanKrish
Copy link

I would like to set the FontImageSource color, font family in global control styling in resource dictionary.

<Style TargetType="FontImageSource">
    <Setter Property="Color" Value="{StaticResource SecondaryTextColor}" />
    <Setter Property="FontFamily" Value="{StaticResource FontSolid}" />
</Style>

But not working.

@FM1973
Copy link

FM1973 commented Mar 29, 2023

I would like that too

@redek91
Copy link

redek91 commented Oct 8, 2023

Same here...

@RahmatilloAbduqodirov
Copy link

same here...

@RhomGit
Copy link

RhomGit commented Nov 8, 2023

Same here

@shareitcode
Copy link

I can set many FontImageSource properties in Button Style :

<Style TargetType="Button" x:Key="ButtonPrimary" BasedOn="{StaticResource ButtonBase}">
    <Setter Property="TextColor" Value="{DynamicResource Neutral-50}" />
    <Setter Property="Background" Value="{DynamicResource ButtonPrimaryBackgroundColor}" />
    <Setter Property="ImageSource">
        <Setter.Value>
            <FontImageSource FontFamily="MaterialIcons-Regular" Size="20"/>
        </Setter.Value>
    </Setter>
    <Setter Property="VisualStateManager.VisualStateGroups">
        <VisualStateGroupList>
            <VisualStateGroup x:Name="CommonStates">
                <VisualState x:Name="Normal" />
                <VisualState x:Name="Disabled"/>
                <VisualState x:Name="PointerOver" />
            </VisualStateGroup>
        </VisualStateGroupList>
    </Setter>
</Style>

I can't set the Color property of FontImageSource in Style. But I set the color in the code-behind the custom control (ContentView):

private static void UpdateButtonStyle(BindableObject bindable, object oldValue, object newValue)
{
    // CustomButton = my custom control (ContentView)
    // MyButton = the button inside the custom control
    if (bindable is CustomButton button && button.MyButton.ImageSource is FontImageSource fontImageSource)
    {
        fontImageSource.Color = Colors.Red;
    }
}

@KannanKrish
Copy link

This is work around. But we need this basic feature to reduce the code.

@JamestsaiTW
Copy link

Same here...

@rockthemeek
Copy link

Same now even it worked yesterday!!

@BeepBeepBopBop
Copy link

That would be nice to have.

@ashiibr
Copy link

ashiibr commented Sep 1, 2024

I am also waiting for it, it will help to reduce the code size

@RokIsmart
Copy link

Same here, global / local settings ....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-fonts Custom fonts and Font related API's fixed-in-9.0.0-rc.2.24503.2 proposal/open t/enhancement ☀️ New feature or request
Projects
None yet
Development

No branches or pull requests