push button logic outside of the GUI

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-22 21:34:46 -07:00
parent 7638127519
commit c4b46266b0
1 changed files with 13 additions and 16 deletions

29
gui.go
View File

@ -21,6 +21,7 @@ type GuiDataStructure struct {
Width int Width int
Height int Height int
ButtonClick func(int, string) ButtonClick func(int, string)
ButtonClickNew func(*ButtonMap)
CurrentVM string CurrentVM string
MyArea *ui.Area MyArea *ui.Area
@ -56,8 +57,8 @@ type ButtonMap struct {
onClick func (int, string) onClick func (int, string)
onChanged func (int, string) onChanged func (int, string)
custom func (int, string) custom func (int, string)
name string // the text on the button Name string // the text on the button
note string // what type of button Note string // what type of button
} }
func setupUI() { func setupUI() {
@ -191,16 +192,12 @@ func defaultButtonClick(button *ui.Button) {
log.Println("Data.allButtons =", key, foo) log.Println("Data.allButtons =", key, foo)
if Data.allButtons[key].B == button { if Data.allButtons[key].B == button {
log.Println("\tBUTTON MATCHED") log.Println("\tBUTTON MATCHED")
log.Println("\tData.allButtons[key].name", Data.allButtons[key].name) 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].Note", Data.allButtons[key].Note)
if Data.allButtons[key].custom != nil { if (Data.ButtonClickNew != nil) {
if Data.allButtons[key].note == "BACK" { Data.ButtonClickNew( &Data.allButtons[key])
Data.allButtons[key].custom(42, "BACK") } else if Data.allButtons[key].custom != nil {
} else if Data.allButtons[key].note == "CLOSE" { Data.allButtons[key].custom(42, "BUTTON DOES NOTHING")
Data.allButtons[key].custom(42, "CLOSE")
} else {
Data.allButtons[key].custom(42, "something foo")
}
} }
} }
} }
@ -220,8 +217,8 @@ func CreateButton(name string, note string, custom func(int, string)) *ui.Button
var newmap ButtonMap var newmap ButtonMap
newmap.B = newB newmap.B = newB
newmap.note = note newmap.Note = note
newmap.name = name newmap.Name = name
newmap.custom = custom newmap.custom = custom
Data.allButtons = append(Data.allButtons, newmap) Data.allButtons = append(Data.allButtons, newmap)
@ -235,8 +232,8 @@ func CreateFontButton(name string, note string, custom func(int, string)) *ui.Fo
var newmap ButtonMap var newmap ButtonMap
newmap.FB = newB newmap.FB = newB
newmap.note = note newmap.Note = note
newmap.name = name newmap.Name = name
newmap.custom = custom newmap.custom = custom
Data.allButtons = append(Data.allButtons, newmap) Data.allButtons = append(Data.allButtons, newmap)