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/animation/generators.dart'; | 7 import 'package:sky/animation/generators.dart'; |
8 import 'package:sky/animation/mechanics.dart'; | 8 import 'package:sky/animation/mechanics.dart'; |
9 import 'package:sky/animation/scroll_behavior.dart'; | 9 import 'package:sky/animation/scroll_behavior.dart'; |
10 import 'package:sky/painting/text_style.dart'; | 10 import 'package:sky/painting/text_style.dart'; |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 var point = new Point( | 221 var point = new Point( |
222 selectedTab.parentData.position.x, | 222 selectedTab.parentData.position.x, |
223 _tabBarHeight - _kTabIndicatorHeight | 223 _tabBarHeight - _kTabIndicatorHeight |
224 ); | 224 ); |
225 Rect rect = (point + offset) & size; | 225 Rect rect = (point + offset) & size; |
226 canvas.drawRect(rect, new Paint()..color = indicatorColor); | 226 canvas.drawRect(rect, new Paint()..color = indicatorColor); |
227 } | 227 } |
228 | 228 |
229 void paint(PaintingCanvas canvas, Offset offset) { | 229 void paint(PaintingCanvas canvas, Offset offset) { |
230 if (backgroundColor != null) { | 230 if (backgroundColor != null) { |
231 double width = layoutWidths != null | 231 double width = layoutWidths != null |
232 ? layoutWidths.reduce((sum, width) => sum + width) | 232 ? layoutWidths.reduce((sum, width) => sum + width) |
233 : size.width; | 233 : size.width; |
234 Rect rect = offset & new Size(width, size.height); | 234 Rect rect = offset & new Size(width, size.height); |
235 canvas.drawRect(rect, new Paint()..color = backgroundColor); | 235 canvas.drawRect(rect, new Paint()..color = backgroundColor); |
236 } | 236 } |
237 | 237 |
238 int index = 0; | 238 int index = 0; |
239 RenderBox child = firstChild; | 239 RenderBox child = firstChild; |
240 while (child != null) { | 240 while (child != null) { |
241 assert(child.parentData is TabBarParentData); | 241 assert(child.parentData is TabBarParentData); |
242 canvas.paintChild(child, child.parentData.position + offset); | 242 canvas.paintChild(child, child.parentData.position + offset); |
243 if (index++ == selectedIndex) | 243 if (index++ == selectedIndex) |
244 _paintIndicator(canvas, child, offset); | 244 _paintIndicator(canvas, child, offset); |
245 child = child.parentData.nextSibling; | 245 child = child.parentData.nextSibling; |
246 } | 246 } |
247 } | 247 } |
248 } | 248 } |
249 | 249 |
250 class TabBarWrapper extends MultiChildRenderObjectWrapper { | 250 class TabBarWrapper extends MultiChildRenderObjectWrapper { |
251 TabBarWrapper({ | 251 TabBarWrapper({ |
252 List<Widget> children, | 252 List<Widget> children, |
253 this.selectedIndex, | 253 this.selectedIndex, |
254 this.backgroundColor, | 254 this.backgroundColor, |
255 this.indicatorColor, | 255 this.indicatorColor, |
256 this.textAndIcons, | 256 this.textAndIcons, |
257 this.scrollable: false, | 257 this.scrollable: false, |
258 this.onLayoutChanged, | 258 this.onLayoutChanged, |
259 String key | 259 String key |
260 }) : super(key: key, children: children); | 260 }) : super(key: key, children: children); |
261 | 261 |
262 final int selectedIndex; | 262 final int selectedIndex; |
263 final Color backgroundColor; | 263 final Color backgroundColor; |
264 final Color indicatorColor; | 264 final Color indicatorColor; |
265 final bool textAndIcons; | 265 final bool textAndIcons; |
266 final bool scrollable; | 266 final bool scrollable; |
267 final LayoutChanged onLayoutChanged; | 267 final LayoutChanged onLayoutChanged; |
268 | 268 |
269 RenderTabBar get root => super.root; | 269 RenderTabBar get root => super.root; |
270 RenderTabBar createNode() => new RenderTabBar(onLayoutChanged); | 270 RenderTabBar createNode() => new RenderTabBar(onLayoutChanged); |
271 | 271 |
272 void syncRenderObject(Widget old) { | 272 void syncRenderObject(Widget old) { |
273 super.syncRenderObject(old); | 273 super.syncRenderObject(old); |
274 root.selectedIndex = selectedIndex; | 274 root.selectedIndex = selectedIndex; |
275 root.backgroundColor = backgroundColor; | 275 root.backgroundColor = backgroundColor; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 } else if (label.text == null) { | 317 } else if (label.text == null) { |
318 labelContents = _buildLabelIcon(); | 318 labelContents = _buildLabelIcon(); |
319 } else { | 319 } else { |
320 labelContents = new Flex( | 320 labelContents = new Flex( |
321 <Widget>[ | 321 <Widget>[ |
322 new Container( | 322 new Container( |
323 child: _buildLabelIcon(), | 323 child: _buildLabelIcon(), |
324 margin: const EdgeDims.only(bottom: 10.0) | 324 margin: const EdgeDims.only(bottom: 10.0) |
325 ), | 325 ), |
326 _buildLabelText() | 326 _buildLabelText() |
327 ], | 327 ], |
328 justifyContent: FlexJustifyContent.center, | 328 justifyContent: FlexJustifyContent.center, |
329 alignItems: FlexAlignItems.center, | 329 alignItems: FlexAlignItems.center, |
330 direction: FlexDirection.vertical | 330 direction: FlexDirection.vertical |
331 ); | 331 ); |
332 } | 332 } |
333 | 333 |
334 Widget highlightedLabel = new Opacity( | 334 Widget highlightedLabel = new Opacity( |
335 child: labelContents, | 335 child: labelContents, |
336 opacity: selected ? 1.0 : 0.7 | 336 opacity: selected ? 1.0 : 0.7 |
337 ); | 337 ); |
338 | 338 |
339 Container centeredLabel = new Container( | 339 Container centeredLabel = new Container( |
340 child: new Center(child: highlightedLabel), | 340 child: new Center(child: highlightedLabel), |
341 constraints: new BoxConstraints(minWidth: _kMinTabWidth), | 341 constraints: new BoxConstraints(minWidth: _kMinTabWidth), |
342 padding: _kTabLabelPadding | 342 padding: _kTabLabelPadding |
343 ); | 343 ); |
344 | 344 |
345 return new InkWell(child: centeredLabel); | 345 return new InkWell(child: centeredLabel); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 textAndIcons = true; | 434 textAndIcons = true; |
435 } | 435 } |
436 | 436 |
437 Color backgroundColor = Theme.of(this).primaryColor; | 437 Color backgroundColor = Theme.of(this).primaryColor; |
438 Color indicatorColor = Theme.of(this).accentColor; | 438 Color indicatorColor = Theme.of(this).accentColor; |
439 if (indicatorColor == backgroundColor) { | 439 if (indicatorColor == backgroundColor) { |
440 indicatorColor = colors.White; | 440 indicatorColor = colors.White; |
441 } | 441 } |
442 | 442 |
443 TabBarWrapper tabBarWrapper = new TabBarWrapper( | 443 TabBarWrapper tabBarWrapper = new TabBarWrapper( |
444 children: tabs, | 444 children: tabs, |
445 selectedIndex: selectedIndex, | 445 selectedIndex: selectedIndex, |
446 backgroundColor: backgroundColor, | 446 backgroundColor: backgroundColor, |
447 indicatorColor: indicatorColor, | 447 indicatorColor: indicatorColor, |
448 textAndIcons: textAndIcons, | 448 textAndIcons: textAndIcons, |
449 scrollable: scrollable, | 449 scrollable: scrollable, |
450 onLayoutChanged: scrollable ? _layoutChanged : null | 450 onLayoutChanged: scrollable ? _layoutChanged : null |
451 ); | 451 ); |
452 | 452 |
453 Matrix4 transform = new Matrix4.identity(); | 453 Matrix4 transform = new Matrix4.identity(); |
454 transform.translate(-scrollOffset, 0.0); | 454 transform.translate(-scrollOffset, 0.0); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 selectedIndex: selectedIndex, | 499 selectedIndex: selectedIndex, |
500 scrollable: scrollable | 500 scrollable: scrollable |
501 ); | 501 ); |
502 | 502 |
503 Widget content = views[selectedIndex].buildContent(); | 503 Widget content = views[selectedIndex].buildContent(); |
504 return new Flex([tabBar, new Flexible(child: content)], | 504 return new Flex([tabBar, new Flexible(child: content)], |
505 direction: FlexDirection.vertical | 505 direction: FlexDirection.vertical |
506 ); | 506 ); |
507 } | 507 } |
508 } | 508 } |
OLD | NEW |