Commit 4a70cfed authored by Adam Barth's avatar Adam Barth

Rename various text-related classes

 - Inline -> Pargraph. This class is actually a box, not an inline. It's really
   a wrapper for RenderParagraph, so Paragraph is the normal name.

 - InlineBase -> RenderInline. The name we used in C++ for the base class of
   all inlines was RenderInline, which removes the ugly "Base" suffix.

 - InlineText -> RenderText. Aligns this name with C++.

 - InlineStyle -> RenderStyled. Matches the foregoing pattern.
parent bd5b9566
...@@ -18,25 +18,25 @@ void main() { ...@@ -18,25 +18,25 @@ void main() {
for(FlexAlignItems alignItems in FlexAlignItems.values) { for(FlexAlignItems alignItems in FlexAlignItems.values) {
TextStyle style = const TextStyle(color: const Color(0xFF000000)); TextStyle style = const TextStyle(color: const Color(0xFF000000));
RenderParagraph paragraph = new RenderParagraph(new InlineStyle(style, [new InlineText("${alignItems}")])); RenderParagraph paragraph = new RenderParagraph(new RenderStyled(style, [new RenderText("${alignItems}")]));
table.add(new RenderPadding(child: paragraph, padding: new EdgeDims.only(top: 20.0))); table.add(new RenderPadding(child: paragraph, padding: new EdgeDims.only(top: 20.0)));
var row = new RenderFlex(alignItems: alignItems, textBaseline: TextBaseline.alphabetic); var row = new RenderFlex(alignItems: alignItems, textBaseline: TextBaseline.alphabetic);
style = new TextStyle(fontSize: 15.0, color: const Color(0xFF000000)); style = new TextStyle(fontSize: 15.0, color: const Color(0xFF000000));
row.add(new RenderDecoratedBox( row.add(new RenderDecoratedBox(
decoration: new BoxDecoration(backgroundColor: const Color(0x7FFFCCCC)), decoration: new BoxDecoration(backgroundColor: const Color(0x7FFFCCCC)),
child: new RenderParagraph(new InlineStyle(style, [new InlineText('foo foo foo')])) child: new RenderParagraph(new RenderStyled(style, [new RenderText('foo foo foo')]))
)); ));
style = new TextStyle(fontSize: 10.0, color: const Color(0xFF000000)); style = new TextStyle(fontSize: 10.0, color: const Color(0xFF000000));
row.add(new RenderDecoratedBox( row.add(new RenderDecoratedBox(
decoration: new BoxDecoration(backgroundColor: const Color(0x7FCCFFCC)), decoration: new BoxDecoration(backgroundColor: const Color(0x7FCCFFCC)),
child: new RenderParagraph(new InlineStyle(style, [new InlineText('foo foo foo')])) child: new RenderParagraph(new RenderStyled(style, [new RenderText('foo foo foo')]))
)); ));
var subrow = new RenderFlex(alignItems: alignItems, textBaseline: TextBaseline.alphabetic); var subrow = new RenderFlex(alignItems: alignItems, textBaseline: TextBaseline.alphabetic);
style = new TextStyle(fontSize: 25.0, color: const Color(0xFF000000)); style = new TextStyle(fontSize: 25.0, color: const Color(0xFF000000));
subrow.add(new RenderDecoratedBox( subrow.add(new RenderDecoratedBox(
decoration: new BoxDecoration(backgroundColor: const Color(0x7FCCCCFF)), decoration: new BoxDecoration(backgroundColor: const Color(0x7FCCCCFF)),
child: new RenderParagraph(new InlineStyle(style, [new InlineText('foo foo foo foo')])) child: new RenderParagraph(new RenderStyled(style, [new RenderText('foo foo foo foo')]))
)); ));
subrow.add(new RenderSolidColorBox(const Color(0x7FCCFFFF), desiredSize: new Size(30.0, 40.0))); subrow.add(new RenderSolidColorBox(const Color(0x7FCCFFFF), desiredSize: new Size(30.0, 40.0)));
row.add(subrow); row.add(subrow);
......
...@@ -13,19 +13,19 @@ import 'package:sky/rendering/sky_binding.dart'; ...@@ -13,19 +13,19 @@ import 'package:sky/rendering/sky_binding.dart';
RenderBox getBox(double lh) { RenderBox getBox(double lh) {
RenderParagraph paragraph = new RenderParagraph( RenderParagraph paragraph = new RenderParagraph(
new InlineStyle( new RenderStyled(
new TextStyle( new TextStyle(
color: const Color(0xFF0000A0) color: const Color(0xFF0000A0)
), ),
[ [
new InlineText('test'), new RenderText('test'),
new InlineStyle( new RenderStyled(
new TextStyle( new TextStyle(
fontFamily: 'serif', fontFamily: 'serif',
fontSize: 50.0, fontSize: 50.0,
height: lh height: lh
), ),
[new InlineText('مرحبا Hello')] [new RenderText('مرحبا Hello')]
) )
] ]
) )
......
...@@ -84,9 +84,9 @@ porchetta bacon kevin meatball meatloaf pig beef ribs chicken. Brisket ribeye ...@@ -84,9 +84,9 @@ porchetta bacon kevin meatball meatloaf pig beef ribs chicken. Brisket ribeye
andouille leberkas capicola meatloaf. Chicken pig ball tip pork picanha bresaola andouille leberkas capicola meatloaf. Chicken pig ball tip pork picanha bresaola
alcatra. Pork pork belly alcatra, flank chuck drumstick biltong doner jowl. alcatra. Pork pork belly alcatra, flank chuck drumstick biltong doner jowl.
Pancetta meatball tongue tenderloin rump tail jowl boudin."""; Pancetta meatball tongue tenderloin rump tail jowl boudin.""";
var text = new InlineStyle( var text = new RenderStyled(
new TextStyle(color: const Color(0xFF009900)), new TextStyle(color: const Color(0xFF009900)),
[new InlineText(meatyString)]); [new RenderText(meatyString)]);
padding = new RenderPadding( padding = new RenderPadding(
padding: const EdgeDims.all(10.0), padding: const EdgeDims.all(10.0),
child: new RenderParagraph(text)); child: new RenderParagraph(text));
......
...@@ -21,7 +21,7 @@ void main() { ...@@ -21,7 +21,7 @@ void main() {
var table = new RenderFlex(direction: FlexDirection.vertical); var table = new RenderFlex(direction: FlexDirection.vertical);
void addRow(FlexJustifyContent justify) { void addRow(FlexJustifyContent justify) {
RenderParagraph paragraph = new RenderParagraph(new InlineStyle(style, [new InlineText("${justify}")])); RenderParagraph paragraph = new RenderParagraph(new RenderStyled(style, [new RenderText("${justify}")]));
table.add(new RenderPadding(child: paragraph, padding: new EdgeDims.only(top: 20.0))); table.add(new RenderPadding(child: paragraph, padding: new EdgeDims.only(top: 20.0)));
var row = new RenderFlex(direction: FlexDirection.horizontal); var row = new RenderFlex(direction: FlexDirection.horizontal);
row.add(new RenderSolidColorBox(const Color(0xFFFFCCCC), desiredSize: new Size(80.0, 60.0))); row.add(new RenderSolidColorBox(const Color(0xFFFFCCCC), desiredSize: new Size(80.0, 60.0)));
......
...@@ -32,9 +32,9 @@ andouille leberkas capicola meatloaf. Chicken pig ball tip pork picanha bresaola ...@@ -32,9 +32,9 @@ andouille leberkas capicola meatloaf. Chicken pig ball tip pork picanha bresaola
alcatra. Pork pork belly alcatra, flank chuck drumstick biltong doner jowl. alcatra. Pork pork belly alcatra, flank chuck drumstick biltong doner jowl.
Pancetta meatball tongue tenderloin rump tail jowl boudin."""; Pancetta meatball tongue tenderloin rump tail jowl boudin.""";
var text = new InlineStyle( var text = new RenderStyled(
new TextStyle(color: const Color(0xFF009900)), new TextStyle(color: const Color(0xFF009900)),
[new InlineText(meatyString)]); [new RenderText(meatyString)]);
child = new RenderDecoratedBox( child = new RenderDecoratedBox(
decoration: new BoxDecoration(backgroundColor: const Color(0xFFFFFFFF)), decoration: new BoxDecoration(backgroundColor: const Color(0xFFFFFFFF)),
child: new RenderParagraph(text) child: new RenderParagraph(text)
......
...@@ -80,7 +80,7 @@ class RenderTouchDemo extends RenderBox { ...@@ -80,7 +80,7 @@ class RenderTouchDemo extends RenderBox {
} }
void main() { void main() {
var paragraph = new RenderParagraph(new InlineText("Touch me!")); var paragraph = new RenderParagraph(new RenderText("Touch me!"));
var stack = new RenderStack(children: [ var stack = new RenderStack(children: [
new RenderTouchDemo(), new RenderTouchDemo(),
paragraph, paragraph,
......
...@@ -8,7 +8,7 @@ import 'package:sky/painting/text_style.dart'; ...@@ -8,7 +8,7 @@ import 'package:sky/painting/text_style.dart';
import 'package:sky/rendering/box.dart'; import 'package:sky/rendering/box.dart';
import 'package:sky/rendering/object.dart'; import 'package:sky/rendering/object.dart';
abstract class InlineBase { abstract class RenderInline {
sky.Node _toDOM(sky.Document owner); sky.Node _toDOM(sky.Document owner);
String toString([String prefix = '']); String toString([String prefix = '']);
...@@ -16,8 +16,8 @@ abstract class InlineBase { ...@@ -16,8 +16,8 @@ abstract class InlineBase {
} }
} }
class InlineText extends InlineBase { class RenderText extends RenderInline {
InlineText(this.text) { RenderText(this.text) {
assert(text != null); assert(text != null);
} }
...@@ -27,25 +27,25 @@ class InlineText extends InlineBase { ...@@ -27,25 +27,25 @@ class InlineText extends InlineBase {
return owner.createText(text); return owner.createText(text);
} }
bool operator ==(other) => other is InlineText && text == other.text; bool operator ==(other) => other is RenderText && text == other.text;
int get hashCode => text.hashCode; int get hashCode => text.hashCode;
String toString([String prefix = '']) => '${prefix}InlineText: "${text}"'; String toString([String prefix = '']) => '${prefix}InlineText: "${text}"';
} }
class InlineStyle extends InlineBase { class RenderStyled extends RenderInline {
InlineStyle(this.style, this.children) { RenderStyled(this.style, this.children) {
assert(style != null); assert(style != null);
assert(children != null); assert(children != null);
} }
final TextStyle style; final TextStyle style;
final List<InlineBase> children; final List<RenderInline> children;
sky.Node _toDOM(sky.Document owner) { sky.Node _toDOM(sky.Document owner) {
sky.Element parent = owner.createElement('t'); sky.Element parent = owner.createElement('t');
style.applyToCSSStyle(parent.style); style.applyToCSSStyle(parent.style);
for (InlineBase child in children) { for (RenderInline child in children) {
parent.appendChild(child._toDOM(owner)); parent.appendChild(child._toDOM(owner));
} }
return parent; return parent;
...@@ -58,7 +58,7 @@ class InlineStyle extends InlineBase { ...@@ -58,7 +58,7 @@ class InlineStyle extends InlineBase {
bool operator ==(other) { bool operator ==(other) {
if (identical(this, other)) if (identical(this, other))
return true; return true;
if (other is! InlineStyle if (other is! RenderStyled
|| style != other.style || style != other.style
|| children.length != other.children.length) || children.length != other.children.length)
return false; return false;
...@@ -72,7 +72,7 @@ class InlineStyle extends InlineBase { ...@@ -72,7 +72,7 @@ class InlineStyle extends InlineBase {
int get hashCode { int get hashCode {
int value = 373; int value = 373;
value = 37 * value + style.hashCode; value = 37 * value + style.hashCode;
for (InlineBase child in children) for (RenderInline child in children)
value = 37 * value + child.hashCode; value = 37 * value + child.hashCode;
return value; return value;
} }
...@@ -82,7 +82,7 @@ class InlineStyle extends InlineBase { ...@@ -82,7 +82,7 @@ class InlineStyle extends InlineBase {
result.add('${prefix}InlineStyle:'); result.add('${prefix}InlineStyle:');
var indent = '${prefix} '; var indent = '${prefix} ';
result.add('${style.toString(indent)}'); result.add('${style.toString(indent)}');
for (InlineBase child in children) { for (RenderInline child in children) {
result.add(child.toString(indent)); result.add(child.toString(indent));
} }
return result.join('\n'); return result.join('\n');
...@@ -102,9 +102,8 @@ double _applyFloatingPointHack(double layoutValue) { ...@@ -102,9 +102,8 @@ double _applyFloatingPointHack(double layoutValue) {
class RenderParagraph extends RenderBox { class RenderParagraph extends RenderBox {
RenderParagraph(InlineBase inlineValue) { RenderParagraph(this._inline) {
_layoutRoot.rootElement = _document.createElement('p'); _layoutRoot.rootElement = _document.createElement('p');
inline = inlineValue;
} }
final sky.Document _document = new sky.Document(); final sky.Document _document = new sky.Document();
...@@ -112,9 +111,9 @@ class RenderParagraph extends RenderBox { ...@@ -112,9 +111,9 @@ class RenderParagraph extends RenderBox {
BoxConstraints _constraintsForCurrentLayout; // when null, we don't have a current layout BoxConstraints _constraintsForCurrentLayout; // when null, we don't have a current layout
InlineBase _inline; RenderInline _inline;
InlineBase get inline => _inline; RenderInline get inline => _inline;
void set inline (InlineBase value) { void set inline (RenderInline value) {
if (_inline == value) if (_inline == value)
return; return;
_inline = value; _inline = value;
......
...@@ -445,17 +445,17 @@ class Flexible extends ParentDataNode { ...@@ -445,17 +445,17 @@ class Flexible extends ParentDataNode {
: super(child, new FlexBoxParentData()..flex = flex, key: key); : super(child, new FlexBoxParentData()..flex = flex, key: key);
} }
class Inline extends LeafRenderObjectWrapper { class Paragraph extends LeafRenderObjectWrapper {
Inline({ Key key, this.text }) : super(key: key); Paragraph({ Key key, this.inline }) : super(key: key);
final InlineBase text; final RenderInline inline;
RenderParagraph createNode() => new RenderParagraph(text); RenderParagraph createNode() => new RenderParagraph(inline);
RenderParagraph get root => super.root; RenderParagraph get root => super.root;
void syncRenderObject(Widget old) { void syncRenderObject(Widget old) {
super.syncRenderObject(old); super.syncRenderObject(old);
root.inline = text; root.inline = inline;
} }
} }
...@@ -467,16 +467,16 @@ class StyledText extends Component { ...@@ -467,16 +467,16 @@ class StyledText extends Component {
final dynamic elements; final dynamic elements;
InlineBase _toInline(dynamic element) { RenderInline _toInline(dynamic element) {
if (element is String) if (element is String)
return new InlineText(element); return new RenderText(element);
if (element is Iterable && element.first is TextStyle) if (element is Iterable && element.first is TextStyle)
return new InlineStyle(element.first, element.skip(1).map(_toInline).toList()); return new RenderStyled(element.first, element.skip(1).map(_toInline).toList());
throw new ArgumentError("invalid elements"); throw new ArgumentError("invalid elements");
} }
Widget build() { Widget build() {
return new Inline(text: _toInline(elements)); return new Paragraph(inline: _toInline(elements));
} }
} }
...@@ -487,7 +487,7 @@ class Text extends Component { ...@@ -487,7 +487,7 @@ class Text extends Component {
final TextStyle style; final TextStyle style;
Widget build() { Widget build() {
InlineBase text = new InlineText(data); RenderInline inline = new RenderText(data);
TextStyle defaultStyle = DefaultTextStyle.of(this); TextStyle defaultStyle = DefaultTextStyle.of(this);
TextStyle combinedStyle; TextStyle combinedStyle;
if (defaultStyle != null) { if (defaultStyle != null) {
...@@ -499,8 +499,8 @@ class Text extends Component { ...@@ -499,8 +499,8 @@ class Text extends Component {
combinedStyle = style; combinedStyle = style;
} }
if (combinedStyle != null) if (combinedStyle != null)
text = new InlineStyle(combinedStyle, [text]); inline = new RenderStyled(combinedStyle, [inline]);
return new Inline(text: text); return new Paragraph(inline: inline);
} }
} }
......
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