mirror of
https://github.com/FroggMaster/CreamInstaller.git
synced 2026-06-12 19:11:25 -07:00
Fixes bug with toggling dark mode
- Fixes issue with toggling dark mode after having added a game to the list, the store identifier / proxy toggle would not properly change colors.
This commit is contained in:
@@ -29,6 +29,7 @@ internal sealed class CustomTreeView : TreeView
|
|||||||
|
|
||||||
private readonly Dictionary<TreeNode, Rectangle> selectionBounds = [];
|
private readonly Dictionary<TreeNode, Rectangle> selectionBounds = [];
|
||||||
private SolidBrush backBrush;
|
private SolidBrush backBrush;
|
||||||
|
private Color lastBackColor; // Tracks the last background color
|
||||||
private ToolStripDropDown comboBoxDropDown;
|
private ToolStripDropDown comboBoxDropDown;
|
||||||
private Font comboBoxFont;
|
private Font comboBoxFont;
|
||||||
private Form form;
|
private Form form;
|
||||||
@@ -65,6 +66,9 @@ internal sealed class CustomTreeView : TreeView
|
|||||||
checkBoxBounds.Clear();
|
checkBoxBounds.Clear();
|
||||||
comboBoxBounds.Clear();
|
comboBoxBounds.Clear();
|
||||||
selectionBounds.Clear();
|
selectionBounds.Clear();
|
||||||
|
backBrush?.Dispose();
|
||||||
|
backBrush = null;
|
||||||
|
lastBackColor = Color.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawTreeNode(object sender, DrawTreeNodeEventArgs e)
|
private void DrawTreeNode(object sender, DrawTreeNodeEventArgs e)
|
||||||
@@ -76,7 +80,15 @@ internal sealed class CustomTreeView : TreeView
|
|||||||
|
|
||||||
bool highlighted = (e.State & TreeNodeStates.Selected) == TreeNodeStates.Selected && Focused;
|
bool highlighted = (e.State & TreeNodeStates.Selected) == TreeNodeStates.Selected && Focused;
|
||||||
Graphics graphics = e.Graphics;
|
Graphics graphics = e.Graphics;
|
||||||
backBrush ??= new(BackColor);
|
|
||||||
|
// Recreate brush if background color changed
|
||||||
|
if (backBrush == null || lastBackColor != BackColor)
|
||||||
|
{
|
||||||
|
backBrush?.Dispose();
|
||||||
|
backBrush = new(BackColor);
|
||||||
|
lastBackColor = BackColor;
|
||||||
|
}
|
||||||
|
|
||||||
Font font = node.NodeFont ?? Font;
|
Font font = node.NodeFont ?? Font;
|
||||||
Brush brush = highlighted ? SystemBrushes.Highlight : backBrush;
|
Brush brush = highlighted ? SystemBrushes.Highlight : backBrush;
|
||||||
Rectangle bounds = node.Bounds;
|
Rectangle bounds = node.Bounds;
|
||||||
@@ -95,7 +107,7 @@ internal sealed class CustomTreeView : TreeView
|
|||||||
Color color = highlighted
|
Color color = highlighted
|
||||||
? C1
|
? C1
|
||||||
: Enabled
|
: Enabled
|
||||||
? C2
|
? ThemeManager.CustomTreeViewPlatformColor
|
||||||
: C3;
|
: C3;
|
||||||
string text;
|
string text;
|
||||||
if (dlcType is not DLCType.None)
|
if (dlcType is not DLCType.None)
|
||||||
@@ -117,7 +129,7 @@ internal sealed class CustomTreeView : TreeView
|
|||||||
color = highlighted
|
color = highlighted
|
||||||
? C4
|
? C4
|
||||||
: Enabled
|
: Enabled
|
||||||
? C5
|
? ThemeManager.CustomTreeViewIdColor
|
||||||
: C6;
|
: C6;
|
||||||
text = id;
|
text = id;
|
||||||
size = TextRenderer.MeasureText(graphics, text, font);
|
size = TextRenderer.MeasureText(graphics, text, font);
|
||||||
@@ -163,7 +175,7 @@ internal sealed class CustomTreeView : TreeView
|
|||||||
checkBoxBounds = new(checkBoxBounds.Location, checkBoxBounds.Size + bounds.Size with { Height = 0 });
|
checkBoxBounds = new(checkBoxBounds.Location, checkBoxBounds.Size + bounds.Size with { Height = 0 });
|
||||||
graphics.FillRectangle(backBrush, bounds);
|
graphics.FillRectangle(backBrush, bounds);
|
||||||
point = new(bounds.Location.X - 1 + left, bounds.Location.Y + 1);
|
point = new(bounds.Location.X - 1 + left, bounds.Location.Y + 1);
|
||||||
TextRenderer.DrawText(graphics, text, font, point, Enabled ? C7 : C8, TextFormatFlags.Default);
|
TextRenderer.DrawText(graphics, text, font, point, Enabled ? ThemeManager.CustomTreeViewProxyColor : C8, TextFormatFlags.Default);
|
||||||
|
|
||||||
this.checkBoxBounds[selection] = RectangleToClient(checkBoxBounds);
|
this.checkBoxBounds[selection] = RectangleToClient(checkBoxBounds);
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,18 @@ internal static class ThemeManager
|
|||||||
private static readonly Color LightFore = SystemColors.ControlText;
|
private static readonly Color LightFore = SystemColors.ControlText;
|
||||||
private static readonly Color LightBorder = SystemColors.ControlDark;
|
private static readonly Color LightBorder = SystemColors.ControlDark;
|
||||||
|
|
||||||
|
internal static Color CustomTreeViewPlatformColor => Program.DarkModeEnabled
|
||||||
|
? ColorTranslator.FromHtml("#FFFF99") // Light yellow for dark mode
|
||||||
|
: ColorTranslator.FromHtml("#696900"); // Dark yellow for light mode
|
||||||
|
|
||||||
|
internal static Color CustomTreeViewIdColor => Program.DarkModeEnabled
|
||||||
|
? ColorTranslator.FromHtml("#99FFFF") // Light cyan for dark mode
|
||||||
|
: ColorTranslator.FromHtml("#006969"); // Dark cyan for light mode
|
||||||
|
|
||||||
|
internal static Color CustomTreeViewProxyColor => Program.DarkModeEnabled
|
||||||
|
? ColorTranslator.FromHtml("#99FF99") // Light green for dark mode
|
||||||
|
: ColorTranslator.FromHtml("#006900"); // Dark green for light mode
|
||||||
|
|
||||||
internal static void ToggleDarkMode(Form anyForm)
|
internal static void ToggleDarkMode(Form anyForm)
|
||||||
{
|
{
|
||||||
Program.DarkModeEnabled = !Program.DarkModeEnabled;
|
Program.DarkModeEnabled = !Program.DarkModeEnabled;
|
||||||
@@ -85,6 +97,7 @@ internal static class ThemeManager
|
|||||||
tv.BackColor = DarkBackAlt;
|
tv.BackColor = DarkBackAlt;
|
||||||
tv.ForeColor = DarkFore;
|
tv.ForeColor = DarkFore;
|
||||||
tv.LineColor = DarkBorder;
|
tv.LineColor = DarkBorder;
|
||||||
|
tv.Invalidate(); // Forces a redraw
|
||||||
break;
|
break;
|
||||||
case RichTextBox rtb:
|
case RichTextBox rtb:
|
||||||
rtb.BackColor = DarkBackAlt;
|
rtb.BackColor = DarkBackAlt;
|
||||||
@@ -135,6 +148,7 @@ internal static class ThemeManager
|
|||||||
tv.BackColor = LightBack;
|
tv.BackColor = LightBack;
|
||||||
tv.ForeColor = LightFore;
|
tv.ForeColor = LightFore;
|
||||||
tv.LineColor = LightBorder;
|
tv.LineColor = LightBorder;
|
||||||
|
tv.Invalidate(); // Forces a redraw
|
||||||
break;
|
break;
|
||||||
case RichTextBox rtb:
|
case RichTextBox rtb:
|
||||||
rtb.BackColor = LightBack;
|
rtb.BackColor = LightBack;
|
||||||
|
|||||||
Reference in New Issue
Block a user