overhaul ThemeHelper

This commit is contained in:
Pilzinsel64
2024-11-29 07:58:35 +01:00
parent 55bf37619b
commit df264ac20d
3 changed files with 60 additions and 11 deletions

View File

@@ -4,32 +4,56 @@ namespace Pilz.UI.Telerik.Theming;
public static class ThemeHelper
{
[Obsolete()]
public static void ApplyApplicationTheme(ApplicationTheme theme, Func<RadThemeComponentBase> getLightTheme, Func<RadThemeComponentBase> getDarkTheme)
{
ApplyApplicationTheme(theme, getLightTheme, getDarkTheme, getDarkTheme);
}
[Obsolete()]
public static void ApplyApplicationTheme(ApplicationTheme theme, Func<RadThemeComponentBase> getLightTheme, Func<RadThemeComponentBase> getDarkTheme, Func<RadThemeComponentBase> getGrayTheme)
{
ThemeResolutionService.ApplicationThemeName = GetThemeName(theme, getLightTheme, getDarkTheme, getGrayTheme).ThemeName;
ApplyApplicationTheme(new(theme, HighContrastMode.Auto), def => def.Theme switch
{
ApplicationTheme.Light => getLightTheme(),
ApplicationTheme.Dark => getDarkTheme(),
ApplicationTheme.Gray => getGrayTheme(),
_ => throw new NotImplementedException(),
});
}
public static RadThemeComponentBase GetThemeName(ApplicationTheme theme, Func<RadThemeComponentBase> getLightTheme, Func<RadThemeComponentBase> getDarkTheme, Func<RadThemeComponentBase> getGrayTheme)
public static void ApplyApplicationTheme(ThemeDefinition themeDefinition, Func<ThemeDefinition, RadThemeComponentBase> getTheme)
{
RadThemeComponentBase? themeToUse;
ThemeResolutionService.ApplicationThemeName = GetThemeName(themeDefinition, getTheme).ThemeName;
}
if (theme == ApplicationTheme.Light || theme == ApplicationTheme.Auto && WindowsSettings.AppsUseLightTheme)
themeToUse = getLightTheme();
else if (theme == ApplicationTheme.Dark || theme == ApplicationTheme.Auto && !WindowsSettings.AppsUseLightTheme)
themeToUse = getDarkTheme();
else /*if (CoreSettings.AppTheme == ApplicationTheme.Gray)*/
themeToUse = getGrayTheme();
public static RadThemeComponentBase GetThemeName(ThemeDefinition themeDefinition, Func<ThemeDefinition, RadThemeComponentBase> getTheme)
{
ApplicationTheme themeToUse;
HighContrastMode highContrast;
return themeToUse;
if (themeDefinition.HighContrast == HighContrastMode.Enable || themeDefinition.HighContrast == HighContrastMode.Auto && SystemInformation.HighContrast)
highContrast = HighContrastMode.Enable;
else
highContrast = HighContrastMode.Disable;
if (themeDefinition.Theme == ApplicationTheme.Light || themeDefinition.Theme == ApplicationTheme.Auto && WindowsSettings.AppsUseLightTheme)
themeToUse = ApplicationTheme.Light;
else if (themeDefinition.Theme == ApplicationTheme.Dark || themeDefinition.Theme == ApplicationTheme.Auto && !WindowsSettings.AppsUseLightTheme)
themeToUse = ApplicationTheme.Dark;
else
themeToUse = ApplicationTheme.Gray;
return getTheme(new(themeToUse, highContrast));
}
public static bool IsDarkTheme(ApplicationTheme theme)
{
return theme == ApplicationTheme.Dark || theme == ApplicationTheme.Gray || theme == ApplicationTheme.Auto && !WindowsSettings.AppsUseLightTheme;
}
public static bool IsHighContrast(HighContrastMode theme)
{
return theme == HighContrastMode.Enable || theme == HighContrastMode.Auto && SystemInformation.HighContrast;
}
}