Skip to content

Commit

Permalink
Move justifyContent check into switch statement
Browse files Browse the repository at this point in the history
Summary: some general cleanup

Reviewed By: lucasr

Differential Revision: D3886861

fbshipit-source-id: 17ba2962016af34b5add3ce6d8355c9c305a35c0
  • Loading branch information
Emil Sjolander authored and Facebook Github Bot 5 committed Sep 20, 2016
1 parent 1415a5d commit 8fd14c7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions CSSLayout/CSSLayout.c
Original file line number Diff line number Diff line change
Expand Up @@ -1497,25 +1497,27 @@ static void layoutNodeImpl(const CSSNodeRef node,
remainingFreeSpace = 0;
}

// Use justifyContent to figure out how to allocate the remaining space
// available in the main axis.
if (justifyContent != CSSJustifyFlexStart) {
if (justifyContent == CSSJustifyCenter) {
switch (justifyContent) {
case CSSJustifyCenter:
leadingMainDim = remainingFreeSpace / 2;
} else if (justifyContent == CSSJustifyFlexEnd) {
break;
case CSSJustifyFlexEnd:
leadingMainDim = remainingFreeSpace;
} else if (justifyContent == CSSJustifySpaceBetween) {
remainingFreeSpace = fmaxf(remainingFreeSpace, 0);
break;
case CSSJustifySpaceBetween:
if (itemsOnLine > 1) {
betweenMainDim = remainingFreeSpace / (itemsOnLine - 1);
betweenMainDim = fmaxf(remainingFreeSpace, 0) / (itemsOnLine - 1);
} else {
betweenMainDim = 0;
}
} else if (justifyContent == CSSJustifySpaceAround) {
break;
case CSSJustifySpaceAround:
// Space on the edges is half of the space between elements
betweenMainDim = remainingFreeSpace / itemsOnLine;
leadingMainDim = betweenMainDim / 2;
}
break;
default:
break;

This comment has been minimized.

Copy link
@jordwalke

jordwalke Oct 9, 2016

Just to double check, while porting this to ReSS, the compiler told me that I did not cover the case of CSSJustifyFlexStart. Was this intentional?

This comment has been minimized.

Copy link
@emilsjolander

emilsjolander Oct 9, 2016

Contributor

It's covered by the default statement.

}

float mainDim = leadingPaddingAndBorderMain + leadingMainDim;
Expand Down
2 changes: 1 addition & 1 deletion format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ clang-format \
AlignOperands: true, \
AllowAllParametersOfDeclarationOnNextLine: false, \
AllowShortBlocksOnASingleLine: false, \
AllowShortCaseLabelsOnASingleLine: true, \
AllowShortCaseLabelsOnASingleLine: false, \
AllowShortFunctionsOnASingleLine: false, \
AllowShortIfStatementsOnASingleLine: false, \
AllowShortLoopsOnASingleLine: false, \
Expand Down

0 comments on commit 8fd14c7

Please sign in to comment.