Mosaic_ui.RendererSourceLayout, drawing, hit testing, and event dispatch pipeline.
Renderer: layout, drawing, hit testing, and event dispatch.
The renderer drives a three-pass pipeline over a Renderable.t tree:
After the pipeline, render diffs the grid against the previous frame and returns minimal ANSI output.
The renderer owns the root Renderable.t, the Screen.t, and all pipeline state. Widget code builds the tree under root; the event loop calls render_frame and render, then dispatches input events.
The type for renderer state. Owns the root renderable, layout tree, screen, and all render pipeline state.
val create :
?glyph_pool:Glyph.Pool.t ->
?width_method:Glyph.width_method ->
?style:Toffee.Style.t ->
unit ->
tcreate () is a renderer with a root renderable and an empty screen. The optional parameters are:
glyph_pool: the shared glyph pool for text rendering. Defaults to a fresh Glyph.Pool.t.width_method: the glyph width computation method. Defaults to the Glyph.width_method default.style: the root node's initial style. Defaults to Toffee.Style.default.root t is the root renderable. Build the UI tree under this node.
glyph_pool t is the shared glyph pool for text rendering.
render_frame t ~width ~height ~delta builds the next frame.
The pipeline runs in order:
on_frame and resize hooks).add_frame_callback).width and height are the frame dimensions in terminal cells. delta is elapsed milliseconds since the last frame.
render t diffs the current frame against the previous one and returns the minimal ANSI output string. Call after render_frame.
When full is true, all cells are emitted regardless of changes. full defaults to false.
needs_render t is true iff a renderable has requested a re-render or live nodes are active.
dispatch_key t key sends key to the focused renderable and returns the resulting event.
If the focused node does not prevent default, the default key handler runs. The returned event carries the default_prevented flag set by the focused node's handler; callers can inspect it to determine whether the key was consumed.
dispatch_mouse t mouse runs the full mouse dispatch pipeline:
Over/Out events on target change.dispatch_paste t text sends text as a paste event to the focused renderable.
val dispatch_scroll :
t ->
x:int ->
y:int ->
direction:Event.Mouse.scroll_direction ->
delta:int ->
modifiers:Input.Key.modifier ->
unitdispatch_scroll t ~x ~y ~direction ~delta ~modifiers dispatches a scroll event at terminal cell position (x, y).
focused t is the currently focused renderable, if any.
focus t node focuses node and is true iff node is focusable.
selection t is the active text selection, if any.
clear_selection t clears the active text selection, notifying all selectable renderables under the selection container.
captured t is the renderable currently capturing all mouse events during a drag gesture, if any.
hover t is the renderable currently under the mouse pointer, if any.
add_frame_callback t f registers f to run at the start of each frame with delta time in milliseconds. Callbacks run after lifecycle passes and before layout computation.
See also remove_frame_callback and clear_frame_callbacks.
remove_frame_callback t f unregisters f using physical equality.
See also add_frame_callback.
clear_frame_callbacks t removes all registered frame callbacks.
See also add_frame_callback.
add_post_process t f registers f as a persistent post-processing transform on the underlying screen. f receives the rendered Grid.t and the frame delta in milliseconds; it runs after frame building and before diffing. Returns a Screen.effect_id for later removal.
See also remove_post_process and clear_post_processes.
remove_post_process t id unregisters the post-processor identified by id.
See also add_post_process.
clear_post_processes t removes all registered post-processing functions.
See also add_post_process.