autogen button click table pb code

This commit is contained in:
Jeff Carr 2025-03-05 21:41:40 -06:00
parent a9f74f08b0
commit 7f03282aca
1 changed files with 29 additions and 9 deletions

View File

@ -7,12 +7,22 @@ import (
"fmt"
"io"
"os"
"unicode"
"go.wit.com/log"
)
// this file is named poorly. It has more than Sort()
func untitle(s string) string {
if s == "" {
return s
}
runes := []rune(s)
runes[0] = unicode.ToLower(runes[0])
return string(runes)
}
func (pb *Files) makeGuiFile(pf *File) error {
newf, _ := os.OpenFile(pf.Filebase+".gui.pb.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
defer newf.Close()
@ -53,9 +63,13 @@ func (pb *Files) makeGuiFile(pf *File) error {
log.Printf("Adding %s\n", funcdef)
*/
}
guiUpdate(newf, pf.Bases.Name, pf.Bases.Name)
guiTableDelete(newf, pf.Bases.Name, pf.Bases.Name)
guiTableCustom(newf, pf.Bases.Name, pf.Bases.Name)
FRUITS := pf.Bases.Name
FRUIT := pf.Base.Name
fRUITS := untitle(pf.Bases.Name)
fRUIT := untitle(pf.Base.Name)
guiUpdate(newf, FRUITS, FRUIT)
guiTableDelete(newf, FRUITS, FRUIT)
guiTableCustom(newf, FRUITS, fRUITS, FRUIT, fRUIT)
fmt.Fprintf(newf, "\n")
fmt.Fprintf(newf, "// END GUI\n")
@ -186,6 +200,7 @@ func guiMain(w io.Writer, FRUITS string, FRUIT string) {
fmt.Fprintln(w, " intFuncs []*"+FRUIT+"IntFunc")
fmt.Fprintln(w, " timeFuncs []*"+FRUIT+"TimeFunc")
fmt.Fprintln(w, " buttonFuncs []*"+FRUIT+"ButtonFunc")
fmt.Fprintln(w, " CustomFunc func(*"+FRUIT+")")
fmt.Fprintln(w, "}")
}
@ -428,10 +443,10 @@ func guiUpdate(w io.Writer, FRUITS string, FRUIT string) {
fmt.Fprintln(w, " }")
fmt.Fprintln(w, " return false")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "// END TABLE UPDATE")
}
func guiTableDelete(w io.Writer, FRUITS string, FRUIT string) {
fmt.Fprintln(w, "")
fmt.Fprintln(w, "func (mt *"+FRUITS+"Table) Delete() {")
fmt.Fprintln(w, " if mt == nil {")
fmt.Fprintln(w, " log.Info(\"mt == nil table already deleted\")")
@ -442,15 +457,20 @@ func guiTableDelete(w io.Writer, FRUITS string, FRUIT string) {
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())")
func guiTableCustom(w io.Writer, FRUITS string, fRUITS string, FRUIT string, fRUIT string) {
fmt.Fprintln(w, "")
fmt.Fprintln(w, "func (mt *"+FRUITS+"Table) "+fRUITS+"Custom(w *guipb.Widget) {")
fmt.Fprintln(w, " row := mt.x."+FRUITS+"[w.Location.Y-1]")
fmt.Fprintln(w, " mt.CustomFunc(row)")
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, "func (mt *"+FRUITS+"Table) Custom(f func(*"+FRUIT+")) {")
fmt.Fprintln(w, " mt.pb.RegisterCustom(mt."+fRUITS+"Custom)")
fmt.Fprintln(w, " mt.CustomFunc = f")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "")
fmt.Fprintln(w, "func (mt *"+FRUITS+"Table) GetUuid() string {")
fmt.Fprintln(w, " return mt.pb.Uuid")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "// END TABLE UPDATE")
}