The creator: "under Live->Layers->webcam->Properties->border color: in the drop down box, the #hex values are good, but add a corresponding color name/label next to the value." Each row now reads "#e94560 Crimson" - the hex stays exactly as it was, the colour's name goes next to it (dimmed #a0a0b0 so the hex reads first), and the tooltip becomes "Crimson (#e94560)". The 14 colours were a hard-coded string[] inside the click handler - a list of bare strings cannot carry a name, and a list hidden in UI code cannot be asserted on. They now live in Models/BorderColorPalette.cs: NamedColor(Hex, Name) + BorderColorPalette.All (the single source of truth) + NameOf(hex), which answers case-insensitively and falls back to the hex for a colour outside the palette. The picker builds its menu from the catalogue and no longer knows any colour by heart. The names are chosen not to collide - the palette has two greens, two blues and two warm colours: #00FF00 is Lime and #22c55e Emerald, #0000FF is Blue and #3b82f6 Azure, #FF8800 is Orange and #f59e0b Amber. Guard: ytLive.Tests/BorderColorPaletteTests.cs - every entry valid + named, no hex or name repeated, the 14 legacy colours all still offered, NameOf answers, and the old list is gone from the handler. 433/433 green, 0 warnings.
50 lines
2.0 KiB
C#
50 lines
2.0 KiB
C#
namespace ytLive.Models;
|
|
|
|
/// <summary>A colour the border picker offers: its hex value and the plain-English
|
|
/// name shown next to it (TASK 60).</summary>
|
|
/// <param name="Hex">The hex value, e.g. <c>#e94560</c>.</param>
|
|
/// <param name="Name">The name the creator reads, e.g. <c>Crimson</c>.</param>
|
|
public readonly record struct NamedColor(string Hex, string Name);
|
|
|
|
/// <summary>The colours the webcam's border-colour drop-down offers — the SINGLE
|
|
/// source of truth for the list and for the names.
|
|
///
|
|
/// <para>TASK 60 (the creator, 2026-10-21): *"in the drop down box, the #hex values are
|
|
/// good, but add a corresponding color name/label next to the value."* The list used to
|
|
/// be a hard-coded array in the click handler, which is why a name could not be added
|
|
/// to it without touching the UI code.</para>
|
|
/// </summary>
|
|
public static class BorderColorPalette
|
|
{
|
|
/// <summary>The offered colours, in menu order.</summary>
|
|
public static IReadOnlyList<NamedColor> All { get; } = new NamedColor[]
|
|
{
|
|
new("#FFFFFF", "White"),
|
|
new("#000000", "Black"),
|
|
new("#FF0000", "Red"),
|
|
new("#00FF00", "Lime"),
|
|
new("#0000FF", "Blue"),
|
|
new("#FFFF00", "Yellow"),
|
|
new("#FF00FF", "Magenta"),
|
|
new("#00FFFF", "Cyan"),
|
|
new("#FF8800", "Orange"),
|
|
new("#8800FF", "Violet"),
|
|
new("#e94560", "Crimson"),
|
|
new("#22c55e", "Emerald"),
|
|
new("#3b82f6", "Azure"),
|
|
new("#f59e0b", "Amber"),
|
|
};
|
|
|
|
/// <summary>The name of a hex value (case-insensitive). A colour that is not in
|
|
/// the palette keeps its hex — there is no name to give it.</summary>
|
|
public static string NameOf(string hex)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(hex)) return string.Empty;
|
|
var trimmed = hex.Trim();
|
|
foreach (var colour in All)
|
|
if (string.Equals(colour.Hex, trimmed, StringComparison.OrdinalIgnoreCase))
|
|
return colour.Name;
|
|
return trimmed;
|
|
}
|
|
}
|