-
Notifications
You must be signed in to change notification settings - Fork 8
/
menu.go
71 lines (63 loc) · 2.31 KB
/
menu.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
package main
import (
"image/color"
"time"
"tinygo.org/x/tinyfont/freemono"
"tinygo.org/x/tinydraw"
"tinygo.org/x/tinyfont"
)
func menu() int16 {
display.FillScreen(color.RGBA{0, 0, 0, 255})
options := []string{
"Badge",
"GopherCon Schedule",
"GopherCon Adventure",
"Snake",
"Rainbow LEDs",
"Accelerometer",
"Music!",
"Game of Life",
"Color Game",
"Info",
}
bgColor := color.RGBA{109, 0, 140, 255}
display.FillScreen(bgColor)
selected := int16(0)
numOpts := int16(len(options))
for i := int16(0); i < numOpts; i++ {
tinydraw.Circle(&display, 28, 35+20*i, 6, color.RGBA{0, 0, 0, 255})
tinyfont.WriteLine(&display, &freemono.Regular12pt7b, 39, 39+20*i, options[i], color.RGBA{0, 0, 0, 255})
tinyfont.WriteLine(&display, &freemono.Regular12pt7b, 39, 40+20*i, options[i], color.RGBA{0, 0, 0, 255})
tinyfont.WriteLine(&display, &freemono.Regular12pt7b, 39, 41+20*i, options[i], color.RGBA{0, 0, 0, 255})
tinyfont.WriteLine(&display, &freemono.Regular12pt7b, 40, 41+20*i, options[i], color.RGBA{0, 0, 0, 255})
tinyfont.WriteLine(&display, &freemono.Regular12pt7b, 41, 41+20*i, options[i], color.RGBA{0, 0, 0, 255})
tinyfont.WriteLine(&display, &freemono.Regular12pt7b, 41, 40+20*i, options[i], color.RGBA{0, 0, 0, 255})
tinyfont.WriteLine(&display, &freemono.Regular12pt7b, 41, 39+20*i, options[i], color.RGBA{0, 0, 0, 255})
tinyfont.WriteLine(&display, &freemono.Regular12pt7b, 40, 39+20*i, options[i], color.RGBA{0, 0, 0, 255})
tinyfont.WriteLine(&display, &freemono.Regular12pt7b, 40, 40+20*i, options[i], color.RGBA{250, 250, 0, 255})
}
tinydraw.FilledCircle(&display, 28, 35, 4, color.RGBA{200, 200, 0, 255})
released := true
for {
if released && !btnUp.Get() && selected > 0 {
selected--
tinydraw.FilledCircle(&display, 28, 35+20*selected, 4, color.RGBA{200, 200, 0, 255})
tinydraw.FilledCircle(&display, 28, 35+20*(selected+1), 4, bgColor)
}
if released && !btnDown.Get() && selected < (numOpts-1) {
selected++
tinydraw.FilledCircle(&display, 28, 35+20*selected, 4, color.RGBA{200, 200, 0, 255})
tinydraw.FilledCircle(&display, 28, 35+20*(selected-1), 4, bgColor)
}
if released && !btnA.Get() {
break
}
if btnA.Get() && btnUp.Get() && btnDown.Get() {
released = true
} else {
released = false
}
time.Sleep(200 * time.Millisecond)
}
return selected
}