forked from ajstarks/giocanvas
/
template
39 lines (35 loc) · 778 Bytes
/
template
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
package main
import (
"flag"
"os"
"gioui.org/app"
"gioui.org/io/key"
"gioui.org/io/system"
"gioui.org/unit"
"github.com/ajstarks/giocanvas"
)
func work(title string, width, height float32) {
defer os.Exit(0)
win := app.NewWindow(app.Title(title), app.Size(unit.Px(width), unit.Px(height)))
for e := range win.Events() {
switch e := e.(type) {
case system.FrameEvent:
canvas := giocanvas.NewCanvas(width, height, e)
// your code here
e.Frame(canvas.Context.Ops)
case key.Event:
switch e.Name {
case "Q", key.NameEscape:
os.Exit(0)
}
}
}
}
func main() {
var w, h int
flag.IntVar(&w, "width", 1000, "canvas width")
flag.IntVar(&h, "height", 1000, "canvas height")
flag.Parse()
go work("work", float32(w), float32(h))
app.Main()
}