CODE: not sure, but it compiles and runs somehow

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2021-10-05 09:29:55 -05:00
parent 6035dc8d79
commit 6438e4cc6a
2 changed files with 39 additions and 59 deletions

View File

@ -118,7 +118,7 @@ func (s GuiBox) InitTab(title string) *ui.Tab {
window.SetChild(tab) window.SetChild(tab)
window.SetMargined(true) window.SetMargined(true)
tab.Append(title, InitBlankWindow()) tab.Append(title, initBlankWindow())
tab.SetMargined(0, true) tab.SetMargined(0, true)
// tab.SetMargined(1, 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 { func (s GuiBox) AddBoxTab(title string) *GuiBox {
uiTab := s.AddTab2(title, InitBlankWindow()) uiTab := s.AddTab2(title, initBlankWindow())
tabSetMargined(uiTab) tabSetMargined(uiTab)
var box *GuiBox var box *GuiBox

View File

@ -7,36 +7,27 @@ import "time"
import "github.com/andlabs/ui" import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest" import _ "github.com/andlabs/ui/winmanifest"
func initUI(name string, callback func(*GuiBox) *GuiBox) {
ui.Main(func() {
log.Println("gui.initUI() inside ui.Main()")
box := InitWindow(nil, "StartNewWindow" + name, 0)
box = callback(box)
window := box.Window
log.Println("StartNewWindow() box =", box)
window.UiWindow.Show()
})
}
func StartNewWindow(bg bool, name string, axis int, callback func(*GuiBox) *GuiBox) { func StartNewWindow(bg bool, name string, axis int, callback func(*GuiBox) *GuiBox) {
log.Println("StartNewWindow() Create a new window") log.Println("StartNewWindow() ui.Main() Create a new window")
if (bg) { if (bg) {
log.Println("StartNewWindow() START NEW GOROUTINE for ui.Main()") go initUI(name, callback)
go ui.Main(func() {
log.Println("gui.StartNewWindow() inside ui.Main() in NEW goroutine")
// 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()
})
time.Sleep(500 * time.Millisecond) // this might make it more stable on windows? time.Sleep(500 * time.Millisecond) // this might make it more stable on windows?
} else { } else {
log.Println("StartNewWindow() WAITING for ui.Main()") initUI(name, callback)
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()
})
} }
} }
@ -62,6 +53,7 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox {
return nil return nil
} }
// return mapWindow(window, name, Config.Height, Config.Width)
log.Println("InitGuiWindow() START") log.Println("InitGuiWindow() START")
var newGuiWindow GuiWindow var newGuiWindow GuiWindow
newGuiWindow.Height = Config.Height newGuiWindow.Height = Config.Height
@ -98,7 +90,6 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox {
newGuiWindow.UiTab = gw.UiTab newGuiWindow.UiTab = gw.UiTab
} }
newGuiWindow.BoxMap = make(map[string]*GuiBox) newGuiWindow.BoxMap = make(map[string]*GuiBox)
newGuiWindow.EntryMap = make(map[string]*GuiEntry) newGuiWindow.EntryMap = make(map[string]*GuiEntry)
// Data.Windows = append(Data.Windows, &newGuiWindow) // Data.Windows = append(Data.Windows, &newGuiWindow)
@ -158,30 +149,10 @@ 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) *GuiBox {
func CreateWindow(title string, tabname string, x int, y int, custom func() ui.Control) *ui.Window { box := CreateBlankWindow(title, x, y)
window := ui.NewWindow(title, x, y, false) box.InitTab(title)
window.SetBorderless(false) return box
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
})
tab := ui.NewTab()
window.SetChild(tab)
window.SetMargined(true)
tab.Append(tabname, custom())
tab.SetMargined(0, true)
window.Show()
return window
} }
func CreateBlankWindow(title string, x int, y int) *GuiBox { func CreateBlankWindow(title string, x int, y int) *GuiBox {
@ -200,6 +171,17 @@ func CreateBlankWindow(title string, x int, y int) *GuiBox {
window.SetMargined(true) window.SetMargined(true)
window.Show() window.Show()
return mapWindow(window, title, x, y)
}
func initBlankWindow() ui.Control {
hbox := ui.NewHorizontalBox()
hbox.SetPadded(true)
return hbox
}
func mapWindow(window *ui.Window, title string, x int, y int) *GuiBox {
var newGuiWindow GuiWindow var newGuiWindow GuiWindow
newGuiWindow.Width = x newGuiWindow.Width = x
newGuiWindow.Height = y newGuiWindow.Height = y
@ -209,6 +191,11 @@ func CreateBlankWindow(title string, x int, y int) *GuiBox {
newGuiWindow.BoxMap = make(map[string]*GuiBox) newGuiWindow.BoxMap = make(map[string]*GuiBox)
newGuiWindow.EntryMap = make(map[string]*GuiEntry) 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 Data.WindowMap[newGuiWindow.Name] = &newGuiWindow
var box GuiBox var box GuiBox
@ -216,10 +203,3 @@ func CreateBlankWindow(title string, x int, y int) *GuiBox {
return &box return &box
} }
func InitBlankWindow() ui.Control {
hbox := ui.NewHorizontalBox()
hbox.SetPadded(true)
return hbox
}