Fixed switch alignment bug

This commit is contained in:
polarboy 2024-10-07 16:25:43 +08:00
parent a97994a132
commit f267c360b0
2 changed files with 11 additions and 8 deletions

View File

@ -141,7 +141,6 @@ internal class CountBadgeAdorner : TemplatedControl
#endregion #endregion
private Panel? _rootLayout;
private MotionActorControl? _indicatorMotionActor; private MotionActorControl? _indicatorMotionActor;
private CancellationTokenSource? _motionCancellationTokenSource; private CancellationTokenSource? _motionCancellationTokenSource;
private bool _needInitialHide; private bool _needInitialHide;

View File

@ -5,6 +5,7 @@ using Avalonia.Controls;
using Avalonia.Controls.Primitives; using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates; using Avalonia.Controls.Templates;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Layout;
using Avalonia.Styling; using Avalonia.Styling;
namespace AtomUI.Controls; namespace AtomUI.Controls;
@ -46,7 +47,7 @@ internal class ToggleSwitchTheme : BaseControlTheme
this.Add(TemplatedControl.ForegroundProperty, GlobalTokenResourceKey.ColorTextLightSolid); this.Add(TemplatedControl.ForegroundProperty, GlobalTokenResourceKey.ColorTextLightSolid);
this.Add(ToggleSwitch.TrackPaddingProperty, ToggleSwitchTokenResourceKey.TrackPadding); this.Add(ToggleSwitch.TrackPaddingProperty, ToggleSwitchTokenResourceKey.TrackPadding);
BuildSizeTypeStyle(); BuildSizeTypeStyle();
BuildEnabledStyle(); BuildCommonStyle();
var disabledStyle = var disabledStyle =
new Style(selector => selector.Nesting().PropertyEquals(InputElement.IsEnabledProperty, false)); new Style(selector => selector.Nesting().PropertyEquals(InputElement.IsEnabledProperty, false));
@ -59,10 +60,13 @@ internal class ToggleSwitchTheme : BaseControlTheme
Add(loadingStyle); Add(loadingStyle);
} }
private void BuildEnabledStyle() private void BuildCommonStyle()
{ {
var enabledStyle = new Style(selector => selector.Nesting()); var commonStyle = new Style(selector => selector.Nesting());
enabledStyle.Add(ToggleSwitch.SwitchOpacityProperty, 1d); commonStyle.Add(ToggleSwitch.SwitchOpacityProperty, 1d);
commonStyle.Add(ToggleSwitch.HorizontalAlignmentProperty, HorizontalAlignment.Left);
commonStyle.Add(ToggleSwitch.VerticalAlignmentProperty, VerticalAlignment.Top);
var checkedStyle = var checkedStyle =
new Style(selector => selector.Nesting().PropertyEquals(ToggleButton.IsCheckedProperty, true)); new Style(selector => selector.Nesting().PropertyEquals(ToggleButton.IsCheckedProperty, true));
checkedStyle.Add(ToggleSwitch.GrooveBackgroundProperty, ToggleSwitchTokenResourceKey.SwitchColor); checkedStyle.Add(ToggleSwitch.GrooveBackgroundProperty, ToggleSwitchTokenResourceKey.SwitchColor);
@ -71,7 +75,7 @@ internal class ToggleSwitchTheme : BaseControlTheme
hoverStyle.Add(ToggleSwitch.GrooveBackgroundProperty, GlobalTokenResourceKey.ColorPrimaryHover); hoverStyle.Add(ToggleSwitch.GrooveBackgroundProperty, GlobalTokenResourceKey.ColorPrimaryHover);
checkedStyle.Add(hoverStyle); checkedStyle.Add(hoverStyle);
} }
enabledStyle.Add(checkedStyle); commonStyle.Add(checkedStyle);
var unCheckedStyle = var unCheckedStyle =
new Style(selector => selector.Nesting().PropertyEquals(ToggleButton.IsCheckedProperty, false)); new Style(selector => selector.Nesting().PropertyEquals(ToggleButton.IsCheckedProperty, false));
@ -81,8 +85,8 @@ internal class ToggleSwitchTheme : BaseControlTheme
hoverStyle.Add(ToggleSwitch.GrooveBackgroundProperty, GlobalTokenResourceKey.ColorTextTertiary); hoverStyle.Add(ToggleSwitch.GrooveBackgroundProperty, GlobalTokenResourceKey.ColorTextTertiary);
unCheckedStyle.Add(hoverStyle); unCheckedStyle.Add(hoverStyle);
} }
enabledStyle.Add(unCheckedStyle); commonStyle.Add(unCheckedStyle);
Add(enabledStyle); Add(commonStyle);
} }
private void BuildSizeTypeStyle() private void BuildSizeTypeStyle()