BListView: fix ScrollToSelection

When selection moves down, BListView was sometimes scroll to upper item,
not lower.

Change-Id: I8f3cf87d43e93c3d2cabfd7ca76f44f1575525e0
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2311
Reviewed-by: waddlesplash <[email protected]>
Reviewed-by: John Scipione <[email protected]>
Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
X512
2020-05-03 19:38:57 +00:00
committed by waddlesplash
parent 325ca7f19c
commit b7c0f682e4
+5 -10
View File
@@ -1113,16 +1113,11 @@ BListView::ScrollToSelection()
{
BRect itemFrame = ItemFrame(CurrentSelection(0));
if (Bounds().Contains(itemFrame))
return;
float scrollPos = itemFrame.top < Bounds().top ?
itemFrame.top : itemFrame.bottom - Bounds().Height();
if (itemFrame.top - scrollPos < Bounds().top)
scrollPos = itemFrame.top;
ScrollTo(itemFrame.left, scrollPos);
if (itemFrame.top < Bounds().top
|| itemFrame.Height() > Bounds().Height())
ScrollBy(0, itemFrame.top - Bounds().top);
else if (itemFrame.bottom > Bounds().bottom)
ScrollBy(0, itemFrame.bottom - Bounds().bottom);
}