| 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'; | 5 import 'dart:sky'; |
| 6 import 'package:sky/framework/app.dart'; | 6 import 'package:sky/framework/app.dart'; |
| 7 import 'package:sky/framework/layout2.dart'; | 7 import 'package:sky/framework/layout2.dart'; |
| 8 | 8 |
| 9 class RenderSolidColor extends RenderDecoratedBox { | 9 class RenderSolidColor extends RenderDecoratedBox { |
| 10 final double desiredHeight; | 10 final Size desiredSize; |
| 11 final double desiredWidth; | |
| 12 final int backgroundColor; | 11 final int backgroundColor; |
| 13 | 12 |
| 14 RenderSolidColor(int backgroundColor, { this.desiredHeight: double.INFINITY, | 13 RenderSolidColor(int backgroundColor, { this.desiredSize: const Size.infinite(
) }) |
| 15 this.desiredWidth: double.INFINITY }) | |
| 16 : backgroundColor = backgroundColor, | 14 : backgroundColor = backgroundColor, |
| 17 super(new BoxDecoration(backgroundColor: backgroundColor)); | 15 super(decoration: new BoxDecoration(backgroundColor: backgroundColor)); |
| 18 | 16 |
| 19 Size getIntrinsicDimensions(BoxConstraints constraints) { | 17 Size getIntrinsicDimensions(BoxConstraints constraints) { |
| 20 return constraints.constrain(new Size(desiredWidth, desiredHeight)); | 18 return constraints.constrain(new Size(desiredWidth, desiredHeight)); |
| 21 } | 19 } |
| 22 | 20 |
| 23 void performLayout() { | 21 void performLayout() { |
| 24 width = constraints.constrainWidth(desiredWidth); | 22 size = constraints.constrain(desiredSize); |
| 25 height = constraints.constrainHeight(desiredHeight); | |
| 26 } | 23 } |
| 27 | 24 |
| 28 void handlePointer(PointerEvent event) { | 25 void handlePointer(PointerEvent event) { |
| 29 if (event.type == 'pointerdown') | 26 if (event.type == 'pointerdown') |
| 30 decoration = new BoxDecoration(backgroundColor: 0xFFFF0000); | 27 decoration = new BoxDecoration(backgroundColor: 0xFFFF0000); |
| 31 else if (event.type == 'pointerup') | 28 else if (event.type == 'pointerup') |
| 32 decoration = new BoxDecoration(backgroundColor: backgroundColor); | 29 decoration = new BoxDecoration(backgroundColor: backgroundColor); |
| 33 } | 30 } |
| 34 } | 31 } |
| 35 | 32 |
| 36 AppView app; | 33 AppView app; |
| 37 | 34 |
| 38 void main() { | 35 void main() { |
| 39 var root = new RenderFlex( | 36 RenderFlex flexRoot = new RenderFlex(direction: FlexDirection.Vertical); |
| 40 direction: FlexDirection.Vertical, | 37 |
| 41 decoration: new BoxDecoration(backgroundColor: 0xFF000000)); | 38 RenderNode root = new RenderDecoratedBox( |
| 39 decoration: new BoxDecoration(backgroundColor: 0xFF606060), |
| 40 child: flexRoot |
| 41 ); |
| 42 | 42 |
| 43 RenderNode child = new RenderSolidColor(0xFFFFFF00); | 43 RenderNode child = new RenderSolidColor(0xFFFFFF00); |
| 44 root.add(child); | 44 flexRoot.add(child); |
| 45 child.parentData.flex = 2; | 45 child.parentData.flex = 2; |
| 46 | 46 |
| 47 // The internet is a beautiful place. https://baconipsum.com/ | 47 // The internet is a beautiful place. https://baconipsum.com/ |
| 48 String meatyString = """Bacon ipsum dolor amet ham fatback tri-tip, prosciutto | 48 String meatyString = """Bacon ipsum dolor amet ham fatback tri-tip, prosciutto |
| 49 porchetta bacon kevin meatball meatloaf pig beef ribs chicken. Brisket ribeye | 49 porchetta bacon kevin meatball meatloaf pig beef ribs chicken. Brisket ribeye |
| 50 andouille leberkas capicola meatloaf. Chicken pig ball tip pork picanha bresaola | 50 andouille leberkas capicola meatloaf. Chicken pig ball tip pork picanha bresaola |
| 51 alcatra. Pork pork belly alcatra, flank chuck drumstick biltong doner jowl. | 51 alcatra. Pork pork belly alcatra, flank chuck drumstick biltong doner jowl. |
| 52 Pancetta meatball tongue tenderloin rump tail jowl boudin."""; | 52 Pancetta meatball tongue tenderloin rump tail jowl boudin."""; |
| 53 | 53 |
| 54 child = new RenderParagraph(meatyString); | 54 child = new RenderDecoratedBox( |
| 55 root.add(child); | 55 decoration: new BoxDecoration(backgroundColor: 0xFFFFFFFF), |
| 56 child: new RenderParagraph(text: meatyString, color: 0xFF009900) |
| 57 ); |
| 58 flexRoot.add(child); |
| 56 child.parentData.flex = 1; | 59 child.parentData.flex = 1; |
| 57 | 60 |
| 58 app = new AppView(root); | 61 app = new AppView(root); |
| 59 } | 62 } |
| OLD | NEW |