diff --git a/src/AtomUI.Controls/AtomUIOSSControlThemesProvider.axaml b/src/AtomUI.Controls/AtomUIOSSControlThemesProvider.axaml index 1c0bf9dcd..dc7986a01 100644 --- a/src/AtomUI.Controls/AtomUIOSSControlThemesProvider.axaml +++ b/src/AtomUI.Controls/AtomUIOSSControlThemesProvider.axaml @@ -19,6 +19,7 @@ + diff --git a/src/AtomUI.Controls/GeneratedFiles/AtomUI.Generator/AtomUI.Generator.ControlThemePoolGenerator/ControlThemePool.g.cs b/src/AtomUI.Controls/GeneratedFiles/AtomUI.Generator/AtomUI.Generator.ControlThemePoolGenerator/ControlThemePool.g.cs index 9e8dece51..85df6f318 100644 --- a/src/AtomUI.Controls/GeneratedFiles/AtomUI.Generator/AtomUI.Generator.ControlThemePoolGenerator/ControlThemePool.g.cs +++ b/src/AtomUI.Controls/GeneratedFiles/AtomUI.Generator/AtomUI.Generator.ControlThemePoolGenerator/ControlThemePool.g.cs @@ -20,8 +20,6 @@ namespace AtomUI.Theme themes.Add(new AtomUI.Controls.HorizontalNavMenuTheme()); themes.Add(new AtomUI.Controls.HyperLinkTextBlockTheme()); themes.Add(new AtomUI.Controls.InlineNavMenuItemTheme()); - themes.Add(new AtomUI.Controls.ListBoxItemTheme()); - themes.Add(new AtomUI.Controls.ListBoxTheme()); themes.Add(new AtomUI.Controls.LoadingIndicatorAdornerTheme()); themes.Add(new AtomUI.Controls.LoadingIndicatorTheme()); themes.Add(new AtomUI.Controls.MenuFlyoutPresenterTheme()); diff --git a/src/AtomUI.Controls/ListBox/ListBoxItemTheme.cs b/src/AtomUI.Controls/ListBox/ListBoxItemTheme.cs deleted file mode 100644 index 4c3c2d886..000000000 --- a/src/AtomUI.Controls/ListBox/ListBoxItemTheme.cs +++ /dev/null @@ -1,134 +0,0 @@ -using AtomUI.Theme; -using AtomUI.Theme.Styling; -using Avalonia.Controls; -using Avalonia.Controls.Presenters; -using Avalonia.Controls.Primitives; -using Avalonia.Controls.Templates; -using Avalonia.Data; -using Avalonia.Data.Converters; -using Avalonia.Layout; -using Avalonia.Styling; - -namespace AtomUI.Controls; - -[ControlThemeProvider] -internal class ListBoxItemTheme : BaseControlTheme -{ - public const string ContentPresenterPart = "PART_ContentPresenter"; - - public ListBoxItemTheme() : this(typeof(ListBoxItem)) - { - } - - protected ListBoxItemTheme(Type targetType) : base(targetType) - { - } - - protected override IControlTemplate BuildControlTemplate() - { - return new FuncControlTemplate((listBoxItem, scope) => - { - var contentPresenter = new ContentPresenter - { - Name = ContentPresenterPart - }; - - CreateTemplateParentBinding(contentPresenter, ContentPresenter.ForegroundProperty, - TemplatedControl.ForegroundProperty); - CreateTemplateParentBinding(contentPresenter, ContentPresenter.BackgroundProperty, - TemplatedControl.BackgroundProperty); - CreateTemplateParentBinding(contentPresenter, ContentPresenter.CornerRadiusProperty, - TemplatedControl.CornerRadiusProperty); - CreateTemplateParentBinding(contentPresenter, ContentPresenter.ContentProperty, - ContentControl.ContentProperty, - BindingMode.Default, - new FuncValueConverter( - o => - { - if (o is string str) - { - return new TextBlock() - { - Text = str, - VerticalAlignment = VerticalAlignment.Center - }; - } - - return o; - })); - CreateTemplateParentBinding(contentPresenter, ContentPresenter.ContentTemplateProperty, - ContentControl.ContentTemplateProperty); - CreateTemplateParentBinding(contentPresenter, Layoutable.MinHeightProperty, Layoutable.MinHeightProperty); - CreateTemplateParentBinding(contentPresenter, ContentPresenter.PaddingProperty, - TemplatedControl.PaddingProperty); - CreateTemplateParentBinding(contentPresenter, ContentPresenter.HorizontalContentAlignmentProperty, - ContentControl.HorizontalContentAlignmentProperty); - CreateTemplateParentBinding(contentPresenter, ContentPresenter.VerticalContentAlignmentProperty, - ContentControl.VerticalContentAlignmentProperty); - return contentPresenter; - }); - } - - protected override void BuildStyles() - { - BuildCommonStyle(); - BuildSizeTypeStyle(); - BuildDisabledStyle(); - } - - private void BuildCommonStyle() - { - var commonStyle = new Style(selector => selector.Nesting()); - commonStyle.Add(ListBoxItem.MarginProperty, ListBoxTokenKey.ItemMargin); - commonStyle.Add(ListBoxItem.ForegroundProperty, ListBoxTokenKey.ItemColor); - commonStyle.Add(ListBoxItem.BackgroundProperty, ListBoxTokenKey.ItemBgColor); - - var disabledItemHoverStyle = new Style(selector => - selector.Nesting().PropertyEquals(ListBoxItem.DisabledItemHoverEffectProperty, false).Class(StdPseudoClass.PointerOver)); - disabledItemHoverStyle.Add(ListBoxItem.ForegroundProperty, ListBoxTokenKey.ItemHoverColor); - disabledItemHoverStyle.Add(ListBoxItem.BackgroundProperty, ListBoxTokenKey.ItemHoverBgColor); - - commonStyle.Add(disabledItemHoverStyle); - - var selectedStyle = new Style(selector => selector.Nesting().Class(StdPseudoClass.Selected)); - selectedStyle.Add(ListBoxItem.ForegroundProperty, ListBoxTokenKey.ItemSelectedColor); - selectedStyle.Add(ListBoxItem.BackgroundProperty, ListBoxTokenKey.ItemSelectedBgColor); - commonStyle.Add(selectedStyle); - Add(commonStyle); - } - - private void BuildSizeTypeStyle() - { - var largeStyle = new Style(selector => - selector.Nesting().PropertyEquals(ListBoxItem.SizeTypeProperty, SizeType.Large)); - largeStyle.Add(TemplatedControl.CornerRadiusProperty, SharedTokenKey.BorderRadius); - largeStyle.Add(Layoutable.MinHeightProperty, SharedTokenKey.ControlHeightLG); - largeStyle.Add(TemplatedControl.PaddingProperty, ListBoxTokenKey.ItemPaddingLG); - - Add(largeStyle); - - var middleStyle = new Style(selector => - selector.Nesting().PropertyEquals(ListBoxItem.SizeTypeProperty, SizeType.Middle)); - middleStyle.Add(TemplatedControl.CornerRadiusProperty, SharedTokenKey.BorderRadiusSM); - middleStyle.Add(Layoutable.MinHeightProperty, SharedTokenKey.ControlHeight); - middleStyle.Add(TemplatedControl.PaddingProperty, ListBoxTokenKey.ItemPadding); - - Add(middleStyle); - - var smallStyle = new Style(selector => - selector.Nesting().PropertyEquals(ListBoxItem.SizeTypeProperty, SizeType.Small)); - smallStyle.Add(TemplatedControl.CornerRadiusProperty, SharedTokenKey.BorderRadiusXS); - smallStyle.Add(Layoutable.MinHeightProperty, SharedTokenKey.ControlHeightSM); - smallStyle.Add(TemplatedControl.PaddingProperty, ListBoxTokenKey.ItemPaddingSM); - Add(smallStyle); - } - - private void BuildDisabledStyle() - { - var disabledStyle = new Style(selector => selector.Nesting().Class(StdPseudoClass.Disabled)); - var contentPresenterStyle = new Style(selector => selector.Nesting().Template().Name(ContentPresenterPart)); - contentPresenterStyle.Add(ContentPresenter.ForegroundProperty, SharedTokenKey.ColorTextDisabled); - disabledStyle.Add(contentPresenterStyle); - Add(disabledStyle); - } -} \ No newline at end of file diff --git a/src/AtomUI.Controls/ListBox/ListBoxTheme.cs b/src/AtomUI.Controls/ListBox/ListBoxTheme.cs deleted file mode 100644 index 34ad45cb7..000000000 --- a/src/AtomUI.Controls/ListBox/ListBoxTheme.cs +++ /dev/null @@ -1,121 +0,0 @@ -using AtomUI.Theme; -using AtomUI.Theme.Styling; -using Avalonia.Controls; -using Avalonia.Controls.Presenters; -using Avalonia.Controls.Primitives; -using Avalonia.Controls.Templates; -using Avalonia.Styling; - -namespace AtomUI.Controls; - -[ControlThemeProvider] -internal class ListBoxTheme : BaseControlTheme -{ - public const string FramePart = "PART_Frame"; - public const string ScrollViewerPart = "PART_ScrollViewer"; - public const string ItemsPresenterPart = "PART_ItemsPresenter"; - - public ListBoxTheme() : this(typeof(ListBox)) - { - } - - protected ListBoxTheme(Type targetType) : base(targetType) - { - } - - protected override IControlTemplate BuildControlTemplate() - { - return new FuncControlTemplate((listBox, scope) => - { - var frameBorder = new Border - { - Name = FramePart - }; - CreateTemplateParentBinding(frameBorder, Border.BackgroundProperty, TemplatedControl.BackgroundProperty); - CreateTemplateParentBinding(frameBorder, Border.BorderBrushProperty, TemplatedControl.BorderBrushProperty); - CreateTemplateParentBinding(frameBorder, Border.BorderThicknessProperty, TemplatedControl.BorderThicknessProperty); - CreateTemplateParentBinding(frameBorder, Border.CornerRadiusProperty, TemplatedControl.CornerRadiusProperty); - - var itemsPresenter = BuildItemsPresenter(listBox, scope); - var scrollViewer = BuildScrollViewer(); - - scrollViewer.Content = itemsPresenter; - frameBorder.Child = scrollViewer; - - return frameBorder; - }); - } - - private ScrollViewer BuildScrollViewer() - { - var scrollViewer = new ScrollViewer - { - Name = ScrollViewerPart - }; - - CreateTemplateParentBinding(scrollViewer, ScrollViewer.AllowAutoHideProperty, ScrollViewer.AllowAutoHideProperty); - CreateTemplateParentBinding(scrollViewer, ScrollViewer.HorizontalScrollBarVisibilityProperty, ScrollViewer.HorizontalScrollBarVisibilityProperty); - CreateTemplateParentBinding(scrollViewer, ScrollViewer.VerticalScrollBarVisibilityProperty, ScrollViewer.VerticalScrollBarVisibilityProperty); - CreateTemplateParentBinding(scrollViewer, ScrollViewer.IsScrollChainingEnabledProperty, ScrollViewer.IsScrollChainingEnabledProperty); - CreateTemplateParentBinding(scrollViewer, ScrollViewer.IsDeferredScrollingEnabledProperty, ScrollViewer.IsDeferredScrollingEnabledProperty); - CreateTemplateParentBinding(scrollViewer, ScrollViewer.IsScrollInertiaEnabledProperty, ScrollViewer.IsScrollInertiaEnabledProperty); - - return scrollViewer; - } - - private ItemsPresenter BuildItemsPresenter(ListBox listBox, INameScope scope) - { - var itemsPresenter = new ItemsPresenter - { - Name = ItemsPresenterPart - }; - itemsPresenter.RegisterInNameScope(scope); - CreateTemplateParentBinding(itemsPresenter, ItemsPresenter.ItemsPanelProperty, ItemsControl.ItemsPanelProperty); - return itemsPresenter; - } - - protected override void BuildStyles() - { - BuildFixedStyle(); - BuildCommonStyle(); - BuildSizeTypeStyle(); - } - - private void BuildSizeTypeStyle() - { - var largeStyle = - new Style(selector => selector.Nesting().PropertyEquals(ListBox.SizeTypeProperty, SizeType.Large)); - largeStyle.Add(Border.CornerRadiusProperty, SharedTokenKey.BorderRadiusLG); - - Add(largeStyle); - - var middleStyle = - new Style(selector => selector.Nesting().PropertyEquals(ListBox.SizeTypeProperty, SizeType.Middle)); - middleStyle.Add(Border.CornerRadiusProperty, SharedTokenKey.BorderRadius); - - Add(middleStyle); - - var smallStyle = - new Style(selector => selector.Nesting().PropertyEquals(ListBox.SizeTypeProperty, SizeType.Small)); - smallStyle.Add(Border.CornerRadiusProperty, SharedTokenKey.BorderRadiusSM); - Add(smallStyle); - } - - private void BuildFixedStyle() - { - this.Add(ScrollViewer.HorizontalScrollBarVisibilityProperty, ScrollBarVisibility.Disabled); - this.Add(ScrollViewer.VerticalScrollBarVisibilityProperty, ScrollBarVisibility.Auto); - this.Add(ScrollViewer.IsScrollChainingEnabledProperty, true); - } - - private void BuildCommonStyle() - { - var commonStyle = new Style(selector => selector.Nesting()); - commonStyle.Add(Border.BorderBrushProperty, SharedTokenKey.ColorBorder); - var frameStyle = new Style(selector => selector.Nesting().Template().Name(FramePart)); - frameStyle.Add(Decorator.PaddingProperty, ListBoxTokenKey.ContentPadding); - frameStyle.Add(Border.BackgroundProperty, SharedTokenKey.ColorBgContainer); - commonStyle.Add(frameStyle); - Add(commonStyle); - } -} \ No newline at end of file diff --git a/src/AtomUI.Controls/ListBox/Themes/ListBoxItemTheme.axaml b/src/AtomUI.Controls/ListBox/Themes/ListBoxItemTheme.axaml new file mode 100644 index 000000000..00e9a3e19 --- /dev/null +++ b/src/AtomUI.Controls/ListBox/Themes/ListBoxItemTheme.axaml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/AtomUI.Controls/ListBox/Themes/ListBoxTheme.axaml b/src/AtomUI.Controls/ListBox/Themes/ListBoxTheme.axaml new file mode 100644 index 000000000..8a06a560b --- /dev/null +++ b/src/AtomUI.Controls/ListBox/Themes/ListBoxTheme.axaml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/AtomUI.Controls/ListBox/Themes/ListBoxThemeConstants.cs b/src/AtomUI.Controls/ListBox/Themes/ListBoxThemeConstants.cs new file mode 100644 index 000000000..7c42b1b5d --- /dev/null +++ b/src/AtomUI.Controls/ListBox/Themes/ListBoxThemeConstants.cs @@ -0,0 +1,13 @@ +namespace AtomUI.Controls.Themes; + +internal static class ListBoxThemeConstants +{ + public const string FramePart = "PART_Frame"; + public const string ScrollViewerPart = "PART_ScrollViewer"; + public const string ItemsPresenterPart = "PART_ItemsPresenter"; +} + +internal static class ListBoxItemThemeConstants +{ + public const string ContentPresenterPart = "PART_ContentPresenter"; +} \ No newline at end of file diff --git a/src/AtomUI.Controls/ListBox/Themes/ListBoxThemes.axaml b/src/AtomUI.Controls/ListBox/Themes/ListBoxThemes.axaml new file mode 100644 index 000000000..c4581ea78 --- /dev/null +++ b/src/AtomUI.Controls/ListBox/Themes/ListBoxThemes.axaml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/src/AtomUI.Controls/Menu/MenuSeparator.cs b/src/AtomUI.Controls/Menu/MenuSeparator.cs index ba3083dad..3cc12e537 100644 --- a/src/AtomUI.Controls/Menu/MenuSeparator.cs +++ b/src/AtomUI.Controls/Menu/MenuSeparator.cs @@ -6,7 +6,6 @@ using AtomUI.Theme.Utils; using Avalonia; using Avalonia.Controls; using Avalonia.Data; -using Avalonia.LogicalTree; using Avalonia.Media; namespace AtomUI.Controls; @@ -51,23 +50,18 @@ public class MenuSeparator : AvaloniaSeparator, context.DrawLine(linePen, new Point(0, offsetY), new Point(Bounds.Right, offsetY)); } - protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e) - { - base.OnAttachedToLogicalTree(e); - _resourceBindingsDisposable = new CompositeDisposable(); - } - - protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e) - { - base.OnDetachedFromLogicalTree(e); - this.DisposeTokenBindings(); - } - protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) { base.OnAttachedToVisualTree(e); + _resourceBindingsDisposable = new CompositeDisposable(); this.AddResourceBindingDisposable(TokenResourceBinder.CreateTokenBinding(this, LineWidthProperty, SharedTokenKey.LineWidth, BindingPriority.Template, new RenderScaleAwareDoubleConfigure(this))); } + + protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e) + { + base.OnDetachedFromVisualTree(e); + this.DisposeTokenBindings(); + } } \ No newline at end of file