feat: OverlapFormType.

This commit is contained in:
Zhang Dian
2024-06-20 21:40:47 +08:00
parent abb9ec51bb
commit c49be02e82
2 changed files with 13 additions and 6 deletions

View File

@@ -15,7 +15,7 @@ public class AvatarGroup : ItemsControl
public static readonly StyledProperty<OverlapFromType> OverlapFromProperty = public static readonly StyledProperty<OverlapFromType> OverlapFromProperty =
AvaloniaProperty.Register<AvatarGroup, OverlapFromType>( AvaloniaProperty.Register<AvatarGroup, OverlapFromType>(
nameof(OverlapFrom)); nameof(OverlapFrom), defaultValue: OverlapFromType.Start);
public int MaxCount public int MaxCount
{ {

View File

@@ -1,6 +1,6 @@
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Interactivity; using Avalonia.LogicalTree;
namespace Ursa.Controls; namespace Ursa.Controls;
@@ -28,18 +28,25 @@ public class AvatarGroupPanel : Panel
{ {
Rect rect = new Rect(finalSize); Rect rect = new Rect(finalSize);
double num = 0d; double num = 0d;
var group = this.GetLogicalAncestors().OfType<AvatarGroup>().FirstOrDefault();
var overlapFrom = group?.OverlapFrom;
var children = Children; var children = Children;
foreach (var child in children) for (var i = 0; i < children.Count; i++)
{ {
child.Measure(finalSize); if (overlapFrom is OverlapFromType.Start)
Size desiredSize = child.DesiredSize; {
children[i].ZIndex = children.Count - i;
}
children[i].Measure(finalSize);
Size desiredSize = children[i].DesiredSize;
double width = desiredSize.Width; double width = desiredSize.Width;
double height = Math.Max(desiredSize.Height, finalSize.Height); double height = Math.Max(desiredSize.Height, finalSize.Height);
rect = rect.WithX(rect.X + num); rect = rect.WithX(rect.X + num);
rect = rect.WithWidth(width); rect = rect.WithWidth(width);
rect = rect.WithHeight(height); rect = rect.WithHeight(height);
num = width * 0.75; num = width * 0.75;
child.Arrange(rect); children[i].Arrange(rect);
} }
return finalSize; return finalSize;