yoga

package module
v0.0.0-...-381a318 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2025 License: MIT Imports: 8 Imported by: 1

README

Yoga Layout for Go

Go Test

Go bindings for Facebook's Yoga Layout library - a cross-platform layout engine implementing Flexbox.

Features

  • 🎯 Complete Flexbox Implementation - Full support for CSS Flexbox properties
  • 📱 Cross-Platform - Works on all platforms supported by Go
  • 🔧 Simple API - Clean, idiomatic Go interface
  • 🎨 Layout Debugging - Built-in support for generating layout representations
  • High Performance - Direct C bindings for optimal performance

Quick Start

package main

import (
    "fmt"
    "github.com/millken/yoga"
)

func main() {
    // Create a root node
    root := yoga.NewNode()
    defer root.Destroy()

    // Set flexbox properties
    root.SetWidth(375)
    root.SetHeight(667)
    root.SetFlexDirection(yoga.FlexDirectionColumn)

    // Create a child node
    child := yoga.NewNode()
    defer child.Destroy()
    child.SetFlexGrow(1)
    child.SetHeight(100)

    // Add child to parent
    root.InsertChild(child, 0)

    // Calculate layout
    root.CalculateLayout(yoga.Undefined, yoga.Undefined, yoga.DirectionLTR)

    // Print computed layout
    fmt.Printf("Child width: %.2f, height: %.2f\n",
        child.GetComputedWidth(), child.GetComputedHeight())

    // Generate layout representation for yogalayout.dev
    layout := root.ToYogaLayout()
    fmt.Println(layout)
}

Layout Debugging

The library provides built-in support for generating layout representations that can be used with yogalayout.dev playground:

root := yoga.NewNode()
defer root.Destroy()

root.SetWidth(200)
root.SetHeight(200)

child := yoga.NewNode()
defer child.Destroy()
child.SetFlexGrow(1)
child.SetHeight(100)

root.InsertChild(child, 0)
root.CalculateLayout(yoga.Undefined, yoga.Undefined, yoga.DirectionLTR)

layout := root.ToYogaLayout()
fmt.Println(layout)

Output:

<Layout config={{useWebDefaults: false}}>
    <Node style={{width: 200, height: 200}}>
    <Node style={{height: 100, flex: 1}} />
  </Node>
</Layout>

Installation

go get github.com/millken/yoga

Documentation

Status

⚠️ Development Version - This is a development version and should not be used in production environments.

License

MIT License - see LICENSE file for details.

Documentation

Overview

Package yoga is a Go binding for the Yoga layout engine.

Index

Constants

This section is empty.

Variables

View Source
var (
	NaN               = math.Float32frombits(uvnan)
	Undefined float32 = NaN
	Zero      float32 = 0.0
)

Functions

func FloatIsUndefined

func FloatIsUndefined(value float32) bool

FloatIsUndefined reports whether a float value represents undefined.

func If

func If[T any](expr bool, a, b T) T

func IsInf

func IsInf(f float32, sign int) bool

func IsNaN

func IsNaN(f float32) (is bool)

IsNaN reports whether f is an IEEE 754 "not-a-number" value.

Types

type Align

type Align int

Align represents the enum type for Align

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

func AlignFromString

func AlignFromString(s string) (Align, error)

AlignFromString parses Align enum value from string

func (Align) String

func (e Align) String() string

String returns the string representation of Align

type BaselineFunc

type BaselineFunc func(width float32, height float32) float32

BaselineFunc defines the type for the baseline callback function

type BoxSizing

type BoxSizing int

BoxSizing represents the enum type for BoxSizing

const (
	BoxSizingBorderBox BoxSizing = iota
	BoxSizingContentBox
)

func BoxSizingFromString

func BoxSizingFromString(s string) (BoxSizing, error)

BoxSizingFromString parses BoxSizing enum value from string

func (BoxSizing) String

func (e BoxSizing) String() string

String returns the string representation of BoxSizing

type Config

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

Config 包装YGConfigRef

func NewConfig

func NewConfig() *Config

NewConfig 创建一个新的配置对象

func (*Config) Destroy

func (c *Config) Destroy()

Destroy 释放配置资源

func (*Config) GetErrata

func (c *Config) GetErrata() Errata

GetErrata 获取当前的错误处理模式

func (*Config) GetLogger

func (c *Config) GetLogger() Logger

GetLogger 获取当前日志回调函数

func (*Config) IsExperimentalFeatureEnabled

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

IsExperimentalFeatureEnabled 检查实验性功能是否启用

func (*Config) PointScaleFactor

func (c *Config) PointScaleFactor() float32

PointScaleFactor 获取点缩放因子

func (*Config) SetErrata

func (c *Config) SetErrata(errata Errata)

SetErrata 设置错误处理模式

func (*Config) SetExperimentalFeatureEnabled

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

SetExperimentalFeatureEnabled 启用或禁用实验性功能

func (*Config) SetLogger

func (c *Config) SetLogger(logger Logger)

SetLogger 设置日志回调函数

func (*Config) SetPointScaleFactor

func (c *Config) SetPointScaleFactor(pixelsInPoint float32)

SetPointScaleFactor 设置点缩放因子

func (*Config) SetUseWebDefaults

func (c *Config) SetUseWebDefaults(useWebDefaults bool)

SetUseWebDefaults 设置是否使用Web默认值

func (*Config) UnsetLogger

func (c *Config) UnsetLogger()

UnsetLogger 取消日志回调函数

func (*Config) UseWebDefaults

func (c *Config) UseWebDefaults() bool

UseWebDefaults 检查是否使用Web默认值

type ConfigContext

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

ConfigContext 存储 Config 的回调句柄,类似于 NodeContext

type Dimension

type Dimension int

Dimension represents the enum type for Dimension

const (
	DimensionWidth Dimension = iota
	DimensionHeight
)

func DimensionFromString

func DimensionFromString(s string) (Dimension, error)

DimensionFromString parses Dimension enum value from string

func (Dimension) String

func (e Dimension) String() string

String returns the string representation of Dimension

type Direction

type Direction int

Direction represents the enum type for Direction

const (
	DirectionInherit Direction = iota
	DirectionLTR
	DirectionRTL
)

func DirectionFromString

func DirectionFromString(s string) (Direction, error)

DirectionFromString parses Direction enum value from string

func (Direction) String

func (e Direction) String() string

String returns the string representation of Direction

type DirtiedFunc

type DirtiedFunc func()

DirtiedFunc defines the callback for node state changes

type Display

type Display int

Display represents the enum type for Display

const (
	DisplayFlex Display = iota
	DisplayNone
	DisplayContents
)

func DisplayFromString

func DisplayFromString(s string) (Display, error)

DisplayFromString parses Display enum value from string

func (Display) String

func (e Display) String() string

String returns the string representation of Display

type Edge

type Edge int

Edge represents the enum type for Edge

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

func EdgeFromString

func EdgeFromString(s string) (Edge, error)

EdgeFromString parses Edge enum value from string

func (Edge) String

func (e Edge) String() string

String returns the string representation of Edge

type Errata

type Errata uint32

Errata represents the enum type for Errata

const (
	ErrataNone                                         Errata = 0
	ErrataStretchFlexBasis                             Errata = 1
	ErrataAbsolutePositionWithoutInsetsExcludesPadding Errata = 2
	ErrataAbsolutePercentAgainstInnerSize              Errata = 4
	ErrataAll                                          Errata = 2147483647
	ErrataClassic                                      Errata = 2147483646
)

func ErrataFromString

func ErrataFromString(s string) (Errata, error)

ErrataFromString parses Errata enum value from string

func (Errata) String

func (e Errata) String() string

String returns the string representation of Errata

type ExperimentalFeature

type ExperimentalFeature int

ExperimentalFeature represents the enum type for ExperimentalFeature

const (
	ExperimentalFeatureWebFlexBasis ExperimentalFeature = iota
)

