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

Side by Side Diff: sky/examples/raw/touch-demo.sky

Issue 1218593002: Move sky/examples to sky/sdk/lib/example, and code changes to support that change. Fixes T277. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 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 #!mojo mojo:sky_viewer
2 <sky>
3 <import src="/packages/sky/framework/debug/shake-to-reload.sky" />
4 <style>
5 dot {
6 position: absolute;
7 height: 10px;
8 width: 10px;
9 background-color: #00FF00;
10 border-radius: 5px;
11 opacity: .75;
12 }
13
14 log {
15 display: paragraph;
16 margin-top: 50px;
17 }
18 </style>
19 <log>Touch the screen!</log>
20 <script>
21 import "dart:sky";
22
23 // Material design colors. :p
24 List<String> colors = [
25 "#009688",
26 "#FFC107",
27 "#9C27B0",
28 "#03A9F4",
29 "#673AB7",
30 "#CDDC39",
31 ];
32
33 Element whichDot(event) {
34 return document.querySelector('dot[id="${event.pointer}"]');
35 }
36
37 void moreDots(event) {
38 Element dot = document.createElement('dot');
39 dot.setAttribute('id', "${event.pointer}");
40 dot.style['background-color'] = colors[event.pointer.remainder(colors.length)] ;
41 document.querySelector('sky').appendChild(dot);
42 runToTheCenter(event);
43 }
44
45 void goAway(event) {
46 whichDot(event).remove();
47 }
48
49 void stopDots(event) {
50 for (Element e in document.querySelectorAll('dot'))
51 e.remove();
52 }
53
54 void runToTheCenter(event) {
55 double radius = (5 + (95 * event.pressure));
56 Element dot = whichDot(event);
57 dot.style["transform"] = "translate(${event.x-radius}px,${event.y-radius}px)";
58 dot.style["width"] = "${2 * radius}px";
59 dot.style["height"] = "${2 * radius}px";
60 dot.style["border-radius"] = "${radius}px";
61 }
62
63 void main() {
64 document.addEventListener("pointerdown", moreDots);
65 document.addEventListener("pointermove", runToTheCenter);
66 document.addEventListener("pointerup", goAway);
67 document.addEventListener("pointercancel", stopDots);
68 }
69 </script>
70 </sky>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698