2023-02-25 14:05:25 -06:00
|
|
|
package gui
|
|
|
|
|
|
|
|
// Lots of debugging things:
|
|
|
|
// A function dump out the binary tree
|
|
|
|
|
|
|
|
import (
|
2023-03-01 11:35:36 -06:00
|
|
|
"strconv"
|
2023-12-20 14:15:00 -06:00
|
|
|
"go.wit.com/gui/toolkit"
|
2023-02-25 14:05:25 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
// various debugging flags
|
2023-03-23 12:35:12 -05:00
|
|
|
var debugNow bool = true // useful for active development
|
2023-02-25 14:05:25 -06:00
|
|
|
var debugGui bool = false
|
2023-03-23 12:35:12 -05:00
|
|
|
var debugError bool = true
|
2023-02-25 14:05:25 -06:00
|
|
|
var debugDump bool = false
|
|
|
|
var debugNode bool = false
|
|
|
|
var debugTabs bool = false
|
2023-03-03 14:41:38 -06:00
|
|
|
var debugFlags bool = false
|
2023-02-25 14:05:25 -06:00
|
|
|
var debugChange bool = false // shows user events like mouse and keyboard
|
|
|
|
var debugPlugin bool = false
|
2023-03-23 12:35:12 -05:00
|
|
|
var debugAction bool = false
|
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
|
|
|
|
|
|
|
func SetDebug (s bool) {
|
2023-03-01 11:35:36 -06:00
|
|
|
debugGui = s
|
|
|
|
debugTabs = s
|
2023-02-25 14:05:25 -06:00
|
|
|
|
2023-04-23 09:47:54 -05:00
|
|
|
logNow = s
|
|
|
|
logInfo = s
|
|
|
|
logWarn = s
|
|
|
|
logError = s
|
|
|
|
logVerbose = s
|
|
|
|
|
2023-03-12 08:47:16 -05:00
|
|
|
SetFlag("Node", s)
|
|
|
|
SetFlag("Tabs", s)
|
|
|
|
SetFlag("Dump", s)
|
2023-03-03 14:41:38 -06:00
|
|
|
SetFlag("Flags", s)
|
2023-03-12 08:47:16 -05:00
|
|
|
SetFlag("Plugin", s)
|
2023-03-03 14:41:38 -06:00
|
|
|
SetFlag("Change", s)
|
|
|
|
SetFlag("Error", s)
|
2023-03-12 08:47:16 -05:00
|
|
|
|
|
|
|
// This flag is only for the internal toolkit debugging
|
|
|
|
SetFlag("Toolkit", s)
|
2023-02-25 14:05:25 -06:00
|
|
|
}
|
|
|
|
|
2023-03-03 14:41:38 -06:00
|
|
|
func SetFlag (s string, b bool) {
|
|
|
|
switch s {
|
2023-03-12 08:47:16 -05:00
|
|
|
case "Toolkit":
|
|
|
|
// This flag is only for internal toolkit debugging
|
|
|
|
case "Tabs":
|
|
|
|
debugTabs = b
|
|
|
|
case "Node":
|
|
|
|
debugNode = b
|
|
|
|
case "Dump":
|
|
|
|
debugDump = b
|
2023-03-03 14:41:38 -06:00
|
|
|
case "Error":
|
|
|
|
debugError = b
|
|
|
|
case "Change":
|
|
|
|
debugChange = b
|
2023-03-12 08:47:16 -05:00
|
|
|
case "Flags":
|
|
|
|
debugFlags = b
|
|
|
|
case "Plugin":
|
|
|
|
debugPlugin = b
|
2023-03-03 14:41:38 -06:00
|
|
|
case "Show":
|
2023-03-12 08:47:16 -05:00
|
|
|
// ShowDebugValues() // print them here?
|
2023-03-03 14:41:38 -06:00
|
|
|
default:
|
2023-03-12 08:47:16 -05:00
|
|
|
log(debugGui, "Can't set unknown flag", s)
|
2023-02-25 14:05:25 -06:00
|
|
|
}
|
|
|
|
|
2023-05-09 19:24:37 -05:00
|
|
|
a := new(toolkit.Action)
|
2023-03-29 23:03:04 -05:00
|
|
|
a.ActionType = toolkit.Set
|
|
|
|
a.WidgetType = toolkit.Flag
|
2023-03-23 12:35:12 -05:00
|
|
|
a.S = s
|
|
|
|
a.B = b
|
2023-05-09 19:24:37 -05:00
|
|
|
sendAction(a)
|
2023-02-25 14:05:25 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func ShowDebugValues() {
|
2023-03-01 11:35:36 -06:00
|
|
|
// The order here should match the order in the GUI
|
|
|
|
// TODO: get the order from the node binary tree
|
|
|
|
log(true, "Debug =", debugGui)
|
2023-03-03 14:41:38 -06:00
|
|
|
log(true, "DebugError =", debugError)
|
2023-03-01 11:35:36 -06:00
|
|
|
log(true, "DebugChange =", debugChange)
|
|
|
|
log(true, "DebugDump =", debugDump)
|
|
|
|
log(true, "DebugTabs =", debugTabs)
|
|
|
|
log(true, "DebugPlugin =", debugPlugin)
|
|
|
|
log(true, "DebugNode =", debugNode)
|
2023-02-25 14:05:25 -06:00
|
|
|
|
2023-03-03 14:41:38 -06:00
|
|
|
SetFlag("Show", true)
|
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
|
|
|
// log("Dump() dump =", b)
|
|
|
|
Indent(b, "NODE DUMP START")
|
|
|
|
Indent(b, "id = ", n.id)
|
|
|
|
Indent(b, "Name = ", n.Name)
|
|
|
|
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
|
|
|
|
2023-05-09 19:24:37 -05:00
|
|
|
a := new(toolkit.Action)
|
2023-04-28 10:30:27 -05:00
|
|
|
a.ActionType = toolkit.Dump
|
|
|
|
a.WidgetId = n.id
|
2023-05-09 19:24:37 -05:00
|
|
|
sendAction(a)
|
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) {
|
|
|
|
log(debugError, "dumpWidget() node == nil")
|
|
|
|
return ""
|
|
|
|
}
|
2023-04-03 10:26:47 -05:00
|
|
|
info = n.WidgetType.String()
|
2023-02-25 14:05:25 -06:00
|
|
|
|
2023-12-03 16:08:39 -06:00
|
|
|
d = strconv.Itoa(n.id) + " " + info + " " + n.Name
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
log(debugNode, "\t\t\tparent =",n.parent.id)
|
|
|
|
if (listChildrenParent != nil) {
|
|
|
|
log(debugNode, "\t\t\tlistChildrenParent =",listChildrenParent.id)
|
|
|
|
if (listChildrenParent.id != n.parent.id) {
|
2023-03-23 12:35:12 -05:00
|
|
|
log("parent =",n.parent.id, n.parent.Name)
|
|
|
|
log("listChildrenParent =",listChildrenParent.id, listChildrenParent.Name)
|
|
|
|
log(listChildrenParent.id, "!=", n.parent.id)
|
2023-03-12 08:47:16 -05:00
|
|
|
exit("parent.child does not match child.parent")
|
2023-02-25 14:05:25 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
log(debugNode, "\t\t", n.id, "has no children")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, child := range n.children {
|
|
|
|
if (child.parent != nil) {
|
|
|
|
log(debugNode, "\t\t\tparent =",child.parent.id)
|
|
|
|
} else {
|
|
|
|
log(debugGui, "\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(debugNode, "\t\t", child.id, "has no children")
|
|
|
|
} else {
|
|
|
|
log(debugNode, "\t\t\tHas children:", child.children)
|
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|