diff options
-rw-r--r-- | include/cru/platform/Color.hpp | 11 | ||||
-rw-r--r-- | include/cru/ui/ThemeManager.hpp | 17 | ||||
-rw-r--r-- | include/cru/ui/UiManager.hpp | 2 | ||||
-rw-r--r-- | include/cru/ui/controls/RootControl.hpp | 3 | ||||
-rw-r--r-- | src/ui/ThemeManager.cpp | 53 | ||||
-rw-r--r-- | src/ui/UiManager.cpp | 27 | ||||
-rw-r--r-- | src/ui/controls/RootControl.cpp | 4 | ||||
-rw-r--r-- | vcpkg.json | 5 |
8 files changed, 66 insertions, 56 deletions
diff --git a/include/cru/platform/Color.hpp b/include/cru/platform/Color.hpp index f60ab692..94c6c485 100644 --- a/include/cru/platform/Color.hpp +++ b/include/cru/platform/Color.hpp @@ -1,10 +1,9 @@ #pragma once +#include "cru/common/Base.hpp" #include "cru/platform/Base.hpp" #include "cru/common/String.hpp" -#include <boost/functional/hash.hpp> - #include <cstdint> #include <optional> #include <string_view> @@ -243,10 +242,10 @@ template <> struct std::hash<cru::platform::Color> { std::size_t operator()(const cru::platform::Color& color) const { std::size_t seed = 0; - boost::hash_combine(seed, color.red); - boost::hash_combine(seed, color.green); - boost::hash_combine(seed, color.blue); - boost::hash_combine(seed, color.alpha); + cru::hash_combine(seed, color.red); + cru::hash_combine(seed, color.green); + cru::hash_combine(seed, color.blue); + cru::hash_combine(seed, color.alpha); return seed; } }; diff --git a/include/cru/ui/ThemeManager.hpp b/include/cru/ui/ThemeManager.hpp index 9908658c..45cd810c 100644 --- a/include/cru/ui/ThemeManager.hpp +++ b/include/cru/ui/ThemeManager.hpp @@ -2,19 +2,20 @@ #include "Base.hpp" #include "cru/common/Base.hpp" #include "cru/common/Event.hpp" +#include "cru/common/Exception.hpp" #include "cru/platform/graphics/Brush.hpp" -#include <boost/property_tree/ptree.hpp> -#include <cstddef> -#include <memory> -#include <stdexcept> -#include <string_view> #include <unordered_map> namespace cru::ui { -class BadThemeResourceException : public std::runtime_error { +class ThemeResourceKeyNotExistException : public Exception { public: - using std::runtime_error::runtime_error; + using Exception::Exception; +}; + +class BadThemeResourceException : public Exception { + public: + using Exception::Exception; }; class ThemeManager : public Object { @@ -42,7 +43,7 @@ class ThemeManager : public Object { private: Event<std::nullptr_t> theme_resource_change_event_; - boost::property_tree::ptree theme_tree_; + std::unordered_map<String, String> theme_resource_map_; std::unordered_map<String, std::shared_ptr<platform::graphics::IBrush>> brushes_; }; diff --git a/include/cru/ui/UiManager.hpp b/include/cru/ui/UiManager.hpp index 6b1083b2..e617dea8 100644 --- a/include/cru/ui/UiManager.hpp +++ b/include/cru/ui/UiManager.hpp @@ -18,7 +18,9 @@ struct ThemeResources { std::shared_ptr<platform::graphics::IBrush> text_brush; std::shared_ptr<platform::graphics::IBrush> text_selection_brush; std::shared_ptr<platform::graphics::IBrush> caret_brush; + style::StyleRuleSet button_style; + style::StyleRuleSet text_box_style; style::StyleRuleSet menu_item_style; diff --git a/include/cru/ui/controls/RootControl.hpp b/include/cru/ui/controls/RootControl.hpp index 823b9f03..c3f3da9f 100644 --- a/include/cru/ui/controls/RootControl.hpp +++ b/include/cru/ui/controls/RootControl.hpp @@ -4,6 +4,7 @@ #include "cru/common/Base.hpp" #include "cru/common/Event.hpp" #include "cru/platform/gui/Base.hpp" +#include "cru/platform/gui/Window.hpp" #include "cru/ui/Base.hpp" #include "cru/ui/host/WindowHost.hpp" @@ -20,6 +21,8 @@ class RootControl : public LayoutControl { public: render::RenderObject* GetRenderObject() const override; + platform::gui::INativeWindow* GetNativeWindow(); + protected: void SetGainFocusOnCreateAndDestroyWhenLoseFocus(bool value); 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; diff --git a/src/ui/UiManager.cpp b/src/ui/UiManager.cpp index 879ea2e1..78078e74 100644 --- a/src/ui/UiManager.cpp +++ b/src/ui/UiManager.cpp @@ -19,15 +19,6 @@ using namespace cru::platform::graphics; using namespace cru::ui::style; using namespace cru::ui::helper; -namespace { -std::unique_ptr<ISolidColorBrush> CreateSolidColorBrush( - IGraphicsFactory* factory, const Color& color) { - auto brush = factory->CreateSolidColorBrush(); - brush->SetColor(color); - return brush; -} -} // namespace - UiManager* UiManager::GetInstance() { static UiManager* instance = new UiManager(); GetUiApplication()->AddOnQuitHandler([] { @@ -47,10 +38,10 @@ UiManager::UiManager() { const auto black_brush = std::shared_ptr<platform::graphics::ISolidColorBrush>( - CreateSolidColorBrush(factory, colors::black)); + factory->CreateSolidColorBrush(colors::black)); theme_resource_.text_brush = black_brush; theme_resource_.text_selection_brush = - CreateSolidColorBrush(factory, colors::skyblue); + factory->CreateSolidColorBrush(colors::skyblue); theme_resource_.caret_brush = black_brush; theme_resource_.button_style.AddStyleRule( @@ -63,28 +54,28 @@ UiManager::UiManager() { {ClickStateCondition::Create(ClickState::None), CompoundStyler::Create( BorderStyler::Create(ApplyBorderStyleInfo{ - CreateSolidColorBrush(factory, Color::FromHex(0x00bfff))}), + factory->CreateSolidColorBrush(Color::FromHex(0x00bfff))}), CursorStyler::Create(platform::gui::SystemCursorType::Arrow)), u"DefaultButtonNormal"}); theme_resource_.button_style.AddStyleRule( {ClickStateCondition::Create(ClickState::Hover), CompoundStyler::Create( BorderStyler::Create(ApplyBorderStyleInfo{ - CreateSolidColorBrush(factory, Color::FromHex(0x47d1ff))}), + factory->CreateSolidColorBrush(Color::FromHex(0x47d1ff))}), CursorStyler::Create(platform::gui::SystemCursorType::Hand)), u"DefaultButtonHover"}); theme_resource_.button_style.AddStyleRule( {ClickStateCondition::Create(ClickState::Press), CompoundStyler::Create( BorderStyler::Create(ApplyBorderStyleInfo{ - CreateSolidColorBrush(factory, Color::FromHex(0x91e4ff))}), + factory->CreateSolidColorBrush(Color::FromHex(0x91e4ff))}), CursorStyler::Create(platform::gui::SystemCursorType::Hand)), u"DefaultButtonPress"}); theme_resource_.button_style.AddStyleRule( {ClickStateCondition::Create(ClickState::PressInactive), CompoundStyler::Create( BorderStyler::Create(ApplyBorderStyleInfo{ - CreateSolidColorBrush(factory, Color::FromHex(0x91e4ff))}), + factory->CreateSolidColorBrush(Color::FromHex(0x91e4ff))}), CursorStyler::Create(platform::gui::SystemCursorType::Arrow)), u"DefaultButtonPressInactive"}); @@ -96,17 +87,17 @@ UiManager::UiManager() { theme_resource_.text_box_style.AddStyleRule( {HoverCondition::Create(false), BorderStyler::Create(ApplyBorderStyleInfo{ - CreateSolidColorBrush(factory, Color::FromHex(0xced4da))}), + factory->CreateSolidColorBrush(Color::FromHex(0xced4da))}), u"DefaultTextBoxNormal"}); theme_resource_.text_box_style.AddStyleRule( {HoverCondition::Create(true), BorderStyler::Create(ApplyBorderStyleInfo{ - CreateSolidColorBrush(factory, Color::FromHex(0xced4da))}), + factory->CreateSolidColorBrush(Color::FromHex(0xced4da))}), u"DefaultTextBoxHover"}); theme_resource_.text_box_style.AddStyleRule( {FocusCondition::Create(true), BorderStyler::Create(ApplyBorderStyleInfo{ - CreateSolidColorBrush(factory, Color::FromHex(0x495057))}), + factory->CreateSolidColorBrush(Color::FromHex(0x495057))}), u"DefaultTextBoxFocus"}); theme_resource_.menu_item_style.AddStyleRule( diff --git a/src/ui/controls/RootControl.cpp b/src/ui/controls/RootControl.cpp index 278649de..7edf4a1d 100644 --- a/src/ui/controls/RootControl.cpp +++ b/src/ui/controls/RootControl.cpp @@ -25,6 +25,10 @@ render::RenderObject* RootControl::GetRenderObject() const { return render_object_.get(); } +platform::gui::INativeWindow* RootControl::GetNativeWindow() { + return window_host_->GetNativeWindow(); +} + void RootControl::SetGainFocusOnCreateAndDestroyWhenLoseFocus(bool value) { gain_focus_on_create_and_destroy_when_lose_focus_event_guard_.Clear(); if (value) { @@ -2,5 +2,8 @@ "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json", "name": "cru", "version": "0.0.1", - "dependencies": ["ms-gsl", "gtest", "boost"] + "dependencies": [ + "ms-gsl", + "gtest" + ] } |