summaryrefslogtreecommitdiff
path: root/toolkit/nocui
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/nocui')
-rw-r--r--toolkit/nocui/action.go8
-rw-r--r--toolkit/nocui/common.go64
-rw-r--r--toolkit/nocui/main.go8
-rw-r--r--toolkit/nocui/stdin.go6
4 files changed, 29 insertions, 57 deletions
diff --git a/toolkit/nocui/action.go b/toolkit/nocui/action.go
index ea1a60e..2e5f20b 100644
--- a/toolkit/nocui/action.go
+++ b/toolkit/nocui/action.go
@@ -98,7 +98,7 @@ func doAction(a *toolkit.Action) {
log(logNow, "doAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId)
switch a.WidgetType {
case toolkit.Root:
- rootNode = addWidget(a)
+ me.rootNode = addNode(a)
log(logNow, "doAction() found rootNode")
return
case toolkit.Flag:
@@ -106,11 +106,11 @@ func doAction(a *toolkit.Action) {
return
}
- n := rootNode.findWidgetId(a.WidgetId)
+ n := me.rootNode.findWidgetId(a.WidgetId)
switch a.ActionType {
case toolkit.Add:
- addWidget(a)
+ addNode(a)
case toolkit.Show:
n.show(true)
case toolkit.Hide:
@@ -144,7 +144,7 @@ func doAction(a *toolkit.Action) {
n.Delete()
case toolkit.Move:
log(logNow, "doAction() attempt to move() =", a.ActionType, a.WidgetType)
- newParent := rootNode.findWidgetId(a.ParentId)
+ newParent := me.rootNode.findWidgetId(a.ParentId)
n.move(newParent)
default:
log(logError, "doAction() Unknown =", a.ActionType, a.WidgetType)
diff --git a/toolkit/nocui/common.go b/toolkit/nocui/common.go
index 797f86a..786bf39 100644
--- a/toolkit/nocui/common.go
+++ b/toolkit/nocui/common.go
@@ -15,10 +15,13 @@ import (
"git.wit.org/wit/gui/toolkit"
)
-// this is the channel that sends the events from the user clicking or typing
-// back to the program using this golang package
+// this is the channel we send user events like
+// mouse clicks or keyboard events back to the program
var callback chan toolkit.Action
+// this is the channel we get requests to make widgets
+var pluginChan chan toolkit.Action
+
type node struct {
parent *node
children []*node
@@ -82,48 +85,6 @@ func (n *node) findWidgetId(id int) *node {
return nil
}
-func addWidget(a *toolkit.Action) *node {
- n := new(node)
- n.WidgetType = a.WidgetType
- n.WidgetId = a.WidgetId
- n.ParentId = a.ParentId
-
- // copy the data from the action message
- n.Name = a.Name
- n.Text = a.Text
- n.I = a.I
- n.S = a.S
- n.B = a.B
-
- n.X = a.X
- n.Y = a.Y
-
- n.W = a.W
- n.H = a.H
- n.AtW = a.AtW
- n.AtH = a.AtH
-
- // store the internal toolkit information
- n.tk = new(guiWidget)
-
- if (a.WidgetType == toolkit.Root) {
- log(logInfo, "addWidget() Root")
- return n
- }
-
- if (me.rootNode.findWidgetId(a.WidgetId) != nil) {
- log(logError, "addWidget() WidgetId already exists", a.WidgetId)
- return me.rootNode.findWidgetId(a.WidgetId)
- }
-
- // add this new widget on the binary tree
- n.parent = me.rootNode.findWidgetId(a.ParentId)
- if n.parent != nil {
- n.parent.children = append(n.parent.children, n)
- }
- return n
-}
-
func (n *node) doUserEvent() {
if (callback == nil) {
log(logError, "doUserEvent() callback == nil", n.WidgetId)
@@ -188,3 +149,18 @@ func addNode(a *toolkit.Action) *node {
}
return n
}
+
+// Other goroutines must use this to access the GUI
+//
+// You can not acess / process the GUI thread directly from
+// other goroutines. This is due to the nature of how
+// Linux, MacOS and Windows work (they all work differently. suprise. surprise.)
+//
+// this sets the channel to send user events back from the plugin
+func Callback(guiCallback chan toolkit.Action) {
+ callback = guiCallback
+}
+
+func PluginChannel() chan toolkit.Action {
+ return pluginChan
+}
diff --git a/toolkit/nocui/main.go b/toolkit/nocui/main.go
index a957773..942a195 100644
--- a/toolkit/nocui/main.go
+++ b/toolkit/nocui/main.go
@@ -5,12 +5,6 @@ import (
"git.wit.org/wit/gui/toolkit"
)
-// this is the channel we get requests to make widgets
-var pluginChan chan toolkit.Action
-
-// the starting point of the binary tree
-var rootNode *node
-
var muAction sync.Mutex
func catchActionChannel() {
@@ -29,6 +23,7 @@ func catchActionChannel() {
}
}
+/*
// Other goroutines must use this to access the GUI
//
// You can not acess / process the GUI thread directly from
@@ -43,6 +38,7 @@ func Callback(guiCallback chan toolkit.Action) {
func PluginChannel() chan toolkit.Action {
return pluginChan
}
+*/
// This is important. This sets the defaults for the gui. Without this, there isn't correct padding, etc
func init() {
diff --git a/toolkit/nocui/stdin.go b/toolkit/nocui/stdin.go
index 86ec664..0738d00 100644
--- a/toolkit/nocui/stdin.go
+++ b/toolkit/nocui/stdin.go
@@ -18,10 +18,10 @@ func simpleStdin() {
switch s {
case "l":
log(true, "list widgets")
- rootNode.listWidgets()
+ me.rootNode.listWidgets()
case "b":
log(true, "show buttons")
- rootNode.showButtons()
+ me.rootNode.showButtons()
case "d":
var a toolkit.Action
a.ActionType = toolkit.EnableDebug
@@ -35,7 +35,7 @@ func simpleStdin() {
default:
i, _ := strconv.Atoi(s)
log(true, "got input:", i)
- n := rootNode.findWidgetId(i)
+ n := me.rootNode.findWidgetId(i)
if (n != nil) {
n.dumpWidget("found node")
n.doUserEvent()