From 724a528b1603be8af859a50c8b454dcc90cb3ac6 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Thu, 18 Jul 2024 16:45:50 +0800 Subject: [PATCH 1/4] feat: try to fix trimming compatibility. --- .run/SC-Single.run.xml | 2 +- .../Semi.Avalonia.Demo.Desktop.csproj | 5 +++++ demo/Semi.Avalonia.Demo/Roots.xml | 5 ----- demo/Semi.Avalonia.Demo/Semi.Avalonia.Demo.csproj | 1 - src/Package.props | 2 +- src/Semi.Avalonia.ColorPicker/Index.axaml | 4 ++-- .../Semi.Avalonia.ColorPicker.csproj | 4 ++++ src/Semi.Avalonia.DataGrid/Index.axaml | 4 ++-- .../Semi.Avalonia.DataGrid.csproj | 4 ++++ .../Semi.Avalonia.TreeDataGrid.csproj | 4 ++++ src/Semi.Avalonia/Locale/en-us.axaml.cs | 8 ++++++++ src/Semi.Avalonia/Locale/zh-cn.axaml.cs | 8 ++++++++ src/Semi.Avalonia/Semi.Avalonia.csproj | 3 +++ src/Semi.Avalonia/Themes/Index.axaml | 4 ++-- src/Semi.Avalonia/Themes/SemiTheme.axaml | 4 ++-- src/Semi.Avalonia/Themes/SemiTheme.axaml.cs | 15 +++++++-------- 16 files changed, 53 insertions(+), 24 deletions(-) delete mode 100644 demo/Semi.Avalonia.Demo/Roots.xml create mode 100644 src/Semi.Avalonia/Locale/en-us.axaml.cs create mode 100644 src/Semi.Avalonia/Locale/zh-cn.axaml.cs diff --git a/.run/SC-Single.run.xml b/.run/SC-Single.run.xml index 1629fa5..269629d 100644 --- a/.run/SC-Single.run.xml +++ b/.run/SC-Single.run.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/demo/Semi.Avalonia.Demo.Desktop/Semi.Avalonia.Demo.Desktop.csproj b/demo/Semi.Avalonia.Demo.Desktop/Semi.Avalonia.Demo.Desktop.csproj index 14f9ffa..4418249 100644 --- a/demo/Semi.Avalonia.Demo.Desktop/Semi.Avalonia.Demo.Desktop.csproj +++ b/demo/Semi.Avalonia.Demo.Desktop/Semi.Avalonia.Demo.Desktop.csproj @@ -11,6 +11,11 @@ --> + + true + true + + app.manifest diff --git a/demo/Semi.Avalonia.Demo/Roots.xml b/demo/Semi.Avalonia.Demo/Roots.xml deleted file mode 100644 index 22c01ba..0000000 --- a/demo/Semi.Avalonia.Demo/Roots.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/demo/Semi.Avalonia.Demo/Semi.Avalonia.Demo.csproj b/demo/Semi.Avalonia.Demo/Semi.Avalonia.Demo.csproj index 8b1e2c3..757b062 100644 --- a/demo/Semi.Avalonia.Demo/Semi.Avalonia.Demo.csproj +++ b/demo/Semi.Avalonia.Demo/Semi.Avalonia.Demo.csproj @@ -7,7 +7,6 @@ - diff --git a/src/Package.props b/src/Package.props index 3010a44..dd12a5c 100644 --- a/src/Package.props +++ b/src/Package.props @@ -1,6 +1,6 @@ - net6.0;netstandard2.0 + net6.0;net8.0;netstandard2.0 enable latest 11.1.0-rc2 diff --git a/src/Semi.Avalonia.ColorPicker/Index.axaml b/src/Semi.Avalonia.ColorPicker/Index.axaml index 2af9525..32b0f04 100644 --- a/src/Semi.Avalonia.ColorPicker/Index.axaml +++ b/src/Semi.Avalonia.ColorPicker/Index.axaml @@ -2,8 +2,8 @@ - - + + diff --git a/src/Semi.Avalonia.ColorPicker/Semi.Avalonia.ColorPicker.csproj b/src/Semi.Avalonia.ColorPicker/Semi.Avalonia.ColorPicker.csproj index ec355ce..a83a8de 100644 --- a/src/Semi.Avalonia.ColorPicker/Semi.Avalonia.ColorPicker.csproj +++ b/src/Semi.Avalonia.ColorPicker/Semi.Avalonia.ColorPicker.csproj @@ -7,6 +7,10 @@ Update to Avalonia 11.1-rc1 + + true + + diff --git a/src/Semi.Avalonia.DataGrid/Index.axaml b/src/Semi.Avalonia.DataGrid/Index.axaml index 29ddeaa..4d798eb 100644 --- a/src/Semi.Avalonia.DataGrid/Index.axaml +++ b/src/Semi.Avalonia.DataGrid/Index.axaml @@ -2,8 +2,8 @@ - - + + diff --git a/src/Semi.Avalonia.DataGrid/Semi.Avalonia.DataGrid.csproj b/src/Semi.Avalonia.DataGrid/Semi.Avalonia.DataGrid.csproj index d74456e..2d025be 100644 --- a/src/Semi.Avalonia.DataGrid/Semi.Avalonia.DataGrid.csproj +++ b/src/Semi.Avalonia.DataGrid/Semi.Avalonia.DataGrid.csproj @@ -7,6 +7,10 @@ Update to Avalonia 11.1-rc1 + + true + + diff --git a/src/Semi.Avalonia.TreeDataGrid/Semi.Avalonia.TreeDataGrid.csproj b/src/Semi.Avalonia.TreeDataGrid/Semi.Avalonia.TreeDataGrid.csproj index 054e41b..efb7e6d 100644 --- a/src/Semi.Avalonia.TreeDataGrid/Semi.Avalonia.TreeDataGrid.csproj +++ b/src/Semi.Avalonia.TreeDataGrid/Semi.Avalonia.TreeDataGrid.csproj @@ -14,6 +14,10 @@ 11.0.0 + + true + + diff --git a/src/Semi.Avalonia/Locale/en-us.axaml.cs b/src/Semi.Avalonia/Locale/en-us.axaml.cs new file mode 100644 index 0000000..f9a9730 --- /dev/null +++ b/src/Semi.Avalonia/Locale/en-us.axaml.cs @@ -0,0 +1,8 @@ +using Avalonia.Controls; + +namespace Semi.Avalonia.Locale; + +public class en_us: ResourceDictionary +{ + +} \ No newline at end of file diff --git a/src/Semi.Avalonia/Locale/zh-cn.axaml.cs b/src/Semi.Avalonia/Locale/zh-cn.axaml.cs new file mode 100644 index 0000000..530a7de --- /dev/null +++ b/src/Semi.Avalonia/Locale/zh-cn.axaml.cs @@ -0,0 +1,8 @@ +using Avalonia.Controls; + +namespace Semi.Avalonia.Locale; + +public class zh_cn: ResourceDictionary +{ + +} \ No newline at end of file diff --git a/src/Semi.Avalonia/Semi.Avalonia.csproj b/src/Semi.Avalonia/Semi.Avalonia.csproj index 92b1aab..28f222b 100644 --- a/src/Semi.Avalonia/Semi.Avalonia.csproj +++ b/src/Semi.Avalonia/Semi.Avalonia.csproj @@ -5,6 +5,9 @@ Semi.Avalonia Update to Avalonia 11.1-rc1 + + + true diff --git a/src/Semi.Avalonia/Themes/Index.axaml b/src/Semi.Avalonia/Themes/Index.axaml index 5af2035..116b7b5 100644 --- a/src/Semi.Avalonia/Themes/Index.axaml +++ b/src/Semi.Avalonia/Themes/Index.axaml @@ -2,8 +2,8 @@ - - + + diff --git a/src/Semi.Avalonia/Themes/SemiTheme.axaml b/src/Semi.Avalonia/Themes/SemiTheme.axaml index 5e86cb3..52c207f 100644 --- a/src/Semi.Avalonia/Themes/SemiTheme.axaml +++ b/src/Semi.Avalonia/Themes/SemiTheme.axaml @@ -2,8 +2,8 @@ - - + + diff --git a/src/Semi.Avalonia/Themes/SemiTheme.axaml.cs b/src/Semi.Avalonia/Themes/SemiTheme.axaml.cs index bb68581..88268f3 100644 --- a/src/Semi.Avalonia/Themes/SemiTheme.axaml.cs +++ b/src/Semi.Avalonia/Themes/SemiTheme.axaml.cs @@ -4,15 +4,16 @@ using System.Globalization; using Avalonia.Controls; using Avalonia.Markup.Xaml; using Avalonia.Styling; +using Semi.Avalonia.Locale; namespace Semi.Avalonia; public class SemiTheme: Styles { - private static readonly Dictionary _localeToResource = new() + private static readonly Dictionary _localeToResource = new() { - { new CultureInfo("zh-cn"), "avares://Semi.Avalonia/Locale/zh-cn.axaml" }, - { new CultureInfo("en-us"), "avares://Semi.Avalonia/Locale/en-us.axaml" }, + { new CultureInfo("zh-cn"), new zh_cn() }, + { new CultureInfo("en-us"), new en_us() }, }; private readonly IServiceProvider? sp; @@ -30,22 +31,20 @@ public class SemiTheme: Styles { _locale = value; var resource = TryGetLocaleResource(value); - var d = AvaloniaXamlLoader.Load(sp, new Uri(resource)) as ResourceDictionary; - if (d is null) return; - foreach (var kv in d) + if(resource is null) return; + foreach (var kv in resource) { this.Resources.Add(kv); } } } - private static string TryGetLocaleResource(CultureInfo? locale) + private static ResourceDictionary? TryGetLocaleResource(CultureInfo? locale) { if (locale is null) { return _localeToResource[new CultureInfo("zh-cn")]; } - if (_localeToResource.TryGetValue(locale, out var resource)) { return resource; From 9259f06f57e45d1af2e3a49a68b3e83360ad371a Mon Sep 17 00:00:00 2001 From: rabbitism Date: Thu, 18 Jul 2024 16:58:05 +0800 Subject: [PATCH 2/4] fix: fix palette trimming issue. --- .../ViewModels/PaletteDemoViewModel.cs | 4 ++-- src/Semi.Avalonia/Themes/Dark/Palette.axaml | 2 +- src/Semi.Avalonia/Themes/Dark/Palette.axaml.cs | 9 +++++++++ src/Semi.Avalonia/Themes/Light/Palette.axaml | 2 +- src/Semi.Avalonia/Themes/Light/Palette.axaml.cs | 9 +++++++++ 5 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 src/Semi.Avalonia/Themes/Dark/Palette.axaml.cs create mode 100644 src/Semi.Avalonia/Themes/Light/Palette.axaml.cs diff --git a/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs b/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs index f772889..1646be8 100644 --- a/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs +++ b/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs @@ -47,8 +47,8 @@ public class PaletteDemoViewModel: ObservableObject public PaletteDemoViewModel() { - _lightResourceDictionary = AvaloniaXamlLoader.Load(new Uri("avares://Semi.Avalonia/Themes/Light/Palette.axaml")) as ResourceDictionary; - _darkResourceDictionary = AvaloniaXamlLoader.Load(new Uri("avares://Semi.Avalonia/Themes/Dark/Palette.axaml")) as ResourceDictionary; + _lightResourceDictionary = new Light.Palette(); + _darkResourceDictionary = new Dark.Palette(); WeakReferenceMessenger.Default.Register(this, OnClickColorItem); } diff --git a/src/Semi.Avalonia/Themes/Dark/Palette.axaml b/src/Semi.Avalonia/Themes/Dark/Palette.axaml index 6960964..71c92a0 100644 --- a/src/Semi.Avalonia/Themes/Dark/Palette.axaml +++ b/src/Semi.Avalonia/Themes/Dark/Palette.axaml @@ -1,4 +1,4 @@ - + #6C090B #901110 diff --git a/src/Semi.Avalonia/Themes/Dark/Palette.axaml.cs b/src/Semi.Avalonia/Themes/Dark/Palette.axaml.cs new file mode 100644 index 0000000..196931f --- /dev/null +++ b/src/Semi.Avalonia/Themes/Dark/Palette.axaml.cs @@ -0,0 +1,9 @@ +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace Semi.Avalonia.Dark; + +public class Palette: ResourceDictionary +{ + +} \ No newline at end of file diff --git a/src/Semi.Avalonia/Themes/Light/Palette.axaml b/src/Semi.Avalonia/Themes/Light/Palette.axaml index bec6dd8..3e280b1 100644 --- a/src/Semi.Avalonia/Themes/Light/Palette.axaml +++ b/src/Semi.Avalonia/Themes/Light/Palette.axaml @@ -1,4 +1,4 @@ - + #FEF2ED #FEDDD2 diff --git a/src/Semi.Avalonia/Themes/Light/Palette.axaml.cs b/src/Semi.Avalonia/Themes/Light/Palette.axaml.cs new file mode 100644 index 0000000..e391acb --- /dev/null +++ b/src/Semi.Avalonia/Themes/Light/Palette.axaml.cs @@ -0,0 +1,9 @@ +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace Semi.Avalonia.Light; + +public class Palette: ResourceDictionary +{ + +} \ No newline at end of file From 31e2c009fbb8aae8bca673171ddcd5e92d36298c Mon Sep 17 00:00:00 2001 From: rabbitism Date: Thu, 18 Jul 2024 17:56:15 +0800 Subject: [PATCH 3/4] feat: remove useless files. --- .../Semi.Avalonia.Demo.Desktop.csproj | 4 ---- demo/Semi.Avalonia.Demo.Desktop/rd.xml | 16 ---------------- demo/Semi.Avalonia.Demo.Web/Roots.xml | 5 ----- .../Semi.Avalonia.Demo.Web.csproj | 1 - 4 files changed, 26 deletions(-) delete mode 100644 demo/Semi.Avalonia.Demo.Desktop/rd.xml delete mode 100644 demo/Semi.Avalonia.Demo.Web/Roots.xml diff --git a/demo/Semi.Avalonia.Demo.Desktop/Semi.Avalonia.Demo.Desktop.csproj b/demo/Semi.Avalonia.Demo.Desktop/Semi.Avalonia.Demo.Desktop.csproj index 4418249..094ce6c 100644 --- a/demo/Semi.Avalonia.Demo.Desktop/Semi.Avalonia.Demo.Desktop.csproj +++ b/demo/Semi.Avalonia.Demo.Desktop/Semi.Avalonia.Demo.Desktop.csproj @@ -19,10 +19,6 @@ app.manifest - - - - diff --git a/demo/Semi.Avalonia.Demo.Desktop/rd.xml b/demo/Semi.Avalonia.Demo.Desktop/rd.xml deleted file mode 100644 index 0133190..0000000 --- a/demo/Semi.Avalonia.Demo.Desktop/rd.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - diff --git a/demo/Semi.Avalonia.Demo.Web/Roots.xml b/demo/Semi.Avalonia.Demo.Web/Roots.xml deleted file mode 100644 index 6fa94a3..0000000 --- a/demo/Semi.Avalonia.Demo.Web/Roots.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/demo/Semi.Avalonia.Demo.Web/Semi.Avalonia.Demo.Web.csproj b/demo/Semi.Avalonia.Demo.Web/Semi.Avalonia.Demo.Web.csproj index 96e64dc..a97b8ce 100644 --- a/demo/Semi.Avalonia.Demo.Web/Semi.Avalonia.Demo.Web.csproj +++ b/demo/Semi.Avalonia.Demo.Web/Semi.Avalonia.Demo.Web.csproj @@ -6,7 +6,6 @@ - From 8982e610e217b05c86585390278bab70009e222a Mon Sep 17 00:00:00 2001 From: Zhang Dian <54255897+zdpcdt@users.noreply.github.com> Date: Thu, 18 Jul 2024 18:36:07 +0800 Subject: [PATCH 4/4] feat: add doc & GitHub repo link buttons. --- demo/Semi.Avalonia.Demo/Views/MainView.axaml | 78 +++++++++++-------- .../Views/MainView.axaml.cs | 17 ++++ 2 files changed, 64 insertions(+), 31 deletions(-) diff --git a/demo/Semi.Avalonia.Demo/Views/MainView.axaml b/demo/Semi.Avalonia.Demo/Views/MainView.axaml index 9979101..4a5bbbc 100644 --- a/demo/Semi.Avalonia.Demo/Views/MainView.axaml +++ b/demo/Semi.Avalonia.Demo/Views/MainView.axaml @@ -1,13 +1,13 @@ + d:DesignHeight="450" + d:DesignWidth="800" + mc:Ignorable="d"> @@ -21,52 +21,68 @@ Margin="8" Padding="12,4" Theme="{DynamicResource CardBorder}"> - + + Theme="{DynamicResource TitleTextBlock}" /> + VerticalAlignment="Center" + Text="/" /> + Text="{Binding #tab.SelectedItem.Header}" /> - - + + + + + + + + + + + + diff --git a/demo/Semi.Avalonia.Demo/Views/MainView.axaml.cs b/demo/Semi.Avalonia.Demo/Views/MainView.axaml.cs index 3a69c9c..a6aec59 100644 --- a/demo/Semi.Avalonia.Demo/Views/MainView.axaml.cs +++ b/demo/Semi.Avalonia.Demo/Views/MainView.axaml.cs @@ -1,3 +1,4 @@ +using System; using Avalonia; using Avalonia.Controls; using Avalonia.Interactivity; @@ -21,4 +22,20 @@ public partial class MainView : UserControl app.RequestedThemeVariant = theme == ThemeVariant.Dark ? ThemeVariant.Light : ThemeVariant.Dark; } } + + 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")); + } + + private async void OpenDocumentation(object sender, RoutedEventArgs e) + { + var top = TopLevel.GetTopLevel(this); + if (top is null) return; + var launcher = top.Launcher; + await launcher.LaunchUriAsync(new Uri("https://docs.irihi.tech/semi")); + } } \ No newline at end of file