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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } |
68 | 68 |
69 PopupMenuController controller; | 69 PopupMenuController controller; |
70 List<List<UINode>> items; | 70 List<UINode> items; |
71 int level; | 71 int level; |
72 | 72 |
73 void syncFields(PopupMenu source) { | 73 void syncFields(PopupMenu source) { |
74 controller = source.controller; | 74 controller = source.controller; |
75 items = source.items; | 75 items = source.items; |
76 level = source.level; | 76 level = source.level; |
77 _painter = source._painter; | 77 _painter = source._painter; |
78 super.syncFields(source); | 78 super.syncFields(source); |
79 } | 79 } |
80 | 80 |
81 double _position; | 81 double _position; |
82 BoxPainter _painter; | 82 BoxPainter _painter; |
83 | 83 |
84 double _opacityFor(int i) { | 84 double _opacityFor(int i) { |
85 if (_position == null || _position == 1.0) | 85 if (_position == null || _position == 1.0) |
86 return 1.0; | 86 return 1.0; |
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((UINode item) { |
96 double opacity = _opacityFor(i); | 96 double opacity = _opacityFor(i); |
97 // TODO(abarth): Using |i| for the key here seems wrong. | 97 return new PopupMenuItem(key: '${key}-${item.key}', |
98 return new PopupMenuItem(key: (i++).toString(), | 98 child: item, |
99 children: item | |
100 opacity: opacity); | 99 opacity: opacity); |
101 })); | 100 })); |
102 | 101 |
103 return new Opacity( | 102 return new Opacity( |
104 opacity: math.min(1.0, _position * 3.0), | 103 opacity: math.min(1.0, _position * 3.0), |
105 child: new ShrinkWrapWidth( | 104 child: new ShrinkWrapWidth( |
106 child: new CustomPaint( | 105 child: new CustomPaint( |
107 callback: (sky.Canvas canvas, Size size) { | 106 callback: (sky.Canvas canvas, Size size) { |
108 double width = math.min(size.width, size.width * (0.5 + _position *
2.0)); | 107 double width = math.min(size.width, size.width * (0.5 + _position *
2.0)); |
109 double height = math.min(size.height, size.height * _position * 1.5)
; | 108 double height = math.min(size.height, size.height * _position * 1.5)
; |
110 _painter.paint(canvas, new Rect.fromLTRB(size.width - width, 0.0, wi
dth, height)); | 109 _painter.paint(canvas, new Rect.fromLTRB(size.width - width, 0.0, wi
dth, height)); |
111 }, | 110 }, |
112 child: new Container( | 111 child: new Container( |
113 padding: const EdgeDims.all(8.0), | 112 padding: const EdgeDims.all(8.0), |
114 child: new Block(children) | 113 child: new Block(children) |
115 ) | 114 ) |
116 ) | 115 ) |
117 ) | 116 ) |
118 ); | 117 ); |
119 } | 118 } |
120 | 119 |
121 } | 120 } |
OLD | NEW |