func ExperimentalFeatureFromString

func ExperimentalFeatureFromString(s string) (ExperimentalFeature, error)

ExperimentalFeatureFromString parses ExperimentalFeature enum value from string

func (ExperimentalFeature) String

func (e ExperimentalFeature) String() string

String returns the string representation of ExperimentalFeature

type FlexDirection

type FlexDirection int

FlexDirection represents the enum type for FlexDirection

const (
	FlexDirectionColumn FlexDirection = iota
	FlexDirectionColumnReverse
	FlexDirectionRow
	FlexDirectionRowReverse
)

func FlexDirectionFromString

func FlexDirectionFromString(s string) (FlexDirection, error)

FlexDirectionFromString parses FlexDirection enum value from string

func (FlexDirection) String

func (e FlexDirection) String() string

String returns the string representation of FlexDirection

type Gutter

type Gutter int

Gutter represents the enum type for Gutter

const (
	GutterColumn Gutter = iota
	GutterRow
	GutterAll
)

func GutterFromString

func GutterFromString(s string) (Gutter, error)

GutterFromString parses Gutter enum value from string

func (Gutter) String

func (e Gutter) String() string

String returns the string representation of Gutter

type Justify

type Justify int

Justify represents the enum type for Justify

const (
	JustifyFlexStart Justify = iota
	JustifyCenter
	JustifyFlexEnd
	JustifySpaceBetween
	JustifySpaceAround
	JustifySpaceEvenly
)

func JustifyFromString

func JustifyFromString(s string) (Justify, error)

JustifyFromString parses Justify enum value from string

func (Justify) String

func (e Justify) String() string

String returns the string representation of Justify

type Layout

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

Layout represents the computed layout information

type LogLevel

type LogLevel int

LogLevel represents the enum type for LogLevel

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

func LogLevelFromString

func LogLevelFromString(s string) (LogLevel, error)

LogLevelFromString parses LogLevel enum value from string

func (LogLevel) String

func (e LogLevel) String() string

String returns the string representation of LogLevel

type Logger

type Logger func(config *Config, node *Node, level LogLevel, message string) int

type MeasureFunc

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

MeasureFunc defines the type for the measurement callback function

type MeasureMode

type MeasureMode int

MeasureMode represents the enum type for MeasureMode

const (
	MeasureModeUndefined MeasureMode = iota
	MeasureModeExactly
	MeasureModeAtMost
)

func MeasureModeFromString

func MeasureModeFromString(s string) (MeasureMode, error)

MeasureModeFromString parses MeasureMode enum value from string

func (MeasureMode) String

func (e MeasureMode) String() string

String returns the string representation of MeasureMode

type Node

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

func NewNode

func NewNode() *Node

NewNode creates a default node

func NewNodeWithConfig

func NewNodeWithConfig(config *Config) *Node

NewNodeWithConfig creates a node with the specified configuration

func (*Node) CalculateLayout

func (n *Node) CalculateLayout(width, height float32, direction Direction)

CalculateLayout calculates the layout

func (*Node) Clone

func (n *Node) Clone() *Node

Clone creates a copy of the node with the same context and children, but no owner set

func (*Node) CopyStyle

func (n *Node) CopyStyle(other *Node)

CopyStyle copies the style from another node

func (*Node) Destroy

func (n *Node) Destroy()

Destroy releases the resources of the node

func (*Node) Finalize

func (n *Node) Finalize()

Finalize frees the node without disconnecting it from its owner or children

func (*Node) Free

func (n *Node) Free()

Free Frees the Yoga node without disconnecting it from its owner or children. Allows garbage collecting Yoga nodes in parallel when the entire tree is unreachable.

func (*Node) FreeRecursive

func (n *Node) FreeRecursive()

FreeRecursive frees the node and all its children recursively

func (*Node) GetAlignContent

func (n *Node) GetAlignContent() Align

GetAlignContent gets the alignment of content

func (*Node) GetAlignItems

func (n *Node) GetAlignItems() Align

