From bea0618fd25980a3223651f7f906980d0fe11a4f Mon Sep 17 00:00:00 2001 From: rabbitism Date: Sat, 27 Jan 2024 20:26:40 +0800 Subject: [PATCH] fix: fix padding. --- demo/Ursa.Demo/Pages/IconButtonDemo.axaml | 16 ++++++++++++- .../Controls/IconButton.axaml | 16 ++++++++----- src/Ursa/Controls/IconButton.cs | 23 +++++++++++++++---- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/demo/Ursa.Demo/Pages/IconButtonDemo.axaml b/demo/Ursa.Demo/Pages/IconButtonDemo.axaml index 9877abf..cde464e 100644 --- a/demo/Ursa.Demo/Pages/IconButtonDemo.axaml +++ b/demo/Ursa.Demo/Pages/IconButtonDemo.axaml @@ -24,7 +24,10 @@ IconPlacement="{Binding #placement.Value}" IsLoading="{Binding #loading.IsChecked}"> - + + + + + + diff --git a/src/Ursa.Themes.Semi/Controls/IconButton.axaml b/src/Ursa.Themes.Semi/Controls/IconButton.axaml index 05581d9..64b822c 100644 --- a/src/Ursa.Themes.Semi/Controls/IconButton.axaml +++ b/src/Ursa.Themes.Semi/Controls/IconButton.axaml @@ -38,8 +38,7 @@ RowDefinitions="Auto, Auto"> + Grid.Column="0"> @@ -61,6 +60,7 @@ @@ -107,16 +107,20 @@ + + @@ -124,11 +128,11 @@ @@ -136,11 +140,11 @@ @@ -148,11 +152,11 @@ diff --git a/src/Ursa/Controls/IconButton.cs b/src/Ursa/Controls/IconButton.cs index 1852a3e..f4fabda 100644 --- a/src/Ursa/Controls/IconButton.cs +++ b/src/Ursa/Controls/IconButton.cs @@ -8,13 +8,14 @@ using Ursa.Common; namespace Ursa.Controls; -[PseudoClasses(PC_Right, PC_Left, PC_Top, PC_Bottom)] +[PseudoClasses(PC_Right, PC_Left, PC_Top, PC_Bottom, PC_Empty)] public class IconButton: Button { public const string PC_Right = ":right"; public const string PC_Left = ":left"; public const string PC_Top = ":top"; public const string PC_Bottom = ":bottom"; + public const string PC_Empty = ":empty"; public static readonly StyledProperty IconProperty = AvaloniaProperty.Register( nameof(Icon)); @@ -56,18 +57,32 @@ public class IconButton: Button { IconPlacementProperty.Changed.AddClassHandler((o, e) => { - o.SetPlacement(e.NewValue.Value); + o.SetPlacement(e.NewValue.Value, o.Icon); + }); + IconProperty.Changed.AddClassHandler((o, e) => + { + o.SetPlacement(o.IconPlacement, e.NewValue.Value); }); } protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { base.OnApplyTemplate(e); - SetPlacement(IconPlacement); + SetPlacement(IconPlacement, Icon); } - private void SetPlacement(IconPlacement placement) + private void SetPlacement(IconPlacement placement, object? icon) { + if (icon is null) + { + PseudoClasses.Set(PC_Empty, true); + PseudoClasses.Set(PC_Left, false); + PseudoClasses.Set(PC_Right, false); + PseudoClasses.Set(PC_Top, false); + PseudoClasses.Set(PC_Bottom, false); + return; + } + PseudoClasses.Set(PC_Empty, false); PseudoClasses.Set(PC_Left, placement == IconPlacement.Left); PseudoClasses.Set(PC_Right, placement == IconPlacement.Right); PseudoClasses.Set(PC_Top, placement == IconPlacement.Top);