feat: add more high contrast themes.

This commit is contained in:
rabbitism
2024-09-20 04:08:08 +08:00
committed by Zhang Dian
parent 2dbfcb38e3
commit bc49ce78e0
9 changed files with 2165 additions and 26 deletions

View File

@@ -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<ThemeItem> 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;
}