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.
remove_children_range
Detach the children at indices start (inclusive) to end (exclusive) from a parent.
The children stay in the tree, without a parent. Raises ChildIndexOutOfBounds if
the range is not within the parent's children.
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.
set_style
Set the style of a node.
Marks the node dirty only if the new style's values differ from the stored style's
(which fields were explicitly set doesn't matter here), so setting an equal style keeps
the node's cached layout. Call mark_dirty to force a relayout.
style
Get the style of a node.
taffy doesn't store which fields were explicitly set, so every field of the returned
style is marked set. It compares equal to the style passed to set_style only if that
style set every field.
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.
measure is called for leaves with a context to size their content. It must return the
same size for the same inputs within one call: repeated inputs for the same node are
answered from the earlier result without calling measure again.
absolute_layouts
Every visible node in the subtree under root, in pre-order, with its absolute position.
A node with display=Display.Nil is left out along with its whole subtree,
since taffy gives those nodes no box, only a zero size at their parent's origin.
If root or one of its ancestors is hidden, the list is empty.
layout(node) still returns a hidden node's zero layout.
The position is relative to the top of the tree (the ancestor with no parent):
the sum of the node's own and all its ancestors' locations. Each Layout is the same as
layout(node) returns, so its location stays relative to the node's parent.
Like layout, this follows the tree's rounding setting. With rounding enabled, the
position is the sum of the unrounded locations, rounded once, which is where taffy's
rounded size assumes the node starts. In taffy 0.14, summing the rounded locations
instead can be off by a pixel, since it rounds each location relative to its parent
(taffy#834).
detailed_layout_info
detailed_layout_info(
node: NodeId,
) -> DetailedGridInfo | None
Get detailed grid layout information for a node.
Returns None if the node is not a grid container or has not been laid out.
enable_rounding
enable_rounding() -> None
Enable rounding of layout values.
disable_rounding
disable_rounding() -> None
Disable rounding of layout values.
format_tree
An indented dump of the subtree rooted at root, one line per node, for debugging.
Each line gives the node's id, its computed location and size, and the style fields
that differ from taffy's defaults. Unlike print_tree, it returns the string rather
than writing to stdout.
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,
direction: Direction | None = None,
contain: Contain | None = None,
float: Float | None = None,
clear: Clear | None = None,
item_is_table: bool | None = None,
item_is_replaced: bool | None = None,
inset_left: LengthPercentageAutoValue | None = None,
inset_right: LengthPercentageAutoValue | None = None,
inset_top: LengthPercentageAutoValue | None = None,
inset_bottom: LengthPercentageAutoValue | None = None,
size_width: DimensionValue | None = None,
size_height: DimensionValue | None = None,
min_size_width: LengthPercentageAutoValue | None = None,
min_size_height: LengthPercentageAutoValue
| None = None,
max_size_width: LengthPercentageAutoValue | None = None,
max_size_height: LengthPercentageAutoValue
| None = None,
aspect_ratio: float | None = None,
margin_left: LengthPercentageAutoValue | None = None,
margin_right: LengthPercentageAutoValue | None = None,
margin_top: LengthPercentageAutoValue | None = None,
margin_bottom: LengthPercentageAutoValue | 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: FlexBasisValue | None = None,
flex_grow: float | None = None,
flex_shrink: float | None = None,
flex_line_count: int | None = None,
grid_template_rows: list[GridTemplateValue]
| None = None,
grid_template_columns: list[GridTemplateValue]
| None = None,
grid_template_row_names: list[list[str]] | None = None,
grid_template_column_names: list[list[str]]
| None = None,
grid_template_areas: GridTemplateAreas | 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.
A style remembers which fields were explicitly set (see fields_set), and a | b takes
each field set in b from b and every other field from a. Two styles are equal only if
they hold the same values and set the same fields, since otherwise they would merge
differently: Style() != Style(display=Display.Flex), though Flex is the default.
See: taffy Style
All arguments are keyword-only. Omitting or passing None for a field uses
the taffy default value for that field, except align_*/justify_* and
grid_template_areas, where None explicitly clears the field. See each property for
documentation of individual fields.
Raises TypeError for an unknown keyword or a value of the wrong type, and
InvalidFlexLineCount if flex_line_count is 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display
|
Display | None
|
How the node is laid out (Block, FlowRoot, 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
|
direction
|
Direction | None
|
Inline direction of the node's content (Ltr or Rtl). MDN |
None
|
contain
|
Contain | None
|
Layout and/or paint containment. MDN |
None
|
float
|
Float | None
|
Which side the node floats to within a block container. MDN |
None
|
clear
|
Clear | None
|
Which preceding floats the node is moved below. MDN |
None
|
item_is_table
|
bool | None
|
Whether the node is a table, which block layout sizes differently. |
None
|
item_is_replaced
|
bool | None
|
Whether the node is a replaced element (like an image). MDN |
None
|
inset_left
|
LengthPercentageAutoValue | None
|
Left offset for absolutely-positioned nodes. MDN |
None
|
inset_right
|
LengthPercentageAutoValue | None
|
Right offset for absolutely-positioned nodes. MDN |
None
|
inset_top
|
LengthPercentageAutoValue | None
|
Top offset for absolutely-positioned nodes. MDN |
None
|
inset_bottom
|
LengthPercentageAutoValue | 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
|
LengthPercentageAutoValue | None
|
Minimum width of the node. MDN |
None
|
min_size_height
|
LengthPercentageAutoValue | None
|
Minimum height of the node. MDN |
None
|
max_size_width
|
LengthPercentageAutoValue | None
|
Maximum width of the node. MDN |
None
|
max_size_height
|
LengthPercentageAutoValue | None
|
Maximum height of the node. MDN |
None
|
aspect_ratio
|
float | None
|
Preferred aspect ratio (width / height), or None. MDN |
None
|
margin_left
|
LengthPercentageAutoValue | None
|
Left outer spacing. MDN |
None
|
margin_right
|
LengthPercentageAutoValue | None
|
Right outer spacing. MDN |
None
|
margin_top
|
LengthPercentageAutoValue | None
|
Top outer spacing. MDN |
None
|
margin_bottom
|
LengthPercentageAutoValue | 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
|
FlexBasisValue | 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
|
flex_line_count
|
int | None
|
Minimum number of lines in a multi-line flex container (at least 1). CSS |
None
|
grid_template_rows
|
list[GridTemplateValue] | None
|
Explicit row track sizing in a grid container. MDN |
None
|
grid_template_columns
|
list[GridTemplateValue] | None
|
Explicit column track sizing in a grid container. MDN |
None
|
grid_template_row_names
|
list[list[str]] | None
|
Names of the lines between rows. MDN |
None
|
grid_template_column_names
|
list[list[str]] | None
|
Names of the lines between columns. MDN |
None
|
grid_template_areas
|
GridTemplateAreas | None
|
Named areas of the grid template. 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
|
display
property
display: Display
How the node is laid out (Block, FlowRoot, Flex, Grid, or Nil). MDN.
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.
item_is_table
property
item_is_table: bool
Whether the node is a table, which block layout sizes differently.
item_is_replaced
property
item_is_replaced: bool
Whether the node is a replaced element (like an image). MDN.
inset_left
property
inset_left: LengthPercentageAutoValue
Left offset for absolutely-positioned nodes. MDN.
inset_right
property
inset_right: LengthPercentageAutoValue
Right offset for absolutely-positioned nodes. MDN.
inset_top
property
inset_top: LengthPercentageAutoValue
Top offset for absolutely-positioned nodes. MDN.
inset_bottom
property
inset_bottom: LengthPercentageAutoValue
Bottom offset for absolutely-positioned nodes. MDN.
min_size_height
property
min_size_height: LengthPercentageAutoValue
Minimum height of the node. MDN.
max_size_height
property
max_size_height: LengthPercentageAutoValue
Maximum height of the node. 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: FlexBasisValue
Default size of a flex item before growing or shrinking. MDN.
flex_line_count
property
flex_line_count: int
Minimum number of lines in a multi-line flex container (at least 1). CSS.
grid_template_rows
property
grid_template_rows: list[GridTemplateValue]
Explicit row track sizing in a grid container. MDN.
grid_template_columns
property
grid_template_columns: list[GridTemplateValue]
Explicit column track sizing in a grid container. MDN.
grid_template_row_names
property
Names of the lines between rows, positional with grid_template_rows.
Entry i names the line before grid_template_rows[i] (a Repeat counts as one
entry), and one final entry names the line after the last row.
MDN.
grid_template_column_names
property
Names of the lines between columns, positional with grid_template_columns.
Entry i names the line before grid_template_columns[i] (a Repeat counts as one
entry), and one final entry names the line after the last column.
MDN.
grid_template_areas
property
grid_template_areas: GridTemplateAreas | None
Named areas of the grid template. 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).
scrollable_overflow_rect
property
scrollable_overflow_rect: Rect
The extent of the node's scrollable overflow, relative to its padding box origin.
left/top are <= 0 (overflow before the scroll origin, which scrolling can't
reach) and right/bottom are >= 0 (the reachable extent of the content).
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).
content_box_size
content_box_size() -> Size
Size of the content box (size minus padding and border).
content_box_x
content_box_x() -> float
X offset of the content box, relative to the parent's border box origin.
content_box_y
content_box_y() -> float
Y offset of the content box, relative to the parent's border box origin.
scroll_width
scroll_width() -> float
The maximum horizontal scroll offset of the node (0 if its content doesn't overflow).
scroll_height
scroll_height() -> float
The maximum vertical scroll offset of the node (0 if its content doesn't overflow).
waxy.DetailedGridInfo
Detailed results of laying out a grid container: its tracks and item placements.
Returned by TaffyTree.detailed_layout_info for grid containers.
items
property
items: list[DetailedGridItemInfo]
The placement of each in-flow grid item.
Absolutely positioned and display: Nil children are not grid items.
grid_template_rows
grid_template_rows() -> str
The used row sizes and line names, as a CSS grid-template-rows resolved value.
For example, "[header-start] 20px [header-end] 30px".
grid_template_columns
grid_template_columns() -> str
The used column sizes and line names, as a CSS grid-template-columns resolved value.
item_grid_area
The location and size of the grid area occupied by the item at item_index.
item_index indexes items. The location is relative to the container's border box,
and the area excludes surrounding gaps. Raises IndexError if item_index is out of
range.
resolve_absolute_grid_area
resolve_absolute_grid_area(
grid_row: GridPlacement,
grid_column: GridPlacement,
direction: Direction,
padding_box: Rect,
) -> Rect
Resolve the grid area for an absolutely positioned box from its grid placement.
padding_box and the returned area are relative to the grid container's border box.
waxy.DetailedGridTracksInfo
The computed tracks of one axis (rows or columns) of a grid container.
Tracks are indexed over the full grid: leading implicit tracks, then explicit tracks,
then trailing implicit tracks. Line i bounds the start of track i.
negative_implicit_tracks
property
negative_implicit_tracks: int
Number of implicit tracks before the explicit grid.
positive_implicit_tracks
property
positive_implicit_tracks: int
Number of implicit tracks after the explicit grid.
positions
property
The start and end position of each track, relative to the container's border box.
Positions account for the container's border and padding, gaps, content alignment, and collapsed tracks.
line_names
property
The names of each grid line (one more line than there are tracks).
waxy.DetailedGridItemInfo
The placement of one grid item, as 1-based grid line numbers.
column_start
property
column_start: int
The 1-based grid line the item starts at in the column axis.
Node
waxy.NodeId
A handle to a node in the layout tree.
Geometry
waxy.Size
waxy.Rect
A value for each of the four sides of a box (left, right, top, bottom).
Mirrors taffy's Rect<f32>: per-side values such as Layout.margin, Layout.padding
and Layout.border, or the edges of a box such as Layout.scrollable_overflow_rect.
waxy.Point
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 size_*, flex_basis, 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 size_*, flex_basis, available space (measure functions),
and grid track sizing.
See: taffy MinTrackSizingFunction::MaxContent,
MDN max-content
waxy.Stretch
Stretch()
CSS stretch sizing keyword.
Fills the containing block's available space, less the node's margins.
Used only in size_* and flex_basis.
See: taffy Dimension::stretch,
MDN stretch
waxy.FitContentKeyword
FitContentKeyword()
CSS fit-content sizing keyword (without a limit).
Equivalent to fit-content(stretch): the node is sized to its contents, clamped between
its min-content size and the available space. For an explicit limit, use FitContent.
Used only in size_* and flex_basis.
See: taffy Dimension::fit_content,
MDN fit-content
waxy.Content
Content()
CSS content flex basis keyword.
Sizes the flex item based on its content, ignoring its size_* in the main axis.
Used only in flex_basis.
See: taffy Dimension::content,
MDN flex-basis: 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() 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. For the bare fit-content keyword, use
FIT_CONTENT.
Used in size_*, flex_basis, and 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.Repeat
Repeat(
count: int | AutoFill | AutoFit,
tracks: list[GridTrackValue],
line_names: list[list[str]] | None = None,
)
CSS repeat() in grid_template_rows / grid_template_columns.
Repeats tracks count times, where count is a positive int, AUTO_FILL, or
AUTO_FIT. line_names, if given, names the lines of each repetition positionally:
entry i names the line before tracks[i], and the final entry names the line after
the last track, so it has len(tracks) + 1 entries.
Raises InvalidRepeat if count is 0, tracks is empty, or line_names is neither
empty nor len(tracks) + 1 long.
waxy.AutoFill
AutoFill()
CSS auto-fill repetition count.
Repeat as many times as fit in the container without overflowing, keeping empty tracks.
Used only as the count of a Repeat.
See: taffy RepetitionCount::AutoFill,
MDN auto-fill
waxy.AutoFit
AutoFit()
CSS auto-fit repetition count.
Like AutoFill, but empty repeated tracks collapse to zero size.
Used only as the count of a Repeat.
See: taffy RepetitionCount::AutoFit,
MDN auto-fit
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.NamedGridLine
Place at the indexth grid line with the given name (counting from the end if negative).
If no line has that name, the implicit name-start/name-end lines of a named grid
area are tried before falling back to the implicit grid, so NamedGridLine("header")
in both start and end places an item in the header area.
Used in GridPlacement.start and GridPlacement.end.
Raises InvalidGridLine if index is 0.
waxy.NamedGridSpan
Span until the countth grid line with the given name.
Used in GridPlacement.start and GridPlacement.end.
Raises InvalidGridSpan if count is 0.
See: taffy GridPlacement::NamedSpan,
MDN grid-row-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 | NamedGridLine | NamedGridSpan | Auto). Defaults both to Auto (the CSS default for unplaced items).
See: taffy Line<GridPlacement>,
MDN grid-row,
MDN grid-column
waxy.GridTemplateArea
A named rectangular area of a grid template, bounded by 1-based grid lines.
An area covering only the first row and first two columns is
GridTemplateArea("header", 1, 2, 1, 3).
Raises InvalidGridTemplateArea if a start line is 0 or an end line is not after its
start line.
See: taffy GridTemplateArea,
MDN grid-template-areas
column_start
property
column_start: int
The 1-based grid line the area starts at in the column axis.
waxy.GridTemplateAreas
GridTemplateAreas(
areas: list[GridTemplateArea],
row_count: int,
column_count: int,
)
A grid template's named areas, plus its size in tracks (CSS grid-template-areas).
The template can be larger than the extent of its named areas because of unnamed
cells, so row_count and column_count are stored explicitly. Most templates are
easiest to build from CSS strings with GridTemplateAreas.from_strings.
Each area also defines implicit named lines name-start and name-end, so items can be
placed into an area with NamedGridLine(name).
Raises InvalidGridTemplateAreas if an area extends past row_count/column_count,
or if two areas share a name.
See: taffy GridTemplateAreas,
MDN grid-template-areas
from_strings
staticmethod
from_strings(rows: list[str]) -> GridTemplateAreas
Parse CSS grid-template-areas row strings.
Each string is one row of whitespace-separated cell names, and . marks an unnamed
cell. For example, GridTemplateAreas.from_strings(["header header", "nav main"]).
Raises InvalidGridTemplateAreas if the rows have different numbers of cells, an
area is not a rectangle, or a row contains a character that is not part of a name.
Constants
waxy.AUTO
module-attribute
AUTO: Auto = Auto()
Automatic sizing or placement.
Used for size_*, min_size_*, max_size_*, flex_basis, margin_*,
inset_*, and grid track and placement contexts.
waxy.MIN_CONTENT
module-attribute
MIN_CONTENT: 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.MAX_CONTENT
module-attribute
MAX_CONTENT: 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.STRETCH
module-attribute
STRETCH: Stretch = Stretch()
CSS stretch sizing keyword.
Fills the containing block's available space, less the node's margins.
Used only in size_* and flex_basis.
waxy.FIT_CONTENT
module-attribute
FIT_CONTENT: FitContentKeyword = FitContentKeyword()
CSS fit-content sizing keyword (without a limit).
Equivalent to fit-content(stretch): the node is sized to its contents, clamped between
its min-content and the available space. For an explicit limit, use [FitContent].
Used only in size_* and flex_basis.
waxy.CONTENT
module-attribute
CONTENT: Content = Content()
CSS content flex basis keyword.
Sizes the flex item based on its content, ignoring its size_* in the main axis.
Used only in flex_basis.
waxy.AUTO_FILL
module-attribute
AUTO_FILL: AutoFill = AutoFill()
CSS auto-fill repetition count: repeat as many times as fit without overflowing,
keeping empty tracks.
Used only as the count of a Repeat.
waxy.AUTO_FIT
module-attribute
AUTO_FIT: AutoFit = AutoFit()
CSS auto-fit repetition count: like auto-fill, but empty repeated tracks collapse.
Used only as the count of a Repeat.
Type aliases
waxy.DimensionValue
DimensionValue = (
Length
| Percent
| Auto
| MinContent
| MaxContent
| FitContent
| FitContentKeyword
| Stretch
)
A dimension value used for size_*.
waxy.FlexBasisValue
FlexBasisValue = DimensionValue | Content
A flex basis value: any DimensionValue, or Content.
waxy.LengthPercentageAutoValue
A length, percentage, or auto value used for margin, inset, and min_size_*/max_size_*.
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.GridTemplateValue
GridTemplateValue = GridTrackValue | Repeat
An entry of grid_template_rows / grid_template_columns: a track or a Repeat.
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
GridPlacementValue = (
GridLine
| GridSpan
| NamedGridLine
| NamedGridSpan
| Auto
)
A grid placement value used in GridPlacement start and end.
waxy.AvailableSpaceValue
AvailableSpaceValue = Definite | MinContent | MaxContent
Available space value for measure functions: Definite, MinContent, or MaxContent.
Enums
waxy.Display
How the node should be displayed.
FlowRoot
instance-attribute
FlowRoot: Display
Block layout that always establishes an independent formatting context.
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
Whether flex items wrap.
WrapReverse
instance-attribute
WrapReverse: FlexWrap
Items wrap onto multiple lines in reverse order.
Balance
instance-attribute
Balance: FlexWrap
Items wrap onto lines of balanced length (CSS flex-wrap: balance).
Lines are balanced into at least flex_line_count lines.
BalanceReverse
instance-attribute
BalanceReverse: FlexWrap
Like Balance, with lines in reverse order.
waxy.AlignItems
Alignment of items along the cross axis.
The Safe* members are the CSS safe variants: an item that would overflow its
alignment container is aligned as if Start instead.
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).
SelfStart
instance-attribute
SelfStart: AlignItems
Align to the start side of the item's own writing direction.
SelfEnd
instance-attribute
SelfEnd: AlignItems
Align to the end side of the item's own writing direction.
waxy.AlignContent
Alignment of content within the container.
The Safe* members are the CSS safe variants: content that would overflow the
container is aligned as if Start instead.
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
waxy.Direction
waxy.Float
waxy.Clear
Which preceding floats a node is moved below (CSS clear).
waxy.Contain
CSS containment (contain). Taffy supports the layout and paint containment types.
Layout
instance-attribute
Layout: Contain
Layout containment.
The node establishes an independent formatting context and has no baseline.
Paint
instance-attribute
Paint: Contain
Paint containment: the node establishes an independent formatting context.
Content
instance-attribute
Content: Contain
Both layout and paint containment (CSS contain: content).
Exceptions
Exception
├── KeyError
│ └── InvalidNodeId [TaffyException]
├── ValueError
│ ├── InvalidPercent [WaxyException]
│ ├── InvalidLength [WaxyException]
│ ├── InvalidGridLine [WaxyException]
│ ├── InvalidGridSpan [WaxyException]
│ ├── InvalidFlexLineCount [WaxyException]
│ ├── InvalidRepeat [WaxyException]
│ ├── InvalidGridTemplateArea [WaxyException]
│ └── InvalidGridTemplateAreas [WaxyException]
└── WaxyException
├── InvalidPercent [ValueError]
├── InvalidLength [ValueError]
├── InvalidGridLine [ValueError]
├── InvalidGridSpan [ValueError]
├── InvalidFlexLineCount [ValueError]
├── InvalidRepeat [ValueError]
├── InvalidGridTemplateArea [ValueError]
├── InvalidGridTemplateAreas [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.InvalidFlexLineCount
Bases: WaxyException, ValueError
Raised when Style(flex_line_count=...) is given 0 (a flex container has at least 1 line).
waxy.InvalidRepeat
Bases: WaxyException, ValueError
Raised when Repeat(...) is given invalid arguments.
That is: a count of 0, no tracks, or a line_names list that is neither empty nor
one longer than tracks.
waxy.InvalidGridTemplateArea
Bases: WaxyException, ValueError
Raised when GridTemplateArea(...) has a start line of 0 or an end line before its start.
waxy.InvalidGridTemplateAreas
Bases: WaxyException, ValueError
Raised when a GridTemplateAreas is invalid.
That is: an area extends past row_count/column_count, two areas share a name, or
GridTemplateAreas.from_strings(...) is given a template CSS would reject (ragged rows,
non-rectangular areas, or invalid characters).
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.