diff options
Diffstat (limited to 'src/gui/widgets/listbox.cpp')
-rw-r--r-- | src/gui/widgets/listbox.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp index 2f0f8d941..e5229eca6 100644 --- a/src/gui/widgets/listbox.cpp +++ b/src/gui/widgets/listbox.cpp @@ -209,8 +209,7 @@ void ListBox::mousePressed1(gcn::MouseEvent &mouseEvent) { if (mouseEvent.getButton() == gcn::MouseEvent::LEFT) { - setSelected(std::max(0, mouseEvent.getY() - mPadding) - / getRowHeight()); + setSelected(std::max(0, getSelectionByMouse(mouseEvent.getY()))); distributeActionEvent(); } } @@ -222,7 +221,7 @@ void ListBox::mouseDragged(gcn::MouseEvent &event) // Make list selection update on drag, but guard against negative y if (getRowHeight()) - setSelected(std::max(0, event.getY() - mPadding) / getRowHeight()); + setSelected(std::max(0, getSelectionByMouse(event.getY()))); } void ListBox::refocus() @@ -249,3 +248,8 @@ void ListBox::logic() { adjustSize(); } + +int ListBox::getSelectionByMouse(const int y) const +{ + return (y - mPadding) / getRowHeight(); +} |