OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 import 'dart:sky' as sky; |
| 6 |
5 import 'package:sky/mojo/asset_bundle.dart'; | 7 import 'package:sky/mojo/asset_bundle.dart'; |
6 import 'package:sky/widgets/basic.dart'; | 8 import 'package:sky/widgets/basic.dart'; |
7 import 'package:sky/widgets/theme.dart'; | 9 import 'package:sky/widgets/theme.dart'; |
8 import 'package:sky/widgets/widget.dart'; | 10 import 'package:sky/widgets/widget.dart'; |
9 | 11 |
10 enum IconThemeColor { white, black } | 12 enum IconThemeColor { white, black } |
11 | 13 |
12 class IconThemeData { | 14 class IconThemeData { |
13 const IconThemeData({ this.color }); | 15 const IconThemeData({ this.color }); |
14 final IconThemeColor color; | 16 final IconThemeColor color; |
(...skipping 24 matching lines...) Expand all Loading... |
39 AssetBundle _initIconBundle() { | 41 AssetBundle _initIconBundle() { |
40 if (rootBundle != null) | 42 if (rootBundle != null) |
41 return rootBundle; | 43 return rootBundle; |
42 const String _kAssetBase = '/packages/sky/assets/material-design-icons/'; | 44 const String _kAssetBase = '/packages/sky/assets/material-design-icons/'; |
43 return new NetworkAssetBundle(Uri.base.resolve(_kAssetBase)); | 45 return new NetworkAssetBundle(Uri.base.resolve(_kAssetBase)); |
44 } | 46 } |
45 | 47 |
46 final AssetBundle _iconBundle = _initIconBundle(); | 48 final AssetBundle _iconBundle = _initIconBundle(); |
47 | 49 |
48 class Icon extends Component { | 50 class Icon extends Component { |
49 Icon({ String key, this.size, this.type: '', this.color }) : super(key: key); | 51 Icon({ |
| 52 String key, |
| 53 this.size, |
| 54 this.type: '', |
| 55 this.color, |
| 56 this.colorFilter |
| 57 }) : super(key: key); |
50 | 58 |
51 final int size; | 59 final int size; |
52 final String type; | 60 final String type; |
53 final IconThemeColor color; | 61 final IconThemeColor color; |
| 62 final sky.ColorFilter colorFilter; |
54 | 63 |
55 String get colorSuffix { | 64 String get colorSuffix { |
56 IconThemeColor iconThemeColor = color; | 65 IconThemeColor iconThemeColor = color; |
57 if (iconThemeColor == null) { | 66 if (iconThemeColor == null) { |
58 IconThemeData iconThemeData = IconTheme.of(this); | 67 IconThemeData iconThemeData = IconTheme.of(this); |
59 iconThemeColor = iconThemeData == null ? null : iconThemeData.color; | 68 iconThemeColor = iconThemeData == null ? null : iconThemeData.color; |
60 } | 69 } |
61 if (iconThemeColor == null) { | 70 if (iconThemeColor == null) { |
62 ThemeBrightness themeBrightness = Theme.of(this).brightness; | 71 ThemeBrightness themeBrightness = Theme.of(this).brightness; |
63 iconThemeColor = themeBrightness == ThemeBrightness.dark ? IconThemeColor.
white : IconThemeColor.black; | 72 iconThemeColor = themeBrightness == ThemeBrightness.dark ? IconThemeColor.
white : IconThemeColor.black; |
(...skipping 13 matching lines...) Expand all Loading... |
77 if (parts.length == 2) { | 86 if (parts.length == 2) { |
78 category = parts[0]; | 87 category = parts[0]; |
79 subtype = parts[1]; | 88 subtype = parts[1]; |
80 } | 89 } |
81 // TODO(eseidel): This clearly isn't correct. Not sure what would be. | 90 // TODO(eseidel): This clearly isn't correct. Not sure what would be. |
82 // Should we use the ios images on ios? | 91 // Should we use the ios images on ios? |
83 String density = 'drawable-xxhdpi'; | 92 String density = 'drawable-xxhdpi'; |
84 return new AssetImage( | 93 return new AssetImage( |
85 bundle: _iconBundle, | 94 bundle: _iconBundle, |
86 name: '${category}/${density}/ic_${subtype}_${colorSuffix}_${size}dp.png', | 95 name: '${category}/${density}/ic_${subtype}_${colorSuffix}_${size}dp.png', |
87 size: new Size(size.toDouble(), size.toDouble()) | 96 size: new Size(size.toDouble(), size.toDouble()), |
| 97 colorFilter: colorFilter |
88 ); | 98 ); |
89 } | 99 } |
90 } | 100 } |
OLD | NEW |