From deaa4e13b3bb39f2b28a6bb6b91da82a5d9a51bb Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sat, 4 Mar 2023 21:57:33 +0100 Subject: [PATCH] Fixed an issues where textlist entries would sometimes scroll horizontally even though they fit inside the element width. --- es-core/src/components/primary/TextListComponent.h | 12 ++++++------ es-core/src/resources/Font.h | 5 +++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/es-core/src/components/primary/TextListComponent.h b/es-core/src/components/primary/TextListComponent.h index 38b50eb52..fbc54147f 100644 --- a/es-core/src/components/primary/TextListComponent.h +++ b/es-core/src/components/primary/TextListComponent.h @@ -282,17 +282,17 @@ template void TextListComponent::update(int deltaTime) mLoopOffset2 = 0; // If we're not scrolling and this object's text exceeds our size, then loop it. - const float textLength {mFont - ->sizeText(Utils::String::toUpper( - mEntries.at(static_cast(mCursor)).name)) - .x}; const float limit {mSize.x - mHorizontalMargin * 2.0f}; + float length {0.0f}; - if (textLength > limit) { + if (mEntries.at(static_cast(mCursor)).data.textCache != nullptr) + length = mEntries.at(static_cast(mCursor)).data.textCache->getSize().x; + + if (length != 0.0f && length > limit) { // Loop the text. const float speed {mFont->sizeText("ABCDEFGHIJKLMNOPQRSTUVWXYZ").x * 0.247f}; const float delay {3000.0f}; - const float scrollLength {textLength}; + const float scrollLength {length}; const float returnLength {speed * 1.5f}; const float scrollTime {(scrollLength * 1000.0f) / speed}; const float returnTime {(returnLength * 1000.0f) / speed}; diff --git a/es-core/src/resources/Font.h b/es-core/src/resources/Font.h index 86990aa53..aed73b85f 100644 --- a/es-core/src/resources/Font.h +++ b/es-core/src/resources/Font.h @@ -234,12 +234,17 @@ public: struct CacheMetrics { glm::vec2 size; int maxGlyphHeight; + + CacheMetrics() + : size {0.0f, 0.0f} + , maxGlyphHeight {0} {}; } metrics; void setColor(unsigned int color); void setOpacity(float opacity); void setSaturation(float saturation); void setDimming(float dimming); + const glm::vec2& getSize() { return metrics.size; } friend Font;