Class InputTextWidget


public class InputTextWidget extends PanelWidget
A widget for input text that supports text editing, selection, and clipboard operations.
  • Constructor Details

    • InputTextWidget

      public InputTextWidget(int x, int y, int width, int height)
      Constructs an InputTextWidget with the specified position and size.
      Parameters:
      x - The x-coordinate of the widget.
      y - The y-coordinate of the widget.
      width - The width of the widget.
      height - The height of the widget.
  • Method Details

    • setOnTextChangeAction

      public final void setOnTextChangeAction(Consumer<String> onTextChangeAction)
      Sets the action to be executed when the text changes.
      Parameters:
      onTextChangeAction - The action to be executed on text change.
    • getValue

      public final String getValue()
      Gets the current value of the text widget.
      Returns:
      The current text value.
    • setValue

      public final void setValue(String value)
      Sets the current value of the text widget.
      Parameters:
      value - The new text value.
    • getPlaceholder

      public final String getPlaceholder()
      Gets the placeholder text shown when the text value is empty.
      Returns:
      The placeholder text.
    • setPlaceholder

      public final void setPlaceholder(String placeholder)
      Sets the placeholder text to be shown when the text value is empty.
      Parameters:
      placeholder - The new placeholder text.
    • getTextFont

      public final String getTextFont()
      Gets the font used for displaying text.
      Returns:
      The text font.
    • setTextFont

      public final void setTextFont(String textFont)
      Sets the font to be used for displaying text.
      Parameters:
      textFont - The new text font.
    • getTextColor

      public final NanoColor getTextColor()
      Gets the color of the text.
      Returns:
      The text color.
    • setTextColor

      public final void setTextColor(NanoColor textColor)
      Sets the color of the text.
      Parameters:
      textColor - The new text color.
    • getPlaceholderColor

      public final NanoColor getPlaceholderColor()
      Gets the color of the placeholder text.
      Returns:
      The placeholder text color.
    • setPlaceholderColor

      public final void setPlaceholderColor(NanoColor placeholderColor)
      Sets the color of the placeholder text.
      Parameters:
      placeholderColor - The new placeholder text color.
    • getSelectionColor

      public final NanoColor getSelectionColor()
      Gets the color of the selected text highlight.
      Returns:
      The selection color.
    • setSelectionColor

      public final void setSelectionColor(NanoColor selectionColor)
      Sets the color of the selected text highlight.
      Parameters:
      selectionColor - The new selection color.
    • getFontSize

      public final int getFontSize()
      Gets the font size used for displaying text.
      Returns:
      The font size.
    • setFontSize

      public final void setFontSize(int fontSize)
      Sets the font size used for displaying text.
      Parameters:
      fontSize - The new font size.
    • getBorderOffset

      public final int getBorderOffset()
      Gets the offset from the border for the text.
      Returns:
      The border offset.
    • setBorderOffset

      public final void setBorderOffset(int borderOffset)
      Sets the offset from the border for the text.
      Parameters:
      borderOffset - The new border offset.
    • getRepeatDelay

      public final int getRepeatDelay()
      Gets the delay between key repeat events in milliseconds.
      Returns:
      The repeat delay.
    • setRepeatDelay

      public final void setRepeatDelay(int repeatDelay)
      Sets the delay between key repeat events in milliseconds.
      Parameters:
      repeatDelay - The new repeat delay.
    • isEditable

      public final boolean isEditable()
      Checks if the text widget is editable.
      Returns:
      true if the text widget is editable, false otherwise.
    • setEditable

      public final void setEditable(boolean editable)
      Sets whether the text widget is editable.
      Parameters:
      editable - true to make the widget editable, false otherwise.
    • isActive

      public final boolean isActive()
      Checks if the text widget is currently active.
      Returns:
      true if the widget is active, false otherwise.
    • setActive

      public final void setActive(boolean active)
      Sets the active state of the text widget.
      Parameters:
      active - true to activate the widget, false to deactivate it.
    • isCursorVisible

      public final boolean isCursorVisible()
      Checks if the cursor is currently visible.
      Returns:
      true if the cursor is visible, false otherwise.
    • setCursorVisible

      public final void setCursorVisible(boolean cursorVisible)
      Sets the visibility of the cursor.
      Parameters:
      cursorVisible - true to make the cursor visible, false to hide it.
    • isSecure

      public final boolean isSecure()
      Returns whether the input field is in secure mode. In secure mode, the input text is masked (with asterisks).
      Returns:
      true if the input field is in secure mode, false otherwise.
    • setSecure

      public final void setSecure(boolean secure)
      Sets the secure mode for the input field. In secure mode, the input text will be masked (with asterisks).
      Parameters:
      secure - true to enable secure mode, false to disable it.
    • onLeftMouseUp

      public void onLeftMouseUp(int x, int y)
      Handles the event when the left mouse button is released. This method updates the widget's state based on the mouse release and finalizes the selection if needed.
      Overrides:
      onLeftMouseUp in class PanelWidget
      Parameters:
      x - The x-coordinate of the mouse position at the time of release.
      y - The y-coordinate of the mouse position at the time of release.
    • getBlockBox

      public zombie.ui.UITextBox2 getBlockBox()
      Getting the default InputText UI Element to block game input
      Returns:
      the default InputText UI element
    • onLeftMouseDownOutside

      public void onLeftMouseDownOutside(int x, int y)
      Handles the event when the left mouse button is released outside the widget. This method clears any active selection and deactivates the widget.
      Overrides:
      onLeftMouseDownOutside in class Widget
      Parameters:
      x - The x-coordinate of the mouse position at the time of release.
      y - The y-coordinate of the mouse position at the time of release.
    • onLeftMouseDown

      public void onLeftMouseDown(int x, int y)
      Handles the event when the left mouse button is pressed down within the widget. This method sets up the widget's state for selection and cursor positioning.
      Overrides:
      onLeftMouseDown in class PanelWidget
      Parameters:
      x - The x-coordinate of the mouse position at the time of press.
      y - The y-coordinate of the mouse position at the time of press.
    • onLeftMouseUpOutside

      public void onLeftMouseUpOutside(int x, int y)
      Handles the event when the left mouse button is released outside the widget. This method deactivates the widget if the mouse was dragging, but reactivates it if it was being selected.
      Overrides:
      onLeftMouseUpOutside in class PanelWidget
      Parameters:
      x - The x-coordinate of the mouse position at the time of release.
      y - The y-coordinate of the mouse position at the time of release.
    • onMouseMove

      public void onMouseMove(int x, int y)
      Handles the event when the mouse is moved within the widget. This method updates the cursor position and adjusts text offset based on the mouse movement during selection.
      Overrides:
      onMouseMove in class Widget
      Parameters:
      x - The x-coordinate of the mouse position at the time of movement.
      y - The y-coordinate of the mouse position at the time of movement.
    • onKeyRepeat

      public void onKeyRepeat(int key)
      Handles the event when a key is repeatedly pressed. This method manages key repeat actions based on the configured repeat delay.
      Overrides:
      onKeyRepeat in class Widget
      Parameters:
      key - The key code of the key being repeated.
    • onKeyPress

      public void onKeyPress(int key)
      Handles the event when a key is pressed down. This method processes key inputs for text manipulation and updates the widget accordingly.
      Overrides:
      onKeyPress in class Widget
      Parameters:
      key - The key code of the key being pressed.
    • render

      public void render()
      Renders the text widget, including text, selection highlight, and cursor. This method also handles text offset adjustments and cursor blinking.
      Overrides:
      render in class PanelWidget