feat(sprint-3): apply Survey Teal field UI
This commit is contained in:
38
FieldLogger/Resources/Styles/ThemeManager.cs
Normal file
38
FieldLogger/Resources/Styles/ThemeManager.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
namespace FieldLogger.Resources.Styles;
|
||||
|
||||
public enum UlThemeMode
|
||||
{
|
||||
Default,
|
||||
Sunlight,
|
||||
}
|
||||
|
||||
/// <summary>Applies generated semantic colors. Call on the UI thread after app resources initialize.</summary>
|
||||
public static class ThemeManager
|
||||
{
|
||||
private static readonly string[] SemanticColors =
|
||||
[
|
||||
"Canvas", "Surface", "SurfaceRaised", "SurfaceStrong", "Text", "TextMuted",
|
||||
"Primary", "PrimaryPressed", "Accent", "Border", "Focus", "Map", "Success",
|
||||
"Warning", "Error", "Neutral", "Disabled", "OnStrong", "OnPrimary", "OnAccent",
|
||||
];
|
||||
|
||||
public static UlThemeMode Current { get; private set; } = UlThemeMode.Default;
|
||||
|
||||
public static void Apply(UlThemeMode mode)
|
||||
{
|
||||
var resources = Application.Current?.Resources
|
||||
?? throw new InvalidOperationException("Application resources are not initialized.");
|
||||
var prefix = mode == UlThemeMode.Sunlight ? "UlSunlightColor" : "UlDefaultColor";
|
||||
|
||||
foreach (var name in SemanticColors)
|
||||
{
|
||||
if (!resources.TryGetValue($"{prefix}{name}", out var value) || value is not Color color)
|
||||
{
|
||||
throw new InvalidOperationException($"Generated theme token {prefix}{name} is missing.");
|
||||
}
|
||||
resources[$"UlColor{name}"] = color;
|
||||
resources[$"UlBrush{name}"] = new SolidColorBrush(color);
|
||||
}
|
||||
Current = mode;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user