Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1295)

Unified Diff: sky/sdk/lib/framework/rendering/stack.dart

Issue 1184483002: Teach stack to size to the max of its non-positioned children (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/sdk/lib/framework/rendering/box.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/sdk/lib/framework/rendering/stack.dart
diff --git a/sky/sdk/lib/framework/rendering/stack.dart b/sky/sdk/lib/framework/rendering/stack.dart
index c35020cf3f17596e1ea062b2abc9bb8df62f7cd5..53319ae7d315006fef7876550af577eb28d605f0 100644
--- a/sky/sdk/lib/framework/rendering/stack.dart
+++ b/sky/sdk/lib/framework/rendering/stack.dart
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+import 'dart:math' as math;
+
import 'box.dart';
import 'object.dart';
@@ -23,6 +25,8 @@ class StackParentData extends BoxParentData with ContainerParentDataMixin<Render
super.merge(other);
}
+ bool get isPositioned => top != null || right != null || bottom != null || left != null;
+
String toString() => '${super.toString()}; top=$top; right=$right; bottom=$bottom, left=$left';
}
@@ -40,68 +44,146 @@ class RenderStack extends RenderBox with ContainerRenderObjectMixin<RenderBox, S
child.parentData = new StackParentData();
}
+
double getMinIntrinsicWidth(BoxConstraints constraints) {
- return constraints.constrainWidth(double.INFINITY);
+ double width = constraints.minWidth;
+ RenderBox child = firstChild;
+ while (child != null) {
+ assert(child.parentData is StackParentData);
+ if (!child.parentData.isPositioned)
+ width = math.max(width, child.getMinIntrinsicWidth(constraints));
+ child = child.parentData.nextSibling;
+ }
+ assert(width == constraints.constrainWidth(width));
+ return width;
}
double getMaxIntrinsicWidth(BoxConstraints constraints) {
- return constraints.constrainWidth(double.INFINITY);
+ bool hasNonPositionedChildren = false;
+ double width = constraints.minWidth;
+ RenderBox child = firstChild;
+ while (child != null) {
+ assert(child.parentData is StackParentData);
+ if (!child.parentData.isPositioned) {
+ hasNonPositionedChildren = true;
+ width = math.max(width, child.getMaxIntrinsicWidth(constraints));
+ }
+ child = child.parentData.nextSibling;
+ }
+ if (!hasNonPositionedChildren)
+ return constraints.constrainWidth(double.INFINITY);
+ assert(width == constraints.constrainWidth(width));
+ return width;
}
double getMinIntrinsicHeight(BoxConstraints constraints) {
- return constraints.constrainHeight(double.INFINITY);
+ double height = constraints.minHeight;
+ RenderBox child = firstChild;
+ while (child != null) {
+ assert(child.parentData is StackParentData);
+ if (!child.parentData.isPositioned)
+ height = math.max(height, child.getMinIntrinsicHeight(constraints));
+ child = child.parentData.nextSibling;
+ }
+ assert(height == constraints.constrainHeight(height));
+ return height;
}
double getMaxIntrinsicHeight(BoxConstraints constraints) {
- return constraints.constrainHeight(double.INFINITY);
+ bool hasNonPositionedChildren = false;
+ double height = constraints.minHeight;
+ RenderBox child = firstChild;
+ while (child != null) {
+ assert(child.parentData is StackParentData);
+ if (!child.parentData.isPositioned) {
+ hasNonPositionedChildren = true;
+ height = math.max(height, child.getMaxIntrinsicHeight(constraints));
+ }
+ child = child.parentData.nextSibling;
+ }
+ if (!hasNonPositionedChildren)
+ return constraints.constrainHeight(double.INFINITY);
+ assert(height == constraints.constrainHeight(height));
+ return height;
}
void performLayout() {
- size = constraints.constrain(Size.infinite);
+ bool hasNonPositionedChildren = false;
+
+ double width = 0.0;
+ double height = 0.0;
+
+ RenderBox child = firstChild;
+ while (child != null) {
+ assert(child.parentData is StackParentData);
+ final StackParentData parentData = child.parentData;
+
+ if (!parentData.isPositioned) {
+ hasNonPositionedChildren = true;
+
+ child.layout(constraints, parentUsesSize: true);
+ parentData.position = Point.origin;
+
+ final Size childSize = child.size;
+ width = math.max(width, childSize.width);
+ height = math.max(height, childSize.height);
+ }
+
+ child = parentData.nextSibling;
+ }
+
+ if (hasNonPositionedChildren)
+ size = new Size(width, height);
+ else
+ size = constraints.constrain(Size.infinite);
+
assert(size.width < double.INFINITY);
assert(size.height < double.INFINITY);
+
BoxConstraints innerConstraints = new BoxConstraints.loose(size);
- RenderBox child = firstChild;
+ child = firstChild;
while (child != null) {
assert(child.parentData is StackParentData);
- StackParentData parentData = child.parentData;
-
- BoxConstraints childConstraints = innerConstraints;
-
- if (parentData.left != null && parentData.right != null)
- childConstraints = childConstraints.applyWidth(parentData.right - parentData.left);
- else if (parentData.left != null)
- childConstraints = childConstraints.applyMaxWidth(size.width - parentData.left);
- else if (parentData.right != null)
- childConstraints = childConstraints.applyMaxWidth(size.width - parentData.right);
-
- if (parentData.top != null && parentData.bottom != null)
- childConstraints = childConstraints.applyHeight(parentData.bottom - parentData.top);
- else if (parentData.top != null)
- childConstraints = childConstraints.applyMaxHeight(size.height - parentData.top);
- else if (parentData.bottom != null)
- childConstraints = childConstraints.applyMaxHeight(size.width - parentData.bottom);
-
- child.layout(childConstraints);
-
- double x = 0.0;
- if (parentData.left != null)
- x = parentData.left;
- else if (parentData.right != null)
- x = size.width - parentData.right - child.size.width;
- assert(x >= 0.0 && x + child.size.width <= size.width);
-
- double y = 0.0;
- if (parentData.top != null)
- y = parentData.top;
- else if (parentData.bottom != null)
- y = size.height - parentData.bottom - child.size.height;
- assert(y >= 0.0 && y + child.size.height <= size.height);
-
- parentData.position = new Point(x, y);
-
- child = child.parentData.nextSibling;
+ final StackParentData parentData = child.parentData;
+
+ if (parentData.isPositioned) {
+ BoxConstraints childConstraints = innerConstraints;
+
+ if (parentData.left != null && parentData.right != null)
+ childConstraints = childConstraints.applyWidth(parentData.right - parentData.left);
+ else if (parentData.left != null)
+ childConstraints = childConstraints.applyMaxWidth(size.width - parentData.left);
+ else if (parentData.right != null)
+ childConstraints = childConstraints.applyMaxWidth(size.width - parentData.right);
+
+ if (parentData.top != null && parentData.bottom != null)
+ childConstraints = childConstraints.applyHeight(parentData.bottom - parentData.top);
+ else if (parentData.top != null)
+ childConstraints = childConstraints.applyMaxHeight(size.height - parentData.top);
+ else if (parentData.bottom != null)
+ childConstraints = childConstraints.applyMaxHeight(size.width - parentData.bottom);
+
+ child.layout(childConstraints);
+
+ double x = 0.0;
+ if (parentData.left != null)
+ x = parentData.left;
+ else if (parentData.right != null)
+ x = size.width - parentData.right - child.size.width;
+ assert(x >= 0.0 && x + child.size.width <= size.width);
+
+ double y = 0.0;
+ if (parentData.top != null)
+ y = parentData.top;
+ else if (parentData.bottom != null)
+ y = size.height - parentData.bottom - child.size.height;
+ assert(y >= 0.0 && y + child.size.height <= size.height);
+
+ parentData.position = new Point(x, y);
+ }
+
+ child = parentData.nextSibling;
}
}
« no previous file with comments | « sky/sdk/lib/framework/rendering/box.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698