Class Dropdown<T>
java.lang.Object
dev.xichil.mvui.Entry
dev.xichil.mvui.Dropdown<T>
- Type Parameters:
T- the value type
Picks one of a list of values, for lists too long to step through with a
Cycle: languages, biomes, profiles.
It has the same builder and the same value handling as a cycle; only pressing it differs.
Dropdown.<String>builder("profile")
.label(Text.translatable("mymod.profile", "Profile"))
.values(profileNames)
.value(() -> config.profile)
.valueText(Text::literal)
.onChange(name -> config.profile = name)
.build();
How it looks and behaves
Backends draw it like a cycle: a button "label: value". Pressing it callsopen(UiHost), which opens a picker
screen titled with the label: the values as a SelectList (<id>.list, row ids are the indexes, the
current value selected) and a Cancel button (<id>.cancel) in the footer. Picking a row closes the picker, as
UiHost.back(), and then passes the value to onChange. No backend draws a popup list (TODO.md
Phase 11). The picker's ids are derived from the dropdown's, so keep <id>.picker, <id>.list and
<id>.cancel free.
Required: label, values (not empty), value,
valueText, onChange. Allowed in a MenuScreen's footer.
-
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> Dropdown.Builder<T> Starts building a dropdown.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; also the picker screen's title.voidOpens the picker screen onhost, the current value selected.voidselect(int index) Passes the value atindextoonChange, even if it is the current one.values()The values, in list 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: the picker's rows.
-
Method Details
-
builder
Starts building a dropdown. GiveTexplicitly:Dropdown.<String>builder("profile").- Type Parameters:
T- the value type- Parameters:
id- the dropdown's id, unique within its screen- Returns:
- a new builder
- Throws:
IllegalArgumentException- ifidis invalid
-
label
The text before ": value", from the mod's supplier; also the picker screen's title.- 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
-
open
Opens the picker screen onhost, the current value selected. Backends call it when the button is pressed, with their own host; the picker belongs to the same mod as this entry, forFailsafe. Picking a row goesbackand thenselectsit; Cancel just goes back.- Parameters:
host- the host showing this dropdown's screen
-
accept
Description copied from class:EntryCalls theEntryVisitormethod for this entry's type (visitButtonfor aButton, …) and returns its result. ASectionvisits as its header, aNumberFieldas itsTextInput.
-