| 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'; |
| 11 import '../theme/colors.dart'; | 11 import '../theme/colors.dart'; |
| 12 import '../theme/shadows.dart'; | 12 import '../theme/shadows.dart'; |
| 13 import 'animated_component.dart'; | 13 import 'animated_component.dart'; |
| 14 import 'basic.dart'; | 14 import 'basic.dart'; |
| 15 import 'popup_menu_item.dart'; | 15 import 'popup_menu_item.dart'; |
| 16 | 16 |
| 17 const double _kMenuOpenDuration = 300.0; | 17 const double _kMenuOpenDuration = 300.0; |
| 18 const double _kMenuCloseDuration = 200.0; | 18 const double _kMenuCloseDuration = 200.0; |
| 19 const double _kMenuCloseDelay = 100.0; | 19 const double _kMenuCloseDelay = 100.0; |
| 20 const double _kMenuWidthStep = 56.0; |
| 21 const double _kMenuMinWidth = 1.5 * _kMenuWidthStep; |
| 22 const double _kMenuHorizontalPadding = 16.0; |
| 23 const double _kMenuVerticalPadding = 8.0; |
| 20 | 24 |
| 21 enum MenuState { hidden, opening, open, closing } | 25 enum MenuState { hidden, opening, open, closing } |
| 22 | 26 |
| 23 class PopupMenuController { | 27 class PopupMenuController { |
| 24 AnimatedValue position = new AnimatedValue(0.0); | 28 AnimatedValue position = new AnimatedValue(0.0); |
| 25 MenuState _state = MenuState.hidden; | 29 MenuState _state = MenuState.hidden; |
| 26 MenuState get state => _state; | 30 MenuState get state => _state; |
| 27 | 31 |
| 28 bool get canReact => (_state == MenuState.opening) || (_state == MenuState.ope
n); | 32 bool get canReact => (_state == MenuState.opening) || (_state == MenuState.ope
n); |
| 29 | 33 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 57 PopupMenu({ String key, this.controller, this.items, this.level }) | 61 PopupMenu({ String key, this.controller, this.items, this.level }) |
| 58 : super(key: key) { | 62 : super(key: key) { |
| 59 _painter = new BoxPainter(new BoxDecoration( | 63 _painter = new BoxPainter(new BoxDecoration( |
| 60 backgroundColor: Grey[50], | 64 backgroundColor: Grey[50], |
| 61 borderRadius: 2.0, | 65 borderRadius: 2.0, |
| 62 boxShadow: shadows[level])); | 66 boxShadow: shadows[level])); |
| 63 watch(controller.position); | 67 watch(controller.position); |
| 64 } | 68 } |
| 65 | 69 |
| 66 PopupMenuController controller; | 70 PopupMenuController controller; |
| 67 List<Widget> items; | 71 List<PopupMenuItem> items; |
| 68 int level; | 72 int level; |
| 69 | 73 |
| 70 void syncFields(PopupMenu source) { | 74 void syncFields(PopupMenu source) { |
| 71 controller = source.controller; | 75 controller = source.controller; |
| 72 items = source.items; | 76 items = source.items; |
| 73 level = source.level; | 77 level = source.level; |
| 74 _painter = source._painter; | 78 _painter = source._painter; |
| 75 super.syncFields(source); | 79 super.syncFields(source); |
| 76 } | 80 } |
| 77 | 81 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 88 | 92 |
| 89 Widget build() { | 93 Widget build() { |
| 90 int i = 0; | 94 int i = 0; |
| 91 List<Widget> children = new List.from(items.map((Widget item) { | 95 List<Widget> children = new List.from(items.map((Widget item) { |
| 92 double opacity = _opacityFor(i); | 96 double opacity = _opacityFor(i); |
| 93 return new PopupMenuItem(child: item, opacity: opacity); | 97 return new PopupMenuItem(child: item, opacity: opacity); |
| 94 })); | 98 })); |
| 95 | 99 |
| 96 return new Opacity( | 100 return new Opacity( |
| 97 opacity: math.min(1.0, controller.position.value * 3.0), | 101 opacity: math.min(1.0, controller.position.value * 3.0), |
| 98 child: new ShrinkWrapWidth( | 102 child: new CustomPaint( |
| 99 child: new CustomPaint( | 103 callback: (sky.Canvas canvas, Size size) { |
| 100 callback: (sky.Canvas canvas, Size size) { | 104 double width = math.min(size.width, size.width * (0.5 + controller.pos
ition.value * 2.0)); |
| 101 double width = math.min(size.width, size.width * (0.5 + controller.p
osition.value * 2.0)); | 105 double height = math.min(size.height, size.height * controller.positio
n.value * 1.5); |
| 102 double height = math.min(size.height, size.height * controller.posit
ion.value * 1.5); | 106 _painter.paint(canvas, new Rect.fromLTRB(size.width - width, 0.0, widt
h, height)); |
| 103 _painter.paint(canvas, new Rect.fromLTRB(size.width - width, 0.0, wi
dth, height)); | 107 }, |
| 104 }, | 108 child: new ConstrainedBox( |
| 105 child: new Container( | 109 constraints: new BoxConstraints( |
| 106 padding: const EdgeDims.all(8.0), | 110 minWidth: _kMenuMinWidth |
| 107 child: new Block(children) | 111 ), |
| 112 child: new ShrinkWrapWidth( |
| 113 stepWidth: _kMenuWidthStep, |
| 114 child: new Container( |
| 115 padding: const EdgeDims.symmetric( |
| 116 horizontal: _kMenuHorizontalPadding, |
| 117 vertical: _kMenuVerticalPadding |
| 118 ), |
| 119 child: new Block(children) |
| 120 ) |
| 108 ) | 121 ) |
| 109 ) | 122 ) |
| 110 ) | 123 ) |
| 111 ); | 124 ); |
| 112 } | 125 } |
| 113 | 126 |
| 114 } | 127 } |
| OLD | NEW |