Documentation
¶
Overview ¶
Package layout computes a fragment tree from render nodes, computed styles, and available space. Its block, inline, flex, grid, list, table, and overlay algorithms measure and position content in terminal cells. The resulting fragments provide geometry for painting and hit testing.
Index ¶
- Constants
- func AbsoluteBounds(root *Fragment, target Node) (geometry.Rect, bool)
- func ClampHeight(node Node, height int, parentSpace ConstraintSpace) int
- func ClampWidth(node Node, width int, parentSpace ConstraintSpace) int
- func InfiniteRect() geometry.Rect
- func IntrinsicBlockSize(ctx *Context, node Node, availableWidth int) int
- func IsInlineLevel(node Node) bool
- func MaxScroll(frag *Fragment) (x, y int)
- func ReleaseFlexLineBuilder(b *FlexLineBuilder)
- func ReleaseGridBuilder(b *GridBuilder)
- func ReleaseInlineItemsBuilder(b *InlineItemsBuilder)
- func ReleaseLineBreaker(l *LineBreaker)
- func ReleaseTableFragmentBuilder(b *TableFragmentBuilder)
- func ResolveTrackSizes(templates []style.GridTrackSize, available int, gap int) []int
- func ScrolledAbsoluteBounds(root *Fragment, target Node) (rect geometry.Rect, clip geometry.Rect, found bool)
- func ScrolledAbsoluteBoundsPath(root *Fragment, target Node, path []Node) (rect geometry.Rect, clip geometry.Rect, found bool)
- func ShouldReserveScrollbar(s *style.Computed) (x, y bool)
- type Algorithm
- type AnonymousBlock
- func (a *AnonymousBlock) CachedBlockSize(width int) (int, bool)
- func (a *AnonymousBlock) CachedLayout(space ConstraintSpace) *Fragment
- func (a *AnonymousBlock) CachedMinMaxSizes() (MinMaxSizes, bool)
- func (a *AnonymousBlock) ClearDirtyLayout()
- func (a *AnonymousBlock) ComputeMinMaxSizes(ctx *Context) MinMaxSizes
- func (a *AnonymousBlock) FirstLayoutChild() Node
- func (a *AnonymousBlock) Fragment() *Fragment
- func (a *AnonymousBlock) HasChildNeedsPaint() bool
- func (a *AnonymousBlock) IsAnonymous() bool
- func (a *AnonymousBlock) IsDirtyLayout() bool
- func (a *AnonymousBlock) IsDirtyPaint() bool
- func (a *AnonymousBlock) Layout(ctx *Context) *Fragment
- func (a *AnonymousBlock) LogicalNode() dom.Node
- func (a *AnonymousBlock) NextLayoutSibling(child Node) Node
- func (a *AnonymousBlock) SetCachedBlockSize(width, height int)
- func (a *AnonymousBlock) SetCachedLayout(space ConstraintSpace, frag *Fragment)
- func (a *AnonymousBlock) SetCachedMinMaxSizes(sizes MinMaxSizes)
- func (a *AnonymousBlock) SetOffset(p geometry.Point)
- func (a *AnonymousBlock) Style() *style.Computed
- type BlockAlgorithm
- type BoxFragmentBuilder
- func (b *BoxFragmentBuilder) AddChild(frag *Fragment, offset geometry.Point)
- func (b *BoxFragmentBuilder) AdvanceBlockOffset(delta int)
- func (b *BoxFragmentBuilder) CurrentBlockOffset() int
- func (b *BoxFragmentBuilder) SetBlockOffset(offset int)
- func (b *BoxFragmentBuilder) SetBlockSize(height int)
- func (b *BoxFragmentBuilder) SetBreakToken(token *BreakToken)
- func (b *BoxFragmentBuilder) SetHasScrollbarX(v bool)
- func (b *BoxFragmentBuilder) SetHasScrollbarY(v bool)
- func (b *BoxFragmentBuilder) SetInlineSize(width int)
- func (b *BoxFragmentBuilder) ToFragment() *Fragment
- type BreakToken
- type ConstraintSpace
- type ConstraintSpaceBuilder
- func (b *ConstraintSpaceBuilder) SetContainerSpace(size geometry.Size) *ConstraintSpaceBuilder
- func (b *ConstraintSpaceBuilder) SetContainingSpace(size geometry.Size) *ConstraintSpaceBuilder
- func (b *ConstraintSpaceBuilder) SetIsFixedBlockSize(fixed bool) *ConstraintSpaceBuilder
- func (b *ConstraintSpaceBuilder) SetIsFixedInlineSize(fixed bool) *ConstraintSpaceBuilder
- func (b *ConstraintSpaceBuilder) ToConstraintSpace() ConstraintSpace
- type Constraints
- type Context
- type FlexAlgorithm
- type FlexItem
- type FlexLine
- type FlexLineBuilder
- func (b *FlexLineBuilder) AddItem(node Node, baseSize, minSize, maxSize, grow, shrink, order int)
- func (b *FlexLineBuilder) AlignCrossAxis(containerCrossSize int, alignContent style.Align, alignItems style.Align)
- func (b *FlexLineBuilder) AlignLine(lineIndex int, containerMainSize int, justifyContent style.Justify, ...)
- func (b *FlexLineBuilder) ComputeLines(availableMainSize int, wrap bool)
- func (b *FlexLineBuilder) Lines() []*FlexLine
- func (b *FlexLineBuilder) ResolveFlexibleLengths(lineIndex int, availableMain int)
- func (b *FlexLineBuilder) ReverseItems()
- func (b *FlexLineBuilder) SortItems()
- type Fragment
- type FragmentLink
- type GridAlgorithm
- type GridBuilder
- type InlineItem
- type InlineItemType
- type InlineItemsBuilder
- type InlineLever
- type LineBox
- type LineBreaker
- type ListAlgorithm
- type MeasureResult
- type MinMaxSizes
- type Node
- type NoneAlgorithm
- type OverlayAlgorithm
- type OverlayLever
- type ResolvedDecorations
- type ShapedTextCache
- type TableAlgorithm
- type TableCellLever
- type TableFragmentBuilder
- func (b *TableFragmentBuilder) AddBodyChild(node Node)
- func (b *TableFragmentBuilder) AddFooterChild(node Node)
- func (b *TableFragmentBuilder) AddHeaderChild(node Node)
- func (b *TableFragmentBuilder) AddNonRowChild(node Node)
- func (b *TableFragmentBuilder) AddRowChild(node Node)
- func (b *TableFragmentBuilder) AdjustRowOffset(hasTopBorder, hasBottomBorder bool) int
- func (b *TableFragmentBuilder) AdvanceBlockOffset(amount int)
- func (b *TableFragmentBuilder) BuildGrid(ctx *Context)
- func (b *TableFragmentBuilder) CurrentBlockOffset() int
- func (b *TableFragmentBuilder) DistributeSpan(ctx *Context, cell Node, colIndex int, colSpan int)
- func (b *TableFragmentBuilder) ResolveWidths(resolvedInlineSize int, parentDecorX int)
- func (b *TableFragmentBuilder) Sections() []Node
- func (b *TableFragmentBuilder) SetBlockSize(size int)
- func (b *TableFragmentBuilder) ToFragment() *Fragment
- type TableRowAlgorithm
- type TableSectionAlgorithm
Constants ¶
const InfiniteBlockSize = math.MaxInt32 / 2
InfiniteBlockSize is the height used when probing a node's intrinsic block size. It represents an unconstrained vertical axis: the node should size to its content, not to the available height. math.MaxInt32/2 avoids overflow when arithmetic is performed on top of it.
Variables ¶
This section is empty.
Functions ¶
func AbsoluteBounds ¶
AbsoluteBounds traverses the fragment tree starting at root and computes the absolute bounding rectangle of the target node. Returns the rect and true if found, or a zero rect and false if the node is not present in the tree.
func ClampHeight ¶
func ClampHeight(node Node, height int, parentSpace ConstraintSpace) int
ClampHeight clamps the height according to the node's style min/max constraints.
func ClampWidth ¶
func ClampWidth(node Node, width int, parentSpace ConstraintSpace) int
ClampWidth clamps the width according to the node's style min/max constraints.
func InfiniteRect ¶
InfiniteRect returns a rectangle that covers the entire signed integer coordinate space.
func IntrinsicBlockSize ¶
IntrinsicBlockSize returns the intrinsic block size (height) of a node given an available inline size (width).
func IsInlineLevel ¶
func MaxScroll ¶
MaxScroll calculates the maximum horizontal and vertical scroll offsets for a fragment, clamped to its content extent.
func ReleaseFlexLineBuilder ¶
func ReleaseFlexLineBuilder(b *FlexLineBuilder)
ReleaseFlexLineBuilder returns a builder to the pool.
func ReleaseGridBuilder ¶
func ReleaseGridBuilder(b *GridBuilder)
ReleaseGridBuilder returns a builder to the pool.
func ReleaseInlineItemsBuilder ¶
func ReleaseInlineItemsBuilder(b *InlineItemsBuilder)
ReleaseInlineItemsBuilder returns a builder to the pool.
func ReleaseLineBreaker ¶
func ReleaseLineBreaker(l *LineBreaker)
func ReleaseTableFragmentBuilder ¶
func ReleaseTableFragmentBuilder(b *TableFragmentBuilder)
ReleaseTableFragmentBuilder returns a builder to the pool.
func ResolveTrackSizes ¶
func ResolveTrackSizes(templates []style.GridTrackSize, available int, gap int) []int
ResolveTrackSizes resolves fixed and percentage track sizes against the available space.
func ScrolledAbsoluteBounds ¶
func ScrolledAbsoluteBounds(root *Fragment, target Node) (rect geometry.Rect, clip geometry.Rect, found bool)
ScrolledAbsoluteBounds returns the absolute bounding box of target, shifted by all ancestor scroll offsets and clipped by all ancestor overflow regions.
It returns:
- rect: the absolute border-box of target (scrolled).
- clip: the absolute content-box clip rectangle of the nearest clipping ancestor (intersected with all further clipping ancestors).
- found: true if target was found in the subtree.
func ShouldReserveScrollbar ¶
ShouldReserveScrollbar returns true if space for a scrollbar must be reserved regardless of content size (i.e. style is OverflowScroll).
Types ¶
type Algorithm ¶
type Algorithm interface {
// Layout computes and returns an immutable Fragment based on the underlying node and constraints.
Layout(ctx *Context, node Node, space ConstraintSpace) *Fragment
// ComputeMinMaxSizes calculates the intrinsic minimum and maximum sizes of the node.
ComputeMinMaxSizes(ctx *Context, node Node) MinMaxSizes
}
Algorithm is the interface that all LayoutNG-inspired layout formatters must implement.
func GetAlgorithm ¶
GetAlgorithm returns the appropriate layout algorithm for the given node.
func NewAlgorithm ¶
func NewAlgorithm(node Node, space ConstraintSpace) Algorithm
NewAlgorithm is deprecated: use GetAlgorithm instead.
type AnonymousBlock ¶
type AnonymousBlock struct {
// contains filtered or unexported fields
}
AnonymousBlock represents an anonymous box created to wrap contiguous runs of inline content.
func (*AnonymousBlock) CachedBlockSize ¶
func (a *AnonymousBlock) CachedBlockSize(width int) (int, bool)
func (*AnonymousBlock) CachedLayout ¶
func (a *AnonymousBlock) CachedLayout(space ConstraintSpace) *Fragment
func (*AnonymousBlock) CachedMinMaxSizes ¶
func (a *AnonymousBlock) CachedMinMaxSizes() (MinMaxSizes, bool)
func (*AnonymousBlock) ClearDirtyLayout ¶
func (a *AnonymousBlock) ClearDirtyLayout()
func (*AnonymousBlock) ComputeMinMaxSizes ¶
func (a *AnonymousBlock) ComputeMinMaxSizes(ctx *Context) MinMaxSizes
func (*AnonymousBlock) FirstLayoutChild ¶
func (a *AnonymousBlock) FirstLayoutChild() Node
func (*AnonymousBlock) Fragment ¶
func (a *AnonymousBlock) Fragment() *Fragment
func (*AnonymousBlock) HasChildNeedsPaint ¶
func (a *AnonymousBlock) HasChildNeedsPaint() bool
func (*AnonymousBlock) IsAnonymous ¶
func (a *AnonymousBlock) IsAnonymous() bool
func (*AnonymousBlock) IsDirtyLayout ¶
func (a *AnonymousBlock) IsDirtyLayout() bool
func (*AnonymousBlock) IsDirtyPaint ¶
func (a *AnonymousBlock) IsDirtyPaint() bool
func (*AnonymousBlock) Layout ¶
func (a *AnonymousBlock) Layout(ctx *Context) *Fragment
func (*AnonymousBlock) LogicalNode ¶
func (a *AnonymousBlock) LogicalNode() dom.Node
func (*AnonymousBlock) NextLayoutSibling ¶
func (a *AnonymousBlock) NextLayoutSibling(child Node) Node
func (*AnonymousBlock) SetCachedBlockSize ¶
func (a *AnonymousBlock) SetCachedBlockSize(width, height int)
func (*AnonymousBlock) SetCachedLayout ¶
func (a *AnonymousBlock) SetCachedLayout(space ConstraintSpace, frag *Fragment)
func (*AnonymousBlock) SetCachedMinMaxSizes ¶
func (a *AnonymousBlock) SetCachedMinMaxSizes(sizes MinMaxSizes)
func (*AnonymousBlock) SetOffset ¶
func (a *AnonymousBlock) SetOffset(p geometry.Point)
func (*AnonymousBlock) Style ¶
func (a *AnonymousBlock) Style() *style.Computed
type BlockAlgorithm ¶
type BlockAlgorithm struct{}
BlockAlgorithm implements the Block formatting context layout. It stacks children vertically (in the block-flow direction) and calculates its own intrinsic size based on the accumulated height of its children.
func (*BlockAlgorithm) ComputeMinMaxSizes ¶
func (a *BlockAlgorithm) ComputeMinMaxSizes(ctx *Context, node Node) MinMaxSizes
ComputeMinMaxSizes calculates the intrinsic minimum and maximum sizes of the node.
func (*BlockAlgorithm) Layout ¶
func (a *BlockAlgorithm) Layout(ctx *Context, node Node, space ConstraintSpace) *Fragment
Layout executes the block layout algorithm and returns an immutable Fragment.
type BoxFragmentBuilder ¶
type BoxFragmentBuilder struct {
// contains filtered or unexported fields
}
BoxFragmentBuilder manages the state of a box fragment being built.
func AcquireBoxFragmentBuilder ¶
func AcquireBoxFragmentBuilder(node Node, space ConstraintSpace) *BoxFragmentBuilder
AcquireBoxFragmentBuilder gets a builder from the pool and initializes it.
func NewBoxFragmentBuilder ¶
func NewBoxFragmentBuilder(node Node, space ConstraintSpace) *BoxFragmentBuilder
NewBoxFragmentBuilder creates a new builder for the given node and constraint space.
func (*BoxFragmentBuilder) AddChild ¶
func (b *BoxFragmentBuilder) AddChild(frag *Fragment, offset geometry.Point)
AddChild adds a child fragment at the specified offset.
func (*BoxFragmentBuilder) AdvanceBlockOffset ¶
func (b *BoxFragmentBuilder) AdvanceBlockOffset(delta int)
AdvanceBlockOffset increases the block-direction offset (Y).
func (*BoxFragmentBuilder) CurrentBlockOffset ¶
func (b *BoxFragmentBuilder) CurrentBlockOffset() int
CurrentBlockOffset returns the current block-direction offset (Y).
func (*BoxFragmentBuilder) SetBlockOffset ¶
func (b *BoxFragmentBuilder) SetBlockOffset(offset int)
SetBlockOffset sets the current block-direction offset (Y).
func (*BoxFragmentBuilder) SetBlockSize ¶
func (b *BoxFragmentBuilder) SetBlockSize(height int)
SetBlockSize sets the final block size (height) of the fragment.
func (*BoxFragmentBuilder) SetBreakToken ¶
func (b *BoxFragmentBuilder) SetBreakToken(token *BreakToken)
SetBreakToken sets the break token for the fragment.
func (*BoxFragmentBuilder) SetHasScrollbarX ¶
func (b *BoxFragmentBuilder) SetHasScrollbarX(v bool)
SetHasScrollbarX sets whether the fragment has a horizontal scrollbar.
func (*BoxFragmentBuilder) SetHasScrollbarY ¶
func (b *BoxFragmentBuilder) SetHasScrollbarY(v bool)
SetHasScrollbarY sets whether the fragment has a vertical scrollbar.
func (*BoxFragmentBuilder) SetInlineSize ¶
func (b *BoxFragmentBuilder) SetInlineSize(width int)
SetInlineSize sets the final inline size (width) of the fragment.
func (*BoxFragmentBuilder) ToFragment ¶
func (b *BoxFragmentBuilder) ToFragment() *Fragment
ToFragment finalizes the builder and returns an immutable Fragment. It also returns the builder to the pool.
type BreakToken ¶
BreakToken represents the state needed to resume layout of a node in a new fragmentainer (e.g., the next page or column).
type ConstraintSpace ¶
type ConstraintSpace struct {
// AvailableSize is the ideal size the node should consume, provided by the parent.
AvailableSize geometry.Size
// ContainingSpace is the parent's resolved border-box dimensions.
ContainingSpace geometry.Size
// ContainerSpace is the parent's content-box dimensions
// (ContainingSpace minus border minus padding).
// KindPercent resolution and per-child AvailableSize derive from this field.
ContainerSpace geometry.Size
// IsFixedInlineSize indicates the inline size (width) is pre-determined.
IsFixedInlineSize bool
// IsFixedBlockSize indicates the block size (height) is pre-determined.
IsFixedBlockSize bool
// BreakToken is the token to resume layout from.
BreakToken *BreakToken
}
ConstraintSpace defines the inputs for a layout operation. It encapsulates the physical size constraints alongside any additional context required during the layout walk (e.g., parent reference sizes, break tokens).
The three size fields serve distinct roles (ADR-018):
- AvailableSize: per-child space after subtracting margins (or an explicit size).
- ContainerSpace: parent's content-box (ContainingSpace − border − padding). KindPercent dimensions resolve against this field, and it is the base for computing per-child AvailableSize. In CSS, percentage widths/heights always resolve against the containing block's content area.
- ContainingSpace: parent's resolved border-box. Carries the parent's total outer size for algorithms that require it (e.g. intrinsic sizing, positioning).
func BuildChildSpace ¶
func BuildChildSpace(child Node, containerSpace geometry.Size, containingSpace geometry.Size, parentSpace ConstraintSpace) ConstraintSpace
BuildChildSpace constructs a ConstraintSpace for a block-level child element.
Parameters:
- child: the child layout node (for computed style access).
- containerSpace: the parent's content-box dimensions, pre-adjusted for the current block offset so that Height reflects the remaining vertical space.
- containingSpace: the parent's border-box dimensions, used as the base for KindPercent resolution (ADR-018).
- parentSpace: the parent's own ConstraintSpace (for IsFixedBlockSize and BreakToken).
This function centralises the child constraint generation that was previously duplicated across BlockAlgorithm and ListAlgorithm (ADR-018).
type ConstraintSpaceBuilder ¶
type ConstraintSpaceBuilder struct {
// contains filtered or unexported fields
}
ConstraintSpaceBuilder is a helper to construct a ConstraintSpace.
func NewConstraintSpaceBuilder ¶
func NewConstraintSpaceBuilder(availableSize geometry.Size) *ConstraintSpaceBuilder
NewConstraintSpaceBuilder creates a new builder initialized with the available size. ContainingSpace and ContainerSpace default to zero and must be set explicitly by the caller.
func (*ConstraintSpaceBuilder) SetContainerSpace ¶
func (b *ConstraintSpaceBuilder) SetContainerSpace(size geometry.Size) *ConstraintSpaceBuilder
SetContainerSpace sets the parent's content-box size (the available space for children before per-child margins are subtracted) (ADR-018).
func (*ConstraintSpaceBuilder) SetContainingSpace ¶
func (b *ConstraintSpaceBuilder) SetContainingSpace(size geometry.Size) *ConstraintSpaceBuilder
SetContainingSpace sets the parent's border-box size (ADR-018). KindPercent resolution uses ContainerSpace (content-box), not this field.
func (*ConstraintSpaceBuilder) SetIsFixedBlockSize ¶
func (b *ConstraintSpaceBuilder) SetIsFixedBlockSize(fixed bool) *ConstraintSpaceBuilder
SetIsFixedBlockSize sets whether the block size is fixed.
func (*ConstraintSpaceBuilder) SetIsFixedInlineSize ¶
func (b *ConstraintSpaceBuilder) SetIsFixedInlineSize(fixed bool) *ConstraintSpaceBuilder
SetIsFixedInlineSize sets whether the inline size is fixed.
func (*ConstraintSpaceBuilder) ToConstraintSpace ¶
func (b *ConstraintSpaceBuilder) ToConstraintSpace() ConstraintSpace
ToConstraintSpace returns the constructed ConstraintSpace.
type Constraints ¶
Constraints defines the minimum and maximum dimensions allowed for a box.
type FlexAlgorithm ¶
type FlexAlgorithm struct{}
FlexAlgorithm implements the CSS Flexbox formatting context layout.
func (*FlexAlgorithm) ComputeMinMaxSizes ¶
func (a *FlexAlgorithm) ComputeMinMaxSizes(ctx *Context, node Node) MinMaxSizes
ComputeMinMaxSizes calculates the intrinsic minimum and maximum sizes of the node.
func (*FlexAlgorithm) Layout ¶
func (a *FlexAlgorithm) Layout(ctx *Context, node Node, space ConstraintSpace) *Fragment
Layout executes the flex layout algorithm and returns an immutable Fragment.
type FlexItem ¶
type FlexItem struct {
Node Node
// Flex base size (initial main size before growing/shrinking).
BaseSize int
// Hypothetical main size (base size clamped by min/max constraints).
HypotheticalMainSize int
// Final resolved sizes.
MainSize int
CrossSize int
// Frozen indicates the item's main size has been fixed.
Frozen bool
// Style shortcuts.
Grow int
Shrink int
Order int
// Min/Max constraints in main axis.
MinMainSize int
MaxMainSize int
// Cached measurement result.
Fragment *Fragment
// AlignSelf override for this item.
AlignSelf style.Align
// Physical offset relative to container content box.
Offset geometry.Point
}
FlexItem represents a transient layout state for a flex child.
type FlexLineBuilder ¶
type FlexLineBuilder struct {
// contains filtered or unexported fields
}
FlexLineBuilder encapsulates the mutable state required for resolving flex lines. It acts as the state machine for the flex layout algorithm, handling item collection, line breaking, space distribution (growing/shrinking), and alignment.
func AcquireFlexLineBuilder ¶
func AcquireFlexLineBuilder(geom flexGeometry, mainGap, crossGap int) *FlexLineBuilder
AcquireFlexLineBuilder gets a builder from the pool and initializes it.
func NewFlexLineBuilder ¶
func NewFlexLineBuilder(geom flexGeometry, mainGap, crossGap int) *FlexLineBuilder
func (*FlexLineBuilder) AddItem ¶
func (b *FlexLineBuilder) AddItem(node Node, baseSize, minSize, maxSize, grow, shrink, order int)
func (*FlexLineBuilder) AlignCrossAxis ¶
func (b *FlexLineBuilder) AlignCrossAxis(containerCrossSize int, alignContent style.Align, alignItems style.Align)
AlignCrossAxis handles cross-axis alignment (align-content and align-items).
func (*FlexLineBuilder) AlignLine ¶
func (b *FlexLineBuilder) AlignLine(lineIndex int, containerMainSize int, justifyContent style.Justify, isReverse bool)
AlignLine handles main-axis alignment (justify-content) for a single line.
func (*FlexLineBuilder) ComputeLines ¶
func (b *FlexLineBuilder) ComputeLines(availableMainSize int, wrap bool)
ComputeLines groups the items into lines based on the available main size.
func (*FlexLineBuilder) Lines ¶
func (b *FlexLineBuilder) Lines() []*FlexLine
Lines returns the computed lines.
func (*FlexLineBuilder) ResolveFlexibleLengths ¶
func (b *FlexLineBuilder) ResolveFlexibleLengths(lineIndex int, availableMain int)
ResolveFlexibleLengths distributes free space among items in a line.
func (*FlexLineBuilder) ReverseItems ¶
func (b *FlexLineBuilder) ReverseItems()
ReverseItems reverses the order of items (used for row-reverse/column-reverse).
func (*FlexLineBuilder) SortItems ¶
func (b *FlexLineBuilder) SortItems()
SortItems sorts items by their Order property.
type Fragment ¶
type Fragment struct {
// Size is the computed physical dimensions of this fragment in terminal cells.
Size geometry.Size
// Node is the layout node that generated this fragment.
Node Node
// Children contains the positioned child fragments relative to this fragment.
Children []FragmentLink
// Text contains the shaped clusters if this fragment represents a text run.
Text []text.Cluster
// ParentNode is the containing inline element for text fragments (for style inheritance).
ParentNode Node
// BreakToken is the token to resume layout in the next fragmentainer.
BreakToken *BreakToken
// HasScrollbarX indicates that a horizontal scrollbar was reserved during layout.
HasScrollbarX bool
// HasScrollbarY indicates that a vertical scrollbar was reserved during layout.
HasScrollbarY bool
}
Fragment represents the immutable output of a layout algorithm. Once created, a Fragment's fields must never be modified. This immutability allows fragments to be cached and reused across layout passes.
type FragmentLink ¶
type FragmentLink struct {
// Offset is the physical position of the child relative to the parent fragment's origin.
Offset geometry.Point
// Fragment is the immutable child fragment.
Fragment *Fragment
}
FragmentLink connects a child Fragment to its parent at a specific physical offset. Positioning information is stored here rather than inside the Fragment itself, allowing the exact same Fragment to be reused in different positions.
type GridAlgorithm ¶
type GridAlgorithm struct{}
GridAlgorithm implements the CSS Grid formatting context layout.
func (*GridAlgorithm) ComputeMinMaxSizes ¶
func (a *GridAlgorithm) ComputeMinMaxSizes(ctx *Context, node Node) MinMaxSizes
func (*GridAlgorithm) Layout ¶
func (a *GridAlgorithm) Layout(ctx *Context, node Node, space ConstraintSpace) *Fragment
Layout executes the grid layout algorithm and returns an immutable Fragment.
type GridBuilder ¶
type GridBuilder struct {
// contains filtered or unexported fields
}
GridBuilder handles the auto-placement algorithm and track sizing for CSS Grid.
func AcquireGridBuilder ¶
func AcquireGridBuilder(node Node, space ConstraintSpace) *GridBuilder
AcquireGridBuilder gets a builder from the pool and initializes it.
func NewGridBuilder ¶
func NewGridBuilder(node Node, space ConstraintSpace) *GridBuilder
NewGridBuilder creates a new GridBuilder for the given node and space.
func (*GridBuilder) Init ¶
func (b *GridBuilder) Init(node Node, space ConstraintSpace)
Init initializes the GridBuilder for the given node and space. This allows for stack allocation or reuse.
func (*GridBuilder) PlaceItems ¶
func (b *GridBuilder) PlaceItems()
type InlineItem ¶
type InlineItem struct {
Type InlineItemType
// Text contains the shaped clusters for InlineText items.
Text []text.Cluster
// Node is the layout node that generated this item.
// For InlineAtomic, this is the element itself.
// For Tags, this is the element providing the styles.
Node Node
// ParentNode is the containing inline element for text items.
ParentNode Node
}
InlineItem is the atomic unit of the flattened inline representation.
type InlineItemType ¶
type InlineItemType uint8
InlineItemType identifies the role of an item in the inline flow.
const ( // InlineText represents a contiguous run of shaped text. InlineText InlineItemType = iota // InlineAtomic represents an opaque block element (inline-block). InlineAtomic // InlineOpenTag marks the start of a styled range. InlineOpenTag // InlineCloseTag marks the end of a styled range. InlineCloseTag // InlineBr represents a <br> element that forces a mandatory line break. // It contributes zero bytes and zero visual width but terminates the // current line immediately, similar to a \n cluster with BreakMandatory. InlineBr // InlineBrPlaceholder represents a trailing placeholder <br> that forces // a line break (so the textarea always has height for an empty last line) // but contributes ZERO bytes to the cursor byte-offset model. This maps // to the browser model where the placeholder break is not part of the // buffer value. InlineBrPlaceholder )
type InlineItemsBuilder ¶
type InlineItemsBuilder struct {
// contains filtered or unexported fields
}
InlineItemsBuilder flattens a tree of layout nodes into a 1D array of InlineItems.
func AcquireInlineItemsBuilder ¶
func AcquireInlineItemsBuilder(shaper *text.Shaper, block Node) *InlineItemsBuilder
AcquireInlineItemsBuilder gets a builder from the pool and initializes it.
func NewInlineItemsBuilder ¶
func NewInlineItemsBuilder(shaper *text.Shaper, block Node) *InlineItemsBuilder
func (*InlineItemsBuilder) Build ¶
func (b *InlineItemsBuilder) Build(root Node) []InlineItem
func (*InlineItemsBuilder) Reset ¶
func (b *InlineItemsBuilder) Reset()
type InlineLever ¶
type InlineLever interface {
IsInlineLevel() bool
}
type LineBox ¶
type LineBox struct {
Size geometry.Size
Children []FragmentLink
}
LineBox represents a single horizontal line of positioned inline fragments.
func (*LineBox) ToFragment ¶
type LineBreaker ¶
type LineBreaker struct {
// contains filtered or unexported fields
}
LineBreaker packs InlineItems into physical lines.
func AcquireLineBreaker ¶
func AcquireLineBreaker(items []InlineItem, width int, textAlign style.TextAlign, verticalAlign style.Align, textOverflow style.TextOverflow) *LineBreaker
type ListAlgorithm ¶
type ListAlgorithm struct{}
ListAlgorithm implements the layout for list items with markers. It formats the list item as a two-column row: Column 1 is the marker, and Column 2 contains the children laid out using Block layout rules.
func (*ListAlgorithm) ComputeMinMaxSizes ¶
func (a *ListAlgorithm) ComputeMinMaxSizes(ctx *Context, node Node) MinMaxSizes
func (*ListAlgorithm) Layout ¶
func (a *ListAlgorithm) Layout(ctx *Context, node Node, space ConstraintSpace) *Fragment
type MeasureResult ¶
MeasureResult is the output of a node's Measure method.
type MinMaxSizes ¶
type MinMaxSizes struct {
Min, Max int
}
MinMaxSizes represents the intrinsic minimum and maximum widths of a node.
func ComputeInlineMinMaxSizes ¶
func ComputeInlineMinMaxSizes(ctx *Context, items []InlineItem) MinMaxSizes
func IntrinsicMinMaxSizes ¶
func IntrinsicMinMaxSizes(ctx *Context, node Node) MinMaxSizes
IntrinsicMinMaxSizes computes the intrinsic min/max widths for a node by selecting the correct algorithm based on its display style.
func (MinMaxSizes) Add ¶
func (m MinMaxSizes) Add(value int) MinMaxSizes
Add shifts both min and max sizes simultaneously.
func (MinMaxSizes) Constrain ¶
func (m MinMaxSizes) Constrain(value int) MinMaxSizes
Constrain caps the boundaries (min/max) to a specific value.
func (*MinMaxSizes) Encompass ¶
func (m *MinMaxSizes) Encompass(other MinMaxSizes)
Encompass expands the min/max bounds to fit another MinMaxSizes.
func (*MinMaxSizes) EncompassSize ¶
func (m *MinMaxSizes) EncompassSize(value int)
EncompassSize expands the min/max bounds to fit an explicit value.
func (MinMaxSizes) Subtract ¶
func (m MinMaxSizes) Subtract(value int) MinMaxSizes
Subtract shifts both min and max sizes simultaneously.
type Node ¶
type Node interface {
// Style returns the node's fully-resolved computed style.
// Must not return nil for nodes that participate in layout.
Style() *style.Computed
// FirstLayoutChild returns the first layout-visible child of this node.
FirstLayoutChild() Node
// NextLayoutSibling returns the next layout-visible sibling of the given child.
NextLayoutSibling(child Node) Node
// LogicalNode returns the logical DOM node that owns this render object.
// May be nil.
LogicalNode() dom.Node
// IsDirtyLayout reports whether this node's layout is stale. The engine
// uses this signal to decide whether cached intrinsic sizes are still
// valid.
IsDirtyLayout() bool
// IsDirtyPaint reports whether this node's paint is stale.
IsDirtyPaint() bool
// HasChildNeedsPaint reports whether any descendant needs paint.
HasChildNeedsPaint() bool
// ClearDirtyLayout clears the DirtyLayout flag on this node. Called by
// the layout engine after successfully measuring the node so that
// subsequent cache lookups are valid.
ClearDirtyLayout()
// Fragment returns the most recent LayoutNG fragment generated for this node.
// It is used by paint, hit testing, and spatial navigation to retrieve the
// physical representation of the element.
Fragment() *Fragment
// CachedLayout returns a previously computed fragment if the node is clean
// and the constraints match. Returns nil if a re-layout is required.
CachedLayout(space ConstraintSpace) *Fragment
// SetCachedLayout stores the computed fragment and the constraints that generated it.
// Implementing this should implicitly clear the DirtyLayout flag.
SetCachedLayout(space ConstraintSpace, frag *Fragment)
// CachedMinMaxSizes returns the intrinsic minimum and maximum sizes if they are still valid.
CachedMinMaxSizes() (MinMaxSizes, bool)
// SetCachedMinMaxSizes stores the computed intrinsic minimum and maximum sizes.
SetCachedMinMaxSizes(sizes MinMaxSizes)
// CachedBlockSize returns the intrinsic block size (height) for a given inline size (width).
CachedBlockSize(width int) (int, bool)
// SetCachedBlockSize stores the computed intrinsic block size for a given inline size.
SetCachedBlockSize(width, height int)
// SetOffset updates the physical offset of this node.
SetOffset(geom.Point)
// IsAnonymous reports whether this node is a virtual layout-only node
// (like flex's AnonymousBlock) that should trigger shrink-wrap for auto width.
IsAnonymous() bool
}
Node is the layout engine's view of a render object. It provides the style, tree-walk, and bounds-mutation interface required by formatting-context algorithms without importing the render package.
Any render object that participates in layout must implement this interface.
type NoneAlgorithm ¶
type NoneAlgorithm struct{}
NoneAlgorithm is a layout formatter for nodes with display: none. It always returns an empty fragment.
func (*NoneAlgorithm) ComputeMinMaxSizes ¶
func (a *NoneAlgorithm) ComputeMinMaxSizes(ctx *Context, node Node) MinMaxSizes
func (*NoneAlgorithm) Layout ¶
func (a *NoneAlgorithm) Layout(ctx *Context, node Node, space ConstraintSpace) *Fragment
type OverlayAlgorithm ¶
type OverlayAlgorithm struct{}
OverlayAlgorithm implements anchored positioning and smart flipping for overlays.
func (*OverlayAlgorithm) ComputeMinMaxSizes ¶
func (a *OverlayAlgorithm) ComputeMinMaxSizes(ctx *Context, node Node) MinMaxSizes
func (*OverlayAlgorithm) Layout ¶
func (a *OverlayAlgorithm) Layout(ctx *Context, node Node, space ConstraintSpace) *Fragment
type OverlayLever ¶
type ResolvedDecorations ¶
type ResolvedDecorations struct {
// Insets is the total space consumed by decorations on each side.
// This is the sum of Border + Padding + (if present) Scrollbar.
Insets style.EdgeValues[int]
// HasScrollbarX indicates if a horizontal scrollbar is active.
HasScrollbarX bool
// HasScrollbarY indicates if a vertical scrollbar is active.
HasScrollbarY bool
}
ResolvedDecorations contains the computed sizes and visibility flags for an element's non-content area (borders, padding, and scrollbars).
func ResolveDecorations ¶
func ResolveDecorations(node Node, scrollX, scrollY bool) ResolvedDecorations
ResolveDecorations computes the decoration sizes for a node based on its style and whether scrollbars have been requested/forced by the layout algorithm.
func (ResolvedDecorations) ViewportSize ¶
func (d ResolvedDecorations) ViewportSize(outer geometry.Size) geometry.Size
ViewportSize returns the available content area for a fragment of the given outer size, accounting for decorations.
type ShapedTextCache ¶
type TableAlgorithm ¶
type TableAlgorithm struct{}
TableAlgorithm implements the DisplayTable layout.
func (*TableAlgorithm) ComputeMinMaxSizes ¶
func (a *TableAlgorithm) ComputeMinMaxSizes(ctx *Context, node Node) MinMaxSizes
func (*TableAlgorithm) Layout ¶
func (a *TableAlgorithm) Layout(ctx *Context, node Node, space ConstraintSpace) *Fragment
Layout executes the two-pass table layout algorithm and returns an immutable Fragment.
type TableCellLever ¶
type TableFragmentBuilder ¶
type TableFragmentBuilder struct {
// contains filtered or unexported fields
}
TableFragmentBuilder manages the mutable state during the two-pass table layout algorithm. It handles section grouping, column matrix math, and implicit border overlapping calculations.
func AcquireTableFragmentBuilder ¶
func AcquireTableFragmentBuilder(node Node, space ConstraintSpace) *TableFragmentBuilder
AcquireTableFragmentBuilder gets a builder from the pool and initializes it.
func NewTableFragmentBuilder ¶
func NewTableFragmentBuilder(node Node, space ConstraintSpace) *TableFragmentBuilder
func (*TableFragmentBuilder) AddBodyChild ¶
func (b *TableFragmentBuilder) AddBodyChild(node Node)
func (*TableFragmentBuilder) AddFooterChild ¶
func (b *TableFragmentBuilder) AddFooterChild(node Node)
func (*TableFragmentBuilder) AddHeaderChild ¶
func (b *TableFragmentBuilder) AddHeaderChild(node Node)
func (*TableFragmentBuilder) AddNonRowChild ¶
func (b *TableFragmentBuilder) AddNonRowChild(node Node)
func (*TableFragmentBuilder) AddRowChild ¶
func (b *TableFragmentBuilder) AddRowChild(node Node)
func (*TableFragmentBuilder) AdjustRowOffset ¶
func (b *TableFragmentBuilder) AdjustRowOffset(hasTopBorder, hasBottomBorder bool) int
AdjustRowOffset handles the -1 Y coordinate adjustment for intersecting row borders.
func (*TableFragmentBuilder) AdvanceBlockOffset ¶
func (b *TableFragmentBuilder) AdvanceBlockOffset(amount int)
func (*TableFragmentBuilder) BuildGrid ¶
func (b *TableFragmentBuilder) BuildGrid(ctx *Context)
func (*TableFragmentBuilder) CurrentBlockOffset ¶
func (b *TableFragmentBuilder) CurrentBlockOffset() int
func (*TableFragmentBuilder) DistributeSpan ¶
func (b *TableFragmentBuilder) DistributeSpan(ctx *Context, cell Node, colIndex int, colSpan int)
DistributeSpan handles the complex math of stretching minimum widths across multiple columns.
func (*TableFragmentBuilder) ResolveWidths ¶
func (b *TableFragmentBuilder) ResolveWidths(resolvedInlineSize int, parentDecorX int)
func (*TableFragmentBuilder) Sections ¶
func (b *TableFragmentBuilder) Sections() []Node
func (*TableFragmentBuilder) SetBlockSize ¶
func (b *TableFragmentBuilder) SetBlockSize(size int)
func (*TableFragmentBuilder) ToFragment ¶
func (b *TableFragmentBuilder) ToFragment() *Fragment
type TableRowAlgorithm ¶
type TableRowAlgorithm struct{}
TableRowAlgorithm implements the DisplayTableRow layout.
func (*TableRowAlgorithm) ComputeMinMaxSizes ¶
func (a *TableRowAlgorithm) ComputeMinMaxSizes(ctx *Context, node Node) MinMaxSizes
func (*TableRowAlgorithm) Layout ¶
func (a *TableRowAlgorithm) Layout(ctx *Context, node Node, space ConstraintSpace) *Fragment
func (*TableRowAlgorithm) LayoutWithData ¶
func (a *TableRowAlgorithm) LayoutWithData(ctx *Context, node Node, space ConstraintSpace, tableBuilder *TableFragmentBuilder, colWidths []int, rowData *tableRowGrid) *Fragment
type TableSectionAlgorithm ¶
type TableSectionAlgorithm struct{}
TableSectionAlgorithm implements the layout for table header, body, and footer groups.
func (*TableSectionAlgorithm) ComputeMinMaxSizes ¶
func (a *TableSectionAlgorithm) ComputeMinMaxSizes(ctx *Context, node Node) MinMaxSizes
func (*TableSectionAlgorithm) Layout ¶
func (a *TableSectionAlgorithm) Layout(ctx *Context, node Node, space ConstraintSpace) *Fragment
func (*TableSectionAlgorithm) LayoutWithData ¶
func (a *TableSectionAlgorithm) LayoutWithData(ctx *Context, node Node, space ConstraintSpace, tableBuilder *TableFragmentBuilder, colWidths []int, rowsData []*tableRowGrid) *Fragment