Class Button

java.lang.Object
dev.xichil.mvui.Entry
dev.xichil.mvui.Button

public final class Button extends Entry
A push button, drawn as the version's vanilla button. Use it for actions (save, reset, open another screen) and in the footer for "Done".
Button.builder("details")
        .label(Text.translatable("mymod.details", "Details..."))
        .onPress(() -> host.open(detailsScreen(host)))
        .build();

Button.builder("done").label(UiTexts.DONE).onPress(host::back).build();

Required: label, onPress. After onPress returns, the host refreshes the current screen, so labels and enabled states reflect what the action changed.

  • Method Details

    • builder

      public static Button.Builder builder(String id)
      Starts building a button.
      Parameters:
      id - the button's id, unique within its screen
      Returns:
      a new builder
      Throws:
      IllegalArgumentException - if id is invalid
    • label

      public Text label()
      The text on the button, from the mod's supplier.
      Returns:
      the text drawn on the button
    • press

      public void press()
      Runs onPress, as a click does. Backends call it only while the button is Entry.enabled(); this method itself doesn't check. Whatever onPress throws passes through.
    • accept

      public <R> R accept(EntryVisitor<R> visitor)
      Description copied from class: Entry
      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.
      Specified by:
      accept in class Entry
      Type Parameters:
      R - the visitor's result type
      Parameters:
      visitor - the visitor, usually a backend's widget factory
      Returns:
      what the visitor returned