#include "cru/ui/ThemeManager.h" #include "cru/base/io/Resource.h" #include "cru/platform/graphics/Brush.h" #include "cru/ui/ThemeResourceDictionary.h" #include "cru/ui/style/StyleRuleSet.h" namespace cru::ui { ThemeManager* ThemeManager::GetInstance() { static ThemeManager instance; return &instance; } ThemeManager::ThemeManager() { std::filesystem::path resourses_file = cru::io::GetResourceDir() / "cru/ui/DefaultResources.xml"; if (!std::filesystem::exists(resourses_file)) { throw Exception("Default resources file not found."); } PrependThemeResourceDictionary( ThemeResourceDictionary::FromFile(String::FromStdPath(resourses_file))); } ThemeManager::~ThemeManager() {} std::vector ThemeManager::GetThemeResourceDictionaryList() const { std::vector result; for (const auto& theme_resource_dictionary : theme_resource_dictionary_list_) { result.push_back(theme_resource_dictionary.get()); } return result; } void ThemeManager::PrependThemeResourceDictionary( std::unique_ptr theme_resource_dictionary) { theme_resource_dictionary_list_.insert( theme_resource_dictionary_list_.begin(), std::move(theme_resource_dictionary)); theme_resource_change_event_.Raise(nullptr); } std::string ThemeManager::GetResourceString(std::string_view key) { return GetResource(key).ToUtf8(); } std::shared_ptr ThemeManager::GetResourceBrush( std::string_view key) { return GetResource>(key); } std::shared_ptr ThemeManager::GetResourceFont( std::string_view key) { return GetResource>(key); } std::shared_ptr ThemeManager::GetResourceStyleRuleSet( std::string_view key) { return GetResource>(key); } } // namespace cru::ui