Commit f35ad647 authored by Adam Barth's avatar Adam Barth

Merge pull request #1814 from abarth/fix_right_align

Right-aligned text paints offscreen sometimes
parents a13147d0 69a0689a
...@@ -166,21 +166,22 @@ class TextPainter { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment