| 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 'dart:math' as math; | 6 import 'dart:math' as math; |
| 7 | 7 |
| 8 import 'package:sky/mojo/net/image_cache.dart' as image_cache; |
| 8 import 'package:sky/painting/text_style.dart'; | 9 import 'package:sky/painting/text_style.dart'; |
| 9 import 'package:sky/rendering/box.dart'; | 10 import 'package:sky/rendering/box.dart'; |
| 10 import 'package:sky/rendering/flex.dart'; | 11 import 'package:sky/rendering/flex.dart'; |
| 11 import 'package:sky/rendering/object.dart'; | 12 import 'package:sky/rendering/object.dart'; |
| 12 import 'package:sky/rendering/paragraph.dart'; | 13 import 'package:sky/rendering/paragraph.dart'; |
| 13 import 'package:sky/rendering/sky_binding.dart'; | 14 import 'package:sky/rendering/sky_binding.dart'; |
| 14 | 15 |
| 15 import 'solid_color_box.dart'; | 16 import 'solid_color_box.dart'; |
| 16 | 17 |
| 17 class Touch { | 18 class Touch { |
| 18 final double x; | 19 final double x; |
| 19 final double y; | 20 final double y; |
| 20 const Touch(this.x, this.y); | 21 const Touch(this.x, this.y); |
| 21 } | 22 } |
| 22 | 23 |
| 23 class RenderImageGrow extends RenderImage { | 24 class RenderImageGrow extends RenderImage { |
| 24 final Size _startingSize; | 25 final Size _startingSize; |
| 25 | 26 |
| 26 RenderImageGrow(String src, Size size) : _startingSize = size, super(src, size
); | 27 RenderImageGrow(Image image, Size size) : _startingSize = size, super(image, s
ize); |
| 27 | 28 |
| 28 double _growth = 0.0; | 29 double _growth = 0.0; |
| 29 double get growth => _growth; | 30 double get growth => _growth; |
| 30 void set growth(double value) { | 31 void set growth(double value) { |
| 31 _growth = value; | 32 _growth = value; |
| 32 double newWidth = _startingSize.width == null ? null : _startingSize.width +
growth; | 33 double newWidth = _startingSize.width == null ? null : _startingSize.width +
growth; |
| 33 double newHeight = _startingSize.height == null ? null : _startingSize.heigh
t + growth; | 34 double newHeight = _startingSize.height == null ? null : _startingSize.heigh
t + growth; |
| 34 requestedSize = new Size(newWidth, newHeight); | 35 requestedSize = new Size(newWidth, newHeight); |
| 35 } | 36 } |
| 36 } | 37 } |
| 37 | 38 |
| 38 RenderImageGrow image; | 39 RenderImageGrow image; |
| 39 | 40 |
| 40 Map<int, Touch> touches = new Map(); | 41 Map<int, Touch> touches = new Map(); |
| 41 void handleEvent(event) { | 42 void handleEvent(event) { |
| 42 if (event is PointerEvent) { | 43 if (event is PointerEvent) { |
| 43 if (event.type == 'pointermove') | 44 if (event.type == 'pointermove') |
| 44 image.growth = math.max(0.0, image.growth + event.x - touches[event.poin
ter].x); | 45 image.growth = math.max(0.0, image.growth + event.x - touches[event.pointe
r].x); |
| 45 touches[event.pointer] = new Touch(event.x, event.y); | 46 touches[event.pointer] = new Touch(event.x, event.y); |
| 46 } | 47 } |
| 47 } | 48 } |
| 48 | 49 |
| 49 void main() { | 50 void main() { |
| 50 void addFlexChildSolidColor(RenderFlex parent, Color backgroundColor, { int fl
ex: 0 }) { | 51 void addFlexChildSolidColor(RenderFlex parent, Color backgroundColor, { int fl
ex: 0 }) { |
| 51 RenderSolidColorBox child = new RenderSolidColorBox(backgroundColor); | 52 RenderSolidColorBox child = new RenderSolidColorBox(backgroundColor); |
| 52 parent.add(child); | 53 parent.add(child); |
| 53 child.parentData.flex = flex; | 54 child.parentData.flex = flex; |
| 54 } | 55 } |
| 55 | 56 |
| 56 var row = new RenderFlex(direction: FlexDirection.horizontal); | 57 var row = new RenderFlex(direction: FlexDirection.horizontal); |
| 57 | 58 |
| 58 // Left cell | 59 // Left cell |
| 59 addFlexChildSolidColor(row, const Color(0xFF00D2B8), flex: 1); | 60 addFlexChildSolidColor(row, const Color(0xFF00D2B8), flex: 1); |
| 60 | 61 |
| 61 // Resizeable image | 62 // Resizeable image |
| 62 image = new RenderImageGrow("https://www.dartlang.org/logos/dart-logo.png", | 63 image = new RenderImageGrow(null, new Size(100.0, null)); |
| 63 new Size(100.0, null)); | 64 image_cache.load("https://www.dartlang.org/logos/dart-logo.png").then((Image d
artLogo) { |
| 65 image.image = dartLogo; |
| 66 }); |
| 67 |
| 64 var padding = new RenderPadding(padding: const EdgeDims.all(10.0), child: imag
e); | 68 var padding = new RenderPadding(padding: const EdgeDims.all(10.0), child: imag
e); |
| 65 row.add(padding); | 69 row.add(padding); |
| 66 | 70 |
| 67 RenderFlex column = new RenderFlex(direction: FlexDirection.vertical); | 71 RenderFlex column = new RenderFlex(direction: FlexDirection.vertical); |
| 68 | 72 |
| 69 // Top cell | 73 // Top cell |
| 70 addFlexChildSolidColor(column, const Color(0xFF55DDCA), flex: 1); | 74 addFlexChildSolidColor(column, const Color(0xFF55DDCA), flex: 1); |
| 71 | 75 |
| 72 // The internet is a beautiful place. https://baconipsum.com/ | 76 // The internet is a beautiful place. https://baconipsum.com/ |
| 73 String meatyString = """Bacon ipsum dolor amet ham fatback tri-tip, prosciutto | 77 String meatyString = """Bacon ipsum dolor amet ham fatback tri-tip, prosciutto |
| (...skipping 16 matching lines...) Expand all Loading... |
| 90 column.parentData.flex = 8; | 94 column.parentData.flex = 8; |
| 91 | 95 |
| 92 RenderDecoratedBox root = new RenderDecoratedBox( | 96 RenderDecoratedBox root = new RenderDecoratedBox( |
| 93 decoration: new BoxDecoration(backgroundColor: const Color(0xFFFFFFFF)), | 97 decoration: new BoxDecoration(backgroundColor: const Color(0xFFFFFFFF)), |
| 94 child: row | 98 child: row |
| 95 ); | 99 ); |
| 96 | 100 |
| 97 new SkyBinding(root: root); | 101 new SkyBinding(root: root); |
| 98 view.setEventCallback(handleEvent); | 102 view.setEventCallback(handleEvent); |
| 99 } | 103 } |
| OLD | NEW |