#pragma once #include "Base.h" #include "cru/base/Event.h" #include "cru/base/Format.h" #include "cru/ui/ThemeResourceDictionary.h" #include namespace cru::ui { class CRU_UI_API ThemeManager : public Object { public: static ThemeManager* GetInstance(); private: ThemeManager(); public: CRU_DELETE_COPY(ThemeManager) CRU_DELETE_MOVE(ThemeManager) ~ThemeManager() override; std::vector GetThemeResourceDictionaryList() const; void PrependThemeResourceDictionary( std::unique_ptr theme_resource_dictionary); template T GetResource(const String& key) { for (const auto& resource_dictionary : theme_resource_dictionary_list_) { try { return resource_dictionary->GetResource(key); } catch (ThemeResourceKeyNotExistException&) { } } throw ThemeResourceKeyNotExistException( Format(u"Theme resource key {} not exist.", key)); } String GetResourceString(const String& key); std::shared_ptr GetResourceBrush( const String& key); std::shared_ptr GetResourceFont(const String& key); std::shared_ptr GetResourceStyleRuleSet( const String& key); IEvent* ThemeResourceChangeEvent() { return &theme_resource_change_event_; } private: Event theme_resource_change_event_; std::vector> theme_resource_dictionary_list_; }; } // namespace cru::ui