diff options
author | 杨宇千 <crupest@outlook.com> | 2018-12-06 03:48:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-06 03:48:18 +0800 |
commit | f0e2b2d3763dd100a5e9d6cda566724d2b7da965 (patch) | |
tree | 24a3c1d5d4a37b724a5a5d694894ac9c09d2e6f0 /src/ui/layout_base.cpp | |
parent | 1166da612f01172270114921eb6785998ef88476 (diff) | |
parent | a0ddf6549313f4b81d55d3c25c724c809230967f (diff) | |
download | cru-f0e2b2d3763dd100a5e9d6cda566724d2b7da965.tar.gz cru-f0e2b2d3763dd100a5e9d6cda566724d2b7da965.tar.bz2 cru-f0e2b2d3763dd100a5e9d6cda566724d2b7da965.zip |
Merge pull request #34 from crupest/dev
Improve layout.
Diffstat (limited to 'src/ui/layout_base.cpp')
-rw-r--r-- | src/ui/layout_base.cpp | 78 |
1 files changed, 0 insertions, 78 deletions
diff --git a/src/ui/layout_base.cpp b/src/ui/layout_base.cpp index 40bb71b3..5898a623 100644 --- a/src/ui/layout_base.cpp +++ b/src/ui/layout_base.cpp @@ -1,84 +1,6 @@ #include "layout_base.hpp" -#include "application.hpp" -#include "control.hpp" -#include "window.hpp" - namespace cru::ui { - LayoutManager* LayoutManager::GetInstance() - { - return Application::GetInstance()->ResolveSingleton<LayoutManager>([](auto) - { - return new LayoutManager{}; - }); - } - - 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] { - for (const auto i : cache_invalid_controls_) - RefreshControlPositionCache(i); - 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); - cache_invalid_controls_.clear(); - } - - 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(); - const Point lefttop( - parent_lefttop_absolute.x + position.x, - parent_lefttop_absolute.y + position.y - ); - control->position_cache_.lefttop_position_absolute = lefttop; - for(auto c : control->GetChildren()) - { - RefreshControlPositionCacheInternal(c, lefttop); - } - } } |