From d5e557190de2e2147f3335309f6ea4b66e72be4f Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 30 Apr 2025 14:40:23 -0500 Subject: it is a tree, but the variable shouldn't be this --- node.go | 2 +- structs.go | 10 +++++----- table.go | 36 +++++++-------------------------- window.go | 67 +++++++++++++++++++++++++++++++++++++++----------------------- 4 files changed, 55 insertions(+), 60 deletions(-) diff --git a/node.go b/node.go index 6866848..95bff4f 100644 --- a/node.go +++ b/node.go @@ -94,7 +94,7 @@ func (parent *Node) Append(n *Node) { n.widget = new(guipb.Widget) } n.widget.Id = int64(n.id) - n.widget.Type = n.TypePB() + // n.widget.Type = n.TypePB() } func (n *Node) TypePB() guipb.WidgetType { diff --git a/structs.go b/structs.go index 128866d..c393037 100644 --- a/structs.go +++ b/structs.go @@ -29,11 +29,11 @@ type guiConfig struct { // a toolkit requirement. never allow more than one per program initOnce sync.Once - rootNode *Node // This is the master node. The Binary Tree starts here - tree *guipb.Tree // the protobuf. switch to this. deprecate rootNode - widgets *guipb.Widgets // don't use this I think - counter int // used to make unique WidgetId's - tables []*guipb.Tables // a list of active protobuf tables + rootNode *Node // This is the master node. The Binary Tree starts here + // tree *guipb.Tree // the protobuf. switch to this. deprecate rootNode + widgets *guipb.Widgets // don't use this I think + counter int // used to make unique WidgetId's + tables []*guipb.Tables // a list of active protobuf tables // sets the chan for the plugins to call back too guiChan chan widget.Action diff --git a/table.go b/table.go index 0824c34..b9a5cd8 100644 --- a/table.go +++ b/table.go @@ -10,36 +10,9 @@ import ( "go.wit.com/log" "go.wit.com/widget" "google.golang.org/protobuf/types/known/anypb" + "google.golang.org/protobuf/types/known/wrapperspb" ) -/* -// makes a grid inside an existing Widget -func (n *Node) NewTable(title string) *NodeTable { - t := new(NodeTable) - - t.grid = n.RawGrid().SetProgName("PB GRID") - - t.tb = t.grid.newNode(title, widget.Table) - t.tb.label = title - - return t -} - -type NodeColumn struct { - Title string - Vals []string -} - -type NodeTable struct { - grid *Node - tb *Node - Custom func() -} - -func (parent *Node) ShowTableCallback(pb *guipb.Table, f func(id int)) { -} -*/ - func (n *Node) findInTablePB(pb *guipb.Table, id int) *guipb.Widget { if n.tablepb == nil { log.Info("SOMETHING WAS WRONG. gui.findInTablePB() n.tablepb == nil for widget id", id) @@ -331,7 +304,12 @@ func (parent *Node) makeTableGrid(pb *guipb.Table) *Node { pbwidget := new(guipb.Widget) pbwidget.Id = int64(label.id) - pbwidget.Size = v + anyValue, err := anypb.New(wrapperspb.Int64(v)) + if err != nil { + log.Info("gui: failed to add time", err) + continue + } + pbwidget.Val = anyValue r.Widgets = append(r.Widgets, pbwidget) // log.Info("gui: added new int", pbwidget) } diff --git a/window.go b/window.go index ef4a804..c30f496 100644 --- a/window.go +++ b/window.go @@ -1,6 +1,7 @@ package gui import ( + "go.wit.com/lib/protobuf/guipb" "go.wit.com/log" "go.wit.com/widget" ) @@ -60,46 +61,49 @@ func (parent *Node) RawWindow(title string) *Node { return newNode } -/* -// TODO: should do this recursively -func (n *Node) UnDraw() *Node { +// TODO: send protobuf +func (n *Node) Draw() *Node { if !n.Ready() { return n } - n.hidden = true + n.hidden = false n.changed = true // inform the toolkits - sendAction(n, widget.Delete) + sendAction(n, widget.Add) return n } -*/ - -// TODO: should do this recursively (on a window only) -func (n *Node) Draw() *Node { - if !n.Ready() { - return n - } +func (n *Node) TestDrawPB(pb bool) { + n.visable = true n.hidden = false n.changed = true - // inform the toolkits - sendAction(n, widget.Add) - return n -} + if !pb { + log.Log(NOW, "TestDrawPB() using TestDraw()") + n.TestDraw() + return + } -// if the toolkit supports a gui with pixels, it might honor this. no promises -// consider this a 'recommendation' or developer 'preference' to the toolkit -/* -func (n *Node) PixelSize(w, h int) *Node { - n.width = w - n.height = w - return n + widgets := guipb.NewWidgets() + n.makePB(widgets.Tree) + + a := getNewAction(me.rootNode, widget.Show) + + a.WidgetPB, err = widgets.Marshal() + if err != nil { + log.Log(WARN, "unmarshal error", err) + return + } + + log.Log(NOW, "TestDrawPB() start") + sendActionToPlugin(a) + log.Log(NOW, "TestDrawPB() end") + return } -*/ +// TODO: remove this after switching to protobuf // when a window is redrawn, every widget in the window // needs to be sent to the toolkit func (n *Node) TestDraw() { @@ -118,6 +122,20 @@ func (n *Node) TestDraw() { return } +func (n *Node) makePB(parent *guipb.Widget) *guipb.Widget { + w := new(guipb.Widget) + w.Id = int64(n.id) + w.Name = n.label + + parent.Children = append(parent.Children, w) + + for _, child := range n.children { + w.Children = append(w.Children, child.makePB(w)) + } + + return w +} + func (n *Node) TestPB() { if n == nil { return @@ -133,6 +151,5 @@ func (n *Node) TestPB() { return } sendActionToPlugin(a) - return } -- cgit v1.2.3