| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 } | 53 } |
| 54 | 54 |
| 55 class PopupMenu extends AnimatedComponent { | 55 class PopupMenu extends AnimatedComponent { |
| 56 | 56 |
| 57 PopupMenu({ String 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 watch(controller.position); |
| 64 animate(controller.position, (double value) { | |
| 65 _position = value; | |
| 66 }); | |
| 67 } | 64 } |
| 68 | 65 |
| 69 PopupMenuController controller; | 66 PopupMenuController controller; |
| 70 List<Widget> items; | 67 List<Widget> items; |
| 71 int level; | 68 int level; |
| 72 | 69 |
| 73 void syncFields(PopupMenu source) { | 70 void syncFields(PopupMenu source) { |
| 74 controller = source.controller; | 71 controller = source.controller; |
| 75 items = source.items; | 72 items = source.items; |
| 76 level = source.level; | 73 level = source.level; |
| 77 _painter = source._painter; | 74 _painter = source._painter; |
| 78 super.syncFields(source); | 75 super.syncFields(source); |
| 79 } | 76 } |
| 80 | 77 |
| 81 double _position; | |
| 82 BoxPainter _painter; | 78 BoxPainter _painter; |
| 83 | 79 |
| 84 double _opacityFor(int i) { | 80 double _opacityFor(int i) { |
| 85 if (_position == null || _position == 1.0) | 81 if (controller.position.value == null || controller.position.value == 1.0) |
| 86 return 1.0; | 82 return 1.0; |
| 87 double unit = 1.0 / items.length; | 83 double unit = 1.0 / items.length; |
| 88 double duration = 1.5 * unit; | 84 double duration = 1.5 * unit; |
| 89 double start = i * unit; | 85 double start = i * unit; |
| 90 return math.max(0.0, math.min(1.0, (_position - start) / duration)); | 86 return math.max(0.0, math.min(1.0, (controller.position.value - start) / dur
ation)); |
| 91 } | 87 } |
| 92 | 88 |
| 93 Widget build() { | 89 Widget build() { |
| 94 int i = 0; | 90 int i = 0; |
| 95 List<Widget> children = new List.from(items.map((Widget item) { | 91 List<Widget> children = new List.from(items.map((Widget item) { |
| 96 double opacity = _opacityFor(i); | 92 double opacity = _opacityFor(i); |
| 97 return new PopupMenuItem(child: item, opacity: opacity); | 93 return new PopupMenuItem(child: item, opacity: opacity); |
| 98 })); | 94 })); |
| 99 | 95 |
| 100 return new Opacity( | 96 return new Opacity( |
| 101 opacity: math.min(1.0, _position * 3.0), | 97 opacity: math.min(1.0, controller.position.value * 3.0), |
| 102 child: new ShrinkWrapWidth( | 98 child: new ShrinkWrapWidth( |
| 103 child: new CustomPaint( | 99 child: new CustomPaint( |
| 104 callback: (sky.Canvas canvas, Size size) { | 100 callback: (sky.Canvas canvas, Size size) { |
| 105 double width = math.min(size.width, size.width * (0.5 + _position *
2.0)); | 101 double width = math.min(size.width, size.width * (0.5 + controller.p
osition.value * 2.0)); |
| 106 double height = math.min(size.height, size.height * _position * 1.5)
; | 102 double height = math.min(size.height, size.height * controller.posit
ion.value * 1.5); |
| 107 _painter.paint(canvas, new Rect.fromLTRB(size.width - width, 0.0, wi
dth, height)); | 103 _painter.paint(canvas, new Rect.fromLTRB(size.width - width, 0.0, wi
dth, height)); |
| 108 }, | 104 }, |
| 109 child: new Container( | 105 child: new Container( |
| 110 padding: const EdgeDims.all(8.0), | 106 padding: const EdgeDims.all(8.0), |
| 111 child: new Block(children) | 107 child: new Block(children) |
| 112 ) | 108 ) |
| 113 ) | 109 ) |
| 114 ) | 110 ) |
| 115 ); | 111 ); |
| 116 } | 112 } |
| 117 | 113 |
| 118 } | 114 } |
| OLD | NEW |