# CyclingButtonWidgetHelper

`com.jsmacrosce.jsmacros.client.api.helper.screen.CyclingButtonWidgetHelper`

**Since:** 1.8.4

A button that displays a selected value and cycles through configured values when
pressed.  

Values may have any type; the builder's converter supplies the text displayed for
each value.  

When configured with a non-empty alternate list and a toggle, the toggle selects
which list cycling uses; otherwise it uses the default list.  
```js
const screen = Hud.createScreen("a screen", true);  
screen.setOnInit(JavaWrapper.methodToJava(function (self) {
  const button = self.cyclicButtonBuilder(JavaWrapper.methodToJava(function (value) {
    return Chat.createTextHelperFromString(String(value));  
  }))
     .pos(10, 20)
     .size(100, 20)
     .option("quality")
     .values(["low", "medium", "high"])
     .initially("low")
     .build();  

  // the value is whatever type the values were, and the string form is the label
  Chat.log(`${button.getValue()}, shown as ${button.getStringValue()}`);  
  // step to the next one, forwards or backwards
  button.forward();  
  button.backward();  
}));  
Hud.openScreen(screen);  
```

Available in scripts as `Widgets.CyclingButton`.

## Type Parameters

- `T`: the type of values displayed by the button

## Nested types

- [CyclicButtonBuilder](CyclingButtonWidgetHelper.CyclicButtonBuilder.md)

## Constructors

### new CyclingButtonWidgetHelper {#com.jsmacrosce.jsmacros.client.api.helper.screen.CyclingButtonWidgetHelper_constructor-CycleButton-}

```js
new CyclingButtonWidgetHelper(CycleButton<T> btn)
```

Wraps `btn` with helper z-index `0` and an empty tooltip list.

**Parameters:**
- `btn`: the cycling button to wrap

### new CyclingButtonWidgetHelper {#com.jsmacrosce.jsmacros.client.api.helper.screen.CyclingButtonWidgetHelper_constructor-CycleButton-int-}

```js
new CyclingButtonWidgetHelper(CycleButton<T> btn, int zIndex)
```

Wraps `btn` with the supplied helper z-index and an empty tooltip list.

**Parameters:**
- `btn`: the cycling button to wrap
- `zIndex`: the helper's draw-ordering value

## Methods

### backward {#com.jsmacrosce.jsmacros.client.api.helper.screen.CyclingButtonWidgetHelper_backward-}

```js
backward(): CyclingButtonWidgetHelper<T>
```

Steps the button back one value, wrapping from the first value to the last. The
builder's action runs as it does during a click.

**Returns:** self for chaining.

**Since:** 1.8.4

### cycle {#com.jsmacrosce.jsmacros.client.api.helper.screen.CyclingButtonWidgetHelper_cycle-int-}

```js
cycle(int amount): CyclingButtonWidgetHelper<T>
```

Cycles by `amount` positions, wrapping at either end; positive values move
forward and negative values backward. The configured action runs for each cycle,  
including a cycle that leaves the selected value unchanged.

**Parameters:**
- `amount`: the amount to cycle by

**Returns:** self for chaining.

**Since:** 1.8.4

### forward {#com.jsmacrosce.jsmacros.client.api.helper.screen.CyclingButtonWidgetHelper_forward-}

```js
forward(): CyclingButtonWidgetHelper<T>
```

Cycles forward once, wrapping to the first value at the end. The configured
action runs as it does for [cycle(int)](#com.jsmacrosce.jsmacros.client.api.helper.screen.CyclingButtonWidgetHelper_cycle-int-).

**Returns:** self for chaining.

**Since:** 1.8.4

### getStringValue {#com.jsmacrosce.jsmacros.client.api.helper.screen.CyclingButtonWidgetHelper_getStringValue-}

```js
getStringValue(): String
```

Returns the current value converted by the builder, as plain text without styling
or the option prefix. This need not match the value's `toString()`.

**Returns:** the current value's converted display text, without styling or prefix.

**Since:** 1.8.4

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

```js
getValue(): T
```

Returns the selected value; it may have a different type from its displayed text.

**Returns:** the current value.

**Since:** 1.8.4

### setValue {#com.jsmacrosce.jsmacros.client.api.helper.screen.CyclingButtonWidgetHelper_setValue-T-}

```js
setValue(T val): boolean
```

Sets the displayed value directly without cycling. If `val` is not in the
currently selected list, the display changes but the cycle index remains
unchanged.  

The return value is `true` when the previous value equals `val`; the
value is set regardless. Equality uses `equals`.  

A change here is written straight onto the button rather than pressed into it, so
the action given to the builder does not run.

**Parameters:**
- `val`: the new value

**Returns:** `true` if the button was already on `val`, so this call left
it where it was, and `false` if the call moved it there.

**Since:** 1.8.4

### toString {#com.jsmacrosce.jsmacros.client.api.helper.screen.CyclingButtonWidgetHelper_toString-}

```js
toString(): String
```

Returns a diagnostic string containing the current value's converted display text.

**Returns:** a diagnostic string containing the converted display text
