Make RenderBlock painting match its hittesting

I added a clip in RenderBlock to make the painted pixels
match the hittesting logic.  This at least makes obvious
all the numerous hittesting bugs in our system. :)

I also moved demo_launcher to ScrollableList awesomeness.

R=abarth@chromium.org, abarth@google.com

Review URL: https://codereview.chromium.org/1223083002 .
This commit is contained in:
Eric Seidel 2015-07-08 13:47:39 -07:00
parent 427f162519
commit 2e8e2d0b72
2 changed files with 23 additions and 11 deletions

View File

@ -19,6 +19,7 @@ import 'package:sky/widgets/scaffold.dart';
import 'package:sky/widgets/task_description.dart';
import 'package:sky/widgets/theme.dart';
import 'package:sky/widgets/tool_bar.dart';
import 'package:sky/widgets/scrollable_list.dart';
AssetBundle _initBundle() {
if (rootBundle != null)
@ -132,11 +133,7 @@ List<Widget> demos = [
const double kCardHeight = 120.0;
const EdgeDims kListPadding = const EdgeDims.all(4.0);
class DemoList extends FixedHeightScrollable {
DemoList({ String key }) : super(key: key, itemHeight: kCardHeight, padding: kListPadding);
int get itemCount => demos.length;
class DemoList extends Component {
Widget buildDemo(SkyDemo demo) {
return new Listener(
key: demo.name,
@ -166,12 +163,13 @@ class DemoList extends FixedHeightScrollable {
);
}
List<Widget> buildItems(int start, int count) {
return demos
.skip(start)
.take(count)
.map(buildDemo)
.toList(growable: false);
Widget build() {
return new ScrollableList<SkyDemo>(
items: demos,
itemHeight: kCardHeight,
itemBuilder: buildDemo,
padding: kListPadding
);
}
}

View File

@ -15,6 +15,8 @@ class RenderBlock extends RenderBox with ContainerRenderObjectMixin<RenderBox, B
// uses the maximum width provided by the parent
// sizes itself to the height of its child stack
bool _hasVisualOverflow = false;
RenderBlock({
List<RenderBox> children
}) {
@ -94,7 +96,12 @@ class RenderBlock extends RenderBox with ContainerRenderObjectMixin<RenderBox, B
y += child.size.height;
child = child.parentData.nextSibling;
}
// FIXME(eseidel): Block lays out its children with unconstrained height
// yet itself remains constrained. Remember that our children wanted to
// be taller than we are so we know to clip them (and not cause confusing
// mismatch of painting vs. hittesting).
size = new Size(width, constraints.constrainHeight(y));
_hasVisualOverflow = y > size.height;
assert(!size.isInfinite);
}
@ -103,7 +110,14 @@ class RenderBlock extends RenderBox with ContainerRenderObjectMixin<RenderBox, B
}
void paint(PaintingCanvas canvas, Offset offset) {
if (_hasVisualOverflow) {
canvas.save();
canvas.clipRect(offset & size);
}
defaultPaint(canvas, offset);
if (_hasVisualOverflow) {
canvas.restore();
}
}
}