Class Collapsible

java.lang.Object
dev.myriadclient.api.ui.widget.Widget
dev.myriadclient.api.ui.widget.Collapsible

public class Collapsible extends Widget
A titled section whose body can be folded away: click the header (or Enter, or h/l with the keyboard selection on it) to fold or unfold it, with an animation. Folded, the body takes no room and gets no input.
VBox body = new VBox(2, 0);
body.add(new Label("Inside"));
content.add(new Collapsible("Advanced", body).indent(10).hint(() -> "1"));
  • Constructor Details

    • Collapsible

      public Collapsible(Supplier<String> title, Widget body, Supplier<Boolean> expanded, Consumer<Boolean> setExpanded)
      A section whose folded state lives elsewhere (a setting group's, say): expanded is read every frame and setExpanded called when the player folds or unfolds it.
    • Collapsible

      public Collapsible(String title, Widget body)
      A section that starts unfolded and remembers its state itself (until the widgets are rebuilt).
  • Method Details

    • indent

      public Collapsible indent(float indent)
      Indents the body by indent UI units and draws a guide line down its left edge, so nested sections read as a tree. Returns this section.
    • hint

      public Collapsible hint(Supplier<@Nullable String> hint)
      Dim text at the right of the header (e.g. how many settings the section holds), asked every frame; null or empty shows none. It gives way to the title in a narrow window. Returns this section.
    • measure

      protected float measure(Canvas canvas, float width)
      Description copied from class: Widget
      Compute height for width and position children. Widget.x, Widget.y and Widget.width are already set. Called every frame while visible; keep it cheap.
      Specified by:
      measure in class Widget
    • render

      public void render(Canvas c, float mx, float my)
      Description copied from class: Widget
      Draws the widget within its box (Widget.x, Widget.y, Widget.width, Widget.height), with the mouse in the same coordinates (far off screen while the pointer is outside the panel or a scroll view's viewport). Called every frame after Widget.layout(Canvas, float, float, float), only while visible.
      Specified by:
      render in class Widget
    • mouseClicked

      public boolean mouseClicked(float mx, float my, int button)
      Description copied from class: Widget
      A mouse press at (mouseX, mouseY); button is a GLFW button (InputConstants.MOUSE_BUTTON_*). Presses go to every visible widget in turn until one returns true, so check Widget.isHovered(float, float) first. Returning true makes this widget receive the drags and the release.
      Overrides:
      mouseClicked in class Widget
    • isNavigable

      public boolean isNavigable()
      Description copied from class: Widget
      Whether the keyboard selection (j/k, arrows) can land on this widget.
      Overrides:
      isNavigable in class Widget
    • activate

      public void activate()
      Description copied from class: Widget
      Enter/Space on the selected widget.
      Overrides:
      activate in class Widget
    • adjust

      public boolean adjust(int direction)
      Description copied from class: Widget
      h/l or Left/Right on the selected widget: -1 or +1. Return true if handled.
      Overrides:
      adjust in class Widget
    • collectNavigable

      public void collectNavigable(List<Widget> out)
      Description copied from class: Widget
      Adds the navigable widgets currently on screen, in visual order. Containers recurse into shown children.
      Overrides:
      collectNavigable in class Widget
    • mouseScrolled

      public boolean mouseScrolled(float mx, float my, float amount)
      Description copied from class: Widget
      The wheel, amount notches (positive turning up), while over the widget. Return true to use it; otherwise the enclosing scroll view scrolls.
      Overrides:
      mouseScrolled in class Widget