Tweak how scroll offsets are calculated for smoother scrolling

This commit is contained in:
Andrew Lanzone 2025-07-06 22:39:13 -07:00
parent abe0467915
commit e349fa248a
2 changed files with 12 additions and 22 deletions

View File

@ -944,21 +944,16 @@ namespace MWGui
if (focused)
{
// Scroll the side bar to keep the active item in view
if (index <= 6)
mTopicsList->setViewOffset(0);
else
int offset = 0;
for (int i = 6; i < static_cast<int>(index); i++)
{
int offset = 0;
for (int i = 0; i < static_cast<int>(index) - 6; i++)
{
const std::string& keyword = mTopicsList->getItemNameAt(i);
if (keyword.empty())
offset += 18 + sVerticalPadding * 2;
else
offset += mTopicsList->getItemWidget(keyword)->getHeight() + sVerticalPadding * 2;
}
mTopicsList->setViewOffset(-offset);
const std::string& keyword = mTopicsList->getItemNameAt(i);
if (keyword.empty())
offset += 18 + sVerticalPadding * 2;
else
offset += mTopicsList->getItemWidget(keyword)->getHeight() + sVerticalPadding * 2;
}
mTopicsList->setViewOffset(-offset);
}
}

View File

@ -971,15 +971,10 @@ namespace
// Scroll the list to keep the active item in view
Gui::MWList* list = getWidget<Gui::MWList>(mQuestMode ? QuestsList : TopicsList);
if (mSelectedQuest <= 3)
list->setViewOffset(0);
else
{
int offset = 0;
for (int i = 0; i < static_cast<int>(mSelectedQuest) - 3; i++)
offset += mButtons[i]->getHeight() + 3;
list->setViewOffset(-offset);
}
int offset = 0;
for (int i = 3; i < static_cast<int>(mSelectedQuest); i++)
offset += mButtons[i]->getHeight();
list->setViewOffset(-offset);
}
}
};