1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 07:45:07 +00:00

GWidget: Tidy up the hit-testing code somewhat.

This commit is contained in:
Andreas Kling 2019-04-16 13:25:00 +02:00
parent c812d63ea6
commit 952f334de7
3 changed files with 11 additions and 13 deletions

View file

@ -296,7 +296,7 @@ Rect GWidget::screen_relative_rect() const
return window_relative_rect().translated(window()->position());
}
GWidget* GWidget::child_at(const Point& point)
GWidget* GWidget::child_at(const Point& point) const
{
for (int i = children().size() - 1; i >= 0; --i) {
if (!children()[i]->is_widget())
@ -310,13 +310,13 @@ GWidget* GWidget::child_at(const Point& point)
return nullptr;
}
GWidget::HitTestResult GWidget::hit_test(int x, int y)
GWidget::HitTestResult GWidget::hit_test(const Point& position)
{
if (is_greedy_for_hits())
return { this, x, y };
if (auto* child = child_at({ x, y }))
return child->hit_test(x - child->x(), y - child->y());
return { this, x, y };
return { this, position };
if (auto* child = child_at(position))
return child->hit_test(position - child->relative_position());
return { this, position };
}
void GWidget::set_window(GWindow* window)