summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2022-02-01 20:30:17 +0100
committerRené 'Necoro' Neumann <necoro@necoro.eu>2022-02-01 20:30:17 +0100
commitbf9032a1bb6dcbb911a13fdde1daa9886c0bdfee (patch)
treed835003e491d5e3c162ca760b649eff6a95c959f
parenteac8028e031f45bddfffe80a85176882ee851f94 (diff)
downloadengarde-importer-bf9032a1bb6dcbb911a13fdde1daa9886c0bdfee.tar.gz
engarde-importer-bf9032a1bb6dcbb911a13fdde1daa9886c0bdfee.tar.bz2
engarde-importer-bf9032a1bb6dcbb911a13fdde1daa9886c0bdfee.zip
More GUI elements
-rw-r--r--gui.go143
-rw-r--r--res/icomoon.ttfbin0 -> 1828 bytes
-rw-r--r--types.go13
3 files changed, 114 insertions, 42 deletions
diff --git a/gui.go b/gui.go
index 62fc05f..ca5e6db 100644
--- a/gui.go
+++ b/gui.go
@@ -5,6 +5,8 @@ import (
_ "embed"
"image"
_ "image/png"
+ "os"
+ "strconv"
"time"
g "github.com/AllenDang/giu"
@@ -17,8 +19,26 @@ import (
//go:embed res/monitor_48.png
var icon []byte
+//go:embed res/icomoon.ttf
+var icomoon []byte
+var icomoonFI *g.FontInfo
+
+const comboSize = 120
+
+type entryCfg struct {
+ inputFile string
+ outputDir string
+ gender Gender
+ ageGroup AgeGroup
+ weapon Weapon
+}
+
var (
- guiCfg EngardeConfig
+ name string
+ description string
+ date time.Time
+ entries []entryCfg
+ targetDir string
)
type GridLayout struct {
@@ -66,49 +86,106 @@ func (grid *GridLayout) 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)),
- Line("Ophardt-Export", g.Row(g.InputText(&guiCfg.inputFile), g.SmallButton("Wähle...").OnClick(func() {
+func Layout(widgets ...g.Widget) g.Layout {
+ return widgets
+}
+
+func PushID(id string) g.Widget {
+ return g.Custom(func() { imgui.PushID(id) })
+}
+
+func PopID() g.Widget {
+ return g.Custom(imgui.PopID)
+}
+
+func buildEntry(idx int) g.Widget {
+ entry := &entries[idx]
+
+ return Layout(
+ PushID(strconv.Itoa(idx)),
+ g.Spacing(),
+ g.Separator(),
+ g.Spacing(),
+ Grid(
+ Line("Waffe", g.Combo("",
+ entry.weapon.String(), WeaponStrings, (*int32)(&entry.weapon)).
+ Size(comboSize)),
+ Line("Geschlecht", g.Combo("",
+ entry.gender.String(), GenderStrings, (*int32)(&entry.gender)).
+ Size(comboSize)),
+ Line("Altersklasse", g.Combo("",
+ entry.ageGroup.String(), AgeGroupStrings, (*int32)(&entry.ageGroup)).
+ Size(comboSize)),
+ Line("Ophardt-Export", g.Row(
+ g.InputText(&entry.inputFile),
+ g.Button("Wähle...").OnClick(func() {
file, err := zenity.SelectFile(zenity.FileFilters{
{Name: "CSV Files", Patterns: []string{"*.csv"}},
})
-
if err == nil && file != "" {
- guiCfg.inputFile = file
+ entry.inputFile = file
}
}))),
- ),
- g.Spacing(),
- g.Align(g.AlignCenter).To(g.Button("Quit").OnClick(w.Close)),
- )
- }
+ ),
+ PopID())
+}
+
+func entryBuilder() g.Widget {
+ const id = "entries"
+
+ return g.Custom(func() {
+ imgui.PushID(id)
+ defer imgui.PopID()
+
+ for i := range entries {
+ buildEntry(i).Build()
+ }
+ })
+}
+
+func shouldQuit() {
+ g.Context.GetPlatform().SetShouldStop(true)
+}
+
+func loop() {
+ g.SingleWindow().Layout(
+ g.Align(g.AlignCenter).To(g.Label("Engarde Importer")),
+ g.Spacing(),
+ Grid(
+ Line("Name", g.InputText(&name)),
+ Line("Beschreibung", g.InputText(&description)),
+ Line("Wettkampftag", g.DatePicker("##date", &date).
+ Format("02.01.2006").StartOfWeek(time.Monday).
+ Size(comboSize)),
+ Line("Zielverzeichnis", g.Row(
+ g.InputText(&targetDir),
+ g.Button("Wähle...").OnClick(func() {
+ dir, err := zenity.SelectFile(zenity.Directory(), zenity.Filename(targetDir+"/"))
+ if err == nil && dir != "" {
+ targetDir = dir
+ }
+ }))),
+ ),
+ entryBuilder(),
+ g.Style().SetFont(icomoonFI).To(
+ g.Button("\ue900").OnClick(func() {
+ entries = append(entries, entryCfg{})
+ })),
+ g.Align(g.AlignCenter).To(g.Button("Quit").OnClick(shouldQuit)),
+ )
}
func gui() {
- guiCfg.Date = time.Now()
- w := g.NewMasterWindow("Engarde Importer", 500, 200, 0)
+ date = time.Now()
+ entries = make([]entryCfg, 1)
+ targetDir, _ = os.UserHomeDir()
+
+ icomoonFI = g.AddFontFromBytes("icomoon", icomoon, 16)
+ w := g.NewMasterWindow("Engarde Importer", 500, 400, 0)
+
if img, _, err := image.Decode(bytes.NewReader(icon)); err == nil {
w.SetIcon([]image.Image{img})
}
- w.Run(loop(w))
+ w.Run(loop)
}
diff --git a/res/icomoon.ttf b/res/icomoon.ttf
new file mode 100644
index 0000000..ec59b5b
--- /dev/null
+++ b/res/icomoon.ttf
Binary files differ
diff --git a/types.go b/types.go
index a221592..d16ef10 100644
--- a/types.go
+++ b/types.go
@@ -2,22 +2,17 @@ package main
import "fmt"
-type Gender int
+type Gender int32
const (
GenderM Gender = iota
GenderF
)
+var GenderStrings = []string{"Herren", "Damen"}
+
func (g Gender) String() string {
- switch g {
- case GenderM:
- return "M"
- case GenderF:
- return "F"
- default:
- return fmt.Sprintf("U%d", g)
- }
+ return GenderStrings[g]
}
func (g Gender) Engarde() (string, error) {