From 5f32b8c387eec5b5e0e60ebde49ff32acc71843f Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 30 Oct 2024 18:07:50 +0100 Subject: [PATCH] Introduce more pseudo-classes - moved pseudo-class definition to base class - add a method to update the classes as needed per icon data - update styles accordingly --- .../PackIconBoxIcons.cs | 2 ++ .../PackIconControlBase.cs | 29 +++++++++++++++++++ src/IconPacks.Avalonia/PackIconControl.cs | 10 ++----- src/IconPacks.Avalonia/PackIconControl.xaml | 18 ++++++++++-- 4 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/IconPacks.Avalonia.BoxIcons/PackIconBoxIcons.cs b/src/IconPacks.Avalonia.BoxIcons/PackIconBoxIcons.cs index cf08088..f89da52 100644 --- a/src/IconPacks.Avalonia.BoxIcons/PackIconBoxIcons.cs +++ b/src/IconPacks.Avalonia.BoxIcons/PackIconBoxIcons.cs @@ -33,6 +33,8 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang { UpdateData(); } + + base.UpdateIconPseudoClasses(true, false, true); } protected override void SetKind(TKind iconKind) diff --git a/src/IconPacks.Avalonia.Core/PackIconControlBase.cs b/src/IconPacks.Avalonia.Core/PackIconControlBase.cs index 9d43945..3001aab 100644 --- a/src/IconPacks.Avalonia.Core/PackIconControlBase.cs +++ b/src/IconPacks.Avalonia.Core/PackIconControlBase.cs @@ -6,6 +6,7 @@ using Avalonia.Animation; using Avalonia.Animation.Easings; using Avalonia.Controls; +using Avalonia.Controls.Metadata; using Avalonia.Controls.Primitives; using Avalonia.Data; using Avalonia.Media; @@ -16,8 +17,29 @@ namespace IconPacks.Avalonia /// /// Class PackIconControlBase which is the base class for any PackIcon control. /// + [PseudoClasses(IconDataFlippedVerticallyPseudoClass)] + [PseudoClasses(IconFilledPseudoClass)] + [PseudoClasses(IconOutlinedPseudoClass)] public abstract class PackIconControlBase : PackIconBase { + /// + /// A string representing the pseudo-class when the icon data is flipped vertically + /// + /// ":icon-data-flipped-vertically" + public const string IconDataFlippedVerticallyPseudoClass = ":icon-data-flipped-vertically"; + + /// + /// A string representing the pseudo-class when the icon data is drawn filled + /// + /// ":icon-filled" + public const string IconFilledPseudoClass = ":icon-filled"; + + /// + /// A string representing the pseudo-class when the icon data is drawn outlined + /// + /// ":icon-outlided" + public const string IconOutlinedPseudoClass = ":icon-outlined"; + protected PackIconControlBase() { AffectsRender(SpinProperty, SpinDurationProperty, OpacityProperty, SpinEasingFunctionProperty, FlipProperty, RotationAngleProperty); @@ -281,5 +303,12 @@ public bool SpinAutoReverse get { return this.GetValue(SpinAutoReverseProperty); } set { this.SetValue(SpinAutoReverseProperty, value); } } + + protected void UpdateIconPseudoClasses(bool filled, bool outlined, bool flipped) + { + PseudoClasses.Set(IconFilledPseudoClass, filled); + PseudoClasses.Set(IconOutlinedPseudoClass, outlined); + PseudoClasses.Set(IconDataFlippedVerticallyPseudoClass, flipped); + } } } \ No newline at end of file diff --git a/src/IconPacks.Avalonia/PackIconControl.cs b/src/IconPacks.Avalonia/PackIconControl.cs index ce94189..ef42c15 100644 --- a/src/IconPacks.Avalonia/PackIconControl.cs +++ b/src/IconPacks.Avalonia/PackIconControl.cs @@ -10,14 +10,8 @@ namespace IconPacks.Avalonia { /// /// - [PseudoClasses(IconDataFlippedVerticallyPseudoClass)] public class PackIconControl : PackIconControlBase { - /// - /// A string representing the pseudo-class when the icon data is flipped vertically - /// - /// ":icon-data-flipped-vertically" - public const string IconDataFlippedVerticallyPseudoClass = ":icon-data-flipped-vertically"; public static readonly StyledProperty KindProperty = AvaloniaProperty.Register(nameof(Kind)); @@ -53,11 +47,11 @@ protected override void UpdateData() switch(Kind) { case PackIconBoxIconsKind: - PseudoClasses.Set(IconDataFlippedVerticallyPseudoClass, true); + UpdateIconPseudoClasses(true, false, true); break; default: - PseudoClasses.Set(IconDataFlippedVerticallyPseudoClass, false); + UpdateIconPseudoClasses(true, false, false); break; } diff --git a/src/IconPacks.Avalonia/PackIconControl.xaml b/src/IconPacks.Avalonia/PackIconControl.xaml index 0e9c10e..a6e48dc 100644 --- a/src/IconPacks.Avalonia/PackIconControl.xaml +++ b/src/IconPacks.Avalonia/PackIconControl.xaml @@ -1,11 +1,11 @@ - - + @@ -21,7 +21,6 @@ Margin="{TemplateBinding Padding}"> @@ -166,6 +165,19 @@ + + + + + +