Support draggable windows
This commit is contained in:
parent
3752ad7da0
commit
8c21543ecb
1 changed files with 30 additions and 0 deletions
|
|
@ -224,6 +224,33 @@ namespace psemek::ui
|
||||||
return children_range{children_};
|
return children_range{children_};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool on_event(mouse_move const & e)
|
||||||
|
{
|
||||||
|
mouse_ = e.position;
|
||||||
|
|
||||||
|
if (drag_ && *drag_ != e.position)
|
||||||
|
{
|
||||||
|
shape_.box += geom::cast<float>(e.position - *drag_);
|
||||||
|
drag_ = e.position;
|
||||||
|
post_reshape();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool on_event(mouse_click const & e)
|
||||||
|
{
|
||||||
|
if (e.button == mouse_button::left)
|
||||||
|
{
|
||||||
|
if (mouse_ && e.down)
|
||||||
|
drag_ = *mouse_;
|
||||||
|
else
|
||||||
|
drag_ = std::nullopt;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
struct shape const & shape() const override
|
struct shape const & shape() const override
|
||||||
{
|
{
|
||||||
return shape_;
|
return shape_;
|
||||||
|
|
@ -310,6 +337,9 @@ namespace psemek::ui
|
||||||
std::shared_ptr<rich_button> close_button_;
|
std::shared_ptr<rich_button> close_button_;
|
||||||
std::shared_ptr<element> child_;
|
std::shared_ptr<element> child_;
|
||||||
|
|
||||||
|
std::optional<geom::point<int, 2>> mouse_;
|
||||||
|
std::optional<geom::point<int, 2>> drag_;
|
||||||
|
|
||||||
box_shape shape_;
|
box_shape shape_;
|
||||||
|
|
||||||
element * children_[3];
|
element * children_[3];
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue