SliderWidgetHelper
com.jsmacrosce.jsmacros.client.api.helper.screen.SliderWidgetHelper
A JsMacros slider widget with a draggable handle.
The widget value is normalized from 0.0 to 1.0; builder SliderBuilder.initially(int) instead accepts a zero-based position.
The callback runs only when an input changes the value.
js
const screen = Hud.createScreen("a screen", true);
screen.setOnInit(JavaWrapper.methodToJava(function (self) {
const slider = self.sliderBuilder()
.pos(10, 20)
.size(100, 20)
.message("volume")
.steps(10)
.initially(5)
.action(JavaWrapper.methodToJava(function (s) {
Chat.log(`now ${s.getValue()}`);
}))
.build();
slider.setValue(1); // move to the maximum; callback runs if this changes the value
}));
Hud.openScreen(screen);Available in scripts as Widgets.Slider.
Nested types
Constructors
new SliderWidgetHelper
Wraps the supplied slider, using z-index zero for this helper.
Parameters:
btn: the slider to wrap
Methods
getSteps
Returns the configured number of discrete positions (including both endpoints).
Returns: the set amount of steps of this slider.
getValue
Returns the normalized value from
0.0 to 1.0, rounded to one of the configured positions. For n positions, the increments are 1.0 / (n - 1).Returns: the current value of this slider.
setSteps
Sets the number of discrete positions without changing or re-rounding the current value. Unlike the builder, this method does not clamp the count; use at least two positions for normal slider operation.
Parameters:
steps: number of discrete positions
Returns: self for chaining.
setValue
Sets the normalized value, clamping it to
[0.0, 1.0] and rounding to a configured position. The change callback runs only if the resulting value differs.Parameters:
value: requested normalized value
Returns: self for chaining.