From 12439e5ccff80d8f500067454690e2f1e8dfd128 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Thu, 21 May 2015 13:32:21 -0700 Subject: [PATCH] Address Ian's comments on layout2.dart R=ianh@google.com Review URL: https://codereview.chromium.org/1152603002 --- examples/raw/simple_render_tree.dart | 7 +-- sdk/lib/framework/layout2.dart | 65 +++++++++++++--------------- 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/examples/raw/simple_render_tree.dart b/examples/raw/simple_render_tree.dart index 205043523b3..a9e559b0ac4 100644 --- a/examples/raw/simple_render_tree.dart +++ b/examples/raw/simple_render_tree.dart @@ -18,8 +18,8 @@ class RenderSolidColor extends RenderDecoratedBox { } void layout(BoxConstraints constraints, { RenderNode relayoutSubtreeRoot }) { - setWidth(constraints, constraints.maxWidth); - setHeight(constraints, 200.0); + width = constraints.constrainWidth(constraints.maxWidth); + height = constraints.constrainHeight(200.0); layoutDone(); } @@ -57,7 +57,8 @@ void main() { view.setBeginFrameCallback(beginFrame); var root = new RenderBlock( - decoration: new BoxDecoration(backgroundColor: 0xFF00FFFF)); + decoration: new BoxDecoration(backgroundColor: 0xFF00FFFF), + padding: const EdgeDims(10.0, 10.0, 10.0, 10.0)); root.add(new RenderSolidColor(0xFF00FF00)); root.add(new RenderSolidColor(0xFF0000FF)); diff --git a/sdk/lib/framework/layout2.dart b/sdk/lib/framework/layout2.dart index 75ff4e6878d..0284dc845ac 100644 --- a/sdk/lib/framework/layout2.dart +++ b/sdk/lib/framework/layout2.dart @@ -401,10 +401,24 @@ class BoxConstraints { this.minHeight: 0.0, this.maxHeight: double.INFINITY}); + const BoxConstraints.tight({ width: width, height: height }) + : minWidth = width, + maxWidth = width, + minHeight = height, + maxHeight = height; + final double minWidth; final double maxWidth; final double minHeight; final double maxHeight; + + double constrainWidth(double width) { + return clamp(min: minWidth, max: maxWidth, value: width); + } + + double constrainHeight(double height) { + return clamp(min: minHeight, max: maxHeight, value: height); + } } class BoxDimensions { @@ -412,8 +426,8 @@ class BoxDimensions { BoxDimensions.withConstraints( BoxConstraints constraints, {double width: 0.0, double height: 0.0}) { - this.width = clamp(min: minWidth, max: maxWidth, value: width); - this.height = clamp(min: minHeight, max: maxHeight, value: height); + this.width = constraints.constrainWidth(width); + this.height = constraints.constrainHeight(height); } final double width; @@ -442,29 +456,17 @@ abstract class RenderBox extends RenderNode { } void layout(BoxConstraints constraints, { RenderNode relayoutSubtreeRoot }) { - setWidth(constraints, 0.0); - setHeight(constraints, 0.0); + width = constraints.constrainWidth(0.0); + height = constraints.constrainHeight(0.0); layoutDone(); } double width; double height; - - void setWidth(BoxConstraints constraints, double newWidth) { - width = clamp(min: constraints.minWidth, - max: constraints.maxWidth, - value: newWidth); - } - - void setHeight(BoxConstraints constraints, double newHeight) { - height = clamp(min: constraints.minHeight, - max: constraints.maxHeight, - value: newHeight); - } } class BoxDecoration { - BoxDecoration({ + const BoxDecoration({ this.backgroundColor }); @@ -628,9 +630,8 @@ class RenderBlock extends RenderDecoratedBox with ContainerRenderNodeMixin