Implement RenderImage and Image for Sky

This also fixes a bug that was preventing markNeedsLayout from working

R=abarth@chromium.org, eseidel@chromium.org, abarth, eseidel

Review URL: https://codereview.chromium.org/1160013004
This commit is contained in:
Collin Jackson
2015-06-03 15:17:12 -07:00
parent 6213436a7d
commit da5e6c9a97
2 changed files with 46 additions and 1 deletions

View File

@@ -5,6 +5,17 @@
import 'dart:sky' as sky;
import 'package:sky/framework/fn2.dart';
import 'package:sky/framework/rendering/box.dart';
import '../lib/solid_color_box.dart';
class Rectangle extends RenderNodeWrapper {
RenderSolidColorBox root;
RenderSolidColorBox createNode() =>
new RenderSolidColorBox(color, desiredSize: new sky.Size(40.0, 130.0));
final int color;
Rectangle(this.color, { Object key }) : super(key: key);
}
class ContainerApp extends App {
UINode build() {
@@ -20,7 +31,11 @@ class ContainerApp extends App {
new Container(
decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFFFFFF00)),
desiredSize: new sky.Size(double.INFINITY, 20.0)
)
),
new Image(src: "https://www.dartlang.org/logos/dart-logo.png",
size: new sky.Size(300.0, 300.0),
key: 1
),
])),
]),
onPointerDown: _handlePointerDown);

View File

@@ -0,0 +1,30 @@
// 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:sky';
import 'package:sky/framework/rendering/box.dart';
class RenderSolidColorBox extends RenderDecoratedBox {
final Size desiredSize;
final Color backgroundColor;
RenderSolidColorBox(Color backgroundColor, { this.desiredSize: const Size.infinite() })
: backgroundColor = backgroundColor,
super(decoration: new BoxDecoration(backgroundColor: backgroundColor));
Size getIntrinsicDimensions(BoxConstraints constraints) {
return constraints.constrain(desiredSize);
}
void performLayout() {
size = constraints.constrain(desiredSize);
}
void handlePointer(PointerEvent event) {
if (event.type == 'pointerdown')
decoration = new BoxDecoration(backgroundColor: const Color(0xFFFF0000));
else if (event.type == 'pointerup')
decoration = new BoxDecoration(backgroundColor: backgroundColor);
}
}