goda

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 6 Imported by: 0

README

Goda

Go Reference Go Report Card

Goda is a pure Go port of Facebook's Yoga layout engine. It implements CSS Flexbox for calculating positions and dimensions of UI elements, making it ideal for custom UI frameworks, game UIs, image generation, and GUI toolkits.

Features

  • Pure Go — zero CGo, zero C dependencies
  • CSS Flexbox — flex-direction, justify-content, align-items, flex-wrap, gap, padding, margin, border, aspect-ratio, and more
  • Fluent Builder API — all setters return *Node for chaining
  • CSS String & Map API — parse CSS-like syntax to configure nodes
  • QML-like RenderFrom — declarative tree-building from extended CSS syntax
  • Node identity — optional id and classes on every node
  • Layout Output — single LayoutOut() call to get position, size, margins, borders, and padding
  • rem/em support — CSS length units resolved against font-size estimates
  • Pixel grid rounding — configurable point scale factor
  • Extensible — custom measure functions, baseline functions, clone callbacks

Installation

go get github.com/raitucarp/goda

Quick Start

package main

import (
    "fmt"
    goda "github.com/raitucarp/goda"
)

func main() {
    // Builder pattern
    root := goda.New().
        SetWidth(800).
        SetHeight(600).
        SetFlexDirection(goda.FlexDirectionRow).
        SetPadding(goda.EdgeAll, 16).
        SetGap(goda.GutterAll, 8)

    child := goda.New().
        SetWidth(100).
        SetHeight(50).
        SetFlexGrow(1)

    root.InsertChildNode(child, 0)

    // Calculate layout
    goda.CalculateNodeLayout(root, 800, 600, goda.DirectionLTR)

    // Read results
    lo := child.LayoutOut()
    fmt.Printf("Position: (%.0f, %.0f) Size: %.0fx%.0f\n",
        lo.Left, lo.Top, lo.Width, lo.Height)
}
CSS String API
root := goda.New().ApplyStyleString(`
    display: flex;
    flex-direction: row;
    width: 800;
    height: 600;
    padding: 16;
    gap: 8;
`)

child := goda.New().ApplyStyle(map[string]string{
    "width":        "100",
    "height":       "50",
    "flex-grow":    "1",
    "align-self":   "center",
})
QML-like RenderFrom
source := `
    .card {
        display: flex;
        flex-direction: column;
        padding: 12;
    }

    #root[card] {
        width: 800; height: 600; gap: 8;

        #header {
            height: 64; flex-shrink: 0;
        }

        #body {
            flex: 1;
        }
    }
`
roots, err := goda.RenderFrom(source)
root := roots[0]
goda.CalculateNodeLayout(root, 800, 600, goda.DirectionLTR)

// ExportAs round-trips back to the same format
// out := root.ExportAs()
// roots2, _ := goda.RenderFrom(out)
Node Identity
node := goda.New("my_id")
node.AddClass("card")
node.AddClass("highlight")

fmt.Println(node.GetID())        // "my_id"
fmt.Println(node.HasClass("card")) // true
fmt.Println(node.GetClasses())    // ["card", "highlight"]
Chaining Builder + CSS
card := goda.New().
    ApplyStyleString("width: 180; padding: 8;").
    SetFlexGrow(1).
    ApplyStyle(map[string]string{"align-self": "center"})

Supported Properties

Category Properties
Layout display, direction, position, overflow, box-sizing
Flex flex-direction, flex-wrap, justify-content, justify-items, justify-self, align-content, align-items, align-self
Flex factors flex, flex-grow, flex-shrink, flex-basis
Dimensions width, height, min-width, max-width, min-height, max-height
Spacing margin, margin-top/right/bottom/left/horizontal/vertical, padding, padding-*
Border & Gap border, border-top/right/bottom/left, gap, column-gap, row-gap
Other aspect-ratio

Values accept numbers (100, 100px), percentages (50%), rem/em (2rem, 1.5em), and keywords (auto, flex, center, max-content, fit-content, stretch).

Running Tests

go test ./...

Examples

See examples/ecommerce/ for a rendered e-commerce page using fogleman/gg with 4 build modes:

cd examples/ecommerce
go run .
# Outputs 4 identical layouts built 4 different ways
Showcase — E-Commerce Page (800x1080)
Builder CSS String
builder cssstring
CSS Map RenderFrom
cssmap renderfrom

All four images render identically — built with builder, CSS string, CSS map, and declarative RenderFrom syntax respectively.

License

MIT — see LICENSE for details.

Acknowledgments

Goda is a Go port of Facebook's Yoga layout engine. The algorithm and API design follow Yoga's architecture while adapting to Go idioms (GC-managed memory, builder patterns, native error handling).

Documentation

Overview

Package goda is a CSS Flexbox layout engine written in pure Go. It calculates positions and dimensions for UI elements based on CSS Flexbox properties such as flex-direction, justify-content, align-items, and more.

Node Identity

Nodes carry an optional id string and a list of class names:

node := goda.New("my_id")
node.AddClass("highlight")
node.AddClass("card")
fmt.Println(node.GetID())       // "my_id"
fmt.Println(node.HasClass("card")) // true

QML-like Extended CSS Syntax

Use RenderFrom to build an entire node tree from a string:

source := `
    .card {
        display: flex;
        flex-direction: column;
        padding: 12;
    }

    #root[card] {
        width: 800;
        height: 600;
        gap: 8;

        #header {
            height: 64;
            flex-shrink: 0;
        }

        #body {
            flex: 1;
        }
    }
`
roots, err := goda.RenderFrom(source)
root := roots[0]
goda.CalculateNodeLayout(root, 800, 600, goda.DirectionLTR)

Use ExportAs to serialize back to a string:

out := root.ExportAs()
roots2, _ := goda.RenderFrom(out) // round-trips

Builder Pattern

All property setters return the receiver (*Node), enabling a fluent builder pattern for constructing layout trees:

root := goda.New().
    SetWidth(800).
    SetHeight(600).
    SetFlexDirection(goda.FlexDirectionRow).
    SetJustifyContent(goda.JustifySpaceBetween).
    SetAlignItems(goda.AlignCenter).
    SetPadding(goda.EdgeAll, 16).
    SetGap(goda.GutterAll, 8)

child := goda.New().
    SetWidth(100).
    SetHeight(50).
    SetFlexGrow(1).
    SetMargin(goda.EdgeAll, 8).
    SetAlignSelf(goda.AlignCenter)

root.InsertChildNode(child, 0)
goda.CalculateNodeLayout(root, 800, 600, goda.DirectionLTR)

fmt.Println(child.GetLeft(), child.GetTop())
fmt.Println(child.GetWidth(), child.GetHeight())

Consuming Layout Results

After CalculateNodeLayout, use LayoutOut() to get all computed layout values in a single struct designed for GUI library consumption:

goda.CalculateNodeLayout(root, 800, 600, goda.DirectionLTR)
lo := root.LayoutOut()

// All at once:
renderer.DrawBox(lo.Left, lo.Top, lo.Width, lo.Height)
renderer.SetMargins(lo.Margin.Top, lo.Margin.Right, lo.Margin.Bottom, lo.Margin.Left)

// Individual accessors still work:
fmt.Printf("Pos:(%f,%f) Size:%fx%f Overflow:%v Dir:%v\n",
    lo.Left, lo.Top, lo.Width, lo.Height, lo.HadOverflow, lo.Direction)

// Child layout:
childLo := child.LayoutOut()
renderer.DrawBox(childLo.Left, childLo.Top, childLo.Width, childLo.Height)

CSS String Properties

Use ParseStyle to convert a CSS-like string into a map, or ApplyStyleString to parse and apply in one call:

css := `
    display: flex;
    flex-direction: row;
    width: 800;
    height: 600;
    padding: 16;
    gap: 8;
`
root := goda.New().ApplyStyleString(css)

// Or parse first, inspect, then apply:

props := goda.ParseStyle(css)
root.ApplyStyle(props)

Declarations use "key: value" syntax separated by ";" or newlines. Lines starting with "//" or "/*" are treated as comments and ignored. Unknown CSS properties (e.g. "color", "font-size") are silently skipped.

Length values support px, rem, and em units. rem resolves against the root node's font size estimate; em resolves against the node's own estimate (default 16 for both). Use SetFontSizeEstimate to customize:

root := goda.New().SetFontSizeEstimate(14)
child := goda.New().
    ApplyStyleString("width: 10rem; padding: 2em;").
    SetFontSizeEstimate(12) // em=12px here, rem=14px from root

CSS Map Properties

Use ApplyStyle with a map[string]string to set multiple properties at once:

root := goda.New().ApplyStyle(map[string]string{
    "display":         "flex",
    "flex-direction":  "row",
    "justify-content": "space-between",
    "align-items":     "center",
    "width":           "800",
    "height":          "600",
    "padding":         "16",
    "gap":             "8",
})

All three APIs chain seamlessly with the builder pattern:

child := goda.New().
    ApplyStyleString("width: 100; height: 50;").
    SetFlexGrow(1).
    ApplyStyle(map[string]string{"align-self": "center"})

Supported CSS Properties

Layout:

display        "flex" | "none" | "contents" | "grid"
direction      "ltr" | "rtl" | "inherit"
position       "static" | "relative" | "absolute"
overflow       "visible" | "hidden" | "scroll"
box-sizing     "border-box" | "content-box"

Flex:

flex-direction  "row" | "row-reverse" | "column" | "column-reverse"
flex-wrap       "nowrap" | "wrap" | "wrap-reverse"
justify         alias for justify-content
justify-content "flex-start" | "center" | "flex-end" | "space-between" |
                "space-around" | "space-evenly" | "start" | "end"
justify-items   same as justify-content + "stretch" | "auto"
justify-self    same as justify-content + "stretch" | "auto"
align-content   same as align-items
align-items     "flex-start" | "center" | "flex-end" | "stretch" |
                "baseline" | "start" | "end" | "auto"
align-self      same as align-items + "auto"

Flex factors:

flex        number
flex-grow   number
flex-shrink number
flex-basis  number | "auto" | number% | "max-content" | "fit-content" | "stretch"

Dimensions:

width      number | "auto" | number% | numberpx | "max-content" | "fit-content" | "stretch"
height     same as width
min-width  same as width
max-width  same as width
min-height same as height
max-height same as height

Spacing:

margin             number
margin-top         number
margin-right       number
margin-bottom      number
margin-left        number
margin-horizontal  number
margin-vertical    number
padding            number
padding-top        number
padding-right      number
padding-bottom     number
padding-left       number
padding-horizontal number
padding-vertical   number

Border & Gap:

border         number
border-top     number
border-right   number
border-bottom  number
border-left    number
gap            number
column-gap     number
row-gap        number

Other:

aspect-ratio number

Complete Example

config := goda.ConfigNewDefault()
config.SetPointScaleFactor(2.0)

root := goda.NewWithConfig(config).ApplyStyleString(`
    width: 800;
    height: 600;
    flex-direction: column;
    justify-content: center;
    align-items: stretch;
    padding: 20;
    gap: 12;
`)

header := goda.New().ApplyStyleString("height: 60;")

body := goda.New().
    SetFlexGrow(1).
    SetFlexDirection(goda.FlexDirectionRow).
    SetGap(goda.GutterAll, 16)

sidebar := goda.New().
    ApplyStyle(map[string]string{"width": "200"}).
    SetFlexShrink(0)

content := goda.New().
    SetFlexGrow(1).
    SetMinWidth(300)

root.InsertChildNode(header, 0)
root.InsertChildNode(body, 1)
body.InsertChildNode(sidebar, 0)
body.InsertChildNode(content, 1)

goda.CalculateNodeLayout(root, 800, 600, goda.DirectionLTR)

Index

Constants

View Source
const (
	LayoutPassInitial = iota
	LayoutPassAbsLayout
	LayoutPassStretch
	LayoutPassMultilineStretch
	LayoutPassFlexLayout
	LayoutPassMeasureChild
	LayoutPassAbsMeasureChild
	LayoutPassFlexMeasure
	LayoutPassGridLayout
	LayoutPassCount
)

Variables

View Source
var (
	ValueZero      = Value{0, UnitPoint}
	ValueUndefined = Value{Undefined, UnitUndefined}
	ValueAuto      = Value{Undefined, UnitAuto}
)
View Source
var Undefined = float32(math.NaN())

Undefined is the NaN sentinel value used throughout the layout engine to represent unset or "auto" dimensions.

Functions

func CalculateLayout

func CalculateLayout(node *Node, ownerWidth, ownerHeight float32, ownerDirection Direction)

CalculateLayout is the public entry point for performing layout on a node tree.

func CalculateLayoutInternal

func CalculateLayoutInternal(node *Node, availableWidth, availableHeight float32, ownerDirection Direction,
	widthMode, heightMode SizingMode, ownerWidth, ownerHeight float32, performLayout bool,
	reason int, layoutMarkerData *LayoutData, depth int, generationCount uint32) bool

CalculateLayoutInternal is the caching wrapper around the layout implementation.

func CalculateNodeLayout

func CalculateNodeLayout(node *Node, availableWidth, availableHeight float32, ownerDirection Direction)

CalculateNodeLayout performs layout on the given node tree.

func IsUndefinedFloat

func IsUndefinedFloat(v float32) bool

IsUndefinedFloat returns true if v is the NaN sentinel value.

func ParseStyle

func ParseStyle(css string) map[string]string

ParseStyle parses a CSS-like string into a map of property-value pairs. Declarations are separated by ";" or newlines. Keys and values are split by ":". Lines starting with "//" or "/*" are treated as comments. Only supported properties are included in the result.

Example:

props := goda.ParseStyle(`
    display: flex;
    flex-direction: row;
    width: 800;
    height: 600;
    padding: 16;
    gap: 8;
`)
node.ApplyStyle(props)

func RoundValueToPixelGrid

func RoundValueToPixelGrid(value float64, pointScaleFactor float64, forceCeil, forceFloor bool) float32

RoundValueToPixelGrid rounds a value to the nearest pixel grid boundary.

Types

type Align

type Align int

Align represents the CSS align-items/align-self/align-content values.

const (
	AlignAuto Align = iota
	AlignFlexStart
	AlignCenter
	AlignFlexEnd
	AlignStretch
	AlignBaseline
	AlignSpaceBetween
	AlignSpaceAround
	AlignSpaceEvenly
	AlignStart
	AlignEnd
)

func (Align) String

func (a Align) String() string

type BaselineFunc

type BaselineFunc func(node *Node, width, height float32) float32

BaselineFunc is the signature for a custom baseline function.

type BoxSizing

type BoxSizing int

BoxSizing represents the CSS box-sizing property.

const (
	BoxSizingBorderBox BoxSizing = iota
	BoxSizingContentBox
)

func (BoxSizing) String

func (b BoxSizing) String() string

type CloneNodeFunc

type CloneNodeFunc func(oldNode *Node, owner *Node, childIndex int) *Node

CloneNodeFunc is the signature for a custom node cloning callback.

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config holds global layout configuration.

func ConfigNew

func ConfigNew(logger LoggerFunc) *Config

ConfigNew creates a new Config with the given logger.

func ConfigNewDefault

func ConfigNewDefault() *Config

ConfigNewDefault creates a new Config with the default no-op logger.

func GetDefaultConfig

func GetDefaultConfig() *Config

func NewConfig

func NewConfig(logger LoggerFunc) *Config

func (*Config) AddErrata

func (c *Config) AddErrata(errata Errata)

func (*Config) CloneNode

func (c *Config) CloneNode(node *Node, owner *Node, childIndex int) *Node

func (*Config) GetContext

func (c *Config) GetContext() interface{}

func (*Config) GetEnabledExperiments

func (c *Config) GetEnabledExperiments() uint64

func (*Config) GetErrata

func (c *Config) GetErrata() Errata

func (*Config) GetPointScaleFactor

func (c *Config) GetPointScaleFactor() float32

func (*Config) GetVersion

func (c *Config) GetVersion() uint32

func (*Config) HasErrata

func (c *Config) HasErrata(errata Errata) bool

func (*Config) IsExperimentalFeatureEnabled

func (c *Config) IsExperimentalFeatureEnabled(feature ExperimentalFeature) bool

func (*Config) Log

func (c *Config) Log(node *Node, level LogLevel, format string, args ...interface{})

func (*Config) RemoveErrata

func (c *Config) RemoveErrata(errata Errata)

func (*Config) SetCloneNodeCallback

func (c *Config) SetCloneNodeCallback(callback CloneNodeFunc)

func (*Config) SetContext

func (c *Config) SetContext(ctx interface{})

func (*Config) SetErrata

func (c *Config) SetErrata(errata Errata)

func (*Config) SetExperimentalFeatureEnabled

func (c *Config) SetExperimentalFeatureEnabled(feature ExperimentalFeature, enabled bool)

func (*Config) SetLogger

func (c *Config) SetLogger(logger LoggerFunc)

func (*Config) SetPointScaleFactor

func (c *Config) SetPointScaleFactor(factor float32)

func (*Config) SetUseWebDefaults

func (c *Config) SetUseWebDefaults(use bool)

func (*Config) SetUseWebDefaultsBool

func (c *Config) SetUseWebDefaultsBool(b bool)

func (*Config) UseWebDefaults

func (c *Config) UseWebDefaults() bool

type Dimension

type Dimension int

Dimension represents width or height axis.

const (
	DimensionWidth Dimension = iota
	DimensionHeight
)

func (Dimension) String

func (d Dimension) String() string

type Direction

type Direction int

Direction represents the text direction (LTR/RTL).

const (
	DirectionInherit Direction = iota
	DirectionLTR
	DirectionRTL
)

func (Direction) String

func (d Direction) String() string

type DirtiedFunc

type DirtiedFunc func(node *Node)

DirtiedFunc is called when a node becomes dirty.

type Display

type Display int

Display represents the CSS display property.

const (
	DisplayFlex Display = iota
	DisplayNone
	DisplayContents
	DisplayGrid
)

func (Display) String

func (d Display) String() string

type Edge

type Edge int

Edge represents a CSS edge (left, top, right, bottom, start, end, etc.).

const (
	EdgeLeft Edge = iota
	EdgeTop
	EdgeRight
	EdgeBottom
	EdgeStart
	EdgeEnd
	EdgeHorizontal
	EdgeVertical
	EdgeAll
)

func (Edge) String

func (e Edge) String() string

type Edges

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

Edges holds the computed margin, border, or padding values for all four sides.

type Errata

type Errata int

Errata is a bitmask of legacy behavior flags.

