Documentation
¶
Overview ¶
Package layout computes logical-pixel boxes and an ordered, serializable paint list. Input nodes and CSS styles are borrowed for one synchronous Layout call.
Index ¶
- Variables
- func AlignOffset(align css.Keyword, direction di.Direction, contentW, lineW float64) float64
- func Hit(r *Result, x, y float64) string
- func Physical(r Rect, scale float64) (x, y, w, h int)
- type Command
- type Edges
- type Glyph
- type Kind
- type Measure
- type Node
- type Options
- type Output
- type Rect
- type Result
- type Run
- type Size
Constants ¶
This section is empty.
Variables ¶
var ErrDepth = errors.New("layout: tree depth exceeds 256")
Functions ¶
func AlignOffset ¶
AlignOffset is the horizontal offset of a line of width lineW inside a content box of width contentW under text-align and the line's direction.
Types ¶
type Command ¶
type Command struct {
Op string
ID string
Rect Rect
Color css.Color
Opacity float64
Widths Edges
Colors css.ColorSides
Radii [4]float64
Shadow *css.Shadow `json:",omitempty"`
Text string `json:",omitempty"`
Runs []Run `json:",omitempty"`
Image image.Image `json:"-"`
}
Command is a paint operation. Text line ranges refer to rune offsets in Text; image pixels are borrowed and excluded from serialized display lists.
type Edges ¶
type Edges struct{ Top, Right, Bottom, Left float64 }
Edges are in top/right/bottom/left order.
type Kind ¶
type Kind string
Kind selects intrinsic and container behavior. CSS display:none suppresses all kinds; display:flex takes precedence over Kind, and row/column flex defaults are overridable.
type Measure ¶
Measure receives the available content width (zero means unbounded), and must return finite logical dimensions and optionally shaped lines. It may return an error. TextEngine, when supplied, is used for Text nodes without an explicit callback.
type Node ¶
type Node struct {
ID string
Kind Kind
Style *css.Style
Children []*Node
Content string
ImageSize Size
Image image.Image `json:"-"`
Measure Measure `json:"-"`
ScrollX, ScrollY float64
NoWrap bool // measure text at unbounded width; useful for single-line editors
EditorScroll bool // clip and clamp own text on both axes, without child scrolling
}
Node has no parent pointers or renderer resources. ID identifies hit targets and display commands; callers must supply stable, unique IDs if they need identity. ImageSize is the decoded image's intrinsic size; image ownership remains with caller. Image is borrowed through painting. Treat it as immutable while passed to Image: pass a new image value to change pixels. Renderer cache identity requires a comparable image.Image interface value (for example, *image.RGBA).
type Rect ¶
type Rect struct{ X, Y, W, H float64 }
Rect uses logical pixels, including fractional positions.
type Result ¶
type Result struct {
ID string
Kind Kind
Border, Content, Clip Rect
Margin, Padding, BorderWidths Edges
ContentSize Size
ScrollX, ScrollY float64
Lines []text.Line `json:"-"`
Children []*Result
Clipped bool
}
Result is a detached layout snapshot. Style is deliberately not retained.