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

Side by Side Diff: sky/framework/sky-icon.sky

Issue 951823002: Update Sky widgets to have more material design (Closed) Base URL: git@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/framework/sky-checkbox.sky ('k') | sky/framework/sky-input.sky » ('j') | 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-element.sky" /> 6 <import src="sky-element.sky" />
7 7
8 <sky-element attributes="type:string, size:number"> 8 <sky-element attributes="type:string, size:number">
9 <template> 9 <template>
10 <img /> 10 <img />
11 </template> 11 </template>
12 <script> 12 <script>
13 import "dart:sky"; 13 import "dart:sky";
14 14
15 const String kAssetBase = '/sky/assets/material-design-icons'; 15 const String kAssetBase = '/sky/assets/material-design-icons';
16 16
17 @Tagname('sky-icon') 17 @Tagname('sky-icon')
18 class SkyIcon extends SkyElement { 18 class SkyIcon extends SkyElement {
19 void shadowRootReady() { 19 Element _img;
20 Element img = shadowRoot.firstElementChild; 20
21 int intSize = size.floor(); 21 void _setSize(int size) {
22 img.style['height'] = '${intSize}px'; 22 _img.style['height'] = '${size}px';
23 img.style['width'] = '${intSize}px'; 23 _img.style['width'] = '${size}px';
24 }
25
26 void _setSrc(String type, int size) {
24 List<String> parts = type.split('/'); 27 List<String> parts = type.split('/');
28 if (parts.length < 2)
29 return;
25 String category = parts[0]; 30 String category = parts[0];
26 String subtype = parts[1]; 31 String subtype = parts[1];
27 img.src = '${kAssetBase}/${category}/2x_web/ic_${subtype}_${intSize}dp.png'; 32 _img.src = '${kAssetBase}/${category}/2x_web/ic_${subtype}_${size}dp.png';
33 }
34
35 void shadowRootReady() {
36 _img = shadowRoot.firstElementChild;
37 int size = this.size.floor();
38 _setSize(size);
39 _setSrc(type, size);
40 }
41
42 void typeChanged(String oldValue, String newValue) {
43 if (_img != null)
44 _setSrc(newValue, size.floor());
45 }
46
47 void sizeChanged(double oldValue, double newValue) {
48 if (_img != null)
49 _setSize(newValue.floor());
28 } 50 }
29 } 51 }
30 52
31 _init(script) => register(script, SkyIcon); 53 _init(script) => register(script, SkyIcon);
32 </script> 54 </script>
33 </sky-element> 55 </sky-element>
OLDNEW
« no previous file with comments | « sky/framework/sky-checkbox.sky ('k') | sky/framework/sky-input.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698