diff --git a/demo/Ursa.Demo/Pages/AvatarDemo.axaml b/demo/Ursa.Demo/Pages/AvatarDemo.axaml index 43b2a5f..9f5ba46 100644 --- a/demo/Ursa.Demo/Pages/AvatarDemo.axaml +++ b/demo/Ursa.Demo/Pages/AvatarDemo.axaml @@ -73,15 +73,5 @@ - - - - - - - - - - \ No newline at end of file diff --git a/src/Ursa.Themes.Semi/Controls/Avatar.axaml b/src/Ursa.Themes.Semi/Controls/Avatar.axaml index 2651563..10607dc 100644 --- a/src/Ursa.Themes.Semi/Controls/Avatar.axaml +++ b/src/Ursa.Themes.Semi/Controls/Avatar.axaml @@ -33,17 +33,13 @@ HorizontalContentAlignment="Center" VerticalContentAlignment="Center" /> - - - - @@ -141,12 +137,4 @@ - - - - - - - - \ No newline at end of file diff --git a/src/Ursa/Controls/Avatar/Avatar.cs b/src/Ursa/Controls/Avatar/Avatar.cs index d198aa1..a3d134c 100644 --- a/src/Ursa/Controls/Avatar/Avatar.cs +++ b/src/Ursa/Controls/Avatar/Avatar.cs @@ -1,42 +1,17 @@ using Avalonia; using Avalonia.Controls; -using Avalonia.Controls.Metadata; -using Avalonia.Controls.Presenters; using Avalonia.Media; namespace Ursa.Controls; -[TemplatePart(PART_HoverMask, typeof(ContentPresenter))] public class Avatar : Button { - public const string PART_TopPresenter = "PART_TopPresenter"; - public const string PART_BottomPresenter = "PART_BottomPresenter"; - public const string PART_HoverMask = "PART_HoverMask"; - - public static readonly StyledProperty ContentMotionProperty = AvaloniaProperty.Register( - nameof(ContentMotion)); - - public static readonly StyledProperty GapProperty = AvaloniaProperty.Register( - nameof(Gap)); - public static readonly StyledProperty SourceProperty = AvaloniaProperty.Register( nameof(Source)); public static readonly StyledProperty HoverMaskProperty = AvaloniaProperty.Register( nameof(HoverMask)); - public bool ContentMotion - { - get => GetValue(ContentMotionProperty); - set => SetValue(ContentMotionProperty, value); - } - - public double Gap - { - get => GetValue(GapProperty); - set => SetValue(GapProperty, value); - } - public IImage? Source { get => GetValue(SourceProperty); diff --git a/src/Ursa/Controls/Avatar/AvatarGroup.cs b/src/Ursa/Controls/Avatar/AvatarGroup.cs deleted file mode 100644 index 0609367..0000000 --- a/src/Ursa/Controls/Avatar/AvatarGroup.cs +++ /dev/null @@ -1,42 +0,0 @@ -using Avalonia; -using Avalonia.Controls; -using Avalonia.Controls.Templates; - -namespace Ursa.Controls; - -public class AvatarGroup : ItemsControl -{ - public const string PART_RenderMore = "PART_RenderMore"; - - private static readonly FuncTemplate DefaultPanel = new(() => new AvatarGroupPanel()); - - public static readonly StyledProperty MaxCountProperty = AvaloniaProperty.Register( - nameof(MaxCount)); - - public static readonly StyledProperty OverlapFromProperty = - AvaloniaProperty.Register( - nameof(OverlapFrom), defaultValue: OverlapFromType.Start); - - public int? MaxCount - { - get => GetValue(MaxCountProperty); - set => SetValue(MaxCountProperty, value); - } - - public OverlapFromType OverlapFrom - { - get => GetValue(OverlapFromProperty); - set => SetValue(OverlapFromProperty, value); - } - - static AvatarGroup() - { - ItemsPanelProperty.OverrideDefaultValue(DefaultPanel); - } -} - -public enum OverlapFromType -{ - Start, - End -} \ No newline at end of file diff --git a/src/Ursa/Controls/Avatar/AvatarGroupPanel.cs b/src/Ursa/Controls/Avatar/AvatarGroupPanel.cs deleted file mode 100644 index 40620d8..0000000 --- a/src/Ursa/Controls/Avatar/AvatarGroupPanel.cs +++ /dev/null @@ -1,64 +0,0 @@ -using Avalonia; -using Avalonia.Controls; -using Avalonia.LogicalTree; - -namespace Ursa.Controls; - -public class AvatarGroupPanel : Panel -{ - protected override Size MeasureOverride(Size availableSize) - { - var children = Children; - if (children.Count <= 0) return new Size(); - - availableSize = availableSize.WithWidth(double.PositiveInfinity); - children[0].Measure(availableSize); - Size first = children[0].DesiredSize; - var group = this.GetLogicalAncestors().OfType().FirstOrDefault(); - var maxCount = group?.MaxCount; - var count = children.Count; - if (maxCount >= 0 && maxCount < count) - { - count = maxCount.Value + 1; - } - - var width = first.Width + first.Width * (count - 1) * 0.75; - return new Size(width, first.Height); - } - - protected override Size ArrangeOverride(Size finalSize) - { - Rect rect = new Rect(finalSize); - double num = 0d; - var children = Children; - var group = this.GetLogicalAncestors().OfType().FirstOrDefault(); - var overlapFrom = group?.OverlapFrom; - var maxCount = group?.MaxCount; - var childrenCount = children.Count; - var count = maxCount < childrenCount ? maxCount.Value : childrenCount; - for (var i = 0; i < count; i++) - { - if (overlapFrom is OverlapFromType.Start) - { - children[i].ZIndex = childrenCount - 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; - children[i].Arrange(rect); - } - - if (maxCount is not null) - { - //TODO: RenderMore - } - - return finalSize; - } -} \ No newline at end of file