Merge pull request #1402 from Hixie/overflow
Change OverflowBox API to allow min and max values
This commit is contained in:
commit
1203b08b73
@ -230,20 +230,26 @@ class SizedBox extends OneChildRenderObjectWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class OverflowBox extends OneChildRenderObjectWidget {
|
class OverflowBox extends OneChildRenderObjectWidget {
|
||||||
OverflowBox({ Key key, this.width, this.height, Widget child })
|
OverflowBox({ Key key, this.minWidth, this.maxWidth, this.minHeight, this.maxHeight, Widget child })
|
||||||
: super(key: key, child: child);
|
: super(key: key, child: child);
|
||||||
|
|
||||||
final double width;
|
final double minWidth;
|
||||||
final double height;
|
final double maxWidth;
|
||||||
|
final double minHeight;
|
||||||
|
final double maxHeight;
|
||||||
|
|
||||||
RenderOverflowBox createRenderObject() => new RenderOverflowBox(
|
RenderOverflowBox createRenderObject() => new RenderOverflowBox(
|
||||||
innerWidth: width,
|
minWidth: minWidth,
|
||||||
innerHeight: height
|
maxWidth: maxWidth,
|
||||||
|
minHeight: minHeight,
|
||||||
|
maxHeight: maxHeight
|
||||||
);
|
);
|
||||||
|
|
||||||
void updateRenderObject(RenderOverflowBox renderObject, OverflowBox oldWidget) {
|
void updateRenderObject(RenderOverflowBox renderObject, OverflowBox oldWidget) {
|
||||||
renderObject.innerWidth = width;
|
renderObject.minWidth = minWidth;
|
||||||
renderObject.innerHeight = height;
|
renderObject.maxWidth = maxWidth;
|
||||||
|
renderObject.minHeight = minHeight;
|
||||||
|
renderObject.maxHeight = maxHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +90,8 @@ class SnackBarState extends AnimatedState<SnackBar> {
|
|||||||
),
|
),
|
||||||
child: new ClipRect(
|
child: new ClipRect(
|
||||||
child: new OverflowBox(
|
child: new OverflowBox(
|
||||||
height: kSnackHeight,
|
minHeight: kSnackHeight,
|
||||||
|
maxHeight: kSnackHeight,
|
||||||
child: new Material(
|
child: new Material(
|
||||||
level: 2,
|
level: 2,
|
||||||
color: kSnackBackground,
|
color: kSnackBackground,
|
||||||
|
@ -150,57 +150,81 @@ class RenderConstrainedBox extends RenderProxyBox {
|
|||||||
///
|
///
|
||||||
/// A render overflow box proxies most functions in the render box protocol to
|
/// A render overflow box proxies most functions in the render box protocol to
|
||||||
/// its child, except that when laying out its child, it passes constraints
|
/// its child, except that when laying out its child, it passes constraints
|
||||||
/// based on the innerWidth and innerHeight fields instead of just passing the
|
/// based on the minWidth, maxWidth, minHeight, and maxHeight fields instead of
|
||||||
/// parent's constraints in. It then sizes itself based on the parent's
|
/// just passing the parent's constraints in. Specifically, it overrides any of
|
||||||
/// constraints' maxWidth and maxHeight, ignoring the child's dimensions.
|
/// the equivalent fields on the constraints given by the parent with the
|
||||||
|
/// constraints given by these fields for each such field that is not null. It
|
||||||
|
/// then sizes itself based on the parent's constraints' maxWidth and maxHeight,
|
||||||
|
/// ignoring the child's dimensions.
|
||||||
///
|
///
|
||||||
/// For example, if you wanted a box to always render 50x50, regardless of where
|
/// For example, if you wanted a box to always render 50 pixels high, regardless
|
||||||
/// it was rendered, you would wrap it in a RenderOverflow with innerWidth and
|
/// of where it was rendered, you would wrap it in a RenderOverflow with
|
||||||
/// innerHeight members set to 50.0. Generally speaking, to avoid confusing
|
/// minHeight and maxHeight set to 50.0. Generally speaking, to avoid confusing
|
||||||
/// behaviour around hit testing, a RenderOverflowBox should usually be wrapped
|
/// behaviour around hit testing, a RenderOverflowBox should usually be wrapped
|
||||||
/// in a RenderClipRect.
|
/// in a RenderClipRect.
|
||||||
///
|
///
|
||||||
/// The child is positioned at the top left of the box. To position a smaller
|
/// The child is positioned at the top left of the box. To position a smaller
|
||||||
/// child inside a larger parent, use [RenderPositionedBox] and
|
/// child inside a larger parent, use [RenderPositionedBox] and
|
||||||
/// [RenderConstrainedBox] rather than RenderOverflowBox.
|
/// [RenderConstrainedBox] rather than RenderOverflowBox.
|
||||||
///
|
|
||||||
/// If you pass null for innerWidth or innerHeight, the constraints from the
|
|
||||||
/// parent are passed instead.
|
|
||||||
class RenderOverflowBox extends RenderProxyBox {
|
class RenderOverflowBox extends RenderProxyBox {
|
||||||
RenderOverflowBox({
|
RenderOverflowBox({
|
||||||
RenderBox child,
|
RenderBox child,
|
||||||
double innerWidth,
|
double minWidth,
|
||||||
double innerHeight
|
double maxWidth,
|
||||||
}) : _innerWidth = innerWidth, _innerHeight = innerHeight, super(child);
|
double minHeight,
|
||||||
|
double maxHeight
|
||||||
|
}) : _minWidth = minWidth, _maxWidth = maxWidth, _minHeight = minHeight, _maxHeight = maxHeight, super(child);
|
||||||
|
|
||||||
/// The tight width constraint to give the child. Set this to null (the
|
/// The minimum width constraint to give the child. Set this to null (the
|
||||||
/// default) to use the constraints from the parent instead.
|
/// default) to use the constraint from the parent instead.
|
||||||
double get innerWidth => _innerWidth;
|
double get minWidth => _minWidth;
|
||||||
double _innerWidth;
|
double _minWidth;
|
||||||
void set innerWidth (double value) {
|
void set minWidth (double value) {
|
||||||
if (_innerWidth == value)
|
if (_minWidth == value)
|
||||||
return;
|
return;
|
||||||
_innerWidth = value;
|
_minWidth = value;
|
||||||
markNeedsLayout();
|
markNeedsLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The tight height constraint to give the child. Set this to null (the
|
/// The maximum width constraint to give the child. Set this to null (the
|
||||||
/// default) to use the constraints from the parent instead.
|
/// default) to use the constraint from the parent instead.
|
||||||
double get innerHeight => _innerHeight;
|
double get maxWidth => _maxWidth;
|
||||||
double _innerHeight;
|
double _maxWidth;
|
||||||
void set innerHeight (double value) {
|
void set maxWidth (double value) {
|
||||||
if (_innerHeight == value)
|
if (_maxWidth == value)
|
||||||
return;
|
return;
|
||||||
_innerHeight = value;
|
_maxWidth = value;
|
||||||
|
markNeedsLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The minimum height constraint to give the child. Set this to null (the
|
||||||
|
/// default) to use the constraint from the parent instead.
|
||||||
|
double get minHeight => _minHeight;
|
||||||
|
double _minHeight;
|
||||||
|
void set minHeight (double value) {
|
||||||
|
if (_minHeight == value)
|
||||||
|
return;
|
||||||
|
_minHeight = value;
|
||||||
|
markNeedsLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The maximum height constraint to give the child. Set this to null (the
|
||||||
|
/// default) to use the constraint from the parent instead.
|
||||||
|
double get maxHeight => _maxHeight;
|
||||||
|
double _maxHeight;
|
||||||
|
void set maxHeight (double value) {
|
||||||
|
if (_maxHeight == value)
|
||||||
|
return;
|
||||||
|
_maxHeight = value;
|
||||||
markNeedsLayout();
|
markNeedsLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
BoxConstraints childConstraints(BoxConstraints constraints) {
|
BoxConstraints childConstraints(BoxConstraints constraints) {
|
||||||
return new BoxConstraints(
|
return new BoxConstraints(
|
||||||
minWidth: _innerWidth ?? constraints.minWidth,
|
minWidth: _minWidth ?? constraints.minWidth,
|
||||||
maxWidth: _innerWidth ?? constraints.maxWidth,
|
maxWidth: _maxWidth ?? constraints.maxWidth,
|
||||||
minHeight: _innerHeight ?? constraints.minHeight,
|
minHeight: _minHeight ?? constraints.minHeight,
|
||||||
maxHeight: _innerHeight ?? constraints.maxHeight
|
maxHeight: _maxHeight ?? constraints.maxHeight
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,8 +257,10 @@ class RenderOverflowBox extends RenderProxyBox {
|
|||||||
|
|
||||||
String debugDescribeSettings(String prefix) {
|
String debugDescribeSettings(String prefix) {
|
||||||
return '${super.debugDescribeSettings(prefix)}' +
|
return '${super.debugDescribeSettings(prefix)}' +
|
||||||
'${prefix}innerWidth: ${innerWidth ?? "use parent width constraints"}\n' +
|
'${prefix}minWidth: ${minWidth ?? "use parent minWidth constraint"}\n' +
|
||||||
'${prefix}innerHeight: ${innerHeight ?? "use parent height constraints"}\n';
|
'${prefix}maxWidth: ${maxWidth ?? "use parent maxWidth constraint"}\n' +
|
||||||
|
'${prefix}minHeight: ${minHeight ?? "use parent minHeight constraint"}\n' +
|
||||||
|
'${prefix}maxHeight: ${maxHeight ?? "use parent maxHeight constraint"}\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user