From d0fc79ed82b80983673981fdbf52eed437999e8f Mon Sep 17 00:00:00 2001 From: polarboy Date: Sat, 3 Aug 2024 10:31:17 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=20TabStrip=20=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为了重构方便,把 TabStrip 放入自己的专属文件夹 --- ...tripMenuItem.cs => OverflowTabMenuItem.cs} | 9 ++++----- ...emTheme.cs => OverflowTabMenuItemTheme.cs} | 20 +++++++++---------- .../TabControl/TabScrollViewer.cs | 6 +++--- .../TabControl/{ => TabStrip}/BaseTabStrip.cs | 0 .../{ => TabStrip}/BaseTabStripItemTheme.cs | 0 .../{ => TabStrip}/BaseTabStripTheme.cs | 0 .../TabControl/{ => TabStrip}/CardTabStrip.cs | 0 .../{ => TabStrip}/CardTabStripItemTheme.cs | 0 .../{ => TabStrip}/CardTabStripTheme.cs | 0 .../TabControl/{ => TabStrip}/TabStrip.cs | 0 .../TabControl/{ => TabStrip}/TabStripItem.cs | 0 .../{ => TabStrip}/TabStripItemTheme.cs | 0 .../TabStripScrollContentPresenter.cs | 0 .../{ => TabStrip}/TabStripTheme.cs | 0 14 files changed, 17 insertions(+), 18 deletions(-) rename src/AtomUI.Controls/TabControl/{TabStripMenuItem.cs => OverflowTabMenuItem.cs} (84%) rename src/AtomUI.Controls/TabControl/{TabStripMenuItemTheme.cs => OverflowTabMenuItemTheme.cs} (87%) rename src/AtomUI.Controls/TabControl/{ => TabStrip}/BaseTabStrip.cs (100%) rename src/AtomUI.Controls/TabControl/{ => TabStrip}/BaseTabStripItemTheme.cs (100%) rename src/AtomUI.Controls/TabControl/{ => TabStrip}/BaseTabStripTheme.cs (100%) rename src/AtomUI.Controls/TabControl/{ => TabStrip}/CardTabStrip.cs (100%) rename src/AtomUI.Controls/TabControl/{ => TabStrip}/CardTabStripItemTheme.cs (100%) rename src/AtomUI.Controls/TabControl/{ => TabStrip}/CardTabStripTheme.cs (100%) rename src/AtomUI.Controls/TabControl/{ => TabStrip}/TabStrip.cs (100%) rename src/AtomUI.Controls/TabControl/{ => TabStrip}/TabStripItem.cs (100%) rename src/AtomUI.Controls/TabControl/{ => TabStrip}/TabStripItemTheme.cs (100%) rename src/AtomUI.Controls/TabControl/{ => TabStrip}/TabStripScrollContentPresenter.cs (100%) rename src/AtomUI.Controls/TabControl/{ => TabStrip}/TabStripTheme.cs (100%) diff --git a/src/AtomUI.Controls/TabControl/TabStripMenuItem.cs b/src/AtomUI.Controls/TabControl/OverflowTabMenuItem.cs similarity index 84% rename from src/AtomUI.Controls/TabControl/TabStripMenuItem.cs rename to src/AtomUI.Controls/TabControl/OverflowTabMenuItem.cs index d395ff5..0754eed 100644 --- a/src/AtomUI.Controls/TabControl/TabStripMenuItem.cs +++ b/src/AtomUI.Controls/TabControl/OverflowTabMenuItem.cs @@ -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 IsClosableProperty = - AvaloniaProperty.RegisterDirect(nameof(IsClosable), + public static readonly DirectProperty IsClosableProperty = + AvaloniaProperty.RegisterDirect(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(TabStripMenuItemTheme.ItemCloseButtonPart); + _iconButton = e.NameScope.Find(OverflowTabMenuItemTheme.ItemCloseButtonPart); if (_iconButton is not null) { _iconButton.Click += (sender, args) => { diff --git a/src/AtomUI.Controls/TabControl/TabStripMenuItemTheme.cs b/src/AtomUI.Controls/TabControl/OverflowTabMenuItemTheme.cs similarity index 87% rename from src/AtomUI.Controls/TabControl/TabStripMenuItemTheme.cs rename to src/AtomUI.Controls/TabControl/OverflowTabMenuItemTheme.cs index 3b3b7bf..e49bedc 100644 --- a/src/AtomUI.Controls/TabControl/TabStripMenuItemTheme.cs +++ b/src/AtomUI.Controls/TabControl/OverflowTabMenuItemTheme.cs @@ -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((item, scope) => + return new FuncControlTemplate((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); } diff --git a/src/AtomUI.Controls/TabControl/TabScrollViewer.cs b/src/AtomUI.Controls/TabControl/TabScrollViewer.cs index 0921586..a431b45 100644 --- a/src/AtomUI.Controls/TabControl/TabScrollViewer.cs +++ b/src/AtomUI.Controls/TabControl/TabScrollViewer.cs @@ -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) { diff --git a/src/AtomUI.Controls/TabControl/BaseTabStrip.cs b/src/AtomUI.Controls/TabControl/TabStrip/BaseTabStrip.cs similarity index 100% rename from src/AtomUI.Controls/TabControl/BaseTabStrip.cs rename to src/AtomUI.Controls/TabControl/TabStrip/BaseTabStrip.cs diff --git a/src/AtomUI.Controls/TabControl/BaseTabStripItemTheme.cs b/src/AtomUI.Controls/TabControl/TabStrip/BaseTabStripItemTheme.cs similarity index 100% rename from src/AtomUI.Controls/TabControl/BaseTabStripItemTheme.cs rename to src/AtomUI.Controls/TabControl/TabStrip/BaseTabStripItemTheme.cs diff --git a/src/AtomUI.Controls/TabControl/BaseTabStripTheme.cs b/src/AtomUI.Controls/TabControl/TabStrip/BaseTabStripTheme.cs similarity index 100% rename from src/AtomUI.Controls/TabControl/BaseTabStripTheme.cs rename to src/AtomUI.Controls/TabControl/TabStrip/BaseTabStripTheme.cs diff --git a/src/AtomUI.Controls/TabControl/CardTabStrip.cs b/src/AtomUI.Controls/TabControl/TabStrip/CardTabStrip.cs similarity index 100% rename from src/AtomUI.Controls/TabControl/CardTabStrip.cs rename to src/AtomUI.Controls/TabControl/TabStrip/CardTabStrip.cs diff --git a/src/AtomUI.Controls/TabControl/CardTabStripItemTheme.cs b/src/AtomUI.Controls/TabControl/TabStrip/CardTabStripItemTheme.cs similarity index 100% rename from src/AtomUI.Controls/TabControl/CardTabStripItemTheme.cs rename to src/AtomUI.Controls/TabControl/TabStrip/CardTabStripItemTheme.cs diff --git a/src/AtomUI.Controls/TabControl/CardTabStripTheme.cs b/src/AtomUI.Controls/TabControl/TabStrip/CardTabStripTheme.cs similarity index 100% rename from src/AtomUI.Controls/TabControl/CardTabStripTheme.cs rename to src/AtomUI.Controls/TabControl/TabStrip/CardTabStripTheme.cs diff --git a/src/AtomUI.Controls/TabControl/TabStrip.cs b/src/AtomUI.Controls/TabControl/TabStrip/TabStrip.cs similarity index 100% rename from src/AtomUI.Controls/TabControl/TabStrip.cs rename to src/AtomUI.Controls/TabControl/TabStrip/TabStrip.cs diff --git a/src/AtomUI.Controls/TabControl/TabStripItem.cs b/src/AtomUI.Controls/TabControl/TabStrip/TabStripItem.cs similarity index 100% rename from src/AtomUI.Controls/TabControl/TabStripItem.cs rename to src/AtomUI.Controls/TabControl/TabStrip/TabStripItem.cs diff --git a/src/AtomUI.Controls/TabControl/TabStripItemTheme.cs b/src/AtomUI.Controls/TabControl/TabStrip/TabStripItemTheme.cs similarity index 100% rename from src/AtomUI.Controls/TabControl/TabStripItemTheme.cs rename to src/AtomUI.Controls/TabControl/TabStrip/TabStripItemTheme.cs diff --git a/src/AtomUI.Controls/TabControl/TabStripScrollContentPresenter.cs b/src/AtomUI.Controls/TabControl/TabStrip/TabStripScrollContentPresenter.cs similarity index 100% rename from src/AtomUI.Controls/TabControl/TabStripScrollContentPresenter.cs rename to src/AtomUI.Controls/TabControl/TabStrip/TabStripScrollContentPresenter.cs diff --git a/src/AtomUI.Controls/TabControl/TabStripTheme.cs b/src/AtomUI.Controls/TabControl/TabStrip/TabStripTheme.cs similarity index 100% rename from src/AtomUI.Controls/TabControl/TabStripTheme.cs rename to src/AtomUI.Controls/TabControl/TabStrip/TabStripTheme.cs