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' as math; | |
7 | |
8 import 'package:sky/mojo/net/image_cache.dart' as image_cache; | |
9 import 'package:sky/painting/text_style.dart'; | |
10 import 'package:sky/rendering/block.dart'; | |
11 import 'package:sky/rendering/box.dart'; | |
12 import 'package:sky/rendering/flex.dart'; | |
13 import 'package:sky/rendering/object.dart'; | |
14 import 'package:sky/rendering/paragraph.dart'; | |
15 import 'package:sky/rendering/sky_binding.dart'; | |
16 | |
17 import '../lib/solid_color_box.dart'; | |
18 | |
19 class Touch { | |
20 final double x; | |
21 final double y; | |
22 const Touch(this.x, this.y); | |
23 } | |
24 | |
25 class RenderImageGrow extends RenderImage { | |
26 final Size _startingSize; | |
27 | |
28 RenderImageGrow(String src, Size size) : _startingSize = size, super(src, size
); | |
29 | |
30 double _growth = 0.0; | |
31 double get growth => _growth; | |
32 void set growth(double value) { | |
33 _growth = value; | |
34 double newWidth = _startingSize.width == null ? null : _startingSize.width +
growth; | |
35 double newHeight = _startingSize.height == null ? null : _startingSize.heigh
t + growth; | |
36 requestedSize = new Size(newWidth, newHeight); | |
37 } | |
38 } | |
39 | |
40 RenderImageGrow image; | |
41 | |
42 Map<int, Touch> touches = new Map(); | |
43 void handleEvent(event) { | |
44 if (event is PointerEvent) { | |
45 if (event.type == 'pointermove') | |
46 image.growth = math.max(0.0, image.growth + event.x - touches[event.poin
ter].x); | |
47 touches[event.pointer] = new Touch(event.x, event.y); | |
48 } | |
49 } | |
50 | |
51 void main() { | |
52 void addFlexChildSolidColor(RenderFlex parent, Color backgroundColor, { int fl
ex: 0 }) { | |
53 RenderSolidColorBox child = new RenderSolidColorBox(backgroundColor); | |
54 parent.add(child); | |
55 child.parentData.flex = flex; | |
56 } | |
57 | |
58 var row = new RenderFlex(direction: FlexDirection.horizontal); | |
59 | |
60 // Left cell | |
61 addFlexChildSolidColor(row, const Color(0xFF00D2B8), flex: 1); | |
62 | |
63 // Resizeable image | |
64 image = new RenderImageGrow("https://www.dartlang.org/logos/dart-logo.png", | |
65 new Size(100.0, null)); | |
66 var padding = new RenderPadding(padding: const EdgeDims.all(10.0), child: imag
e); | |
67 row.add(padding); | |
68 | |
69 RenderFlex column = new RenderFlex(direction: FlexDirection.vertical); | |
70 | |
71 // Top cell | |
72 addFlexChildSolidColor(column, const Color(0xFF55DDCA), flex: 1); | |
73 | |
74 // The internet is a beautiful place. https://baconipsum.com/ | |
75 String meatyString = """Bacon ipsum dolor amet ham fatback tri-tip, prosciutto | |
76 porchetta bacon kevin meatball meatloaf pig beef ribs chicken. Brisket ribeye | |
77 andouille leberkas capicola meatloaf. Chicken pig ball tip pork picanha bresaola | |
78 alcatra. Pork pork belly alcatra, flank chuck drumstick biltong doner jowl. | |
79 Pancetta meatball tongue tenderloin rump tail jowl boudin."""; | |
80 var text = new InlineStyle( | |
81 new TextStyle(color: const Color(0xFF009900)), | |
82 [new InlineText(meatyString)]); | |
83 padding = new RenderPadding( | |
84 padding: const EdgeDims.all(10.0), | |
85 child: new RenderParagraph(text)); | |
86 column.add(padding); | |
87 | |
88 // Bottom cell | |
89 addFlexChildSolidColor(column, const Color(0xFF0081C6), flex: 2); | |
90 | |
91 row.add(column); | |
92 column.parentData.flex = 8; | |
93 | |
94 RenderDecoratedBox root = new RenderDecoratedBox( | |
95 decoration: new BoxDecoration(backgroundColor: const Color(0xFFFFFFFF)), | |
96 child: row | |
97 ); | |
98 | |
99 new SkyBinding(root: root); | |
100 view.setEventCallback(handleEvent); | |
101 } | |
OLD | NEW |