From 2eb34dfc3dd3ca718da6ebf049886b4ae140b332 Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Wed, 19 Nov 2025 02:59:30 +0800 Subject: Remove all children when control destroyed. --- src/ui/controls/Control.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/ui/controls/Control.cpp') diff --git a/src/ui/controls/Control.cpp b/src/ui/controls/Control.cpp index 02148b72..70a3b1f3 100644 --- a/src/ui/controls/Control.cpp +++ b/src/ui/controls/Control.cpp @@ -27,6 +27,7 @@ Control::~Control() { } RemoveFromParent(); + RemoveAllChild(); } std::string Control::GetDebugId() const { @@ -89,9 +90,8 @@ void Control::InsertChildAt(Control* control, Index index) { children_.insert(children_.cbegin() + index, control); control->parent_ = this; - - TraverseDescendents([this](Control* control) { control->host_ = host_; }, - false); + control->TraverseDescendents( + [this](Control* control) { control->host_ = host_; }, true); if (host_) { host_->NotifyControlParentChange(control, nullptr, this); } @@ -111,8 +111,8 @@ void Control::RemoveChildAt(Index index) { auto control = children_[index]; children_.erase(children_.cbegin() + index); control->parent_ = nullptr; - TraverseDescendents([this](Control* control) { control->host_ = nullptr; }, - false); + control->TraverseDescendents( + [this](Control* control) { control->host_ = nullptr; }, true); if (host_) { host_->NotifyControlParentChange(control, this, nullptr); } -- cgit v1.2.3