Class MenuScreen
java.lang.Object
dev.xichil.mvui.Screen
dev.xichil.mvui.MenuScreen
The main screen type: a title, a vertical, scrolling list of
entries, and a row of footer entries at
the bottom (usually "Done"). Backends draw it like vanilla's options screens: one widget per row in the list, the
footer buttons side by side below it.
MenuScreen screen = MenuScreen.builder("main")
.title(Text.translatable("mymod.title", "My Mod"))
.add(Toggle.builder("enabled")
.label(Text.translatable("mymod.enabled", "Enabled"))
.value(() -> config.enabled)
.onChange(v -> config.enabled = v)
.build())
.add(Section.builder("advanced")
.title(Text.translatable("mymod.advanced", "Advanced"))
.add(Slider.builder("speed")…build())
.build())
.footer(Button.builder("done").label(UiTexts.DONE).onPress(host::back).build())
.build();
Rules, checked by the builder
- Entry ids are unique across the whole screen: list entries, section children and footer entries together.
MenuScreen.Builder.build()throwsIllegalStateExceptionon a duplicate. - A
Sectionis added as a whole:MenuScreen.Builder.add(Entry)adds the section and then its children, so they follow it inentries(). Adding a section's child on its own throws. - Only always-visible buttons and text may be in the footer; see
MenuScreen.Builder.footer(Entry).
Backends draw every entry of entries() that is Entry.visible and leave out the others; a
collapsed section's children are not visible. A screen is immutable once built, but its entries' suppliers make
what it shows dynamic.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionall()static MenuScreen.BuilderStarts building a menu screen.entries()The list's entries in screen order, top to bottom.The entry with this id, in the list or the footer, ornullif there is none.footer()The footer row's entries, left to right.
-
Method Details
-
builder
Starts building a menu screen.- Parameters:
id- the screen's id, matching[A-Za-z0-9_.-]+- Returns:
- a new builder;
MenuScreen.Builder.titleis required beforeMenuScreen.Builder.build() - Throws:
IllegalArgumentException- ifidis invalid
-
entries
The list's entries in screen order, top to bottom. A section is followed by its children, and aStringListEditorappears as its four entries. Includes entries that are currently notEntry.visible.- Returns:
- an unmodifiable list
-
all
-
entry
-