UI: fix slider state after mouse button up
This commit is contained in:
parent
03acb43dc4
commit
05b50d2826
2 changed files with 10 additions and 7 deletions
|
|
@ -43,7 +43,7 @@ namespace psemek::ui
|
|||
int value_ = 0;
|
||||
|
||||
state_t state_ = state_t::normal;
|
||||
std::optional<int> mouse_x_;
|
||||
std::optional<geom::point<int, 2>> mouse_;
|
||||
|
||||
on_value_changed_callback callback_;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ namespace psemek::ui
|
|||
bool slider::on_event(mouse_move const & e)
|
||||
{
|
||||
bool const over = shape().contains(geom::cast<float>(e.position));
|
||||
mouse_x_ = e.position[0];
|
||||
mouse_ = e.position;
|
||||
|
||||
switch (state_) {
|
||||
case state_t::normal:
|
||||
|
|
@ -24,8 +24,8 @@ namespace psemek::ui
|
|||
}
|
||||
break;
|
||||
case state_t::mousedown:
|
||||
if (mouse_x_)
|
||||
set_value(compute_value(*mouse_x_));
|
||||
if (mouse_)
|
||||
set_value(compute_value((*mouse_)[0]));
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -43,8 +43,8 @@ namespace psemek::ui
|
|||
if (e.down)
|
||||
{
|
||||
state_ = state_t::mousedown;
|
||||
if (mouse_x_)
|
||||
set_value(compute_value(*mouse_x_));
|
||||
if (mouse_)
|
||||
set_value(compute_value((*mouse_)[0]));
|
||||
on_state_changed(state_t::mouseover);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -52,7 +52,10 @@ namespace psemek::ui
|
|||
case state_t::mousedown:
|
||||
if (!e.down)
|
||||
{
|
||||
state_ = state_t::mouseover;
|
||||
if (mouse_ && shape().contains(geom::cast<float>(*mouse_)))
|
||||
state_ = state_t::mouseover;
|
||||
else
|
||||
state_ = state_t::normal;
|
||||
on_state_changed(state_t::mousedown);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue