start an Entries map

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-27 16:27:43 -07:00
parent 7ada34f221
commit 9453772d63
3 changed files with 72 additions and 62 deletions

View File

@ -13,24 +13,20 @@ func makeSplashArea() *ui.Area {
Data.fontButton = CreateFontButton("SplashFont", "DONE")
makeAttributedString()
splashArea := ui.NewArea(myAH)
Data.splashArea = ui.NewArea(myAH)
// create a 'fake' button entry for the mouse clicks
var newmap ButtonMap
newmap.Action = "AREA"
newmap.A = splashArea
newmap.A = Data.splashArea
myAH.button = &newmap
Data.AllButtons = append(Data.AllButtons, newmap)
Data.splashArea = splashArea
if (Data.Debug) {
spew.Dump(Data.splashArea)
log.Println("DEBUGGING", Data.Debug)
} else {
log.Println("NOT DEBUGGING AREA mhAH.button =", myAH.button)
log.Println("NOT DEBUGGING AREA mhAH.button =", myAH.button)
log.Println("NOT DEBUGGING AREA mhAH.button =", myAH.button)
}
return Data.splashArea
}

View File

@ -279,46 +279,59 @@ func AddVmConfigureTab(name string, pbVM *pb.Event_VM) {
}
// makeEntryBox(box, "hostname:", "blah.foo.org") {
func makeEntryVbox(hbox *ui.Box, a string, b string, edit bool) {
func makeEntryVbox(hbox *ui.Box, a string, startValue string, edit bool, action string) {
// Start 'Nickname' vertical box
vboxN := ui.NewVerticalBox()
vboxN.SetPadded(true)
vboxN.Append(ui.NewLabel(a), false)
entryNick := ui.NewEntry()
entryNick.SetText(b)
if (edit == false) {
entryNick.SetReadOnly(true)
}
entryNick := defaultMakeEntry(startValue, edit, action)
vboxN.Append(entryNick, false)
entryNick.OnChanged(func(*ui.Entry) {
log.Println("OK. TEXT WAS CHANGED TO =", entryNick.Text())
// Data.AccNick = entryNick.Text()
})
hbox.Append(vboxN, false)
// End 'Nickname' vertical box
}
func makeEntryHbox(hbox *ui.Box, a string, b string, edit bool) {
func defaultEntryChange(e *ui.Entry) {
for key, foo := range Data.AllEntries {
if (Data.Debug) {
log.Println("\tdefaultEntryChange() Data.AllEntries =", key, foo)
}
if Data.AllEntries[key].E == e {
log.Println("defaultEntryChange() FOUND", "action =", Data.AllEntries[key].Action, "e.Text() =", e.Text())
return
}
}
log.Println("defaultEntryChange() ERROR. MISSING ENTRY MAP. e.Text() =", e.Text())
}
func defaultMakeEntry(startValue string, edit bool, action string) *ui.Entry {
e := ui.NewEntry()
e.SetText(startValue)
if (edit == false) {
e.SetReadOnly(true)
}
e.OnChanged(defaultEntryChange)
// add the entry field to the global map
var newEntryMap EntryMap
newEntryMap.E = e
newEntryMap.Edit = edit
newEntryMap.Action = action
Data.AllEntries = append(Data.AllEntries, newEntryMap)
return e
}
func makeEntryHbox(hbox *ui.Box, a string, startValue string, edit bool, action string) {
// Start 'Nickname' vertical box
hboxN := ui.NewHorizontalBox()
hboxN.SetPadded(true)
hboxN.Append(ui.NewLabel(a), false)
entryNick := ui.NewEntry()
entryNick.SetText(b)
if (edit == false) {
entryNick.SetReadOnly(true)
}
entryNick := defaultMakeEntry(startValue, edit, action)
hboxN.Append(entryNick, false)
entryNick.OnChanged(func(*ui.Entry) {
log.Println("OK. TEXT WAS CHANGED TO =", entryNick.Text())
// Data.AccNick = entryNick.Text()
})
hbox.Append(hboxN, false)
// End 'Nickname' vertical box
}
@ -343,12 +356,12 @@ func CreateVmBox(tab *ui.Tab, vm *pb.Event_VM) {
vbox.Append(hboxAccount, false)
// Add hostname entry box
makeEntryVbox(hboxAccount, "hostname:", vm.Hostname, true)
makeEntryVbox(hboxAccount, "IPv6:", vm.IPv6, true)
makeEntryVbox(hboxAccount, "RAM:", fmt.Sprintf("%d",vm.Memory), true)
makeEntryVbox(hboxAccount, "CPU:", fmt.Sprintf("%d",vm.Cpus), true)
makeEntryVbox(hboxAccount, "Disk (GB):", fmt.Sprintf("%d",vm.Disk), true)
makeEntryVbox(hboxAccount, "OS Image:", vm.BaseImage, true)
makeEntryVbox(hboxAccount, "hostname:", vm.Hostname, true, "Hostname")
makeEntryVbox(hboxAccount, "IPv6:", vm.IPv6, true, "IPv6")
makeEntryVbox(hboxAccount, "RAM:", fmt.Sprintf("%d",vm.Memory), true, "Memory")
makeEntryVbox(hboxAccount, "CPU:", fmt.Sprintf("%d",vm.Cpus), true, "Cpus")
makeEntryVbox(hboxAccount, "Disk (GB):",fmt.Sprintf("%d",vm.Disk), true, "Disk")
makeEntryVbox(hboxAccount, "OS Image:", vm.BaseImage, true, "BaseImage")
vbox.Append(ui.NewHorizontalSeparator(), false)
@ -379,7 +392,7 @@ func createAddVmBox(tab *ui.Tab, name string, b *ButtonMap) {
vbox.Append(hboxAccount, false)
// Add hostname entry box
makeEntryHbox(hboxAccount, "hostname:", "", true)
makeEntryHbox(hboxAccount, "hostname:", "", true, "Hostname")
vbox.Append(ui.NewHorizontalSeparator(), false)

View File

@ -15,24 +15,6 @@ import pb "git.wit.com/wit/witProtobuf"
var Data GuiDataStructure
var myAH areaHandler
/*
type GuiTabStructure struct {
me *ui.Tab
parentWindow *ui.Window
firstBox *ui.Box
tabOffset int
// this means only one table per tab
mh *TableData
// stuff for the 'area'
// this means only one area per tab
fontButton *ui.FontButton
attrstr *ui.AttributedString
splashArea *ui.Area
}
*/
type GuiDataStructure struct {
State string
Width int
@ -42,7 +24,10 @@ type GuiDataStructure struct {
// if nothing else is defined to handle them
MouseClick func(*ButtonMap)
// general information
// account entry textboxes
Config *pb.Config
// general information on the App
Version string
GitCommit string
GoVersion string
@ -55,22 +40,19 @@ type GuiDataStructure struct {
Hostname string
IPv6 string
// account entry textboxes
Config *pb.Config
// A map of all buttons everywhere on all
// windows, all tabs, across all goroutines
// This is "GLOBAL"
AllButtons []ButtonMap
// A map of all the entry boxes
AllEntries []EntryMap
// a VM (maybe the one the user is playing with?)
// if opening a new window, this is a trick to
// pass it in
CurrentVM *pb.Event_VM
// All the tabs
// Tabs []GuiTabStructure
EntryNick *ui.Entry
EntryUser *ui.Entry
EntryPass *ui.Entry
@ -81,8 +63,8 @@ type GuiDataStructure struct {
cloudBox *ui.Box
smallBox *ui.Box
mainwin *ui.Window
maintab *ui.Tab
// mainwin *ui.Window
// maintab *ui.Tab
tabcount int
// stuff for the 'area'
@ -99,6 +81,25 @@ type TableColumnData struct {
Color string
}
type EntryMap struct {
E *ui.Entry
Edit bool
Account *pb.Account
VM *pb.Event_VM
B *ui.Button
FB *ui.FontButton
A *ui.Area
W *ui.Window
T *ui.Tab
Action string // what type of button
// custom callback function to your main application
custom func (*EntryMap)
}
type ButtonMap struct {
B *ui.Button
FB *ui.FontButton