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
ConstructorsConstructorDescriptionInputTextWidget(int x, int y, int width, int height) Constructs an InputTextWidget with the specified position and size. -
Method Summary
Modifier and TypeMethodDescriptionzombie.ui.UITextBox2Getting the default InputText UI Element to block game inputfinal intGets the offset from the border for the text.final intGets the font size used for displaying text.final StringGets the placeholder text shown when the text value is empty.final NanoColorGets the color of the placeholder text.final intGets the delay between key repeat events in milliseconds.final NanoColorGets the color of the selected text highlight.final NanoColorGets the color of the text.final StringGets the font used for displaying text.final StringgetValue()Gets the current value of the text widget.final booleanisActive()Checks if the text widget is currently active.final booleanChecks if the cursor is currently visible.final booleanChecks if the text widget is editable.final booleanisSecure()Returns whether the input field is in secure mode.voidonKeyPress(int key) Handles the event when a key is pressed down.voidonKeyRepeat(int key) Handles the event when a key is repeatedly pressed.voidonLeftMouseDown(int x, int y) Handles the event when the left mouse button is pressed down within the widget.voidonLeftMouseDownOutside(int x, int y) Handles the event when the left mouse button is released outside the widget.voidonLeftMouseUp(int x, int y) Handles the event when the left mouse button is released.voidonLeftMouseUpOutside(int x, int y) Handles the event when the left mouse button is released outside the widget.voidonMouseMove(int x, int y) Handles the event when the mouse is moved within the widget.voidrender()Renders the text widget, including text, selection highlight, and cursor.final voidsetActive(boolean active) Sets the active state of the text widget.final voidsetBorderOffset(int borderOffset) Sets the offset from the border for the text.final voidsetCursorVisible(boolean cursorVisible) Sets the visibility of the cursor.final voidsetEditable(boolean editable) Sets whether the text widget is editable.final voidsetFontSize(int fontSize) Sets the font size used for displaying text.final voidsetOnTextChangeAction(Consumer<String> onTextChangeAction) Sets the action to be executed when the text changes.final voidsetPlaceholder(String placeholder) Sets the placeholder text to be shown when the text value is empty.final voidsetPlaceholderColor(NanoColor placeholderColor) Sets the color of the placeholder text.final voidsetRepeatDelay(int repeatDelay) Sets the delay between key repeat events in milliseconds.final voidsetSecure(boolean secure) Sets the secure mode for the input field.final voidsetSelectionColor(NanoColor selectionColor) Sets the color of the selected text highlight.final voidsetTextColor(NanoColor textColor) Sets the color of the text.final voidsetTextFont(String textFont) Sets the font to be used for displaying text.final voidSets the current value of the text widget.Methods inherited from class com.avrix.ui.widgets.PanelWidget
isDraggable, postRender, setBackgroundColor, setBorderColor, setBorderRadius, setBorderWidth, setDraggable, setDrawBorder, updateMethods 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:
trueif the text widget is editable,falseotherwise.
-
setEditable
public final void setEditable(boolean editable) Sets whether the text widget is editable.- Parameters:
editable-trueto make the widget editable,falseotherwise.
-
isActive
public final boolean isActive()Checks if the text widget is currently active.- Returns:
trueif the widget is active,falseotherwise.
-
setActive
public final void setActive(boolean active) Sets the active state of the text widget.- Parameters:
active-trueto activate the widget,falseto deactivate it.
-
isCursorVisible
public final boolean isCursorVisible()Checks if the cursor is currently visible.- Returns:
trueif the cursor is visible,falseotherwise.
-
setCursorVisible
public final void setCursorVisible(boolean cursorVisible) Sets the visibility of the cursor.- Parameters:
cursorVisible-trueto make the cursor visible,falseto 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:
trueif the input field is in secure mode,falseotherwise.
-
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-trueto enable secure mode,falseto 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:
onLeftMouseUpin 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:
onLeftMouseDownOutsidein 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:
onLeftMouseDownin 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:
onLeftMouseUpOutsidein 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:
onMouseMovein 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:
onKeyRepeatin 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:
onKeyPressin 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:
renderin classPanelWidget
-