From 690083a123e4c0d4c8b78996709ec2e9a4095d0e Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sat, 16 Oct 2021 13:21:52 +0200 Subject: [PATCH] The scroll indicators don't fade in and out any longer if quick jumping in a list. --- es-core/src/components/ComponentList.cpp | 7 +++++- es-core/src/components/ComponentList.h | 8 ++++--- .../src/components/ScrollIndicatorComponent.h | 24 ++++++++++++------- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/es-core/src/components/ComponentList.cpp b/es-core/src/components/ComponentList.cpp index c829399ee..d05047e79 100644 --- a/es-core/src/components/ComponentList.cpp +++ b/es-core/src/components/ComponentList.cpp @@ -15,6 +15,7 @@ ComponentList::ComponentList(Window* window) , mFocused{false} , mSetupCompleted{false} , mBottomCameraOffset{false} + , mSingleRowScroll{false} , mSelectorBarOffset{0.0f} , mCameraOffset{0.0f} , mScrollIndicatorStatus{SCROLL_NONE} @@ -63,6 +64,8 @@ bool ComponentList::input(InputConfig* config, Input input) if (size() == 0) return false; + mSingleRowScroll = false; + if (input.value && (config->isMappedTo("a", input) || config->isMappedLike("lefttrigger", input) || config->isMappedLike("righttrigger", input))) { @@ -86,9 +89,11 @@ bool ComponentList::input(InputConfig* config, Input input) // Input handler didn't consume the input - try to scroll. if (config->isMappedLike("up", input)) { + mSingleRowScroll = true; return listInput(input.value != 0 ? -1 : 0); } else if (config->isMappedLike("down", input)) { + mSingleRowScroll = true; return listInput(input.value != 0 ? 1 : 0); } else if (config->isMappedLike("leftshoulder", input)) { @@ -142,7 +147,7 @@ void ComponentList::update(int deltaTime) } if (scrollIndicatorChanged == true && mScrollIndicatorChangedCallback != nullptr) - mScrollIndicatorChangedCallback(mScrollIndicatorStatus); + mScrollIndicatorChangedCallback(mScrollIndicatorStatus, mSingleRowScroll); listUpdate(deltaTime); diff --git a/es-core/src/components/ComponentList.h b/es-core/src/components/ComponentList.h index fd7739fc5..d1a3eee01 100644 --- a/es-core/src/components/ComponentList.h +++ b/es-core/src/components/ComponentList.h @@ -90,7 +90,7 @@ public: { mScrollIndicatorStatus = SCROLL_NONE; if (mScrollIndicatorChangedCallback != nullptr) - mScrollIndicatorChangedCallback(mScrollIndicatorStatus); + mScrollIndicatorChangedCallback(mScrollIndicatorStatus, false); } void setCursorChangedCallback(const std::function& callback) @@ -102,7 +102,7 @@ public: return mCursorChangedCallback; } void setScrollIndicatorChangedCallback( - const std::function& callback) + const std::function& callback) { mScrollIndicatorChangedCallback = callback; } @@ -114,6 +114,7 @@ private: bool mFocused; bool mSetupCompleted; bool mBottomCameraOffset; + bool mSingleRowScroll; void updateCameraOffset(); void updateElementPosition(const ComponentListRow& row); @@ -126,7 +127,8 @@ private: float mCameraOffset; std::function mCursorChangedCallback; - std::function mScrollIndicatorChangedCallback; + std::function + mScrollIndicatorChangedCallback; ScrollIndicator mScrollIndicatorStatus; }; diff --git a/es-core/src/components/ScrollIndicatorComponent.h b/es-core/src/components/ScrollIndicatorComponent.h index 4c0f5801c..58afa5b9b 100644 --- a/es-core/src/components/ScrollIndicatorComponent.h +++ b/es-core/src/components/ScrollIndicatorComponent.h @@ -34,7 +34,7 @@ public: // If the scroll indicators setting is disabled, then show a permanent down arrow // symbol when the component list contains more entries than can fit on screen. componentList.get()->setScrollIndicatorChangedCallback( - [scrollUp, scrollDown](ComponentList::ScrollIndicator state) { + [scrollUp, scrollDown](ComponentList::ScrollIndicator state, bool singleRowScroll) { if (state == ComponentList::SCROLL_UP || state == ComponentList::SCROLL_UP_DOWN || state == ComponentList::SCROLL_DOWN) { @@ -46,8 +46,9 @@ public: // If the scroll indicator setting is enabled, then also show the up and up/down // combination and switch between these as the list is scrolled. componentList.get()->setScrollIndicatorChangedCallback( - [this, scrollUp, scrollDown](ComponentList::ScrollIndicator state) { - float fadeInTime{FADE_IN_TIME}; + [this, scrollUp, scrollDown](ComponentList::ScrollIndicator state, + bool singleRowScroll) { + float fadeTime{FADE_IN_TIME}; bool upFadeIn = false; bool upFadeOut = false; @@ -68,7 +69,7 @@ public: else if (state == ComponentList::SCROLL_UP && mPreviousScrollState == ComponentList::SCROLL_DOWN) { upFadeIn = true; - fadeInTime *= 1.5f; + fadeTime *= 2.0f; scrollDown->setOpacity(0); } else if (state == ComponentList::SCROLL_UP_DOWN && @@ -95,17 +96,22 @@ public: else if (state == ComponentList::SCROLL_DOWN && mPreviousScrollState == ComponentList::SCROLL_UP) { downFadeIn = true; - fadeInTime *= 1.5f; + fadeTime *= 2.0f; scrollUp->setOpacity(0); } + // If jumping more than one row using the shoulder or trigger buttons, then + // don't fade the indicators. + if (!singleRowScroll) + fadeTime = 0.0f; + if (upFadeIn) { auto upFadeInFunc = [scrollUp](float t) { scrollUp->setOpacity( static_cast(glm::mix(0.0f, 1.0f, t) * 255)); }; scrollUp->setAnimation( - new LambdaAnimation(upFadeInFunc, static_cast(fadeInTime)), 0, + new LambdaAnimation(upFadeInFunc, static_cast(fadeTime)), 0, nullptr, false); } @@ -115,7 +121,7 @@ public: static_cast(glm::mix(0.0f, 1.0f, t) * 255)); }; scrollUp->setAnimation( - new LambdaAnimation(upFadeOutFunc, static_cast(fadeInTime)), 0, + new LambdaAnimation(upFadeOutFunc, static_cast(fadeTime)), 0, nullptr, true); } @@ -125,7 +131,7 @@ public: static_cast(glm::mix(0.0f, 1.0f, t) * 255)); }; scrollDown->setAnimation( - new LambdaAnimation(downFadeInFunc, static_cast(fadeInTime)), 0, + new LambdaAnimation(downFadeInFunc, static_cast(fadeTime)), 0, nullptr, false); } @@ -135,7 +141,7 @@ public: static_cast(glm::mix(0.0f, 1.0f, t) * 255)); }; scrollDown->setAnimation( - new LambdaAnimation(downFadeOutFunc, static_cast(fadeInTime)), 0, + new LambdaAnimation(downFadeOutFunc, static_cast(fadeTime)), 0, nullptr, true); }