Skip to main content

Slider

This is a slider component that allows users to select a value within a specified range with a dragging interaction.The slider includes a draggable knob and emits events when the value changes or interaction finishes. The value is normalized from 0 and 1. The knob's position is updated based on the current value. And, The component supports animations for knob position updates.

Component Breakdown



Render OrderSets the renderOrder for the visuals of the element.
SizeSets the size of the element. X is width, Y is height and Z is the depth of the underlying collider.
InactiveMakes the element impossible to interact with. Think "grayed out".
Play AudioTurns on the built-in audio cues for the element.
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. So, if the knob is at 0 and you pinch around halfway on the track, the knob will move there automatically, no need to drag.
SegmentedThis checkmark enables a segmented (or digital) behavior for the slider. So instead of smoothly dragging, it will subdivide the slider into stops.
Number of SegmentsSets the number of segments from start to finish inclusive. So if you set this to 3, the three segments will be 0, .5, and 1.
Has Track VisualTurns on the default track visual for this element.
Custom Knob SizeTurns on controls for the knob size.
Knob Size(shows if Custom Knob Size is checked) Set the size of the knob inside of the element.
Add CallbacksAdds the editor hooks for the event callbacks to the element.
On Value Changed CallbacksA callback for when the element's value changes.
On Interaction Finished CallbacksA callback for when the element interaction and changes are all finished.

Code Example

import { DegToRad } from 'SpectaclesInteractionKit.lspkg/Utils/mathUtils';
import { Slider } from 'SpectaclesUIKit.lspkg/Scripts/Components/Slider/Slider';

/**
* A simple programmatic slider example
*/

@component
export class ExampleSliderScript extends BaseScriptComponent {
onAwake() {
const slider = this.sceneObject.createComponent(Slider.getTypeName());
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(`Switch value changed to ${value}`);
});
}
}
Was this page helpful?
Yes
No