Class TextInput.Builder

Enclosing class:
TextInput

public static final class TextInput.Builder extends Entry.Builder<TextInput.Builder>
Builds a TextInput; from TextInput.builder(String). Also has the options every entry has (Entry.Builder).
  • Method Details

    • label

      public TextInput.Builder label(Supplier<Text> label)
      The text above the field, re-read on every refresh. Required.
      Parameters:
      label - read on refresh
      Returns:
      this builder
    • label

      public TextInput.Builder label(Text label)
      A fixed label; see label(Supplier).
      Parameters:
      label - the label
      Returns:
      this builder
    • initial

      public TextInput.Builder initial(String initial)
      The text the field starts with, usually the mod's current value; empty by default. Cut to maxLength. Not passed to onChange.
      Parameters:
      initial - the starting text
      Returns:
      this builder
    • maxLength

      public TextInput.Builder maxLength(int maxLength)
      The most characters the field accepts; 64 by default. Must be positive.
      Parameters:
      maxLength - the limit
      Returns:
      this builder
    • validator

      public TextInput.Builder validator(Function<String,Text> validator)
      Checks the text after every edit and refresh: returns an error text for invalid input (shown below the field), null for valid input. Runs on the main thread, often: keep it fast. By default every text is valid.
      Parameters:
      validator - maps the text to an error, or null
      Returns:
      this builder
    • onChange

      public TextInput.Builder onChange(Consumer<String> onChange)
      Receives the text after each edit that leaves it valid, on the main thread. Optional.
      Parameters:
      onChange - receives valid text
      Returns:
      this builder
    • build

      public TextInput build()
      Builds the field.
      Returns:
      the field
      Throws:
      IllegalStateException - if label is missing or maxLength is not positive