doc.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // SPDX-License-Identifier: Unlicense OR MIT
  2. /*
  3. Package app provides a platform-independent interface to operating system
  4. functionality for running graphical user interfaces.
  5. See https://gioui.org for instructions to set up and run Gio programs.
  6. # Windows
  7. A Window is run by calling its Event method in a loop. The first time a
  8. method on Window is called, a new GUI window is created and shown. On mobile
  9. platforms or when Gio is embedded in another project, Window merely connects
  10. with a previously created GUI window.
  11. The most important event is [FrameEvent] that prompts an update of the window
  12. contents.
  13. For example:
  14. w := new(app.Window)
  15. for {
  16. e := w.Event()
  17. if e, ok := e.(app.FrameEvent); ok {
  18. ops.Reset()
  19. // Add operations to ops.
  20. ...
  21. // Completely replace the window contents and state.
  22. e.Frame(ops)
  23. }
  24. }
  25. A program must keep receiving events from the event channel until
  26. [DestroyEvent] is received.
  27. # Main
  28. The Main function must be called from a program's main function, to hand over
  29. control of the main thread to operating systems that need it.
  30. Because Main is also blocking on some platforms, the event loop of a Window must run in a goroutine.
  31. For example, to display a blank but otherwise functional window:
  32. package main
  33. import "gioui.org/app"
  34. func main() {
  35. go func() {
  36. w := app.NewWindow()
  37. for {
  38. w.Event()
  39. }
  40. }()
  41. app.Main()
  42. }
  43. # Permissions
  44. The packages under gioui.org/app/permission should be imported
  45. by a Gio program or by one of its dependencies to indicate that specific
  46. operating-system permissions are required. Please see documentation for
  47. package gioui.org/app/permission for more information.
  48. */
  49. package app