summaryrefslogtreecommitdiff
path: root/toolkit/andlabs/common.go
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/andlabs/common.go')
-rw-r--r--toolkit/andlabs/common.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/toolkit/andlabs/common.go b/toolkit/andlabs/common.go
index cd8e9c8..630c6a9 100644
--- a/toolkit/andlabs/common.go
+++ b/toolkit/andlabs/common.go
@@ -4,6 +4,67 @@ import (
"git.wit.org/wit/gui/toolkit"
)
+// searches the binary tree for a WidgetId
+func (n *node) findWidgetId(id int) *node {
+ if (n == nil) {
+ return nil
+ }
+
+ if n.WidgetId == id {
+ return n
+ }
+
+ for _, child := range n.children {
+ newN := child.findWidgetId(id)
+ if (newN != nil) {
+ return newN
+ }
+ }
+ return nil
+}
+
+func addWidget(a *toolkit.Action, tk *andlabsT) *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
+
+ // store the internal toolkit information
+ n.tk = tk
+
+ if (a.WidgetType == toolkit.Root) {
+ log(logInfo, "addWidget() Root")
+ return n
+ }
+
+ if (rootNode.findWidgetId(a.WidgetId) != nil) {
+ log(logError, "addWidget() WidgetId already exists", a.WidgetId)
+ return rootNode.findWidgetId(a.WidgetId)
+ }
+
+ // add this new widget on the binary tree
+ n.parent = rootNode.findWidgetId(a.ParentId)
+ if n.parent != nil {
+ n.parent.children = append(n.parent.children, n)
+ }
+
+ // deprecate this when this toolkit uses the binary tree instead
+ if (andlabs[a.WidgetId] == nil) {
+ andlabs[a.WidgetId] = tk
+ }
+
+ return n
+}
+
func (t *andlabsT) doUserEvent() {
if (callback == nil) {
log(debugError, "doUserEvent() callback == nil", t.wId)