Skip to content

SliderWidgetHelper.SliderBuilder ​

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

Since1.8.4

Builds sliders for the screen returned by IScreen.sliderBuilder().
Defaults to two positions and position zero. Set steps(int) before initially(int), since the latter clamps against the current count.

Nested type declared in SliderWidgetHelper.

Constructors ​

new SliderWidgetHelper.SliderBuilder ​

new SliderWidgetHelper.SliderBuilder(IScreen screen)#
Associates this builder with the screen that will receive widgets built from it.

Parameters:

  • screen: the screen to associate with this builder

Methods ​

action ​

Sets the callback invoked with the built slider and its screen when the slider value changes, whether by dragging or by SliderWidgetHelper.setValue(double). Passing null clears the callback.

Parameters:

  • action: the change listener for the slider
Returns: self for chaining.

createWidget ​

createWidget(): SliderWidgetHelper#
Constructs a slider from the builder's configured geometry, message, step count, and initial step converted to a normalized fraction. The configured action receives this helper and its associated screen; exceptions from the action are logged. The returned helper uses the configured z-index; build() applies the other builder properties and adds the widget to the associated screen.
Returns: the helper wrapping the constructed slider

getAction ​

getAction(): MethodWrapper<SliderWidgetHelper, IScreen, Object, ?>Since1.8.4#
Returns the configured change callback, or null if none is set.
Returns: the change listener of the slider.

getSteps ​

getSteps(): intSince1.8.4#
Returns the configured number of discrete positions; defaults to two.
Returns: the amount of steps of this slider.

getValue ​

getValue(): intSince1.8.4#
Returns the builder's configured starting position as a zero-based step number; it defaults to zero.
Returns: the initial value of the slider.

initially ​

initially(int value): SliderWidgetHelper.SliderBuilderSince1.8.4#
Sets the starting position as a zero-based step number, clamped to the range from zero through steps - 1. The clamp reads the step count as it stands at the moment of the call, so a chain that sets the value before the steps is clamping against the default of two and a value of five becomes one. Setting the steps first is what makes this land where it looks like it should. The widget value is a normalized fraction, so the step number is divided by steps - 1 (for example, step five of ten corresponds to 5/9).
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)
     .build();
  // step five of ten is five ninths along, not halfway
  Chat.log(`built at ${slider.getValue()}`);
}));
Hud.openScreen(screen);

Parameters:

  • value: the initial value of the slider. Must be between 0 and steps - 1
Returns: self for chaining.

steps ​

steps(int steps): SliderWidgetHelper.SliderBuilderSince1.8.4#
Sets the number of discrete positions, clamping values below two to two. Does not re-clamp a previously configured starting position.

Parameters:

  • steps: requested number of positions; values below two become two
Returns: self for chaining.