Added mouse scrolling to List, Table, TextView, and TreeView.

pull/422/head
Oliver 4 years ago
parent b3dc389cb4
commit f395cf6e33

@ -37,10 +37,10 @@ const (
MouseRightUp
MouseRightClick
MouseRightDoubleClick
WheelUp
WheelDown
WheelLeft
WheelRight
MouseScrollUp
MouseScrollDown
MouseScrollLeft
MouseScrollRight
)
// queuedUpdate represented the execution of f queued by
@ -467,10 +467,10 @@ func (a *Application) fireMouseActions(event *tcell.EventMouse) (consumed, isMou
button tcell.ButtonMask
action MouseAction
}{
{tcell.WheelUp, WheelUp},
{tcell.WheelDown, WheelDown},
{tcell.WheelLeft, WheelLeft},
{tcell.WheelRight, WheelRight}} {
{tcell.WheelUp, MouseScrollUp},
{tcell.WheelDown, MouseScrollDown},
{tcell.WheelLeft, MouseScrollLeft},
{tcell.WheelRight, MouseScrollRight}} {
if buttons&wheelEvent.button != 0 {
fire(wheelEvent.action)
}

@ -560,7 +560,7 @@ func (l *List) InputHandler() func(event *tcell.EventKey, setFocus func(p Primit
}
// indexAtPoint returns the index of the list item found at the given position
// or -1 if there is no such list item.
// or a negative value if there is no such list item.
func (l *List) indexAtPoint(x, y int) int {
rectX, rectY, width, height := l.GetInnerRect()
if rectX < 0 || rectX >= rectX+width || y < rectY || y >= rectY+height {
@ -571,6 +571,7 @@ func (l *List) indexAtPoint(x, y int) int {
if l.showSecondaryText {
index /= 2
}
index += l.offset
if index >= len(l.items) {
return -1
@ -586,7 +587,8 @@ func (l *List) MouseHandler() func(action MouseAction, event *tcell.EventMouse,
}
// Process mouse event.
if action == MouseLeftClick {
switch action {
case MouseLeftClick:
setFocus(l)
index := l.indexAtPoint(event.Position())
if index != -1 {
@ -603,6 +605,20 @@ func (l *List) MouseHandler() func(action MouseAction, event *tcell.EventMouse,
l.currentItem = index
}
consumed = true
case MouseScrollUp:
if l.offset > 0 {
l.offset--
}
consumed = true
case MouseScrollDown:
lines := len(l.items) - l.offset
if l.showSecondaryText {
lines *= 2
}
if _, _, _, height := l.GetInnerRect(); lines > height {
l.offset++
}
consumed = true
}
return

@ -1242,6 +1242,13 @@ func (t *Table) MouseHandler() func(action MouseAction, event *tcell.EventMouse,
}
consumed = true
setFocus(t)
case MouseScrollUp:
t.trackEnd = false
t.rowOffset--
consumed = true
case MouseScrollDown:
t.rowOffset++
consumed = true
}
return

@ -1164,6 +1164,13 @@ func (t *TextView) MouseHandler() func(action MouseAction, event *tcell.EventMou
}
consumed = true
setFocus(t)
case MouseScrollUp:
t.trackEnd = false
t.lineOffset--
consumed = true
case MouseScrollDown:
t.lineOffset++
consumed = true
}
return

@ -757,6 +757,12 @@ func (t *TreeView) MouseHandler() func(action MouseAction, event *tcell.EventMou
}
consumed = true
setFocus(t)
case MouseScrollUp:
t.movement = treeUp
consumed = true
case MouseScrollDown:
t.movement = treeDown
consumed = true
}
return

Loading…
Cancel
Save