| 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 '../animation/animated_value.dart'; | 9 import '../animation/animated_value.dart'; |
| 10 import '../painting/box_painter.dart'; | 10 import '../painting/box_painter.dart'; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 backgroundColor: Grey[50], | 66 backgroundColor: Grey[50], |
| 67 borderRadius: 2.0, | 67 borderRadius: 2.0, |
| 68 boxShadow: shadows[level])); | 68 boxShadow: shadows[level])); |
| 69 watch(controller.position); | 69 watch(controller.position); |
| 70 } | 70 } |
| 71 | 71 |
| 72 PopupMenuController controller; | 72 PopupMenuController controller; |
| 73 List<PopupMenuItem> items; | 73 List<PopupMenuItem> items; |
| 74 int level; | 74 int level; |
| 75 | 75 |
| 76 @override |
| 76 void syncFields(PopupMenu source) { | 77 void syncFields(PopupMenu source) { |
| 77 controller = source.controller; | 78 controller = source.controller; |
| 78 items = source.items; | 79 items = source.items; |
| 79 level = source.level; | 80 level = source.level; |
| 80 _painter = source._painter; | 81 _painter = source._painter; |
| 81 super.syncFields(source); | 82 super.syncFields(source); |
| 82 } | 83 } |
| 83 | 84 |
| 84 BoxPainter _painter; | 85 BoxPainter _painter; |
| 85 | 86 |
| 86 double _opacityFor(int i) { | 87 double _opacityFor(int i) { |
| 87 assert(controller.position.value != null); | 88 assert(controller.position.value != null); |
| 88 if (controller.position.value == null || controller.position.value == 1.0) | 89 if (controller.position.value == null || controller.position.value == 1.0) |
| 89 return 1.0; | 90 return 1.0; |
| 90 double unit = 1.0 / items.length; | 91 double unit = 1.0 / items.length; |
| 91 double duration = 1.5 * unit; | 92 double duration = 1.5 * unit; |
| 92 double start = i * unit; | 93 double start = i * unit; |
| 93 return math.max(0.0, math.min(1.0, (controller.position.value - start) / dur
ation)); | 94 return math.max(0.0, math.min(1.0, (controller.position.value - start) / dur
ation)); |
| 94 } | 95 } |
| 95 | 96 |
| 97 @override |
| 96 Widget build() { | 98 Widget build() { |
| 97 int i = 0; | 99 int i = 0; |
| 98 List<Widget> children = new List.from(items.map((Widget item) { | 100 List<Widget> children = new List.from(items.map((Widget item) { |
| 99 double opacity = _opacityFor(i); | 101 double opacity = _opacityFor(i); |
| 100 return new PopupMenuItem(child: item, opacity: opacity); | 102 return new PopupMenuItem(child: item, opacity: opacity); |
| 101 })); | 103 })); |
| 102 | 104 |
| 103 return new Opacity( | 105 return new Opacity( |
| 104 opacity: math.min(1.0, controller.position.value * 3.0), | 106 opacity: math.min(1.0, controller.position.value * 3.0), |
| 105 child: new Container( | 107 child: new Container( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 125 child: new Block(children) | 127 child: new Block(children) |
| 126 ) | 128 ) |
| 127 ) | 129 ) |
| 128 ) | 130 ) |
| 129 ) | 131 ) |
| 130 ) | 132 ) |
| 131 ); | 133 ); |
| 132 } | 134 } |
| 133 | 135 |
| 134 } | 136 } |
| OLD | NEW |