diff --git a/libs/ui/include/psemek/ui/event_interceptor.hpp b/libs/ui/include/psemek/ui/event_interceptor.hpp index a39dce5b..00972803 100644 --- a/libs/ui/include/psemek/ui/event_interceptor.hpp +++ b/libs/ui/include/psemek/ui/event_interceptor.hpp @@ -35,6 +35,8 @@ namespace psemek::ui std::shared_ptr child_; element * children_[1]{nullptr}; + bool mouseover_ = false; + std::function mouse_move_callback_; std::function mouse_click_callback_; std::function mouse_wheel_callback_; diff --git a/libs/ui/source/event_interceptor.cpp b/libs/ui/source/event_interceptor.cpp index fa6d41f8..1f36b2e9 100644 --- a/libs/ui/source/event_interceptor.cpp +++ b/libs/ui/source/event_interceptor.cpp @@ -59,21 +59,26 @@ namespace psemek::ui bool event_interceptor::on_event(mouse_move const & event) { - if (mouse_move_callback_) + if (child_) + mouseover_ = child_->shape().contains(geom::cast(event.position)); + else + mouseover_ = false; + + if (mouseover_ && mouse_move_callback_) return mouse_move_callback_(event); return false; } bool event_interceptor::on_event(mouse_click const & event) { - if (mouse_click_callback_) + if (mouseover_ && mouse_click_callback_) return mouse_click_callback_(event); return false; } bool event_interceptor::on_event(mouse_wheel const & event) { - if (mouse_wheel_callback_) + if (mouseover_ && mouse_wheel_callback_) return mouse_wheel_callback_(event); return false; }