aboutsummaryrefslogtreecommitdiff
path: root/CruUI/ui/layout_base.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-09-25 13:08:40 +0800
committercrupest <crupest@outlook.com>2018-09-25 13:08:40 +0800
commit4b86554a0354d78efeb40e551eaccaac0fecd1d1 (patch)
treec8a73d848401f523ff91fe8ed1b0887aa88bbfb8 /CruUI/ui/layout_base.cpp
parentcea138417c54d6cf8043b6334c22e3af957d26f8 (diff)
downloadcru-4b86554a0354d78efeb40e551eaccaac0fecd1d1.tar.gz
cru-4b86554a0354d78efeb40e551eaccaac0fecd1d1.tar.bz2
cru-4b86554a0354d78efeb40e551eaccaac0fecd1d1.zip
Change the structure of project.
Diffstat (limited to 'CruUI/ui/layout_base.cpp')
-rw-r--r--CruUI/ui/layout_base.cpp79
1 files changed, 0 insertions, 79 deletions
diff --git a/CruUI/ui/layout_base.cpp b/CruUI/ui/layout_base.cpp
deleted file mode 100644
index a26379a0..00000000
--- a/CruUI/ui/layout_base.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-#include "layout_base.h"
-
-#include "application.h"
-#include "control.h"
-
-namespace cru::ui
-{
- LayoutManager* LayoutManager::GetInstance()
- {
- static LayoutManager layout_manager;
- return &layout_manager;
- }
-
- void LayoutManager::InvalidateControlPositionCache(Control * control)
- {
- if (cache_invalid_controls_.count(control) == 1)
- return;
-
- // find descendant then erase it; find ancestor then just return.
- auto i = cache_invalid_controls_.cbegin();
- while (i != cache_invalid_controls_.cend())
- {
- auto current_i = i++;
- const auto result = IsAncestorOrDescendant(*current_i, control);
- if (result == control)
- cache_invalid_controls_.erase(current_i);
- else if (result != nullptr)
- return; // find a ancestor of "control", just return
- }
-
- cache_invalid_controls_.insert(control);
-
- if (cache_invalid_controls_.size() == 1) // when insert just now and not repeat to "InvokeLater".
- {
- InvokeLater([this] {
-
- RefreshInvalidControlPositionCache(); // first refresh position cache.
- for (const auto i : cache_invalid_controls_) // traverse all descendants of position-invalid controls and notify position change event
- i->TraverseDescendants([](Control* control)
- {
- control->CheckAndNotifyPositionChanged();
- });
- cache_invalid_controls_.clear(); // after update and notify, clear the set.
-
- });
- }
- }
-
- void LayoutManager::RefreshInvalidControlPositionCache()
- {
- for (const auto i : cache_invalid_controls_)
- RefreshControlPositionCache(i);
- }
-
- void LayoutManager::RefreshControlPositionCache(Control * control)
- {
- auto point = Point::Zero();
- auto parent = control;
- while ((parent = parent->GetParent())) {
- const auto p = parent->GetPositionRelative();
- point.x += p.x;
- point.y += p.y;
- }
- RefreshControlPositionCacheInternal(control, point);
- }
-
- void LayoutManager::RefreshControlPositionCacheInternal(Control * control, const Point & parent_lefttop_absolute)
- {
- const auto position = control->GetPositionRelative();
- Point lefttop(
- parent_lefttop_absolute.x + position.x,
- parent_lefttop_absolute.y + position.y
- );
- control->position_cache_.lefttop_position_absolute = lefttop;
- control->ForeachChild([lefttop](Control* c) {
- RefreshControlPositionCacheInternal(c, lefttop);
- });
- }
-}