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);
|
void update(button const & value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool is_mouseover_ = false;
|
|
||||||
bool is_mousedown_ = false;
|
|
||||||
|
|
||||||
react::source<bool> mouseover_;
|
react::source<bool> mouseover_;
|
||||||
react::source<bool> mousedown_;
|
react::source<bool> mousedown_;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -11,28 +11,22 @@ namespace psemek::ui::impl
|
||||||
{
|
{
|
||||||
bool const mouseover = geom::contains(shape(), geom::cast<float>(event.position));
|
bool const mouseover = geom::contains(shape(), geom::cast<float>(event.position));
|
||||||
|
|
||||||
if (is_mouseover_ != mouseover)
|
if (*mouseover_ != mouseover)
|
||||||
{
|
mouseover_.set(mouseover);
|
||||||
is_mouseover_ = mouseover;
|
|
||||||
mouseover_.set(is_mouseover_);
|
|
||||||
}
|
|
||||||
|
|
||||||
return is_mouseover_;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool button_base::on_event(mouse_button_event const & event)
|
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)
|
return *mouseover_ && mousedown;
|
||||||
{
|
|
||||||
is_mousedown_ = mousedown;
|
|
||||||
mousedown_.set(is_mousedown_);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue