diff options
| author | Yuqian Yang <crupest@crupest.life> | 2025-11-18 00:46:27 +0800 |
|---|---|---|
| committer | Yuqian Yang <crupest@crupest.life> | 2025-11-18 00:46:27 +0800 |
| commit | 6b4edc9be8ec556147c195cf2047d92b9439efd7 (patch) | |
| tree | a1d7b7d1e821b4e1911fd00761f77a24ee483f4a /src/ui/controls/TreeView.cpp | |
| parent | f7c4d19df66c602d74795e98ce2ee4390d06fbb4 (diff) | |
| download | cru-6b4edc9be8ec556147c195cf2047d92b9439efd7.tar.gz cru-6b4edc9be8ec556147c195cf2047d92b9439efd7.tar.bz2 cru-6b4edc9be8ec556147c195cf2047d92b9439efd7.zip | |
Bring back ControlHost and refactor tree management of control.
Diffstat (limited to 'src/ui/controls/TreeView.cpp')
| -rw-r--r-- | src/ui/controls/TreeView.cpp | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/src/ui/controls/TreeView.cpp b/src/ui/controls/TreeView.cpp index 659aef00..89613763 100644 --- a/src/ui/controls/TreeView.cpp +++ b/src/ui/controls/TreeView.cpp @@ -9,7 +9,7 @@ TreeViewItem::TreeViewItem(TreeView* tree_view, TreeViewItem* parent, TreeViewItem::~TreeViewItem() { if (control_) { - control_->SetParent(nullptr); + tree_view_->RemoveChild(control_); } for (auto item : children_) { @@ -46,12 +46,12 @@ void TreeViewItem::RemoveItem(Index position) { void TreeViewItem::SetControl(Control* control) { if (control_) { - control_->SetParent(nullptr); + tree_view_->RemoveChild(control); render_object_item_->SetRenderObject(nullptr); } control_ = control; if (control) { - control->SetParent(tree_view_); + tree_view_->AddChild(tree_view_); render_object_item_->SetRenderObject(control->GetRenderObject()); } } @@ -69,18 +69,10 @@ TreeView::TreeView() TreeView::~TreeView() {} -void TreeView::ForEachChild(const std::function<void(Control*)>& predicate) { - root_item_.TraverseDescendants([&predicate](TreeViewItem* item) { - if (auto control = item->GetControl()) { - predicate(control); - } - }); -} - -void TreeView::RemoveChild(Control* control) { - root_item_.TraverseDescendants([&control](TreeViewItem* item) { +void TreeView::OnChildRemoved(Control* control, Index index) { + root_item_.TraverseDescendants([control](TreeViewItem* item) { if (item->GetControl() == control) { - item->SetControl(nullptr); + item->RemoveFromParent(); } }); } |
