Skip to content

ColorPicker

Components · interactive

A colour picker: a saturation/value square, a hue rail and an alpha rail.

Import

cpp
#include "gbui/widgets/colorPicker.hpp"

Example

ColorPicker

colorPicker · Components · interactive

Nothing is downloaded until you press it.

cpp
ColorPickerResult colorPicker(Ui& ui, const Interaction& input, std::string_view id, ColorPickerState& state, const ColorPickerOptions& options = {});

Draws the picker and edits state in place. The square is built the way every picker on the web is: the pure hue behind, a white-to-transparent gradient across it and a transparent-to-black gradient down it. Two gradients over a fill is a two-dimensional ramp, and it costs three nodes rather than a per-pixel shader the painter does not have.

ColorField

colorField · Components · interactive

Nothing is downloaded until you press it.

cpp
ColorPickerResult colorField(Ui& ui, const Interaction& input, std::string_view id, ColorPickerState& state, const ColorFieldOptions& options = {});

The same picker behind a swatch, opened in a popover. Two entry points rather than a flag, because they are two different components in every way that matters: the inline one is always open and owns its space, and this one is a control in a form that borrows space when asked. They share the state and the drawing, which is the part worth sharing. The application owns whether it is open, as it does for every other overlay here — state.open is a plain bool it can set, restore or ignore.

API

ColorPickerOptions

OptionTypeDefaultWhat it does
alphabooltrueThe alpha rail and the alpha in the readout. Off for a picker choosing a theme token, where a translucent colour is not a valid answer.
huebooltrueThe hue rail. Off leaves a picker that only shades one hue, which is what a "tint of the accent" control wants.
showHexbooltrueThe #rrggbb readout under the rails.
swatchesstd::vector<Color>A row of fixed swatches under everything else. Empty draws none.
widthfloat240.0f
squareHeightfloat150.0f
railHeightfloat14.0f
gapfloat10.0f
namestd::string_viewWhat colour this is of — "Accent", "Series 3". The value announces itself as a hex code; only the caller knows what it colours.

ColorFieldOptions

OptionTypeDefaultWhat it does
heightfloat28.0fThe trigger's own size. The popover takes width from the picker options above, as everything else does.
showHexOnTriggerbooltrueThe hex code beside the swatch on the closed control. Off leaves the swatch alone, which is what a trigger in a tight toolbar wants.
disabledboolfalse
dismissOnOutsideClickbooltrueA press anywhere else closes it. On, because a popup that outlives the attention that opened it is a popup the reader has to dismiss on purpose. Off keeps it open until the application says otherwise — which is what a picker being dragged from inside a dialog wants, where the click outside belongs to the dialog.
dismissOnEscapebooltrueEscape closes it. Separate from the above: a caller may want the key without the click, and a modal that owns Escape may want neither.

Released under the LGPL-3.0-or-later licence.