API Reference
Tree
waxy.TaffyTree
TaffyTree()
A tree of layout nodes.
with_capacity
staticmethod
Create a new layout tree with pre-allocated capacity.
new_leaf_with_context
Create a new leaf node with the given style and context.
get_node_context
get_node_context(node: NodeId) -> NodeContext | None
Get the context attached to a node, if any.
set_node_context
set_node_context(
node: NodeId, context: NodeContext | None
) -> None
Set or clear the context attached to a node.
new_with_children
Create a new node with children.
insert_child_at_index
Insert a child at a specific index.
set_children
Set the children of a node, replacing any existing children.
remove_child
Remove a specific child from a parent.
remove_child_at_index
Remove a child at a specific index.
replace_child_at_index
Replace the child at a specific index with a new child.
child_at_index
Get the child at a specific index.
clear
clear() -> None
Clear all nodes from the tree.
compute_layout
compute_layout(
node: NodeId,
available: AvailableSize | None = None,
measure: Callable[
[KnownSize, AvailableSize, NodeContext], Size
]
| None = None,
) -> None
Compute the layout of a tree rooted at the given node.
enable_rounding
enable_rounding() -> None
Enable rounding of layout values.
disable_rounding
disable_rounding() -> None
Disable rounding of layout values.
Style
waxy.Style
Style(
*,
display: Display | None = None,
box_sizing: BoxSizing | None = None,
overflow_x: Overflow | None = None,
overflow_y: Overflow | None = None,
scrollbar_width: float | None = None,
position: Position | None = None,
inset_left: DimensionValue | None = None,
inset_right: DimensionValue | None = None,
inset_top: DimensionValue | None = None,
inset_bottom: DimensionValue | None = None,
size_width: DimensionValue | None = None,
size_height: DimensionValue | None = None,
min_size_width: DimensionValue | None = None,
min_size_height: DimensionValue | None = None,
max_size_width: DimensionValue | None = None,
max_size_height: DimensionValue | None = None,
aspect_ratio: float | None = None,
margin_left: DimensionValue | None = None,
margin_right: DimensionValue | None = None,
margin_top: DimensionValue | None = None,
margin_bottom: DimensionValue | None = None,
padding_left: LengthPercentageValue | None = None,
padding_right: LengthPercentageValue | None = None,
padding_top: LengthPercentageValue | None = None,
padding_bottom: LengthPercentageValue | None = None,
border_left: LengthPercentageValue | None = None,
border_right: LengthPercentageValue | None = None,
border_top: LengthPercentageValue | None = None,
border_bottom: LengthPercentageValue | None = None,
align_items: AlignItems | None = None,
align_self: AlignItems | None = None,
justify_items: AlignItems | None = None,
justify_self: AlignItems | None = None,
align_content: AlignContent | None = None,
justify_content: AlignContent | None = None,
gap_width: LengthPercentageValue | None = None,
gap_height: LengthPercentageValue | None = None,
text_align: TextAlign | None = None,
flex_direction: FlexDirection | None = None,
flex_wrap: FlexWrap | None = None,
flex_basis: DimensionValue | None = None,
flex_grow: float | None = None,
flex_shrink: float | None = None,
grid_template_rows: list[GridTrackValue] | None = None,
grid_template_columns: list[GridTrackValue]
| None = None,
grid_auto_rows: list[GridTrackValue] | None = None,
grid_auto_columns: list[GridTrackValue] | None = None,
grid_auto_flow: GridAutoFlow | None = None,
grid_row: GridPlacement | None = None,
grid_column: GridPlacement | None = None,
)
Style properties for a layout node.
All fields are keyword-only. Passing None (or omitting) uses the taffy default. Style is immutable — construct a new instance to change fields, or use | to merge.
See: taffy Style
All arguments are keyword-only. Omitting or passing None for a field uses the taffy default value for that field. See each property for documentation of individual fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display
|
Display | None
|
How the node is laid out (Block, Flex, Grid, or Nil). MDN |
None
|
box_sizing
|
BoxSizing | None
|
Whether size includes border and padding (BorderBox) or not (ContentBox). MDN |
None
|
overflow_x
|
Overflow | None
|
How overflowing content is handled horizontally. MDN |
None
|
overflow_y
|
Overflow | None
|
How overflowing content is handled vertically. MDN |
None
|
scrollbar_width
|
float | None
|
Width of the scrollbar gutter in pixels. MDN |
None
|
position
|
Position | None
|
Whether the node is positioned relative to its parent or absolutely. MDN |
None
|
inset_left
|
DimensionValue | None
|
Left offset for absolutely-positioned nodes. MDN |
None
|
inset_right
|
DimensionValue | None
|
Right offset for absolutely-positioned nodes. MDN |
None
|
inset_top
|
DimensionValue | None
|
Top offset for absolutely-positioned nodes. MDN |
None
|
inset_bottom
|
DimensionValue | None
|
Bottom offset for absolutely-positioned nodes. MDN |
None
|
size_width
|
DimensionValue | None
|
Preferred width of the node. MDN |
None
|
size_height
|
DimensionValue | None
|
Preferred height of the node. MDN |
None
|
min_size_width
|
DimensionValue | None
|
Minimum width of the node. MDN |
None
|
min_size_height
|
DimensionValue | None
|
Minimum height of the node. MDN |
None
|
max_size_width
|
DimensionValue | None
|
Maximum width of the node. MDN |
None
|
max_size_height
|
DimensionValue | None
|
Maximum height of the node. MDN |
None
|
aspect_ratio
|
float | None
|
Preferred aspect ratio (width / height), or None. MDN |
None
|
margin_left
|
DimensionValue | None
|
Left outer spacing. MDN |
None
|
margin_right
|
DimensionValue | None
|
Right outer spacing. MDN |
None
|
margin_top
|
DimensionValue | None
|
Top outer spacing. MDN |
None
|
margin_bottom
|
DimensionValue | None
|
Bottom outer spacing. MDN |
None
|
padding_left
|
LengthPercentageValue | None
|
Left inner spacing. MDN |
None
|
padding_right
|
LengthPercentageValue | None
|
Right inner spacing. MDN |
None
|
padding_top
|
LengthPercentageValue | None
|
Top inner spacing. MDN |
None
|
padding_bottom
|
LengthPercentageValue | None
|
Bottom inner spacing. MDN |
None
|
border_left
|
LengthPercentageValue | None
|
Left border width. MDN |
None
|
border_right
|
LengthPercentageValue | None
|
Right border width. MDN |
None
|
border_top
|
LengthPercentageValue | None
|
Top border width. MDN |
None
|
border_bottom
|
LengthPercentageValue | None
|
Bottom border width. MDN |
None
|
align_items
|
AlignItems | None
|
Default alignment of children along the cross axis. MDN |
None
|
align_self
|
AlignItems | None
|
Override alignment of this node along the parent's cross axis. MDN |
None
|
justify_items
|
AlignItems | None
|
Default alignment of children along the main axis. MDN |
None
|
justify_self
|
AlignItems | None
|
Override alignment of this node along the parent's main axis. MDN |
None
|
align_content
|
AlignContent | None
|
Alignment of rows/columns when there is extra space in the cross axis. MDN |
None
|
justify_content
|
AlignContent | None
|
Distribution of children along the main axis. MDN |
None
|
gap_width
|
LengthPercentageValue | None
|
Horizontal gap between grid/flex items. MDN |
None
|
gap_height
|
LengthPercentageValue | None
|
Vertical gap between grid/flex items. MDN |
None
|
text_align
|
TextAlign | None
|
Text alignment within the node. MDN |
None
|
flex_direction
|
FlexDirection | None
|
Direction of the flex container's main axis. MDN |
None
|
flex_wrap
|
FlexWrap | None
|
Whether flex items wrap onto multiple lines. MDN |
None
|
flex_basis
|
DimensionValue | None
|
Default size of a flex item before growing or shrinking. MDN |
None
|
flex_grow
|
float | None
|
Rate at which a flex item grows to fill available space. MDN |
None
|
flex_shrink
|
float | None
|
Rate at which a flex item shrinks when space is tight. MDN |
None
|
grid_template_rows
|
list[GridTrackValue] | None
|
Explicit row track sizing in a grid container. MDN |
None
|
grid_template_columns
|
list[GridTrackValue] | None
|
Explicit column track sizing in a grid container. MDN |
None
|
grid_auto_rows
|
list[GridTrackValue] | None
|
Sizing of implicitly-created row tracks. MDN |
None
|
grid_auto_columns
|
list[GridTrackValue] | None
|
Sizing of implicitly-created column tracks. MDN |
None
|
grid_auto_flow
|
GridAutoFlow | None
|
How auto-placed items are inserted in the grid. MDN |
None
|
grid_row
|
GridPlacement | None
|
Row placement of this item in a grid container. MDN |
None
|
grid_column
|
GridPlacement | None
|
Column placement of this item in a grid container. MDN |
None
|
box_sizing
property
box_sizing: BoxSizing
Whether size includes border and padding (BorderBox) or not (ContentBox). MDN.
position
property
position: Position
Whether the node is positioned relative to its parent or absolutely. MDN.
inset_bottom
property
inset_bottom: DimensionValue
Bottom offset for absolutely-positioned nodes. MDN.
aspect_ratio
property
aspect_ratio: float | None
Preferred aspect ratio (width / height), or None. MDN.
align_items
property
align_items: AlignItems | None
Default alignment of children along the cross axis. MDN.
align_self
property
align_self: AlignItems | None
Override alignment of this node along the parent's cross axis. MDN.
justify_items
property
justify_items: AlignItems | None
Default alignment of children along the main axis. MDN.
justify_self
property
justify_self: AlignItems | None
Override alignment of this node along the parent's main axis. MDN.
align_content
property
align_content: AlignContent | None
Alignment of rows/columns when there is extra space in the cross axis. MDN.
justify_content
property
justify_content: AlignContent | None
Distribution of children along the main axis. MDN.
flex_direction
property
flex_direction: FlexDirection
Direction of the flex container's main axis. MDN.
flex_basis
property
flex_basis: DimensionValue
Default size of a flex item before growing or shrinking. MDN.
grid_template_rows
property
grid_template_rows: list[GridTrackValue]
Explicit row track sizing in a grid container. MDN.
grid_template_columns
property
grid_template_columns: list[GridTrackValue]
Explicit column track sizing in a grid container. MDN.
grid_auto_rows
property
grid_auto_rows: list[GridTrackValue]
Sizing of implicitly-created row tracks. MDN.
grid_auto_columns
property
grid_auto_columns: list[GridTrackValue]
Sizing of implicitly-created column tracks. MDN.
grid_auto_flow
property
grid_auto_flow: GridAutoFlow
How auto-placed items are inserted in the grid. MDN.
grid_column
property
grid_column: GridPlacement
Column placement of this item in a grid container. MDN.
Layout
waxy.Layout
The computed layout of a node.
The layout uses a border box coordinate system:
locationis the position of this node's border box origin, relative to the parent's border box origin (not the parent's content box, and not absolute/viewport coordinates). This means a child inside a parent with padding or border will have its location offset by the parent's padding + border widths. A child's own margin also offsets its location outward from siblings.sizeis the border box size: it includes border + padding + content, but excludes margin.- To compute absolute positions, accumulate
locationvalues from the root down to the node. - To compute the content box, subtract
borderandpaddingfromsize(or usecontent_box_width()/content_box_height()). - To compute the margin box, expand outward from (
location,size) by themarginwidths.
Note: box_sizing does not affect the Layout output.
It only controls how the style's size_width/size_height inputs are interpreted
(as border box or content box dimensions). The computed Layout.size is always the
border box. For example, with padding_left=10, padding_right=10 and size_width=100:
BorderBox(default): style size is the border box →layout.size.width = 100,content_box_width() = 80ContentBox: style size is the content box →layout.size.width = 120,content_box_width() = 100
order
property
order: int
Topological paint order computed by taffy. Higher values are painted on top.
location
property
location: Point
Position of this node's border box origin, relative to the parent's border box origin.
size
property
size: Size
Border box dimensions (includes border + padding + content, excludes margin).
content_size
property
content_size: Size
Size of the content inside the node (may exceed the border box if overflowing).
content_box_width
content_box_width() -> float
Width of the content box (size minus padding and border).
content_box_height
content_box_height() -> float
Height of the content box (size minus padding and border).
Node
waxy.NodeId
A handle to a node in the layout tree.
Geometry
waxy.Size
A 2D size with width and height.
waxy.Rect
A rectangle with left, right, top, bottom edges.
corners
Return the four corner points (top-left, top-right, bottom-right, bottom-left).
bottom_edge
Iterate over integer pixel locations along the bottom edge.
right_edge
Iterate over integer pixel locations along the right edge.
points
Iterate over all integer pixel locations contained within this rectangle.
rows
Iterate over rows of integer pixel locations.
Each row is an iterator of Points with the same y coordinate.
waxy.Line
waxy.KnownSize
Known dimensions passed to measure functions (independently-optional width/height).
Passed to the measure callback to indicate which dimensions are already known from the node's style. If a dimension is None, the measure function must compute it.
waxy.AvailableSize
AvailableSize(
width: AvailableSpaceValue, height: AvailableSpaceValue
)
Available space for measure functions (width/height: Definite | MinContent | MaxContent).
Passed to the measure callback to indicate how much space is available for layout. Each dimension is one of the available-space variants.
See: taffy Size<AvailableSpace>
Value types
waxy.Length
Length(value: float)
A length value in pixels.
Used for size, padding, border, gap, margin, inset, and grid track sizing fields.
Raises InvalidLength if value is NaN.
See: taffy Dimension::Length,
MDN <length>
waxy.Percent
Percent(value: float)
A percentage value (0.0 to 1.0).
Used for size, padding, border, gap, margin, inset, and grid track sizing fields. Raises InvalidPercent (a subclass of both WaxyException and ValueError) if value is outside the range [0.0, 1.0].
See: taffy Dimension::Percent,
MDN <percentage>
waxy.Auto
Auto()
Automatic sizing or placement.
Used for size, margin, inset, flex-basis, and grid placement fields.
waxy.MinContent
MinContent()
CSS min-content intrinsic sizing.
The smallest size that can fit the item's contents with all soft line-wrapping opportunities taken. Used in available space (measure functions) and grid track sizing.
See: taffy MinTrackSizingFunction::MinContent,
MDN min-content
waxy.MaxContent
MaxContent()
CSS max-content intrinsic sizing.
The smallest size that can fit the item's contents with no soft line-wrapping opportunities taken. Used in available space (measure functions) and grid track sizing.
See: taffy MinTrackSizingFunction::MaxContent,
MDN max-content
waxy.Definite
Definite(value: float)
A definite available space in pixels.
Used only in AvailableSize (measure function input) to represent a concrete pixel measurement of available space.
See: taffy AvailableSpace::Definite
waxy.Fraction
Fraction(value: float)
A fractional unit of remaining grid space (CSS fr unit).
After fixed lengths and percentages are allocated, remaining space is divided among fractional tracks proportionally. For example, Fraction(1) and Fraction(2) in the same grid get 1/3 and 2/3 of remaining space.
Used only in grid track sizing (grid_template_, grid_auto_).
See: taffy MaxTrackSizingFunction::Fraction,
MDN <flex> (fr unit)
waxy.FitContent
CSS fit-content() grid track sizing function.
Grows up to a specified limit, then clamps: max(min_content, min(max_content, limit)). The limit must be a Length or Percent.
Used only in grid track sizing.
See: taffy MaxTrackSizingFunction::FitContent,
MDN fit-content()
waxy.Minmax
Minmax(min: GridTrackMinValue, max: GridTrackMaxValue)
CSS minmax() grid track sizing function.
Defines a size range: min sets the minimum track size, max sets the maximum.
- min: Length | Percent | Auto | MinContent | MaxContent
- max: Length | Percent | Auto | MinContent | MaxContent | Fraction | FitContent
Used only in grid track sizing.
See: taffy TrackSizingFunction,
MDN minmax()
waxy.GridLine
GridLine(index: int)
A 1-based grid line index (negative indices count from the end).
Used in GridPlacement.start and GridPlacement.end.
Raises InvalidGridLine if index is 0
(grid lines are 1-based; negative indices count from the end).
See: taffy GridPlacement::Line,
MDN Line-based placement
waxy.GridSpan
GridSpan(count: int)
Span a number of grid tracks.
Used in GridPlacement.start and GridPlacement.end.
Raises InvalidGridSpan if count is 0 (must span at least 1 track).
See: taffy GridPlacement::Span,
MDN grid-column-start (span)
waxy.GridPlacement
GridPlacement(
start: GridPlacementValue | None = None,
end: GridPlacementValue | None = None,
)
A start/end pair of grid placements for a child item.
Each of start and end is a GridPlacementValue (GridLine | GridSpan | Auto). Defaults both to Auto (the CSS default for unplaced items).
See: taffy Line<GridPlacement>,
MDN grid-row,
MDN grid-column
Type aliases
waxy.DimensionValue
A dimension value used for sizes, margins, insets, and flex-basis: Length, Percent, or Auto.
waxy.LengthPercentageValue
A length-or-percentage value used for padding, border, and gap: Length or Percent.
waxy.GridTrackValue
GridTrackValue = (
Length
| Percent
| Auto
| MinContent
| MaxContent
| Fraction
| Minmax
| FitContent
)
A grid track sizing value used in grid_template_ and grid_auto_ fields.
waxy.GridTrackMinValue
GridTrackMinValue = (
Length | Percent | Auto | MinContent | MaxContent
)
Minimum sizing bound for a Minmax grid track.
waxy.GridTrackMaxValue
GridTrackMaxValue = (
Length
| Percent
| Auto
| MinContent
| MaxContent
| Fraction
| FitContent
)
Maximum sizing bound for a Minmax grid track.
waxy.GridPlacementValue
A grid placement value used in GridPlacement start and end: GridLine, GridSpan, or Auto.
waxy.AvailableSpaceValue
AvailableSpaceValue = Definite | MinContent | MaxContent
Available space value for measure functions: Definite, MinContent, or MaxContent.
Enums
waxy.Display
waxy.Position
waxy.FlexDirection
The direction of a flex container's main axis.
RowReverse
instance-attribute
RowReverse: FlexDirection
Items are laid out in a row in reverse order (right to left).
ColumnReverse
instance-attribute
ColumnReverse: FlexDirection
Items are laid out in a column in reverse order (bottom to top).
waxy.FlexWrap
waxy.AlignItems
Alignment of items along the cross axis.
FlexStart
instance-attribute
FlexStart: AlignItems
Align to the start of the cross axis (respects flex-direction).
FlexEnd
instance-attribute
FlexEnd: AlignItems
Align to the end of the cross axis (respects flex-direction).
waxy.AlignContent
Alignment of content within the container.
FlexStart
instance-attribute
FlexStart: AlignContent
Pack lines to the start of the container (respects flex-direction).
FlexEnd
instance-attribute
FlexEnd: AlignContent
Pack lines to the end of the container (respects flex-direction).
SpaceBetween
instance-attribute
SpaceBetween: AlignContent
Distribute lines evenly; first line at start, last at end.
SpaceEvenly
instance-attribute
SpaceEvenly: AlignContent
Distribute lines with equal space around each line.
SpaceAround
instance-attribute
SpaceAround: AlignContent
Distribute lines with half-size spaces on the edges.
waxy.Overflow
How content overflows its container.
Hidden
instance-attribute
Hidden: Overflow
Content is clipped and hidden; scroll position cannot be changed programmatically.
waxy.GridAutoFlow
How grid items are auto-placed.
RowDense
instance-attribute
RowDense: GridAutoFlow
Place items by filling each row, backfilling gaps.
ColumnDense
instance-attribute
ColumnDense: GridAutoFlow
Place items by filling each column, backfilling gaps.
waxy.BoxSizing
waxy.TextAlign
Exceptions
Exception
├── KeyError
│ └── InvalidNodeId [TaffyException]
├── ValueError
│ ├── InvalidPercent [WaxyException]
│ ├── InvalidLength [WaxyException]
│ ├── InvalidGridLine [WaxyException]
│ └── InvalidGridSpan [WaxyException]
└── WaxyException
├── InvalidPercent [ValueError]
├── InvalidLength [ValueError]
├── InvalidGridLine [ValueError]
├── InvalidGridSpan [ValueError]
└── TaffyException
├── ChildIndexOutOfBounds
├── InvalidParentNode
├── InvalidChildNode
├── InvalidInputNode
└── InvalidNodeId [KeyError]
waxy.WaxyException
Bases: Exception
Base exception for all waxy errors.
waxy.TaffyException
Bases: WaxyException
Base exception for all taffy errors.
waxy.InvalidPercent
Bases: WaxyException, ValueError
Raised when Percent(value) is called with a value outside [0.0, 1.0].
waxy.InvalidLength
Bases: WaxyException, ValueError
Raised when Length(value) is called with a NaN value.
waxy.InvalidGridLine
Bases: WaxyException, ValueError
Raised when GridLine(index) is called with index 0 (grid lines are 1-based).
waxy.InvalidGridSpan
Bases: WaxyException, ValueError
Raised when GridSpan(count) is called with count 0 (must span at least 1 track).
waxy.InvalidNodeId
Bases: TaffyException, KeyError
Raised when a node ID is not valid (node may have been removed).
waxy.ChildIndexOutOfBounds
Bases: TaffyException
Child index is out of bounds.
waxy.InvalidParentNode
Bases: TaffyException
Parent node is invalid.
waxy.InvalidChildNode
Bases: TaffyException
Child node is invalid.
waxy.InvalidInputNode
Bases: TaffyException
Input node is invalid.