Use placeholder dimensions that reflect the final text layout (#42558)

The _computeChildren[Width/Height]With[Min/Max]Intrinsics methods in
RenderParagraph overwrite the text painter's placeholder dimensions
in order to compute potential widths and heights for the paragraph.

The placeholder dimensions should be restored to the values computed by
_layoutChildren before painting the text.
This commit is contained in:
Jason Simmons 2019-10-15 10:17:52 -07:00 committed by GitHub
parent 0821b759f5
commit fb33b7a1b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 5 deletions

View File

@ -1 +1 @@
fa13c1b039e693123888e434e4ee1f9ff79d3b6e
65bd07204149c4f7612bbf179cf088a2d69ca549

View File

@ -488,7 +488,15 @@ class RenderParagraph extends RenderBox
_textPainter.markNeedsLayout();
}
// Placeholder dimensions representing the sizes of child inline widgets.
//
// These need to be cached because the text painter's placeholder dimensions
// will be overwritten during intrinsic width/height calculations and must be
// restored to the original values before final layout and painting.
List<PlaceholderDimensions> _placeholderDimensions;
void _layoutTextWithConstraints(BoxConstraints constraints) {
_textPainter.setPlaceholderDimensions(_placeholderDimensions);
_layoutText(minWidth: constraints.minWidth, maxWidth: constraints.maxWidth);
}
@ -501,7 +509,7 @@ class RenderParagraph extends RenderBox
return;
}
RenderBox child = firstChild;
final List<PlaceholderDimensions> placeholderDimensions = List<PlaceholderDimensions>(childCount);
_placeholderDimensions = List<PlaceholderDimensions>(childCount);
int childIndex = 0;
while (child != null) {
// Only constrain the width to the maximum width of the paragraph.
@ -525,7 +533,7 @@ class RenderParagraph extends RenderBox
break;
}
}
placeholderDimensions[childIndex] = PlaceholderDimensions(
_placeholderDimensions[childIndex] = PlaceholderDimensions(
size: child.size,
alignment: _placeholderSpans[childIndex].alignment,
baseline: _placeholderSpans[childIndex].baseline,
@ -534,7 +542,6 @@ class RenderParagraph extends RenderBox
child = childAfter(child);
childIndex += 1;
}
_textPainter.setPlaceholderDimensions(placeholderDimensions);
}
// Iterate through the laid-out children and set the parentData offsets based

View File

@ -831,7 +831,7 @@ void main() {
find.byType(Container),
matchesGoldenFile(
'text_golden.TextInlineWidgetNest.1.png',
version: 2,
version: 3,
),
);
});