app

package
v0.0.0-...-155abb7 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: GPL-3.0 Imports: 20 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 {
	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.

func New

func New(opts Options) *App

New creates a new application with the given options.

func (*App) 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.

func (*App) Backend

func (a *App) Backend() gfxdisplay.Backend

Backend returns the display backend.

func (*App) ClearFocusables

func (a *App) ClearFocusables()

ClearFocusables removes all registered focusable widgets.

func (*App) CloseMenu

func (a *App) CloseMenu()

CloseMenu closes the currently open popup menu, if any.

func (*App) Configure

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

Configure registers a callback invoked once before Run starts.

func (*App) FindElement

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

FindElement searches the loaded declarative tree by id.

func (*App) Focus

func (a *App) Focus(widget Widget)

Focus sets keyboard focus to a specific widget.

func (*App) FocusNext

func (a *App) FocusNext()

FocusNext moves focus to the next focusable widget.

func (*App) FocusPrevious

func (a *App) FocusPrevious()

FocusPrevious moves focus to the previous focusable widget.

func (*App) Input

func (a *App) Input() gfxinput.Handler

Input returns the input handler.

func (*App) LoadFile

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

LoadFile loads a .ui file and builds the element tree.

func (*App) LoadString

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

LoadString loads UI from a string source.

func (*App) OpenMenu

func (a *App) OpenMenu(menuID string, x, y int) bool

OpenMenu opens a popup menu at window-local coordinates (x, y) using the menu definition found by menuID in the current UI tree.

func (*App) Quit

func (a *App) Quit()

Quit stops the application.

func (*App) Redraw

func (a *App) Redraw()

Redraw marks the entire screen for redraw.

func (*App) RegisterClientShortcut

func (a *App) RegisterClientShortcut(shortcutID, windowID uint32, key gfxinput.Key, ch rune, modifiers gfxinput.Modifiers, handler func(gfxinput.Event)) error

RegisterClientShortcut registers a shortcut scoped to this client. Pass windowID=0 to match any window from this client.

func (*App) RegisterGlobalShortcut

func (a *App) RegisterGlobalShortcut(shortcutID uint32, key gfxinput.Key, ch rune, modifiers gfxinput.Modifiers, handler func(gfxinput.Event)) error

RegisterGlobalShortcut registers a global shortcut callback.

func (*App) RegisterShortcut

func (a *App) RegisterShortcut(shortcutID, windowID, scope uint32, key gfxinput.Key, ch rune, modifiers gfxinput.Modifiers, handler func(gfxinput.Event)) error

RegisterShortcut registers a compositor shortcut callback. If key is gfxinput.KeyNone, ch must be a printable rune.

func (*App) RequestFrame

func (a *App) RequestFrame()

RequestFrame schedules a render pass without forcing a full-screen redraw.

func (*App) Root

func (a *App) Root() Widget

Root returns the current root widget.

func (*App) Run

func (a *App) Run() error

Run starts the main application loop. The root widget is resized to fill the entire framebuffer.

func (*App) SetBackground

func (a *App) SetBackground(c color.NRGBA)

SetBackground sets the background color.

func (*App) 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.

func (*App) SetDebugFlashColor

func (a *App) SetDebugFlashColor(c color.NRGBA)

SetDebugFlashColor sets the flash overlay color (default semi-transparent red).

func (*App) SetDebugFlashFrames

func (a *App) SetDebugFlashFrames(frames int)

SetDebugFlashFrames sets how many frames each flash persists (default 6).

func (*App) SetFPS

func (a *App) SetFPS(fps int)

SetFPS sets the target frames per second.

func (*App) SetOptions

func (a *App) SetOptions(opts Options)

SetOptions configures app startup options on this instance.

func (*App) 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.

func (*App) SetTitle

func (a *App) SetTitle(title string)

SetTitle sets the application title (informational only).

func (*App) Size

func (a *App) Size() (width, height int)

Size returns the screen size.

func (*App) UIRoot

func (a *App) UIRoot() *ui.Element

UIRoot returns the declarative root element, if loaded.

func (*App) UnregisterShortcut

func (a *App) UnregisterShortcut(shortcutID uint32) error

UnregisterShortcut removes a previously registered shortcut callback.

type 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.

type 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.

Jump to

Keyboard shortcuts

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