|
|
|
@ -549,3 +549,35 @@ func (l *List) InputHandler() func(event *tcell.EventKey, setFocus func(p Primit
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// returns -1 if not found.
|
|
|
|
|
func (l *List) indexAtPoint(atX, atY int) int {
|
|
|
|
|
_, y, _, h := l.GetInnerRect()
|
|
|
|
|
if atY < y || atY >= y+h {
|
|
|
|
|
return -1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n := atY - y
|
|
|
|
|
if l.showSecondaryText {
|
|
|
|
|
n /= 2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if n >= len(l.items) {
|
|
|
|
|
return -1
|
|
|
|
|
}
|
|
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MouseHandler returns the mouse handler for this primitive.
|
|
|
|
|
func (l *List) MouseHandler() func(event EventMouse) {
|
|
|
|
|
return l.WrapMouseHandler(func(event EventMouse) {
|
|
|
|
|
// Process mouse event.
|
|
|
|
|
if event.Buttons()&tcell.Button1 != 0 {
|
|
|
|
|
atX, atY := event.Position()
|
|
|
|
|
index := l.indexAtPoint(atX, atY)
|
|
|
|
|
if index != -1 {
|
|
|
|
|
l.SetCurrentItem(index)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|