Skip to main content

Slider

Reference for the UI Kit 4.0.0 Slider component: pick a value between 0 and 1 by dragging in a SPECS Lens, with segments, a track fill, a knob icon, and value events.

  • Snapchat: not supported
  • SPECS: fully supported
  • Camera Kit Web: not supported
  • Camera Kit Mobile: not supported
  • SnapchatNot supported
  • SPECSFully supported
  • Camera Kit WebNot supported
  • Camera Kit MobileNot supported

Platform details

  • Snapchat — Not supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Not supported.

  • Camera Kit Mobile — Not supported.

The UI Kit Slider component lets people select a value within a range with a dragging interaction. The value is normalized from 0 to 1, and the knob's position follows the current value. The Slider emits onValueChange with the committed value and onKnobMoved continuously while the knob moves. It can animate the knob to a new value: updateCurrentValue(value, true) springs the knob there.

On the System 3.0 theme, the Slider element itself is the track and there is no separate knob. A slider taller than about 1.6 cm renders as a slab, so keep its height small.

A System 3.0 slider partway filled while it is dragged

Slider Inspector properties

The Slider component in the Inspector, with Segmented, Custom Knob Size, and Add Callbacks checked
PropertyDescription
Render OrderSets the renderOrder for the visuals of the element.
InactiveMakes the element ignore input and shows its inactive look. Think "grayed out."
Play AudioTurns on the built-in audio cues for the element.
ThemeThe theme the slider uses: Inherited (the default, follows the global theme) or System 3.0.
SizeSets the size of the element in centimeters. X is width, Y is height and Z is the depth of the underlying collider. The default is 6 × 3 × 1.
Default ValueThe starting value, between 0 and 1, for the knob of the slider and values of the slider.
Snap To Trigger PositionEnables a jump to trigger position behavior on the track. For example, if the knob is at 0 and you pinch around halfway on the track, the knob moves there automatically, with no need to drag.
SegmentedEnables a segmented (or digital) behavior for the slider. Instead of smoothly dragging, it subdivides the slider into stops.
Number Of Segments(shows if Segmented is checked) Sets the number of segments from start to finish inclusive. For example, if you set this to 3, the three segments are 0, .5, and 1. The default is 5 and the minimum is 2.
Has Track VisualShows a fill on the track up to the knob's position. On by default.
Custom Knob SizeTurns on controls for the knob size.
Knob Size(shows if Custom Knob Size is checked) Sets the size of the knob inside of the element. The default is 3 × 3.
Knob IconAn optional icon drawn on the knob, which moves with it. Leave it empty for no icon.
Add CallbacksAdds the editor hooks for the event callbacks to the element.
On Value Changed Callbacks(shows if Add Callbacks is checked) A callback for when the element's value changes.

Create a Slider from a script

The script below creates a slider, rotates it to stand vertically, and prints its value when it changes. To set the value from your own state without firing onValueChange, call resetToValue(value); updateCurrentValue(value) sets it and fires the event.

import { DegToRad } from 'InteractionKit.lspkg/Utils/mathUtils';
import { Slider } from 'UIKit.lspkg/Scripts/Components/Slider/Slider';

/**
* A simple programmatic slider example
*/

@component
export class ExampleSliderScript extends BaseScriptComponent {
onAwake() {
const slider = this.sceneObject.createComponent(
Slider.getTypeName()
) as Slider;
slider.size = new vec3(20, 4, 1);
slider.transform.setLocalRotation(
quat.fromEulerVec(new vec3(0, 0, DegToRad * -90))
);
slider.initialize();
slider.onValueChange.add((value) => {
print(`Slider value changed to ${value}`);
});
}
}

The example's slider is 4 cm tall. On System 3.0 a slider taller than about 1.6 cm renders as a slab, so use a height of 1.6 cm or less there.