buttons for table pb

This commit is contained in:
Jeff Carr 2025-03-05 13:32:10 -06:00
parent 6700553417
commit a9f74f08b0
1 changed files with 66 additions and 4 deletions

View File

@ -54,6 +54,8 @@ func (pb *Files) makeGuiFile(pf *File) error {
*/
}
guiUpdate(newf, pf.Bases.Name, pf.Bases.Name)
guiTableDelete(newf, pf.Bases.Name, pf.Bases.Name)
guiTableCustom(newf, pf.Bases.Name, pf.Bases.Name)
fmt.Fprintf(newf, "\n")
fmt.Fprintf(newf, "// END GUI\n")
@ -96,19 +98,24 @@ func guiMain(w io.Writer, FRUITS string, FRUIT string) {
fmt.Fprintln(w, " t.stringFuncs = append(t.stringFuncs, sf)")
fmt.Fprintln(w, " return sf")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "func (t *"+FRUITS+"Table) AddButtonFunc(title string, f func(*"+FRUIT+") string) *"+FRUIT+"ButtonFunc {")
fmt.Fprintln(w, " t.pb.Order = append(t.pb.Order, title)")
fmt.Fprintln(w, "")
fmt.Fprintln(w, " sf := new("+FRUIT+"ButtonFunc)")
fmt.Fprintln(w, " sf.title = title")
fmt.Fprintln(w, " sf.f = f")
fmt.Fprintln(w, " t.buttonFuncs = append(t.buttonFuncs, sf)")
fmt.Fprintln(w, " return sf")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "func (sf *"+FRUIT+"StringFunc) SetTitle(title string) {")
fmt.Fprintln(w, " sf.title = title")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "func (sf *"+FRUIT+"IntFunc) SetTitle(title string) {")
fmt.Fprintln(w, " sf.title = title")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "func (sf *"+FRUIT+"TimeFunc) SetTitle(title string) {")
fmt.Fprintln(w, " sf.title = title")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "func (t *"+FRUITS+"Table) AddIntFunc(title string, f func(*"+FRUIT+") int) *"+FRUIT+"IntFunc {")
fmt.Fprintln(w, " t.pb.Order = append(t.pb.Order, title)")
fmt.Fprintln(w, "")
@ -151,6 +158,12 @@ func guiMain(w io.Writer, FRUITS string, FRUIT string) {
fmt.Fprintln(w, " Custom func(*"+FRUIT+")")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "")
fmt.Fprintln(w, "type "+FRUIT+"ButtonFunc struct {")
fmt.Fprintln(w, " title string")
fmt.Fprintln(w, " f func(*"+FRUIT+") string")
fmt.Fprintln(w, " Custom func(*"+FRUIT+")")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "")
fmt.Fprintln(w, "type "+FRUIT+"IntFunc struct {")
fmt.Fprintln(w, " title string")
fmt.Fprintln(w, " f func(*"+FRUIT+") int")
@ -172,6 +185,7 @@ func guiMain(w io.Writer, FRUITS string, FRUIT string) {
fmt.Fprintln(w, " stringFuncs []*"+FRUIT+"StringFunc")
fmt.Fprintln(w, " intFuncs []*"+FRUIT+"IntFunc")
fmt.Fprintln(w, " timeFuncs []*"+FRUIT+"TimeFunc")
fmt.Fprintln(w, " buttonFuncs []*"+FRUIT+"ButtonFunc")
fmt.Fprintln(w, "}")
}
@ -197,6 +211,27 @@ func guiStringFuncs(w io.Writer, ZOOPB string, FRUITS string, FRUIT string) {
fmt.Fprintln(w, " return false")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "")
fmt.Fprintln(w, "func (mt *"+FRUITS+"Table) doButtonFunc(name string) bool {")
fmt.Fprintln(w, " for _, sf := range mt.buttonFuncs {")
fmt.Fprintln(w, " if sf.title != name {")
fmt.Fprintln(w, " continue")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, " // log.Info(\""+ZOOPB+": found stringfunc name:\", name)")
fmt.Fprintln(w, " r := new(guipb.ButtonRow)")
fmt.Fprintln(w, " r.Header = new(guipb.Widget)")
fmt.Fprintln(w, " r.Header.Name = name")
fmt.Fprintln(w, " all := mt.x.All()")
fmt.Fprintln(w, " for all.Scan() {")
fmt.Fprintln(w, " m := all.Next()")
fmt.Fprintln(w, " r.Vals = append(r.Vals, sf.f(m))")
fmt.Fprintln(w, " // log.Info(\""+ZOOPB+": adding\", name, r.Vals)")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, " mt.pb.ButtonRows = append(mt.pb.ButtonRows, r)")
fmt.Fprintln(w, " return true")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, " return false")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "")
fmt.Fprintln(w, "func (mt *"+FRUITS+"Table) doIntFunc(name string) bool {")
fmt.Fprintln(w, " for _, sf := range mt.intFuncs {")
fmt.Fprintln(w, " if sf.title != name {")
@ -252,6 +287,9 @@ func guiStringFuncs(w io.Writer, ZOOPB string, FRUITS string, FRUIT string) {
fmt.Fprintln(w, " if mt.doTimeFunc(name) {")
fmt.Fprintln(w, " continue")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, " if mt.doButtonFunc(name) {")
fmt.Fprintln(w, " continue")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, "}")
}
@ -392,3 +430,27 @@ func guiUpdate(w io.Writer, FRUITS string, FRUIT string) {
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "// END TABLE UPDATE")
}
func guiTableDelete(w io.Writer, FRUITS string, FRUIT string) {
fmt.Fprintln(w, "func (mt *"+FRUITS+"Table) Delete() {")
fmt.Fprintln(w, " if mt == nil {")
fmt.Fprintln(w, " log.Info(\"mt == nil table already deleted\")")
fmt.Fprintln(w, " return")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, " // log.Info(\"table Delete here\")")
fmt.Fprintln(w, " mt.parent.DeleteTable(mt.pb)")
fmt.Fprintln(w, "}")
}
func guiTableCustom(w io.Writer, FRUITS string, FRUIT string) {
fmt.Fprintln(w, "func (mt *"+FRUITS+"Table) lookupWidgetId(id int) {")
fmt.Fprintln(w, " log.Info(\"no shit. got to lookupWidgdetId() id =\", id, \"on mt\", mt.GetUuid())")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "")
fmt.Fprintln(w, "func (mt *"+FRUITS+"Table) Custom(f func(int)) {")
fmt.Fprintln(w, " mt.pb.RegisterCustom(mt.lookupWidgetId)")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "func (mt *"+FRUITS+"Table) GetUuid() string {")
fmt.Fprintln(w, " return mt.pb.Uuid")
fmt.Fprintln(w, "}")
}