ready to implement Destroy()

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-06-13 14:17:05 -07:00
parent 22760127b9
commit 17512c10c5
5 changed files with 40 additions and 41 deletions

View File

@ -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)

2
box.go
View File

@ -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
}

View File

@ -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") {

View File

@ -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

View File

@ -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
}