Right-aligned text paints offscreen sometimes
We were assuming that the text extended from 0.0 to its max content width. That's not correct for right-aligned text. Instead, we need to layout the text again at the width we want it to occupy.
This commit is contained in:
@@ -166,21 +166,22 @@ class TextPainter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The width at which decreasing the width of the text would prevent it from painting itself completely within its bounds
|
/// The width at which decreasing the width of the text would prevent it from painting itself completely within its bounds
|
||||||
double get minContentWidth {
|
double get minIntrinsicWidth {
|
||||||
assert(!_needsLayout);
|
assert(!_needsLayout);
|
||||||
return _applyFloatingPointHack(_paragraph.minIntrinsicWidth);
|
return _applyFloatingPointHack(_paragraph.minIntrinsicWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The width at which increasing the width of the text no longer decreases the height
|
/// The width at which increasing the width of the text no longer decreases the height
|
||||||
double get maxContentWidth {
|
double get maxIntrinsicWidth {
|
||||||
assert(!_needsLayout);
|
assert(!_needsLayout);
|
||||||
return _applyFloatingPointHack(_paragraph.maxIntrinsicWidth);
|
return _applyFloatingPointHack(_paragraph.maxIntrinsicWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The height required to paint the text completely within its bounds
|
Size get size {
|
||||||
double get height {
|
|
||||||
assert(!_needsLayout);
|
assert(!_needsLayout);
|
||||||
return _applyFloatingPointHack(_paragraph.height);
|
double height = _applyFloatingPointHack(_paragraph.height);
|
||||||
|
double width = _applyFloatingPointHack(_paragraph.width);
|
||||||
|
return new Size(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The distance from the top of the text to the first baseline of the given type
|
/// The distance from the top of the text to the first baseline of the given type
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ class RenderEditableParagraph extends RenderParagraph {
|
|||||||
// because we only support single-line text.
|
// because we only support single-line text.
|
||||||
layoutText(constraints);
|
layoutText(constraints);
|
||||||
return constraints.constrainWidth(
|
return constraints.constrainWidth(
|
||||||
textPainter.maxContentWidth + _kCursorGap + _kCursorWidth
|
textPainter.size.width + _kCursorGap + _kCursorWidth
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,10 +83,8 @@ class RenderEditableParagraph extends RenderParagraph {
|
|||||||
void performLayout() {
|
void performLayout() {
|
||||||
layoutText(constraints);
|
layoutText(constraints);
|
||||||
|
|
||||||
Size newContentSize = new Size(
|
Offset cursorPadding = const Offset(_kCursorGap + _kCursorWidth, 0.0);
|
||||||
textPainter.maxContentWidth + _kCursorGap + _kCursorWidth,
|
Size newContentSize = textPainter.size + cursorPadding;
|
||||||
textPainter.height
|
|
||||||
);
|
|
||||||
size = constraints.constrain(newContentSize);
|
size = constraints.constrain(newContentSize);
|
||||||
|
|
||||||
if (_contentSize == null || _contentSize != newContentSize) {
|
if (_contentSize == null || _contentSize != newContentSize) {
|
||||||
@@ -109,7 +107,7 @@ class RenderEditableParagraph extends RenderParagraph {
|
|||||||
|
|
||||||
if (_showCursor) {
|
if (_showCursor) {
|
||||||
Rect cursorRect = new Rect.fromLTWH(
|
Rect cursorRect = new Rect.fromLTWH(
|
||||||
textPainter.maxContentWidth + _kCursorGap,
|
textPainter.size.width + _kCursorGap,
|
||||||
_kCursorHeightOffset,
|
_kCursorHeightOffset,
|
||||||
_kCursorWidth,
|
_kCursorWidth,
|
||||||
size.height - 2.0 * _kCursorHeightOffset
|
size.height - 2.0 * _kCursorHeightOffset
|
||||||
|
|||||||
@@ -59,22 +59,27 @@ class RenderParagraph extends RenderBox {
|
|||||||
textPainter.minHeight = constraints.minHeight;
|
textPainter.minHeight = constraints.minHeight;
|
||||||
textPainter.maxHeight = constraints.maxHeight;
|
textPainter.maxHeight = constraints.maxHeight;
|
||||||
textPainter.layout();
|
textPainter.layout();
|
||||||
|
// By default, we shrinkwrap to the intrinsic width.
|
||||||
|
double width = constraints.constrainWidth(textPainter.maxIntrinsicWidth);
|
||||||
|
textPainter.minWidth = width;
|
||||||
|
textPainter.maxWidth = width;
|
||||||
|
textPainter.layout();
|
||||||
_constraintsForCurrentLayout = constraints;
|
_constraintsForCurrentLayout = constraints;
|
||||||
}
|
}
|
||||||
|
|
||||||
double getMinIntrinsicWidth(BoxConstraints constraints) {
|
double getMinIntrinsicWidth(BoxConstraints constraints) {
|
||||||
layoutText(constraints);
|
layoutText(constraints);
|
||||||
return constraints.constrainWidth(textPainter.minContentWidth);
|
return constraints.constrainWidth(textPainter.minIntrinsicWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
double getMaxIntrinsicWidth(BoxConstraints constraints) {
|
double getMaxIntrinsicWidth(BoxConstraints constraints) {
|
||||||
layoutText(constraints);
|
layoutText(constraints);
|
||||||
return constraints.constrainWidth(textPainter.maxContentWidth);
|
return constraints.constrainWidth(textPainter.maxIntrinsicWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
double _getIntrinsicHeight(BoxConstraints constraints) {
|
double _getIntrinsicHeight(BoxConstraints constraints) {
|
||||||
layoutText(constraints);
|
layoutText(constraints);
|
||||||
return constraints.constrainHeight(textPainter.height);
|
return constraints.constrainHeight(textPainter.size.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
double getMinIntrinsicHeight(BoxConstraints constraints) {
|
double getMinIntrinsicHeight(BoxConstraints constraints) {
|
||||||
@@ -93,12 +98,7 @@ class RenderParagraph extends RenderBox {
|
|||||||
|
|
||||||
void performLayout() {
|
void performLayout() {
|
||||||
layoutText(constraints);
|
layoutText(constraints);
|
||||||
|
size = constraints.constrain(textPainter.size);
|
||||||
// We use textPainter.maxContentWidth here, rather that textPainter.width,
|
|
||||||
// because the latter is the width that it used to wrap the text, whereas
|
|
||||||
// the former is the actual width of the text.
|
|
||||||
size = constraints.constrain(new Size(textPainter.maxContentWidth,
|
|
||||||
textPainter.height));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void paint(PaintingContext context, Offset offset) {
|
void paint(PaintingContext context, Offset offset) {
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class Label extends Node {
|
|||||||
_painter.minWidth = 0.0;
|
_painter.minWidth = 0.0;
|
||||||
_painter.layout();
|
_painter.layout();
|
||||||
|
|
||||||
_width = _painter.maxContentWidth.ceil().toDouble();
|
_width = _painter.maxIntrinsicWidth.ceil().toDouble();
|
||||||
|
|
||||||
_painter.maxWidth = _width;
|
_painter.maxWidth = _width;
|
||||||
_painter.minWidth = _width;
|
_painter.minWidth = _width;
|
||||||
|
|||||||
Reference in New Issue
Block a user