Class WTextField

java.lang.Object
io.github.cottonmc.cotton.gui.widget.WWidget
io.github.cottonmc.cotton.gui.widget.WTextField

public class WTextField extends WWidget
  • Field Details

  • Constructor Details

    • WTextField

      public WTextField()
    • WTextField

      public WTextField(Text suggestion)
  • Method Details

    • setText

      public void setText(String s)
    • getText

      public String getText()
    • canResize

      public boolean canResize()
      Description copied from class: WWidget
      Checks whether this widget can be resized using WWidget.setSize(int, int).
      Overrides:
      canResize in class WWidget
      Returns:
      true if this widget can be resized, false otherwise
    • setSize

      public void setSize(int x, int y)
      Description copied from class: WWidget
      Sets the size of this widget.

      Overriding methods may restrict one of the dimensions to be a constant value, for example super.setSize(x, 20).

      Overrides:
      setSize in class WWidget
      Parameters:
      x - the new width
      y - the new height
    • setCursorPos

      public void setCursorPos(int location)
    • getMaxLength

      public int getMaxLength()
    • getCursor

      public int getCursor()
    • getSelection

      @Nullable public @Nullable String getSelection()
    • isEditable

      public boolean isEditable()
    • renderTextField

      @Environment(CLIENT) protected void renderTextField(MatrixStack matrices, int x, int y)
    • setTextPredicate

      public WTextField setTextPredicate(Predicate<String> predicate_1)
    • setChangedListener

      public WTextField setChangedListener(Consumer<String> listener)
    • setMaxLength

      public WTextField setMaxLength(int max)
    • setEnabledColor

      public WTextField setEnabledColor(int col)
    • setDisabledColor

      public WTextField setDisabledColor(int col)
    • setEditable

      public WTextField setEditable(boolean editable)
    • getSuggestion

      @Nullable public @Nullable Text getSuggestion()
    • setSuggestion

      public WTextField setSuggestion(@Nullable @Nullable String suggestion)
    • setSuggestion

      public WTextField setSuggestion(@Nullable @Nullable Text suggestion)
    • setBackgroundPainter

      @Environment(CLIENT) public WTextField setBackgroundPainter(BackgroundPainter painter)
    • canFocus

      public boolean canFocus()
      Description copied from class: WWidget
      Tests whether this widget can have the focus in the GUI.
      Overrides:
      canFocus in class WWidget
      Returns:
      true if this widget can be focused, false otherwise
    • onFocusGained

      public void onFocusGained()
      Description copied from class: WWidget
      Notifies this widget that it has gained focus
      Overrides:
      onFocusGained in class WWidget
    • paint

      @Environment(CLIENT) public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY)
      Description copied from class: WWidget
      Paints this widget.
      Overrides:
      paint in class WWidget
      Parameters:
      matrices - the rendering matrix stack
      x - this widget's X coordinate on the screen
      y - this widget's Y coordinate on the screen
      mouseX - the X coordinate of the cursor
      mouseY - the X coordinate of the cursor
    • onClick

      @Environment(CLIENT) public InputResult onClick(int x, int y, int button)
      Description copied from class: WWidget
      Notifies this widget that the mouse has been pressed and released, both while inside its bounds.
      Overrides:
      onClick in class WWidget
      Parameters:
      x - The X coordinate of the event, in widget-space (0 is the left edge of this widget)
      y - The Y coordinate of the event, in widget-space (0 is the top edge of this widget)
      button - The mouse button that was used. Button numbering is consistent with LWJGL Mouse (0=left, 1=right, 2=mousewheel click)
      Returns:
      InputResult.PROCESSED if the event is handled, InputResult.IGNORED otherwise.
    • onCharTyped

      @Environment(CLIENT) public void onCharTyped(char ch)
      Description copied from class: WWidget
      Notifies this widget that a character has been typed. This method is subject to key repeat, and may be called for characters that do not directly have a corresponding keyboard key.
      Overrides:
      onCharTyped in class WWidget
      Parameters:
      ch - the character typed
    • onKeyPressed

      @Environment(CLIENT) public void onKeyPressed(int ch, int key, int modifiers)
      Description copied from class: WWidget
      Notifies this widget that a key has been pressed.
      Overrides:
      onKeyPressed in class WWidget
      key - the GLFW scancode of the key
    • getCaretPos

      @Environment(CLIENT) public static int getCaretPos(String s, int x)
      From an X offset past the left edge of a TextRenderer.draw, finds out what the closest caret position (division between letters) is.
      Parameters:
      s -
      x -
      Returns:
    • getCaretOffset

      @Environment(CLIENT) public static int getCaretOffset(String s, int pos)
      From a caret position, finds out what the x-offset to draw the caret is.
      Parameters:
      s -
      pos -
      Returns: