Chromium Code Reviews| 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'; | |
| 6 import 'dart:math'; | |
| 7 import 'package:sky/framework/net/image_cache.dart' as image_cache; | |
| 8 import 'package:sky/framework/app.dart'; | |
| 9 import 'package:sky/framework/rendering/box.dart'; | |
| 10 import 'package:sky/framework/rendering/block.dart'; | |
| 11 import 'package:sky/framework/rendering/flex.dart'; | |
| 12 import 'package:sky/framework/rendering/image.dart'; | |
| 13 import 'package:sky/framework/rendering/node.dart'; | |
| 14 import 'package:sky/framework/rendering/paragraph.dart'; | |
| 15 | |
| 16 class RenderSolidColor extends RenderDecoratedBox { | |
| 17 final Size desiredSize; | |
| 18 final int backgroundColor; | |
| 19 | |
| 20 RenderSolidColor(int backgroundColor, { this.desiredSize: const Size.infinite( ) }) | |
| 21 : backgroundColor = backgroundColor, | |
| 22 super(decoration: new BoxDecoration(backgroundColor: backgroundColor)); | |
| 23 | |
| 24 Size getIntrinsicDimensions(BoxConstraints constraints) { | |
| 25 return constraints.constrain(desiredSize); | |
| 26 } | |
| 27 | |
| 28 void performLayout() { | |
| 29 size = constraints.constrain(desiredSize); | |
| 30 } | |
| 31 | |
| 32 void handlePointer(PointerEvent event) { | |
| 33 if (event.type == 'pointerdown') | |
| 34 decoration = new BoxDecoration(backgroundColor: 0xFFFF0000); | |
| 35 else if (event.type == 'pointerup') | |
| 36 decoration = new BoxDecoration(backgroundColor: backgroundColor); | |
| 37 } | |
| 38 } | |
|
abarth-chromium
2015/06/03 00:16:31
Can we not copy/paste this class for the Nth time?
jackson
2015/06/03 17:41:43
Done.
| |
| 39 | |
| 40 class RenderImageResizable extends RenderImage { | |
| 41 RenderImageResizable(String src, double width, double height) | |
|
abarth-chromium
2015/06/03 00:16:31
The caller should pass in a sky.Size instead of wi
jackson
2015/06/03 17:41:43
Done.
| |
| 42 : _src = src, | |
| 43 _startingSize = new Size(width, height), | |
| 44 super(src, width, height) { | |
| 45 } | |
| 46 | |
| 47 final String _src; | |
| 48 final Size _startingSize; | |
| 49 double lastX = null; | |
| 50 double lastY = null; | |
| 51 double growX = 0.0; | |
| 52 double growY = 0.0; | |
| 53 double swipeSize = 0.0; | |
| 54 | |
| 55 void handlePointer(PointerEvent event) { | |
| 56 if (event.type == 'pointermove') { | |
| 57 growX = clamp(min: 0.0, value: growX + event.x - lastX); | |
| 58 growY = clamp(min: 0.0, value: growY + event.y - lastY); | |
|
abarth-chromium
2015/06/03 00:16:30
Rather than using clamp, you can just use math.max
jackson
2015/06/03 17:41:43
Done.
| |
| 59 double newWidth = _startingSize.width == null ? null : _startingSize.width + growX; | |
| 60 double newHeight = _startingSize.height == null ? null : _startingSize.hei ght + growY; | |
| 61 configure(_src, newWidth, newHeight); | |
|
abarth-chromium
2015/06/03 00:16:31
This leans pretty heavily on the image cache. Sho
jackson
2015/06/03 17:41:43
Done.
| |
| 62 markNeedsLayout(); | |
|
abarth-chromium
2015/06/03 00:16:31
This class shouldn't need to markNeedsLayout here.
jackson
2015/06/03 17:41:43
Done.
| |
| 63 } | |
| 64 lastX = event.x; | |
| 65 lastY = event.y; | |
|
abarth-chromium
2015/06/03 00:16:31
This code will get really confused by multitouch.
jackson
2015/06/03 17:41:43
Done.
jackson
2015/06/03 22:06:25
Done.
| |
| 66 } | |
| 67 } | |
| 68 | |
| 69 AppView app; | |
| 70 RenderDecoratedBox root; | |
| 71 | |
| 72 void main() { | |
| 73 RenderFlex flexRoot = new RenderFlex(direction: FlexDirection.Vertical); | |
| 74 | |
| 75 root = new RenderDecoratedBox( | |
| 76 decoration: new BoxDecoration(backgroundColor: 0xFF333333), | |
| 77 child: flexRoot | |
| 78 ); | |
| 79 | |
| 80 void addFlexChildSolidColor(RenderFlex parent, int backgroundColor, { int flex : 0 }) { | |
| 81 RenderSolidColor child = new RenderSolidColor(backgroundColor); | |
| 82 parent.add(child); | |
| 83 child.parentData.flex = flex; | |
| 84 } | |
| 85 | |
| 86 // Yellow bar at top | |
| 87 addFlexChildSolidColor(flexRoot, 0xFFFFFF00, flex: 1); | |
| 88 | |
| 89 var row = new RenderFlex(direction: FlexDirection.Horizontal); | |
| 90 | |
| 91 // Purple cell | |
| 92 addFlexChildSolidColor(row, 0xFF0000FF, flex: 1); | |
| 93 | |
| 94 // Resizeable image | |
| 95 RenderImage image1 = new RenderImageResizable("https://www.dartlang.org/logos/ dart-logo.png", 100.0, 100.0); | |
|
abarth-chromium
2015/06/03 00:16:30
image1 <--- is there another image?
jackson
2015/06/03 17:41:43
Done.
| |
| 96 row.add(new RenderPadding(const EdgeDims(10.0, 10.0, 10.0, 10.0), image1)); | |
|
abarth-chromium
2015/06/03 00:16:31
const EdgeDims.all(10.0)
jackson
2015/06/03 17:41:43
Done.
| |
| 97 | |
| 98 // The internet is a beautiful place. https://baconipsum.com/ | |
| 99 String meatyString = """Bacon ipsum dolor amet ham fatback tri-tip, prosciutto | |
| 100 porchetta bacon kevin meatball meatloaf pig beef ribs chicken. Brisket ribeye | |
| 101 andouille leberkas capicola meatloaf. Chicken pig ball tip pork picanha bresaola | |
| 102 alcatra. Pork pork belly alcatra, flank chuck drumstick biltong doner jowl. | |
| 103 Pancetta meatball tongue tenderloin rump tail jowl boudin."""; | |
| 104 RenderParagraph paragraph = new RenderParagraph(text: meatyString, color: 0xFF 009900); | |
| 105 row.add(paragraph); | |
| 106 paragraph.parentData.flex = 2; | |
| 107 | |
| 108 var decoratedRow = new RenderDecoratedBox( | |
| 109 decoration: new BoxDecoration(backgroundColor: 0xFFFFFFFF), | |
| 110 child: row | |
| 111 ); | |
| 112 | |
| 113 flexRoot.add(decoratedRow); | |
| 114 decoratedRow.parentData.flex = 3; | |
| 115 app = new AppView(root); | |
| 116 } | |
| OLD | NEW |