Fixed the test program crashing after a while (prevent the Window and Controls from being garbage-collected from under us).
This commit is contained in:
parent
84e04cdae1
commit
389269bc66
|
@ -25,16 +25,20 @@ var ddata = []dtype{
|
||||||
{ "iota", "kappa" },
|
{ "iota", "kappa" },
|
||||||
}
|
}
|
||||||
|
|
||||||
// because Cocoa hates being run off the main thread, even if it's run exclusively off the main thread
|
type testwin struct {
|
||||||
func init() {
|
t Tab
|
||||||
flag.BoolVar(&spaced, "spaced", false, "enable spacing")
|
w Window
|
||||||
flag.Parse()
|
table Table
|
||||||
go func() {
|
b Button
|
||||||
done := make(chan struct{})
|
c Checkbox
|
||||||
Do(func() {
|
e TextField
|
||||||
t := NewTab()
|
e2 TextField
|
||||||
w := NewWindow("Hello", 320, 240, t)
|
}
|
||||||
w.OnClosing(func() bool {
|
|
||||||
|
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 {
|
if *closeOnClick {
|
||||||
panic("window closed normally in close on click mode (should not happen)")
|
panic("window closed normally in close on click mode (should not happen)")
|
||||||
}
|
}
|
||||||
|
@ -43,37 +47,46 @@ func init() {
|
||||||
done <- struct{}{}
|
done <- struct{}{}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
table := NewTable(reflect.TypeOf(ddata[0]))
|
tw.table = NewTable(reflect.TypeOf(ddata[0]))
|
||||||
table.Lock()
|
tw.table.Lock()
|
||||||
dq := table.Data().(*[]dtype)
|
dq := tw.table.Data().(*[]dtype)
|
||||||
*dq = ddata
|
*dq = ddata
|
||||||
table.Unlock()
|
tw.table.Unlock()
|
||||||
t.Append("Table", table)
|
tw.t.Append("Table", tw.table)
|
||||||
b := NewButton("There")
|
tw.b = NewButton("There")
|
||||||
if *closeOnClick {
|
if *closeOnClick {
|
||||||
b.SetText("Click to Close")
|
tw.b.SetText("Click to Close")
|
||||||
}
|
}
|
||||||
// GTK+ TODO: this is causing a resize event to happen afterward?!
|
// GTK+ TODO: this is causing a resize event to happen afterward?!
|
||||||
b.OnClicked(func() {
|
tw.b.OnClicked(func() {
|
||||||
println("in OnClicked()")
|
println("in OnClicked()")
|
||||||
if *closeOnClick {
|
if *closeOnClick {
|
||||||
w.Close()
|
tw.w.Close()
|
||||||
Stop()
|
Stop()
|
||||||
done <- struct{}{}
|
done <- struct{}{}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
t.Append("Button", b)
|
tw.t.Append("Button", tw.b)
|
||||||
c := NewCheckbox("You Should Now See Me Instead")
|
tw.c = NewCheckbox("You Should Now See Me Instead")
|
||||||
c.OnClicked(func() {
|
tw.c.OnClicked(func() {
|
||||||
w.SetTitle(fmt.Sprint(c.Checked()))
|
tw.w.SetTitle(fmt.Sprint(tw.c.Checked()))
|
||||||
})
|
|
||||||
t.Append("Checkbox", c)
|
|
||||||
e := NewTextField()
|
|
||||||
t.Append("Text Field", e)
|
|
||||||
e = NewPasswordField()
|
|
||||||
t.Append("Password Field", e)
|
|
||||||
w.Show()
|
|
||||||
})
|
})
|
||||||
|
tw.t.Append("Checkbox", tw.c)
|
||||||
|
tw.e = NewTextField()
|
||||||
|
tw.t.Append("Text Field", tw.e)
|
||||||
|
tw.e2 = NewPasswordField()
|
||||||
|
tw.t.Append("Password Field", tw.e)
|
||||||
|
tw.w.Show()
|
||||||
|
}
|
||||||
|
|
||||||
|
// because Cocoa hates being run off the main thread, even if it's run exclusively off the main thread
|
||||||
|
func init() {
|
||||||
|
flag.BoolVar(&spaced, "spaced", false, "enable spacing")
|
||||||
|
flag.Parse()
|
||||||
|
go func() {
|
||||||
|
tw := new(testwin)
|
||||||
|
done := make(chan struct{})
|
||||||
|
Do(func() { tw.make(done) })
|
||||||
<-done
|
<-done
|
||||||
}()
|
}()
|
||||||
err := Go()
|
err := Go()
|
||||||
|
|
Loading…
Reference in New Issue