aboutsummaryrefslogtreecommitdiff
path: root/src/ui/control.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-11-24 00:41:38 +0800
committercrupest <crupest@outlook.com>2018-11-24 00:41:38 +0800
commitd4658bfd97e1770e7ab4de356b3fd8c0d1999493 (patch)
treeaa91d04d7abfe776625ed2980bcae82fbfd516d0 /src/ui/control.cpp
parente8589550140d20b675fa7736441d7cdd1daee4d7 (diff)
downloadcru-d4658bfd97e1770e7ab4de356b3fd8c0d1999493.tar.gz
cru-d4658bfd97e1770e7ab4de356b3fd8c0d1999493.tar.bz2
cru-d4658bfd97e1770e7ab4de356b3fd8c0d1999493.zip
Improve hit test for clip.
Diffstat (limited to 'src/ui/control.cpp')
-rw-r--r--src/ui/control.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/ui/control.cpp b/src/ui/control.cpp
index 9afa5497..91b5aea3 100644
--- a/src/ui/control.cpp
+++ b/src/ui/control.cpp
@@ -211,6 +211,30 @@ namespace cru::ui
return false;
}
+ Control* Control::HitTest(const Point& point)
+ {
+ const auto point_inside = IsPointInside(point);
+
+ if (!point_inside && IsClipToPadding())
+ return nullptr; // if clip then don't test children.
+
+ const auto& children = GetChildren();
+
+ for (auto i = children.crbegin(); i != children.crend(); ++i)
+ {
+ const auto&& lefttop = (*i)->GetPositionRelative();
+ const auto&& coerced_point = Point(point.x - lefttop.x, point.y - lefttop.y);
+ const auto child_hit_test_result = (*i)->HitTest(coerced_point);
+ if (child_hit_test_result != nullptr)
+ return child_hit_test_result;
+ }
+
+ if (!point_inside)
+ return nullptr;
+
+ return this;
+ }
+
void Control::SetClipToPadding(const bool clip)
{
if (clip_to_padding_ == clip)
@@ -385,7 +409,6 @@ namespace cru::ui
child->TraverseDescendants([window](Control* control) {
control->OnAttachToWindow(window);
});
- window->RefreshControlList();
InvalidateLayout();
}
}
@@ -397,7 +420,6 @@ namespace cru::ui
child->TraverseDescendants([window](Control* control) {
control->OnDetachToWindow(window);
});
- window->RefreshControlList();
InvalidateLayout();
}
}