CyclingButtonWidgetHelper
com.jsmacrosce.jsmacros.client.api.helper.screen.CyclingButtonWidgetHelper
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
Constructors
new CyclingButtonWidgetHelper
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(CycleButton<T> btn, int zIndex)#Wraps
btn with the supplied helper z-index and an empty tooltip list.Parameters:
btn: the cycling button to wrapzIndex: the helper's draw-ordering value
Methods
backward
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.
cycle
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.
forward
Cycles forward once, wrapping to the first value at the end. The configured action runs as it does for cycle(int).
Returns: self for chaining.
getStringValue
getValue
Returns the selected value; it may have a different type from its displayed text.
Returns: the current value.
setValue
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.