package mosaic
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9e4e90d17f9b2af1b07071fe425bc2c519c849c4f1d1ab73cde512be2d874849
sha512=06e9c4a741590942e81a27738d0b5c0413fafec8cf3b7dae047ad69f155e7b718aa4223818dc161b7d028efffcfd3365905e264d6fd31d453910ddfa91dcf9b9
doc/mosaic.ui/Mosaic_ui/Renderable/index.html
Module Mosaic_ui.RenderableSource
Mutable UI tree nodes with layout integration.
Mutable UI tree nodes with layout integration.
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.
Types
The type for mutable nodes in the UI tree.
The type for render callbacks. render self grid ~delta draws self into grid. delta is the elapsed time in milliseconds since the last frame.
type measure =
known_dimensions:float option Toffee.Geometry.Size.t ->
available_space:Toffee.Available_space.t Toffee.Geometry.Size.t ->
style:Toffee.Style.t ->
float Toffee.Geometry.Size.tThe type for intrinsic size computation callbacks. Called during layout when a node lacks explicit dimensions.
type cursor = {x : int;y : int;style : [ `Block | `Line | `Underline ];color : Ansi.Color.t;blinking : bool;
}The type for hardware cursor descriptions. Coordinates are absolute terminal cell positions.
equal_cursor a b is true iff all fields of a and b match.
pp_cursor ppf c formats c on ppf for debugging.
Constructors
val create :
parent:t ->
?index:int ->
?id:string ->
?style:Toffee.Style.t ->
?visible:bool ->
?z_index:int ->
?opacity:float ->
?live:bool ->
?render:render ->
unit ->
tcreate ~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 toToffee.Style.default.visible: initial visibility. Defaults totrue.z_index: rendering order; higher values render on top. Defaults to0.opacity: opacity clamped to [0.0;1.0]. Defaults to1.0.live: continuous rendering every frame. Defaults tofalse.
Raises Invalid_argument if the layout tree rejects the node.
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.
detach t removes t from its parent. The node remains valid and can be reattached with attach. Blurs t if focused. No-op if already detached.
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.
destroy_recursively t destroys t and all descendants depth-first. See also destroy.
Identity
children t is t's children in insertion order. The list is a snapshot; subsequent mutations are not reflected.
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).
See also set_child_target.
set_child_target t target sets the node that receives children on behalf of t. None resets to t itself.
Layout
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_measure t fn assigns a custom measure function for intrinsic sizing and marks layout dirty. None clears it.
width t is t's layout width in terminal cells. Returns 0 when t is hidden or layout has not yet been computed.
height t is t's layout height in terminal cells. Returns 0 when t is hidden or layout has not yet been computed.
bounds t is { x = x t; y = y t; width = width t; height = height t }.
set_translate t ~x ~y shifts t's rendering position by (x, y) without affecting layout. Useful for scrolling.
Rendering
set_render t fn replaces t's render callback and schedules a re-render.
set_render_before t hook assigns an optional pre-render hook. None clears it.
set_render_after t hook assigns an optional post-render hook. None clears it.
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.
Visual properties
set_visible t v shows or hides t. Blurs t if it is focused while being hidden.
set_z_index t z sets t's rendering order. Higher values render on top.
set_opacity t v sets t's opacity, clamped to [0.0;1.0]. Values below 1.0 cause the renderer to push an opacity context around t and its descendants.
set_buffered t v enables or disables offscreen buffering. When true, t renders into a private grid that is blitted to the parent grid.
set_live t v enables or disables continuous rendering. When live, the renderer runs t's render callback every frame rather than only on request.
Focus
focus t requests focus for t. Returns false if t is not focusable. Delegates to the renderer's focus controller.
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.
cursor t is the current hardware cursor state as reported by t's cursor provider, or None if no provider is set.
Events
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.
on_key t handler registers a keyboard handler on t. Handlers accumulate and run newest-first until one calls Event.Key.prevent_default.
set_default_key_handler t handler assigns a fallback key handler that runs after on_key handlers. Only one fallback handler per node. None clears it.
set_paste_handler t handler assigns a paste handler on t. Only one paste handler per node. None clears it.
Selection
val set_selection :
t ->
should_start:(x:int -> y:int -> bool) ->
on_change:(Selection.t option -> bool) ->
clear:(unit -> unit) ->
get_text:(unit -> string) ->
unitset_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 ~yistrueiff a selection drag starting at(x, y)should be initiated.on_change selis called when the selection changes; returnstrueto accept the selection.clear ()discards any active selection state.get_text ()returns the currently selected text.
Line information
type line_info = {line_count : int;display_line_count : int;line_sources : int array;line_wrap_indices : int array;scroll_y : int;
}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 linei.line_wrap_indices.(i): sub-line index within the logical line —0for the first display line,1for the first continuation, and so on.scroll_y: vertical scroll offset in display lines.
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
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.
Formatting and inspecting
pp ppf t formats t on ppf for debugging.
Renderer integration
Privileged operations used by the renderer during the render pipeline and event dispatch. Widget authors must not call these directly.