Input, focus and async

Focus and tab order, overlays, animation, background work, shortcuts, file drops and the clipboard.

  • Focus. Interactive DSL widgets register themselves. Tab order is Layout order. .DefaultFocus() / c.Focus().EnsureFocus(w) picks a fallback when nothing is focused. Open dialogs call BeginModal then SetModal so Tab and keys stay inside the dialog.
  • Overlays. Menus, selects, dialogs, and toasts call c.Overlay(el). Overlays paint and hit-test on top of the body.
  • Animation. c.Animate(d) schedules a repaint within d (caret blink, spinner, polling). The runtime waits the minimum requested duration, or sleeps until the next OS event.
  • Background work. Safe to call c.Invalidate() from any goroutine (a job finished, HTTP returned). Typical pattern: a result channel drained at the top of Body, plus c.Animate(30*time.Millisecond) while a request is in flight.
  • Shortcuts. Read c.Keyboard() in Body, or implement yoga.KeyHook when a focused widget would otherwise eat the key.
  • File drops. c.Mouse().Dropped holds the paths of files dropped on the window this frame, at the pointer position. Set it to nil once taken.
  • Clipboard images. c.Clipboard() may also be an input.ImageClipboard; GetImage() returns the clipboard's picture as PNG. It works on macOS, and on Linux when wl-paste or xclip is installed. MemClipboard.SetImage fills it in tests.

Pointer handlers set m.Consumed = true to stop bubbling. Overlay hit-testing runs first.

Edit this page on GitHub
esc