diff options
author | crupest <crupest@outlook.com> | 2020-10-29 00:01:26 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-10-29 00:01:26 +0800 |
commit | 52594324b302f6e9da10ac01fe803196371bb2d9 (patch) | |
tree | 38dd36e0bf934b283dd80f808531a2ee862b174b /src/ui/ContentControl.cpp | |
parent | df4df679e157f974773dad7776b204e9d4f3009e (diff) | |
download | cru-52594324b302f6e9da10ac01fe803196371bb2d9.tar.gz cru-52594324b302f6e9da10ac01fe803196371bb2d9.tar.bz2 cru-52594324b302f6e9da10ac01fe803196371bb2d9.zip |
...
Diffstat (limited to 'src/ui/ContentControl.cpp')
-rw-r--r-- | src/ui/ContentControl.cpp | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/src/ui/ContentControl.cpp b/src/ui/ContentControl.cpp index 60d944d6..19b1b06f 100644 --- a/src/ui/ContentControl.cpp +++ b/src/ui/ContentControl.cpp @@ -3,25 +3,19 @@ #include "cru/ui/Window.hpp" namespace cru::ui { -ContentControl::ContentControl() - : child_vector_{nullptr}, child_(child_vector_[0]) {} - -ContentControl::~ContentControl() { delete child_; } +Control* ContentControl::GetChild() const { + if (GetChildren().empty()) return nullptr; + return GetChildren()[0]; +} void ContentControl::SetChild(Control* child) { - Expects(!dynamic_cast<Window*>(child)); // Can't add a window as child. - if (child == child_) return; - - const auto host = GetWindowHost(); - const auto old_child = child_; - child_ = child; - if (old_child) { - old_child->_SetParent(nullptr); - old_child->_SetDescendantWindowHost(nullptr); + Control* old_child = nullptr; + if (!GetChildren().empty()) { + old_child = GetChildren()[0]; + this->RemoveChild(0); } if (child) { - child->_SetParent(this); - child->_SetDescendantWindowHost(host); + this->AddChild(child, 0); } OnChildChanged(old_child, child); } |