Class MenuScreen

java.lang.Object
dev.xichil.mvui.Screen
dev.xichil.mvui.MenuScreen

public final class MenuScreen extends Screen
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

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.

  • Method Details

    • builder

      public static MenuScreen.Builder builder(String id)
      Starts building a menu screen.
      Parameters:
      id - the screen's id, matching [A-Za-z0-9_.-]+
      Returns:
      a new builder; MenuScreen.Builder.title is required before MenuScreen.Builder.build()
      Throws:
      IllegalArgumentException - if id is invalid
    • entries

      public List<Entry> entries()
      The list's entries in screen order, top to bottom. A section is followed by its children, and a StringListEditor appears as its four entries. Includes entries that are currently not Entry.visible.
      Returns:
      an unmodifiable list
    • footer

      public List<Entry> footer()
      The footer row's entries, left to right.
      Returns:
      an unmodifiable list, possibly empty
    • all

      public List<Entry> all()
      entries() followed by footer().
      Returns:
      a new, modifiable list
    • entry

      public Entry entry(String id)
      The entry with this id, in the list or the footer, or null if there is none. Handy in tests and to reach a typed entry from an action:
      TextInput name = (TextInput) screen.entry("name");
      
      Parameters:
      id - an entry id
      Returns:
      the entry, or null