const (
	ErrataNone                                         Errata = 0
	ErrataStretchFlexBasis                             Errata = 1 << 0
	ErrataAbsolutePositionWithoutInsetsExcludesPadding Errata = 1 << 1
	ErrataAbsolutePercentAgainstInnerSize              Errata = 1 << 2
	ErrataMinSizeUndefinedInsteadOfAuto                Errata = 1 << 3
	ErrataAll                                          Errata = 1<<31 - 1
	ErrataClassic                                      Errata = ErrataAll & ^ErrataMinSizeUndefinedInsteadOfAuto
)

type ExperimentalFeature

type ExperimentalFeature int

ExperimentalFeature represents feature flags for optional behavior.

const (
	ExperimentalFeatureWebFlexBasis ExperimentalFeature = iota
	ExperimentalFeatureFixFlexBasisFitContent
)

type FlexDirection

type FlexDirection int

FlexDirection represents the CSS flex-direction property.

const (
	FlexDirectionColumn FlexDirection = iota
	FlexDirectionColumnReverse
	FlexDirectionRow
	FlexDirectionRowReverse
)

func (FlexDirection) String

func (f FlexDirection) String() string

type FlexLine

type FlexLine struct {
	ItemsInFlow         []*Node
	SizeConsumed        float32
	NumberOfAutoMargins int
	Layout              FlexLineRunningLayout
}

FlexLine represents a single line of flex items.

type FlexLineRunningLayout

type FlexLineRunningLayout struct {
	TotalFlexGrowFactors         float32
	TotalFlexShrinkScaledFactors float32
	RemainingFreeSpace           float32
	MainDim                      float32
	CrossDim                     float32
}

FlexLineRunningLayout holds transient layout state for a flex line.

type FloatOptional

type FloatOptional struct {
	// contains filtered or unexported fields
}

FloatOptional represents an optional float32 value that may be undefined.

func NewFloatOptional

func NewFloatOptional(v float32) FloatOptional

func (FloatOptional) Equals

func (f FloatOptional) Equals(other FloatOptional) bool

func (FloatOptional) IsDefined

func (f FloatOptional) IsDefined() bool

func (FloatOptional) IsUndefined

func (f FloatOptional) IsUndefined() bool

func (FloatOptional) Unwrap

func (f FloatOptional) Unwrap() float32

func (FloatOptional) UnwrapOrDefault

func (f FloatOptional) UnwrapOrDefault(defaultValue float32) float32

type GridLine

type GridLine struct {
	Type    GridLineType
	Integer int32
}

GridLine represents a CSS Grid line placement value.

func GridLineAuto

func GridLineAuto() GridLine

func GridLineFromInteger

func GridLineFromInteger(value int32) GridLine

func GridLineSpan

func GridLineSpan(value int32) GridLine

func (GridLine) IsAuto

func (g GridLine) IsAuto() bool

func (GridLine) IsInteger

func (g GridLine) IsInteger() bool

func (GridLine) IsSpan

func (g GridLine) IsSpan() bool

type GridLineType

type GridLineType int

GridLineType describes the type of a CSS Grid line placement.

const (
	GridLineTypeAuto GridLineType = iota
	GridLineTypeInteger
	GridLineTypeSpan
)

type GridTrackList

type GridTrackList []GridTrackSize

GridTrackList is a slice of GridTrackSize representing a track listing.

type GridTrackSize

type GridTrackSize struct {
	MinSizingFunction  StyleSizeLength
	MaxSizingFunction  StyleSizeLength
	BaseSize           float32
	GrowthLimit        float32
	InfinitelyGrowable bool
}

GridTrackSize represents a CSS Grid track sizing function.

func GridTrackSizeAuto

func GridTrackSizeAuto() GridTrackSize

func GridTrackSizeFr

func GridTrackSizeFr(fraction float32) GridTrackSize

func GridTrackSizeLength

func GridTrackSizeLength(points float32) GridTrackSize

func GridTrackSizeMinmax

func GridTrackSizeMinmax(minFn, maxFn StyleSizeLength) GridTrackSize

func GridTrackSizePercent

func GridTrackSizePercent(percentage float32) GridTrackSize

type GridTrackType

type GridTrackType int

GridTrackType describes a CSS Grid track sizing function type.

const (
	GridTrackTypeAuto GridTrackType = iota
	GridTrackTypePoints
	GridTrackTypePercent
	GridTrackTypeFr
	GridTrackTypeMinmax
)

func (GridTrackType) String

func (g GridTrackType) String() string

type Gutter

type Gutter int

Gutter represents a CSS Grid gap axis.

const (
	GutterColumn Gutter = iota
	GutterRow
	GutterAll
)

func (Gutter) String

func (g Gutter) String() string

type Justify

type Justify int

Justify represents CSS justify-content/justify-items/justify-self values.

const (
	JustifyAuto Justify = iota
	JustifyFlexStart
	JustifyCenter
	JustifyFlexEnd
	JustifySpaceBetween
	JustifySpaceAround
	JustifySpaceEvenly
	JustifyStretch
	JustifyStart
	JustifyEnd
)

func (Justify) String

func (j Justify) String() string

type LayoutData

type LayoutData struct {
	Layouts                int
	Measures               int
	MaxMeasureCache        uint32
	CachedLayouts          int
	CachedMeasures         int
	MeasureCallbacks       int
	MeasureCallbackReasons [LayoutPassCount]int
}

LayoutData tracks layout performance counters.

type LayoutOut

type LayoutOut struct {
	Rect
	Margin      Edges
	Border      Edges
	Padding     Edges
	Direction   Direction
	HadOverflow bool
}

LayoutOut is the public layout output for a node after CalculateNodeLayout. It bundles position, size, box-model edges, and layout metadata into one struct for easy consumption by GUI libraries.

Example:

goda.CalculateNodeLayout(root, 800, 600, goda.DirectionLTR)
lo := root.LayoutOut()
renderer.DrawBox(lo.Left, lo.Top, lo.Width, lo.Height, lo.Margin, lo.Padding)

type LayoutResults

type LayoutResults struct {
	// contains filtered or unexported fields
}

LayoutResults holds the computed layout output for a Node.

func NewLayoutResults

func NewLayoutResults() LayoutResults

func (*LayoutResults) Border

func (l *LayoutResults) Border(edge PhysicalEdge) float32

func (*LayoutResults) Dimension

func (l *LayoutResults) Dimension(axis Dimension) float32

func (*LayoutResults) Direction

func (l *LayoutResults) Direction() Direction

func (*LayoutResults) HadOverflow

func (l *LayoutResults) HadOverflow() bool

func (*LayoutResults) Margin

func (l *LayoutResults) Margin(edge PhysicalEdge) float32

func (*LayoutResults) MeasuredDimension

func (l *LayoutResults) MeasuredDimension(axis Dimension) float32

func (*LayoutResults) Padding

func (l *LayoutResults) Padding(edge PhysicalEdge) float32

func (*LayoutResults) Position

func (l *LayoutResults) Position(edge PhysicalEdge) float32

func (*LayoutResults) RawDimension

func (l *LayoutResults) RawDimension(axis Dimension) float32

func (*LayoutResults) SetBorder

func (l *LayoutResults) SetBorder(edge PhysicalEdge, v float32)

func (*LayoutResults) SetDimension

func (l *LayoutResults) SetDimension(axis Dimension, v float32)

func (*LayoutResults) SetDirection

func (l *LayoutResults) SetDirection(d Direction)

func (*LayoutResults) SetHadOverflow

func (l *LayoutResults) SetHadOverflow(v bool)

func (*LayoutResults) SetMargin

func (l *LayoutResults) SetMargin(edge PhysicalEdge, v float32)

func (*LayoutResults) SetMeasuredDimension

func (l *LayoutResults) SetMeasuredDimension(axis Dimension, v float32)

func (*LayoutResults) SetPadding

func (l *LayoutResults) SetPadding(edge PhysicalEdge, v float32)

func (*LayoutResults) SetPosition

func (l *LayoutResults) SetPosition(edge PhysicalEdge, v float32)

func (*LayoutResults) SetRawDimension

func (l *LayoutResults) SetRawDimension(axis Dimension, v float32)

type LayoutableIterator

type LayoutableIterator struct {
	// contains filtered or unexported fields
}

LayoutableIterator iterates over children of a node that participate in layout, transparently flattening DisplayContents children.

func NewLayoutableIterator

func NewLayoutableIterator(n *Node) *LayoutableIterator

func (*LayoutableIterator) Current

func (it *LayoutableIterator) Current() *Node

func (*LayoutableIterator) Next

func (it *LayoutableIterator) Next() bool

func (*LayoutableIterator) Reset

func (it *LayoutableIterator) Reset(n *Node)

type LogLevel

type LogLevel int

LogLevel represents the severity of a log message.

const (
	LogLevelError LogLevel = iota
	LogLevelWarn
	LogLevelInfo
	LogLevelDebug
	LogLevelVerbose
	LogLevelFatal
)

func (LogLevel) String

func (l LogLevel) String() string

type LoggerFunc

type LoggerFunc func(config *Config, node *Node, level LogLevel, format string, args ...interface{}) int

LoggerFunc is the signature for a custom logger.

var DefaultLogger LoggerFunc = func(config *Config, node *Node, level LogLevel, format string, args ...interface{}) int {
	if level == LogLevelError || level == LogLevelFatal {
		return 0
	}
	return 0
}

DefaultLogger is a no-op logger that suppresses error/fatal messages.

type MeasureFunc

