Skip to content

Commit

Permalink
Fixed tab color issue when changing theme (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpeyr committed Dec 10, 2023
1 parent 9394770 commit 92a46ee
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 14 deletions.
11 changes: 10 additions & 1 deletion ColorPicker/Classes/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
using Synethia;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design.Serialization;
using System.Linq;
using System.Threading;
using System.Windows;
Expand Down Expand Up @@ -254,7 +255,7 @@ public static AppPages PageInfoToAppPages(PageInfo pageInfo)
/// <summary>
/// Changes the application's theme.
/// </summary>
public static void ChangeTheme()
public static void ChangeTheme(bool reload = false)
{
App.Current.Resources.MergedDictionaries.Clear();
ResourceDictionary resourceDictionary = new(); // Create a resource dictionary
Expand All @@ -275,6 +276,14 @@ public static void ChangeTheme()
}

App.Current.Resources.MergedDictionaries.Add(resourceDictionary); // Add the dictionary

if (!reload) return;
AiGenPage.CheckButton(AiGenPage.CheckedButton);
BookmarksPage.CheckButton(BookmarksPage.CheckedButton);
ConverterPage.CheckButton(ConverterPage.SelectedColorBtn);
ChromaticWheelPage.CheckButton(ChromaticWheelPage.CheckedButton);
HarmoniesPage.CheckButton(HarmoniesPage.SelectedColorBtn);
PalettePage.CheckButton(PalettePage.SelectedColorBtn);
}

public static bool IsSystemThemeDark()
Expand Down
6 changes: 5 additions & 1 deletion ColorPicker/Pages/AiGenPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ private void InitUI()
if (!string.IsNullOrEmpty(Global.Settings.ApiKey))
{
CheckButton(ColorBtn);
CheckedButton = ColorBtn;
ColorPanel.Visibility = Visibility.Visible;
ApiPlaceholder.Visibility = Visibility.Collapsed;
return;
Expand Down Expand Up @@ -202,7 +203,8 @@ private async void GenerateBtn_Click(object sender, RoutedEventArgs e)
catch { }
}

private void CheckButton(Button button) => button.Background = Global.GetColorFromResource("LightAccentColor");
internal Button CheckedButton;
internal void CheckButton(Button button) => button.Background = Global.GetColorFromResource("LightAccentColor");

private void UnCheckAllButtons()
{
Expand All @@ -218,6 +220,7 @@ private void ColorBtn_Click(object sender, RoutedEventArgs e)
if (string.IsNullOrEmpty(Global.Settings.ApiKey)) return;
UnCheckAllButtons();
CheckButton(ColorBtn);
CheckedButton = ColorBtn;
ColorPanel.Visibility = Visibility.Visible;
}

Expand All @@ -226,6 +229,7 @@ private void PaletteBtn_Click(object sender, RoutedEventArgs e)
if (string.IsNullOrEmpty(Global.Settings.ApiKey)) return;
UnCheckAllButtons();
CheckButton(PaletteBtn);
CheckedButton = PaletteBtn;
PalettePanel.Visibility = Visibility.Visible;
}

Expand Down
3 changes: 2 additions & 1 deletion ColorPicker/Pages/BookmarksPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ private void UnCheckAllButtons()
TextBookmarks.Visibility = Visibility.Collapsed;
}

private void CheckButton(Button button) => button.Background = Global.GetColorFromResource("LightAccentColor");
internal Button CheckedButton;
internal void CheckButton(Button button) { button.Background = Global.GetColorFromResource("LightAccentColor"); CheckedButton = button; }

private void TextBtn_Click(object sender, RoutedEventArgs e)
{
Expand Down
3 changes: 2 additions & 1 deletion ColorPicker/Pages/ChromaticWheelPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ private void UnCheckAllButtons()
ShadesBtn.Background = new SolidColorBrush { Color = Colors.Transparent };
}

private void CheckButton(Button button) => button.Background = Global.GetColorFromResource("LightAccentColor");
internal Button CheckedButton;
internal void CheckButton(Button button) { button.Background = Global.GetColorFromResource("LightAccentColor"); CheckedButton = button; }

