From 61ebba897b2cb65161e62b64116873d7744faa7f Mon Sep 17 00:00:00 2001 From: rabbitism Date: Tue, 23 Jan 2024 19:55:23 +0800 Subject: [PATCH] feat: extract common button style. --- src/Ursa.Themes.Semi/Controls/Dialog.axaml | 33 +++++++++++---- .../Controls/DialogShared.axaml | 42 +++++++++++++++++++ .../Controls/MessageBoxWindow.axaml | 18 +------- src/Ursa.Themes.Semi/Controls/_index.axaml | 1 + src/Ursa/Common/DialogButton.cs | 11 +++++ src/Ursa/Common/DialogIcon.cs | 15 +++++++ src/Ursa/Common/DialogResult.cs | 10 +++++ src/Ursa/Controls/Dialog/DialogControl.cs | 24 ++++++++++- src/Ursa/Controls/Dialog/OverlayDialogHost.cs | 32 ++++---------- 9 files changed, 137 insertions(+), 49 deletions(-) create mode 100644 src/Ursa.Themes.Semi/Controls/DialogShared.axaml create mode 100644 src/Ursa/Common/DialogButton.cs create mode 100644 src/Ursa/Common/DialogIcon.cs create mode 100644 src/Ursa/Common/DialogResult.cs diff --git a/src/Ursa.Themes.Semi/Controls/Dialog.axaml b/src/Ursa.Themes.Semi/Controls/Dialog.axaml index 2b8df2a..160f6b8 100644 --- a/src/Ursa.Themes.Semi/Controls/Dialog.axaml +++ b/src/Ursa.Themes.Semi/Controls/Dialog.axaml @@ -7,18 +7,29 @@ - - - + + + + @@ -58,8 +69,16 @@ - - + + diff --git a/src/Ursa.Themes.Semi/Controls/DialogShared.axaml b/src/Ursa.Themes.Semi/Controls/DialogShared.axaml new file mode 100644 index 0000000..e4a1fd2 --- /dev/null +++ b/src/Ursa.Themes.Semi/Controls/DialogShared.axaml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Ursa.Themes.Semi/Controls/MessageBoxWindow.axaml b/src/Ursa.Themes.Semi/Controls/MessageBoxWindow.axaml index c0f4913..7e5bd25 100644 --- a/src/Ursa.Themes.Semi/Controls/MessageBoxWindow.axaml +++ b/src/Ursa.Themes.Semi/Controls/MessageBoxWindow.axaml @@ -45,23 +45,7 @@ Name="{x:Static u:MessageBoxWindow.PART_CloseButton}" Grid.Column="1" Margin="0,4,4,0" - Background="{DynamicResource CaptionButtonClosePointeroverBackground}" - BorderBrush="{DynamicResource CaptionButtonClosePressedBackground}" - Theme="{DynamicResource CaptionButton}"> - - - - - - + Theme="{DynamicResource CloseButton}"/> + diff --git a/src/Ursa/Common/DialogButton.cs b/src/Ursa/Common/DialogButton.cs new file mode 100644 index 0000000..32e9e4c --- /dev/null +++ b/src/Ursa/Common/DialogButton.cs @@ -0,0 +1,11 @@ +namespace Ursa.Common; + +public enum DialogButton +{ + None, + OK, + OKCancel, + YesNo, + YesNoCancel, +} + diff --git a/src/Ursa/Common/DialogIcon.cs b/src/Ursa/Common/DialogIcon.cs new file mode 100644 index 0000000..e8a0deb --- /dev/null +++ b/src/Ursa/Common/DialogIcon.cs @@ -0,0 +1,15 @@ +namespace Ursa.Common; + +public enum DialogIcon +{ + Asterisk, // Same as Information + Error, + Exclamation, // Same as Warning + Hand, // Same as Error + Information, + None, + Question, + Stop, // Same as Error + Warning, + Success, +} \ No newline at end of file diff --git a/src/Ursa/Common/DialogResult.cs b/src/Ursa/Common/DialogResult.cs new file mode 100644 index 0000000..36b8df4 --- /dev/null +++ b/src/Ursa/Common/DialogResult.cs @@ -0,0 +1,10 @@ +namespace Ursa.Common; + +public enum DialogResult +{ + Cancel, + No, + None, + OK, + Yes, +} \ No newline at end of file diff --git a/src/Ursa/Controls/Dialog/DialogControl.cs b/src/Ursa/Controls/Dialog/DialogControl.cs index 10a4ef5..967d0a9 100644 --- a/src/Ursa/Controls/Dialog/DialogControl.cs +++ b/src/Ursa/Controls/Dialog/DialogControl.cs @@ -2,16 +2,20 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Metadata; using Avalonia.Controls.Primitives; +using Avalonia.Input; using Avalonia.Interactivity; namespace Ursa.Controls; [TemplatePart(PART_CloseButton, typeof(Button))] +[TemplatePart(PART_TitleArea, typeof(Panel))] public class DialogControl: ContentControl { public const string PART_CloseButton = "PART_CloseButton"; + public const string PART_TitleArea = "PART_TitleArea"; private Button? _closeButton; + private Panel? _titleArea; public event EventHandler? OnClose; static DialogControl() @@ -32,6 +36,7 @@ public class DialogControl: ContentControl } } + protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { @@ -40,13 +45,30 @@ public class DialogControl: ContentControl { _closeButton.Click -= Close; } + _titleArea?.RemoveHandler(PointerMovedEvent, OnTitlePointerMove); + _titleArea?.RemoveHandler(PointerPressedEvent, OnTitlePointerPressed); + _closeButton = e.NameScope.Find