Fixed multiple navigation issues in GridComponent.

This commit is contained in:
Leon Styhre 2022-12-03 14:01:17 +01:00
parent 1631cbd30f
commit 3ec8ec14ca
2 changed files with 48 additions and 68 deletions

View file

@ -350,8 +350,10 @@ protected:
mLastCursor = mCursor;
if (!doScroll)
if (!doScroll) {
onCursorChanged(CursorState::CURSOR_STOPPED);
return;
}
int cursor {mCursor + amt};
int absAmt {amt < 0 ? -amt : amt};

View file

@ -416,17 +416,10 @@ template <typename T> bool GridComponent<T>::input(InputConfig* config, Input in
config->isMappedLike("up", input) || config->isMappedLike("down", input) ||
config->isMappedLike("lefttrigger", input) ||
config->isMappedLike("righttrigger", input)) {
if constexpr (std::is_same_v<T, SystemData*>) {
if (isScrolling())
onCursorChanged(CursorState::CURSOR_STOPPED);
List::listInput(0);
}
else {
if (isScrolling())
onCursorChanged(CursorState::CURSOR_STOPPED);
List::listInput(0);
}
}
}
}
@ -630,22 +623,25 @@ void GridComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
template <typename T> void GridComponent<T>::onCursorChanged(const CursorState& state)
{
if (mColumns == 0)
return;
if (mColumns != 0 && (mScrollVelocity == mColumns || mPreviousScrollVelocity == mColumns) &&
size() - mCursor <= size() % mColumns) {
if (mWasScrolling && state == CursorState::CURSOR_STOPPED && mScrollVelocity != 0) {
mWasScrolling = false;
}
else if (mWasScrolling && state == CursorState::CURSOR_STOPPED) {
if (mCursorChangedCallback)
mCursorChangedCallback(state);
mWasScrolling = false;
return;
}
if (mCursor == mLastCursor && !mJustCalculatedLayout)
if (mCursor == mLastCursor && !mJustCalculatedLayout) {
mWasScrolling = false;
if (mCursorChangedCallback)
mCursorChangedCallback(state);
return;
else
}
else {
mJustCalculatedLayout = false;
}
float startPos {mEntryOffset};
float posMax {static_cast<float>(mEntries.size())};
@ -699,34 +695,15 @@ template <typename T> void GridComponent<T>::onCursorChanged(const CursorState&
// animTime);
const float visibleRows {mVisibleRows - 1.0f};
float startRow {static_cast<float>(mLastCursor / mColumns)};
const float startRow {static_cast<float>(mScrollPos)};
float endRow {static_cast<float>(mCursor / mColumns)};
if (endRow <= visibleRows) {
if (startRow == endRow || startRow <= visibleRows) {
startRow = mScrollPos;
}
else if (startRow > visibleRows) {
if (!mFractionalRows)
startRow = mScrollPos + 1.0f;
startRow -= visibleRows;
}
if (endRow <= visibleRows)
endRow = 0.0f;
}
else {
if (startRow <= visibleRows) {
startRow = mScrollPos;
}
else {
if (mFractionalRows)
startRow = mScrollPos + visibleRows;
else
startRow = mScrollPos + 1.0f;
startRow -= visibleRows;
}
endRow -= visibleRows;
}
if (startPos != endPos) {
Animation* anim {new LambdaAnimation(
[this, startPos, endPos, posMax, startRow, endRow](float t) {
// Non-linear interpolation.
@ -754,6 +731,7 @@ template <typename T> void GridComponent<T>::onCursorChanged(const CursorState&
static_cast<int>(animTime))};
GuiComponent::setAnimation(anim, 0, nullptr, false, 0);
}
if (mCursorChangedCallback)
mCursorChangedCallback(state);