Skip to content

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

OptionTypeDefaultWhat it does
minimumdouble0.0
maximumdouble1.0
stepdouble0.00 is continuous; anything else snaps to a multiple of it.
disabledboolfalse
widthfloatkAuto
growfloat1.0fTakes 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.
heightfloat20.0f
showValueboolfalseShows the value at the right of the track.
decimalsint2Digits 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.
namestd::string_viewWhat 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.
valueTextstd::string_viewWhat 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.

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