NODE: start passing *Node around
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
5e439f7340
commit
a3c0cc390c
10
box.go
10
box.go
|
@ -1,6 +1,7 @@
|
||||||
package gui
|
package gui
|
||||||
|
|
||||||
import "log"
|
import "log"
|
||||||
|
import "os"
|
||||||
// import "reflect"
|
// import "reflect"
|
||||||
|
|
||||||
import "github.com/andlabs/ui"
|
import "github.com/andlabs/ui"
|
||||||
|
@ -64,7 +65,14 @@ func add(box *GuiBox, newbox *GuiBox) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBox(box *GuiBox, axis int, name string) *GuiBox {
|
func NewBox(box *GuiBox, axis int, name string) *GuiBox {
|
||||||
log.Println("VerticalBox START")
|
log.Println("gui.NewBox() START")
|
||||||
|
n := box.FindNode()
|
||||||
|
if (n == nil) {
|
||||||
|
log.Println("gui.NewBox() SERIOUS ERROR. CAN NOT FIND NODE")
|
||||||
|
} else {
|
||||||
|
log.Println("gui.NewBox() node =", n.Name)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
var newbox *GuiBox
|
var newbox *GuiBox
|
||||||
newbox = new(GuiBox)
|
newbox = new(GuiBox)
|
||||||
newbox.Window = box.Window
|
newbox.Window = box.Window
|
||||||
|
|
|
@ -15,13 +15,20 @@ type Node struct {
|
||||||
Width int
|
Width int
|
||||||
Height int
|
Height int
|
||||||
|
|
||||||
uiType *ui.Control
|
|
||||||
children []*Node
|
children []*Node
|
||||||
|
|
||||||
|
control *ui.Control
|
||||||
|
window *ui.Window
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n Node) SetName(name string) {
|
func (n Node) SetName(name string) {
|
||||||
// n.uiType.SetName(name)
|
// n.uiType.SetName(name)
|
||||||
log.Println("n.uiType =", n.uiType)
|
if (n.window != nil) {
|
||||||
|
log.Println("node is a window. setting title =", name)
|
||||||
|
n.window.SetTitle(name)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Println("*ui.Control =", n.control)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
36
structs.go
36
structs.go
|
@ -3,6 +3,7 @@ package gui
|
||||||
import (
|
import (
|
||||||
"image/color"
|
"image/color"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/andlabs/ui"
|
"github.com/andlabs/ui"
|
||||||
"golang.org/x/image/font"
|
"golang.org/x/image/font"
|
||||||
|
@ -87,6 +88,8 @@ type GuiWindow struct {
|
||||||
EntryMap map[string]*GuiEntry
|
EntryMap map[string]*GuiEntry
|
||||||
Area *GuiArea
|
Area *GuiArea
|
||||||
|
|
||||||
|
node *Node
|
||||||
|
|
||||||
// andlabs/ui abstraction mapping
|
// andlabs/ui abstraction mapping
|
||||||
UiWindow *ui.Window
|
UiWindow *ui.Window
|
||||||
UiTab *ui.Tab // if this != nil, the window is 'tabbed'
|
UiTab *ui.Tab // if this != nil, the window is 'tabbed'
|
||||||
|
@ -99,6 +102,8 @@ type GuiBox struct {
|
||||||
Axis int // does it add items to the X or Y axis
|
Axis int // does it add items to the X or Y axis
|
||||||
Window *GuiWindow // the parent Window
|
Window *GuiWindow // the parent Window
|
||||||
|
|
||||||
|
node *Node
|
||||||
|
|
||||||
// andlabs/ui abstraction mapping
|
// andlabs/ui abstraction mapping
|
||||||
UiBox *ui.Box
|
UiBox *ui.Box
|
||||||
}
|
}
|
||||||
|
@ -115,6 +120,13 @@ func (s GuiBox) SetTitle(title string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s GuiBox) FindNode() *Node {
|
||||||
|
if s.node != nil {
|
||||||
|
return s.node
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s GuiBox) Append(child ui.Control, x bool) {
|
func (s GuiBox) Append(child ui.Control, x bool) {
|
||||||
if s.UiBox == nil {
|
if s.UiBox == nil {
|
||||||
return
|
return
|
||||||
|
@ -140,7 +152,7 @@ func (w GuiWindow) InitWindow(title string) *GuiBox {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
func (s GuiBox) InitTab(title string, custom func() ui.Control) *ui.Tab {
|
func (s GuiBox) InitTab(title string, custom func() ui.Control) *Node {
|
||||||
if s.Window == nil {
|
if s.Window == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -158,7 +170,11 @@ func (s GuiBox) InitTab(title string, custom func() ui.Control) *ui.Tab {
|
||||||
// tab.SetMargined(1, true)
|
// tab.SetMargined(1, true)
|
||||||
|
|
||||||
s.Window.UiTab = tab
|
s.Window.UiTab = tab
|
||||||
return 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 {
|
func (s GuiBox) AddTab(title string, custom ui.Control) *ui.Tab {
|
||||||
|
@ -169,27 +185,13 @@ func (s GuiBox) AddTab(title string, custom ui.Control) *ui.Tab {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
tab := s.Window.UiTab
|
|
||||||
|
|
||||||
tab.Append(title, custom)
|
|
||||||
return tab
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s GuiBox) AddTab2(title string, custom ui.Control) *ui.Tab {
|
|
||||||
if s.Window == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if s.Window.UiTab == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
tab := s.Window.UiTab
|
tab := s.Window.UiTab
|
||||||
tab.Append(title, custom)
|
tab.Append(title, custom)
|
||||||
return tab
|
return tab
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s GuiBox) AddBoxTab(title string) *GuiBox {
|
func (s GuiBox) AddBoxTab(title string) *GuiBox {
|
||||||
uiTab := s.AddTab2(title, InitBlankWindow())
|
uiTab := s.AddTab(title, InitBlankWindow())
|
||||||
tabSetMargined(uiTab)
|
tabSetMargined(uiTab)
|
||||||
|
|
||||||
var box *GuiBox
|
var box *GuiBox
|
||||||
|
|
25
window.go
25
window.go
|
@ -65,7 +65,9 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox {
|
||||||
// This is the first window. One must create it here
|
// This is the first window. One must create it here
|
||||||
if gw == nil {
|
if gw == nil {
|
||||||
log.Println("initWindow() ADDING ui.NewWindow()")
|
log.Println("initWindow() ADDING ui.NewWindow()")
|
||||||
w := uiNewWindow(name, Config.Height, Config.Width)
|
n := uiNewWindow(name, Config.Height, Config.Width)
|
||||||
|
box.node = n
|
||||||
|
w := n.window
|
||||||
newGuiWindow.UiWindow = w
|
newGuiWindow.UiWindow = w
|
||||||
|
|
||||||
// newGuiWindow.UiWindow.SetTitle("test")
|
// newGuiWindow.UiWindow.SetTitle("test")
|
||||||
|
@ -150,11 +152,16 @@ func CreateWindow(title string, tabname string, x int, y int, custom func() ui.C
|
||||||
return box
|
return box
|
||||||
}
|
}
|
||||||
|
|
||||||
func uiNewWindow(title string, x int, y int) *ui.Window {
|
func uiNewWindow(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
|
||||||
|
if (Data.NodeMap[title] != nil) {
|
||||||
|
log.Println("Duplicate uiNewWindow() name =", title)
|
||||||
|
// TODO: just change the 'title' to something unique
|
||||||
|
return nil
|
||||||
|
}
|
||||||
Data.NodeMap[title] = &node
|
Data.NodeMap[title] = &node
|
||||||
|
|
||||||
w := ui.NewWindow(title, x, y, false)
|
w := ui.NewWindow(title, x, y, false)
|
||||||
|
@ -163,18 +170,20 @@ func uiNewWindow(title string, x int, y int) *ui.Window {
|
||||||
log.Println("ui.Window().OnClosing() IS EMPTY FOR window name =", title)
|
log.Println("ui.Window().OnClosing() IS EMPTY FOR window name =", title)
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
w.SetMargined(true)
|
w.SetMargined(true)
|
||||||
w.Show()
|
w.Show()
|
||||||
|
node.window = w
|
||||||
return w
|
// w.node = &node
|
||||||
|
return &node
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateBlankWindow(title string, x int, y int) *GuiBox {
|
func CreateBlankWindow(title string, x int, y int) *GuiBox {
|
||||||
box := mapWindow(nil, title, x, y)
|
box := mapWindow(nil, title, x, y)
|
||||||
log.Println("gui.CreateBlankWindow() title = box.Name =", box.Name)
|
log.Println("gui.CreateBlankWindow() title = box.Name =", box.Name)
|
||||||
|
|
||||||
window := uiNewWindow(box.Name, x, y)
|
n := uiNewWindow(box.Name, x, y)
|
||||||
|
box.node = n
|
||||||
|
window := n.window
|
||||||
|
|
||||||
ui.OnShouldQuit(func() bool {
|
ui.OnShouldQuit(func() bool {
|
||||||
log.Println("createWindow().Destroy()", box.Name)
|
log.Println("createWindow().Destroy()", box.Name)
|
||||||
|
@ -233,7 +242,9 @@ func NewWindow(title string, x int, y int) *GuiBox {
|
||||||
box := mapWindow(nil, title, x, y)
|
box := mapWindow(nil, title, x, y)
|
||||||
log.Println("gui.NewWindow() title = box.Name =", box.Name)
|
log.Println("gui.NewWindow() title = box.Name =", box.Name)
|
||||||
|
|
||||||
window := uiNewWindow(box.Name, x, y)
|
n := uiNewWindow(box.Name, x, y)
|
||||||
|
box.node = n
|
||||||
|
window := n.window
|
||||||
|
|
||||||
ui.OnShouldQuit(func() bool {
|
ui.OnShouldQuit(func() bool {
|
||||||
log.Println("createWindow().Destroy()", box.Name)
|
log.Println("createWindow().Destroy()", box.Name)
|
||||||
|
|
Loading…
Reference in New Issue