Improve hit testing

Now a RenderBox is considered hit if one of its children are hit or it itself
decides that it's hit. In particular, empty space inside a flex won't be hit
because none of the children are located there and a RenderFlex doesn't
consider itself hittable.

Fixes #53
Fixes #1221
This commit is contained in:
Adam Barth
2015-11-04 16:26:33 -08:00
parent 7b36d94455
commit 9bc64540c5
24 changed files with 145 additions and 70 deletions

View File

@@ -5,8 +5,14 @@ import 'rendering_tester.dart';
void main() {
test('Should be able to hit with negative scroll offset', () {
RenderBox green = new RenderDecoratedBox(
decoration: new BoxDecoration(
backgroundColor: const Color(0xFF00FF00)
));
RenderBox size = new RenderConstrainedBox(
additionalConstraints: new BoxConstraints.tight(const Size(100.0, 100.0)));
additionalConstraints: new BoxConstraints.tight(const Size(100.0, 100.0)),
child: green);
RenderBox red = new RenderDecoratedBox(
decoration: new BoxDecoration(
@@ -21,10 +27,10 @@ void main() {
result = new HitTestResult();
renderView.hitTest(result, position: new Point(15.0, 0.0));
expect(result.path.first.target, equals(viewport));
expect(result.path.first.target.runtimeType, equals(TestRenderView));
result = new HitTestResult();
renderView.hitTest(result, position: new Point(15.0, 15.0));
expect(result.path.first.target, equals(size));
expect(result.path.first.target, equals(green));
});
}