class

TUI::Form::Host(M)

Inherits TUI::Widget < Reference < Object

Drives a list of FieldSpec(M) against a bound model M. Layout and per-field focus/editing are delegated to an internal Grid (src/tui/layout/grid.cr) of FormFieldCell widgets (one per field, each drawing its own label + editor and handling its own start/commit/cancel) — Host itself now only owns the outer box/title chrome and builds the Grid once at construction time. Previously Host hand-computed row/column coordinates and drove @editor/@focus_index directly; that per-field state now lives in each FormFieldCell, and cross-field focus traversal (Tab/Shift+Tab) lives in Grid — both reusable independent of Form::Host.

Constants

DEFAULT_LABEL_WIDTH = 12

Default column width reserved for a field's label, before the value column starts — override via #initialize's label_width for consumers with longer labels.

DEFAULT_MAX_ERROR_WIDTH = 40

Default upper bound on how much value-column width an inline error message may claim, even if there'd be room to give it more. Override via #initialize's max_error_width.

DEFAULT_MIN_VALUE_WIDTH = 20

Default floor: the value column must keep at least this much width before any of it is given up to an inline error message — below this floor, the error is dropped rather than squeezing the value further. Override via #initialize's min_value_width.

Constructors

new(x : Int32, y : Int32, width : Int32, height : Int32, fields : Array(FieldSpec(M)), model : M, popup : PopupHost, title : String = "Edit", label_width : Int32 = DEFAULT_LABEL_WIDTH, min_value_width : Int32 = DEFAULT_MIN_VALUE_WIDTH, max_error_width : Int32 = DEFAULT_MAX_ERROR_WIDTH)
Source

Class methods

full_screen(screen : Screen, fields : Array(FieldSpec(M)), model : M, popup : PopupHost, title : String = "Edit", label_width : Int32 = DEFAULT_LABEL_WIDTH, min_value_width : Int32 = DEFAULT_MIN_VALUE_WIDTH, max_error_width : Int32 = DEFAULT_MAX_ERROR_WIDTH) : Host(M)

Sizes and positions a Host to fill the screen below the status bar row — see Window.full_screen for the same reasoning.

Source

Instance methods

border_style

Applied to the box border drawn by #render.

Source
border_style=(border_style : Style)

Applied to the box border drawn by #render.

Source
composite(screen : Screen) : Nil

Re-derives the Grid's own x/y/width/height from Host's current geometry every frame — the same convention HSplit#composite/ #layout follow, rather than trusting the values fixed at construction — so a Host that gets resized after construction (e.g. Runtime's SIGWINCH handler calling Widget#width=/#height= on whatever full-screen page is on top of the NavStack, which includes a Form::Host page like example/pages/form_page.cr) still hosts a correctly-sized Grid, which in turn reflows every attached FormFieldCell's width via its own weighted #col_widths (see Grid#layout) instead of staying pinned to the width current when the Grid/cells were first constructed.

Source
handle_key(ev : KeyEvent) : Bool

Returns true if the key was consumed.

Source
render

Draw into @buffer using LOCAL coordinates (0, 0 = this widget's own top-left). Widgets never need to know their own x/y offset to draw themselves — that arithmetic is handled entirely by composite.

Source
status_hint

Plain text describing the actions available in the widget's current state. Rendered by the App in the global status bar at the bottom of the screen — widgets must NOT draw their own hint lines.

Source