Merge branch 'feature/dropdownbutton' into develop

This commit is contained in:
polarboy 2024-08-24 23:38:52 +08:00
commit de2bd782cb
6 changed files with 51 additions and 16 deletions

View File

@ -243,5 +243,6 @@
</atom:DropdownButton> </atom:DropdownButton>
</WrapPanel> </WrapPanel>
</showcase:ShowCaseItem> </showcase:ShowCaseItem>
</showcase:ShowCasePanel> </showcase:ShowCasePanel>
</UserControl> </UserControl>

View File

@ -78,9 +78,8 @@ internal abstract class BaseButtonTheme : BaseControlTheme
HorizontalContentAlignment = HorizontalAlignment.Center, HorizontalContentAlignment = HorizontalAlignment.Center,
VerticalContentAlignment = VerticalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center VerticalAlignment = VerticalAlignment.Center,
}; };
CreateTemplateParentBinding(extraContentPresenter, ContentPresenter.IsVisibleProperty, Button.RightExtraContentProperty, CreateTemplateParentBinding(extraContentPresenter, ContentPresenter.IsVisibleProperty, Button.RightExtraContentProperty,
BindingMode.Default, BindingMode.Default,
ObjectConverters.IsNotNull); ObjectConverters.IsNotNull);
@ -88,7 +87,7 @@ internal abstract class BaseButtonTheme : BaseControlTheme
DockPanel.SetDock(extraContentPresenter, Dock.Right); DockPanel.SetDock(extraContentPresenter, Dock.Right);
var rootLayout = new DockPanel() var rootLayout = new DockPanel
{ {
Name = RootLayoutPart, Name = RootLayoutPart,
LastChildFill = true LastChildFill = true
@ -145,7 +144,7 @@ internal abstract class BaseButtonTheme : BaseControlTheme
} }
{ {
var extraContentStyle = new Style(selector => selector.Nesting().Template().Name(RightExtraContentPart)); var extraContentStyle = new Style(selector => selector.Nesting().Template().Name(RightExtraContentPart));
extraContentStyle.Add(ContentPresenter.PaddingProperty, ButtonTokenResourceKey.ExtraContentMargin); extraContentStyle.Add(ContentPresenter.MarginProperty, ButtonTokenResourceKey.ExtraContentMargin);
middleSizeStyle.Add(extraContentStyle); middleSizeStyle.Add(extraContentStyle);
} }
Add(middleSizeStyle); Add(middleSizeStyle);
@ -162,7 +161,7 @@ internal abstract class BaseButtonTheme : BaseControlTheme
} }
{ {
var extraContentStyle = new Style(selector => selector.Nesting().Template().Name(RightExtraContentPart)); var extraContentStyle = new Style(selector => selector.Nesting().Template().Name(RightExtraContentPart));
extraContentStyle.Add(ContentPresenter.PaddingProperty, ButtonTokenResourceKey.ExtraContentMarginSM); extraContentStyle.Add(ContentPresenter.MarginProperty, ButtonTokenResourceKey.ExtraContentMarginSM);
smallSizeStyle.Add(extraContentStyle); smallSizeStyle.Add(extraContentStyle);
} }
Add(smallSizeStyle); Add(smallSizeStyle);

View File

