Fix handling state in ui::impl::button_base
This commit is contained in:
parent
7346aff9f6
commit
13862d8b47
2 changed files with 9 additions and 18 deletions
|
|
@ -17,9 +17,6 @@ namespace psemek::ui::impl
|
|||
void update(button const & value);
|
||||
|
||||
private:
|
||||
bool is_mouseover_ = false;
|
||||
bool is_mousedown_ = false;
|
||||
|
||||
react::source<bool> mouseover_;
|
||||
react::source<bool> mousedown_;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -11,28 +11,22 @@ namespace psemek::ui::impl
|
|||
{
|
||||
bool const mouseover = geom::contains(shape(), geom::cast<float>(event.position));
|
||||
|
||||
if (is_mouseover_ != mouseover)
|
||||
{
|
||||
is_mouseover_ = mouseover;
|
||||
mouseover_.set(is_mouseover_);
|
||||
}
|
||||
if (*mouseover_ != mouseover)
|
||||
mouseover_.set(mouseover);
|
||||
|
||||
return is_mouseover_;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool button_base::on_event(mouse_button_event const & event)
|
||||
{
|
||||
if (is_mouseover_)
|
||||
bool const mousedown = event.button == app::mouse_button::left && event.down;
|
||||
|
||||
if (*mouseover_ || !mousedown)
|
||||
{
|
||||
bool const mousedown = event.button == app::mouse_button::left && event.down;
|
||||
if (*mousedown_ != mousedown)
|
||||
mousedown_.set(mousedown);
|
||||
|
||||
if (is_mousedown_ != mousedown)
|
||||
{
|
||||
is_mousedown_ = mousedown;
|
||||
mousedown_.set(is_mousedown_);
|
||||
}
|
||||
|
||||
return true;
|
||||
return *mouseover_ && mousedown;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue