fix(ui): address code review issues in color scheme feature

- Sync PlateView.BackColor on repaint so live scheme switch updates background
- Guard FromHex against truncated hex strings (< 6 chars)
- Cache disk schemes to avoid re-reading Schemes/ folder on every access

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-15 21:56:15 -04:00
parent 320cf40f41
commit a6ec21accc
3 changed files with 17 additions and 2 deletions
+12 -2
View File
@@ -17,8 +17,18 @@ namespace OpenNest
["Dark"] = BuildDark()
};
public static IEnumerable<ColorScheme> AllSchemes =>
builtIns.Values.Concat(LoadDiskSchemes());
private static List<ColorScheme> diskCache;
public static IEnumerable<ColorScheme> AllSchemes
{
get
{
diskCache ??= LoadDiskSchemes().ToList();
return builtIns.Values.Concat(diskCache);
}
}
public static void Refresh() => diskCache = null;
public static ColorScheme Get(string name)
{
+2
View File
@@ -59,6 +59,8 @@ namespace OpenNest
if (string.IsNullOrWhiteSpace(hex))
return Color.Black;
var h = hex.TrimStart('#');
if (h.Length < 6)
return Color.Black;
var r = byte.Parse(h.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
var g = byte.Parse(h.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
var b = byte.Parse(h.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
+3
View File
@@ -464,6 +464,9 @@ namespace OpenNest.Controls
protected override void OnPaint(PaintEventArgs e)
{
if (BackColor != ColorScheme.BackgroundColor)
BackColor = ColorScheme.BackgroundColor;
e.Graphics.SmoothingMode = SmoothingMode.HighSpeed;
if (DrawOrigin)