Widgets»Slider

Slider

HSlider and VSlider widgets allow numeric data to be specified by manipulating a horizontal or a vertical handle in a fashion similar to scrollbars, yet with slighly different interaction behaviors.

Source docs

Sliding the handle or picking its location will change the position property. Its possible values range from minValue to maxValue. By default, linearly moving the handle will linearly change the value.

This may be changing by supplying an inputMap and a outputMap.

Whenever the position field is changed manually within a Slider, it is mapped using the inputMap to the [0..1] range and represented as the handle position.

Whenever the position field is read from a Slider, the handle's position within [0..1] is mapped to the user scale by the outputMap.

Supplying both of these functions will allow a slider to provide e.g. logarithmic or exponential scale. For reference, the default implementations look like this:

protected final float linearInputMap(float f) {
    return (f - _minValue) / (_maxValue - _minValue);
}


protected final float linearOutputMap(float f) {
    return f * (_maxValue - _minValue) + _minValue;
}

Usage example:

auto slider = HSlider().minValue(-3.f).maxValue(3.f).layoutAttribs("hexpand hfill");
float pos = slider.position;

VSlider().layoutAttribs("vexpand vfill");