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:
parent
0821b759f5
commit
fb33b7a1b8
@ -1 +1 @@
|
|||||||
fa13c1b039e693123888e434e4ee1f9ff79d3b6e
|
65bd07204149c4f7612bbf179cf088a2d69ca549
|
||||||
|
@ -488,7 +488,15 @@ class RenderParagraph extends RenderBox
|
|||||||
_textPainter.markNeedsLayout();
|
_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) {
|
void _layoutTextWithConstraints(BoxConstraints constraints) {
|
||||||
|
_textPainter.setPlaceholderDimensions(_placeholderDimensions);
|
||||||
_layoutText(minWidth: constraints.minWidth, maxWidth: constraints.maxWidth);
|
_layoutText(minWidth: constraints.minWidth, maxWidth: constraints.maxWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -501,7 +509,7 @@ class RenderParagraph extends RenderBox
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
RenderBox child = firstChild;
|
RenderBox child = firstChild;
|
||||||
final List<PlaceholderDimensions> placeholderDimensions = List<PlaceholderDimensions>(childCount);
|
_placeholderDimensions = List<PlaceholderDimensions>(childCount);
|
||||||
int childIndex = 0;
|
int childIndex = 0;
|
||||||
while (child != null) {
|
while (child != null) {
|
||||||
// Only constrain the width to the maximum width of the paragraph.
|
// Only constrain the width to the maximum width of the paragraph.
|
||||||
@ -525,7 +533,7 @@ class RenderParagraph extends RenderBox
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
placeholderDimensions[childIndex] = PlaceholderDimensions(
|
_placeholderDimensions[childIndex] = PlaceholderDimensions(
|
||||||
size: child.size,
|
size: child.size,
|
||||||
alignment: _placeholderSpans[childIndex].alignment,
|
alignment: _placeholderSpans[childIndex].alignment,
|
||||||
baseline: _placeholderSpans[childIndex].baseline,
|
baseline: _placeholderSpans[childIndex].baseline,
|
||||||
@ -534,7 +542,6 @@ class RenderParagraph extends RenderBox
|
|||||||
child = childAfter(child);
|
child = childAfter(child);
|
||||||
childIndex += 1;
|
childIndex += 1;
|
||||||
}
|
}
|
||||||
_textPainter.setPlaceholderDimensions(placeholderDimensions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate through the laid-out children and set the parentData offsets based
|
// Iterate through the laid-out children and set the parentData offsets based
|
||||||
|
@ -831,7 +831,7 @@ void main() {
|
|||||||
find.byType(Container),
|
find.byType(Container),
|
||||||
matchesGoldenFile(
|
matchesGoldenFile(
|
||||||
'text_golden.TextInlineWidgetNest.1.png',
|
'text_golden.TextInlineWidgetNest.1.png',
|
||||||
version: 2,
|
version: 3,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user