summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gui.go1
-rw-r--r--new-structs.go79
-rw-r--r--structs.go1
-rw-r--r--window.go27
4 files changed, 84 insertions, 24 deletions
diff --git a/gui.go b/gui.go
index 9e7c253..ccefa00 100644
--- a/gui.go
+++ b/gui.go
@@ -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
}
diff --git a/structs.go b/structs.go
index 961e743..3bb8c05 100644
--- a/structs.go
+++ b/structs.go
@@ -28,6 +28,7 @@ type GuiConfig struct {
depth int
counter int // used to make unique ID's
+ prefix string
}
type GuiData struct {
diff --git a/window.go b/window.go
index cfab004..8505242 100644
--- a/window.go
+++ b/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()")
}
- 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