Class TextFieldWidget

All Implemented Interfaces:
Drawable, Element

@Environment(CLIENT)
public class TextFieldWidget
extends AbstractButtonWidget
implements Drawable, Element
  • Field Details

    • textRenderer

      private final TextRenderer textRenderer
    • text

      private String text
    • maxLength

      private int maxLength
    • focusedTicks

      private int focusedTicks
    • focused

      private boolean focused
    • focusUnlocked

      private boolean focusUnlocked
    • editable

      private boolean editable
    • selecting

      private boolean selecting
    • firstCharacterIndex

      private int firstCharacterIndex
    • selectionStart

      private int selectionStart
    • selectionEnd

      private int selectionEnd
    • editableColor

      private int editableColor
    • uneditableColor

      private int uneditableColor
    • suggestion

      private String suggestion
    • changedListener

      private Consumer<String> changedListener
    • textPredicate

      private Predicate<String> textPredicate
    • renderTextProvider

      private BiFunction<String,​Integer,​OrderedText> renderTextProvider
  • Constructor Details

    • TextFieldWidget

      public TextFieldWidget​(TextRenderer textRenderer, int x, int y, int width, int height, Text text)
    • TextFieldWidget

      public TextFieldWidget​(TextRenderer textRenderer, int x, int y, int width, int height, @Nullable TextFieldWidget copyFrom, Text text)
  • Method Details

    • setChangedListener

      public void setChangedListener​(Consumer<String> changedListener)
    • setRenderTextProvider

      public void setRenderTextProvider​(BiFunction<String,​Integer,​OrderedText> renderTextProvider)
    • tick

      public void tick()
    • getNarrationMessage

      protected MutableText getNarrationMessage()
      Overrides:
      getNarrationMessage in class AbstractButtonWidget
    • setText

      public void setText​(String text)
    • getText

      public String getText()
    • getSelectedText

      public String getSelectedText()
    • setTextPredicate

      public void setTextPredicate​(Predicate<String> textPredicate)
    • write

      public void write​(String string)
    • onChanged

      private void onChanged​(String newText)
    • erase

      private void erase​(int offset)
    • eraseWords

      public void eraseWords​(int wordOffset)
    • eraseCharacters

      public void eraseCharacters​(int characterOffset)
    • getWordSkipPosition

      public int getWordSkipPosition​(int wordOffset)
    • getWordSkipPosition

      private int getWordSkipPosition​(int wordOffset, int cursorPosition)
    • getWordSkipPosition

      private int getWordSkipPosition​(int wordOffset, int cursorPosition, boolean skipOverSpaces)
    • moveCursor

      public void moveCursor​(int offset)
    • method_27537

      private int method_27537​(int int2)
    • setCursor

      public void setCursor​(int cursor)
    • setSelectionStart

      public void setSelectionStart​(int cursor)
    • setCursorToStart

      public void setCursorToStart()
    • setCursorToEnd

      public void setCursorToEnd()
    • keyPressed

      public boolean keyPressed​(int keyCode, int scanCode, int modifiers)
      Callback for when a key down event has been captured. The key code is identified by the constants in GLFW class.
      Specified by:
      keyPressed in interface Element
      Parameters:
      keyCode - the named key code of the event as described in the GLFW class
      scanCode - the unique/platform-specific scan code of the keyboard input
      modifiers - a GLFW bitfield describing the modifier keys that are held down (see {@linkplain https://www.glfw.org/docs/3.3/group__mods.html GLFW Modifier key flags})
      Returns:
      true to indicate that the event handling is successful/valid
      See Also:
      Keyboard.onKey(long, int, int, int, int), GLFW.GLFW_KEY_Q, GLFWKeyCallbackI.invoke(long, int, int, int, int)
    • isActive

      public boolean isActive()
    • charTyped

      public boolean charTyped​(char chr, int keyCode)
      Callback for when a character input has been captured. The key code is identified by the constants in GLFW class.
      Specified by:
      charTyped in interface Element
      Parameters:
      chr - the captured character
      keyCode - the associated key code
      Returns:
      true to indicate that the event handling is successful/valid
      See Also:
      Keyboard.onChar(long, int, int), GLFW.GLFW_KEY_Q, GLFWKeyCallbackI.invoke(long, int, int, int, int)
    • mouseClicked

      public boolean mouseClicked​(double mouseX, double mouseY, int button)
      Callback for when a mouse button down event has been captured. The button number is identified by the constants in GLFW class.
      Specified by:
      mouseClicked in interface Element
      Overrides:
      mouseClicked in class AbstractButtonWidget
      Parameters:
      mouseX - the X coordinate of the mouse
      mouseY - the Y coordinate of the mouse
      button - the mouse button number
      Returns:
      true to indicate that the event handling is successful/valid
      See Also:
      Mouse.onMouseButton(long, int, int, int), GLFW.GLFW_MOUSE_BUTTON_1
    • setSelected

      public void setSelected​(boolean selected)
    • renderButton

      public void renderButton​(MatrixStack matrices, int mouseX, int mouseY, float delta)
      Overrides:
      renderButton in class AbstractButtonWidget
    • drawSelectionHighlight

      private void drawSelectionHighlight​(int x1, int y1, int x2, int y2)
    • setMaxLength

      public void setMaxLength​(int maxLength)
    • getMaxLength

      private int getMaxLength()
    • getCursor

      public int getCursor()
    • hasBorder

      private boolean hasBorder()
    • setHasBorder

      public void setHasBorder​(boolean hasBorder)
    • setEditableColor

      public void setEditableColor​(int color)
    • setUneditableColor

      public void setUneditableColor​(int color)
    • changeFocus

      public boolean changeFocus​(boolean lookForwards)
      Changes the focusing element by cycling to the next/previous element. This action is done typically when the user has pressed the 'Tab' or 'Ctrl+Tab' key.
      Specified by:
      changeFocus in interface Element
      Overrides:
      changeFocus in class AbstractButtonWidget
      Parameters:
      lookForwards - true to cycle forwards, otherwise cycle backwards
      Returns:
      true to indicate that the event handling is successful/valid
    • isMouseOver

      public boolean isMouseOver​(double mouseX, double mouseY)
      Checks if the mouse position is within the bound of the element.
      Specified by:
      isMouseOver in interface Element
      Overrides:
      isMouseOver in class AbstractButtonWidget
      Parameters:
      mouseX - the X coordinate of the mouse
      mouseY - the Y coordinate of the mouse
      Returns:
      true if the mouse is within the bound of the element, otherwise false
    • onFocusedChanged

      protected void onFocusedChanged​(boolean bool)
      Overrides:
      onFocusedChanged in class AbstractButtonWidget
    • isEditable

      private boolean isEditable()
    • setEditable

      public void setEditable​(boolean editable)
    • getInnerWidth

      public int getInnerWidth()
    • setSelectionEnd

      public void setSelectionEnd​(int int2)
    • setFocusUnlocked

      public void setFocusUnlocked​(boolean focusUnlocked)
    • isVisible

      public boolean isVisible()
    • setVisible

      public void setVisible​(boolean visible)
    • setSuggestion

      public void setSuggestion​(@Nullable String suggestion)
    • getCharacterX

      public int getCharacterX​(int index)
    • setX

      public void setX​(int x)