From 4f08c8f1cea5103c9713d2374d3e266025208893 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 26 May 2019 11:54:33 -0700 Subject: [PATCH] standardize other mouse clicks Signed-off-by: Jeff Carr --- gui.go | 49 ++++++++++++++++++++++++++----------------------- mainCloudBox.go | 18 ++++++++---------- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/gui.go b/gui.go index 2853dd6..fdea647 100644 --- a/gui.go +++ b/gui.go @@ -143,23 +143,19 @@ func mouseClick(b *ButtonMap) { } } -/* -func buttonMapClick(b *ButtonMap) { - log.Println("gui.buttonVmClick() START") - if (Data.MouseClick == nil) { - log.Println("Data.MouseClick() IS nil. NOT DOING ANYTHING") - } else { - log.Println("Data.MouseClick() START") - Data.MouseClick(b) - } -} -*/ - +// +// 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 []ButtonMap which has all the buttons. We search +// for the button and then call the function below +// func defaultButtonClick(button *ui.Button) { - log.Println("defaultButtonClick() button =", button) + log.Println("defaultButtonClick() LOOK FOR BUTTON button =", button) for key, foo := range Data.AllButtons { - log.Println("Data.AllButtons =", key, foo) + if (Data.Debug) { + 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) @@ -179,12 +175,17 @@ func defaultButtonClick(button *ui.Button) { } } log.Println("\tBUTTON NOT FOUND") - // still run the mouse click handler + if (Data.Debug) { + panic("SHOULD NOT HAVE UNMAPPED BUTTONS") + } + // still run the mouse click handler if you got here + // TODO: get rid of this to make sure everything is perfectly mapped if (Data.MouseClick != nil) { Data.MouseClick(nil) } } +/* // This is the raw routine passed to every button in andlabs libui / ui // (this has to be different for FontButtons) // TODO; merge the logic with the function above @@ -194,6 +195,7 @@ func defaultFontButtonClick(button *ui.FontButton) { log.Println("Data.AllButtons =", key, foo) } } +*/ func CreateButton(a *pb.Account, vm *pb.Event_VM, name string, note string, custom func(*ButtonMap)) *ui.Button { @@ -212,16 +214,17 @@ func CreateButton(a *pb.Account, vm *pb.Event_VM, return newB } -func CreateFontButton(name string, note string, custom func(*ButtonMap)) *ui.FontButton { +func CreateFontButton(action string, note string, custom func(*ButtonMap)) *ui.FontButton { newB := ui.NewFontButton() - newB.OnChanged(defaultFontButtonClick) - - var newmap ButtonMap - newmap.FB = newB - newmap.Action = note - newmap.custom = custom - Data.AllButtons = append(Data.AllButtons, newmap) + // create a 'fake' button entry for the mouse clicks + var newButtonMap ButtonMap + newButtonMap.Action = action + newButtonMap.FB = newB + Data.AllButtons = append(Data.AllButtons, newButtonMap) + newB.OnChanged(func (*ui.FontButton) { + mouseClick(&newButtonMap) + }) return newB } diff --git a/mainCloudBox.go b/mainCloudBox.go index 91caa4d..d6b9340 100644 --- a/mainCloudBox.go +++ b/mainCloudBox.go @@ -209,20 +209,18 @@ func GoMainWindow() { func makeCloudWindow() { Data.cloudWindow = ui.NewWindow("", Data.Width, Data.Height, true) // cloudWindow.SetBorderless(true) + + // create a 'fake' button entry for the mouse clicks + var newButtonMap ButtonMap + newButtonMap.Action = "QUIT" + Data.AllButtons = append(Data.AllButtons, newButtonMap) + Data.cloudWindow.OnClosing(func(*ui.Window) bool { - if (Data.MouseClick != nil) { - log.Println("SIMULATE Data.MouseClick(QUIT)") - Data.State = "QUIT" - Data.MouseClick(nil) - } + mouseClick(&newButtonMap) return true }) ui.OnShouldQuit(func() bool { - if (Data.MouseClick != nil) { - log.Println("SIMULATE Data.MouseClick(QUIT)") - Data.State = "QUIT" - Data.MouseClick(nil) - } + mouseClick(&newButtonMap) return true })