TABS: very reliable tab, window and node handling

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2021-11-01 03:44:39 -05:00
parent 934470d1a9
commit 9960652ec7
2 changed files with 22 additions and 26 deletions

View File

@ -12,7 +12,7 @@ import _ "github.com/andlabs/ui/winmanifest"
func (n *Node) NewLabel(text string) *Node { func (n *Node) NewLabel(text string) *Node {
// make new node here // make new node here
// n.Append(ui.NewLabel(text), false) // n.Append(ui.NewLabel(text), false)
newNode := makeNode(n, text, 333, 334) newNode := n.makeNode(text, 333, 334)
newNode.Dump() newNode.Dump()
// panic("node.NewLabel()") // panic("node.NewLabel()")

View File

@ -2,7 +2,7 @@ package gui
import ( import (
"log" "log"
"fmt" // "fmt"
"strconv" "strconv"
"github.com/andlabs/ui" "github.com/andlabs/ui"
@ -21,7 +21,7 @@ func (n *Node) ErrorWindow2(msg1 string, msg2 string) (*Node) {
return n return n
} }
func makeNode(parent *Node, title string, x int, y int) *Node { func initNode(title string, x int, y int) *Node {
var node Node var node Node
node.Name = title node.Name = title
node.Width = x node.Width = x
@ -31,26 +31,18 @@ func makeNode(parent *Node, title string, x int, y int) *Node {
Config.counter += 1 Config.counter += 1
node.id = id node.id = id
// panic("gui.makeNode() START") if (Data.NodeMap[title] != nil) {
if (parent == nil) { log.Println("Duplicate window name =", title)
if (Data.NodeMap[title] != nil) { // TODO: just change the 'title' to something unique
log.Println("Duplicate window name =", title) // panic(fmt.Sprintf("Duplicate window name = %s\n", title))
// TODO: just change the 'title' to something unique return Data.NodeMap[title]
panic(fmt.Sprintf("Duplicate window name = %s\n", title))
return nil
}
// panic("gui.makeNode() before NodeMap()")
Data.NodeMap[title] = &node
Data.NodeArray = append(Data.NodeArray, &node)
Data.NodeSlice = append(Data.NodeSlice, &node)
// panic("gui.makeNode() after NodeMap()")
return &node
} else {
// panic("gui.makeNode() before Append()")
parent.Append(&node)
// panic("gui.makeNode() after Append()")
} }
node.parent = parent Data.NodeMap[title] = &node
Data.NodeArray = append(Data.NodeArray, &node)
Data.NodeSlice = append(Data.NodeSlice, &node)
return &node
// parent.Append(&node)
//node.parent = parent
return &node return &node
} }
@ -104,6 +96,7 @@ func (n *Node) uiNewWindow(title string, x int, y int) {
return return
} }
/*
func mapWindow(parent *Node, window *ui.Window, title string, x int, y int) *Node { func mapWindow(parent *Node, window *ui.Window, title string, x int, y int) *Node {
log.Println("gui.WindowMap START title =", title) log.Println("gui.WindowMap START title =", title)
@ -112,6 +105,7 @@ func mapWindow(parent *Node, window *ui.Window, title string, x int, y int) *Nod
return node return node
} }
*/
// This routine creates a blank window with a Title and size (W x H) // This routine creates a blank window with a Title and size (W x H)
// //
@ -124,11 +118,13 @@ func NewWindow() *Node {
w := Config.Width w := Config.Width
h := Config.Height h := Config.Height
var n *Node if (Data.NodeMap[title] != nil) {
n = mapWindow(nil, nil, title, w, h) log.Println("Duplicate window name =", title)
// box := n.box return Data.NodeMap[title]
// log.Println("gui.NewWindow() title = box.Name =", box.Name) }
var n *Node
n = initNode(title, w, h)
n.uiNewWindow(title, w, h) n.uiNewWindow(title, w, h)
window := n.uiWindow window := n.uiWindow