Skip to main content

Module compute

Module compute 

Source
Expand description

Low-level access to the layout algorithms themselves. For a higher-level API, see the TaffyTree struct.

§Layout functions

The layout functions all take an &mut impl LayoutPartialTree parameter, which represents a single container node and it’s direct children.

FunctionPurpose
[compute_flexbox_layout]Layout a Flexbox container and it’s direct children
compute_grid_layoutLayout a CSS Grid container and it’s direct children
[compute_block_layout]Layout a Block container and it’s direct children
compute_leaf_layoutApplies common properties like padding/border/aspect-ratio to a node before deferring to a passed closure to determine it’s size. Can be applied to nodes like text or image nodes.
compute_root_layoutLayout the root node of a tree (regardless of it’s layout mode). This function is typically called once to begin a layout run.
compute_hidden_layoutMark a node as hidden during layout (like Display::None)
compute_cached_layoutAttempts to find a cached layout for the specified node and layout inputs. Uses the provided closure to compute the layout (and then stores the result in the cache) if no cached layout is found.

§Other functions

FunctionRequiresPurpose
round_layoutRoundTreeRound a tree of float-valued layouts to integer pixels
print_treePrintTreePrint a debug representation of a node tree and it’s computed layout

Modules§

common 🔒
Generic code that is shared between multiple layout algorithms
detailed_info
A module for unified re-exports of detailed layout info structs, used by low level API
grid 🔒
This module is a partial implementation of the CSS Grid Level 1 specification https://www.w3.org/TR/css-grid-1
leaf 🔒
Computes size using styles and measure functions
oof 🔒
Shared positioning pass for out-of-flow (position: absolute / position: fixed) boxes.

Structs§

OofLayoutResult
The result of laying out out-of-flow candidates against an explicit positioning area.

Functions§

compute_cached_layout
Attempts to find a cached layout for the specified node and layout inputs.
compute_grid_layout
Grid layout algorithm This consists of a few phases:
compute_hidden_layout
Creates a layout for this node and its children, recursively. Each hidden node has zero size and is placed at the origin
compute_in_flow_root_layout 🔒
Lay out an in-flow (or position: relative) root node against the available space, store its layout and return it along with the out-of-flow candidates bubbled up from its subtree.
compute_leaf_layout
Compute the size of a leaf node (node with no children)
compute_oof_layout
Run the out-of-flow positioning pass for node_id after its layout algorithm has produced output: lay out the out-of-flow candidates in output.oof_candidates for which the node is the containing block, record them as the node’s hoisted children, and replace output.oof_candidates with the unclaimed remainder (which bubble further up the tree). The scrollable overflow contributed by the claimed boxes is merged into output.scrollable_overflow_rect.
compute_oof_layout_for_area
Lay out out-of-flow candidates against an explicit positioning area.
compute_root_layout
Compute layout for the root node in the tree
resolve_static_offset
Resolve the final static offset of an out-of-flow box from its static position, given the box’s final size and resolved margins.
round_layout
Rounds the calculated layout to exact pixel values