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
102
103
104
|
package main
import (
"bytes"
_ "embed"
"image"
_ "image/png"
"time"
g "github.com/AllenDang/giu"
"github.com/AllenDang/imgui-go"
)
//go:generate goversioninfo -64 -o resource_amd64.syso res/versioninfo.json
//go:embed res/monitor_48.png
var icon []byte
var (
guiCfg EngardeConfig
)
type GridLayout struct {
size float32
widgets []g.Widget
labels []*g.LabelWidget
}
type GridLine struct {
label string
widget g.Widget
}
func Line(label string, widget g.Widget) GridLine {
return GridLine{label, widget}
}
func Grid(lines ...GridLine) *GridLayout {
var size float32
widgets := make([]g.Widget, len(lines))
labels := make([]*g.LabelWidget, len(lines))
for i, line := range lines {
labelSize, _ := g.CalcTextSize(line.label)
if labelSize > size {
size = labelSize
}
labels[i] = g.Label(line.label)
widgets[i] = line.widget
}
// add a default padding
size = size + 10
return &GridLayout{size, widgets, labels}
}
func (grid *GridLayout) Build() {
for i := range grid.labels {
g.AlignTextToFramePadding()
grid.labels[i].Build()
imgui.SameLineV(grid.size, 0)
grid.widgets[i].Build()
}
}
func loop(w *g.MasterWindow) func() {
const comboSize = 120
return func() {
g.SingleWindow().Layout(
g.Align(g.AlignCenter).To(g.Label("Engarde Importer")),
g.Spacing(),
Grid(
Line("Name", g.InputText(&guiCfg.Name)),
Line("Beschreibung", g.InputText(&guiCfg.Description)),
Line("Wettkampftag", g.DatePicker("##date", &guiCfg.Date).
Format("02.01.2006").StartOfWeek(time.Monday).
Size(comboSize)),
Line("Altersklasse", g.Combo(
"", guiCfg.AgeGroup.String(), AgeGroupStrings,
(*int32)(&guiCfg.AgeGroup)).
Size(comboSize)),
Line("Waffe", g.Combo(
"", guiCfg.Weapon.String(), WeaponStrings,
(*int32)(&guiCfg.Weapon)).
Size(comboSize)),
),
g.Spacing(),
g.Align(g.AlignCenter).To(g.Button("Quit").OnClick(w.Close)),
)
}
}
func gui() {
guiCfg.Date = time.Now()
w := g.NewMasterWindow("Engarde Importer", 400, 200, 0)
if img, _, err := image.Decode(bytes.NewReader(icon)); err == nil {
w.SetIcon([]image.Image{img})
}
w.Run(loop(w))
}
|