/
gui.go
101 lines (89 loc) · 1.53 KB
/
gui.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package ge_go_sdl2
import (
"github.com/veandco/go-sdl2/sdl"
)
type uiElement interface {
View | Container | Text | Button | TextField
}
type View struct {
Id string
X int32
Y int32
W int32
H int32
BgColor uint32
BorderColor uint32
Flags uint
Children []interface{}
}
type Container struct {
Id string
ViewId string
X int32
Y int32
}
type HAlign int64
const (
Left HAlign = iota
Center
Right
)
type Text struct {
Content string
X int32
Y int32
W int32
H int32
Size int
Font string
TextColor sdl.Color
Id string
Alignment HAlign
}
type Button struct {
ContentLabel Text
Content string
X int32
Y int32
W int32
H int32
BorderColor uint32
BgColor uint32
Id string
OnClick chan string
}
type TextField struct {
Value string
OnChanged chan string
X int32
Y int32
W int32
H int32
BorderColor uint32
BgColor uint32
Size int
Font string
TextColor sdl.Color
Id string
}
func (e *TextField) notifyChange() {
valueToChange := e.Value
go func() {
e.OnChanged <- valueToChange
}()
}
func HandleAsCallbackArg[T interface{}](channel chan T, callback func(T)) {
go func() {
for {
callback(<-channel)
}
}()
}
func HandleAsCallback(channel chan string, callback func()) {
go func() {
for {
<-channel
callback()
}
}()
}