Class WidgetPanel
java.lang.Object
dev.myriadclient.api.ui.Panel
dev.myriadclient.api.ui.WidgetPanel
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
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedA panel with 6 UI units of padding around its content.protectedWidgetPanel(float padding) A panel withpaddingUI units around its content (the scroll bar sits in the right-hand padding). -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidAdds the panel's widgets tocontent, a column with 4 units between widgets and the panel's padding around them.booleanTrue while typing in a text field or binding a key, so UI shortcuts and Escape go to the widget.booleancharTyped(char chr, int modifiers) A typed character, to the focused window's panel.booleankeyPressed(int key, int scancode, int modifiers) A key pressed while this window is focused.booleanmouseClicked(float mx, float my, int button) A mouse press in the content area, in content coordinates and UI units;buttonis a GLFW button (InputConstants.MOUSE_BUTTON_*).booleanmouseDragged(float mx, float my, int button, float dx, float dy) The mouse moving with a button down after a press that went toPanel.mouseClicked(float, float, int), in content coordinates;dx/dyis how far it moved since the last drag event (or the press), in UI units.booleanmouseReleased(float mx, float my, int button) The release of a press that went toPanel.mouseClicked(float, float, int), in content coordinates (possibly outside the area).booleanmouseScrolled(float mx, float my, float amount) The wheel over the content, in content coordinates;amountis in notches, positive when the wheel turns up (scroll towards the top).voidrebuild()Throws the widgets away and callsbuild(VBox)again, keeping the scroll position.voidDraws the panel.@Nullable Stringtooltip()The hovered widget's tooltip, from the last frame.protected WidgetRootThe root hosting the widgets, building them first if they haven't been.Methods inherited from class Panel
attach, bindClient, icon, load, onClose, onOpen, preferredSize, save, subtitle, tick, title, titleControls, window
-
Constructor Details
-
WidgetPanel
protected WidgetPanel()A panel with 6 UI units of padding around its content. -
WidgetPanel
protected WidgetPanel(float padding) A panel withpaddingUI units around its content (the scroll bar sits in the right-hand padding).
-
-
Method Details
-
build
-
rebuild
public void rebuild()Throws the widgets away and callsbuild(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. fromPanel.tick()or a button's action. -
render
Description copied from class:PanelDraws 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/heightis 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. -
mouseClicked
public boolean mouseClicked(float mx, float my, int button) Description copied from class:PanelA mouse press in the content area, in content coordinates and UI units;buttonis 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:
mouseClickedin classPanel
-
mouseReleased
public boolean mouseReleased(float mx, float my, int button) Description copied from class:PanelThe release of a press that went toPanel.mouseClicked(float, float, int), in content coordinates (possibly outside the area).- Overrides:
mouseReleasedin classPanel
-
mouseDragged
public boolean mouseDragged(float mx, float my, int button, float dx, float dy) Description copied from class:PanelThe mouse moving with a button down after a press that went toPanel.mouseClicked(float, float, int), in content coordinates;dx/dyis how far it moved since the last drag event (or the press), in UI units.- Overrides:
mouseDraggedin classPanel
-
mouseScrolled
public boolean mouseScrolled(float mx, float my, float amount) Description copied from class:PanelThe wheel over the content, in content coordinates;amountis 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:
mouseScrolledin classPanel
-
keyPressed
public boolean keyPressed(int key, int scancode, int modifiers) Description copied from class:PanelA key pressed while this window is focused. Return true to consume the key (e.g. while a text field is focused).keyis its position (anInputConstants.KEY_*value),scancodewhat it types on the player's layout (asKeyEvent),modifiersInputConstants.MOD_*bits. WhilePanel.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:
keyPressedin classPanel
-
charTyped
public boolean charTyped(char chr, int modifiers) Description copied from class:PanelA typed character, to the focused window's panel. Characters only arrive whilePanel.capturesKeyboard()is true (the game's text input is only on then), and not while the UI's mod key is held. -
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:
capturesKeyboardin classPanel
-
tooltip
-
widgetRoot
The root hosting the widgets, building them first if they haven't been. Arebuild()replaces it.
-