ListView: More safe ScrollToSelection implementation

The Problem was observed in the Time Preferences Zone view - the
selection was set inside of TimeZoneView::DoLayout() call on
the OutlineListView control that had zero-sized Bounds. After
the control was resized the selection stay mainly hidden "under"
the upper edge. The Problem looks like generic so should be fixed
in the interface kit code. Proposed fix introduces additional check
for the scroll position to not cross the top edge of control.
This commit is contained in:
Siarzhuk Zharski 2013-09-15 23:39:44 +02:00
parent 83f9d3c431
commit 81cdbc6ae6

View File

@ -1037,10 +1037,13 @@ BListView::ScrollToSelection()
if (Bounds().Contains(itemFrame))
return;
if (itemFrame.top < Bounds().top)
ScrollTo(itemFrame.left, itemFrame.top);
else
ScrollTo(itemFrame.left, itemFrame.bottom - Bounds().Height());
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);
}