make slots configurable by theme (fix)

This commit is contained in:
Sophia Hadash 2021-09-27 01:50:45 +02:00
parent 593b6d94ee
commit a928142d5b
3 changed files with 20 additions and 7 deletions

View file

@ -14,8 +14,8 @@
#include "resources/TextureResource.h"
// Available slot definitions.
const std::vector<std::string> BadgesComponent::mSlots = {SLOT_FAVORITE, SLOT_COMPLETED, SLOT_KIDS, SLOT_BROKEN,
SLOT_ALTERNATIVE_EMULATOR};
std::vector<std::string> BadgesComponent::mSlots = {SLOT_FAVORITE, SLOT_COMPLETED, SLOT_KIDS, SLOT_BROKEN,
SLOT_ALTERNATIVE_EMULATOR};
BadgesComponent::BadgesComponent(Window *window)
: FlexboxComponent(window) {
@ -63,7 +63,7 @@ void BadgesComponent::setValue(const std::string &value) {
if (!(temp == SLOT_FAVORITE || temp == SLOT_COMPLETED || temp == SLOT_KIDS ||
temp == SLOT_BROKEN || temp == SLOT_ALTERNATIVE_EMULATOR))
LOG(LogError) << "Badge slot '" << temp << "' is invalid.";
else
else if (std::find(mSlots.begin(), mSlots.end(), temp) != mSlots.end())
mChildren.push_back(&mImageComponents.find(temp)->second);
}
}
@ -101,8 +101,21 @@ void BadgesComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
}
}
if (elem->has("slots"))
setValue(elem->get<std::string>("slots"));
if (elem->has("slots")) {
auto value = elem->get<std::string>("slots");
mSlots = {};
if (!value.empty()) {
std::string temp;
std::istringstream ss(value);
while (std::getline(ss, temp, ' ')) {
if (!(temp == SLOT_FAVORITE || temp == SLOT_COMPLETED || temp == SLOT_KIDS ||
temp == SLOT_BROKEN || temp == SLOT_ALTERNATIVE_EMULATOR))
LOG(LogError) << "Badge slot '" << temp << "' is invalid.";
else
mSlots.push_back(temp);
}
}
}
// Apply theme on the flexbox component parent.
FlexboxComponent::applyTheme(theme, view, element, properties);

View file

@ -42,7 +42,7 @@ public:
virtual std::vector<HelpPrompt> getHelpPrompts() override;
private:
static const std::vector<std::string> mSlots;
static std::vector<std::string> mSlots;
std::map<std::string, std::string> mBadgeIcons;
std::map<std::string, ImageComponent> mImageComponents;
};

View file

@ -248,7 +248,7 @@ based on: 'recalbox-multi' by the Recalbox community
<itemWidth>.035</itemWidth>
<!-- badges properties -->
<slots>favorite completed kidgame broken</slots>
<slots>favorite completed kidgame broken altemu</slots>
<customBadgeIcon badge="favorite">:/graphics/badge_favorite.svg</customBadgeIcon>
<customBadgeIcon badge="completed">:/graphics/badge_completed.svg</customBadgeIcon>
<customBadgeIcon badge="kidgame">:/graphics/badge_kidgame.svg</customBadgeIcon>