Class Entry

java.lang.Object
dev.xichil.mvui.Entry
Direct Known Subclasses:
Button, Checkbox, ColorPicker, Cycle, Dropdown, Keybind, Label, MultiLineInput, NumberField, Section, SelectList, Slider, StatusLine, TextInput, Toggle

public abstract class Entry extends Object
One widget on a MenuScreen: the base class of every widget type (Button, Toggle, Slider…). The set of entry types is closed (the constructor is package-private): each maps to one vanilla widget, and a backend handles all of them through EntryVisitor.

Options every entry has

Each widget's builder extends Entry.Builder, so every entry supports:
  • enabled: while false the widget is drawn greyed out and can't be used. Default true.
  • tooltip: text shown while the mouse is over the widget. Default none.
  • visible: while false the entry has no row on the screen at all. Default true.
Button.builder("export")
        .label(Text.translatable("mymod.export", "Export"))
        .onPress(this::export)
        .enabled(() -> !profiles.isEmpty())
        .tooltip(() -> profiles.isEmpty() ? Text.translatable("mymod.export.none", "Nothing to export") : null)
        .visible(() -> config.advanced)
        .build();

Suppliers and refreshes

Labels, values, enabled state, visibility and tooltips are suppliers. The backend re-reads them whenever the screen is refreshed: when it opens, after each entry action, after a UiHost.runAsync(Callable, BiConsumer) callback, and on UiHost.refresh(). They run on the main thread, often, so keep them fast and free of side effects.

An entry that is not visible has no row on the screen: the backend reads none of its other suppliers, and it can't be used. That is how a collapsed Section hides its children.

Exceptions

Whatever the mod's suppliers and actions throw passes through these methods unchanged. On a registered menu's screen it is also tagged with the mod (ModFault), so that a failure there turns off only that mod's menu: a throwing supplier turns the menu off for the session, a throwing action is logged and the menu stays open.

The public methods that run the mod's code (enabled(), tooltip(), visible(), and each subclass's getters and setters) are what backends and tests call to draw and drive the widget. Mods normally only use the builders.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    The options every entry builder has.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract <R> R
    accept(EntryVisitor<R> visitor)
    Calls the EntryVisitor method for this entry's type (visitButton for a Button, …) and returns its result.
    boolean
    Whether the widget can be used now, from the builder's enabled supplier.
    id()
    The entry's id, as given to its builder: matches [A-Za-z0-9_.-]+ and is unique within its screen.
    The tooltip shown while the mouse is over the widget, from the builder's tooltip supplier.
    boolean
    Whether the entry has a row on the screen now: its own visible supplier, and for a child of a Section also whether the section is shown and expanded.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • id

      public String id()
      The entry's id, as given to its builder: matches [A-Za-z0-9_.-]+ and is unique within its screen. Not shown to players; tests find entries by it (MenuScreen.entry(String)).
      Returns:
      the id given to the builder
    • enabled

      public boolean enabled()
      Whether the widget can be used now, from the builder's enabled supplier. A disabled widget is drawn greyed out and ignores clicks and keys.
      Returns:
      the supplier's value; true if none was set
    • tooltip

      public Text tooltip()
      The tooltip shown while the mouse is over the widget, from the builder's tooltip supplier.
      Returns:
      the tooltip, or null for none
    • visible

      public boolean visible()
      Whether the entry has a row on the screen now: its own visible supplier, and for a child of a Section also whether the section is shown and expanded. Backends read it first on every refresh; while it is false they read nothing else of the entry, show no row for it and drop its focus.
      Returns:
      whether the entry is shown
    • accept

      public abstract <R> R accept(EntryVisitor<R> visitor)
      Calls the EntryVisitor method for this entry's type (visitButton for a Button, …) and returns its result. A Section visits as its header, a NumberField as its TextInput.
      Type Parameters:
      R - the visitor's result type
      Parameters:
      visitor - the visitor, usually a backend's widget factory
      Returns:
      what the visitor returned