aboutsummaryrefslogtreecommitdiff
path: root/src/ui/content_control.cpp
blob: d5abca1c483e8b55178f8bcbf4ea616c3517d29d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "content_control.hpp"

#include "window.hpp"

namespace cru::ui {
ContentControl::ContentControl()
    : child_vector_{nullptr}, child_(child_vector_[0]) {}

ContentControl::~ContentControl() { delete child_; }

void ContentControl::SetChild(Control* child) {
  assert(!dynamic_cast<Window*>(child));  // Can't add a window as child.
  if (child == child_) return;

  const auto window = GetWindow();
  const auto old_child = child_;
  child_ = child;
  if (old_child) {
    old_child->_SetParent(nullptr);
    old_child->_SetDescendantWindow(nullptr);
  }
  if (child) {
    child->_SetParent(this);
    child->_SetDescendantWindow(window);
  }
  OnChildChanged(old_child, child);
}

void ContentControl::OnChildChanged(Control* old_child, Control* new_child) {}
}  // namespace cru::ui