From a76289ff0ac6926c29c36393efc0597ee545478a Mon Sep 17 00:00:00 2001 From: Clement Sepulchre Date: Fri, 29 Nov 2024 10:21:15 +0100 Subject: [PATCH] shadcn inspire high contrast theme --- SukiUI.Demo/App.axaml.cs | 9 ++ .../ControlsLibrary/PropertyGridView.axaml | 14 +- SukiUI.Demo/SukiUIDemoViewModel.cs | 2 +- .../Shaders/Background/backgroundshadcn.sksl | 102 +++++++++++++ .../Shaders/Background/gradientdarker.sksl | 101 +++++++++++++ SukiUI/Controls/SukiWindow.axaml.cs | 2 +- SukiUI/Enums/SukiBackgroundStyle.cs | 1 + SukiUI/SukiUI.csproj | 4 + SukiUI/Theme/Shadcn/BlackWhiteTheme.axaml | 27 ++++ SukiUI/Theme/Shadcn/ShadDarkStyles.axaml | 138 ++++++++++++++++++ SukiUI/Theme/Shadcn/Shadcn.cs | 60 ++++++++ SukiUI/Theme/ToggleSwitchStyles.xaml | 9 +- 12 files changed, 460 insertions(+), 9 deletions(-) create mode 100644 SukiUI/Content/Shaders/Background/backgroundshadcn.sksl create mode 100644 SukiUI/Content/Shaders/Background/gradientdarker.sksl create mode 100644 SukiUI/Theme/Shadcn/BlackWhiteTheme.axaml create mode 100644 SukiUI/Theme/Shadcn/ShadDarkStyles.axaml create mode 100644 SukiUI/Theme/Shadcn/Shadcn.cs diff --git a/SukiUI.Demo/App.axaml.cs b/SukiUI.Demo/App.axaml.cs index d0f257f6c..d77e8f4cf 100644 --- a/SukiUI.Demo/App.axaml.cs +++ b/SukiUI.Demo/App.axaml.cs @@ -1,8 +1,12 @@ +using System; using Avalonia; using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Controls.Templates; using Avalonia.Markup.Xaml; +using Avalonia.Markup.Xaml.Styling; +using Avalonia.Media; +using Avalonia.Styling; using Microsoft.Extensions.DependencyInjection; using SukiUI.Demo.Common; using SukiUI.Demo.Features.ControlsLibrary; @@ -19,6 +23,8 @@ using SukiUI.Demo.Features.Theming; using SukiUI.Demo.Services; using SukiUI.Dialogs; +using SukiUI.Models; +using SukiUI.Theme.Shadcn; using SukiUI.Toasts; namespace SukiUI.Demo; @@ -28,6 +34,7 @@ public class App : Application public override void Initialize() { AvaloniaXamlLoader.Load(this); + } public override void OnFrameworkInitializationCompleted() @@ -47,6 +54,8 @@ public override void OnFrameworkInitializationCompleted() } base.OnFrameworkInitializationCompleted(); + + // Shadcn.Configure(Application.Current, ThemeVariant.Dark); } private static SukiViews ConfigureViews(ServiceCollection services) diff --git a/SukiUI.Demo/Features/ControlsLibrary/PropertyGridView.axaml b/SukiUI.Demo/Features/ControlsLibrary/PropertyGridView.axaml index efd35e490..90a089643 100644 --- a/SukiUI.Demo/Features/ControlsLibrary/PropertyGridView.axaml +++ b/SukiUI.Demo/Features/ControlsLibrary/PropertyGridView.axaml @@ -18,11 +18,15 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SukiUI/Theme/Shadcn/Shadcn.cs b/SukiUI/Theme/Shadcn/Shadcn.cs new file mode 100644 index 000000000..317cadd48 --- /dev/null +++ b/SukiUI/Theme/Shadcn/Shadcn.cs @@ -0,0 +1,60 @@ +using System; +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Markup.Xaml.Styling; +using Avalonia.Media; +using Avalonia.Styling; +using SukiUI.Controls; +using SukiUI.Models; + +namespace SukiUI.Theme.Shadcn +{ + public static class Shadcn + { + public static void Configure(Application application, ThemeVariant startupTheme) + { + Application.Current.Resources.MergedDictionaries.Add(new ResourceInclude(new Uri("avares://SukiUI/Theme/Shadcn/BlackWhiteTheme.axaml") + ) + { + Source = new Uri("avares://SukiUI/Theme/Shadcn/BlackWhiteTheme.axaml") + }); + + var whiteTheme = new SukiColorTheme("White", new Color(255, 255, 255, 255), new Color(255, 255, 255, 255)); + var blackTheme = new SukiColorTheme("Black", new Color(255, 0, 0, 0), new Color(255, 0, 0, 0)); + + SukiTheme.GetInstance().AddColorThemes(new []{whiteTheme, blackTheme}); + + var BlackStyles = new StyleInclude(new Uri("avares://SukiUI/Theme/Shadcn/ShadDarkStyles.axaml")) + { + Source = new Uri("avares://SukiUI/Theme/Shadcn/ShadDarkStyles.axaml") + }; + + + SukiTheme.GetInstance().OnBaseThemeChanged += variant => + { + if (variant == ThemeVariant.Dark) + { + application.Styles.Add(BlackStyles); + SukiTheme.GetInstance().ChangeColorTheme(whiteTheme); + + } + else + { + SukiTheme.GetInstance().ChangeColorTheme(blackTheme); + application.Styles.Remove(BlackStyles); + } + }; + + try + { + ((SukiWindow)((ClassicDesktopStyleApplicationLifetime)application.ApplicationLifetime).MainWindow) + .BackgroundShaderFile = "backgroundshadcn"; + }catch{} + + SukiTheme.GetInstance().ChangeBaseTheme(ThemeVariant.Light); + SukiTheme.GetInstance().ChangeBaseTheme(ThemeVariant.Dark); + SukiTheme.GetInstance().ChangeBaseTheme(startupTheme); + + } + } +} \ No newline at end of file diff --git a/SukiUI/Theme/ToggleSwitchStyles.xaml b/SukiUI/Theme/ToggleSwitchStyles.xaml index 3fbd8ff0c..c7ce783ba 100644 --- a/SukiUI/Theme/ToggleSwitchStyles.xaml +++ b/SukiUI/Theme/ToggleSwitchStyles.xaml @@ -138,6 +138,7 @@ + @@ -165,7 +166,7 @@ Width="18" Height="18" Margin="0,0,0,0" - Background="#fcfcfc" + BoxShadow="{DynamicResource SukiSwitchShadow}" CornerRadius="{DynamicResource MediumCornerRadius}"> @@ -196,7 +197,10 @@ - + +