package toffee
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9e4e90d17f9b2af1b07071fe425bc2c519c849c4f1d1ab73cde512be2d874849
sha512=06e9c4a741590942e81a27738d0b5c0413fafec8cf3b7dae047ad69f155e7b718aa4223818dc161b7d028efffcfd3365905e264d6fd31d453910ddfa91dcf9b9
doc/toffee.tree/Tree/Layout_output/index.html
Module Tree.Layout_outputSource
Layout algorithm output for a single node.
Overview
Layout output represents the result of computing layout for a single node. It contains the node's outer size, content size, baseline positions, and margin collapsing data for CSS block layout. Layout algorithms return this structure to their parent nodes during the layout computation phase.
Key Concepts
Outer Size vs Content Size
The size field represents the node's outer dimensions including padding and borders. The content_size field represents the dimensions of content within the node, which may exceed size when content overflows. This distinction enables computation of scroll dimensions for scrollable containers.
Baselines
Baselines indicate the line on which text sits, used for aligning inline content and flex items. Text nodes and nodes containing text descendants typically have baselines. For nodes without baselines, use Geometry.(Point.none) for the first_baselines field.
Margin Collapsing
Margin collapsing is specific to CSS block layout, where adjacent vertical margins collapse according to CSS rules. The top_margin, bottom_margin, and margins_can_collapse_through fields track collapsible margins during block layout computation.
For layout modes that do not support margin collapsing (flexbox, grid), set top_margin and bottom_margin to Collapsible_margin_set.zero and margins_can_collapse_through to false.
type t = {size : float Geometry.size;(*The computed outer size of the node's box.
*)content_size : float Geometry.size;(*The size of the content within the node.
This may exceed
*)sizewhen content overflows, enabling computation of scroll dimensions for scrollable containers.first_baselines : float option Geometry.point;(*The first baseline in each dimension, if any.
Use
*)Geometry.(Point.none ())for nodes without baselines.top_margin : Collapsible_margin_set.t;(*Top margin available for collapsing in CSS block layout.
Set to
*)Collapsible_margin_set.zerofor non-block layout modes.bottom_margin : Collapsible_margin_set.t;(*Bottom margin available for collapsing in CSS block layout.
Set to
*)Collapsible_margin_set.zerofor non-block layout modes.margins_can_collapse_through : bool;(*Whether margins can collapse through this node in CSS block layout.
Set to
*)falsefor non-block layout modes.
}val make :
size:float Geometry.size ->
content_size:float Geometry.size ->
first_baselines:float option Geometry.point ->
top_margin:Collapsible_margin_set.t ->
bottom_margin:Collapsible_margin_set.t ->
margins_can_collapse_through:bool ->
tmake ~size ~content_size ~first_baselines ~top_margin ~bottom_margin ~margins_can_collapse_through creates a layout output with all fields specified.
Use this constructor for CSS block layout where margin collapsing is relevant. For flexbox and grid layouts, prefer from_sizes_and_baselines which sets margins to zero automatically.
size t returns the outer size of t.
content_size t returns the content size of t.
first_baselines t returns the first baselines of t.
top_margin t returns the top collapsible margin set of t.
bottom_margin t returns the bottom collapsible margin set of t.
margins_can_collapse_through t returns whether margins can collapse through t.
hidden is a zero-sized layout output for nodes with Display.None.
All sizes are zero (size and content_size), baselines are None, top and bottom margins are zero, and margins cannot collapse through. Use this when a node is hidden and should not contribute to layout.
default is a zero-sized default layout output.
Identical to hidden. Provided as a convenient default value.
from_outer_size size creates a layout output from just the outer size.
Sets size to the provided value and content_size to zero. Use this when short-circuiting layout computation after determining the container's outer dimensions but before computing content layout. Baselines are None, margins are zero, and margins cannot collapse through.
val from_sizes_and_baselines :
float Geometry.size ->
float Geometry.size ->
float option Geometry.point ->
tfrom_sizes_and_baselines size content_size first_baselines creates a layout output from sizes and baselines.
Use this for flexbox and grid layouts after computing both outer size and content size. The content_size should reflect the actual dimensions of content within the node, which may differ from size when content overflows or when the container is larger than its content.
Margins are set to zero and margins cannot collapse through, as flexbox and grid do not support margin collapsing.
to_string t converts t to a string representation showing size, content_size, and margins_can_collapse_through.
compare a b compares layout outputs a and b lexicographically.
Comparison order: size, content_size, first_baselines, top_margin, bottom_margin, margins_can_collapse_through.
pp fmt t prints t to formatter fmt using to_string.