2021-10-05 05:52:50 -05:00
|
|
|
package gui
|
|
|
|
|
2021-10-06 11:17:43 -05:00
|
|
|
import (
|
|
|
|
"log"
|
2021-10-05 05:52:50 -05:00
|
|
|
|
2021-10-06 11:17:43 -05:00
|
|
|
"github.com/andlabs/ui"
|
|
|
|
_ "github.com/andlabs/ui/winmanifest"
|
|
|
|
"github.com/davecgh/go-spew/spew"
|
|
|
|
)
|
2021-10-05 06:25:32 -05:00
|
|
|
|
2021-10-05 05:52:50 -05:00
|
|
|
var names = make([]string, 100)
|
2021-10-09 02:37:14 -05:00
|
|
|
var nodeNames = make([]string, 100)
|
|
|
|
|
2021-10-25 05:41:12 -05:00
|
|
|
func DebugWindow() {
|
|
|
|
log.Println("START gui.DebugWindow()")
|
|
|
|
|
|
|
|
title := "WIT GUI Debug Window"
|
|
|
|
node := InitWindow(nil, nil, title, 0)
|
|
|
|
box := node.box
|
|
|
|
window := box.Window
|
|
|
|
log.Println("box =", box)
|
|
|
|
log.Println("window =", window)
|
|
|
|
node.AddDebugTab("WIT GUI Debug Tab")
|
|
|
|
|
|
|
|
window.UiWindow.Show()
|
|
|
|
}
|
|
|
|
|
2021-10-09 02:37:14 -05:00
|
|
|
// TODO: remove this crap
|
2021-10-25 05:00:12 -05:00
|
|
|
// What does this actually do?
|
|
|
|
// It populates the nodeNames in a map. No, not a map, an array. What is the difference again?
|
2021-10-09 02:37:14 -05:00
|
|
|
func addNodeName(c *ui.Combobox, s string) {
|
|
|
|
c.Append(s)
|
|
|
|
nodeNames[y] = s
|
|
|
|
y = y + 1
|
|
|
|
}
|
2021-10-05 05:52:50 -05:00
|
|
|
|
|
|
|
func makeWindowDebug() ui.Control {
|
|
|
|
hbox := ui.NewHorizontalBox()
|
|
|
|
hbox.SetPadded(true)
|
|
|
|
|
2021-10-06 11:17:43 -05:00
|
|
|
/////////////////////////////////////////////////////
|
2021-10-09 02:37:14 -05:00
|
|
|
vbox := addGroup(hbox, "range Data.WindowMap")
|
2021-10-05 06:25:32 -05:00
|
|
|
cbox := ui.NewCombobox()
|
2021-10-05 05:52:50 -05:00
|
|
|
|
2021-10-05 06:25:32 -05:00
|
|
|
for name, _ := range Data.WindowMap {
|
|
|
|
log.Println("range Data.WindowMap() name =", name)
|
|
|
|
addName(cbox, name)
|
|
|
|
}
|
2021-10-06 11:50:35 -05:00
|
|
|
cbox.SetSelected(0)
|
2021-10-05 05:52:50 -05:00
|
|
|
|
|
|
|
vbox.Append(cbox, false)
|
|
|
|
|
|
|
|
cbox.OnSelected(func(*ui.Combobox) {
|
2021-10-05 06:25:32 -05:00
|
|
|
x := cbox.Selected()
|
|
|
|
log.Println("x =", x)
|
|
|
|
log.Println("names[x] =", names[x])
|
|
|
|
dumpBox(names[x])
|
2021-10-05 05:52:50 -05:00
|
|
|
})
|
|
|
|
|
2021-10-06 11:17:43 -05:00
|
|
|
/////////////////////////////////////////////////////
|
2021-10-06 13:23:00 -05:00
|
|
|
vbox = addGroup(hbox, "Debug Window")
|
2021-10-05 07:13:24 -05:00
|
|
|
|
2021-10-06 13:23:00 -05:00
|
|
|
b1 := addButton(vbox, "dumpBox(window)")
|
2021-10-05 06:46:46 -05:00
|
|
|
b1.OnClicked(func(*ui.Button) {
|
|
|
|
x := cbox.Selected()
|
|
|
|
log.Println("x =", x)
|
|
|
|
log.Println("names[x] =", names[x])
|
|
|
|
dumpBox(names[x])
|
|
|
|
})
|
2021-10-05 07:13:24 -05:00
|
|
|
|
2021-10-06 13:23:00 -05:00
|
|
|
b2 := addButton(vbox, "SetMargined(tab)")
|
2021-10-05 06:46:46 -05:00
|
|
|
b2.OnClicked(func(*ui.Button) {
|
2021-10-05 07:13:24 -05:00
|
|
|
x := cbox.Selected()
|
|
|
|
log.Println("x =", x)
|
2021-10-06 13:23:00 -05:00
|
|
|
log.Println("FindWindow; names[x] =", names[x])
|
|
|
|
gw := FindWindow(names[x])
|
2021-10-06 11:17:43 -05:00
|
|
|
if gw == nil {
|
2021-10-05 07:13:24 -05:00
|
|
|
return
|
|
|
|
}
|
2021-10-06 11:17:43 -05:00
|
|
|
if gw.UiTab == nil {
|
2021-10-05 07:13:24 -05:00
|
|
|
return
|
|
|
|
}
|
2021-10-06 11:17:43 -05:00
|
|
|
if gw.TabNumber == nil {
|
2021-10-05 07:13:24 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
scs := spew.ConfigState{MaxDepth: 1}
|
|
|
|
scs.Dump(gw)
|
|
|
|
log.Println("gui.DumpBoxes()\tWindow.UiTab =", gw.UiTab)
|
|
|
|
log.Println("gui.DumpBoxes()\tWindow.TabNumber =", *gw.TabNumber)
|
|
|
|
gw.UiTab.SetMargined(*gw.TabNumber, true)
|
2021-10-05 06:46:46 -05:00
|
|
|
})
|
|
|
|
|
2021-10-06 13:23:00 -05:00
|
|
|
b3 := addButton(vbox, "Hide(tab)")
|
2021-10-05 09:42:30 -05:00
|
|
|
b3.OnClicked(func(*ui.Button) {
|
|
|
|
x := cbox.Selected()
|
|
|
|
log.Println("x =", x)
|
2021-10-06 13:23:00 -05:00
|
|
|
log.Println("FindWindow; names[x] =", names[x])
|
|
|
|
gw := FindWindow(names[x])
|
2021-10-06 11:17:43 -05:00
|
|
|
if gw == nil {
|
2021-10-05 09:42:30 -05:00
|
|
|
return
|
|
|
|
}
|
2021-10-06 11:17:43 -05:00
|
|
|
if gw.UiTab == nil {
|
2021-10-05 09:42:30 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
gw.UiTab.Hide()
|
|
|
|
})
|
|
|
|
|
2021-10-06 13:23:00 -05:00
|
|
|
b4 := addButton(vbox, "Show(tab)")
|
2021-10-05 09:42:30 -05:00
|
|
|
b4.OnClicked(func(*ui.Button) {
|
|
|
|
x := cbox.Selected()
|
|
|
|
log.Println("x =", x)
|
2021-10-06 13:23:00 -05:00
|
|
|
log.Println("FindWindow; names[x] =", names[x])
|
|
|
|
gw := FindWindow(names[x])
|
2021-10-06 11:17:43 -05:00
|
|
|
if gw == nil {
|
2021-10-05 09:42:30 -05:00
|
|
|
return
|
|
|
|
}
|
2021-10-06 11:17:43 -05:00
|
|
|
if gw.UiTab == nil {
|
2021-10-05 09:42:30 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
gw.UiTab.Show()
|
|
|
|
})
|
|
|
|
|
2021-10-06 13:23:00 -05:00
|
|
|
b5 := addButton(vbox, "Delete(tab)")
|
2021-10-05 09:42:30 -05:00
|
|
|
b5.OnClicked(func(*ui.Button) {
|
|
|
|
x := cbox.Selected()
|
|
|
|
log.Println("x =", x)
|
2021-10-06 13:23:00 -05:00
|
|
|
log.Println("FindWindow; names[x] =", names[x])
|
|
|
|
gw := FindWindow(names[x])
|
2021-10-06 11:17:43 -05:00
|
|
|
if gw == nil {
|
2021-10-05 09:42:30 -05:00
|
|
|
return
|
|
|
|
}
|
2021-10-06 11:17:43 -05:00
|
|
|
if gw.UiTab == nil {
|
2021-10-05 09:42:30 -05:00
|
|
|
return
|
|
|
|
}
|
2021-10-06 11:17:43 -05:00
|
|
|
if gw.TabNumber == nil {
|
2021-10-05 09:42:30 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
gw.UiTab.Delete(*gw.TabNumber)
|
|
|
|
})
|
|
|
|
|
2021-10-06 13:23:00 -05:00
|
|
|
/////////////////////////////////////////////////////
|
|
|
|
vbox = addGroup(hbox, "Global Debug")
|
|
|
|
|
2021-10-07 01:37:37 -05:00
|
|
|
dump3 := addButton(vbox, "Dump Windows")
|
|
|
|
dump3.OnClicked(func(*ui.Button) {
|
|
|
|
DumpWindows()
|
|
|
|
})
|
|
|
|
|
2021-10-06 13:23:00 -05:00
|
|
|
dump2 := addButton(vbox, "Dump Boxes")
|
|
|
|
dump2.OnClicked(func(*ui.Button) {
|
|
|
|
DumpBoxes()
|
|
|
|
})
|
|
|
|
|
|
|
|
dump1 := addButton(vbox, "Dump MAP")
|
|
|
|
dump1.OnClicked(func(*ui.Button) {
|
|
|
|
DumpMap()
|
|
|
|
})
|
|
|
|
|
2021-10-09 02:37:14 -05:00
|
|
|
/////////////////////////////////////////////////////
|
|
|
|
nodeBox := addGroup(hbox, "range Data.NodeMap")
|
|
|
|
nodeCombo := ui.NewCombobox()
|
|
|
|
|
|
|
|
for name, node := range Data.NodeMap {
|
|
|
|
log.Println("range Data.NodeMap() name =", name)
|
|
|
|
addNodeName(nodeCombo, node.id)
|
|
|
|
}
|
|
|
|
nodeCombo.SetSelected(0)
|
|
|
|
|
|
|
|
nodeBox.Append(nodeCombo, false)
|
|
|
|
|
|
|
|
nodeCombo.OnSelected(func(*ui.Combobox) {
|
|
|
|
y := nodeCombo.Selected()
|
|
|
|
log.Println("y =", y)
|
|
|
|
log.Println("nodeNames[y] =", nodeNames[y])
|
|
|
|
node := Data.findId(nodeNames[y])
|
|
|
|
if (node != nil) {
|
|
|
|
node.Dump()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-10-07 21:31:15 -05:00
|
|
|
/////////////////////////////////////////////////////
|
|
|
|
vbox = addGroup(hbox, "Node Debug")
|
|
|
|
|
2021-10-09 03:04:15 -05:00
|
|
|
n1 := addButton(vbox, "Data.DumpNodeMap()")
|
2021-10-07 21:31:15 -05:00
|
|
|
n1.OnClicked(func(*ui.Button) {
|
2021-10-09 03:04:15 -05:00
|
|
|
Data.DumpNodeMap()
|
2021-10-07 21:31:15 -05:00
|
|
|
})
|
|
|
|
|
2021-10-09 05:31:59 -05:00
|
|
|
/*
|
2021-10-09 03:04:15 -05:00
|
|
|
n1 = addButton(vbox, "DebugDataNodeChildren()")
|
|
|
|
n1.OnClicked(func(*ui.Button) {
|
2021-10-07 21:56:16 -05:00
|
|
|
DebugDataNodeChildren()
|
|
|
|
})
|
2021-10-09 05:31:59 -05:00
|
|
|
*/
|
2021-10-07 21:56:16 -05:00
|
|
|
|
2021-10-09 03:04:15 -05:00
|
|
|
n1 = addButton(vbox, "Data.ListChildren(false)")
|
|
|
|
n1.OnClicked(func(*ui.Button) {
|
2021-10-09 02:37:14 -05:00
|
|
|
Data.ListChildren(false)
|
|
|
|
})
|
|
|
|
|
2021-10-09 03:04:15 -05:00
|
|
|
n1 = addButton(vbox, "Data.ListChildren(true)")
|
|
|
|
n1.OnClicked(func(*ui.Button) {
|
2021-10-09 02:37:14 -05:00
|
|
|
Data.ListChildren(true)
|
2021-10-07 21:31:15 -05:00
|
|
|
})
|
|
|
|
|
2021-10-09 10:46:57 -05:00
|
|
|
n1 = addButton(vbox, "Node.Dump()")
|
|
|
|
n1.OnClicked(func(*ui.Button) {
|
|
|
|
y := nodeCombo.Selected()
|
|
|
|
log.Println("y =", y)
|
|
|
|
log.Println("nodeNames[y] =", nodeNames[y])
|
|
|
|
node := Data.findId(nodeNames[y])
|
|
|
|
if (node != nil) {
|
|
|
|
node.Dump()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-10-09 03:04:15 -05:00
|
|
|
n1 = addButton(vbox, "Node.ListChildren(false)")
|
|
|
|
n1.OnClicked(func(*ui.Button) {
|
|
|
|
y := nodeCombo.Selected()
|
|
|
|
log.Println("y =", y)
|
|
|
|
log.Println("nodeNames[y] =", nodeNames[y])
|
|
|
|
node := Data.findId(nodeNames[y])
|
|
|
|
if (node != nil) {
|
|
|
|
node.ListChildren(false)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
n1 = addButton(vbox, "Node.ListChildren(true)")
|
|
|
|
n1.OnClicked(func(*ui.Button) {
|
|
|
|
y := nodeCombo.Selected()
|
|
|
|
log.Println("y =", y)
|
|
|
|
log.Println("nodeNames[y] =", nodeNames[y])
|
|
|
|
node := Data.findId(nodeNames[y])
|
|
|
|
if (node != nil) {
|
|
|
|
node.ListChildren(true)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-10-25 05:00:12 -05:00
|
|
|
n1 = addButton(vbox, "Node.AddDebugTab")
|
|
|
|
n1.OnClicked(func(*ui.Button) {
|
|
|
|
y := nodeCombo.Selected()
|
|
|
|
log.Println("y =", y)
|
|
|
|
log.Println("nodeNames[y] =", nodeNames[y])
|
|
|
|
node := Data.findId(nodeNames[y])
|
|
|
|
if (node != nil) {
|
|
|
|
node.AddDebugTab("added this DebugTab")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
n1 = addButton(vbox, "Node.DemoTab")
|
|
|
|
n1.OnClicked(func(*ui.Button) {
|
|
|
|
y := nodeCombo.Selected()
|
|
|
|
log.Println("y =", y)
|
|
|
|
log.Println("nodeNames[y] =", nodeNames[y])
|
|
|
|
node := Data.findId(nodeNames[y])
|
|
|
|
if (node != nil) {
|
|
|
|
node.AddDemoTab("added this DemoTab")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-10-07 21:31:15 -05:00
|
|
|
/*
|
2021-10-07 01:37:37 -05:00
|
|
|
/////////////////////////////////////////////////////
|
|
|
|
vbox = addGroup(hbox, "Numbers")
|
|
|
|
pbar := ui.NewProgressBar()
|
|
|
|
vbox.Append(pbar, false)
|
2021-10-07 21:31:15 -05:00
|
|
|
*/
|
2021-10-07 01:37:37 -05:00
|
|
|
|
|
|
|
|
2021-10-05 05:52:50 -05:00
|
|
|
return hbox
|
|
|
|
}
|
|
|
|
|
2021-10-09 02:37:14 -05:00
|
|
|
// TODO: remove this crap
|
2021-10-05 05:52:50 -05:00
|
|
|
var x int = 0
|
2021-10-09 02:37:14 -05:00
|
|
|
var y int = 0
|
2021-10-05 05:52:50 -05:00
|
|
|
|
2021-10-09 02:37:14 -05:00
|
|
|
// TODO: remove this crap
|
2021-10-05 05:52:50 -05:00
|
|
|
func addName(c *ui.Combobox, s string) {
|
|
|
|
c.Append(s)
|
|
|
|
names[x] = s
|
|
|
|
x = x + 1
|
|
|
|
}
|
2021-10-05 06:25:32 -05:00
|
|
|
|
2021-10-05 06:46:46 -05:00
|
|
|
func addGroup(b *ui.Box, name string) *ui.Box {
|
2021-10-05 06:25:32 -05:00
|
|
|
group := ui.NewGroup(name)
|
|
|
|
group.SetMargined(true)
|
2021-10-05 06:46:46 -05:00
|
|
|
b.Append(group, true)
|
2021-10-05 06:25:32 -05:00
|
|
|
|
|
|
|
vbox := ui.NewVerticalBox()
|
|
|
|
vbox.SetPadded(true)
|
|
|
|
group.SetChild(vbox)
|
|
|
|
|
|
|
|
return vbox
|
|
|
|
}
|
|
|
|
|
|
|
|
func dumpBox(s string) {
|
2021-10-09 10:46:57 -05:00
|
|
|
var name string
|
|
|
|
var window *GuiWindow
|
|
|
|
|
|
|
|
for name, window = range Data.WindowMap {
|
2021-10-06 11:17:43 -05:00
|
|
|
if name != s {
|
2021-10-05 06:25:32 -05:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
log.Println("gui.DumpBoxes() MAP: ", name)
|
2021-10-06 11:17:43 -05:00
|
|
|
if window.TabNumber == nil {
|
2021-10-05 06:25:32 -05:00
|
|
|
log.Println("gui.DumpBoxes() \tWindows.TabNumber = nil")
|
|
|
|
} else {
|
|
|
|
log.Println("gui.DumpBoxes() \tWindows.TabNumber =", *window.TabNumber)
|
|
|
|
}
|
|
|
|
log.Println("gui.DumpBoxes()\tWindow.name =", window.Name)
|
|
|
|
// log.Println("gui.DumpBoxes()\tWindow.UiWindow type =", reflect.TypeOf(window.UiWindow))
|
|
|
|
log.Println("gui.DumpBoxes()\tWindow.UiWindow =", window.UiWindow)
|
2021-10-05 07:13:24 -05:00
|
|
|
log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab)
|
2021-10-06 13:23:00 -05:00
|
|
|
log.Println("gui.dumpBox() BoxMap START")
|
2021-10-05 06:25:32 -05:00
|
|
|
for name, abox := range window.BoxMap {
|
|
|
|
log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name)
|
2021-10-09 10:46:57 -05:00
|
|
|
abox.Dump()
|
2021-10-06 11:17:43 -05:00
|
|
|
if name == "MAINBOX" {
|
|
|
|
if Config.Debug {
|
2021-10-05 06:25:32 -05:00
|
|
|
scs := spew.ConfigState{MaxDepth: 1}
|
|
|
|
scs.Dump(abox.UiBox)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-06 13:23:00 -05:00
|
|
|
log.Println("gui.dumpBox() BoxMap END")
|
2021-10-06 11:17:43 -05:00
|
|
|
if window.UiTab != nil {
|
2021-10-05 06:25:32 -05:00
|
|
|
pages := window.UiTab.NumPages()
|
|
|
|
log.Println("gui.DumpBoxes()\tWindow.UiTab.NumPages() =", pages)
|
|
|
|
tabSetMargined(window.UiTab)
|
2021-10-06 11:17:43 -05:00
|
|
|
if Config.Debug {
|
2021-10-05 06:25:32 -05:00
|
|
|
scs := spew.ConfigState{MaxDepth: 2}
|
|
|
|
scs.Dump(window.UiTab)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-05 06:46:46 -05:00
|
|
|
|
|
|
|
func addButton(box *ui.Box, name string) *ui.Button {
|
|
|
|
button := ui.NewButton(name)
|
|
|
|
|
|
|
|
button.OnClicked(func(*ui.Button) {
|
|
|
|
log.Println("Should do something here")
|
|
|
|
})
|
|
|
|
|
|
|
|
box.Append(button, false)
|
|
|
|
return button
|
|
|
|
}
|
2021-10-25 05:00:12 -05:00
|
|
|
|
|
|
|
func (n *Node) AddDebugTab(title string) {
|
|
|
|
newNode := n.AddTab(title, makeWindowDebug())
|
2021-10-25 05:25:10 -05:00
|
|
|
if (Config.DebugNode) {
|
|
|
|
newNode.Dump()
|
|
|
|
}
|
2021-10-25 05:00:12 -05:00
|
|
|
tabSetMargined(newNode.uiTab)
|
|
|
|
}
|
|
|
|
|
|
|
|
// This sets _all_ the tabs to Margin = true
|
|
|
|
//
|
|
|
|
// TODO: do proper tab tracking (will be complicated). low priority
|
|
|
|
func tabSetMargined(tab *ui.Tab) {
|
2021-10-25 05:25:10 -05:00
|
|
|
if (Config.DebugTabs) {
|
|
|
|
log.Println("tabSetMargined() IGNORE THIS")
|
|
|
|
}
|
2021-10-25 05:00:12 -05:00
|
|
|
c := tab.NumPages()
|
|
|
|
for i := 0; i < c; i++ {
|
2021-10-25 05:25:10 -05:00
|
|
|
if (Config.DebugTabs) {
|
|
|
|
log.Println("tabSetMargined() i =", i)
|
|
|
|
}
|
2021-10-25 05:00:12 -05:00
|
|
|
tab.SetMargined(i, true)
|
|
|
|
}
|
|
|
|
}
|