GetAlignItems gets the alignment of child items

func (*Node) GetAlignSelf

func (n *Node) GetAlignSelf() Align

GetAlignSelf gets the alignment for the node itself

func (*Node) GetAlwaysFormsContainingBlock

func (n *Node) GetAlwaysFormsContainingBlock() bool

GetAlwaysFormsContainingBlock checks if the node always forms a containing block

func (*Node) GetAspectRatio

func (n *Node) GetAspectRatio() float32

GetAspectRatio gets the aspect ratio

func (*Node) GetBorder

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

GetBorder gets the border width

func (*Node) GetBoxSizing

func (n *Node) GetBoxSizing() BoxSizing

GetBoxSizing gets the box model type

func (*Node) GetChild

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

GetChild gets the child node at the specified index

func (*Node) GetChildCount

func (n *Node) GetChildCount() uint32

GetChildCount gets the number of child nodes

func (*Node) GetComputedBorder

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

GetComputedBorder gets the computed border width

func (*Node) GetComputedBottom

func (n *Node) GetComputedBottom() float32

GetComputedBottom gets the computed bottom position

func (*Node) GetComputedHeight

func (n *Node) GetComputedHeight() float32

GetComputedHeight gets the computed height

func (*Node) GetComputedLayout

func (n *Node) GetComputedLayout() Layout

GetComputedLayout gets the complete computed layout

func (*Node) GetComputedLeft

func (n *Node) GetComputedLeft() float32

GetComputedLeft gets the computed left position

func (*Node) GetComputedMargin

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

GetComputedMargin gets the computed margin

func (*Node) GetComputedPadding

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

GetComputedPadding gets the computed padding

func (*Node) GetComputedRight

func (n *Node) GetComputedRight() float32

GetComputedRight gets the computed right position

func (*Node) GetComputedTop

func (n *Node) GetComputedTop() float32

GetComputedTop gets the computed top position

func (*Node) GetComputedWidth

func (n *Node) GetComputedWidth() float32

GetComputedWidth gets the computed width

func (*Node) GetConfig

func (n *Node) GetConfig() *Config

GetConfig gets the configuration of the node

func (*Node) GetContext

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

GetContext gets the context of the node

func (*Node) GetDirection

func (n *Node) GetDirection() Direction

GetDirection gets the document flow direction

func (*Node) GetDirtiedFunc

func (n *Node) GetDirtiedFunc() DirtiedFunc

GetDirtiedFunc gets the current dirtied callback function

func (*Node) GetDisplay

func (n *Node) GetDisplay() Display

GetDisplay gets the display behavior

func (*Node) GetFlex

func (n *Node) GetFlex() float32

GetFlex gets the flex layout value

func (*Node) GetFlexBasis

func (n *Node) GetFlexBasis() Value

GetFlexBasis gets the flex basis size

func (*Node) GetFlexDirection

func (n *Node) GetFlexDirection() FlexDirection

GetFlexDirection gets the flex direction

func (*Node) GetFlexGrow

func (n *Node) GetFlexGrow() float32

GetFlexGrow gets the flex grow factor

func (*Node) GetFlexShrink

func (n *Node) GetFlexShrink() float32

GetFlexShrink gets the flex shrink factor

func (*Node) GetFlexWrap

func (n *Node) GetFlexWrap() Wrap

GetFlexWrap gets the wrapping behavior

func (*Node) GetGap

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

GetGap gets the gap

func (*Node) GetHeight

func (n *Node) GetHeight() Value

GetHeight gets the height

func (*Node) GetJustifyContent

func (n *Node) GetJustifyContent() Justify

GetJustifyContent gets the alignment along the main axis

func (*Node) GetLayoutDirection

func (n *Node) GetLayoutDirection() Direction

GetLayoutDirection gets the layout direction after layout calculation

func (*Node) GetMargin

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

GetMargin gets the margin

func (*Node) GetMaxHeight

func (n *Node) GetMaxHeight() Value

GetMaxHeight gets the maximum height

