aboutsummaryrefslogtreecommitdiff
path: root/CruUI/ui/control.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-09-02 16:25:47 +0800
committercrupest <crupest@outlook.com>2018-09-02 16:25:47 +0800
commit09e480f0c956a16751a535558b84431ea47cd38f (patch)
treef98aa86d2b23970c7d03ea2463ea120d06838e17 /CruUI/ui/control.cpp
parentf3d62dec00748a306af658b87bffc54e4949a4f4 (diff)
downloadcru-09e480f0c956a16751a535558b84431ea47cd38f.tar.gz
cru-09e480f0c956a16751a535558b84431ea47cd38f.tar.bz2
cru-09e480f0c956a16751a535558b84431ea47cd38f.zip
...
Diffstat (limited to 'CruUI/ui/control.cpp')
-rw-r--r--CruUI/ui/control.cpp25
1 files changed, 18 insertions, 7 deletions
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 <algorithm>
#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<void(Control*)>& predicate)
+ void TraverseDescendantsInternal(Control* control, Action<Control*>& predicate)
{
predicate(control);
- control->ForeachChild([predicate](Control* c) {
+ control->ForeachChild([&predicate](Control* c) {
TraverseDescendantsInternal(c, predicate);
});
}
- void Control::TraverseDescendants(
- const std::function<void(Control*)>& predicate)
+ void Control::TraverseDescendants(Action<Control*>&& 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<Control*> GetAncestorList(Control* control)
{
std::list<Control*> l;