diff options
Diffstat (limited to 'src/ui')
-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 |
3 files changed, 43 insertions, 41 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; 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) { |