Normalize source whitespace

This commit is contained in:
dasp committed 2026-10-15 22:46:29 +02:00
1 parent 79ae6bd7f2
commit eab48e30e4
2 files changed
+63 -1

No files matched your search

-1
View File
@@ -79,4 +79,3 @@
</Application.Resources> </Application.Resources>
</Application> </Application>
+63
View File
@@ -1,64 +1,127 @@
using System.Windows; using System.Windows;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Data; using System.Windows.Data;
using System.ComponentModel; using System.ComponentModel;
namespace ShortcutsPanel; namespace ShortcutsPanel;
public static class Theme public static class Theme
{ {
static readonly Dictionary<string, string> DarkColors = new(StringComparer.OrdinalIgnoreCase) static readonly Dictionary<string, string> DarkColors = new(StringComparer.OrdinalIgnoreCase)
{ {
["#FAF9F6"] = "#202020", ["#252924"] = "#EEEEEE", ["#FAF9F6"] = "#202020", ["#252924"] = "#EEEEEE",
["#F1F2ED"] = "#252525", ["#E2E5DD"] = "#3B3B3B", ["#F1F2ED"] = "#252525", ["#E2E5DD"] = "#3B3B3B",
["#294B3D"] = "#505050", ["#294B3C"] = "#E0E0E0", ["#80877D"] = "#AAAAAA", ["#294B3D"] = "#505050", ["#294B3C"] = "#E0E0E0", ["#80877D"] = "#AAAAAA",
["#8C9388"] = "#AAAAAA", ["#838B7F"] = "#AAAAAA", ["#8C9388"] = "#AAAAAA", ["#838B7F"] = "#AAAAAA",
["#7B8377"] = "#BBBBBB", ["#868D80"] = "#AAAAAA", ["#7B8377"] = "#BBBBBB", ["#868D80"] = "#AAAAAA",
["#DFE6DA"] = "#3D3D3D", ["#374632"] = "#E5E5E5", ["#DFE6DA"] = "#3D3D3D", ["#374632"] = "#E5E5E5",
["#FFFFFF"] = "#2B2B2B", ["#A2AA9B"] = "#AAAAAA", ["#FFFFFF"] = "#2B2B2B", ["#A2AA9B"] = "#AAAAAA",
["#F5F6F2"] = "#EAEAEA", ["#252D23"] = "#EEEEEE", ["#F5F6F2"] = "#EAEAEA", ["#252D23"] = "#EEEEEE",
["#8B9285"] = "#AAAAAA", ["#E5E8E0"] = "#414141", ["#8B9285"] = "#AAAAAA", ["#E5E8E0"] = "#414141",
["#ACBDA4"] = "#777777", ["#EEF0E9"] = "#3A3A3A", ["#ACBDA4"] = "#777777", ["#EEF0E9"] = "#3A3A3A",
["#DDE2D6"] = "#555555", ["#A83C38"] = "#FFB3AB", ["#DDE2D6"] = "#555555", ["#A83C38"] = "#FFB3AB",
["#F8E9E5"] = "#583936", ["#53654B"] = "#505050", ["#F8E9E5"] = "#583936", ["#53654B"] = "#505050",
["#738B65"] = "#999999", ["#528462"] = "#777777", ["#738B65"] = "#999999", ["#528462"] = "#777777",
["#AACB94"] = "#BBBBBB", ["#8A9485"] = "#666666" ["#AACB94"] = "#BBBBBB", ["#8A9485"] = "#666666"
}; };
static readonly Dictionary<string, SolidColorBrush> Brushes = new(StringComparer.OrdinalIgnoreCase); static readonly Dictionary<string, SolidColorBrush> Brushes = new(StringComparer.OrdinalIgnoreCase);
static readonly Dictionary<string, ThemeColor> Colors = new(StringComparer.OrdinalIgnoreCase); static readonly Dictionary<string, ThemeColor> Colors = new(StringComparer.OrdinalIgnoreCase);
sealed class ThemeColor : INotifyPropertyChanged sealed class ThemeColor : INotifyPropertyChanged
{ {
public Color Color { get; private set; } public Color Color { get; private set; }
public event PropertyChangedEventHandler? PropertyChanged; public event PropertyChangedEventHandler? PropertyChanged;
public void Set(Color color) { Color = color; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Color))); } public void Set(Color color) { Color = color; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Color))); }
} }
public static bool IsDark { get; private set; } public static bool IsDark { get; private set; }
public static SolidColorBrush Brush(string light) public static SolidColorBrush Brush(string light)
{ {
if (!Brushes.TryGetValue(light, out var brush)) if (!Brushes.TryGetValue(light, out var brush))
{ {
var value = new ThemeColor(); value.Set(ColorFor(light)); Colors[light] = value; var value = new ThemeColor(); value.Set(ColorFor(light)); Colors[light] = value;
Brushes[light] = brush = new SolidColorBrush(); Brushes[light] = brush = new SolidColorBrush();
// A binding keeps WPF styles from freezing a brush that must change at runtime. // A binding keeps WPF styles from freezing a brush that must change at runtime.
BindingOperations.SetBinding(brush, SolidColorBrush.ColorProperty, new Binding(nameof(ThemeColor.Color)) { Source = value }); BindingOperations.SetBinding(brush, SolidColorBrush.ColorProperty, new Binding(nameof(ThemeColor.Color)) { Source = value });
} }
return brush; return brush;
} }
static Color ColorFor(string light) => (Color)ColorConverter.ConvertFromString( static Color ColorFor(string light) => (Color)ColorConverter.ConvertFromString(
IsDark && DarkColors.TryGetValue(light, out var dark) ? dark : light); IsDark && DarkColors.TryGetValue(light, out var dark) ? dark : light);
public static void Apply(bool dark) public static void Apply(bool dark)
{ {
IsDark = dark; IsDark = dark;
foreach (var pair in Colors) pair.Value.Set(ColorFor(pair.Key)); foreach (var pair in Colors) pair.Value.Set(ColorFor(pair.Key));
var resources = Application.Current.Resources; var resources = Application.Current.Resources;
resources["WindowBackground"] = Brush("#FAF9F6"); resources["WindowBackground"] = Brush("#FAF9F6");
resources["Ink"] = Brush("#252924"); resources["Ink"] = Brush("#252924");
resources["ControlBackground"] = Brush("#EEF0E9"); resources["ControlBackground"] = Brush("#EEF0E9");
resources["InputBackground"] = Brush("#FFFFFF"); resources["InputBackground"] = Brush("#FFFFFF");
resources["InputBorder"] = Brush("#DDE2D6"); resources["InputBorder"] = Brush("#DDE2D6");
resources["FocusBorder"] = Brush("#738B65"); resources["FocusBorder"] = Brush("#738B65");
resources["SwitchOn"] = Brush("#528462"); resources["SwitchOn"] = Brush("#528462");
resources["SwitchOff"] = Brush("#8A9485"); resources["SwitchOff"] = Brush("#8A9485");
resources["SwitchFocus"] = Brush("#AACB94"); resources["SwitchFocus"] = Brush("#AACB94");
} }
} }