more cleaning

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-06-01 02:58:49 -07:00
parent c11e03c499
commit 32d07aaf5f
4 changed files with 41 additions and 110 deletions

View File

@ -75,7 +75,9 @@ func (ah GuiArea) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) {
log.Println("GOT MOUSE UP") log.Println("GOT MOUSE UP")
log.Println("GOT MOUSE UP ah.Button =", ah.Button) log.Println("GOT MOUSE UP ah.Button =", ah.Button)
log.Println("GOT MOUSE UP ah.Button.FB =", ah.Button.FB) log.Println("GOT MOUSE UP ah.Button.FB =", ah.Button.FB)
mouseClick(ah.Button) if (Data.MouseClick != nil) {
Data.MouseClick(ah.Button)
}
} }
} }

93
gui.go
View File

@ -10,7 +10,7 @@ import pb "git.wit.com/wit/witProtobuf"
import "github.com/davecgh/go-spew/spew" import "github.com/davecgh/go-spew/spew"
// THIS IS CLEAN (all that is left is the 'createAddVmBox') // THIS IS CLEAN (all that is left is the 'ADD VM')
func InitColumns(mh *TableData, parts []TableColumnData) { func InitColumns(mh *TableData, parts []TableColumnData) {
tmpBTindex := 0 tmpBTindex := 0
@ -96,16 +96,12 @@ func AddTableTab(gw *GuiWindow, name string, rowcount int, parts []TableColumnDa
vbox.Append(table, true) vbox.Append(table, true)
gw.UiTab.Append(name, vbox) gw.UiTab.Append(name, vbox)
// mytab.SetMargined(mytabcount, true)
vbox.Append(ui.NewVerticalSeparator(), false) vbox.Append(ui.NewVerticalSeparator(), false)
hbox := ui.NewHorizontalBox() hbox := ui.NewHorizontalBox()
hbox.SetPadded(true) hbox.SetPadded(true)
// a := CreateButton(gb, account, nil, "Add Virtual Machine", "createAddVmBox", nil)
// hbox.Append(a.B, false)
vbox.Append(hbox, false) vbox.Append(hbox, false)
return mh return mh
@ -124,47 +120,6 @@ func ErrorWindow(gw *GuiWindow, msg1 string, msg2 string) {
// something specific will fall into this routine // something specific will fall into this routine
// By default, all it runs is the call back to // By default, all it runs is the call back to
// the main program that is using this library // the main program that is using this library
// This is one of the routines that is called from the
// defaultButtonClick() below when the button is found
// in the AllButtons %map
// TODO: clean up the text above
// TODO: remove this all together going only to main()
func mouseClick(b *GuiButton) {
log.Println("gui.mouseClick() START")
if (b == nil) {
log.Println("\tgui.mouseClick() START b = nil")
} else {
log.Println("\tgui.mouseClick() START b.Action =", b.Action)
/*
if (b.Action == "CreateAddVmBox") {
log.Println("\tgui.mouseClick() CreateAddVmBox for b =", b)
CreateAddVmBox(b.GW, b)
return
}
*/
/*
if (b.Action == "WINDOW CLOSE") {
b.W.Hide()
// TODO: fix this (seems to crash? maybe because we are in the button here?)
// b.W.Destroy()
return
}
if (b.Action == "ADD") {
log.Println("\tgui.mouseClick() SHOULD ADD VM HERE?")
}
*/
}
if (Data.MouseClick == nil) {
log.Println("\tgui.mouseClick() Data.MouseClick() IS nil. NOT DOING ANYTHING")
log.Println("\tgui.mouseClick() Your application did not set a MouseClick() callback function")
} else {
log.Println("\tgui.mouseClick() Data.MouseClick() START")
Data.MouseClick(b)
}
}
// //
// This routine MUST be here as this is how the andlabs/ui works // 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 // This is the raw routine passed to every button in andlabs libui / ui
@ -177,21 +132,21 @@ func defaultButtonClick(button *ui.Button) {
for key, foo := range Data.AllButtons { for key, foo := range Data.AllButtons {
if (Data.Debug) { if (Data.Debug) {
log.Println("defaultButtonClick() Data.AllButtons =", key, foo) log.Println("defaultButtonClick() Data.AllButtons =", key, foo)
spew.Dump(foo) // spew.Dump(foo)
} }
if Data.AllButtons[key].B == button { if Data.AllButtons[key].B == button {
log.Println("\tdefaultButtonClick() BUTTON MATCHED") log.Println("\tdefaultButtonClick() BUTTON MATCHED")
// log.Println("\tData.AllButtons[key].Name =", Data.AllButtons[key].Name)
log.Println("\tdefaultButtonClick() Data.AllButtons[key].Action =", Data.AllButtons[key].Action) log.Println("\tdefaultButtonClick() Data.AllButtons[key].Action =", Data.AllButtons[key].Action)
if Data.AllButtons[key].custom != nil { if Data.AllButtons[key].custom != nil {
log.Println("\tdefaultButtonClick() DOING CUSTOM FUNCTION") log.Println("\tdefaultButtonClick() DOING CUSTOM FUNCTION")
var tmp *GuiButton Data.AllButtons[key].custom(Data.AllButtons[key])
tmp = Data.AllButtons[key]
// spew.Dump(tmp)
Data.AllButtons[key].custom(tmp)
return return
} }
mouseClick(Data.AllButtons[key]) if (Data.MouseClick != nil) {
Data.MouseClick(Data.AllButtons[key])
} else {
log.Println("\tdefaultButtonClick() IGNORING BUTTON. MouseClick() is nil")
}
return return
} }
} }
@ -199,7 +154,6 @@ func defaultButtonClick(button *ui.Button) {
if (Data.Debug) { if (Data.Debug) {
panic("defaultButtonClick() SHOULD NOT HAVE UNMAPPED BUTTONS") panic("defaultButtonClick() SHOULD NOT HAVE UNMAPPED BUTTONS")
} }
mouseClick(nil)
} }
func AddButton(b *GuiButton, name string) *ui.Button { func AddButton(b *GuiButton, name string) *ui.Button {
@ -249,7 +203,9 @@ func CreateFontButton(box *GuiBox, action string) *GuiButton {
newGB.FB.OnChanged(func (*ui.FontButton) { newGB.FB.OnChanged(func (*ui.FontButton) {
log.Println("FontButton.OnChanged() START mouseClick(&newBM)", newGB) log.Println("FontButton.OnChanged() START mouseClick(&newBM)", newGB)
mouseClick(&newGB) if (Data.MouseClick != nil) {
Data.MouseClick(&newGB)
}
}) })
return &newGB return &newGB
} }
@ -345,6 +301,11 @@ func AddEntry(box *GuiBox, name string) *GuiEntry {
return ge return ge
} }
func HorizontalBreak(box *GuiBox) {
tmp := ui.NewHorizontalSeparator()
box.UiBox.Append(tmp, false)
}
func AddGenericBox(gw *GuiWindow) *GuiBox { func AddGenericBox(gw *GuiWindow) *GuiBox {
var gb *GuiBox var gb *GuiBox
gb = new(GuiBox) gb = new(GuiBox)
@ -365,7 +326,23 @@ func AddGenericBox(gw *GuiWindow) *GuiBox {
return gb return gb
} }
func HorizontalBreak(box *GuiBox) { func CreateGenericBox(gw *GuiWindow, b *GuiButton, name string) *GuiBox{
tmp := ui.NewHorizontalSeparator() log.Println("CreateAddVmBox() START name =", name)
box.UiBox.Append(tmp, false)
var box *GuiBox
box = new(GuiBox)
vbox := ui.NewVerticalBox()
vbox.SetPadded(true)
box.UiBox = vbox
box.W = gw
gw.BoxMap["ADD VM" + name] = box
hbox := ui.NewHorizontalBox()
hbox.SetPadded(true)
vbox.Append(hbox, false)
AddBoxToTab(name, gw.UiTab, vbox)
return box
} }

View File

@ -110,7 +110,9 @@ func defaultSetCellValue(mh *TableData, row int, column int) {
button := mh.Rows[row].HumanData[humanID].Button button := mh.Rows[row].HumanData[humanID].Button
if (button != nil) { if (button != nil) {
mouseClick(button) if (Data.MouseClick != nil) {
Data.MouseClick(button)
}
return return
} }
if (Data.Debug) { if (Data.Debug) {

View File

@ -71,53 +71,3 @@ func CreateVmBox(gw *GuiWindow, vm *pb.Event_VM) {
AddBoxToTab(vm.Name, gw.UiTab, vbox) AddBoxToTab(vm.Name, gw.UiTab, vbox)
} }
func CreateAddVmBox(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.W = gw
gw.BoxMap["ADD VM" + name] = box
hbox := ui.NewHorizontalBox()
hbox.SetPadded(true)
vbox.Append(hbox, false)
// abox := gw.MakeTab(gw)
AddBoxToTab(name, gw.UiTab, vbox)
return box
/*
// Add hostname entry box
hostname := MakeEntryHbox(box, "Hostname:", "testhost", true, "Hostname")
memory := MakeEntryHbox(box, "Memory:", "512", true, "Memory")
disk := MakeEntryHbox(box, "Disk:", "20", true, "Disk")
log.Println("CreateAddVmBox() hostname, memory, disk =", hostname, memory, disk)
vbox.Append(ui.NewHorizontalSeparator(), false)
hboxButtons := ui.NewHorizontalBox()
hboxButtons.SetPadded(true)
vbox.Append(hboxButtons, false)
var newb GuiButton
newb.Action = "CREATE"
newb.VM = b.VM
newb.Account = b.Account
hostname.B = &newb
memory.B = &newb
disk.B = &newb
hboxButtons.Append(AddButton(&newb, "Add Virtual Machine"), false)
a := CreateButton(box, nil, nil, "Cancel", "CLOSE", nil)
hboxButtons.Append(a.B, false)
*/
}