-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
main.go
47 lines (42 loc) · 822 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"log"
"os"
"gioui.org/app"
"gioui.org/io/system"
"gioui.org/layout"
"gioui.org/op"
"github.com/tdewolff/canvas"
"github.com/tdewolff/canvas/renderers/gio"
)
func main() {
go func() {
w := app.NewWindow()
if err := loop(w); err != nil {
log.Fatal(err)
}
os.Exit(0)
}()
app.Main()
}
func loop(w *app.Window) error {
var ops op.Ops
for {
e := <-w.Events()
switch e := e.(type) {
case system.DestroyEvent:
return e.Err
case system.FrameEvent:
gtx := layout.NewContext(&ops, e)
layout.Center.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
c := gio.NewContain(gtx, 200.0, 100.0)
ctx := canvas.NewContext(c)
if err := canvas.DrawPreview(ctx); err != nil {
panic(err)
}
return c.Dimensions()
})
e.Frame(gtx.Ops)
}
}
}