summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-02-05 09:05:09 -0600
committerJeff Carr <[email protected]>2024-02-05 09:05:09 -0600
commit8f937c19eeaeb116c53c74d07d71f245a0a68280 (patch)
treefdd83ccb3d6607b5e13b5b9b643db2b436bf8f31
parent6291ddc13db10fe5ff18958763193d52de1b44c6 (diff)
compiles. kinda works
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--common.go4
-rw-r--r--init.go34
-rw-r--r--structs.go20
3 files changed, 42 insertions, 16 deletions
diff --git a/common.go b/common.go
index 66da97c..361c165 100644
--- a/common.go
+++ b/common.go
@@ -20,6 +20,10 @@ func (n *Node) String() string {
return widget.GetString(n.State.Value)
}
+func (n *Node) ProgName() string {
+ return n.State.ProgName
+}
+
func (n *Node) Hidden() bool {
return n.State.Hidden
}
diff --git a/init.go b/init.go
index 02d2623..67b5d18 100644
--- a/init.go
+++ b/init.go
@@ -10,18 +10,40 @@ import (
var muAction sync.Mutex
-/*
-func (me *TreeInfo) newAction(a widget.Action) *tree.Node {
+func (me *TreeInfo) newAction(a widget.Action) {
+ n := me.treeRoot.FindWidgetId(a.WidgetId)
switch a.ActionType {
case widget.Add:
- n := me.treeRoot.FindWidgetId(a.WidgetId)
if n == nil {
n := me.AddNode(&a)
- me.ActionFromChannel(n, a.ActionType)
+ me.Add(n)
+ return
}
+ case widget.SetText:
+ switch n.WidgetType {
+ case widget.Dropdown:
+ me.SetText(n, widget.GetString(a.State.Value))
+ case widget.Combobox:
+ me.SetText(n, widget.GetString(a.State.Value))
+ case widget.Window:
+ me.SetTitle(n, a.State.Label)
+ default:
+ // buttons, checkboxes, groups, etc
+ me.SetLabel(n, a.State.Label)
+ }
+ case widget.AddText:
+ switch n.WidgetType {
+ case widget.Dropdown:
+ me.AddText(n, widget.GetString(a.State.Value))
+ case widget.Combobox:
+ me.AddText(n, widget.GetString(a.State.Value))
+ default:
+ log.Warn("AddText() not supported on widget", n.WidgetType, n.String())
+ }
+ default:
+ me.NodeAction(n, a.ActionType)
}
}
-*/
func (me *TreeInfo) catchActionChannel() {
defer func() {
@@ -42,8 +64,8 @@ func (me *TreeInfo) catchActionChannel() {
log.Error(errors.New("toolkit ActionFromChannel == nil"), a.WidgetId, a.ActionType, a.WidgetType)
} else {
// send this to the toolkit
+ me.newAction(a)
me.ActionFromChannel(a)
- // me.newAction(a)
}
muAction.Unlock()
}
diff --git a/structs.go b/structs.go
index 4ff96c7..1ae9682 100644
--- a/structs.go
+++ b/structs.go
@@ -1,24 +1,18 @@
package tree
/*
- These code should be common to all gui plugins
-
There are some helper functions that are probably going to be
the same everywhere. Mostly due to handling the binary tree structure
and the channel communication
-
- For now, it's just a symlink to the 'master' version in
- ./toolkit/nocui/common.go
*/
import (
- // "go.wit.com/log"
"go.wit.com/widget"
)
-// var me *TreeInfo
-
type TreeInfo struct {
+ PluginName string
+
// this is the channel we send user events like
// mouse clicks or keyboard events back to the program
callback chan widget.Action
@@ -27,9 +21,15 @@ type TreeInfo struct {
pluginChan chan widget.Action
treeRoot *Node
- NodeI interface{}
+ // NodeI interface{}
+
ActionFromChannel func(widget.Action)
- PluginName string
+ NodeAction func(*Node, widget.ActionType)
+ Add func(*Node)
+ AddText func(*Node, string)
+ SetText func(*Node, string)
+ SetTitle func(*Node, string)
+ SetLabel func(*Node, string)
}
type Node struct {