2023-02-25 14:05:25 -06:00
|
|
|
package gui
|
|
|
|
|
2024-01-03 18:54:08 -06:00
|
|
|
// old debugging things. probably deprecate
|
|
|
|
// everything should be moved to "go.wit.com/gui/debugger"
|
2023-02-25 14:05:25 -06:00
|
|
|
// A function dump out the binary tree
|
|
|
|
|
|
|
|
import (
|
2024-01-03 18:15:54 -06:00
|
|
|
"errors"
|
2023-03-01 11:35:36 -06:00
|
|
|
"strconv"
|
2024-01-03 18:15:54 -06:00
|
|
|
|
|
|
|
"go.wit.com/log"
|
2024-01-05 13:18:44 -06:00
|
|
|
"go.wit.com/gui/widget"
|
2023-02-25 14:05:25 -06:00
|
|
|
)
|
|
|
|
|
2023-03-03 14:41:38 -06:00
|
|
|
// for printing out the binary tree
|
|
|
|
var listChildrenParent *Node
|
|
|
|
var listChildrenDepth int = 0
|
|
|
|
var defaultPadding = " "
|
2023-02-25 14:05:25 -06:00
|
|
|
|
2023-04-28 10:30:27 -05:00
|
|
|
func (n *Node) Dump() {
|
|
|
|
b := true
|
2023-03-23 12:35:12 -05:00
|
|
|
Indent(b, "NODE DUMP START")
|
|
|
|
Indent(b, "id = ", n.id)
|
2024-01-11 19:32:40 -06:00
|
|
|
Indent(b, "progname = ", n.progname)
|
2023-03-23 12:35:12 -05:00
|
|
|
Indent(b, "(X,Y) = ", n.X, n.Y)
|
2023-05-09 17:48:21 -05:00
|
|
|
Indent(b, "Next (W,H) = ", n.NextW, n.NextH)
|
2023-02-25 14:05:25 -06:00
|
|
|
|
|
|
|
if (n.parent == nil) {
|
2023-03-23 12:35:12 -05:00
|
|
|
Indent(b, "parent = nil")
|
2023-02-25 14:05:25 -06:00
|
|
|
} else {
|
2023-03-23 12:35:12 -05:00
|
|
|
Indent(b, "parent.id =", n.parent.id)
|
2023-02-25 14:05:25 -06:00
|
|
|
}
|
|
|
|
if (n.children != nil) {
|
2023-03-23 12:35:12 -05:00
|
|
|
Indent(b, "children = ", n.children)
|
2023-02-25 14:05:25 -06:00
|
|
|
}
|
2023-03-01 11:35:36 -06:00
|
|
|
if (n.Custom != nil) {
|
2023-03-23 12:35:12 -05:00
|
|
|
Indent(b, "Custom = ", n.Custom)
|
2023-02-25 14:05:25 -06:00
|
|
|
}
|
2023-03-23 12:35:12 -05:00
|
|
|
Indent(b, "NODE DUMP END")
|
2023-04-28 10:30:27 -05:00
|
|
|
|
2024-01-13 22:02:12 -06:00
|
|
|
n.changed = true
|
|
|
|
sendAction(n, widget.Dump)
|
2023-02-25 14:05:25 -06:00
|
|
|
}
|
|
|
|
|
2023-03-23 12:35:12 -05:00
|
|
|
func Indent(b bool, a ...interface{}) {
|
|
|
|
logindent(b, listChildrenDepth, defaultPadding, a...)
|
2023-02-25 14:05:25 -06:00
|
|
|
}
|
|
|
|
|
2023-03-23 12:35:12 -05:00
|
|
|
func (n *Node) dumpWidget(b bool) string {
|
2023-03-12 08:47:16 -05:00
|
|
|
var info, d string
|
2023-02-25 14:05:25 -06:00
|
|
|
|
2023-03-23 12:35:12 -05:00
|
|
|
if (n == nil) {
|
2024-01-03 18:15:54 -06:00
|
|
|
log.Error(errors.New("dumpWidget() node == nil"))
|
2023-03-23 12:35:12 -05:00
|
|
|
return ""
|
|
|
|
}
|
2023-04-03 10:26:47 -05:00
|
|
|
info = n.WidgetType.String()
|
2023-02-25 14:05:25 -06:00
|
|
|
|
2024-01-11 19:32:40 -06:00
|
|
|
d = strconv.Itoa(n.id) + " " + info + " " + n.progname
|
2023-03-12 08:47:16 -05:00
|
|
|
|
|
|
|
var tabs string
|
|
|
|
for i := 0; i < listChildrenDepth; i++ {
|
|
|
|
tabs = tabs + defaultPadding
|
|
|
|
}
|
2023-12-14 10:36:56 -06:00
|
|
|
logindent(b, listChildrenDepth, defaultPadding, d)
|
|
|
|
return tabs + d
|
2023-02-25 14:05:25 -06:00
|
|
|
}
|
|
|
|
|
2024-01-03 13:37:03 -06:00
|
|
|
func (n *Node) Children() []*Node {
|
|
|
|
return n.children
|
|
|
|
}
|
|
|
|
|
2023-03-23 12:35:12 -05:00
|
|
|
// func (n *Node) ListChildren(dump bool, dropdown *Node, mapNodes map[string]*Node) {
|
|
|
|
func (n *Node) ListChildren(dump bool) {
|
|
|
|
if (n == nil) {
|
|
|
|
return
|
2023-03-12 08:47:16 -05:00
|
|
|
}
|
2023-02-25 14:05:25 -06:00
|
|
|
|
2023-03-23 12:35:12 -05:00
|
|
|
n.dumpWidget(dump)
|
2023-02-25 14:05:25 -06:00
|
|
|
if len(n.children) == 0 {
|
|
|
|
if (n.parent == nil) {
|
2023-03-12 08:47:16 -05:00
|
|
|
return
|
|
|
|
}
|
2024-01-03 18:15:54 -06:00
|
|
|
log.Log(NODE, "\t\t\tparent =",n.parent.id)
|
2023-03-12 08:47:16 -05:00
|
|
|
if (listChildrenParent != nil) {
|
2024-01-03 18:15:54 -06:00
|
|
|
log.Log(NODE, "\t\t\tlistChildrenParent =",listChildrenParent.id)
|
2023-03-12 08:47:16 -05:00
|
|
|
if (listChildrenParent.id != n.parent.id) {
|
2024-01-11 19:32:40 -06:00
|
|
|
log.Log(NOW, "parent =",n.parent.id, n.parent.progname)
|
|
|
|
log.Log(NOW, "listChildrenParent =",listChildrenParent.id, listChildrenParent.progname)
|
2024-01-08 22:27:17 -06:00
|
|
|
log.Log(NOW, listChildrenParent.id, "!=", n.parent.id)
|
2024-01-03 18:15:54 -06:00
|
|
|
log.Exit("parent.child does not match child.parent")
|
2023-02-25 14:05:25 -06:00
|
|
|
}
|
|
|
|
}
|
2024-01-03 18:15:54 -06:00
|
|
|
log.Log(NODE, "\t\t", n.id, "has no children")
|
2023-02-25 14:05:25 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, child := range n.children {
|
|
|
|
if (child.parent != nil) {
|
2024-01-03 18:15:54 -06:00
|
|
|
log.Log(NODE, "\t\t\tparent =",child.parent.id)
|
2023-02-25 14:05:25 -06:00
|
|
|
} else {
|
2024-01-03 18:15:54 -06:00
|
|
|
log.Log(GUI, "\t\t\tno parent")
|
2023-02-25 14:05:25 -06:00
|
|
|
// 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) {
|
2024-01-03 18:15:54 -06:00
|
|
|
log.Log(NODE, "\t\t", child.id, "has no children")
|
2023-02-25 14:05:25 -06:00
|
|
|
} else {
|
2024-01-03 18:15:54 -06:00
|
|
|
log.Log(NODE, "\t\t\tHas children:", child.children)
|
2023-02-25 14:05:25 -06:00
|
|
|
}
|
|
|
|
listChildrenParent = n
|
|
|
|
listChildrenDepth += 1
|
2023-03-23 12:35:12 -05:00
|
|
|
// child.ListChildren(dump, dropdown, mapNodes)
|
|
|
|
child.ListChildren(dump)
|
2023-02-25 14:05:25 -06:00
|
|
|
listChildrenDepth -= 1
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2024-01-03 18:15:54 -06:00
|
|
|
|
|
|
|
// 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...)
|
2024-01-08 22:27:17 -06:00
|
|
|
log.Log(NOW, a...)
|
2024-01-03 18:15:54 -06:00
|
|
|
}
|