@ -503,12 +503,13 @@ public class Button : AvaloniaButton,
normalFilledBrushKey = GlobalTokenResourceKey.ColorPrimary; normalFilledBrushKey = GlobalTokenResourceKey.ColorPrimary;
selectedFilledBrushKey = GlobalTokenResourceKey.ColorPrimaryActive; selectedFilledBrushKey = GlobalTokenResourceKey.ColorPrimaryActive;
activeFilledBrushKey = GlobalTokenResourceKey.ColorPrimaryHover; activeFilledBrushKey = GlobalTokenResourceKey.ColorPrimaryHover;
if (IsDanger) {
normalFilledBrushKey = GlobalTokenResourceKey.ColorError;
selectedFilledBrushKey = GlobalTokenResourceKey.ColorErrorActive;
activeFilledBrushKey = GlobalTokenResourceKey.ColorErrorBorderHover;
}
} }
if (IsDanger) {
normalFilledBrushKey = GlobalTokenResourceKey.ColorError;
selectedFilledBrushKey = GlobalTokenResourceKey.ColorErrorActive;
activeFilledBrushKey = GlobalTokenResourceKey.ColorErrorBorderHover;
}
} else if (ButtonType == ButtonType.Text) { } else if (ButtonType == ButtonType.Text) {
normalFilledBrushKey = ButtonTokenResourceKey.DefaultColor; normalFilledBrushKey = ButtonTokenResourceKey.DefaultColor;
selectedFilledBrushKey = ButtonTokenResourceKey.DefaultColor; selectedFilledBrushKey = ButtonTokenResourceKey.DefaultColor;

View File

@ -225,6 +225,21 @@ internal class ButtonToken : AbstractControlDesignToken
/// </summary> /// </summary>
public double ContentLineHeightSM { get; set; } = double.NaN; public double ContentLineHeightSM { get; set; } = double.NaN;
/// <summary>
/// 按钮右边一个额外的区域对右侧的小号外边距
/// </summary>
public Thickness ExtraContentMarginSM { get; set; }
/// <summary>
/// 按钮右边一个额外的区域对右侧的外边距
/// </summary>
public Thickness ExtraContentMargin { get; set; }
/// <summary>
/// 按钮右边一个额外的区域对右侧的大号外边距
/// </summary>
public Thickness ExtraContentMarginLG { get; set; }
#region Token #region Token
/// <summary> /// <summary>

View File

@ -153,11 +153,27 @@ public class DropdownButton : Button
}; };
BindUtils.RelayBind(this, IconSizeProperty, _openIndicatorIcon, PathIcon.WidthProperty); BindUtils.RelayBind(this, IconSizeProperty, _openIndicatorIcon, PathIcon.WidthProperty);
BindUtils.RelayBind(this, IconSizeProperty, _openIndicatorIcon, PathIcon.HeightProperty); BindUtils.RelayBind(this, IconSizeProperty, _openIndicatorIcon, PathIcon.HeightProperty);
RightExtraContent = _openIndicatorIcon;
base.OnApplyTemplate(e); base.OnApplyTemplate(e);
TokenResourceBinder.CreateGlobalTokenBinding(this, MarginToAnchorProperty, GlobalTokenResourceKey.MarginXXS); TokenResourceBinder.CreateGlobalTokenBinding(this, MarginToAnchorProperty, GlobalTokenResourceKey.MarginXXS);
SetupFlyoutProperties(); SetupFlyoutProperties();
if (IsShowIndicator) {
RightExtraContent = _openIndicatorIcon;
}
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);
if (VisualRoot is not null) {
if (e.Property == IsShowIndicatorProperty) {
if (IsShowIndicator) {
RightExtraContent = _openIndicatorIcon;
} else {
RightExtraContent = null;
}
}
}
} }
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e) protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
@ -394,9 +410,9 @@ public class DropdownButton : Button
} }
protected override void NotifyIconBrushCalculated(in TokenResourceKey normalFilledBrushKey, protected override void NotifyIconBrushCalculated(in TokenResourceKey normalFilledBrushKey,
in TokenResourceKey selectedFilledBrushKey, in TokenResourceKey selectedFilledBrushKey,
in TokenResourceKey activeFilledBrushKey, in TokenResourceKey activeFilledBrushKey,
in TokenResourceKey disabledFilledBrushKey) in TokenResourceKey disabledFilledBrushKey)
{ {
if (_openIndicatorIcon is not null) { if (_openIndicatorIcon is not null) {
TokenResourceBinder.CreateGlobalTokenBinding(_openIndicatorIcon, PathIcon.NormalFilledBrushProperty, TokenResourceBinder.CreateGlobalTokenBinding(_openIndicatorIcon, PathIcon.NormalFilledBrushProperty,

View File

@ -123,6 +123,9 @@ namespace AtomUI.Theme.Styling
public static readonly TokenResourceKey ContentLineHeight = new TokenResourceKey("Button.ContentLineHeight", "AtomUI.Token"); public static readonly TokenResourceKey ContentLineHeight = new TokenResourceKey("Button.ContentLineHeight", "AtomUI.Token");
public static readonly TokenResourceKey ContentLineHeightLG = new TokenResourceKey("Button.ContentLineHeightLG", "AtomUI.Token"); public static readonly TokenResourceKey ContentLineHeightLG = new TokenResourceKey("Button.ContentLineHeightLG", "AtomUI.Token");
public static readonly TokenResourceKey ContentLineHeightSM = new TokenResourceKey("Button.ContentLineHeightSM", "AtomUI.Token"); public static readonly TokenResourceKey ContentLineHeightSM = new TokenResourceKey("Button.ContentLineHeightSM", "AtomUI.Token");
public static readonly TokenResourceKey ExtraContentMarginSM = new TokenResourceKey("Button.ExtraContentMarginSM", "AtomUI.Token");
public static readonly TokenResourceKey ExtraContentMargin = new TokenResourceKey("Button.ExtraContentMargin", "AtomUI.Token");
public static readonly TokenResourceKey ExtraContentMarginLG = new TokenResourceKey("Button.ExtraContentMarginLG", "AtomUI.Token");
public static readonly TokenResourceKey IconOnyPadding = new TokenResourceKey("Button.IconOnyPadding", "AtomUI.Token"); public static readonly TokenResourceKey IconOnyPadding = new TokenResourceKey("Button.IconOnyPadding", "AtomUI.Token");
public static readonly TokenResourceKey IconOnyPaddingLG = new TokenResourceKey("Button.IconOnyPaddingLG", "AtomUI.Token"); public static readonly TokenResourceKey IconOnyPaddingLG = new TokenResourceKey("Button.IconOnyPaddingLG", "AtomUI.Token");
public static readonly TokenResourceKey IconOnyPaddingSM = new TokenResourceKey("Button.IconOnyPaddingSM", "AtomUI.Token"); public static readonly TokenResourceKey IconOnyPaddingSM = new TokenResourceKey("Button.IconOnyPaddingSM", "AtomUI.Token");