diff options
| author | Jeff Carr <[email protected]> | 2021-10-09 06:38:32 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2021-10-09 06:38:32 -0500 |
| commit | 663b031c8f22f3c58de29410c9764abf2f29b095 (patch) | |
| tree | 8f08b1ac1461f9911abc9ae4e73caf653a0d65e8 | |
| parent | 822a1c8f2aeeda6b36437cf06c0fa65a45df29ef (diff) | |
NODE: walking around in the rabbit hole
| -rw-r--r-- | gui.go | 1 | ||||
| -rw-r--r-- | new-structs.go | 79 | ||||
| -rw-r--r-- | structs.go | 1 | ||||
| -rw-r--r-- | window.go | 27 |
4 files changed, 84 insertions, 24 deletions
@@ -21,6 +21,7 @@ func init() { Data.NodeMap = make(map[string]*Node) Config.counter = 0 + Config.prefix = "jwc" } func GuiInit() { diff --git a/new-structs.go b/new-structs.go index d5aa2fb..1089fcf 100644 --- a/new-structs.go +++ b/new-structs.go @@ -10,7 +10,33 @@ import ( _ "github.com/andlabs/ui/winmanifest" ) +type Element int + // 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 { id string @@ -120,16 +146,14 @@ func (n *Node) ListChildren(dump bool) { log.Println("\t\t\tno parent") panic("no parent") } - /* if (dump == true) { child.Dump() } - */ if (child.children == nil) { 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) } return @@ -173,45 +197,56 @@ func findByName(node *Node, name string) *Node { return nil } -func (n *Node) InitTab(title string) *Node { - if n.uiWindow == nil { - n.Dump() +/* +func (parent *Node) InitTab(title string) *Node { + if parent.uiWindow == nil { + parent.Dump() panic("gui.InitTab() ERROR ui.Window == nil") } - if n.box == nil { - n.Dump() + if parent.box == nil { + parent.Dump() panic("gui.InitTab() ERROR box == nil") } tab := ui.NewTab() - n.uiWindow.SetChild(tab) - n.uiWindow.SetMargined(true) + parent.uiWindow.SetChild(tab) + parent.uiWindow.SetMargined(true) + parent.uiTab = tab tab.Append(title, initBlankWindow()) tab.SetMargined(0, true) - newNode := makeNode(n, title, 555, 600 + Config.counter) - newNode.uiTab = tab + newNode := makeNode(parent, title, 555, 600 + Config.counter) return newNode } +*/ -func (n *Node) AddTab(title string, custom func() ui.Control) *Node { - if n.uiWindow == nil { - n.Dump() +func (parent *Node) AddTab(title string) *Node { + if parent.uiWindow == nil { + parent.Dump() panic("gui.AddTab() ERROR ui.Window == nil") } - if n.box == nil { - n.Dump() + if parent.box == nil { + parent.Dump() 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() - n.uiWindow.SetMargined(true) + parent.Dump() + // panic("gui.AddTab() ERROR uiTab == nil") + } + + tab := parent.uiTab + parent.uiWindow.SetMargined(true) - tab.Append(title, custom()) + tab.Append(title, initBlankWindow()) 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 } @@ -28,6 +28,7 @@ type GuiConfig struct { depth int counter int // used to make unique ID's + prefix string } type GuiData struct { @@ -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()") } - n.InitTab(title) + n.AddTab(title) // TODO: run custom() here // Oct 9 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 // if parent == nil, that means it is a new window and needs to be put // 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 { var node Node node.Name = title node.Width = x node.Height = y - id := "jwc" + strconv.Itoa(Config.counter) + id := Config.prefix + strconv.Itoa(Config.counter) Config.counter += 1 node.id = id |
