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>
</WrapPanel>
</showcase:ShowCaseItem>
</showcase:ShowCasePanel>
</UserControl>

View File

@ -78,9 +78,8 @@ internal abstract class BaseButtonTheme : BaseControlTheme
HorizontalContentAlignment = HorizontalAlignment.Center,
VerticalContentAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
VerticalAlignment = VerticalAlignment.Center,
};
CreateTemplateParentBinding(extraContentPresenter, ContentPresenter.IsVisibleProperty, Button.RightExtraContentProperty,
BindingMode.Default,
ObjectConverters.IsNotNull);
@ -88,7 +87,7 @@ internal abstract class BaseButtonTheme : BaseControlTheme
DockPanel.SetDock(extraContentPresenter, Dock.Right);
var rootLayout = new DockPanel()
var rootLayout = new DockPanel
{
Name = RootLayoutPart,
LastChildFill = true
@ -145,7 +144,7 @@ internal abstract class BaseButtonTheme : BaseControlTheme
}
{
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);
}
Add(middleSizeStyle);
@ -162,7 +161,7 @@ internal abstract class BaseButtonTheme : BaseControlTheme
}
{
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);
}
Add(smallSizeStyle);

View File

@ -503,12 +503,13 @@ public class Button : AvaloniaButton,
normalFilledBrushKey = GlobalTokenResourceKey.ColorPrimary;
selectedFilledBrushKey = GlobalTokenResourceKey.ColorPrimaryActive;
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) {
normalFilledBrushKey = ButtonTokenResourceKey.DefaultColor;
selectedFilledBrushKey = ButtonTokenResourceKey.DefaultColor;

View File

@ -225,6 +225,21 @@ internal class ButtonToken : AbstractControlDesignToken
/// </summary>
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
/// <summary>

View File

@ -153,11 +153,27 @@ public class DropdownButton : Button
};
BindUtils.RelayBind(this, IconSizeProperty, _openIndicatorIcon, PathIcon.WidthProperty);
BindUtils.RelayBind(this, IconSizeProperty, _openIndicatorIcon, PathIcon.HeightProperty);
RightExtraContent = _openIndicatorIcon;
base.OnApplyTemplate(e);
TokenResourceBinder.CreateGlobalTokenBinding(this, MarginToAnchorProperty, GlobalTokenResourceKey.MarginXXS);
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)
@ -394,9 +410,9 @@ public class DropdownButton : Button
}
protected override void NotifyIconBrushCalculated(in TokenResourceKey normalFilledBrushKey,
in TokenResourceKey selectedFilledBrushKey,
in TokenResourceKey activeFilledBrushKey,
in TokenResourceKey disabledFilledBrushKey)
in TokenResourceKey selectedFilledBrushKey,
in TokenResourceKey activeFilledBrushKey,
in TokenResourceKey disabledFilledBrushKey)
{
if (_openIndicatorIcon is not null) {
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 ContentLineHeightLG = new TokenResourceKey("Button.ContentLineHeightLG", "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 IconOnyPaddingLG = new TokenResourceKey("Button.IconOnyPaddingLG", "AtomUI.Token");
public static readonly TokenResourceKey IconOnyPaddingSM = new TokenResourceKey("Button.IconOnyPaddingSM", "AtomUI.Token");