type MeasureFunc func(node *Node, width float32, widthMode MeasureMode, height float32, heightMode MeasureMode) Size

MeasureFunc is the signature for a custom measure function.

type MeasureMode

type MeasureMode int

MeasureMode describes how a measurement constraint is applied.

const (
	MeasureModeUndefined MeasureMode = iota
	MeasureModeExactly
	MeasureModeAtMost
)

func (MeasureMode) String

func (m MeasureMode) String() string

type Node

type Node struct {
	// contains filtered or unexported fields
}

Node is the fundamental unit of the layout tree. Each Node has a Style and computed LayoutResults.

func New

func New(id ...string) *Node

New creates a new Node with default configuration. Optionally accepts an id string as the first argument: New("my_id").

func NewNode

func NewNode() *Node

func NewNodeWithConfig

func NewNodeWithConfig(config *Config) *Node

func NewWithConfig

func NewWithConfig(config *Config) *Node

NewWithConfig creates a new Node with the given configuration.

func RenderFrom

func RenderFrom(source string) ([]*Node, error)

RenderFrom parses an extended CSS / QML-like string and returns the root nodes. Class definitions (e.g. ".myClass { ... }") define reusable style blocks. Node definitions (e.g. "#myId[class1, class2] { ... }") create nodes with optional class references whose styles are applied as defaults.

Children are nested inside braces:

#root {
  width: 800;
  #child {
    flex: 1;
  }
}

