summaryrefslogtreecommitdiff
path: root/node.go
blob: 4b056fb2e98f183f9b12386c87d5b96c9bf2924e (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package gui

import (
	"go.wit.com/log"
	"go.wit.com/widget"
)

/*
generic function to create a new node on the binary tree

this is called each time you want a new widget
and it initializes basic default values

there isn't much to see here.
*/
func (n *Node) newNode(title string, t widget.WidgetType) *Node {
	if n == nil {
		log.Warn("newNode got parent == nil")
		panic("gui newNode")
	}
	var newN *Node

	newN = addNode()
	newN.progname = title
	newN.value = title
	newN.WidgetType = t

	newN.strings = make(map[string]int)

	// set these defaults
	newN.expand = false
	// honor the visable settings of the parent
	newN.visable = n.visable
	newN.pad = true
	newN.borderless = false

	newN.enabled = true
	newN.changed = true

	if n.WidgetType == widget.Grid {
		n.gridIncrement()
	}
	newN.AtW = n.NextW
	newN.AtH = n.NextH
	newN.hidden = n.hidden // by default, use the value from above

	n.children = append(n.children, newN)
	newN.parent = n
	return newN
}

/*
raw create function for a new node struct and increments the counter
*/
func addNode() *Node {
	n := new(Node)
	n.id = me.counter
	log.Log(NODE, "addNode = widget setid =", n.id)

	me.counter += 1
	return n
}

func (n *Node) Parent() *Node {
	if !n.Ready() {
		return n
	}
	return n.parent
}

func (n *Node) Delete(d *Node) {
	if !n.Ready() {
		return
	}

	for i, child := range n.children {
		log.Log(NODE, "\t", i, child.id, child.progname)
		if child.id == d.id {
			log.Log(NODE, "\t\t Deleting this")
			n.children = append(n.children[:i], n.children[i+1:]...)
			return
		}
	}
	log.Warn("did not find node to delete", d.id, d.progname)
}