Commit 647232b8 authored by Adam Barth's avatar Adam Barth

Use Point, Size, and Rect in layout2.dart

R=ianh@google.com

Review URL: https://codereview.chromium.org/1156303004
parent 081a440e
...@@ -256,7 +256,7 @@ class RenderSectorRing extends RenderSectorWithChildren { ...@@ -256,7 +256,7 @@ class RenderSectorRing extends RenderSectorWithChildren {
RenderSector child = firstChild; RenderSector child = firstChild;
while (child != null) { while (child != null) {
assert(child.parentData is SectorChildListParentData); assert(child.parentData is SectorChildListParentData);
canvas.paintChild(child, 0.0, 0.0); canvas.paintChild(child, new sky.Point(0.0, 0.0));
child = child.parentData.nextSibling; child = child.parentData.nextSibling;
} }
} }
...@@ -361,7 +361,7 @@ class RenderSectorSlice extends RenderSectorWithChildren { ...@@ -361,7 +361,7 @@ class RenderSectorSlice extends RenderSectorWithChildren {
RenderSector child = firstChild; RenderSector child = firstChild;
while (child != null) { while (child != null) {
assert(child.parentData is SectorChildListParentData); assert(child.parentData is SectorChildListParentData);
canvas.paintChild(child, 0.0, 0.0); canvas.paintChild(child, new sky.Point(0.0, 0.0));
child = child.parentData.nextSibling; child = child.parentData.nextSibling;
} }
} }
...@@ -411,9 +411,8 @@ class RenderBoxToRenderSectorAdapter extends RenderBox { ...@@ -411,9 +411,8 @@ class RenderBoxToRenderSectorAdapter extends RenderBox {
} }
void performLayout() { void performLayout() {
BoxDimensions ourDimensions;
if (child == null) { if (child == null) {
ourDimensions = new BoxDimensions.withConstraints(constraints, width: 0.0, height: 0.0); size = constraints.constrain(new sky.Size(0.0, 0.0));
} else { } else {
assert(child is RenderSector); assert(child is RenderSector);
assert(!constraints.isInfinite); assert(!constraints.isInfinite);
...@@ -423,28 +422,27 @@ class RenderBoxToRenderSectorAdapter extends RenderBox { ...@@ -423,28 +422,27 @@ class RenderBoxToRenderSectorAdapter extends RenderBox {
child.parentData.theta = 0.0; child.parentData.theta = 0.0;
child.layout(new SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), parentUsesSize: true); child.layout(new SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), parentUsesSize: true);
double dimension = (innerRadius + child.deltaRadius) * 2.0; double dimension = (innerRadius + child.deltaRadius) * 2.0;
ourDimensions = new BoxDimensions.withConstraints(constraints, width: dimension, height: dimension); size = constraints.constrain(new sky.Size(dimension, dimension));
} }
width = ourDimensions.width;
height = ourDimensions.height;
} }
double width;
double height;
// paint origin is 0,0 of our circle // paint origin is 0,0 of our circle
void paint(RenderNodeDisplayList canvas) { void paint(RenderNodeDisplayList canvas) {
super.paint(canvas); super.paint(canvas);
if (child != null) if (child != null) {
canvas.paintChild(child, width/2.0, height/2.0); sky.Rect bounds = new sky.Rect.fromSize(size);
canvas.paintChild(child, bounds.center);
}
} }
bool hitTest(HitTestResult result, { double x, double y }) { bool hitTest(HitTestResult result, { sky.Point position }) {
double x = position.x;
double y = position.y;
if (child == null) if (child == null)
return false; return false;
// translate to our origin // translate to our origin
x -= width/2.0; x -= size.width/2.0;
y -= height/2.0; y -= size.height/2.0;
// convert to radius/theta // convert to radius/theta
double radius = math.sqrt(x*x+y*y); double radius = math.sqrt(x*x+y*y);
double theta = (math.atan2(x, -y) - math.PI/2.0) % kTwoPi; double theta = (math.atan2(x, -y) - math.PI/2.0) % kTwoPi;
......
...@@ -7,24 +7,22 @@ import 'package:sky/framework/app.dart'; ...@@ -7,24 +7,22 @@ import 'package:sky/framework/app.dart';
import 'package:sky/framework/layout2.dart'; import 'package:sky/framework/layout2.dart';
class RenderSolidColor extends RenderDecoratedBox { class RenderSolidColor extends RenderDecoratedBox {
final double desiredHeight; final Size desiredSize;
final double desiredWidth;
final int backgroundColor; final int backgroundColor;
RenderSolidColor(int backgroundColor, { this.desiredHeight: double.INFINITY, RenderSolidColor(int backgroundColor, { this.desiredSize })
this.desiredWidth: double.INFINITY })
: backgroundColor = backgroundColor, : backgroundColor = backgroundColor,
super(new BoxDecoration(backgroundColor: backgroundColor)); super(new BoxDecoration(backgroundColor: backgroundColor)) {
}
BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) { BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) {
return new BoxDimensions.withConstraints(constraints, return new BoxDimensions.withConstraints(constraints,
height: desiredHeight, width: desiredSize.width,
width: desiredWidth); height: desiredSize.height);
} }
void performLayout() { void performLayout() {
width = constraints.constrainWidth(desiredWidth); size = constraints.constrain(desiredSize);
height = constraints.constrainHeight(desiredHeight);
} }
void handlePointer(PointerEvent event) { void handlePointer(PointerEvent event) {
...@@ -43,7 +41,7 @@ void main() { ...@@ -43,7 +41,7 @@ void main() {
decoration: new BoxDecoration(backgroundColor: 0xFF000000)); decoration: new BoxDecoration(backgroundColor: 0xFF000000));
void addFlexChild(RenderFlex parent, int backgroundColor, { int flex: 0 }) { void addFlexChild(RenderFlex parent, int backgroundColor, { int flex: 0 }) {
RenderNode child = new RenderSolidColor(backgroundColor); RenderNode child = new RenderSolidColor(backgroundColor, desiredSize: new Size.infinite());
parent.add(child); parent.add(child);
child.parentData.flex = flex; child.parentData.flex = flex;
} }
...@@ -52,13 +50,13 @@ void main() { ...@@ -52,13 +50,13 @@ void main() {
addFlexChild(root, 0xFFFFFF00, flex: 1); addFlexChild(root, 0xFFFFFF00, flex: 1);
// Turquoise box // Turquoise box
root.add(new RenderSolidColor(0x7700FFFF, desiredHeight: 100.0, desiredWidth: 100.0)); root.add(new RenderSolidColor(0x7700FFFF, desiredSize: new Size(100.0, 100.0)));
// Green and cyan render block with padding // Green and cyan render block with padding
var renderBlock = new RenderBlock(decoration: new BoxDecoration(backgroundColor: 0xFFFFFFFF)); var renderBlock = new RenderBlock(decoration: new BoxDecoration(backgroundColor: 0xFFFFFFFF));
renderBlock.add(new RenderSolidColor(0xFF00FF00, desiredHeight: 50.0, desiredWidth: 100.0)); renderBlock.add(new RenderSolidColor(0xFF00FF00, desiredSize: new Size(100.0, 50.0)));
renderBlock.add(new RenderSolidColor(0x7700FFFF, desiredHeight: 100.0, desiredWidth: 50.0)); renderBlock.add(new RenderSolidColor(0x7700FFFF, desiredSize: new Size(50.0, 100.0)));
root.add(new RenderPadding(const EdgeDims(10.0, 10.0, 10.0, 10.0), renderBlock)); root.add(new RenderPadding(const EdgeDims(10.0, 10.0, 10.0, 10.0), renderBlock));
......
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