From 17512c10c5e111868e4cea74cd9d55ba95bbcb39 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 13 Jun 2019 14:17:05 -0700 Subject: [PATCH] ready to implement Destroy() Signed-off-by: Jeff Carr --- area.go | 5 +++-- box.go | 2 +- debug.go | 6 ++--- structs.go | 2 +- window.go | 66 ++++++++++++++++++++++++++---------------------------- 5 files changed, 40 insertions(+), 41 deletions(-) diff --git a/area.go b/area.go index d170659..0cc7531 100644 --- a/area.go +++ b/area.go @@ -109,6 +109,7 @@ func (ah GuiArea) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) { func ShowTextBox(box *GuiBox, newText *ui.AttributedString, custom func(*GuiButton), name string) { log.Println("ShowTextBox() START") + gw := box.Window if (gw == nil) { log.Println("ShowTextBox() ERROR gw = nil") @@ -123,10 +124,10 @@ func ShowTextBox(box *GuiBox, newText *ui.AttributedString, custom func(*GuiButt newbox.Name = name hbox := ui.NewVerticalBox() newbox.UiBox = hbox + */ // TODO: allow padded & axis here - hbox.SetPadded(true) - */ + box.UiBox.SetPadded(true) // add(gw.BoxMap["MAINBOX"], newbox) diff --git a/box.go b/box.go index b554248..08d4918 100644 --- a/box.go +++ b/box.go @@ -113,7 +113,7 @@ func HardBox(gw *GuiWindow, axis int, name string) *GuiBox { add(gw.BoxMap["MAINBOX"], newbox) - log.Println("HardBoxk END") + log.Println("HardBox END") return newbox } diff --git a/debug.go b/debug.go index 5319354..f1fdf92 100644 --- a/debug.go +++ b/debug.go @@ -33,14 +33,14 @@ func WatchGUI() { func DumpBoxes() { for name, window := range Data.WindowMap { log.Println("gui.DumpBoxes() MAP: ", name) - log.Println("gui.DumpBoxes()\tWindow.name =", window.Name) - // log.Println("gui.DumpBoxes()\tWindow.UiWindow type =", reflect.TypeOf(window.UiWindow)) - // log.Println("gui.DumpBoxes()\tWindow.UiWindow =", window.UiWindow) if (window.TabNumber == nil) { log.Println("gui.DumpBoxes() \tWindows.TabNumber = nil") } else { log.Println("gui.DumpBoxes() \tWindows.TabNumber =", *window.TabNumber) } + log.Println("gui.DumpBoxes()\tWindow.name =", window.Name) + // log.Println("gui.DumpBoxes()\tWindow.UiWindow type =", reflect.TypeOf(window.UiWindow)) + log.Println("gui.DumpBoxes()\tWindow.UiWindow =", window.UiWindow) for name, abox := range window.BoxMap { log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) if (name == "MAINBOX") { diff --git a/structs.go b/structs.go index baf514a..0f02147 100644 --- a/structs.go +++ b/structs.go @@ -67,7 +67,7 @@ type GuiWindow struct { TabNumber *int // the andlabs/ui tab index // the callback function to make the window contents - MakeWindow func(*GuiBox) *GuiBox + // MakeWindow func(*GuiBox) *GuiBox // the components of the window BoxMap map[string]*GuiBox diff --git a/window.go b/window.go index 33e17cd..543ae2a 100644 --- a/window.go +++ b/window.go @@ -9,54 +9,33 @@ import _ "github.com/andlabs/ui/winmanifest" func StartNewWindow(bg bool, name string, axis int, callback func(*GuiBox) *GuiBox) { log.Println("StartNewWindow() Create a new window") - var tmp GuiWindow - tmp.MakeWindow = callback - tmp.Name = name - tmp.Axis = axis if (bg) { log.Println("StartNewWindow() START NEW GOROUTINE for ui.Main()") go ui.Main(func() { log.Println("gui.StartNewWindow() inside ui.Main()") - go initTabWindow(&tmp) + go runWindow(name, axis, callback) }) time.Sleep(2000 * time.Millisecond) // this might make it more stable on windows? } else { log.Println("StartNewWindow() WAITING for ui.Main()") ui.Main(func() { log.Println("gui.StartNewWindow() inside ui.Main()") - initTabWindow(&tmp) + runWindow(name, axis, callback) }) } } // This creates the raw andlabs/ui Window -func initTabWindow(gw *GuiWindow) { +func runWindow(name string, axis int, callback func(*GuiBox) *GuiBox) { log.Println("initTabWindow() START. THIS WINDOW IS NOT YET SHOWN") - log.Println("initTabWindow() START. name =", gw.Name) + log.Println("initTabWindow() START. name =", name) - gw.UiWindow = ui.NewWindow(gw.Name, int(gw.Width), int(gw.Height), true) - gw.UiWindow.SetBorderless(false) - - gw.UiWindow.OnClosing(func(*ui.Window) bool { - log.Println("initTabWindow() OnClosing() THIS WINDOW IS CLOSING gw=", gw) - ui.Quit() - return true - }) - - gw.UiTab = ui.NewTab() - gw.UiWindow.SetChild(gw.UiTab) - gw.UiWindow.SetMargined(true) - tmp := 0 - gw.TabNumber = &tmp - - DumpBoxes() - // for {} - box := InitWindow(gw, gw.Name, gw.Axis) - box = gw.MakeWindow(box) - gw = box.Window + box := InitWindow(nil, name, axis) + box = callback(box) + window := box.Window log.Println("initTabWindow() END box =", box) - log.Println("initTabWindow() END gw =", gw) - gw.UiWindow.Show() + log.Println("initTabWindow() END gw =", window) + window.UiWindow.Show() } func MessageWindow(gw *GuiWindow, msg1 string, msg2 string) { @@ -88,10 +67,29 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { newGuiWindow.Height = 600 newGuiWindow.Width = 800 + // This is the first window. One must create it here + if (gw == nil) { + log.Println("initWindow() ADDING ui.NewWindow()") + newGuiWindow.UiWindow = ui.NewWindow(newGuiWindow.Name, int(newGuiWindow.Width), int(newGuiWindow.Height), true) + newGuiWindow.UiWindow.SetBorderless(false) + + newGuiWindow.UiWindow.OnClosing(func(*ui.Window) bool { + log.Println("initTabWindow() OnClosing() THIS WINDOW IS CLOSING newGuiWindow=", newGuiWindow) + ui.Quit() + return true + }) + + newGuiWindow.UiTab = ui.NewTab() + newGuiWindow.UiWindow.SetChild(newGuiWindow.UiTab) + newGuiWindow.UiWindow.SetMargined(true) + tmp := 0 + newGuiWindow.TabNumber = &tmp + } else { + newGuiWindow.UiWindow = gw.UiWindow + newGuiWindow.UiTab = gw.UiTab + } + newGuiWindow.Axis = axis - newGuiWindow.MakeWindow = gw.MakeWindow - newGuiWindow.UiWindow = gw.UiWindow - newGuiWindow.UiTab = gw.UiTab newGuiWindow.Name = name newGuiWindow.BoxMap = make(map[string]*GuiBox) @@ -103,7 +101,7 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { tabnum := 0 newGuiWindow.TabNumber = &tabnum } else { - tabnum := gw.UiTab.NumPages() + tabnum := newGuiWindow.UiTab.NumPages() newGuiWindow.TabNumber = &tabnum }