diff --git a/src/Ursa/Controls/Avatar/AvatarGroup.cs b/src/Ursa/Controls/Avatar/AvatarGroup.cs index 300a3f6..d2f236a 100644 --- a/src/Ursa/Controls/Avatar/AvatarGroup.cs +++ b/src/Ursa/Controls/Avatar/AvatarGroup.cs @@ -1,7 +1,6 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Templates; -using Avalonia.Layout; namespace Ursa.Controls; @@ -10,7 +9,7 @@ public class AvatarGroup : ItemsControl public const string PART_RenderMore = "PART_RenderMore"; private static readonly FuncTemplate DefaultPanel = - new(() => new StackPanel { Orientation = Orientation.Horizontal }); + new(() => new AvatarGroupPanel()); public static readonly StyledProperty MaxCountProperty = AvaloniaProperty.Register( nameof(MaxCount)); diff --git a/src/Ursa/Controls/Avatar/AvatarGroupPanel.cs b/src/Ursa/Controls/Avatar/AvatarGroupPanel.cs new file mode 100644 index 0000000..324f523 --- /dev/null +++ b/src/Ursa/Controls/Avatar/AvatarGroupPanel.cs @@ -0,0 +1,46 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Interactivity; + +namespace Ursa.Controls; + +public class AvatarGroupPanel : Panel +{ + protected override Size MeasureOverride(Size availableSize) + { + Size size = new Size(); + availableSize = availableSize.WithWidth(double.PositiveInfinity); + var children = Children; + foreach (var child in children) + { + child.Measure(availableSize); + Size desiredSize = child.DesiredSize; + size = size.WithWidth(size.Width + desiredSize.Width); + size = size.WithHeight(Math.Max(size.Height, desiredSize.Height)); + } + + size = size.WithWidth(size.Width); + return size; + } + + protected override Size ArrangeOverride(Size finalSize) + { + Rect rect = new Rect(finalSize); + double num = 0d; + var children = Children; + foreach (var child in children) + { + Size desiredSize = child.DesiredSize; + double width = desiredSize.Width; + double height = Math.Max(desiredSize.Height, finalSize.Height); + rect = rect.WithX(rect.X + num); + rect = rect.WithWidth(width); + rect = rect.WithHeight(height); + num = width; + child.Arrange(rect); + } + + RaiseEvent(new RoutedEventArgs(StackPanel.HorizontalSnapPointsChangedEvent)); + return finalSize; + } +} \ No newline at end of file