From aa8ba64f4f580552ba14325dd3e04f38a3c9a1de Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 10 Sep 2018 00:09:52 +0800 Subject: ... --- CruUI/ui/control.cpp | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) (limited to 'CruUI/ui/control.cpp') diff --git a/CruUI/ui/control.cpp b/CruUI/ui/control.cpp index ee6db284..507beee8 100644 --- a/CruUI/ui/control.cpp +++ b/CruUI/ui/control.cpp @@ -1,6 +1,8 @@ #include "control.h" +#include #include +#include #include "window.h" #include "timer.h" @@ -25,19 +27,29 @@ namespace cru { } + Control::~Control() + { + ForeachChild([](auto control) + { + delete control; + }); + } + void Control::ForeachChild(Action&& predicate) const { - for (const auto child : children_) - predicate(child); + if (is_container_) + for (const auto child : children_) + predicate(child); } void Control::ForeachChild(FlowControlAction&& predicate) const { - for (const auto child : children_) - { - if (predicate(child) == FlowControl::Break) - break; - } + if (is_container_) + for (const auto child : children_) + { + if (predicate(child) == FlowControl::Break) + break; + } } void AddChildCheck(Control* control) @@ -128,7 +140,8 @@ namespace cru { void Control::TraverseDescendants(Action&& predicate) { - TraverseDescendantsInternal(this, predicate); + if (is_container_) + TraverseDescendantsInternal(this, predicate); } Point Control::GetPositionRelative() @@ -138,13 +151,16 @@ namespace cru { void Control::SetPositionRelative(const Point & position) { - if (old_position_ == position) // if cache has been refreshed and no pending notify - old_position_ = position_; - position_ = position; - if (auto window = GetWindow()) + if (position != position_) { - window->GetLayoutManager()->InvalidateControlPositionCache(this); - window->Repaint(); + if (old_position_ == position) // if cache has been refreshed and no pending notify + old_position_ = position_; + position_ = position; + if (auto window = GetWindow()) + { + window->GetLayoutManager()->InvalidateControlPositionCache(this); + window->Repaint(); + } } } @@ -241,9 +257,12 @@ namespace cru { void Control::Layout(const Rect& rect) { + auto before = std::chrono::steady_clock::now(); SetPositionRelative(rect.GetLeftTop()); SetSize(rect.GetSize()); OnLayout(rect); + auto after = std::chrono::steady_clock::now(); + OutputDebugStringW((L"Layout time duration:" + std::to_wstring(std::chrono::duration_cast(after - before).count()) + L"\n").c_str()); } Size Control::GetDesiredSize() const -- cgit v1.2.3