From fd9a8668c5c8dd0f52b47ae1b0941dc075131893 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Tue, 25 Jun 2024 21:49:23 +0800 Subject: [PATCH 1/5] feat: WIP. --- demo/Ursa.Demo/Views/MainWindow.axaml | 5 +- .../Controls/UrsaWindow.axaml | 8 +++ src/Ursa/Windows/UrsaWindow.cs | 50 +++++++++++++++++++ 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 src/Ursa.Themes.Semi/Controls/UrsaWindow.axaml create mode 100644 src/Ursa/Windows/UrsaWindow.cs diff --git a/demo/Ursa.Demo/Views/MainWindow.axaml b/demo/Ursa.Demo/Views/MainWindow.axaml index 054e043..86de1ef 100644 --- a/demo/Ursa.Demo/Views/MainWindow.axaml +++ b/demo/Ursa.Demo/Views/MainWindow.axaml @@ -1,10 +1,11 @@ - - \ No newline at end of file + \ No newline at end of file diff --git a/src/Ursa.Themes.Semi/Controls/UrsaWindow.axaml b/src/Ursa.Themes.Semi/Controls/UrsaWindow.axaml new file mode 100644 index 0000000..ae6cb6e --- /dev/null +++ b/src/Ursa.Themes.Semi/Controls/UrsaWindow.axaml @@ -0,0 +1,8 @@ + + + + + + diff --git a/src/Ursa/Windows/UrsaWindow.cs b/src/Ursa/Windows/UrsaWindow.cs new file mode 100644 index 0000000..d315151 --- /dev/null +++ b/src/Ursa/Windows/UrsaWindow.cs @@ -0,0 +1,50 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Platform; + +namespace Ursa.Controls; + +/// +/// Ursa Window is an advanced Window control that provides a lot of features and customization options. +/// +public class UrsaWindow: Window +{ + public static readonly StyledProperty ShowFullScreenButtonProperty = AvaloniaProperty.Register( + nameof(ShowFullScreenButton), false); + + public bool ShowFullScreenButton + { + get => GetValue(ShowFullScreenButtonProperty); + set => SetValue(ShowFullScreenButtonProperty, value); + } + + public static readonly StyledProperty ShowMaximumButtonProperty = AvaloniaProperty.Register( + nameof(ShowMaximumButton)); + + public bool ShowMaximumButton + { + get => GetValue(ShowMaximumButtonProperty); + set => SetValue(ShowMaximumButtonProperty, value); + } + + public static readonly StyledProperty ShowMinimumButtonProperty = AvaloniaProperty.Register( + nameof(ShowMinimumButton)); + + public bool ShowMinimumButton + { + get => GetValue(ShowMinimumButtonProperty); + set => SetValue(ShowMinimumButtonProperty, value); + } + + public static readonly StyledProperty ShowCloseButtonProperty = AvaloniaProperty.Register( + nameof(ShowCloseButton)); + + public bool ShowCloseButton + { + get => GetValue(ShowCloseButtonProperty); + set => SetValue(ShowCloseButtonProperty, value); + } + + + +} \ No newline at end of file From 26873208a85dd62bed3643a8128860fabf0308aa Mon Sep 17 00:00:00 2001 From: rabbitism Date: Wed, 26 Jun 2024 21:04:50 +0800 Subject: [PATCH 2/5] feat: implement title bar and caption buttons. --- demo/Ursa.Demo/Views/MainView.axaml | 13 +- demo/Ursa.Demo/Views/MainWindow.axaml | 6 + demo/Ursa.Demo/Views/MainWindow.axaml.cs | 4 +- .../Controls/UrsaWindow.axaml | 140 +++++++++++++++++- src/Ursa.Themes.Semi/Controls/_index.axaml | 1 + src/Ursa/Controls/TitleBar/CaptionButtons.cs | 75 ++++++++++ src/Ursa/Controls/TitleBar/TitleBar.cs | 91 ++++++++++++ src/Ursa/Windows/UrsaWindow.cs | 86 ++++++++--- 8 files changed, 379 insertions(+), 37 deletions(-) create mode 100644 src/Ursa/Controls/TitleBar/CaptionButtons.cs create mode 100644 src/Ursa/Controls/TitleBar/TitleBar.cs diff --git a/demo/Ursa.Demo/Views/MainView.axaml b/demo/Ursa.Demo/Views/MainView.axaml index 9e31e57..e01f3f1 100644 --- a/demo/Ursa.Demo/Views/MainView.axaml +++ b/demo/Ursa.Demo/Views/MainView.axaml @@ -22,8 +22,7 @@ + ColumnDefinitions="Auto, *" > + + + + + + + diff --git a/src/Ursa.Themes.Semi/Controls/_index.axaml b/src/Ursa.Themes.Semi/Controls/_index.axaml index 4d7ae82..4ecab88 100644 --- a/src/Ursa.Themes.Semi/Controls/_index.axaml +++ b/src/Ursa.Themes.Semi/Controls/_index.axaml @@ -43,6 +43,7 @@ + diff --git a/src/Ursa/Controls/TitleBar/CaptionButtons.cs b/src/Ursa/Controls/TitleBar/CaptionButtons.cs new file mode 100644 index 0000000..2ff0aeb --- /dev/null +++ b/src/Ursa/Controls/TitleBar/CaptionButtons.cs @@ -0,0 +1,75 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Controls.Metadata; +using Avalonia.Controls.Primitives; +using Irihi.Avalonia.Shared.Helpers; +using Irihi.Avalonia.Shared.Reactive; + +namespace Ursa.Controls; + +[TemplatePart(PART_CloseButton, typeof (Button))] +[TemplatePart(PART_RestoreButton, typeof (Button))] +[TemplatePart(PART_MinimizeButton, typeof (Button))] +[TemplatePart(PART_FullScreenButton, typeof (Button))] +[PseudoClasses(":minimized", ":normal", ":maximized", ":fullscreen")] +public class CaptionButtons: Avalonia.Controls.Chrome.CaptionButtons +{ + private const string PART_CloseButton = "PART_CloseButton"; + private const string PART_RestoreButton = "PART_RestoreButton"; + private const string PART_MinimizeButton = "PART_MinimizeButton"; + private const string PART_FullScreenButton = "PART_FullScreenButton"; + + private Button? _closeButton; + private Button? _restoreButton; + private Button? _minimizeButton; + private Button? _fullScreenButton; + + private IDisposable? _visibilityDisposable; + + protected override void OnApplyTemplate(TemplateAppliedEventArgs e) + { + _closeButton = e.NameScope.Get