Added theme support for controlling the TextListComponent indicators.

This commit is contained in:
Leon Styhre 2022-04-15 17:06:33 +02:00
parent 486d3b0fcb
commit 254e271392
3 changed files with 65 additions and 40 deletions

View file

@ -571,14 +571,21 @@ void GamelistBase::populateList(const std::vector<FileData*>& files, FileData* f
if (mTextList != nullptr) {
TextListComponent<FileData*>::Entry textListEntry;
std::string indicators {mTextList->getIndicators()};
if (!mFirstGameEntry && (*it)->getType() == GAME)
mFirstGameEntry = (*it);
if (indicators == "none") {
name = (*it)->getName();
}
else {
// Add a leading tick mark icon to the game name if it's part of the custom
// collection currently being edited.
if (isEditing && (*it)->getType() == GAME) {
if (CollectionSystemsManager::getInstance()->inCustomCollection(
editingCollection, (*it))) {
if (Settings::getInstance()->getBool("SpecialCharsASCII"))
if (indicators == "ascii")
inCollectionPrefix = "! ";
else
inCollectionPrefix = ViewController::TICKMARK_CHAR + " ";
@ -590,7 +597,7 @@ void GamelistBase::populateList(const std::vector<FileData*>& files, FileData* f
if ((*it)->getFavorite() && favoriteStar &&
mRoot->getSystem()->getName() != "favorites") {
if (Settings::getInstance()->getBool("SpecialCharsASCII"))
if (indicators == "ascii")
name = inCollectionPrefix + "* " + (*it)->getName();
else
name = inCollectionPrefix + ViewController::FAVORITE_CHAR + " " +
@ -598,7 +605,7 @@ void GamelistBase::populateList(const std::vector<FileData*>& files, FileData* f
}
else if ((*it)->getType() == FOLDER &&
mRoot->getSystem()->getName() != "collections") {
if (Settings::getInstance()->getBool("SpecialCharsASCII")) {
if (indicators == "ascii") {
if ((*it)->metadata.get("folderlink") != "")
name = "> " + (*it)->getName();
else
@ -614,6 +621,7 @@ void GamelistBase::populateList(const std::vector<FileData*>& files, FileData* f
else {
name = inCollectionPrefix + (*it)->getName();
}
}
color = (*it)->getType() == FOLDER;
textListEntry.name = name;
textListEntry.object = *it;

View file

@ -289,6 +289,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"letterCase", STRING},
{"forceUppercase", BOOLEAN}, // For backward compatibility with legacy themes.
{"lineSpacing", FLOAT},
{"indicators", STRING},
{"zIndex", FLOAT}}},
{"gameselector",
{{"selection", STRING},

View file

@ -118,6 +118,7 @@ public:
void setSelectedColor(unsigned int color) { mSelectedColor = color; }
void setColor(unsigned int id, unsigned int color) { mColors[id] = color; }
void setLineSpacing(float lineSpacing) { mLineSpacing = lineSpacing; }
const std::string& getIndicators() const { return mIndicators; }
protected:
void onScroll() override
@ -161,6 +162,7 @@ private:
ImageComponent mSelectorImage;
std::shared_ptr<Font> mFont;
std::string mIndicators;
bool mUppercase;
bool mLowercase;
bool mCapitalize;
@ -190,6 +192,7 @@ TextListComponent<T>::TextListComponent()
, mAlignment {PrimaryAlignment::ALIGN_CENTER}
, mHorizontalMargin {0.0f}
, mFont {Font::get(FONT_SIZE_MEDIUM)}
, mIndicators {"symbols"}
, mUppercase {false}
, mLowercase {false}
, mCapitalize {false}
@ -587,8 +590,8 @@ void TextListComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (elem->has("selectorHeight"))
setSelectorHeight(elem->get<float>("selectorHeight") * Renderer::getScreenHeight());
if (elem->has("selectorOffsetY")) {
float scale = this->mParent ? this->mParent->getSize().y :
static_cast<float>(Renderer::getScreenHeight());
float scale {this->mParent ? this->mParent->getSize().y :
static_cast<float>(Renderer::getScreenHeight())};
setSelectorOffsetY(elem->get<float>("selectorOffsetY") * scale);
}
else {
@ -596,8 +599,21 @@ void TextListComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
}
}
if (elem->has("indicators")) {
std::string indicators {elem->get<std::string>("indicators")};
if (indicators == "symbols" || indicators == "ascii" || indicators == "none") {
mIndicators = indicators;
}
else {
mIndicators = "symbols";
LOG(LogWarning) << "TextListComponent: Invalid theme configuration, property "
"<indicators> defined as \""
<< indicators << "\"";
}
}
if (elem->has("selectorImagePath")) {
std::string path = elem->get<std::string>("selectorImagePath");
std::string path {elem->get<std::string>("selectorImagePath")};
bool tile = elem->has("selectorImageTile") && elem->get<bool>("selectorImageTile");
mSelectorImage.setImage(path, tile);
mSelectorImage.setSize(mSize.x, mSelectorHeight);