summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--box.go30
-rw-r--r--gui-example/main.go2
-rw-r--r--new-structs.go35
-rw-r--r--structs.go26
-rw-r--r--window.go16
5 files changed, 39 insertions, 70 deletions
diff --git a/box.go b/box.go
index 1b08945..6b77912 100644
--- a/box.go
+++ b/box.go
@@ -72,25 +72,18 @@ func add(box *GuiBox, newbox *GuiBox) {
log.Println("gui.add() END")
}
-func (n *Node) NewBox(axis int, name string) *Node {
- var newBox *GuiBox
- var newNode *Node = n
+func (parent *Node) NewBox(axis int, name string) *Node {
+ if (parent.box == nil) {
+ panic("gui.Node.NewBox() parent.box == nil")
+ }
- newBox = new(GuiBox)
- // newBox.Window = newNode.uiWindow
+ newBox := new(GuiBox)
+ newBox.Window = parent.window
newBox.Name = name
- if (n.box == nil) {
- panic("node.newBox() box == nil")
- }
- if (n.box == nil) {
- // add a box here
- newBox.node = n
- n.box = newBox
- } else {
- // make a new box & a new node
- newNode = makeNode(n, name, 111, 112)
- }
+ // make a new box & a new node
+ newNode := parent.makeNode(name, 111, 100 + Config.counter)
+ Config.counter += 1
var uiBox *ui.Box
if (axis == Xaxis) {
@@ -100,7 +93,10 @@ func (n *Node) NewBox(axis int, name string) *Node {
}
uiBox.SetPadded(true)
newBox.UiBox = uiBox
- add(n.box, newBox)
+ newNode.uiBox = uiBox
+
+ parent.Append(newNode)
+ // add(n.box, newBox)
return newNode
}
diff --git a/gui-example/main.go b/gui-example/main.go
index 5f34f98..cba4545 100644
--- a/gui-example/main.go
+++ b/gui-example/main.go
@@ -34,7 +34,7 @@ func watchGUI() {
for {
log.Println("Waiting for customExit()", i)
i += 1
- time.Sleep(3 * time.Second)
+ time.Sleep(1 * time.Second)
if i == 2 {
log.Println("Sending ExampleWindow to gui.Queue()")
gui.Queue(gui.DebugWindow)
diff --git a/new-structs.go b/new-structs.go
index 1089fcf..ffe83d4 100644
--- a/new-structs.go
+++ b/new-structs.go
@@ -47,11 +47,13 @@ type Node struct {
parent *Node
children []*Node
+ window *GuiWindow
box *GuiBox
uiControl *ui.Control
uiWindow *ui.Window
uiTab *ui.Tab
+ uiBox *ui.Box
}
func (n *Node) Parent() *Node {
@@ -67,12 +69,17 @@ func (n *Node) Dump() {
log.Println("gui.Node.Dump() Name = ", n.Name)
log.Println("gui.Node.Dump() Width = ", n.Width)
log.Println("gui.Node.Dump() Height = ", n.Height)
+
log.Println("gui.Node.Dump() parent = ", n.parent)
log.Println("gui.Node.Dump() children = ", n.children)
+
+ log.Println("gui.Node.Dump() window = ", n.window)
log.Println("gui.Node.Dump() box = ", n.box)
- log.Println("gui.Node.Dump() uiControl = ", n.uiControl)
+
log.Println("gui.Node.Dump() uiWindow = ", n.uiWindow)
log.Println("gui.Node.Dump() uiTab = ", n.uiTab)
+ log.Println("gui.Node.Dump() uiBox = ", n.uiBox)
+ log.Println("gui.Node.Dump() uiControl = ", n.uiControl)
if (n.id == "") {
panic("gui.Node.Dump() id == nil")
}
@@ -197,30 +204,6 @@ func findByName(node *Node, name string) *Node {
return nil
}
-/*
-func (parent *Node) InitTab(title string) *Node {
- if parent.uiWindow == nil {
- parent.Dump()
- panic("gui.InitTab() ERROR ui.Window == nil")
- }
- if parent.box == nil {
- parent.Dump()
- panic("gui.InitTab() ERROR box == nil")
- }
-
- tab := ui.NewTab()
- parent.uiWindow.SetChild(tab)
- parent.uiWindow.SetMargined(true)
- parent.uiTab = tab
-
- tab.Append(title, initBlankWindow())
- tab.SetMargined(0, true)
-
- newNode := makeNode(parent, title, 555, 600 + Config.counter)
- return newNode
-}
-*/
-
func (parent *Node) AddTab(title string) *Node {
if parent.uiWindow == nil {
parent.Dump()
@@ -246,7 +229,7 @@ func (parent *Node) AddTab(title string) *Node {
tab.Append(title, initBlankWindow())
tab.SetMargined(0, true)
- newNode := makeNode(parent, title, 555, 600 + Config.counter)
+ newNode := parent.makeNode(title, 555, 600 + Config.counter)
newNode.uiTab = tab
return newNode
}
diff --git a/structs.go b/structs.go
index 3bb8c05..d09efb8 100644
--- a/structs.go
+++ b/structs.go
@@ -186,32 +186,6 @@ func (s GuiBox) Append(child ui.Control, x bool) {
s.UiBox.Append(child, x)
}
-/*
-func (s GuiBox) InitTab(title string, custom func() ui.Control) *Node {
- if s.Window == nil {
- return nil
- }
- if s.Window.UiWindow == nil {
- return nil
- }
-
- window := s.Window.UiWindow
- tab := ui.NewTab()
- window.SetChild(tab)
- window.SetMargined(true)
-
- tab.Append(title, custom())
- tab.SetMargined(0, true)
- // tab.SetMargined(1, true)
-
- s.Window.UiTab = tab
- if s.node == nil {
- log.Println("Fuck node = ", s.node)
- os.Exit(-1)
- }
- return s.node
-}
-*/
func (s *GuiBox) AddTab(title string, custom ui.Control) *ui.Tab {
if s.Window == nil {
diff --git a/window.go b/window.go
index 8505242..2f7c58a 100644
--- a/window.go
+++ b/window.go
@@ -20,6 +20,7 @@ func initUI(name string, callback func(*GuiBox) *GuiBox) {
box := node.box
box = callback(box)
window := box.Window
+ node.window = window
log.Println("StartNewWindow() box =", box)
window.UiWindow.Show()
@@ -271,6 +272,21 @@ func makeNode(parent *Node, title string, x int, y int) *Node {
return &node
}
+func (parent *Node) makeNode(title string, x int, y int) *Node {
+ var node Node
+ node.Name = title
+ node.Width = x
+ node.Height = y
+
+ id := Config.prefix + strconv.Itoa(Config.counter)
+ Config.counter += 1
+ node.id = id
+
+ parent.Append(&node)
+ node.parent = parent
+ return &node
+}
+
func (n *Node) uiNewWindow(title string, x int, y int) {
w := ui.NewWindow(title, x, y, false)
w.SetBorderless(false)