From e57036163db9edde42d665dba0f7333ba56009a3 Mon Sep 17 00:00:00 2001 From: Zhang Dian <54255897+zdpcdt@users.noreply.github.com> Date: Tue, 14 Jan 2025 21:28:41 +0800 Subject: [PATCH] feat: add Gap property to Avatar. --- demo/Ursa.Demo/Pages/AvatarDemo.axaml | 6 ++++ src/Ursa.Themes.Semi/Controls/Avatar.axaml | 32 +++++++++++++------ src/Ursa/Controls/Avatar/Avatar.cs | 9 ++++++ ...erter.cs => DoubleToThicknessConverter.cs} | 7 ++-- 4 files changed, 42 insertions(+), 12 deletions(-) rename src/Ursa/Converters/{DivideByTwoConverter.cs => DoubleToThicknessConverter.cs} (72%) diff --git a/demo/Ursa.Demo/Pages/AvatarDemo.axaml b/demo/Ursa.Demo/Pages/AvatarDemo.axaml index c3046c3..e401bfc 100644 --- a/demo/Ursa.Demo/Pages/AvatarDemo.axaml +++ b/demo/Ursa.Demo/Pages/AvatarDemo.axaml @@ -93,5 +93,11 @@ + + + + + + \ 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 4fe9705..b8cfc97 100644 --- a/src/Ursa.Themes.Semi/Controls/Avatar.axaml +++ b/src/Ursa.Themes.Semi/Controls/Avatar.axaml @@ -3,12 +3,20 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:u="https://irihi.tech/ursa" xmlns:converters="clr-namespace:Ursa.Converters;assembly=Ursa"> - + + + + + + + + + @@ -24,14 +32,20 @@ BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="{TemplateBinding CornerRadius}" - Background="{TemplateBinding Background}" /> - + Background="{TemplateBinding Background}"> + + + + GapProperty = AvaloniaProperty.Register( + nameof(Gap)); + public static readonly StyledProperty SourceProperty = AvaloniaProperty.Register( nameof(Source)); public static readonly StyledProperty HoverMaskProperty = AvaloniaProperty.Register( nameof(HoverMask)); + public double Gap + { + get => GetValue(GapProperty); + set => SetValue(GapProperty, value); + } + [ExcludeFromCodeCoverage] public IImage? Source { diff --git a/src/Ursa/Converters/DivideByTwoConverter.cs b/src/Ursa/Converters/DoubleToThicknessConverter.cs similarity index 72% rename from src/Ursa/Converters/DivideByTwoConverter.cs rename to src/Ursa/Converters/DoubleToThicknessConverter.cs index 15c2aa3..6ac248b 100644 --- a/src/Ursa/Converters/DivideByTwoConverter.cs +++ b/src/Ursa/Converters/DoubleToThicknessConverter.cs @@ -1,18 +1,19 @@ using System.Globalization; +using Avalonia; using Avalonia.Data.Converters; namespace Ursa.Converters; -public class DivideByTwoConverter : IValueConverter +public class DoubleToThicknessConverter : IValueConverter { public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { if (value is double d) { - return d / 2; + return new Thickness(d, 0); } - return value; + return AvaloniaProperty.UnsetValue; } public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)