From a567cbbbf5903f74701eaa7bdb61bb0eb2af3a6b Mon Sep 17 00:00:00 2001 From: lisyarus Date: Fri, 27 May 2022 19:59:03 +0300 Subject: [PATCH] Support moving ui::screen child to top --- libs/ui/include/psemek/ui/screen.hpp | 3 ++- libs/ui/source/screen.cpp | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/libs/ui/include/psemek/ui/screen.hpp b/libs/ui/include/psemek/ui/screen.hpp index 154e643f..60124c3d 100644 --- a/libs/ui/include/psemek/ui/screen.hpp +++ b/libs/ui/include/psemek/ui/screen.hpp @@ -34,8 +34,9 @@ namespace psemek::ui bool add_child(std::shared_ptr c, x_policy x, y_policy y); bool add_child(std::shared_ptr c) override; - bool has_child(element *c) const override; + bool has_child(element * c) const override; std::shared_ptr remove_child(element * c) override; + bool move_to_top(element * c); struct shape const & shape() const override { return shape_; } void reshape(geom::box const & bbox) override; diff --git a/libs/ui/source/screen.cpp b/libs/ui/source/screen.cpp index e57c359d..b32bae53 100644 --- a/libs/ui/source/screen.cpp +++ b/libs/ui/source/screen.cpp @@ -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(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 const & bbox) { shape_.box = bbox;