Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: sky/examples/raw/interactive_flex.dart

Issue 1160013004: Implement RenderImage and Image for Sky (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Implement code review feedback from Adam and improve demo Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 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/node.dart';
13 import 'package:sky/framework/rendering/paragraph.dart';
14 import '../lib/solid_color_box.dart';
15
16 class Touch {
17 final double x;
18 final double y;
19 const Touch(this.x, this.y);
20 }
21
22 class RenderImageGrow extends RenderImage {
23 final Size _startingSize;
24
25 RenderImageGrow(String src, Size size) : _startingSize = size, super(src, size );
26
27 double _growth = 0.0;
28 double get growth => _growth;
29 void set growth(double value) {
30 _growth = value;
31 double newWidth = _startingSize.width == null ? null : _startingSize.width + growth;
32 double newHeight = _startingSize.height == null ? null : _startingSize.heigh t + growth;
33 requestedSize = new Size(newWidth, newHeight);
34 }
35 }
36
37 AppView app;
38 RenderImageGrow image;
39
40 Map<int, Touch> touches = new Map();
41 void handleEvent(event) {
42 if (event.type == 'pointermove')
43 image.growth = math.max(0.0, image.growth + event.x - touches[event.pointer] .x);
44 if (event.type == 'pointerdown' || event.type == 'pointermove')
45 touches[event.pointer] = new Touch(event.x, event.y);
46 }
47
48 void main() {
49 void addFlexChildSolidColor(RenderFlex parent, int backgroundColor, { int flex : 0 }) {
50 RenderSolidColorBox child = new RenderSolidColorBox(backgroundColor);
51 parent.add(child);
52 child.parentData.flex = flex;
53 }
54
55 var row = new RenderFlex(direction: FlexDirection.Horizontal);
56
57 // Left cell
58 addFlexChildSolidColor(row, 0xFF00D2B8, flex: 1);
59
60 // Resizeable image
61 image = new RenderImageGrow("https://www.dartlang.org/logos/dart-logo.png",
62 new Size(100.0, null));
63 var padding = new RenderPadding(padding: const EdgeDims.all(10.0), child: imag e);
64 row.add(padding);
65
66 RenderFlex column = new RenderFlex(direction: FlexDirection.Vertical);
67
68 // Top cell
69 addFlexChildSolidColor(column, 0xFF55DDCA, flex: 1);
70
71 // The internet is a beautiful place. https://baconipsum.com/
72 String meatyString = """Bacon ipsum dolor amet ham fatback tri-tip, prosciutto
73 porchetta bacon kevin meatball meatloaf pig beef ribs chicken. Brisket ribeye
74 andouille leberkas capicola meatloaf. Chicken pig ball tip pork picanha bresaola
75 alcatra. Pork pork belly alcatra, flank chuck drumstick biltong doner jowl.
76 Pancetta meatball tongue tenderloin rump tail jowl boudin.""";
77 RenderParagraph paragraph = new RenderParagraph(text: meatyString, color: 0xFF 009900);
78 padding = new RenderPadding(padding: const EdgeDims.all(10.0), child: paragrap h);
79 column.add(padding);
80
81 // Bottom cell
82 addFlexChildSolidColor(column, 0xFF0081C6, flex: 2);
83
84 row.add(column);
85 column.parentData.flex = 8;
86
87 RenderDecoratedBox root = new RenderDecoratedBox(
88 decoration: new BoxDecoration(backgroundColor: 0xFFFFFFFF),
89 child: row
90 );
91
92 app = new AppView(root);
93 view.setEventCallback(handleEvent);
94 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698