attempt to make buttons with custom callback functions
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
4876f4ae77
commit
c43ef7e7e3
61
gui.go
61
gui.go
|
@ -15,6 +15,8 @@ var tabcount int
|
||||||
var Width int
|
var Width int
|
||||||
var Height int
|
var Height int
|
||||||
|
|
||||||
|
var allButtons []ButtonMap
|
||||||
|
|
||||||
type TableColumnData struct {
|
type TableColumnData struct {
|
||||||
Index int
|
Index int
|
||||||
CellType string
|
CellType string
|
||||||
|
@ -24,6 +26,12 @@ type TableColumnData struct {
|
||||||
|
|
||||||
type ButtonMap struct {
|
type ButtonMap struct {
|
||||||
B *ui.Button
|
B *ui.Button
|
||||||
|
FB *ui.FontButton
|
||||||
|
onClick func (int, string)
|
||||||
|
onChanged func (int, string)
|
||||||
|
custom func (int, string)
|
||||||
|
name string // the text on the button
|
||||||
|
note string // what type of button
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupUI() {
|
func setupUI() {
|
||||||
|
@ -151,6 +159,59 @@ func DoGUI() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func defaultMouseEvent() {
|
||||||
|
}
|
||||||
|
|
||||||
|
func defaultButtonClick(button *ui.Button) {
|
||||||
|
log.Println("defaultButtonClick() button =", button)
|
||||||
|
for key, foo := range allButtons {
|
||||||
|
log.Println("allButtons =", key, foo)
|
||||||
|
if allButtons[key].B == button {
|
||||||
|
log.Println("\tBUTTON MATCHED")
|
||||||
|
if allButtons[key].custom != nil {
|
||||||
|
allButtons[key].custom(42, "something foo")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func defaultFontButtonClick(button *ui.FontButton) {
|
||||||
|
log.Println("defaultButtonClick() button =", button)
|
||||||
|
for key, foo := range allButtons {
|
||||||
|
log.Println("allButtons =", key, foo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateButton(name string, note string, custom func(int, string)) *ui.Button {
|
||||||
|
newB := ui.NewButton("OK")
|
||||||
|
|
||||||
|
newB.OnClicked(defaultButtonClick)
|
||||||
|
|
||||||
|
var newmap ButtonMap
|
||||||
|
newmap.B = newB
|
||||||
|
newmap.note = note
|
||||||
|
newmap.name = name
|
||||||
|
newmap.custom = custom
|
||||||
|
allButtons = append(allButtons, newmap)
|
||||||
|
|
||||||
|
return newB
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateFontButton(name string, note string, custom func(int, string)) *ui.FontButton {
|
||||||
|
newB := ui.NewFontButton()
|
||||||
|
|
||||||
|
newB.OnChanged(defaultFontButtonClick)
|
||||||
|
|
||||||
|
var newmap ButtonMap
|
||||||
|
newmap.FB = newB
|
||||||
|
newmap.note = note
|
||||||
|
newmap.name = name
|
||||||
|
newmap.custom = custom
|
||||||
|
allButtons = append(allButtons, newmap)
|
||||||
|
|
||||||
|
return newB
|
||||||
|
}
|
||||||
|
|
||||||
func closeButtonClick(button *ui.Button) {
|
func closeButtonClick(button *ui.Button) {
|
||||||
log.Println("closeButtonClick() hostname =", config.String("hostname"), button)
|
log.Println("closeButtonClick() hostname =", config.String("hostname"), button)
|
||||||
spew.Dump(button)
|
spew.Dump(button)
|
||||||
|
|
Loading…
Reference in New Issue