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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
|
package gui
import "log"
import "fmt"
import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"
import pb "git.wit.com/wit/witProtobuf"
import "github.com/davecgh/go-spew/spew"
// THIS IS CLEAN (all that is left is the 'ADD VM')
func InitColumns(mh *TableData, parts []TableColumnData) {
tmpBTindex := 0
humanID := 0
for key, foo := range parts {
log.Println("key, foo =", key, foo)
parts[key].Index = humanID
humanID += 1
if (foo.CellType == "BG") {
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableColor{})
initRowBTcolor (mh, tmpBTindex, parts[key])
tmpBTindex += 1
} else if (foo.CellType == "BUTTON") {
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString(""))
initRowButtonColumn (mh, tmpBTindex, parts[key].Heading, parts[key])
tmpBTindex += 1
} else if (foo.CellType == "TEXTCOLOR") {
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString(""))
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableColor{})
initRowTextColorColumn(mh, tmpBTindex, tmpBTindex + 1, parts[key].Heading, ui.TableColor{0.0, 0, 0.9, 1}, parts[key])
tmpBTindex += 2
} else if (foo.CellType == "TEXT") {
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString(""))
initRowTextColumn (mh, tmpBTindex, parts[key].Heading, parts[key])
tmpBTindex += 1
} else {
panic("I don't know what this is in initColumnNames")
}
}
}
func AddTableTab(gw *GuiWindow, name string, rowcount int, parts []TableColumnData, account *pb.Account) *TableData {
mh := new(TableData)
mh.RowCount = rowcount
mh.Rows = make([]RowData, mh.RowCount)
InitColumns(mh, parts)
model := ui.NewTableModel(mh)
table := ui.NewTable(
&ui.TableParams{
Model: model,
RowBackgroundColorModelColumn: 0, // Row Background color is always index zero
})
tmpBTindex := 0
for key, foo := range parts {
log.Println(key, foo)
if (foo.CellType == "BG") {
} else if (foo.CellType == "BUTTON") {
tmpBTindex += 1
table.AppendButtonColumn(foo.Heading, tmpBTindex, ui.TableModelColumnAlwaysEditable)
} else if (foo.CellType == "TEXTCOLOR") {
tmpBTindex += 1
table.AppendTextColumn(foo.Heading, tmpBTindex, ui.TableModelColumnAlwaysEditable,
&ui.TableTextColumnOptionalParams{
ColorModelColumn: tmpBTindex + 1,
});
tmpBTindex += 1
} else if (foo.CellType == "TEXT") {
tmpBTindex += 1
table.AppendTextColumn(foo.Heading, tmpBTindex, ui.TableModelColumnAlwaysEditable, nil)
} else {
panic("I don't know what this is in initColumnNames")
}
}
var gb *GuiBox
gb = new(GuiBox)
gb.EntryMap = make(map[string]*GuiEntry)
gb.EntryMap["test"] = nil
vbox := ui.NewVerticalBox()
vbox.SetPadded(true)
gb.UiBox = vbox
gb.Window = gw
gw.BoxMap[name] = gb
mh.Box = gb
vbox.Append(table, true)
gw.UiTab.Append(name, vbox)
vbox.Append(ui.NewVerticalSeparator(), false)
hbox := ui.NewHorizontalBox()
hbox.SetPadded(true)
vbox.Append(hbox, false)
return mh
}
func MessageWindow(gw *GuiWindow, msg1 string, msg2 string) {
ui.MsgBox(gw.UiWindow, msg1, msg2)
}
func ErrorWindow(gw *GuiWindow, msg1 string, msg2 string) {
ui.MsgBoxError(gw.UiWindow, msg1, msg2)
}
// This is the default mouse click handler
// Every mouse click that hasn't been assigned to
// something specific will fall into this routine
// By default, all it runs is the call back to
// the main program that is using this library
//
// This routine MUST be here as this is how the andlabs/ui works
// This is the raw routine passed to every button in andlabs libui / ui
//
// There is a []GuiButton which has all the buttons. We search
// for the button and then call the function below
//
func defaultButtonClick(button *ui.Button) {
log.Println("defaultButtonClick() LOOK FOR BUTTON button =", button)
for key, foo := range Data.AllButtons {
if (Data.Debug) {
log.Println("defaultButtonClick() Data.AllButtons =", key, foo)
// spew.Dump(foo)
}
if Data.AllButtons[key].B == button {
log.Println("\tdefaultButtonClick() BUTTON MATCHED")
log.Println("\tdefaultButtonClick() Data.AllButtons[key].Action =", Data.AllButtons[key].Action)
if Data.AllButtons[key].custom != nil {
log.Println("\tdefaultButtonClick() DOING CUSTOM FUNCTION")
Data.AllButtons[key].custom(Data.AllButtons[key])
return
}
if (Data.MouseClick != nil) {
Data.MouseClick(Data.AllButtons[key])
} else {
log.Println("\tdefaultButtonClick() IGNORING BUTTON. MouseClick() is nil")
}
return
}
}
log.Println("\tdefaultButtonClick() BUTTON NOT FOUND")
if (Data.Debug) {
panic("defaultButtonClick() SHOULD NOT HAVE UNMAPPED BUTTONS")
}
}
func AddButton(b *GuiButton, name string) *ui.Button {
newB := ui.NewButton(name)
newB.OnClicked(defaultButtonClick)
b.B = newB
Data.AllButtons = append(Data.AllButtons, b)
return newB
}
func AddButtonToBox(box *GuiBox, button *GuiButton) {
box.UiBox.Append(button.B, false)
}
func CreateButton(box *GuiBox, a *pb.Account, vm *pb.Event_VM, name string, action string, custom func(*GuiButton)) *GuiButton {
newUiB := ui.NewButton(name)
newUiB.OnClicked(defaultButtonClick)
var newB *GuiButton
newB = new(GuiButton)
newB.B = newUiB
if (box.Window == nil) {
log.Println("CreateButton() box.Window == nil")
panic("crap")
}
newB.GW = box.Window
newB.Account = a
newB.VM = vm
newB.Box = box
newB.Action = action
newB.custom = custom
Data.AllButtons = append(Data.AllButtons, newB)
return newB
}
func CreateFontButton(box *GuiBox, action string) *GuiButton {
// create a 'fake' button entry for the mouse clicks
var newGB GuiButton
newGB.Action = action
newGB.FB = ui.NewFontButton()
newGB.Box = box
newGB.Area = box.Area
Data.AllButtons = append(Data.AllButtons, &newGB)
newGB.FB.OnChanged(func (*ui.FontButton) {
log.Println("FontButton.OnChanged() START mouseClick(&newBM)", newGB)
if (Data.MouseClick != nil) {
Data.MouseClick(&newGB)
}
})
return &newGB
}
func GetText(box *GuiBox, name string) string {
if (box == nil) {
log.Println("gui.GetText() ERROR box == nil")
return ""
}
if (box.EntryMap == nil) {
log.Println("gui.GetText() ERROR b.Box.EntryMap == nil")
return ""
}
spew.Dump(box.EntryMap)
if (box.EntryMap[name] == nil) {
log.Println("gui.GetText() ERROR box.EntryMap[", name, "] == nil ")
return ""
}
e := box.EntryMap[name]
log.Println("gui.GetText() box.EntryMap[", name, "] = ", e.UiEntry.Text())
log.Println("gui.GetText() END")
return e.UiEntry.Text()
}
func SetText(box *GuiBox, name string, value string) error {
if (box == nil) {
return fmt.Errorf("gui.SetText() ERROR box == nil")
}
if (box.EntryMap == nil) {
return fmt.Errorf("gui.SetText() ERROR b.Box.EntryMap == nil")
}
spew.Dump(box.EntryMap)
if (box.EntryMap[name] == nil) {
return fmt.Errorf("gui.SetText() ERROR box.EntryMap[", name, "] == nil ")
}
e := box.EntryMap[name]
log.Println("gui.SetText() box.EntryMap[", name, "] = ", e.UiEntry.Text())
e.UiEntry.SetText(value)
log.Println("gui.SetText() box.EntryMap[", name, "] = ", e.UiEntry.Text())
log.Println("gui.SetText() END")
return nil
}
// makeEntryBox(box, "hostname:", "blah.foo.org") {
func MakeEntryVbox(box *GuiBox, a string, startValue string, edit bool, action string) *GuiEntry {
// Start 'Nickname' vertical box
vboxN := ui.NewVerticalBox()
vboxN.SetPadded(true)
vboxN.Append(ui.NewLabel(a), false)
e := defaultMakeEntry(startValue, edit, action)
vboxN.Append(e.UiEntry, false)
box.UiBox.Append(vboxN, false)
// End 'Nickname' vertical box
return e
}
func MakeEntryHbox(box *GuiBox, a string, startValue string, edit bool, action string) *GuiEntry {
// Start 'Nickname' vertical box
hboxN := ui.NewHorizontalBox()
hboxN.SetPadded(true)
hboxN.Append(ui.NewLabel(a), false)
e := defaultMakeEntry(startValue, edit, action)
hboxN.Append(e.UiEntry, false)
box.UiBox.Append(hboxN, false)
// End 'Nickname' vertical box
return e
}
func NewLabel(box *GuiBox, text string) {
box.UiBox.Append(ui.NewLabel(text), false)
}
func AddEntry(box *GuiBox, name string) *GuiEntry {
var ge *GuiEntry
ge = new(GuiEntry)
ue := ui.NewEntry()
ue.SetReadOnly(false)
ue.OnChanged(func(*ui.Entry) {
log.Println("gui.AddEntry() OK. ue.Text() =", ue.Text())
})
box.UiBox.Append(ue, false)
ge.UiEntry = ue
box.EntryMap[name] = ge
return ge
}
func HardHorizontalBreak(box *GuiBox) {
log.Println("HardHorizontalBreak START")
gw := box.Window
mainbox := gw.mainbox
tmp := ui.NewHorizontalSeparator()
mainbox.Append(tmp, false)
hbox := ui.NewVerticalBox()
hbox.SetPadded(true)
box.UiBox = hbox
mainbox.Append(hbox, true)
log.Println("HardHorizontalBreak END")
}
func HardVerticalBreak(box *GuiBox) {
log.Println("HardVerticalBreak START")
gw := box.Window
mainbox := gw.mainbox
tmp := ui.NewVerticalSeparator()
mainbox.Append(tmp, false)
hbox := ui.NewVerticalBox()
hbox.SetPadded(true)
box.UiBox = hbox
mainbox.Append(hbox, false)
log.Println("HardVerticalBreak END")
}
func HorizontalBreak(box *GuiBox) {
tmp := ui.NewHorizontalSeparator()
box.UiBox.Append(tmp, false)
}
func VerticalBreak(box *GuiBox) {
tmp := ui.NewVerticalSeparator()
box.UiBox.Append(tmp, false)
}
func AddGenericBox(gw *GuiWindow) *GuiBox {
var gb *GuiBox
gb = new(GuiBox)
gb.EntryMap = make(map[string]*GuiEntry)
gb.EntryMap["test"] = nil
vbox := ui.NewVerticalBox()
vbox.SetPadded(true)
// gw.Box1 = vbox
gb.UiBox = vbox
gb.Window = gw
hbox := ui.NewHorizontalBox()
hbox.SetPadded(true)
vbox.Append(hbox, false)
return gb
}
func CreateGenericBox(gw *GuiWindow, b *GuiButton, name string) *GuiBox{
log.Println("CreateAddVmBox() START name =", name)
var box *GuiBox
box = new(GuiBox)
vbox := ui.NewVerticalBox()
vbox.SetPadded(true)
box.UiBox = vbox
box.Window = gw
gw.BoxMap["ADD VM" + name] = box
hbox := ui.NewHorizontalBox()
hbox.SetPadded(true)
vbox.Append(hbox, false)
AddBoxToTab(name, gw.UiTab, vbox)
return box
}
func CreateBox(gw *GuiWindow, name string) *GuiBox {
log.Println("CreateVmBox() START")
log.Println("CreateVmBox() vm.Name =", name)
log.Println("CreateVmBox() gw =", gw)
var box *GuiBox
box = new(GuiBox)
vbox := ui.NewVerticalBox()
vbox.SetPadded(true)
log.Println("CreateVmBox() vbox =", vbox)
log.Println("CreateVmBox() box.UiBox =", box.UiBox)
box.UiBox = vbox
log.Println("CreateVmBox() box.Window =", box.Window)
box.Window = gw
log.Println("CreateVmBox() gw.BoxMap =", gw.BoxMap)
gw.BoxMap[name] = box
hboxAccount := ui.NewHorizontalBox()
hboxAccount.SetPadded(true)
vbox.Append(hboxAccount, false)
box.UiBox = hboxAccount
AddBoxToTab(name, gw.UiTab, vbox)
return box
}
|