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

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

Issue 1219113003: Make popup menus line up to their baseline per the Material spec. (Closed) Base URL: https://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/basic.dart ('k') | sky/sdk/lib/widgets/popup_menu_item.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:async'; 5 import 'dart:async';
6 import 'dart:math' as math; 6 import 'dart:math' as math;
7 import 'dart:sky' as sky; 7 import 'dart:sky' as sky;
8 8
9 import '../animation/animated_value.dart'; 9 import '../animation/animated_value.dart';
10 import '../painting/box_painter.dart'; 10 import '../painting/box_painter.dart';
11 import '../theme/colors.dart'; 11 import '../theme/colors.dart';
12 import '../theme/shadows.dart'; 12 import '../theme/shadows.dart';
13 import 'animated_component.dart'; 13 import 'animated_component.dart';
14 import 'basic.dart'; 14 import 'basic.dart';
15 import 'popup_menu_item.dart'; 15 import 'popup_menu_item.dart';
16 16
17 const double _kMenuOpenDuration = 300.0; 17 const double _kMenuOpenDuration = 300.0;
18 const double _kMenuCloseDuration = 200.0; 18 const double _kMenuCloseDuration = 200.0;
19 const double _kMenuCloseDelay = 100.0; 19 const double _kMenuCloseDelay = 100.0;
20 const double _kMenuWidthStep = 56.0; 20 const double _kMenuWidthStep = 56.0;
21 const double _kMenuMinWidth = 1.5 * _kMenuWidthStep; 21 const double _kMenuMargin = 16.0; // 24.0 on tablet
22 const double _kMenuMinWidth = 2.0 * _kMenuWidthStep;
23 const double _kMenuMaxWidth = 5.0 * _kMenuWidthStep;
22 const double _kMenuHorizontalPadding = 16.0; 24 const double _kMenuHorizontalPadding = 16.0;
23 const double _kMenuVerticalPadding = 8.0; 25 const double _kMenuVerticalPadding = 8.0;
24 26
25 enum MenuState { hidden, opening, open, closing } 27 enum MenuState { hidden, opening, open, closing }
26 28
27 class PopupMenuController { 29 class PopupMenuController {
28 AnimatedValue position = new AnimatedValue(0.0); 30 AnimatedValue position = new AnimatedValue(0.0);
29 MenuState _state = MenuState.hidden; 31 MenuState _state = MenuState.hidden;
30 MenuState get state => _state; 32 MenuState get state => _state;
31 33
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 controller = source.controller; 77 controller = source.controller;
76 items = source.items; 78 items = source.items;
77 level = source.level; 79 level = source.level;
78 _painter = source._painter; 80 _painter = source._painter;
79 super.syncFields(source); 81 super.syncFields(source);
80 } 82 }
81 83
82 BoxPainter _painter; 84 BoxPainter _painter;
83 85
84 double _opacityFor(int i) { 86 double _opacityFor(int i) {
87 assert(controller.position.value != null);
85 if (controller.position.value == null || controller.position.value == 1.0) 88 if (controller.position.value == null || controller.position.value == 1.0)
86 return 1.0; 89 return 1.0;
87 double unit = 1.0 / items.length; 90 double unit = 1.0 / items.length;
88 double duration = 1.5 * unit; 91 double duration = 1.5 * unit;
89 double start = i * unit; 92 double start = i * unit;
90 return math.max(0.0, math.min(1.0, (controller.position.value - start) / dur ation)); 93 return math.max(0.0, math.min(1.0, (controller.position.value - start) / dur ation));
91 } 94 }
92 95
93 Widget build() { 96 Widget build() {
94 int i = 0; 97 int i = 0;
95 List<Widget> children = new List.from(items.map((Widget item) { 98 List<Widget> children = new List.from(items.map((Widget item) {
96 double opacity = _opacityFor(i); 99 double opacity = _opacityFor(i);
97 return new PopupMenuItem(child: item, opacity: opacity); 100 return new PopupMenuItem(child: item, opacity: opacity);
98 })); 101 }));
99 102
100 return new Opacity( 103 return new Opacity(
101 opacity: math.min(1.0, controller.position.value * 3.0), 104 opacity: math.min(1.0, controller.position.value * 3.0),
102 child: new CustomPaint( 105 child: new Container(
103 callback: (sky.Canvas canvas, Size size) { 106 margin: new EdgeDims.all(_kMenuMargin),
104 double width = math.min(size.width, size.width * (0.5 + controller.pos ition.value * 2.0)); 107 child: new CustomPaint(
105 double height = math.min(size.height, size.height * controller.positio n.value * 1.5); 108 callback: (sky.Canvas canvas, Size size) {
106 _painter.paint(canvas, new Rect.fromLTRB(size.width - width, 0.0, widt h, height)); 109 double width = math.min(size.width, size.width * (0.5 + controller.p osition.value * 2.0));
107 }, 110 double height = math.min(size.height, size.height * controller.posit ion.value * 1.5);
108 child: new ConstrainedBox( 111 _painter.paint(canvas, new Rect.fromLTRB(size.width - width, 0.0, wi dth, height));
109 constraints: new BoxConstraints( 112 },
110 minWidth: _kMenuMinWidth 113 child: new ConstrainedBox(
111 ), 114 constraints: new BoxConstraints(
112 child: new ShrinkWrapWidth( 115 minWidth: _kMenuMinWidth,
113 stepWidth: _kMenuWidthStep, 116 maxWidth: _kMenuMaxWidth
114 child: new Container( 117 ),
115 padding: const EdgeDims.symmetric( 118 child: new ShrinkWrapWidth(
116 horizontal: _kMenuHorizontalPadding, 119 stepWidth: _kMenuWidthStep,
117 vertical: _kMenuVerticalPadding 120 child: new Container(
118 ), 121 padding: const EdgeDims.symmetric(
119 child: new Block(children) 122 horizontal: _kMenuHorizontalPadding,
123 vertical: _kMenuVerticalPadding
124 ),
125 child: new Block(children)
126 )
120 ) 127 )
121 ) 128 )
122 ) 129 )
123 ) 130 )
124 ); 131 );
125 } 132 }
126 133
127 } 134 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/widgets/basic.dart ('k') | sky/sdk/lib/widgets/popup_menu_item.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698