From f463ee7d7b656e8c838ddc8f3f105e7a1fccf8d4 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Thu, 10 Aug 2023 19:20:44 +0200 Subject: [PATCH] Added a number of properties to allow horizontally scrolling text entries with GridComponent --- es-core/src/ThemeData.cpp | 4 ++ .../components/primary/CarouselComponent.h | 3 +- .../src/components/primary/GridComponent.h | 40 ++++++++++++++++--- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index 13bb974df..3894fa2b0 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -209,6 +209,10 @@ std::map> {"textBackgroundColor", COLOR}, {"textSelectedColor", COLOR}, {"textSelectedBackgroundColor", COLOR}, + {"textHorizontalScrolling", BOOLEAN}, + {"textHorizontalScrollSpeed", FLOAT}, + {"textHorizontalScrollDelay", FLOAT}, + {"textHorizontalScrollGap", FLOAT}, {"fontPath", PATH}, {"fontSize", FLOAT}, {"letterCase", STRING}, diff --git a/es-core/src/components/primary/CarouselComponent.h b/es-core/src/components/primary/CarouselComponent.h index 06022ca48..debe3db45 100644 --- a/es-core/src/components/primary/CarouselComponent.h +++ b/es-core/src/components/primary/CarouselComponent.h @@ -362,7 +362,8 @@ void CarouselComponent::addEntry(Entry& entry, const std::shared_ptr( entry.name, mFont, 0x000000FF, mItemHorizontalAlignment, mItemVerticalAlignment, glm::vec3 {0.0f, 0.0f, 0.0f}, diff --git a/es-core/src/components/primary/GridComponent.h b/es-core/src/components/primary/GridComponent.h index 4b31ebc15..ad6d545b8 100644 --- a/es-core/src/components/primary/GridComponent.h +++ b/es-core/src/components/primary/GridComponent.h @@ -192,6 +192,10 @@ private: unsigned int mTextSelectedColor; unsigned int mTextSelectedBackgroundColor; bool mHasTextSelectedColor; + bool mTextHorizontalScrolling; + float mTextHorizontalScrollSpeed; + float mTextHorizontalScrollDelay; + float mTextHorizontalScrollGap; std::shared_ptr mFont; LetterCase mLetterCase; LetterCase mLetterCaseAutoCollections; @@ -260,6 +264,10 @@ GridComponent::GridComponent() , mTextSelectedColor {0x000000FF} , mTextSelectedBackgroundColor {0xFFFFFF00} , mHasTextSelectedColor {false} + , mTextHorizontalScrolling {false} + , mTextHorizontalScrollSpeed {1.0f} + , mTextHorizontalScrollDelay {3000.0f} + , mTextHorizontalScrollGap {1.5f} , mLetterCase {LetterCase::NONE} , mLetterCaseAutoCollections {LetterCase::UNDEFINED} , mLetterCaseCustomCollections {LetterCase::UNDEFINED} @@ -355,14 +363,14 @@ void GridComponent::addEntry(Entry& entry, const std::shared_ptr& } if (!entry.data.item) { - // If no item image is present, add item text as fallback. + // Always add the item text as fallback in case there is no image. This is also displayed + // when quick-jumping as textures are not loaded in this case. auto text = std::make_shared( entry.name, mFont, 0x000000FF, Alignment::ALIGN_CENTER, Alignment::ALIGN_CENTER, - glm::vec3 {0.0f, 0.0f, 0.0f}, mItemSize * mTextRelativeScale, 0x00000000); + glm::vec3 {0.0f, 0.0f, 0.0f}, mItemSize * mTextRelativeScale, 0x00000000, mLineSpacing, + mTextRelativeScale, mTextHorizontalScrolling, mTextHorizontalScrollSpeed, + mTextHorizontalScrollDelay, mTextHorizontalScrollGap); text->setOrigin(0.5f, 0.5f); - text->setLineSpacing(mLineSpacing); - if (!mGamelistView) - text->setValue(entry.name); text->setColor(mTextColor); text->setBackgroundColor(mTextBackgroundColor); text->setRenderBackground(true); @@ -621,6 +629,7 @@ template bool GridComponent::input(InputConfig* config, Input in template void GridComponent::update(int deltaTime) { + mEntries.at(mCursor).data.item->update(deltaTime); List::listUpdate(deltaTime); GuiComponent::update(deltaTime); } @@ -1318,6 +1327,24 @@ void GridComponent::applyTheme(const std::shared_ptr& theme, mHasTextSelectedColor = true; } + if (elem->has("textHorizontalScrolling")) + mTextHorizontalScrolling = elem->get("textHorizontalScrolling"); + + if (elem->has("textHorizontalScrollSpeed")) { + mTextHorizontalScrollSpeed = + glm::clamp(elem->get("textHorizontalScrollSpeed"), 0.1f, 10.0f); + } + + if (elem->has("textHorizontalScrollDelay")) { + mTextHorizontalScrollDelay = + glm::clamp(elem->get("textHorizontalScrollDelay"), 0.0f, 10.0f) * 1000.0f; + } + + if (elem->has("textHorizontalScrollGap")) { + mTextHorizontalScrollGap = + glm::clamp(elem->get("textHorizontalScrollGap"), 0.1f, 5.0f); + } + if (elem->has("lineSpacing")) mLineSpacing = glm::clamp(elem->get("lineSpacing"), 0.5f, 3.0f); @@ -1416,6 +1443,9 @@ void GridComponent::applyTheme(const std::shared_ptr& theme, template void GridComponent::onCursorChanged(const CursorState& state) { + if (mEntries.size() > static_cast(mLastCursor)) + mEntries.at(mLastCursor).data.item->resetComponent(); + if (mColumns == 0) return;