More elaborate RenderBox example

Also, some trivial fixes for things that I found while playing with
the rendering library directly.
This commit is contained in:
Ian Hickson
2016-01-14 23:17:45 -08:00
parent 96958b203e
commit 51566aeffa
4 changed files with 97 additions and 29 deletions

View File

@@ -10,6 +10,7 @@ import 'text_style.dart';
/// An immutable span of text.
abstract class TextSpan {
// This class must be immutable, because we won't notice when it changes.
const TextSpan();
String toString([String prefix = '']);
void build(ui.ParagraphBuilder builder);
ui.ParagraphStyle get paragraphStyle => null;
@@ -17,14 +18,13 @@ abstract class TextSpan {
/// An immutable span of unstyled text.
class PlainTextSpan extends TextSpan {
PlainTextSpan(this.text) {
assert(text != null);
}
const PlainTextSpan(this.text);
/// The text contained in the span.
final String text;
void build(ui.ParagraphBuilder builder) {
assert(text != null);
builder.addText(text);
}
@@ -42,10 +42,7 @@ class PlainTextSpan extends TextSpan {
/// An immutable text span that applies a style to a list of children.
class StyledTextSpan extends TextSpan {
StyledTextSpan(this.style, this.children) {
assert(style != null);
assert(children != null);
}
const StyledTextSpan(this.style, this.children);
/// The style to apply to the children.
final TextStyle style;
@@ -54,9 +51,13 @@ class StyledTextSpan extends TextSpan {
final List<TextSpan> children;
void build(ui.ParagraphBuilder builder) {
assert(style != null);
assert(children != null);
builder.pushStyle(style.textStyle);
for (TextSpan child in children)
for (TextSpan child in children) {
assert(child != null);
child.build(builder);
}
builder.pop();
}

View File

@@ -93,7 +93,7 @@ void debugDumpLayerTree() {
/// A concrete binding for applications that use the Rendering framework
/// directly. This is the glue that binds the framework to the Flutter engine.
class RenderingFlutterBinding extends BindingBase with Scheduler, Renderer, Gesturer {
class RenderingFlutterBinding extends BindingBase with Scheduler, Gesturer, Renderer {
RenderingFlutterBinding({ RenderBox root }) {
assert(renderView != null);
renderView.child = root;

View File

@@ -1304,6 +1304,7 @@ class RenderPointerListener extends RenderProxyBox {
/// not, we can re-record its display list without re-recording the display list
/// for the surround tree.
class RenderRepaintBoundary extends RenderProxyBox {
RenderRepaintBoundary({ RenderBox child }) : super(child);
bool get isRepaintBoundary => true;
}