NODE: walking around in the rabbit hole
This commit is contained in:
parent
043c5d7fcb
commit
3d6e0e5518
1
gui.go
1
gui.go
|
@ -21,6 +21,7 @@ func init() {
|
||||||
Data.NodeMap = make(map[string]*Node)
|
Data.NodeMap = make(map[string]*Node)
|
||||||
|
|
||||||
Config.counter = 0
|
Config.counter = 0
|
||||||
|
Config.prefix = "jwc"
|
||||||
}
|
}
|
||||||
|
|
||||||
func GuiInit() {
|
func GuiInit() {
|
||||||
|
|
|
@ -10,7 +10,33 @@ import (
|
||||||
_ "github.com/andlabs/ui/winmanifest"
|
_ "github.com/andlabs/ui/winmanifest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Element int
|
||||||
|
|
||||||
// https://ieftimov.com/post/golang-datastructures-trees/
|
// https://ieftimov.com/post/golang-datastructures-trees/
|
||||||
|
const (
|
||||||
|
Unknown Element = iota
|
||||||
|
Window
|
||||||
|
Tab
|
||||||
|
Box
|
||||||
|
Label
|
||||||
|
Combo
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s Element) String() string {
|
||||||
|
switch s {
|
||||||
|
case Window:
|
||||||
|
return "window"
|
||||||
|
case Tab:
|
||||||
|
return "tab"
|
||||||
|
case Box:
|
||||||
|
return "box"
|
||||||
|
case Label:
|
||||||
|
return "label"
|
||||||
|
case Combo:
|
||||||
|
return "combo"
|
||||||
|
}
|
||||||
|
return "unknown"
|
||||||
|
}
|
||||||
|
|
||||||
type Node struct {
|
type Node struct {
|
||||||
id string
|
id string
|
||||||
|
@ -120,16 +146,14 @@ func (n *Node) ListChildren(dump bool) {
|
||||||
log.Println("\t\t\tno parent")
|
log.Println("\t\t\tno parent")
|
||||||
panic("no parent")
|
panic("no parent")
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
if (dump == true) {
|
if (dump == true) {
|
||||||
child.Dump()
|
child.Dump()
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
if (child.children == nil) {
|
if (child.children == nil) {
|
||||||
log.Println("\t\t", child.id, "has no children")
|
log.Println("\t\t", child.id, "has no children")
|
||||||
break
|
} else {
|
||||||
}
|
|
||||||
log.Println("\t\t\tHas children:", child.children)
|
log.Println("\t\t\tHas children:", child.children)
|
||||||
|
}
|
||||||
child.ListChildren(dump)
|
child.ListChildren(dump)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -173,45 +197,56 @@ func findByName(node *Node, name string) *Node {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) InitTab(title string) *Node {
|
/*
|
||||||
if n.uiWindow == nil {
|
func (parent *Node) InitTab(title string) *Node {
|
||||||
n.Dump()
|
if parent.uiWindow == nil {
|
||||||
|
parent.Dump()
|
||||||
panic("gui.InitTab() ERROR ui.Window == nil")
|
panic("gui.InitTab() ERROR ui.Window == nil")
|
||||||
}
|
}
|
||||||
if n.box == nil {
|
if parent.box == nil {
|
||||||
n.Dump()
|
parent.Dump()
|
||||||
panic("gui.InitTab() ERROR box == nil")
|
panic("gui.InitTab() ERROR box == nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
tab := ui.NewTab()
|
tab := ui.NewTab()
|
||||||
n.uiWindow.SetChild(tab)
|
parent.uiWindow.SetChild(tab)
|
||||||
n.uiWindow.SetMargined(true)
|
parent.uiWindow.SetMargined(true)
|
||||||
|
parent.uiTab = tab
|
||||||
|
|
||||||
tab.Append(title, initBlankWindow())
|
tab.Append(title, initBlankWindow())
|
||||||
tab.SetMargined(0, true)
|
tab.SetMargined(0, true)
|
||||||
|
|
||||||
newNode := makeNode(n, title, 555, 600 + Config.counter)
|
newNode := makeNode(parent, title, 555, 600 + Config.counter)
|
||||||
newNode.uiTab = tab
|
|
||||||
return newNode
|
return newNode
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
func (n *Node) AddTab(title string, custom func() ui.Control) *Node {
|
func (parent *Node) AddTab(title string) *Node {
|
||||||
if n.uiWindow == nil {
|
if parent.uiWindow == nil {
|
||||||
n.Dump()
|
parent.Dump()
|
||||||
panic("gui.AddTab() ERROR ui.Window == nil")
|
panic("gui.AddTab() ERROR ui.Window == nil")
|
||||||
}
|
}
|
||||||
if n.box == nil {
|
if parent.box == nil {
|
||||||
n.Dump()
|
parent.Dump()
|
||||||
panic("gui.AddTab() ERROR box == nil")
|
panic("gui.AddTab() ERROR box == nil")
|
||||||
}
|
}
|
||||||
|
if parent.uiTab == nil {
|
||||||
|
inittab := ui.NewTab() // no, not that 'inittab'
|
||||||
|
parent.uiWindow.SetChild(inittab)
|
||||||
|
parent.uiWindow.SetMargined(true)
|
||||||
|
parent.uiTab = inittab
|
||||||
|
|
||||||
tab := ui.NewTab()
|
parent.Dump()
|
||||||
n.uiWindow.SetMargined(true)
|
// panic("gui.AddTab() ERROR uiTab == nil")
|
||||||
|
}
|
||||||
|
|
||||||
tab.Append(title, custom())
|
tab := parent.uiTab
|
||||||
|
parent.uiWindow.SetMargined(true)
|
||||||
|
|
||||||
|
tab.Append(title, initBlankWindow())
|
||||||
tab.SetMargined(0, true)
|
tab.SetMargined(0, true)
|
||||||
|
|
||||||
newNode := makeNode(n, title, 555, 600 + Config.counter)
|
newNode := makeNode(parent, title, 555, 600 + Config.counter)
|
||||||
newNode.uiTab = tab
|
newNode.uiTab = tab
|
||||||
return newNode
|
return newNode
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ type GuiConfig struct {
|
||||||
|
|
||||||
depth int
|
depth int
|
||||||
counter int // used to make unique ID's
|
counter int // used to make unique ID's
|
||||||
|
prefix string
|
||||||
}
|
}
|
||||||
|
|
||||||
type GuiData struct {
|
type GuiData struct {
|
||||||
|
|
27
window.go
27
window.go
|
@ -213,23 +213,46 @@ func CreateWindow(title string, tabname string, x int, y int, custom func() ui.C
|
||||||
log.Println("SERIOUS ERROR n.box == nil in CreateWindow()")
|
log.Println("SERIOUS ERROR n.box == nil in CreateWindow()")
|
||||||
log.Println("SERIOUS ERROR n.box == nil in CreateWindow()")
|
log.Println("SERIOUS ERROR n.box == nil in CreateWindow()")
|
||||||
}
|
}
|
||||||
n.InitTab(title)
|
n.AddTab(title)
|
||||||
// TODO: run custom() here // Oct 9
|
// TODO: run custom() here // Oct 9
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n *Node) Add(e Element) *Node {
|
||||||
|
newNode := n.addNode("testingAdd")
|
||||||
|
if(e == Tab) {
|
||||||
|
log.Println("gui.Add() SHOULD ADD element =", e.String())
|
||||||
|
}
|
||||||
|
return newNode
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Create a new node
|
// Create a new node
|
||||||
// if parent == nil, that means it is a new window and needs to be put
|
// if parent == nil, that means it is a new window and needs to be put
|
||||||
// in the window map (aka Data.NodeMap)
|
// in the window map (aka Data.NodeMap)
|
||||||
//
|
//
|
||||||
|
func (parent *Node) addNode(title string) *Node {
|
||||||
|
var node Node
|
||||||
|
node.Name = title
|
||||||
|
node.Width = parent.Width
|
||||||
|
node.Height = parent.Height
|
||||||
|
node.parent = parent
|
||||||
|
|
||||||
|
id := Config.prefix + strconv.Itoa(Config.counter)
|
||||||
|
Config.counter += 1
|
||||||
|
node.id = id
|
||||||
|
|
||||||
|
parent.Append(&node)
|
||||||
|
return &node
|
||||||
|
}
|
||||||
|
|
||||||
func makeNode(parent *Node, title string, x int, y int) *Node {
|
func makeNode(parent *Node, 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
|
||||||
node.Height = y
|
node.Height = y
|
||||||
|
|
||||||
id := "jwc" + strconv.Itoa(Config.counter)
|
id := Config.prefix + strconv.Itoa(Config.counter)
|
||||||
Config.counter += 1
|
Config.counter += 1
|
||||||
node.id = id
|
node.id = id
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue