does Distroy() on the ui.Box

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-22 11:14:42 -07:00
parent b9d10aed57
commit 28a96010fd
4 changed files with 75 additions and 35 deletions

View File

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

View File

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

View File

@ -1,2 +1,6 @@
build:
go build
./test2
run:
go run *.go

View File

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