diff options
-rw-r--r-- | include/cru/ui/host/WindowHost.hpp | 6 | ||||
-rw-r--r-- | include/cru/ui/render/ScrollBar.hpp | 2 | ||||
-rw-r--r-- | src/ui/host/WindowHost.cpp | 21 | ||||
-rw-r--r-- | src/ui/render/ScrollBar.cpp | 17 |
4 files changed, 35 insertions, 11 deletions
diff --git a/include/cru/ui/host/WindowHost.hpp b/include/cru/ui/host/WindowHost.hpp index bd2f7c16..cd9093bc 100644 --- a/include/cru/ui/host/WindowHost.hpp +++ b/include/cru/ui/host/WindowHost.hpp @@ -3,6 +3,7 @@ #include "../render/Base.hpp" #include "cru/common/Event.hpp" +#include "cru/platform/gui/Cursor.hpp" #include "cru/platform/gui/UiApplication.hpp" #include "cru/platform/gui/Window.hpp" @@ -118,6 +119,9 @@ class WindowHost : public Object { void SetWindowRect(const Rect& rect); + std::shared_ptr<platform::gui::ICursor> GetOverrideCursor(); + void SetOverrideCursor(std::shared_ptr<platform::gui::ICursor> cursor); + private: //*************** region: native messages *************** void OnNativeDestroy(platform::gui::INativeWindow* window, std::nullptr_t); @@ -172,5 +176,7 @@ class WindowHost : public Object { Event<platform::gui::INativeWindow*> native_window_change_event_; std::optional<Rect> saved_rect_; + + std::shared_ptr<platform::gui::ICursor> override_cursor_; }; } // namespace cru::ui::host diff --git a/include/cru/ui/render/ScrollBar.hpp b/include/cru/ui/render/ScrollBar.hpp index a271ae71..005cf3bb 100644 --- a/include/cru/ui/render/ScrollBar.hpp +++ b/include/cru/ui/render/ScrollBar.hpp @@ -147,7 +147,7 @@ class ScrollBar : public Object { Event<Scroll> scroll_attempt_event_; - std::optional<std::shared_ptr<platform::gui::ICursor>> old_cursor_; + bool cursor_overrided_ = false; platform::gui::TimerAutoCanceler auto_collapse_timer_canceler_; }; diff --git a/src/ui/host/WindowHost.cpp b/src/ui/host/WindowHost.cpp index 5e107733..eac2ef41 100644 --- a/src/ui/host/WindowHost.cpp +++ b/src/ui/host/WindowHost.cpp @@ -422,9 +422,13 @@ void WindowHost::DispatchMouseHoverControlChangeEvent( void WindowHost::UpdateCursor() { if (native_window_) { - const auto capture = GetMouseCaptureControl(); - native_window_->SetCursor( - (capture ? capture : GetMouseHoverControl())->GetInheritedCursor()); + if (override_cursor_) { + native_window_->SetCursor(override_cursor_); + } else { + const auto capture = GetMouseCaptureControl(); + native_window_->SetCursor( + (capture ? capture : GetMouseHoverControl())->GetInheritedCursor()); + } } } @@ -437,4 +441,15 @@ controls::Control* WindowHost::HitTest(const Point& point) { } return root_control_; } + +std::shared_ptr<platform::gui::ICursor> WindowHost::GetOverrideCursor() { + return override_cursor_; +} + +void WindowHost::SetOverrideCursor( + std::shared_ptr<platform::gui::ICursor> cursor) { + if (cursor == override_cursor_) return; + override_cursor_ = cursor; + UpdateCursor(); +} } // namespace cru::ui::host diff --git a/src/ui/render/ScrollBar.cpp b/src/ui/render/ScrollBar.cpp index 4bde6d19..ec583b2a 100644 --- a/src/ui/render/ScrollBar.cpp +++ b/src/ui/render/ScrollBar.cpp @@ -14,6 +14,7 @@ #include "cru/ui/UiManager.hpp" #include "cru/ui/events/UiEvent.hpp" #include "cru/ui/helper/ClickDetector.hpp" +#include "cru/ui/host/WindowHost.hpp" #include "cru/ui/render/ScrollRenderObject.hpp" #include <algorithm> @@ -348,22 +349,24 @@ void ScrollBar::OnDraw(platform::graphics::IPainter* painter, } void ScrollBar::SetCursor() { - if (!old_cursor_) { - if (const auto control = render_object_->GetAttachedControl()) { - old_cursor_ = control->GetCursor(); - control->SetCursor( + if (const auto control = render_object_->GetAttachedControl()) { + if (const auto window_host = control->GetWindowHost()) { + window_host->SetOverrideCursor( GetUiApplication()->GetCursorManager()->GetSystemCursor( platform::gui::SystemCursorType::Arrow)); + cursor_overrided_ = true; } } } void ScrollBar::RestoreCursor() { - if (old_cursor_) { + if (cursor_overrided_) { if (const auto control = render_object_->GetAttachedControl()) { - control->SetCursor(*old_cursor_); + if (const auto window_host = control->GetWindowHost()) { + window_host->SetOverrideCursor(nullptr); + } } - old_cursor_ = std::nullopt; + cursor_overrided_ = false; } } |