重构 TabStrip 文件结构

为了重构方便,把 TabStrip 放入自己的专属文件夹
This commit is contained in:
polarboy 2024-08-03 10:31:17 +08:00
parent f962cc3bb2
commit d0fc79ed82
14 changed files with 17 additions and 18 deletions

View File

@ -2,17 +2,16 @@
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using Avalonia.Threading;
namespace AtomUI.Controls;
internal class TabStripMenuItem : MenuItem
internal class OverflowTabMenuItem : MenuItem
{
#region
public static readonly DirectProperty<TabStripMenuItem, bool> IsClosableProperty =
AvaloniaProperty.RegisterDirect<TabStripMenuItem, bool>(nameof(IsClosable),
public static readonly DirectProperty<OverflowTabMenuItem, bool> IsClosableProperty =
AvaloniaProperty.RegisterDirect<OverflowTabMenuItem, bool>(nameof(IsClosable),
o => o.IsClosable,
(o, v) => o.IsClosable = v);
@ -41,7 +40,7 @@ internal class TabStripMenuItem : MenuItem
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
_iconButton = e.NameScope.Find<IconButton>(TabStripMenuItemTheme.ItemCloseButtonPart);
_iconButton = e.NameScope.Find<IconButton>(OverflowTabMenuItemTheme.ItemCloseButtonPart);
if (_iconButton is not null) {
_iconButton.Click += (sender, args) =>
{

View File

@ -13,21 +13,21 @@ using Avalonia.Styling;
namespace AtomUI.Controls;
[ControlThemeProvider]
internal class TabStripMenuItemTheme : BaseControlTheme
internal class OverflowTabMenuItemTheme : BaseControlTheme
{
public const string ItemDecoratorPart = "Part_ItemDecorator";
public const string MainContainerPart = "Part_MainContainer";
public const string ItemTextPresenterPart = "Part_ItemTextPresenter";
public const string ItemCloseButtonPart = "Part_ItemCloseIcon";
public TabStripMenuItemTheme()
: base(typeof(TabStripMenuItem))
public OverflowTabMenuItemTheme()
: base(typeof(OverflowTabMenuItem))
{
}
protected override IControlTemplate BuildControlTemplate()
{
return new FuncControlTemplate<TabStripMenuItem>((item, scope) =>
return new FuncControlTemplate<OverflowTabMenuItem>((item, scope) =>
{
var container = new Border()
{
@ -61,8 +61,8 @@ internal class TabStripMenuItemTheme : BaseControlTheme
Grid.SetColumn(itemTextPresenter, 0);
TokenResourceBinder.CreateTokenBinding(itemTextPresenter, ContentPresenter.MarginProperty, MenuResourceKey.ItemMargin);
CreateTemplateParentBinding(itemTextPresenter, ContentPresenter.ContentProperty, TabStripMenuItem.HeaderProperty);
CreateTemplateParentBinding(itemTextPresenter, ContentPresenter.ContentTemplateProperty, TabStripMenuItem.HeaderTemplateProperty);
CreateTemplateParentBinding(itemTextPresenter, ContentPresenter.ContentProperty, OverflowTabMenuItem.HeaderProperty);
CreateTemplateParentBinding(itemTextPresenter, ContentPresenter.ContentTemplateProperty, OverflowTabMenuItem.HeaderTemplateProperty);
itemTextPresenter.RegisterInNameScope(scope);
@ -82,7 +82,7 @@ internal class TabStripMenuItemTheme : BaseControlTheme
};
CreateTemplateParentBinding(closeButton, IconButton.IsVisibleProperty, TabStripMenuItem.IsClosableProperty);
CreateTemplateParentBinding(closeButton, IconButton.IsVisibleProperty, OverflowTabMenuItem.IsClosableProperty);
TokenResourceBinder.CreateGlobalTokenBinding(menuCloseIcon, PathIcon.NormalFilledBrushProperty, GlobalResourceKey.ColorIcon);
TokenResourceBinder.CreateGlobalTokenBinding(menuCloseIcon, PathIcon.ActiveFilledBrushProperty, GlobalResourceKey.ColorIconHover);
@ -110,7 +110,7 @@ internal class TabStripMenuItemTheme : BaseControlTheme
private void BuildCommonStyle(Style commonStyle)
{
commonStyle.Add(TabStripMenuItem.ForegroundProperty, MenuResourceKey.ItemColor);
commonStyle.Add(OverflowTabMenuItem.ForegroundProperty, MenuResourceKey.ItemColor);
{
var borderStyle = new Style(selector => selector.Nesting().Template().Name(ItemDecoratorPart));
borderStyle.Add(Border.MinHeightProperty, MenuResourceKey.ItemHeight);
@ -122,7 +122,7 @@ internal class TabStripMenuItemTheme : BaseControlTheme
// Hover 状态
var hoverStyle = new Style(selector => selector.Nesting().Class(StdPseudoClass.PointerOver));
hoverStyle.Add(TabStripMenuItem.ForegroundProperty, MenuResourceKey.ItemHoverColor);
hoverStyle.Add(OverflowTabMenuItem.ForegroundProperty, MenuResourceKey.ItemHoverColor);
{
var borderStyle = new Style(selector => selector.Nesting().Template().Name(ItemDecoratorPart));
borderStyle.Add(Border.BackgroundProperty, MenuResourceKey.ItemHoverBg);
@ -134,7 +134,7 @@ internal class TabStripMenuItemTheme : BaseControlTheme
private void BuildDisabledStyle()
{
var disabledStyle = new Style(selector => selector.Nesting().Class(StdPseudoClass.Disabled));
disabledStyle.Add(TabStripMenuItem.ForegroundProperty, MenuResourceKey.ItemDisabledColor);
disabledStyle.Add(OverflowTabMenuItem.ForegroundProperty, MenuResourceKey.ItemDisabledColor);
Add(disabledStyle);
}

View File

@ -210,7 +210,7 @@ public class TabScrollViewer : ScrollViewer
var right = Math.Floor(itemBounds.Right - Offset.X);
if (TabStripPlacement == Dock.Top || TabStripPlacement == Dock.Bottom) {
if (left < 0 || right > Viewport.Width) {
var menuItem = new TabStripMenuItem()
var menuItem = new OverflowTabMenuItem()
{
Header = tabStripItem.Content,
TabStripItem = tabStripItem,
@ -235,7 +235,7 @@ public class TabScrollViewer : ScrollViewer
if (TabStrip is not null) {
Dispatcher.UIThread.Post(sender =>
{
if (sender is TabStripMenuItem tabStripMenuItem) {
if (sender is OverflowTabMenuItem tabStripMenuItem) {
var tabStripItem = tabStripMenuItem.TabStripItem;
if (tabStripItem is not null) {
tabStripItem.BringIntoView();
@ -248,7 +248,7 @@ public class TabScrollViewer : ScrollViewer
private void HandleCloseTabRequest(object? sender, RoutedEventArgs args)
{
if (sender is TabStripMenuItem tabStripMenuItem) {
if (sender is OverflowTabMenuItem tabStripMenuItem) {
if (TabStrip is not null) {
if (TabStrip.SelectedItem is TabStripItem selectedItem) {
if (selectedItem == tabStripMenuItem.TabStripItem) {