From c49be02e829cf06bdbbe804908957e14367e8bb8 Mon Sep 17 00:00:00 2001 From: Zhang Dian <54255897+zdpcdt@users.noreply.github.com> Date: Thu, 20 Jun 2024 21:40:47 +0800 Subject: [PATCH] feat: OverlapFormType. --- src/Ursa/Controls/Avatar/AvatarGroup.cs | 2 +- src/Ursa/Controls/Avatar/AvatarGroupPanel.cs | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Ursa/Controls/Avatar/AvatarGroup.cs b/src/Ursa/Controls/Avatar/AvatarGroup.cs index fbd4e84..340b2c6 100644 --- a/src/Ursa/Controls/Avatar/AvatarGroup.cs +++ b/src/Ursa/Controls/Avatar/AvatarGroup.cs @@ -15,7 +15,7 @@ public class AvatarGroup : ItemsControl public static readonly StyledProperty OverlapFromProperty = AvaloniaProperty.Register( - nameof(OverlapFrom)); + nameof(OverlapFrom), defaultValue: OverlapFromType.Start); public int MaxCount { diff --git a/src/Ursa/Controls/Avatar/AvatarGroupPanel.cs b/src/Ursa/Controls/Avatar/AvatarGroupPanel.cs index 4f02108..cfc24fb 100644 --- a/src/Ursa/Controls/Avatar/AvatarGroupPanel.cs +++ b/src/Ursa/Controls/Avatar/AvatarGroupPanel.cs @@ -1,6 +1,6 @@ using Avalonia; using Avalonia.Controls; -using Avalonia.Interactivity; +using Avalonia.LogicalTree; namespace Ursa.Controls; @@ -28,18 +28,25 @@ public class AvatarGroupPanel : Panel { Rect rect = new Rect(finalSize); double num = 0d; + var group = this.GetLogicalAncestors().OfType().FirstOrDefault(); + var overlapFrom = group?.OverlapFrom; var children = Children; - foreach (var child in children) + for (var i = 0; i < children.Count; i++) { - child.Measure(finalSize); - Size desiredSize = child.DesiredSize; + if (overlapFrom is OverlapFromType.Start) + { + children[i].ZIndex = children.Count - i; + } + + children[i].Measure(finalSize); + Size desiredSize = children[i].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 * 0.75; - child.Arrange(rect); + children[i].Arrange(rect); } return finalSize;