longestLine layout width (#62657)
This commit is contained in:
parent
f29f05ed17
commit
3bc3ea51ed
@ -568,7 +568,21 @@ class TextPainter {
|
|||||||
_previousCaretPrototype = null;
|
_previousCaretPrototype = null;
|
||||||
_paragraph.layout(ui.ParagraphConstraints(width: maxWidth));
|
_paragraph.layout(ui.ParagraphConstraints(width: maxWidth));
|
||||||
if (minWidth != maxWidth) {
|
if (minWidth != maxWidth) {
|
||||||
final double newWidth = maxIntrinsicWidth.clamp(minWidth, maxWidth) as double;
|
double newWidth;
|
||||||
|
switch (textWidthBasis) {
|
||||||
|
case TextWidthBasis.longestLine:
|
||||||
|
// The parent widget expects the paragraph to be exactly
|
||||||
|
// `TextPainter.width` wide, if that value satisfies the constraints
|
||||||
|
// it gave to the TextPainter. So when `textWidthBasis` is longestLine,
|
||||||
|
// the paragraph's width needs to be as close to the width of its
|
||||||
|
// longest line as possible.
|
||||||
|
newWidth = _applyFloatingPointHack(_paragraph.longestLine);
|
||||||
|
break;
|
||||||
|
case TextWidthBasis.parent:
|
||||||
|
newWidth = maxIntrinsicWidth;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
newWidth = newWidth.clamp(minWidth, maxWidth) as double;
|
||||||
if (newWidth != _applyFloatingPointHack(_paragraph.width)) {
|
if (newWidth != _applyFloatingPointHack(_paragraph.width)) {
|
||||||
_paragraph.layout(ui.ParagraphConstraints(width: newWidth));
|
_paragraph.layout(ui.ParagraphConstraints(width: newWidth));
|
||||||
}
|
}
|
||||||
|
@ -914,6 +914,38 @@ void main() {
|
|||||||
expect(tester.getSize(find.text('RIGHT ALIGNED, LONGEST LINE')).width, equals(width));
|
expect(tester.getSize(find.text('RIGHT ALIGNED, LONGEST LINE')).width, equals(width));
|
||||||
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/44020
|
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/44020
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'textWidthBasis.longestLine confines the width of the paragraph '
|
||||||
|
'when given loose constraints',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
// Regression test for https://github.com/flutter/flutter/issues/62550.
|
||||||
|
await tester.pumpWidget(
|
||||||
|
Center(
|
||||||
|
child: SizedBox(
|
||||||
|
width: 400,
|
||||||
|
child: Center(
|
||||||
|
child: RichText(
|
||||||
|
text: const TextSpan(text: 'fwefwefwewfefewfwe fwfwfwefweabcdefghijklmnopqrstuvwxyz'),
|
||||||
|
textWidthBasis: TextWidthBasis.longestLine,
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(find.byType(RichText), paints..something((Symbol method, List<dynamic> arguments) {
|
||||||
|
if (method != #drawParagraph)
|
||||||
|
return false;
|
||||||
|
final ui.Paragraph paragraph = arguments[0] as ui.Paragraph;
|
||||||
|
if (paragraph.width > paragraph.longestLine)
|
||||||
|
throw 'paragraph width (${paragraph.width}) greater than its longest line (${paragraph.longestLine}).';
|
||||||
|
if (paragraph.width >= 400)
|
||||||
|
throw 'paragraph.width (${paragraph.width}) >= 400';
|
||||||
|
return true;
|
||||||
|
}));
|
||||||
|
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/44020
|
||||||
|
|
||||||
testWidgets('Paragraph.getBoxesForRange returns nothing when selection range is zero length', (WidgetTester tester) async {
|
testWidgets('Paragraph.getBoxesForRange returns nothing when selection range is zero length', (WidgetTester tester) async {
|
||||||
final ui.ParagraphBuilder builder = ui.ParagraphBuilder(ui.ParagraphStyle());
|
final ui.ParagraphBuilder builder = ui.ParagraphBuilder(ui.ParagraphStyle());
|
||||||
builder.addText('hello');
|
builder.addText('hello');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user