aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-02-28 15:57:47 +0800
committercrupest <crupest@outlook.com>2021-02-28 15:57:47 +0800
commite19d42f2f89ad6670e6b9a226bcf7abc12003bb5 (patch)
tree45a1221d6254233de127506f1b85a00f0bf7e989 /src
parenta64ace1b09cb3c8594f510075ceffee17d8b7cfb (diff)
downloadcru-e19d42f2f89ad6670e6b9a226bcf7abc12003bb5.tar.gz
cru-e19d42f2f89ad6670e6b9a226bcf7abc12003bb5.tar.bz2
cru-e19d42f2f89ad6670e6b9a226bcf7abc12003bb5.zip
...
Diffstat (limited to 'src')
-rw-r--r--src/ui/render/ScrollBar.cpp58
1 files changed, 50 insertions, 8 deletions
diff --git a/src/ui/render/ScrollBar.cpp b/src/ui/render/ScrollBar.cpp
index fa53292e..ee4b9e0d 100644
--- a/src/ui/render/ScrollBar.cpp
+++ b/src/ui/render/ScrollBar.cpp
@@ -6,6 +6,7 @@
#include "cru/platform/graphics/Factory.hpp"
#include "cru/platform/graphics/Painter.hpp"
#include "cru/platform/gui/Base.hpp"
+#include "cru/platform/gui/Cursor.hpp"
#include "cru/ui/Base.hpp"
#include "cru/ui/events/UiEvent.hpp"
#include "cru/ui/render/ScrollRenderObject.hpp"
@@ -45,6 +46,8 @@ ScrollBar::ScrollBar(gsl::not_null<ScrollRenderObject*> render_object,
graphics_factory->CreateSolidColorBrush(colors::black);
}
+ScrollBar::~ScrollBar() { RestoreCursor(); }
+
void ScrollBar::SetEnabled(bool value) {
if (value == is_enabled_) return;
if (!value) {
@@ -150,19 +153,38 @@ void ScrollBar::InstallHandlers(controls::Control* control) {
return true;
}
- if (IsEnabled() && !IsExpanded()) {
- auto trigger_expand_area = GetCollapsedTriggerExpandAreaRect();
- if (trigger_expand_area &&
- trigger_expand_area->IsPointInside(
- event.GetPoint(this->render_object_))) {
- SetExpanded(true);
- event.SetHandled();
- return true;
+ if (IsEnabled()) {
+ if (IsExpanded()) {
+ auto hit_test_result =
+ ExpandedHitTest(event.GetPoint(this->render_object_));
+ if (hit_test_result) {
+ SetCursor();
+ } else {
+ RestoreCursor();
+ }
+ } else {
+ auto trigger_expand_area =
+ GetCollapsedTriggerExpandAreaRect();
+ if (trigger_expand_area &&
+ trigger_expand_area->IsPointInside(
+ event.GetPoint(this->render_object_))) {
+ SetExpanded(true);
+ SetCursor();
+ event.SetHandled();
+ return true;
+ }
}
}
return false;
});
+
+ event_guard_ +=
+ control->MouseLeaveEvent()->Bubble()->PrependShortCircuitHandler(
+ [this](event::MouseEventArgs&) {
+ if (IsExpanded() && !move_thumb_start_) RestoreCursor();
+ return false;
+ });
}
}
@@ -225,6 +247,26 @@ 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(
+ GetUiApplication()->GetCursorManager()->GetSystemCursor(
+ platform::gui::SystemCursorType::Arrow));
+ }
+ }
+}
+
+void ScrollBar::RestoreCursor() {
+ if (old_cursor_) {
+ if (const auto control = render_object_->GetAttachedControl()) {
+ control->SetCursor(*old_cursor_);
+ }
+ old_cursor_ = std::nullopt;
+ }
+}
+
std::optional<ScrollBarAreaKind> ScrollBar::ExpandedHitTest(
const Point& point) {
for (auto kind : kScrollBarAreaKindList) {