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:vector_math/vector_math.dart'; | 8 import 'package:vector_math/vector_math.dart'; |
9 | 9 |
10 import '../framework/debug/utils.dart'; | 10 import '../framework/debug/utils.dart'; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 this.minHeight: 0.0, | 65 this.minHeight: 0.0, |
66 this.maxHeight: double.INFINITY | 66 this.maxHeight: double.INFINITY |
67 }); | 67 }); |
68 | 68 |
69 BoxConstraints.tight(Size size) | 69 BoxConstraints.tight(Size size) |
70 : minWidth = size.width, | 70 : minWidth = size.width, |
71 maxWidth = size.width, | 71 maxWidth = size.width, |
72 minHeight = size.height, | 72 minHeight = size.height, |
73 maxHeight = size.height; | 73 maxHeight = size.height; |
74 | 74 |
| 75 BoxConstraints.tightFor({ |
| 76 double width, |
| 77 double height |
| 78 }): minWidth = width != null ? width : 0.0, |
| 79 maxWidth = width != null ? width : double.INFINITY, |
| 80 minHeight = height != null ? height : 0.0, |
| 81 maxHeight = height != null ? height : double.INFINITY; |
| 82 |
75 BoxConstraints.loose(Size size) | 83 BoxConstraints.loose(Size size) |
76 : minWidth = 0.0, | 84 : minWidth = 0.0, |
77 maxWidth = size.width, | 85 maxWidth = size.width, |
78 minHeight = 0.0, | 86 minHeight = 0.0, |
79 maxHeight = size.height; | 87 maxHeight = size.height; |
80 | 88 |
81 BoxConstraints deflate(EdgeDims edges) { | 89 BoxConstraints deflate(EdgeDims edges) { |
82 assert(edges != null); | 90 assert(edges != null); |
83 double horizontal = edges.left + edges.right; | 91 double horizontal = edges.left + edges.right; |
84 double vertical = edges.top + edges.bottom; | 92 double vertical = edges.top + edges.bottom; |
85 return new BoxConstraints( | 93 return new BoxConstraints( |
86 minWidth: math.max(0.0, minWidth - horizontal), | 94 minWidth: math.max(0.0, minWidth - horizontal), |
87 maxWidth: maxWidth - horizontal, | 95 maxWidth: maxWidth - horizontal, |
88 minHeight: math.max(0.0, minHeight - vertical), | 96 minHeight: math.max(0.0, minHeight - vertical), |
89 maxHeight: maxHeight - vertical | 97 maxHeight: maxHeight - vertical |
90 ); | 98 ); |
91 } | 99 } |
92 | 100 |
93 BoxConstraints loosen() { | 101 BoxConstraints loosen() { |
94 return new BoxConstraints( | 102 return new BoxConstraints( |
95 minWidth: 0.0, | 103 minWidth: 0.0, |
96 maxWidth: maxWidth, | 104 maxWidth: maxWidth, |
97 minHeight: 0.0, | 105 minHeight: 0.0, |
98 maxHeight: maxHeight | 106 maxHeight: maxHeight |
99 ); | 107 ); |
100 } | 108 } |
101 | 109 |
102 BoxConstraints apply(BoxConstraints constraints) { | 110 BoxConstraints apply(BoxConstraints constraints) { |
103 return new BoxConstraints( | 111 return new BoxConstraints( |
104 minWidth: math.max(minWidth, constraints.minWidth), | 112 minWidth: clamp(min: constraints.minWidth, max: constraints.maxWidth, valu
e: minWidth), |
105 maxWidth: math.min(maxWidth, constraints.maxWidth), | 113 maxWidth: clamp(min: constraints.minWidth, max: constraints.maxWidth, valu
e: maxWidth), |
106 minHeight: math.max(minHeight, constraints.minHeight), | 114 minHeight: clamp(min: constraints.minHeight, max: constraints.maxHeight, v
alue: minHeight), |
107 maxHeight: math.min(maxHeight, constraints.maxHeight)); | 115 maxHeight: clamp(min: constraints.minHeight, max: constraints.maxHeight, v
alue: maxHeight) |
| 116 ); |
108 } | 117 } |
109 | 118 |
110 BoxConstraints applyWidth(double width) { | 119 BoxConstraints applyWidth(double width) { |
111 return new BoxConstraints(minWidth: math.max(minWidth, width), | 120 return new BoxConstraints(minWidth: math.max(math.min(maxWidth, width), minW
idth), |
112 maxWidth: math.min(maxWidth, width), | 121 maxWidth: math.max(math.min(maxWidth, width), minW
idth), |
113 minHeight: minHeight, | 122 minHeight: minHeight, |
114 maxHeight: maxHeight); | 123 maxHeight: maxHeight); |
115 } | 124 } |
116 | 125 |
117 BoxConstraints applyMinWidth(double width) { | 126 BoxConstraints applyMinWidth(double newMinWidth) { |
118 return new BoxConstraints(minWidth: math.max(minWidth, width), | 127 return new BoxConstraints(minWidth: math.max(minWidth, newMinWidth), |
119 maxWidth: maxWidth, | 128 maxWidth: math.max(maxWidth, newMinWidth), |
120 minHeight: minHeight, | 129 minHeight: minHeight, |
121 maxHeight: maxHeight); | 130 maxHeight: maxHeight); |
122 } | 131 } |
123 | 132 |
124 BoxConstraints applyMaxWidth(double width) { | 133 BoxConstraints applyMaxWidth(double newMaxWidth) { |
125 return new BoxConstraints(minWidth: minWidth, | 134 return new BoxConstraints(minWidth: minWidth, |
126 maxWidth: math.min(maxWidth, width), | 135 maxWidth: math.min(maxWidth, newMaxWidth), |
127 minHeight: minHeight, | 136 minHeight: minHeight, |
128 maxHeight: maxHeight); | 137 maxHeight: maxHeight); |
129 } | 138 } |
130 | 139 |
131 BoxConstraints applyHeight(double height) { | 140 BoxConstraints applyHeight(double height) { |
132 return new BoxConstraints(minWidth: minWidth, | 141 return new BoxConstraints(minWidth: minWidth, |
133 maxWidth: maxWidth, | 142 maxWidth: maxWidth, |
134 minHeight: math.max(minHeight, height), | 143 minHeight: math.max(math.min(maxHeight, height), m
inHeight), |
135 maxHeight: math.min(maxHeight, height)); | 144 maxHeight: math.max(math.min(maxHeight, height), m
inHeight)); |
136 } | 145 } |
137 | 146 |
138 BoxConstraints applyMinHeight(double height) { | 147 BoxConstraints applyMinHeight(double newMinHeight) { |
139 return new BoxConstraints(minWidth: minWidth, | 148 return new BoxConstraints(minWidth: minWidth, |
140 maxWidth: maxWidth, | 149 maxWidth: maxWidth, |
141 minHeight: math.max(minHeight, height), | 150 minHeight: math.max(minHeight, newMinHeight), |
142 maxHeight: maxHeight); | 151 maxHeight: math.max(maxHeight, newMinHeight)); |
143 } | 152 } |
144 | 153 |
145 BoxConstraints applyMaxHeight(double height) { | 154 BoxConstraints applyMaxHeight(double newMaxHeight) { |
146 return new BoxConstraints(minWidth: minWidth, | 155 return new BoxConstraints(minWidth: minWidth, |
147 maxWidth: maxWidth, | 156 maxWidth: maxWidth, |
148 minHeight: minHeight, | 157 minHeight: minHeight, |
149 maxHeight: math.min(maxHeight, height)); | 158 maxHeight: math.min(maxHeight, newMaxHeight)); |
150 } | 159 } |
151 | 160 |
152 final double minWidth; | 161 final double minWidth; |
153 final double maxWidth; | 162 final double maxWidth; |
154 final double minHeight; | 163 final double minHeight; |
155 final double maxHeight; | 164 final double maxHeight; |
156 | 165 |
157 double constrainWidth(double width) { | 166 double constrainWidth(double width) { |
158 return clamp(min: minWidth, max: maxWidth, value: width); | 167 return clamp(min: minWidth, max: maxWidth, value: width); |
159 } | 168 } |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 super.hitTestChildren(result, position: position); | 347 super.hitTestChildren(result, position: position); |
339 } | 348 } |
340 | 349 |
341 void paint(RenderObjectDisplayList canvas) { | 350 void paint(RenderObjectDisplayList canvas) { |
342 if (child != null) | 351 if (child != null) |
343 child.paint(canvas); | 352 child.paint(canvas); |
344 } | 353 } |
345 | 354 |
346 } | 355 } |
347 | 356 |
348 class RenderSizedBox extends RenderProxyBox { | |
349 | |
350 RenderSizedBox({ | |
351 RenderBox child, | |
352 Size desiredSize: Size.infinite | |
353 }) : super(child), _desiredSize = desiredSize { | |
354 assert(desiredSize != null); | |
355 } | |
356 | |
357 Size _desiredSize; | |
358 Size get desiredSize => _desiredSize; | |
359 void set desiredSize (Size value) { | |
360 assert(value != null); | |
361 if (_desiredSize == value) | |
362 return; | |
363 _desiredSize = value; | |
364 markNeedsLayout(); | |
365 } | |
366 | |
367 double getMinIntrinsicWidth(BoxConstraints constraints) { | |
368 return constraints.constrainWidth(_desiredSize.width); | |
369 } | |
370 | |
371 double getMaxIntrinsicWidth(BoxConstraints constraints) { | |
372 return constraints.constrainWidth(_desiredSize.width); | |
373 } | |
374 | |
375 double getMinIntrinsicHeight(BoxConstraints constraints) { | |
376 return constraints.constrainHeight(_desiredSize.height); | |
377 } | |
378 | |
379 double getMaxIntrinsicHeight(BoxConstraints constraints) { | |
380 return constraints.constrainHeight(_desiredSize.height); | |
381 } | |
382 | |
383 void performLayout() { | |
384 size = constraints.constrain(_desiredSize); | |
385 if (child != null) | |
386 child.layout(new BoxConstraints.tight(size)); | |
387 } | |
388 | |
389 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(
prefix)}${prefix}desiredSize: ${desiredSize}\n'; | |
390 } | |
391 | |
392 class RenderConstrainedBox extends RenderProxyBox { | 357 class RenderConstrainedBox extends RenderProxyBox { |
393 RenderConstrainedBox({ | 358 RenderConstrainedBox({ |
394 RenderBox child, | 359 RenderBox child, |
395 BoxConstraints additionalConstraints | 360 BoxConstraints additionalConstraints |
396 }) : super(child), _additionalConstraints = additionalConstraints { | 361 }) : super(child), _additionalConstraints = additionalConstraints { |
397 assert(additionalConstraints != null); | 362 assert(additionalConstraints != null); |
398 } | 363 } |
399 | 364 |
400 BoxConstraints _additionalConstraints; | 365 BoxConstraints _additionalConstraints; |
401 BoxConstraints get additionalConstraints => _additionalConstraints; | 366 BoxConstraints get additionalConstraints => _additionalConstraints; |
402 void set additionalConstraints (BoxConstraints value) { | 367 void set additionalConstraints (BoxConstraints value) { |
403 assert(value != null); | 368 assert(value != null); |
404 if (_additionalConstraints == value) | 369 if (_additionalConstraints == value) |
405 return; | 370 return; |
406 _additionalConstraints = value; | 371 _additionalConstraints = value; |
407 markNeedsLayout(); | 372 markNeedsLayout(); |
408 } | 373 } |
409 | 374 |
410 double getMinIntrinsicWidth(BoxConstraints constraints) { | 375 double getMinIntrinsicWidth(BoxConstraints constraints) { |
411 if (child != null) | 376 if (child != null) |
412 return child.getMinIntrinsicWidth(constraints.apply(_additionalConstraints
)); | 377 return child.getMinIntrinsicWidth(_additionalConstraints.apply(constraints
)); |
413 return constraints.constrainWidth(0.0); | 378 return constraints.constrainWidth(0.0); |
414 } | 379 } |
415 | 380 |
416 double getMaxIntrinsicWidth(BoxConstraints constraints) { | 381 double getMaxIntrinsicWidth(BoxConstraints constraints) { |
417 if (child != null) | 382 if (child != null) |
418 return child.getMaxIntrinsicWidth(constraints.apply(_additionalConstraints
)); | 383 return child.getMaxIntrinsicWidth(_additionalConstraints.apply(constraints
)); |
419 return constraints.constrainWidth(0.0); | 384 return constraints.constrainWidth(0.0); |
420 } | 385 } |
421 | 386 |
422 double getMinIntrinsicHeight(BoxConstraints constraints) { | 387 double getMinIntrinsicHeight(BoxConstraints constraints) { |
423 if (child != null) | 388 if (child != null) |
424 return child.getMinIntrinsicHeight(constraints.apply(_additionalConstraint
s)); | 389 return child.getMinIntrinsicHeight(_additionalConstraints.apply(constraint
s)); |
425 return constraints.constrainHeight(0.0); | 390 return constraints.constrainHeight(0.0); |
426 } | 391 } |
427 | 392 |
428 double getMaxIntrinsicHeight(BoxConstraints constraints) { | 393 double getMaxIntrinsicHeight(BoxConstraints constraints) { |
429 if (child != null) | 394 if (child != null) |
430 return child.getMaxIntrinsicHeight(constraints.apply(_additionalConstraint
s)); | 395 return child.getMaxIntrinsicHeight(_additionalConstraints.apply(constraint
s)); |
431 return constraints.constrainHeight(0.0); | 396 return constraints.constrainHeight(0.0); |
432 } | 397 } |
433 | 398 |
434 void performLayout() { | 399 void performLayout() { |
435 if (child != null) { | 400 if (child != null) { |
436 child.layout(constraints.apply(_additionalConstraints), parentUsesSize: tr
ue); | 401 child.layout(_additionalConstraints.apply(constraints), parentUsesSize: tr
ue); |
437 size = child.size; | 402 size = child.size; |
438 } else { | 403 } else { |
439 performResize(); | 404 size = _additionalConstraints.apply(constraints).constrain(Size.zero); |
440 } | 405 } |
441 } | 406 } |
442 | 407 |
443 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(
prefix)}${prefix}additionalConstraints: ${additionalConstraints}\n'; | 408 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(
prefix)}${prefix}additionalConstraints: ${additionalConstraints}\n'; |
444 } | 409 } |
445 | 410 |
446 class RenderShrinkWrapWidth extends RenderProxyBox { | 411 class RenderShrinkWrapWidth extends RenderProxyBox { |
447 RenderShrinkWrapWidth({ RenderBox child }) : super(child); | 412 RenderShrinkWrapWidth({ RenderBox child }) : super(child); |
448 | 413 |
449 BoxConstraints _getInnerConstraints(BoxConstraints constraints) { | 414 BoxConstraints _getInnerConstraints(BoxConstraints constraints) { |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 | 1043 |
1079 void defaultPaint(RenderObjectDisplayList canvas) { | 1044 void defaultPaint(RenderObjectDisplayList canvas) { |
1080 RenderBox child = firstChild; | 1045 RenderBox child = firstChild; |
1081 while (child != null) { | 1046 while (child != null) { |
1082 assert(child.parentData is ParentDataType); | 1047 assert(child.parentData is ParentDataType); |
1083 canvas.paintChild(child, child.parentData.position); | 1048 canvas.paintChild(child, child.parentData.position); |
1084 child = child.parentData.nextSibling; | 1049 child = child.parentData.nextSibling; |
1085 } | 1050 } |
1086 } | 1051 } |
1087 } | 1052 } |
OLD | NEW |