continue work to move to 'any' in GUI PB table

This commit is contained in:
Jeff Carr 2025-09-15 03:50:46 -05:00
parent 086329f1db
commit 66aacceee5
1 changed files with 18 additions and 6 deletions

View File

@ -141,6 +141,7 @@ func headerGui(w io.Writer, pf *File) {
fmt.Fprintln(w, " \"go.wit.com/gui\"")
fmt.Fprintln(w, " \"go.wit.com/lib/protobuf/guipb\"")
fmt.Fprintln(w, " \"go.wit.com/log\"")
fmt.Fprintln(w, " anypb \"google.golang.org/protobuf/types/known/anypb\"")
fmt.Fprintln(w, " timestamppb \"google.golang.org/protobuf/types/known/timestamppb\"")
fmt.Fprintln(w, ")")
fmt.Fprintln(w, "")
@ -262,15 +263,26 @@ func guiMain(w io.Writer, FRUITS string, FRUIT string) {
fmt.Fprintln(w, " Width int")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "")
fmt.Fprintln(w, "type "+FRUIT+"AnyFunc struct {")
fmt.Fprintln(w, " title string")
fmt.Fprintln(w, " f func(*"+FRUIT+") any")
fmt.Fprintln(w, " Custom func(*"+FRUIT+")")
fmt.Fprintln(w, " order int")
fmt.Fprintln(w, " Width int")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "")
fmt.Fprintln(w, "type "+FRUITS+"Table struct {")
fmt.Fprintln(w, " pb *guipb.Table")
fmt.Fprintln(w, " parent *gui.Node")
fmt.Fprintln(w, " x *"+FRUITS+"")
fmt.Fprintln(w, " hostnames []string")
fmt.Fprintln(w, "")
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, " anyFuncs []*"+FRUIT+"AnyFunc")
fmt.Fprintln(w, "")
fmt.Fprintln(w, " CustomFunc func(*"+FRUIT+")")
fmt.Fprintln(w, " order int")
fmt.Fprintln(w, "}")
@ -352,8 +364,7 @@ func guiStringFuncs(w io.Writer, ZOOPB string, FRUITS string, FRUIT string) {
fmt.Fprintln(w, " if sf.title != name {")
fmt.Fprintln(w, " continue")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, " // log.Info(\""+ZOOPB+": found timefunc name:\", name)")
fmt.Fprintln(w, " r := new(guipb.TimeCol)")
fmt.Fprintln(w, " r := new(guipb.AnyCol)")
fmt.Fprintln(w, " r.Header = new(guipb.Widget)")
fmt.Fprintln(w, " r.Header.Name = name")
fmt.Fprintln(w, " r.Attr = new(guipb.ColAttr)")
@ -362,10 +373,12 @@ func guiStringFuncs(w io.Writer, ZOOPB string, FRUITS string, FRUIT string) {
fmt.Fprintln(w, "")
fmt.Fprintln(w, " for m := range mt.x.IterAll() {")
fmt.Fprintln(w, " t := sf.f(m)")
fmt.Fprintln(w, " r.Vals = append(r.Vals, timestamppb.New(t)) // convert to protobuf time")
fmt.Fprintln(w, " // log.Info(\""+ZOOPB+": adding\", name, r.Vals)")
fmt.Fprintln(w, " tsProto := timestamppb.New(t)")
fmt.Fprintln(w, " anyProto, err := anypb.New(tsProto)")
fmt.Fprintln(w, " _ = err // do something with err someday (?)")
fmt.Fprintln(w, " r.Vals = append(r.Vals, anyProto)")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, " mt.pb.TimeCols = append(mt.pb.TimeCols, r)")
fmt.Fprintln(w, " mt.pb.AnyCols = append(mt.pb.AnyCols, r)")
fmt.Fprintln(w, " return true")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, " return false")
@ -373,7 +386,6 @@ func guiStringFuncs(w io.Writer, ZOOPB string, FRUITS string, FRUIT string) {
fmt.Fprintln(w, "")
fmt.Fprintln(w, "func (mt *"+FRUITS+"Table) MakeTable() {")
fmt.Fprintln(w, " for _, name := range mt.pb.Order {")
fmt.Fprintln(w, " // log.Info(\""+ZOOPB+": looking for row name()\", name)")
fmt.Fprintln(w, " if mt.doStringFunc(name) {")
fmt.Fprintln(w, " continue")
fmt.Fprintln(w, " }")