summaryrefslogtreecommitdiff
path: root/common/addNode.go
blob: be769fc2abeb073c630448df6e51224fde520e1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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 (
	"reflect"
	"strconv"

	"go.wit.com/log"
	"go.wit.com/gui/widget"
)

// this is in common.go, do not move it
func addNode(a *widget.Action) *node {
	n := new(node)
	n.WidgetType = a.WidgetType
	n.WidgetId = a.WidgetId
	n.ParentId = a.ParentId

	n.state = a.State

	// copy the data from the action message
	n.progname = a.ProgName
	n.value = a.Value
	n.direction = a.Direction
	n.strings = a.Strings

	// TODO: these need to be rethought
	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 == widget.Root) {
		log.Log(INFO, "addNode() Root")
		return n
	}

	if (me.rootNode.findWidgetId(a.WidgetId) != nil) {
		log.Log(ERROR, "addNode() 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)
		//w := n.tk
		//w.parent = n.parent.tk
		//w.parent.children = append(w.parent.children, w)
	}
	return n
}