Fixed a cosmetic menu scrolling alignment issue.

This commit is contained in:
Leon Styhre 2021-01-29 17:59:05 +01:00
parent 53e8b45089
commit 39e8e33733
2 changed files with 10 additions and 8 deletions

View file

@ -150,21 +150,21 @@ void ComponentList::updateCameraOffset()
// Move the camera to scroll. // Move the camera to scroll.
const float totalHeight = getTotalRowHeight(); const float totalHeight = getTotalRowHeight();
if (totalHeight > mSize.y()) { if (totalHeight > mSize.y()) {
float target = mSelectorBarOffset + getRowHeight(mEntries.at(mCursor).data)/2 - float target = mSelectorBarOffset +
(mSize.y() / 2); getRowHeight(mEntries.at(mCursor).data) / 2.0f - (mSize.y() / 2.0f);
// Clamp it. // Clamp the camera to prevent a fraction of a row from being displayed.
mCameraOffset = 0; mCameraOffset = 0.0f;
unsigned int i = 0; unsigned int i = 0;
while (mCameraOffset < target && i < mEntries.size()) { while (mCameraOffset < target && i < mEntries.size()) {
mCameraOffset += getRowHeight(mEntries.at(i).data); mCameraOffset += getRowHeight(mEntries.at(i).data);
if (mCameraOffset > totalHeight - mSize.y())
break;
i++; i++;
} }
if (mCameraOffset < 0) if (mCameraOffset < 0)
mCameraOffset = 0; mCameraOffset = 0;
else if (mCameraOffset + mSize.y() > totalHeight)
mCameraOffset = totalHeight - mSize.y();
} }
else { else {
mCameraOffset = 0; mCameraOffset = 0;

View file

@ -82,12 +82,14 @@ float MenuComponent::getButtonGridHeight() const
void MenuComponent::updateSize() void MenuComponent::updateSize()
{ {
const float maxHeight = Renderer::getScreenHeight() * 0.75f; const float maxHeight = Renderer::getScreenHeight() * 0.75f;
float height = TITLE_HEIGHT + mList->getTotalRowHeight() + getButtonGridHeight() + 2; float height = TITLE_HEIGHT + mList->getTotalRowHeight() + getButtonGridHeight() +
(2 * Renderer::getScreenHeightModifier());
if (height > maxHeight) { if (height > maxHeight) {
height = TITLE_HEIGHT + getButtonGridHeight(); height = TITLE_HEIGHT + getButtonGridHeight();
int i = 0; int i = 0;
while (i < mList->size()) { while (i < mList->size()) {
float rowHeight = mList->getRowHeight(i); // Add the separator height to the row height so that it also gets properly rendered.
float rowHeight = mList->getRowHeight(i) + (1 * Renderer::getScreenHeightModifier());
if (height + rowHeight < maxHeight) if (height + rowHeight < maxHeight)
height += rowHeight; height += rowHeight;
else else