Class StatusLine

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

public final class StatusLine extends Entry
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.

  • Method Details

    • builder

      public static StatusLine.Builder builder(String id)
      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 - if id is invalid
    • kind

      public StatusLine.Kind kind()
      The current message's severity; StatusLine.Kind.INFO while empty.
      Returns:
      the severity, StatusLine.Kind.INFO while the line is empty
    • text

      public Text text()
      The current message, or null while the line is empty.
      Returns:
      the message, or null while the line is empty
    • show

      public void show(StatusLine.Kind kind, Text text)
      Shows a message, replacing the previous one. It appears after the next refresh, which happens automatically after an entry action or a UiHost.runAsync(Callable, BiConsumer) callback; elsewhere call UiHost.refresh().
      Parameters:
      kind - the severity
      text - the message
      Throws:
      IllegalStateException - if an argument is null
    • clear

      public void clear()
      Empties the line (and resets kind() to StatusLine.Kind.INFO).
    • 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