ui

package
v0.0.0-...-7e1b392 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2026 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

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

App is the base struct for UI applications. Embed this in your app struct and implement handler methods that get bound to UI signals.

Usage:

type MyApp struct {
    ui.App
}

func (a *MyApp) HandleClick() { ... }

func main() {
    app := &MyApp{}
    app.LoadFile("ui/demo.ui")
    app.Run()
}

func (*App) AddFocusable

func (a *App) AddFocusable(widgets ...graphics.Widget)

AddFocusable registers focusable widgets.

func (*App) Configure

func (a *App) Configure(fn func(*gapp.App))

Configure registers a callback invoked after app construction and before Run.

func (*App) FindElement

func (a *App) FindElement(id string) *Element

FindElement searches the element tree by id.

func (*App) Focus

func (a *App) Focus(widget graphics.Widget)

Focus sets initial or current focus.

func (*App) InternalApp

func (a *App) InternalApp() *gapp.App

InternalApp returns the underlying app.App for advanced use.

func (*App) LoadFile

func (a *App) LoadFile(path string, handler interface{}) error

LoadFile loads a .ui file and builds the element tree. The receiver (typically the embedding struct) is used as the signal handler.

func (*App) LoadString

func (a *App) LoadString(source string, handler interface{}) error

LoadString loads UI from a string source.

func (*App) Quit

func (a *App) Quit()

Quit stops the application.

func (*App) Redraw

func (a *App) Redraw()

Redraw forces a full screen redraw.

func (*App) Root

func (a *App) Root() *Element

Root returns the root element.

func (*App) Run

func (a *App) Run() error

Run starts the application main loop.

func (*App) SetOptions

func (a *App) SetOptions(opts gapp.Options)

SetOptions sets app.App options used when Run starts the app.

type BuildError

type BuildError struct {
	Line    int
	Element string
	Message string
}

BuildError represents an error during element tree construction.

func (*BuildError) Error

func (e *BuildError) Error() string

type ComponentDef

type ComponentDef struct {
	Name       string
	Properties []*Property  // property declarations with defaults
	Signals    []SignalDecl // signal declarations
	Defaults   []*Property  // default attribute values
	Children   []*Node      // child element templates (future)
	Line       int
}

ComponentDef represents a component definition.

type ComponentRegistry

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

ComponentRegistry holds parsed component definitions keyed by name.

func NewComponentRegistry

func NewComponentRegistry() *ComponentRegistry

NewComponentRegistry creates an empty registry.

func (*ComponentRegistry) BuildElement

func (r *ComponentRegistry) BuildElement(node *Node, handler interface{}) (*Element, error)

BuildElement builds an Element from an AST node, resolving components.

func (*ComponentRegistry) Has

func (r *ComponentRegistry) Has(name string) bool

Has returns true if the registry has a component with the given name.

func (*ComponentRegistry) Instantiate

func (r *ComponentRegistry) Instantiate(name string, node *Node, handler interface{}) (*Element, error)

Instantiate creates an Element from a component definition and an AST node. The node provides instance-specific property overrides and children.

func (*ComponentRegistry) Lookup

func (r *ComponentRegistry) Lookup(name string) *ComponentDef

Lookup returns a component definition by name, or nil.

func (*ComponentRegistry) Register

func (r *ComponentRegistry) Register(def *ComponentDef)

Register adds a component definition.

type Document

type Document struct {
	Imports    []ImportDecl
	Components []*ComponentDef
	Root       *Node // the root element (Window, VBox, etc.)
}

Document is the top-level parse result.

func Parse

func Parse(source string) (*Document, error)

Parse parses a .ui source into a Document.

type Element

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

Element is the universal DOM-like node. Every UI element is an Element. It implements graphics.Widget and renders entirely from attributes. Based on its attributes, it can behave as any widget: button, text input, checkbox, slider, container, etc.

func CollectFocusable

func CollectFocusable(root *Element) []*Element

CollectFocusable collects all elements with focusable=true.

func FindElement

func FindElement(root *Element, id string) *Element

FindElement searches the tree for an element by id.

func NewElement

func NewElement(tag string) *Element

NewElement creates a new Element with the given tag.

func (*Element) AddChild

func (e *Element) AddChild(child *Element)

AddChild adds a child element.

func (*Element) Attr

func (e *Element) Attr(name, def string) string

Attr returns the string attribute or default.

func (*Element) AttrBool

func (e *Element) AttrBool(name string, def bool) bool

AttrBool returns a boolean attribute or default.

func (*Element) AttrColor

func (e *Element) AttrColor(name string, def graphics.Color) graphics.Color

AttrColor returns a color attribute or default.

func (*Element) AttrFloat

func (e *Element) AttrFloat(name string, def float64) float64

AttrFloat returns a float attribute or default.

func (*Element) AttrInt

func (e *Element) AttrInt(name string, def int) int

AttrInt returns an integer attribute or default.

func (*Element) BindSignal

func (e *Element) BindSignal(name string, fn interface{}) bool

BindSignal binds a runtime signal handler (for example "clicked").

func (*Element) Bounds

func (e *Element) Bounds() graphics.Rect

func (*Element) ChildElements

func (e *Element) ChildElements() []*Element

