Added a selectedSecondaryColor property to TextListComponent.

This commit is contained in:
Leon Styhre 2022-11-03 23:24:11 +01:00
parent b91daa113d
commit b4d2babf01
4 changed files with 36 additions and 20 deletions

View file

@ -570,7 +570,6 @@ void GamelistBase::populateList(const std::vector<FileData*>& files, FileData* f
std::string name; std::string name;
std::string carouselItemType; std::string carouselItemType;
std::string carouselDefaultItem; std::string carouselDefaultItem;
unsigned int color {0};
if (mCarousel != nullptr) { if (mCarousel != nullptr) {
carouselItemType = mCarousel->getItemType(); carouselItemType = mCarousel->getItemType();
@ -672,10 +671,12 @@ void GamelistBase::populateList(const std::vector<FileData*>& files, FileData* f
else if (letterCase == LetterCase::CAPITALIZED) else if (letterCase == LetterCase::CAPITALIZED)
name = Utils::String::toCapitalized(name); name = Utils::String::toCapitalized(name);
color = (*it)->getType() == FOLDER;
textListEntry.name = name; textListEntry.name = name;
textListEntry.object = *it; textListEntry.object = *it;
textListEntry.data.colorId = color; if ((*it)->getType() == FOLDER)
textListEntry.data.entryType = TextListEntryType::SECONDARY;
else
textListEntry.data.entryType = TextListEntryType::PRIMARY;
mTextList->addEntry(textListEntry); mTextList->addEntry(textListEntry);
} }
} }
@ -702,7 +703,7 @@ void GamelistBase::addPlaceholder(FileData* firstEntry)
TextListComponent<FileData*>::Entry textListEntry; TextListComponent<FileData*>::Entry textListEntry;
textListEntry.name = placeholder->getName(); textListEntry.name = placeholder->getName();
textListEntry.object = placeholder; textListEntry.object = placeholder;
textListEntry.data.colorId = 1; textListEntry.data.entryType = TextListEntryType::SECONDARY;
mTextList->addEntry(textListEntry); mTextList->addEntry(textListEntry);
} }
if (mCarousel != nullptr) { if (mCarousel != nullptr) {

View file

@ -680,7 +680,7 @@ void SystemView::populate()
entry.name = it->getFullName(); entry.name = it->getFullName();
letterCaseFunc(entry.name); letterCaseFunc(entry.name);
entry.object = it; entry.object = it;
entry.data.colorId = 0; entry.data.entryType = TextListEntryType::PRIMARY;
mTextList->addEntry(entry); mTextList->addEntry(entry);
} }
} }

View file

@ -333,9 +333,10 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"selectorGradientType", STRING}, {"selectorGradientType", STRING},
{"selectorImagePath", PATH}, {"selectorImagePath", PATH},
{"selectorImageTile", BOOLEAN}, {"selectorImageTile", BOOLEAN},
{"selectedColor", COLOR},
{"primaryColor", COLOR}, {"primaryColor", COLOR},
{"secondaryColor", COLOR}, {"secondaryColor", COLOR},
{"selectedColor", COLOR},
{"selectedSecondaryColor", COLOR},
{"fontPath", PATH}, {"fontPath", PATH},
{"fontSize", FLOAT}, {"fontSize", FLOAT},
{"scrollSound", PATH}, // For backward compatibility with legacy themes. {"scrollSound", PATH}, // For backward compatibility with legacy themes.

View file

@ -15,8 +15,13 @@
#include "components/primary/PrimaryComponent.h" #include "components/primary/PrimaryComponent.h"
#include "resources/Font.h" #include "resources/Font.h"
enum class TextListEntryType {
PRIMARY,
SECONDARY
};
struct TextListData { struct TextListData {
unsigned int colorId; TextListEntryType entryType;
std::shared_ptr<TextCache> textCache; std::shared_ptr<TextCache> textCache;
}; };
@ -133,10 +138,11 @@ private:
float mSelectorOffsetY; float mSelectorOffsetY;
unsigned int mSelectorColor; unsigned int mSelectorColor;
unsigned int mSelectorColorEnd; unsigned int mSelectorColorEnd;
bool mSelectorColorGradientHorizontal = true; bool mSelectorColorGradientHorizontal;
unsigned int mPrimaryColor;
unsigned int mSecondaryColor;
unsigned int mSelectedColor; unsigned int mSelectedColor;
static const unsigned int COLOR_ID_COUNT {2}; unsigned int mSelectedSecondaryColor;
unsigned int mColors[COLOR_ID_COUNT];
}; };
template <typename T> template <typename T>
@ -167,8 +173,10 @@ TextListComponent<T>::TextListComponent()
, mSelectorColor {0x333333FF} , mSelectorColor {0x333333FF}
, mSelectorColorEnd {0x333333FF} , mSelectorColorEnd {0x333333FF}
, mSelectorColorGradientHorizontal {true} , mSelectorColorGradientHorizontal {true}
, mSelectedColor {0} , mPrimaryColor {0x0000FFFF}
, mColors {0x0000FFFF, 0x00FF00FF} , mSecondaryColor {0x00FF00FF}
, mSelectedColor {0x0000FFFF}
, mSelectedSecondaryColor {0x00FF00FF}
{ {
} }
@ -383,12 +391,12 @@ template <typename T> void TextListComponent<T>::render(const glm::mat4& parentT
for (int i = startEntry; i < listCutoff; ++i) { for (int i = startEntry; i < listCutoff; ++i) {
Entry& entry {mEntries.at(i)}; Entry& entry {mEntries.at(i)};
unsigned int color {0};
unsigned int color; if (entry.data.entryType == TextListEntryType::PRIMARY)
if (mCursor == i && mSelectedColor) color = (mCursor == i ? mSelectedColor : mPrimaryColor);
color = mSelectedColor;
else else
color = mColors[entry.data.colorId]; color = (mCursor == i ? mSelectedSecondaryColor : mSecondaryColor);
if (!entry.data.textCache) { if (!entry.data.textCache) {
entry.data.textCache = entry.data.textCache =
@ -502,12 +510,18 @@ void TextListComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
<< element.substr(9) << "\" defined as \"" << gradientType << "\""; << element.substr(9) << "\" defined as \"" << gradientType << "\"";
} }
} }
if (elem->has("primaryColor"))
mPrimaryColor = elem->get<unsigned int>("primaryColor");
if (elem->has("secondaryColor"))
mSecondaryColor = elem->get<unsigned int>("secondaryColor");
if (elem->has("selectedColor")) if (elem->has("selectedColor"))
mSelectedColor = elem->get<unsigned int>("selectedColor"); mSelectedColor = elem->get<unsigned int>("selectedColor");
if (elem->has("primaryColor")) else
mColors[0] = elem->get<unsigned int>("primaryColor"); mSelectedColor = mPrimaryColor;
if (elem->has("secondaryColor")) if (elem->has("selectedSecondaryColor"))
mColors[1] = elem->get<unsigned int>("secondaryColor"); mSelectedSecondaryColor = elem->get<unsigned int>("selectedSecondaryColor");
else
mSelectedSecondaryColor = mSelectedColor;
} }
setFont(Font::getFromTheme(elem, properties, mFont, 0.0f, mLegacyMode)); setFont(Font::getFromTheme(elem, properties, mFont, 0.0f, mLegacyMode));