Comments (// and /* */) are supported anywhere.

func (*Node) AddClass

func (n *Node) AddClass(class string)

func (*Node) AlwaysFormsContainingBlock

func (n *Node) AlwaysFormsContainingBlock() bool

func (*Node) ApplyStyle

func (n *Node) ApplyStyle(props map[string]string) *Node

ApplyStyle applies CSS-like properties from a map. Keys use kebab-case (e.g. "flex-direction", "justify-content") or camelCase. Values are parsed as CSS values: numbers, percentages ("50%"), or keywords. Unknown properties are silently ignored. Returns the receiver for chaining.

Example:

node.ApplyStyle(map[string]string{
    "display":       "flex",
    "flex-direction": "row",
    "width":         "800",
    "height":        "600",
    "padding":       "16",
    "gap":           "8",
})

func (*Node) ApplyStyleString

func (n *Node) ApplyStyleString(css string) *Node

ApplyStyleString parses a CSS-like string and applies the properties. This is a convenience combining ParseStyle and ApplyStyle. Returns the receiver for chaining.

Example:

node.ApplyStyleString(`
    display: flex;
    flex-direction: row;
    width: 800;
    height: 600;
    padding: 16;
    gap: 8;
`)

func (*Node) Baseline

func (n *Node) Baseline(width, height float32) float32

func (*Node) ClearChildren

func (n *Node) ClearChildren()

func (*Node) Clone

func (n *Node) Clone() *Node

func (*Node) CloneChildrenIfNeeded

func (n *Node) CloneChildrenIfNeeded()

func (*Node) CloneContentsChildrenIfNeeded

func (n *Node) CloneContentsChildrenIfNeeded()

func (*Node) CopyStyleFrom

func (n *Node) CopyStyleFrom(src *Node) *Node

CopyStyleFrom copies all style properties from the source node (deep copy).

func (*Node) DimensionWithMargin

func (n *Node) DimensionWithMargin(axis FlexDirection, widthSize float32) float32

func (*Node) ExportAs

func (n *Node) ExportAs() string

ExportAs serializes the node tree into the same extended CSS format that RenderFrom can parse. Only non-default style properties are included.

func (*Node) GetAlignContent

func (n *Node) GetAlignContent() Align

func (*Node) GetAlignItems

func (n *Node) GetAlignItems() Align

func (*Node) GetAlignSelf

func (n *Node) GetAlignSelf() Align

func (*Node) GetAspectRatio

func (n *Node) GetAspectRatio() float32

func (*Node) GetBorder

func (n *Node) GetBorder(edge Edge) float32

func (*Node) GetBottom

func (n *Node) GetBottom() float32

func (*Node) GetBoxSizing

func (n *Node) GetBoxSizing() BoxSizing

func (*Node) GetChild

func (n *Node) GetChild(index int) *Node

func (*Node) GetChildCount

func (n *Node) GetChildCount() int

func (*Node) GetChildren

func (n *Node) GetChildren() []*Node

func (*Node) GetClasses

func (n *Node) GetClasses() []string

func (*Node) GetConfig

func (n *Node) GetConfig() *Config

func (*Node) GetContext

func (n *Node) GetContext() interface{}

func (*Node) GetDirection

func (n *Node) GetDirection() Direction

func (*Node) GetDirtiedFunc

func (n *Node) GetDirtiedFunc() DirtiedFunc

func (*Node) GetDisplay

func (n *Node) GetDisplay() Display

func (*Node) GetEdgePosition

func (n *Node) GetEdgePosition(edge Edge) Value

func (*Node) GetFlex

func (n *Node) GetFlex() float32

func (*Node) GetFlexBasis

func (n *Node) GetFlexBasis() Value

func (*Node) GetFlexDirection

func (n *Node) GetFlexDirection() FlexDirection

func (*Node) GetFlexGrow

func (n *Node) GetFlexGrow() float32

func (*Node) GetFlexShrink

func (n *Node) GetFlexShrink() float32

func (*Node) GetFlexWrap

func (n *Node) GetFlexWrap() Wrap

func (*Node) GetFontSizeEstimate

func (n *Node) GetFontSizeEstimate() float32

func (*Node) GetGap

func (n *Node) GetGap(gutter Gutter) Value

func (*Node) GetGridColumnEnd

func (n *Node) GetGridColumnEnd() int32

func (*Node) GetGridColumnStart

func (n *Node) GetGridColumnStart() int32

func (*Node) GetGridRowEnd

func (n *Node) GetGridRowEnd() int32

func (*Node) GetGridRowStart

func (n *Node) GetGridRowStart() int32

func (*Node) GetHadOverflow

func (n *Node) GetHadOverflow() bool

func (*Node) GetHasNewLayout

func (n *Node) GetHasNewLayout() bool

func (*Node) GetHeight

func (n *Node) GetHeight() float32

func (*Node) GetHeightValue

func (n *Node) GetHeightValue() Value

func (*Node) GetID

func (n *Node) GetID() string

func (*Node) GetIsReferenceBaseline

func (n *Node) GetIsReferenceBaseline() bool

func (*Node) GetJustifyContent

func (n *Node) GetJustifyContent() Justify

func (*Node) GetJustifyItems

func (n *Node) GetJustifyItems() Justify

func (*Node) GetJustifySelf

func (n *Node) GetJustifySelf() Justify

func (*Node) GetLayout

func (n *Node) GetLayout() *LayoutResults

func (*Node) GetLayoutBorder

func (n *Node) GetLayoutBorder(edge Edge) float32

func (*Node) GetLayoutChildCount

func (n *Node) GetLayoutChildCount() int

func (*Node) GetLayoutDirection

func (n *Node) GetLayoutDirection() Direction

func (*Node) GetLayoutMargin

func (n *Node) GetLayoutMargin(edge Edge) float32

func (*Node) GetLayoutPadding

func (n *Node) GetLayoutPadding(edge Edge) float32

func (*Node) GetLayoutVal

func (n *Node) GetLayoutVal() LayoutResults

func (*Node) GetLeft

func (n *Node) GetLeft() float32

Layout position getters.

func (*Node) GetLineIndex

func (n *Node) GetLineIndex() int

func (*Node) GetMargin

func (n *Node) GetMargin(edge Edge) Value

func (*Node) GetMaxHeight

func (n *Node) GetMaxHeight() Value

func (*Node) GetMaxWidth

func (n *Node) GetMaxWidth() Value

func (*Node) GetMinContentHeight

func (n *Node) GetMinContentHeight() FloatOptional

func (*Node) GetMinContentHeightValue

func (n *Node) GetMinContentHeightValue() float32

func (*Node) GetMinContentWidth

func (n *Node) GetMinContentWidth() FloatOptional

func (*Node) GetMinContentWidthValue

func (n *Node) GetMinContentWidthValue() float32

func (*Node) GetMinHeight

func (n *Node) GetMinHeight() Value

func (*Node) GetMinWidth

func (n *Node) GetMinWidth() Value

func (*Node) GetNodeType

func (n *Node) GetNodeType() NodeType

func (*Node) GetNodeType_Public

func (n *Node) GetNodeType_Public() NodeType

func (*Node) GetOverflow

func (n *Node) GetOverflow() Overflow

func (*Node) GetOwner

func (n *Node) GetOwner() *Node

func (*Node) GetPadding

func (n *Node) GetPadding(edge Edge) Value

func (*Node) GetParent

func (n *Node) GetParent() *Node

func (*Node) GetPositionType

func (n *Node) GetPositionType() PositionType

func (*Node) GetProcessedDimension

func (n *Node) GetProcessedDimension(dim Dimension) StyleSizeLength

func (*Node) GetRawHeight

func (n *Node) GetRawHeight() float32

func (*Node) GetRawWidth

func (n *Node) GetRawWidth() float32

func (*Node) GetResolvedDimension

func (n *Node) GetResolvedDimension(dir Direction, dim Dimension, referenceLength, ownerWidth float32) FloatOptional

func (*Node) GetRight

func (n *Node) GetRight() float32

func (*Node) GetStyle

func (n *Node) GetStyle() Style

func (*Node) GetTop

func (n *Node) GetTop() float32

func (*Node) GetWidth

func (n *Node) GetWidth() float32

func (*Node) GetWidthValue

func (n *Node) GetWidthValue() Value

func (*Node) HasBaselineFunc

func (n *Node) HasBaselineFunc() bool

func (*Node) HasClass

func (n *Node) HasClass(class string) bool

func (*Node) HasContentsChildren

func (n *Node) HasContentsChildren() bool

func (*Node) HasDefiniteLength

func (n *Node) HasDefiniteLength(dim Dimension, ownerSize float32) bool

func (*Node) HasErrata

func (n *Node) HasErrata(errata Errata) bool

func (*Node) HasLayoutableChildren

func (n *Node) HasLayoutableChildren() bool

func (*Node) HasMeasureFunc

func (n *Node) HasMeasureFunc() bool

func (*Node) HasMinContentMeasureFunc

func (n *Node) HasMinContentMeasureFunc() bool

func (*Node) InsertChild

func (n *Node) InsertChild(child *Node, index int)

func (*Node) InsertChildNode

func (n *Node) InsertChildNode(child *Node, index int) *Node

InsertChildNode inserts a child node at the given index. Returns the parent node for chaining.

func (*Node) IsDirty

func (n *Node) IsDirty() bool

func (*Node) IsLayoutDimensionDefined

func (n *Node) IsLayoutDimensionDefined(axis FlexDirection) bool

func (*Node) IsNodeFlexible

func (n *Node) IsNodeFlexible() bool

func (*Node) IsReferenceBaseline

func (n *Node) IsReferenceBaseline() bool

func (*Node) LayoutOut

func (n *Node) LayoutOut() LayoutOut

LayoutOut returns the computed layout as a single convenience struct. Call this after CalculateNodeLayout to get position, dimensions, and box-model edges in one shot.

func (*Node) LayoutableSlice

func (n *Node) LayoutableSlice() []*Node

func (*Node) MarkDirty

func (n *Node) MarkDirty() *Node

MarkDirty marks the node as dirty. Only valid for leaf nodes with measure functions.

func (*Node) MarkDirtyAndPropagate

func (n *Node) MarkDirtyAndPropagate()

func (*Node) Measure

func (n *Node) Measure(availableWidth float32, widthMode MeasureMode, availableHeight float32, heightMode MeasureMode) Size

func (*Node) MeasureMinContent

func (n *Node) MeasureMinContent(availableWidth float32, widthMode MeasureMode, availableHeight float32, heightMode MeasureMode) Size

func (*Node) ProcessDimensions

func (n *Node) ProcessDimensions()

func (*Node) ProcessFlexBasis

func (n *Node) ProcessFlexBasis() StyleSizeLength

func (*Node) RelativePosition

func (n *Node) RelativePosition(axis FlexDirection, dir Direction, axisSize float32) float32

func (*Node) RemoveAllChildren

func (n *Node) RemoveAllChildren() *Node

RemoveAllChildren removes all children from the node.

func (*Node) RemoveChild

func (n *Node) RemoveChild(child *Node) bool

func (*Node) RemoveChildAt

func (n *Node) RemoveChildAt(index int)

func (*Node) RemoveChildNode

func (n *Node) RemoveChildNode(child *Node) *Node

RemoveChildNode removes a child node. Returns the parent for chaining.

func (*Node) ReplaceChild

func (n *Node) ReplaceChild(oldChild, newChild *Node)

func (*Node) ReplaceChildAt

func (n *Node) ReplaceChildAt(child *Node, index int)

func (*Node) ResolveDirection

func (n *Node) ResolveDirection(ownerDir Direction) Direction

func (*Node) ResolveFlexBasis

func (n *Node) ResolveFlexBasis(dir Direction, flexDir FlexDirection, referenceLength, ownerWidth float32) FloatOptional

func (*Node) ResolveFlexGrow

func (n *Node) ResolveFlexGrow() float32

func (*Node) ResolveFlexShrink

func (n *Node) ResolveFlexShrink() float32

func (*Node) SetAlignContent

func (n *Node) SetAlignContent(a Align) *Node

func (*Node) SetAlignItems

func (n *Node) SetAlignItems(a Align) *Node

func (*Node) SetAlignSelf

func (n *Node) SetAlignSelf(a Align) *Node

func (*Node) SetAlwaysFormsContainingBlock

func (n *Node) SetAlwaysFormsContainingBlock(v bool)

func (*Node) SetAspectRatio

func (n *Node) SetAspectRatio(value float32) *Node

func (*Node) SetBaselineFunc

func (n *Node) SetBaselineFunc(f BaselineFunc)

func (*Node) SetBorder

func (n *Node) SetBorder(edge Edge, value float32) *Node

func (*Node) SetBoxSizing

func (n *Node) SetBoxSizing(b BoxSizing) *Node

func (*Node) SetChildren

func (n *Node) SetChildren(children []*Node)

Child management

func (*Node) SetChildrenList

func (n *Node) SetChildrenList(children []*Node) *Node

SetChildrenList replaces all children with the given list.

func (*Node) SetClasses

func (n *Node) SetClasses(classes []string)

func (*Node) SetConfig

func (n *Node) SetConfig(config *Config)

func (*Node) SetContext

func (n *Node) SetContext(ctx interface{})

func (*Node) SetDirection

func (n *Node) SetDirection(d Direction) *Node

func (*Node) SetDirtiedFunc

func (n *Node) SetDirtiedFunc(f DirtiedFunc)

func (*Node) SetDirty

func (n *Node) SetDirty(isDirty bool)

func (*Node) SetDisplay

func (n *Node) SetDisplay(d Display) *Node

func (*Node) SetEdgePosition

func (n *Node) SetEdgePosition(edge Edge, value float32) *Node

func (*Node) SetEdgePositionAuto

func (n *Node) SetEdgePositionAuto(edge Edge) *Node

func (*Node) SetEdgePositionPercent

func (n *Node) SetEdgePositionPercent(edge Edge, value float32) *Node

func (*Node) SetFlex

func (n *Node) SetFlex(f float32) *Node

func (*Node) SetFlexBasis

func (n *Node) SetFlexBasis(f float32) *Node

func (*Node) SetFlexBasisAuto

func (n *Node) SetFlexBasisAuto() *Node

func (*Node) SetFlexBasisFitContent

func (n *Node) SetFlexBasisFitContent() *Node

func (*Node) SetFlexBasisMaxContent

func (n *Node) SetFlexBasisMaxContent() *Node

func (*Node) SetFlexBasisPercent

func (n *Node) SetFlexBasisPercent(f float32) *Node

func (*Node) SetFlexBasisStretch

func (n *Node) SetFlexBasisStretch() *Node

func (*Node) SetFlexDirection

func (n *Node) SetFlexDirection(fd FlexDirection) *Node

func (*Node) SetFlexGrow

func (n *Node) SetFlexGrow(f float32) *Node

func (*Node) SetFlexShrink

func (n *Node) SetFlexShrink(f float32) *Node

func (*Node) SetFlexWrap

func (n *Node) SetFlexWrap(w Wrap) *Node

func (*Node) SetFontSizeEstimate

func (n *Node) SetFontSizeEstimate(v float32) *Node

FontSizeEstimate controls how rem and em units are resolved in CSS strings. Default is 16. For em, uses the node's own estimate; for rem, walks up to the root node's estimate.

func (*Node) SetGap

func (n *Node) SetGap(gutter Gutter, value float32) *Node

func (*Node) SetGapPercent

func (n *Node) SetGapPercent(gutter Gutter, value float32) *Node

func (*Node) SetGridAutoColumn

func (n *Node) SetGridAutoColumn(index int, trackType GridTrackType, value float32) *Node

func (*Node) SetGridAutoColumnMinMax

func (n *Node) SetGridAutoColumnMinMax(index int, minType GridTrackType, minVal float32, maxType GridTrackType, maxVal float32) *Node

func (*Node) SetGridAutoColumnsCount

func (n *Node) SetGridAutoColumnsCount(count int) *Node

func (*Node) SetGridAutoRow

func (n *Node) SetGridAutoRow(index int, trackType GridTrackType, value float32) *Node

func (*Node) SetGridAutoRowMinMax

func (n *Node) SetGridAutoRowMinMax(index int, minType GridTrackType, minVal float32, maxType GridTrackType, maxVal float32) *Node

func (*Node) SetGridAutoRowsCount

func (n *Node) SetGridAutoRowsCount(count int) *Node

func (*Node) SetGridColumnEnd

func (n *Node) SetGridColumnEnd(v int32) *Node

func (*Node) SetGridColumnEndAuto

func (n *Node) SetGridColumnEndAuto() *Node

func (*Node) SetGridColumnEndSpan

func (n *Node) SetGridColumnEndSpan(span int32) *Node

func (*Node) SetGridColumnStart

func (n *Node) SetGridColumnStart(v int32) *Node

func (*Node) SetGridColumnStartAuto

func (n *Node) SetGridColumnStartAuto() *Node

func (*Node) SetGridColumnStartSpan

func (n *Node) SetGridColumnStartSpan(span int32) *Node

func (*Node) SetGridRowEnd

func (n *Node) SetGridRowEnd(v int32) *Node

func (*Node) SetGridRowEndAuto

func (n *Node) SetGridRowEndAuto() *Node

func (*Node) SetGridRowEndSpan

func (n *Node) SetGridRowEndSpan(span int32) *Node

func (*Node) SetGridRowStart

func (n *Node) SetGridRowStart(v int32) *Node

func (*Node) SetGridRowStartAuto

func (n *Node) SetGridRowStartAuto() *Node

func (*Node) SetGridRowStartSpan

func (n *Node) SetGridRowStartSpan(span int32) *Node

func (*Node) SetGridTemplateColumn

func (n *Node) SetGridTemplateColumn(index int, trackType GridTrackType, value float32) *Node

func (*Node) SetGridTemplateColumnMinMax

func (n *Node) SetGridTemplateColumnMinMax(index int, minType GridTrackType, minVal float32, maxType GridTrackType, maxVal float32) *Node

func (*Node) SetGridTemplateColumnsCount

func (n *Node) SetGridTemplateColumnsCount(count int) *Node

func (*Node) SetGridTemplateRow

func (n *Node) SetGridTemplateRow(index int, trackType GridTrackType, value float32) *Node

func (*Node) SetGridTemplateRowMinMax

func (n *Node) SetGridTemplateRowMinMax(index int, minType GridTrackType, minVal float32, maxType GridTrackType, maxVal float32) *Node

func (*Node) SetGridTemplateRowsCount

func (n *Node) SetGridTemplateRowsCount(count int) *Node

func (*Node) SetHasNewLayout

func (n *Node) SetHasNewLayout(v bool)

func (*Node) SetHeight

func (n *Node) SetHeight(value float32) *Node

func (*Node) SetHeightAuto

func (n *Node) SetHeightAuto() *Node

func (*Node) SetHeightFitContent

func (n *Node) SetHeightFitContent() *Node

func (*Node) SetHeightMaxContent

func (n *Node) SetHeightMaxContent() *Node

func (*Node) SetHeightPercent

func (n *Node) SetHeightPercent(value float32) *Node

func (*Node) SetHeightStretch

func (n *Node) SetHeightStretch() *Node

func (*Node) SetID

func (n *Node) SetID(id string)

func (*Node) SetIsReferenceBaseline

func (n *Node) SetIsReferenceBaseline(v bool)

func (*Node) SetIsReferenceBaseline_Public

func (n *Node) SetIsReferenceBaseline_Public(v bool) *Node

func (*Node) SetJustifyContent

func (n *Node) SetJustifyContent(j Justify) *Node

func (*Node) SetJustifyItems

func (n *Node) SetJustifyItems(j Justify) *Node

func (*Node) SetJustifySelf

func (n *Node) SetJustifySelf(j Justify) *Node

func (*Node) SetLayout

func (n *Node) SetLayout(l LayoutResults)

func (*Node) SetLayoutBorder

func (n *Node) SetLayoutBorder(v float32, edge PhysicalEdge)

func (*Node) SetLayoutComputedFlexBasis

func (n *Node) SetLayoutComputedFlexBasis(fb FloatOptional)

func (*Node) SetLayoutComputedFlexBasisGeneration

func (n *Node) SetLayoutComputedFlexBasisGeneration(g uint32)

func (*Node) SetLayoutDimension

func (n *Node) SetLayoutDimension(v float32, dim Dimension)

func (*Node) SetLayoutDirection

func (n *Node) SetLayoutDirection(dir Direction)

func (*Node) SetLayoutHadOverflow

func (n *Node) SetLayoutHadOverflow(v bool)

func (*Node) SetLayoutLastOwnerDirection

func (n *Node) SetLayoutLastOwnerDirection(dir Direction)

func (*Node) SetLayoutMargin

func (n *Node) SetLayoutMargin(v float32, edge PhysicalEdge)

func (*Node) SetLayoutMeasuredDimension

func (n *Node) SetLayoutMeasuredDimension(v float32, dim Dimension)

func (*Node) SetLayoutPadding

func (n *Node) SetLayoutPadding(v float32, edge PhysicalEdge)

func (*Node) SetLayoutPosition

func (n *Node) SetLayoutPosition(v float32, edge PhysicalEdge)

func (*Node) SetLineIndex

func (n *Node) SetLineIndex(i int)

func (*Node) SetMargin

func (n *Node) SetMargin(edge Edge, value float32) *Node

func (*Node) SetMarginAuto

func (n *Node) SetMarginAuto(edge Edge) *Node

func (*Node) SetMarginPercent

func (n *Node) SetMarginPercent(edge Edge, value float32) *Node

func (*Node) SetMaxHeight

func (n *Node) SetMaxHeight(value float32) *Node

func (*Node) SetMaxHeightFitContent

func (n *Node) SetMaxHeightFitContent() *Node

func (*Node) SetMaxHeightMaxContent

func (n *Node) SetMaxHeightMaxContent() *Node

func (*Node) SetMaxHeightPercent

func (n *Node) SetMaxHeightPercent(value float32) *Node

func (*Node) SetMaxHeightStretch

func (n *Node) SetMaxHeightStretch() *Node

func (*Node) SetMaxWidth

func (n *Node) SetMaxWidth(value float32) *Node

func (*Node) SetMaxWidthFitContent

func (n *Node) SetMaxWidthFitContent() *Node

func (*Node) SetMaxWidthMaxContent

func (n *Node) SetMaxWidthMaxContent() *Node

func (*Node) SetMaxWidthPercent

func (n *Node) SetMaxWidthPercent(value float32) *Node

func (*Node) SetMaxWidthStretch

func (n *Node) SetMaxWidthStretch() *Node

func (*Node) SetMeasureFunc

func (n *Node) SetMeasureFunc(f MeasureFunc)

func (*Node) SetMinContentHeight

func (n *Node) SetMinContentHeight(v FloatOptional)

func (*Node) SetMinContentHeightValue

func (n *Node) SetMinContentHeightValue(v float32) *Node

func (*Node) SetMinContentMeasureFunc

func (n *Node) SetMinContentMeasureFunc(f MeasureFunc)

func (*Node) SetMinContentWidth

func (n *Node) SetMinContentWidth(v FloatOptional)

func (*Node) SetMinContentWidthFunc

func (n *Node) SetMinContentWidthFunc(f MeasureFunc) *Node

func (*Node) SetMinContentWidthValue

func (n *Node) SetMinContentWidthValue(v float32) *Node

func (*Node) SetMinHeight

func (n *Node) SetMinHeight(value float32) *Node

func (*Node) SetMinHeightFitContent

func (n *Node) SetMinHeightFitContent() *Node

func (*Node) SetMinHeightMaxContent

func (n *Node) SetMinHeightMaxContent() *Node

func (*Node) SetMinHeightPercent

func (n *Node) SetMinHeightPercent(value float32) *Node

func (*Node) SetMinHeightStretch

func (n *Node) SetMinHeightStretch() *Node

func (*Node) SetMinWidth

func (n *Node) SetMinWidth(value float32) *Node

func (*Node) SetMinWidthFitContent

func (n *Node) SetMinWidthFitContent() *Node

func (*Node) SetMinWidthMaxContent

func (n *Node) SetMinWidthMaxContent() *Node

func (*Node) SetMinWidthPercent

func (n *Node) SetMinWidthPercent(value float32) *Node

func (*Node) SetMinWidthStretch

func (n *Node) SetMinWidthStretch() *Node

func (*Node) SetNodeType

func (n *Node) SetNodeType(v NodeType)

func (*Node) SetNodeType_Public

func (n *Node) SetNodeType_Public(nt NodeType) *Node

Convenience methods.

func (*Node) SetOverflow

func (n *Node) SetOverflow(o Overflow) *Node

func (*Node) SetOwner

func (n *Node) SetOwner(owner *Node)

func (*Node) SetPadding

func (n *Node) SetPadding(edge Edge, value float32) *Node

func (*Node) SetPaddingPercent

func (n *Node) SetPaddingPercent(edge Edge, value float32) *Node

func (*Node) SetPosition

func (n *Node) SetPosition(dir Direction, ownerWidth, ownerHeight float32)

func (*Node) SetPositionType

func (n *Node) SetPositionType(p PositionType) *Node

func (*Node) SetStyle

func (n *Node) SetStyle(s Style)

func (*Node) SetWidth

func (n *Node) SetWidth(value float32) *Node

func (*Node) SetWidthAuto

func (n *Node) SetWidthAuto() *Node

func (*Node) SetWidthFitContent

func (n *Node) SetWidthFitContent() *Node

func (*Node) SetWidthMaxContent

func (n *Node) SetWidthMaxContent() *Node

func (*Node) SetWidthPercent

func (n *Node) SetWidthPercent(value float32) *Node

func (*Node) SetWidthStretch

func (n *Node) SetWidthStretch() *Node

func (*Node) Style

func (n *Node) Style() *Style

func (*Node) SwapChildNode

func (n *Node) SwapChildNode(child *Node, index int) *Node

SwapChildNode swaps a child node at the given index. The old child at index is properly detached (owner cleared, layout reset, marked dirty). The new child must not already have an owner.

type NodeType

type NodeType int

NodeType categorizes a node (default container or text leaf).

const (
	NodeTypeDefault NodeType = iota
	NodeTypeText
)

func (NodeType) String

func (n NodeType) String() string

type Overflow

type Overflow int

Overflow represents the CSS overflow property.

const (
	OverflowVisible Overflow = iota
	OverflowHidden
	OverflowScroll
)

func (Overflow) String

func (o Overflow) String() string

type PhysicalEdge

type PhysicalEdge int

PhysicalEdge represents a fixed physical edge (not logical).

const (
	PhysicalEdgeLeft PhysicalEdge = iota
	PhysicalEdgeTop
	PhysicalEdgeRight
	PhysicalEdgeBottom
)

type PositionType

type PositionType int

PositionType represents the CSS position property.

const (
	PositionTypeStatic PositionType = iota
	PositionTypeRelative
	PositionTypeAbsolute
)

func (PositionType) String

func (p PositionType) String() string

type Rect

type Rect struct {
	Left   float32
	Top    float32
	Right  float32
	Bottom float32
	Width  float32
	Height float32
}

Rect holds the computed position and size of a laid-out node. These values are only meaningful after CalculateNodeLayout is called.

type Size

type Size struct {
	Width  float32
	Height float32
}

Size is a simple width/height pair used by measure callbacks.

type SizingMode

type SizingMode int

SizingMode controls how dimensions are resolved during layout.

const (
	SizingModeStretchFit SizingMode = iota
	SizingModeMaxContent
	SizingModeFitContent
)

type Style

type Style struct {
	// contains filtered or unexported fields
}

Style holds all CSS properties for a single Node.

func NewStyle

func NewStyle() Style

func (*Style) AlignContent

func (s *Style) AlignContent() Align

func (*Style) AlignItems

func (s *Style) AlignItems() Align

func (*Style) AlignSelf

func (s *Style) AlignSelf() Align

func (*Style) AspectRatio

func (s *Style) AspectRatio() FloatOptional

func (*Style) Border

func (s *Style) Border(edge Edge) StyleLength

func (*Style) BoxSizing

func (s *Style) BoxSizing() BoxSizing

func (*Style) ComputeBorderForAxis

func (s *Style) ComputeBorderForAxis(axis FlexDirection) float32

func (*Style) ComputeFlexEndBorder

func (s *Style) ComputeFlexEndBorder(axis FlexDirection, dir Direction) float32

func (*Style) ComputeFlexEndMargin

func (s *Style) ComputeFlexEndMargin(axis FlexDirection, dir Direction, widthSize float32) float32

func (*Style) ComputeFlexEndPadding

func (s *Style) ComputeFlexEndPadding(axis FlexDirection, dir Direction, widthSize float32) float32

func (*Style) ComputeFlexEndPaddingAndBorder

func (s *Style) ComputeFlexEndPaddingAndBorder(axis FlexDirection, dir Direction, widthSize float32) float32

func (*Style) ComputeFlexEndPosition

func (s *Style) ComputeFlexEndPosition(axis FlexDirection, dir Direction, axisSize float32) float32

func (*Style) ComputeFlexStartBorder

func (s *Style) ComputeFlexStartBorder(axis FlexDirection, dir Direction) float32

Border helpers

func (*Style) ComputeFlexStartMargin

func (s *Style) ComputeFlexStartMargin(axis FlexDirection, dir Direction, widthSize float32) float32

Margin helpers

func (*Style) ComputeFlexStartPadding

func (s *Style) ComputeFlexStartPadding(axis FlexDirection, dir Direction, widthSize float32) float32

Padding helpers

func (*Style) ComputeFlexStartPaddingAndBorder

func (s *Style) ComputeFlexStartPaddingAndBorder(axis FlexDirection, dir Direction, widthSize float32) float32

func (*Style) ComputeFlexStartPosition

func (s *Style) ComputeFlexStartPosition(axis FlexDirection, dir Direction, axisSize float32) float32

func (*Style) ComputeGapForAxis

func (s *Style) ComputeGapForAxis(axis FlexDirection, ownerSize float32) float32

func (*Style) ComputeGapForDimension

func (s *Style) ComputeGapForDimension(dim Dimension, ownerSize float32) float32

func (*Style) ComputeInlineEndBorder

func (s *Style) ComputeInlineEndBorder(axis FlexDirection, dir Direction) float32

func (*Style) ComputeInlineEndMargin

func (s *Style) ComputeInlineEndMargin(axis FlexDirection, dir Direction, widthSize float32) float32

func (*Style) ComputeInlineEndPadding

func (s *Style) ComputeInlineEndPadding(axis FlexDirection, dir Direction, widthSize float32) float32

func (*Style) ComputeInlineEndPaddingAndBorder

func (s *Style) ComputeInlineEndPaddingAndBorder(axis FlexDirection, dir Direction, widthSize float32) float32

func (*Style) ComputeInlineEndPosition

func (s *Style) ComputeInlineEndPosition(axis FlexDirection, dir Direction, axisSize float32) float32

func (*Style) ComputeInlineStartBorder

func (s *Style) ComputeInlineStartBorder(axis FlexDirection, dir Direction) float32

func (*Style) ComputeInlineStartMargin

func (s *Style) ComputeInlineStartMargin(axis FlexDirection, dir Direction, widthSize float32) float32

func (*Style) ComputeInlineStartPadding

func (s *Style) ComputeInlineStartPadding(axis FlexDirection, dir Direction, widthSize float32) float32

func (*Style) ComputeInlineStartPaddingAndBorder

func (s *Style) ComputeInlineStartPaddingAndBorder(axis FlexDirection, dir Direction, widthSize float32) float32

func (*Style) ComputeInlineStartPosition

func (s *Style) ComputeInlineStartPosition(axis FlexDirection, dir Direction, axisSize float32) float32

func (*Style) ComputeMarginForAxis

func (s *Style) ComputeMarginForAxis(axis FlexDirection, widthSize float32) float32

func (*Style) ComputePaddingAndBorderForDimension

func (s *Style) ComputePaddingAndBorderForDimension(dir Direction, dim Dimension, widthSize float32) float32

func (*Style) Copy

func (s *Style) Copy() Style

func (*Style) Dimension

func (s *Style) Dimension(axis Dimension) StyleSizeLength

func (*Style) Direction

func (s *Style) Direction() Direction

func (*Style) Display

func (s *Style) Display() Display

func (*Style) Equals

func (s *Style) Equals(other *Style) bool

Equals returns true if all style properties match.

func (*Style) Flex

func (s *Style) Flex() FloatOptional

func (*Style) FlexBasis

func (s *Style) FlexBasis() StyleSizeLength

func (*Style) FlexDirection

func (s *Style) FlexDirection() FlexDirection

func (*Style) FlexEndMarginIsAuto

func (s *Style) FlexEndMarginIsAuto(axis FlexDirection, dir Direction) bool

func (*Style) FlexGrow

func (s *Style) FlexGrow() FloatOptional

func (*Style) FlexShrink

func (s *Style) FlexShrink() FloatOptional

func (*Style) FlexStartMarginIsAuto

func (s *Style) FlexStartMarginIsAuto(axis FlexDirection, dir Direction) bool

func (*Style) FlexWrap

func (s *Style) FlexWrap() Wrap

func (*Style) Gap

func (s *Style) Gap(gutter Gutter) StyleLength

func (*Style) GridAutoColumns

func (s *Style) GridAutoColumns() GridTrackList

func (*Style) GridAutoRows

func (s *Style) GridAutoRows() GridTrackList

func (*Style) GridColumnEnd

func (s *Style) GridColumnEnd() GridLine

func (*Style) GridColumnStart

func (s *Style) GridColumnStart() GridLine

Grid item properties

func (*Style) GridRowEnd

func (s *Style) GridRowEnd() GridLine

func (*Style) GridRowStart

func (s *Style) GridRowStart() GridLine

func (*Style) GridTemplateColumns

func (s *Style) GridTemplateColumns() GridTrackList

Grid container properties

func (*Style) GridTemplateRows

func (s *Style) GridTemplateRows() GridTrackList

func (*Style) HorizontalInsetsDefined

func (s *Style) HorizontalInsetsDefined() bool

func (*Style) InlineEndMarginIsAuto

func (s *Style) InlineEndMarginIsAuto(axis FlexDirection, dir Direction) bool

func (*Style) InlineStartMarginIsAuto

func (s *Style) InlineStartMarginIsAuto(axis FlexDirection, dir Direction) bool

func (*Style) IsFlexEndPositionAuto

func (s *Style) IsFlexEndPositionAuto(axis FlexDirection, dir Direction) bool

func (*Style) IsFlexEndPositionDefined

func (s *Style) IsFlexEndPositionDefined(axis FlexDirection, dir Direction) bool

func (*Style) IsFlexStartPositionAuto

func (s *Style) IsFlexStartPositionAuto(axis FlexDirection, dir Direction) bool

func (*Style) IsFlexStartPositionDefined

func (s *Style) IsFlexStartPositionDefined(axis FlexDirection, dir Direction) bool

func (*Style) IsInlineEndPositionAuto

func (s *Style) IsInlineEndPositionAuto(axis FlexDirection, dir Direction) bool

func (*Style) IsInlineEndPositionDefined

func (s *Style) IsInlineEndPositionDefined(axis FlexDirection, dir Direction) bool

func (*Style) IsInlineStartPositionAuto

func (s *Style) IsInlineStartPositionAuto(axis FlexDirection, dir Direction) bool

func (*Style) IsInlineStartPositionDefined

func (s *Style) IsInlineStartPositionDefined(axis FlexDirection, dir Direction) bool

func (*Style) JustifyContent

func (s *Style) JustifyContent() Justify

func (*Style) JustifyItems

func (s *Style) JustifyItems() Justify

func (*Style) JustifySelf

func (s *Style) JustifySelf() Justify

func (*Style) Margin

func (s *Style) Margin(edge Edge) StyleLength

func (*Style) MaxDimension

func (s *Style) MaxDimension(axis Dimension) StyleSizeLength

func (*Style) MinDimension

func (s *Style) MinDimension(axis Dimension) StyleSizeLength

func (*Style) Overflow

func (s *Style) Overflow() Overflow

func (*Style) Padding

func (s *Style) Padding(edge Edge) StyleLength

func (*Style) Position

func (s *Style) Position(edge Edge) StyleLength

func (*Style) PositionType

func (s *Style) PositionType() PositionType

func (*Style) ResizeGridAutoColumns

func (s *Style) ResizeGridAutoColumns(count int)

func (*Style) ResizeGridAutoRows

func (s *Style) ResizeGridAutoRows(count int)

func (*Style) ResizeGridTemplateColumns

func (s *Style) ResizeGridTemplateColumns(count int)

func (*Style) ResizeGridTemplateRows

func (s *Style) ResizeGridTemplateRows(count int)

func (*Style) ResolvedMaxDimension

func (s *Style) ResolvedMaxDimension(direction Direction, axis Dimension, referenceLength, ownerWidth float32) FloatOptional

ResolvedMaxDimension returns the resolved maximum size for the given axis.

func (*Style) ResolvedMinDimension

func (s *Style) ResolvedMinDimension(direction Direction, axis Dimension, referenceLength, ownerWidth float32) FloatOptional

ResolvedMinDimension returns the resolved minimum size for the given axis.

func (*Style) SetAlignContent

func (s *Style) SetAlignContent(v Align)

func (*Style) SetAlignItems

func (s *Style) SetAlignItems(v Align)

func (*Style) SetAlignSelf

func (s *Style) SetAlignSelf(v Align)

func (*Style) SetAspectRatio

func (s *Style) SetAspectRatio(v FloatOptional)

func (*Style) SetBorder

func (s *Style) SetBorder(edge Edge, v StyleLength)

func (*Style) SetBoxSizing

func (s *Style) SetBoxSizing(v BoxSizing)

func (*Style) SetDimension

func (s *Style) SetDimension(axis Dimension, v StyleSizeLength)

func (*Style) SetDirection

func (s *Style) SetDirection(v Direction)

func (*Style) SetDisplay

func (s *Style) SetDisplay(v Display)

func (*Style) SetFlex

func (s *Style) SetFlex(v FloatOptional)

func (*Style) SetFlexBasis

func (s *Style) SetFlexBasis(v StyleSizeLength)

func (*Style) SetFlexDirection

func (s *Style) SetFlexDirection(v FlexDirection)

func (*Style) SetFlexGrow

func (s *Style) SetFlexGrow(v FloatOptional)

func (*Style) SetFlexShrink

func (s *Style) SetFlexShrink(v FloatOptional)

func (*Style) SetFlexWrap

func (s *Style) SetFlexWrap(v Wrap)

func (*Style) SetGap

func (s *Style) SetGap(gutter Gutter, v StyleLength)

func (*Style) SetGridAutoColumnAt

func (s *Style) SetGridAutoColumnAt(index int, v GridTrackSize)

func (*Style) SetGridAutoColumns

func (s *Style) SetGridAutoColumns(v GridTrackList)

func (*Style) SetGridAutoRowAt

func (s *Style) SetGridAutoRowAt(index int, v GridTrackSize)

func (*Style) SetGridAutoRows

func (s *Style) SetGridAutoRows(v GridTrackList)

func (*Style) SetGridColumnEnd

func (s *Style) SetGridColumnEnd(v GridLine)

func (*Style) SetGridColumnStart

func (s *Style) SetGridColumnStart(v GridLine)

func (*Style) SetGridRowEnd

func (s *Style) SetGridRowEnd(v GridLine)

func (*Style) SetGridRowStart

func (s *Style) SetGridRowStart(v GridLine)

func (*Style) SetGridTemplateColumnAt

func (s *Style) SetGridTemplateColumnAt(index int, v GridTrackSize)

func (*Style) SetGridTemplateColumns

func (s *Style) SetGridTemplateColumns(v GridTrackList)

func (*Style) SetGridTemplateRowAt

func (s *Style) SetGridTemplateRowAt(index int, v GridTrackSize)

func (*Style) SetGridTemplateRows

func (s *Style) SetGridTemplateRows(v GridTrackList)

func (*Style) SetJustifyContent

func (s *Style) SetJustifyContent(v Justify)

func (*Style) SetJustifyItems

func (s *Style) SetJustifyItems(v Justify)

func (*Style) SetJustifySelf

func (s *Style) SetJustifySelf(v Justify)

func (*Style) SetMargin

func (s *Style) SetMargin(edge Edge, v StyleLength)

func (*Style) SetMaxDimension

func (s *Style) SetMaxDimension(axis Dimension, v StyleSizeLength)

func (*Style) SetMinDimension

func (s *Style) SetMinDimension(axis Dimension, v StyleSizeLength)

func (*Style) SetOverflow

func (s *Style) SetOverflow(v Overflow)

func (*Style) SetPadding

func (s *Style) SetPadding(edge Edge, v StyleLength)

func (*Style) SetPosition

func (s *Style) SetPosition(edge Edge, v StyleLength)

func (*Style) SetPositionType

func (s *Style) SetPositionType(v PositionType)

func (*Style) VerticalInsetsDefined

func (s *Style) VerticalInsetsDefined() bool

type StyleLength

type StyleLength struct {
	// contains filtered or unexported fields
}

StyleLength represents a CSS length value (for margins, padding, borders, positions). It supports point, percent, auto, and undefined units.

func StyleLengthAuto

func StyleLengthAuto() StyleLength

func StyleLengthPercent

func StyleLengthPercent(v float32) StyleLength

func StyleLengthPoints

func StyleLengthPoints(v float32) StyleLength

func StyleLengthUndefined

func StyleLengthUndefined() StyleLength

func (StyleLength) IsAuto

func (l StyleLength) IsAuto() bool

func (StyleLength) IsDefined

func (l StyleLength) IsDefined() bool

func (StyleLength) IsPercent

func (l StyleLength) IsPercent() bool

func (StyleLength) IsPoints

func (l StyleLength) IsPoints() bool

func (StyleLength) IsUndefined

func (l StyleLength) IsUndefined() bool

func (StyleLength) Resolve

func (l StyleLength) Resolve(referenceLength float32) FloatOptional

func (StyleLength) ToValue

func (l StyleLength) ToValue() Value

func (StyleLength) Value

func (l StyleLength) Value() FloatOptional

type StyleSizeLength

type StyleSizeLength struct {
	// contains filtered or unexported fields
}

StyleSizeLength represents a CSS size value for dimensions (width, height, flex-basis). It supports all units including max-content, fit-content, and stretch.

func StyleSizeLengthAuto

func StyleSizeLengthAuto() StyleSizeLength

func StyleSizeLengthFitContent

func StyleSizeLengthFitContent() StyleSizeLength

func StyleSizeLengthMaxContent

func StyleSizeLengthMaxContent() StyleSizeLength

func StyleSizeLengthOfStretch

func StyleSizeLengthOfStretch() StyleSizeLength

func StyleSizeLengthPercent

func StyleSizeLengthPercent(v float32) StyleSizeLength

func StyleSizeLengthPoints

func StyleSizeLengthPoints(v float32) StyleSizeLength

func StyleSizeLengthStretch

func StyleSizeLengthStretch(fraction float32) StyleSizeLength

func StyleSizeLengthUndefined

func StyleSizeLengthUndefined() StyleSizeLength

func (StyleSizeLength) Equals

func (l StyleSizeLength) Equals(other StyleSizeLength) bool

func (StyleSizeLength) IsAuto

func (l StyleSizeLength) IsAuto() bool

func (StyleSizeLength) IsDefined

func (l StyleSizeLength) IsDefined() bool

func (StyleSizeLength) IsFitContent

func (l StyleSizeLength) IsFitContent() bool

func (StyleSizeLength) IsMaxContent

func (l StyleSizeLength) IsMaxContent() bool

func (StyleSizeLength) IsPercent

func (l StyleSizeLength) IsPercent() bool

func (StyleSizeLength) IsPoints

func (l StyleSizeLength) IsPoints() bool

func (StyleSizeLength) IsStretch

func (l StyleSizeLength) IsStretch() bool

func (StyleSizeLength) IsUndefined

func (l StyleSizeLength) IsUndefined() bool

func (StyleSizeLength) Resolve

func (l StyleSizeLength) Resolve(referenceLength float32) FloatOptional

func (StyleSizeLength) ToValue

func (l StyleSizeLength) ToValue() Value

func (StyleSizeLength) Value

func (l StyleSizeLength) Value() FloatOptional

type Unit

type Unit int

Unit represents a CSS length unit.

const (
	UnitUndefined Unit = iota
	UnitPoint
	UnitPercent
	UnitAuto
	UnitMaxContent
	UnitFitContent
	UnitStretch
)

func (Unit) String

func (u Unit) String() string

type Value

type Value struct {
	Value float32
	Unit  Unit
}

Value is a CSS-style value with a numeric component and a unit.

type Wrap

type Wrap int

Wrap represents the CSS flex-wrap property.

const (
	WrapNoWrap Wrap = iota
	WrapWrap
	WrapWrapReverse
)

func (Wrap) String

func (w Wrap) String() string

Jump to

Keyboard shortcuts

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