Support moving ui::screen child to top

This commit is contained in:
Nikita Lisitsa 2022-05-27 19:59:03 +03:00
parent 203d0504ac
commit a567cbbbf5
2 changed files with 17 additions and 2 deletions

View file

@ -34,8 +34,9 @@ namespace psemek::ui
bool add_child(std::shared_ptr<element> c, x_policy x, y_policy y);
bool add_child(std::shared_ptr<element> c) override;
bool has_child(element *c) const override;
bool has_child(element * c) const override;
std::shared_ptr<element> remove_child(element * c) override;
bool move_to_top(element * c);
struct shape const & shape() const override { return shape_; }
void reshape(geom::box<float, 2> const & bbox) override;

View file

@ -27,7 +27,7 @@ namespace psemek::ui
return add_child(std::move(c), x_policy::floating, y_policy::floating);
}
bool screen::has_child(element *c) const
bool screen::has_child(element * c) const
{
return static_cast<bool>(container_.find(c));
}
@ -37,6 +37,20 @@ namespace psemek::ui
return container_.remove(c);
}
bool screen::move_to_top(element * c)
{
if (auto idx = container_.find(c))
{
auto e = container_.remove(*idx);
auto new_idx = container_.size();
container_.add(e, new_idx);
policies_.resize(container_.size());
policies_[new_idx] = policies_[*idx];
return true;
}
return false;
}
void screen::reshape(geom::box<float, 2> const & bbox)
{
shape_.box = bbox;