better StartNewWindow() function

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-29 22:24:41 -07:00
parent 4e80e1cbd6
commit cf74635790
3 changed files with 26 additions and 20 deletions

View File

@ -3,6 +3,7 @@ package gui
import "log" import "log"
import "time" import "time"
import "regexp" import "regexp"
import "reflect"
import "github.com/andlabs/ui" import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest" import _ "github.com/andlabs/ui/winmanifest"
@ -210,7 +211,7 @@ func ShowMainTab(wm *WindowMap) {
wm.T.SetMargined(0, true) wm.T.SetMargined(0, true)
} }
func StartNewWindow(c *pb.Config, action string) { func StartNewWindow(c *pb.Config, bg bool, action string) {
log.Println("InitNewWindow() Create a new window") log.Println("InitNewWindow() Create a new window")
var newWindowMap WindowMap var newWindowMap WindowMap
newWindowMap.C = c newWindowMap.C = c
@ -226,10 +227,21 @@ func StartNewWindow(c *pb.Config, action string) {
for i, aWM := range(Data.Windows) { for i, aWM := range(Data.Windows) {
log.Println(aWM) log.Println(aWM)
if (aWM.W == nil) { if (aWM.W == nil) {
log.Println("ShowWindow() THIS WINDOW IS NOT YET SHOWN") log.Println("ShowWindow() THIS WINDOW IS NOT YET SHOWN i=", i)
log.Println("ShowWindow() THIS WINDOW IS NOT YET SHOWN aWM=", reflect.TypeOf(aWM))
// Data.NewWindow = &aWM // Data.NewWindow = &aWM
Data.NewWindow = i // Data.NewWindow = i
ui.Main(InitWindow) // ui.Main(InitWindow)
time.Sleep(200 * time.Millisecond)
if (bg) {
ui.Main(func() {
InitWindow(Data.Windows[i], i)
})
} else {
ui.Main(func() {
InitWindow(Data.Windows[i], i)
})
}
return return
} }
} }
@ -242,8 +254,10 @@ func getSplashText() *ui.AttributedString {
} }
func InitWindow() { func InitWindow(wm *WindowMap, i int) {
i := Data.NewWindow log.Println("InitWindow() THIS WINDOW IS NOT YET SHOWN")
// i := Data.NewWindow
log.Println("InitWindow() THIS WINDOW IS NOT YET SHOWN i=", i)
c := Data.Windows[i].C c := Data.Windows[i].C
Data.Windows[i].W = ui.NewWindow("", int(c.Width), int(c.Height), true) Data.Windows[i].W = ui.NewWindow("", int(c.Width), int(c.Height), true)
@ -257,7 +271,8 @@ func InitWindow() {
Data.AllButtons = append(Data.AllButtons, newBM) Data.AllButtons = append(Data.AllButtons, newBM)
Data.Windows[i].W.OnClosing(func(*ui.Window) bool { Data.Windows[i].W.OnClosing(func(*ui.Window) bool {
mouseClick(&newBM) log.Println("InitWindow() OnClosing() THIS WINDOW IS CLOSING i=", i)
// mouseClick(&newBM)
ui.Quit() ui.Quit()
return true return true
}) })

View File

@ -13,9 +13,9 @@ import pb "git.wit.com/wit/witProtobuf"
// If you need cross platform support, these might only // If you need cross platform support, these might only
// be the safe way to interact with the GUI // be the safe way to interact with the GUI
// //
var Data GuiDataStructure var Data GuiData
type GuiDataStructure struct { type GuiData struct {
State string State string
Width int Width int
Height int Height int
@ -48,15 +48,7 @@ type GuiDataStructure struct {
// A map of all the entry boxes // A map of all the entry boxes
AllEntries []EntryMap AllEntries []EntryMap
// a VM (maybe the one the user is playing with?)
// if opening a new window, this is a trick to
// pass it in
CurrentVM *pb.Event_VM
Windows []*WindowMap Windows []*WindowMap
NewWindow int
// Window1 *WindowMap
Window2 *WindowMap
EntryNick *ui.Entry EntryNick *ui.Entry
EntryUser *ui.Entry EntryUser *ui.Entry
@ -97,7 +89,6 @@ type WindowMap struct {
C *pb.Config C *pb.Config
AH *AreaHandler AH *AreaHandler
// AreaText *ui.AttributedString
Action string Action string
} }

View File

@ -45,7 +45,7 @@ func ShowVM() {
*/ */
func AddVmConfigureTab(wm *WindowMap, name string, pbVM *pb.Event_VM) { func AddVmConfigureTab(wm *WindowMap, name string, pbVM *pb.Event_VM) {
CreateVmBox(wm, wm.T, Data.CurrentVM) CreateVmBox(wm, wm.T, pbVM)
} }
func CreateVmBox(wm *WindowMap, tab *ui.Tab, vm *pb.Event_VM) { func CreateVmBox(wm *WindowMap, tab *ui.Tab, vm *pb.Event_VM) {
@ -84,7 +84,7 @@ func CreateVmBox(wm *WindowMap, tab *ui.Tab, vm *pb.Event_VM) {
hboxButtons.Append(CreateButton(wm, nil, vm, "Save", "SAVE", nil), false) hboxButtons.Append(CreateButton(wm, nil, vm, "Save", "SAVE", nil), false)
hboxButtons.Append(CreateButton(wm, nil, vm, "Done", "DONE", nil), false) hboxButtons.Append(CreateButton(wm, nil, vm, "Done", "DONE", nil), false)
AddBoxToTab(Data.CurrentVM.Name, tab, vbox) AddBoxToTab(vm.Name, tab, vbox)
} }
func createAddVmBox(wm *WindowMap, tab *ui.Tab, name string, b *ButtonMap) { func createAddVmBox(wm *WindowMap, tab *ui.Tab, name string, b *ButtonMap) {