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:
@@ -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);
|
||||
|
||||
30
engine/src/flutter/examples/lib/solid_color_box.dart
Normal file
30
engine/src/flutter/examples/lib/solid_color_box.dart
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user