func (*Node) GetMaxWidth

func (n *Node) GetMaxWidth() Value

GetMaxWidth gets the maximum width

func (*Node) GetMeasureFunc

func (n *Node) GetMeasureFunc() MeasureFunc

GetMeasureFunc gets the current measurement callback function

func (*Node) GetMinHeight

func (n *Node) GetMinHeight() Value

GetMinHeight gets the minimum height

func (*Node) GetMinWidth

func (n *Node) GetMinWidth() Value

GetMinWidth gets the minimum width

func (*Node) GetNodeType

func (n *Node) GetNodeType() NodeType

GetNodeType gets the type of the node

func (*Node) GetOverflow

func (n *Node) GetOverflow() Overflow

GetOverflow gets the overflow behavior

func (*Node) GetOwner

func (n *Node) GetOwner() *Node

GetOwner returns the owner of the node.

func (*Node) GetPadding

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

GetPadding gets the padding

func (*Node) GetParent

func (n *Node) GetParent() *Node

GetParent gets the parent node

func (*Node) GetPosition

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

GetPosition gets the position value

func (*Node) GetPositionType

func (n *Node) GetPositionType() PositionType

GetPositionType gets the position type

func (*Node) GetRawHeight

func (n *Node) GetRawHeight() float32

GetRawHeight gets the measured height before layout rounding

func (*Node) GetRawWidth

func (n *Node) GetRawWidth() float32

GetRawWidth gets the measured width before layout rounding

func (*Node) GetWidth

func (n *Node) GetWidth() Value

GetWidth gets the width

func (*Node) HadOverflow

func (n *Node) HadOverflow() bool

HadOverflow checks if the node had overflow

func (*Node) HasBaselineFunc

func (n *Node) HasBaselineFunc() bool

HasBaselineFunc checks if a baseline function is set

func (*Node) HasNewLayout

func (n *Node) HasNewLayout() bool

HasNewLayout checks if the node has a new layout

func (*Node) InsertChild

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

InsertChild inserts a child node at the specified position

func (*Node) IsDirty

func (n *Node) IsDirty() bool

IsDirty checks if the node is dirty

func (*Node) IsReferenceBaseline

func (n *Node) IsReferenceBaseline() bool

IsReferenceBaseline checks if the node is a reference baseline

func (*Node) MarkDirty

func (n *Node) MarkDirty()

MarkDirty marks the node as dirty (needs recalculation)

func (*Node) RemoveAllChildren

func (n *Node) RemoveAllChildren()

RemoveAllChildren removes all child nodes from the node

func (*Node) RemoveChild

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

RemoveChild removes a child node

func (*Node) Reset

func (n *Node) Reset()

Reset resets the node settings

func (*Node) SetAlignContent

func (n *Node) SetAlignContent(alignContent Align)

SetAlignContent sets the alignment of content

func (*Node) SetAlignItems

func (n *Node) SetAlignItems(alignItems Align)

SetAlignItems sets the alignment of child items

func (*Node) SetAlignSelf

func (n *Node) SetAlignSelf(alignSelf Align)

SetAlignSelf sets the alignment for the node itself

func (*Node) SetAlwaysFormsContainingBlock

func (n *Node) SetAlwaysFormsContainingBlock(alwaysFormsContainingBlock bool)

SetAlwaysFormsContainingBlock sets whether the node always forms a containing block

func (*Node) SetAspectRatio

func (n *Node) SetAspectRatio(aspectRatio float32)

SetAspectRatio sets the aspect ratio

func (*Node) SetBaselineFunc

func (n *Node) SetBaselineFunc(baselineFunc BaselineFunc)

SetBaselineFunc sets the baseline function

func (*Node) SetBorder

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

SetBorder sets the border width

func (*Node) SetBoxSizing

func (n *Node) SetBoxSizing(boxSizing BoxSizing)

SetBoxSizing sets the box model type

func (*Node) SetChildren

func (n *Node) SetChildren(children *Node, count uint32)

SetChildren sets children according to the given list of nodes.

