aboutsummaryrefslogtreecommitdiff
path: root/CruUI/ui/control.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-09-10 00:09:52 +0800
committercrupest <crupest@outlook.com>2018-09-10 00:09:52 +0800
commitaa8ba64f4f580552ba14325dd3e04f38a3c9a1de (patch)
treecde762da1a0bfb24c28a8a3dfa5253ad95a5b809 /CruUI/ui/control.cpp
parent74031db4b8c366531db5be8fa8d765483ab377b0 (diff)
downloadcru-aa8ba64f4f580552ba14325dd3e04f38a3c9a1de.tar.gz
cru-aa8ba64f4f580552ba14325dd3e04f38a3c9a1de.tar.bz2
cru-aa8ba64f4f580552ba14325dd3e04f38a3c9a1de.zip
...
Diffstat (limited to 'CruUI/ui/control.cpp')
-rw-r--r--CruUI/ui/control.cpp47
1 files changed, 33 insertions, 14 deletions
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 <string>
#include <algorithm>
+#include <chrono>
#include "window.h"
#include "timer.h"
@@ -25,19 +27,29 @@ namespace cru {
}
+ Control::~Control()
+ {
+ ForeachChild([](auto control)
+ {
+ delete control;
+ });
+ }
+
void Control::ForeachChild(Action<Control*>&& predicate) const
{
- for (const auto child : children_)
- predicate(child);
+ if (is_container_)
+ for (const auto child : children_)
+ predicate(child);
}
void Control::ForeachChild(FlowControlAction<Control*>&& 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<Control*>&& 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<std::chrono::milliseconds>(after - before).count()) + L"\n").c_str());
}
Size Control::GetDesiredSize() const