private void CopyYiqBtn_Click(object sender, RoutedEventArgs e)
{
Expand Down
4 changes: 2 additions & 2 deletions ColorPicker/Pages/ConverterPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void InitUI()
}, null);
}

Button SelectedColorBtn { get; set; }
internal Button SelectedColorBtn { get; set; }
private void UnCheckAllButtons()
{
RgbBtn.Background = new SolidColorBrush { Color = Colors.Transparent };
Expand All @@ -100,7 +100,7 @@ internal void RgbBtn_Click(object sender, RoutedEventArgs? e)
LoadInputUI();
}

private void CheckButton(Button button) => button.Background = Global.GetColorFromResource("LightAccentColor");
internal void CheckButton(Button button) => button.Background = Global.GetColorFromResource("LightAccentColor");
internal ColorInfo ColorInfo { get; set; }

private RGB ConvertToRgb()
Expand Down
4 changes: 2 additions & 2 deletions ColorPicker/Pages/HarmoniesPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private RGB ConvertToRgb()
double.Parse(Txt3.Text)));
}

Button SelectedColorBtn { get; set; }
internal Button SelectedColorBtn { get; set; }
private void UnCheckAllButtons()
{
RgbBtn.Background = new SolidColorBrush { Color = Colors.Transparent };
Expand All @@ -247,7 +247,7 @@ internal void RgbBtn_Click(object sender, RoutedEventArgs? e)
Global.SynethiaConfig.PagesInfo[7].InteractionCount++;
}

private void CheckButton(Button button) => button.Background = Global.GetColorFromResource("LightAccentColor");
internal void CheckButton(Button button) => button.Background = Global.GetColorFromResource("LightAccentColor");

private void HideAllInput()
{
Expand Down
5 changes: 2 additions & 3 deletions ColorPicker/Pages/PalettePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
using ColorPicker.Enums;
using ColorPicker.Windows;
using Synethia;
using System.Security.Cryptography;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
Expand Down Expand Up @@ -103,7 +102,7 @@ private RGB ConvertToRgb()
double.Parse(Txt3.Text)));
}

Button SelectedColorBtn { get; set; }
internal Button SelectedColorBtn { get; set; }
private void UnCheckAllButtons()
{
RgbBtn.Background = new SolidColorBrush { Color = Colors.Transparent };
Expand All @@ -128,7 +127,7 @@ internal void RgbBtn_Click(object sender, RoutedEventArgs? e)
LoadInputUI();
}

private void CheckButton(Button button) => button.Background = Global.GetColorFromResource("LightAccentColor");
internal void CheckButton(Button button) => button.Background = Global.GetColorFromResource("LightAccentColor");

private void HideAllInput()
{
Expand Down
6 changes: 3 additions & 3 deletions ColorPicker/Pages/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private void LightBorder_MouseLeftButtonUp(object sender, MouseButtonEventArgs e
SynethiaManager.Save(Global.SynethiaConfig, Global.SynethiaPath);
XmlSerializerManager.SaveToXml(Global.Bookmarks, Global.BookmarksPath);

Global.ChangeTheme();
Global.ChangeTheme(true);
}

private void DarkBorder_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
Expand All @@ -214,7 +214,7 @@ private void DarkBorder_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
SynethiaManager.Save(Global.SynethiaConfig, Global.SynethiaPath);
XmlSerializerManager.SaveToXml(Global.Bookmarks, Global.BookmarksPath);

Global.ChangeTheme();
Global.ChangeTheme(true);
}
private void SystemBorder_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
Expand All @@ -227,7 +227,7 @@ private void SystemBorder_MouseLeftButtonUp(object sender, MouseButtonEventArgs
SynethiaManager.Save(Global.SynethiaConfig, Global.SynethiaPath);
XmlSerializerManager.SaveToXml(Global.Bookmarks, Global.BookmarksPath);

Global.ChangeTheme();
Global.ChangeTheme(true);
}

private void LangComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
Expand Down

0 comments on commit 92a46ee

Please sign in to comment.