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

Side by Side Diff: sky/sdk/lib/widgets/icon.dart

Issue 1235443002: Support for icon theming (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: fix tests 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
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 '../mojo/asset_bundle.dart'; 5 import '../mojo/asset_bundle.dart';
6 import 'basic.dart'; 6 import 'basic.dart';
7 import 'icon_theme.dart';
8 import 'theme.dart';
7 9
8 AssetBundle _initIconBundle() { 10 AssetBundle _initIconBundle() {
9 if (rootBundle != null) 11 if (rootBundle != null)
10 return rootBundle; 12 return rootBundle;
11 const String _kAssetBase = '/packages/sky/assets/material-design-icons/'; 13 const String _kAssetBase = '/packages/sky/assets/material-design-icons/';
12 return new NetworkAssetBundle(Uri.base.resolve(_kAssetBase)); 14 return new NetworkAssetBundle(Uri.base.resolve(_kAssetBase));
13 } 15 }
14 16
15 final AssetBundle _iconBundle = _initIconBundle(); 17 final AssetBundle _iconBundle = _initIconBundle();
16 18
17 class Icon extends Component { 19 class Icon extends Component {
18 Icon({ String key, this.size, this.type: '' }) : super(key: key); 20 Icon({ String key, this.size, this.type: '', this.color }) : super(key: key);
19 21
20 final int size; 22 final int size;
21 final String type; 23 final String type;
24 final IconThemeColor color;
25
26 String get colorSuffix {
27 IconThemeColor iconThemeColor = color;
28 if (iconThemeColor == null) {
29 IconThemeData iconThemeData = IconTheme.of(this);
30 iconThemeColor = iconThemeData == null ? null : iconThemeData.color;
31 }
32 if (iconThemeColor == null) {
33 ThemeBrightness themeBrightness = Theme.of(this).brightness;
34 iconThemeColor = themeBrightness == ThemeBrightness.dark ? IconThemeColor. white : IconThemeColor.black;
35 }
36 switch(iconThemeColor) {
37 case IconThemeColor.white:
38 return "white";
39 case IconThemeColor.black:
40 return "black";
41 }
42 }
22 43
23 Widget build() { 44 Widget build() {
24 String category = ''; 45 String category = '';
25 String subtype = ''; 46 String subtype = '';
26 List<String> parts = type.split('/'); 47 List<String> parts = type.split('/');
27 if (parts.length == 2) { 48 if (parts.length == 2) {
28 category = parts[0]; 49 category = parts[0];
29 subtype = parts[1]; 50 subtype = parts[1];
30 } 51 }
31 // TODO(eseidel): This clearly isn't correct. Not sure what would be. 52 // TODO(eseidel): This clearly isn't correct. Not sure what would be.
32 // Should we use the ios images on ios? 53 // Should we use the ios images on ios?
33 String density = 'drawable-xxhdpi'; 54 String density = 'drawable-xxhdpi';
34 return new AssetImage( 55 return new AssetImage(
35 bundle: _iconBundle, 56 bundle: _iconBundle,
36 name: '${category}/${density}/ic_${subtype}_${size}dp.png', 57 name: '${category}/${density}/ic_${subtype}_${colorSuffix}_${size}dp.png',
37 size: new Size(size.toDouble(), size.toDouble()) 58 size: new Size(size.toDouble(), size.toDouble())
38 ); 59 );
39 } 60 }
40 } 61 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698