From fa1764d7cb77aa683c6049f915a46b981f9161f7 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 8 Feb 2022 21:13:01 +0800 Subject: ... --- src/ui/controls/Control.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/ui/controls/Control.cpp') diff --git a/src/ui/controls/Control.cpp b/src/ui/controls/Control.cpp index bda8cb35..36d5cd60 100644 --- a/src/ui/controls/Control.cpp +++ b/src/ui/controls/Control.cpp @@ -32,17 +32,32 @@ Control::Control() { } Control::~Control() { - for (const auto child : children_) delete child; + if (auto_delete_children_) { + for (const auto child : children_) { + delete child; + } + } } host::WindowHost* Control::GetWindowHost() const { return window_host_; } +Index Control::IndexOf(Control* child) const { + for (Index i = 0; i < children_.size(); ++i) { + if (children_[i] == child) return i; + } + return -1; +} + void Control::TraverseDescendants( const std::function& predicate) { predicate(this); for (auto c : GetChildren()) c->TraverseDescendants(predicate); } +void Control::RemoveFromParent() { + if (parent_) parent_->RemoveChild(parent_->IndexOf(this)); +} + bool Control::HasFocus() { auto host = GetWindowHost(); if (host == nullptr) return false; -- cgit v1.2.3