From f267c360b0e055b0d1ebcd6a2aa00b4b6118a637 Mon Sep 17 00:00:00 2001 From: polarboy Date: Mon, 7 Oct 2024 16:25:43 +0800 Subject: [PATCH] Fixed switch alignment bug --- src/AtomUI.Controls/Badge/CountBadgeAdorner.cs | 1 - .../Switch/ToggleSwitchTheme.cs | 18 +++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/AtomUI.Controls/Badge/CountBadgeAdorner.cs b/src/AtomUI.Controls/Badge/CountBadgeAdorner.cs index 26a57f0..42c2b7b 100644 --- a/src/AtomUI.Controls/Badge/CountBadgeAdorner.cs +++ b/src/AtomUI.Controls/Badge/CountBadgeAdorner.cs @@ -141,7 +141,6 @@ internal class CountBadgeAdorner : TemplatedControl #endregion - private Panel? _rootLayout; private MotionActorControl? _indicatorMotionActor; private CancellationTokenSource? _motionCancellationTokenSource; private bool _needInitialHide; diff --git a/src/AtomUI.Controls/Switch/ToggleSwitchTheme.cs b/src/AtomUI.Controls/Switch/ToggleSwitchTheme.cs index 5eb0176..5db4822 100644 --- a/src/AtomUI.Controls/Switch/ToggleSwitchTheme.cs +++ b/src/AtomUI.Controls/Switch/ToggleSwitchTheme.cs @@ -5,6 +5,7 @@ using Avalonia.Controls; using Avalonia.Controls.Primitives; using Avalonia.Controls.Templates; using Avalonia.Input; +using Avalonia.Layout; using Avalonia.Styling; namespace AtomUI.Controls; @@ -46,7 +47,7 @@ internal class ToggleSwitchTheme : BaseControlTheme this.Add(TemplatedControl.ForegroundProperty, GlobalTokenResourceKey.ColorTextLightSolid); this.Add(ToggleSwitch.TrackPaddingProperty, ToggleSwitchTokenResourceKey.TrackPadding); BuildSizeTypeStyle(); - BuildEnabledStyle(); + BuildCommonStyle(); var disabledStyle = new Style(selector => selector.Nesting().PropertyEquals(InputElement.IsEnabledProperty, false)); @@ -59,10 +60,13 @@ internal class ToggleSwitchTheme : BaseControlTheme Add(loadingStyle); } - private void BuildEnabledStyle() + private void BuildCommonStyle() { - var enabledStyle = new Style(selector => selector.Nesting()); - enabledStyle.Add(ToggleSwitch.SwitchOpacityProperty, 1d); + var commonStyle = new Style(selector => selector.Nesting()); + commonStyle.Add(ToggleSwitch.SwitchOpacityProperty, 1d); + commonStyle.Add(ToggleSwitch.HorizontalAlignmentProperty, HorizontalAlignment.Left); + commonStyle.Add(ToggleSwitch.VerticalAlignmentProperty, VerticalAlignment.Top); + var checkedStyle = new Style(selector => selector.Nesting().PropertyEquals(ToggleButton.IsCheckedProperty, true)); checkedStyle.Add(ToggleSwitch.GrooveBackgroundProperty, ToggleSwitchTokenResourceKey.SwitchColor); @@ -71,7 +75,7 @@ internal class ToggleSwitchTheme : BaseControlTheme hoverStyle.Add(ToggleSwitch.GrooveBackgroundProperty, GlobalTokenResourceKey.ColorPrimaryHover); checkedStyle.Add(hoverStyle); } - enabledStyle.Add(checkedStyle); + commonStyle.Add(checkedStyle); var unCheckedStyle = new Style(selector => selector.Nesting().PropertyEquals(ToggleButton.IsCheckedProperty, false)); @@ -81,8 +85,8 @@ internal class ToggleSwitchTheme : BaseControlTheme hoverStyle.Add(ToggleSwitch.GrooveBackgroundProperty, GlobalTokenResourceKey.ColorTextTertiary); unCheckedStyle.Add(hoverStyle); } - enabledStyle.Add(unCheckedStyle); - Add(enabledStyle); + commonStyle.Add(unCheckedStyle); + Add(commonStyle); } private void BuildSizeTypeStyle()