Browse Source

Fire Selected on list item click

merge-requests/1/merge
Chris Miller 3 years ago committed by Trevor Slocum
parent
commit
67c158fa9c
  1. 1
      demos/list/main.go
  2. 12
      list.go

1
demos/list/main.go

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

12
list.go

@ -576,7 +576,17 @@ func (l *List) MouseHandler() func(event EventMouse) {
atX, atY := event.Position()
index := l.indexAtPoint(atX, atY)
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
}
}
})

Loading…
Cancel
Save