diff options
| author | Jeff Carr <[email protected]> | 2025-03-05 21:41:40 -0600 | 
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-03-05 21:41:40 -0600 | 
| commit | 7f03282acaf7a5f7746ee46a52ac5bafa818f876 (patch) | |
| tree | fb26243c63575fea0a606c46a9bdfdf87634bf6b | |
| parent | a9f74f08b047693d1c1627eefb84bc9e23eef923 (diff) | |
autogen button click table pb codev0.0.63
| -rw-r--r-- | generateGui.go | 38 | 
1 files changed, 29 insertions, 9 deletions
diff --git a/generateGui.go b/generateGui.go index a156eee..c522b20 100644 --- a/generateGui.go +++ b/generateGui.go @@ -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")  }  | 
