This document captures design and implementation notes for TextBox.
For end-user usage and examples, see TextBox.
TextEditorBase).TextEditorBase / TextEditorCore)TextBox : TextEditorBaseTextBox():
HorizontalAlignment = Align.StretchDynamicTextDocument bound to the Text propertyIsPassword = false, PasswordRevealMode = Never, ClipboardMode = CopyTextTextBox(string? text) sets initial Text.Text : string?IsPassword : boolPasswordRevealMode : PasswordRevealMode (Never, WhileFocused, Always)ClipboardMode : TextBoxClipboardMode
CopyText: allows standard copy/cut behaviorCtrl+C/Ctrl+X (for sensitive inputs)TextAlignment : TextAlignmentIsSingleLine = trueAcceptsReturn = falseAlignment => TextAlignmentShowPlaceholderWhenUnfocusedOnly = trueGetTextBoxStyle() resolves TextBoxStyle from 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)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 = finalRect minus TextBoxStyle.PaddingUpdateEditorLayoutForOverflowIndicators(baseRect, style):
UpdateEditorLayout(editorRect) (from TextEditorBase) to update scroll viewport/extentsScroll.OffsetX > 0 (left)Scroll.OffsetX + Scroll.ViewportWidth < Scroll.ExtentWidth (right)UpdateEditorLayout can change Scroll.* values)Rendering is split into two parts:
TextBoxStyle.BackgroundStyle(theme, focused)RenderEditor(...) into the computed editor rectTextBoxStyle.OverflowIndicatorStyle(theme)TextBox uses a DynamicTextDocument so the editor reads/writes through the Text bindable property.TextEditorBase.Placeholder and is styled with TextBoxStyle.PlaceholderStyle(...).TextBoxStyle.SelectionStyle(theme) (currently bold + selection background color).IsPassword is enabled and PasswordRevealMode does not allow reveal, TextBox overrides WriteTextSegment(...) to render a mask glyph (TextBoxStyle.PasswordMaskGlyph) for the text region.* to preserve layout.TextBoxStyle controls:
Padding (default Thickness(1,0,1,0))PasswordMaskGlyph (default •)OverflowIndicatorLeft / OverflowIndicatorRight (defaults ← / →, can be disabled by setting to null)Border, FocusBorder, Selection, Background, Placeholder)The default style resolution uses theme colors like Theme.InputFill, Theme.InputFillFocused, Theme.SurfaceAlt, and Theme.Muted.
src/XenoAtom.Terminal.UI.Tests/TextBoxInputTests.cssrc/XenoAtom.Terminal.UI.Tests/TextBoxOverflowIndicatorTests.cssrc/XenoAtom.Terminal.UI.Tests/TextBoxPasswordTests.cs