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

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

Issue 1241483002: Improve drawer menu items (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: 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/dialog.dart ('k') | sky/sdk/lib/widgets/tabs.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:sky' as sky;
6
5 import 'package:sky/painting/text_style.dart'; 7 import 'package:sky/painting/text_style.dart';
8 import 'package:sky/theme/colors.dart' as colors;
6 import 'package:sky/widgets/basic.dart'; 9 import 'package:sky/widgets/basic.dart';
7 import 'package:sky/widgets/button_base.dart'; 10 import 'package:sky/widgets/button_base.dart';
8 import 'package:sky/widgets/default_text_style.dart'; 11 import 'package:sky/widgets/default_text_style.dart';
9 import 'package:sky/widgets/icon.dart'; 12 import 'package:sky/widgets/icon.dart';
10 import 'package:sky/widgets/ink_well.dart'; 13 import 'package:sky/widgets/ink_well.dart';
11 import 'package:sky/widgets/theme.dart'; 14 import 'package:sky/widgets/theme.dart';
12 import 'package:sky/widgets/widget.dart'; 15 import 'package:sky/widgets/widget.dart';
13 16
14 const BoxDecoration _kHighlightDecoration = const BoxDecoration(
15 backgroundColor: const Color.fromARGB(102, 153, 153, 153)
16 );
17
18 // TODO(abarth): We shouldn't need _kHighlightBoring, but currently Container
19 // isn't smart enough to retain the components it builds when we
20 // add or remove a |decoration|. For now, we use a transparent
21 // decoration to avoid changing the structure of the tree. The
22 // right fix, however, is to make Container smarter about how it
23 // syncs its subcomponents.
24 const BoxDecoration _kHighlightBoring = const BoxDecoration(
25 backgroundColor: const Color.fromARGB(0, 0, 0, 0)
26 );
27
28 class MenuItem extends ButtonBase { 17 class MenuItem extends ButtonBase {
29 MenuItem({ String key, this.icon, this.children, this.onPressed, this.selected : false }) 18 MenuItem({ String key, this.icon, this.children, this.onPressed, this.selected : false })
30 : super(key: key); 19 : super(key: key);
31 20
32 String icon; 21 String icon;
33 List<Widget> children; 22 List<Widget> children;
34 Function onPressed; 23 Function onPressed;
35 bool selected; 24 bool selected;
36 25
37 void syncFields(MenuItem source) { 26 void syncFields(MenuItem source) {
38 icon = source.icon; 27 icon = source.icon;
39 children = source.children; 28 children = source.children;
40 onPressed = source.onPressed; 29 onPressed = source.onPressed;
41 selected = source.selected; 30 selected = source.selected;
42 super.syncFields(source); 31 super.syncFields(source);
43 } 32 }
44 33
45 TextStyle get textStyle { 34 TextStyle _textStyle(ThemeData themeData) {
Hixie 2015/07/13 23:48:22 name it using a verb?
46 TextStyle result = Theme.of(this).text.body2; 35 TextStyle result = themeData.text.body2;
47 if (highlight) 36 if (selected)
48 result = result.copyWith(color: Theme.of(this).primaryColor); 37 result = result.copyWith(color: themeData.primaryColor);
49 return result; 38 return result;
50 } 39 }
51 40
41 Color _backgroundColor(ThemeData themeData) {
42 if (highlight)
43 return themeData.highlightColor;
44 if (selected)
45 return themeData.selectedColor;
46 return colors.transparent;
47 }
48
52 Widget buildContent() { 49 Widget buildContent() {
50 ThemeData themeData = Theme.of(this);
51
53 List<Widget> flexChildren = new List<Widget>(); 52 List<Widget> flexChildren = new List<Widget>();
54 if (icon != null) { 53 if (icon != null) {
54 Widget child = new Icon(type: icon, size: 24);
55 if (selected) {
56 child = new ColorFilter(
57 color: themeData.primaryColor,
58 transferMode: sky.TransferMode.srcATop,
59 child: child
60 );
61 }
55 flexChildren.add( 62 flexChildren.add(
56 new Opacity( 63 new Opacity(
57 opacity: selected ? 1.0 : 0.45, 64 opacity: selected ? 1.0 : 0.45,
58 child: new Padding( 65 child: new Padding(
59 padding: const EdgeDims.symmetric(horizontal: 16.0), 66 padding: const EdgeDims.symmetric(horizontal: 16.0),
60 child: new Icon(type: icon, size: 24) 67 child: child
61 ) 68 )
62 ) 69 )
63 ); 70 );
64 } 71 }
65 flexChildren.add( 72 flexChildren.add(
66 new Flexible( 73 new Flexible(
67 child: new Padding( 74 child: new Padding(
68 padding: const EdgeDims.symmetric(horizontal: 16.0), 75 padding: const EdgeDims.symmetric(horizontal: 16.0),
69 child: new DefaultTextStyle( 76 child: new DefaultTextStyle(
70 style: textStyle, 77 style: _textStyle(themeData),
71 child: new Flex(children, direction: FlexDirection.horizontal) 78 child: new Flex(children, direction: FlexDirection.horizontal)
72 ) 79 )
73 ) 80 )
74 ) 81 )
75 ); 82 );
83
76 return new Listener( 84 return new Listener(
77 onGestureTap: (_) { 85 onGestureTap: (_) {
78 if (onPressed != null) 86 if (onPressed != null)
79 onPressed(); 87 onPressed();
80 }, 88 },
81 child: new Container( 89 child: new Container(
82 height: 48.0, 90 height: 48.0,
83 decoration: selected ? _kHighlightDecoration : _kHighlightBoring, 91 decoration: new BoxDecoration(backgroundColor: _backgroundColor(themeDat a)),
Hixie 2015/07/13 23:48:22 we should keep the TODO() about not including BoxD
84 child: new Container( 92 child: new InkWell(
85 decoration: highlight ? _kHighlightDecoration : _kHighlightBoring, 93 child: new Flex(flexChildren)
86 child: new InkWell(
87 child: new Flex(flexChildren)
88 )
89 ) 94 )
90 ) 95 )
91 ); 96 );
92 } 97 }
93 } 98 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/widgets/dialog.dart ('k') | sky/sdk/lib/widgets/tabs.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698