Fixed an issue where the theme sets were not always sorted correctly.

This commit is contained in:
Leon Styhre 2022-04-09 15:57:37 +02:00
parent 21f21c20f5
commit 16955e5318
6 changed files with 27 additions and 16 deletions

View file

@ -1355,7 +1355,7 @@ std::vector<std::string> CollectionSystemsManager::getSystemsFromTheme()
if (themeSets.empty())
return systems; // No theme sets available.
std::map<std::string, ThemeData::ThemeSet>::const_iterator set =
std::map<std::string, ThemeData::ThemeSet, ThemeData::StringComparator>::const_iterator set =
themeSets.find(Settings::getInstance()->getString("ThemeSet"));
if (set == themeSets.cend()) {
// Currently selected theme set is missing, so just pick the first available set.

View file

@ -98,8 +98,10 @@ void GuiMenu::openUIOptions()
// Theme options section.
std::map<std::string, ThemeData::ThemeSet> themeSets {ThemeData::getThemeSets()};
std::map<std::string, ThemeData::ThemeSet>::const_iterator selectedSet;
std::map<std::string, ThemeData::ThemeSet, ThemeData::StringComparator> themeSets {
ThemeData::getThemeSets()};
std::map<std::string, ThemeData::ThemeSet, ThemeData::StringComparator>::const_iterator
selectedSet;
auto theme_set =
std::make_shared<OptionListComponent<std::string>>(getHelpStyle(), "THEME SET", false);
@ -153,8 +155,8 @@ void GuiMenu::openUIOptions()
auto themeVariantsFunc = [=](const std::string& selectedTheme,
const std::string& selectedVariant) {
std::map<std::string, ThemeData::ThemeSet>::const_iterator currentSet {
themeSets.find(selectedTheme)};
std::map<std::string, ThemeData::ThemeSet, ThemeData::StringComparator>::const_iterator
currentSet {themeSets.find(selectedTheme)};
if (currentSet == themeSets.cend())
return;
// We need to recreate the OptionListComponent entries.
@ -209,8 +211,8 @@ void GuiMenu::openUIOptions()
auto themeAspectRatiosFunc = [=](const std::string& selectedTheme,
const std::string& selectedAspectRatio) {
std::map<std::string, ThemeData::ThemeSet>::const_iterator currentSet {
themeSets.find(selectedTheme)};
std::map<std::string, ThemeData::ThemeSet, ThemeData::StringComparator>::const_iterator
currentSet {themeSets.find(selectedTheme)};
if (currentSet == themeSets.cend())
return;
// We need to recreate the OptionListComponent entries.

View file

@ -91,8 +91,8 @@ void GamelistView::onTransition()
void GamelistView::onThemeChanged(const std::shared_ptr<ThemeData>& theme)
{
auto themeSets = ThemeData::getThemeSets();
std::map<std::string, ThemeData::ThemeSet>::const_iterator selectedSet {
themeSets.find(Settings::getInstance()->getString("ThemeSet"))};
std::map<std::string, ThemeData::ThemeSet, ThemeData::StringComparator>::const_iterator
selectedSet {themeSets.find(Settings::getInstance()->getString("ThemeSet"))};
assert(selectedSet != themeSets.cend());
mLegacyMode = selectedSet->second.capabilities.legacyTheme;

View file

@ -361,8 +361,8 @@ void SystemView::populate()
LOG(LogDebug) << "SystemView::populate(): Populating carousel";
auto themeSets = ThemeData::getThemeSets();
std::map<std::string, ThemeData::ThemeSet>::const_iterator selectedSet {
themeSets.find(Settings::getInstance()->getString("ThemeSet"))};
std::map<std::string, ThemeData::ThemeSet, ThemeData::StringComparator>::const_iterator
selectedSet {themeSets.find(Settings::getInstance()->getString("ThemeSet"))};
assert(selectedSet != themeSets.cend());
mLegacyMode = selectedSet->second.capabilities.legacyTheme;

View file

@ -500,7 +500,8 @@ const ThemeData::ThemeElement* ThemeData::getElement(const std::string& view,
return &elemIt->second;
}
const std::map<std::string, ThemeData::ThemeSet>& ThemeData::getThemeSets()
const std::map<std::string, ThemeData::ThemeSet, ThemeData::StringComparator>&
ThemeData::getThemeSets()
{
if (!mThemeSets.empty())
return mThemeSets;
@ -564,7 +565,7 @@ const std::string ThemeData::getThemeFromCurrentSet(const std::string& system)
// No theme sets available.
return "";
std::map<std::string, ThemeSet>::const_iterator set {
std::map<std::string, ThemeSet, StringComparator>::const_iterator set {
mThemeSets.find(Settings::getInstance()->getString("ThemeSet"))};
if (set == mThemeSets.cend()) {
// Currently configured theme set is missing, attempt to load the default theme set

View file

@ -13,6 +13,7 @@
#include "utils/FileSystemUtil.h"
#include "utils/MathUtil.h"
#include "utils/StringUtil.h"
#include <algorithm>
#include <any>
@ -200,6 +201,13 @@ public:
}
};
struct StringComparator {
bool operator()(const std::string& a, const std::string& b) const
{
return Utils::String::toUpper(a) < Utils::String::toUpper(b);
}
};
void loadFile(const std::map<std::string, std::string>& sysDataMap, const std::string& path);
bool hasView(const std::string& view);
ThemeView& getViewElements(std::string view) { return mViews[view]; }
@ -211,7 +219,7 @@ public:
const std::string& element,
const std::string& expectedType) const;
const static std::map<std::string, ThemeSet>& getThemeSets();
const static std::map<std::string, ThemeSet, StringComparator>& getThemeSets();
const static std::string getThemeFromCurrentSet(const std::string& system);
const static std::string getAspectRatioLabel(const std::string& aspectRatio);
@ -256,8 +264,8 @@ private:
static std::map<std::string, std::map<std::string, std::string>> sPropertyAttributeMap;
static std::map<std::string, std::map<std::string, ElementPropertyType>> sElementMap;
static inline std::map<std::string, ThemeSet> mThemeSets;
std::map<std::string, ThemeData::ThemeSet>::iterator mCurrentThemeSet;
static inline std::map<std::string, ThemeSet, StringComparator> mThemeSets;
std::map<std::string, ThemeSet, StringComparator>::iterator mCurrentThemeSet;
std::map<std::string, ThemeView> mViews;
std::deque<std::string> mPaths;