mirror of
https://gitee.com/chinware/atomui.git
synced 2024-12-02 03:47:52 +08:00
完成顶层菜单风格定义
This commit is contained in:
parent
b010aed373
commit
f58b518855
@ -265,32 +265,32 @@ public class Button : AvaloniaButton,
|
||||
|
||||
void IControlCustomStyle.SetupTransitions()
|
||||
{
|
||||
var transitions = new Transitions();
|
||||
if (ButtonType == ButtonType.Primary) {
|
||||
transitions.Add(AnimationUtils.CreateTransition<SolidColorBrushTransition>(BackgroundProperty));
|
||||
if (IsGhost) {
|
||||
if (Transitions is null) {
|
||||
var transitions = new Transitions();
|
||||
if (ButtonType == ButtonType.Primary) {
|
||||
transitions.Add(AnimationUtils.CreateTransition<SolidColorBrushTransition>(BackgroundProperty));
|
||||
if (IsGhost) {
|
||||
transitions.Add(AnimationUtils.CreateTransition<SolidColorBrushTransition>(BorderBrushProperty));
|
||||
transitions.Add(AnimationUtils.CreateTransition<SolidColorBrushTransition>(ForegroundProperty));
|
||||
}
|
||||
} else if (ButtonType == ButtonType.Default) {
|
||||
transitions.Add(AnimationUtils.CreateTransition<SolidColorBrushTransition>(BorderBrushProperty));
|
||||
transitions.Add(AnimationUtils.CreateTransition<SolidColorBrushTransition>(ForegroundProperty));
|
||||
} else if (ButtonType == ButtonType.Text) {
|
||||
transitions.Add(AnimationUtils.CreateTransition<SolidColorBrushTransition>(BackgroundProperty));
|
||||
} else if (ButtonType == ButtonType.Link) {
|
||||
transitions.Add(AnimationUtils.CreateTransition<SolidColorBrushTransition>(ForegroundProperty));
|
||||
}
|
||||
} else if (ButtonType == ButtonType.Default) {
|
||||
transitions.Add(AnimationUtils.CreateTransition<SolidColorBrushTransition>(BorderBrushProperty));
|
||||
transitions.Add(AnimationUtils.CreateTransition<SolidColorBrushTransition>(ForegroundProperty));
|
||||
} else if (ButtonType == ButtonType.Text) {
|
||||
transitions.Add(AnimationUtils.CreateTransition<SolidColorBrushTransition>(BackgroundProperty));
|
||||
} else if (ButtonType == ButtonType.Link) {
|
||||
transitions.Add(AnimationUtils.CreateTransition<SolidColorBrushTransition>(ForegroundProperty));
|
||||
}
|
||||
|
||||
Transitions = transitions;
|
||||
Transitions = transitions;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
base.OnApplyTemplate(e);
|
||||
_customStyle.HandleTemplateApplied(e.NameScope);
|
||||
if (Transitions is null) {
|
||||
_customStyle.SetupTransitions();
|
||||
}
|
||||
_customStyle.SetupTransitions();
|
||||
}
|
||||
|
||||
void IControlCustomStyle.HandleTemplateApplied(INameScope scope)
|
||||
|
@ -184,32 +184,32 @@ internal class ButtonToken : AbstractControlDesignToken
|
||||
/// <summary>
|
||||
/// 按钮内容字体大小
|
||||
/// </summary>
|
||||
public double ContentFontSize { get; set; } = -1;
|
||||
public double ContentFontSize { get; set; } = double.NaN;
|
||||
|
||||
/// <summary>
|
||||
/// 大号按钮内容字体大小
|
||||
/// </summary>
|
||||
public double ContentFontSizeLG { get; set; } = -1;
|
||||
public double ContentFontSizeLG { get; set; } = double.NaN;
|
||||
|
||||
/// <summary>
|
||||
/// 小号按钮内容字体大小
|
||||
/// </summary>
|
||||
public double ContentFontSizeSM { get; set; } = -1;
|
||||
public double ContentFontSizeSM { get; set; } = double.NaN;
|
||||
|
||||
/// <summary>
|
||||
/// 按钮内容字体行高
|
||||
/// </summary>
|
||||
public double ContentLineHeight { get; set; } = -1;
|
||||
public double ContentLineHeight { get; set; } = double.NaN;
|
||||
|
||||
/// <summary>
|
||||
/// 大号按钮内容字体行高
|
||||
/// </summary>
|
||||
public double ContentLineHeightLG { get; set; } = -1;
|
||||
public double ContentLineHeightLG { get; set; } = double.NaN;
|
||||
|
||||
/// <summary>
|
||||
/// 小号按钮内容字体行高
|
||||
/// </summary>
|
||||
public double ContentLineHeightSM { get; set; } = -1;
|
||||
public double ContentLineHeightSM { get; set; } = double.NaN;
|
||||
|
||||
public ButtonToken()
|
||||
: base(ID)
|
||||
@ -222,18 +222,18 @@ internal class ButtonToken : AbstractControlDesignToken
|
||||
var fontSize = _globalToken.FontToken.FontSize;
|
||||
var fontSizeLG = _globalToken.FontToken.FontSizeLG;
|
||||
|
||||
ContentFontSize = !MathUtils.AreClose(ContentFontSize, -1) ? ContentFontSize : fontSize;
|
||||
ContentFontSizeSM = !MathUtils.AreClose(ContentFontSizeSM, -1) ? ContentFontSizeSM : fontSize;
|
||||
ContentFontSizeLG = !MathUtils.AreClose(ContentFontSizeLG, -1) ? ContentFontSizeLG : fontSizeLG;
|
||||
ContentLineHeight = !MathUtils.AreClose(ContentLineHeight, -1)
|
||||
ContentFontSize = !double.IsNaN(ContentFontSize) ? ContentFontSize : fontSize;
|
||||
ContentFontSizeSM = !double.IsNaN(ContentFontSizeSM) ? ContentFontSizeSM : fontSize;
|
||||
ContentFontSizeLG = !double.IsNaN(ContentFontSizeLG) ? ContentFontSizeLG : fontSizeLG;
|
||||
ContentLineHeight = !double.IsNaN(ContentLineHeight)
|
||||
? ContentLineHeight
|
||||
: CalculatorUtils.CalculateLineHeight(ContentFontSize);
|
||||
ContentLineHeightSM = !MathUtils.AreClose(ContentLineHeightSM, -1)
|
||||
: CalculatorUtils.CalculateLineHeight(ContentFontSize) * ContentFontSize;
|
||||
ContentLineHeightSM = !double.IsNaN(ContentLineHeightSM)
|
||||
? ContentLineHeightSM
|
||||
: CalculatorUtils.CalculateLineHeight(ContentFontSizeSM);
|
||||
ContentLineHeightLG = !MathUtils.AreClose(ContentLineHeightLG, -1)
|
||||
: CalculatorUtils.CalculateLineHeight(ContentFontSizeSM) * ContentFontSizeSM;
|
||||
ContentLineHeightLG = !double.IsNaN(ContentLineHeightLG)
|
||||
? ContentLineHeightLG
|
||||
: CalculatorUtils.CalculateLineHeight(ContentFontSizeLG);
|
||||
: CalculatorUtils.CalculateLineHeight(ContentFontSizeLG) * ContentFontSizeLG;
|
||||
|
||||
var controlOutlineWidth = _globalToken.ControlOutlineWidth;
|
||||
FontWeight = 400;
|
||||
@ -290,16 +290,17 @@ internal class ButtonToken : AbstractControlDesignToken
|
||||
DefaultActiveColor = primaryColorToken.ColorPrimaryActive;
|
||||
DefaultActiveBorderColor = primaryColorToken.ColorPrimaryActive;
|
||||
|
||||
var controlHeight = _globalToken.SeedToken.ControlHeight;
|
||||
var controlHeightSM = base._globalToken.HeightToken.ControlHeightSM;
|
||||
var controlHeight = _globalToken.SeedToken.ControlHeight;
|
||||
var controlHeightLG = _globalToken.HeightToken.ControlHeightLG;
|
||||
|
||||
Padding = new Thickness(_globalToken.PaddingContentHorizontal - lineWidth,
|
||||
Math.Max((controlHeight - ContentFontSize * ContentLineHeight) / 2 - lineWidth, 0));
|
||||
PaddingLG = new Thickness(_globalToken.PaddingContentHorizontal - lineWidth,
|
||||
Math.Max((controlHeightSM - ContentFontSizeSM * ContentLineHeightSM) / 2 - lineWidth, 0));
|
||||
PaddingSM = new Thickness(8 - _globalToken.SeedToken.LineWidth,
|
||||
Math.Max((controlHeightLG - controlHeightLG * controlHeightLG) / 2 - lineWidth, 0));
|
||||
Math.Max((controlHeightSM - ContentLineHeightSM) / 2 - lineWidth, 0));
|
||||
Padding = new Thickness(_globalToken.PaddingContentHorizontal - lineWidth,
|
||||
Math.Max((controlHeight - ContentLineHeight) / 2 - lineWidth, 0));
|
||||
PaddingLG = new Thickness(_globalToken.PaddingContentHorizontal - lineWidth,
|
||||
Math.Max((controlHeightLG - ContentLineHeightLG) / 2 - lineWidth, 0));
|
||||
|
||||
CirclePadding = new Thickness(PaddingSM.Left / 2);
|
||||
OnlyIconSizeSM = _globalToken.IconSize;
|
||||
OnlyIconSize = _globalToken.IconSizeLG;
|
||||
|
@ -74,9 +74,8 @@ internal class DefaultButtonTheme : BaseButtonTheme
|
||||
}
|
||||
enabledStyle.Add(dangerStyle);
|
||||
|
||||
BuildEnabledGhostStyle(enabledStyle);
|
||||
Add(enabledStyle);
|
||||
|
||||
BuildEnabledGhostStyle();
|
||||
}
|
||||
|
||||
private void BuildIconStyle()
|
||||
@ -114,7 +113,7 @@ internal class DefaultButtonTheme : BaseButtonTheme
|
||||
|
||||
}
|
||||
|
||||
private void BuildEnabledGhostStyle()
|
||||
private void BuildEnabledGhostStyle(Style enabledStyle)
|
||||
{
|
||||
var ghostStyle = new Style(selector => selector.Nesting().PropertyEquals(Button.IsGhostProperty, true));
|
||||
// 正常状态
|
||||
@ -141,9 +140,26 @@ internal class DefaultButtonTheme : BaseButtonTheme
|
||||
// 危险按钮状态
|
||||
var dangerStyle = new Style(selector => selector.Nesting().PropertyEquals(Button.IsDangerProperty, true));
|
||||
dangerStyle.Add(Button.BackgroundProperty, new DynamicResourceExtension(GlobalResourceKey.ColorTransparent));
|
||||
dangerStyle.Add(Button.BorderBrushProperty, new DynamicResourceExtension(GlobalResourceKey.ColorError));
|
||||
dangerStyle.Add(Button.ForegroundProperty, new DynamicResourceExtension(GlobalResourceKey.ColorError));
|
||||
|
||||
// 危险状态 hover
|
||||
{
|
||||
var hoverStyle = new Style(selector => selector.Nesting().Class(StdPseudoClass.PointerOver));
|
||||
hoverStyle.Add(Button.BorderBrushProperty, new DynamicResourceExtension(GlobalResourceKey.ColorErrorBorderHover));
|
||||
hoverStyle.Add(Button.ForegroundProperty, new DynamicResourceExtension(GlobalResourceKey.ColorErrorBorderHover));
|
||||
dangerStyle.Add(hoverStyle);
|
||||
}
|
||||
|
||||
// 危险状态按下
|
||||
{
|
||||
var pressedStyle = new Style(selector => selector.Nesting().Class(StdPseudoClass.PointerOver).Class(StdPseudoClass.Pressed));
|
||||
pressedStyle.Add(Button.BorderBrushProperty, new DynamicResourceExtension(GlobalResourceKey.ColorErrorActive));
|
||||
pressedStyle.Add(Button.ForegroundProperty, new DynamicResourceExtension(GlobalResourceKey.ColorErrorActive));
|
||||
dangerStyle.Add(pressedStyle);
|
||||
}
|
||||
ghostStyle.Add(dangerStyle);
|
||||
Add(ghostStyle);
|
||||
enabledStyle.Add(ghostStyle);
|
||||
}
|
||||
|
||||
private void BuildDisabledStyle()
|
||||
|
@ -31,37 +31,37 @@ internal class TextButtonTheme : BaseButtonTheme
|
||||
{
|
||||
var enabledStyle = new Style(selector => selector.Nesting());
|
||||
// 正常状态
|
||||
enabledStyle.Add(Button.BackgroundProperty, new DynamicResourceExtension(GlobalResourceKey.ColorTransparent));
|
||||
enabledStyle.Add(Button.ForegroundProperty, new DynamicResourceExtension(ButtonResourceKey.DefaultColor));
|
||||
enabledStyle.Add(Button.BackgroundProperty, GlobalResourceKey.ColorTransparent);
|
||||
enabledStyle.Add(Button.ForegroundProperty, ButtonResourceKey.DefaultColor);
|
||||
|
||||
// 正常 hover
|
||||
{
|
||||
var hoverStyle = new Style(selector => selector.Nesting().Class(StdPseudoClass.PointerOver));
|
||||
hoverStyle.Add(Button.BackgroundProperty, new DynamicResourceExtension(ButtonResourceKey.TextHoverBg));
|
||||
hoverStyle.Add(Button.BackgroundProperty, ButtonResourceKey.TextHoverBg);
|
||||
enabledStyle.Add(hoverStyle);
|
||||
}
|
||||
// 正常按下
|
||||
{
|
||||
var pressedStyle = new Style(selector => selector.Nesting().Class(StdPseudoClass.PointerOver).Class(StdPseudoClass.Pressed));
|
||||
pressedStyle.Add(Button.BackgroundProperty, new DynamicResourceExtension(GlobalResourceKey.ColorBgTextActive));
|
||||
pressedStyle.Add(Button.BackgroundProperty, GlobalResourceKey.ColorBgTextActive);
|
||||
enabledStyle.Add(pressedStyle);
|
||||
}
|
||||
|
||||
// 危险按钮状态
|
||||
var dangerStyle = new Style(selector => selector.Nesting().PropertyEquals(Button.IsDangerProperty, true));
|
||||
dangerStyle.Add(Button.ForegroundProperty, new DynamicResourceExtension(GlobalResourceKey.ColorError));
|
||||
dangerStyle.Add(Button.ForegroundProperty, GlobalResourceKey.ColorError);
|
||||
|
||||
// 危险状态 hover
|
||||
{
|
||||
var hoverStyle = new Style(selector => selector.Nesting().Class(StdPseudoClass.PointerOver));
|
||||
hoverStyle.Add(Button.BackgroundProperty, new DynamicResourceExtension(GlobalResourceKey.ColorErrorBgHover));
|
||||
hoverStyle.Add(Button.BackgroundProperty, GlobalResourceKey.ColorErrorBgHover);
|
||||
dangerStyle.Add(hoverStyle);
|
||||
}
|
||||
|
||||
// 危险状态按下
|
||||
{
|
||||
var pressedStyle = new Style(selector => selector.Nesting().Class(StdPseudoClass.PointerOver).Class(StdPseudoClass.Pressed));
|
||||
pressedStyle.Add(Button.BackgroundProperty, new DynamicResourceExtension(GlobalResourceKey.ColorErrorBgActive));
|
||||
pressedStyle.Add(Button.BackgroundProperty, GlobalResourceKey.ColorErrorBgActive);
|
||||
dangerStyle.Add(pressedStyle);
|
||||
}
|
||||
enabledStyle.Add(dangerStyle);
|
||||
@ -94,7 +94,7 @@ internal class TextButtonTheme : BaseButtonTheme
|
||||
private void BuildDisabledStyle()
|
||||
{
|
||||
var disabledStyle = new Style(selector => selector.Nesting().Class(StdPseudoClass.Disabled));
|
||||
disabledStyle.Add(Button.ForegroundProperty, new DynamicResourceExtension(GlobalResourceKey.ColorTextDisabled));
|
||||
disabledStyle.Add(Button.ForegroundProperty, GlobalResourceKey.ColorTextDisabled);
|
||||
Add(disabledStyle);
|
||||
}
|
||||
}
|
@ -136,6 +136,24 @@ namespace AtomUI.Styling
|
||||
public static readonly TokenResourceKey ItemIconMarginInlineEnd = new TokenResourceKey("Menu.ItemIconMarginInlineEnd");
|
||||
public static readonly TokenResourceKey ItemBorderRadius = new TokenResourceKey("Menu.ItemBorderRadius");
|
||||
public static readonly TokenResourceKey ItemPaddingInline = new TokenResourceKey("Menu.ItemPaddingInline");
|
||||
public static readonly TokenResourceKey TopLevelItemColor = new TokenResourceKey("Menu.TopLevelItemColor");
|
||||
public static readonly TokenResourceKey TopLevelItemSelectedColor = new TokenResourceKey("Menu.TopLevelItemSelectedColor");
|
||||
public static readonly TokenResourceKey TopLevelItemHoverColor = new TokenResourceKey("Menu.TopLevelItemHoverColor");
|
||||
public static readonly TokenResourceKey TopLevelItemBg = new TokenResourceKey("Menu.TopLevelItemBg");
|
||||
public static readonly TokenResourceKey TopLevelItemSelectedBg = new TokenResourceKey("Menu.TopLevelItemSelectedBg");
|
||||
public static readonly TokenResourceKey TopLevelItemHoverBg = new TokenResourceKey("Menu.TopLevelItemHoverBg");
|
||||
public static readonly TokenResourceKey TopLevelItemBorderRadiusSM = new TokenResourceKey("Menu.TopLevelItemBorderRadiusSM");
|
||||
public static readonly TokenResourceKey TopLevelItemBorderRadius = new TokenResourceKey("Menu.TopLevelItemBorderRadius");
|
||||
public static readonly TokenResourceKey TopLevelItemBorderRadiusLG = new TokenResourceKey("Menu.TopLevelItemBorderRadiusLG");
|
||||
public static readonly TokenResourceKey TopLevelItemPaddingSM = new TokenResourceKey("Menu.TopLevelItemPaddingSM");
|
||||
public static readonly TokenResourceKey TopLevelItemPadding = new TokenResourceKey("Menu.TopLevelItemPadding");
|
||||
public static readonly TokenResourceKey TopLevelItemPaddingLG = new TokenResourceKey("Menu.TopLevelItemPaddingLG");
|
||||
public static readonly TokenResourceKey TopLevelItemFontSizeSM = new TokenResourceKey("Menu.TopLevelItemFontSizeSM");
|
||||
public static readonly TokenResourceKey TopLevelItemFontSize = new TokenResourceKey("Menu.TopLevelItemFontSize");
|
||||
public static readonly TokenResourceKey TopLevelItemFontSizeLG = new TokenResourceKey("Menu.TopLevelItemFontSizeLG");
|
||||
public static readonly TokenResourceKey TopLevelItemLineHeight = new TokenResourceKey("Menu.TopLevelItemLineHeight");
|
||||
public static readonly TokenResourceKey TopLevelItemLineHeightLG = new TokenResourceKey("Menu.TopLevelItemLineHeightLG");
|
||||
public static readonly TokenResourceKey TopLevelItemLineHeightSM = new TokenResourceKey("Menu.TopLevelItemLineHeightSM");
|
||||
public static readonly TokenResourceKey MenuBoxShadows = new TokenResourceKey("Menu.MenuBoxShadows");
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ public class Menu : AvaloniaMenu,
|
||||
#region 公共属性定义
|
||||
|
||||
public static readonly StyledProperty<SizeType> SizeTypeProperty =
|
||||
AvaloniaProperty.Register<Button, SizeType>(nameof(SizeType), SizeType.Middle);
|
||||
AvaloniaProperty.Register<Menu, SizeType>(nameof(SizeType), SizeType.Middle);
|
||||
|
||||
public SizeType SizeType
|
||||
{
|
||||
@ -31,4 +31,12 @@ public class Menu : AvaloniaMenu,
|
||||
BindUtils.CreateGlobalResourceBinding(this, ItemContainerThemeProperty, TopLevelMenuItemTheme.ID);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void PrepareContainerForItemOverride(Control container, object? item, int index)
|
||||
{
|
||||
if (container is MenuItem menuItem) {
|
||||
BindUtils.RelayBind(this, SizeTypeProperty, menuItem, MenuItem.SizeTypeProperty);
|
||||
}
|
||||
base.PrepareContainerForItemOverride(container, item, index);
|
||||
}
|
||||
}
|
@ -1,12 +1,16 @@
|
||||
using AtomUI.Utils;
|
||||
using AtomUI.Media;
|
||||
using AtomUI.Styling;
|
||||
using AtomUI.Utils;
|
||||
using Avalonia;
|
||||
using Avalonia.LogicalTree;
|
||||
using Avalonia.Animation;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
|
||||
namespace AtomUI.Controls;
|
||||
|
||||
using AvaloniaMenuItem = Avalonia.Controls.MenuItem;
|
||||
|
||||
public class MenuItem : AvaloniaMenuItem
|
||||
public class MenuItem : AvaloniaMenuItem, IControlCustomStyle
|
||||
{
|
||||
#region 公共属性定义
|
||||
|
||||
@ -20,4 +24,39 @@ public class MenuItem : AvaloniaMenuItem
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private readonly IControlCustomStyle _customStyle;
|
||||
|
||||
static MenuItem()
|
||||
{
|
||||
AffectsRender<MenuItem>(BackgroundProperty);
|
||||
}
|
||||
|
||||
public MenuItem()
|
||||
{
|
||||
_customStyle = this;
|
||||
}
|
||||
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
base.OnApplyTemplate(e);
|
||||
_customStyle.HandleTemplateApplied(e.NameScope);
|
||||
}
|
||||
|
||||
#region IControlCustomStyle 实现
|
||||
void IControlCustomStyle.SetupTransitions()
|
||||
{
|
||||
if (Transitions is null) {
|
||||
var transitions = new Transitions();
|
||||
transitions.Add(AnimationUtils.CreateTransition<SolidColorBrushTransition>(BackgroundProperty));
|
||||
transitions.Add(AnimationUtils.CreateTransition<SolidColorBrushTransition>(ForegroundProperty));
|
||||
Transitions = transitions;
|
||||
}
|
||||
}
|
||||
|
||||
void IControlCustomStyle.HandleTemplateApplied(INameScope scope)
|
||||
{
|
||||
_customStyle.SetupTransitions();
|
||||
}
|
||||
#endregion
|
||||
}
|
@ -25,7 +25,8 @@ public class MenuTheme : ControlTheme
|
||||
var itemPresenter = new ItemsPresenter()
|
||||
{
|
||||
Name = ItemsPresenterPart,
|
||||
VerticalAlignment = VerticalAlignment.Stretch,
|
||||
HorizontalAlignment = HorizontalAlignment.Stretch,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
ItemsPanel = new FuncTemplate<Panel?>(() => new StackPanel()
|
||||
{
|
||||
Orientation = Orientation.Horizontal
|
||||
|
@ -1,4 +1,5 @@
|
||||
using AtomUI.TokenSystem;
|
||||
using AtomUI.Styling;
|
||||
using AtomUI.TokenSystem;
|
||||
using Avalonia;
|
||||
using Avalonia.Media;
|
||||
|
||||
@ -115,6 +116,97 @@ internal class MenuToken : AbstractControlDesignToken
|
||||
/// </summary>
|
||||
public Thickness ItemPaddingInline { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 顶层菜单项颜色
|
||||
/// </summary>
|
||||
public Color TopLevelItemColor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 顶层菜单项选中颜色
|
||||
/// </summary>
|
||||
public Color TopLevelItemSelectedColor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 顶层菜单项鼠标放上去的颜色
|
||||
/// </summary>
|
||||
public Color TopLevelItemHoverColor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 顶层菜单项背景色
|
||||
/// </summary>
|
||||
public Color TopLevelItemBg { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 顶层菜单项选中时背景色
|
||||
/// </summary>
|
||||
public Color TopLevelItemSelectedBg { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 顶层菜单项鼠标放上去背景色
|
||||
/// </summary>
|
||||
public Color TopLevelItemHoverBg { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 顶层菜单项小号圆角
|
||||
/// </summary>
|
||||
public CornerRadius TopLevelItemBorderRadiusSM { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 顶层菜单项圆角
|
||||
/// </summary>
|
||||
public CornerRadius TopLevelItemBorderRadius { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 顶层菜单项大号圆角
|
||||
/// </summary>
|
||||
public CornerRadius TopLevelItemBorderRadiusLG { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 顶层菜单项小号内间距
|
||||
/// </summary>
|
||||
public Thickness TopLevelItemPaddingSM { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 顶层菜单项间距
|
||||
/// </summary>
|
||||
public Thickness TopLevelItemPadding { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 顶层菜单项大号内间距
|
||||
/// </summary>
|
||||
public Thickness TopLevelItemPaddingLG { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 顶层菜单项小号字体
|
||||
/// </summary>
|
||||
public double TopLevelItemFontSizeSM { get; set; } = double.NaN;
|
||||
|
||||
/// <summary>
|
||||
/// 顶层菜单项字体
|
||||
/// </summary>
|
||||
public double TopLevelItemFontSize { get; set; } = double.NaN;
|
||||
|
||||
/// <summary>
|
||||
/// 顶层菜单项大号字体
|
||||
/// </summary>
|
||||
public double TopLevelItemFontSizeLG { get; set; } = double.NaN;
|
||||
|
||||
/// <summary>
|
||||
/// 顶层菜单项内容字体行高
|
||||
/// </summary>
|
||||
public double TopLevelItemLineHeight { get; set; } = double.NaN;
|
||||
|
||||
/// <summary>
|
||||
/// 大号顶层菜单项内容字体行高
|
||||
/// </summary>
|
||||
public double TopLevelItemLineHeightLG { get; set; } = double.NaN;
|
||||
|
||||
/// <summary>
|
||||
/// 小号顶层菜单项内容字体行高
|
||||
/// </summary>
|
||||
public double TopLevelItemLineHeightSM { get; set; } = double.NaN;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 菜单阴影
|
||||
/// </summary>
|
||||
@ -133,8 +225,12 @@ internal class MenuToken : AbstractControlDesignToken
|
||||
var colorBgTextHover = _globalToken.ColorBgTextHover;
|
||||
var colorBgElevated = colorNeutralToken.ColorBgElevated;
|
||||
var padding = _globalToken.Padding;
|
||||
var controlHeight = _globalToken.SeedToken.ControlHeight;
|
||||
var controlHeightSM = base._globalToken.HeightToken.ControlHeightSM;
|
||||
var controlHeightLG = _globalToken.HeightToken.ControlHeightLG;
|
||||
|
||||
var fontSize = _globalToken.FontToken.FontSize;
|
||||
var controlHeightSM = _globalToken.HeightToken.ControlHeightSM;
|
||||
var fontSizeLG = _globalToken.FontToken.FontSizeLG;
|
||||
|
||||
MenuBorderRadius = _globalToken.StyleToken.BorderRadiusLG;
|
||||
MenuPanelWidth = _globalToken.SeedToken.LineWidth;
|
||||
@ -164,5 +260,39 @@ internal class MenuToken : AbstractControlDesignToken
|
||||
MenuMargin = new Thickness(1);
|
||||
|
||||
MenuBoxShadows = _globalToken.BoxShadowsSecondary;
|
||||
|
||||
TopLevelItemColor = colorNeutralToken.ColorText;
|
||||
TopLevelItemSelectedColor = colorNeutralToken.ColorTextSecondary;
|
||||
TopLevelItemHoverColor = colorNeutralToken.ColorTextSecondary;
|
||||
|
||||
TopLevelItemBg = colorBgContainer;
|
||||
TopLevelItemHoverBg = colorBgTextHover;
|
||||
TopLevelItemSelectedBg = colorBgTextHover;
|
||||
|
||||
TopLevelItemBorderRadiusSM = _globalToken.StyleToken.BorderRadiusSM;
|
||||
TopLevelItemBorderRadius = _globalToken.SeedToken.BorderRadius;
|
||||
TopLevelItemBorderRadiusLG = _globalToken.StyleToken.BorderRadiusLG;
|
||||
|
||||
TopLevelItemFontSize = !double.IsNaN(TopLevelItemFontSize) ? TopLevelItemFontSize : fontSize;
|
||||
TopLevelItemFontSizeSM = !double.IsNaN(TopLevelItemFontSizeSM) ? TopLevelItemFontSizeSM : fontSize;
|
||||
TopLevelItemFontSizeLG = !double.IsNaN(TopLevelItemFontSizeLG) ? TopLevelItemFontSizeLG : fontSizeLG;
|
||||
|
||||
TopLevelItemLineHeight = !double.IsNaN(TopLevelItemLineHeight)
|
||||
? TopLevelItemLineHeight
|
||||
: CalculatorUtils.CalculateLineHeight(TopLevelItemFontSize) * TopLevelItemFontSize;
|
||||
TopLevelItemLineHeightSM = !double.IsNaN(TopLevelItemLineHeightSM)
|
||||
? TopLevelItemLineHeightSM
|
||||
: CalculatorUtils.CalculateLineHeight(TopLevelItemFontSizeSM) * TopLevelItemFontSizeSM;
|
||||
TopLevelItemLineHeightLG = !double.IsNaN(TopLevelItemLineHeightLG)
|
||||
? TopLevelItemLineHeightLG
|
||||
: CalculatorUtils.CalculateLineHeight(TopLevelItemFontSizeLG) * TopLevelItemFontSizeLG;
|
||||
|
||||
TopLevelItemPaddingSM = new Thickness(_globalToken.PaddingContentHorizontalXS * 0.7,
|
||||
Math.Max((controlHeightSM - TopLevelItemLineHeightSM) / 2, 0));
|
||||
TopLevelItemPadding = new Thickness(_globalToken.PaddingContentHorizontalXS,
|
||||
Math.Max((controlHeight - TopLevelItemLineHeight) / 2, 0));
|
||||
TopLevelItemPaddingLG = new Thickness(_globalToken.PaddingContentHorizontalSM,
|
||||
Math.Max((controlHeightLG - TopLevelItemLineHeightLG) / 2, 0));
|
||||
|
||||
}
|
||||
}
|
@ -1,7 +1,13 @@
|
||||
using AtomUI.Styling;
|
||||
using AtomUI.Media;
|
||||
using AtomUI.Styling;
|
||||
using AtomUI.Utils;
|
||||
using Avalonia.Animation;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Presenters;
|
||||
using Avalonia.Controls.Templates;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Layout;
|
||||
using Avalonia.Styling;
|
||||
|
||||
namespace AtomUI.Controls;
|
||||
|
||||
@ -26,8 +32,20 @@ public class TopLevelMenuItemTheme : ControlTheme
|
||||
var panel = new Panel();
|
||||
var contentPresenter = new ContentPresenter()
|
||||
{
|
||||
Name = HeaderPresenterPart
|
||||
Name = HeaderPresenterPart,
|
||||
HorizontalAlignment = HorizontalAlignment.Stretch,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
RecognizesAccessKey = true
|
||||
};
|
||||
|
||||
CreateTemplateParentBinding(contentPresenter, ContentPresenter.ContentProperty, MenuItem.HeaderProperty);
|
||||
CreateTemplateParentBinding(contentPresenter, ContentPresenter.ContentTemplateProperty, MenuItem.HeaderTemplateProperty);
|
||||
CreateTemplateParentBinding(contentPresenter, ContentPresenter.CornerRadiusProperty, MenuItem.CornerRadiusProperty);
|
||||
CreateTemplateParentBinding(contentPresenter, ContentPresenter.PaddingProperty, MenuItem.PaddingProperty);
|
||||
CreateTemplateParentBinding(contentPresenter, ContentPresenter.MinHeightProperty, MenuItem.MinHeightProperty);
|
||||
CreateTemplateParentBinding(contentPresenter, ContentPresenter.FontSizeProperty, MenuItem.FontSizeProperty);
|
||||
CreateTemplateParentBinding(contentPresenter, ContentPresenter.BackgroundProperty, MenuItem.BackgroundProperty);
|
||||
CreateTemplateParentBinding(contentPresenter, ContentPresenter.ForegroundProperty, MenuItem.ForegroundProperty);
|
||||
contentPresenter.RegisterInNameScope(scope);
|
||||
panel.Children.Add(contentPresenter);
|
||||
return panel;
|
||||
@ -36,6 +54,67 @@ public class TopLevelMenuItemTheme : ControlTheme
|
||||
|
||||
protected override void BuildStyles()
|
||||
{
|
||||
BuildCommonStyle();
|
||||
BuildSizeTypeStyle();
|
||||
BuildDisabledStyle();
|
||||
}
|
||||
|
||||
private void BuildCommonStyle()
|
||||
{
|
||||
var commonStyle = new Style(selector => selector.Nesting().PropertyEquals(MenuItem.IsEnabledProperty, true));
|
||||
commonStyle.Add(MenuItem.BackgroundProperty, GlobalResourceKey.ColorTransparent);
|
||||
var hoverStyle = new Style(selector => selector.Nesting().Class(StdPseudoClass.PointerOver));
|
||||
hoverStyle.Add(MenuItem.BackgroundProperty, MenuResourceKey.TopLevelItemHoverBg);
|
||||
hoverStyle.Add(MenuItem.ForegroundProperty, MenuResourceKey.TopLevelItemHoverColor);
|
||||
hoverStyle.Add(MenuItem.CursorProperty, new Cursor(StandardCursorType.Hand));
|
||||
commonStyle.Add(hoverStyle);
|
||||
Add(commonStyle);
|
||||
}
|
||||
|
||||
private void BuildSizeTypeStyle()
|
||||
{
|
||||
var largeSizeStyle = new Style(selector => selector.Nesting().PropertyEquals(MenuItem.SizeTypeProperty, SizeType.Large));
|
||||
largeSizeStyle.Add(MenuItem.CornerRadiusProperty, MenuResourceKey.TopLevelItemBorderRadiusLG);
|
||||
largeSizeStyle.Add(MenuItem.MinHeightProperty, GlobalResourceKey.ControlHeightLG);
|
||||
largeSizeStyle.Add(MenuItem.PaddingProperty, MenuResourceKey.TopLevelItemPaddingLG);
|
||||
largeSizeStyle.Add(MenuItem.FontSizeProperty, MenuResourceKey.TopLevelItemFontSizeLG);
|
||||
{
|
||||
var presenterStyle = new Style(selector => selector.Nesting().Template().Name(HeaderPresenterPart));
|
||||
|
||||
presenterStyle.Add(ContentPresenter.LineHeightProperty, MenuResourceKey.TopLevelItemLineHeightLG);
|
||||
largeSizeStyle.Add(presenterStyle);
|
||||
}
|
||||
Add(largeSizeStyle);
|
||||
|
||||
var middleSizeStyle = new Style(selector => selector.Nesting().PropertyEquals(MenuItem.SizeTypeProperty, SizeType.Middle));
|
||||
middleSizeStyle.Add(MenuItem.CornerRadiusProperty, MenuResourceKey.TopLevelItemBorderRadius);
|
||||
middleSizeStyle.Add(MenuItem.MinHeightProperty, GlobalResourceKey.ControlHeight);
|
||||
middleSizeStyle.Add(MenuItem.PaddingProperty, MenuResourceKey.TopLevelItemPadding);
|
||||
middleSizeStyle.Add(MenuItem.FontSizeProperty, MenuResourceKey.TopLevelItemFontSize);
|
||||
{
|
||||
var presenterStyle = new Style(selector => selector.Nesting().Template().Name(HeaderPresenterPart));
|
||||
presenterStyle.Add(ContentPresenter.LineHeightProperty, MenuResourceKey.TopLevelItemLineHeight);
|
||||
middleSizeStyle.Add(presenterStyle);
|
||||
}
|
||||
Add(middleSizeStyle);
|
||||
|
||||
var smallSizeStyle = new Style(selector => selector.Nesting().PropertyEquals(MenuItem.SizeTypeProperty, SizeType.Small));
|
||||
smallSizeStyle.Add(MenuItem.CornerRadiusProperty, MenuResourceKey.TopLevelItemBorderRadiusSM);
|
||||
smallSizeStyle.Add(MenuItem.MinHeightProperty, GlobalResourceKey.ControlHeightSM);
|
||||
smallSizeStyle.Add(MenuItem.PaddingProperty, MenuResourceKey.TopLevelItemPaddingSM);
|
||||
smallSizeStyle.Add(MenuItem.FontSizeProperty, MenuResourceKey.TopLevelItemFontSizeSM);
|
||||
{
|
||||
var presenterStyle = new Style(selector => selector.Nesting().Template().Name(HeaderPresenterPart));
|
||||
presenterStyle.Add(ContentPresenter.LineHeightProperty, MenuResourceKey.TopLevelItemLineHeightSM);
|
||||
smallSizeStyle.Add(presenterStyle);
|
||||
}
|
||||
Add(smallSizeStyle);
|
||||
}
|
||||
|
||||
private void BuildDisabledStyle()
|
||||
{
|
||||
var disabledStyle = new Style(selector => selector.Nesting().Class(StdPseudoClass.Disabled));
|
||||
disabledStyle.Add(MenuItem.ForegroundProperty, MenuResourceKey.ItemDisabledColor);
|
||||
Add(disabledStyle);
|
||||
}
|
||||
}
|
@ -429,7 +429,6 @@ public partial class Segmented : TemplatedControl, IControlCustomStyle
|
||||
void IControlCustomStyle.HandleTemplateApplied(INameScope scope)
|
||||
{
|
||||
_mainContainer = scope.Find<Canvas>(SegmentedTheme.MainContainerPart);
|
||||
NotifyCurrentChanged();
|
||||
ClipToBounds = true;
|
||||
Items.CollectionChanged += HandleItemsChanged;
|
||||
|
||||
@ -440,7 +439,7 @@ public partial class Segmented : TemplatedControl, IControlCustomStyle
|
||||
HorizontalAlignment = HorizontalAlignment.Stretch
|
||||
});
|
||||
}
|
||||
|
||||
NotifyCurrentChanged();
|
||||
}
|
||||
|
||||
private bool IsValidIndex(int index)
|
||||
|
@ -160,6 +160,7 @@ internal partial class SegmentedItemBox : TemplatedControl,
|
||||
Cursor = new Cursor(StandardCursorType.Hand);
|
||||
_customStyle.CollectStyleState();
|
||||
_customStyle.SetupTransitions();
|
||||
_customStyle.UpdatePseudoClasses();
|
||||
}
|
||||
|
||||
private void SetCurrentItem(bool flag)
|
||||
|
@ -48,6 +48,7 @@ namespace AtomUI.Styling
|
||||
public static readonly TokenResourceKey PaddingContentHorizontalLG = new TokenResourceKey("PaddingContentHorizontalLG");
|
||||
public static readonly TokenResourceKey PaddingContentHorizontal = new TokenResourceKey("PaddingContentHorizontal");
|
||||
public static readonly TokenResourceKey PaddingContentHorizontalSM = new TokenResourceKey("PaddingContentHorizontalSM");
|
||||
public static readonly TokenResourceKey PaddingContentHorizontalXS = new TokenResourceKey("PaddingContentHorizontalXS");
|
||||
public static readonly TokenResourceKey PaddingContentVerticalLG = new TokenResourceKey("PaddingContentVerticalLG");
|
||||
public static readonly TokenResourceKey PaddingContentVertical = new TokenResourceKey("PaddingContentVertical");
|
||||
public static readonly TokenResourceKey PaddingContentVerticalSM = new TokenResourceKey("PaddingContentVerticalSM");
|
||||
|
@ -264,6 +264,12 @@ public class AliasDesignToken : MapDesignToken
|
||||
/// 控制内容元素水平内间距,适用于小屏幕设备。
|
||||
/// </summary>
|
||||
public double PaddingContentHorizontalSM { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 内容水平内间距(XS)
|
||||
/// 控制内容元素水平内间距,适用于小屏幕设备。
|
||||
/// </summary>
|
||||
public double PaddingContentHorizontalXS { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 内容垂直内间距(LG)
|
||||
|
@ -104,7 +104,8 @@ public static class AliasDesignTokenExtensions
|
||||
aliasToken.PaddingContentVerticalLG = sizeToken.SizeMS;
|
||||
aliasToken.PaddingContentHorizontal = sizeToken.SizeMS;
|
||||
aliasToken.PaddingContentVertical = sizeToken.SizeSM;
|
||||
aliasToken.PaddingContentHorizontalSM = sizeToken.Size;
|
||||
aliasToken.PaddingContentHorizontalSM = sizeToken.SizeSM;
|
||||
aliasToken.PaddingContentHorizontalXS = sizeToken.SizeXS;
|
||||
aliasToken.PaddingContentVerticalSM = sizeToken.SizeXS;
|
||||
|
||||
aliasToken.MarginXXS = sizeToken.SizeXXS;
|
||||
|
Loading…
Reference in New Issue
Block a user