From 192f218bd54adaf86cebfc09794cf9665e6e941f Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Wed, 1 Feb 2023 19:55:24 +0100 Subject: [PATCH] Added two new textlist properties selectedBackgroundColor and selectedSecondaryBackgroundColor. --- es-core/src/ThemeData.cpp | 2 ++ .../components/primary/TextListComponent.h | 34 +++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index 0939a9df1..81aa7eebd 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -255,6 +255,8 @@ std::map> {"secondaryColor", COLOR}, {"selectedColor", COLOR}, {"selectedSecondaryColor", COLOR}, + {"selectedBackgroundColor", COLOR}, + {"selectedSecondaryBackgroundColor", COLOR}, {"fontPath", PATH}, {"fontSize", FLOAT}, {"scrollSound", PATH}, // For backward compatibility with legacy themes. diff --git a/es-core/src/components/primary/TextListComponent.h b/es-core/src/components/primary/TextListComponent.h index a430d4084..6d82a6a74 100644 --- a/es-core/src/components/primary/TextListComponent.h +++ b/es-core/src/components/primary/TextListComponent.h @@ -142,6 +142,8 @@ private: unsigned int mSecondaryColor; unsigned int mSelectedColor; unsigned int mSelectedSecondaryColor; + unsigned int mSelectedBackgroundColor; + unsigned int mSelectedSecondaryBackgroundColor; PrimaryAlignment mAlignment; float mHorizontalMargin; LetterCase mLetterCase; @@ -180,6 +182,8 @@ TextListComponent::TextListComponent() , mSecondaryColor {0x00FF00FF} , mSelectedColor {0x0000FFFF} , mSelectedSecondaryColor {0x00FF00FF} + , mSelectedBackgroundColor {0x00000000} + , mSelectedSecondaryBackgroundColor {0x00000000} , mAlignment {PrimaryAlignment::ALIGN_CENTER} , mHorizontalMargin {0.0f} , mLetterCase {LetterCase::NONE} @@ -407,12 +411,17 @@ template void TextListComponent::render(const glm::mat4& parentT for (int i = startEntry; i < listCutoff; ++i) { Entry& entry {mEntries.at(i)}; - unsigned int color {0}; + unsigned int color {0x00000000}; + unsigned int backgroundColor {0x00000000}; - if (entry.data.entryType == TextListEntryType::PRIMARY) + if (entry.data.entryType == TextListEntryType::PRIMARY) { color = (mCursor == i ? mSelectedColor : mPrimaryColor); - else + backgroundColor = (mCursor == i ? mSelectedBackgroundColor : 0x00000000); + } + else { color = (mCursor == i ? mSelectedSecondaryColor : mSecondaryColor); + backgroundColor = (mCursor == i ? mSelectedSecondaryBackgroundColor : 0x00000000); + } if (!entry.data.textCache) { entry.data.textCache = @@ -470,6 +479,13 @@ template void TextListComponent::render(const glm::mat4& parentT mLoopScroll = false; mRenderer->setMatrix(drawTrans); + + if (i == mCursor && backgroundColor != 0x00000000) { + mRenderer->drawRect(mSelectorHorizontalOffset, 0.0f, + entry.data.textCache->metrics.size.x, mSelectorHeight, + backgroundColor, backgroundColor); + } + font->renderTextCache(entry.data.textCache.get()); // Render currently selected row again if text is moved far enough for it to repeat. @@ -479,6 +495,11 @@ template void TextListComponent::render(const glm::mat4& parentT drawTrans = glm::translate( drawTrans, offset - glm::vec3 {static_cast(mLoopOffset2), 0.0f, 0.0f}); mRenderer->setMatrix(drawTrans); + if (i == mCursor && backgroundColor != 0x00000000) { + mRenderer->drawRect(mSelectorHorizontalOffset, 0.0f, + entry.data.textCache->metrics.size.x, mSelectorHeight, + backgroundColor, backgroundColor); + } font->renderTextCache(entry.data.textCache.get()); } y += entrySize; @@ -545,6 +566,13 @@ void TextListComponent::applyTheme(const std::shared_ptr& theme, mSelectedSecondaryColor = elem->get("selectedSecondaryColor"); else mSelectedSecondaryColor = mSelectedColor; + if (elem->has("selectedBackgroundColor")) + mSelectedBackgroundColor = elem->get("selectedBackgroundColor"); + if (elem->has("selectedSecondaryBackgroundColor")) + mSelectedSecondaryBackgroundColor = + elem->get("selectedSecondaryBackgroundColor"); + else + mSelectedSecondaryBackgroundColor = mSelectedBackgroundColor; } setFont(Font::getFromTheme(elem, properties, mFont, 0.0f, false, mLegacyMode));