Chromium Code Reviews| Index: sky/sdk/lib/framework/rendering/paragraph.dart |
| diff --git a/sky/sdk/lib/framework/rendering/paragraph.dart b/sky/sdk/lib/framework/rendering/paragraph.dart |
| index c0823a7b591e1456d9e54bf315baaaf46c38a6ed..2afc8337c8a94ffcbe687c361342c3f64ed4e183 100644 |
| --- a/sky/sdk/lib/framework/rendering/paragraph.dart |
| +++ b/sky/sdk/lib/framework/rendering/paragraph.dart |
| @@ -11,6 +11,23 @@ class RenderInline extends RenderObject { |
| String data; |
| } |
| +class TextStyle { |
| + final Color color; |
|
Hixie
2015/06/11 17:39:28
constructor then fields (see sky/specs/style-guide
|
| + final String fontSize; |
|
Hixie
2015/06/11 17:39:27
fontSize should be a double (pixels).
|
| + final String fontWeight; |
|
Hixie
2015/06/11 17:39:27
fontWeight should be an enum.
|
| + |
| + const TextStyle({ |
| + this.color, |
| + this.fontSize, |
| + this.fontWeight |
| + }); |
| + |
| + bool operator ==(other) => other is TextStyle && |
|
Hixie
2015/06/11 17:39:28
If you have an operator ==, you need a hashCode fu
|
| + color == other.color && |
| + fontSize == other.fontSize && |
| + fontWeight == other.fontWeight; |
| +} |
| + |
| // Unfortunately, using full precision floating point here causes bad layouts |
| // because floating point math isn't associative. If we add and subtract |
| // padding, for example, we'll get different values when we estimate sizes and |
| @@ -26,8 +43,9 @@ class RenderParagraph extends RenderBox { |
| RenderParagraph({ |
| String text, |
| - Color color |
| - }) : _color = color { |
| + Color color, |
| + TextStyle style |
| + }) : _color = color, _style = style { |
| _layoutRoot.rootElement = _document.createElement('p'); |
| this.text = text; |
| } |
| @@ -41,6 +59,7 @@ class RenderParagraph extends RenderBox { |
| markNeedsLayout(); |
| } |
| + // TODO(hansmuller): remove this |
| Color _color = const Color(0xFF000000); |
| Color get color => _color; |
| void set color (Color value) { |
| @@ -50,6 +69,16 @@ class RenderParagraph extends RenderBox { |
| } |
| } |
| + TextStyle _style; |
| + TextStyle get style => _style; |
| + void set style (TextStyle value) { |
| + if (_style != value) { |
| + _style = value; |
| + // TODO(hansmuller): decide if a new layout or paint is needed |
| + markNeedsLayout(); |
| + } |
| + } |
| + |
| BoxConstraints _constraintsForCurrentLayout; |
| sky.Element _layout(BoxConstraints constraints) { |
| @@ -106,9 +135,10 @@ class RenderParagraph extends RenderBox { |
| if (_constraintsForCurrentLayout != constraints && constraints != null) |
| _layout(constraints); |
| - if (_color != null) { |
| + if (style != null && style.color != null) { |
| + Color color = style.color; |
| _layoutRoot.rootElement.style['color'] = |
| - 'rgba(${_color.red}, ${_color.green}, ${_color.blue}, ${_color.alpha / 255.0 })'; |
| + 'rgba(${color.red}, ${color.green}, ${color.blue}, ${color.alpha / 255.0 })'; |
| } |
| _layoutRoot.paint(canvas); |
| } |