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:
@@ -17,8 +17,18 @@ namespace OpenNest
|
|||||||
["Dark"] = BuildDark()
|
["Dark"] = BuildDark()
|
||||||
};
|
};
|
||||||
|
|
||||||
public static IEnumerable<ColorScheme> AllSchemes =>
|
private static List<ColorScheme> diskCache;
|
||||||
builtIns.Values.Concat(LoadDiskSchemes());
|
|
||||||
|
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)
|
public static ColorScheme Get(string name)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ namespace OpenNest
|
|||||||
if (string.IsNullOrWhiteSpace(hex))
|
if (string.IsNullOrWhiteSpace(hex))
|
||||||
return Color.Black;
|
return Color.Black;
|
||||||
var h = hex.TrimStart('#');
|
var h = hex.TrimStart('#');
|
||||||
|
if (h.Length < 6)
|
||||||
|
return Color.Black;
|
||||||
var r = byte.Parse(h.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
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 g = byte.Parse(h.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||||
var b = byte.Parse(h.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
var b = byte.Parse(h.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||||
|
|||||||
@@ -464,6 +464,9 @@ namespace OpenNest.Controls
|
|||||||
|
|
||||||
protected override void OnPaint(PaintEventArgs e)
|
protected override void OnPaint(PaintEventArgs e)
|
||||||
{
|
{
|
||||||
|
if (BackColor != ColorScheme.BackgroundColor)
|
||||||
|
BackColor = ColorScheme.BackgroundColor;
|
||||||
|
|
||||||
e.Graphics.SmoothingMode = SmoothingMode.HighSpeed;
|
e.Graphics.SmoothingMode = SmoothingMode.HighSpeed;
|
||||||
|
|
||||||
if (DrawOrigin)
|
if (DrawOrigin)
|
||||||
|
|||||||
Reference in New Issue
Block a user