summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-03-05 12:11:46 -0600
committerJeff Carr <[email protected]>2025-03-05 12:42:50 -0600
commitf984dd3a9fe7cf319ea2f0837eb8d0fc2af37b70 (patch)
treefeeded637a6ab8ab6ceda7a53fa79d783bb0ea8c
parente93d9586929b5ac50628180b45e010bf898ec7bb (diff)
passes mouse clicks to gitpb
-rw-r--r--init.go12
-rw-r--r--structs.go39
-rw-r--r--table.go57
3 files changed, 75 insertions, 33 deletions
diff --git a/init.go b/init.go
index 6887436..5a71eda 100644
--- a/init.go
+++ b/init.go
@@ -213,6 +213,8 @@ func watchCallback() {
*/
break
}
+ log.Log(WARN, "guiChan() n == nil is widget id in a table?", a.ActionType, a.WidgetId)
+ log.Log(WARN, "guiChan() todo: list tables here")
log.Log(WARN, "guiChan() Action could not be found or handled", a.ActionType, a)
}
}
@@ -232,6 +234,16 @@ func (n *Node) gotUserEvent(a widget.Action) {
return
}
+ if ok, pb := n.isWidgetInTable(); ok {
+ log.Log(WARN, "widget is in pb table", n.id, n.progname, a.Value)
+ if pb != nil {
+ log.Log(WARN, "found pb table", pb.GetUuid())
+ pb.Custom(n.id)
+ }
+ } else {
+ log.Log(WARN, "widget is not in pb table", n.id, n.progname, a.Value)
+ }
+
switch n.WidgetType {
case widget.Dropdown:
// n.checked = a.State.Checked // TODO: do this and/or time to switch to protobuf
diff --git a/structs.go b/structs.go
index 704202e..128866d 100644
--- a/structs.go
+++ b/structs.go
@@ -25,27 +25,15 @@ import (
var me guiConfig
-// Range(1, 10) includes the values 1 and 10
-// almost all toolkits use integers so there doesn't
-// seem to be a good idea to use 'type any' here as it
-// just makes things more complicated for no good reason
-type RangeMovedToWidget struct {
- Low int
- High int
-}
-
-// type List []string
-
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
- 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
+ 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
@@ -82,15 +70,18 @@ type guiConfig struct {
*/
+// TODO: MOVE MUCH OF THIS TO PROTOBUFS
type Node struct {
- 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
+ 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
+ tablepb *guipb.Table // set in the parent if this is a tablepb
+ mu sync.Mutex // this is old and probably is wrong at this point
+ // deprecate below here if possible
+ WidgetType widget.WidgetType // deprecate
// most widgets need one value, this is current alue
// value any
defaultS string
diff --git a/table.go b/table.go
index 08418ae..aa8da77 100644
--- a/table.go
+++ b/table.go
@@ -12,6 +12,7 @@ import (
"google.golang.org/protobuf/types/known/anypb"
)
+/*
// makes a grid inside an existing Widget
func (n *Node) NewTable(title string) *NodeTable {
t := new(NodeTable)
@@ -35,6 +36,23 @@ type NodeTable struct {
Custom func()
}
+func (parent *Node) ShowTableCallback(pb *guipb.Table, f func(id int)) {
+}
+*/
+
+func (n *Node) isWidgetInTable() (bool, *guipb.Table) {
+ if n.id == 0 {
+ return false, nil
+ }
+ if n.progname == "gridtablePB" {
+ return true, n.tablepb
+ }
+ if n.parent == nil {
+ return false, nil
+ }
+ return n.parent.isWidgetInTable()
+}
+
func (parent *Node) ShowTable(pb *guipb.Table) {
// make a new action and populate the current node state
// this should be parent and not rootNode?
@@ -44,7 +62,8 @@ func (parent *Node) ShowTable(pb *guipb.Table) {
pb.Parent.Id = int64(parent.id)
pb.Parent.Name = pb.Title
- makeTableGrid(pb)
+ grid := parent.makeTableGrid(pb)
+ grid.tablepb = pb
nt := guipb.NewTables()
nt.Append(pb)
@@ -85,19 +104,17 @@ func (parent *Node) DeleteTable(pb *guipb.Table) {
sendActionToPlugin(a)
}
-func makeTableGrid(pb *guipb.Table) {
+func (parent *Node) makeTableGrid(pb *guipb.Table) *Node {
grid := addNode()
+ grid.progname = "gridtablePB"
+ grid.WidgetType = widget.Grid
+
pb.Grid = new(guipb.Widget)
pb.Grid.Id = int64(grid.id)
pb.Grid.Name = "gridtablePB"
- /*
- // get unique widget ID numbers for the headers
- for i, r := range pb.Order {
- n := addNode()
- r.Id = int64(n.id)
- }
- */
+ parent.children = append(parent.children, grid)
+ grid.parent = parent
for _, r := range pb.StringRows {
// log.Info("gui: got string row:", pb.Title, i, r.Header, r.Vals)
@@ -105,6 +122,11 @@ func makeTableGrid(pb *guipb.Table) {
r.Header.Id = int64(header.id)
for _, v := range r.Vals {
label := addNode()
+ label.WidgetType = widget.Label
+ label.parent = grid
+ label.enabled = true
+ grid.children = append(grid.children, label)
+
pbwidget := new(guipb.Widget)
pbwidget.Id = int64(label.id)
pbwidget.Name = v
@@ -119,6 +141,11 @@ func makeTableGrid(pb *guipb.Table) {
r.Header.Id = int64(header.id)
for _, v := range r.Vals {
label := addNode()
+ label.WidgetType = widget.Button
+ label.parent = grid
+ label.enabled = true
+ grid.children = append(grid.children, label)
+
pbwidget := new(guipb.Widget)
pbwidget.Id = int64(label.id)
pbwidget.Name = v
@@ -133,6 +160,11 @@ func makeTableGrid(pb *guipb.Table) {
r.Header.Id = int64(header.id)
for _, v := range r.Vals {
label := addNode()
+ label.WidgetType = widget.Label
+ label.parent = grid
+ label.enabled = true
+ grid.children = append(grid.children, label)
+
pbwidget := new(guipb.Widget)
pbwidget.Id = int64(label.id)
pbwidget.Size = v
@@ -147,6 +179,11 @@ func makeTableGrid(pb *guipb.Table) {
r.Header.Id = int64(header.id)
for _, v := range r.Vals {
label := addNode()
+ label.WidgetType = widget.Label
+ label.parent = grid
+ label.enabled = true
+ grid.children = append(grid.children, label)
+
pbwidget := new(guipb.Widget)
pbwidget.Id = int64(label.id)
anyValue, err := anypb.New(v)
@@ -159,4 +196,6 @@ func makeTableGrid(pb *guipb.Table) {
// log.Info("gui: added new val", pbwidget)
}
}
+
+ return grid
}