Skip to content

TextInput ​

com.jsmacrosce.wagyourgui.elements.TextInput

A native-button-backed editable text widget with selection and optional change and press callbacks.
Its constructor does not register it with a host; add it to an existing host separately for input and rendering.

js
function makeTextInput(font, onChanged) {
 const TextInput = Java.type('com.jsmacrosce.wagyourgui.elements.TextInput');  
 return new TextInput(10, 10, 120, 20, font, Color.rgb(0x00, 0x00, 0x00), Color.rgb(0xFF, 0xFF, 0xFF),  
   Color.argb(0x80, 0x40, 0x40, 0xFF), Color.rgb(0xFF, 0xFF, 0xFF), '', null, JavaWrapper.methodToJava(onChanged));  
}

Supply a native font and JavaScript function for onChanged; onClick may be null.

Constructors ​

new TextInput ​

new TextInput(int x, int y, int width, int height, Font textRenderer, int color, int borderColor, int highlightColor, int textColor, String message, Consumer<Button> onClick, Consumer<String> onChange)#
Initializes native geometry and font, stores editable content and optional callbacks, and collapses selection at the content end. The native button label starts empty; message initializes editable content, not that label. Color, border, and text colors use button alpha correction; native hover fill uses color, while highlightColor is stored raw as the selection background. Does not invoke callbacks or register with a host.

Parameters:

  • x: left position in GUI units
  • y: top position in GUI units
  • width: width in GUI units
  • height: height in GUI units
  • textRenderer: non-null native font
  • color: idle fill as packed ARGB
  • borderColor: border as packed ARGB
  • highlightColor: raw packed ARGB selection background
  • textColor: text color as packed ARGB
  • message: non-null initial editable content
  • onClick: optional native button press callback; may be null
  • onChange: optional content-change callback; may be null

Fields ​

content ​

content: String#
Current editable display string, initialized from the constructor message; it is not the native button label. Direct writes and setMessage(String) do not update selection positions or other native-widget state; keep indices valid and refresh their GUI positions with the corresponding update methods after changing content.

mask ​

mask: String#
Mutable Java regular-expression pattern, initially ".*"; character entry tests the entire candidate content with full-string matching. Paste, cut, deletion, setMessage(String), and direct content assignment do not apply the pattern.

onChange ​

onChange: Consumer<String>#
Optional mutable callback receiving stored content after accepted character input, paste, cut, or deletion; null suppresses notification. Some boundary deletions notify even when content is unchanged. Constructor initialization, direct field writes, setMessage(String), selection changes, and focus changes do not notify. The callback runs before later selection updates.

selEndIndex ​

selEndIndex: int#
Zero-based UTF-16 end endpoint of the selection, from zero through content.length(); endpoints may be reversed. Direct writes do not refresh its cached GUI position; use updateSelEnd(int) to recalculate it.

selStartIndex ​

selStartIndex: int#
Zero-based UTF-16 start endpoint of the selection, from zero through content.length(); endpoints may be reversed. Direct writes do not refresh its cached GUI position; use updateSelStart(int) to recalculate it.

Methods ​

charTyped ​

charTyped(char chr, int modifiers): boolean#
Replaces the current selection with one Java UTF-16 char only when the resulting content fully matches the mask; this method does not check focus. Reversed selection endpoints are exchanged before testing, even if insertion is rejected. Accepted content is stored before the optional change callback, then selection and arrowCursor advance past the inserted char; a callback failure prevents those later updates. Requires a valid non-null regex mask and valid indices in non-null content. Does not delegate to the superclass and returns false on normal completion even when insertion was accepted.

Parameters:

  • chr: Java UTF-16 char to insert
  • modifiers: unused modifier bits
Returns: false on normal completion, independently of acceptance

keyPressed ​

keyPressed(int keyCode, int scanCode, int modifiers): boolean#
Handles focused text-editing shortcuts and navigation, then delegates the key event to the superclass. Supports select-all, copy, paste, cut, deletion and cursor navigation. Paste and deletions bypass the mask; Control, not Shift, extends left/right selection using the current native modifier state. Select-all, Home and End update selection endpoints without refreshing arrowCursor. Edits can notify the optional change callback even when deletion leaves content unchanged; a callback failure can leave changed content before endpoint updates and prevents superclass delegation.

Parameters:

  • keyCode: GLFW key code used for local handling
  • scanCode: scan code forwarded to the superclass, unused locally
  • modifiers: modifier bits forwarded to the superclass, not consulted by local shortcuts or navigation
Returns: the superclass's handled state, not whether text changed; local edits can occur even when it is false

mouseClicked ​

mouseClicked(double mouseX, double mouseY, int button): boolean#
When already focused on entry, moves both selection endpoints and arrowCursor to the position derived from mouseX, then delegates to the native widget. The local position update occurs before superclass filtering and may happen even if the returned handled state is false; an unfocused call makes no local cursor change before delegation.

Parameters:

  • mouseX: mouse x-coordinate in GUI units, used for the local text position
  • mouseY: mouse y-coordinate in GUI units, forwarded to the native handler
  • button: mouse button forwarded to the native handler
Returns: the native handler's handled state, not whether the local selection moved

mouseDragged ​

mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY): boolean#
When focused on entry, moves the selection end and arrowCursor to the position derived from mouseX, leaving the start endpoint unchanged, then delegates to the native widget. The local update has no button, bounds, active, or visibility guard; the native return value is independent of whether that update occurred.

Parameters:

  • mouseX: mouse x-coordinate in GUI units, used for the local text position
  • mouseY: mouse y-coordinate forwarded to the native handler
  • button: mouse button forwarded to the native handler
  • deltaX: horizontal drag delta forwarded to the native handler
  • deltaY: vertical drag delta forwarded to the native handler
Returns: the native handler's handled state

setMessage ​

setMessage(String message): void#
Replaces editable content only; unlike the inherited component-label setter, this does not update the native button label. Does not apply mask, notify onChange, or refresh selection positions or arrowCursor; keep existing indices valid and refresh positions with the corresponding update methods.

Parameters:

  • message: replacement content; supported as non-null
setMessage(Component message): void#
Sets the native label and caches wrapping at width minus four GUI units, a height-limited visible-line count and vertical offset for the current geometry. The cache is not refreshed by later geometry changes until this method is called again. This method does not invoke the press callback.

Parameters:

  • message: nonnull native component label

setSelected ​

setSelected(boolean sel): void#
Sets this widget's native focus flag without changing text selection or arrowCursor, invoking the change callback, or requesting focus through the host.

Parameters:

  • sel: desired native widget focus state, not a text-selection flag

swapStartEnd ​

swapStartEnd(): void#
Exchanges the selection's start and end indices and recalculates their GUI positions from the current content and font. This is an exchange, not a sort; it does not change content, arrowCursor, focus or the change callback. Indices must be within the current non-null content's range.

updateSelEnd ​

updateSelEnd(int endIndex): void#
Stores the selection end endpoint and recalculates its cached GUI x-position from current content and font. Indices are zero-based UTF-16 offsets in 0..content.length(); the index is stored before position calculation, which can fail for invalid content or index.

Parameters:

  • endIndex: nonnegative UTF-16 endpoint within current content

updateSelStart ​

updateSelStart(int startIndex): void#
Stores the selection start endpoint and recalculates its cached GUI x-position from current content and font. Indices are zero-based UTF-16 offsets in 0..content.length(); the index is stored before position calculation, which can fail for invalid content or index.

Parameters:

  • startIndex: nonnegative UTF-16 endpoint within current content