summaryrefslogtreecommitdiff
path: root/redo/zz_test.go
blob: 1d23f35392b55025885955b24f7aee00eca819ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// 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 (
	"fmt"
	"flag"
	"reflect"
	"testing"
)

var closeOnClick = flag.Bool("close", false, "close on click")

type dtype struct {
	Name	string
	Address	string
}
var ddata = []dtype{
	{ "alpha", "beta" },
	{ "gamma", "delta" },
	{ "epsilon", "zeta" },
	{ "eta", "theta" },
	{ "iota", "kappa" },
}

// 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() {
		done := make(chan struct{})
		Do(func() {
			t := NewTab()
			w := NewWindow("Hello", 320, 240, t)
			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
			})
			table := NewTable(reflect.TypeOf(ddata[0]))
			table.Lock()
			dq := table.Data().(*[]dtype)
			*dq = ddata
			table.Unlock()
			t.Append("Table", table)
			b := NewButton("There")
			if *closeOnClick {
				b.SetText("Click to Close")
			}
			// GTK+ TODO: this is causing a resize event to happen afterward?!
			b.OnClicked(func() {
				println("in OnClicked()")
				if *closeOnClick {
					w.Close()
					Stop()
					done <- struct{}{}
				}
			})
			t.Append("Button", b)
			c := NewCheckbox("You Should Now See Me Instead")
			c.OnClicked(func() {
				w.SetTitle(fmt.Sprint(c.Checked()))
			})
			t.Append("Checkbox", c)
			e := NewTextField()
			t.Append("Text Field", e)
			e = NewPasswordField()
			t.Append("Password Field", e)
			w.Show()
		})
		<-done
	}()
	err := Go()
	if err != nil {
		panic(err)
	}
}

func TestDummy(t *testing.T) {
	// do nothing
}