Dropdown
Dropdown picks one of many values - languages, biomes, profiles - by opening a picker screen that lists them all, with the same builder as Cycle.
On this page
Picks one of a list of values that is too long to step through with a Cycle: languages, biomes, profiles. It looks like a cycle ("label: value"); pressing it opens a picker screen listing every value.
Dropdown.<String>builder("profile")
.label(Text.translatable("mymod.profile", "Profile"))
.values(profileNames)
.value(() -> config.profile)
.valueText(Text::literal)
.onChange(name -> config.profile = name)
.build();
Builder#
The same setters as Cycle: label, values (not empty, copied at build time), value,
valueText and onChange are all required, plus the options every widget has.
Give the value type explicitly: Dropdown.<String>builder("profile").
The picker screen#
Pressing the dropdown opens a screen built from ordinary entries, which every version can draw:
| Part | Id |
|---|---|
| the screen, titled with the dropdown's label | <id>.picker |
a SelectList of the values, the current one selected; row ids are the indexes 0, 1, … |
<id>.list |
| a Cancel button in the footer | <id>.cancel |
Picking a row closes the picker and then passes the value to onChange. Cancel just closes it. Keep those three
ids free on your screen.
Behaviour#
valueTextis used both on the button and for the picker's rows.- A value that isn't in the list shows as the first one.
- To offer a list that changes, build the screen again (for example, reopen it).
- Footer: yes.
Test it#
host.click("profile"); // opens "profile.picker"
host.select("profile.list", "2"); // picks the third value and closes the picker
Rendered as [dropdown profile] Profile: default.
See also#
- Javadoc: Dropdown