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 IndefiniteHeights(s css.Style) css.Style
- func Physical(r Rect, scale float64) (x, y, w, h int)
- type Arena
- 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.
func Hit ¶
Hit returns the frontmost node ID whose border box contains the logical point. Ancestor content clips constrain descendants, but not the ancestor border itself.
func IndefiniteHeights ¶ added in v0.7.0
IndefiniteHeights returns s with percentage height, min-height and max-height replaced by auto (no constraint), for a root whose containing height is not known, such as a surface that does not exist yet.
Types ¶
type Arena ¶ added in v0.6.1
type Arena struct {
// contains filtered or unexported fields
}
Arena holds the result tree and display storage of one Output, so a steady layout reuses it instead of allocating. An Output stays valid until its arena is passed to Layout again; alternate two arenas to keep the previous Output readable while building the next.
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
// Rect, when HasRect is set on a direct child of a Stack, is the child's
// border-box geometry relative to the Stack's content box. It replaces the
// child's authored width, height and margin; it is ignored elsewhere.
// A flex-styled Stack with a visible Rect child is rejected.
Rect Rect
HasRect bool
}
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 Options ¶
Options provide logical viewport size and an optional text shaping engine. Arena, when set, supplies reusable storage for the Output.
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.
type Size ¶
type Size struct{ W, H float64 }
func Natural ¶ added in v0.7.0
Natural returns the border-box size root takes when it is not stretched: the widest and tallest envelope of its content plus its padding and border, honoring explicit width, height, min and max like Layout. Text wraps at options.Width minus the root margins, but the width may still exceed options.Width when content cannot wrap (a long word, an unwrapped text, an explicit width): callers clamp. The root's own margins are not part of the result. Percentage height, min-height and max-height of root are treated as auto, as for nested nodes (CSS: the containing height is indefinite), so options.Height has no effect.