OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 import 'dart:sky' as sky; | 5 import 'dart:sky' as sky; |
6 | 6 |
7 import 'package:vector_math/vector_math.dart'; | 7 import 'package:vector_math/vector_math.dart'; |
8 | 8 |
9 import '../painting/text_style.dart'; | 9 import '../painting/text_style.dart'; |
10 import '../rendering/block.dart'; | 10 import '../rendering/block.dart'; |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
373 | 373 |
374 final InlineBase text; | 374 final InlineBase text; |
375 | 375 |
376 void syncRenderObject(Widget old) { | 376 void syncRenderObject(Widget old) { |
377 super.syncRenderObject(old); | 377 super.syncRenderObject(old); |
378 root.inline = text; | 378 root.inline = text; |
379 } | 379 } |
380 | 380 |
381 } | 381 } |
382 | 382 |
383 class StyledText extends Component { | |
384 // elements ::= "string" | [<text-style> <elements>*] | |
Hixie
2015/06/18 22:32:24
I think it'd be better to have this only support T
| |
385 // Where "string" is text to display and text-style is an instance of | |
386 // TextStyle. The text-style applies to all of the elements that follow. | |
387 StyledText({ this.elements, String key }) : super(key: key); | |
388 | |
389 final dynamic elements; | |
390 | |
391 InlineBase _toInline(dynamic element) { | |
392 if (element is String) { | |
393 return new InlineText(element); | |
394 } | |
395 if (element is Iterable && element.first is TextStyle) { | |
396 return new InlineStyle(element.first, element.skip(1).map(_toInline).toLis t()); | |
397 } | |
398 throw new ArgumentError("invalid elements"); | |
399 } | |
400 | |
401 Widget build() { | |
402 return new Inline(text: _toInline(elements)); | |
403 } | |
404 } | |
405 | |
383 class Text extends Component { | 406 class Text extends Component { |
384 Text(this.data, { String key, TextStyle this.style }) : super(key: key); | 407 Text(this.data, { String key, TextStyle this.style }) : super(key: key); |
385 final String data; | 408 final String data; |
386 final TextStyle style; | 409 final TextStyle style; |
387 bool get interchangeable => true; | 410 bool get interchangeable => true; |
388 Widget build() { | 411 Widget build() { |
389 InlineBase text = new InlineText(data); | 412 InlineBase text = new InlineText(data); |
390 if (style != null) text = new InlineStyle(style, [text]); | 413 if (style != null) text = new InlineStyle(style, [text]); |
391 return new Inline(text: text); | 414 return new Inline(text: text); |
392 } | 415 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
436 } | 459 } |
437 | 460 |
438 void remove() { | 461 void remove() { |
439 RenderObjectWrapper ancestor = findAncestor(RenderObjectWrapper); | 462 RenderObjectWrapper ancestor = findAncestor(RenderObjectWrapper); |
440 assert(ancestor is RenderObjectWrapper); | 463 assert(ancestor is RenderObjectWrapper); |
441 ancestor.detachChildRoot(this); | 464 ancestor.detachChildRoot(this); |
442 super.remove(); | 465 super.remove(); |
443 } | 466 } |
444 | 467 |
445 } | 468 } |
OLD | NEW |