button handling almost completely cleaned up

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-24 13:23:50 -07:00
parent 238c39de36
commit 858f7fd93c
9 changed files with 42 additions and 48 deletions

View File

@ -5,7 +5,7 @@ import "log"
import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"
func AddAccountQuestionBox(junk *ui.Box, custom func(*ButtonMap, string)) *ui.Box {
func AddAccountQuestionBox(junk *ui.Box, custom func(*ButtonMap)) *ui.Box {
newbox := ui.NewVerticalBox()
newbox.SetPadded(true)
@ -20,7 +20,7 @@ func AddAccountQuestionBox(junk *ui.Box, custom func(*ButtonMap, string)) *ui.Bo
return newbox
}
func AddAccountBox(custom func(*ButtonMap, string)) *ui.Box {
func AddAccountBox(custom func(*ButtonMap)) *ui.Box {
vbox := ui.NewVerticalBox()
vbox.SetPadded(true)

View File

@ -7,7 +7,7 @@ import _ "github.com/andlabs/ui/winmanifest"
import "github.com/davecgh/go-spew/spew"
func makeSplashArea(custom func(*ButtonMap, string)) *ui.Area {
func makeSplashArea(custom func(*ButtonMap)) *ui.Area {
// make this button just to get the default font (but don't display the button)
// There should be another way to do this (?)
Data.fontButton = CreateFontButton("SplashFont", "DONE", custom)

View File

@ -56,7 +56,7 @@ func addTableTab() {
AddTableTab(Data.cloudTab, 1, "test seven", 7, parts)
}
func addDebuggingButtons(vbox *ui.Box, custom func(*ButtonMap, string)) {
func addDebuggingButtons(vbox *ui.Box, custom func(*ButtonMap)) {
vbox.Append(ui.NewLabel("Debugging:"), false)
vbox.Append(ui.NewColorButton(), false)
@ -116,7 +116,7 @@ func addDebuggingButtons(vbox *ui.Box, custom func(*ButtonMap, string)) {
vbox.Append(CreateButton("Load test.json config file", "CONFIG", custom), false)
}
func runTestExecClick(b *ButtonMap, msg string) {
func runTestExecClick(b *ButtonMap) {
log.Println("runTestExecClick START")
if runtime.GOOS == "linux" {
go runCommand("xterm -report-fonts")

47
gui.go
View File

@ -105,25 +105,33 @@ func AddTableTab(mytab *ui.Tab, mytabcount int, name string, rowcount int, parts
// 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
func mouseClick(b *ButtonMap, s string) {
log.Println("gui.mouseClick() START b, s =", b, s)
if (Data.MouseClick != nil) {
// 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
func mouseClick(b *ButtonMap) {
log.Println("gui.mouseClick() START b =", b)
if (Data.MouseClick == nil) {
log.Println("Data.MouseClick() IS nil. NOT DOING ANYTHING")
} else {
log.Println("\tData.MouseClick() START")
Data.MouseClick(b)
}
}
// This is one of the routines that is called from the
// defaultButtonClick() below when the button is found
// in the AllButtons %map
func buttonMapClick(b *ButtonMap, s string) {
/*
func buttonMapClick(b *ButtonMap) {
log.Println("gui.buttonVmClick() START")
if (Data.MouseClick != nil) {
log.Println("Data.ButtonClick() START")
Data.MouseClick(nil)
if (Data.MouseClick == nil) {
log.Println("Data.MouseClick() IS nil. NOT DOING ANYTHING")
} else {
log.Println("Data.MouseClick() START")
Data.MouseClick(b)
}
}
*/
// This is the raw routine passed to every button in andlabs libui / ui
func defaultButtonClick(button *ui.Button) {
@ -132,11 +140,14 @@ func defaultButtonClick(button *ui.Button) {
log.Println("Data.AllButtons =", key, foo)
if Data.AllButtons[key].B == button {
log.Println("\tBUTTON MATCHED")
log.Println("\tData.AllButtons[key].Name", Data.AllButtons[key].Name)
log.Println("\tData.AllButtons[key].Note", Data.AllButtons[key].Note)
log.Println("\tData.AllButtons[key].Name =", Data.AllButtons[key].Name)
log.Println("\tData.AllButtons[key].Note =", Data.AllButtons[key].Note)
if Data.AllButtons[key].custom != nil {
log.Println("\tDOING CUSTOM FUNCTION")
Data.AllButtons[key].custom(&Data.AllButtons[key], "SOMETHING CUSTOM")
var tmp ButtonMap
tmp = Data.AllButtons[key]
spew.Dump(tmp)
Data.AllButtons[key].custom(&tmp)
return
}
if (Data.MouseClick != nil) {
@ -162,7 +173,7 @@ func defaultFontButtonClick(button *ui.FontButton) {
}
}
func CreateButton(name string, note string, custom func(*ButtonMap, string)) *ui.Button {
func CreateButton(name string, note string, custom func(*ButtonMap)) *ui.Button {
newB := ui.NewButton(name)
newB.OnClicked(defaultButtonClick)
@ -177,7 +188,7 @@ func CreateButton(name string, note string, custom func(*ButtonMap, string)) *ui
return newB
}
func CreateAccountButton(account string, custom func(*ButtonMap, string)) *ui.Button {
func CreateAccountButton(account string, custom func(*ButtonMap)) *ui.Button {
name := "Show " + account
newB := ui.NewButton(name)
@ -194,7 +205,7 @@ func CreateAccountButton(account string, custom func(*ButtonMap, string)) *ui.Bu
return newB
}
func CreateLoginButton(account string, custom func(*ButtonMap, string)) *ui.Button {
func CreateLoginButton(account string, custom func(*ButtonMap)) *ui.Button {
name := "Login " + account
newB := ui.NewButton(name)
@ -211,7 +222,7 @@ func CreateLoginButton(account string, custom func(*ButtonMap, string)) *ui.Butt
return newB
}
func CreateFontButton(name string, note string, custom func(*ButtonMap, string)) *ui.FontButton {
func CreateFontButton(name string, note string, custom func(*ButtonMap)) *ui.FontButton {
newB := ui.NewFontButton()
newB.OnChanged(defaultFontButtonClick)
@ -242,7 +253,7 @@ func addVmButtonClick(button *ui.Button) {
if (Data.Debug) {
spew.Dump(button)
}
createAddVmBox(Data.cloudTab, "Create New Virtual Machine", buttonMapClick)
createAddVmBox(Data.cloudTab, "Create New Virtual Machine", mouseClick)
}
func addVmButton(name string) ui.Control {

View File

@ -11,7 +11,7 @@ import _ "github.com/andlabs/ui/winmanifest"
// import "github.com/davecgh/go-spew/spew"
func makeCloudInfoBox(custom func(*ButtonMap, string)) *ui.Box {
func makeCloudInfoBox(custom func(*ButtonMap)) *ui.Box {
hbox := ui.NewHorizontalBox()
hbox.SetPadded(true)

View File

@ -10,7 +10,7 @@ import "runtime"
import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"
func ShowSplashBox(vbox *ui.Box, atest chan int, custom func(*ButtonMap, string)) *ui.Box {
func ShowSplashBox(vbox *ui.Box, atest chan int, custom func(*ButtonMap)) *ui.Box {
newbox := ui.NewVerticalBox()
newbox.SetPadded(true)

View File

@ -101,7 +101,7 @@ type ButtonMap struct {
FB *ui.FontButton
onClick func (int, string)
onChanged func (int, string)
custom func (*ButtonMap, string)
custom func (*ButtonMap)
Name string // the text on the button
Note string // what type of button
AccNick string // what account this button is for

View File

@ -108,7 +108,7 @@ func defaultSetCellValue(mh *TableData, row int, column int) {
} else {
// AddVmConfigureTab(vmname, mh.Rows[row].PbVM)
// createVmBox(Data.cloudTab, buttonVmClick, mh.Rows[row].PbVM)
createVmBox(Data.cloudTab, buttonMapClick, mh.Rows[row].PbVM)
createVmBox(Data.cloudTab, mouseClick, mh.Rows[row].PbVM)
}
}
}

View File

@ -27,19 +27,12 @@ func ShowVM() {
VMwin.SetChild(VMtab)
VMwin.SetMargined(true)
createVmBox(VMtab, buttonMapClick, Data.CurrentPbVM)
// vmBox := createVmBox(buttonVmClick)
// VMtab.Append(Data.CurrentVM, vmBox)
// VMtab.SetMargined(0, true)
createVmBox(VMtab, mouseClick, Data.CurrentPbVM)
VMwin.Show()
}
func AddVmConfigureTab(name string, pbVM *pb.Event_VM) {
createVmBox(Data.cloudTab, buttonMapClick, Data.CurrentPbVM)
// vmBox := createVmBox(Data.cloudTab, buttonVmClick)
// Data.cloudTab.Append(name, vmBox)
// Data.cloudTab.SetMargined(0, true)
createVmBox(Data.cloudTab, mouseClick, Data.CurrentPbVM)
}
// makeEntryBox(box, "hostname:", "blah.foo.org") {
@ -87,7 +80,7 @@ func makeEntryHbox(hbox *ui.Box, a string, b string, edit bool) {
// End 'Nickname' vertical box
}
func createVmBox(tab *ui.Tab, custom func(b *ButtonMap,s string), pbVM *pb.Event_VM) {
func createVmBox(tab *ui.Tab, custom func(*ButtonMap), pbVM *pb.Event_VM) {
log.Println("createVmBox() START")
log.Println("createVmBox() pbVM.Name", pbVM.Name)
spew.Dump(pbVM)
@ -126,7 +119,7 @@ func createVmBox(tab *ui.Tab, custom func(b *ButtonMap,s string), pbVM *pb.Event
tab.SetMargined(0, true)
}
func createAddVmBox(tab *ui.Tab, name string, custom func(b *ButtonMap,s string)) {
func createAddVmBox(tab *ui.Tab, name string, custom func(*ButtonMap)) {
log.Println("createAddVmBox() START")
vbox := ui.NewVerticalBox()
vbox.SetPadded(true)
@ -150,13 +143,3 @@ func createAddVmBox(tab *ui.Tab, name string, custom func(b *ButtonMap,s string)
tab.Append(name, vbox)
tab.SetMargined(0, true)
}
/*
func buttonVmClick(b *ButtonMap, s string) {
log.Println("gui.buttonVmClick() START")
if (Data.MouseClick != nil) {
log.Println("Data.ButtonClick() START")
Data.MouseClick(nil)
}
}
*/