From 400d6df700d39956ca8f33d817f71ae0038416d6 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Thu, 21 May 2015 11:15:50 -0700 Subject: [PATCH] Actually perform a block layout This CL teaches simple_render_tree how to do a block layout using layout2.dart. R=eseidel@chromium.org, ianh@google.com Review URL: https://codereview.chromium.org/1144423002 --- examples/raw/simple_render_tree.dart | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/examples/raw/simple_render_tree.dart b/examples/raw/simple_render_tree.dart index f5ae7e7dc0..ee168f5609 100644 --- a/examples/raw/simple_render_tree.dart +++ b/examples/raw/simple_render_tree.dart @@ -6,16 +6,29 @@ import 'dart:math'; import 'dart:sky'; import 'package:sky/framework/layout2.dart'; -class RenderBlueCircle extends RenderBox { - void paint(RenderNodeDisplayList canvas) { - double radius = min(width, height) * 0.45; - Paint paint = new Paint()..setARGB(255, 0, 255, 255); - canvas.drawCircle(width / 2, height / 2, radius, paint); +class RenderSolidColor extends RenderDecoratedBox { + RenderSolidColor(int backgroundColor) + : super(new BoxDecoration(backgroundColor: backgroundColor)); + + BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) { + return new BoxDimensions.withConstraints(constraints, height: 200.0); + } + + void layout(BoxConstraints constraints, { RenderNode relayoutSubtreeRoot }) { + setWidth(constraints, constraints.maxWidth); + setHeight(constraints, 200.0); + layoutDone(); } } void main() { - RenderView renderView = new RenderView(root: new RenderBlueCircle()); + 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.layout(newWidth: view.width, newHeight: view.height); renderView.paintFrame(); }