diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ui/UiManager.cpp | 25 | ||||
-rw-r--r-- | src/ui/controls/Button.cpp | 27 | ||||
-rw-r--r-- | src/ui/style/Styler.cpp | 14 |
3 files changed, 31 insertions, 35 deletions
diff --git a/src/ui/UiManager.cpp b/src/ui/UiManager.cpp index 5b4d4931..7981aa86 100644 --- a/src/ui/UiManager.cpp +++ b/src/ui/UiManager.cpp @@ -6,6 +6,7 @@ #include "cru/platform/graphics/Brush.hpp" #include "cru/platform/graphics/Factory.hpp" #include "cru/platform/graphics/Font.hpp" +#include "cru/platform/gui/Cursor.hpp" #include "cru/platform/gui/UiApplication.hpp" #include "cru/ui/Base.hpp" #include "cru/ui/style/ApplyBorderStyleInfo.hpp" @@ -59,23 +60,31 @@ UiManager::UiManager() { u"DefaultButton"}); theme_resource_.button_style.AddStyleRule( {ClickStateCondition::Create(ClickState::None), - BorderStyler::Create(ApplyBorderStyleInfo{ - CreateSolidColorBrush(factory, Color::FromHex(0x00bfff))}), + CompoundStyler::Create( + BorderStyler::Create(ApplyBorderStyleInfo{ + CreateSolidColorBrush(factory, Color::FromHex(0x00bfff))}), + CursorStyler::Create(platform::gui::SystemCursorType::Arrow)), u"DefaultButtonNormal"}); theme_resource_.button_style.AddStyleRule( {ClickStateCondition::Create(ClickState::Hover), - BorderStyler::Create(ApplyBorderStyleInfo{ - CreateSolidColorBrush(factory, Color::FromHex(0x47d1ff))}), + CompoundStyler::Create( + BorderStyler::Create(ApplyBorderStyleInfo{ + CreateSolidColorBrush(factory, Color::FromHex(0x47d1ff))}), + CursorStyler::Create(platform::gui::SystemCursorType::Hand)), u"DefaultButtonHover"}); theme_resource_.button_style.AddStyleRule( {ClickStateCondition::Create(ClickState::Press), - BorderStyler::Create(ApplyBorderStyleInfo{ - CreateSolidColorBrush(factory, Color::FromHex(0x91e4ff))}), + CompoundStyler::Create( + BorderStyler::Create(ApplyBorderStyleInfo{ + CreateSolidColorBrush(factory, Color::FromHex(0x91e4ff))}), + CursorStyler::Create(platform::gui::SystemCursorType::Hand)), u"DefaultButtonPress"}); theme_resource_.button_style.AddStyleRule( {ClickStateCondition::Create(ClickState::PressInactive), - BorderStyler::Create(ApplyBorderStyleInfo{ - CreateSolidColorBrush(factory, Color::FromHex(0x91e4ff))}), + CompoundStyler::Create( + BorderStyler::Create(ApplyBorderStyleInfo{ + CreateSolidColorBrush(factory, Color::FromHex(0x91e4ff))}), + CursorStyler::Create(platform::gui::SystemCursorType::Arrow)), u"DefaultButtonPressInactive"}); theme_resource_.text_box_style.AddStyleRule( diff --git a/src/ui/controls/Button.cpp b/src/ui/controls/Button.cpp index 8bd9f93f..c6480b77 100644 --- a/src/ui/controls/Button.cpp +++ b/src/ui/controls/Button.cpp @@ -1,5 +1,4 @@ #include "cru/ui/controls/Button.hpp" -#include <memory> #include "../Helper.hpp" #include "cru/platform/graphics/Brush.hpp" @@ -10,38 +9,12 @@ #include "cru/ui/render/BorderRenderObject.hpp" namespace cru::ui::controls { -using cru::platform::gui::SystemCursorType; - -namespace { -std::shared_ptr<platform::gui::ICursor> GetSystemCursor(SystemCursorType type) { - return GetUiApplication()->GetCursorManager()->GetSystemCursor(type); -} -} // namespace - Button::Button() : click_detector_(this) { render_object_ = std::make_unique<render::BorderRenderObject>(); render_object_->SetAttachedControl(this); SetContainerRenderObject(render_object_.get()); render_object_->SetBorderEnabled(true); - click_detector_.StateChangeEvent()->AddHandler( - [this](const helper::ClickState& state) { - switch (state) { - case helper::ClickState::None: - SetCursor(GetSystemCursor(SystemCursorType::Arrow)); - break; - case helper::ClickState::Hover: - SetCursor(GetSystemCursor(SystemCursorType::Hand)); - break; - case helper::ClickState::Press: - SetCursor(GetSystemCursor(SystemCursorType::Hand)); - break; - case helper::ClickState::PressInactive: - SetCursor(GetSystemCursor(SystemCursorType::Arrow)); - break; - } - }); - GetStyleRuleSet()->SetParent( &UiManager::GetInstance()->GetThemeResources()->button_style); } diff --git a/src/ui/style/Styler.cpp b/src/ui/style/Styler.cpp index 823ac718..da3a2247 100644 --- a/src/ui/style/Styler.cpp +++ b/src/ui/style/Styler.cpp @@ -1,4 +1,9 @@ #include "cru/ui/style/Styler.hpp" + +#include "../Helper.hpp" +#include "cru/common/ClonablePtr.hpp" +#include "cru/platform/gui/Cursor.hpp" +#include "cru/platform/gui/UiApplication.hpp" #include "cru/ui/controls/Control.hpp" #include "cru/ui/controls/IBorderControl.hpp" #include "cru/ui/style/ApplyBorderStyleInfo.hpp" @@ -12,4 +17,13 @@ void BorderStyler::Apply(controls::Control *control) const { border_control->ApplyBorderStyle(style_); } } + +ClonablePtr<CursorStyler> CursorStyler::Create( + platform::gui::SystemCursorType type) { + return Create(GetUiApplication()->GetCursorManager()->GetSystemCursor(type)); +} + +void CursorStyler::Apply(controls::Control *control) const { + control->SetCursor(cursor_); +} } // namespace cru::ui::style |