# SliderWidgetHelper.SliderBuilder

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

**Since:** 1.8.4

Builds sliders for the screen returned by [IScreen.sliderBuilder()](../../classes/render/IScreen.md#com.jsmacrosce.jsmacros.client.api.classes.render.IScreen_sliderBuilder-).  
Defaults to two positions and position zero. Set [steps(int)](#com.jsmacrosce.jsmacros.client.api.helper.screen.SliderWidgetHelper.SliderBuilder_steps-int-) before
[initially(int)](#com.jsmacrosce.jsmacros.client.api.helper.screen.SliderWidgetHelper.SliderBuilder_initially-int-), since the latter clamps against the current count.

Nested type declared in [SliderWidgetHelper](SliderWidgetHelper.md).

## Constructors

### new SliderWidgetHelper.SliderBuilder {#com.jsmacrosce.jsmacros.client.api.helper.screen.SliderWidgetHelper.SliderBuilder_constructor-IScreen-}

```js
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 {#com.jsmacrosce.jsmacros.client.api.helper.screen.SliderWidgetHelper.SliderBuilder_action-MethodWrapper-}

```js
action(MethodWrapper<SliderWidgetHelper, IScreen, Object, ?> action): SliderWidgetHelper.SliderBuilder
```

Sets the callback invoked with the built slider and its screen when the
slider value changes, whether by dragging or by [SliderWidgetHelper.setValue(double)](SliderWidgetHelper.md#com.jsmacrosce.jsmacros.client.api.helper.screen.SliderWidgetHelper_setValue-double-).  
Passing `null` clears the callback.

**Parameters:**
- `action`: the change listener for the slider

**Returns:** self for chaining.

**Since:** 1.8.4

### createWidget {#com.jsmacrosce.jsmacros.client.api.helper.screen.SliderWidgetHelper.SliderBuilder_createWidget-}

```js
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 {#com.jsmacrosce.jsmacros.client.api.helper.screen.SliderWidgetHelper.SliderBuilder_getAction-}

```js
getAction(): MethodWrapper<SliderWidgetHelper, IScreen, Object, ?>
```

Returns the configured change callback, or `null` if none is set.

**Returns:** the change listener of the slider.

**Since:** 1.8.4

### getSteps {#com.jsmacrosce.jsmacros.client.api.helper.screen.SliderWidgetHelper.SliderBuilder_getSteps-}

```js
getSteps(): int
```

Returns the configured number of discrete positions; defaults to two.

**Returns:** the amount of steps of this slider.

**Since:** 1.8.4

### getValue {#com.jsmacrosce.jsmacros.client.api.helper.screen.SliderWidgetHelper.SliderBuilder_getValue-}

```js
getValue(): int
```

Returns the builder's configured starting position as a zero-based step
number; it defaults to zero.

**Returns:** the initial value of the slider.

**Since:** 1.8.4

### initially {#com.jsmacrosce.jsmacros.client.api.helper.screen.SliderWidgetHelper.SliderBuilder_initially-int-}

```js
initially(int value): SliderWidgetHelper.SliderBuilder
```

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`).  

```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)
     .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.

**Since:** 1.8.4

### steps {#com.jsmacrosce.jsmacros.client.api.helper.screen.SliderWidgetHelper.SliderBuilder_steps-int-}

```js
steps(int steps): SliderWidgetHelper.SliderBuilder
```

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.

**Since:** 1.8.4
