blob: 7358637e1710cf8e18f34e3e9e940099cfda9cb2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#include "cru/ui/ThemeManager.h"
#include "Helper.h"
#include "cru/common/StringUtil.h"
#include "cru/common/io/Resource.h"
#include "cru/platform/graphics/Brush.h"
#include "cru/platform/graphics/Factory.h"
#include "cru/platform/gui/UiApplication.h"
#include "cru/ui/ThemeResourceDictionary.h"
#include "cru/ui/style/StyleRuleSet.h"
#include "cru/xml/XmlParser.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(u"Default resources file not found.");
}
PrependThemeResourceDictionary(
ThemeResourceDictionary::FromFile(String::FromStdPath(resourses_file)));
}
ThemeManager::~ThemeManager() {}
std::vector<ThemeResourceDictionary*>
ThemeManager::GetThemeResourceDictionaryList() const {
std::vector<ThemeResourceDictionary*> 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<ThemeResourceDictionary> theme_resource_dictionary) {
theme_resource_dictionary_list_.insert(
theme_resource_dictionary_list_.begin(),
std::move(theme_resource_dictionary));
theme_resource_change_event_.Raise(nullptr);
}
String ThemeManager::GetResourceString(const String& key) {
return GetResource<String>(key);
}
std::shared_ptr<platform::graphics::IBrush> ThemeManager::GetResourceBrush(
const String& key) {
return GetResource<std::shared_ptr<platform::graphics::IBrush>>(key);
}
std::shared_ptr<platform::graphics::IFont> ThemeManager::GetResourceFont(
const String& key) {
return GetResource<std::shared_ptr<platform::graphics::IFont>>(key);
}
std::shared_ptr<style::StyleRuleSet> ThemeManager::GetResourceStyleRuleSet(
const String& key) {
return GetResource<std::shared_ptr<style::StyleRuleSet>>(key);
}
} // namespace cru::ui
|