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"
|
|
|
|
"git.wit.org/wit/gui/toolkit"
|
2023-02-25 14:05:25 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
// various debugging flags
|
|
|
|
var debugGui bool = false
|
|
|
|
var debugDump bool = false
|
|
|
|
var debugNode bool = false
|
|
|
|
var debugTabs bool = false
|
|
|
|
var debugChange bool = false // shows user events like mouse and keyboard
|
|
|
|
var debugPlugin bool = false
|
|
|
|
var debugToolkit bool = false
|
|
|
|
|
2023-03-01 11:35:36 -06:00
|
|
|
// func GetDebug () bool {
|
|
|
|
// return debugGui
|
|
|
|
// }
|
2023-02-25 14:05:25 -06:00
|
|
|
|
|
|
|
func SetDebug (s bool) {
|
2023-03-01 11:35:36 -06:00
|
|
|
debugGui = s
|
|
|
|
debugChange = s
|
|
|
|
debugDump = s
|
|
|
|
debugTabs = s
|
|
|
|
debugPlugin = s
|
|
|
|
debugNode = s
|
|
|
|
debugToolkit = s
|
|
|
|
SetDebugChange(s)
|
|
|
|
SetDebugToolkit(s)
|
2023-02-25 14:05:25 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
func GetDebugToolkit () bool {
|
|
|
|
return debugToolkit
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
// This passes the debugToolkit flag to the toolkit plugin
|
|
|
|
func SetDebugToolkit (s bool) {
|
|
|
|
debugToolkit = s
|
|
|
|
for _, aplug := range allPlugins {
|
|
|
|
log(debugPlugin, "gui.SetDebugToolkit() aplug =", aplug.name)
|
|
|
|
if (aplug.SetDebugToolkit == nil) {
|
|
|
|
log(debugPlugin, "\tgui.SetDebugToolkit() = nil", aplug.name)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
aplug.SetDebugToolkit(s)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
log(debugPlugin, "\tgui.SetDebugToolkit() = nil in all plugins")
|
|
|
|
}
|
|
|
|
|
|
|
|
// This passes the debugChange flag to the toolkit plugin
|
|
|
|
func SetDebugChange (s bool) {
|
|
|
|
// debugToolkit = s
|
|
|
|
for _, aplug := range allPlugins {
|
|
|
|
log(debugPlugin, "gui.SetDebugChange() aplug =", aplug.name)
|
|
|
|
if (aplug.SetDebugChange == nil) {
|
|
|
|
log(debugPlugin, "\tgui.SetDebugChange() = nil", aplug.name)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
aplug.SetDebugChange(s)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
log(debugPlugin, "\tgui.SetDebugChange() = nil in all plugins")
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
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
|
|
|
log(true, "DebugToolkit =", debugToolkit)
|
|
|
|
|
|
|
|
// dump out the debugging flags for the plugins
|
|
|
|
for _, aplug := range allPlugins {
|
|
|
|
log(debugPlugin, "gui.ShowDebug() aplug =", aplug.name)
|
|
|
|
if (aplug.ShowDebug == nil) {
|
|
|
|
log(debugPlugin, "\tgui.ShowDebug() = nil", aplug.name)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
aplug.ShowDebug()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *Node) Dump() {
|
|
|
|
if ! debugDump {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
Indent("NODE DUMP START")
|
|
|
|
Indent("id = ", n.id)
|
|
|
|
Indent("Name = ", n.Name)
|
|
|
|
Indent("Width = ", n.Width)
|
|
|
|
Indent("Height = ", n.Height)
|
|
|
|
|
|
|
|
if (n.parent == nil) {
|
|
|
|
Indent("parent = nil")
|
|
|
|
} else {
|
|
|
|
Indent("parent.id =", n.parent.id)
|
|
|
|
}
|
|
|
|
if (n.children != nil) {
|
|
|
|
Indent("children = ", n.children)
|
|
|
|
}
|
2023-03-01 11:35:36 -06:00
|
|
|
if (n.Custom != nil) {
|
|
|
|
Indent("Custom = ", n.Custom)
|
2023-02-25 14:05:25 -06:00
|
|
|
}
|
|
|
|
Indent("NODE DUMP END")
|
|
|
|
}
|
|
|
|
|
|
|
|
var listChildrenParent *Node
|
|
|
|
var listChildrenDepth int = 0
|
|
|
|
var defaultPadding = " "
|
|
|
|
|
|
|
|
func Indent(a ...interface{}) {
|
|
|
|
logindent(listChildrenDepth, defaultPadding, a...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *Node) dumpWidget() {
|
|
|
|
var info string
|
|
|
|
|
2023-03-01 11:35:36 -06:00
|
|
|
info = n.widget.Type.String()
|
2023-02-25 14:05:25 -06:00
|
|
|
|
2023-03-01 11:35:36 -06:00
|
|
|
info += ", " + n.widget.Name
|
|
|
|
if (n.Name != n.widget.Name) {
|
2023-02-25 14:05:25 -06:00
|
|
|
info += " NAME MISMATCH"
|
|
|
|
}
|
2023-03-01 11:35:36 -06:00
|
|
|
if (n.widget.Type == toolkit.Checkbox) {
|
|
|
|
info += " = " + strconv.FormatBool(n.widget.B)
|
|
|
|
}
|
2023-02-25 14:05:25 -06:00
|
|
|
|
|
|
|
logindent(listChildrenDepth, defaultPadding, n.id, info)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *Node) ListChildren(dump bool) {
|
|
|
|
n.dumpWidget()
|
|
|
|
|
|
|
|
if (dump == true) {
|
|
|
|
n.Dump()
|
|
|
|
}
|
|
|
|
if len(n.children) == 0 {
|
|
|
|
if (n.parent == nil) {
|
|
|
|
} else {
|
|
|
|
log(debugNode, "\t\t\tparent =",n.parent.id)
|
|
|
|
if (listChildrenParent != nil) {
|
|
|
|
log(debugNode, "\t\t\tlistChildrenParent =",listChildrenParent.id)
|
|
|
|
if (listChildrenParent.id != n.parent.id) {
|
|
|
|
// log("parent.child does not match child.parent")
|
|
|
|
exit("parent.child does not match child.parent")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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 (dump == true) {
|
|
|
|
child.Dump()
|
|
|
|
}
|
|
|
|
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
|
|
|
|
child.ListChildren(dump)
|
|
|
|
listChildrenDepth -= 1
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|