layout

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CaretIndexForTextFragments

func CaretIndexForTextFragments(fragments []TextFragment, x float64) (int, bool)

func CaretXForTextFragments

func CaretXForTextFragments(fragments []TextFragment, caret int) (float64, bool)

func ScrollbarSize

func ScrollbarSize(computed *style.ComputedStyle) float64

ScrollbarSize is shared by layout and painting so the gutter matches its bar.

func UsedLineHeight

func UsedLineHeight(computed *style.ComputedStyle, face *font.Face) float64

UsedLineHeight resolves the used value of line-height for a shaped face. The computed style stores a 1.2 fallback for `normal`, but Chromium derives the normal value from the selected face metrics instead of that fallback.

Types

type Box

type Box struct {
	Style  *style.ComputedStyle
	Parent *Box
	Node   *dom.Node

	StableID          string
	ControlFragments  []ControlFragment
	InlineBackgrounds []InlineBackground
	ImageFragments    []ImageFragment
	TextFragments     []TextFragment
	Children          []*Box

	Padding       Edges
	FlowMarginBox Rect
	// ScrollbarGutter is reserved between the padding edge and border.
	ScrollbarGutter Edges
	Border          Edges
	Content         Rect
	Margin          Edges
	ScrollHeight    float64
	TextHeight      float64
	ScrollWidth     float64
	// contains filtered or unexported fields
}

func Build

func Build(root *dom.Node, styles style.Map, face *font.Face, viewportWidth, viewportHeight float64) (*Box, error)

func BuildWithFonts

func BuildWithFonts(root *dom.Node, styles style.Map, face, boldFace *font.Face, viewportWidth, viewportHeight float64) (*Box, error)

BuildWithFonts lays out a document using separate regular and bold faces. The bold face is selected for text whose computed font weight is 600 or heavier, matching the font used when its visual is spawned.

func (*Box) BorderBox

func (b *Box) BorderBox() Rect

func (*Box) CachedPaintHash

func (b *Box) CachedPaintHash() (uint64, bool)

func (*Box) GeometryHash

func (b *Box) GeometryHash() uint64

func (*Box) InvalidatePaintHash

func (b *Box) InvalidatePaintHash()

func (*Box) MarginBox

func (b *Box) MarginBox() Rect

func (*Box) OwnGeometryHash

func (b *Box) OwnGeometryHash() uint64

func (*Box) PaddingBox

func (b *Box) PaddingBox() Rect

func (*Box) Restyle

func (box *Box) Restyle(styles style.Map)

Restyle adopts current paint styles without rebuilding geometry.

func (*Box) ScrollportBox

func (b *Box) ScrollportBox() Rect

ScrollportBox excludes classic scrollbar gutters from the padding box.

func (*Box) SetCachedPaintHash

func (b *Box) SetCachedPaintHash(hash uint64)

func (*Box) UpdateInlineBackgrounds

func (b *Box) UpdateInlineBackgrounds(styles style.Map)

func (*Box) Viewport

func (box *Box) Viewport() Rect

Viewport returns the document viewport on the root box. Descendant boxes have no viewport payload and return a zero rectangle.

type Cache

type Cache struct {
	Root *Box

	// Changed contains boxes needing render synchronization: reflowed or
	// translated boxes, plus ancestors whose descendant bounds may have changed.
	// Each box appears once per pass; callers can sort by current tree depth.
	Changed []*Box
	// Removed contains boxes retired by this topology pass.
	Removed []*Box

	// Reordered contains flex containers whose child order actually changed.
	Reordered []*Box

	Work Work

	// ReserveScrollbarSpace selects classic scrollbars for this document.
	ReserveScrollbarSpace bool
	// contains filtered or unexported fields
}

Cache owns a retained layout tree and scratch storage for one document. Styles and DOM mutations are explicit inputs; callers must supply all nodes whose content or geometry changed, including inherited style changes.

func (*Cache) MaintainCache

func (cache *Cache) MaintainCache()

MaintainCache releases historical workspace peaks after sustained underuse. It is also safe between updates, after consumers finish using Changed/Removed.

func (*Cache) Restyle

func (cache *Cache) Restyle(nodes []*dom.Node, styles style.Map)

Restyle repoints retained boxes and fragments at the instances the cascade chose for changed nodes. Interning can move a node to another pointer.

func (*Cache) Update

func (cache *Cache) Update(root *dom.Node, styles style.Map, face, boldFace *font.Face, width, height float64, dirty, reordered []*dom.Node, topology, force bool) (*Box, error)

Update reconciles topology only when needed, then propagates changed layout inputs through the existing formatting algorithm. Force invalidates all geometry for environment/resource changes. Reordered nodes only require sorting their retained flex parent; topology handles DOM/display changes.

type ControlFragment

type ControlFragment struct {
	Node           *dom.Node
	Style          *style.ComputedStyle
	TextFragments  []TextFragment
	ImageFragments []ImageFragment
	Rect           Rect
	Content        Rect
	Padding        Edges
	Border         Edges
	Line           int
}

type Edges

type Edges struct {
	Top    float64
	Right  float64
	Bottom float64
	Left   float64
}

type GlyphFragment

type GlyphFragment = font.PositionedGlyph

type ImageFragment

type ImageFragment struct {
	Node  *dom.Node
	Style *style.ComputedStyle
	Rect  Rect
	Line  int
}

type InlineBackground

type InlineBackground struct {
	Node  *dom.Node
	Style *style.ComputedStyle
	Rect  Rect
	Line  int
}

Inline backgrounds follow the fragments on each line, not the containing block. One run includes nested syntax spans and intervening whitespace.

type Rect

type Rect struct {
	X      float64
	Y      float64
	Width  float64
	Height float64
}

type TextFragment

type TextFragment struct {
	Node   *dom.Node
	Style  *style.ComputedStyle
	Text   string
	Glyphs []GlyphFragment
	Rect   Rect
	Line   int
}

type TextLayoutOptions

type TextLayoutOptions struct {
	Context            *layoutContext
	Face               *font.Face
	StyleMap           style.Map
	Reuse              *Box
	InlineBoxes        map[*dom.Node]*Box
	Node               *dom.Node
	FlowBoxes          []*Box
	InlineBoxFragments []inlineBoxFragment
	AbsoluteContaining Rect
	Width              float64
	FlowHeight         float64
	ContentHeight      float64
	OriginY            float64
	OriginX            float64
}

type Work

type Work struct {
	Visited, Reflowed, Reused, Translated, Created int
	LocalFlexReflows                               int
	TopologyVisited, OrderContainers               int
}

Work counts formatting calls separately from reused and translated subtrees. A reused subtree is counted once, without visiting its descendants.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL