Class MultiLineInput
java.lang.Object
dev.xichil.mvui.Entry
dev.xichil.mvui.MultiLineInput
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilds aMultiLineInput; frombuilder(String). -
Method Summary
Modifier and TypeMethodDescription<R> Raccept(EntryVisitor<R> visitor) Calls theEntryVisitormethod for this entry's type (visitButtonfor aButton, …) and returns its result.static MultiLineInput.BuilderStarts building a text box.error()Why the current text is invalid, from the mod's validator; shown below the box.booleanisValid()Whether the current text is valid:error()isnull.label()The text shown above the box, from the mod's supplier.intlines()How many lines of text the box shows at once (2 – 12): its height.intThe most characters the box accepts, line breaks included; longer text is cut.voidStores the text (line breaks as'\n', cut tomaxLength();nullcounts as empty) and passes it toonChangeif it is valid.value()The text in the box now, valid or not, with'\n'line breaks; nevernull.
-
Method Details
-
builder
Starts building a text box.- Parameters:
id- the box's id, unique within its screen- Returns:
- a new builder
- Throws:
IllegalArgumentException- ifidis invalid
-
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
The text in the box now, valid or not, with'\n'line breaks; nevernull.- Returns:
- the text in the box, with
'\n'line breaks
-
setValue
Stores the text (line breaks as'\n', cut tomaxLength();nullcounts as empty) and passes it toonChangeif it is valid. Backends call it on every edit.- Parameters:
newValue- the new text
-
error
Why the current text is invalid, from the mod's validator; shown below the box.- Returns:
- the error, or
nullif the text is valid
-
isValid
public boolean isValid()Whether the current text is valid:error()isnull.- Returns:
trueif the text is valid
-
accept
Description copied from class:EntryCalls theEntryVisitormethod for this entry's type (visitButtonfor aButton, …) and returns its result. ASectionvisits as its header, aNumberFieldas itsTextInput.
-