@@ -797,6 +797,27 @@ YOGA_EXPORT float YGNodeStyleGetBorder(
797
797
return static_cast <YGValue>(border).value ;
798
798
}
799
799
800
+ YOGA_EXPORT void YGNodeStyleSetGap (
801
+ const YGNodeRef node,
802
+ const YGGutter gutter,
803
+ const float gapLength) {
804
+ auto length = detail::CompactValue::ofMaybe<YGUnitPoint>(gapLength);
805
+ updateIndexedStyleProp<MSVC_HINT (gap)>(node, &YGStyle::gap, gutter, length);
806
+ }
807
+
808
+ YOGA_EXPORT float YGNodeStyleGetGap (
809
+ const YGNodeConstRef node,
810
+ const YGGutter gutter) {
811
+ auto gapLength = node->getStyle ().gap ()[gutter];
812
+ if (gapLength.isUndefined () || gapLength.isAuto ()) {
813
+ // TODO(T26792433): Rather than returning YGUndefined, change the api to
814
+ // return YGFloatOptional.
815
+ return YGUndefined;
816
+ }
817
+
818
+ return static_cast <YGValue>(gapLength).value ;
819
+ }
820
+
800
821
// Yoga specific properties, not compatible with flexbox specification
801
822
802
823
// TODO(T26792433): Change the API to accept YGFloatOptional.
@@ -1972,6 +1993,7 @@ static YGCollectFlexItemsRowValues YGCalculateCollectFlexItemsRowValues(
1972
1993
const YGFlexDirection mainAxis = YGResolveFlexDirection (
1973
1994
node->getStyle ().flexDirection (), node->resolveDirection (ownerDirection));
1974
1995
const bool isNodeFlexWrap = node->getStyle ().flexWrap () != YGWrapNoWrap;
1996
+ const float gap = node->getGapForAxis (mainAxis, availableInnerWidth).unwrap ();
1975
1997
1976
1998
// Add items to the current line until it's full or we run out of items.
1977
1999
uint32_t endOfLineIndex = startOfLineIndex;
@@ -1981,9 +2003,13 @@ static YGCollectFlexItemsRowValues YGCalculateCollectFlexItemsRowValues(
1981
2003
child->getStyle ().positionType () == YGPositionTypeAbsolute) {
1982
2004
continue ;
1983
2005
}
2006
+
2007
+ const bool isFirstElementInLine = (endOfLineIndex - startOfLineIndex) == 0 ;
2008
+
1984
2009
child->setLineIndex (lineCount);
1985
2010
const float childMarginMainAxis =
1986
2011
child->getMarginForAxis (mainAxis, availableInnerWidth).unwrap ();
2012
+ const float childLeadingGapMainAxis = isFirstElementInLine ? 0 .0f : gap;
1987
2013
const float flexBasisWithMinAndMaxConstraints =
1988
2014
YGNodeBoundAxisWithinMinAndMax (
1989
2015
child,
@@ -1996,16 +2022,19 @@ static YGCollectFlexItemsRowValues YGCalculateCollectFlexItemsRowValues(
1996
2022
// size, we've hit the end of the current line. Break out of the loop and
1997
2023
// lay out the current line.
1998
2024
if (sizeConsumedOnCurrentLineIncludingMinConstraint +
1999
- flexBasisWithMinAndMaxConstraints + childMarginMainAxis >
2025
+ flexBasisWithMinAndMaxConstraints + childMarginMainAxis +
2026
+ childLeadingGapMainAxis >
2000
2027
availableInnerMainDim &&
2001
2028
isNodeFlexWrap && flexAlgoRowMeasurement.itemsOnLine > 0 ) {
2002
2029
break ;
2003
2030
}
2004
2031
2005
2032
sizeConsumedOnCurrentLineIncludingMinConstraint +=
2006
- flexBasisWithMinAndMaxConstraints + childMarginMainAxis;
2033
+ flexBasisWithMinAndMaxConstraints + childMarginMainAxis +
2034
+ childLeadingGapMainAxis;
2007
2035
flexAlgoRowMeasurement.sizeConsumedOnCurrentLine +=
2008
- flexBasisWithMinAndMaxConstraints + childMarginMainAxis;
2036
+ flexBasisWithMinAndMaxConstraints + childMarginMainAxis +
2037
+ childLeadingGapMainAxis;
2009
2038
flexAlgoRowMeasurement.itemsOnLine ++;
2010
2039
2011
2040
if (child->isNodeFlexible ()) {
@@ -2415,6 +2444,7 @@ static void YGJustifyMainAxis(
2415
2444
node->getLeadingPaddingAndBorder (mainAxis, ownerWidth).unwrap ();
2416
2445
const float trailingPaddingAndBorderMain =
2417
2446
node->getTrailingPaddingAndBorder (mainAxis, ownerWidth).unwrap ();
2447
+ const float gap = node->getGapForAxis (mainAxis, ownerWidth).unwrap ();
2418
2448
// If we are using "at most" rules in the main axis, make sure that
2419
2449
// remainingFreeSpace is 0 when min main dimension is not given
2420
2450
if (measureModeMainDim == YGMeasureModeAtMost &&
@@ -2462,7 +2492,7 @@ static void YGJustifyMainAxis(
2462
2492
// The space between the beginning and the first element and the space between
2463
2493
// each two elements.
2464
2494
float leadingMainDim = 0 ;
2465
- float betweenMainDim = 0 ;
2495
+ float betweenMainDim = gap ;
2466
2496
const YGJustify justifyContent = node->getStyle ().justifyContent ();
2467
2497
2468
2498
if (numberOfAutoMarginsOnCurrentLine == 0 ) {
@@ -2475,24 +2505,22 @@ static void YGJustifyMainAxis(
2475
2505
break ;
2476
2506
case YGJustifySpaceBetween:
2477
2507
if (collectedFlexItemsValues.itemsOnLine > 1 ) {
2478
- betweenMainDim =
2508
+ betweenMainDim + =
2479
2509
YGFloatMax (collectedFlexItemsValues.remainingFreeSpace , 0 ) /
2480
2510
(collectedFlexItemsValues.itemsOnLine - 1 );
2481
- } else {
2482
- betweenMainDim = 0 ;
2483
2511
}
2484
2512
break ;
2485
2513
case YGJustifySpaceEvenly:
2486
2514
// Space is distributed evenly across all elements
2487
- betweenMainDim = collectedFlexItemsValues.remainingFreeSpace /
2515
+ leadingMainDim = collectedFlexItemsValues.remainingFreeSpace /
2488
2516
(collectedFlexItemsValues.itemsOnLine + 1 );
2489
- leadingMainDim = betweenMainDim ;
2517
+ betweenMainDim += leadingMainDim ;
2490
2518
break ;
2491
2519
case YGJustifySpaceAround:
2492
2520
// Space on the edges is half of the space between elements
2493
- betweenMainDim = collectedFlexItemsValues.remainingFreeSpace /
2521
+ leadingMainDim = 0 . 5f * collectedFlexItemsValues.remainingFreeSpace /
2494
2522
collectedFlexItemsValues.itemsOnLine ;
2495
- leadingMainDim = betweenMainDim / 2 ;
2523
+ betweenMainDim += leadingMainDim * 2 ;
2496
2524
break ;
2497
2525
case YGJustifyFlexStart:
2498
2526
break ;
@@ -2890,6 +2918,9 @@ static void YGNodelayoutImpl(
2890
2918
// Accumulated cross dimensions of all lines so far.
2891
2919
float totalLineCrossDim = 0 ;
2892
2920
2921
+ const float crossAxisGap =
2922
+ node->getGapForAxis (crossAxis, availableInnerCrossDim).unwrap ();
2923
+
2893
2924
// Max main dimension of all the lines.
2894
2925
float maxLineMainDim = 0 ;
2895
2926
YGCollectFlexItemsRowValues collectedFlexItemsValues;
@@ -3209,7 +3240,8 @@ static void YGNodelayoutImpl(
3209
3240
}
3210
3241
}
3211
3242
3212
- totalLineCrossDim += collectedFlexItemsValues.crossDim ;
3243
+ const float appliedCrossGap = lineCount != 0 ? crossAxisGap : 0 .0f ;
3244
+ totalLineCrossDim += collectedFlexItemsValues.crossDim + appliedCrossGap;
3213
3245
maxLineMainDim =
3214
3246
YGFloatMax (maxLineMainDim, collectedFlexItemsValues.mainDim );
3215
3247
}
@@ -3304,6 +3336,7 @@ static void YGNodelayoutImpl(
3304
3336
}
3305
3337
endIndex = ii;
3306
3338
lineHeight += crossDimLead;
3339
+ currentLead += i != 0 ? crossAxisGap : 0 ;
3307
3340
3308
3341
if (performLayout) {
3309
3342
for (ii = startIndex; ii < endIndex; ii++) {
0 commit comments