Simplified logic distributing flex space.

This commit is contained in:
Russell Keith-Magee
2015-03-31 18:58:56 +08:00
parent c523b7c404
commit 2b6844f00a
3 changed files with 15 additions and 31 deletions

View File

@@ -579,8 +579,9 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth) {
float baseMainDim;
float boundMainDim;
// Iterate over every child-> If the flex share of remaining space doesn't
// meet min/max bounds, remove this child from flex calculations.
// Iterate over every child in the axis. If the flex share of remaining
// space doesn't meet min/max bounds, remove this child from flex
// calculations.
for (i = startLine; i < endLine; ++i) {
child = node->get_child(node->context, i);
if (isFlex(child)) {
@@ -609,15 +610,9 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth) {
if (isFlex(child)) {
// At this point we know the final size of the element in the main
// dimension
baseMainDim = flexibleMainDim * getFlex(child) +
getPaddingAndBorderAxis(child, mainAxis);
boundMainDim = boundAxis(child, mainAxis, baseMainDim);
if (baseMainDim == boundMainDim) {
child->layout.dimensions[dim[mainAxis]] = baseMainDim;
} else {
child->layout.dimensions[dim[mainAxis]] = boundMainDim;
}
child->layout.dimensions[dim[mainAxis]] = boundAxis(child, mainAxis,
flexibleMainDim * getFlex(child) + getPaddingAndBorderAxis(child, mainAxis)
);
maxWidth = CSS_UNDEFINED;
if (isDimDefined(node, CSS_FLEX_DIRECTION_ROW)) {

View File

@@ -501,15 +501,9 @@ var computeLayout = (function() {
if (isFlex(child)) {
// At this point we know the final size of the element in the main
// dimension
baseMainDim = flexibleMainDim * getFlex(child) +
getPaddingAndBorderAxis(child, mainAxis);
boundMainDim = boundAxis(child, mainAxis, baseMainDim);
if (baseMainDim === boundMainDim) {
child.layout[dim[mainAxis]] = baseMainDim;
} else {
child.layout[dim[mainAxis]] = boundMainDim;
}
child.layout[dim[mainAxis]] = boundAxis(child, mainAxis,
flexibleMainDim * getFlex(child) + getPaddingAndBorderAxis(child, mainAxis)
);
maxWidth = CSS_UNDEFINED;
if (isDimDefined(node, CSS_FLEX_DIRECTION_ROW)) {

View File

@@ -524,8 +524,9 @@ public class LayoutEngine {
float baseMainDim;
float boundMainDim;
// Iterate over every child. If the flex share of remaining space doesn't
// meet min/max bounds, remove this child from flex calculations.
// Iterate over every child in the axis. If the flex share of remaining
// space doesn't meet min/max bounds, remove this child from flex
// calculations.
for (i = startLine; i < endLine; ++i) {
child = node.getChildAt(i);
if (isFlex(child)) {
@@ -554,15 +555,9 @@ public class LayoutEngine {
if (isFlex(child)) {
// At this point we know the final size of the element in the main
// dimension
baseMainDim = flexibleMainDim * getFlex(child) +
getPaddingAndBorderAxis(child, mainAxis);
boundMainDim = boundAxis(child, mainAxis, baseMainDim);
if (baseMainDim == boundMainDim) {
setLayoutDimension(child, getDim(mainAxis), baseMainDim);
} else {
setLayoutDimension(child, getDim(mainAxis), boundMainDim);
}
setLayoutDimension(child, getDim(mainAxis), boundAxis(child, mainAxis,
flexibleMainDim * getFlex(child) + getPaddingAndBorderAxis(child, mainAxis)
));
maxWidth = CSSConstants.UNDEFINED;
if (isDimDefined(node, CSSFlexDirection.ROW)) {