package toffee

Build not yet checked
  1. Overview
  2. Docs
CSS layout engine for OCaml (Flexbox, Grid, Block)

Install

dune-project
 Dependency

Authors

Maintainers

Sources

mosaic-0.3.0.tbz
sha256=a92cbbcbe016fb19fb0a749222da0e459a9567aef3f4c7340d9bd6b71c53ed6f
sha512=6a7ab054605538bb31a2b73a1a6d093981a2704c9f0af5852221c05735290d74aca7c7282298c4d0f91e86a800e2ccd94b4918af883cd963449c758eb6b272b3

doc/toffee.tree/Toffee_tree/Layout/index.html

Module Toffee_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 scrollable_overflow field is the area the content reaches, relative to the padding box; it exceeds the box when content overflows, which gives the scroll extents.

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

Sourcetype t = {
  1. 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.

    *)
  2. location : Toffee_geometry.Pointf.t;
    (*

    Top-left corner of the margin box relative to the parent's content box.

    *)
  3. size : Toffee_geometry.Sizef.t;
    (*

    Width and height of the border box (includes padding and border, but not margin).

    *)
  4. scrollable_overflow : Scrollable_overflow.t;
    (*

    The area the node's content reaches, relative to its padding box, with its scroll origins. Exceeds the box when content overflows; see Scrollable_overflow.

    *)
  5. scrollbar_size : Toffee_geometry.Sizef.t;
    (*

    Size of scrollbars in each dimension. Zero when no scrollbar is present.

    *)
  6. border : Toffee_geometry.Rectf.t;
    (*

    Border widths on each edge.

    *)
  7. padding : Toffee_geometry.Rectf.t;
    (*

    Padding on each edge.

    *)
  8. margin : Toffee_geometry.Rectf.t;
    (*

    Margin on each edge.

    *)
}

t represents the complete layout state for a node after layout computation.

Construction

Sourceval make : order:int -> location:Toffee_geometry.Pointf.t -> size:Toffee_geometry.Sizef.t -> scrollable_overflow:Scrollable_overflow.t -> scrollbar_size:Toffee_geometry.Sizef.t -> border:Toffee_geometry.Rectf.t -> padding:Toffee_geometry.Rectf.t -> margin:Toffee_geometry.Rectf.t -> t

make ~order ~location ~size ~scrollable_overflow ~scrollbar_size ~border ~padding ~margin creates a layout with all fields specified.

Sourceval default : t

default is a zero layout with all dimensions and spacing set to zero and order set to 0.

Sourceval with_order : int -> t

with_order order creates a zero layout with the specified order value. All other fields are set to zero.

Field Accessors

Sourceval order : t -> int

order layout returns the rendering order.

location layout returns the top-left corner position.

size layout returns the border box dimensions.

Sourceval scrollable_overflow : t -> Scrollable_overflow.t

scrollable_overflow layout returns the scrollable overflow area.

Sourceval scrollbar_size : t -> Toffee_geometry.Sizef.t

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

Sourceval content_box_width : t -> float

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.

Sourceval content_box_height : t -> float

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.

Sourceval content_box_size : t -> Toffee_geometry.Sizef.t

content_box_size layout computes the content box dimensions.

Equivalent to {width = content_box_width layout; height = content_box_height layout}.

Sourceval content_box_x : t -> float

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.

Sourceval content_box_y : t -> float

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

Sourceval scroll_width : t -> float

scroll_width layout computes the horizontal scroll extent.

Returns how far the content can be scrolled horizontally: the extent of the scrollable overflow past the padding box less the scrollbar (its client box), never negative. Returns 0.0 when the content fits. With a reversed horizontal scroll origin, the content extends left of the origin instead, and the extent is how far.

Sourceval scroll_height : t -> float

scroll_height layout computes the vertical scroll extent.

Returns how far the content can be scrolled vertically, as scroll_width does horizontally.

Comparison and Formatting

Sourceval compare : t -> t -> int

compare a b compares layouts lexicographically.

Fields are compared in order: order, location, size, scrollable_overflow, scrollbar_size, border, padding, margin.

Sourceval equal : t -> t -> bool

equal a b tests whether two layouts are structurally equal.

Sourceval to_string : t -> string

to_string layout converts layout to a string representation showing order, location, size, and scrollable_overflow.

Sourceval pp : Format.formatter -> t -> unit

pp fmt layout formats layout for printing.