mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-31 14:58:22 -04:00
[GUI] Clean up theme management
This commit is contained in:
parent
19f678ca01
commit
239c47c06e
7 changed files with 62 additions and 56 deletions
|
@ -14,10 +14,12 @@
|
||||||
|
|
||||||
<!-- Merged dictionaries -->
|
<!-- Merged dictionaries -->
|
||||||
<ResourceDictionary.MergedDictionaries>
|
<ResourceDictionary.MergedDictionaries>
|
||||||
|
<!-- Colors are irrelevant because they are overriden in runtime -->
|
||||||
<materialDesign:BundledTheme
|
<materialDesign:BundledTheme
|
||||||
BaseTheme="Light"
|
BaseTheme="Light"
|
||||||
PrimaryColor="Blue"
|
PrimaryColor="Blue"
|
||||||
SecondaryColor="Blue" />
|
SecondaryColor="Blue" />
|
||||||
|
|
||||||
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
|
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
|
||||||
</ResourceDictionary.MergedDictionaries>
|
</ResourceDictionary.MergedDictionaries>
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using DiscordChatExporter.Gui.Internal;
|
||||||
|
using MaterialDesignThemes.Wpf;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Gui
|
namespace DiscordChatExporter.Gui
|
||||||
{
|
{
|
||||||
|
@ -13,4 +15,31 @@ namespace DiscordChatExporter.Gui
|
||||||
|
|
||||||
public static string VersionString => Version.ToString(3);
|
public static string VersionString => Version.ToString(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public partial class App
|
||||||
|
{
|
||||||
|
private static Theme LightTheme { get; } = Theme.Create(
|
||||||
|
new MaterialDesignLightTheme(),
|
||||||
|
MediaColor.FromHex("#343838"),
|
||||||
|
MediaColor.FromHex("#F9A825")
|
||||||
|
);
|
||||||
|
|
||||||
|
private static Theme DarkTheme { get; } = Theme.Create(
|
||||||
|
new MaterialDesignDarkTheme(),
|
||||||
|
MediaColor.FromHex("#E8E8E8"),
|
||||||
|
MediaColor.FromHex("#F9A825")
|
||||||
|
);
|
||||||
|
|
||||||
|
public static void SetLightTheme()
|
||||||
|
{
|
||||||
|
var paletteHelper = new PaletteHelper();
|
||||||
|
paletteHelper.SetTheme(LightTheme);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetDarkTheme()
|
||||||
|
{
|
||||||
|
var paletteHelper = new PaletteHelper();
|
||||||
|
paletteHelper.SetTheme(DarkTheme);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -13,6 +13,14 @@ namespace DiscordChatExporter.Gui
|
||||||
{
|
{
|
||||||
public class Bootstrapper : Bootstrapper<RootViewModel>
|
public class Bootstrapper : Bootstrapper<RootViewModel>
|
||||||
{
|
{
|
||||||
|
protected override void OnStart()
|
||||||
|
{
|
||||||
|
base.OnStart();
|
||||||
|
|
||||||
|
// Light theme is the default
|
||||||
|
App.SetLightTheme();
|
||||||
|
}
|
||||||
|
|
||||||
protected override void ConfigureIoC(IStyletIoCBuilder builder)
|
protected override void ConfigureIoC(IStyletIoCBuilder builder)
|
||||||
{
|
{
|
||||||
base.ConfigureIoC(builder);
|
base.ConfigureIoC(builder);
|
||||||
|
|
9
DiscordChatExporter.Gui/Internal/MediaColor.cs
Normal file
9
DiscordChatExporter.Gui/Internal/MediaColor.cs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
using System.Windows.Media;
|
||||||
|
|
||||||
|
namespace DiscordChatExporter.Gui.Internal
|
||||||
|
{
|
||||||
|
internal static class MediaColor
|
||||||
|
{
|
||||||
|
public static Color FromHex(string hex) => (Color) ColorConverter.ConvertFromString(hex);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,42 +0,0 @@
|
||||||
using MaterialDesignThemes.Wpf;
|
|
||||||
using System.Windows.Media;
|
|
||||||
|
|
||||||
namespace DiscordChatExporter.Gui
|
|
||||||
{
|
|
||||||
public sealed class Theme
|
|
||||||
{
|
|
||||||
public static Theme Light { get; } = new Theme(new MaterialDesignLightTheme(), HexToColor.Convert("#343838"), HexToColor.Convert("#F9A825"));
|
|
||||||
public static Theme Dark { get; } = new Theme(new MaterialDesignDarkTheme(), HexToColor.Convert("#E8E8E8"), HexToColor.Convert("#F9A825"));
|
|
||||||
|
|
||||||
public static void SetCurrent(Theme theme)
|
|
||||||
{
|
|
||||||
var paletteHelper = new PaletteHelper();
|
|
||||||
|
|
||||||
var materialTheme = paletteHelper.GetTheme();
|
|
||||||
materialTheme.SetBaseTheme(theme.BaseTheme);
|
|
||||||
materialTheme.SetPrimaryColor(theme.PrimaryColor);
|
|
||||||
materialTheme.SetSecondaryColor(theme.SecondaryColor);
|
|
||||||
|
|
||||||
paletteHelper.SetTheme(materialTheme);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Theme(IBaseTheme baseTheme, Color primaryColor, Color secondaryColor)
|
|
||||||
{
|
|
||||||
BaseTheme = baseTheme;
|
|
||||||
PrimaryColor = primaryColor;
|
|
||||||
SecondaryColor = secondaryColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IBaseTheme BaseTheme { get; }
|
|
||||||
public Color PrimaryColor { get; }
|
|
||||||
public Color SecondaryColor { get; }
|
|
||||||
|
|
||||||
class HexToColor
|
|
||||||
{
|
|
||||||
public static Color Convert(string hex)
|
|
||||||
{
|
|
||||||
return (Color)ColorConverter.ConvertFromString(hex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -108,7 +108,14 @@ namespace DiscordChatExporter.Gui.ViewModels
|
||||||
TokenValue = _settingsService.LastToken.Value;
|
TokenValue = _settingsService.LastToken.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
Theme.SetCurrent(_settingsService.IsDarkThemeEnabled ? Theme.Dark : Theme.Light);
|
if (_settingsService.IsDarkThemeEnabled)
|
||||||
|
{
|
||||||
|
App.SetDarkTheme();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
App.SetLightTheme();
|
||||||
|
}
|
||||||
|
|
||||||
await HandleAutoUpdateAsync();
|
await HandleAutoUpdateAsync();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
using MaterialDesignThemes;
|
using System.Windows;
|
||||||
using MaterialDesignThemes.Wpf;
|
|
||||||
using System.Windows.Media.Media3D;
|
|
||||||
|
|
||||||
namespace DiscordChatExporter.Gui.Views.Dialogs
|
namespace DiscordChatExporter.Gui.Views.Dialogs
|
||||||
{
|
{
|
||||||
|
@ -11,19 +9,14 @@ namespace DiscordChatExporter.Gui.Views.Dialogs
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ToggleButton_Checked(object sender, System.Windows.RoutedEventArgs e)
|
private void ToggleButton_Checked(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
setBaseTheme(Theme.Dark);
|
App.SetDarkTheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ToggleButton_Unchecked(object sender, System.Windows.RoutedEventArgs e)
|
private void ToggleButton_Unchecked(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
setBaseTheme(Theme.Light);
|
App.SetLightTheme();
|
||||||
}
|
|
||||||
|
|
||||||
private void setBaseTheme(Theme theme)
|
|
||||||
{
|
|
||||||
Theme.SetCurrent(theme);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue