diff options
Diffstat (limited to 'src/ui/controls/button.cpp')
-rw-r--r-- | src/ui/controls/button.cpp | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/src/ui/controls/button.cpp b/src/ui/controls/button.cpp index 38ce75a8..5e32e064 100644 --- a/src/ui/controls/button.cpp +++ b/src/ui/controls/button.cpp @@ -5,14 +5,14 @@ #include "cru/platform/graph/graph_factory.hpp" #include "cru/platform/native/cursor.hpp" #include "cru/platform/native/native_window.hpp" -#include "cru/platform/native/ui_applicaition.hpp" +#include "cru/platform/native/ui_application.hpp" #include "cru/ui/render/border_render_object.hpp" #include "cru/ui/ui_manager.hpp" #include "cru/ui/window.hpp" namespace cru::ui::controls { +using platform::native::GetSystemCursor; using platform::native::SystemCursor; -using platform::native::UiApplication; Button::Button() : click_detector_(this) { // const auto predefined_resource = @@ -25,12 +25,17 @@ Button::Button() : click_detector_(this) { factory->CreateSolidColorBrush(Color::FromHex(0x47d1ff))); border_style_.press.brush = std::shared_ptr<platform::graph::Brush>( factory->CreateSolidColorBrush(Color::FromHex(0x91e4ff))); + border_style_.press_cancel.brush = std::shared_ptr<platform::graph::Brush>( + factory->CreateSolidColorBrush(Color::FromHex(0x91e4ff))); border_style_.normal.thickness = border_style_.hover.thickness = - border_style_.press.thickness = Thickness{3}; + border_style_.press.thickness = border_style_.press_cancel.thickness = + Thickness{3}; border_style_.normal.corner_radius = border_style_.hover.corner_radius = - border_style_.press.corner_radius = render::CornerRadius{Point{10, 5}}; + border_style_.press.corner_radius = + border_style_.press_cancel.corner_radius = + render::CornerRadius{Point{10, 5}}; render_object_.reset( new render::BorderRenderObject(border_style_.normal.brush)); @@ -44,14 +49,14 @@ Button::Button() : click_detector_(this) { } else { SetState(ButtonState::Hover); } - SetCursor(UiApplication::GetInstance()->GetCursorManager()->GetSystemCursor( - SystemCursor::Hand)); }); MouseLeaveEvent()->Direct()->AddHandler([this](event::MouseEventArgs& args) { - SetState(ButtonState::Normal); - SetCursor(UiApplication::GetInstance()->GetCursorManager()->GetSystemCursor( - SystemCursor::Arrow)); + if (click_detector_.GetPressingButton() & trigger_button_) { + SetState(ButtonState::Normal); + } else { + SetState(ButtonState::PressCancel); + } }); click_detector_.ClickBeginEvent()->AddHandler([this](MouseButton button) { @@ -62,7 +67,7 @@ Button::Button() : click_detector_(this) { click_detector_.ClickEndEvent()->AddHandler([this](MouseButton button) { if (button & trigger_button_) { - SetState(ButtonState::Normal); + SetState(ButtonState::Hover); } }); } @@ -81,12 +86,19 @@ void Button::OnStateChange(ButtonState oldState, ButtonState newState) { switch (newState) { case ButtonState::Normal: render_object_->SetStyle(border_style_.normal); + SetCursor(GetSystemCursor(SystemCursor::Arrow)); break; case ButtonState::Hover: render_object_->SetStyle(border_style_.hover); + SetCursor(GetSystemCursor(SystemCursor::Hand)); break; case ButtonState::Press: render_object_->SetStyle(border_style_.press); + SetCursor(GetSystemCursor(SystemCursor::Hand)); + break; + case ButtonState::PressCancel: + render_object_->SetStyle(border_style_.press_cancel); + SetCursor(GetSystemCursor(SystemCursor::Arrow)); break; } GetWindow()->GetNativeWindow()->Repaint(); |