aboutsummaryrefslogtreecommitdiff
path: root/src/ui/ContentControl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/ContentControl.cpp')
-rw-r--r--src/ui/ContentControl.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/ui/ContentControl.cpp b/src/ui/ContentControl.cpp
new file mode 100644
index 00000000..8d1a17d2
--- /dev/null
+++ b/src/ui/ContentControl.cpp
@@ -0,0 +1,33 @@
+#include "cru/ui/ContentControl.hpp"
+
+#include "cru/ui/Window.hpp"
+
+namespace cru::ui {
+ContentControl::ContentControl()
+ : child_vector_{nullptr}, child_(child_vector_[0]) {}
+
+ContentControl::~ContentControl() { delete child_; }
+
+void ContentControl::SetChild(Control* child) {
+ Expects(!dynamic_cast<Window*>(child)); // Can't add a window as child.
+ if (child == child_) return;
+
+ const auto host = GetUiHost();
+ const auto old_child = child_;
+ child_ = child;
+ if (old_child) {
+ old_child->_SetParent(nullptr);
+ old_child->_SetDescendantUiHost(nullptr);
+ }
+ if (child) {
+ child->_SetParent(this);
+ child->_SetDescendantUiHost(host);
+ }
+ OnChildChanged(old_child, child);
+}
+
+void ContentControl::OnChildChanged(Control* old_child, Control* new_child) {
+ CRU_UNUSED(old_child)
+ CRU_UNUSED(new_child)
+}
+} // namespace cru::ui