class
TUI::Form::Host(M)
- TUI::Form::Host(M)
- TUI::Widget
- Reference
- Object
Overview
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.
Defined in:
tui/form/host.crConstant Summary
-
DEFAULT_LABEL_WIDTH =
12 -
Default column width reserved for a field's label, before the value column starts — override via #initialize's
label_widthfor 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
Class Method Summary
-
.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.
-
.popup_host(screen : Screen, nav : NavStack(Widget)) : PopupHost
Builds a PopupHost from an app's actual NavStack(Widget), so a host app doesn't need to hand-write the push/pop proc wiring itself.
Instance Method Summary
-
#border_style : Style
Applied to the box border drawn by #render.
-
#border_style=(border_style : Style)
Applied to the box border drawn by #render.
-
#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.
-
#handle_key(ev : KeyEvent) : Bool
Returns true if the key was consumed.
-
#render : Nil
Draw into @buffer using LOCAL coordinates (0, 0 = this widget's own top-left).
-
#status_hint : String
Plain text describing the actions available in the widget's current state.
Instance methods inherited from class TUI::Widget
absolute(row : Int32, col : Int32) : NamedTuple(row: Int32, col: Int32)
absolute,
composite(screen : Screen) : Nil
composite,
focus_if(condition : Bool) : Nil
focus_if,
focused=(focused : Bool)
focused=,
focused? : Bool
focused?,
handle_key(ev : KeyEvent) : Bool
handle_key,
height : Int32
height,
height=(height : Int32)
height=,
local(row : Int32, col : Int32) : NamedTuple(row: Int32, col: Int32)
local,
render : Nil
render,
render_to(buffer : Buffer) : Nil
render_to,
status_hint : String
status_hint,
width : Int32
width,
width=(width : Int32)
width=,
x : Int32
x,
x=(x : Int32)
x=,
y : Int32
y,
y=(y : Int32)
y=
Constructor methods inherited from class TUI::Widget
new(x : Int32, y : Int32, width : Int32, height : Int32)
new
Constructor Detail
Class Method Detail
Sizes and positions a Host to fill the screen below the status bar row — see Window.full_screen for the same reasoning.
Instance Method Detail
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.
Returns true if the key was consumed.
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.
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.