From 09e480f0c956a16751a535558b84431ea47cd38f Mon Sep 17 00:00:00 2001 From: crupest Date: Sun, 2 Sep 2018 16:25:47 +0800 Subject: ... --- CruUI/ui/control.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'CruUI/ui/control.cpp') diff --git a/CruUI/ui/control.cpp b/CruUI/ui/control.cpp index e8223498..68713841 100644 --- a/CruUI/ui/control.cpp +++ b/CruUI/ui/control.cpp @@ -3,6 +3,7 @@ #include #include "window.h" +#include "timer.h" namespace cru { namespace ui { @@ -12,6 +13,7 @@ namespace cru { window_(nullptr), parent_(nullptr), children_(), + old_position_(Point::zero), position_(Point::zero), size_(Size::zero), position_cache_(), @@ -116,17 +118,15 @@ namespace cru { return ancestor; } - void TraverseDescendantsInternal(Control* control, - const std::function& predicate) + void TraverseDescendantsInternal(Control* control, Action& predicate) { predicate(control); - control->ForeachChild([predicate](Control* c) { + control->ForeachChild([&predicate](Control* c) { TraverseDescendantsInternal(c, predicate); }); } - void Control::TraverseDescendants( - const std::function& predicate) + void Control::TraverseDescendants(Action&& predicate) { TraverseDescendantsInternal(this, predicate); } @@ -138,13 +138,14 @@ 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()) { window->GetLayoutManager()->InvalidateControlPositionCache(this); window->Repaint(); } - //TODO: Position change notify. } Size Control::GetSize() @@ -416,7 +417,7 @@ namespace cru { auto&& calculate_final_length = [](const MeasureLength& layout_length, const float length_for_children, const float max_child_length) -> float { - switch(layout_length.mode) + switch (layout_length.mode) { case MeasureMode::Exactly: case MeasureMode::Stretch: @@ -442,6 +443,16 @@ namespace cru { }); } + void Control::CheckAndNotifyPositionChanged() + { + if (this->old_position_ != this->position_) + { + PositionChangedEventArgs args(this, this, this->old_position_, this->position_); + this->OnPositionChangedCore(args); + this->old_position_ = this->position_; + } + } + std::list GetAncestorList(Control* control) { std::list l; -- cgit v1.2.3