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

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

Issue 1235443002: Support for icon theming (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: fix analyzer warning 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
« no previous file with comments | « sky/sdk/lib/widgets/menu_item.dart ('k') | sky/sdk/lib/widgets/tool_bar.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 'dart:math' as math; 5 import 'dart:math' as math;
6 6
7 import 'package:sky/animation/generators.dart'; 7 import 'package:sky/animation/generators.dart';
8 import 'package:sky/animation/mechanics.dart'; 8 import 'package:sky/animation/mechanics.dart';
9 import 'package:sky/animation/scroll_behavior.dart'; 9 import 'package:sky/animation/scroll_behavior.dart';
10 import 'package:sky/painting/text_style.dart'; 10 import 'package:sky/painting/text_style.dart';
11 import 'package:sky/rendering/box.dart'; 11 import 'package:sky/rendering/box.dart';
12 import 'package:sky/rendering/object.dart'; 12 import 'package:sky/rendering/object.dart';
13 import 'package:vector_math/vector_math.dart'; 13 import 'package:vector_math/vector_math.dart';
14 import 'package:sky/theme/colors.dart' as colors; 14 import 'package:sky/theme/colors.dart' as colors;
15 import 'package:sky/theme/typography.dart' as typography;
15 import 'package:sky/widgets/basic.dart'; 16 import 'package:sky/widgets/basic.dart';
17 import 'package:sky/widgets/default_text_style.dart';
16 import 'package:sky/widgets/icon.dart'; 18 import 'package:sky/widgets/icon.dart';
17 import 'package:sky/widgets/ink_well.dart'; 19 import 'package:sky/widgets/ink_well.dart';
18 import 'package:sky/widgets/scrollable.dart'; 20 import 'package:sky/widgets/scrollable.dart';
19 import 'package:sky/widgets/theme.dart'; 21 import 'package:sky/widgets/theme.dart';
20 import 'package:sky/widgets/widget.dart'; 22 import 'package:sky/widgets/widget.dart';
21 23
22 typedef void SelectedIndexChanged(int selectedIndex); 24 typedef void SelectedIndexChanged(int selectedIndex);
23 typedef void LayoutChanged(Size size, List<double> widths); 25 typedef void LayoutChanged(Size size, List<double> widths);
24 26
25 // See https://www.google.com/design/spec/components/tabs.html#tabs-specs 27 // See https://www.google.com/design/spec/components/tabs.html#tabs-specs
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 this.selected: false 296 this.selected: false
295 }) : super(key: key) { 297 }) : super(key: key) {
296 assert(label.text != null || label.icon != null); 298 assert(label.text != null || label.icon != null);
297 } 299 }
298 300
299 final TabLabel label; 301 final TabLabel label;
300 final bool selected; 302 final bool selected;
301 303
302 Widget _buildLabelText() { 304 Widget _buildLabelText() {
303 assert(label.text != null); 305 assert(label.text != null);
304 TextStyle textStyle = Theme.of(this).toolbarText.button.merge(_kTabTextStyle ); 306 return new Text(label.text, style: _kTabTextStyle);
305 return new Text(label.text, style: textStyle);
306 } 307 }
307 308
308 Widget _buildLabelIcon() { 309 Widget _buildLabelIcon() {
309 assert(label.icon != null); 310 assert(label.icon != null);
310 return new Icon(type: label.icon, size: _kTabIconSize); 311 return new Icon(type: label.icon, size: _kTabIconSize);
311 } 312 }
312 313
313 Widget build() { 314 Widget build() {
314 Widget labelContents; 315 Widget labelContents;
315 if (label.icon == null) { 316 if (label.icon == null) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 assert(labels != null && labels.isNotEmpty); 428 assert(labels != null && labels.isNotEmpty);
428 List<Widget> tabs = <Widget>[]; 429 List<Widget> tabs = <Widget>[];
429 bool textAndIcons = false; 430 bool textAndIcons = false;
430 int tabIndex = 0; 431 int tabIndex = 0;
431 for (TabLabel label in labels) { 432 for (TabLabel label in labels) {
432 tabs.add(_toTab(label, tabIndex++)); 433 tabs.add(_toTab(label, tabIndex++));
433 if (label.text != null && label.icon != null) 434 if (label.text != null && label.icon != null)
434 textAndIcons = true; 435 textAndIcons = true;
435 } 436 }
436 437
437 Color backgroundColor = Theme.of(this).primaryColor; 438 ThemeData themeData = Theme.of(this);
438 Color indicatorColor = Theme.of(this).accentColor; 439 Color backgroundColor = themeData.primaryColor;
440 Color indicatorColor = themeData.accentColor;
439 if (indicatorColor == backgroundColor) { 441 if (indicatorColor == backgroundColor) {
440 indicatorColor = colors.White; 442 indicatorColor = colors.White;
441 } 443 }
442 444
443 TabBarWrapper tabBarWrapper = new TabBarWrapper( 445 TextStyle textStyle;
444 children: tabs, 446 IconThemeColor iconThemeColor;
445 selectedIndex: selectedIndex, 447 switch (themeData.primaryColorBrightness) {
446 backgroundColor: backgroundColor, 448 case ThemeBrightness.light:
447 indicatorColor: indicatorColor, 449 textStyle = typography.black.body1;
448 textAndIcons: textAndIcons, 450 iconThemeColor = IconThemeColor.black;
449 scrollable: scrollable, 451 break;
450 onLayoutChanged: scrollable ? _layoutChanged : null 452 case ThemeBrightness.dark:
451 ); 453 textStyle = typography.white.body1;
454 iconThemeColor = IconThemeColor.white;
455 break;
456 }
452 457
453 Matrix4 transform = new Matrix4.identity(); 458 Matrix4 transform = new Matrix4.identity();
454 transform.translate(-scrollOffset, 0.0); 459 transform.translate(-scrollOffset, 0.0);
455 return new Transform(child: tabBarWrapper, transform: transform); 460
461 return new Transform(
462 transform: transform,
463 child: new IconTheme(
464 data: new IconThemeData(color: iconThemeColor),
465 child: new DefaultTextStyle(
466 style: textStyle,
467 child: new TabBarWrapper(
468 children: tabs,
469 selectedIndex: selectedIndex,
470 backgroundColor: backgroundColor,
471 indicatorColor: indicatorColor,
472 textAndIcons: textAndIcons,
473 scrollable: scrollable,
474 onLayoutChanged: scrollable ? _layoutChanged : null
475 )
476 )
477 )
478 );
456 } 479 }
457 } 480 }
458 481
459 class TabNavigatorView { 482 class TabNavigatorView {
460 TabNavigatorView({ this.label, this.builder }); 483 TabNavigatorView({ this.label, this.builder });
461 484
462 final TabLabel label; 485 final TabLabel label;
463 final Builder builder; 486 final Builder builder;
464 487
465 Widget buildContent() { 488 Widget buildContent() {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 selectedIndex: selectedIndex, 522 selectedIndex: selectedIndex,
500 scrollable: scrollable 523 scrollable: scrollable
501 ); 524 );
502 525
503 Widget content = views[selectedIndex].buildContent(); 526 Widget content = views[selectedIndex].buildContent();
504 return new Flex([tabBar, new Flexible(child: content)], 527 return new Flex([tabBar, new Flexible(child: content)],
505 direction: FlexDirection.vertical 528 direction: FlexDirection.vertical
506 ); 529 );
507 } 530 }
508 } 531 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/widgets/menu_item.dart ('k') | sky/sdk/lib/widgets/tool_bar.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698