layout

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package layout builds a simple visual tree from the Growse DOM.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyAnimatedStyles

func ApplyAnimatedStyles(tree *Tree, styles stylemodel.Map)

ApplyAnimatedStyles applies paint and hit-test state to an existing layout tree without changing its geometry. Paint.Build and HitTest consequently observe the exact same transform matrix.

func HitTest

func HitTest(tree *Tree, x, y float32) (dom.NodeID, bool)

HitTest returns the deepest visible DOM node at document coordinates.

Types

type BorderRadii

type BorderRadii struct {
	TopLeft, TopRight, BottomRight, BottomLeft CornerRadius
}

BorderRadii contains resolved radii in clockwise order.

type Box

type Box struct {
	Order      int
	StackingID int
	NodeID     dom.NodeID
	Tag        string
	Text       string
	Input      bool
	Multiline  bool
	Select     bool
	Options    []forms.Option
	Selected   int
	Checkable  bool
	Checked    bool
	InputType  string
	Disabled   bool
	ReadOnly   bool
	Button     bool

	X        float32
	Y        float32
	Width    float32
	Height   float32
	Baseline float32
	Clip     *Rect
	Clips    []ClipRegion
	Opacity  float32

	FontSize        float32
	Bold            bool
	Color           uint32
	Background      uint32
	Decoration      stylemodel.TextDecorationLine
	DecorationColor uint32
	TextShadows     []stylemodel.Shadow
	Transform       stylemodel.Matrix
	Hidden          bool
	Runs            []TextRun
}

Box is one line of visible page content.

func (Box) Rect

func (box Box) Rect() Rect

type ClipRegion

type ClipRegion struct {
	Rect
	Radius BorderRadii
}

ClipRegion is one nested rectangular or rounded clipping boundary.

type CornerRadius

type CornerRadius struct{ X, Y float32 }

CornerRadius is one resolved elliptical radius in CSS pixels.

type Decoration

type Decoration struct {
	Order      int
	StackingID int
	NodeID     dom.NodeID
	Rect
	Background    uint32
	Image         stylemodel.BackgroundImage
	Layers        []stylemodel.BackgroundLayer
	Repeat        stylemodel.BackgroundRepeat
	Position      stylemodel.BackgroundPosition
	Size          stylemodel.BackgroundSize
	Border        stylemodel.Borders
	Radius        BorderRadii
	Opacity       float32
	Clip          *Rect
	Clips         []ClipRegion
	BoxShadows    []stylemodel.Shadow
	Outline       stylemodel.BorderSide
	OutlineOffset float32
	Transform     stylemodel.Matrix
	Hidden        bool
}

Decoration is the border-box visual of one element. It is kept separately from line boxes so backgrounds can be painted before descendant content.

type PaintEntry

type PaintEntry struct {
	Order, StackingID         int
	BoxIndex, DecorationIndex int
}

PaintEntry references one visual in final forward paint order.

type Rect

type Rect struct {
	X, Y, Width, Height float32
}

Rect is a document-coordinate clipping rectangle.

type StackingContext

type StackingContext struct {
	Parent    int
	NodeID    dom.NodeID
	ZIndex    int
	Order     int
	Opacity   float32
	Offscreen bool
}

StackingContext records atomic paint-order ownership.

type TextRun

type TextRun struct {
	NodeID dom.NodeID
	Tag    string
	Text   string
	Width  float32

	FontSize        float32
	Bold            bool
	Color           uint32
	Background      uint32
	Baseline        float32
	Decoration      stylemodel.TextDecorationLine
	DecorationColor uint32
	Opacity         float32
	TextShadows     []stylemodel.Shadow
}

TextRun is a continuously styled fragment inside one line box.

type Tree

type Tree struct {
	Width            float32
	Height           float32
	Background       uint32
	Decorations      []Decoration
	Boxes            []Box
	ScrollWidth      float32
	ScrollHeight     float32
	StackingContexts []StackingContext
	Parents          map[dom.NodeID]dom.NodeID
	Bounds           map[dom.NodeID]Rect
}

Tree is the result of laying out one document at a specific viewport width.

func Build

func Build(document *dom.Document, computed stylemodel.Map, viewportWidth float32) *Tree

Build creates a vertical block layout with a minimal inline text flow.

func BuildWithScroll

func BuildWithScroll(document *dom.Document, computed stylemodel.Map, viewportWidth, viewportHeight, scrollX, scrollY float32) *Tree

BuildWithScroll lays out viewport-attached and sticky elements at a scroll offset.

func BuildWithViewport

func BuildWithViewport(document *dom.Document, computed stylemodel.Map, viewportWidth, viewportHeight float32) *Tree

BuildWithViewport lays out a document with definite viewport dimensions.

func Clone

func Clone(tree *Tree) *Tree

Clone returns a frame-local copy of a layout tree. Geometry can be cached while ApplyAnimatedStyles mutates paint and hit-test state on the copy.

func (*Tree) OrderedPaintEntries

func (t *Tree) OrderedPaintEntries() []PaintEntry

OrderedPaintEntries returns the shared paint and hit-test ordering.

Jump to

Keyboard shortcuts

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