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
|
package main
import (
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
"git.wit.org/wit/gui/toolkit"
)
func (t *andlabsT) newDropdown(w *toolkit.Widget) *andlabsT {
var newt andlabsT
log(debugToolkit, "gui.Toolbox.newDropdown() START", w.Name)
if t.broken() {
return nil
}
newt.tw = w
s := ui.NewCombobox()
newt.uiCombobox = s
newt.uiBox = t.uiBox
t.uiBox.Append(s, stretchy)
// initialize the index
newt.c = 0
newt.val = make(map[int]string)
s.OnSelected(func(spin *ui.Combobox) {
i := spin.Selected()
if (newt.val == nil) {
log(debugChange, "make map didn't work")
newt.text = "error"
}
newt.tw.S = newt.val[i]
newt.commonChange(newt.tw)
})
return &newt
}
func (t *andlabsT) AddDropdownName(title string) {
t.uiCombobox.Append(title)
if (t.val == nil) {
log(debugToolkit, "make map didn't work")
return
}
t.val[t.c] = title
// If this is the first menu added, set the dropdown to it
if (t.c == 0) {
log(debugChange, "THIS IS THE FIRST Dropdown", title)
t.uiCombobox.SetSelected(0)
}
t.c = t.c + 1
}
func (t *andlabsT) SetDropdown(i int) {
t.uiCombobox.SetSelected(i)
}
func AddDropdownName(w *toolkit.Widget, s string) {
log(debugToolkit, "gui.andlabs.AddDropdownName()", w.Name, "add:", s)
t := mapToolkits[w]
if (t == nil) {
log(debugToolkit, "go.andlabs.AddDropdownName() toolkit struct == nil. name=", w.Name, s)
listMap(debugToolkit)
return
}
t.AddDropdownName(s)
}
func SetDropdownName(w *toolkit.Widget, s string) {
log(debugChange, "gui.andlabs.SetDropdown()", w.Name, ",", s)
t := mapToolkits[w]
if (t == nil) {
log(debugError, "ERROR: SetDropdown() FAILED mapToolkits[w] == nil. name=", w.Name, s)
listMap(debugError)
return
}
t.SetDropdown(1)
t.tw.S = s
}
func newDropdown(parentW *toolkit.Widget, w *toolkit.Widget) {
log(debugToolkit, "gui.andlabs.newDropdown()", w.Name)
t := mapToolkits[parentW]
if (t == nil) {
log(debugToolkit, "go.andlabs.newDropdown() toolkit struct == nil. name=", parentW.Name, w.Name)
listMap(debugToolkit)
return
}
newt := t.newDropdown(w)
mapWidgetsToolkits(w, newt)
}
func doDropdown(p *toolkit.Widget, c *toolkit.Widget) {
if broken(c) {
return
}
if (c.Action == "New") {
newDropdown(p, c)
return
}
ct := mapToolkits[c]
if (ct == nil) {
log(debugError, "Trying to do something on a widget that doesn't work or doesn't exist or something", c)
return
}
if ct.broken() {
log(debugError, "Dropdown() ct.broken", ct)
return
}
if (ct.uiCombobox == nil) {
log(debugError, "Dropdown() uiCombobox == nil", ct)
return
}
log(debugChange, "Going to attempt:", c.Action)
switch c.Action {
case "Add":
ct.AddDropdownName(c.S)
// ct.uiCombobox.Enable()
case "Enable":
ct.uiCombobox.Enable()
case "Disable":
ct.uiCombobox.Disable()
case "Show":
ct.uiCombobox.Show()
case "Hide":
ct.uiCombobox.Hide()
case "Set":
ct.uiCombobox.SetSelected(1)
case "SetText":
var orig int
var i int = -1
var s string
orig = ct.uiCombobox.Selected()
log(debugError, "TODO: set a Dropdown by the name selected =", orig, ct.c, c.S)
// try to find the string
for i, s = range ct.val {
log(debugError, "i, s", i, s)
if (c.S == s) {
ct.uiCombobox.SetSelected(i)
return
}
}
// if i == -1, then there are not any things in the menu to select
if (i == -1) {
return
}
// if the string was never set, then set the dropdown to the last thing added to the menu
if (orig == -1) {
ct.uiCombobox.SetSelected(i)
}
default:
log(debugError, "Can't do", c.Action, "to a Dropdown")
}
}
|