From dcce32583387be7fc4f6cd8c8dea62fd7dc42ecf Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 15 Dec 2023 17:18:48 -0600 Subject: make a common.go for the toolkits Signed-off-by: Jeff Carr --- toolkit/andlabs/common.go | 85 +---------------------------------------------- 1 file changed, 1 insertion(+), 84 deletions(-) mode change 100644 => 120000 toolkit/andlabs/common.go (limited to 'toolkit/andlabs/common.go') diff --git a/toolkit/andlabs/common.go b/toolkit/andlabs/common.go deleted file mode 100644 index ff157ab..0000000 --- a/toolkit/andlabs/common.go +++ /dev/null @@ -1,84 +0,0 @@ -package main - -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 - - n.W = a.W - n.H = a.H - n.AtW = a.AtW - n.AtH = a.AtH - - // 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) - } - return n -} - -func (n *node) doUserEvent() { - if (callback == nil) { - log(debugError, "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/andlabs/common.go b/toolkit/andlabs/common.go new file mode 120000 index 0000000..35417a1 --- /dev/null +++ b/toolkit/andlabs/common.go @@ -0,0 +1 @@ +../nocui/common.go \ No newline at end of file -- cgit v1.2.3