Class Cycle<T>
java.lang.Object
dev.xichil.mvui.Entry
dev.xichil.mvui.Cycle<T>
- Type Parameters:
T- the value type
A button that steps through a fixed list of values, shown as "label: value" like vanilla's option buttons
(e.g. "Graphics: Fancy"). Each click selects the next value, wrapping around after the last. Good for a handful of
values, typically an enum; for long lists use a
Dropdown, which has the same builder.
Cycle.<Mode>builder("mode")
.label(Text.translatable("mymod.mode", "Mode"))
.values(Arrays.asList(Mode.values()))
.value(() -> config.mode)
.valueText(m -> Text.translatable("mymod.mode." + m.name().toLowerCase(Locale.ROOT), m.name()))
.onChange(m -> config.mode = m)
.build();
Required: label, values (not empty), value,
valueText, onChange. The value lives in the mod. Values are
compared with Object.equals(Object); a current value that is not in the list shows as the first one.
Backends work with indexes (index(), select(int), next()) so they never need the value
type.
-
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 <T> Cycle.Builder<T> Starts building a cycle.intindex()Index of the mod's current value invalues(); 0 if the current value is not in the list.label()The text before ": value", from the mod's supplier.voidnext()Selects the value after the current one, wrapping to the first after the last, as a click does.voidselect(int index) Passes the value atindextoonChange, even if it is the current one.values()The values, in cycling order: a copy of the builder's list taken at build time.The current value's text, shown after "label: ".Every value's text, invalues()order, from the mod'svalueTextfunction.
-
Method Details
-
builder
Starts building a cycle. Java usually can't inferTfrom a chained call, so give it explicitly:Cycle.<Mode>builder("mode").- Type Parameters:
T- the value type- Parameters:
id- the cycle's id, unique within its screen- Returns:
- a new builder
- Throws:
IllegalArgumentException- ifidis invalid
-
label
The text before ": value", from the mod's supplier.- Returns:
- the text shown before the value
-
values
-
valueTexts
-
index
public int index()Index of the mod's current value invalues(); 0 if the current value is not in the list.- Returns:
- the index of the current value, or 0 if it is not in the list
-
valueText
The current value's text, shown after "label: ".- Returns:
- the text of the current value
-
select
public void select(int index) Passes the value atindextoonChange, even if it is the current one.- Parameters:
index- an index intovalues()- Throws:
IndexOutOfBoundsException- ifindexis out of range
-
next
public void next()Selects the value after the current one, wrapping to the first after the last, 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.
-