Slider
slider · Elements · interactive
A single-value slider.
Import
cpp
#include "gbui/widgets/slider.hpp"Example
Nothing is downloaded until you press it.
cpp
[[nodiscard]] SliderResult slider(Ui& ui, const Interaction& input, std::string_view id, double value, const SliderOptions& options = {});Follows the pointer while it is held, even when it wanders off the track — which is what Interaction::dragging is for.
API
SliderOptions
| Option | Type | Default | What it does |
|---|---|---|---|
minimum | double | 0.0 | |
maximum | double | 1.0 | |
step | double | 0.0 | 0 is continuous; anything else snaps to a multiple of it. |
disabled | bool | false | |
width | float | kAuto | |
grow | float | 1.0f | Takes the free space on the parent's main axis, which is what a slider in a row wants and the only thing grow can mean. In a column the main axis is vertical, so this used to make a slider eat the leftover height and sit alone at the bottom of its card. It no longer can: the control is clamped to height whichever way it is pointed, so growing is free horizontally and impossible vertically. |
height | float | 20.0f | |
showValue | bool | false | Shows the value at the right of the track. |
decimals | int | 2 | Digits in the label showValue draws. It does not round the value: the caller's number is untouched, and a slider that quietly rounded it would be one you cannot set to a third. |
name | std::string_view | What this slider is called, for a reader who cannot see the caption beside it. Unnecessary when a label or a field names it — those attach the relation instead. | |
valueText | std::string_view | What a reader hears instead of the number — "70 percent", "3 of 8". Empty falls back to the number, which is right for a bare fraction and wrong for everything with a unit. The toolkit cannot supply this: it has no locale to spell a unit in and no idea what the number counts. |