package mosaic
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9e4e90d17f9b2af1b07071fe425bc2c519c849c4f1d1ab73cde512be2d874849
sha512=06e9c4a741590942e81a27738d0b5c0413fafec8cf3b7dae047ad69f155e7b718aa4223818dc161b7d028efffcfd3365905e264d6fd31d453910ddfa91dcf9b9
doc/mosaic.ui/Mosaic_ui/Renderer/index.html
Module Mosaic_ui.RendererSource
Layout, 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:
- Lifecycle: runs per-frame and resize hooks on registered nodes.
- Layout and command generation: computes layout via Toffee, walks the tree depth-first to extract absolute positions, and builds a flat render command list (opacity, scissors, draw calls).
- Execution: replays the command list to populate the grid and hit grid.
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.
Types
The type for renderer state. Owns the root renderable, layout tree, screen, and all render pipeline state.
Constructors
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 freshGlyph.Pool.t.width_method: the glyph width computation method. Defaults to theGlyph.width_methoddefault.style: the root node's initial style. Defaults toToffee.Style.default.
Accessors
root t is the root renderable. Build the UI tree under this node.
glyph_pool t is the shared glyph pool for text rendering.
Rendering
render_frame t ~width ~height ~delta builds the next frame.
The pipeline runs in order:
- Runs lifecycle passes (
on_frameand resize hooks). - Runs frame callbacks (see
add_frame_callback). - Computes layout via Toffee.
- Walks the tree: extracts layout and builds the render command list.
- Executes render commands: draws to the grid and populates the hit grid.
- Rechecks hover state against the updated hit grid.
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.
Event dispatch
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:
- Updates pointer state.
- Hit-tests the mouse position.
- Advances the selection state machine (start, update, or finish).
- Tracks hover state and fires
Over/Outevents on target change. - Redirects events to the drag-captured node when active.
- Dispatches with bubbling to the hit-tested node.
- Auto-focuses on left click.
- Clears stale selection if not prevented.
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).
Focus
focused t is the currently focused renderable, if any.
focus t node focuses node and is true iff node is focusable.
Selection
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.
Drag capture
captured t is the renderable currently capturing all mouse events during a drag gesture, if any.
Hover
hover t is the renderable currently under the mouse pointer, if any.
Frame callbacks
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.
Post-processing
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.