From 12122f8cac998568223a6d8bccb485a3de3628ad Mon Sep 17 00:00:00 2001 From: rabbitism Date: Tue, 13 Aug 2024 18:07:12 +0800 Subject: [PATCH 1/7] feat: single view trial. --- demo/Ursa.Demo/Views/MainWindow.axaml | 4 +- demo/Ursa.Demo/Views/SingleView.axaml | 12 ++-- demo/Ursa.Demo/Views/SingleView.axaml.cs | 3 +- .../Views/TitleBarRightContent.axaml | 20 +++++++ .../Views/TitleBarRightContent.axaml.cs | 23 ++++++++ src/Ursa.Themes.Semi/Controls/UrsaView.axaml | 35 ++++++++++++ src/Ursa.Themes.Semi/Controls/_index.axaml | 1 + src/Ursa/Windows/UrsaView.cs | 55 +++++++++++++++++++ 8 files changed, 143 insertions(+), 10 deletions(-) create mode 100644 demo/Ursa.Demo/Views/TitleBarRightContent.axaml create mode 100644 demo/Ursa.Demo/Views/TitleBarRightContent.axaml.cs create mode 100644 src/Ursa.Themes.Semi/Controls/UrsaView.axaml create mode 100644 src/Ursa/Windows/UrsaView.cs diff --git a/demo/Ursa.Demo/Views/MainWindow.axaml b/demo/Ursa.Demo/Views/MainWindow.axaml index 45760f58..d548ae68 100644 --- a/demo/Ursa.Demo/Views/MainWindow.axaml +++ b/demo/Ursa.Demo/Views/MainWindow.axaml @@ -16,9 +16,7 @@ Icon="/Assets/Ursa.ico" mc:Ignorable="d"> - + \ No newline at end of file diff --git a/demo/Ursa.Demo/Views/SingleView.axaml b/demo/Ursa.Demo/Views/SingleView.axaml index 20659738..f447a48d 100644 --- a/demo/Ursa.Demo/Views/SingleView.axaml +++ b/demo/Ursa.Demo/Views/SingleView.axaml @@ -1,4 +1,4 @@ - - - - - - + + + + + diff --git a/demo/Ursa.Demo/Views/SingleView.axaml.cs b/demo/Ursa.Demo/Views/SingleView.axaml.cs index 5a20b4f5..ca15c4c7 100644 --- a/demo/Ursa.Demo/Views/SingleView.axaml.cs +++ b/demo/Ursa.Demo/Views/SingleView.axaml.cs @@ -1,8 +1,9 @@ using Avalonia.Controls; +using Ursa.Controls; namespace Ursa.Demo.Views; -public partial class SingleView : UserControl +public partial class SingleView : UrsaView { public SingleView() { diff --git a/demo/Ursa.Demo/Views/TitleBarRightContent.axaml b/demo/Ursa.Demo/Views/TitleBarRightContent.axaml new file mode 100644 index 00000000..dd4d12b9 --- /dev/null +++ b/demo/Ursa.Demo/Views/TitleBarRightContent.axaml @@ -0,0 +1,20 @@ + + + + + + diff --git a/demo/Ursa.Demo/Views/TitleBarRightContent.axaml.cs b/demo/Ursa.Demo/Views/TitleBarRightContent.axaml.cs new file mode 100644 index 00000000..026dc574 --- /dev/null +++ b/demo/Ursa.Demo/Views/TitleBarRightContent.axaml.cs @@ -0,0 +1,23 @@ +using System; +using Avalonia; +using Avalonia.Controls; +using Avalonia.Interactivity; +using Avalonia.Markup.Xaml; + +namespace Ursa.Demo.Views; + +public partial class TitleBarRightContent : UserControl +{ + public TitleBarRightContent() + { + InitializeComponent(); + } + + private async void OpenRepository(object? sender, RoutedEventArgs e) + { + var top = TopLevel.GetTopLevel(this); + if (top is null) return; + var launcher = top.Launcher; + await launcher.LaunchUriAsync(new Uri("https://github.com/irihitech/Semi.Avalonia")); + } +} \ No newline at end of file diff --git a/src/Ursa.Themes.Semi/Controls/UrsaView.axaml b/src/Ursa.Themes.Semi/Controls/UrsaView.axaml new file mode 100644 index 00000000..e67c584f --- /dev/null +++ b/src/Ursa.Themes.Semi/Controls/UrsaView.axaml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Ursa.Themes.Semi/Controls/_index.axaml b/src/Ursa.Themes.Semi/Controls/_index.axaml index 36e75e77..bec20a14 100644 --- a/src/Ursa.Themes.Semi/Controls/_index.axaml +++ b/src/Ursa.Themes.Semi/Controls/_index.axaml @@ -48,6 +48,7 @@ + diff --git a/src/Ursa/Windows/UrsaView.cs b/src/Ursa/Windows/UrsaView.cs new file mode 100644 index 00000000..36e48284 --- /dev/null +++ b/src/Ursa/Windows/UrsaView.cs @@ -0,0 +1,55 @@ +using Avalonia; +using Avalonia.Controls; + +namespace Ursa.Controls; + +/// +/// Ursa window is designed to +/// +public class UrsaView: ContentControl +{ + public static readonly StyledProperty IsTitleBarVisibleProperty = + UrsaWindow.IsTitleBarVisibleProperty.AddOwner(); + + public bool IsTitleBarVisible + { + get => GetValue(IsTitleBarVisibleProperty); + set => SetValue(IsTitleBarVisibleProperty, value); + } + + public static readonly StyledProperty LeftContentProperty = + UrsaWindow.LeftContentProperty.AddOwner(); + + public object? LeftContent + { + get => GetValue(LeftContentProperty); + set => SetValue(LeftContentProperty, value); + } + + public static readonly StyledProperty RightContentProperty = + UrsaWindow.RightContentProperty.AddOwner(); + + public object? RightContent + { + get => GetValue(RightContentProperty); + set => SetValue(RightContentProperty, value); + } + + public static readonly StyledProperty TitleBarContentProperty = + UrsaWindow.TitleBarContentProperty.AddOwner(); + + public object? TitleBarContent + { + get => GetValue(TitleBarContentProperty); + set => SetValue(TitleBarContentProperty, value); + } + + public static readonly StyledProperty TitleBarMarginProperty = + UrsaWindow.TitleBarMarginProperty.AddOwner(); + + public Thickness TitleBarMargin + { + get => GetValue(TitleBarMarginProperty); + set => SetValue(TitleBarMarginProperty, value); + } +} \ No newline at end of file From 7479cff1101f404b4ef81f86e918bda79e054434 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Tue, 13 Aug 2024 18:09:15 +0800 Subject: [PATCH 2/7] tst --- demo/Ursa.Demo/App.axaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/Ursa.Demo/App.axaml b/demo/Ursa.Demo/App.axaml index 9ac19d2b..418891cc 100644 --- a/demo/Ursa.Demo/App.axaml +++ b/demo/Ursa.Demo/App.axaml @@ -1,7 +1,7 @@ From 2789f88fc773e4ebf258b20bee36ee46ff7a6aa7 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Tue, 13 Aug 2024 22:53:35 +0800 Subject: [PATCH 3/7] feat: make UrsaView base. --- demo/Ursa.Demo/App.axaml.cs | 4 +++- src/Ursa.Themes.Semi/Controls/UrsaView.axaml | 11 ++++++----- src/Ursa.Themes.Semi/Styles/UrsaView.axaml | 14 ++++++++++++++ src/Ursa.Themes.Semi/Styles/_index.axaml | 1 + 4 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 src/Ursa.Themes.Semi/Styles/UrsaView.axaml diff --git a/demo/Ursa.Demo/App.axaml.cs b/demo/Ursa.Demo/App.axaml.cs index 1b2ba8ae..71665e93 100644 --- a/demo/Ursa.Demo/App.axaml.cs +++ b/demo/Ursa.Demo/App.axaml.cs @@ -1,4 +1,5 @@ using Avalonia; +using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; using Ursa.Demo.ViewModels; @@ -17,8 +18,9 @@ public override void OnFrameworkInitializationCompleted() { if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { - desktop.MainWindow = new MainWindow() + desktop.MainWindow = new Window() { + Content = new SingleView(), DataContext = new MainViewViewModel(), }; } diff --git a/src/Ursa.Themes.Semi/Controls/UrsaView.axaml b/src/Ursa.Themes.Semi/Controls/UrsaView.axaml index e67c584f..92c0989c 100644 --- a/src/Ursa.Themes.Semi/Controls/UrsaView.axaml +++ b/src/Ursa.Themes.Semi/Controls/UrsaView.axaml @@ -20,12 +20,13 @@ VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" /> - + Margin="{Binding $parent[u:UrsaWindow].TitleBarMargin}"> + + + + diff --git a/src/Ursa.Themes.Semi/Styles/UrsaView.axaml b/src/Ursa.Themes.Semi/Styles/UrsaView.axaml new file mode 100644 index 00000000..b2430456 --- /dev/null +++ b/src/Ursa.Themes.Semi/Styles/UrsaView.axaml @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/src/Ursa.Themes.Semi/Styles/_index.axaml b/src/Ursa.Themes.Semi/Styles/_index.axaml index 8de34d29..e17a4a31 100644 --- a/src/Ursa.Themes.Semi/Styles/_index.axaml +++ b/src/Ursa.Themes.Semi/Styles/_index.axaml @@ -10,5 +10,6 @@ + From b04f83f340d06d715982832ef9fc321d95970879 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Wed, 14 Aug 2024 09:45:20 +0800 Subject: [PATCH 4/7] feat: revert test window. --- demo/Ursa.Demo/App.axaml.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/demo/Ursa.Demo/App.axaml.cs b/demo/Ursa.Demo/App.axaml.cs index 71665e93..980608c6 100644 --- a/demo/Ursa.Demo/App.axaml.cs +++ b/demo/Ursa.Demo/App.axaml.cs @@ -18,9 +18,8 @@ public override void OnFrameworkInitializationCompleted() { if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { - desktop.MainWindow = new Window() + desktop.MainWindow = new MainWindow() { - Content = new SingleView(), DataContext = new MainViewViewModel(), }; } From 74994e77f73ff9f70a47f89a848842cda34cf134 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Wed, 14 Aug 2024 18:23:56 +0800 Subject: [PATCH 5/7] feat: make titlebar visible property actually useful. --- src/Ursa.Themes.Semi/Controls/UrsaView.axaml | 32 +++++++++++++------ .../Controls/UrsaWindow.axaml | 4 +++ src/Ursa/Controls/TitleBar/TitleBar.cs | 9 ++++++ src/Ursa/Windows/UrsaWindow.cs | 2 +- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/Ursa.Themes.Semi/Controls/UrsaView.axaml b/src/Ursa.Themes.Semi/Controls/UrsaView.axaml index 92c0989c..fb7bb62f 100644 --- a/src/Ursa.Themes.Semi/Controls/UrsaView.axaml +++ b/src/Ursa.Themes.Semi/Controls/UrsaView.axaml @@ -1,7 +1,8 @@ - - + + @@ -20,12 +21,25 @@ VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" /> - - - - + ColumnDefinitions="Auto, *, Auto"> + + + diff --git a/src/Ursa.Themes.Semi/Controls/UrsaWindow.axaml b/src/Ursa.Themes.Semi/Controls/UrsaWindow.axaml index ebe33e1e..b651a881 100644 --- a/src/Ursa.Themes.Semi/Controls/UrsaWindow.axaml +++ b/src/Ursa.Themes.Semi/Controls/UrsaWindow.axaml @@ -60,6 +60,7 @@ GetValue(RightContentProperty); set => SetValue(RightContentProperty, value); } + + public static readonly StyledProperty IsTitleVisibleProperty = AvaloniaProperty.Register( + nameof(IsTitleVisible)); + + public bool IsTitleVisible + { + get => GetValue(IsTitleVisibleProperty); + set => SetValue(IsTitleVisibleProperty, value); + } protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { diff --git a/src/Ursa/Windows/UrsaWindow.cs b/src/Ursa/Windows/UrsaWindow.cs index a23ea2bc..73ebd676 100644 --- a/src/Ursa/Windows/UrsaWindow.cs +++ b/src/Ursa/Windows/UrsaWindow.cs @@ -47,7 +47,7 @@ public bool IsCloseButtonVisible } public static readonly StyledProperty IsTitleBarVisibleProperty = AvaloniaProperty.Register( - nameof(IsTitleBarVisible)); + nameof(IsTitleBarVisible), true); public bool IsTitleBarVisible { From 8c2aa378f4545f1fd812137362bb7a6e46a9b518 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Wed, 14 Aug 2024 22:05:36 +0800 Subject: [PATCH 6/7] fix: fix titlebar visibility. --- src/Ursa.Themes.Semi/Controls/UrsaWindow.axaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ursa.Themes.Semi/Controls/UrsaWindow.axaml b/src/Ursa.Themes.Semi/Controls/UrsaWindow.axaml index b651a881..3487f478 100644 --- a/src/Ursa.Themes.Semi/Controls/UrsaWindow.axaml +++ b/src/Ursa.Themes.Semi/Controls/UrsaWindow.axaml @@ -60,7 +60,7 @@ Date: Wed, 14 Aug 2024 22:14:21 +0800 Subject: [PATCH 7/7] Update demo/Ursa.Demo/Views/TitleBarRightContent.axaml.cs Co-authored-by: Zhang Dian <54255897+zdpcdt@users.noreply.github.com> --- demo/Ursa.Demo/Views/TitleBarRightContent.axaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/Ursa.Demo/Views/TitleBarRightContent.axaml.cs b/demo/Ursa.Demo/Views/TitleBarRightContent.axaml.cs index 026dc574..fe9da4da 100644 --- a/demo/Ursa.Demo/Views/TitleBarRightContent.axaml.cs +++ b/demo/Ursa.Demo/Views/TitleBarRightContent.axaml.cs @@ -18,6 +18,6 @@ private async void OpenRepository(object? sender, RoutedEventArgs e) var top = TopLevel.GetTopLevel(this); if (top is null) return; var launcher = top.Launcher; - await launcher.LaunchUriAsync(new Uri("https://github.com/irihitech/Semi.Avalonia")); + await launcher.LaunchUriAsync(new Uri("https://github.com/irihitech/Ursa.Avalonia")); } } \ No newline at end of file