ChildElements returns child elements.

func (*Element) Children

func (e *Element) Children() []graphics.Widget

Children returns child widgets (for app.App damage tracking).

func (*Element) ClearChildren

func (e *Element) ClearChildren()

ClearChildren removes all child elements.

func (*Element) Draw

func (e *Element) Draw(buf *graphics.Buffer)

func (*Element) EmitSignal

func (e *Element) EmitSignal(name string, args ...interface{})

EmitSignal emits a signal by name with optional args.

func (*Element) FindChild

func (e *Element) FindChild(id string) *Element

FindChild finds a descendant by id (depth-first).

func (*Element) GetAttribute

func (e *Element) GetAttribute(name string) string

GetAttribute returns an attribute value.

func (*Element) HandleEvent

func (e *Element) HandleEvent(ev graphics.Event) bool

func (*Element) ID

func (e *Element) ID() string

ID returns the element's id.

func (*Element) IsDirty

func (e *Element) IsDirty() bool

func (*Element) IsFocused

func (e *Element) IsFocused() bool

func (*Element) IsVisible

func (e *Element) IsVisible() bool

func (*Element) MarkClean

func (e *Element) MarkClean()

func (*Element) MarkDirty

func (e *Element) MarkDirty()

func (*Element) MinSize

func (e *Element) MinSize() graphics.Point

func (*Element) ScrollTextAreaToBottom

func (e *Element) ScrollTextAreaToBottom()

ScrollTextAreaToBottom moves the multiline viewport to the newest lines.

func (*Element) SelfDirty

func (e *Element) SelfDirty() bool

func (*Element) SetAttribute

func (e *Element) SetAttribute(name string, value interface{})

SetAttribute sets an attribute value and marks dirty.

func (*Element) SetBounds

func (e *Element) SetBounds(r graphics.Rect)

func (*Element) SetFocused

func (e *Element) SetFocused(focused bool)

func (*Element) SetID

func (e *Element) SetID(id string)

SetID updates the element id.

func (*Element) SetTerminalBuffer

func (e *Element) SetTerminalBuffer(lines [][]TerminalCell, cursorCol, cursorRow int, showCursor bool)

SetTerminalBuffer updates a multiline element with terminal-styled cells. It keeps the text-area scroll state while replacing its backing lines.

func (*Element) SetVisible

func (e *Element) SetVisible(visible bool)

func (*Element) Tag

func (e *Element) Tag() string

Tag returns the element's tag name.

func (*Element) TextAreaAtBottom

func (e *Element) TextAreaAtBottom(threshold int) bool

TextAreaAtBottom reports whether the current multiline viewport is at the end.

type Engine

type Engine struct {
	Registry *ComponentRegistry
}

Engine loads .ui files and builds Element trees.

func NewEngine

func NewEngine() (*Engine, error)

NewEngine creates a new Engine with the standard library loaded.

func (*Engine) LoadFile

func (eng *Engine) LoadFile(path string, handler interface{}) (*Element, error)

LoadFile loads a .ui file from disk and builds the root Element.

func (*Engine) LoadString

func (eng *Engine) LoadString(source string, handler interface{}) (*Element, error)

LoadString parses a .ui source string and builds the root Element. The handler receives signal connections (onXxx: MethodName).

type ImportDecl

type ImportDecl struct {
	Path string
	Line int
}

ImportDecl represents an import statement.

type Node

type Node struct {
	TypeName   string
	Properties []*Property
	Children   []*Node
	Line       int
}

Node represents an element in the UI tree.

func (*Node) PropBool

func (n *Node) PropBool(name string, def bool) bool

PropBool returns the bool value of a property, or the default.

func (*Node) PropFloat

func (n *Node) PropFloat(name string, def float64) float64

PropFloat returns the float value of a property, or the default.

func (*Node) PropInt

func (n *Node) PropInt(name string, def int) int

PropInt returns the int value of a property, or the default.

func (*Node) PropString

func (n *Node) PropString(name string) string

PropString returns the string representation of a property.

func (*Node) PropValue

func (n *Node) PropValue(name string) (Value, bool)

PropValue returns the Value for a named property, or zero Value and false.

type ParseError

type ParseError struct {
	Line    int
	Column  int
	Message string
}

ParseError represents an error during UI parsing with location info.

func (*ParseError) Error

func (e *ParseError) Error() string

type Property

type Property struct {
	Name  string
	Value Value
	Line  int
}

Property is a key-value pair in a Node.

type SignalDecl

type SignalDecl struct {
	Name string
	Line int
}

SignalDecl represents a signal declaration inside a component.

type TerminalCell

type TerminalCell struct {
	Char      rune
	Fg        graphics.Color
	Bg        graphics.Color
	Underline bool
}

TerminalCell holds one terminal glyph with resolved foreground/background colors.

type Value

type Value struct {
	Kind  ValueKind
	Str   string
	Int   int64
	Float float64
	Bool  bool
}

Value is a parsed property value.

type ValueKind

type ValueKind int

ValueKind distinguishes the type of a parsed value.

const (
	ValueString ValueKind = iota
	ValueInt
	ValueFloat
	ValueBool
	ValueIdent
)

Jump to

Keyboard shortcuts

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