feat(lists): selectable list/folder colors with accent-aware swatches and custom picker

This commit is contained in:
mika kuns
2026-10-01 10:29:53 +02:00
parent d316f3c6a5
commit a6926f53b5
26 changed files with 1529 additions and 45 deletions
+24 -6
View File
@@ -9,14 +9,32 @@ namespace ClaudeDo.Ui.Converters;
// instantiate a generic FuncValueConverter as a resource; they stay one per type so the
// x:Key names in App.axaml keep resolving. Anything with real logic gets its own file.
/// <summary>"#RRGGBB" to a brush; anything else falls back to the app resource named by the parameter.</summary>
public sealed class HexBrushConverter : OneWayConverter
/// <summary>
/// A stored list/folder colour to a brush: "#RRGGBB" becomes a <see cref="SolidColorBrush"/>, a swatch key
/// ("Swatch3") resolves to the app resource "Swatch3Brush"; null, empty or unknown falls back to the resource named by the parameter.
/// </summary>
public sealed class ColorBrushConverter : OneWayConverter
{
public static HexBrushConverter Instance { get; } = new();
public static ColorBrushConverter Instance { get; } = new();
public override object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
=> value is string s && Color.TryParse(s, out var c)
? new SolidColorBrush(c)
: Avalonia.Application.Current?.TryGetResource(parameter as string ?? "", null, out var res) == true ? res : null;
=> Resolve(value as string, parameter as string, LookupResource);
private static object? LookupResource(string key)
=> Avalonia.Application.Current?.TryGetResource(key, null, out var res) == true ? res : null;
/// <summary>Resolves a stored colour against <paramref name="lookup"/> (app resources in production); split out so tests need no Avalonia app.</summary>
internal static object? Resolve(string? value, string? fallbackKey, Func<string, object?> lookup)
{
if (value is { Length: > 0 })
{
if (value[0] == '#')
{
if (Color.TryParse(value, out var c)) return new SolidColorBrush(c);
}
else if (lookup(value + "Brush") is { } swatch) return swatch;
}
return fallbackKey is null ? null : lookup(fallbackKey);
}
}
/// <summary>True when the value's string form equals the parameter (segmented-switch active state).</summary>