Fixed some GridComponent animation glitches when marking games as favorites.

This commit is contained in:
Leon Styhre 2022-12-05 21:15:15 +01:00
parent fe1f408355
commit b9e6cdd9da
3 changed files with 22 additions and 0 deletions

View file

@ -435,11 +435,18 @@ bool GamelistBase::input(InputConfig* config, Input input)
}
else if (CollectionSystemsManager::getInstance()->toggleGameInCollection(
entryToUpdate)) {
// Needed to avoid some minor transition animation glitches.
auto grid =
ViewController::getInstance()->getGamelistView(system).get()->mGrid.get();
if (grid != nullptr)
grid->setSuppressTransitions(true);
// As the toggling of the game destroyed this object, we need to get the view
// from ViewController instead of using the reference that existed before the
// destruction. Otherwise we get random crashes.
GamelistView* view {
ViewController::getInstance()->getGamelistView(system).get()};
// Jump to the first entry in the gamelist if the last favorite was unmarked.
if (foldersOnTop && removedLastFavorite &&
!entryToUpdate->getSystem()->isCustomCollection()) {
@ -457,6 +464,10 @@ bool GamelistBase::input(InputConfig* config, Input input)
else if (selectLastEntry && view->getPrimary()->size() > 0) {
view->setCursor(view->getLastEntry());
}
if (grid != nullptr)
grid->setSuppressTransitions(false);
// Display the indication icons which show what games are part of the
// custom collection currently being edited. This is done cheaply using
// onFileChanged() which will trigger populateList().

View file

@ -49,7 +49,12 @@ void GamelistView::onFileChanged(FileData* file, bool reloadGamelist)
FileData* cursor {getCursor()};
if (!cursor->isPlaceHolder()) {
populateList(cursor->getParent()->getChildrenListToDisplay(), cursor->getParent());
// Needed to avoid some minor transition animation glitches.
if (mGrid != nullptr)
mGrid->setSuppressTransitions(true);
setCursor(cursor);
if (mGrid != nullptr)
mGrid->setSuppressTransitions(false);
}
else {
populateList(mRoot->getChildrenListToDisplay(), mRoot);

View file

@ -44,6 +44,7 @@ public:
const int getColumnCount() const { return mColumns; }
const int getRowCount() const { return mRows; }
void setScrollVelocity(int velocity) { mScrollVelocity = velocity; }
void setSuppressTransitions(bool state) { mSuppressTransitions = state; }
void setCancelTransitionsCallback(const std::function<void()>& func) override
{
@ -138,6 +139,7 @@ private:
bool mLayoutValid;
bool mWasScrolling;
bool mJustCalculatedLayout;
bool mSuppressTransitions;
};
template <typename T>
@ -172,6 +174,7 @@ GridComponent<T>::GridComponent()
, mLayoutValid {false}
, mWasScrolling {false}
, mJustCalculatedLayout {false}
, mSuppressTransitions {false}
{
}
@ -725,6 +728,9 @@ template <typename T> void GridComponent<T>::onCursorChanged(const CursorState&
// glm::clamp(std::fabs(glm::mix(0.0f, animTime, timeDiff * 1.5f)), 180.0f,
// animTime);
if (mSuppressTransitions)
animTime = 0.0f;
const float visibleRows {mVisibleRows - 1.0f};
const float startRow {static_cast<float>(mScrollPos)};
float endRow {static_cast<float>(mCursor / mColumns)};