Class StatusLine
java.lang.Object
dev.xichil.mvui.Entry
dev.xichil.mvui.StatusLine
A line the screen's actions write their results to, e.g. "Loaded 'default'" or "Couldn't write the file". Empty until
a message is
shown; backends color the text by its StatusLine.Kind.
StatusLine status = StatusLine.builder("status").build();
Button save = Button.builder("save")
.label(Text.translatable("mymod.save", "Save"))
.onPress(() -> host.runAsync(() -> {
store.save(); // off the main thread
return null;
}, (ignored, error) -> { // back on the main thread
if (error != null) {
status.show(StatusLine.Kind.ERROR, Text.translatable("mymod.save.failed", "Save failed: %s",
Text.literal(String.valueOf(error.getMessage()))));
} else {
status.show(StatusLine.Kind.SUCCESS, Text.translatable("mymod.saved", "Saved"));
}
}))
.build();
MenuScreen.builder("main").title(title).add(status).add(save)…
Keep a reference to the status line so actions can write to it. Unlike other entries it has no supplier: the
message is state of the entry, set by show(StatusLine.Kind, Text) and clear(), and stays until replaced. It is safe to call
those from any thread; the new message shows on the next refresh.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilds aStatusLine; frombuilder(String).static enumThe severity of a message; backends pick its color from it (e.g. -
Method Summary
Modifier and TypeMethodDescription<R> Raccept(EntryVisitor<R> visitor) Calls theEntryVisitormethod for this entry's type (visitButtonfor aButton, …) and returns its result.static StatusLine.BuilderStarts building a status line.voidclear()Empties the line (and resetskind()toStatusLine.Kind.INFO).kind()The current message's severity;StatusLine.Kind.INFOwhile empty.voidshow(StatusLine.Kind kind, Text text) Shows a message, replacing the previous one.text()The current message, ornullwhile the line is empty.
-
Method Details
-
builder
Starts building a status line. It has no required fields:StatusLine.builder("status").build().- Parameters:
id- the status line's id, unique within its screen- Returns:
- a new builder
- Throws:
IllegalArgumentException- ifidis invalid
-
kind
The current message's severity;StatusLine.Kind.INFOwhile empty.- Returns:
- the severity,
StatusLine.Kind.INFOwhile the line is empty
-
text
The current message, ornullwhile the line is empty.- Returns:
- the message, or
nullwhile the line is empty
-
show
Shows a message, replacing the previous one. It appears after the next refresh, which happens automatically after an entry action or aUiHost.runAsync(Callable, BiConsumer)callback; elsewhere callUiHost.refresh().- Parameters:
kind- the severitytext- the message- Throws:
IllegalStateException- if an argument is null
-
clear
public void clear()Empties the line (and resetskind()toStatusLine.Kind.INFO). -
accept
Description copied from class:EntryCalls theEntryVisitormethod for this entry's type (visitButtonfor aButton, …) and returns its result. ASectionvisits as its header, aNumberFieldas itsTextInput.
-