Documentation
¶
Index ¶
- type App
- func (a *App) AddFocusable(widgets ...graphics.Widget)
- func (a *App) Configure(fn func(*gapp.App))
- func (a *App) FindElement(id string) *Element
- func (a *App) Focus(widget graphics.Widget)
- func (a *App) InternalApp() *gapp.App
- func (a *App) LoadFile(path string, handler interface{}) error
- func (a *App) LoadString(source string, handler interface{}) error
- func (a *App) Quit()
- func (a *App) Redraw()
- func (a *App) Root() *Element
- func (a *App) Run() error
- func (a *App) SetOptions(opts gapp.Options)
- type BuildError
- type ComponentDef
- type ComponentRegistry
- func (r *ComponentRegistry) BuildElement(node *Node, handler interface{}) (*Element, error)
- func (r *ComponentRegistry) Has(name string) bool
- func (r *ComponentRegistry) Instantiate(name string, node *Node, handler interface{}) (*Element, error)
- func (r *ComponentRegistry) Lookup(name string) *ComponentDef
- func (r *ComponentRegistry) Register(def *ComponentDef)
- type Document
- type Element
- func (e *Element) AddChild(child *Element)
- func (e *Element) Attr(name, def string) string
- func (e *Element) AttrBool(name string, def bool) bool
- func (e *Element) AttrColor(name string, def graphics.Color) graphics.Color
- func (e *Element) AttrFloat(name string, def float64) float64
- func (e *Element) AttrInt(name string, def int) int
- func (e *Element) BindSignal(name string, fn interface{}) bool
- func (e *Element) Bounds() graphics.Rect
- func (e *Element) ChildElements() []*Element
- func (e *Element) Children() []graphics.Widget
- func (e *Element) ClearChildren()
- func (e *Element) Draw(buf *graphics.Buffer)
- func (e *Element) EmitSignal(name string, args ...interface{})
- func (e *Element) FindChild(id string) *Element
- func (e *Element) GetAttribute(name string) string
- func (e *Element) HandleEvent(ev graphics.Event) bool
- func (e *Element) ID() string
- func (e *Element) IsDirty() bool
- func (e *Element) IsFocused() bool
- func (e *Element) IsVisible() bool
- func (e *Element) MarkClean()
- func (e *Element) MarkDirty()
- func (e *Element) MinSize() graphics.Point
- func (e *Element) ScrollTextAreaToBottom()
- func (e *Element) SelfDirty() bool
- func (e *Element) SetAttribute(name string, value interface{})
- func (e *Element) SetBounds(r graphics.Rect)
- func (e *Element) SetFocused(focused bool)
- func (e *Element) SetID(id string)
- func (e *Element) SetTerminalBuffer(lines [][]TerminalCell, cursorCol, cursorRow int, showCursor bool)
- func (e *Element) SetVisible(visible bool)
- func (e *Element) Tag() string
- func (e *Element) TextAreaAtBottom(threshold int) bool
- type Engine
- type ImportDecl
- type Node
- type ParseError
- type Property
- type SignalDecl
- type TerminalCell
- type Value
- type ValueKind
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 ¶
AddFocusable registers focusable widgets.
func (*App) Configure ¶
Configure registers a callback invoked after app construction and before Run.
func (*App) FindElement ¶
FindElement searches the element tree by id.
func (*App) InternalApp ¶
InternalApp returns the underlying app.App for advanced use.
func (*App) LoadFile ¶
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 ¶
LoadString loads UI from a string source.
func (*App) SetOptions ¶
SetOptions sets app.App options used when Run starts the app.
type BuildError ¶
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.
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 ¶
CollectFocusable collects all elements with focusable=true.
func FindElement ¶
FindElement searches the tree for an element by id.
func NewElement ¶
NewElement creates a new Element with the given tag.
func (*Element) BindSignal ¶
BindSignal binds a runtime signal handler (for example "clicked").
func (*Element) ChildElements ¶
ChildElements returns child elements.
func (*Element) ClearChildren ¶
func (e *Element) ClearChildren()
ClearChildren removes all child elements.
func (*Element) EmitSignal ¶
EmitSignal emits a signal by name with optional args.
func (*Element) GetAttribute ¶
GetAttribute returns an attribute value.
func (*Element) ScrollTextAreaToBottom ¶
func (e *Element) ScrollTextAreaToBottom()
ScrollTextAreaToBottom moves the multiline viewport to the newest lines.
func (*Element) SetAttribute ¶
SetAttribute sets an attribute value and marks dirty.
func (*Element) SetFocused ¶
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 (*Element) TextAreaAtBottom ¶
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.
type ImportDecl ¶
ImportDecl represents an import statement.
type Node ¶
Node represents an element in the UI tree.
func (*Node) PropString ¶
PropString returns the string representation of a property.
type ParseError ¶
ParseError represents an error during UI parsing with location info.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
type SignalDecl ¶
SignalDecl represents a signal declaration inside a component.
type TerminalCell ¶
TerminalCell holds one terminal glyph with resolved foreground/background colors.