Added a test case for Window.Close().
This commit is contained in:
parent
abb5b0c1d7
commit
08f5c42639
|
@ -5,23 +5,39 @@ package ui
|
||||||
// This file is called zz_test.go to keep it separate from the other files in this package (and because go test won't accept just test.go)
|
// This file is called zz_test.go to keep it separate from the other files in this package (and because go test won't accept just test.go)
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var closeOnClick = flag.Bool("close", false, "close on click")
|
||||||
|
|
||||||
// because Cocoa hates being run off the main thread, even if it's run exclusively off the main thread
|
// because Cocoa hates being run off the main thread, even if it's run exclusively off the main thread
|
||||||
func init() {
|
func init() {
|
||||||
|
flag.Parse()
|
||||||
go func() {
|
go func() {
|
||||||
w := GetNewWindow(Do, "Hello", 320, 240)
|
w := GetNewWindow(Do, "Hello", 320, 240)
|
||||||
b := GetNewButton(Do, "There")
|
b := GetNewButton(Do, "There")
|
||||||
Wait(Do, w.SetControl(b))
|
Wait(Do, w.SetControl(b))
|
||||||
|
if *closeOnClick {
|
||||||
|
Wait(Do, b.SetText("Click to Close"))
|
||||||
|
}
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
Wait(Do, w.OnClosing(func(c Doer) bool {
|
Wait(Do, w.OnClosing(func(c Doer) bool {
|
||||||
|
if *closeOnClick {
|
||||||
|
panic("window closed normally in close on click mode (should not happen)")
|
||||||
|
}
|
||||||
|
println("window close event received")
|
||||||
Stop()
|
Stop()
|
||||||
done <- struct{}{}
|
done <- struct{}{}
|
||||||
return true
|
return true
|
||||||
}))
|
}))
|
||||||
Wait(Do, b.OnClicked(func(c Doer) {
|
Wait(Do, b.OnClicked(func(c Doer) {
|
||||||
println("in OnClicked()")
|
println("in OnClicked()")
|
||||||
|
if *closeOnClick {
|
||||||
|
Wait(c, w.Close())
|
||||||
|
Stop()
|
||||||
|
done <- struct{}{}
|
||||||
|
}
|
||||||
}))
|
}))
|
||||||
Wait(Do, w.Show())
|
Wait(Do, w.Show())
|
||||||
<-done
|
<-done
|
||||||
|
|
Loading…
Reference in New Issue