gioui.org/ui@v0.0.0-20190926171558-ce74bc0cbaea/app/doc.go (about) 1 // SPDX-License-Identifier: Unlicense OR MIT 2 3 /* 4 Package app provides a platform-independent interface to operating system 5 functionality for running graphical user interfaces. 6 7 Windows 8 9 Create a new Window by calling NewWindow. On mobile platforms or when Gio 10 is embedded in another project, NewWindow merely connects with a previously 11 created window. 12 13 A Window is run by receiving events from its Events channel. The most 14 important event is UpdateEvent that prompts an update of the window 15 contents and state. 16 17 For example: 18 19 import "gioui.org/ui" 20 21 w := app.NewWindow() 22 for e := range w.Events() { 23 if e, ok := e.(app.UpdateEvent); ok { 24 ops.Reset() 25 // Add operations to ops. 26 ... 27 // Completely replace the window contents and state. 28 w.Update(ops) 29 } 30 } 31 32 A program must keep receiving events from the event channel until 33 DestroyEvent is received. 34 35 Main 36 37 The Main function must be called from a programs main function, to hand over 38 control of the main thread to operating systems that need it. 39 40 Because Main is also blocking, the event loop of a Window must run in a goroutine. 41 42 For example, to display a blank but otherwise functional window: 43 44 package main 45 46 import "gioui.org/ui/app" 47 48 func main() { 49 go func() { 50 w := app.NewWindow() 51 for range w.Events() { 52 } 53 }() 54 app.Main() 55 } 56 57 58 Event queue 59 60 A Window's Queue method returns an ui.Queue implementation that distributes 61 incoming events to the event handlers declared in the latest call to Update. 62 See the gioui.org/ui package for more information about event handlers. 63 64 */ 65 package app