From d4983ec0c8cb45c6f28b1e5b19e5c9eeadeff4a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Mon, 5 Nov 2007 15:29:25 +0000 Subject: [PATCH] * use BListItem::Height() consistently (clicking a nick in Vision now selects that same nick, not a different one) * performance improvement in Draw() (using ItemFrame() in the inner loop scales really bad) * fixed scroll range for when BListItem::Height() is non-integer (scrolling all the way to the bottom in Visions nick list works now) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22835 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/ListView.cpp | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/kits/interface/ListView.cpp b/src/kits/interface/ListView.cpp index 37a0db0ec3..d500025b78 100644 --- a/src/kits/interface/ListView.cpp +++ b/src/kits/interface/ListView.cpp @@ -187,11 +187,19 @@ BListView::Archive(BMessage *archive, bool deep) const void BListView::Draw(BRect updateRect) { - for (int i = 0; i < CountItems(); i++) { - BRect itemFrame = ItemFrame(i); + int32 count = CountItems(); + if (count == 0) + return; + + BRect itemFrame(Bounds().left, 0, Bounds().right, -1); + for (int i = 0; i < count; i++) { + BListItem* item = ItemAt(i); + itemFrame.bottom = itemFrame.top + ceilf(item->Height()) - 1; if (itemFrame.Intersects(updateRect)) - DrawItem(((BListItem*)ItemAt(i)), itemFrame); + DrawItem(item, itemFrame); + + itemFrame.top = itemFrame.bottom + 1; } } @@ -696,7 +704,7 @@ BListView::IndexOf(BPoint point) const // TODO: somehow binary search, but items don't know their frame for (int i = 0; i < fList.CountItems(); i++) { - y += ItemAt(i)->Height(); + y += ceilf(ItemAt(i)->Height()); if (point.y < y) return i; @@ -1010,7 +1018,7 @@ BListView::FrameMoved(BPoint new_position) BRect BListView::ItemFrame(int32 index) { - BRect frame(0, 0, Bounds().Width(), -1); + BRect frame(Bounds().left, 0, Bounds().right, -1); if (index < 0 || index >= CountItems()) return frame; @@ -1018,7 +1026,7 @@ BListView::ItemFrame(int32 index) // TODO: this is very expensive, the (last) offsets could be cached for (int32 i = 0; i <= index; i++) { frame.top = frame.bottom + 1; - frame.bottom += (float)ceil(ItemAt(i)->Height()); + frame.bottom = frame.top + ceilf(ItemAt(i)->Height()) - 1; } return frame; @@ -1200,9 +1208,8 @@ BListView::_FixupScrollBar() int32 count = CountItems(); float itemHeight = 0; - for (int32 i = 0; BListItem* item = ItemAt(i); i++) { - itemHeight += item->Height(); - } + for (int32 i = 0; i < count; i++) + itemHeight += ceilf(ItemAt(i)->Height()); if (bounds.Height() > itemHeight) { // no scrolling @@ -1218,10 +1225,8 @@ BListView::_FixupScrollBar() } } - if (count != 0) { - vertScroller->SetSteps((float)ceil(FirstItem()->Height()), - bounds.Height()); - } + if (count != 0) + vertScroller->SetSteps(ceilf(FirstItem()->Height()), bounds.Height()); } // _InvalidateFrom