NODE: continued work on implementing a node tree

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2021-10-07 12:04:48 -05:00
parent b288902b1c
commit 189d31bb33
6 changed files with 189 additions and 45 deletions

2
box.go
View File

@ -69,9 +69,9 @@ func NewBox(box *GuiBox, axis int, name string) *GuiBox {
n := box.FindNode()
if (n == nil) {
log.Println("gui.NewBox() SERIOUS ERROR. CAN NOT FIND NODE")
os.Exit(0)
} else {
log.Println("gui.NewBox() node =", n.Name)
os.Exit(0)
}
var newbox *GuiBox
newbox = new(GuiBox)

View File

@ -2,6 +2,7 @@ package gui
import (
"fmt"
"os"
"log"
"time"
@ -112,3 +113,54 @@ func addTableTab() {
log.Println("Sleep for 1 second, then try to add new tabs")
time.Sleep(1 * time.Second)
}
func DebugDataNodeMap() {
if Data.NodeMap == nil {
log.Println("Data.NodeMap == nil")
return
}
log.Println("Dumping Data.NodeMap:")
for name, node := range Data.NodeMap {
log.Println("\tData.NodeMap name =", node.Width, node.Height, name)
// node.SetName("yahoo")
// log.Println("\tData.NodeMap node =", node)
}
}
func FindNode(name string) *Node {
if Data.NodeMap == nil {
log.Println("gui.FindNode() gui.Data.NodeMap == nil")
return nil
}
log.Println("gui.FindNode() searching Data.NodeMap:")
for id, node := range Data.NodeMap {
log.Println("\tData.NodeMap name =", node.Width, node.Height, id)
node.Dump()
if (name == node.Name) {
return node
}
newNode := findByName(node, name)
if (newNode != nil) {
return newNode
}
log.Println("gui.FindNode() could not find node name =", name)
os.Exit(-1)
}
log.Println("gui.FindNode() could not find node name =", name)
return nil
}
func DebugNodeChildren() {
if Data.NodeMap == nil {
log.Println("Data.NodeMap == nil")
return
}
log.Println("Dumping Data.NodeMap:")
for name, node := range Data.NodeMap {
log.Println("\tData.NodeMap name =", node.Width, node.Height, name)
node.Dump()
node.List()
// node.SetName("yahoo")
// log.Println("\tData.NodeMap node =", node)
}
}

View File

@ -8,6 +8,10 @@ import (
)
func Main(f func()) {
log.Println("Starting gui.Main() (using gtk via andlabs/ui)")
log.Println("Starting gui.Main() (using gtk via andlabs/ui)")
log.Println("Starting gui.Main() (using gtk via andlabs/ui)")
log.Println("Starting gui.Main() (using gtk via andlabs/ui)")
log.Println("Starting gui.Main() (using gtk via andlabs/ui)")
ui.Main(f)
}

View File

@ -21,8 +21,9 @@ type Node struct {
box *GuiBox
control *ui.Control
window *ui.Window
uiControl *ui.Control
uiWindow *ui.Window
uiTab *ui.Tab
}
func (n *Node) Parent() *Node {
@ -34,44 +35,50 @@ func (n *Node) Window() *Node {
}
func (n *Node) Dump() {
log.Println("gui.Node.Dump() id = ", n.id)
log.Println("gui.Node.Dump() Name = ", n.Name)
log.Println("gui.Node.Dump() Width = ", n.Width)
log.Println("gui.Node.Dump() Height = ", n.Height)
log.Println("gui.Node.Dump() parent = ", n.parent)
log.Println("gui.Node.Dump() children = ", n.children)
log.Println("gui.Node.Dump() box = ", n.box)
log.Println("gui.Node.Dump() control = ", n.control)
log.Println("gui.Node.Dump() window = ", n.window)
log.Println("gui.Node.Dump() id = ", n.id)
log.Println("gui.Node.Dump() Name = ", n.Name)
log.Println("gui.Node.Dump() Width = ", n.Width)
log.Println("gui.Node.Dump() Height = ", n.Height)
log.Println("gui.Node.Dump() parent = ", n.parent)
log.Println("gui.Node.Dump() children = ", n.children)
log.Println("gui.Node.Dump() box = ", n.box)
log.Println("gui.Node.Dump() uiControl = ", n.uiControl)
log.Println("gui.Node.Dump() uiWindow = ", n.uiWindow)
log.Println("gui.Node.Dump() uiTab = ", n.uiTab)
}
func (n *Node) SetName(name string) {
// n.uiType.SetName(name)
if (n.window != nil) {
if (n.uiWindow != nil) {
log.Println("node is a window. setting title =", name)
n.window.SetTitle(name)
n.uiWindow.SetTitle(name)
return
}
log.Println("*ui.Control =", n.control)
log.Println("*ui.Control =", n.uiControl)
return
}
func (n *Node) FindTab() *ui.Tab {
return n.uiTab
}
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)
}
return n.box
}
func (n *Node) Append(child Node) {
func (n *Node) Append(child *Node) {
// if (n.UiBox == nil) {
// return
// }
// n.uiType.Append(child, x)
n.children = append(n.children, child)
}
func (n *Node) List() {
findByIdDFS(n, "test")
@ -79,6 +86,7 @@ func (n *Node) List() {
func findByIdDFS(node *Node, id string) *Node {
log.Println("findByIdDFS()", id, node)
node.Dump()
if node.id == id {
log.Println("Found node id =", id, node)
return node
@ -86,46 +94,64 @@ func findByIdDFS(node *Node, id string) *Node {
if len(node.children) > 0 {
for _, child := range node.children {
findByIdDFS(child, id)
newNode := findByIdDFS(child, id)
if (newNode != nil) {
return newNode
}
}
}
return nil
}
func findByName(node *Node, name string) *Node {
log.Println("findByName()", name, node)
node.Dump()
if node.Name == name {
log.Println("findByName() Found node name =", name, node)
return node
}
if len(node.children) > 0 {
for _, child := range node.children {
newNode := findByName(child, name)
if (newNode != nil) {
return newNode
}
}
}
return nil
}
func (n *Node) InitTab(title string, custom func() ui.Control) *Node {
boxs := n.box
if boxs == nil {
log.Println("gui.InitTab() 1 Fuck node = ", n)
if n.uiWindow == nil {
log.Println("gui.InitTab() ERROR ui.Window == nil")
n.Dump()
os.Exit(-1)
}
if boxs.Window == nil {
log.Println("gui.InitTab() 2 Fuck node = ", n)
if n.box != nil {
log.Println("gui.InitTab() ERROR box already exists")
n.Dump()
os.Exit(-1)
return nil
}
if boxs.Window.UiWindow == nil {
log.Println("gui.InitTab() 3 Fuck node = ", n)
n.Dump()
os.Exit(-1)
return nil
}
window := boxs.Window.UiWindow
tab := ui.NewTab()
window.SetChild(tab)
window.SetMargined(true)
n.uiWindow.SetChild(tab)
n.uiWindow.SetMargined(true)
tab.Append(title, custom())
tab.SetMargined(0, true)
// tab.SetMargined(1, true)
boxs.Window.UiTab = tab
var newNode Node
newNode.Name = title
newNode.parent = n
n.Append(&newNode)
newNode.uiTab = tab
/*
if boxs.node == nil {
log.Println("gui.InitTab() 4 Fuck node = ", n)
n.Dump()
os.Exit(-1)
}
return n
*/
return &newNode
}

View File

@ -3,6 +3,7 @@ package gui
import (
"image/color"
"log"
"os"
"github.com/andlabs/ui"
"golang.org/x/image/font"
@ -24,6 +25,8 @@ type GuiConfig struct {
Debug bool
DebugTable bool
Exit func(*GuiWindow)
depth int
}
type GuiData struct {
@ -107,6 +110,14 @@ type GuiBox struct {
UiBox *ui.Box
}
func (gb *GuiBox) Dump() {
log.Println("gui.GuiBox.Dump() Name = ", gb.Name)
log.Println("gui.GuiBox.Dump() Axis = ", gb.Axis)
log.Println("gui.GuiBox.Dump() GuiWindow = ", gb.Window)
log.Println("gui.GuiBox.Dump() node = ", gb.node)
log.Println("gui.GuiBox.Dump() UiBox = ", gb.UiBox)
}
func (s GuiBox) SetTitle(title string) {
log.Println("DID IT!", title)
if s.Window == nil {
@ -119,10 +130,30 @@ func (s GuiBox) SetTitle(title string) {
return
}
func (s GuiBox) FindNode() *Node {
if s.node != nil {
return s.node
func (b *GuiBox) SetNode(n *Node) {
if (b.node != nil) {
b.Dump()
log.Println("gui.SetNode() Error not nil")
os.Exit(-1)
}
b.node = n
if (b.node == nil) {
b.Dump()
log.Println("gui.SetNode() node == nil")
os.Exit(-1)
}
b.Dump()
}
func (b *GuiBox) FindNode() *Node {
log.Println("gui.FindNode() on GuiBox")
if b.node != nil {
return b.node
}
DebugNodeChildren()
b.Dump()
log.Println("gui.FindNode() on GuiBox is nil")
os.Exit(-1)
return nil
}
@ -194,6 +225,8 @@ func (s GuiBox) AddDebugTab(title string) {
}
func tabSetMargined(tab *ui.Tab) {
log.Println("tabSetMargined() IGNORE THIS")
return
c := tab.NumPages()
for i := 0; i < c; i++ {
log.Println("tabSetMargined() i =", i)

View File

@ -2,6 +2,7 @@ package gui
import (
"log"
"os"
"strconv"
"time"
@ -50,7 +51,7 @@ func ErrorWindow(gw *GuiWindow, msg1 string, msg2 string) {
// actual window but that does not appear to work on the MacOS or Windows
//
func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox {
log.Println("InitGuiWindow() START")
log.Println("InitWindow() START")
var box *GuiBox
if gw == nil {
@ -67,8 +68,12 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox {
log.Println("initWindow() ADDING ui.NewWindow()")
n := uiNewWindow(name, Config.Height, Config.Width)
box.node = n
w := n.window
if (n.box == nil) {
n.box = box
}
w := n.uiWindow
newGuiWindow.UiWindow = w
os.Exit(-1)
// newGuiWindow.UiWindow.SetTitle("test")
w.OnClosing(func(*ui.Window) bool {
@ -107,7 +112,31 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox {
Data.WindowMap[newGuiWindow.Name] = newGuiWindow
log.Println("InitGuiWindow() END *GuiWindow =", newGuiWindow)
if (box.node == nil) {
fn := FindNode("full initTab")
log.Println("InitWindow() fn =", fn)
log.Println("InitWindow() mapping node <=> box")
box.node = fn
if (fn.box == nil) {
log.Println("InitWindow() mapping node <=> box")
fn.box = box
}
}
if (box.node == nil) {
DebugNodeChildren()
log.Println("InitWindow() box has a FUCKING nil node")
fn := FindNode("full initTab")
log.Println("InitWindow() fn =", fn)
os.Exit(-1)
}
if (newGuiWindow.node == nil) {
DebugNodeChildren()
log.Println("InitWindow() newGuiWindow has a FUCKING nil node")
// os.Exit(-1)
}
log.Println("InitWindow() END *GuiWindow =", newGuiWindow)
return box
}
@ -178,7 +207,7 @@ func uiNewWindow(title string, x int, y int) *Node {
})
w.SetMargined(true)
w.Show()
node.window = w
node.uiWindow = w
// w.node = &node
return &node
}
@ -190,7 +219,7 @@ func CreateBlankWindow(title string, x int, y int) *Node {
n := uiNewWindow(box.Name, x, y)
box.node = n
n.box = box
window := n.window
window := n.uiWindow
ui.OnShouldQuit(func() bool {
log.Println("createWindow().Destroy()", box.Name)
@ -251,7 +280,7 @@ func NewWindow(title string, x int, y int) *GuiBox {
n := uiNewWindow(box.Name, x, y)
box.node = n
window := n.window
window := n.uiWindow
ui.OnShouldQuit(func() bool {
log.Println("createWindow().Destroy()", box.Name)