feat: move identification to measure process.
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Ursa.Demo.Pages.ToolBarDemo">
|
||||
<StackPanel>
|
||||
<u:ToolBar HorizontalAlignment="Left">
|
||||
<u:ToolBar HorizontalAlignment="Left" Header="Hello World">
|
||||
<Button Content="Button 1" />
|
||||
<Button Content="Button 2" />
|
||||
<Button Content="Button 3" u:ToolBar.OverflowMode="Always" />
|
||||
@@ -20,6 +20,5 @@
|
||||
<template:ToolBarItemTemplateSelector/>
|
||||
</u:ToolBar.ItemTemplate>
|
||||
</u:ToolBar>
|
||||
<CheckBox Content="Check"></CheckBox>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
|
||||
@@ -38,10 +38,16 @@ public class ToolBar: HeaderedItemsControl
|
||||
}
|
||||
|
||||
public static readonly AttachedProperty<OverflowMode> OverflowModeProperty =
|
||||
AvaloniaProperty.RegisterAttached<ToolBar, Control?, OverflowMode>("OverflowMode");
|
||||
AvaloniaProperty.RegisterAttached<ToolBar, Control, OverflowMode>("OverflowMode");
|
||||
|
||||
public static void SetOverflowMode(Control? obj, OverflowMode value) => obj.SetValue(OverflowModeProperty, value);
|
||||
public static OverflowMode GetOverflowMode(Control? obj) => obj.GetValue(OverflowModeProperty);
|
||||
public static void SetOverflowMode(Control obj, OverflowMode value) => obj.SetValue(OverflowModeProperty, value);
|
||||
public static OverflowMode GetOverflowMode(Control obj) => obj.GetValue(OverflowModeProperty);
|
||||
|
||||
internal static readonly AttachedProperty<bool> IsOverflowItemProperty =
|
||||
AvaloniaProperty.RegisterAttached<ToolBar, Control, bool>("IsOverflowItem");
|
||||
|
||||
internal static void SetIsOverflowItem(Control obj, bool value) => obj.SetValue(IsOverflowItemProperty, value);
|
||||
internal static bool GetIsOverflowItem(Control obj) => obj.GetValue(IsOverflowItemProperty);
|
||||
|
||||
static ToolBar()
|
||||
{
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Layout;
|
||||
using Avalonia.LogicalTree;
|
||||
using Avalonia.VisualTree;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
|
||||
@@ -45,16 +44,18 @@ public class ToolBarPanel: StackPanel
|
||||
Size measureSize = availableSize;
|
||||
bool horizontal = Orientation == Orientation.Horizontal;
|
||||
bool hasVisibleChildren = false;
|
||||
measureSize = horizontal
|
||||
? measureSize.WithWidth(double.PositiveInfinity)
|
||||
: measureSize.WithHeight(double.PositiveInfinity);
|
||||
measureSize = new Size(double.PositiveInfinity, double.PositiveInfinity);
|
||||
int index = 0;
|
||||
if (logicalChildren is null) return size;
|
||||
for (int count = logicalChildren.Count; index < count; ++index)
|
||||
{
|
||||
Control control = logicalChildren[index];
|
||||
var mode = ToolBar.GetOverflowMode(control);
|
||||
if(mode == OverflowMode.Always) continue;
|
||||
if (mode == OverflowMode.Always)
|
||||
{
|
||||
ToolBar.SetIsOverflowItem(control, true);
|
||||
continue;
|
||||
}
|
||||
bool isVisible = control.IsVisible;
|
||||
if (isVisible)
|
||||
{
|
||||
@@ -83,6 +84,21 @@ public class ToolBarPanel: StackPanel
|
||||
|
||||
protected override Size ArrangeOverride(Size finalSize)
|
||||
{
|
||||
var logicalChildren = _parent?.GetLogicalChildren().OfType<Control>().ToList();
|
||||
Children.Clear();
|
||||
OverflowPanel?.Children.Clear();
|
||||
foreach (var child in logicalChildren)
|
||||
{
|
||||
if (ToolBar.GetIsOverflowItem(child))
|
||||
{
|
||||
OverflowPanel?.Children.Add(child);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Children.Add(child);
|
||||
}
|
||||
}
|
||||
return base.ArrangeOverride(finalSize);
|
||||
if (_parent is null)
|
||||
{
|
||||
return finalSize;
|
||||
|
||||
Reference in New Issue
Block a user