aboutsummaryrefslogtreecommitdiff
path: root/include/cru/ui/ThemeManager.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/cru/ui/ThemeManager.hpp')
-rw-r--r--include/cru/ui/ThemeManager.hpp33
1 files changed, 25 insertions, 8 deletions
diff --git a/include/cru/ui/ThemeManager.hpp b/include/cru/ui/ThemeManager.hpp
index 07b5f57b..7d52fa48 100644
--- a/include/cru/ui/ThemeManager.hpp
+++ b/include/cru/ui/ThemeManager.hpp
@@ -4,6 +4,9 @@
#include "cru/common/Event.hpp"
#include "cru/common/Exception.hpp"
#include "cru/platform/graphics/Brush.hpp"
+#include "cru/ui/mapper/MapperRegistry.hpp"
+#include "cru/ui/style/StyleRuleSet.hpp"
+#include "cru/xml/XmlNode.hpp"
#include <unordered_map>
@@ -29,22 +32,36 @@ class CRU_UI_API ThemeManager : public Object {
CRU_DELETE_COPY(ThemeManager)
CRU_DELETE_MOVE(ThemeManager)
- ~ThemeManager() override = default;
+ ~ThemeManager() override;
IEvent<std::nullptr_t>* ThemeResourceChangeEvent() {
return &theme_resource_change_event_;
}
- gsl::not_null<std::shared_ptr<platform::graphics::IBrush>> GetBrush(
- StringView key);
+ void ReadResourcesFile(const String& file_path);
- private:
- void Init();
+ template <typename T>
+ T GetResource(const String& key) {
+ auto find_result = theme_resource_map_.find(key);
+ if (find_result == theme_resource_map_.cend()) {
+ throw ThemeResourceKeyNotExistException(
+ Format(u"Theme resource key \"%s\" not exist.", key));
+ }
+
+ auto mapper_registry = mapper::MapperRegistry::GetInstance();
+ auto mapper = mapper_registry->GetMapper<T>();
+ return mapper->MapFromXml(find_result->second);
+ }
+
+ std::shared_ptr<platform::graphics::IBrush> GetResourceBrush(
+ const String& key);
+
+ std::shared_ptr<style::StyleRuleSet> GetResourceStyleRuleSet(
+ const String& key);
private:
Event<std::nullptr_t> theme_resource_change_event_;
- std::unordered_map<String, String> theme_resource_map_;
- std::unordered_map<String, std::shared_ptr<platform::graphics::IBrush>>
- brushes_;
+ std::unique_ptr<xml::XmlElementNode> theme_resource_xml_root_;
+ std::unordered_map<String, xml::XmlElementNode*> theme_resource_map_;
};
} // namespace cru::ui