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 1/7] 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) From 63be2d15ad4b965d8faf09dc6e937ec8458d797e Mon Sep 17 00:00:00 2001 From: Zhang Dian <54255897+zdpcdt@users.noreply.github.com> Date: Wed, 15 Jan 2025 22:58:21 +0800 Subject: [PATCH 2/7] fix: fix invisible issue when Dot=True & fix some style issues in Badge. --- src/Ursa.Themes.Semi/Controls/Badge.axaml | 30 +++++++++++++++++-- .../Themes/Shared/Badge.axaml | 2 +- .../BadgeContentOverflowConverter.cs | 11 +++---- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/Ursa.Themes.Semi/Controls/Badge.axaml b/src/Ursa.Themes.Semi/Controls/Badge.axaml index 6fd316a..adac623 100644 --- a/src/Ursa.Themes.Semi/Controls/Badge.axaml +++ b/src/Ursa.Themes.Semi/Controls/Badge.axaml @@ -3,7 +3,27 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:converters="clr-namespace:Ursa.Converters;assembly=Ursa" xmlns:u="https://irihi.tech/ursa"> - + + + + + + + + + + + + + + + + + + + @@ -94,7 +114,6 @@ BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="{TemplateBinding CornerRadius}" - IsVisible="{Binding Header, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static ObjectConverters.IsNotNull}}" RenderTransformOrigin=".5,.5" /> @@ -138,6 +157,12 @@ + + diff --git a/src/Ursa.Themes.Semi/Themes/Shared/Badge.axaml b/src/Ursa.Themes.Semi/Themes/Shared/Badge.axaml index 7c39786..9f1dd5d 100644 --- a/src/Ursa.Themes.Semi/Themes/Shared/Badge.axaml +++ b/src/Ursa.Themes.Semi/Themes/Shared/Badge.axaml @@ -6,7 +6,7 @@ 18 8 8 - 6,0 + 4,0 1 10 100 diff --git a/src/Ursa/Converters/BadgeContentOverflowConverter.cs b/src/Ursa/Converters/BadgeContentOverflowConverter.cs index 922c44f..e44d902 100644 --- a/src/Ursa/Converters/BadgeContentOverflowConverter.cs +++ b/src/Ursa/Converters/BadgeContentOverflowConverter.cs @@ -3,18 +3,19 @@ using Avalonia.Data.Converters; namespace Ursa.Converters; -public class BadgeContentOverflowConverter: IMultiValueConverter +public class BadgeContentOverflowConverter : IMultiValueConverter { public object? Convert(IList values, Type targetType, object? parameter, CultureInfo culture) { - string overflowMark = parameter is string s ? s : "+"; - if (double.TryParse(values[0]?.ToString(), out var b) && values[1] is int i and > 0) + var overflowMark = parameter as string ?? "+"; + if (double.TryParse(values[0]?.ToString(), out var b) && values[1] is int count and > 0) { - if (b > i) + if (b > count) { - return i + overflowMark; + return $"{count}{overflowMark}"; } } + return values[0]; } } \ No newline at end of file From b968970b0b94cad083e2af2aef1fcd2c9ab3274a Mon Sep 17 00:00:00 2001 From: Zhang Dian <54255897+zdpcdt@users.noreply.github.com> Date: Wed, 15 Jan 2025 22:08:40 +0800 Subject: [PATCH 3/7] feat: replace Border with Avatar in BadgeDemo. --- demo/Ursa.Demo/Pages/BadgeDemo.axaml | 319 ++++++++++++--------------- 1 file changed, 142 insertions(+), 177 deletions(-) diff --git a/demo/Ursa.Demo/Pages/BadgeDemo.axaml b/demo/Ursa.Demo/Pages/BadgeDemo.axaml index f46673b..f633f70 100644 --- a/demo/Ursa.Demo/Pages/BadgeDemo.axaml +++ b/demo/Ursa.Demo/Pages/BadgeDemo.axaml @@ -16,341 +16,306 @@ - + - - - - + + - - - - + + + + + + + + + + + + + - - + - - - - + + - - - - + + - - - - + + - - - - + + + - - - - + + - - - - + + - - - - + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + - - - + - - - + - - - + - - - + - - - + - - - + + - - - + - - - + - - - + - - - + - - - + - - - + + - - - + - - - + - - - + - - - + - - - + - - - + + - - - + - - - + - - - + - - - + - - - + - - - + + - - - + - - - + - - - + - - - + - - - + - - - + - + + - - - + - - - + - - - + - - - + - - - + - - - + From 7017ce88acbded84a5e8e5fc810d74f77e998f07 Mon Sep 17 00:00:00 2001 From: Zhang Dian <54255897+zdpcdt@users.noreply.github.com> Date: Thu, 16 Jan 2025 15:45:10 +0800 Subject: [PATCH 4/7] feat: replace Border with Avatar in IntroductionDemo. --- demo/Ursa.Demo/Pages/IntroductionDemo.axaml | 80 ++++++++------------- 1 file changed, 30 insertions(+), 50 deletions(-) diff --git a/demo/Ursa.Demo/Pages/IntroductionDemo.axaml b/demo/Ursa.Demo/Pages/IntroductionDemo.axaml index ac0a9f2..cfdd29b 100644 --- a/demo/Ursa.Demo/Pages/IntroductionDemo.axaml +++ b/demo/Ursa.Demo/Pages/IntroductionDemo.axaml @@ -103,24 +103,24 @@ Content="Step 1" Header="ToDo" Type="Default" - Time="2023-01-14 09:24:05"/> + Time="2023-01-14 09:24:05" /> + Time="2024-01-04 22:32:58" /> + Time="2024-01-05 00:08:29" /> + Type="Success" + Time="2024-01-05 00:27:44" /> @@ -133,58 +133,38 @@ - Badge + + + - - - - + + - - - - + + - - - - + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + - DualBadge + + + From 7ff0e63e4d4efb85f2512c8cd6e4dca755723831 Mon Sep 17 00:00:00 2001 From: Zhang Dian <54255897+zdpcdt@users.noreply.github.com> Date: Thu, 16 Jan 2025 15:44:12 +0800 Subject: [PATCH 5/7] fix: fix Badge Light Classes colors. --- src/Ursa.Themes.Semi/Controls/Badge.axaml | 15 +++--- src/Ursa.Themes.Semi/Themes/Dark/Badge.axaml | 48 +++++++++---------- src/Ursa.Themes.Semi/Themes/Light/Badge.axaml | 24 +++++----- .../Themes/Shared/Badge.axaml | 2 +- 4 files changed, 44 insertions(+), 45 deletions(-) diff --git a/src/Ursa.Themes.Semi/Controls/Badge.axaml b/src/Ursa.Themes.Semi/Controls/Badge.axaml index adac623..11cd4c5 100644 --- a/src/Ursa.Themes.Semi/Controls/Badge.axaml +++ b/src/Ursa.Themes.Semi/Controls/Badge.axaml @@ -22,6 +22,9 @@ + + + @@ -42,7 +45,7 @@ - @@ -59,8 +62,6 @@ MinWidth="{DynamicResource BadgeMinWidth}" MinHeight="{DynamicResource BadgeMinHeight}" Padding="{DynamicResource BadgePadding}" - HorizontalAlignment="Right" - VerticalAlignment="Top" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" @@ -85,14 +86,14 @@ - + diff --git a/src/Ursa.Themes.Semi/Themes/Dark/Badge.axaml b/src/Ursa.Themes.Semi/Themes/Dark/Badge.axaml index 37c6584..5c2b5e9 100644 --- a/src/Ursa.Themes.Semi/Themes/Dark/Badge.axaml +++ b/src/Ursa.Themes.Semi/Themes/Dark/Badge.axaml @@ -3,32 +3,32 @@ - - - - - - + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - + + + + + + \ No newline at end of file diff --git a/src/Ursa.Themes.Semi/Themes/Light/Badge.axaml b/src/Ursa.Themes.Semi/Themes/Light/Badge.axaml index 403f137..ff148f7 100644 --- a/src/Ursa.Themes.Semi/Themes/Light/Badge.axaml +++ b/src/Ursa.Themes.Semi/Themes/Light/Badge.axaml @@ -3,32 +3,32 @@ - + + - - + - + - - - - - + - + + + + + - + + - \ No newline at end of file diff --git a/src/Ursa.Themes.Semi/Themes/Shared/Badge.axaml b/src/Ursa.Themes.Semi/Themes/Shared/Badge.axaml index 9f1dd5d..b69c74a 100644 --- a/src/Ursa.Themes.Semi/Themes/Shared/Badge.axaml +++ b/src/Ursa.Themes.Semi/Themes/Shared/Badge.axaml @@ -8,7 +8,7 @@ 8 4,0 1 - 10 + 12 100 TopRight \ No newline at end of file From 33bfd67833e6227d151f8f73582c7e5bee2c98d5 Mon Sep 17 00:00:00 2001 From: Zhang Dian <54255897+zdpcdt@users.noreply.github.com> Date: Thu, 16 Jan 2025 18:31:03 +0800 Subject: [PATCH 6/7] feat: remove Template when Dot=True, add Badge Tests, format Badge class. --- src/Ursa.Themes.Semi/Controls/Badge.axaml | 41 +++------- src/Ursa/Controls/Badge.cs | 39 +++++---- .../Controls/BadgeTests/BadgeTests.cs | 79 +++++++++++++++++++ 3 files changed, 115 insertions(+), 44 deletions(-) create mode 100644 tests/HeadlessTest.Ursa/Controls/BadgeTests/BadgeTests.cs diff --git a/src/Ursa.Themes.Semi/Controls/Badge.axaml b/src/Ursa.Themes.Semi/Controls/Badge.axaml index 11cd4c5..d11ee3f 100644 --- a/src/Ursa.Themes.Semi/Controls/Badge.axaml +++ b/src/Ursa.Themes.Semi/Controls/Badge.axaml @@ -66,10 +66,15 @@ BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="{TemplateBinding CornerRadius}" - IsVisible="{Binding Header, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static ObjectConverters.IsNotNull}}" RenderTransformOrigin=".5,.5" Theme="{TemplateBinding BadgeTheme}" UseLayoutRounding="False"> + + + + + + - +