2014-07-08 09:00:16 -05:00
|
|
|
// 8 july 2014
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
import (
|
2014-07-18 21:30:07 -05:00
|
|
|
"flag"
|
2014-07-08 09:00:16 -05:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2014-07-18 21:30:07 -05:00
|
|
|
var closeOnClick = flag.Bool("close", false, "close on click")
|
|
|
|
|
2014-07-08 15:47:28 -05:00
|
|
|
// because Cocoa hates being run off the main thread, even if it's run exclusively off the main thread
|
|
|
|
func init() {
|
2014-07-18 21:30:07 -05:00
|
|
|
flag.Parse()
|
2014-07-19 08:58:57 -05:00
|
|
|
go Do(func() {
|
2014-07-19 09:07:42 -05:00
|
|
|
w := NewWindow("Hello", 320, 240)
|
|
|
|
b := NewButton("There")
|
2014-07-19 08:58:57 -05:00
|
|
|
w.SetControl(b)
|
2014-07-18 21:30:07 -05:00
|
|
|
if *closeOnClick {
|
2014-07-19 08:58:57 -05:00
|
|
|
b.SetText("Click to Close")
|
2014-07-18 21:30:07 -05:00
|
|
|
}
|
2014-07-08 09:00:16 -05:00
|
|
|
done := make(chan struct{})
|
2014-07-19 09:07:42 -05:00
|
|
|
w.OnClosing(func() bool {
|
2014-07-18 21:30:07 -05:00
|
|
|
if *closeOnClick {
|
|
|
|
panic("window closed normally in close on click mode (should not happen)")
|
|
|
|
}
|
|
|
|
println("window close event received")
|
2014-07-13 19:26:16 -05:00
|
|
|
Stop()
|
2014-07-08 11:04:51 -05:00
|
|
|
done <- struct{}{}
|
|
|
|
return true
|
2014-07-19 08:58:57 -05:00
|
|
|
})
|
2014-07-19 09:07:42 -05:00
|
|
|
b.OnClicked(func() {
|
2014-07-17 11:02:39 -05:00
|
|
|
println("in OnClicked()")
|
2014-07-18 21:30:07 -05:00
|
|
|
if *closeOnClick {
|
2014-07-19 09:07:42 -05:00
|
|
|
w.Close()
|
2014-07-18 21:30:07 -05:00
|
|
|
Stop()
|
|
|
|
done <- struct{}{}
|
|
|
|
}
|
2014-07-19 08:58:57 -05:00
|
|
|
})
|
|
|
|
w.Show()
|
2014-07-08 09:00:16 -05:00
|
|
|
<-done
|
2014-07-19 09:07:42 -05:00
|
|
|
})
|
2014-07-08 09:00:16 -05:00
|
|
|
err := Go()
|
|
|
|
if err != nil {
|
2014-07-08 15:47:28 -05:00
|
|
|
panic(err)
|
2014-07-08 09:00:16 -05:00
|
|
|
}
|
|
|
|
}
|
2014-07-08 15:47:28 -05:00
|
|
|
|
|
|
|
func TestDummy(t *testing.T) {
|
|
|
|
// do nothing
|
|
|
|
}
|