Class WidgetPanel

java.lang.Object
dev.myriadclient.api.ui.Panel
dev.myriadclient.api.ui.WidgetPanel

public abstract class WidgetPanel extends Panel
A panel whose content is a scrolling column of widgets. Implement build(VBox) to add widgets; call rebuild() when the structure (not just values) changes. Widgets read live values through suppliers each frame, so changing a value needs no rebuild. Input, keyboard navigation, focus and tooltips are handled by its WidgetRoot.
public final class NotesPanel extends WidgetPanel {
    private final List<String> notes = new ArrayList<>();
    private String draft = "";

    @Override
    public String title() { return "Notes"; }

    @Override
    protected void build(VBox content) {
        HBox add = content.add(new HBox());
        add.addWeighted(new TextField(() -> draft).onChange(s -> draft = s).placeholder("New note"), 1);
        add.addFixed(new Button("Add", () -> { notes.add(draft); draft = ""; rebuild(); }), 40);
        if (notes.isEmpty()) content.add(new EmptyState(Icons.PENCIL, "No notes yet", "Type one above."));
        for (String n : notes) content.add(new Label(n));
    }
}
  • Field Summary

    Fields inherited from class Panel

    mc, settings
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    A panel with 6 UI units of padding around its content.
    protected
    WidgetPanel(float padding)
    A panel with padding UI units around its content (the scroll bar sits in the right-hand padding).
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract void
    build(VBox content)
    Adds the panel's widgets to content, a column with 4 units between widgets and the panel's padding around them.
    boolean
    True while typing in a text field or binding a key, so UI shortcuts and Escape go to the widget.
    boolean
    charTyped(char chr, int modifiers)
    A typed character, to the focused window's panel.
    boolean
    keyPressed(int key, int scancode, int modifiers)
    A key pressed while this window is focused.
    boolean
    mouseClicked(float mx, float my, int button)
    A mouse press in the content area, in content coordinates and UI units; button is a GLFW button (InputConstants.MOUSE_BUTTON_*).
    boolean
    mouseDragged(float mx, float my, int button, float dx, float dy)
    The mouse moving with a button down after a press that went to Panel.mouseClicked(float, float, int), in content coordinates; dx/dy is how far it moved since the last drag event (or the press), in UI units.
    boolean
    mouseReleased(float mx, float my, int button)
    The release of a press that went to Panel.mouseClicked(float, float, int), in content coordinates (possibly outside the area).
    boolean
    mouseScrolled(float mx, float my, float amount)
    The wheel over the content, in content coordinates; amount is in notches, positive when the wheel turns up (scroll towards the top).
    void
    Throws the widgets away and calls build(VBox) again, keeping the scroll position.
    void
    render(Canvas canvas, float width, float height, float mouseX, float mouseY)
    Draws the panel.
    @Nullable String
    The hovered widget's tooltip, from the last frame.
    protected WidgetRoot
    The root hosting the widgets, building them first if they haven't been.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WidgetPanel

      protected WidgetPanel()
      A panel with 6 UI units of padding around its content.
    • WidgetPanel

      protected WidgetPanel(float padding)
      A panel with padding UI units around its content (the scroll bar sits in the right-hand padding).
  • Method Details

    • build

      protected abstract void build(VBox content)
      Adds the panel's widgets to content, a column with 4 units between widgets and the panel's padding around them. Called before the first frame and on every rebuild(), each time into a fresh column.
    • rebuild

      public void rebuild()
      Throws the widgets away and calls build(VBox) again, keeping the scroll position. Widget state (focus, an open dropdown, the keyboard selection) starts over. Call it on the render thread, e.g. from Panel.tick() or a button's action.
    • render

      public void render(Canvas canvas, float width, float height, float mouseX, float mouseY)
      Description copied from class: Panel
      Draws the panel. Called every frame while visible, with the canvas clipped to the content area and translated so (0,0) is its top-left. width/height is the content area's size in UI units (animating while the window opens or moves). The mouse is in the same coordinates while the pointer is over this window and nothing covers it, and far outside (-10000) otherwise, so hover checks fail. A HUD element drawn in game, or while the HUD is being edited, gets no meaningful mouse position.
      Specified by:
      render in class Panel
    • mouseClicked

      public boolean mouseClicked(float mx, float my, int button)
      Description copied from class: Panel
      A mouse press in the content area, in content coordinates and UI units; button is a GLFW button (InputConstants.MOUSE_BUTTON_*). The press goes to the panel whatever this returns; after it, the panel gets the drags and the release, even outside its area. Presses with the UI's mod key held move or resize the window instead. HUD elements get no mouse input.
      Overrides:
      mouseClicked in class Panel
    • mouseReleased

      public boolean mouseReleased(float mx, float my, int button)
      Description copied from class: Panel
      The release of a press that went to Panel.mouseClicked(float, float, int), in content coordinates (possibly outside the area).
      Overrides:
      mouseReleased in class Panel
    • mouseDragged

      public boolean mouseDragged(float mx, float my, int button, float dx, float dy)
      Description copied from class: Panel
      The mouse moving with a button down after a press that went to Panel.mouseClicked(float, float, int), in content coordinates; dx/dy is how far it moved since the last drag event (or the press), in UI units.
      Overrides:
      mouseDragged in class Panel
    • mouseScrolled

      public boolean mouseScrolled(float mx, float my, float amount)
      Description copied from class: Panel
      The wheel over the content, in content coordinates; amount is in notches, positive when the wheel turns up (scroll towards the top). Return whether it was used. Shift + wheel scrolls the workspace's layout instead where the layout scrolls sideways.
      Overrides:
      mouseScrolled in class Panel
    • keyPressed

      public boolean keyPressed(int key, int scancode, int modifiers)
      Description copied from class: Panel
      A key pressed while this window is focused. Return true to consume the key (e.g. while a text field is focused). key is its position (an InputConstants.KEY_* value), scancode what it types on the player's layout (as KeyEvent), modifiers InputConstants.MOD_* bits. While Panel.capturesKeyboard() is true the panel sees every key first; otherwise the UI's mod-key shortcuts go first. Escape that the panel doesn't consume shuts the menu.
      Overrides:
      keyPressed in class Panel
    • charTyped

      public boolean charTyped(char chr, int modifiers)
      Description copied from class: Panel
      A typed character, to the focused window's panel. Characters only arrive while Panel.capturesKeyboard() is true (the game's text input is only on then), and not while the UI's mod key is held.
      Overrides:
      charTyped in class Panel
    • capturesKeyboard

      public boolean capturesKeyboard()
      True while typing in a text field or binding a key, so UI shortcuts and Escape go to the widget.
      Overrides:
      capturesKeyboard in class Panel
    • tooltip

      public @Nullable String tooltip()
      The hovered widget's tooltip, from the last frame.
      Overrides:
      tooltip in class Panel
    • widgetRoot

      protected WidgetRoot widgetRoot()
      The root hosting the widgets, building them first if they haven't been. A rebuild() replaces it.