From a3c0cc390ccfa23dd64372e1e98a93c4cef8dbec Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 7 Oct 2021 05:52:22 -0500 Subject: [PATCH] NODE: start passing *Node around Signed-off-by: Jeff Carr --- box.go | 10 +++++++++- new-structs.go | 11 +++++++++-- structs.go | 36 +++++++++++++++++++----------------- window.go | 25 ++++++++++++++++++------- 4 files changed, 55 insertions(+), 27 deletions(-) diff --git a/box.go b/box.go index 2640742..a077064 100644 --- a/box.go +++ b/box.go @@ -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 diff --git a/new-structs.go b/new-structs.go index 0fa326a..df25cae 100644 --- a/new-structs.go +++ b/new-structs.go @@ -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 } diff --git a/structs.go b/structs.go index a7e78b5..2629cdc 100644 --- a/structs.go +++ b/structs.go @@ -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 diff --git a/window.go b/window.go index 8e68a70..d3b329a 100644 --- a/window.go +++ b/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 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)