summaryrefslogtreecommitdiff
path: root/toolkit/nocui
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/nocui')
-rw-r--r--toolkit/nocui/common.go132
-rw-r--r--toolkit/nocui/event.go19
-rw-r--r--toolkit/nocui/structs.go46
-rw-r--r--toolkit/nocui/widget.go29
4 files changed, 166 insertions, 60 deletions
diff --git a/toolkit/nocui/common.go b/toolkit/nocui/common.go
index a012138..797f86a 100644
--- a/toolkit/nocui/common.go
+++ b/toolkit/nocui/common.go
@@ -1,9 +1,68 @@
package main
+/*
+ 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 (
"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
+var callback chan toolkit.Action
+
+type node struct {
+ parent *node
+ children []*node
+
+ WidgetId int // widget ID
+ WidgetType toolkit.WidgetType
+ ParentId int // parent ID
+
+ Name string
+ Text string
+
+ // This is how the values are passed back and forth
+ // values from things like checkboxes & dropdown's
+ B bool
+ I int
+ S string
+
+ A any // switch to this or deprecate this? pros/cons?
+
+ // This is used for things like a slider(0,100)
+ X int
+ Y int
+
+ // This is for the grid size & widget position
+ W int
+ H int
+ AtW int
+ AtH int
+
+ vals []string // dropdown menu items
+
+ // horizontal=true means layout widgets like books on a bookshelf
+ // horizontal=false means layout widgets like books in a stack
+ horizontal bool `default:false`
+
+ hasTabs bool // does the window have tabs?
+ currentTab bool // the visible tab
+
+ // the internal plugin toolkit structure
+ // in the gtk plugin, it has gtk things like margin & border settings
+ // in the text console one, it has text console things like colors for menus & buttons
+ tk *guiWidget
+}
+
// searches the binary tree for a WidgetId
func (n *node) findWidgetId(id int) *node {
if (n == nil) {
@@ -45,22 +104,87 @@ func addWidget(a *toolkit.Action) *node {
n.AtH = a.AtH
// store the internal toolkit information
- n.tk = new(nocuiT)
+ n.tk = new(guiWidget)
if (a.WidgetType == toolkit.Root) {
log(logInfo, "addWidget() Root")
return n
}
- if (rootNode.findWidgetId(a.WidgetId) != nil) {
+ if (me.rootNode.findWidgetId(a.WidgetId) != nil) {
log(logError, "addWidget() WidgetId already exists", a.WidgetId)
- return rootNode.findWidgetId(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)
+ return
+ }
+ var a toolkit.Action
+ a.WidgetId = n.WidgetId
+ a.Name = n.Name
+ a.Text = n.Text
+ a.S = n.S
+ a.I = n.I
+ a.B = n.B
+ a.ActionType = toolkit.User
+ log(logInfo, "doUserEvent() START: send a user event to the callback channel")
+ callback <- a
+ log(logInfo, "doUserEvent() END: sent a user event to the callback channel")
+ return
+}
+
+func addNode(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 = initWidget(n)
+ // n.tk = new(guiWidget)
+
+ if (a.WidgetType == toolkit.Root) {
+ log(logInfo, "addNode() Root")
+ return n
+ }
+
+ if (me.rootNode.findWidgetId(a.WidgetId) != nil) {
+ log(logError, "addNode() WidgetId already exists", a.WidgetId)
+ return me.rootNode.findWidgetId(a.WidgetId)
}
// add this new widget on the binary tree
- n.parent = rootNode.findWidgetId(a.ParentId)
+ n.parent = me.rootNode.findWidgetId(a.ParentId)
if n.parent != nil {
n.parent.children = append(n.parent.children, n)
+ //w := n.tk
+ //w.parent = n.parent.tk
+ //w.parent.children = append(w.parent.children, w)
}
return n
}
diff --git a/toolkit/nocui/event.go b/toolkit/nocui/event.go
index 73b7ff2..1075266 100644
--- a/toolkit/nocui/event.go
+++ b/toolkit/nocui/event.go
@@ -45,22 +45,3 @@ func (n *node) doWidgetClick() {
default:
}
}
-
-func (n *node) doUserEvent() {
- if (callback == nil) {
- log(logError, "doUserEvent() callback == nil", n.WidgetId)
- return
- }
- var a toolkit.Action
- a.WidgetId = n.WidgetId
- a.Name = n.Name
- a.Text = n.Text
- a.S = n.S
- a.I = n.I
- a.B = n.B
- a.ActionType = toolkit.User
- log(logInfo, "doUserEvent() START: send a user event to the callback channel")
- callback <- a
- log(logInfo, "doUserEvent() END: sent a user event to the callback channel")
- return
-}
diff --git a/toolkit/nocui/structs.go b/toolkit/nocui/structs.go
index c3ece3b..90c2c1e 100644
--- a/toolkit/nocui/structs.go
+++ b/toolkit/nocui/structs.go
@@ -1,47 +1,19 @@
package main
-import "git.wit.org/wit/gui/toolkit"
-
-var callback chan toolkit.Action
-
-type node struct {
- parent *node
- children []*node
-
- WidgetId int // widget ID
- WidgetType toolkit.WidgetType
- ParentId int // parent ID
-
- Name string
- Text string
-
- // This is how the values are passed back and forth
- // values from things like checkboxes & dropdown's
- B bool
- I int
- S string
-
- A any // switch to this or deprecate this? pros/cons?
-
- // This is used for things like a slider(0,100)
- X int
- Y int
-
- // This is for the grid size & widget position
- W int
- H int
- AtW int
- AtH int
-
- // the internal plugin toolkit structure
- tk *nocuiT
-}
+// import "git.wit.org/wit/gui/toolkit"
// stores the raw toolkit internals
-type nocuiT struct {
+type guiWidget struct {
Width int
Height int
c int
val map[int]string
}
+
+// It's probably a terrible idea to call this 'me'
+var me config
+
+type config struct {
+ rootNode *node // the base of the binary tree. it should have id == 0
+}
diff --git a/toolkit/nocui/widget.go b/toolkit/nocui/widget.go
new file mode 100644
index 0000000..9155530
--- /dev/null
+++ b/toolkit/nocui/widget.go
@@ -0,0 +1,29 @@
+package main
+
+import (
+ "git.wit.org/wit/gui/toolkit"
+)
+
+// this is specific to the nocui toolkit
+func initWidget(n *node) *guiWidget {
+ var w *guiWidget
+ w = new(guiWidget)
+ // Set(w, "default")
+
+ if n.WidgetType == toolkit.Root {
+ log(logInfo, "setupWidget() FOUND ROOT w.id =", n.WidgetId)
+ n.WidgetId = 0
+ me.rootNode = n
+ return w
+ }
+
+ if (n.WidgetType == toolkit.Box) {
+ if (n.B) {
+ n.horizontal = true
+ } else {
+ n.horizontal = false
+ }
+ }
+
+ return w
+}