diff options
| author | Jeff Carr <[email protected]> | 2021-10-05 09:29:55 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2021-10-05 09:29:55 -0500 |
| commit | 1f216a0362a8512e9cfe63172ad4decaf3614037 (patch) | |
| tree | 8d8ab8080d96f2fbc1070fe18184e55da4b71afd /window.go | |
| parent | b036f9fccbf6b20ec510a54c892c3ee2a166b6f1 (diff) | |
CODE: not sure, but it compiles and runs somehow
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'window.go')
| -rw-r--r-- | window.go | 92 |
1 files changed, 36 insertions, 56 deletions
@@ -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 -} |
