Commit 5497ba18 authored by Adam Barth's avatar Adam Barth

Update engine (#3637)

Turns out there were more clients of the old paragraph API than I expected.
This patch migrates them to the new API.
parent f93ea0ea
28fbcc3a38d94281ba2a77426fda0e157a563735
a25959370a0181c41794e512bbc8983ae8071238
......@@ -15,8 +15,7 @@ void beginFrame(Duration timeStamp) {
final ui.ParagraphBuilder paragraphBuilder = new ui.ParagraphBuilder()
..addText('Hello, world.');
final ui.Paragraph paragraph = paragraphBuilder.build(new ui.ParagraphStyle())
..maxWidth = logicalSize.width
..layout();
..layout(new ui.ParagraphConstraints(width: logicalSize.width));
final ui.Rect physicalBounds = ui.Point.origin & (logicalSize * devicePixelRatio);
final ui.PictureRecorder recorder = new ui.PictureRecorder();
......
......@@ -21,7 +21,7 @@ ui.Picture paint(ui.Rect paintBounds) {
// The paint method of Pargraph draws the contents of the paragraph unto the
// given canvas.
canvas.drawParagraph(paragraph, new ui.Offset(paragraph.maxWidth / -2.0, (paragraph.maxWidth / 2.0) - 125));
canvas.drawParagraph(paragraph, new ui.Offset(paragraph.width / -2.0, (paragraph.width / 2.0) - 125));
return recorder.endRecording();
}
......@@ -72,11 +72,10 @@ void main() {
// left, right, or center alignment. Once built, the contents of the paragraph
// cannot be altered, but sizing and positioning information can be updated.
paragraph = builder.build(new ui.ParagraphStyle())
// Next, we supply a maximum width that the text is permitted to occupy.
..maxWidth = 180.0
// ... and we ask the paragraph to the visual position of each its glyphs as
// well as its overall size, subject to its sizing constraints.
..layout();
// Next, we supply a width that the text is permitted to occupy and we ask
// the paragraph to the visual position of each its glyphs as well as its
// overall size, subject to its sizing constraints.
..layout(new ui.ParagraphConstraints(width: 180.0));
// Finally, we register our beginFrame callback and kick off the first frame.
ui.window.onBeginFrame = beginFrame;
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ui' as ui show Paragraph, ParagraphBuilder, ParagraphStyle, TextBox;
import 'dart:ui' as ui show Paragraph, ParagraphBuilder, ParagraphConstraints, ParagraphStyle, TextBox;
import 'package:flutter/gestures.dart';
......@@ -157,11 +157,7 @@ class RenderEditableLine extends RenderBox {
// TODO(abarth): ParagraphBuilder#build's argument should be optional.
// TODO(abarth): These min/max values should be the default for ui.Paragraph.
_layoutTemplate = builder.build(new ui.ParagraphStyle())
..minWidth = 0.0
..maxWidth = double.INFINITY
..minHeight = 0.0
..maxHeight = double.INFINITY
..layout();
..layout(new ui.ParagraphConstraints(width: double.INFINITY));
}
return _layoutTemplate.height;
}
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ui' as ui show Paragraph, ParagraphBuilder, ParagraphStyle, TextStyle;
import 'dart:ui' as ui show Paragraph, ParagraphBuilder, ParagraphConstraints, ParagraphStyle, TextStyle;
import 'box.dart';
import 'object.dart';
......@@ -103,16 +103,17 @@ class RenderErrorBox extends RenderBox {
void paint(PaintingContext context, Offset offset) {
try {
context.canvas.drawRect(offset & size, new Paint() .. color = backgroundColor);
double width;
if (_paragraph != null) {
// See the comment in the RenderErrorBox constructor. This is not the
// code you want to be copying and pasting. :-)
if (parent is RenderBox) {
RenderBox parentBox = parent;
_paragraph.maxWidth = parentBox.size.width;
width = parentBox.size.width;
} else {
_paragraph.maxWidth = size.width;
width = size.width;
}
_paragraph.layout();
_paragraph.layout(new ui.ParagraphConstraints(width: width));
context.canvas.drawParagraph(_paragraph, offset);
}
} catch (e) { }
......
......@@ -13,12 +13,7 @@ void main() {
Paragraph paragraph = builder.build(new ParagraphStyle());
expect(paragraph, isNotNull);
paragraph.minWidth = 0.0;
paragraph.maxWidth = 800.0;
paragraph.minHeight = 0.0;
paragraph.maxHeight = 600.0;
paragraph.layout();
paragraph.layout(new ParagraphConstraints(width: 800.0));
expect(paragraph.width, isNonZero);
expect(paragraph.height, isNonZero);
});
......
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