A multi-line text input widget. More...
Public Member Functions | |
| void | OnKeyEvent (KeyMsg key, Action< IMsg > dispatch) |
| Process a key event and dispatch a TextAreaChangedMsg with the new document state. | |
| void | Render (IRenderContext ctx) |
| Renders visible lines into the allocated region. | |
| TextArea () | |
| Object-initializer constructor; all properties default. | |
| TextArea (IReadOnlyList< string >? lines=null, int cursorRow=0, int cursorCol=0, int scrollRow=0, int maxLines=0, Style? style=null) | |
| Positional constructor for inline usage. | |
Static Public Member Functions | |
| static int | ComputeScrollRow (int cursorRow, int viewportHeight, int currentScrollRow) |
| Compute a new ScrollRow that keeps cursorRow within the visible viewport. | |
Properties | |
| int | CursorCol [get] |
| Zero-based column of the cursor within the current line. | |
| int | CursorRow [get] |
| Zero-based row of the cursor within Lines. | |
| bool | HasFocus [get, set] |
| True when this widget holds keyboard focus. | |
| SizeConstraint | Height = SizeConstraint.Flex(1) [get] |
| Height constraint used by the layout engine. | |
| IReadOnlyList< string > | Lines = [""] [get] |
| Lines of text. Never null; empty list = empty document. | |
| int | MaxLines [get] |
| Maximum number of lines allowed. | |
| int | ScrollRow [get] |
| First line index rendered. | |
| Style | Style = Style.Default [get] |
| Visual style for the text content. Inherits theme base style when unset. | |
| SizeConstraint | Width = SizeConstraint.Flex(1) [get] |
| Width constraint used by the layout engine. | |
A multi-line text input widget.
Cursor position and scroll state live in the model (all properties are { get; init; }) — use the TextAreaChangedMsg returned from OnKeyEvent to derive the next widget state via with.
Scroll — The widget renders lines [ScrollRow, ScrollRow + visibleHeight). Update ScrollRow in your model's Update handler; use ComputeScrollRow as a helper.
Line endings — All text is stored as a list of strings (one per logical line). The widget does not produce or consume in its messages.
| ConsoleForge.Widgets.TextArea.TextArea | ( | IReadOnlyList< string >? | lines = null, |
| int | cursorRow = 0, | ||
| int | cursorCol = 0, | ||
| int | scrollRow = 0, | ||
| int | maxLines = 0, | ||
| Style? | style = null ) |
Positional constructor for inline usage.
| lines | Initial line content. Null or empty → single empty line. |
| cursorRow | Initial cursor row (clamped). |
| cursorCol | Initial cursor column (clamped). |
| scrollRow | Initial vertical scroll offset. |
| maxLines | Max line count (0 = unlimited). |
| style | Optional visual style override. |
|
static |
Compute a new ScrollRow that keeps cursorRow within the visible viewport.
Call this from your model's Update handler when handling TextAreaChangedMsg and WindowResizeMsg.
| cursorRow | The cursor row after the edit. |
| viewportHeight | Number of visible rows in the TextArea's region. |
| currentScrollRow | Current scroll offset. |
| void ConsoleForge.Widgets.TextArea.OnKeyEvent | ( | KeyMsg | key, |
| Action< IMsg > | dispatch ) |
Process a key event and dispatch a TextAreaChangedMsg with the new document state.
The model should replace this widget instance with one constructed from the message fields using with expressions.
Implements ConsoleForge.Layout.IFocusable.
| void ConsoleForge.Widgets.TextArea.Render | ( | IRenderContext | ctx | ) |
Renders visible lines into the allocated region.
Lines outside [ScrollRow, ScrollRow + height) are not drawn. When focused, the cursor position is highlighted with reverse-video.
Implements ConsoleForge.Layout.IWidget.
|
get |
Maximum number of lines allowed.
0 = unlimited. When at the limit, Enter is a no-op.
|
get |
First line index rendered.
Used for vertical scrolling. Update via ComputeScrollRow when handling TextAreaChangedMsg.