Class TextField

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

public class TextField extends Widget
Single-line text input. onChange fires on every edit, onSubmit on Enter. While unfocused it shows getter's value; clicking it (or Enter, or / for the first field in a window) starts editing a copy of that value, and the field holds keyboard focus until Enter, Escape or a click elsewhere. While focused it takes every key, so the UI's shortcuts don't fire. Ctrl+Left and Ctrl+Backspace go by words, Ctrl+A/C/V (Cmd on a Mac) select all, copy and paste; right-click empties it.
content.add(new TextField(() -> filter).onChange(s -> filter = s).search().placeholder("Filter…"));
  • Constructor Details

    • TextField

      public TextField(Supplier<String> getter)
      A field showing getter's value while it isn't being edited (read every frame).
  • Method Details

    • onChange

      public TextField onChange(Consumer<String> onChange)
      Called with the whole text after every edit while typing (including emptying it). Returns this field.
    • onSubmit

      public TextField onSubmit(Consumer<String> onSubmit)
      Called with the text when Enter is pressed, before the field lets go of the keyboard. Returns this field.
    • placeholder

      public TextField placeholder(String placeholder)
      Dim text shown while the field is empty and not being edited. Returns this field.
    • icon

      @AvailableSince("1.4") public TextField icon(String glyph)
      A glyph at the left of the field: a search box's magnifier. Returns this field.
    • search

      @AvailableSince("1.4") public TextField search()
      A search box: the magnifier at its left, and a cross at its right that empties it once it holds something. Returns this field.
    • text

      public String text()
      What's typed while it's being edited, otherwise getter's value.
    • hasFocus

      @AvailableSince("1.4") public boolean hasFocus()
      Whether the keyboard is typing here.
    • releaseFocus

      @AvailableSince("1.4") public void releaseFocus()
      Lets go of the keyboard, as Escape does.
    • requestFocus

      public void requestFocus()
      Focuses the field programmatically (e.g. a launcher's search box).
    • setText

      public void setText(String s)
      Replaces what's being typed with s, the cursor at its end, and calls onChange. While the field isn't focused it shows getter's value regardless.
    • 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
    • minWidth

      public float minWidth(Canvas canvas)
      Description copied from class: Widget
      The narrowest this is still usable at, for a row deciding whether to shrink it or wrap (HBox), or -1 if it has no opinion: a row then keeps a fixed child at its width and gives a shared one a small default.
      Overrides:
      minWidth 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
    • onBlur

      protected void onBlur()
      Description copied from class: Widget
      Called when this widget loses keyboard focus.
      Overrides:
      onBlur in class Widget
    • keyPressed

      public boolean keyPressed(int key, int scancode, int mods)
      Description copied from class: Widget
      A key pressed while this widget is focused: key is its position (an InputConstants.KEY_* value), scancode what it types on the player's layout (as KeyEvent); modifiers are InputConstants.MOD_* bits.
      Overrides:
      keyPressed in class Widget
    • charTyped

      public boolean charTyped(char chr, int mods)
      Description copied from class: Widget
      A character typed while this widget is focused.
      Overrides:
      charTyped in class Widget