diff options
author | crupest <crupest@outlook.com> | 2021-05-12 08:36:43 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-05-12 08:36:43 +0800 |
commit | 02baef645090f0514fa14b43aecf954fd55257dc (patch) | |
tree | 3d26669c5781238fb4737c9b315ad534b7c0a3e0 /src | |
parent | f54032b94817bc5a03be68d39758e9b3d67a1b59 (diff) | |
download | cru-02baef645090f0514fa14b43aecf954fd55257dc.tar.gz cru-02baef645090f0514fa14b43aecf954fd55257dc.tar.bz2 cru-02baef645090f0514fa14b43aecf954fd55257dc.zip |
...
Diffstat (limited to 'src')
-rw-r--r-- | src/ui/host/WindowHost.cpp | 21 | ||||
-rw-r--r-- | src/ui/render/ScrollBar.cpp | 17 |
2 files changed, 28 insertions, 10 deletions
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; } } |