package mosaic

  1. Overview
  2. Docs

Module Renderable.PrivateSource

Context

Sourcetype context = {
  1. tree : unit Toffee.tree;
  2. schedule : unit -> unit;
  3. focus : t -> bool;
  4. blur : t -> unit;
  5. register_lifecycle : t -> unit;
  6. unregister_lifecycle : t -> unit;
  7. alloc_num : unit -> int;
  8. register : t -> unit;
  9. unregister : t -> unit;
}

The type for renderer callbacks inherited by all nodes in a tree.

Root construction

Sourceval create_root : context -> ?id:string -> ?style:Toffee.Style.t -> ?glyph_pool:Glyph.Pool.t -> unit -> t

create_root ctx () is a new root node backed by ctx's layout tree.

Optional parameters:

  • id: identifier string. Defaults to "node-N".
  • style: flexbox style. Defaults to Toffee.Style.default.
  • glyph_pool: glyph pool for text rendering. Defaults to none.

Identity

Sourceval num : t -> int

num t is t's numeric identifier, unique within the renderer.

Sourceval toffee_node : t -> Toffee.Node_id.t

toffee_node t is t's layout node identifier.

Sourceval set_is_root : t -> bool -> unit

set_is_root t v marks or unmarks t as a root node.

Layout cache

Sourceval layout_dirty : t -> bool

layout_dirty t is true iff t needs re-layout.

Sourceval clear_layout_dirty : t -> unit

clear_layout_dirty t clears t's layout dirty flag.

Sourceval update_layout : t -> x:float -> y:float -> width:float -> height:float -> unit

update_layout t ~x ~y ~width ~height caches layout results for t, enabling O(1) queries via x, y, width, and height.

Sourceval measure : t -> measure option

measure t is t's measure function, if any.

Render pipeline

Sourceval pre_render_update : t -> delta:float -> unit

pre_render_update t ~delta runs t's on-frame and resize hooks.

Sourceval render : t -> Grid.t -> delta:float -> unit

render t grid ~delta invokes t's render callback.

Sourceval render_before : t -> render option

render_before t is t's pre-render hook, if any.

Sourceval render_after : t -> render option

render_after t is t's post-render hook, if any.

Sourceval ensure_frame_buffer : t -> parent:Grid.t -> Grid.t option

ensure_frame_buffer t ~parent is Some buf if t uses buffered rendering and has positive dimensions, None otherwise.

Sourceval blit_frame_buffer : t -> dst:Grid.t -> unit

blit_frame_buffer t ~dst copies t's frame buffer into dst.

Sourceval render_full : t -> grid:Grid.t -> delta:float -> unit

render_full t ~grid ~delta runs the complete render sequence for t: frame buffer selection, pre-render hook, render callback, post-render hook, and frame buffer blit.

Children

Sourceval children_z : t -> t array

children_z t is t's children sorted by z-index. The result is cached.

Sourceval iter_children_z : t -> (t -> unit) -> unit

iter_children_z t f applies f to each child of t in z-index order.

Sourceval children_in_viewport : parent:t -> viewport:Grid.region -> padding:int -> t list

children_in_viewport ~parent ~viewport ~padding is the children of parent whose bounds intersect viewport expanded by padding cells, sorted by z-index.

Focus

Sourceval focus_direct : t -> bool

focus_direct t focuses t without delegating to the renderer. Returns false if t is not focusable.

Sourceval blur_direct : t -> unit

blur_direct t blurs t without delegating to the renderer.

Lifecycle

Sourceval live_count : t -> int

live_count t is the total number of live-rendering nodes in t's subtree, including t itself.

Sourceval set_on_live_count_change : t -> (t -> unit) option -> unit

set_on_live_count_change t cb registers an observer called when live_count t changes. None clears it.

Sourceval set_lifecycle_pass : t -> (t -> unit) option -> unit

set_lifecycle_pass t callback registers a lifecycle pass hook for t. None clears it.

Sourceval run_lifecycle_pass : t -> unit

run_lifecycle_pass t invokes t's lifecycle callback, if any.

Event emission

Sourceval emit_mouse : t -> Event.mouse -> unit

emit_mouse t event dispatches event to t's mouse handlers, bubbling to ancestors unless propagation is stopped via Event.Mouse.stop_propagation.

Sourceval emit_key : t -> Event.key -> unit

emit_key t event dispatches event to t's key handlers.

Sourceval emit_default_key : t -> Event.key -> unit

emit_default_key t event dispatches event to t's default key handler, if any.

Sourceval emit_paste : t -> Event.paste -> unit

emit_paste t event dispatches event to t's paste handler, if any.

Selection

Sourceval emit_selection_changed : t -> Selection.t option -> bool

emit_selection_changed t sel notifies t's selection on_change callback with sel. Returns false if no callback is registered.

Sourceval clear_selection : t -> unit

clear_selection t calls t's selection clear callback, if any.

Sourceval should_start_selection : t -> x:int -> y:int -> bool

should_start_selection t ~x ~y is true iff t's should_start callback returns true for (x, y). Returns false if no callback is registered.

Sourceval get_selected_text : t -> string

get_selected_text t calls t's get_text callback and returns the result, or "" if no callback is registered.

Child clipping

Sourceval child_clip : t -> Grid.region option

child_clip t is the clipping rectangle for t's children as returned by t's clip override, or None if no override is set.

Glyph pool

Sourceval set_glyph_pool : t -> Glyph.Pool.t -> unit

set_glyph_pool t pool assigns a glyph pool for text rendering by t and its descendants.

Sourceval glyph_pool : t -> Glyph.Pool.t option

glyph_pool t is t's glyph pool, or None if none is assigned.