From 95682fb45072e73d58729e4f7365ba846b024351 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Sat, 6 Jan 2024 16:02:14 +0800 Subject: [PATCH 1/4] feat: initialize icon button. --- demo/Ursa.Demo/Models/MenuKeys.cs | 1 + demo/Ursa.Demo/Pages/IconButtonDemo.axaml | 14 ++++++++ demo/Ursa.Demo/Pages/IconButtonDemo.axaml.cs | 13 +++++++ .../ViewModels/IconButtonDemoViewModel.cs | 8 +++++ .../Ursa.Demo/ViewModels/MainViewViewModel.cs | 1 + demo/Ursa.Demo/ViewModels/MenuViewModel.cs | 1 + .../Controls/IconButton.axaml | 24 +++++++++++++ src/Ursa.Themes.Semi/Controls/_index.axaml | 1 + src/Ursa/Controls/IconButton.cs | 35 +++++++++++++++++++ 9 files changed, 98 insertions(+) create mode 100644 demo/Ursa.Demo/Pages/IconButtonDemo.axaml create mode 100644 demo/Ursa.Demo/Pages/IconButtonDemo.axaml.cs create mode 100644 demo/Ursa.Demo/ViewModels/IconButtonDemoViewModel.cs create mode 100644 src/Ursa.Themes.Semi/Controls/IconButton.axaml create mode 100644 src/Ursa/Controls/IconButton.cs diff --git a/demo/Ursa.Demo/Models/MenuKeys.cs b/demo/Ursa.Demo/Models/MenuKeys.cs index 17bf7b3..8532a7f 100644 --- a/demo/Ursa.Demo/Models/MenuKeys.cs +++ b/demo/Ursa.Demo/Models/MenuKeys.cs @@ -10,6 +10,7 @@ public static class MenuKeys public const string MenuKeyDualBadge = "DualBadge"; public const string MenuKeyImageViewer = "ImageViewer"; public const string MenuKeyIpBox = "IPv4Box"; + public const string MenuKeyIconButton = "IconButton"; public const string MenuKeyKeyGestureInput = "KeyGestureInput"; public const string MenuKeyLoading = "Loading"; public const string MenuKeyNavigation = "Navigation"; diff --git a/demo/Ursa.Demo/Pages/IconButtonDemo.axaml b/demo/Ursa.Demo/Pages/IconButtonDemo.axaml new file mode 100644 index 0000000..83252fe --- /dev/null +++ b/demo/Ursa.Demo/Pages/IconButtonDemo.axaml @@ -0,0 +1,14 @@ + + + + + diff --git a/demo/Ursa.Demo/Pages/IconButtonDemo.axaml.cs b/demo/Ursa.Demo/Pages/IconButtonDemo.axaml.cs new file mode 100644 index 0000000..4b2931d --- /dev/null +++ b/demo/Ursa.Demo/Pages/IconButtonDemo.axaml.cs @@ -0,0 +1,13 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace Ursa.Demo.Pages; + +public partial class IconButtonDemo : UserControl +{ + public IconButtonDemo() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/demo/Ursa.Demo/ViewModels/IconButtonDemoViewModel.cs b/demo/Ursa.Demo/ViewModels/IconButtonDemoViewModel.cs new file mode 100644 index 0000000..a75fe5a --- /dev/null +++ b/demo/Ursa.Demo/ViewModels/IconButtonDemoViewModel.cs @@ -0,0 +1,8 @@ +using CommunityToolkit.Mvvm.ComponentModel; + +namespace Ursa.Demo.ViewModels; + +public class IconButtonDemoViewModel: ObservableObject +{ + +} \ No newline at end of file diff --git a/demo/Ursa.Demo/ViewModels/MainViewViewModel.cs b/demo/Ursa.Demo/ViewModels/MainViewViewModel.cs index cefd8f3..d2c59ba 100644 --- a/demo/Ursa.Demo/ViewModels/MainViewViewModel.cs +++ b/demo/Ursa.Demo/ViewModels/MainViewViewModel.cs @@ -31,6 +31,7 @@ public class MainViewViewModel : ViewModelBase MenuKeys.MenuKeyDivider => new DividerDemoViewModel(), MenuKeys.MenuKeyDualBadge => new DualBadgeDemoViewModel(), MenuKeys.MenuKeyImageViewer => new ImageViewerDemoViewModel(), + MenuKeys.MenuKeyIconButton => new IconButtonDemoViewModel(), MenuKeys.MenuKeyIpBox => new IPv4BoxDemoViewModel(), MenuKeys.MenuKeyKeyGestureInput => new KeyGestureInputDemoViewModel(), MenuKeys.MenuKeyLoading => new LoadingDemoViewModel(), diff --git a/demo/Ursa.Demo/ViewModels/MenuViewModel.cs b/demo/Ursa.Demo/ViewModels/MenuViewModel.cs index a091983..b2f04b0 100644 --- a/demo/Ursa.Demo/ViewModels/MenuViewModel.cs +++ b/demo/Ursa.Demo/ViewModels/MenuViewModel.cs @@ -17,6 +17,7 @@ public class MenuViewModel: ViewModelBase new() { MenuHeader = "ButtonGroup", Key = MenuKeys.MenuKeyButtonGroup }, new() { MenuHeader = "Divider", Key = MenuKeys.MenuKeyDivider }, new() { MenuHeader = "DualBadge", Key = MenuKeys.MenuKeyDualBadge }, + new() { MenuHeader = "IconButton", Key = MenuKeys.MenuKeyIconButton }, new() { MenuHeader = "ImageViewer", Key = MenuKeys.MenuKeyImageViewer }, new() { MenuHeader = "IPv4Box", Key = MenuKeys.MenuKeyIpBox }, new() { MenuHeader = "KeyGestureInput", Key = MenuKeys.MenuKeyKeyGestureInput }, diff --git a/src/Ursa.Themes.Semi/Controls/IconButton.axaml b/src/Ursa.Themes.Semi/Controls/IconButton.axaml new file mode 100644 index 0000000..e60b722 --- /dev/null +++ b/src/Ursa.Themes.Semi/Controls/IconButton.axaml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/Ursa.Themes.Semi/Controls/_index.axaml b/src/Ursa.Themes.Semi/Controls/_index.axaml index c7bf111..f3b1ac5 100644 --- a/src/Ursa.Themes.Semi/Controls/_index.axaml +++ b/src/Ursa.Themes.Semi/Controls/_index.axaml @@ -6,6 +6,7 @@ + diff --git a/src/Ursa/Controls/IconButton.cs b/src/Ursa/Controls/IconButton.cs new file mode 100644 index 0000000..0016137 --- /dev/null +++ b/src/Ursa/Controls/IconButton.cs @@ -0,0 +1,35 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Controls.Templates; + +namespace Ursa.Controls; + +public class IconButton: Button +{ + public static readonly StyledProperty IconProperty = AvaloniaProperty.Register( + nameof(Icon)); + + public object? Icon + { + get => GetValue(IconProperty); + set => SetValue(IconProperty, value); + } + + public static readonly StyledProperty IconTemplateProperty = AvaloniaProperty.Register( + nameof(IconTemplate)); + + public IDataTemplate? IconTemplate + { + get => GetValue(IconTemplateProperty); + set => SetValue(IconTemplateProperty, value); + } + + public static readonly StyledProperty IsLoadingProperty = AvaloniaProperty.Register( + nameof(IsLoading)); + + public bool IsLoading + { + get => GetValue(IsLoadingProperty); + set => SetValue(IsLoadingProperty, value); + } +} \ No newline at end of file From 08c010588828f59cc7f3a4c78c5e4380253afe3c Mon Sep 17 00:00:00 2001 From: rabbitism Date: Sat, 6 Jan 2024 16:39:19 +0800 Subject: [PATCH 2/4] feat: add styles. --- demo/Ursa.Demo/Pages/IconButtonDemo.axaml | 24 ++++- .../Controls/IconButton.axaml | 93 ++++++++++++++++++- 2 files changed, 111 insertions(+), 6 deletions(-) diff --git a/demo/Ursa.Demo/Pages/IconButtonDemo.axaml b/demo/Ursa.Demo/Pages/IconButtonDemo.axaml index 83252fe..8d49e69 100644 --- a/demo/Ursa.Demo/Pages/IconButtonDemo.axaml +++ b/demo/Ursa.Demo/Pages/IconButtonDemo.axaml @@ -8,7 +8,27 @@ d:DesignHeight="450" d:DesignWidth="800" mc:Ignorable="d"> - - + + M12.0101 1C5.92171 1 1 5.92171 1 12.0101C1 16.8771 4.15354 20.9967 8.5284 22.455C9.07526 22.5644 9.27577 22.218 9.27577 21.9264C9.27577 21.6712 9.25754 20.7962 9.25754 19.8848C6.19514 20.541 5.55714 18.5723 5.55714 18.5723C5.06497 17.2963 4.33583 16.9682 4.33583 16.9682C3.33326 16.2938 4.40874 16.2938 4.40874 16.2938C5.52069 16.3667 6.104 17.4239 6.104 17.4239C7.08834 19.101 8.67423 18.627 9.31223 18.3354C9.40337 17.6245 9.69503 17.1323 10.0049 16.8589C7.56229 16.6037 4.99206 15.6558 4.99206 11.4267C4.99206 10.2237 5.42954 9.23931 6.12223 8.47371C6.01286 8.20028 5.63006 7.07011 6.2316 5.55714C6.2316 5.55714 7.16126 5.26548 9.25754 6.68731C10.1325 6.45034 11.0804 6.32274 12.0101 6.32274C12.9397 6.32274 13.8876 6.45034 14.7626 6.68731C16.8589 5.26548 17.7885 5.55714 17.7885 5.55714C18.3901 7.07011 18.0073 8.20028 17.8979 8.47371C18.6088 9.23931 19.0281 10.2237 19.0281 11.4267C19.0281 15.6558 16.4578 16.5854 13.997 16.8589C14.398 17.2052 14.7443 17.8614 14.7443 18.9004C14.7443 20.377 14.7261 21.5618 14.7261 21.9264C14.7261 22.218 14.9266 22.5644 15.4735 22.455C19.8483 20.9967 23.0019 16.8771 23.0019 12.0101C23.0201 5.92171 18.0802 1 12.0101 1Z + + + + + + + + + + + + + + diff --git a/src/Ursa.Themes.Semi/Controls/IconButton.axaml b/src/Ursa.Themes.Semi/Controls/IconButton.axaml index e60b722..fe9fdf3 100644 --- a/src/Ursa.Themes.Semi/Controls/IconButton.axaml +++ b/src/Ursa.Themes.Semi/Controls/IconButton.axaml @@ -4,21 +4,106 @@ xmlns:u="https://irihi.tech/ursa"> + + + + + + + + + + + + + + - + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + From e5e7f020e3d787a68f6730efb39dbccd86b27772 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Sat, 6 Jan 2024 16:50:00 +0800 Subject: [PATCH 3/4] feat: add more themes and demo. --- demo/Ursa.Demo/Pages/IconButtonDemo.axaml | 67 +++++++++- .../Controls/IconButton.axaml | 117 ++++++++++++++++++ 2 files changed, 183 insertions(+), 1 deletion(-) diff --git a/demo/Ursa.Demo/Pages/IconButtonDemo.axaml b/demo/Ursa.Demo/Pages/IconButtonDemo.axaml index 8d49e69..44f7c93 100644 --- a/demo/Ursa.Demo/Pages/IconButtonDemo.axaml +++ b/demo/Ursa.Demo/Pages/IconButtonDemo.axaml @@ -22,7 +22,72 @@ Data="{StaticResource iconGlyph}" /> - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 1312ab612869b09e4e404ee34e780c72fc3848c4 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Sat, 6 Jan 2024 20:44:01 +0800 Subject: [PATCH 4/4] feat: add placement. --- demo/Ursa.Demo/Pages/IconButtonDemo.axaml | 8 +++++ .../Controls/IconButton.axaml | 28 +++++++++++---- src/Ursa/Common/IconPlacement.cs | 7 ++++ src/Ursa/Controls/IconButton.cs | 34 +++++++++++++++++++ 4 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 src/Ursa/Common/IconPlacement.cs diff --git a/demo/Ursa.Demo/Pages/IconButtonDemo.axaml b/demo/Ursa.Demo/Pages/IconButtonDemo.axaml index 44f7c93..a6e611a 100644 --- a/demo/Ursa.Demo/Pages/IconButtonDemo.axaml +++ b/demo/Ursa.Demo/Pages/IconButtonDemo.axaml @@ -22,6 +22,14 @@ Data="{StaticResource iconGlyph}" /> + + + + + - + - + - + @@ -99,6 +103,16 @@ + + + + @@ -106,8 +120,8 @@ - - diff --git a/src/Ursa/Common/IconPlacement.cs b/src/Ursa/Common/IconPlacement.cs new file mode 100644 index 0000000..c38cec6 --- /dev/null +++ b/src/Ursa/Common/IconPlacement.cs @@ -0,0 +1,7 @@ +namespace Ursa.Common; + +public enum IconPlacement +{ + Left, + Right, +} \ No newline at end of file diff --git a/src/Ursa/Controls/IconButton.cs b/src/Ursa/Controls/IconButton.cs index 0016137..b4c5039 100644 --- a/src/Ursa/Controls/IconButton.cs +++ b/src/Ursa/Controls/IconButton.cs @@ -1,11 +1,17 @@ using Avalonia; using Avalonia.Controls; +using Avalonia.Controls.Metadata; +using Avalonia.Controls.Primitives; using Avalonia.Controls.Templates; +using Ursa.Common; namespace Ursa.Controls; +[PseudoClasses(PC_Right)] public class IconButton: Button { + public const string PC_Right = ":right"; + public static readonly StyledProperty IconProperty = AvaloniaProperty.Register( nameof(Icon)); @@ -32,4 +38,32 @@ public class IconButton: Button get => GetValue(IsLoadingProperty); set => SetValue(IsLoadingProperty, value); } + + public static readonly StyledProperty IconPlacementProperty = AvaloniaProperty.Register( + nameof(IconPlacement), defaultValue: IconPlacement.Left); + + public IconPlacement IconPlacement + { + get => GetValue(IconPlacementProperty); + set => SetValue(IconPlacementProperty, value); + } + + static IconButton() + { + IconPlacementProperty.Changed.AddClassHandler((o, e) => + { + o.SetPlacement(e.NewValue.Value); + }); + } + + protected override void OnApplyTemplate(TemplateAppliedEventArgs e) + { + base.OnApplyTemplate(e); + SetPlacement(IconPlacement); + } + + private void SetPlacement(IconPlacement placement) + { + PseudoClasses.Set(PC_Right, placement == IconPlacement.Right); + } } \ No newline at end of file