REORG: move find() functions into find.go

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2021-10-25 06:46:49 -05:00
parent 76b371b375
commit 3fa94aeb01
3 changed files with 80 additions and 97 deletions

View File

@ -2,7 +2,6 @@ package gui
import ( import (
"fmt" "fmt"
"os"
"log" "log"
"time" "time"
@ -145,29 +144,6 @@ func DebugDataNodeChildren() {
} }
*/ */
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 (dn *GuiData) ListChildren(dump bool) { func (dn *GuiData) ListChildren(dump bool) {
if Data.NodeMap == nil { if Data.NodeMap == nil {
log.Println("gui.Data.ListChildren() Data.NodeMap == nil") log.Println("gui.Data.ListChildren() Data.NodeMap == nil")
@ -182,38 +158,3 @@ func (dn *GuiData) ListChildren(dump bool) {
node.ListChildren(dump) node.ListChildren(dump)
} }
} }
func (dn *GuiData) findId(id string) *Node {
if Data.NodeMap == nil {
log.Println("gui.Data.findId() map == nil")
return nil
}
// log.Println("Dumping Data.NodeMap:")
for name, node := range Data.NodeMap {
// log.Println("\tData.NodeMap name =", node.id, node.Width, node.Height, name)
if (id == node.id) {
log.Println("\tgui.Data.findId() found node =", node.id, node.Width, node.Height, name)
return node
}
// TODO: fix // Oct 9
// node.findId(id)
}
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.id, node.Width, node.Height, name)
// node.Dump()
node.ListChildren()
// node.SetName("yahoo")
// log.Println("\tData.NodeMap node =", node)
}
}
*/

80
find.go
View File

@ -2,6 +2,7 @@ package gui
import ( import (
"log" "log"
"os"
// "github.com/andlabs/ui" // "github.com/andlabs/ui"
// _ "github.com/andlabs/ui/winmanifest" // _ "github.com/andlabs/ui/winmanifest"
@ -33,3 +34,82 @@ func FindBox(s string) *GuiBox {
log.Println("gui.FindBox() COULD NOT FIND BOX", s) log.Println("gui.FindBox() COULD NOT FIND BOX", s)
return nil return nil
} }
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 (dn *GuiData) findId(id string) *Node {
if Data.NodeMap == nil {
log.Println("gui.Data.findId() map == nil")
return nil
}
// log.Println("Dumping Data.NodeMap:")
for name, node := range Data.NodeMap {
// log.Println("\tData.NodeMap name =", node.id, node.Width, node.Height, name)
if (id == node.id) {
log.Println("\tgui.Data.findId() found node =", node.id, node.Width, node.Height, name)
return node
}
// TODO: fix // Oct 9
// node.findId(id)
}
return nil
}
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
}
if len(node.children) > 0 {
for _, child := range node.children {
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
}

View File

@ -177,44 +177,6 @@ func (n *Node) ListChildren(dump bool) {
return return
} }
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
}
if len(node.children) > 0 {
for _, child := range node.children {
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
}
// The parent Node needs to be the raw Window // The parent Node needs to be the raw Window
// The 'stuff' Node needs to be the contents of the tab // The 'stuff' Node needs to be the contents of the tab
// //