From 87d1c19e68a0fb238dd13a0790d5424320a2351a Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Tue, 27 Sep 2022 21:56:15 +0200 Subject: [PATCH] Fixed an issue where the scrollable container would not get properly sized after using the single-game scraper. --- .../src/components/ScrollableContainer.cpp | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/es-core/src/components/ScrollableContainer.cpp b/es-core/src/components/ScrollableContainer.cpp index ddf923ed4..dec2586ed 100644 --- a/es-core/src/components/ScrollableContainer.cpp +++ b/es-core/src/components/ScrollableContainer.cpp @@ -62,10 +62,24 @@ void ScrollableContainer::setScrollParameters(float autoScrollDelayConstant, void ScrollableContainer::reset() { - mScrollPos = glm::vec2 {}; + mScrollPos = glm::vec2 {0.0f, 0.0f}; mAutoScrollResetAccumulator = 0; mAutoScrollAccumulator = -mAutoScrollDelay + mAutoScrollSpeed; mAtEnd = false; + // This is needed to resize to the designated area when the backgrund image gets invalidated. + if (!mChildren.empty()) { + float combinedHeight { + mChildren.front()->getFont()->getHeight(mChildren.front()->getLineSpacing())}; + if (mChildren.front()->getSize().y > mSize.y) { + if (mVerticalSnap) { + float numLines {std::floor(mSize.y / combinedHeight)}; + mAdjustedHeight = std::round(numLines * combinedHeight); + } + else { + mAdjustedHeight = mSize.y; + } + } + } } void ScrollableContainer::applyTheme(const std::shared_ptr& theme, @@ -112,8 +126,8 @@ void ScrollableContainer::update(int deltaTime) // Calculate the spacing which will be used to clip the container. if (lineSpacing > 1.2f && mClipSpacing == 0.0f) { - const float minimumSpacing = mChildren.front()->getFont()->getHeight(1.2f); - const float currentSpacing = mChildren.front()->getFont()->getHeight(lineSpacing); + const float minimumSpacing {mChildren.front()->getFont()->getHeight(1.2f)}; + const float currentSpacing {mChildren.front()->getFont()->getHeight(lineSpacing)}; mClipSpacing = std::round((currentSpacing - minimumSpacing) / 2.0f); } @@ -219,7 +233,7 @@ void ScrollableContainer::render(const glm::mat4& parentTrans) glm::ivec2 clipPos {static_cast(trans[3].x), static_cast(trans[3].y)}; - glm::vec3 dimScaled {}; + glm::vec3 dimScaled {0.0f, 0.0f, 0.0f}; dimScaled.x = std::fabs(trans[3].x + mSize.x); dimScaled.y = std::fabs(trans[3].y + mAdjustedHeight);