Unverified Commit 3f0024e1 authored by Mjk's avatar Mjk Committed by GitHub

Fix compute intrinsic size for wrap (#55469)

parent 3a67a8bb
...@@ -54,3 +54,4 @@ Cédric Wyss <cedi.wyss@gmail.com> ...@@ -54,3 +54,4 @@ Cédric Wyss <cedi.wyss@gmail.com>
Michel Feinstein <michel@feinstein.com.br> Michel Feinstein <michel@feinstein.com.br>
Michael Lee <ckmichael8@gmail.com> Michael Lee <ckmichael8@gmail.com>
Katarina Sheremet <katarina@sheremet.ch> Katarina Sheremet <katarina@sheremet.ch>
Mikhail Zotyev <mbixjkee1392@gmail.com>
...@@ -383,7 +383,6 @@ class RenderWrap extends RenderBox with ContainerRenderObjectMixin<RenderBox, Wr ...@@ -383,7 +383,6 @@ class RenderWrap extends RenderBox with ContainerRenderObjectMixin<RenderBox, Wr
double _computeIntrinsicHeightForWidth(double width) { double _computeIntrinsicHeightForWidth(double width) {
assert(direction == Axis.horizontal); assert(direction == Axis.horizontal);
int runCount = 0;
double height = 0.0; double height = 0.0;
double runWidth = 0.0; double runWidth = 0.0;
double runHeight = 0.0; double runHeight = 0.0;
...@@ -392,11 +391,9 @@ class RenderWrap extends RenderBox with ContainerRenderObjectMixin<RenderBox, Wr ...@@ -392,11 +391,9 @@ class RenderWrap extends RenderBox with ContainerRenderObjectMixin<RenderBox, Wr
while (child != null) { while (child != null) {
final double childWidth = child.getMaxIntrinsicWidth(double.infinity); final double childWidth = child.getMaxIntrinsicWidth(double.infinity);
final double childHeight = child.getMaxIntrinsicHeight(childWidth); final double childHeight = child.getMaxIntrinsicHeight(childWidth);
if (runWidth + childWidth > width) { // There must be at least one child before we move on to the next run.
height += runHeight; if (childCount > 0 && runWidth + childWidth + spacing > width) {
if (runCount > 0) height += runHeight + runSpacing;
height += runSpacing;
runCount += 1;
runWidth = 0.0; runWidth = 0.0;
runHeight = 0.0; runHeight = 0.0;
childCount = 0; childCount = 0;
...@@ -408,14 +405,12 @@ class RenderWrap extends RenderBox with ContainerRenderObjectMixin<RenderBox, Wr ...@@ -408,14 +405,12 @@ class RenderWrap extends RenderBox with ContainerRenderObjectMixin<RenderBox, Wr
childCount += 1; childCount += 1;
child = childAfter(child); child = childAfter(child);
} }
if (childCount > 0) height += runHeight;
height += runHeight + runSpacing;
return height; return height;
} }
double _computeIntrinsicWidthForHeight(double height) { double _computeIntrinsicWidthForHeight(double height) {
assert(direction == Axis.vertical); assert(direction == Axis.vertical);
int runCount = 0;
double width = 0.0; double width = 0.0;
double runHeight = 0.0; double runHeight = 0.0;
double runWidth = 0.0; double runWidth = 0.0;
...@@ -424,11 +419,9 @@ class RenderWrap extends RenderBox with ContainerRenderObjectMixin<RenderBox, Wr ...@@ -424,11 +419,9 @@ class RenderWrap extends RenderBox with ContainerRenderObjectMixin<RenderBox, Wr
while (child != null) { while (child != null) {
final double childHeight = child.getMaxIntrinsicHeight(double.infinity); final double childHeight = child.getMaxIntrinsicHeight(double.infinity);
final double childWidth = child.getMaxIntrinsicWidth(childHeight); final double childWidth = child.getMaxIntrinsicWidth(childHeight);
if (runHeight + childHeight > height) { // There must be at least one child before we move on to the next run.
width += runWidth; if (childCount > 0 && runHeight + childHeight + spacing > height) {
if (runCount > 0) width += runWidth + runSpacing;
width += runSpacing;
runCount += 1;
runHeight = 0.0; runHeight = 0.0;
runWidth = 0.0; runWidth = 0.0;
childCount = 0; childCount = 0;
...@@ -440,8 +433,7 @@ class RenderWrap extends RenderBox with ContainerRenderObjectMixin<RenderBox, Wr ...@@ -440,8 +433,7 @@ class RenderWrap extends RenderBox with ContainerRenderObjectMixin<RenderBox, Wr
childCount += 1; childCount += 1;
child = childAfter(child); child = childAfter(child);
} }
if (childCount > 0) width += runWidth;
width += runWidth + runSpacing;
return width; return width;
} }
......
...@@ -25,4 +25,130 @@ void main() { ...@@ -25,4 +25,130 @@ void main() {
), ),
); );
}); });
test('Compute intrinsic height test', () {
final List<RenderBox> children = <RenderBox>[
RenderConstrainedBox(
additionalConstraints: const BoxConstraints(
minWidth: 80,
minHeight: 80,
),
),
RenderConstrainedBox(
additionalConstraints: const BoxConstraints(
minWidth: 80,
minHeight: 80,
),
),
RenderConstrainedBox(
additionalConstraints: const BoxConstraints(
minWidth: 80,
minHeight: 80,
),
),
];
final RenderWrap renderWrap = RenderWrap();
children.forEach(renderWrap.add);
renderWrap.spacing = 5;
renderWrap.runSpacing = 5;
renderWrap.direction = Axis.horizontal;
expect(renderWrap.computeMaxIntrinsicHeight(245), 165);
expect(renderWrap.computeMaxIntrinsicHeight(250), 80);
expect(renderWrap.computeMaxIntrinsicHeight(80), 250);
expect(renderWrap.computeMaxIntrinsicHeight(79), 250);
expect(renderWrap.computeMinIntrinsicHeight(245), 165);
expect(renderWrap.computeMinIntrinsicHeight(250), 80);
expect(renderWrap.computeMinIntrinsicHeight(80), 250);
expect(renderWrap.computeMinIntrinsicHeight(79), 250);
});
test('Compute intrinsic width test', () {
final List<RenderBox> children = <RenderBox>[
RenderConstrainedBox(
additionalConstraints: const BoxConstraints(
minWidth: 80,
minHeight: 80,
),
),
RenderConstrainedBox(
additionalConstraints: const BoxConstraints(
minWidth: 80,
minHeight: 80,
),
),
RenderConstrainedBox(
additionalConstraints: const BoxConstraints(
minWidth: 80,
minHeight: 80,
),
),
];
final RenderWrap renderWrap = RenderWrap();
children.forEach(renderWrap.add);
renderWrap.spacing = 5;
renderWrap.runSpacing = 5;
renderWrap.direction = Axis.vertical;
expect(renderWrap.computeMaxIntrinsicWidth(245), 165);
expect(renderWrap.computeMaxIntrinsicWidth(250), 80);
expect(renderWrap.computeMaxIntrinsicWidth(80), 250);
expect(renderWrap.computeMaxIntrinsicWidth(79), 250);
expect(renderWrap.computeMinIntrinsicWidth(245), 165);
expect(renderWrap.computeMinIntrinsicWidth(250), 80);
expect(renderWrap.computeMinIntrinsicWidth(80), 250);
expect(renderWrap.computeMinIntrinsicWidth(79), 250);
});
test('Compute intrinsic height for only one run', () {
final RenderBox child = RenderConstrainedBox(
additionalConstraints: const BoxConstraints(
minWidth: 80,
minHeight: 80,
),
);
final RenderWrap renderWrap = RenderWrap();
renderWrap.add(child);
renderWrap.spacing = 5;
renderWrap.runSpacing = 5;
renderWrap.direction = Axis.horizontal;
expect(renderWrap.computeMaxIntrinsicHeight(100), 80);
expect(renderWrap.computeMaxIntrinsicHeight(79), 80);
expect(renderWrap.computeMaxIntrinsicHeight(80), 80);
expect(renderWrap.computeMinIntrinsicHeight(100), 80);
expect(renderWrap.computeMinIntrinsicHeight(79), 80);
expect(renderWrap.computeMinIntrinsicHeight(80), 80);
});
test('Compute intrinsic width for only one run', () {
final RenderBox child = RenderConstrainedBox(
additionalConstraints: const BoxConstraints(
minWidth: 80,
minHeight: 80,
),
);
final RenderWrap renderWrap = RenderWrap();
renderWrap.add(child);
renderWrap.spacing = 5;
renderWrap.runSpacing = 5;
renderWrap.direction = Axis.vertical;
expect(renderWrap.computeMaxIntrinsicWidth(100), 80);
expect(renderWrap.computeMaxIntrinsicWidth(79), 80);
expect(renderWrap.computeMaxIntrinsicWidth(80), 80);
expect(renderWrap.computeMinIntrinsicWidth(100), 80);
expect(renderWrap.computeMinIntrinsicWidth(79), 80);
expect(renderWrap.computeMinIntrinsicWidth(80), 80);
});
} }
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