| 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 | 6 |
| 7 import 'package:sky/rendering/box.dart'; | 7 import 'package:sky/rendering/box.dart'; |
| 8 import 'package:sky/rendering/object.dart'; | 8 import 'package:sky/rendering/object.dart'; |
| 9 import 'package:sky/widgets/basic.dart'; | 9 import 'package:sky/widgets/basic.dart'; |
| 10 import 'package:sky/widgets/icon.dart'; | 10 import 'package:sky/widgets/icon.dart'; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 child.parentData.position = new Point(x, 0.0); | 124 child.parentData.position = new Point(x, 0.0); |
| 125 x += tabWidth; | 125 x += tabWidth; |
| 126 child = child.parentData.nextSibling; | 126 child = child.parentData.nextSibling; |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 | 129 |
| 130 void hitTestChildren(HitTestResult result, { Point position }) { | 130 void hitTestChildren(HitTestResult result, { Point position }) { |
| 131 defaultHitTestChildren(result, position: position); | 131 defaultHitTestChildren(result, position: position); |
| 132 } | 132 } |
| 133 | 133 |
| 134 void _paintIndicator(RenderCanvas canvas, RenderBox selectedTab) { | 134 void _paintIndicator(RenderCanvas canvas, RenderBox selectedTab, Offset offset
) { |
| 135 if (indicatorColor == null) | 135 if (indicatorColor == null) |
| 136 return; | 136 return; |
| 137 | 137 |
| 138 var size = new Size(selectedTab.size.width, _kTabIndicatorHeight); | 138 var size = new Size(selectedTab.size.width, _kTabIndicatorHeight); |
| 139 var point = new Point( | 139 var point = new Point( |
| 140 selectedTab.parentData.position.x, | 140 selectedTab.parentData.position.x, |
| 141 _tabBarHeight - _kTabIndicatorHeight); | 141 _tabBarHeight - _kTabIndicatorHeight |
| 142 Rect rect = new Rect.fromPointAndSize(point, size); | 142 ); |
| 143 Rect rect = new Rect.fromPointAndSize(point + offset, size); |
| 143 canvas.drawRect(rect, new Paint()..color = indicatorColor); | 144 canvas.drawRect(rect, new Paint()..color = indicatorColor); |
| 144 } | 145 } |
| 145 | 146 |
| 146 void paint(RenderCanvas canvas) { | 147 void paint(RenderCanvas canvas, Offset offset) { |
| 147 if (backgroundColor != null) { | 148 if (backgroundColor != null) { |
| 148 Rect rect = new Rect.fromSize(size); | 149 Rect rect = offset + size; |
| 149 canvas.drawRect(rect, new Paint()..color = backgroundColor); | 150 canvas.drawRect(rect, new Paint()..color = backgroundColor); |
| 150 } | 151 } |
| 151 | 152 |
| 152 int index = 0; | 153 int index = 0; |
| 153 RenderBox child = firstChild; | 154 RenderBox child = firstChild; |
| 154 while (child != null) { | 155 while (child != null) { |
| 155 assert(child.parentData is TabBarParentData); | 156 assert(child.parentData is TabBarParentData); |
| 156 canvas.paintChild(child, child.parentData.position); | 157 canvas.paintChild(child, child.parentData.position + offset); |
| 157 if (index++ == selectedIndex) | 158 if (index++ == selectedIndex) |
| 158 _paintIndicator(canvas, child); | 159 _paintIndicator(canvas, child, offset); |
| 159 child = child.parentData.nextSibling; | 160 child = child.parentData.nextSibling; |
| 160 } | 161 } |
| 161 } | 162 } |
| 162 } | 163 } |
| 163 | 164 |
| 164 class TabBarWrapper extends MultiChildRenderObjectWrapper { | 165 class TabBarWrapper extends MultiChildRenderObjectWrapper { |
| 165 TabBarWrapper({ | 166 TabBarWrapper({ |
| 166 List<Widget> children, | 167 List<Widget> children, |
| 167 this.selectedIndex, | 168 this.selectedIndex, |
| 168 this.backgroundColor, | 169 this.backgroundColor, |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 } | 293 } |
| 293 return new TabBarWrapper( | 294 return new TabBarWrapper( |
| 294 children: tabs, | 295 children: tabs, |
| 295 selectedIndex: selectedIndex, | 296 selectedIndex: selectedIndex, |
| 296 backgroundColor: Theme.of(this).primary[500], | 297 backgroundColor: Theme.of(this).primary[500], |
| 297 indicatorColor: Theme.of(this).accent[200], | 298 indicatorColor: Theme.of(this).accent[200], |
| 298 textAndIcons: textAndIcons | 299 textAndIcons: textAndIcons |
| 299 ); | 300 ); |
| 300 } | 301 } |
| 301 } | 302 } |
| OLD | NEW |