提交 c0d90041 编写于 作者: A Adam Barth

Add |constraints| to Container for PopupMenuItem

This CL is the first step towards getting PopupMenuItem working in fn2. We
introduce the ability to add a minWidth to a Container by creating a
RenderConstrainedBox class to apply the new constraints.

R=ianh@google.com

Review URL: https://codereview.chromium.org/1155683011
上级 5703762f
......@@ -6,21 +6,17 @@ import '../fn2.dart';
import 'ink_well.dart';
class PopupMenuItem extends Component {
static final Style _style = new Style('''
min-width: 112px;
padding: 16px;''');
List<UINode> children;
double opacity;
PopupMenuItem({ Object key, this.children, this.opacity}) : super(key: key);
UINode build() {
return new StyleNode(
new InkWell(
inlineStyle: opacity == null ? null : 'opacity: ${opacity}',
children: children
),
_style);
return new Container(
constraints: const BoxConstraints(minWidth: 112.0),
padding: const EdgeDims.all(16.0),
// TODO(abarth): opacity: opacity,
child: new InkWell(children: children)
);
}
}
......@@ -18,7 +18,7 @@ import 'rendering/object.dart';
import 'rendering/paragraph.dart';
import 'rendering/stack.dart';
export 'rendering/object.dart' show Point, Size, Rect, Color, Paint, Path;
export 'rendering/box.dart' show BoxDecoration, Border, BorderSide, EdgeDims;
export 'rendering/box.dart' show BoxConstraints, BoxDecoration, Border, BorderSide, EdgeDims;
export 'rendering/flex.dart' show FlexDirection;
// final sky.Tracing _tracing = sky.window.tracing;
......@@ -421,6 +421,21 @@ class SizedBox extends OneChildRenderObjectWrapper {
}
}
class ConstrainedBox extends OneChildRenderObjectWrapper {
RenderConstrainedBox root;
final BoxConstraints constraints;
ConstrainedBox({ this.constraints, UINode child, Object key })
: super(child: child, key: key);
RenderConstrainedBox createNode() => new RenderConstrainedBox(additionalConstraints: constraints);
void syncRenderObject(ConstrainedBox old) {
super.syncRenderObject(old);
root.additionalConstraints = constraints;
}
}
class Transform extends OneChildRenderObjectWrapper {
RenderTransform root;
final Matrix4 transform;
......@@ -935,20 +950,22 @@ abstract class Component extends UINode {
class Container extends Component {
final UINode child;
final Matrix4 transform;
final EdgeDims margin;
final BoxConstraints constraints;
final BoxDecoration decoration;
final Size desiredSize;
final EdgeDims margin;
final EdgeDims padding;
final Matrix4 transform;
final Size desiredSize;
Container({
Object key,
this.child,
this.transform,
this.margin,
this.constraints,
this.decoration,
this.desiredSize,
this.padding
this.margin,
this.padding,
this.transform
}) : super(key: key);
UINode build() {
......@@ -963,6 +980,9 @@ class Container extends Component {
if (desiredSize != null)
current = new SizedBox(desiredSize: desiredSize, child: current);
if (constraints != null)
current = new ConstrainedBox(constraints: constraints);
if (margin != null)
current = new Padding(padding: margin, child: current);
......
......@@ -77,6 +77,14 @@ class BoxConstraints {
);
}
BoxConstraints apply(BoxConstraints constraints) {
return new BoxConstraints(
minWidth: math.max(minWidth, constraints.minWidth),
maxWidth: math.min(maxWidth, constraints.maxWidth),
minHeight: math.max(minHeight, constraints.minHeight),
maxHeight: math.min(maxHeight, constraints.maxHeight));
}
final double minWidth;
final double maxWidth;
final double minHeight;
......@@ -192,9 +200,8 @@ class RenderSizedBox extends RenderProxyBox {
RenderSizedBox({
RenderBox child,
Size desiredSize: Size.infinite
}) : super(child) {
}) : super(child), _desiredSize = desiredSize {
assert(desiredSize != null);
this.desiredSize = desiredSize;
}
Size _desiredSize;
......@@ -220,6 +227,42 @@ class RenderSizedBox extends RenderProxyBox {
String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}desiredSize: ${desiredSize}\n';
}
class RenderConstrainedBox extends RenderProxyBox {
RenderConstrainedBox({
RenderBox child,
BoxConstraints additionalConstraints
}) : super(child), _additionalConstraints = additionalConstraints {
assert(additionalConstraints != null);
}
BoxConstraints _additionalConstraints;
BoxConstraints get additionalConstraints => _additionalConstraints;
void set additionalConstraints (BoxConstraints value) {
assert(value != null);
if (_additionalConstraints == value)
return;
_additionalConstraints = value;
markNeedsLayout();
}
Size getIntrinsicDimensions(BoxConstraints constraints) {
if (child == null)
return constraints.constrain(Size.zero);
return child.getIntrinsicDimensions(constraints.apply(_additionalConstraints));
}
void performLayout() {
if (child != null) {
child.layout(constraints.apply(_additionalConstraints));
size = child.size;
} else {
performResize();
}
}
String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}additionalConstraints: ${additionalConstraints}\n';
}
class RenderClip extends RenderProxyBox {
RenderClip({ RenderBox child }) : super(child);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册