Documentation
¶
Overview ¶
Package flexbox is waffle's own flexbox layout engine — the replacement for react-pdf's Yoga binding. It computes box positions and sizes for a tree of nodes following CSS flexbox semantics (the subset react-pdf documents).
Owning the engine (rather than binding an external Yoga port) keeps the dependency graph clean and gives the pagination step the re-layout control it needs. The core implementation covers flex-direction row/column, grow/shrink, justify-content, align-items/self (including stretch), the full box model (margin/padding/border), gap, percentages, aspect-ratio, absolute positioning, flex-wrap (wrap/wrap-reverse) with align-content, and min/max width/height. Reversed directions are layered on in later passes.
All coordinates in Layout are border-box and relative to the parent's content-box origin, matching react-pdf's node model.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Align ¶
type Align int
Align is a cross-axis alignment (align-items / align-self / align-content). AlignAuto on a child defers to the container's align-items; AlignAuto on a container means stretch for align-items and flex-start for align-content. AlignSpaceBetween and AlignSpaceAround are meaningful only for align-content; elsewhere they fall back to flex-start.
type Dim ¶
Dim is a dimension that may be a definite point value, a percentage, or auto. Its zero value is auto, so an unset Width/Height/Basis behaves like CSS "auto" rather than a definite 0.
type Direction ¶
type Direction int
Direction is the flex main-axis direction. The zero value is Column, matching react-pdf's default.
type Layout ¶
type Layout struct {
Left, Top, Width, Height float64
}
Layout is a node's computed border-box, relative to its parent's content-box origin.
type MeasureFunc ¶
MeasureFunc measures a leaf node (e.g. text or an image) given the available space. Returned sizes are content sizes (the engine adds nothing to them).
type Node ¶
type Node struct {
Style Style
Children []*Node
Measure MeasureFunc
Layout Layout
}
Node is a layout node. Set Style, Children, and (for leaves) Measure; after Calculate, read Layout.
type Position ¶
type Position int
Position is a node's positioning scheme. Absolute takes the node out of flow and positions it via Top/Right/Bottom/Left against the parent's content box. Relative is currently treated as Static (in-flow) for layout.
type Style ¶
type Style struct {
Direction Direction
Wrap Wrap // flex-wrap; the zero value (NoWrap) keeps all children on one line
Justify Justify
AlignItems Align // container cross alignment; AlignAuto ⇒ stretch
AlignSelf Align // per-child override; AlignAuto ⇒ use parent's AlignItems
AlignContent Align // cross-axis distribution of wrapped lines; AlignAuto ⇒ flex-start
Grow float64
Shrink float64
Basis Dim // flex-basis; Auto ⇒ use the main-dimension size
Width, Height Dim
MinWidth, MaxWidth Dim // min/max constraints; DimAuto ⇒ unconstrained
MinHeight, MaxHeight Dim
AspectRatio float64 // width/height; when one dimension is auto, derive the other
Position Position
Top, Right, Bottom, Left Dim // insets for absolute positioning
MarginTop, MarginRight, MarginBottom, MarginLeft float64
PaddingTop, PaddingRight, PaddingBottom, PaddingLeft float64
BorderTop, BorderRight, BorderBottom, BorderLeft float64
Gap float64 // space between children along the main axis and between wrapped lines along the cross axis
}
Style holds the resolved layout inputs for a node. Lengths are in points; percentages are resolved by the caller before layout.