avyos.dev/pkg/graphics/ui
package ui
Package Overview
No package-level documentation is provided.
| Export Group | Count |
|---|---|
| Constants | 1 |
| Variables | 0 |
| Functions | 0 |
| Types | 15 |
Constants
const (
ValueString = uiparse.ValueString
ValueInt = uiparse.ValueInt
ValueFloat = uiparse.ValueFloat
ValueBool = uiparse.ValueBool
ValueIdent = uiparse.ValueIdent
)Types
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() }
Methods
func (a *App) AddFocusable(widgets ...graphics.Widget)AddFocusable registers focusable widgets.
func (a *App) CloseMenu()CloseMenu closes the currently open popup menu, if any.
func (a *App) Configure(fn func(*gapp.App))Configure registers a callback invoked after app construction and before Run.
func (a *App) FindElement(id string) *ElementFindElement searches the element tree by id.
func (a *App) Focus(widget graphics.Widget)Focus sets initial or current focus.
func (a *App) InternalApp() *gapp.AppInternalApp returns the underlying app.App for advanced use.
func (a *App) LoadFile(path string, handler interface{}) errorLoadFile loads a .ui file and builds the element tree. The receiver (typically the embedding struct) is used as the signal handler.
func (a *App) LoadString(source string, handler interface{}) errorLoadString loads UI from a string source.
func (a *App) OpenMenu(menuID string, x, y int) boolOpenMenu opens a popup menu at window-local coordinates (x, y) using the menu definition found by menuID in the current UI tree.
func (a *App) Quit()Quit stops the application.
func (a *App) Redraw()Redraw forces a full screen redraw.
func (a *App) RegisterClientShortcut(shortcutID, windowID uint32, key graphics.Key, ch rune, modifiers graphics.Modifiers, handler func(graphics.Event)) errorRegisterClientShortcut registers a shortcut scoped to this client. Pass windowID=0 to match any window from this client.
func (a *App) RegisterGlobalShortcut(shortcutID uint32, key graphics.Key, ch rune, modifiers graphics.Modifiers, handler func(graphics.Event)) errorRegisterGlobalShortcut registers a global shortcut callback.
func (a *App) RegisterShortcut(shortcutID, windowID, scope uint32, key graphics.Key, ch rune, modifiers graphics.Modifiers, handler func(graphics.Event)) errorRegisterShortcut registers a compositor shortcut callback. For rune-based shortcuts use key=graphics.KeyNone and set ch.
func (a *App) RequestFrame()RequestFrame schedules a render pass using incremental damage when possible.
func (a *App) Root() *ElementRoot returns the root element.
func (a *App) Run() errorRun starts the application main loop.
func (a *App) SetOptions(opts gapp.Options)SetOptions sets app.App options used when Run starts the app.
func (a *App) UnregisterShortcut(shortcutID uint32) errorUnregisterShortcut removes a previously registered shortcut callback.
BuildError
type BuildError = uiparse.BuildErrorComponentDef
type ComponentDef = uiparse.ComponentDefComponentRegistry
type ComponentRegistry struct {
// contains filtered or unexported fields
}ComponentRegistry holds parsed component definitions keyed by name.
Functions
func NewComponentRegistry() *ComponentRegistryNewComponentRegistry creates an empty registry.
Methods
func (r *ComponentRegistry) BuildElement(node *Node, handler interface{}) (*Element, error)BuildElement builds an Element from an AST node, resolving components.
func (r *ComponentRegistry) Has(name string) boolHas returns true if the registry has a component with the given name.
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 (r *ComponentRegistry) Lookup(name string) *ComponentDefLookup returns a component definition by name, or nil.
func (r *ComponentRegistry) Register(def *ComponentDef)Register adds a component definition.
Document
type Document = uiparse.DocumentFunctions
func Parse(source string) (*Document, error)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.
Functions
func CollectFocusable(root *Element) []*ElementCollectFocusable collects all elements with focusable=true.
func FindElement(root *Element, id string) *ElementFindElement searches the tree for an element by id.
func NewElement(tag string) *ElementNewElement creates a new Element with the given tag.
Methods
func (e *Element) AddChild(child *Element)AddChild adds a child element.
func (e *Element) Attr(name, def string) stringAttr returns the string attribute or default.
func (e *Element) AttrBool(name string, def bool) boolAttrBool returns a boolean attribute or default.
func (e *Element) AttrColor(name string, def graphics.Color) graphics.ColorAttrColor returns a color attribute or default.
func (e *Element) AttrFloat(name string, def float64) float64AttrFloat returns a float attribute or default.
func (e *Element) AttrInt(name string, def int) intAttrInt returns an integer attribute or default.
func (e *Element) BindSignal(name string, fn interface{}) boolBindSignal binds a runtime signal handler (for example "clicked").
func (e *Element) Bounds() graphics.Rectfunc (e *Element) ChildElements() []*ElementChildElements returns child elements.
func (e *Element) Children() []graphics.WidgetChildren returns child widgets (for app.App damage tracking).
func (e *Element) ClearChildren()ClearChildren removes all child elements.
func (e *Element) DirtyRects() []graphics.RectDirtyRects returns optional subregions that should be redrawn for this widget. Nil means repaint the full widget bounds.
func (e *Element) Draw(buf *graphics.Buffer)func (e *Element) EmitSignal(name string, args ...interface{})EmitSignal emits a signal by name with optional args.
func (e *Element) FindChild(id string) *ElementFindChild finds a descendant by id (depth-first).
func (e *Element) GetAttribute(name string) stringGetAttribute returns an attribute value.
func (e *Element) HandleEvent(ev graphics.Event) boolfunc (e *Element) ID() stringID returns the element's id.
func (e *Element) IsDirty() boolfunc (e *Element) IsFocused() boolfunc (e *Element) IsVisible() boolfunc (e *Element) MarkClean()func (e *Element) MarkDirty()func (e *Element) MinSize() graphics.Pointfunc (e *Element) ScrollTextAreaToBottom()ScrollTextAreaToBottom moves the multiline viewport to the newest lines.
func (e *Element) SelfDirty() boolfunc (e *Element) SetAttribute(name string, value interface{})SetAttribute sets an attribute value and marks dirty.
func (e *Element) SetBounds(r graphics.Rect)func (e *Element) SetFocused(focused bool)func (e *Element) SetID(id string)SetID updates the element id.
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 (e *Element) SetVisible(visible bool)func (e *Element) Tag() stringTag returns the element's tag name.
func (e *Element) TextAreaAtBottom(threshold int) boolTextAreaAtBottom reports whether the current multiline viewport is at the end.
Engine
type Engine struct {
Registry *ComponentRegistry
}Engine loads .ui files and builds Element trees.
Functions
func NewEngine() (*Engine, error)NewEngine creates a new Engine with the standard library loaded.
Methods
func (eng *Engine) LoadFile(path string, handler interface{}) (*Element, error)LoadFile loads a .ui file from disk and builds the root Element.
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).
ImportDecl
type ImportDecl = uiparse.ImportDeclNode
type Node = uiparse.NodeParseError
type ParseError = uiparse.ParseErrorProperty
type Property = uiparse.PropertySignalDecl
type SignalDecl = uiparse.SignalDeclTerminalCell
type TerminalCell struct {
Char rune
Fg graphics.Color
Bg graphics.Color
Underline bool
}TerminalCell holds one terminal glyph with resolved foreground/background colors.
Value
type Value = uiparse.ValueValueKind
type ValueKind = uiparse.ValueKind