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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
package gui
// old debugging things. probably deprecate
// everything should be moved to "go.wit.com/gui/debugger"
// A function dump out the binary tree
import (
"errors"
"strconv"
"strings"
"go.wit.com/log"
"go.wit.com/gui/widget"
)
// for printing out the binary tree
var listChildrenParent *Node
var listChildrenDepth int = 0
var defaultPadding = " "
func (n *Node) Dump() {
b := true
Indent(b, "NODE DUMP START")
Indent(b, "id = ", n.id)
Indent(b, "progname = ", n.progname)
Indent(b, "(X,Y) = ", n.X, n.Y)
Indent(b, "Next (W,H) = ", n.NextW, n.NextH)
if (n.parent == nil) {
Indent(b, "parent = nil")
} else {
Indent(b, "parent.id =", n.parent.id)
}
if (n.children != nil) {
Indent(b, "children = ", n.children)
}
if (n.Custom != nil) {
Indent(b, "Custom = ", n.Custom)
}
Indent(b, "NODE DUMP END")
n.changed = true
sendAction(n, widget.Dump)
}
func Indent(b bool, a ...interface{}) {
logindent(b, listChildrenDepth, defaultPadding, a...)
}
func (n *Node) dumpWidget(b bool) string {
var info, d string
if (n == nil) {
log.Error(errors.New("dumpWidget() node == nil"))
return ""
}
info = n.WidgetType.String()
var tabs string
for i := 0; i < listChildrenDepth; i++ {
tabs = tabs + defaultPadding
}
d = strconv.Itoa(n.id) + " " + info + " " + n.GetProgName()
logindent(b, listChildrenDepth, defaultPadding, d)
if b {
switch n.WidgetType {
case widget.Combobox:
logindent(b, listChildrenDepth, defaultPadding, " Dropdown", n.value)
logindent(b, listChildrenDepth, defaultPadding, " Dropdown", n.strings)
case widget.Dropdown:
logindent(b, listChildrenDepth, defaultPadding, " Dropdown", n.value)
logindent(b, listChildrenDepth, defaultPadding, " Dropdown", n.strings)
case widget.Grid:
logindent(b, listChildrenDepth, defaultPadding, " GridSize =", n.X, n.Y)
case widget.Box:
logindent(b, listChildrenDepth, defaultPadding, " Direction =", n.direction)
default:
}
}
return tabs + d
}
func (n *Node) Children() []*Node {
return n.children
}
// func (n *Node) ListChildren(dump bool, dropdown *Node, mapNodes map[string]*Node) {
func (n *Node) ListChildren(dump bool) {
if (n == nil) {
return
}
n.dumpWidget(dump)
if len(n.children) == 0 {
if (n.parent == nil) {
return
}
log.Log(NODE, "\t\t\tparent =",n.parent.id)
if (listChildrenParent != nil) {
log.Log(NODE, "\t\t\tlistChildrenParent =",listChildrenParent.id)
if (listChildrenParent.id != n.parent.id) {
log.Log(NOW, "parent =",n.parent.id, n.parent.progname)
log.Log(NOW, "listChildrenParent =",listChildrenParent.id, listChildrenParent.progname)
log.Log(NOW, listChildrenParent.id, "!=", n.parent.id)
log.Exit("parent.child does not match child.parent")
}
}
log.Log(NODE, "\t\t", n.id, "has no children")
return
}
for _, child := range n.children {
if (child.parent != nil) {
log.Log(NODE, "\t\t\tparent =",child.parent.id)
} else {
log.Log(GUI, "\t\t\tno parent")
// memory corruption? non-threadsafe access?
// can all binary tree changes to Node.parent & Node.child be forced into a singular goroutine?
panic("something is wrong with the wit golang gui logic and the binary tree is broken. child has no parent")
}
if (child.children == nil) {
log.Log(NODE, "\t\t", child.id, "has no children")
} else {
log.Log(NODE, "\t\t\tHas children:", child.children)
}
listChildrenParent = n
listChildrenDepth += 1
// child.ListChildren(dump, dropdown, mapNodes)
child.ListChildren(dump)
listChildrenDepth -= 1
}
return
}
// b bool, print if true
func logindent(b bool, depth int, format string, a ...any) {
var tabs string
for i := 0; i < depth; i++ {
tabs = tabs + format
}
// newFormat := tabs + strconv.Itoa(depth) + " " + format
newFormat := tabs + format
// array prepend(). Why isn't this a standard function. It should be:
// a.prepend(debugGui, newFormat)
a = append([]any{b, newFormat}, a...)
log.Log(NOW, a...)
}
|