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
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 extendsEntry.Builder, so every entry supports:
enabled: while false the widget is drawn greyed out and can't be used. Defaulttrue.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. Defaulttrue.
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 aUiHost.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 ClassesModifier and TypeClassDescriptionstatic classEntry.Builder<B extends Entry.Builder<B>>The options every entry builder has. -
Method Summary
Modifier and TypeMethodDescriptionabstract <R> Raccept(EntryVisitor<R> visitor) Calls theEntryVisitormethod for this entry's type (visitButtonfor aButton, …) and returns its result.booleanenabled()Whether the widget can be used now, from the builder'senabledsupplier.id()The entry's id, as given to its builder: matches[A-Za-z0-9_.-]+and is unique within its screen.tooltip()The tooltip shown while the mouse is over the widget, from the builder'stooltipsupplier.booleanvisible()Whether the entry has a row on the screen now: its ownvisiblesupplier, and for a child of aSectionalso whether the section is shown and expanded.
-
Method Details
-
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'senabledsupplier. A disabled widget is drawn greyed out and ignores clicks and keys.- Returns:
- the supplier's value;
trueif none was set
-
tooltip
The tooltip shown while the mouse is over the widget, from the builder'stooltipsupplier.- Returns:
- the tooltip, or
nullfor none
-
visible
public boolean visible()Whether the entry has a row on the screen now: its ownvisiblesupplier, and for a child of aSectionalso 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
Calls theEntryVisitormethod for this entry's type (visitButtonfor aButton, …) and returns its result. ASectionvisits as its header, aNumberFieldas itsTextInput.- Type Parameters:
R- the visitor's result type- Parameters:
visitor- the visitor, usually a backend's widget factory- Returns:
- what the visitor returned
-