From e9afb0fdeb25eb760e2af17bfd5b904845955c2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Tue, 1 Feb 2022 10:57:27 +0100 Subject: Combo Boxes --- gui.go | 16 ++++++++++++++-- types.go | 33 +++++++++++++-------------------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/gui.go b/gui.go index c29ec41..6b03aff 100644 --- a/gui.go +++ b/gui.go @@ -9,7 +9,9 @@ import ( //go:generate rsrc -manifest engarde-importer.exe.manifest -var guiCfg EngardeConfig +var ( + guiCfg EngardeConfig +) type gridLayout struct { size float32 @@ -57,6 +59,8 @@ 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")), @@ -66,7 +70,15 @@ func loop(w *g.MasterWindow) func() { Line("Beschreibung", g.InputText(&guiCfg.Description)), Line("Wettkampftag", g.DatePicker("##date", &guiCfg.Date). Format("02.01.2006").StartOfWeek(time.Monday). - Size(120)), + 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)), diff --git a/types.go b/types.go index 01c8b5e..a221592 100644 --- a/types.go +++ b/types.go @@ -51,22 +51,17 @@ func (g *Gender) UnmarshalCSV(content []byte) error { } } -type AgeGroup int +type AgeGroup int32 const ( AgeVeteran AgeGroup = iota AgeSenior ) +var AgeGroupStrings = []string{"Veteranen", "Senioren"} + func (a AgeGroup) String() string { - switch a { - case AgeVeteran: - return "V" - case AgeSenior: - return "S" - default: - return fmt.Sprintf("U%d", a) - } + return AgeGroupStrings[a] } func (a AgeGroup) Engarde() (string, error) { @@ -91,7 +86,7 @@ func AgeGroupFromString(content string) (AgeGroup, error) { } } -type Weapon int +type Weapon int32 const ( Epee Weapon = iota @@ -99,17 +94,15 @@ const ( Sabre ) +var WeaponStrings = []string{"Degen", "Florett", "Säbel"} +var WeaponShorts = []string{"D", "F", "S"} + func (w Weapon) String() string { - switch w { - case Epee: - return "D" - case Foil: - return "F" - case Sabre: - return "S" - default: - return fmt.Sprintf("U%d", w) - } + return WeaponStrings[w] +} + +func (w Weapon) ShortString() string { + return WeaponShorts[w] } func (w Weapon) Engarde() (string, error) { -- cgit v1.2.3