NODE: start passing *Node around

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2021-10-07 05:52:22 -05:00
parent 5e439f7340
commit a3c0cc390c
4 changed files with 55 additions and 27 deletions

10
box.go
View File

@ -1,6 +1,7 @@
package gui
import "log"
import "os"
// import "reflect"
import "github.com/andlabs/ui"
@ -64,7 +65,14 @@ func add(box *GuiBox, newbox *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
newbox = new(GuiBox)
newbox.Window = box.Window

View File

@ -15,13 +15,20 @@ type Node struct {
Width int
Height int
uiType *ui.Control
children []*Node
control *ui.Control
window *ui.Window
}
func (n Node) SetName(name string) {
// 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
}

View File

@ -3,6 +3,7 @@ package gui
import (
"image/color"
"log"
"os"
"github.com/andlabs/ui"
"golang.org/x/image/font"
@ -87,6 +88,8 @@ type GuiWindow struct {
EntryMap map[string]*GuiEntry
Area *GuiArea
node *Node
// andlabs/ui abstraction mapping
UiWindow *ui.Window
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
Window *GuiWindow // the parent Window
node *Node
// andlabs/ui abstraction mapping
UiBox *ui.Box
}
@ -115,6 +120,13 @@ func (s GuiBox) SetTitle(title string) {
return
}
func (s GuiBox) FindNode() *Node {
if s.node != nil {
return s.node
}
return nil
}
func (s GuiBox) Append(child ui.Control, x bool) {
if s.UiBox == nil {
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 {
return nil
}
@ -158,7 +170,11 @@ func (s GuiBox) InitTab(title string, custom func() ui.Control) *ui.Tab {
// tab.SetMargined(1, true)
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 {
@ -169,27 +185,13 @@ func (s GuiBox) AddTab(title string, custom ui.Control) *ui.Tab {
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.Append(title, custom)
return tab
}
func (s GuiBox) AddBoxTab(title string) *GuiBox {
uiTab := s.AddTab2(title, InitBlankWindow())
uiTab := s.AddTab(title, InitBlankWindow())
tabSetMargined(uiTab)
var box *GuiBox

View File

@ -65,7 +65,9 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox {
// This is the first window. One must create it here
if gw == nil {
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.SetTitle("test")
@ -150,11 +152,16 @@ func CreateWindow(title string, tabname string, x int, y int, custom func() ui.C
return box
}
func uiNewWindow(title string, x int, y int) *ui.Window {
func uiNewWindow(title string, x int, y int) *Node {
var node Node
node.Name = title
node.Width = x
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
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)
return true
})
w.SetMargined(true)
w.Show()
return w
node.window = w
// w.node = &node
return &node
}
func CreateBlankWindow(title string, x int, y int) *GuiBox {
box := mapWindow(nil, title, x, y)
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 {
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)
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 {
log.Println("createWindow().Destroy()", box.Name)