feat: stack elements.
This commit is contained in:
@@ -72,6 +72,7 @@
|
|||||||
<u:Avatar Background="#FDE3CF" Foreground="#F56A00" Content="ZL" />
|
<u:Avatar Background="#FDE3CF" Foreground="#F56A00" Content="ZL" />
|
||||||
<u:Avatar Background="#87D068" Classes="" Content="YZ" />
|
<u:Avatar Background="#87D068" Classes="" Content="YZ" />
|
||||||
</u:AvatarGroup>
|
</u:AvatarGroup>
|
||||||
|
<u:Avatar />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
@@ -8,8 +8,7 @@ public class AvatarGroup : ItemsControl
|
|||||||
{
|
{
|
||||||
public const string PART_RenderMore = "PART_RenderMore";
|
public const string PART_RenderMore = "PART_RenderMore";
|
||||||
|
|
||||||
private static readonly FuncTemplate<Panel?> DefaultPanel =
|
private static readonly FuncTemplate<Panel?> DefaultPanel = new(() => new AvatarGroupPanel());
|
||||||
new(() => new AvatarGroupPanel());
|
|
||||||
|
|
||||||
public static readonly StyledProperty<int> MaxCountProperty = AvaloniaProperty.Register<AvatarGroup, int>(
|
public static readonly StyledProperty<int> MaxCountProperty = AvaloniaProperty.Register<AvatarGroup, int>(
|
||||||
nameof(MaxCount));
|
nameof(MaxCount));
|
||||||
|
|||||||
@@ -11,12 +11,13 @@ public class AvatarGroupPanel : Panel
|
|||||||
Size size = new Size();
|
Size size = new Size();
|
||||||
availableSize = availableSize.WithWidth(double.PositiveInfinity);
|
availableSize = availableSize.WithWidth(double.PositiveInfinity);
|
||||||
var children = Children;
|
var children = Children;
|
||||||
foreach (var child in children)
|
if (children.Count > 0)
|
||||||
{
|
{
|
||||||
child.Measure(availableSize);
|
children[0].Measure(availableSize);
|
||||||
Size desiredSize = child.DesiredSize;
|
Size first = children[0].DesiredSize;
|
||||||
size = size.WithWidth(size.Width + desiredSize.Width);
|
var width = first.Width + first.Width * (children.Count - 1) * 0.75;
|
||||||
size = size.WithHeight(Math.Max(size.Height, desiredSize.Height));
|
size = size.WithWidth(width);
|
||||||
|
size = size.WithHeight(first.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
size = size.WithWidth(size.Width);
|
size = size.WithWidth(size.Width);
|
||||||
@@ -30,17 +31,17 @@ public class AvatarGroupPanel : Panel
|
|||||||
var children = Children;
|
var children = Children;
|
||||||
foreach (var child in children)
|
foreach (var child in children)
|
||||||
{
|
{
|
||||||
|
child.Measure(finalSize);
|
||||||
Size desiredSize = child.DesiredSize;
|
Size desiredSize = child.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;
|
num = width * 0.75;
|
||||||
child.Arrange(rect);
|
child.Arrange(rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
RaiseEvent(new RoutedEventArgs(StackPanel.HorizontalSnapPointsChangedEvent));
|
|
||||||
return finalSize;
|
return finalSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user