Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
feat: theme in config
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-houille committed Dec 20, 2023
1 parent 0de511f commit d390672
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 20 deletions.
1 change: 1 addition & 0 deletions EasyGUI/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Themes/White.xaml" />
<ResourceDictionary Source="Resources/Themes/Dark.xaml" />
<ResourceDictionary Source="Resources/GlobalStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
Expand Down
12 changes: 12 additions & 0 deletions EasyGUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
using EasyGUI.Events;
using EasyGUI.Resources;
using EasyLib.Enums;
using EasyLib.Files;
using EasyLib.Job;
using EasyLib.JobManager;
using Application = System.Windows.Application;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;

namespace EasyGUI;
Expand All @@ -20,6 +22,16 @@ public partial class MainWindow

public MainWindow()
{
// checkif os in dark mode
if (ConfigManager.Instance.DarkMode)
{
Application.Current.Resources.MergedDictionaries.RemoveAt(0);
}
else
{
Application.Current.Resources.MergedDictionaries.RemoveAt(1);
}

InitializeComponent();
_jobManager = new LocalJobManager();
foreach (var job in _jobManager.GetJobs())
Expand Down
38 changes: 19 additions & 19 deletions EasyGUI/Resources/GlobalStyles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Setter Property="FontSize" Value="16" />
<Setter Property="FontFamily" Value="Inter, Segoe UI Variable, Arial" />
<Setter Property="FontWeight" Value="Regular" />
<Setter Property="Foreground" Value="{StaticResource TextBlackBrush}"/>
<Setter Property="Foreground" Value="{DynamicResource TextBlackBrush}"/>
</Style>

<Style TargetType="{x:Type TextBox}">
Expand All @@ -26,15 +26,15 @@
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter TargetName="border" Property="BorderBrush" Value="{StaticResource BlueBrush}" />
<Setter TargetName="border" Property="BorderBrush" Value="{DynamicResource BlueBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Background" Value="{StaticResource BackgroundBrush}" />
<Setter Property="Foreground" Value="{StaticResource TextBlackBrush}" />
<Setter Property="BorderBrush" Value="{StaticResource DarkGrayBrush}" />
<Setter Property="Background" Value="{DynamicResource BackgroundBrush}" />
<Setter Property="Foreground" Value="{DynamicResource TextBlackBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource DarkGrayBrush}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Padding" Value="8,6" />
<Setter Property="FontSize" Value="16" />
Expand All @@ -53,28 +53,28 @@
Grid.ColumnSpan="2"
CornerRadius="6"
Padding="6,8"
Background="{StaticResource TextBlackBrush}"
BorderBrush="{StaticResource DarkGrayBrush}"
Background="{DynamicResource BackgroundBrush}"
BorderBrush="{DynamicResource DarkGrayBrush}"
BorderThickness="1" />
<Border
Grid.Column="0"
CornerRadius="6,0,0,6"
Margin="1"
Background="{StaticResource BackgroundBrush}"
BorderBrush="{StaticResource DarkGrayBrush}"
Background="{DynamicResource BackgroundBrush}"
BorderBrush="{DynamicResource DarkGrayBrush}"
BorderThickness="0,0,1,0" />
<Path
x:Name="Arrow"
Grid.Column="1"
Fill="{StaticResource BackgroundBrush}"
Fill="{DynamicResource BackgroundBrush}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Data="M0,0 L0,2 L4,6 L8,2 L8,0 L4,4 z" />
</Grid>
</ControlTemplate>

<ControlTemplate x:Key="ComboBoxTextBox" TargetType="{x:Type TextBox}">
<Border x:Name="PART_ContentHost" Focusable="False" Background="{StaticResource TextWhiteBrush}" />
<Border x:Name="PART_ContentHost" Focusable="False" Background="{DynamicResource TextWhiteBrush}" />
</ControlTemplate>

<Style x:Key="{x:Type ComboBox}" TargetType="{x:Type ComboBox}">
Expand All @@ -85,14 +85,14 @@
<Setter Property="ScrollViewer.CanContentScroll" Value="true" />
<Setter Property="MinWidth" Value="120" />
<Setter Property="MinHeight" Value="34" />
<Setter Property="Foreground" Value="{StaticResource TextBlackBrush}" />
<Setter Property="Foreground" Value="{DynamicResource TextBlackBrush}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBox}">
<Grid>
<ToggleButton
Name="ToggleButton"
Template="{StaticResource ComboBoxToggleButton}"
Template="{DynamicResource ComboBoxToggleButton}"
Grid.Column="2"
Focusable="false"
IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
Expand All @@ -106,7 +106,7 @@
HorizontalAlignment="Left" />
<TextBox x:Name="PART_EditableTextBox"
Style="{x:Null}"
Template="{StaticResource ComboBoxTextBox}"
Template="{DynamicResource ComboBoxTextBox}"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Margin="3,3,23,3"
Expand All @@ -127,9 +127,9 @@
MaxHeight="{TemplateBinding MaxDropDownHeight}">
<Border
x:Name="DropDownBorder"
Background="{StaticResource BackgroundBrush}"
Background="{DynamicResource BackgroundBrush}"
BorderThickness="1"
BorderBrush="{StaticResource DarkGrayBrush}" />
BorderBrush="{DynamicResource DarkGrayBrush}" />
<ScrollViewer Margin="4,6,4,6" SnapsToDevicePixels="True">
<StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" />
</ScrollViewer>
Expand All @@ -141,7 +141,7 @@
<Setter TargetName="DropDownBorder" Property="MinHeight" Value="95" />
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{StaticResource TextWhiteBrush}" />
<Setter Property="Foreground" Value="{DynamicResource TextWhiteBrush}" />
</Trigger>
<Trigger Property="IsGrouping" Value="true">
<Setter Property="ScrollViewer.CanContentScroll" Value="false" />
Expand All @@ -163,7 +163,7 @@

<Style x:Key="{x:Type ComboBoxItem}" TargetType="{x:Type ComboBoxItem}">
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="Foreground" Value="{StaticResource TextBlackBrush}" />
<Setter Property="Foreground" Value="{DynamicResource TextBlackBrush}" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="Template">
<Setter.Value>
Expand All @@ -178,7 +178,7 @@
<Setter TargetName="Border" Property="Background" Value="LightGray" />
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{StaticResource DarkGrayBrush}" />
<Setter Property="Foreground" Value="{DynamicResource DarkGrayBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
Expand Down
6 changes: 5 additions & 1 deletion EasyLib/Files/References/ConfigManagerReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public ConfigManagerReference(string appDataPath)
public ulong MaxFileSize { get; set; } = 1000000;
public int? ServerPort { get; set; }
public string? ServerIp { get; set; }
public bool DarkMode { get; set; } = false;

private static string GenerateRandomKey()
{
Expand Down Expand Up @@ -92,6 +93,7 @@ private void ReadConfig()
PriorityFileExtensions = jsonConfig.PriorityFileExtensions ?? [];
ServerPort = jsonConfig.ServerPort;
ServerIp = jsonConfig.ServerIp;
DarkMode = jsonConfig.DarkMode;

// If the key was null, write the new key
if (xorKey == null)
Expand All @@ -116,7 +118,8 @@ public void WriteConfig()
Language = Language.ToString(),
MaxFileSize = MaxFileSize,
ServerPort = ServerPort,
ServerIp = ServerIp
ServerIp = ServerIp,
DarkMode = DarkMode
};
JsonFileUtils.WriteJson(_configFilePath, jsonConfig);
}
Expand Down Expand Up @@ -150,6 +153,7 @@ public string GetStringProperties()
sb.AppendLine($"MaxFileSize: {MaxFileSize}");
sb.AppendLine($"ServerPort: {ServerPort}");
sb.AppendLine($"ServerIp: {ServerIp ?? "<null>"}");
sb.AppendLine($"DarkMode: {DarkMode}");
return sb.ToString();
}
}
1 change: 1 addition & 0 deletions EasyLib/Json/ConfigElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public string LogFormat
public ulong MaxFileSize { get; init; }
public int? ServerPort { get; init; }
public string? ServerIp { get; init; }
public bool DarkMode { get; init; }
}

0 comments on commit d390672

Please sign in to comment.