From bc49ce78e03b434c76f4aaf9f9cf436df186d9d9 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Fri, 20 Sep 2024 04:08:08 +0800 Subject: [PATCH] feat: add more high contrast themes. --- demo/Semi.Avalonia.Demo/App.axaml | 4 +- demo/Semi.Avalonia.Demo/Views/MainView.axaml | 35 +- .../Views/MainView.axaml.cs | 35 + .../{Aquatic => HighContrast}/Aquatic.axaml | 0 .../Themes/HighContrast/Desert.axaml | 703 ++++++++++++++++++ .../Themes/HighContrast/Dusk.axaml | 703 ++++++++++++++++++ .../Themes/HighContrast/NightSky.axaml | 703 ++++++++++++++++++ src/Semi.Avalonia/Themes/SemiTheme.axaml | 5 +- src/Semi.Avalonia/Themes/SemiTheme.axaml.cs | 3 + 9 files changed, 2165 insertions(+), 26 deletions(-) rename src/Semi.Avalonia/Themes/{Aquatic => HighContrast}/Aquatic.axaml (100%) create mode 100644 src/Semi.Avalonia/Themes/HighContrast/Desert.axaml create mode 100644 src/Semi.Avalonia/Themes/HighContrast/Dusk.axaml create mode 100644 src/Semi.Avalonia/Themes/HighContrast/NightSky.axaml diff --git a/demo/Semi.Avalonia.Demo/App.axaml b/demo/Semi.Avalonia.Demo/App.axaml index 0beecc9..f01ab5c 100644 --- a/demo/Semi.Avalonia.Demo/App.axaml +++ b/demo/Semi.Avalonia.Demo/App.axaml @@ -2,8 +2,8 @@ x:Class="Semi.Avalonia.Demo.App" xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - RequestedThemeVariant="{x:Static semi:SemiTheme.Aquatic}" - xmlns:semi="https://irihi.tech/semi"> + + xmlns:semi="https://irihi.tech/semi"> diff --git a/demo/Semi.Avalonia.Demo/Views/MainView.axaml b/demo/Semi.Avalonia.Demo/Views/MainView.axaml index 4a5bbbc..0c12b22 100644 --- a/demo/Semi.Avalonia.Demo/Views/MainView.axaml +++ b/demo/Semi.Avalonia.Demo/Views/MainView.axaml @@ -5,8 +5,11 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:pages="using:Semi.Avalonia.Demo.Pages" + xmlns:views="clr-namespace:Semi.Avalonia.Demo.Views" d:DesignHeight="450" d:DesignWidth="800" + x:CompileBindings="True" + x:DataType="views:MainViewModel" mc:Ignorable="d"> @@ -36,43 +39,29 @@ Margin="8,0" VerticalAlignment="Center" Classes="Secondary" - Text="{Binding #tab.SelectedItem.Header}" /> + Text="{ReflectionBinding #tab.SelectedItem.Header}" /> - - - - - - - - - - + diff --git a/demo/Semi.Avalonia.Demo/Views/MainView.axaml.cs b/demo/Semi.Avalonia.Demo/Views/MainView.axaml.cs index a6aec59..b7e74a8 100644 --- a/demo/Semi.Avalonia.Demo/Views/MainView.axaml.cs +++ b/demo/Semi.Avalonia.Demo/Views/MainView.axaml.cs @@ -1,8 +1,10 @@ using System; +using System.Collections.ObjectModel; using Avalonia; using Avalonia.Controls; using Avalonia.Interactivity; using Avalonia.Styling; +using CommunityToolkit.Mvvm.ComponentModel; namespace Semi.Avalonia.Demo.Views; @@ -11,6 +13,7 @@ public partial class MainView : UserControl public MainView() { InitializeComponent(); + this.DataContext = new MainViewModel(); } private void ToggleButton_OnIsCheckedChanged(object sender, RoutedEventArgs e) @@ -38,4 +41,36 @@ public partial class MainView : UserControl var launcher = top.Launcher; await launcher.LaunchUriAsync(new Uri("https://docs.irihi.tech/semi")); } +} + +public partial class MainViewModel: ObservableObject +{ + public ObservableCollection Themes { get; } = new() + { + new ThemeItem("Light", ThemeVariant.Light), + new ThemeItem("Dark", ThemeVariant.Dark), + new ThemeItem("Aquatic", SemiTheme.Aquatic), + new ThemeItem("Desert", SemiTheme.Desert), + new ThemeItem("Dust", SemiTheme.Dust), + new ThemeItem("NightSky", SemiTheme.NightSky), + }; + + [ObservableProperty] private ThemeItem? _selectedTheme; + + partial void OnSelectedThemeChanged(ThemeItem? oldValue, ThemeItem? newValue) + { + if (newValue is null) return; + var app = Application.Current; + if (app is not null) + { + app.RequestedThemeVariant = newValue.Theme; + } + } + +} + +public class ThemeItem(string name, ThemeVariant theme) +{ + public string Name { get; set; } = name; + public ThemeVariant Theme { get; set; } = theme; } \ No newline at end of file diff --git a/src/Semi.Avalonia/Themes/Aquatic/Aquatic.axaml b/src/Semi.Avalonia/Themes/HighContrast/Aquatic.axaml similarity index 100% rename from src/Semi.Avalonia/Themes/Aquatic/Aquatic.axaml rename to src/Semi.Avalonia/Themes/HighContrast/Aquatic.axaml diff --git a/src/Semi.Avalonia/Themes/HighContrast/Desert.axaml b/src/Semi.Avalonia/Themes/HighContrast/Desert.axaml new file mode 100644 index 0000000..cc44132 --- /dev/null +++ b/src/Semi.Avalonia/Themes/HighContrast/Desert.axaml @@ -0,0 +1,703 @@ + + + #FFFAEF + #3D3D3D + #1C5E75 + #676767 + #FFF5E3 + #903909 + #FFFAEF + #202020 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Semi.Avalonia/Themes/HighContrast/Dusk.axaml b/src/Semi.Avalonia/Themes/HighContrast/Dusk.axaml new file mode 100644 index 0000000..69fee1d --- /dev/null +++ b/src/Semi.Avalonia/Themes/HighContrast/Dusk.axaml @@ -0,0 +1,703 @@ + + + #2D3236 + #FFFFFF + #70EBDE + #A6A6A6 + #212D3B + #A1BFDE + #2D3236 + #B6F6F0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Semi.Avalonia/Themes/HighContrast/NightSky.axaml b/src/Semi.Avalonia/Themes/HighContrast/NightSky.axaml new file mode 100644 index 0000000..3a896f1 --- /dev/null +++ b/src/Semi.Avalonia/Themes/HighContrast/NightSky.axaml @@ -0,0 +1,703 @@ + + + #000000 + #FFFFFF + #8080FF + #A6A6A6 + #2B2B2B + #D6B4FD + #000000 + #FFEE32 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Semi.Avalonia/Themes/SemiTheme.axaml b/src/Semi.Avalonia/Themes/SemiTheme.axaml index b5f679c..5281aa0 100644 --- a/src/Semi.Avalonia/Themes/SemiTheme.axaml +++ b/src/Semi.Avalonia/Themes/SemiTheme.axaml @@ -5,7 +5,10 @@ - + + + + diff --git a/src/Semi.Avalonia/Themes/SemiTheme.axaml.cs b/src/Semi.Avalonia/Themes/SemiTheme.axaml.cs index f0103a0..d178f31 100644 --- a/src/Semi.Avalonia/Themes/SemiTheme.axaml.cs +++ b/src/Semi.Avalonia/Themes/SemiTheme.axaml.cs @@ -11,6 +11,9 @@ namespace Semi.Avalonia; public class SemiTheme : Styles { public static ThemeVariant Aquatic => new ThemeVariant(nameof(Aquatic), ThemeVariant.Dark); + public static ThemeVariant Desert => new ThemeVariant(nameof(Desert), ThemeVariant.Light); + public static ThemeVariant Dust => new ThemeVariant(nameof(Dust), ThemeVariant.Dark); + public static ThemeVariant NightSky => new ThemeVariant(nameof(NightSky), ThemeVariant.Dark); private static readonly Dictionary _localeToResource = new() {