Class Toggle
java.lang.Object
dev.xichil.mvui.Entry
dev.xichil.mvui.Toggle
An on/off setting, drawn as a vanilla button reading "label: ON" or "label: OFF" (
UiTexts.ON,
UiTexts.OFF), like the toggles on vanilla's options screens. A click flips it.
Toggle.builder("particles")
.label(Text.translatable("mymod.particles", "Particles"))
.value(() -> config.particles)
.onChange(on -> config.particles = on)
.build();
The value lives in the mod: the button shows what value returns, and a click calls onChange with
the opposite. Required: label, value, onChange.
Checkbox is the same setting drawn as a check box.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescription<R> Raccept(EntryVisitor<R> visitor) Calls theEntryVisitormethod for this entry's type (visitButtonfor aButton, …) and returns its result.static Toggle.BuilderStarts building a toggle.label()The text before ": ON/OFF", from the mod's supplier.voidset(boolean newValue) PassesnewValuetoonChange, even if it equals the current value.voidtoggle()Passes the opposite ofvalue()toonChange, as a click does.booleanvalue()The mod's current value, from itsvaluesupplier.
-
Method Details
-
builder
Starts building a toggle.- Parameters:
id- the toggle's id, unique within its screen- Returns:
- a new builder
- Throws:
IllegalArgumentException- ifidis invalid
-
label
-
value
public boolean value()The mod's current value, from itsvaluesupplier.- Returns:
trueif the toggle shows ON
-
set
public void set(boolean newValue) PassesnewValuetoonChange, even if it equals the current value.- Parameters:
newValue- the new value
-
toggle
public void toggle()Passes the opposite ofvalue()toonChange, as a click does. -
accept
Description copied from class:EntryCalls theEntryVisitormethod for this entry's type (visitButtonfor aButton, …) and returns its result. ASectionvisits as its header, aNumberFieldas itsTextInput.
-