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-21 20:07:14 -05:00
|
|
|
"fmt"
|
2014-07-18 21:30:07 -05:00
|
|
|
"flag"
|
2014-07-28 19:52:32 -05:00
|
|
|
"reflect"
|
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-28 16:59:50 -05:00
|
|
|
type dtype struct {
|
|
|
|
Name string
|
|
|
|
Address string
|
|
|
|
}
|
|
|
|
var ddata = []dtype{
|
|
|
|
{ "alpha", "beta" },
|
|
|
|
{ "gamma", "delta" },
|
|
|
|
{ "epsilon", "zeta" },
|
|
|
|
{ "eta", "theta" },
|
|
|
|
{ "iota", "kappa" },
|
|
|
|
}
|
|
|
|
|
2014-07-28 22:55:52 -05:00
|
|
|
type testwin struct {
|
|
|
|
t Tab
|
|
|
|
w Window
|
|
|
|
table Table
|
|
|
|
b Button
|
|
|
|
c Checkbox
|
|
|
|
e TextField
|
|
|
|
e2 TextField
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tw *testwin) make(done chan struct{}) {
|
|
|
|
tw.t = NewTab()
|
|
|
|
tw.w = NewWindow("Hello", 320, 240, tw.t)
|
|
|
|
tw.w.OnClosing(func() bool {
|
|
|
|
if *closeOnClick {
|
|
|
|
panic("window closed normally in close on click mode (should not happen)")
|
|
|
|
}
|
|
|
|
println("window close event received")
|
|
|
|
Stop()
|
|
|
|
done <- struct{}{}
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
tw.table = NewTable(reflect.TypeOf(ddata[0]))
|
|
|
|
tw.table.Lock()
|
|
|
|
dq := tw.table.Data().(*[]dtype)
|
|
|
|
*dq = ddata
|
|
|
|
tw.table.Unlock()
|
|
|
|
tw.t.Append("Table", tw.table)
|
|
|
|
tw.b = NewButton("There")
|
|
|
|
if *closeOnClick {
|
|
|
|
tw.b.SetText("Click to Close")
|
|
|
|
}
|
|
|
|
// GTK+ TODO: this is causing a resize event to happen afterward?!
|
|
|
|
tw.b.OnClicked(func() {
|
|
|
|
println("in OnClicked()")
|
|
|
|
if *closeOnClick {
|
|
|
|
tw.w.Close()
|
|
|
|
Stop()
|
|
|
|
done <- struct{}{}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
tw.t.Append("Button", tw.b)
|
|
|
|
tw.c = NewCheckbox("You Should Now See Me Instead")
|
|
|
|
tw.c.OnClicked(func() {
|
|
|
|
tw.w.SetTitle(fmt.Sprint(tw.c.Checked()))
|
|
|
|
})
|
|
|
|
tw.t.Append("Checkbox", tw.c)
|
|
|
|
tw.e = NewTextField()
|
|
|
|
tw.t.Append("Text Field", tw.e)
|
|
|
|
tw.e2 = NewPasswordField()
|
2014-07-29 00:40:17 -05:00
|
|
|
tw.t.Append("Password Field", tw.e2)
|
2014-07-28 22:55:52 -05:00
|
|
|
tw.w.Show()
|
|
|
|
}
|
|
|
|
|
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-28 13:00:01 -05:00
|
|
|
flag.BoolVar(&spaced, "spaced", false, "enable spacing")
|
2014-07-18 21:30:07 -05:00
|
|
|
flag.Parse()
|
2014-07-19 09:16:00 -05:00
|
|
|
go func() {
|
2014-07-28 22:55:52 -05:00
|
|
|
tw := new(testwin)
|
2014-07-08 09:00:16 -05:00
|
|
|
done := make(chan struct{})
|
2014-07-28 22:55:52 -05:00
|
|
|
Do(func() { tw.make(done) })
|
2014-07-08 09:00:16 -05:00
|
|
|
<-done
|
2014-07-19 09:16:00 -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
|
|
|
|
}
|