Unverified Commit 57dd51a3 authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Fix documentation for UnconstrainedBox and code cleanup (#17249)

parent 916ed6c4
...@@ -484,7 +484,6 @@ class RenderPositionedBox extends RenderAligningShiftedBox { ...@@ -484,7 +484,6 @@ class RenderPositionedBox extends RenderAligningShiftedBox {
/// * [RenderSizedOverflowBox], a render object that is a specific size but /// * [RenderSizedOverflowBox], a render object that is a specific size but
/// passes its original constraints through to its child, which it allows to /// passes its original constraints through to its child, which it allows to
/// overflow. /// overflow.
class RenderConstrainedOverflowBox extends RenderAligningShiftedBox { class RenderConstrainedOverflowBox extends RenderAligningShiftedBox {
/// Creates a render object that lets its child overflow itself. /// Creates a render object that lets its child overflow itself.
RenderConstrainedOverflowBox({ RenderConstrainedOverflowBox({
...@@ -584,10 +583,11 @@ class RenderConstrainedOverflowBox extends RenderAligningShiftedBox { ...@@ -584,10 +583,11 @@ class RenderConstrainedOverflowBox extends RenderAligningShiftedBox {
/// render at its "natural" size. /// render at its "natural" size.
/// ///
/// This allows a child to render at the size it would render if it were alone /// This allows a child to render at the size it would render if it were alone
/// on an infinite canvas with no constraints. This box will then expand /// on an infinite canvas with no constraints. This box will then attempt to
/// as much as it can within its own constraints and align the child based on /// adopt the same size, within the limits of its own constraints. If it ends
/// [alignment]. If the box cannot expand enough to accommodate the entire /// up with a different size, it will align the child based on [alignment].
/// child, the child will be clipped. /// If the box cannot expand enough to accommodate the entire child, the
/// child will be clipped.
/// ///
/// In debug mode, if the child overflows the box, a warning will be printed on /// In debug mode, if the child overflows the box, a warning will be printed on
/// the console, and black and yellow striped areas will appear where the /// the console, and black and yellow striped areas will appear where the
...@@ -595,9 +595,9 @@ class RenderConstrainedOverflowBox extends RenderAligningShiftedBox { ...@@ -595,9 +595,9 @@ class RenderConstrainedOverflowBox extends RenderAligningShiftedBox {
/// ///
/// See also: /// See also:
/// ///
/// * [RenderConstrainedBox] renders a box which imposes constraints on its /// * [RenderConstrainedBox], which renders a box which imposes constraints
/// child. /// on its child.
/// * [RenderConstrainedOverflowBox], renders a box that imposes different /// * [RenderConstrainedOverflowBox], which renders a box that imposes different
/// constraints on its child than it gets from its parent, possibly allowing /// constraints on its child than it gets from its parent, possibly allowing
/// the child to overflow the parent. /// the child to overflow the parent.
/// * [RenderSizedOverflowBox], a render object that is a specific size but /// * [RenderSizedOverflowBox], a render object that is a specific size but
...@@ -641,40 +641,31 @@ class RenderUnconstrainedBox extends RenderAligningShiftedBox with DebugOverflow ...@@ -641,40 +641,31 @@ class RenderUnconstrainedBox extends RenderAligningShiftedBox with DebugOverflow
if (child != null) { if (child != null) {
// Let the child lay itself out at it's "natural" size, but if // Let the child lay itself out at it's "natural" size, but if
// constrainedAxis is non-null, keep any constraints on that axis. // constrainedAxis is non-null, keep any constraints on that axis.
BoxConstraints childConstraints;
if (constrainedAxis != null) { if (constrainedAxis != null) {
switch (constrainedAxis) { switch (constrainedAxis) {
case Axis.horizontal: case Axis.horizontal:
child.layout(new BoxConstraints( childConstraints = new BoxConstraints(maxWidth: constraints.maxWidth, minWidth: constraints.minWidth);
maxWidth: constraints.maxWidth, minWidth: constraints.minWidth),
parentUsesSize: true,
);
break; break;
case Axis.vertical: case Axis.vertical:
child.layout(new BoxConstraints( childConstraints = new BoxConstraints(maxHeight: constraints.maxHeight, minHeight: constraints.minHeight);
maxHeight: constraints.maxHeight, minHeight: constraints.minHeight),
parentUsesSize: true,
);
break; break;
} }
} else { } else {
child.layout(const BoxConstraints(), parentUsesSize: true); childConstraints = const BoxConstraints();
} }
child.layout(childConstraints, parentUsesSize: true);
size = constraints.constrain(child.size); size = constraints.constrain(child.size);
alignChild(); alignChild();
final BoxParentData childParentData = child.parentData; final BoxParentData childParentData = child.parentData;
_overflowContainerRect = Offset.zero & size; _overflowContainerRect = Offset.zero & size;
_overflowChildRect = childParentData.offset & child.size; _overflowChildRect = childParentData.offset & child.size;
} else { } else {
size = constraints.constrain(Size.zero); size = constraints.smallest;
_overflowContainerRect = Rect.zero; _overflowContainerRect = Rect.zero;
_overflowChildRect = Rect.zero; _overflowChildRect = Rect.zero;
} }
_isOverflowing = new RelativeRect.fromRect(_overflowContainerRect, _overflowChildRect).hasInsets;
final RelativeRect overflow = new RelativeRect.fromRect(_overflowContainerRect, _overflowChildRect);
_isOverflowing = overflow.left > 0.0 ||
overflow.right > 0.0 ||
overflow.top > 0.0 ||
overflow.bottom > 0.0;
} }
@override @override
......
...@@ -77,6 +77,12 @@ class RelativeRect { ...@@ -77,6 +77,12 @@ class RelativeRect {
/// May be negative if the bottom side of the rectangle is outside of the container. /// May be negative if the bottom side of the rectangle is outside of the container.
final double bottom; final double bottom;
/// Returns whether any of the values are greater than zero.
///
/// This corresponds to one of the sides ([left], [top], [right], or [bottom]) having
/// some positive inset towards the center.
bool get hasInsets => left > 0.0 || top > 0.0 || right > 0.0 || bottom > 0.0;
/// Returns a new rectangle object translated by the given offset. /// Returns a new rectangle object translated by the given offset.
RelativeRect shift(Offset offset) { RelativeRect shift(Offset offset) {
return new RelativeRect.fromLTRB(left + offset.dx, top + offset.dy, right - offset.dx, bottom - offset.dy); return new RelativeRect.fromLTRB(left + offset.dx, top + offset.dy, right - offset.dx, bottom - offset.dy);
......
...@@ -1775,10 +1775,11 @@ class ConstrainedBox extends SingleChildRenderObjectWidget { ...@@ -1775,10 +1775,11 @@ class ConstrainedBox extends SingleChildRenderObjectWidget {
/// at its "natural" size. /// at its "natural" size.
/// ///
/// This allows a child to render at the size it would render if it were alone /// This allows a child to render at the size it would render if it were alone
/// on an infinite canvas with no constraints. This container will then expand /// on an infinite canvas with no constraints. This container will then attempt
/// as much as it can within its own constraints and align the child based on /// to adopt the same size, within the limits of its own constraints. If it ends
/// [alignment]. If the container cannot expand enough to accommodate the /// up with a different size, it will align the child based on [alignment].
/// entire child, the child will be clipped. /// If the box cannot expand enough to accommodate the entire child, the
/// child will be clipped.
/// ///
/// In debug mode, if the child overflows the container, a warning will be /// In debug mode, if the child overflows the container, a warning will be
/// printed on the console, and black and yellow striped areas will appear where /// printed on the console, and black and yellow striped areas will appear where
...@@ -1786,7 +1787,9 @@ class ConstrainedBox extends SingleChildRenderObjectWidget { ...@@ -1786,7 +1787,9 @@ class ConstrainedBox extends SingleChildRenderObjectWidget {
/// ///
/// See also: /// See also:
/// ///
/// * [ConstrainedBox] for a box which imposes constraints on its child. /// * [ConstrainedBox], for a box which imposes constraints on its child.
/// * [Align], which loosens the constraints given to the child rather than
/// removing them entirely.
/// * [Container], a convenience widget that combines common painting, /// * [Container], a convenience widget that combines common painting,
/// positioning, and sizing widgets. /// positioning, and sizing widgets.
/// * [OverflowBox], a widget that imposes different constraints on its child /// * [OverflowBox], a widget that imposes different constraints on its child
......
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