提交 0a09212f 编写于 作者: A Adam Barth

Add a simple_render_tree example

This example shows how to draw a circle using subclasses of RenderNode.

R=ianh@google.com

Review URL: https://codereview.chromium.org/1144193004
上级 66dd961f
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:math';
import 'dart:sky';
import 'package:sky/framework/layout2.dart';
class RenderBlueCircle extends RenderBox {
void paint(RenderNodeDisplayList canvas) {
double radius = min(width, height) * 0.45;
Paint paint = new Paint()..setARGB(255, 0, 255, 255);
canvas.drawCircle(width / 2, height / 2, radius, paint);
}
}
void main() {
RenderView renderView = new RenderView(root: new RenderBlueCircle());
renderView.layout(newWidth: view.width, newHeight: view.height);
renderView.paintFrame();
}
......@@ -67,6 +67,7 @@ dart_pkg("sdk") {
"lib/framework/embedder.dart",
"lib/framework/fn.dart",
"lib/framework/layout.dart",
"lib/framework/layout2.dart",
"lib/framework/layouts/block.dart",
"lib/framework/net/fetch.dart",
"lib/framework/node.dart",
......
......@@ -228,7 +228,7 @@ abstract class RenderNode extends AbstractNode {
var ancestor = this;
while (ancestor.parent != null)
ancestor = ancestor.parent;
assert(ancestor is Screen);
assert(ancestor is RenderView);
ancestor.paintFrame();
}
void paint(RenderNodeDisplayList canvas) { }
......@@ -450,11 +450,11 @@ abstract class RenderBox extends RenderNode {
}
// SCREEN LAYOUT MANAGER
// RENDER VIEW LAYOUT MANAGER
class Screen extends RenderNode {
class RenderView extends RenderNode {
Screen({
RenderView({
RenderBox root,
this.timeForRotation: const Duration(microseconds: 83333)
}) {
......@@ -474,7 +474,7 @@ class Screen extends RenderNode {
RenderBox _root;
RenderBox get root => _root;
void set root (RenderBox value) {
assert(root != null);
assert(value != null);
_root = value;
adoptChild(_root);
markNeedsLayout();
......@@ -547,12 +547,12 @@ class EdgeDims {
class BlockParentData extends BoxParentData with ContainerParentDataMixin<RenderBox> { }
class BlockBox extends RenderBox with ContainerRenderNodeMixin<RenderBox, BlockParentData> {
class RenderBlock extends RenderBox with ContainerRenderNodeMixin<RenderBox, BlockParentData> {
// lays out RenderBox children in a vertical stack
// uses the maximum width provided by the parent
// sizes itself to the height of its child stack
BlockBox({
RenderBlock({
EdgeDims padding: const EdgeDims(0.0, 0.0, 0.0, 0.0)
}) {
_padding = padding;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册