app/app.go
Functions
func Frame
func (a *App) Frame() {
a.window.Frame()
}
func HandleEvent
HandleEvent dispatches a single event to the widget tree.
This method is an alternative to using an EventSource. It allows
the host application to push events manually.
func (a *App) HandleEvent(e event.Event) {
a.window.HandleEvent(e)
}
func New
New creates a new App with the given options.
When no options are provided, the App operates in headless mode with
default settings suitable for testing.
func New(opts ...Option) *App {
cfg := &appConfig{}
for _, opt := range opts {
opt(cfg)
}
t := cfg.theme
if t == nil {
t = theme.DefaultLight()
}
a := &App{
theme: t,
pp: cfg.pp,
}
// Create scheduler that marks dirty widgets for retained-mode rendering
// and requests a redraw.
a.scheduler = state.NewScheduler(func(dirty []widget.Widget) {
// Set persistent needsRedraw flag on each dirty widget.
// This flag survives until the draw pass clears it,
// unlike the scheduler's pending set which is cleared on flush.
for _, w := range dirty {
if setter, ok := w.(interface{ SetNeedsRedraw(bool) }); ok {
setter.SetNeedsRedraw(true)
}
}
if a.window != nil && a.window.wp != nil {
a.window.wp.RequestRedraw()
}
})
// Create the window.
a.window = newWindow(cfg.wp, cfg.pp, a.scheduler, t, cfg.renderMode)
// Attach event bridge if event source is provided.
if cfg.es != nil {
attachEventBridge(cfg.es, a.window)
}
return a
}
func PlatformProvider
PlatformProvider returns the platform provider, or nil if not set.
func (a *App) PlatformProvider() gpucontext.PlatformProvider {
return a.pp
}
func Scheduler
Scheduler returns the App's state scheduler.
func (a *App) Scheduler() *state.Scheduler {
return a.scheduler
}
func SetRoot
SetRoot sets the root widget for the App's window.
The root widget forms the top of the widget tree. It receives
layout constraints matching the window size and is drawn to fill
the window.
func (a *App) SetRoot(root widget.Widget) {
a.window.SetRoot(root)
}
func SetTheme
SetTheme changes the App's theme.
This updates both the App and Window theme and triggers a full redraw.
func (a *App) SetTheme(t *theme.Theme) {
if t == nil {
return
}
a.theme = t
a.window.setTheme(t)
}
func Theme
Theme returns the App's current theme.
func (a *App) Theme() *theme.Theme {
return a.theme
}
func Window
Window returns the App's Window.
func (a *App) Window() *Window {
return a.window
}
func WithEventSource
WithEventSource sets the event source for the App.
The EventSource delivers input events (keyboard, mouse, scroll, resize,
focus) from the host application. When nil, no events are delivered.
func WithEventSource(es gpucontext.EventSource) Option {
return func(c *appConfig) {
c.es = es
}
}
func WithPlatformProvider
WithPlatformProvider sets the platform provider for the App.
The PlatformProvider provides OS integration features such as clipboard,
cursor management, and accessibility preferences. When nil, these
features are unavailable.
func WithPlatformProvider(pp gpucontext.PlatformProvider) Option {
return func(c *appConfig) {
c.pp = pp
}
}
func WithRenderMode
WithRenderMode sets the rendering mode for the App's window.
RenderModeHostManaged (default): the host application draws the background
before calling DrawTo. DrawTo does not call canvas.Clear and always draws
the full widget tree.
RenderModeFrameworkManaged: the framework owns the pixmap and draws the
theme background. Enables frame skip (DrawTo returns false when idle)
and incremental dirty-region rendering.
See [RenderMode] for detailed documentation of each mode.
func WithRenderMode(mode RenderMode) Option {
return func(c *appConfig) {
c.renderMode = mode
}
}
func WithTheme
WithTheme sets the theme for the App.
When nil, the default light theme is used.
func WithTheme(t *theme.Theme) Option {
return func(c *appConfig) {
c.theme = t
}
}
func WithWindowProvider
WithWindowProvider sets the window provider for the App.
The WindowProvider provides window geometry (Size, ScaleFactor) and
the ability to request redraws. When nil, the App operates in headless
mode with a default 800x600 window at 1x scale.
func WithWindowProvider(wp gpucontext.WindowProvider) Option {
return func(c *appConfig) {
c.wp = wp
}
}
Structs
type App struct
App is the main entry point for the UI framework.
App bridges the widget tree with the windowing system through gpucontext
interfaces. It manages the Window, theme, and scheduler.
Create an App with [New] and functional options.
type App struct {
window *Window
theme *theme.Theme
scheduler *state.Scheduler
pp gpucontext.PlatformProvider
}
Frame performs one complete frame: layout, draw, and state management.
This method should be called by the host application's render loop
(e.g., gogpu.App's draw callback).