This document specifies the current behavior and design of the ColorPicker control as implemented.
For end-user usage and examples, see ColorPicker.
Color via:
#RRGGBB / optional #RRGGBBAA)rgb(…), named colors) (not implemented).Value : ColorAllowAlpha : boolShowPalette : boolPalette : IReadOnlyList<Color?>? (optional override; otherwise derived from Theme.Scheme)ColorPicker is a composite control built from existing visuals:
SwatchVisual preview that renders a border, a checkerboard background, and the selected color over it.Grid with 4 rows (R, G, B, A) and a Slider<int> per channel.
AllowAlpha is false.TextBox wrapped by a ValidationPresenter to display parsing errors.ComputedVisual(BuildPalette) that renders a grid of clickable swatches._root visual.HorizontalAlignment = Align.StretchVerticalAlignment = Align.StartHStack with the swatch on the left and a VStack containing channels + hex row on the right.The control maintains two data flows:
Value → UI controlsPrepareChildren() via UpdateControlsFromValue().R/G/B sliders from Value.ToRgb()A slider from Value.A when AllowAlpha is enabled; otherwise forced to 255#RRGGBB or #RRGGBBAA)The hex text is not overwritten while the user is editing it: when the hex TextBox has focus, updates to Value
do not replace the current hex text.
ValueUpdateValueFromSliders().TextBox.TextDocument.Changed and parsed by UpdateValueFromHex().A private guard (_updatingFromValue) prevents internal feedback loops.
Value is normalized so that:
AllowAlpha is false, the value is forced to ColorKind.Rgb (alpha effectively becomes 255).AllowAlpha is true, the value is represented as ColorKind.RgbA so alpha blending can be previewed.Color.Default is preserved and treated as “no color” in rendering; hex formatting uses #000000 as the placeholder output.ColorPickerStyleSwatchWidth, SwatchHeight, SwatchGlyphs, SwatchBorderStyleCheckerLight, CheckerDarkPaletteColumns, PaletteSwatchWidth, PaletteSwatchHeight, PaletteGapPaletteSelectionGlyphs, PaletteSelectionStyleUppercaseHexColorPickerStyle.Padding exists but is currently not applied by the ColorPicker implementation (reserved for future layout customization).
Value is then drawn as an overlay background on top of the checkerboard.
Value is RgbA, the overlay relies on the CellBuffer’s alpha blending behavior to show the checkerboard through the color.null).swatch.ToRgb() equals Value.ToRgb() (selection ignores alpha).ColorPicker itself is not focusable; it is interacted with via children:
Slider<T> behavior)TextBox behavior)Value)src/XenoAtom.Terminal.UI.Tests/ColorPickerTests.cs:
ValueValue and shows validationValueValuesamples/ControlsDemo/Demos/ColorPickerDemo.cs shows RGB and RGBA variants side-by-side.