diff options
author | crupest <crupest@outlook.com> | 2022-02-08 21:13:01 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-02-08 21:13:01 +0800 |
commit | fa1764d7cb77aa683c6049f915a46b981f9161f7 (patch) | |
tree | e5b54620d3b84f5391e995ab483647214152ca99 /src/ui/controls/Control.cpp | |
parent | 74bb9cd27242b9320f99ff4d2b50c3051576cc14 (diff) | |
download | cru-fa1764d7cb77aa683c6049f915a46b981f9161f7.tar.gz cru-fa1764d7cb77aa683c6049f915a46b981f9161f7.tar.bz2 cru-fa1764d7cb77aa683c6049f915a46b981f9161f7.zip |
...
Diffstat (limited to 'src/ui/controls/Control.cpp')
-rw-r--r-- | src/ui/controls/Control.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
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<void(Control*)>& 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; |