Layout

Computed layout result containing position, size, and spacing values for a node.

This class wraps the native [taffy::Layout] and provides read-only access to all computed layout values. All dimensions are in pixels.

Example

const tree = new TaffyTree(); const rootId = tree.newLeaf(new Style()); const node = rootId; tree.computeLayout(rootId, { width: 800, height: 600 }); const layout = tree.getLayout(node); console.log("Position:", layout.x, layout.y); console.log("Size:", layout.width, layout.height); console.log("Content:", layout.contentWidth, layout.contentHeight); console.log( "Padding:", layout.paddingTop, layout.paddingRight, layout.paddingBottom, layout.paddingLeft, ); console.log( "Border:", layout.borderTop, layout.borderRight, layout.borderBottom, layout.borderLeft, ); console.log( "Margin:", layout.marginTop, layout.marginRight, layout.marginBottom, layout.marginLeft, ); console.log("Scrollbar:", layout.scrollbarWidth, layout.scrollbarHeight); console.log("Order:", layout.order);

Properties

PropertyModifierTypeDescription
borderreadonlyanyGets the border as a Rect with left, right, top, bottom border widths Example import { TaffyTree, Style } from "taffy-layout"; const tree = new TaffyTree(); const root = tree.newLeaf(new Style()); tree.computeLayout(root, { width: 100, height: 100 }); const layout = tree.getLayout(root); const border = layout.border; console.log(Border: ${border.left} ${border.right} ${border.top} ${border.bottom}); tree.free();
borderBottomreadonlynumberGets the bottom border width
borderLeftreadonlynumberGets the left border width
borderRightreadonlynumberGets the right border width
borderTopreadonlynumberGets the top border width
contentHeightreadonlynumberGets the height of the scrollable content If the node has overflow content, this represents the total height of all content (may exceed height).
contentSizereadonlyanyGets the content size as a Size with contentWidth and contentHeight If the node has overflow content, this represents the total size of all content (may exceed the node's width/height). Example import { TaffyTree, Style } from "taffy-layout"; const tree = new TaffyTree(); const root = tree.newLeaf(new Style()); tree.computeLayout(root, { width: 100, height: 100 }); const layout = tree.getLayout(root); const contentSize = layout.contentSize; console.log(Content: ${contentSize.width} x ${contentSize.height}); tree.free();
contentWidthreadonlynumberGets the width of the scrollable content If the node has overflow content, this represents the total width of all content (may exceed width).
heightreadonlynumberGets the computed height of the node This is the final height after layout computation, including any constraints from min/max size or flex properties.
marginreadonlyanyGets the margin as a Rect with left, right, top, bottom margins Example import { TaffyTree, Style } from "taffy-layout"; const tree = new TaffyTree(); const root = tree.newLeaf(new Style()); tree.computeLayout(root, { width: 100, height: 100 }); const layout = tree.getLayout(root); const margin = layout.margin; console.log(Margin: ${margin.left} ${margin.right} ${margin.top} ${margin.bottom}); tree.free();
marginBottomreadonlynumberGets the bottom margin
marginLeftreadonlynumberGets the left margin
marginRightreadonlynumberGets the right margin
marginTopreadonlynumberGets the top margin
orderreadonlynumberGets the rendering order of the node This value determines the z-order for overlapping elements. Lower values are rendered first (behind higher values).
paddingreadonlyanyGets the padding as a Rect with left, right, top, bottom padding Example import { TaffyTree, Style } from "taffy-layout"; const tree = new TaffyTree(); const root = tree.newLeaf(new Style()); tree.computeLayout(root, { width: 100, height: 100 }); const layout = tree.getLayout(root); const padding = layout.padding; console.log(Padding: ${padding.left} ${padding.right} ${padding.top} ${padding.bottom}); tree.free();
paddingBottomreadonlynumberGets the bottom padding
paddingLeftreadonlynumberGets the left padding
paddingRightreadonlynumberGets the right padding
paddingTopreadonlynumberGets the top padding
positionreadonlyanyGets the position as a Point with x and y coordinates Example import { TaffyTree, Style } from "taffy-layout"; const tree = new TaffyTree(); const root = tree.newLeaf(new Style()); tree.computeLayout(root, { width: 100, height: 100 }); const layout = tree.getLayout(root); const pos = layout.position; console.log(Position: (${pos.x}, ${pos.y})); tree.free();
scrollbarHeightreadonlynumberGets the height of the horizontal scrollbar When overflow is set to scroll, this indicates the space reserved for the horizontal scrollbar.
scrollbarSizereadonlyanyGets the scrollbar size as a Size with scrollbarWidth and scrollbarHeight When overflow is set to scroll, this indicates the space reserved for scrollbars. Example import { TaffyTree, Style } from "taffy-layout"; const tree = new TaffyTree(); const root = tree.newLeaf(new Style()); tree.computeLayout(root, { width: 100, height: 100 }); const layout = tree.getLayout(root); const scrollbarSize = layout.scrollbarSize; console.log(Scrollbar: ${scrollbarSize.width} x ${scrollbarSize.height}); tree.free();
scrollbarWidthreadonlynumberGets the width of the vertical scrollbar When overflow is set to scroll, this indicates the space reserved for the vertical scrollbar.
sizereadonlyanyGets the size as a Size with width and height Example import { TaffyTree, Style } from "taffy-layout"; const tree = new TaffyTree(); const root = tree.newLeaf(new Style()); tree.computeLayout(root, { width: 100, height: 100 }); const layout = tree.getLayout(root); const size = layout.size; console.log(Size: ${size.width} x ${size.height}); tree.free();
widthreadonlynumberGets the computed width of the node This is the final width after layout computation, including any constraints from min/max size or flex properties.
xreadonlynumberGets the X coordinate of the node's top-left corner This value is relative to the node's parent. For the root node, this is always 0.
yreadonlynumberGets the Y coordinate of the node's top-left corner This value is relative to the node's parent. For the root node, this is always 0.

Methods

[dispose]()

dispose: void;

Returns

void


free()

free(): void;

Returns

void


get()

Call Signature

get<K>(...keys): LayoutPropertyValues[K];

Reads multiple layout properties in a single WASM call. Supports both object properties and individual flat properties.

Type Parameters
Type Parameter
K extends LayoutProperty
Parameters
ParameterType
...keys[K]
Returns

LayoutPropertyValues[K]

Single value for one key, tuple for 2-3 keys, array for 4+ keys

Throws

Error if any property key is unknown.

Remarks
  • Single property: returns exact value type
  • 2-3 properties: returns typed tuple for destructuring
  • 4+ properties: returns array of union types
Example
import { TaffyTree, Style } from "taffy-layout"; const tree = new TaffyTree(); const root = tree.newLeaf(new Style()); tree.computeLayout(root, { width: 100, height: 100 }); const layout = tree.getLayout(root); // Single property - returns exact type const width = layout.get("width"); // number // Two properties - returns tuple for destructuring const [pos, size] = layout.get("position", "size"); // pos: Point<number>, size: Size<number> // Three properties - returns tuple for destructuring const [x, y, w] = layout.get("x", "y", "width"); // Four or more properties - returns array const values = layout.get("x", "y", "width", "height"); // values type is: number[] tree.free();

Call Signature

get<K1, K2>(...keys): [LayoutPropertyValues[K1], LayoutPropertyValues[K2]];
Type Parameters
Type Parameter
K1 extends LayoutProperty
K2 extends LayoutProperty
Parameters
ParameterType
...keys[K1, K2]
Returns

[LayoutPropertyValues[K1], LayoutPropertyValues[K2]]

Call Signature

get<K1, K2, K3>(...keys): [LayoutPropertyValues[K1], LayoutPropertyValues[K2], LayoutPropertyValues[K3]];
Type Parameters
Type Parameter
K1 extends LayoutProperty
K2 extends LayoutProperty
K3 extends LayoutProperty
Parameters
ParameterType
...keys[K1, K2, K3]
Returns

[LayoutPropertyValues[K1], LayoutPropertyValues[K2], LayoutPropertyValues[K3]]

Call Signature

get<Keys>(...keys): LayoutPropertyArrayValues<Keys>;
Type Parameters
Type Parameter
Keys extends LayoutProperty[]
Parameters
ParameterType
...keysKeys
Returns

LayoutPropertyArrayValues<Keys>

© 2026 ByteLand Technology Limited