diff options
Diffstat (limited to 'src/ui/controls/Control.cpp')
| -rw-r--r-- | src/ui/controls/Control.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/ui/controls/Control.cpp b/src/ui/controls/Control.cpp index e903b5b3..9c0fc537 100644 --- a/src/ui/controls/Control.cpp +++ b/src/ui/controls/Control.cpp @@ -1,4 +1,5 @@ #include "cru/ui/controls/Control.h" +#include "cru/base/log/Logger.h" #include "cru/ui/controls/Window.h" #include "cru/platform/gui/Cursor.h" @@ -27,11 +28,14 @@ Control::Control() { Control::~Control() { if (auto window = GetWindow()) { if (window->IsInEventHandling()) { - // Don't delete control during event handling. Use DeleteLater. - std::terminate(); + CRU_LOG_TAG_WARN( + "Better use delete later to delete control during event handling."); } } + if (auto window = GetWindow()) { + window->NotifyControlDestroyed(this); + } RemoveFromParent(); } @@ -58,6 +62,15 @@ void Control::SetParent(Control* parent) { OnParentChanged(old_parent, parent); } +bool Control::HasAncestor(Control* control) { + auto parent = this; + while (parent) { + if (parent == control) return true; + parent = parent->GetParent(); + } + return false; +} + void Control::RemoveFromParent() { if (parent_) { parent_->RemoveChild(this); |
