Make ui::event_interceptor only intercept mouse events when mouseover
This commit is contained in:
parent
fd0048c423
commit
223ce10e0f
2 changed files with 10 additions and 3 deletions
|
|
@ -35,6 +35,8 @@ namespace psemek::ui
|
|||
std::shared_ptr<element> child_;
|
||||
element * children_[1]{nullptr};
|
||||
|
||||
bool mouseover_ = false;
|
||||
|
||||
std::function<bool(mouse_move const &)> mouse_move_callback_;
|
||||
std::function<bool(mouse_click const &)> mouse_click_callback_;
|
||||
std::function<bool(mouse_wheel const &)> mouse_wheel_callback_;
|
||||
|
|
|
|||
|
|
@ -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<float>(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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue