UITextInput Class
Definition
Namespace: Brine2D.UI
Single-line text input with cursor, horizontal scrolling, and selection.
Inheritance System.Object ā UITextInput
Implements IUIComponent, IAnchoredUIComponent
| Properties | |
|---|---|
| Anchor | The screen anchor point this component is positioned relative to. |
| AnchorOffset | Pixel offset from the resolved anchor point. |
| BackgroundColor | Background color when unfocused. |
| BorderColor | Border color. |
| CharacterFilter | Optional per-character filter. When set, only characters for which the delegate returns true are accepted ā both from direct typing and from paste. Leave null to accept all characters. |
| CursorHeight | Height in pixels of the cursor bar and text selection highlight. Defaults to 16. Set this to match the cap-height of a custom Font. |
| CursorPosition | Current cursor position \(character index, 0 = before first character\). |
| FocusedBackgroundColor | Background color when focused. |
| FocusedBorderColor | Focused border color. |
| Font | Font to use for rendering \(null = renderer default\). |
| IsFocused | Whether this input is currently focused. |
| IsPassword | When true, the text is hidden behind MaskChar characters. |
| MaskChar | Character used to mask text when IsPassword is true. Defaults to 'ā'. |
| MaxLength | Maximum character length \(0 = unlimited\). |
| Placeholder | Placeholder text shown when empty. |
| PlaceholderColor | Placeholder text color. |
| ReadOnly | When true, the field displays its text but rejects all edits. Navigation and copy \(Ctrl\+C\) still work. |
| SelectionColor | Selection highlight color. |
| Text | Current text value. |
| TextColor | Text color. |
| UndoStackLimit | Maximum undo steps retained. Older steps are discarded when exceeded. Set to 0 for unlimited history. Defaults to 100. |
| Methods | |
|---|---|
| ClearUndoHistory() | Clears the undo and redo history. |
| EndMouseDrag() | Called by UICanvas when the mouse button is released \(drag\-to\-select end\). |
| FindWordBoundaryBackward\(int\) | Returns the index of the start of the previous word \(or 0 if already at the beginning\). Skips whitespace, then skips the preceding word. |
| FindWordBoundaryForward\(int\) | Returns the index just past the end of the next word \(or Text\.Length if already at the end\). Skips whitespace, then skips the following word. |
| HandleTextInput\(IInputContext\) | Called by UICanvas to handle text input. |
| HitTestCharacterIndex\(IRenderer, float, string\) | Returns the character index closest to screenX given the current scroll offset. Used to position the cursor on mouse click or drag. displayText should be Brine2D.UI.UITextInput.GetDisplayText so that password-masked fields are measured correctly. Widths are accumulated incrementally \(O\(n\) measurements instead of O\(n²\)). |
| Redo() | Redoes the last undone change. No-op if the redo stack is empty. |
| SetFocused\(bool, IInputContext\) | Called by UICanvas when input is focused or unfocused. |
| SetFocused\(bool, IInputContext, Nullable<float>\) | Called by UICanvas when the field is focused by a mouse click. clickX is the screen X of the click; the cursor is placed at the nearest character boundary on the next Render call. |
| StartMouseDrag\(float\) | Called by UICanvas when the mouse button is pressed inside the field \(drag\-to\-select start\). Returns true when the click was a double-click and word selection was applied \(no drag should begin in that case\). |
| Undo() | Undoes the last text change. No-op if the undo stack is empty. |
| UpdateMouseDrag\(float\) | Called by UICanvas each frame the mouse is held and moving \(drag\-to\-select update\). |
| Events | |
|---|---|
| OnFocusGained | Event fired when this field gains keyboard focus. |
| OnFocusLost | Event fired when this field loses keyboard focus. |
| OnSubmit | Event fired when Enter key is pressed. |
| OnTextChanged | Event fired when text changes. |