From 28a96010fd55416f53bd2127d84a5df20d8259f4 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 22 May 2019 11:14:42 -0700 Subject: [PATCH] does Distroy() on the ui.Box Signed-off-by: Jeff Carr --- splash/area.go | 17 ++++++++++------- splash/splash.go | 40 +++++++++++++++++---------------------- test2/Makefile | 4 ++++ test2/main.go | 49 +++++++++++++++++++++++++++++++++++++++++++----- 4 files changed, 75 insertions(+), 35 deletions(-) diff --git a/splash/area.go b/splash/area.go index 75559f7..8164516 100644 --- a/splash/area.go +++ b/splash/area.go @@ -5,20 +5,22 @@ import "log" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" +import "git.wit.com/wit/gui" + import "github.com/davecgh/go-spew/spew" var fontButton *ui.FontButton var attrstr *ui.AttributedString var splashArea *ui.Area -func makeSplashArea() *ui.Area { - fontButton = ui.NewFontButton() - fontButton.OnChanged(func(*ui.FontButton) { - spew.Dump(fontButton.Font()) - // SplashArea.QueueRedrawAll() - }) +func areaClick(a int, b string) { + log.Println("GOT areaClick(a,b) =", a, b) +} - spew.Dump(fontButton.Font()) +func makeSplashArea(custom func(int, string)) *ui.Area { + // make this button just to get the default font (but don't display the button) + // There should be another way to do this (?) + fontButton = gui.CreateFontButton("SplashFont", "CLOSE", custom) makeAttributedString() splashArea = ui.NewArea(myAH) @@ -90,6 +92,7 @@ func (ah areaHandler) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) { // splashWin.Destroy() // ui.Quit() } + areaClick(1, "done") } func (ah areaHandler) MouseCrossed(a *ui.Area, left bool) { diff --git a/splash/splash.go b/splash/splash.go index f23d456..cdd43c7 100644 --- a/splash/splash.go +++ b/splash/splash.go @@ -4,12 +4,14 @@ package splash // import "time" // import "fmt" -import "log" +// import "log" import "runtime" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" +import "git.wit.com/wit/gui" + // var splashWin *ui.Window var MyArea *ui.Area @@ -33,41 +35,33 @@ func ShowSplash() *ui.Window { // This displays the window // splashWin.Show() - ShowSplashBox(vbox, nil) + ShowSplashBox(vbox, nil, nil) return splashWin } -func ShowSplashBox(vbox *ui.Box, atest chan int) *ui.Box { - // vbox := ui.NewVerticalBox() - vbox.SetPadded(true) +func ShowSplashBox(vbox *ui.Box, atest chan int, custom func(int, string)) *ui.Box { + newbox := ui.NewVerticalBox() + newbox.SetPadded(true) makeAttributedString() - MyArea = makeSplashArea() + MyArea = makeSplashArea(custom) - vbox.Append(MyArea, true) + newbox.Append(MyArea, true) if runtime.GOOS == "linux" { - vbox.Append(ui.NewLabel("OS: Linux"), false) + newbox.Append(ui.NewLabel("OS: Linux"), false) } else if runtime.GOOS == "windows" { - vbox.Append(ui.NewLabel("OS: Windows"), false) + newbox.Append(ui.NewLabel("OS: Windows"), false) } else { - vbox.Append(ui.NewLabel("OS: " + runtime.GOOS), false) + newbox.Append(ui.NewLabel("OS: " + runtime.GOOS), false) } - vbox.Append(ui.NewLabel("Version: v0.3"), false) + newbox.Append(ui.NewLabel("Version: v0.3"), false) + okButton := gui.CreateButton("OK", "CLOSE", custom) + newbox.Append(okButton, false) - okButton := ui.NewButton("OK") + vbox.Append(newbox, true) - okButton.OnClicked(func(*ui.Button) { - log.Println("OK. Should close window here") - // test := 4 - // atest <- test - // splashWin.Destroy() - // ui.Quit() - }) - - vbox.Append(okButton, false) - - return vbox + return newbox } diff --git a/test2/Makefile b/test2/Makefile index e07773d..d81691a 100644 --- a/test2/Makefile +++ b/test2/Makefile @@ -1,2 +1,6 @@ +build: + go build + ./test2 + run: go run *.go diff --git a/test2/main.go b/test2/main.go index 0e87438..76a5049 100644 --- a/test2/main.go +++ b/test2/main.go @@ -10,10 +10,36 @@ import "git.wit.com/wit/cloud-control-panel/splash" import "git.wit.com/wit/cloud-control-panel/account1" import "git.wit.com/wit/cloud-control-panel/account2" +import "github.com/davecgh/go-spew/spew" + var cloudWindow *ui.Window var cloudBox *ui.Box +var smallBox *ui.Box var state string +func splashClose(a int, b string) { + log.Println("GOT splashClose(a,b) =", a, b) + // smallBox.Parent = nil + log.Println("cloudBox:") + log.Println("cloudBox:") + log.Println("cloudBox:") + spew.Dump(cloudBox) + cloudBox.Delete(0) + // cloudBox.Delete(1) + smallBox.Hide() + // smallBox.Parent = nil + log.Println("cloudBox:") + log.Println("cloudBox:") + log.Println("cloudBox:") + spew.Dump(cloudBox) + log.Println("smallBox:") + log.Println("smallBox:") + log.Println("smallBox:") + spew.Dump(smallBox) + // cloudBox.Destroy() + state = "kill" +} + func main() { go watchGUI() @@ -24,22 +50,31 @@ func main() { ui.Main(account2.AddAccountWindow) } +func buttonClick(i int) { + log.Println("buttonClick() i =", i) +} + func watchGUI() { - log.Println("Sleep()") - time.Sleep(2000 * time.Millisecond) +// log.Println("Sleep()") +// time.Sleep(2000 * time.Millisecond) for { log.Println("Sleep()") time.Sleep(200 * time.Millisecond) if (state == "splash") { - log.Println("Sleep()") - time.Sleep(200 * time.Millisecond) log.Println("Display the splash box") - splash.ShowSplashBox(cloudBox, nil) + smallBox = splash.ShowSplashBox(cloudBox, nil, splashClose) // newbox.SetPadded(true) state = "done" } + if (state == "kill") { + log.Println("state = kill") + log.Println("state = kill") + log.Println("state = kill") + smallBox.Destroy() + state = "account1" + } } } @@ -64,5 +99,9 @@ func makeCloudWindow() { // This displays the window cloudWindow.Show() + log.Println("cloudBox:") + log.Println("cloudBox:") + log.Println("cloudBox:") + spew.Dump(cloudBox) state = "splash" }