feat: add separator support, fix various issues.
This commit is contained in:
@@ -86,7 +86,11 @@ public class ToolBar: HeaderedItemsControl
|
||||
{
|
||||
return c;
|
||||
}
|
||||
return ItemTemplate?.Build(item) ?? new ContentPresenter();
|
||||
if(ItemTemplate is not null && ItemTemplate.Match(item))
|
||||
{
|
||||
return ItemTemplate.Build(item)?? new ContentPresenter();
|
||||
}
|
||||
return new ContentPresenter();
|
||||
}
|
||||
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
|
||||
@@ -116,8 +116,24 @@ public class ToolBarPanel: StackPanel
|
||||
{
|
||||
Children.Add(child);
|
||||
}
|
||||
|
||||
if (child is ToolBarSeparator s)
|
||||
{
|
||||
s.IsVisible = true;
|
||||
}
|
||||
}
|
||||
|
||||
var thisLast = this.Children.LastOrDefault();
|
||||
if (thisLast is ToolBarSeparator s2)
|
||||
{
|
||||
s2.IsVisible = false;
|
||||
}
|
||||
|
||||
var thatFirst = OverflowPanel?.Children.FirstOrDefault();
|
||||
if (thatFirst is ToolBarSeparator s3)
|
||||
{
|
||||
s3.IsVisible = false;
|
||||
}
|
||||
if (_parent != null) _parent.HasOverflowItems = overflow;
|
||||
return base.ArrangeOverride(finalSize);
|
||||
}
|
||||
|
||||
41
src/Ursa/Controls/ToolBar/ToolBarSeparator.cs
Normal file
41
src/Ursa/Controls/ToolBar/ToolBarSeparator.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Metadata;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Layout;
|
||||
using Avalonia.LogicalTree;
|
||||
using Irihi.Avalonia.Shared.Helpers;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
|
||||
[PseudoClasses(PC_Vertical)]
|
||||
public class ToolBarSeparator: TemplatedControl
|
||||
{
|
||||
public const string PC_Vertical = ":vertical";
|
||||
|
||||
public static readonly StyledProperty<Orientation> OrientationProperty =
|
||||
ToolBar.OrientationProperty.AddOwner<ToolBarSeparator>();
|
||||
|
||||
public Orientation Orientation
|
||||
{
|
||||
get => GetValue(OrientationProperty);
|
||||
set => SetValue(OrientationProperty, value);
|
||||
}
|
||||
|
||||
static ToolBarSeparator()
|
||||
{
|
||||
OrientationProperty.OverrideDefaultValue<ToolBarSeparator>(Orientation.Horizontal);
|
||||
OrientationProperty.Changed.AddClassHandler<ToolBarSeparator, Orientation>((separator, args) =>
|
||||
{
|
||||
separator.PseudoClasses.Set(PC_Vertical, args.NewValue.Value == Orientation.Vertical);
|
||||
});
|
||||
}
|
||||
|
||||
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnAttachedToLogicalTree(e);
|
||||
var ancestor = this.GetLogicalAncestors().OfType<ToolBar>().FirstOrDefault();
|
||||
if (ancestor is null) return;
|
||||
this[!OrientationProperty] = ancestor[!ToolBar.OrientationProperty];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user