diff options
author | crupest <crupest@outlook.com> | 2021-11-30 15:26:16 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-11-30 15:26:16 +0800 |
commit | ff6cb3b468a0d4caf87c2291818d24e0a6d12b39 (patch) | |
tree | 7799f31d70aae62e70bec5e9d1c54811e01164be /src/ui/ThemeManager.cpp | |
parent | 1bbd3e0c1817774335c97f4c59e0310b61949ece (diff) | |
download | cru-ff6cb3b468a0d4caf87c2291818d24e0a6d12b39.tar.gz cru-ff6cb3b468a0d4caf87c2291818d24e0a6d12b39.tar.bz2 cru-ff6cb3b468a0d4caf87c2291818d24e0a6d12b39.zip |
...
Diffstat (limited to 'src/ui/ThemeManager.cpp')
-rw-r--r-- | src/ui/ThemeManager.cpp | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/src/ui/ThemeManager.cpp b/src/ui/ThemeManager.cpp index a5280d40..e26da3fb 100644 --- a/src/ui/ThemeManager.cpp +++ b/src/ui/ThemeManager.cpp @@ -15,38 +15,45 @@ ThemeManager* ThemeManager::GetInstance() { ThemeManager::ThemeManager() { Init(); } void ThemeManager::Init() { - theme_tree_.put("scrollbar.collapse-thumb.color", - colors::gray.WithAlpha(128).ToString().ToUtf8()); - theme_tree_.put("scrollbar.arrow.normal.color", "#505050"); - theme_tree_.put("scrollbar.arrow.hover.color", "#505050"); - theme_tree_.put("scrollbar.arrow.press.color", "#ffffff"); - theme_tree_.put("scrollbar.arrow.disable.color", "#a3a3a3"); - theme_tree_.put("scrollbar.arrow-background.normal.color", "#f1f1f1"); - theme_tree_.put("scrollbar.arrow-background.hover.color", "#d2d2d2"); - theme_tree_.put("scrollbar.arrow-background.press.color", "#787878"); - theme_tree_.put("scrollbar.arrow-background.disable.color", "#f1f1f1"); - theme_tree_.put("scrollbar.slot.normal.color", "#f1f1f1"); - theme_tree_.put("scrollbar.slot.hover.color", "#f1f1f1"); - theme_tree_.put("scrollbar.slot.press.color", "#f1f1f1"); - theme_tree_.put("scrollbar.slot.disable.color", "#f1f1f1"); - theme_tree_.put("scrollbar.thumb.normal.color", "#c1c1c1"); - theme_tree_.put("scrollbar.thumb.hover.color", "#a8a8a8"); - theme_tree_.put("scrollbar.thumb.press.color", "#787878"); - theme_tree_.put("scrollbar.thumb.disable.color", "#c1c1c1"); + theme_resource_map_.emplace(u"scrollbar.collapse-thumb.color", + colors::gray.WithAlpha(128).ToString()); + theme_resource_map_.emplace(u"scrollbar.arrow.normal.color", u"#505050"); + theme_resource_map_.emplace(u"scrollbar.arrow.hover.color", u"#505050"); + theme_resource_map_.emplace(u"scrollbar.arrow.press.color", u"#ffffff"); + theme_resource_map_.emplace(u"scrollbar.arrow.disable.color", u"#a3a3a3"); + theme_resource_map_.emplace(u"scrollbar.arrow-background.normal.color", + u"#f1f1f1"); + theme_resource_map_.emplace(u"scrollbar.arrow-background.hover.color", + u"#d2d2d2"); + theme_resource_map_.emplace(u"scrollbar.arrow-background.press.color", + u"#787878"); + theme_resource_map_.emplace(u"scrollbar.arrow-background.disable.color", + u"#f1f1f1"); + theme_resource_map_.emplace(u"scrollbar.slot.normal.color", u"#f1f1f1"); + theme_resource_map_.emplace(u"scrollbar.slot.hover.color", u"#f1f1f1"); + theme_resource_map_.emplace(u"scrollbar.slot.press.color", u"#f1f1f1"); + theme_resource_map_.emplace(u"scrollbar.slot.disable.color", u"#f1f1f1"); + theme_resource_map_.emplace(u"scrollbar.thumb.normal.color", u"#c1c1c1"); + theme_resource_map_.emplace(u"scrollbar.thumb.hover.color", u"#a8a8a8"); + theme_resource_map_.emplace(u"scrollbar.thumb.press.color", u"#787878"); + theme_resource_map_.emplace(u"scrollbar.thumb.disable.color", u"#c1c1c1"); } gsl::not_null<std::shared_ptr<platform::graphics::IBrush>> ThemeManager::GetBrush(StringView key) { - String k = ToLower(key); + auto k = key.ToString(); auto cached_brush_iter = brushes_.find(k); if (cached_brush_iter != brushes_.cend()) { return cached_brush_iter->second; } - auto color_string = - String::FromUtf8(theme_tree_.get<std::string>(key.ToUtf8())); - auto color = Color::Parse(color_string); - if (!color) throw BadThemeResourceException("Value is not a valid color."); + auto color_string_iter = theme_resource_map_.find(k); + if (color_string_iter == theme_resource_map_.cend()) { + throw ThemeResourceKeyNotExistException(u"Key do not exist."); + } + + auto color = Color::Parse(color_string_iter->second); + if (!color) throw BadThemeResourceException(u"Value is not a valid color."); std::shared_ptr<platform::graphics::IBrush> brush = GetUiApplication()->GetGraphicsFactory()->CreateSolidColorBrush(*color); brushes_[k] = brush; |