func (*Node) SetConfig

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

SetConfig sets the configuration for the node

func (*Node) SetContext

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

SetContext sets the context for the node

func (*Node) SetDirection

func (n *Node) SetDirection(direction Direction)

SetDirection sets the document flow direction

func (*Node) SetDirtiedFunc

func (n *Node) SetDirtiedFunc(dirtiedFunc DirtiedFunc)

SetDirtiedFunc sets the dirtied callback function

func (*Node) SetDisplay

func (n *Node) SetDisplay(display Display)

SetDisplay sets the display behavior

func (*Node) SetFlex

func (n *Node) SetFlex(flex float32)

SetFlex sets the flex layout

func (*Node) SetFlexBasis

func (n *Node) SetFlexBasis(flexBasis float32)

SetFlexBasis sets the flex basis size

func (*Node) SetFlexBasisAuto

func (n *Node) SetFlexBasisAuto()

SetFlexBasisAuto sets the flex basis size to auto

func (*Node) SetFlexBasisFitContent

func (n *Node) SetFlexBasisFitContent()

SetFlexBasisFitContent sets the flex basis to fit-content

func (*Node) SetFlexBasisMaxContent

func (n *Node) SetFlexBasisMaxContent()

SetFlexBasisMaxContent sets the flex basis to max-content

func (*Node) SetFlexBasisPercent

func (n *Node) SetFlexBasisPercent(flexBasis float32)

SetFlexBasisPercent sets the flex basis size in percentage

func (*Node) SetFlexBasisStretch

func (n *Node) SetFlexBasisStretch()

SetFlexBasisStretch sets the flex basis to stretch

func (*Node) SetFlexDirection

func (n *Node) SetFlexDirection(flexDirection FlexDirection)

SetFlexDirection sets the flex direction

func (*Node) SetFlexGrow

func (n *Node) SetFlexGrow(flexGrow float32)

SetFlexGrow sets the flex grow factor

func (*Node) SetFlexShrink

func (n *Node) SetFlexShrink(flexShrink float32)

SetFlexShrink sets the flex shrink factor

func (*Node) SetFlexWrap

func (n *Node) SetFlexWrap(flexWrap Wrap)

SetFlexWrap sets the wrapping behavior

func (*Node) SetGap

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

SetGap sets the gap

func (*Node) SetGapPercent

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

SetGapPercent sets the gap in percentage

func (*Node) SetHasNewLayout

func (n *Node) SetHasNewLayout(hasNewLayout bool)

SetHasNewLayout marks the layout as seen

func (*Node) SetHeight

func (n *Node) SetHeight(height float32)

SetHeight sets the height

func (*Node) SetHeightAuto

func (n *Node) SetHeightAuto()

SetHeightAuto sets the height to auto

func (*Node) SetHeightFitContent

func (n *Node) SetHeightFitContent()

SetHeightFitContent sets the height to fit-content

func (*Node) SetHeightMaxContent

func (n *Node) SetHeightMaxContent()

SetHeightMaxContent sets the height to max-content

func (*Node) SetHeightPercent

func (n *Node) SetHeightPercent(height float32)

SetHeightPercent sets the height in percentage

func (*Node) SetHeightStretch

func (n *Node) SetHeightStretch()

SetHeightStretch sets the height to stretch

func (*Node) SetIsReferenceBaseline

func (n *Node) SetIsReferenceBaseline(isReferenceBaseline bool)

SetIsReferenceBaseline sets whether the node is a reference baseline

func (*Node) SetJustifyContent

func (n *Node) SetJustifyContent(justifyContent Justify)

SetJustifyContent sets the alignment along the main axis

func (*Node) SetMargin

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

SetMargin sets the margin

func (*Node) SetMarginAuto

func (n *Node) SetMarginAuto(edge Edge)

SetMarginAuto sets the margin to auto

func (*Node) SetMarginPercent

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

SetMarginPercent sets the margin in percentage

func (*Node) SetMaxHeight

func (n *Node) SetMaxHeight(maxHeight float32)

