NODE: going down a rabbit hole

This commit is contained in:
Jeff Carr 2021-10-08 07:36:53 -05:00
parent f83ab4577d
commit 3cdc585913
9 changed files with 155 additions and 70 deletions

4
box.go
View File

@ -93,6 +93,10 @@ func NewBox(box *GuiBox, axis int, name string) *GuiBox {
func HardBox(gw *GuiWindow, axis int, name string) *GuiBox {
log.Println("HardBox() START axis =", axis)
if (gw.node == nil) {
gw.Dump()
panic("gui.HardBox() gw.node == nil")
}
// add a Vertical Seperator if there is already a box
// Is this right?
box := gw.BoxMap["MAINBOX"]

View File

@ -178,7 +178,7 @@ func DebugNodeChildren() {
}
log.Println("Dumping Data.NodeMap:")
for name, node := range Data.NodeMap {
log.Println("\tData.NodeMap name =", node.Width, node.Height, name)
log.Println("\tData.NodeMap name =", node.id, node.Width, node.Height, name)
// node.Dump()
node.ListChildren()
// node.SetName("yahoo")

2
gui.go
View File

@ -19,6 +19,8 @@ func init() {
Data.buttonMap = make(map[*ui.Button]*GuiButton)
Data.WindowMap = make(map[string]*GuiWindow)
Data.NodeMap = make(map[string]*Node)
Config.counter = 0
}
func GuiInit() {

View File

@ -31,7 +31,8 @@ func ExampleWindow() {
log.Println("START gui.ExampleWindow()")
title := "Test Window"
box := InitWindow(nil, title, 0)
node := InitWindow(nil, nil, title, 0)
box := node.box
window := box.Window
log.Println("box =", box)
log.Println("window =", window)
@ -44,7 +45,8 @@ func DebugWindow() {
log.Println("START gui.ExampleWindow()")
title := "Debug Window"
box := InitWindow(nil, title, 0)
node := InitWindow(nil, nil, title, 0)
box := node.box
window := box.Window
log.Println("box =", box)
log.Println("window =", window)

View File

@ -2,7 +2,9 @@ package gui
import (
"log"
"os"
"time"
// "github.com/davecgh/go-spew/spew"
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
@ -45,6 +47,9 @@ func (n *Node) Dump() {
log.Println("gui.Node.Dump() uiControl = ", n.uiControl)
log.Println("gui.Node.Dump() uiWindow = ", n.uiWindow)
log.Println("gui.Node.Dump() uiTab = ", n.uiTab)
if (n.id == "") {
panic("gui.Node.Dump() id == nil")
}
}
@ -63,13 +68,13 @@ func (n *Node) FindTab() *ui.Tab {
return n.uiTab
}
func (n *Node) FindBox() *GuiBox {
return n.box
}
func (n *Node) FindWindowBox() *GuiBox {
if (n.box == nil) {
log.Println("SERIOUS ERROR n.box == nil in FindWindowBox()")
log.Println("SERIOUS ERROR n.box == nil in FindWindowBox()")
log.Println("SERIOUS ERROR n.box == nil in FindWindowBox()")
log.Println("SERIOUS ERROR n.box == nil in FindWindowBox()")
os.Exit(-1)
panic("SERIOUS ERROR n.box == nil in FindWindowBox()")
}
return n.box
}
@ -79,6 +84,11 @@ func (n *Node) Append(child *Node) {
// return
// }
n.children = append(n.children, child)
log.Println("child node:")
child.Dump()
log.Println("parent node:")
n.Dump()
time.Sleep(3 * time.Second)
}
func (n *Node) List() {
@ -86,20 +96,28 @@ func (n *Node) List() {
}
func (n *Node) ListChildren() {
log.Println("gui.Node.ListChildren() node =", n.Name, n)
log.Println("\tListChildren() node =", n.id, n.Name, n.Width, n.Height)
if len(n.children) == 0 {
log.Println("\t\t\tparent =",n.parent.id)
log.Println("\t\tNo children START")
return
}
// if len(n.children) > 0 {
// spew.Dump(n)
for _, child := range n.children {
log.Println("gui.Node.ListChildren() child =", child.Name, child)
if (child.children == nil) {
log.Println("\t\tNo children END")
break
log.Println("\t\tListChildren() child =",child.id, child.Name, child.Width, child.Height)
if (child.parent != nil) {
log.Println("\t\t\tparent =",child.parent.id)
} else {
log.Println("\t\t\tno parent")
panic("no parent")
}
log.Println("\t\tHas children:", child.children)
// child.Dump()
if (child.children == nil) {
log.Println("\t\t\tNo children END")
// break
}
log.Println("\t\t\tHas children:", child.children)
child.ListChildren()
}
return
@ -145,14 +163,12 @@ func findByName(node *Node, name string) *Node {
func (n *Node) InitTab(title string, custom func() ui.Control) *Node {
if n.uiWindow == nil {
log.Println("gui.InitTab() ERROR ui.Window == nil")
n.Dump()
os.Exit(-1)
panic("gui.InitTab() ERROR ui.Window == nil")
}
if n.box != nil {
log.Println("gui.InitTab() ERROR box already exists title =", title)
if n.box == nil {
n.Dump()
// os.Exit(-1)
panic("gui.InitTab() ERROR box == nil")
}
tab := ui.NewTab()
@ -162,17 +178,7 @@ func (n *Node) InitTab(title string, custom func() ui.Control) *Node {
tab.Append(title, custom())
tab.SetMargined(0, true)
var newNode Node
newNode.Name = title
newNode.parent = n
n.Append(&newNode)
newNode := makeNode(n, title, 555, 666)
newNode.uiTab = tab
/*
if boxs.node == nil {
log.Println("gui.InitTab() 4 Fuck node = ", n)
n.Dump()
os.Exit(-1)
}
*/
return &newNode
return newNode
}

View File

@ -27,6 +27,7 @@ type GuiConfig struct {
Exit func(*GuiWindow)
depth int
counter int // used to make unique ID's
}
type GuiData struct {
@ -97,6 +98,13 @@ type GuiWindow struct {
UiTab *ui.Tab // if this != nil, the window is 'tabbed'
}
func (gw *GuiWindow) Dump() {
log.Println("gui.GuiWindow.Dump() Name = ", gw.Name)
log.Println("gui.GuiWindow.Dump() node = ", gw.node)
log.Println("gui.GuiWindow.Dump() Width = ", gw.Width)
log.Println("gui.GuiWindow.Dump() Height = ", gw.Height)
}
// GuiBox is any type of ui.Hbox or ui.Vbox
// There can be lots of these for each GuiWindow
type GuiBox struct {
@ -130,19 +138,32 @@ func (s GuiBox) SetTitle(title string) {
return
}
func (w *GuiWindow) SetNode(n *Node) {
if (w.node != nil) {
w.Dump()
panic("gui.SetNode() Error not nil")
}
w.node = n
if (w.node == nil) {
w.Dump()
panic("gui.SetNode() node == nil")
}
}
func (b *GuiBox) SetNode(n *Node) {
if (b.node != nil) {
b.Dump()
log.Println("gui.SetNode() Error not nil")
os.Exit(-1)
panic("gui.SetNode() Error not nil")
}
b.node = n
if (b.node == nil) {
b.Dump()
log.Println("gui.SetNode() node == nil")
os.Exit(-1)
panic("gui.SetNode() node == nil")
}
b.Dump()
}
func (w *GuiWindow) FindNode() *Node {
return w.node
}
func (b *GuiBox) FindNode() *Node {

View File

@ -98,9 +98,9 @@ func InitColumns(mh *TableData, parts []TableColumnData) {
}
func AddTableTab(gw *GuiWindow, name string, rowcount int, parts []TableColumnData) *TableData {
box := InitWindow(gw, name, Yaxis)
node := InitWindow(nil, gw, name, Yaxis)
return AddTableBox(box, name, rowcount, parts)
return AddTableBox(node.box, name, rowcount, parts)
}
func AddTableBox(box *GuiBox, name string, rowcount int, parts []TableColumnData) *TableData {

View File

@ -145,7 +145,7 @@ func makeWindowDebug() ui.Control {
DebugDataNodeChildren()
})
n3 := addButton(vbox, "DebugNodeChildren()")
n3 := addButton(vbox, "Node.ListChildren()")
n3.OnClicked(func(*ui.Button) {
DebugNodeChildren()
})

108
window.go
View File

@ -2,7 +2,6 @@ package gui
import (
"log"
"os"
"strconv"
"time"
@ -17,7 +16,8 @@ func initUI(name string, callback func(*GuiBox) *GuiBox) {
ui.Main(func() {
log.Println("gui.initUI() inside ui.Main()")
box := InitWindow(nil, "StartNewWindow"+name, 0)
node := InitWindow(nil, nil, "StartNewWindow"+name, 0)
box := node.box
box = callback(box)
window := box.Window
log.Println("StartNewWindow() box =", box)
@ -50,14 +50,18 @@ func ErrorWindow(gw *GuiWindow, msg1 string, msg2 string) {
// This is this way because on Linux you can have more than one
// actual window but that does not appear to work on the MacOS or Windows
//
func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox {
func InitWindow(parent *Node, gw *GuiWindow, name string, axis int) *Node {
log.Println("gui.InitWindow() START")
var box *GuiBox
var node *Node
if gw == nil {
box = mapWindow(nil, name, Config.Width, Config.Height)
node = mapWindow(parent, nil, name, Config.Width, Config.Height)
box = node.box
} else {
box = mapWindow(gw.UiWindow, name, Config.Width, Config.Height)
node = mapWindow(parent, gw.UiWindow, name, Config.Width, Config.Height)
box = node.box
}
// box.Window = &newGuiWindow
@ -66,12 +70,12 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox {
// This is the first window. One must create it here
if gw == nil {
log.Println("gui.initWindow() ADDING ui.NewWindow()")
n := uiNewWindow(name, Config.Width, Config.Height)
box.node = n
if (n.box == nil) {
n.box = box
node = uiNewWindow(node, name, Config.Width, Config.Height)
box.node = node
if (node.box == nil) {
node.box = box
}
w := n.uiWindow
w := node.uiWindow
newGuiWindow.UiWindow = w
// newGuiWindow.UiWindow.SetTitle("test")
@ -126,17 +130,36 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox {
log.Println("InitWindow() box has a FUCKING nil node")
fn := FindNode("full initTab")
log.Println("InitWindow() fn =", fn)
os.Exit(-1)
panic(-1)
}
if (newGuiWindow.node == nil) {
DebugNodeChildren()
log.Println("InitWindow() newGuiWindow has a FUCKING nil node")
// os.Exit(-1)
// panic(-1)
}
log.Println("InitWindow() END *GuiWindow =", newGuiWindow)
return box
if (box.node == nil) {
box.Dump()
panic(-1)
}
box.Dump()
box.node.Dump()
if (box.node != node) {
log.Println("InitWindow() box.node != node. Hmmm....")
log.Println("InitWindow() box.node != node. Hmmm....")
log.Println("InitWindow() box.node != node. Hmmm....")
panic(-1)
}
if (node.box != box) {
log.Println("InitWindow() node.box != box. Hmmm....")
log.Println("InitWindow() node.box != box. Hmmm....")
log.Println("InitWindow() node.box != box. Hmmm....")
panic(-1)
}
// panic("InitWindow")
return node
}
func DeleteWindow(name string) {
@ -186,17 +209,40 @@ func CreateWindow(title string, tabname string, x int, y int, custom func() ui.C
return n
}
func uiNewWindow(title string, x int, y int) *Node {
//
// Create a new node
// if parent == nil, that means it is a new window and needs to be put
// in the window map (aka Data.NodeMap)
//
func makeNode(parent *Node, title string, x int, y int) *Node {
var node Node
node.Name = title
node.Width = x
node.Height = y
if (Data.NodeMap[title] != nil) {
log.Println("Duplicate uiNewWindow() name =", title)
// TODO: just change the 'title' to something unique
return nil
id := "jwc" + strconv.Itoa(Config.counter)
Config.counter += 1
node.id = id
if (parent == nil) {
if (Data.NodeMap[title] != nil) {
log.Println("Duplicate uiNewWindow() name =", title)
// TODO: just change the 'title' to something unique
return nil
}
Data.NodeMap[title] = &node
return &node
} else {
parent.Append(&node)
}
node.parent = parent
return &node
}
func uiNewWindow(node *Node, title string, x int, y int) *Node {
if (node == nil) {
node = makeNode(nil, title, x, y)
}
Data.NodeMap[title] = &node
w := ui.NewWindow(title, x, y, false)
w.SetBorderless(false)
@ -208,16 +254,15 @@ func uiNewWindow(title string, x int, y int) *Node {
w.Show()
node.uiWindow = w
// w.node = &node
return &node
return node
}
func CreateBlankWindow(title string, x int, y int) *Node {
box := mapWindow(nil, title, x, y)
n := mapWindow(nil, nil, title, x, y)
box := n.box
log.Println("gui.CreateBlankWindow() title = box.Name =", box.Name)
n := uiNewWindow(box.Name, x, y)
box.node = n
n.box = box
n = uiNewWindow(n, box.Name, x, y)
window := n.uiWindow
ui.OnShouldQuit(func() bool {
@ -239,7 +284,7 @@ func InitBlankWindow() ui.Control {
var master = 0
func mapWindow(window *ui.Window, title string, x int, y int) *GuiBox {
func mapWindow(parent *Node, window *ui.Window, title string, x int, y int) *Node {
log.Println("gui.WindowMap START title =", title)
if Data.WindowMap[title] != nil {
log.Println("Data.WindowMap[title] already exists title =", title)
@ -268,17 +313,22 @@ func mapWindow(window *ui.Window, title string, x int, y int) *GuiBox {
box.Window = &newGuiWindow
box.Name = title
// func makeNode(parent *Node, title string, x int, y int) *Node {
node := makeNode(parent, title, x, y)
node.box = &box
box.node = node
newGuiWindow.BoxMap["jcarrInitTest"] = &box
return &box
return node
}
func NewWindow(title string, x int, y int) *GuiBox {
box := mapWindow(nil, title, x, y)
n := mapWindow(nil, nil, title, x, y)
box := n.box
log.Println("gui.NewWindow() title = box.Name =", box.Name)
n := uiNewWindow(box.Name, x, y)
box.node = n
n = uiNewWindow(n, box.Name, x, y)
window := n.uiWindow
ui.OnShouldQuit(func() bool {