From 9554b6a28765db7debce2cc27587476dc90e5d3e Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 3 Mar 2025 00:12:12 -0600 Subject: starting to stub in widgetpb --- init.go | 11 +++++++---- node.go | 31 +++++++++++++++++++++++++++++++ structs.go | 29 ++++++++++++----------------- window.go | 19 +++++++++++++++++++ 4 files changed, 69 insertions(+), 21 deletions(-) diff --git a/init.go b/init.go index 7c8a35a..6887436 100644 --- a/init.go +++ b/init.go @@ -6,6 +6,7 @@ import ( "os" "runtime/debug" + "go.wit.com/lib/protobuf/guipb" "go.wit.com/log" "go.wit.com/widget" ) @@ -25,12 +26,14 @@ func initNew() { me.rootNode.WidgetType = widget.Root me.rootNode.hidden = false // always send the rootNode to the toolkits + me.widgets = guipb.NewWidgets() + // used to pass debugging flags to the toolkit plugins - me.flag = me.rootNode.newNode("flag", 0) - me.flag.WidgetType = widget.Flag + flag := me.rootNode.newNode("flag", 0) + flag.WidgetType = widget.Flag - me.flag = me.rootNode.newNode("stdout", 0) - me.flag.WidgetType = widget.Stdout + flag = me.rootNode.newNode("stdout", 0) + flag.WidgetType = widget.Stdout me.guiChan = make(chan widget.Action, 1) diff --git a/node.go b/node.go index 3fdea60..6866848 100644 --- a/node.go +++ b/node.go @@ -1,6 +1,7 @@ package gui import ( + "go.wit.com/lib/protobuf/guipb" "go.wit.com/log" "go.wit.com/widget" ) @@ -87,6 +88,36 @@ func (parent *Node) Append(n *Node) { // honor the visable settings of the parent n.visable = parent.visable + + // deprecate everything above and switch to protobuf below + if n.widget == nil { + n.widget = new(guipb.Widget) + } + n.widget.Id = int64(n.id) + n.widget.Type = n.TypePB() +} + +func (n *Node) TypePB() guipb.WidgetType { + switch n.WidgetType { + case widget.Window: + return guipb.WidgetType_Window + case widget.Group: + return guipb.WidgetType_Group + case widget.Grid: + return guipb.WidgetType_Grid + case widget.Box: + return guipb.WidgetType_Box + case widget.Label: + return guipb.WidgetType_Label + case widget.Button: + return guipb.WidgetType_Button + case widget.Checkbox: + return guipb.WidgetType_Checkbox + case widget.Dropdown: + return guipb.WidgetType_Dropdown + default: + return guipb.WidgetType_Label + } } // returns the parent widget diff --git a/structs.go b/structs.go index a3a1781..704202e 100644 --- a/structs.go +++ b/structs.go @@ -40,16 +40,12 @@ type guiConfig struct { // a toolkit requirement. never allow more than one per program initOnce sync.Once - // locking for the binary tree - muTree sync.Mutex - - // This is the master node. The Binary Tree starts here - rootNode *Node + rootNode *Node // This is the master node. The Binary Tree starts here + widgets *guipb.Widgets // the protobuf. switch to this. deprecate rootNode + counter int // used to make unique WidgetId's // A node off of rootNode for passing debugging flags - flag *Node - - counter int // used to make unique WidgetId's + // flag *Node // sets the chan for the plugins to call back too guiChan chan widget.Action @@ -87,12 +83,12 @@ type guiConfig struct { */ type Node struct { - id int // should be unique - hidden bool // don't update the toolkits when it's hidden - changed bool // do we need to inform the toolkit something changed? - enabled bool // if false, then the the user can't click on it - mu sync.Mutex - + widget *guipb.Widget // deprecate everything below and switch to this protobuf + id int // should be unique + hidden bool // don't update the toolkits when it's hidden + changed bool // do we need to inform the toolkit something changed? + enabled bool // if false, then the the user can't click on it + mu sync.Mutex WidgetType widget.WidgetType // most widgets need one value, this is current alue @@ -158,9 +154,8 @@ type Node struct { NextH int // if this widget is in a grid, this is the position of a widget - AtW int - AtH int - widget guipb.Widget + AtW int + AtH int } type Widget interface { diff --git a/window.go b/window.go index e0a1b01..ef4a804 100644 --- a/window.go +++ b/window.go @@ -117,3 +117,22 @@ func (n *Node) TestDraw() { } return } + +func (n *Node) TestPB() { + if n == nil { + return + } + + a := getNewAction(me.rootNode, widget.Show) + + log.Info("gui.UpdateTable() TODO: move the widget update val logic here instead of tree") + + a.WidgetPB, err = me.widgets.Marshal() + if err != nil { + log.Info("unmarshal error", err) + return + } + sendActionToPlugin(a) + + return +} -- cgit v1.2.3