package toffee
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9e4e90d17f9b2af1b07071fe425bc2c519c849c4f1d1ab73cde512be2d874849
sha512=06e9c4a741590942e81a27738d0b5c0413fafec8cf3b7dae047ad69f155e7b718aa4223818dc161b7d028efffcfd3365905e264d6fd31d453910ddfa91dcf9b9
doc/toffee.tree/Tree/Layout/index.html
Module Tree.LayoutSource
Final computed layout for a single node.
Layout represents the output of a layout algorithm, containing all spatial and box model information needed to render a node. This includes the node's position, dimensions, spacing properties (border, padding, margin), and rendering order.
Box Model
CSS layout uses a nested box model where each node has multiple boxes:
- Margin box: outermost, transparent spacing around the border
- Border box: contains the border, padding, and content
- Padding box: spacing between border and content
- Content box: innermost, holds the actual content
The size field represents the border box dimensions. Use content_box_size to compute the content box dimensions. The content_size field may exceed size when content overflows, which is important for computing scroll dimensions.
Coordinate System
The location field specifies the top-left corner of the node's margin box relative to its parent's content box origin. This is the primary positioning coordinate. To compute other box positions, use content_box_x and content_box_y which add the appropriate spacing offsets.
Type
type t = {order : int;(*Rendering order for layering. Nodes with higher order values render on top of nodes with lower values. This implements a topological sort of the tree.
*)location : float Geometry.point;(*Top-left corner of the margin box relative to the parent's content box.
*)size : float Geometry.size;(*Width and height of the border box (includes padding and border, but not margin).
*)content_size : float Geometry.size;(*Width and height of the content inside the node. May exceed
*)sizewhen content overflows, useful for computing scroll dimensions.scrollbar_size : float Geometry.size;(*Size of scrollbars in each dimension. Zero when no scrollbar is present.
*)border : float Geometry.rect;(*Border widths on each edge.
*)padding : float Geometry.rect;(*Padding on each edge.
*)margin : float Geometry.rect;(*Margin on each edge.
*)
}t represents the complete layout state for a node after layout computation.
Construction
val make :
order:int ->
location:float Geometry.point ->
size:float Geometry.size ->
content_size:float Geometry.size ->
scrollbar_size:float Geometry.size ->
border:float Geometry.rect ->
padding:float Geometry.rect ->
margin:float Geometry.rect ->
tmake ~order ~location ~size ~content_size ~scrollbar_size ~border ~padding ~margin creates a layout with all fields specified.
default is a zero layout with all dimensions and spacing set to zero and order set to 0.
with_order order creates a zero layout with the specified order value. All other fields are set to zero.
Field Accessors
location layout returns the top-left corner position.
size layout returns the border box dimensions.
content_size layout returns the content dimensions.
scrollbar_size layout returns the scrollbar dimensions.
border layout returns the border widths.
padding layout returns the padding.
margin layout returns the margin.
Content Box Dimensions
content_box_width layout computes the width of the content box.
This is the border box width minus horizontal padding and border: size.width - padding.left - padding.right - border.left - border.right.
content_box_height layout computes the height of the content box.
This is the border box height minus vertical padding and border: size.height - padding.top - padding.bottom - border.top - border.bottom.
content_box_size layout computes the content box dimensions.
Equivalent to {width = content_box_width layout; height = content_box_height layout}.
content_box_x layout computes the x offset of the content box relative to the parent's content box.
This is location.x + margin.left + border.left + padding.left.
content_box_y layout computes the y offset of the content box relative to the parent's content box.
This is location.y + margin.top + border.top + padding.top.
Scroll Dimensions
scroll_width layout computes the horizontal scroll extent.
Returns the amount by which content overflows horizontally, accounting for scrollbar width. Result is always non-negative. Returns 0.0 when content fits within the border box.
Formula: max 0.0 (content_size.width + min scrollbar_size.width size.width - size.width + border.right).
scroll_height layout computes the vertical scroll extent.
Returns the amount by which content overflows vertically, accounting for scrollbar height. Result is always non-negative. Returns 0.0 when content fits within the border box.
Formula: max 0.0 (content_size.height + min scrollbar_size.height size.height - size.height + border.bottom).
Comparison and Formatting
compare a b compares layouts lexicographically.
Fields are compared in order: order, location, size, content_size, scrollbar_size, border, padding, margin.
to_string layout converts layout to a string representation showing order, location, size, and content_size.
pp fmt layout formats layout for printing.