Search guides and the APICtrl K
  1. API reference
  2. Native GUI

gfx/colour_selector.h

ColourSelector: choosing a colour.

#include <sonore/gfx/colour_selector.h>
On this page

Design notes

The layout is the reference's

The colour itself across the top with its hex code beside it, a saturation/brightness square with a hue strip next to it, a slider each for red, green, blue and alpha, and a row of swatches. Flags turn the parts on and off, so a picker hanging off a theme swatch in a CallOutBox can be just the square and the strip.

Hue is kept, not recomputed

The selector holds hue, saturation and brightness as numbers of its own and derives the colour from them, rather than holding the colour and deriving HSV every time it is asked. The difference shows at the edges: drag the brightness to zero and every hue is the same black, so a picker that recomputed hue from the colour would snap the strip to red there, and dragging back up would come out red instead of the blue the user started with. Grey loses hue the same way at zero saturation. A colour that arrives from OUTSIDE (setCurrentColour, a slider, a swatch, typed hex) recomputes what it can and keeps the rest.

The square is two gradients

White to the pure hue across, then transparent to black down, composited. That is HSV exactly -- the vertical layer multiplies by brightness, the horizontal one mixes towards white by saturation -- so the square needs no per-pixel loop and no cached image, and a test can read a pixel back and compare it with the conversion the selector itself uses.

The hue strip is one gradient with a stop every sixty degrees, which is also exact: between primaries and secondaries the hue ramp is linear in RGB.

Types 1

class ColourSelector : public Widget

A colour picker.

Reports through onChange with every change, from any of its parts, and never for a colour set with notify false -- the rule every control here follows so a host or a theme pushing a colour in is not echoed back out.

↑↓ to move↵ to openEvery public name in the headers, and every guide