Commit c63c396d authored by Adam Barth's avatar Adam Barth

Make hit testing work in layout2.dart

This CL makes simple_render_tree.dart interactive by making the hit testing
system work. I've also added a mechanism for requesting an animation frame.

R=eseidel@chromium.org, ianh@google.com

Review URL: https://codereview.chromium.org/1153543002
parent 400d6df7
......@@ -20,13 +20,13 @@ Picture draw(int a, int r, int g, int b) {
bool handleEvent(Event event) {
if (event.type == "pointerdown") {
view.picture = draw(255, 0, 0, 255);
view.schedulePaint();
view.scheduleFrame();
return true;
}
if (event.type == "pointerup") {
view.picture = draw(255, 0, 255, 0);
view.schedulePaint();
view.scheduleFrame();
return true;
}
......@@ -36,7 +36,7 @@ bool handleEvent(Event event) {
void main() {
print("Hello, world");
view.picture = draw(255, 0, 255, 0);
view.schedulePaint();
view.scheduleFrame();
view.setEventCallback(handleEvent);
}
......@@ -7,8 +7,11 @@ import 'dart:sky';
import 'package:sky/framework/layout2.dart';
class RenderSolidColor extends RenderDecoratedBox {
final int backgroundColor;
RenderSolidColor(int backgroundColor)
: super(new BoxDecoration(backgroundColor: backgroundColor));
: super(new BoxDecoration(backgroundColor: backgroundColor)),
backgroundColor = backgroundColor;
BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) {
return new BoxDimensions.withConstraints(constraints, height: 200.0);
......@@ -19,16 +22,48 @@ class RenderSolidColor extends RenderDecoratedBox {
setHeight(constraints, 200.0);
layoutDone();
}
bool handlePointer(PointerEvent event, { double x: 0.0, double y: 0.0 }) {
if (event.type == 'pointerdown') {
setBoxDecoration(new BoxDecoration(backgroundColor: 0xFFFF0000));
return true;
}
if (event.type == 'pointerup') {
setBoxDecoration(new BoxDecoration(backgroundColor: backgroundColor));
return true;
}
return false;
}
}
RenderView renderView;
void beginFrame(double timeStamp) {
RenderNode.flushLayout();
renderView.paintFrame();
}
bool handleEvent(Event event) {
if (event is! PointerEvent)
return false;
return renderView.handlePointer(event, x: event.x, y: event.y);
}
void main() {
view.setEventCallback(handleEvent);
view.setBeginFrameCallback(beginFrame);
var root = new RenderBlock(
decoration: new BoxDecoration(backgroundColor: 0xFF00FFFF));
root.add(new RenderSolidColor(0xFF00FF00));
root.add(new RenderSolidColor(0xFF0000FF));
RenderView renderView = new RenderView(root: root);
renderView = new RenderView(root: root);
renderView.layout(newWidth: view.width, newHeight: view.height);
renderView.paintFrame();
view.scheduleFrame();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment