package toffee

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module TreeSource

Tree abstractions for CSS layout computation.

This module defines signatures and types for layout trees in toffee. Layout algorithms operate on trees by calling trait methods to access children, styles, and storage.

Trait Hierarchy

Traits form a dependency hierarchy enabling different operations:

Layout algorithms require LAYOUT_PARTIAL_TREE. Pixel rounding and debug printing require TRAVERSE_TREE, which extends TRAVERSE_PARTIAL_TREE with a guarantee that child access methods can recurse infinitely.

Layout Flow

Layout proceeds top-down: parents pass Layout_input constraints to children via compute_child_layout, and children return Layout_output with computed sizes and margins. Algorithms read styles via get_core_container_style and store results via set_unrounded_layout.

Core Types

Sourcemodule Node_id : sig ... end

Unique identifier for nodes in a layout tree.

Sourcemodule Run_mode : sig ... end

Layout computation mode.

Sourcemodule Sizing_mode : sig ... end

Sizing mode for layout computation.

Sourcemodule Collapsible_margin_set : sig ... end

Collapsible margin tracking for CSS Block layout.

Sourcemodule Requested_axis : sig ... end

Axis that layout algorithms can be requested to compute a size for.

Sourcemodule Available_space : sig ... end

Available space constraints for layout computation.

Sourcemodule Layout_input : sig ... end

Layout input constraints passed from parent to child during layout computation.

Sourcemodule Layout_output : sig ... end

Layout algorithm output for a single node.

Sourcemodule Layout : sig ... end

Final computed layout for a single node.

Sourcemodule Cache : sig ... end

Layout computation result caching.

Tree Signatures

Sourcemodule type TRAVERSE_PARTIAL_TREE = sig ... end

Tree traversal for immediate children.

Sourcemodule type TRAVERSE_TREE = sig ... end

Tree traversal with full recursive access.

Sourcemodule type LAYOUT_PARTIAL_TREE = sig ... end

Tree interface for layout algorithms.

Sourcemodule type CACHE_TREE = sig ... end

Tree interface for layout caching.

Sourcemodule type ROUND_TREE = sig ... end

Tree interface for pixel rounding.

Sourcemodule type PRINT_TREE = sig ... end

Tree interface for debug printing.

Tree Functions

Sourceval print_tree : (module PRINT_TREE with type t = 'a) -> 'a -> Node_id.t -> unit

print_tree (module Tree) tree root prints a debug representation of the layout tree rooted at root to stdout.

Output format:

TREE
└── Flex [x: 0 y: 0 w: 800 h: 600 content_w: 780 content_h: 580 ...] (Node 0)
    ├── Block [x: 10 y: 10 w: 200 h: 100 ...] (Node 1)
    └── Text [x: 10 y: 120 w: 150 h: 20 ...] (Node 2)

Each line shows the node's label, location, size, content_size, border, padding, and node ID. Children are indented with tree drawing characters.