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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
package main
import (
"strconv"
"go.wit.com/dev/andlabs/ui"
"go.wit.com/log"
"go.wit.com/gui/widget"
)
func (n *node) ready() bool {
if n == nil { return false }
if n.tk == nil { return false }
return true
}
func (n *node) show(b bool) {
if n.tk == nil {
return
}
if n.tk.uiControl == nil {
return
}
if (b) {
n.tk.uiControl.Show()
} else {
n.tk.uiControl.Hide()
}
}
func (n *node) enable(b bool) {
if n == nil {
panic("WHAT? enable was passed nil. How does this even happen?")
}
if n.tk == nil {
return
}
if n.tk.uiControl == nil {
return
}
if (b) {
n.tk.uiControl.Enable()
} else {
n.tk.uiControl.Disable()
}
}
func (n *node) pad(b bool) {
log.Warn("pad() on WidgetId =", n.WidgetId)
t := n.tk
if (t == nil) {
log.Log(ERROR, "pad() toolkit struct == nil. for", n.WidgetId)
return
}
switch n.WidgetType {
case widget.Window:
t.uiWindow.SetMargined(b)
t.uiWindow.SetBorderless(b)
case widget.Tab:
tabSetMargined(t.uiTab, b)
case widget.Group:
t.uiGroup.SetMargined(b)
case widget.Grid:
t.uiGrid.SetPadded(b)
case widget.Box:
t.uiBox.SetPadded(b)
default:
log.Log(ERROR, "TODO: implement pad() for", n.WidgetType, n.progname)
}
}
func (n *node) move(newParent *node) {
p := n.parent
switch p.WidgetType {
case widget.Group:
case widget.Tab:
// tabSetMargined(tParent.uiTab, true)
case widget.Window:
// t.uiWindow.SetBorderless(false)
case widget.Grid:
// t.uiGrid.SetPadded(true)
case widget.Box:
log.Log(INFO, "TODO: move() where =", p.ParentId)
log.Log(INFO, "TODO: move() for widget =", n.WidgetId)
stretchy = true
if (p.tk.uiBox != nil) {
p.tk.uiBox.Append(n.tk.uiControl, stretchy)
}
default:
log.Log(ERROR, "TODO: need to implement move() for type =", n.WidgetType)
log.Log(ERROR, "TODO: need to implement move() for where =", p.ParentId)
log.Log(ERROR, "TODO: need to implement move() for widget =", n.WidgetId)
}
}
func (n *node) Delete() {
p := n.parent
log.Log(NOW, "uiDelete()", n.WidgetId, "to", p.WidgetId)
if n.WidgetType == widget.Window {
log.Warn("DESTROY uiWindow here")
log.Warn("NEED TO REMOVE n from parent.Children")
n.tk.uiWindow.Destroy()
n.tk.uiWindow = nil
for i, child := range p.children {
log.Warn("parent has child:", i, child.WidgetId, child.progname)
if n == child {
log.Warn("Found child ==", i, child.WidgetId, child.progname)
log.Warn("Found n ==", i, n.WidgetId, n.progname)
p.children = append(p.children[:i], p.children[i+1:]...)
}
// t.uiWindow.SetBorderless(false)
}
for i, child := range p.children {
log.Warn("parent now has child:", i, child.WidgetId, child.progname)
}
return
}
switch p.WidgetType {
case widget.Group:
// tParent.uiGroup.SetMargined(true)
case widget.Tab:
// tabSetMargined(tParent.uiTab, true)
case widget.Window:
case widget.Grid:
// t.uiGrid.SetPadded(true)
case widget.Box:
log.Log(NOW, "tWidget.boxC =", p.progname)
log.Log(NOW, "is there a tParent parent? =", p.parent)
if (p.tk.boxC < 1) {
log.Log(NOW, "Can not delete from Box. already empty. tWidget.boxC =", p.tk.boxC)
return
}
p.tk.uiBox.Delete(0)
p.tk.boxC -= 1
// this didn't work:
// tWidget.uiControl.Disable()
// sleep(.8)
// tParent.uiBox.Append(tWidget.uiControl, stretchy)
default:
log.Log(ERROR, "TODO: need to implement uiDelete() for widget =", n.WidgetId, n.WidgetType)
log.Log(ERROR, "TODO: need to implement uiDelete() for parent =", p.WidgetId, p.WidgetType)
}
}
func rawAction(a *widget.Action) {
log.Log(INFO, "rawAction() START a.ActionType =", a.ActionType, "a.Value", a.Value)
if (a.ActionType == widget.InitToolkit) {
// TODO: make sure to only do this once
// go uiMain.Do(func() {
// ui.Main(demoUI)
// go catchActionChannel()
// })
// try doing this on toolkit load in init()
return
}
log.Log(INFO, "rawAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId)
switch a.WidgetType {
case widget.Flag:
log.Log(ERROR, "rawAction() RE-IMPLEMENT LOG FLAGS")
return
}
n := me.rootNode.findWidgetId(a.WidgetId)
if (a.ActionType == widget.Add) {
ui.QueueMain(func() {
add(a)
})
// TODO: remove this artificial delay
// sleep(.001)
return
}
if (a.ActionType == widget.Dump) {
log.Log(NOW, "rawAction() Dump =", a.ActionType, a.WidgetType, n.progname)
me.rootNode.listChildren(true)
return
}
if (n == nil) {
me.rootNode.listChildren(true)
log.Log(NOW, "rawAction() ERROR findWidgetId found nil", a.ActionType, a.WidgetType)
log.Log(NOW, "rawAction() ERROR findWidgetId found nil for id =", a.WidgetId)
log.Log(NOW, "rawAction() ERROR findWidgetId found nil", a.ActionType, a.WidgetType)
log.Log(NOW, "rawAction() ERROR findWidgetId found nil for id =", a.WidgetId)
return
panic("findWidgetId found nil for id = " + strconv.Itoa(a.WidgetId))
}
switch a.ActionType {
case widget.Show:
n.show(true)
case widget.Hide:
n.show(false)
case widget.Enable:
n.enable(true)
case widget.Disable:
log.Warn("andlabs got disable for", n.WidgetId, n.progname)
n.enable(false)
case widget.Get:
n.setText(a)
case widget.GetText:
switch a.WidgetType {
case widget.Textbox:
a.Value = n.value
}
case widget.Set:
n.setText(a)
case widget.SetText:
n.setText(a)
case widget.AddText:
n.addText(a)
case widget.Margin:
n.pad(true)
case widget.Unmargin:
n.pad(false)
case widget.Pad:
n.pad(true)
case widget.Unpad:
n.pad(false)
case widget.Delete:
n.Delete()
case widget.Move:
log.Log(NOW, "rawAction() attempt to move() =", a.ActionType, a.WidgetType)
newParent := me.rootNode.findWidgetId(a.ParentId)
n.move(newParent)
default:
log.Log(ERROR, "rawAction() Unknown =", a.ActionType, a.WidgetType)
}
log.Log(INFO, "rawAction() END =", a.ActionType, a.WidgetType)
}
|