From 37f849a6ae4d96a22d7b972d3021c235aa294ad8 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 29 Jun 2013 16:02:11 +0300 Subject: Add support for multilines in extendedlistbox. --- src/gui/widgets/listbox.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/gui/widgets/listbox.cpp') 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(); +} -- cgit v1.2.3-70-g09d2