SetMaxHeight sets the maximum height

func (*Node) SetMaxHeightFitContent

func (n *Node) SetMaxHeightFitContent()

SetMaxHeightFitContent sets the maximum height to fit-content

func (*Node) SetMaxHeightMaxContent

func (n *Node) SetMaxHeightMaxContent()

SetMaxHeightMaxContent sets the maximum height to max-content

func (*Node) SetMaxHeightPercent

func (n *Node) SetMaxHeightPercent(maxHeight float32)

SetMaxHeightPercent sets the maximum height in percentage

func (*Node) SetMaxHeightStretch

func (n *Node) SetMaxHeightStretch()

SetMaxHeightStretch sets the maximum height to stretch

func (*Node) SetMaxWidth

func (n *Node) SetMaxWidth(maxWidth float32)

SetMaxWidth sets the maximum width

func (*Node) SetMaxWidthFitContent

func (n *Node) SetMaxWidthFitContent()

SetMaxWidthFitContent sets the maximum width to fit-content

func (*Node) SetMaxWidthMaxContent

func (n *Node) SetMaxWidthMaxContent()

SetMaxWidthMaxContent sets the maximum width to max-content

func (*Node) SetMaxWidthPercent

func (n *Node) SetMaxWidthPercent(maxWidth float32)

SetMaxWidthPercent sets the maximum width in percentage

func (*Node) SetMaxWidthStretch

func (n *Node) SetMaxWidthStretch()

SetMaxWidthStretch sets the maximum width to stretch

func (*Node) SetMeasureFunc

func (n *Node) SetMeasureFunc(measureFunc MeasureFunc)

SetMeasureFunc sets the measurement function

func (*Node) SetMinHeight

func (n *Node) SetMinHeight(minHeight float32)

SetMinHeight sets the minimum height

func (*Node) SetMinHeightFitContent

func (n *Node) SetMinHeightFitContent()

SetMinHeightFitContent sets the minimum height to fit-content

func (*Node) SetMinHeightMaxContent

func (n *Node) SetMinHeightMaxContent()

SetMinHeightMaxContent sets the minimum height to max-content

func (*Node) SetMinHeightPercent

func (n *Node) SetMinHeightPercent(minHeight float32)

SetMinHeightPercent sets the minimum height in percentage

func (*Node) SetMinHeightStretch

func (n *Node) SetMinHeightStretch()

SetMinHeightStretch sets the minimum height to stretch

func (*Node) SetMinWidth

func (n *Node) SetMinWidth(minWidth float32)

SetMinWidth sets the minimum width

func (*Node) SetMinWidthFitContent

func (n *Node) SetMinWidthFitContent()

SetMinWidthFitContent sets the minimum width to fit-content

func (*Node) SetMinWidthMaxContent

func (n *Node) SetMinWidthMaxContent()

SetMinWidthMaxContent sets the minimum width to max-content

func (*Node) SetMinWidthPercent

func (n *Node) SetMinWidthPercent(minWidth float32)

SetMinWidthPercent sets the minimum width in percentage

func (*Node) SetMinWidthStretch

func (n *Node) SetMinWidthStretch()

SetMinWidthStretch sets the minimum width to stretch

func (*Node) SetNodeType

func (n *Node) SetNodeType(nodeType NodeType)

SetNodeType Sets whether a leaf node's layout results may be truncated during layout rounding.

func (*Node) SetOverflow

func (n *Node) SetOverflow(overflow Overflow)

SetOverflow sets the overflow behavior

func (*Node) SetPadding

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

SetPadding sets the padding

func (*Node) SetPaddingPercent

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

SetPaddingPercent sets the padding in percentage

func (*Node) SetPosition

func (n *Node) SetPosition(edge Edge, position float32)

SetPosition sets the position

func (*Node) SetPositionAuto

func (n *Node) SetPositionAuto(edge Edge)

SetPositionAuto sets the position to auto

func (*Node) SetPositionPercent

