summaryrefslogtreecommitdiff
path: root/choices.go
blob: 0b52464c621c2648754f6acd2abbc7d8e8f13798 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// This creates a simple hello world window
package main

import (
	"math/rand"
	"time"

	"go.wit.com/gui"
	"go.wit.com/lib/gadgets"
	"go.wit.com/log"
)

type choices struct {
	group     *gui.Node // the group
	grid      *gui.Node // the grid
	hello     *gui.Node // the hello button
	computers *gui.Node
	colors    *gui.Node
	checkers  *gui.Node

	socks  *gadgets.OneLiner
	animal *gadgets.BasicCombobox
	place  *gadgets.BasicEntry
}

// This initializes the first window and some widgets
func newChoices(parent *gui.Node) *choices {
	var c *choices
	c = new(choices)
	c.group = parent.NewGroup("choices")
	c.grid = c.group.NewGrid("gridiron", 8, 1)

	c.grid.NewButton("hello", func() {
		log.Info("world")
	})
	c.grid.NewButton("toggle basic window", func() {
		basicWindow.Toggle()
	})
	c.grid.NewLabel("a label")
	c.grid.NextRow()

	c.computers = c.grid.NewDropdown().SetProgName("COMPUTERS")
	c.computers.AddText("Atari 500")
	c.computers.AddText("Beagleboard")
	c.computers.AddText("Unmatched Rev B")
	c.computers.SetText("Beagleboard")
	c.computers.Custom = func() {
		log.Info("You changed the computer to:", c.computers.String())
	}
	c.grid.NewButton("modify dropdown state", func() {
		c.computers.AddText("Irix")
		c.computers.AddText("Macintosh Plus")
		c.computers.SetText("Irix")

		rand.Seed(time.Now().UnixNano())
		// Generate a random number between 0 and 25
		randomNum := rand.Intn(8) // 26 because Intn is [0, n)
		// Convert to a corresponding uppercase letter
		randomLetter := rune('A' + randomNum)
		c.computers.AddText("WIT " + string(randomLetter))
		c.showState()
	})
	c.grid.NewButton("toggle", func() {
		if c.computers.Hidden() {
			c.computers.Show()
		} else {
			c.computers.Hide()
		}
	})
	c.grid.NewButton("dropdown state", func() {
		c.showState()
	})
	c.grid.NextRow()

	c.colors = c.grid.NewCombobox().SetProgName("COLORS")
	c.colors.AddText("Cyan")
	c.colors.AddText("Magenta")
	c.colors.AddText("Yellow")
	c.colors.SetText("orange")
	c.grid.NewButton("modify combobox state", func() {
		c.colors.AddText("Red")
		rand.Seed(time.Now().UnixNano())
		// Generate a random number between 0 and 25
		randomNum := rand.Intn(26) // 26 because Intn is [0, n)
		// Convert to a corresponding uppercase letter
		randomLetter := rune('A' + randomNum)
		c.colors.AddText("Yellow " + string(randomLetter))

		c.colors.SetText("blue")
		log.Info("color value =", c.colors.String())
	})
	c.grid.NewButton("toggle", func() {
		if c.colors.Hidden() {
			c.colors.Show()
		} else {
			c.colors.Hide()
		}
	})
	c.grid.NewButton("show state", func() {
		c.showState()
	})
	c.grid.NextRow()

	c.checkers = c.grid.NewCheckbox("Checkers").SetProgName("CHECKERS")
	c.checkers.Custom = func() {
		log.Info("Checkers is", c.checkers.Bool())
	}
	c.grid.NextRow()

	c.socks = gadgets.NewOneLiner(c.grid, "two for one")
	c.socks.SetValue("socks")
	c.grid.NextRow()

	c.animal = gadgets.NewBasicCombobox(c.grid, "animals")
	c.animal.AddText("otter")
	c.animal.AddText("honey badger")
	c.animal.AddText("polar bear")
	c.grid.NextRow()

	c.place = gadgets.NewBasicEntry(c.grid, "favorite place")
	c.place.Custom = func() {
		log.Info("now set to:", c.place.String())
		if c.place == section1.place {
			section2.place.SetText(c.place.String())
		}
		if c.place == section2.place {
			section1.place.SetText(c.place.String())
		}
	}
	c.place.SetText("coffee shop")
	c.grid.NextRow()

	c.grid.NewButton("enable animals", func() {
		c.animal.Enable()
	})
	c.grid.NewButton("disable animals", func() {
		c.animal.Disable()
	})
	c.grid.NewButton("set trust", func() {
		c.place.SetText("trust")
	})

	return c
}

func (c *choices) SetSocks(s string) *choices {
	c.socks.SetValue(s)
	return c
}

func (c *choices) showState() {
	log.Info("computers value =", c.computers.String())
	for i, s := range c.computers.Strings() {
		log.Println("computers has:", i, s)
	}
	log.Info("color value =", c.colors.String())
	for i, s := range c.colors.Strings() {
		log.Println("has option", i, s)
	}
}