Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(433)

Side by Side Diff: sky/sdk/lib/widgets/tabs.dart

Issue 1217533002: Add RenderObject.childCount (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Moved childCount to ContainerRenderObjectMixin Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 void setupParentData(RenderBox child) { 57 void setupParentData(RenderBox child) {
58 if (child.parentData is! TabBarParentData) 58 if (child.parentData is! TabBarParentData)
59 child.parentData = new TabBarParentData(); 59 child.parentData = new TabBarParentData();
60 } 60 }
61 61
62 double getMinIntrinsicWidth(BoxConstraints constraints) { 62 double getMinIntrinsicWidth(BoxConstraints constraints) {
63 BoxConstraints widthConstraints = 63 BoxConstraints widthConstraints =
64 new BoxConstraints(maxWidth: constraints.maxWidth, maxHeight: constraint s.maxHeight); 64 new BoxConstraints(maxWidth: constraints.maxWidth, maxHeight: constraint s.maxHeight);
65 double maxWidth = 0.0; 65 double maxWidth = 0.0;
66 int childCount = 0;
67 RenderBox child = firstChild; 66 RenderBox child = firstChild;
68 while (child != null) { 67 while (child != null) {
69 maxWidth = math.max(maxWidth, child.getMinIntrinsicWidth(widthConstraints) ); 68 maxWidth = math.max(maxWidth, child.getMinIntrinsicWidth(widthConstraints) );
70 ++childCount;
71 assert(child.parentData is TabBarParentData); 69 assert(child.parentData is TabBarParentData);
72 child = child.parentData.nextSibling; 70 child = child.parentData.nextSibling;
73 } 71 }
74 return constraints.constrainWidth(maxWidth * childCount); 72 return constraints.constrainWidth(maxWidth * childCount);
75 } 73 }
76 74
77 double getMaxIntrinsicWidth(BoxConstraints constraints) { 75 double getMaxIntrinsicWidth(BoxConstraints constraints) {
78 BoxConstraints widthConstraints = 76 BoxConstraints widthConstraints =
79 new BoxConstraints(maxWidth: constraints.maxWidth, maxHeight: constraint s.maxHeight); 77 new BoxConstraints(maxWidth: constraints.maxWidth, maxHeight: constraint s.maxHeight);
80 double maxWidth = 0.0; 78 double maxWidth = 0.0;
81 int childCount = 0;
82 RenderBox child = firstChild; 79 RenderBox child = firstChild;
83 while (child != null) { 80 while (child != null) {
84 maxWidth = math.max(maxWidth, child.getMaxIntrinsicWidth(widthConstraints) ); 81 maxWidth = math.max(maxWidth, child.getMaxIntrinsicWidth(widthConstraints) );
85 ++childCount;
86 assert(child.parentData is TabBarParentData); 82 assert(child.parentData is TabBarParentData);
87 child = child.parentData.nextSibling; 83 child = child.parentData.nextSibling;
88 } 84 }
89 return constraints.constrainWidth(maxWidth * childCount); 85 return constraints.constrainWidth(maxWidth * childCount);
90 } 86 }
91 87
92 double _getIntrinsicHeight(BoxConstraints constraints) => constraints.constrai nHeight(_kTabBarHeight); 88 double _getIntrinsicHeight(BoxConstraints constraints) => constraints.constrai nHeight(_kTabBarHeight);
93 89
94 double getMinIntrinsicHeight(BoxConstraints constraints) => _getIntrinsicHeigh t(constraints); 90 double getMinIntrinsicHeight(BoxConstraints constraints) => _getIntrinsicHeigh t(constraints);
95 91
96 double getMaxIntrinsicHeight(BoxConstraints constraints) => _getIntrinsicHeigh t(constraints); 92 double getMaxIntrinsicHeight(BoxConstraints constraints) => _getIntrinsicHeigh t(constraints);
97 93
98 // TODO(hansmuller): track this value in the parent rather than computing it.
99 int _childCount() {
100 int childCount = 0;
101 RenderBox child = firstChild;
102 while (child != null) {
103 ++childCount;
104 assert(child.parentData is TabBarParentData);
105 child = child.parentData.nextSibling;
106 }
107 return childCount;
108 }
109
110 void performLayout() { 94 void performLayout() {
111 assert(constraints is BoxConstraints); 95 assert(constraints is BoxConstraints);
112 96
113 size = constraints.constrain(new Size(constraints.maxWidth, _kTabBarHeight)) ; 97 size = constraints.constrain(new Size(constraints.maxWidth, _kTabBarHeight)) ;
114 assert(!size.isInfinite); 98 assert(!size.isInfinite);
115 99
116 int childCount = _childCount();
117 if (childCount == 0) 100 if (childCount == 0)
118 return; 101 return;
119 102
120 double tabWidth = size.width / childCount; 103 double tabWidth = size.width / childCount;
121 BoxConstraints tabConstraints = 104 BoxConstraints tabConstraints =
122 new BoxConstraints.tightFor(width: tabWidth, height: size.height); 105 new BoxConstraints.tightFor(width: tabWidth, height: size.height);
123 double x = 0.0; 106 double x = 0.0;
124 RenderBox child = firstChild; 107 RenderBox child = firstChild;
125 while (child != null) { 108 while (child != null) {
126 child.layout(tabConstraints); 109 child.layout(tabConstraints);
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 return new TabBarWrapper( 266 return new TabBarWrapper(
284 children: tabs, 267 children: tabs,
285 selectedIndex: selectedIndex, 268 selectedIndex: selectedIndex,
286 backgroundColor: Theme.of(this).primary[500], 269 backgroundColor: Theme.of(this).primary[500],
287 indicatorColor: Theme.of(this).accent[200] 270 indicatorColor: Theme.of(this).accent[200]
288 ); 271 );
289 } 272 }
290 } 273 }
291 274
292 275
OLDNEW
« sky/sdk/lib/rendering/object.dart ('K') | « sky/sdk/lib/rendering/object.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698