diff options
author | crupest <crupest@outlook.com> | 2022-02-10 19:26:19 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-02-10 19:26:19 +0800 |
commit | b2622f654598f82a220a98daaa84fed9ce3b92b2 (patch) | |
tree | 544d5a9a52d7530bf54e888d3fabd79ff85bfdb7 /include/cru/ui/render/LayoutRenderObject.h | |
parent | b8863c403a44c1c7ac35f1a1da92bbf3c8858552 (diff) | |
download | cru-b2622f654598f82a220a98daaa84fed9ce3b92b2.tar.gz cru-b2622f654598f82a220a98daaa84fed9ce3b92b2.tar.bz2 cru-b2622f654598f82a220a98daaa84fed9ce3b92b2.zip |
...
Diffstat (limited to 'include/cru/ui/render/LayoutRenderObject.h')
-rw-r--r-- | include/cru/ui/render/LayoutRenderObject.h | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/include/cru/ui/render/LayoutRenderObject.h b/include/cru/ui/render/LayoutRenderObject.h index d6882f9a..c8678deb 100644 --- a/include/cru/ui/render/LayoutRenderObject.h +++ b/include/cru/ui/render/LayoutRenderObject.h @@ -26,7 +26,7 @@ class CRU_UI_API LayoutRenderObject : public RenderObject { Index GetChildCount() const { return static_cast<Index>(children_.size()); } RenderObject* GetChildAt(Index position) { - Expects(position > 0 && position < GetChildCount()); + Expects(position >= 0 && position < GetChildCount()); return children_[position].render_object; } void AddChild(RenderObject* render_object, Index position) { @@ -35,12 +35,22 @@ class CRU_UI_API LayoutRenderObject : public RenderObject { children_.insert(children_.begin() + position, ChildData{render_object, ChildLayoutData()}); render_object->SetParent(this); + InvalidateLayout(); } void RemoveChild(Index position) { Expects(position > 0 && position < GetChildCount()); children_[position].render_object->SetParent(nullptr); children_.erase(children_.begin() + position); + InvalidateLayout(); + } + + void ClearChildren() { + for (auto child : children_) { + child.render_object->SetParent(nullptr); + } + children_.clear(); + InvalidateLayout(); } const ChildLayoutData& GetChildLayoutDataAt(Index position) const { |