From 7875c2271c6f6bf60da9358bf8dde111d9a75b18 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Mon, 24 Mar 2014 15:34:38 -0500 Subject: [PATCH] Fixed camera scrolling for ComponentLists to always be by row heights. --- src/components/ComponentList.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/ComponentList.cpp b/src/components/ComponentList.cpp index ca285d851..eccfcca2f 100644 --- a/src/components/ComponentList.cpp +++ b/src/components/ComponentList.cpp @@ -111,7 +111,16 @@ void ComponentList::onCursorChanged(const CursorState& state) const float totalHeight = getTotalRowHeight(); if(totalHeight > mSize.y()) { - mCameraOffset = mSelectorBarOffset - (mSize.y() / 2); + float target = mSelectorBarOffset + getRowHeight(mEntries.at(mCursor).data)/2 - (mSize.y() / 2); + + // clamp it + mCameraOffset = 0; + unsigned int i = 0; + while(mCameraOffset < target && i < mEntries.size()) + { + mCameraOffset += getRowHeight(mEntries.at(i).data); + i++; + } if(mCameraOffset < 0) mCameraOffset = 0;