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

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: Clean up the example 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
« no previous file with comments | « no previous file | sky/sdk/lib/framework/fn2.dart » ('j') | sky/sdk/lib/framework/fn2.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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';
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/render_box.dart';
10 import 'package:sky/framework/rendering/render_block.dart';
11 import 'package:sky/framework/rendering/render_node.dart';
12 import 'package:sky/framework/rendering/render_flex.dart';
13 import 'package:sky/framework/rendering/render_image.dart';
14 import 'package:sky/framework/rendering/render_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 }
39
40 class RenderImageResizable extends RenderImage {
41 RenderImageResizable(String src, double width, double height)
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);
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);
62 markNeedsLayout();
63 }
64 lastX = event.x;
65 lastY = event.y;
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);
96 row.add(new RenderPadding(const EdgeDims(10.0, 10.0, 10.0, 10.0), image1));
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 }
OLDNEW
« no previous file with comments | « no previous file | sky/sdk/lib/framework/fn2.dart » ('j') | sky/sdk/lib/framework/fn2.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698