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

Side by Side Diff: sky/examples/color/color-wheel.sky

Issue 897683002: Extend the sky color picker example (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 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 | « sky/examples/color/color-samples.sky ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!-- 1 <!--
2 // Copyright 2015 The Chromium Authors. All rights reserved. 2 // Copyright 2015 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be 3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file. 4 // found in the LICENSE file.
5 --> 5 -->
6 <import src="/sky/framework/sky-element/sky-element.sky" as="SkyElement" /> 6 <import src="/sky/framework/sky-element/sky-element.sky" as="SkyElement" />
7 7
8 <sky-element name="color-wheel" 8 <sky-element name="color-wheel"
9 attributes="color:string" 9 attributes="color:string"
10 on-pointerdown="handlePointerDown" 10 on-pointerdown="handlePointerDown">
11 on-pointermove="handlePointerMove">
12 <template> 11 <template>
13 <style> 12 <style>
14 img { 13 img {
15 min-width: 100%; 14 min-width: 100%;
16 height: auto; 15 height: auto;
17 } 16 }
18 </style> 17 </style>
19 <img class="color-wheel-img" src="color-wheel.png"> 18 <img class="color-wheel-img" src="color-wheel.png">
20 </template> 19 </template>
21 <script> 20 <script>
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 } 57 }
59 58
60 function rgbToString(rgb) { 59 function rgbToString(rgb) {
61 return "#" + toHexString(rgb.r) + toHexString(rgb.g) + toHexString(rgb.b); 60 return "#" + toHexString(rgb.r) + toHexString(rgb.g) + toHexString(rgb.b);
62 } 61 }
63 62
64 module.exports = class extends SkyElement { 63 module.exports = class extends SkyElement {
65 created() { 64 created() {
66 super.created(); 65 super.created();
67 this.color = "#xFF00FF"; 66 this.color = "#xFF00FF";
67 this.colorChanged = function() {
68 this.dispatchEvent(new CustomEvent('color-change', {
69 bubbles: true,
70 detail: this.color,
71 }));
72 };
68 } 73 }
69 updateColor(event) { 74 updateColor(event) {
70 var bounds = event.target.getBoundingClientRect(); 75 var bounds = event.target.getBoundingClientRect();
71 var x = event.x - bounds.left; 76 var x = event.x - bounds.left;
72 var y = event.y - bounds.top; 77 var y = event.y - bounds.top;
73 var radius = Math.min(bounds.width, bounds.height) / 2.0; 78 var radius = Math.min(bounds.width, bounds.height) / 2.0;
74 var rgb = xyToRgb(x, y, radius); 79 var rgb = xyToRgb(x, y, radius);
75 if (rgb) 80 if (rgb)
76 this.color = rgbToString(rgb); 81 this.color = rgbToString(rgb);
77 } 82 }
78 handlePointerDown(event) { 83 handlePointerDown(event) {
79 this.updateColor(event); 84 this.updateColor(event);
80 } 85 }
81 handlePointerMove(event) {
82 this.updateColor(event);
83 }
84 }.register(); 86 }.register();
85 </script> 87 </script>
86 </sky-element> 88 </sky-element>
OLDNEW
« no previous file with comments | « sky/examples/color/color-samples.sky ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698