A t combines a layout node with rendering callbacks, event handlers, focus state, and lifecycle hooks. Nodes form a mutable tree: parent-child relationships drive both layout computation and rendering order.
Widgets create nodes with create, configure them with setters, and render content through callbacks. The renderer drives the pipeline through Private.
create ~parent () is a new node attached as a child of child_target parent. When index is omitted the node is appended last; otherwise it is inserted at the given position, clamped to [0;child_count].
Optional parameters:
id: unique identifier string. Defaults to "node-N".
style: flexbox style. Defaults to Toffee.Style.default.
visible: initial visibility. Defaults to true.
z_index: rendering order; higher values render on top. Defaults to 0.
opacity: opacity clamped to [0.0;1.0]. Defaults to 1.0.
live: continuous rendering every frame. Defaults to false.
Raises Invalid_argument if the layout tree rejects the node.
Sourceval attach : parent:t->?index:int ->t-> unit
attach ~parent t attaches t as a child of child_target parent, detaching t from any previous parent first. When index is omitted the node is appended last.
Raises Invalid_argument if parent and t belong to different trees, or if either node is destroyed.
destroy t detaches t, removes all children (clearing their parent pointers and lifecycle registrations), frees its layout node, and clears all handlers. The node becomes unusable. No-op if already destroyed.
Children are removed but not themselves destroyed — they become orphaned nodes that can be reattached elsewhere. Use destroy_recursively to destroy the entire subtree.
child_target t is the node that receives children on behalf of t. Defaults to t itself. Composite widgets override this to redirect children to an internal container (e.g. a scroll box routes children to its content node).
set_style t style updates t's flexbox style, marks layout dirty, and schedules a re-render. When explicit dimensions are present and flex_shrink is still at its default 1.0, it is automatically set to 0.0 to match terminal layout conventions.
set_child_clip t fn overrides the clipping rectangle applied to t's children. When set, the renderer calls fn t to obtain a scissor rectangle before rendering children. Useful for scroll containers and bordered boxes. None clears the override.
blur t removes focus from t. No-op if t is not focused.
Sourceval set_cursor_provider : t->(t->cursor option)-> unit
set_cursor_provider t f registers a hardware cursor provider consulted when t is focused. f is called with t and returns the desired cursor state, or None to hide the cursor.
on_mouse t handler registers a mouse event handler on t. Handlers accumulate and run newest-first. Mouse events bubble to ancestors unless Event.Mouse.stop_propagation is called.
set_selection t ~should_start ~on_change ~clear ~get_text enables text selection on t. The renderer calls these callbacks during mouse interactions and clipboard operations. The contract is:
should_start ~x ~y is true iff a selection drag starting at (x, y) should be initiated.
on_change sel is called when the selection changes; returns true to accept the selection.
The type for display line metrics used by line-numbering widgets.
line_count: number of logical lines.
display_line_count: number of visual lines after wrapping.
line_sources.(i): logical line index for display line i.
line_wrap_indices.(i): sub-line index within the logical line — 0 for the first display line, 1 for the first continuation, and so on.
scroll_y: vertical scroll offset in display lines.
Sourceval set_line_info_provider : t->(unit ->line_info) option-> unit
set_line_info_provider t f registers a function that supplies line metrics for t. Used by composite widgets (e.g. line-number gutters) to read display line information from a content child without coupling to its concrete type. None clears the provider.
line_info t is the current line metrics from t's provider, or None if no provider is registered.
Lifecycle
Sourceval set_on_frame : t->(t->delta:float -> unit) option-> unit
set_on_frame t callback registers a per-frame update hook. callback t ~delta is called every frame with delta as the elapsed milliseconds. None clears the hook.
Sourceval set_on_resize : t->(t-> unit) option-> unit
set_on_resize t callback registers a size-change hook. The callback is called when width or height changes after layout. None clears the hook.