diff options
| -rw-r--r-- | structs.go | 4 | ||||
| -rw-r--r-- | window.go | 92 |
2 files changed, 38 insertions, 58 deletions
@@ -118,7 +118,7 @@ func (s GuiBox) InitTab(title string) *ui.Tab { window.SetChild(tab) window.SetMargined(true) - tab.Append(title, InitBlankWindow()) + tab.Append(title, initBlankWindow()) tab.SetMargined(0, true) // tab.SetMargined(1, true) @@ -154,7 +154,7 @@ func (s GuiBox) AddTab2(title string, custom ui.Control) *ui.Tab { } func (s GuiBox) AddBoxTab(title string) *GuiBox { - uiTab := s.AddTab2(title, InitBlankWindow()) + uiTab := s.AddTab2(title, initBlankWindow()) tabSetMargined(uiTab) var box *GuiBox @@ -7,36 +7,27 @@ import "time" import "github.com/andlabs/ui" 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") +func initUI(name string, callback func(*GuiBox) *GuiBox) { + ui.Main(func() { + log.Println("gui.initUI() inside ui.Main()") - if (bg) { - log.Println("StartNewWindow() START NEW GOROUTINE for ui.Main()") - go ui.Main(func() { - log.Println("gui.StartNewWindow() inside ui.Main() in NEW goroutine") + box := InitWindow(nil, "StartNewWindow" + name, 0) + box = callback(box) + window := box.Window + log.Println("StartNewWindow() box =", box) - // InitWindow must be called from within ui.Main() - box := InitWindow(nil, name, axis) - box = callback(box) - window := box.Window - log.Println("StartNewWindow() box =", box) + window.UiWindow.Show() + }) +} - window.UiWindow.Show() - }) +func StartNewWindow(bg bool, name string, axis int, callback func(*GuiBox) *GuiBox) { + log.Println("StartNewWindow() ui.Main() Create a new window") + + if (bg) { + go initUI(name, callback) time.Sleep(500 * 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()") - - // InitWindow must be called from within ui.Main() - box := InitWindow(nil, name, axis) - box = callback(box) - window := box.Window - log.Println("StartNewWindow() box =", box) - - window.UiWindow.Show() - }) + initUI(name, callback) } } @@ -62,6 +53,7 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { return nil } + // return mapWindow(window, name, Config.Height, Config.Width) log.Println("InitGuiWindow() START") var newGuiWindow GuiWindow newGuiWindow.Height = Config.Height @@ -98,7 +90,6 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { newGuiWindow.UiTab = gw.UiTab } - newGuiWindow.BoxMap = make(map[string]*GuiBox) newGuiWindow.EntryMap = make(map[string]*GuiEntry) // Data.Windows = append(Data.Windows, &newGuiWindow) @@ -158,8 +149,13 @@ func DeleteWindow(name string) { } } -// CreateWindow("my title", "my tabname", 300, 200, makeNumbersPagewin2) -func CreateWindow(title string, tabname string, x int, y int, custom func() ui.Control) *ui.Window { +func CreateWindow(title string, tabname string, x int, y int, custom func() ui.Control) *GuiBox { + box := CreateBlankWindow(title, x, y) + box.InitTab(title) + return box +} + +func CreateBlankWindow(title string, x int, y int) *GuiBox { window := ui.NewWindow(title, x, y, false) window.SetBorderless(false) window.OnClosing(func(*ui.Window) bool { @@ -172,34 +168,20 @@ func CreateWindow(title string, tabname string, x int, y int, custom func() ui.C return true }) - tab := ui.NewTab() - window.SetChild(tab) window.SetMargined(true) - - tab.Append(tabname, custom()) - tab.SetMargined(0, true) - window.Show() - return window + return mapWindow(window, title, x, y) } -func CreateBlankWindow(title string, x int, y int) *GuiBox { - window := ui.NewWindow(title, x, y, false) - window.SetBorderless(false) - window.OnClosing(func(*ui.Window) bool { - log.Println("createWindow().OnClosing()", title) - return true - }) - ui.OnShouldQuit(func() bool { - log.Println("createWindow().Destroy()", title) - window.Destroy() - return true - }) +func initBlankWindow() ui.Control { + hbox := ui.NewHorizontalBox() + hbox.SetPadded(true) - window.SetMargined(true) - window.Show() + return hbox +} +func mapWindow(window *ui.Window, title string, x int, y int) *GuiBox { var newGuiWindow GuiWindow newGuiWindow.Width = x newGuiWindow.Height = y @@ -209,6 +191,11 @@ func CreateBlankWindow(title string, x int, y int) *GuiBox { newGuiWindow.BoxMap = make(map[string]*GuiBox) newGuiWindow.EntryMap = make(map[string]*GuiEntry) + if (Data.WindowMap[newGuiWindow.Name] != nil) { + log.Println("Data.WindowMap[newGuiWindow.Name] already exists\n") + panic("Data.WindowMap[newGuiWindow.Name] already exists") + return nil + } Data.WindowMap[newGuiWindow.Name] = &newGuiWindow var box GuiBox @@ -216,10 +203,3 @@ func CreateBlankWindow(title string, x int, y int) *GuiBox { return &box } - -func InitBlankWindow() ui.Control { - hbox := ui.NewHorizontalBox() - hbox.SetPadded(true) - - return hbox -} |
