From 16955e5318b4609680aefeda0b4be617f6176968 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sat, 9 Apr 2022 15:57:37 +0200 Subject: [PATCH] Fixed an issue where the theme sets were not always sorted correctly. --- es-app/src/CollectionSystemsManager.cpp | 2 +- es-app/src/guis/GuiMenu.cpp | 14 ++++++++------ es-app/src/views/GamelistView.cpp | 4 ++-- es-app/src/views/SystemView.cpp | 4 ++-- es-core/src/ThemeData.cpp | 5 +++-- es-core/src/ThemeData.h | 14 +++++++++++--- 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/es-app/src/CollectionSystemsManager.cpp b/es-app/src/CollectionSystemsManager.cpp index 16fd70a29..1f473afbe 100644 --- a/es-app/src/CollectionSystemsManager.cpp +++ b/es-app/src/CollectionSystemsManager.cpp @@ -1355,7 +1355,7 @@ std::vector CollectionSystemsManager::getSystemsFromTheme() if (themeSets.empty()) return systems; // No theme sets available. - std::map::const_iterator set = + std::map::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. diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index 4e67dfff4..c87925699 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -98,8 +98,10 @@ void GuiMenu::openUIOptions() // Theme options section. - std::map themeSets {ThemeData::getThemeSets()}; - std::map::const_iterator selectedSet; + std::map themeSets { + ThemeData::getThemeSets()}; + std::map::const_iterator + selectedSet; auto theme_set = std::make_shared>(getHelpStyle(), "THEME SET", false); @@ -153,8 +155,8 @@ void GuiMenu::openUIOptions() auto themeVariantsFunc = [=](const std::string& selectedTheme, const std::string& selectedVariant) { - std::map::const_iterator currentSet { - themeSets.find(selectedTheme)}; + std::map::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::const_iterator currentSet { - themeSets.find(selectedTheme)}; + std::map::const_iterator + currentSet {themeSets.find(selectedTheme)}; if (currentSet == themeSets.cend()) return; // We need to recreate the OptionListComponent entries. diff --git a/es-app/src/views/GamelistView.cpp b/es-app/src/views/GamelistView.cpp index 13ff86f20..5f309e5c8 100644 --- a/es-app/src/views/GamelistView.cpp +++ b/es-app/src/views/GamelistView.cpp @@ -91,8 +91,8 @@ void GamelistView::onTransition() void GamelistView::onThemeChanged(const std::shared_ptr& theme) { auto themeSets = ThemeData::getThemeSets(); - std::map::const_iterator selectedSet { - themeSets.find(Settings::getInstance()->getString("ThemeSet"))}; + std::map::const_iterator + selectedSet {themeSets.find(Settings::getInstance()->getString("ThemeSet"))}; assert(selectedSet != themeSets.cend()); mLegacyMode = selectedSet->second.capabilities.legacyTheme; diff --git a/es-app/src/views/SystemView.cpp b/es-app/src/views/SystemView.cpp index 90f87fe58..b79f9f126 100644 --- a/es-app/src/views/SystemView.cpp +++ b/es-app/src/views/SystemView.cpp @@ -361,8 +361,8 @@ void SystemView::populate() LOG(LogDebug) << "SystemView::populate(): Populating carousel"; auto themeSets = ThemeData::getThemeSets(); - std::map::const_iterator selectedSet { - themeSets.find(Settings::getInstance()->getString("ThemeSet"))}; + std::map::const_iterator + selectedSet {themeSets.find(Settings::getInstance()->getString("ThemeSet"))}; assert(selectedSet != themeSets.cend()); mLegacyMode = selectedSet->second.capabilities.legacyTheme; diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index 1481661af..49ed2d1be 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -500,7 +500,8 @@ const ThemeData::ThemeElement* ThemeData::getElement(const std::string& view, return &elemIt->second; } -const std::map& ThemeData::getThemeSets() +const std::map& +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::const_iterator set { + std::map::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 diff --git a/es-core/src/ThemeData.h b/es-core/src/ThemeData.h index 118233cba..5193f2026 100644 --- a/es-core/src/ThemeData.h +++ b/es-core/src/ThemeData.h @@ -13,6 +13,7 @@ #include "utils/FileSystemUtil.h" #include "utils/MathUtil.h" +#include "utils/StringUtil.h" #include #include @@ -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& 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& getThemeSets(); + const static std::map& 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> sPropertyAttributeMap; static std::map> sElementMap; - static inline std::map mThemeSets; - std::map::iterator mCurrentThemeSet; + static inline std::map mThemeSets; + std::map::iterator mCurrentThemeSet; std::map mViews; std::deque mPaths;