UI Toolbox logoUI Toolbox
Support

RangeSlider

A RangeSlider is a slider with two thumbs that sets a range, a low and a high value. Its value is a Vector2: x is the low value and y is the high value.

Difficulty and enemy level sliders, each with two handlesDifficulty and enemy level sliders, each with two handles

<UIToolbox.RangeSlider
    label="Price"
    low-limit="0"
    high-limit="500"
    step="10"
    show-values="true" />
<UIToolbox.RangeSlider
    label="Level"
    low-limit="1"
    high-limit="60"
    whole-numbers="true"
    min-range="5" />
var slider = new RangeSlider("Price")
{
    LowLimit = 0,
    HighLimit = 500,
    Step = 10
};
slider.value = new Vector2(100, 300);
slider.RegisterValueChangedCallback(evt =>
    Debug.Log($"{evt.newValue.x} to {evt.newValue.y}"));
Member Description
LowLimit (low-limit) The smallest value (0).
HighLimit (high-limit) The largest value (100).
Step (step) The distance between the values the thumbs take. 0 (the default) is continuous.
WholeNumbers (whole-numbers) Rounds the values to whole numbers. The step is then at least 1.
MinRange (min-range) The smallest distance between the thumbs.
ShowValues (show-values) Shows the low value at the left and the high value at the right of the track.
FormatString (format-string) The format of the shown values. The default shows no decimals with WholeNumbers and up to two otherwise.
value The range as a Vector2. A set sorts the two numbers, snaps them to the step, clamps them to the limits and keeps the distance of MinRange.

The UXML value attribute takes a Vector2, which the UI Builder writes. Without a value, the range is the full range, from LowLimit to HighLimit. A change of a limit, the step or MinRange applies to the current value again.

Pointer

Keyboard and gamepad

Tab (or a gamepad move to the next control) focuses each thumb in turn. The keys act on the focused thumb.

Key Action
Left, Right Moves the thumb by Step, or by 1% of the range when the step is 0. A key at the end of the way moves the focus on.
Page Up, Page Down Moves the thumb by 10% of the range.
Home, End Moves the thumb to the low or the high limit, or as near as the other thumb allows.

The gamepad D-pad and stick act like Left and Right.

Events

A change of the value from the pointer, the keys or value sends one ChangeEvent<Vector2>. A key or a drag step that changes nothing sends none, and SetValueWithoutNotify sends none.

Styling

Class Element
tb-range-slider The field.
tb-range-slider__track The area of the rails and the thumbs.
tb-range-slider__rail The line behind the thumbs.
tb-range-slider__fill The part between the thumbs, in the accent color.
tb-range-slider__thumb A thumb. tb-range-slider__thumb--low and tb-range-slider__thumb--high mark the two.
tb-range-slider__value A shown value. tb-range-slider__value--low and tb-range-slider__value--high mark the two.

The colors come from --tb-color-accent, --tb-color-text, --tb-color-border and --tb-color-surface-alt. The thumb fades between the colors with --tb-animation-duration-fast.

The RangeSliderDemo scene shows the distance at which enemies spawn around the player, a price range that filters a shop and a level range that picks the players of a match.