overhaul ThemeHelper
This commit is contained in:
8
Pilz.UI.Telerik/Theming/HighContrastMode.cs
Normal file
8
Pilz.UI.Telerik/Theming/HighContrastMode.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Pilz.UI.Telerik.Theming;
|
||||
|
||||
public enum HighContrastMode
|
||||
{
|
||||
Auto,
|
||||
Enable,
|
||||
Disable,
|
||||
}
|
||||
17
Pilz.UI.Telerik/Theming/ThemeDefinition.cs
Normal file
17
Pilz.UI.Telerik/Theming/ThemeDefinition.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace Pilz.UI.Telerik.Theming;
|
||||
|
||||
public class ThemeDefinition
|
||||
{
|
||||
public ApplicationTheme Theme { get; set; }
|
||||
public HighContrastMode HighContrast { get; set; }
|
||||
|
||||
public ThemeDefinition()
|
||||
{
|
||||
}
|
||||
|
||||
public ThemeDefinition(ApplicationTheme theme, HighContrastMode highContrast)
|
||||
{
|
||||
Theme = theme;
|
||||
HighContrast = highContrast;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user