mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
This CL splits getIntrinsicDimensions into getMinIntrinsicWidth, getMaxIntrinsicWidth, getMinIntrinsicHeight, and getMaxIntrinsicHeight so that we can properly shrink-wrap the stocks app menu. This CL just contains the refactoring. The use in stocks app will come in a later CL. R=ianh@google.com Review URL: https://codereview.chromium.org/1167293003
102 lines
3.4 KiB
Dart
102 lines
3.4 KiB
Dart
// Copyright 2015 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'box.dart';
|
|
import 'object.dart';
|
|
|
|
class BlockParentData extends BoxParentData with ContainerParentDataMixin<RenderBox> { }
|
|
|
|
class RenderBlock extends RenderBox with ContainerRenderObjectMixin<RenderBox, BlockParentData>,
|
|
RenderBoxContainerDefaultsMixin<RenderBox, BlockParentData> {
|
|
// lays out RenderBox children in a vertical stack
|
|
// uses the maximum width provided by the parent
|
|
// sizes itself to the height of its child stack
|
|
|
|
RenderBlock({
|
|
List<RenderBox> children
|
|
}) {
|
|
if (children != null)
|
|
children.forEach((child) { add(child); });
|
|
}
|
|
|
|
void setParentData(RenderBox child) {
|
|
if (child.parentData is! BlockParentData)
|
|
child.parentData = new BlockParentData();
|
|
}
|
|
|
|
double getMinIntrinsicWidth(BoxConstraints constraints) {
|
|
double width = 0.0;
|
|
BoxConstraints innerConstraints = new BoxConstraints(
|
|
minWidth: constraints.minWidth, maxWidth: constraints.maxWidth);
|
|
RenderBox child = firstChild;
|
|
while (child != null) {
|
|
width = math.max(width, child.getMinIntrinsicWidth(innerConstraints));
|
|
child = child.parentData.nextSibling;
|
|
}
|
|
return width;
|
|
}
|
|
|
|
double getMaxIntrinsicWidth(BoxConstraints constraints) {
|
|
double width = 0.0;
|
|
BoxConstraints innerConstraints = new BoxConstraints(
|
|
minWidth: constraints.minWidth, maxWidth: constraints.maxWidth);
|
|
RenderBox child = firstChild;
|
|
while (child != null) {
|
|
width = math.max(width, child.getMaxIntrinsicWidth(innerConstraints));
|
|
child = child.parentData.nextSibling;
|
|
}
|
|
return width;
|
|
}
|
|
|
|
double _getIntrinsicHeight(BoxConstraints constraints) {
|
|
double height = 0.0;
|
|
double width = constraints.constrainWidth(constraints.maxWidth);
|
|
BoxConstraints innerConstraints = new BoxConstraints(minWidth: width,
|
|
maxWidth: width);
|
|
RenderBox child = firstChild;
|
|
while (child != null) {
|
|
double childHeight = child.getMinIntrinsicHeight(innerConstraints);
|
|
assert(childHeight == child.getMaxIntrinsicHeight(innerConstraints));
|
|
height += childHeight;
|
|
child = child.parentData.nextSibling;
|
|
}
|
|
return height;
|
|
}
|
|
|
|
double getMinIntrinsicHeight(BoxConstraints constraints) {
|
|
return _getIntrinsicHeight(constraints);
|
|
}
|
|
|
|
double getMaxIntrinsicHeight(BoxConstraints constraints) {
|
|
return _getIntrinsicHeight(constraints);
|
|
}
|
|
|
|
void performLayout() {
|
|
assert(constraints is BoxConstraints);
|
|
double width = constraints.constrainWidth(constraints.maxWidth);
|
|
double y = 0.0;
|
|
RenderBox child = firstChild;
|
|
while (child != null) {
|
|
child.layout(new BoxConstraints(minWidth: width, maxWidth: width), parentUsesSize: true);
|
|
assert(child.parentData is BlockParentData);
|
|
child.parentData.position = new Point(0.0, y);
|
|
y += child.size.height;
|
|
child = child.parentData.nextSibling;
|
|
}
|
|
size = new Size(width, constraints.constrainHeight(y));
|
|
assert(size.width < double.INFINITY);
|
|
assert(size.height < double.INFINITY);
|
|
}
|
|
|
|
void hitTestChildren(HitTestResult result, { Point position }) {
|
|
defaultHitTestChildren(result, position: position);
|
|
}
|
|
|
|
void paint(RenderObjectDisplayList canvas) {
|
|
defaultPaint(canvas);
|
|
}
|
|
|
|
}
|
|
|