|
|
@@ -1,66 +1,77 @@
|
|
|
-using Avalonia;
|
|
|
-using Avalonia.Controls;
|
|
|
-using Avalonia.Controls.ApplicationLifetimes;
|
|
|
using Avalonia.Media;
|
|
|
|
|
|
namespace YZWater.Avalonia.Controls;
|
|
|
|
|
|
/// <summary>
|
|
|
-/// 涓婚璧勬簮杈呭姪鏂规硶
|
|
|
+/// 涓婚璧勬簮杈呭姪鏂规硶 - 鐩存帴缂撳瓨褰撳墠涓婚鐢诲埛
|
|
|
/// </summary>
|
|
|
internal static class ThemeHelper
|
|
|
{
|
|
|
- /// <summary>
|
|
|
- /// 涓婚鍙樻洿浜嬩欢
|
|
|
- /// </summary>
|
|
|
public static event Action? ThemeChanged;
|
|
|
+ public static void NotifyThemeChanged() => ThemeChanged?.Invoke();
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 瑙﹀彂涓婚鍙樻洿锛堢敱 App.axaml.cs 璋冪敤锛
|
|
|
- /// </summary>
|
|
|
- public static void NotifyThemeChanged()
|
|
|
- {
|
|
|
- ThemeChanged?.Invoke();
|
|
|
- }
|
|
|
+ // 鈹鈹鈹 褰撳墠涓婚鐢诲埛缂撳瓨 鈹鈹鈹
|
|
|
+ public static IBrush AppBg { get; private set; } = new SolidColorBrush(Color.Parse("#0A0E14"));
|
|
|
+ public static IBrush SurfaceBg { get; private set; } = new SolidColorBrush(Color.Parse("#111820"));
|
|
|
+ public static IBrush PanelBg { get; private set; } = new SolidColorBrush(Color.Parse("#0D1117"));
|
|
|
+ public static IBrush Border { get; private set; } = new SolidColorBrush(Color.Parse("#1C2333"));
|
|
|
+ public static IBrush TextPrimary { get; private set; } = new SolidColorBrush(Color.Parse("#E6EDF3"));
|
|
|
+ public static IBrush TextSecondary { get; private set; } = new SolidColorBrush(Color.Parse("#9CA3AF"));
|
|
|
+ public static IBrush TextTertiary { get; private set; } = new SolidColorBrush(Color.Parse("#6B7280"));
|
|
|
+ public static IBrush TextDisabled { get; private set; } = new SolidColorBrush(Color.Parse("#4B5563"));
|
|
|
+ public static IBrush Success { get; private set; } = new SolidColorBrush(Color.Parse("#00897B"));
|
|
|
+ public static IBrush Warning { get; private set; } = new SolidColorBrush(Color.Parse("#F59E0B"));
|
|
|
+ public static IBrush Danger { get; private set; } = new SolidColorBrush(Color.Parse("#EF4444"));
|
|
|
+ public static IBrush Info { get; private set; } = new SolidColorBrush(Color.Parse("#3B82F6"));
|
|
|
+ public static IBrush HeaderBg { get; private set; } = new SolidColorBrush(Color.Parse("#111820"));
|
|
|
+ public static IBrush HeaderText { get; private set; } = new SolidColorBrush(Color.Parse("#E6EDF3"));
|
|
|
+ public static IBrush HeaderSubtext { get; private set; } = new SolidColorBrush(Color.Parse("#9CA3AF"));
|
|
|
+ public static IBrush NavBg { get; private set; } = new SolidColorBrush(Color.Parse("#111820"));
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 浠庡簲鐢ㄨ祫婧愯幏鍙栫敾鍒凤紝鎵句笉鍒板垯杩斿洖榛樿鍊
|
|
|
+ /// 璁剧疆褰撳墠涓婚锛堢敱 App.axaml.cs 璋冪敤锛
|
|
|
/// </summary>
|
|
|
- public static IBrush GetBrush(string key, string fallbackHex)
|
|
|
+ public static void SetTheme(bool isDark)
|
|
|
{
|
|
|
- try
|
|
|
+ if (isDark)
|
|
|
{
|
|
|
- var app = Application.Current;
|
|
|
- if (app?.Resources?.MergedDictionaries != null)
|
|
|
- {
|
|
|
- foreach (var dict in app.Resources.MergedDictionaries)
|
|
|
- {
|
|
|
- if (dict.TryGetResource(key, null, out var value) && value is IBrush brush)
|
|
|
- return brush;
|
|
|
- }
|
|
|
- }
|
|
|
- if (app != null && app.Resources.TryGetResource(key, null, out var rootValue) && rootValue is IBrush rootBrush)
|
|
|
- return rootBrush;
|
|
|
+ AppBg = new SolidColorBrush(Color.Parse("#0A0E14"));
|
|
|
+ SurfaceBg = new SolidColorBrush(Color.Parse("#111820"));
|
|
|
+ PanelBg = new SolidColorBrush(Color.Parse("#0D1117"));
|
|
|
+ Border = new SolidColorBrush(Color.Parse("#1C2333"));
|
|
|
+ TextPrimary = new SolidColorBrush(Color.Parse("#E6EDF3"));
|
|
|
+ TextSecondary = new SolidColorBrush(Color.Parse("#9CA3AF"));
|
|
|
+ TextTertiary = new SolidColorBrush(Color.Parse("#6B7280"));
|
|
|
+ TextDisabled = new SolidColorBrush(Color.Parse("#4B5563"));
|
|
|
+ Success = new SolidColorBrush(Color.Parse("#00897B"));
|
|
|
+ Warning = new SolidColorBrush(Color.Parse("#F59E0B"));
|
|
|
+ Danger = new SolidColorBrush(Color.Parse("#EF4444"));
|
|
|
+ Info = new SolidColorBrush(Color.Parse("#3B82F6"));
|
|
|
+ HeaderBg = new SolidColorBrush(Color.Parse("#111820"));
|
|
|
+ HeaderText = new SolidColorBrush(Color.Parse("#E6EDF3"));
|
|
|
+ HeaderSubtext = new SolidColorBrush(Color.Parse("#9CA3AF"));
|
|
|
+ NavBg = new SolidColorBrush(Color.Parse("#111820"));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ AppBg = new SolidColorBrush(Color.Parse("#E5E7EB"));
|
|
|
+ SurfaceBg = new SolidColorBrush(Color.Parse("#F3F4F6"));
|
|
|
+ PanelBg = new SolidColorBrush(Color.Parse("#FFFFFF"));
|
|
|
+ Border = new SolidColorBrush(Color.Parse("#9CA3AF"));
|
|
|
+ TextPrimary = new SolidColorBrush(Color.Parse("#111827"));
|
|
|
+ TextSecondary = new SolidColorBrush(Color.Parse("#4B5563"));
|
|
|
+ TextTertiary = new SolidColorBrush(Color.Parse("#6B7280"));
|
|
|
+ TextDisabled = new SolidColorBrush(Color.Parse("#9CA3AF"));
|
|
|
+ Success = new SolidColorBrush(Color.Parse("#047857"));
|
|
|
+ Warning = new SolidColorBrush(Color.Parse("#B45309"));
|
|
|
+ Danger = new SolidColorBrush(Color.Parse("#B91C1C"));
|
|
|
+ Info = new SolidColorBrush(Color.Parse("#1D4ED8"));
|
|
|
+ HeaderBg = new SolidColorBrush(Color.Parse("#1F2937"));
|
|
|
+ HeaderText = new SolidColorBrush(Color.Parse("#F9FAFB"));
|
|
|
+ HeaderSubtext = new SolidColorBrush(Color.Parse("#9CA3AF"));
|
|
|
+ NavBg = new SolidColorBrush(Color.Parse("#F9FAFB"));
|
|
|
}
|
|
|
- catch { }
|
|
|
- return new SolidColorBrush(Color.Parse(fallbackHex));
|
|
|
- }
|
|
|
|
|
|
- // 甯哥敤蹇嵎鏂规硶
|
|
|
- public static IBrush AppBg() => GetBrush("AppBgBrush", "#0A0E14");
|
|
|
- public static IBrush SurfaceBg() => GetBrush("SurfaceBgBrush", "#111820");
|
|
|
- public static IBrush PanelBg() => GetBrush("PanelBgBrush", "#0D1117");
|
|
|
- public static IBrush Border() => GetBrush("BorderBrush", "#1C2333");
|
|
|
- public static IBrush TextPrimary() => GetBrush("TextPrimaryBrush", "#E6EDF3");
|
|
|
- public static IBrush TextSecondary() => GetBrush("TextSecondaryBrush", "#9CA3AF");
|
|
|
- public static IBrush TextTertiary() => GetBrush("TextTertiaryBrush", "#6B7280");
|
|
|
- public static IBrush TextDisabled() => GetBrush("TextDisabledBrush", "#4B5563");
|
|
|
- public static IBrush Success() => GetBrush("SuccessBrush", "#00897B");
|
|
|
- public static IBrush Warning() => GetBrush("WarningBrush", "#F59E0B");
|
|
|
- public static IBrush Danger() => GetBrush("DangerBrush", "#EF4444");
|
|
|
- public static IBrush Info() => GetBrush("InfoBrush", "#3B82F6");
|
|
|
- public static IBrush HeaderBg() => GetBrush("HeaderBgBrush", "#111820");
|
|
|
- public static IBrush HeaderText() => GetBrush("HeaderTextBrush", "#E6EDF3");
|
|
|
- public static IBrush HeaderSubtext() => GetBrush("HeaderSubtextBrush", "#9CA3AF");
|
|
|
- public static IBrush NavBg() => GetBrush("NavBgBrush", "#111820");
|
|
|
+ ThemeChanged?.Invoke();
|
|
|
+ }
|
|
|
}
|