| 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 'animated_component.dart'; | 5 import 'animated_component.dart'; |
| 6 import '../animation/animated_value.dart'; | 6 import '../animation/animated_value.dart'; |
| 7 import '../fn2.dart'; | 7 import '../fn2.dart'; |
| 8 import '../theme/colors.dart'; | 8 import '../theme2/colors.dart'; |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 import 'dart:math' as math; | 10 import 'dart:math' as math; |
| 11 import 'material.dart'; | 11 import 'material.dart'; |
| 12 import 'popup_menu_item.dart'; | 12 import 'popup_menu_item.dart'; |
| 13 | 13 |
| 14 const double _kMenuOpenDuration = 300.0; | 14 const double _kMenuOpenDuration = 300.0; |
| 15 const double _kMenuCloseDuration = 200.0; | 15 const double _kMenuCloseDuration = 200.0; |
| 16 const double _kMenuCloseDelay = 100.0; | 16 const double _kMenuCloseDelay = 100.0; |
| 17 | 17 |
| 18 enum MenuState { hidden, opening, open, closing } | 18 enum MenuState { hidden, opening, open, closing } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 43 _closeState = null; | 43 _closeState = null; |
| 44 result.complete(); | 44 result.complete(); |
| 45 return result.future; | 45 return result.future; |
| 46 } | 46 } |
| 47 assert(_closeState != null); | 47 assert(_closeState != null); |
| 48 return _closeState; | 48 return _closeState; |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | 51 |
| 52 class PopupMenu extends AnimatedComponent { | 52 class PopupMenu extends AnimatedComponent { |
| 53 static final Style _style = new Style(''' | |
| 54 border-radius: 2px; | |
| 55 padding: 8px 0; | |
| 56 box-sizing: border-box; | |
| 57 background-color: ${Grey[50]};'''); | |
| 58 | |
| 59 List<List<UINode>> items; | 53 List<List<UINode>> items; |
| 60 int level; | 54 int level; |
| 61 PopupMenuController controller; | 55 PopupMenuController controller; |
| 62 | 56 |
| 63 double _position; | 57 double _position; |
| 64 int _width; | 58 // int _width; |
| 65 int _height; | 59 // int _height; |
| 66 | 60 |
| 67 PopupMenu({ Object key, this.controller, this.items, this.level }) | 61 PopupMenu({ Object key, this.controller, this.items, this.level }) |
| 68 : super(key: key) { | 62 : super(key: key) { |
| 69 animateField(controller.position, #_position); | 63 animateField(controller.position, #_position); |
| 70 onDidMount(_measureSize); | 64 // onDidMount(_measureSize); |
| 71 } | 65 } |
| 72 | 66 |
| 73 double _opacityFor(int i) { | 67 double _opacityFor(int i) { |
| 74 if (_position == null || _position == 1.0) | 68 if (_position == null || _position == 1.0) |
| 75 return null; | 69 return null; |
| 76 double unit = 1.0 / items.length; | 70 double unit = 1.0 / items.length; |
| 77 double duration = 1.5 * unit; | 71 double duration = 1.5 * unit; |
| 78 double start = i * unit; | 72 double start = i * unit; |
| 79 return math.max(0.0, math.min(1.0, (_position - start) / duration)); | 73 return math.max(0.0, math.min(1.0, (_position - start) / duration)); |
| 80 } | 74 } |
| 81 | 75 |
| 82 String _inlineStyle() { | 76 // String _inlineStyle() { |
| 83 if (_position == null || _position == 1.0 || | 77 // if (_position == null || _position == 1.0 || |
| 84 _height == null || _width == null) | 78 // _height == null || _width == null) |
| 85 return null; | 79 // return null; |
| 86 return ''' | 80 // return ''' |
| 87 opacity: ${math.min(1.0, _position * 3.0)}; | 81 // opacity: ${math.min(1.0, _position * 3.0)}; |
| 88 width: ${math.min(_width, _width * (0.5 + _position * 2.0))}px; | 82 // width: ${math.min(_width, _width * (0.5 + _position * 2.0))}px; |
| 89 height: ${math.min(_height, _height * _position * 1.5)}px;'''; | 83 // height: ${math.min(_height, _height * _position * 1.5)}px;'''; |
| 90 } | 84 // } |
| 91 | 85 |
| 92 void _measureSize() { | 86 // void _measureSize() { |
| 93 setState(() { | 87 // setState(() { |
| 94 var root = getRoot(); | 88 // var root = getRoot(); |
| 95 _width = root.width.round(); | 89 // _width = root.width.round(); |
| 96 _height = root.height.round(); | 90 // _height = root.height.round(); |
| 97 }); | 91 // }); |
| 98 } | 92 // } |
| 99 | 93 |
| 100 UINode build() { | 94 UINode build() { |
| 101 int i = 0; | 95 int i = 0; |
| 102 List<UINode> children = new List.from(items.map((List<UINode> item) { | 96 List<UINode> children = new List.from(items.map((List<UINode> item) { |
| 103 double opacity = _opacityFor(i); | 97 double opacity = _opacityFor(i); |
| 104 return new PopupMenuItem(key: i++, children: item, opacity: opacity); | 98 return new PopupMenuItem(key: i++, children: item, opacity: opacity); |
| 105 })); | 99 })); |
| 106 | 100 |
| 107 return new Material( | 101 return new Material( |
| 108 content: new Container( | 102 content: new Container( |
| 109 style: _style, | 103 padding: const EdgeDims.all(8.0), |
| 110 inlineStyle: _inlineStyle(), | 104 // border-radius: 2px |
| 111 children: children | 105 decoration: new BoxDecoration(backgroundColor: Grey[50]), |
| 106 // inlineStyle: _inlineStyle(), |
| 107 child: new BlockContainer(children: children) |
| 112 ), | 108 ), |
| 113 level: level); | 109 level: level); |
| 114 } | 110 } |
| 115 } | 111 } |
| OLD | NEW |