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