Commit 617fa8c3 authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

Engine roll with updates to the ParagraphBuilder constructor (#6528)

parent 33c65264
a8604ba9d22d22092aa1b245aaf30b11d562b804 9f65114e2061aa2964cc0d2baec8046fc7361ef7
...@@ -11,9 +11,9 @@ void beginFrame(Duration timeStamp) { ...@@ -11,9 +11,9 @@ void beginFrame(Duration timeStamp) {
final double devicePixelRatio = ui.window.devicePixelRatio; final double devicePixelRatio = ui.window.devicePixelRatio;
final ui.Size logicalSize = ui.window.physicalSize / devicePixelRatio; final ui.Size logicalSize = ui.window.physicalSize / devicePixelRatio;
final ui.ParagraphBuilder paragraphBuilder = new ui.ParagraphBuilder() final ui.ParagraphBuilder paragraphBuilder = new ui.ParagraphBuilder(new ui.ParagraphStyle())
..addText('Hello, world.'); ..addText('Hello, world.');
final ui.Paragraph paragraph = paragraphBuilder.build(new ui.ParagraphStyle()) final ui.Paragraph paragraph = paragraphBuilder.build()
..layout(new ui.ParagraphConstraints(width: logicalSize.width)); ..layout(new ui.ParagraphConstraints(width: logicalSize.width));
final ui.Rect physicalBounds = ui.Point.origin & (logicalSize * devicePixelRatio); final ui.Rect physicalBounds = ui.Point.origin & (logicalSize * devicePixelRatio);
......
...@@ -52,7 +52,7 @@ void beginFrame(Duration timeStamp) { ...@@ -52,7 +52,7 @@ void beginFrame(Duration timeStamp) {
void main() { void main() {
// To create a paragraph of text, we use ParagraphBuilder. // To create a paragraph of text, we use ParagraphBuilder.
ui.ParagraphBuilder builder = new ui.ParagraphBuilder() ui.ParagraphBuilder builder = new ui.ParagraphBuilder(new ui.ParagraphStyle())
// We first push a style that turns the text blue. // We first push a style that turns the text blue.
..pushStyle(new ui.TextStyle(color: const ui.Color(0xFF0000FF))) ..pushStyle(new ui.TextStyle(color: const ui.Color(0xFF0000FF)))
..addText('Hello, ') ..addText('Hello, ')
...@@ -74,7 +74,7 @@ void main() { ...@@ -74,7 +74,7 @@ void main() {
// which time we can apply styling that affects the entire paragraph, such as // which time we can apply styling that affects the entire paragraph, such as
// 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()
// Next, we supply a width that the text is permitted to occupy and we ask // 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 // the paragraph to the visual position of each its glyphs as well as its
// overall size, subject to its sizing constraints. // overall size, subject to its sizing constraints.
......
...@@ -176,15 +176,15 @@ class TextPainter { ...@@ -176,15 +176,15 @@ class TextPainter {
return; return;
_needsLayout = false; _needsLayout = false;
if (_paragraph == null) { if (_paragraph == null) {
ui.ParagraphBuilder builder = new ui.ParagraphBuilder();
_text.build(builder, textScaleFactor: textScaleFactor);
ui.ParagraphStyle paragraphStyle = _text.style?.getParagraphStyle( ui.ParagraphStyle paragraphStyle = _text.style?.getParagraphStyle(
textAlign: textAlign, textAlign: textAlign,
textScaleFactor: textScaleFactor, textScaleFactor: textScaleFactor,
ellipsis: _ellipsis, ellipsis: _ellipsis,
); );
paragraphStyle ??= new ui.ParagraphStyle(); paragraphStyle ??= new ui.ParagraphStyle();
_paragraph = builder.build(paragraphStyle); ui.ParagraphBuilder builder = new ui.ParagraphBuilder(paragraphStyle);
_text.build(builder, textScaleFactor: textScaleFactor);
_paragraph = builder.build();
} }
_lastMinWidth = minWidth; _lastMinWidth = minWidth;
_lastMaxWidth = maxWidth; _lastMaxWidth = maxWidth;
......
...@@ -216,12 +216,12 @@ class RenderEditable extends RenderBox { ...@@ -216,12 +216,12 @@ class RenderEditable extends RenderBox {
ui.Paragraph _layoutTemplate; ui.Paragraph _layoutTemplate;
double get _preferredLineHeight { double get _preferredLineHeight {
if (_layoutTemplate == null) { if (_layoutTemplate == null) {
ui.ParagraphBuilder builder = new ui.ParagraphBuilder() ui.ParagraphBuilder builder = new ui.ParagraphBuilder(new ui.ParagraphStyle())
..pushStyle(text.style.getTextStyle(textScaleFactor: textScaleFactor)) ..pushStyle(text.style.getTextStyle(textScaleFactor: textScaleFactor))
..addText(_kZeroWidthSpace); ..addText(_kZeroWidthSpace);
// 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()
..layout(new ui.ParagraphConstraints(width: double.INFINITY)); ..layout(new ui.ParagraphConstraints(width: double.INFINITY));
} }
return _layoutTemplate.height; return _layoutTemplate.height;
......
...@@ -40,10 +40,10 @@ class RenderErrorBox extends RenderBox { ...@@ -40,10 +40,10 @@ class RenderErrorBox extends RenderBox {
// Generally, the much better way to draw text in a RenderObject is to // Generally, the much better way to draw text in a RenderObject is to
// use the TextPainter class. If you're looking for code to crib from, // use the TextPainter class. If you're looking for code to crib from,
// see the paragraph.dart file and the RenderParagraph class. // see the paragraph.dart file and the RenderParagraph class.
ui.ParagraphBuilder builder = new ui.ParagraphBuilder(); ui.ParagraphBuilder builder = new ui.ParagraphBuilder(paragraphStyle);
builder.pushStyle(textStyle); builder.pushStyle(textStyle);
builder.addText(message); builder.addText(message);
_paragraph = builder.build(paragraphStyle); _paragraph = builder.build();
} }
} catch (e) { } } catch (e) { }
} }
......
...@@ -8,9 +8,9 @@ import 'package:test/test.dart'; ...@@ -8,9 +8,9 @@ import 'package:test/test.dart';
void main() { void main() {
test("Should be able to build and layout a paragraph", () { test("Should be able to build and layout a paragraph", () {
ParagraphBuilder builder = new ParagraphBuilder(); ParagraphBuilder builder = new ParagraphBuilder(new ParagraphStyle());
builder.addText('Hello'); builder.addText('Hello');
Paragraph paragraph = builder.build(new ParagraphStyle()); Paragraph paragraph = builder.build();
expect(paragraph, isNotNull); expect(paragraph, isNotNull);
paragraph.layout(new ParagraphConstraints(width: 800.0)); paragraph.layout(new ParagraphConstraints(width: 800.0));
......
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