summaryrefslogtreecommitdiff
path: root/toolkit/gocui/common.go
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/gocui/common.go')
-rw-r--r--toolkit/gocui/common.go100
1 files changed, 100 insertions, 0 deletions
diff --git a/toolkit/gocui/common.go b/toolkit/gocui/common.go
new file mode 100644
index 0000000..2fe82cb
--- /dev/null
+++ b/toolkit/gocui/common.go
@@ -0,0 +1,100 @@
+package main
+
+import (
+ "strconv"
+ "git.wit.org/wit/gui/toolkit"
+// "github.com/awesome-gocui/gocui"
+)
+
+func setupWidget(a *toolkit.Action) *cuiWidget {
+ var w *cuiWidget
+ w = new(cuiWidget)
+
+ w.name = a.Name
+ w.text = a.Text
+ w.b = a.B
+ w.i = a.I
+ w.s = a.S
+ w.x = a.X
+ w.y = a.Y
+ w.width = a.Width
+ w.height = a.Height
+
+ w.widgetType = a.WidgetType
+ w.id = a.WidgetId
+ // set the name used by gocui to the id
+ w.cuiName = strconv.Itoa(w.id)
+
+ w.parent = findWidget(a.ParentId, me.rootNode)
+ log(logInfo, "setupWidget() w.id =", w.id, "w.parent", w.parent, "ParentId =", a.ParentId)
+ if (w.id == 0) {
+ me.rootNode = w
+ // this is the rootNode
+ return w
+ }
+ if (w.parent == nil) {
+ log(logError, "setupWidget() ERROR: PARENT = NIL w.id =", w.id, "w.parent", w.parent, "ParentId =", a.ParentId)
+ // just use the rootNode (hopefully it's not nil)
+ w.parent = me.rootNode
+ // return w
+ }
+ if (w.parent == nil) {
+ log(logError, "setupWidget() ERROR: PARENT = NIL w.id =", w.id, "w.parent", w.parent, "ParentId =", a.ParentId)
+ me.rootNode = w
+ return w
+ }
+ // add this widget as a child for the parent
+ w.parent.Append(w)
+
+ if (a.WidgetType == toolkit.Box) {
+ if (a.B) {
+ w.horizontal = true
+ } else {
+ w.horizontal = false
+ }
+ }
+
+ // w.showWidgetPlacement(logNow)
+ return w
+}
+
+func setupCtrlDownWidget() {
+ var w *cuiWidget
+ w = new(cuiWidget)
+
+ w.name = "ctrlDown"
+
+ w.widgetType = toolkit.Flag
+ w.id = -1
+ me.ctrlDown = w
+ // me.rootNode.Append(w)
+}
+
+func (n *cuiWidget) Append(child *cuiWidget) {
+ n.children = append(n.children, child)
+ // child.parent = n
+}
+
+// find widget by number
+func findWidget(i int, w *cuiWidget) (*cuiWidget) {
+ if (w == nil) {
+ log(logVerbose, "findWidget() Trying to find i =", i, "currently checking against w.id = nil")
+ return nil
+ }
+ log(logVerbose, "findWidget() Trying to find i =", i, "currently checking against w.id =", w.id)
+
+ if (w.id == i) {
+ log(logInfo, "findWidget() FOUND w.id ==", i, w.widgetType, w.name)
+ return w
+ }
+
+ for _, child := range w.children {
+ newW := findWidget(i, child)
+ log(logVerbose, "findWidget() Trying to find i =", i, "currently checking against child.id =", child.id)
+ if (newW != nil) {
+ return newW
+ }
+ }
+ return nil
+}
+