Skip to content

Commit

Permalink
RenderFlex baseline intrinsics (#145483)
Browse files Browse the repository at this point in the history
Implements `RenderFlex` intrinsics calculation when children are baseline aligned in the cross axis.
  • Loading branch information
LongCatIsLooong authored Mar 28, 2024
1 parent b36c16d commit 460a5e2
Show file tree
Hide file tree
Showing 8 changed files with 695 additions and 283 deletions.
26 changes: 15 additions & 11 deletions packages/flutter/lib/src/rendering/box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2046,7 +2046,9 @@ abstract class RenderBox extends RenderObject {
final double? baselineOffset = _computeIntrinsics(_CachedLayoutCalculation.baseline, (constraints, baseline), _computeDryBaseline).offset;
// This assert makes sure computeDryBaseline always gets called in debug mode,
// in case the computeDryBaseline implementation invokes debugCannotComputeDryLayout.
assert(baselineOffset == computeDryBaseline(constraints, baseline));
// This check should be skipped when debugCheckintIntrinsics is true to avoid
// slowing down the app significantly.
assert(RenderObject.debugCheckingIntrinsics || baselineOffset == computeDryBaseline(constraints, baseline));
return baselineOffset;
}

Expand Down Expand Up @@ -2508,18 +2510,20 @@ abstract class RenderBox extends RenderObject {
}
}

testIntrinsicsForValues(getMinIntrinsicWidth, getMaxIntrinsicWidth, 'Width', double.infinity);
testIntrinsicsForValues(getMinIntrinsicHeight, getMaxIntrinsicHeight, 'Height', double.infinity);
if (constraints.hasBoundedWidth) {
testIntrinsicsForValues(getMinIntrinsicWidth, getMaxIntrinsicWidth, 'Width', constraints.maxHeight);
}
if (constraints.hasBoundedHeight) {
testIntrinsicsForValues(getMinIntrinsicHeight, getMaxIntrinsicHeight, 'Height', constraints.maxWidth);
try {
testIntrinsicsForValues(getMinIntrinsicWidth, getMaxIntrinsicWidth, 'Width', double.infinity);
testIntrinsicsForValues(getMinIntrinsicHeight, getMaxIntrinsicHeight, 'Height', double.infinity);
if (constraints.hasBoundedWidth) {
testIntrinsicsForValues(getMinIntrinsicWidth, getMaxIntrinsicWidth, 'Width', constraints.maxHeight);
}
if (constraints.hasBoundedHeight) {
testIntrinsicsForValues(getMinIntrinsicHeight, getMaxIntrinsicHeight, 'Height', constraints.maxWidth);
}
// TODO(ianh): Test that values are internally consistent in more ways than the above.
} finally {
RenderObject.debugCheckingIntrinsics = false;
}

// TODO(ianh): Test that values are internally consistent in more ways than the above.

RenderObject.debugCheckingIntrinsics = false;
if (failures.isNotEmpty) {
// TODO(jacobr): consider nesting the failures object so it is collapsible.
throw FlutterError.fromParts(<DiagnosticsNode>[
Expand Down
Loading

0 comments on commit 460a5e2

Please sign in to comment.