diff options
Diffstat (limited to '')
-rw-r--r-- | gui.go | 143 | ||||
-rw-r--r-- | res/icomoon.ttf | bin | 0 -> 1828 bytes | |||
-rw-r--r-- | types.go | 13 |
3 files changed, 114 insertions, 42 deletions
@@ -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 Binary files differnew file mode 100644 index 0000000..ec59b5b --- /dev/null +++ b/res/icomoon.ttf @@ -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) { |