Class MultiLineInput

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

public final class MultiLineInput extends Entry
A text box of several lines, for notes, descriptions or lists the player types freely. It wraps long lines at the box's width and takes Enter as a line break; text longer than the box scrolls inside it. On 1.19.3+ it is vanilla's MultiLineEditBox; older versions draw an equivalent box (see TextAreaModel).
MultiLineInput.builder("notes")
        .label(Text.translatable("mymod.notes", "Notes"))
        .initial(config.notes)
        .lines(6)
        .maxLength(2000)
        .onChange(s -> config.notes = s)
        .build();

Otherwise it works like TextInput: the text lives in the entry (a refresh doesn't reset it), backends call setValue(String) on every edit and show error() below the box, and onChange receives only valid text. Line breaks are always '\n' (also for pasted "\r\n"); maxLength() counts them too. There is no limit on the number of lines apart from maxLength.

Required: label. Defaults: empty text, 1024 characters, 4 visible lines, no validation. Can't be in a MenuScreen's footer.

  • Method Details

    • builder

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

      public Text label()
      The text shown above the box, from the mod's supplier.
      Returns:
      the label
    • maxLength

      public int maxLength()
      The most characters the box accepts, line breaks included; longer text is cut.
      Returns:
      the most characters the box accepts
    • lines

      public int lines()
      How many lines of text the box shows at once (2 – 12): its height.
      Returns:
      the number of lines shown, from 2 to 12
    • value

      public String value()
      The text in the box now, valid or not, with '\n' line breaks; never null.
      Returns:
      the text in the box, with '\n' line breaks
    • setValue

      public void setValue(String newValue)
      Stores the text (line breaks as '\n', cut to maxLength(); null counts as empty) and passes it to onChange if it is valid. Backends call it on every edit.
      Parameters:
      newValue - the new text
    • error

      public Text error()
      Why the current text is invalid, from the mod's validator; shown below the box.
      Returns:
      the error, or null if the text is valid
    • isValid

      public boolean isValid()
      Whether the current text is valid: error() is null.
      Returns:
      true if the text is valid
    • 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