Documentation
¶
Index ¶
- func CompAsButton(c *widget.Component) *widget.Button
- func CompAsLabel(c *widget.Component) *widget.Label
- func EncodeIR(node *IRNode) ([]byte, error)
- func EvalExpression(node ExprNode, ctx *EvalContext) (any, error)
- func ParseColor(s string) sg.Color
- func ToBool(v any) bool
- type AttrSetter
- type BinOp
- type DataProvider
- type DirectiveType
- type EvalContext
- type ExprBinary
- type ExprConcat
- type ExprLiteral
- type ExprNode
- type ExprRef
- type ExprTernary
- type ExprUnary
- type FactoryContext
- type IRAttribute
- type IRDirective
- type IRNode
- type TemplateRegistry
- func (r *TemplateRegistry) Get(name string) *IRNode
- func (r *TemplateRegistry) Instantiate(name string, ctrl widget.Controller, screen *widget.Screen) (*widget.Component, error)
- func (r *TemplateRegistry) InstantiateIR(ir *IRNode, ctrl widget.Controller, screen *widget.Screen) (*widget.Component, error)
- func (r *TemplateRegistry) InstantiateStatic(name string, screen *widget.Screen) (*widget.Component, error)
- func (r *TemplateRegistry) RegisterBinary(name string, binData []byte) error
- func (r *TemplateRegistry) RegisterWidget(typeName string, factory WidgetFactory, setters map[string]AttrSetter)
- func (r *TemplateRegistry) RegisterXML(name string, xmlData []byte) error
- func (r *TemplateRegistry) SetFontSize(size float64)
- func (r *TemplateRegistry) SetFonts(fonts map[string]*sg.FontFamily, defaultFont *sg.FontFamily)
- func (r *TemplateRegistry) SetTheme(t *widget.Theme)
- func (r *TemplateRegistry) SetThemeJSON(data []byte) error
- type UnaryOp
- type WidgetFactory
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompAsButton ¶
CompAsButton is the exported equivalent of compAsButton, for use by the root package tests which cannot call the unexported version.
func CompAsLabel ¶
CompAsLabel is the exported equivalent of compAsLabel, for use by the root package tests which cannot call the unexported version.
func EvalExpression ¶
func EvalExpression(node ExprNode, ctx *EvalContext) (any, error)
EvalExpression evaluates an expression AST node in the given context.
func ParseColor ¶
ParseColor is the exported equivalent of parseColor, for use by the root package tests which cannot call the unexported version.
Types ¶
type AttrSetter ¶
AttrSetter applies a named attribute value to a custom widget component.
type DataProvider ¶
DataProvider is implemented by controllers that support XML template data binding.
type DirectiveType ¶
type DirectiveType int
DirectiveType identifies a structural directive in a compiled template.
const ( DirectiveIf DirectiveType = iota // ui:if="expr" DirectiveElseIf // ui:else-if="expr" DirectiveElse // ui:else DirectiveFor // ui:for="item in list" DirectiveKey // ui:key="expr" DirectiveShow // ui:show="expr" )
type EvalContext ¶
type EvalContext struct {
Provider DataProvider
Locals map[string]any
Parent *EvalContext
}
EvalContext provides the evaluation environment for expressions.
type ExprBinary ¶
ExprBinary is a binary operation (e.g. a + b, x == y).
type ExprConcat ¶
type ExprConcat struct {
Parts []ExprNode
}
ExprConcat is a string concatenation of parts (from interpolation).
type ExprLiteral ¶
type ExprLiteral struct {
Value any
}
ExprLiteral is a constant value (string, float64, bool, nil).
type ExprNode ¶
type ExprNode interface {
// contains filtered or unexported methods
}
ExprNode is the interface for all expression AST nodes.
func ParseExpression ¶
ParseExpression parses an expression string into an AST.
func ParseInterpolation ¶
ParseInterpolation is the exported equivalent of parseInterpolation, for use by the root package tests which cannot call the unexported version.
type ExprRef ¶
type ExprRef struct {
Path string
}
ExprRef is a dotted reference path like "user.name" or just "count".
type ExprTernary ¶
ExprTernary is a ternary conditional (cond ? then : else).
type FactoryContext ¶
type FactoryContext struct {
Fonts map[string]*sg.FontFamily
DefaultFont *sg.FontFamily
DefaultFontSize float64
// CustomVariants maps user-defined variant names to their Variant slots.
// Populated by SetTheme; nil means only built-in names are resolved.
CustomVariants map[string]widget.Variant
// contains filtered or unexported fields
}
FactoryContext provides resources needed by component factories.
type IRAttribute ¶
type IRAttribute struct {
Name string // attribute name (e.g. "text", "size")
Static string // static value (empty when Expr is set)
Expr ExprNode // parsed expression for bind: attributes
IsEvent bool // true for on:click etc.
}
IRAttribute represents a single attribute on an IR node.
type IRDirective ¶
type IRDirective struct {
Type DirectiveType
Expr ExprNode // condition or collection expression
VarName string // loop variable name (for ui:for)
}
IRDirective represents a structural directive attached to an IR node.
type IRNode ¶
type IRNode struct {
ComponentType string
Attributes []IRAttribute
Children []*IRNode
Directives []IRDirective
Text string // interpolated text content
ThemePatch []byte // raw JSON from a <Theme> child element (root node only)
}
IRNode is the intermediate representation of a compiled XML template element.
func CompileXML ¶
CompileXML parses XML template data and compiles it to an IR tree.
func CompileXMLWithTypes ¶
CompileXMLWithTypes parses XML template data and compiles it to an IR tree, accepting extra custom component type names in addition to built-in types.
type TemplateRegistry ¶
type TemplateRegistry struct {
// contains filtered or unexported fields
}
TemplateRegistry stores compiled XML templates and instantiates them.
func NewTemplateRegistry ¶
func NewTemplateRegistry() *TemplateRegistry
NewTemplateRegistry creates a new template registry.
func NewTemplateRegistryWithFont ¶
func NewTemplateRegistryWithFont(ttf []byte, size float64) (*TemplateRegistry, error)
NewTemplateRegistryWithFont creates a new template registry with a default font loaded from raw TTF data and a display font size. This is a convenience for the common 3-line boilerplate of NewTemplateRegistry + SetFonts + SetFontSize.
func (*TemplateRegistry) Get ¶
func (r *TemplateRegistry) Get(name string) *IRNode
Get returns the compiled IR for a named template.
func (*TemplateRegistry) Instantiate ¶
func (r *TemplateRegistry) Instantiate(name string, ctrl widget.Controller, screen *widget.Screen) (*widget.Component, error)
Instantiate creates a live component tree from a named template. ctrl may be nil for templates that have no reactive bindings or event handlers.
func (*TemplateRegistry) InstantiateIR ¶
func (r *TemplateRegistry) InstantiateIR(ir *IRNode, ctrl widget.Controller, screen *widget.Screen) (*widget.Component, error)
InstantiateIR creates a live component tree from an IR node directly.
func (*TemplateRegistry) InstantiateStatic ¶
func (r *TemplateRegistry) InstantiateStatic(name string, screen *widget.Screen) (*widget.Component, error)
InstantiateStatic creates a live component tree from a named template without any controller. Use this for templates that have no reactive bindings or event handlers.
func (*TemplateRegistry) RegisterBinary ¶
func (r *TemplateRegistry) RegisterBinary(name string, binData []byte) error
RegisterBinary decodes a .xmlui binary blob and registers the template by name.
func (*TemplateRegistry) RegisterWidget ¶
func (r *TemplateRegistry) RegisterWidget(typeName string, factory WidgetFactory, setters map[string]AttrSetter)
RegisterWidget registers a custom widget type for use in XML templates. The typeName must not collide with built-in widget names. The factory creates the component; setters apply XML attributes by name. RegisterWidget must be called before RegisterXML for any template that uses the custom widget type.
func (*TemplateRegistry) RegisterXML ¶
func (r *TemplateRegistry) RegisterXML(name string, xmlData []byte) error
RegisterXML compiles and registers an XML template by name.
func (*TemplateRegistry) SetFontSize ¶
func (r *TemplateRegistry) SetFontSize(size float64)
SetFontSize configures the default display font size for instantiation.
func (*TemplateRegistry) SetFonts ¶
func (r *TemplateRegistry) SetFonts(fonts map[string]*sg.FontFamily, defaultFont *sg.FontFamily)
SetFonts configures the font map and default font for instantiation.
func (*TemplateRegistry) SetTheme ¶
func (r *TemplateRegistry) SetTheme(t *widget.Theme)
SetTheme registers the compiled theme with the registry so that custom variant names declared in the theme JSON (e.g. "card", "muted") can be resolved when the variant attribute is used in templates.
func (*TemplateRegistry) SetThemeJSON ¶
func (r *TemplateRegistry) SetThemeJSON(data []byte) error
SetThemeJSON registers a theme from raw JSON bytes. The JSON is stored so that inline <Theme> patches in templates can be merged against it.