Fire Selected on list item click

This commit is contained in:
Chris Miller 2019-11-04 06:55:58 +00:00
parent d7250288e2
commit d891191b78
2 changed files with 12 additions and 1 deletions

View File

@ -15,6 +15,7 @@ func main() {
AddItem("Quit", "Press to exit", 'q', func() { AddItem("Quit", "Press to exit", 'q', func() {
app.Stop() app.Stop()
}) })
app.EnableMouse()
if err := app.SetRoot(list, true).Run(); err != nil { if err := app.SetRoot(list, true).Run(); err != nil {
panic(err) panic(err)
} }

12
list.go
View File

@ -554,7 +554,17 @@ func (l *List) MouseHandler() func(event EventMouse) {
atX, atY := event.Position() atX, atY := event.Position()
index := l.indexAtPoint(atX, atY) index := l.indexAtPoint(atX, atY)
if index != -1 { if index != -1 {
l.SetCurrentItem(index) item := l.items[index]
if item.Selected != nil {
item.Selected()
}
if l.selected != nil {
l.selected(index, item.MainText, item.SecondaryText, item.Shortcut)
}
if index != l.currentItem && l.changed != nil {
l.changed(index, item.MainText, item.SecondaryText, item.Shortcut)
}
l.currentItem = index
} }
} }
}) })