TASK 60: the border-colour drop-down names every colour

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.
This commit is contained in:
2026-10-21 20:03:19 -07:00
parent 89f6aa3a67
commit 6271bf34c9
10 changed files with 231 additions and 16 deletions
+21 -7
View File
@@ -247,21 +247,35 @@ public partial class LeftPanel : UserControl
if (sender is FrameworkElement fe && fe.ContextMenu == null)
{
var menu = new System.Windows.Controls.ContextMenu();
string[] colors = ["#FFFFFF", "#000000", "#FF0000", "#00FF00", "#0000FF",
"#FFFF00", "#FF00FF", "#00FFFF", "#FF8800", "#8800FF",
"#e94560", "#22c55e", "#3b82f6", "#f59e0b"];
foreach (var c in colors)
foreach (var swatch in BorderColorPalette.All)
{
var item = new System.Windows.Controls.MenuItem { Header = c, ToolTip = c };
// TASK 60: the hex stays, and the colour's NAME goes next to it.
var header = new System.Windows.Controls.StackPanel
{
Orientation = System.Windows.Controls.Orientation.Horizontal
};
header.Children.Add(new System.Windows.Controls.TextBlock { Text = swatch.Hex });
header.Children.Add(new System.Windows.Controls.TextBlock
{
Text = swatch.Name,
Foreground = new System.Windows.Media.SolidColorBrush(
System.Windows.Media.Color.FromRgb(0xa0, 0xa0, 0xb0)),
Margin = new System.Windows.Thickness(10, 0, 0, 0)
});
var item = new System.Windows.Controls.MenuItem
{
Header = header,
ToolTip = $"{swatch.Name} ({swatch.Hex})"
};
var brush = new System.Windows.Media.SolidColorBrush(
(System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(c));
(System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(swatch.Hex));
item.Icon = new System.Windows.Controls.Border
{
Width = 16, Height = 16,
Background = brush,
CornerRadius = new System.Windows.CornerRadius(2)
};
var color = c;
var color = swatch.Hex;
item.Click += (_, _) => src.BorderColor = color;
menu.Items.Add(item);
}