增加 TreeViewToken

This commit is contained in:
polarboy 2024-08-11 15:36:16 +08:00
parent f01fb5a68c
commit 370a0580fc
7 changed files with 94 additions and 7 deletions

View File

@ -166,9 +166,7 @@ public class Expander : AvaloniaExpander
} }
#endregion #endregion
private bool _animating = false;
private bool _enableAnimation = true;
private AnimationTargetPanel? _animationTarget; private AnimationTargetPanel? _animationTarget;
private Border? _headerDecorator; private Border? _headerDecorator;
private IconButton? _expandButton; private IconButton? _expandButton;
@ -182,13 +180,10 @@ public class Expander : AvaloniaExpander
TokenResourceBinder.CreateTokenBinding(this, MotionDurationProperty, GlobalResourceKey.MotionDurationSlow); TokenResourceBinder.CreateTokenBinding(this, MotionDurationProperty, GlobalResourceKey.MotionDurationSlow);
TokenResourceBinder.CreateGlobalResourceBinding(this, BorderThicknessProperty, GlobalResourceKey.BorderThickness, TokenResourceBinder.CreateGlobalResourceBinding(this, BorderThicknessProperty, GlobalResourceKey.BorderThickness,
BindingPriority.Template, new RenderScaleAwareThicknessConfigure(this)); BindingPriority.Template, new RenderScaleAwareThicknessConfigure(this));
// SetupHeaderLayout();
SetupEffectiveBorderThickness(); SetupEffectiveBorderThickness();
SetupExpanderBorderThickness(); SetupExpanderBorderThickness();
SetupIconButton(); SetupIconButton();
_enableAnimation = false;
HandleExpandedChanged(); HandleExpandedChanged();
_enableAnimation = true;
if (_expandButton is not null) { if (_expandButton is not null) {
_expandButton.Click += (sender, args) => _expandButton.Click += (sender, args) =>
{ {
@ -266,7 +261,7 @@ public class Expander : AvaloniaExpander
var position = e.GetPosition(_headerDecorator); var position = e.GetPosition(_headerDecorator);
if (_headerDecorator is not null) { if (_headerDecorator is not null) {
var targetRect = new Rect(_headerDecorator.Bounds.Size); var targetRect = new Rect(_headerDecorator.Bounds.Size);
if (targetRect.Contains(position) && !_animating) { if (targetRect.Contains(position)) {
IsExpanded = !IsExpanded; IsExpanded = !IsExpanded;
} }
} }

View File

@ -408,6 +408,15 @@ namespace AtomUI.Theme.Styling
public static readonly TokenResourceKey ToolTipArrowSize = new TokenResourceKey("ToolTip.ToolTipArrowSize"); public static readonly TokenResourceKey ToolTipArrowSize = new TokenResourceKey("ToolTip.ToolTipArrowSize");
} }
public static class TreeViewResourceKey
{
public static readonly TokenResourceKey TitleHeight = new TokenResourceKey("TreeView.TitleHeight");
public static readonly TokenResourceKey NodeHoverBg = new TokenResourceKey("TreeView.NodeHoverBg");
public static readonly TokenResourceKey NodeSelectedBg = new TokenResourceKey("TreeView.NodeSelectedBg");
public static readonly TokenResourceKey DirectoryNodeSelectedColor = new TokenResourceKey("TreeView.DirectoryNodeSelectedColor");
public static readonly TokenResourceKey DirectoryNodeSelectedBg = new TokenResourceKey("TreeView.DirectoryNodeSelectedBg");
}
public static class CaptionButtonResourceKey public static class CaptionButtonResourceKey
{ {
public static readonly TokenResourceKey HoverBackgroundColor = new TokenResourceKey("CaptionButton.HoverBackgroundColor"); public static readonly TokenResourceKey HoverBackgroundColor = new TokenResourceKey("CaptionButton.HoverBackgroundColor");

View File

@ -0,0 +1,8 @@
namespace AtomUI.Controls;
using AvaloniaTreeView = Avalonia.Controls.TreeView;
public class TreeView : AvaloniaTreeView
{
}

View File

@ -0,0 +1,8 @@
namespace AtomUI.Controls;
using AvaloniaTreeItem = Avalonia.Controls.TreeViewItem;
public class TreeViewItem : AvaloniaTreeItem
{
}

View File

@ -0,0 +1,6 @@
namespace AtomUI.Controls;
public class TreeViewItemTheme
{
}

View File

@ -0,0 +1,6 @@
namespace AtomUI.Controls;
public class TreeViewTheme
{
}

View File

@ -0,0 +1,55 @@
using AtomUI.Theme.TokenSystem;
using Avalonia.Media;
namespace AtomUI.Controls;
[ControlDesignToken]
internal class TreeViewToken : AbstractControlDesignToken
{
public const string ID = "TreeView";
public TreeViewToken()
: base(ID)
{
}
/// <summary>
/// 节点标题高度
/// </summary>
public double TitleHeight { get; set; }
/// <summary>
/// 节点悬浮态背景色
/// </summary>
public Color NodeHoverBg { get; set; }
/// <summary>
/// 节点选中态背景色
/// </summary>
public Color NodeSelectedBg { get; set; }
#region Token
/// <summary>
/// 目录树节点选中文字颜色
/// </summary>
public Color DirectoryNodeSelectedColor { get; set; }
/// <summary>
/// 目录树节点选中背景色
/// </summary>
public Color DirectoryNodeSelectedBg { get; set; }
#endregion
internal override void CalculateFromAlias()
{
base.CalculateFromAlias();
TitleHeight = _globalToken.HeightToken.ControlHeightSM;
NodeHoverBg = _globalToken.ControlItemBgHover;
NodeSelectedBg = _globalToken.ControlItemBgActive;
DirectoryNodeSelectedColor = _globalToken.ColorTextLightSolid;
DirectoryNodeSelectedBg = _globalToken.ColorToken.ColorPrimaryToken.ColorPrimary;
}
}