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: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 '../framework/animation/animated_value.dart'; | 9 import '../framework/animation/animated_value.dart'; |
10 import '../painting/box_painter.dart'; | 10 import '../painting/box_painter.dart'; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 result.complete(); | 47 result.complete(); |
48 return result.future; | 48 return result.future; |
49 } | 49 } |
50 assert(_closeState != null); | 50 assert(_closeState != null); |
51 return _closeState; | 51 return _closeState; |
52 } | 52 } |
53 } | 53 } |
54 | 54 |
55 class PopupMenu extends AnimatedComponent { | 55 class PopupMenu extends AnimatedComponent { |
56 | 56 |
57 PopupMenu({ Object key, this.controller, this.items, this.level }) | 57 PopupMenu({ String key, this.controller, this.items, this.level }) |
58 : super(key: key) { | 58 : super(key: key) { |
59 _painter = new BoxPainter(new BoxDecoration( | 59 _painter = new BoxPainter(new BoxDecoration( |
60 backgroundColor: Grey[50], | 60 backgroundColor: Grey[50], |
61 borderRadius: 2.0, | 61 borderRadius: 2.0, |
62 boxShadow: shadows[level])); | 62 boxShadow: shadows[level])); |
63 | 63 |
64 animate(controller.position, (double value) { | 64 animate(controller.position, (double value) { |
65 _position = value; | 65 _position = value; |
66 }); | 66 }); |
67 } | 67 } |
(...skipping 19 matching lines...) Expand all Loading... |
87 double unit = 1.0 / items.length; | 87 double unit = 1.0 / items.length; |
88 double duration = 1.5 * unit; | 88 double duration = 1.5 * unit; |
89 double start = i * unit; | 89 double start = i * unit; |
90 return math.max(0.0, math.min(1.0, (_position - start) / duration)); | 90 return math.max(0.0, math.min(1.0, (_position - start) / duration)); |
91 } | 91 } |
92 | 92 |
93 UINode build() { | 93 UINode build() { |
94 int i = 0; | 94 int i = 0; |
95 List<UINode> children = new List.from(items.map((List<UINode> item) { | 95 List<UINode> children = new List.from(items.map((List<UINode> item) { |
96 double opacity = _opacityFor(i); | 96 double opacity = _opacityFor(i); |
97 return new PopupMenuItem(key: i++, children: item, opacity: opacity); | 97 // TODO(abarth): Using |i| for the key here seems wrong. |
| 98 return new PopupMenuItem(key: (i++).toString(), |
| 99 children: item |
| 100 opacity: opacity); |
98 })); | 101 })); |
99 | 102 |
100 return new Opacity( | 103 return new Opacity( |
101 opacity: math.min(1.0, _position * 3.0), | 104 opacity: math.min(1.0, _position * 3.0), |
102 child: new ShrinkWrapWidth( | 105 child: new ShrinkWrapWidth( |
103 child: new CustomPaint( | 106 child: new CustomPaint( |
104 callback: (sky.Canvas canvas, Size size) { | 107 callback: (sky.Canvas canvas, Size size) { |
105 double width = math.min(size.width, size.width * (0.5 + _position *
2.0)); | 108 double width = math.min(size.width, size.width * (0.5 + _position *
2.0)); |
106 double height = math.min(size.height, size.height * _position * 1.5)
; | 109 double height = math.min(size.height, size.height * _position * 1.5)
; |
107 _painter.paint(canvas, new Rect.fromLTRB(size.width - width, 0.0, wi
dth, height)); | 110 _painter.paint(canvas, new Rect.fromLTRB(size.width - width, 0.0, wi
dth, height)); |
108 }, | 111 }, |
109 child: new Container( | 112 child: new Container( |
110 padding: const EdgeDims.all(8.0), | 113 padding: const EdgeDims.all(8.0), |
111 child: new Block(children) | 114 child: new Block(children) |
112 ) | 115 ) |
113 ) | 116 ) |
114 ) | 117 ) |
115 ); | 118 ); |
116 } | 119 } |
117 | 120 |
118 } | 121 } |
OLD | NEW |