| 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:math' as math; | 5 import 'dart:math' as math; |
| 6 import 'dart:sky' as sky; | 6 import 'dart:sky' as sky; |
| 7 | 7 |
| 8 import 'package:sky/animation/animation_performance.dart'; | 8 import 'package:sky/animation/animation_performance.dart'; |
| 9 import 'package:sky/painting/box_painter.dart'; | 9 import 'package:sky/painting/box_painter.dart'; |
| 10 import 'package:sky/theme/colors.dart'; | 10 import 'package:sky/theme/colors.dart'; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 this.items, | 40 this.items, |
| 41 this.level | 41 this.level |
| 42 }) : super(key: key); | 42 }) : super(key: key); |
| 43 | 43 |
| 44 bool showing; | 44 bool showing; |
| 45 PopupMenuStatusChangedCallback onStatusChanged; | 45 PopupMenuStatusChangedCallback onStatusChanged; |
| 46 List<PopupMenuItem> items; | 46 List<PopupMenuItem> items; |
| 47 int level; | 47 int level; |
| 48 | 48 |
| 49 AnimatedType<double> _opacity; | 49 AnimatedType<double> _opacity; |
| 50 AnimatedType<double> _width; |
| 50 AnimatedType<double> _height; | 51 AnimatedType<double> _height; |
| 51 AnimatedType<double> _width; | |
| 52 List<AnimatedType<double>> _itemOpacities; | 52 List<AnimatedType<double>> _itemOpacities; |
| 53 AnimationPerformance _performance; | 53 AnimationPerformance _performance; |
| 54 | 54 |
| 55 void initState() { | 55 void initState() { |
| 56 _performance = new AnimationPerformance() | 56 _performance = new AnimationPerformance() |
| 57 ..addListener(_checkForStateChanged); | 57 ..addListener(_checkForStateChanged); |
| 58 _updateAnimationVariables(); | 58 _updateAnimationVariables(); |
| 59 watch(_performance); | 59 watch(_performance); |
| 60 _updateBoxPainter(); | 60 _updateBoxPainter(); |
| 61 if (showing) | 61 if (showing) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 75 level = source.level; | 75 level = source.level; |
| 76 _updateBoxPainter(); | 76 _updateBoxPainter(); |
| 77 } | 77 } |
| 78 if (items.length != source.items.length) | 78 if (items.length != source.items.length) |
| 79 _updateAnimationVariables(); | 79 _updateAnimationVariables(); |
| 80 items = source.items; | 80 items = source.items; |
| 81 super.syncFields(source); | 81 super.syncFields(source); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void _updateAnimationVariables() { | 84 void _updateAnimationVariables() { |
| 85 double unit = 1.0 / (items.length + 1); |
| 85 _opacity = new AnimatedType<double>(0.0, end: 1.0); | 86 _opacity = new AnimatedType<double>(0.0, end: 1.0); |
| 86 _width = new AnimatedType<double>(0.5, end: 1.0, interval: new Interval(0.0,
0.5)); | 87 _width = new AnimatedType<double>(0.0, end: 1.0, interval: new Interval(0.0,
unit)); |
| 87 _height = new AnimatedType<double>(0.0, end: 1.0, interval: new Interval(0.0
, 0.33)); | 88 _height = new AnimatedType<double>(0.0, end: 1.0, interval: new Interval(0.0
, 0.5)); |
| 88 _itemOpacities = new List<AnimatedType<double>>(); | 89 _itemOpacities = new List<AnimatedType<double>>(); |
| 89 double unit = 1.0 / items.length; | |
| 90 for (int i = 0; i < items.length; ++i) { | 90 for (int i = 0; i < items.length; ++i) { |
| 91 double start = i * unit; | 91 double start = (i + 1) * unit; |
| 92 double end = (start + 1.5 * unit).clamp(0.0, 1.0); | 92 double end = (start + 1.5 * unit).clamp(0.0, 1.0); |
| 93 _itemOpacities.add(new AnimatedType<double>( | 93 _itemOpacities.add(new AnimatedType<double>( |
| 94 0.0, end: 1.0, interval: new Interval(start, end))); | 94 0.0, end: 1.0, interval: new Interval(start, end))); |
| 95 } | 95 } |
| 96 List<AnimatedVariable> variables = new List<AnimatedVariable>() | 96 List<AnimatedVariable> variables = new List<AnimatedVariable>() |
| 97 ..add(_opacity) | 97 ..add(_opacity) |
| 98 ..add(_width) | 98 ..add(_width) |
| 99 ..add(_height) | 99 ..add(_height) |
| 100 ..addAll(_itemOpacities); | 100 ..addAll(_itemOpacities); |
| 101 _performance.variable = new AnimatedList(variables); | 101 _performance.variable = new AnimatedList(variables); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 })); | 139 })); |
| 140 | 140 |
| 141 return new Opacity( | 141 return new Opacity( |
| 142 opacity: math.min(1.0, _opacity.value * 3.0), | 142 opacity: math.min(1.0, _opacity.value * 3.0), |
| 143 child: new Container( | 143 child: new Container( |
| 144 margin: new EdgeDims.all(_kMenuMargin), | 144 margin: new EdgeDims.all(_kMenuMargin), |
| 145 child: new CustomPaint( | 145 child: new CustomPaint( |
| 146 callback: (sky.Canvas canvas, Size size) { | 146 callback: (sky.Canvas canvas, Size size) { |
| 147 double width = _width.value * size.width; | 147 double width = _width.value * size.width; |
| 148 double height = _height.value * size.height; | 148 double height = _height.value * size.height; |
| 149 _painter.paint(canvas, new Rect.fromLTRB(size.width - width, 0.0, wi
dth, height)); | 149 _painter.paint(canvas, new Rect.fromLTWH(size.width - width, 0.0, wi
dth, height)); |
| 150 }, | 150 }, |
| 151 child: new ConstrainedBox( | 151 child: new ConstrainedBox( |
| 152 constraints: new BoxConstraints( | 152 constraints: new BoxConstraints( |
| 153 minWidth: _kMenuMinWidth, | 153 minWidth: _kMenuMinWidth, |
| 154 maxWidth: _kMenuMaxWidth | 154 maxWidth: _kMenuMaxWidth |
| 155 ), | 155 ), |
| 156 child: new ShrinkWrapWidth( | 156 child: new ShrinkWrapWidth( |
| 157 stepWidth: _kMenuWidthStep, | 157 stepWidth: _kMenuWidthStep, |
| 158 child: new ScrollableViewport( | 158 child: new ScrollableViewport( |
| 159 child: new Container( | 159 child: new Container( |
| 160 padding: const EdgeDims.symmetric( | 160 padding: const EdgeDims.symmetric( |
| 161 horizontal: _kMenuHorizontalPadding, | 161 horizontal: _kMenuHorizontalPadding, |
| 162 vertical: _kMenuVerticalPadding | 162 vertical: _kMenuVerticalPadding |
| 163 ), | 163 ), |
| 164 child: new Block(children) | 164 child: new Block(children) |
| 165 ) | 165 ) |
| 166 ) | 166 ) |
| 167 ) | 167 ) |
| 168 ) | 168 ) |
| 169 ) | 169 ) |
| 170 ) | 170 ) |
| 171 ); | 171 ); |
| 172 } | 172 } |
| 173 | 173 |
| 174 } | 174 } |
| OLD | NEW |