aboutsummaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/helper/ClickDetector.cpp8
-rw-r--r--src/ui/host/WindowHost.cpp6
-rw-r--r--src/ui/render/ScrollBar.cpp240
-rw-r--r--src/ui/render/ScrollRenderObject.cpp7
4 files changed, 117 insertions, 144 deletions
diff --git a/src/ui/helper/ClickDetector.cpp b/src/ui/helper/ClickDetector.cpp
index 21caff35..cf219db0 100644
--- a/src/ui/helper/ClickDetector.cpp
+++ b/src/ui/helper/ClickDetector.cpp
@@ -23,7 +23,7 @@ ClickDetector::ClickDetector(controls::Control* control) {
control_ = control;
event_rovoker_guards_.push_back(
- EventRevokerGuard(control->MouseEnterEvent()->Direct()->AddHandler(
+ EventHandlerRevokerGuard(control->MouseEnterEvent()->Direct()->AddHandler(
[this](events::MouseEventArgs&) {
if (this->enable_) {
if (this->state_ == ClickState::PressInactive) {
@@ -37,7 +37,7 @@ ClickDetector::ClickDetector(controls::Control* control) {
})));
event_rovoker_guards_.push_back(
- EventRevokerGuard(control->MouseLeaveEvent()->Direct()->AddHandler(
+ EventHandlerRevokerGuard(control->MouseLeaveEvent()->Direct()->AddHandler(
[this](events::MouseEventArgs&) {
if (this->enable_) {
if (this->state_ == ClickState::Press) {
@@ -51,7 +51,7 @@ ClickDetector::ClickDetector(controls::Control* control) {
})));
event_rovoker_guards_.push_back(
- EventRevokerGuard(control->MouseDownEvent()->Direct()->AddHandler(
+ EventHandlerRevokerGuard(control->MouseDownEvent()->Direct()->AddHandler(
[this](events::MouseButtonEventArgs& args) {
const auto button = args.GetButton();
if (this->enable_ && (button & this->trigger_button_) &&
@@ -70,7 +70,7 @@ ClickDetector::ClickDetector(controls::Control* control) {
})));
event_rovoker_guards_.push_back(
- EventRevokerGuard(control->MouseUpEvent()->Direct()->AddHandler(
+ EventHandlerRevokerGuard(control->MouseUpEvent()->Direct()->AddHandler(
[this](events::MouseButtonEventArgs& args) {
const auto button = args.GetButton();
if (this->enable_ && (button & this->trigger_button_) &&
diff --git a/src/ui/host/WindowHost.cpp b/src/ui/host/WindowHost.cpp
index 4c707772..7417740d 100644
--- a/src/ui/host/WindowHost.cpp
+++ b/src/ui/host/WindowHost.cpp
@@ -93,9 +93,9 @@ namespace {
template <typename T>
inline void BindNativeEvent(
WindowHost* host, INativeWindow* native_window, IEvent<T>* event,
- void (WindowHost::*handler)(INativeWindow*, typename IEvent<T>::EventArgs),
- std::vector<EventRevokerGuard>& guard_pool) {
- guard_pool.push_back(EventRevokerGuard(event->AddHandler(
+ void (WindowHost::*handler)(INativeWindow*, typename IEvent<T>::Args),
+ std::vector<EventHandlerRevokerGuard>& guard_pool) {
+ guard_pool.push_back(EventHandlerRevokerGuard(event->AddHandler(
std::bind(handler, host, native_window, std::placeholders::_1))));
}
} // namespace
diff --git a/src/ui/render/ScrollBar.cpp b/src/ui/render/ScrollBar.cpp
index a3bee22c..804395e4 100644
--- a/src/ui/render/ScrollBar.cpp
+++ b/src/ui/render/ScrollBar.cpp
@@ -115,143 +115,121 @@ void ScrollBar::Draw(platform::graphics::IPainter* painter) {
void ScrollBar::InstallHandlers(controls::Control* control) {
event_guard_.Clear();
if (control != nullptr) {
- event_guard_ +=
- control->MouseDownEvent()->Tunnel()->PrependShortCircuitHandler(
- [control, this](events::MouseButtonEventArgs& event) {
- if (event.GetButton() == MouseButtons::Left && IsEnabled() &&
- IsExpanded()) {
- auto hit_test_result =
- ExpandedHitTest(event.GetPoint(render_object_));
- if (!hit_test_result) return false;
-
- if (mouse_press_ != hit_test_result) {
- mouse_press_ = hit_test_result;
- render_object_->InvalidatePaint();
- }
-
- switch (*hit_test_result) {
- case ScrollBarAreaKind::UpArrow:
- this->scroll_attempt_event_.Raise(
- {GetDirection(), ScrollKind::Line, -1});
- event.SetHandled();
- return true;
- case ScrollBarAreaKind::DownArrow:
- this->scroll_attempt_event_.Raise(
- {GetDirection(), ScrollKind::Line, 1});
- event.SetHandled();
- return true;
- case ScrollBarAreaKind::UpSlot:
- this->scroll_attempt_event_.Raise(
- {GetDirection(), ScrollKind::Page, -1});
- event.SetHandled();
- return true;
- case ScrollBarAreaKind::DownSlot:
- this->scroll_attempt_event_.Raise(
- {GetDirection(), ScrollKind::Page, 1});
- event.SetHandled();
- return true;
- case ScrollBarAreaKind::Thumb: {
- auto thumb_rect =
- GetExpandedAreaRect(ScrollBarAreaKind::Thumb);
- assert(thumb_rect);
-
- if (!control->CaptureMouse()) break;
- move_thumb_thumb_original_rect_ = *thumb_rect;
- move_thumb_start_ = event.GetPoint();
- event.SetHandled();
- return true;
- }
- default:
- break;
- }
- }
-
- return false;
- });
-
- event_guard_ +=
- control->MouseUpEvent()->Tunnel()->PrependShortCircuitHandler(
- [control, this](events::MouseButtonEventArgs& event) {
- if (mouse_press_ != std::nullopt) {
- mouse_press_ = std::nullopt;
- render_object_->InvalidatePaint();
- }
-
- if (event.GetButton() == MouseButtons::Left &&
- move_thumb_start_) {
- move_thumb_start_ = std::nullopt;
-
- auto hit_test_result =
- ExpandedHitTest(event.GetPoint(this->render_object_));
- if (!hit_test_result) {
- OnMouseLeave();
- }
-
- control->ReleaseMouse();
+ event_guard_ += control->MouseDownEvent()->Tunnel()->AddHandler(
+ [control, this](events::MouseButtonEventArgs& event) {
+ if (event.GetButton() == MouseButtons::Left && IsEnabled() &&
+ IsExpanded()) {
+ auto hit_test_result =
+ ExpandedHitTest(event.GetPoint(render_object_));
+ if (!hit_test_result) return;
+
+ if (mouse_press_ != hit_test_result) {
+ mouse_press_ = hit_test_result;
+ render_object_->InvalidatePaint();
+ }
+
+ switch (*hit_test_result) {
+ case ScrollBarAreaKind::UpArrow:
+ this->scroll_attempt_event_.Raise(
+ {GetDirection(), ScrollKind::Line, -1});
event.SetHandled();
- return true;
- }
- return false;
- });
-
- event_guard_ +=
- control->MouseMoveEvent()->Tunnel()->PrependShortCircuitHandler(
- [this](events::MouseEventArgs& event) {
- if (move_thumb_start_) {
- auto new_scroll_position = CalculateNewScrollPosition(
- move_thumb_thumb_original_rect_,
- event.GetPoint() - *move_thumb_start_);
-
- this->scroll_attempt_event_.Raise({GetDirection(),
- ScrollKind::Absolute,
- new_scroll_position});
+ case ScrollBarAreaKind::DownArrow:
+ this->scroll_attempt_event_.Raise(
+ {GetDirection(), ScrollKind::Line, 1});
event.SetHandled();
- return true;
- }
+ case ScrollBarAreaKind::UpSlot:
+ this->scroll_attempt_event_.Raise(
+ {GetDirection(), ScrollKind::Page, -1});
+ event.SetHandled();
+ case ScrollBarAreaKind::DownSlot:
+ this->scroll_attempt_event_.Raise(
+ {GetDirection(), ScrollKind::Page, 1});
+ event.SetHandled();
+ case ScrollBarAreaKind::Thumb: {
+ auto thumb_rect = GetExpandedAreaRect(ScrollBarAreaKind::Thumb);
+ assert(thumb_rect);
- if (IsEnabled()) {
- if (IsExpanded()) {
- auto hit_test_result =
- ExpandedHitTest(event.GetPoint(this->render_object_));
- if (mouse_hover_ != hit_test_result) {
- mouse_hover_ = hit_test_result;
- render_object_->InvalidatePaint();
- }
- if (hit_test_result) {
- SetCursor();
- StopAutoCollapseTimer();
- } else {
- OnMouseLeave();
- }
- } 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;
- }
- }
+ if (!control->CaptureMouse()) break;
+ move_thumb_thumb_original_rect_ = *thumb_rect;
+ move_thumb_start_ = event.GetPoint();
+ event.SetHandled();
}
-
- return false;
- });
-
- event_guard_ +=
- control->MouseLeaveEvent()->Tunnel()->PrependShortCircuitHandler(
- [this](events::MouseEventArgs&) {
- if (IsExpanded() && !move_thumb_start_) {
- if (mouse_hover_ != std::nullopt) {
- mouse_hover_ = std::nullopt;
- render_object_->InvalidatePaint();
- }
+ default:
+ break;
+ }
+ }
+ });
+
+ event_guard_ += control->MouseUpEvent()->Tunnel()->AddHandler(
+ [control, this](events::MouseButtonEventArgs& event) {
+ if (mouse_press_ != std::nullopt) {
+ mouse_press_ = std::nullopt;
+ render_object_->InvalidatePaint();
+ }
+
+ if (event.GetButton() == MouseButtons::Left && move_thumb_start_) {
+ move_thumb_start_ = std::nullopt;
+
+ auto hit_test_result =
+ ExpandedHitTest(event.GetPoint(this->render_object_));
+ if (!hit_test_result) {
+ OnMouseLeave();
+ }
+
+ control->ReleaseMouse();
+ event.SetHandled();
+ }
+ });
+
+ event_guard_ += control->MouseMoveEvent()->Tunnel()->AddHandler(
+ [this](events::MouseEventArgs& event) {
+ if (move_thumb_start_) {
+ auto new_scroll_position = CalculateNewScrollPosition(
+ move_thumb_thumb_original_rect_,
+ event.GetPoint() - *move_thumb_start_);
+
+ this->scroll_attempt_event_.Raise(
+ {GetDirection(), ScrollKind::Absolute, new_scroll_position});
+ event.SetHandled();
+ }
+
+ if (IsEnabled()) {
+ if (IsExpanded()) {
+ auto hit_test_result =
+ ExpandedHitTest(event.GetPoint(this->render_object_));
+ if (mouse_hover_ != hit_test_result) {
+ mouse_hover_ = hit_test_result;
+ render_object_->InvalidatePaint();
+ }
+ if (hit_test_result) {
+ SetCursor();
+ StopAutoCollapseTimer();
+ } else {
OnMouseLeave();
}
- return false;
- });
+ } else {
+ auto trigger_expand_area = GetCollapsedTriggerExpandAreaRect();
+ if (trigger_expand_area &&
+ trigger_expand_area->IsPointInside(
+ event.GetPoint(this->render_object_))) {
+ SetExpanded(true);
+ SetCursor();
+ event.SetHandled();
+ }
+ }
+ }
+ });
+
+ event_guard_ += control->MouseLeaveEvent()->Tunnel()->AddHandler(
+ [this](events::MouseEventArgs&) {
+ if (IsExpanded() && !move_thumb_start_) {
+ if (mouse_hover_ != std::nullopt) {
+ mouse_hover_ = std::nullopt;
+ render_object_->InvalidatePaint();
+ }
+ OnMouseLeave();
+ }
+ });
}
}
diff --git a/src/ui/render/ScrollRenderObject.cpp b/src/ui/render/ScrollRenderObject.cpp
index b8b6904d..ea93dd21 100644
--- a/src/ui/render/ScrollRenderObject.cpp
+++ b/src/ui/render/ScrollRenderObject.cpp
@@ -218,7 +218,7 @@ void ScrollRenderObject::InstallMouseWheelHandler(controls::Control* control) {
guard_.Clear();
if (control != nullptr) {
- guard_ += control->MouseWheelEvent()->Bubble()->PrependShortCircuitHandler(
+ guard_ += control->MouseWheelEvent()->Bubble()->AddHandler(
[this](events::MouseWheelEventArgs& args) {
auto delta = args.GetDelta();
@@ -228,24 +228,19 @@ void ScrollRenderObject::InstallMouseWheelHandler(controls::Control* control) {
if (VerticalCanScrollDown()) {
ApplyScroll(
Scroll{Direction::Vertical, ScrollKind::Relative, delta});
- return true;
} else if (HorizontalCanScrollDown()) {
ApplyScroll(
Scroll{Direction::Horizontal, ScrollKind::Relative, delta});
- return true;
}
} else if (delta < 0) {
if (VerticalCanScrollUp()) {
ApplyScroll(
Scroll{Direction::Vertical, ScrollKind::Relative, delta});
- return true;
} else if (HorizontalCanScrollUp()) {
ApplyScroll(
Scroll{Direction::Horizontal, ScrollKind::Relative, delta});
- return true;
}
}
- return false;
});
}
}