OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 import 'dart:sky' as sky; |
| 6 |
| 7 import 'package:sky/rendering/box.dart'; |
| 8 import 'package:sky/rendering/flex.dart'; |
| 9 import 'package:sky/rendering/sky_binding.dart'; |
| 10 |
| 11 class RenderSolidColor extends RenderDecoratedBox { |
| 12 final sky.Size desiredSize; |
| 13 final sky.Color backgroundColor; |
| 14 |
| 15 RenderSolidColor(sky.Color backgroundColor, { this.desiredSize: sky.Size.infin
ite }) |
| 16 : backgroundColor = backgroundColor, |
| 17 super(decoration: new BoxDecoration(backgroundColor: backgroundColor)) { |
| 18 } |
| 19 |
| 20 double getMinIntrinsicWidth(BoxConstraints constraints) { |
| 21 return constraints.constrainWidth(desiredSize.width); |
| 22 } |
| 23 |
| 24 double getMaxIntrinsicWidth(BoxConstraints constraints) { |
| 25 return constraints.constrainWidth(desiredSize.width); |
| 26 } |
| 27 |
| 28 double getMinIntrinsicHeight(BoxConstraints constraints) { |
| 29 return constraints.constrainHeight(desiredSize.height); |
| 30 } |
| 31 |
| 32 double getMaxIntrinsicHeight(BoxConstraints constraints) { |
| 33 return constraints.constrainHeight(desiredSize.height); |
| 34 } |
| 35 |
| 36 void performLayout() { |
| 37 size = constraints.constrain(desiredSize); |
| 38 } |
| 39 |
| 40 void handleEvent(sky.Event event, BoxHitTestEntry entry) { |
| 41 if (event.type == 'pointerdown') |
| 42 decoration = new BoxDecoration(backgroundColor: const sky.Color(0xFFFF0000
)); |
| 43 else if (event.type == 'pointerup') |
| 44 decoration = new BoxDecoration(backgroundColor: backgroundColor); |
| 45 } |
| 46 } |
| 47 |
| 48 RenderBox buildFlexExample() { |
| 49 RenderFlex flexRoot = new RenderFlex(direction: FlexDirection.vertical); |
| 50 |
| 51 RenderDecoratedBox root = new RenderDecoratedBox( |
| 52 decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFF000000)), |
| 53 child: flexRoot |
| 54 ); |
| 55 |
| 56 void addFlexChildSolidColor(RenderFlex parent, sky.Color backgroundColor, { in
t flex: 0 }) { |
| 57 RenderSolidColor child = new RenderSolidColor(backgroundColor); |
| 58 parent.add(child); |
| 59 child.parentData.flex = flex; |
| 60 } |
| 61 |
| 62 // Yellow bar at top |
| 63 addFlexChildSolidColor(flexRoot, const sky.Color(0xFFFFFF00), flex: 1); |
| 64 |
| 65 // Turquoise box |
| 66 flexRoot.add(new RenderSolidColor(const sky.Color(0x7700FFFF), desiredSize: ne
w sky.Size(100.0, 100.0))); |
| 67 |
| 68 var renderDecoratedBlock = new RenderDecoratedBox( |
| 69 decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFFFFFFFF)) |
| 70 ); |
| 71 |
| 72 flexRoot.add(new RenderPadding(padding: const EdgeDims.all(10.0), child: rende
rDecoratedBlock)); |
| 73 |
| 74 var row = new RenderFlex(direction: FlexDirection.horizontal); |
| 75 |
| 76 // Purple and blue cells |
| 77 addFlexChildSolidColor(row, const sky.Color(0x77FF00FF), flex: 1); |
| 78 addFlexChildSolidColor(row, const sky.Color(0xFF0000FF), flex: 2); |
| 79 |
| 80 var decoratedRow = new RenderDecoratedBox( |
| 81 decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFF333333)), |
| 82 child: row |
| 83 ); |
| 84 |
| 85 flexRoot.add(decoratedRow); |
| 86 decoratedRow.parentData.flex = 3; |
| 87 |
| 88 return root; |
| 89 } |
| 90 |
| 91 void main() { |
| 92 new SkyBinding(root: buildFlexExample()); |
| 93 } |
OLD | NEW |