func (n *Node) SetPositionPercent(edge Edge, position float32)

SetPositionPercent sets the position in percentage

func (*Node) SetPositionType

func (n *Node) SetPositionType(positionType PositionType)

SetPositionType sets the position type

func (*Node) SetWidth

func (n *Node) SetWidth(width float32)

SetWidth sets the width

func (*Node) SetWidthAuto

func (n *Node) SetWidthAuto()

SetWidthAuto sets the width to auto

func (*Node) SetWidthFitContent

func (n *Node) SetWidthFitContent()

SetWidthFitContent sets the width to fit-content

func (*Node) SetWidthMaxContent

func (n *Node) SetWidthMaxContent()

SetWidthMaxContent sets the width to max-content

func (*Node) SetWidthPercent

func (n *Node) SetWidthPercent(width float32)

SetWidthPercent sets the width in percentage

func (*Node) SetWidthStretch

func (n *Node) SetWidthStretch()

SetWidthStretch sets the width to stretch

func (*Node) SwapChild

func (n *Node) SwapChild(child *Node, index uint32)

SwapChild replaces the child node at the specified index with a new one

func (*Node) ToYogaLayout

func (n *Node) ToYogaLayout() string

ToYogaLayout generates a JSX representation of the node tree compatible with yogalayout.dev playground

func (*Node) UnsetDirtiedFunc

func (n *Node) UnsetDirtiedFunc()

UnsetDirtiedFunc unsets the dirtied callback function

func (*Node) UnsetMeasureFunc

func (n *Node) UnsetMeasureFunc()

UnsetMeasureFunc unsets the measurement function

type NodeContext

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

NodeContext 存储节点的回调句柄,避免全局 map 查找

type NodeType

type NodeType int

NodeType represents the enum type for NodeType

const (
	NodeTypeDefault NodeType = iota
	NodeTypeText
)

func NodeTypeFromString

func NodeTypeFromString(s string) (NodeType, error)

NodeTypeFromString parses NodeType enum value from string

func (NodeType) String

func (e NodeType) String() string

String returns the string representation of NodeType

type Overflow

type Overflow int

Overflow represents the enum type for Overflow

const (
	OverflowVisible Overflow = iota
	OverflowHidden
	OverflowScroll
)

func OverflowFromString

func OverflowFromString(s string) (Overflow, error)

OverflowFromString parses Overflow enum value from string

func (Overflow) String

func (e Overflow) String() string

String returns the string representation of Overflow

type PositionType

type PositionType int

PositionType represents the enum type for PositionType

const (
	PositionTypeStatic PositionType = iota
	PositionTypeRelative
	PositionTypeAbsolute
)

func PositionTypeFromString

func PositionTypeFromString(s string) (PositionType, error)

PositionTypeFromString parses PositionType enum value from string

func (PositionType) String

func (e PositionType) String() string

String returns the string representation of PositionType

type Size

type Size struct {
	Width  float32
	Height float32
}

Size represents the measurement result

type Unit

type Unit int

Unit represents the enum type for Unit

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

func UnitFromString

func UnitFromString(s string) (Unit, error)

UnitFromString parses Unit enum value from string

func (Unit) String

func (e Unit) String() string

String returns the string representation of Unit

type Value

type Value struct {
	Value float32
	Unit  Unit
}

Value represents the Yoga style value

func (Value) Equal

func (v Value) Equal(other Value) bool

func (Value) IsAuto

func (v Value) IsAuto() bool

func (Value) IsUndefined

func (v Value) IsUndefined() bool

func (*Value) NotEqual

func (v *Value) NotEqual(other Value) bool

type Wrap

type Wrap int

Wrap represents the enum type for Wrap

const (
	WrapNoWrap Wrap = iota
	WrapWrap
	WrapWrapReverse
)

func WrapFromString

func WrapFromString(s string) (Wrap, error)

WrapFromString parses Wrap enum value from string

func (Wrap) String

func (e Wrap) String() string

String returns the string representation of Wrap

Directories

Path Synopsis
benchmark module