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 {
RenderSector child = firstChild;
while (child != null) {
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;
}
}
......@@ -361,7 +361,7 @@ class RenderSectorSlice extends RenderSectorWithChildren {
RenderSector child = firstChild;
while (child != null) {
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;
}
}
......@@ -411,9 +411,8 @@ class RenderBoxToRenderSectorAdapter extends RenderBox {
}
void performLayout() {
BoxDimensions ourDimensions;
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 {
assert(child is RenderSector);
assert(!constraints.isInfinite);
......@@ -423,28 +422,27 @@ class RenderBoxToRenderSectorAdapter extends RenderBox {
child.parentData.theta = 0.0;
child.layout(new SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), parentUsesSize: true);
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
void paint(RenderNodeDisplayList canvas) {
super.paint(canvas);
if (child != null)
canvas.paintChild(child, width/2.0, height/2.0);
if (child != null) {
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)
return false;
// translate to our origin
x -= width/2.0;
y -= height/2.0;
x -= size.width/2.0;
y -= size.height/2.0;
// convert to radius/theta
double radius = math.sqrt(x*x+y*y);
double theta = (math.atan2(x, -y) - math.PI/2.0) % kTwoPi;
......
......@@ -7,24 +7,22 @@ import 'package:sky/framework/app.dart';
import 'package:sky/framework/layout2.dart';
class RenderSolidColor extends RenderDecoratedBox {
final double desiredHeight;
final double desiredWidth;
final Size desiredSize;
final int backgroundColor;
RenderSolidColor(int backgroundColor, { this.desiredHeight: double.INFINITY,
this.desiredWidth: double.INFINITY })
RenderSolidColor(int backgroundColor, { this.desiredSize })
: backgroundColor = backgroundColor,
super(new BoxDecoration(backgroundColor: backgroundColor));
super(new BoxDecoration(backgroundColor: backgroundColor)) {
}
BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) {
return new BoxDimensions.withConstraints(constraints,
height: desiredHeight,
width: desiredWidth);
width: desiredSize.width,
height: desiredSize.height);
}
void performLayout() {
width = constraints.constrainWidth(desiredWidth);
height = constraints.constrainHeight(desiredHeight);
size = constraints.constrain(desiredSize);
}
void handlePointer(PointerEvent event) {
......@@ -43,7 +41,7 @@ void main() {
decoration: new BoxDecoration(backgroundColor: 0xFF000000));
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);
child.parentData.flex = flex;
}
......@@ -52,13 +50,13 @@ void main() {
addFlexChild(root, 0xFFFFFF00, flex: 1);
// 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
var renderBlock = new RenderBlock(decoration: new BoxDecoration(backgroundColor: 0xFFFFFFFF));
renderBlock.add(new RenderSolidColor(0xFF00FF00, desiredHeight: 50.0, desiredWidth: 100.0));
renderBlock.add(new RenderSolidColor(0x7700FFFF, desiredHeight: 100.0, desiredWidth: 50.0));
renderBlock.add(new RenderSolidColor(0xFF00FF00, desiredSize: new Size(100.0, 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));
......
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