diff options
Diffstat (limited to 'include/cru/ui/controls/SingleChildControl.h')
| -rw-r--r-- | include/cru/ui/controls/SingleChildControl.h | 35 |
1 files changed, 7 insertions, 28 deletions
diff --git a/include/cru/ui/controls/SingleChildControl.h b/include/cru/ui/controls/SingleChildControl.h index b2e58c5f..f748a38d 100644 --- a/include/cru/ui/controls/SingleChildControl.h +++ b/include/cru/ui/controls/SingleChildControl.h @@ -10,25 +10,17 @@ class SingleChildControl : public Control { } public: - CRU_DELETE_COPY(SingleChildControl) - CRU_DELETE_MOVE(SingleChildControl) - - ~SingleChildControl() override { SetChild(nullptr); } + Control* GetChild() { + return GetChildren().empty() ? nullptr : GetChildren().front(); + } - Control* GetChild() const { return child_; } void SetChild(Control* child) { - if (child == child_) return; - - assert(child == nullptr || child->GetParent() == nullptr); - - if (child_) { - child_->SetParent(nullptr); + if (GetChild() == child) return; + if (!GetChildren().empty()) { + RemoveChildAt(0); } - - child_ = child; - if (child) { - child->SetParent(this); + InsertChildAt(child, 0); } container_render_object_->SetChild( @@ -43,20 +35,7 @@ class SingleChildControl : public Control { return container_render_object_.get(); } - void ForEachChild(const std::function<void(Control*)>& predicate) override { - if (child_) { - predicate(child_); - } - } - - void RemoveChild(Control* child) override { - if (child_ == child) { - SetChild(nullptr); - } - } - private: - Control* child_ = nullptr; std::unique_ptr<TRenderObject> container_render_object_; }; } // namespace cru::ui::controls |
