Browse Source

Add themes

Daniel Chalmers 4 years ago
parent
commit
aea7c21081
4 changed files with 67 additions and 1 deletions
  1. 26 1
      DesktopClock/App.xaml.cs
  2. 12 0
      DesktopClock/MainViewModel.cs
  3. 13 0
      DesktopClock/MainWindow.xaml
  4. 16 0
      DesktopClock/Theme.cs

+ 26 - 1
DesktopClock/App.xaml.cs

@@ -1,4 +1,5 @@
-using System.Reflection;
+using System.Collections.Generic;
+using System.Reflection;
 using System.Windows;
 using System.Windows;
 using DesktopClock.Properties;
 using DesktopClock.Properties;
 
 
@@ -12,6 +13,30 @@ namespace DesktopClock
         public static Assembly Assembly { get; } = Assembly.GetExecutingAssembly();
         public static Assembly Assembly { get; } = Assembly.GetExecutingAssembly();
         public static string Title { get; } = Assembly.GetCustomAttribute<AssemblyTitleAttribute>().Title;
         public static string Title { get; } = Assembly.GetCustomAttribute<AssemblyTitleAttribute>().Title;
 
 
+        // https://www.materialui.co/colors
+        public static IReadOnlyCollection<Theme> Themes { get; } = new Theme[]
+        {
+            new Theme("White", "#FFFFFF", "#000000"),
+            new Theme("Black", "#000000", "#9E9E9E"),
+            new Theme("Grey", "#9E9E9E", "#000000"),
+            new Theme("Red", "#ff5252", "#212121"),
+            new Theme("Pink", "#FF4081", "#212121"),
+            new Theme("Purple", "#E040FB", "#212121"),
+            new Theme("Deep Purple", "#7C4DFF", "#212121"),
+            new Theme("Indigo", "#536DFE", "#212121"),
+            new Theme("Blue", "#448AFF", "#212121"),
+            new Theme("Light Blue", "#40C4FF", "#212121"),
+            new Theme("Cyan", "#18FFFF", "#212121"),
+            new Theme("Teal", "#64FFDA", "#212121"),
+            new Theme("Green", "#69F0AE", "#212121"),
+            new Theme("Light Green", "#B2FF59", "#212121"),
+            new Theme("Lime", "#EEFF41", "#212121"),
+            new Theme("Yellow", "#FFFF00", "#212121"),
+            new Theme("Amber", "#FFD740", "#212121"),
+            new Theme("Orange", "#FFAB40", "#212121"),
+            new Theme("Deep Orange", "#FF6E40", "#212121"),
+        };
+
         private void Application_Exit(object sender, ExitEventArgs e)
         private void Application_Exit(object sender, ExitEventArgs e)
         {
         {
             if (!Settings.Default.CheckIfModifiedExternally())
             if (!Settings.Default.CheckIfModifiedExternally())

+ 12 - 0
DesktopClock/MainViewModel.cs

@@ -1,6 +1,7 @@
 using System;
 using System;
 using System.ComponentModel;
 using System.ComponentModel;
 using System.Windows.Input;
 using System.Windows.Input;
+using System.Windows.Media;
 using DesktopClock.Properties;
 using DesktopClock.Properties;
 using GalaSoft.MvvmLight;
 using GalaSoft.MvvmLight;
 using GalaSoft.MvvmLight.CommandWpf;
 using GalaSoft.MvvmLight.CommandWpf;
@@ -32,6 +33,11 @@ namespace DesktopClock
             (Settings.Default.CountdownTo - DateTimeOffset.Now).ToString(Settings.Default.Format) :
             (Settings.Default.CountdownTo - DateTimeOffset.Now).ToString(Settings.Default.Format) :
             CurrentTimeInSelectedTimeZone.ToString(Settings.Default.Format);
             CurrentTimeInSelectedTimeZone.ToString(Settings.Default.Format);
 
 
+        /// <summary>
+        /// Sets app theme to parameter's value.
+        /// </summary>
+        public ICommand SetThemeCommand { get; } = new RelayCommand<Theme>(SetTheme);
+
         /// <summary>
         /// <summary>
         /// Sets format string in settings to parameter's string.
         /// Sets format string in settings to parameter's string.
         /// </summary>
         /// </summary>
@@ -73,5 +79,11 @@ namespace DesktopClock
         }
         }
 
 
         private void UpdateTimeString() => RaisePropertyChanged(nameof(CurrentTimeOrCountdownString));
         private void UpdateTimeString() => RaisePropertyChanged(nameof(CurrentTimeOrCountdownString));
+
+        private static void SetTheme(Theme theme)
+        {
+            Settings.Default.TextColor = (Color)ColorConverter.ConvertFromString(theme.PrimaryColor);
+            Settings.Default.OuterColor = (Color)ColorConverter.ConvertFromString(theme.SecondaryColor);
+        }
     }
     }
 }
 }

+ 13 - 0
DesktopClock/MainWindow.xaml

@@ -60,6 +60,19 @@
                 </MenuItem.Header>
                 </MenuItem.Header>
             </MenuItem>
             </MenuItem>
 
 
+            <MenuItem Header="T_heme"
+                      ItemsSource="{x:Static local:App.Themes}">
+                <MenuItem.Resources>
+                    <Style TargetType="MenuItem">
+                        <Setter Property="Command" Value="{Binding DataContext.SetThemeCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" />
+
+                        <Setter Property="CommandParameter" Value="{Binding}" />
+
+                        <Setter Property="DisplayMemberPath" Value="Name" />
+                    </Style>
+                </MenuItem.Resources>
+            </MenuItem>
+
             <MenuItem Header="Time _Zone"
             <MenuItem Header="Time _Zone"
                       ItemsSource="{x:Static local:DateTimeUtil.TimeZones}">
                       ItemsSource="{x:Static local:DateTimeUtil.TimeZones}">
                 <MenuItem.Resources>
                 <MenuItem.Resources>

+ 16 - 0
DesktopClock/Theme.cs

@@ -0,0 +1,16 @@
+namespace DesktopClock
+{
+    public readonly struct Theme
+    {
+        public string Name { get; }
+        public string PrimaryColor { get; }
+        public string SecondaryColor { get; }
+
+        public Theme(string name, string primaryColor, string secondaryColor)
+        {
+            Name = name;
+            PrimaryColor = primaryColor;
+            SecondaryColor = secondaryColor;
+        }
+    }
+}