| title | TextBox Specs |
|---|
This document captures design and implementation notes for TextBox.
Note
For end-user usage and examples, see TextBox.
- Status: Implemented
- Primary purpose: A single-line, focusable text input built on the shared text editing infrastructure (
TextEditorBase). - Key features:
- selection, clipboard, undo/redo, word navigation (via
TextEditorBase/TextEditorCore) - horizontal scrolling with optional overflow indicators
- password mode with reveal policies
- placeholder rendering (when empty)
- selection, clipboard, undo/redo, word navigation (via
TextBox : TextEditorBase
TextBox():- sets
HorizontalAlignment = Align.Stretch - initializes a
DynamicTextDocumentbound to theTextproperty - sets defaults:
IsPassword = false,PasswordRevealMode = Never,ClipboardMode = CopyText
- sets
TextBox(string? text)sets initialText.
Text : string?IsPassword : boolPasswordRevealMode : PasswordRevealMode(Never,WhileFocused,Always)ClipboardMode : TextBoxClipboardModeCopyText: allows standard copy/cut behavior- other modes: prevent
Ctrl+C/Ctrl+X(for sensitive inputs)
TextAlignment : TextAlignment
IsSingleLine = trueAcceptsReturn = falseAlignment => TextAlignmentShowPlaceholderWhenUnfocusedOnly = falseGetTextBoxStyle()resolvesTextBoxStylefrom the style environment.
TextBox intentionally measures to a “reasonable default” single-line size:
width = clamp(availableWidth, min: 10, max: 24)height = 1 + TextBoxStyle.Padding.Vertical(clamped to available height)- returns
SizeHints.Fixed(...)
This is a default sizing policy; parent layout and constraints (e.g., MinWidth, MaxWidth, containers) still control the final size.
ArrangeCore computes a padded “base rect” and then allocates space for overflow indicators:
baseRect = finalRectminusTextBoxStyle.PaddingUpdateEditorLayoutForOverflowIndicators(baseRect, style):- calls
UpdateEditorLayout(editorRect)(fromTextEditorBase) to update scroll viewport/extents - decides whether to show left/right indicators based on:
Scroll.OffsetX > 0(left)Scroll.OffsetX + Scroll.ViewportWidth < Scroll.ExtentWidth(right)
- if indicators are visible, shrinks the editor rect by 1 cell on the corresponding side(s)
- repeats up to 3 passes to converge (because
UpdateEditorLayoutcan changeScroll.*values)
- calls
Rendering is split into two parts:
- Background fill: fills the padded base rect with
TextBoxStyle.BackgroundStyle(theme, focused) - Text editor: calls
RenderEditor(...)into the computed editor rect - Overflow indicators: when active, draws glyphs in the reserved cells adjacent to the editor rect (inside the padded base rect), using
TextBoxStyle.OverflowIndicatorStyle(theme)
TextBoxuses aDynamicTextDocumentso the editor reads/writes through theTextbindable property.- Placeholder rendering comes from
TextEditorBase.Placeholderand is styled withTextBoxStyle.PlaceholderStyle(...). The placeholder stays visible while the editor is empty, including when focused, and renders withTextStyle.Dim. - Selection rendering uses
TextBoxStyle.SelectionStyle(theme)(currently bold + selection background color).
- When
IsPasswordis enabled andPasswordRevealModedoes not allow reveal,TextBoxoverridesWriteTextSegment(...)to render a mask glyph (TextBoxStyle.PasswordMaskGlyph) for the text region. - The mask glyph must be single-cell wide; otherwise the control falls back to
*to preserve layout.
TextBoxStyle controls:
Padding(defaultThickness(1,0,1,0))PasswordMaskGlyph(default•)OverflowIndicatorLeft/OverflowIndicatorRight(defaults←/→, can be disabled by setting tonull)- optional color overrides (
Border,FocusBorder,Selection,Background,Placeholder)
The default style resolution uses theme colors like Theme.InputFill, Theme.InputFillFocused, Theme.SurfaceAlt, and Theme.Muted.
- Tests:
src/XenoAtom.Terminal.UI.Tests/TextBoxInputTests.cssrc/XenoAtom.Terminal.UI.Tests/TextBoxOverflowIndicatorTests.cssrc/XenoAtom.Terminal.UI.Tests/TextBoxPasswordTests.cs
- Demo:
- See the ControlsDemo “TextBox” page.
- Expose a configurable default measure policy (e.g., desired width) without requiring custom subclasses.
- Add a dedicated “secure input” mode that disables both copy and cut, and optionally disables selection.