| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:sky' as sky; | 5 import 'dart:sky' as sky; |
| 6 | 6 |
| 7 import 'package:sky/rendering/block.dart'; | |
| 8 import 'package:sky/rendering/box.dart'; | 7 import 'package:sky/rendering/box.dart'; |
| 9 import 'package:sky/rendering/flex.dart'; | |
| 10 | 8 |
| 9 import '../../sdk/example/rendering/flex.dart'; |
| 11 import '../resources/display_list.dart'; | 10 import '../resources/display_list.dart'; |
| 12 import '../resources/third_party/unittest/unittest.dart'; | 11 import '../resources/third_party/unittest/unittest.dart'; |
| 13 import '../resources/unit.dart'; | 12 import '../resources/unit.dart'; |
| 14 | 13 |
| 15 class RenderSolidColor extends RenderDecoratedBox { | |
| 16 final sky.Size desiredSize; | |
| 17 final sky.Color backgroundColor; | |
| 18 | |
| 19 RenderSolidColor(sky.Color backgroundColor, { this.desiredSize: sky.Size.infin
ite }) | |
| 20 : backgroundColor = backgroundColor, | |
| 21 super(decoration: new BoxDecoration(backgroundColor: backgroundColor)) { | |
| 22 } | |
| 23 | |
| 24 double getMinIntrinsicWidth(BoxConstraints constraints) { | |
| 25 return constraints.constrainWidth(desiredSize.width); | |
| 26 } | |
| 27 | |
| 28 double getMaxIntrinsicWidth(BoxConstraints constraints) { | |
| 29 return constraints.constrainWidth(desiredSize.width); | |
| 30 } | |
| 31 | |
| 32 double getMinIntrinsicHeight(BoxConstraints constraints) { | |
| 33 return constraints.constrainHeight(desiredSize.height); | |
| 34 } | |
| 35 | |
| 36 double getMaxIntrinsicHeight(BoxConstraints constraints) { | |
| 37 return constraints.constrainHeight(desiredSize.height); | |
| 38 } | |
| 39 | |
| 40 void performLayout() { | |
| 41 size = constraints.constrain(desiredSize); | |
| 42 } | |
| 43 | |
| 44 void handleEvent(sky.Event event, BoxHitTestEntry entry) { | |
| 45 if (event.type == 'pointerdown') | |
| 46 decoration = new BoxDecoration(backgroundColor: const sky.Color(0xFFFF0000
)); | |
| 47 else if (event.type == 'pointerup') | |
| 48 decoration = new BoxDecoration(backgroundColor: backgroundColor); | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 void main() { | 14 void main() { |
| 53 initUnit(); | 15 initUnit(); |
| 54 | 16 |
| 55 test("should flex", () { | 17 test("should flex", () { |
| 56 RenderFlex flexRoot = new RenderFlex(direction: FlexDirection.vertical); | 18 RenderBox root = buildFlexExample(); |
| 57 | |
| 58 RenderDecoratedBox root = new RenderDecoratedBox( | |
| 59 decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFF000000)
), | |
| 60 child: flexRoot | |
| 61 ); | |
| 62 | |
| 63 void addFlexChildSolidColor(RenderFlex parent, sky.Color backgroundColor, {
int flex: 0 }) { | |
| 64 RenderSolidColor child = new RenderSolidColor(backgroundColor); | |
| 65 parent.add(child); | |
| 66 child.parentData.flex = flex; | |
| 67 } | |
| 68 | |
| 69 // Yellow bar at top | |
| 70 addFlexChildSolidColor(flexRoot, const sky.Color(0xFFFFFF00), flex: 1); | |
| 71 | |
| 72 // Turquoise box | |
| 73 flexRoot.add(new RenderSolidColor(const sky.Color(0x7700FFFF), desiredSize:
new sky.Size(100.0, 100.0))); | |
| 74 | |
| 75 // Green and cyan render block with padding | |
| 76 var renderBlock = new RenderBlock(); | |
| 77 | |
| 78 renderBlock.add(new RenderSolidColor(const sky.Color(0xFF00FF00), desiredSiz
e: new sky.Size(100.0, 50.0))); | |
| 79 renderBlock.add(new RenderSolidColor(const sky.Color(0x7700FFFF), desiredSiz
e: new sky.Size(50.0, 100.0))); | |
| 80 | |
| 81 var renderDecoratedBlock = new RenderDecoratedBox( | |
| 82 decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFFFFFFFF)
), | |
| 83 child: renderBlock | |
| 84 ); | |
| 85 | |
| 86 flexRoot.add(new RenderPadding(padding: const EdgeDims.all(10.0), child: ren
derDecoratedBlock)); | |
| 87 | |
| 88 var row = new RenderFlex(direction: FlexDirection.horizontal); | |
| 89 | |
| 90 // Purple and blue cells | |
| 91 addFlexChildSolidColor(row, const sky.Color(0x77FF00FF), flex: 1); | |
| 92 addFlexChildSolidColor(row, const sky.Color(0xFF0000FF), flex: 2); | |
| 93 | |
| 94 var decoratedRow = new RenderDecoratedBox( | |
| 95 decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFF333333)
), | |
| 96 child: row | |
| 97 ); | |
| 98 | |
| 99 flexRoot.add(decoratedRow); | |
| 100 decoratedRow.parentData.flex = 3; | |
| 101 | |
| 102 new TestRenderView(root); | 19 new TestRenderView(root); |
| 103 | |
| 104 expect(root.size.width, equals(sky.view.width)); | 20 expect(root.size.width, equals(sky.view.width)); |
| 105 expect(root.size.height, equals(sky.view.height)); | 21 expect(root.size.height, equals(sky.view.height)); |
| 106 expect(renderBlock.size.width, equals(sky.view.width - 20.0)); | |
| 107 | |
| 108 }); | 22 }); |
| 109 } | 23 } |
| OLD | NEW |