-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
80 lines (64 loc) · 1.3 KB
/
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"log"
"math/rand"
"os"
"time"
"gioui.org/app"
"gioui.org/font/gofont"
"gioui.org/io/system"
"gioui.org/layout"
"gioui.org/op"
"gioui.org/text"
"gioui.org/unit"
"gioui.org/widget/material"
)
type C = layout.Context
type D = layout.Dimensions
func init() {
rand.Seed(time.Now().UnixMicro())
}
var window *app.Window
func main() {
go func() {
// Create the window
window = app.NewWindow(
app.Title("Minesweeper"),
app.Size(unit.Dp(800), unit.Dp(600)),
)
if err := draw(window); err != nil {
log.Fatal(err)
}
os.Exit(0)
}()
app.Main()
}
var emojiFont text.FontFace
func draw(w *app.Window) error {
// Ops are the operations from the UI.
var ops op.Ops
// th defines the material design theme.
th := material.NewTheme(gofont.Collection())
bar := NewBar(th)
grid := NewGrid(th)
// Handle window events.
for e := range w.Events() {
switch e := e.(type) {
// This is sent when the application should re-render.
case system.FrameEvent:
gtx := layout.NewContext(&ops, e)
layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return bar.Layout(gtx)
}),
layout.Flexed(1, func(gtx C) D {
return grid.Layout(gtx)
}),
)
e.Frame(gtx.Ops)
case system.DestroyEvent:
return e.Err
}
}
return nil
}