avyos.dev/pkg/graphics/app
package app
Overview
No package-level documentation is provided.
| Export Group | Count |
|---|---|
| Constants | 0 |
| Variables | 0 |
| Functions | 0 |
| Types | 3 |
Types
App
type App struct {
OnQuit func()
OnEscape func() // If set, called on Escape instead of quitting.
OnEvent func(ev gfxinput.Event) bool
// contains filtered or unexported fields
}App represents the main application with a single root widget that fills the entire screen.
Functions
New
func New(opts Options) *AppNew creates a new application with the given options.
Methods
AddFocusable
func (a *App) AddFocusable(widgets ...Widget)AddFocusable registers a widget for keyboard focus (tab navigation). These are typically interactive leaf widgets (buttons, text inputs) that live somewhere inside the root widget tree.
Backend
func (a *App) Backend() gfxdisplay.BackendBackend returns the display backend.
ClearFocusables
func (a *App) ClearFocusables()ClearFocusables removes all registered focusable widgets.
CloseMenu
func (a *App) CloseMenu()CloseMenu closes the currently open popup menu, if any.
Configure
func (a *App) Configure(fn func(*App))Configure registers a callback invoked once before Run starts.
FindElement
func (a *App) FindElement(id string) *ui.ElementFindElement searches the loaded declarative tree by id.
Focus
func (a *App) Focus(widget Widget)Focus sets keyboard focus to a specific widget.
FocusNext
func (a *App) FocusNext()FocusNext moves focus to the next focusable widget.
FocusPrevious
func (a *App) FocusPrevious()FocusPrevious moves focus to the previous focusable widget.
Input
func (a *App) Input() gfxinput.HandlerInput returns the input handler.
LoadFile
func (a *App) LoadFile(path string, handler interface{}) errorLoadFile loads a .ui file and builds the element tree.
LoadString
func (a *App) LoadString(source string, handler interface{}) errorLoadString loads UI from a string source.
OpenMenu
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.
Quit
func (a *App) Quit()Quit stops the application.
Redraw
func (a *App) Redraw()Redraw marks the entire screen for redraw.
RegisterClientShortcut
func (a *App) RegisterClientShortcut(shortcutID, windowID uint32, key gfxinput.Key, ch rune, modifiers gfxinput.Modifiers, handler func(gfxinput.Event)) errorRegisterClientShortcut registers a shortcut scoped to this client. Pass windowID=0 to match any window from this client.
RegisterGlobalShortcut
func (a *App) RegisterGlobalShortcut(shortcutID uint32, key gfxinput.Key, ch rune, modifiers gfxinput.Modifiers, handler func(gfxinput.Event)) errorRegisterGlobalShortcut registers a global shortcut callback.
RegisterShortcut
func (a *App) RegisterShortcut(shortcutID, windowID, scope uint32, key gfxinput.Key, ch rune, modifiers gfxinput.Modifiers, handler func(gfxinput.Event)) errorRegisterShortcut registers a compositor shortcut callback. If key is gfxinput.KeyNone, ch must be a printable rune.
RequestFrame
func (a *App) RequestFrame()RequestFrame schedules a render pass without forcing a full-screen redraw.
Root
func (a *App) Root() WidgetRoot returns the current root widget.
Run
func (a *App) Run() errorRun starts the main application loop. The root widget is resized to fill the entire framebuffer.
SetBackground
func (a *App) SetBackground(c color.NRGBA)SetBackground sets the background color.
SetDebugDamage
func (a *App) SetDebugDamage(enabled bool)SetDebugDamage enables or disables the damage flash overlay. When enabled, repainted regions flash red and fade out over several frames, similar to Android's "Show surface updates" developer option.
SetDebugFlashColor
func (a *App) SetDebugFlashColor(c color.NRGBA)SetDebugFlashColor sets the flash overlay color (default semi-transparent red).
SetDebugFlashFrames
func (a *App) SetDebugFlashFrames(frames int)SetDebugFlashFrames sets how many frames each flash persists (default 6).
SetFPS
func (a *App) SetFPS(fps int)SetFPS sets the target frames per second.
SetOptions
func (a *App) SetOptions(opts Options)SetOptions configures app startup options on this instance.
SetRoot
func (a *App) SetRoot(widget Widget)SetRoot sets the single root widget. It will be resized to fill the entire screen when Run() is called.
SetTitle
func (a *App) SetTitle(title string)SetTitle sets the application title (informational only).
Size
func (a *App) Size() (width, height int)Size returns the screen size.
UIRoot
func (a *App) UIRoot() *ui.ElementUIRoot returns the declarative root element, if loaded.
UnregisterShortcut
func (a *App) UnregisterShortcut(shortcutID uint32) errorUnregisterShortcut removes a previously registered shortcut callback.
Options
type Options struct {
Title string // Window title.
Width int // Window width; 0 = default (800).
Height int // Window height; 0 = default (600).
Backend gfxdisplay.Backend // Display backend (required).
Input gfxinput.Handler // Input handler (required).
FPS int // Target FPS; 0 = default (60).
Background color.NRGBA // Background color.
BackgroundSet bool // When true, use Background even if it is transparent (0 alpha).
}Options configures a new application.
Widget
type Widget interface {
Draw(buf *core.Buffer)
Bounds() image.Rectangle
SetBounds(r image.Rectangle)
MinSize() image.Point
HandleEvent(ev gfxinput.Event) bool
SetFocused(focused bool)
IsFocused() bool
IsDirty() bool
MarkClean()
SetVisible(visible bool)
IsVisible() bool
}Widget is the rendering/input contract expected by app.App.