Fixed an issues where textlist entries would sometimes scroll horizontally even though they fit inside the element width.

This commit is contained in:
Leon Styhre 2023-03-04 21:57:33 +01:00
parent 309e635be4
commit deaa4e13b3
2 changed files with 11 additions and 6 deletions

View file

@ -282,17 +282,17 @@ template <typename T> void TextListComponent<T>::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<unsigned int>(mCursor)).name))
.x};
const float limit {mSize.x - mHorizontalMargin * 2.0f};
float length {0.0f};
if (textLength > limit) {
if (mEntries.at(static_cast<unsigned int>(mCursor)).data.textCache != nullptr)
length = mEntries.at(static_cast<unsigned int>(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};

View file

@ -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;