| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 typedef void SelectHandler(String menuText); | 5 typedef void SelectHandler(String menuText); |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * This implements a horizontal menu bar with a sliding triangle arrow | 8 * This implements a horizontal menu bar with a sliding triangle arrow |
| 9 * that points at the currently selected item. | 9 * that points at the currently selected item. |
| 10 */ | 10 */ |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 final result = node.query('.sm-item.sel').previousElementSibling; | 146 final result = node.query('.sm-item.sel').previousElementSibling; |
| 147 if (result != null) { | 147 if (result != null) { |
| 148 selectItem(result, animate); | 148 selectItem(result, animate); |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 | 151 |
| 152 /** | 152 /** |
| 153 * animate - if true, then animate the movement of the triangle slider | 153 * animate - if true, then animate the movement of the triangle slider |
| 154 */ | 154 */ |
| 155 void updateIndicator(bool animate) { | 155 void updateIndicator(bool animate) { |
| 156 num x = 0; | |
| 157 if (selectedItem != null) { | 156 if (selectedItem != null) { |
| 158 // calculate where we want to put the triangle | 157 // calculate where we want to put the triangle |
| 159 x = selectedItem.offsetLeft + | 158 selectedItem.rect.then((ElementRect rect) { |
| 160 selectedItem.offsetWidth / 2 - TRIANGLE_WIDTH / 2; | 159 num x = rect.offset.left + |
| 160 rect.offset.width / 2 - TRIANGLE_WIDTH / 2; |
| 161 _moveIndicator(x, animate); |
| 162 }); |
| 163 } else { |
| 164 _moveIndicator(0, animate); |
| 161 } | 165 } |
| 166 } |
| 162 | 167 |
| 168 void _moveIndicator(num x, bool animate) { |
| 163 // find the slider filler (the div element to the left of the | 169 // find the slider filler (the div element to the left of the |
| 164 // triangle) set its width the push the triangle to where we want it. | 170 // triangle) set its width the push the triangle to where we want it. |
| 165 String duration = animate ? '.3s' : '0s'; | 171 String duration = animate ? '.3s' : '0s'; |
| 166 final triangle = node.query('.sm-triangle'); | 172 final triangle = node.query('.sm-triangle'); |
| 167 triangle.style.transitionDuration = duration; | 173 triangle.style.transitionDuration = duration; |
| 168 FxUtil.setWebkitTransform(triangle, x, 0); | 174 FxUtil.setWebkitTransform(triangle, x, 0); |
| 169 } | 175 } |
| 170 } | 176 } |
| OLD | NEW |