Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Unified Diff: sky/sdk/lib/framework/rendering/paragraph.dart

Issue 1176133002: Add support for text styles - Work In Progress (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/sdk/lib/framework/fn2.dart ('k') | sky/sdk/lib/framework/theme2/typography.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
« no previous file with comments | « sky/sdk/lib/framework/fn2.dart ('k') | sky/sdk/lib/framework/theme2/typography.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698