Skip to content

SliderWidgetHelper ​

com.jsmacrosce.jsmacros.client.api.helper.screen.SliderWidgetHelper

Since1.8.4

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 ​

new SliderWidgetHelper(Slider btn)#
Wraps the supplied slider, using z-index zero for this helper.

Parameters:

  • btn: the slider to wrap
new SliderWidgetHelper(Slider btn, int zIndex)#
Wraps the supplied slider and sets this helper's drawing-order index.

Parameters:

  • btn: the slider to wrap
  • zIndex: the drawing-order index for this helper

Methods ​

getSteps ​

getSteps(): intSince1.8.4#
Returns the configured number of discrete positions (including both endpoints).
Returns: the set amount of steps of this slider.

getValue ​

getValue(): doubleSince1.8.4#
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 ​

setSteps(int steps): SliderWidgetHelperSince1.8.4#
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 ​

setValue(double value): SliderWidgetHelperSince1.8.4#
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.

toString ​

toString(): String#
Returns a formatted diagnostic containing this slider's message, value, and step count. The message is inserted without JSON escaping, and numeric formatting follows the default locale.
Returns: the formatted diagnostic string