Class SelectList
java.lang.Object
dev.xichil.mvui.Entry
dev.xichil.mvui.SelectList
A scrolling list of rows of text, at most one of them selected, like vanilla's world or server lists. The rows come
from a supplier that is re-read on every refresh, so the list follows the mod's data; the selection lives in the
entry and is identified by row id.
SelectList profiles = SelectList.builder("profiles")
.rows(() -> {
List<SelectList.Row> rows = new ArrayList<>();
for (Profile p : store.profiles()) {
rows.add(SelectList.Row.of(p.id(), Text.literal(p.name())));
}
return rows;
})
.build();
Button delete = Button.builder("delete")
.label(Text.translatable("mymod.delete", "Delete"))
.enabled(() -> profiles.selected() != null)
.onPress(() -> store.delete(profiles.selected()))
.build();
Required: rows. Row ids must be unique within the list; a duplicate throws when the rows are
read. When the selected row disappears from the rows, the selection is cleared (without calling
onSelect).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilds aSelectList; frombuilder(String).static final classOne row of aSelectList: an id the mod knows it by, and the text shown. -
Method Summary
Modifier and TypeMethodDescription<R> Raccept(EntryVisitor<R> visitor) Calls theEntryVisitormethod for this entry's type (visitButtonfor aButton, …) and returns its result.static SelectList.BuilderStarts building a list.rows()The current rows, from the mod's supplier.voidSelects a row and notifiesonSelect, as a click on the row does.selected()The selected row's id, ornullif no row is selected.
-
Method Details
-
builder
Starts building a list.- Parameters:
id- the list's id, unique within its screen- Returns:
- a new builder
- Throws:
IllegalArgumentException- ifidis invalid
-
rows
The current rows, from the mod's supplier. Drops the selection if its row is gone.- Returns:
- an unmodifiable copy of the rows
- Throws:
IllegalStateException- if two rows have the same id
-
selected
The selected row's id, ornullif no row is selected. Mods read it from actions, e.g. a "Load" button that loads the selected profile.- Returns:
- the selected row's id, or
nullif no row is selected
-
select
Selects a row and notifiesonSelect, as a click on the row does. A mod may call it from an action, e.g.select(null)after deleting the selected item.- Parameters:
rowId- a row id, ornullto clear the selection
-
accept
Description copied from class:EntryCalls theEntryVisitormethod for this entry's type (visitButtonfor aButton, …) and returns its result. ASectionvisits as its header, aNumberFieldas itsTextInput.
-