From 96b4c0b5a1c26504b098f6d35471de9b7b5a5cbb Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 5 Mar 2025 07:47:03 -0600 Subject: [PATCH] hand write table buttons for testing --- machine.test.go | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 machine.test.go diff --git a/machine.test.go b/machine.test.go new file mode 100644 index 0000000..37ccdc8 --- /dev/null +++ b/machine.test.go @@ -0,0 +1,70 @@ +package zoopb + +import ( + "fmt" + + "go.wit.com/lib/protobuf/guipb" + "go.wit.com/log" +) + +func (mt *MachinesTable) Delete() { + if mt == nil { + log.Info("mt == nil table already deleted") + return + } + log.Info("implement table Delete here") + mt.parent.DeleteTable(mt.pb) +} + +func (mt *MachinesTable) UpdateTable(pb *Machines) { + // mt.parent.UpdateTable(pb) +} + +func (mt *MachinesTable) GetUuid() string { + return mt.pb.Uuid +} + +func (t *MachinesTable) AddButtonFunc(title string, f func(*Machine) string) { + t.pb.Order = append(t.pb.Order, title) + + sf := new(machineButtonFunc) + sf.title = title + sf.f = f + t.buttonFuncs = append(t.buttonFuncs, sf) +} + +type machineButtonFunc struct { + title string + f func(*Machine) string + Custom func(*Machine) +} + +func (mt *MachinesTable) doButtonFunc(name string) bool { + for _, sf := range mt.buttonFuncs { + if sf.title != name { + continue + } + // log.Info("zoopb: found timefunc name:", name) + r := new(guipb.ButtonRow) + r.Header = new(guipb.Widget) + r.Header.Name = name + all := mt.x.All() + for all.Scan() { + m := all.Next() + tmp := fmt.Sprintf("%s %s %d", name, sf.f(m), all.Cur()) + r.Vals = append(r.Vals, tmp) + // log.Info("zoopb: adding", name, r.Vals) + } + mt.pb.ButtonRows = append(mt.pb.ButtonRows, r) + return true + } + return false +} + +func (it *MachinesIterator) Cur() int { + return it.index +} + +func (it *MachineIterator) Cur() int { + return it.index +}