Package com.avrix.ui.widgets
Class InputTextWidget
java.lang.Object
com.avrix.ui.widgets.Widget
com.avrix.ui.widgets.PanelWidget
com.avrix.ui.widgets.InputTextWidget
A widget for input text that supports text editing, selection, and clipboard operations.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionInputTextWidget
(int x, int y, int width, int height) Constructs an InputTextWidget with the specified position and size. -
Method Summary
Modifier and TypeMethodDescriptionzombie.ui.UITextBox2
Getting the default InputText UI Element to block game inputfinal int
Gets the offset from the border for the text.final int
Gets the font size used for displaying text.final String
Gets the placeholder text shown when the text value is empty.final NanoColor
Gets the color of the placeholder text.final int
Gets the delay between key repeat events in milliseconds.final NanoColor
Gets the color of the selected text highlight.final NanoColor
Gets the color of the text.final String
Gets the font used for displaying text.final String
getValue()
Gets the current value of the text widget.final boolean
isActive()
Checks if the text widget is currently active.final boolean
Checks if the cursor is currently visible.final boolean
Checks if the text widget is editable.final boolean
isSecure()
Returns whether the input field is in secure mode.void
onKeyPress
(int key) Handles the event when a key is pressed down.void
onKeyRepeat
(int key) Handles the event when a key is repeatedly pressed.void
onLeftMouseDown
(int x, int y) Handles the event when the left mouse button is pressed down within the widget.void
onLeftMouseDownOutside
(int x, int y) Handles the event when the left mouse button is released outside the widget.void
onLeftMouseUp
(int x, int y) Handles the event when the left mouse button is released.void
onLeftMouseUpOutside
(int x, int y) Handles the event when the left mouse button is released outside the widget.void
onMouseMove
(int x, int y) Handles the event when the mouse is moved within the widget.void
render()
Renders the text widget, including text, selection highlight, and cursor.final void
setActive
(boolean active) Sets the active state of the text widget.final void
setBorderOffset
(int borderOffset) Sets the offset from the border for the text.final void
setCursorVisible
(boolean cursorVisible) Sets the visibility of the cursor.final void
setEditable
(boolean editable) Sets whether the text widget is editable.final void
setFontSize
(int fontSize) Sets the font size used for displaying text.final void
setOnTextChangeAction
(Consumer<String> onTextChangeAction) Sets the action to be executed when the text changes.final void
setPlaceholder
(String placeholder) Sets the placeholder text to be shown when the text value is empty.final void
setPlaceholderColor
(NanoColor placeholderColor) Sets the color of the placeholder text.final void
setRepeatDelay
(int repeatDelay) Sets the delay between key repeat events in milliseconds.final void
setSecure
(boolean secure) Sets the secure mode for the input field.final void
setSelectionColor
(NanoColor selectionColor) Sets the color of the selected text highlight.final void
setTextColor
(NanoColor textColor) Sets the color of the text.final void
setTextFont
(String textFont) Sets the font to be used for displaying text.final void
Sets the current value of the text widget.Methods inherited from class com.avrix.ui.widgets.PanelWidget
isDraggable, postRender, setBackgroundColor, setBorderColor, setBorderRadius, setBorderWidth, setDraggable, setDrawBorder, update
Methods inherited from class com.avrix.ui.widgets.Widget
addChild, addToScreen, bringToTop, drawArc, drawArc, drawCircle, drawEllipse, drawImage, drawLine, drawRect, drawRectOutline, drawRoundedRect, drawRoundedRectOutline, drawText, getAbsoluteParent, getChildren, getHeight, getMaxScrollX, getMaxScrollY, getParent, getScrollSpeed, getScrollX, getScrollY, getWidth, getX, getXA, getY, getYA, intersectScissor, isAlwaysOnTop, isHovered, isPointOver, isScrollable, isScrollLock, isVisible, isVisibleWithinParent, isVisibleWithinWindow, onInitialize, onKeyRelease, onMouseEnter, onMouseExit, onMouseMoveOutside, onMouseWheel, onRightMouseDown, onRightMouseDownOutside, onRightMouseUp, onRightMouseUpOutside, preRender, removeChild, removeFromScreen, renderChildren, setAlwaysOnTop, setHeight, setMaxScrollX, setMaxScrollY, setScrollable, setScrollLock, setScrollSpeed, setScrollX, setScrollY, setVisible, setWidth, setX, setXA, setY, setYA
-
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
Sets the action to be executed when the text changes.- Parameters:
onTextChangeAction
- The action to be executed on text change.
-
getValue
Gets the current value of the text widget.- Returns:
- The current text value.
-
setValue
Sets the current value of the text widget.- Parameters:
value
- The new text value.
-
getPlaceholder
Gets the placeholder text shown when the text value is empty.- Returns:
- The placeholder text.
-
setPlaceholder
Sets the placeholder text to be shown when the text value is empty.- Parameters:
placeholder
- The new placeholder text.
-
getTextFont
Gets the font used for displaying text.- Returns:
- The text font.
-
setTextFont
Sets the font to be used for displaying text.- Parameters:
textFont
- The new text font.
-
getTextColor
Gets the color of the text.- Returns:
- The text color.
-
setTextColor
Sets the color of the text.- Parameters:
textColor
- The new text color.
-
getPlaceholderColor
Gets the color of the placeholder text.- Returns:
- The placeholder text color.
-
setPlaceholderColor
Sets the color of the placeholder text.- Parameters:
placeholderColor
- The new placeholder text color.
-
getSelectionColor
Gets the color of the selected text highlight.- Returns:
- The selection color.
-
setSelectionColor
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 classPanelWidget
- 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 classWidget
- 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 classPanelWidget
- 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 classPanelWidget
- 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 classWidget
- 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 classWidget
- 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 classWidget
- 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 classPanelWidget
-