| 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 'box.dart'; | 7 import 'package:sky/rendering/box.dart'; |
| 8 import 'object.dart'; | 8 import 'package:sky/rendering/object.dart'; |
| 9 | 9 |
| 10 class FlexBoxParentData extends BoxParentData with ContainerParentDataMixin<Rend
erBox> { | 10 class FlexBoxParentData extends BoxParentData with ContainerParentDataMixin<Rend
erBox> { |
| 11 int flex; | 11 int flex; |
| 12 | 12 |
| 13 void merge(FlexBoxParentData other) { | 13 void merge(FlexBoxParentData other) { |
| 14 if (other.flex != null) | 14 if (other.flex != null) |
| 15 flex = other.flex; | 15 flex = other.flex; |
| 16 super.merge(other); | 16 super.merge(other); |
| 17 } | 17 } |
| 18 | 18 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 RenderBox child = firstChild; | 158 RenderBox child = firstChild; |
| 159 while (child != null) { | 159 while (child != null) { |
| 160 int flex = _getFlex(child); | 160 int flex = _getFlex(child); |
| 161 totalFlex += flex; | 161 totalFlex += flex; |
| 162 double mainSize; | 162 double mainSize; |
| 163 double crossSize; | 163 double crossSize; |
| 164 if (flex == 0) { | 164 if (flex == 0) { |
| 165 switch (_direction) { | 165 switch (_direction) { |
| 166 case FlexDirection.horizontal: | 166 case FlexDirection.horizontal: |
| 167 mainSize = child.getMaxIntrinsicWidth(childConstraints); | 167 mainSize = child.getMaxIntrinsicWidth(childConstraints); |
| 168 BoxConstraints widthConstraints = | 168 BoxConstraints widthConstraints = |
| 169 new BoxConstraints(minWidth: mainSize, maxWidth: mainSize); | 169 new BoxConstraints(minWidth: mainSize, maxWidth: mainSize); |
| 170 crossSize = child.getMaxIntrinsicHeight(widthConstraints); | 170 crossSize = child.getMaxIntrinsicHeight(widthConstraints); |
| 171 break; | 171 break; |
| 172 case FlexDirection.vertical: | 172 case FlexDirection.vertical: |
| 173 mainSize = child.getMaxIntrinsicHeight(childConstraints); | 173 mainSize = child.getMaxIntrinsicHeight(childConstraints); |
| 174 BoxConstraints heightConstraints = | 174 BoxConstraints heightConstraints = |
| 175 new BoxConstraints(minWidth: mainSize, maxWidth: mainSize); | 175 new BoxConstraints(minWidth: mainSize, maxWidth: mainSize); |
| 176 crossSize = child.getMaxIntrinsicWidth(heightConstraints); | 176 crossSize = child.getMaxIntrinsicWidth(heightConstraints); |
| 177 break; | 177 break; |
| 178 } | 178 } |
| 179 inflexibleSpace += mainSize; | 179 inflexibleSpace += mainSize; |
| 180 maxCrossSize = math.max(maxCrossSize, crossSize); | 180 maxCrossSize = math.max(maxCrossSize, crossSize); |
| 181 } | 181 } |
| 182 assert(child.parentData is FlexBoxParentData); | 182 assert(child.parentData is FlexBoxParentData); |
| 183 child = child.parentData.nextSibling; | 183 child = child.parentData.nextSibling; |
| 184 } | 184 } |
| 185 | 185 |
| 186 // Determine the spacePerFlex by allocating the remaining available space | 186 // Determine the spacePerFlex by allocating the remaining available space |
| 187 double spacePerFlex = (availableMainSpace - inflexibleSpace) / totalFlex; | 187 double spacePerFlex = (availableMainSpace - inflexibleSpace) / totalFlex; |
| 188 | 188 |
| 189 // Size remaining items, find the maximum cross size | 189 // Size remaining items, find the maximum cross size |
| 190 child = firstChild; | 190 child = firstChild; |
| 191 while (child != null) { | 191 while (child != null) { |
| 192 int flex = _getFlex(child); | 192 int flex = _getFlex(child); |
| 193 if (flex > 0) { | 193 if (flex > 0) { |
| 194 double childMainSize = spacePerFlex * flex; | 194 double childMainSize = spacePerFlex * flex; |
| 195 double crossSize; | 195 double crossSize; |
| 196 switch (_direction) { | 196 switch (_direction) { |
| 197 case FlexDirection.horizontal: | 197 case FlexDirection.horizontal: |
| 198 BoxConstraints childConstraints = | 198 BoxConstraints childConstraints = |
| 199 new BoxConstraints(minWidth: childMainSize, maxWidth: childMainS
ize); | 199 new BoxConstraints(minWidth: childMainSize, maxWidth: childMainS
ize); |
| 200 crossSize = child.getMaxIntrinsicHeight(childConstraints); | 200 crossSize = child.getMaxIntrinsicHeight(childConstraints); |
| 201 break; | 201 break; |
| 202 case FlexDirection.vertical: | 202 case FlexDirection.vertical: |
| 203 BoxConstraints childConstraints = | 203 BoxConstraints childConstraints = |
| 204 new BoxConstraints(minHeight: childMainSize, maxHeight: childMai
nSize); | 204 new BoxConstraints(minHeight: childMainSize, maxHeight: childMai
nSize); |
| 205 crossSize = child.getMaxIntrinsicWidth(childConstraints); | 205 crossSize = child.getMaxIntrinsicWidth(childConstraints); |
| 206 break; | 206 break; |
| 207 } | 207 } |
| 208 maxCrossSize = math.max(maxCrossSize, crossSize); | 208 maxCrossSize = math.max(maxCrossSize, crossSize); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 } | 412 } |
| 413 | 413 |
| 414 void hitTestChildren(HitTestResult result, { Point position }) { | 414 void hitTestChildren(HitTestResult result, { Point position }) { |
| 415 defaultHitTestChildren(result, position: position); | 415 defaultHitTestChildren(result, position: position); |
| 416 } | 416 } |
| 417 | 417 |
| 418 void paint(PaintingCanvas canvas, Offset offset) { | 418 void paint(PaintingCanvas canvas, Offset offset) { |
| 419 defaultPaint(canvas, offset); | 419 defaultPaint(canvas, offset); |
| 420 } | 420 } |
| 421 } | 421 } |
| OLD | NEW |