From 3d6fb2f2e5b05611e22fb7be967e24609438b963 Mon Sep 17 00:00:00 2001 From: Maxime Ollivier Date: Fri, 10 Mar 2017 05:14:55 -0800 Subject: [PATCH 1/8] Update .travis.yml to build iOS sample project Summary: Closes https://github.com/facebook/yoga/pull/472 Differential Revision: D4688993 Pulled By: emilsjolander fbshipit-source-id: 9b5a16866c4258245a50582aa1110d54139a7ec2 --- .travis.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9455dc46..bf922231 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,7 +40,10 @@ before_install: # iOS - | if [[ $TARGET = "ios" ]]; then - brew outdated xctool || brew upgrade xctool + brew outdated xctool || brew upgrade xctool; + gem install xcpretty --no-document --quiet; + gem install cocoapods --pre --no-document --quiet; + pod install --project-directory=YogaKit/YogaKitSample/; fi # Emscripten (used for js tests) @@ -102,7 +105,8 @@ script: # iOS - | if [[ $TARGET = "ios" ]]; then - buck test --verbose 0 //YogaKit:YogaKitTests --config cxx.default_platform=iphonesimulator-x86_64 + buck test --verbose 0 //YogaKit:YogaKitTests --config cxx.default_platform=iphonesimulator-x86_64 && + xcodebuild build -workspace YogaKit/YogaKitSample/YogaKitSample.xcworkspace -scheme YogaKitSample -sdk iphonesimulator | xcpretty -c fi # Android -- 2.50.1.windows.1 From 061981fb23fd77e2e95a18e1532cf7f138a33afd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20W=C3=B6hrl?= Date: Fri, 10 Mar 2017 06:05:53 -0800 Subject: [PATCH 2/8] Align resolve function names to have similiar namings Summary: We have some resolve functions with ```YG**Resolve``` and others named ```YGResolve**```. This changes both to be named like the later one, as I think this is the grammatically better readable one. Closes https://github.com/facebook/yoga/pull/471 Differential Revision: D4688997 Pulled By: emilsjolander fbshipit-source-id: 38b5f84d4d39ed3effedf08188085b9efd96b4ce --- yoga/Yoga.c | 102 ++++++++++++++++++++++++++-------------------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/yoga/Yoga.c b/yoga/Yoga.c index d77be50e..dd3ebd9d 100644 --- a/yoga/Yoga.c +++ b/yoga/Yoga.c @@ -290,7 +290,7 @@ static inline const YGValue *YGComputedEdgeValue(const YGValue edges[YGEdgeCount return defaultValue; } -static inline float YGValueResolve(const YGValue *const value, const float parentSize) { +static inline float YGResolveValue(const YGValue *const value, const float parentSize) { switch (value->unit) { case YGUnitUndefined: case YGUnitAuto: @@ -303,8 +303,8 @@ static inline float YGValueResolve(const YGValue *const value, const float paren return YGUndefined; } -static inline float YGValueResolveMargin(const YGValue *const value, const float parentSize) { - return value->unit == YGUnitAuto ? 0 : YGValueResolve(value, parentSize); +static inline float YGResolveValueMargin(const YGValue *const value, const float parentSize) { + return value->unit == YGUnitAuto ? 0 : YGResolveValue(value, parentSize); } int32_t gNodeInstanceCount = 0; @@ -1001,10 +1001,10 @@ static inline float YGNodeLeadingMargin(const YGNodeRef node, const YGFlexDirection axis, const float widthSize) { if (YGFlexDirectionIsRow(axis) && node->style.margin[YGEdgeStart].unit != YGUnitUndefined) { - return YGValueResolveMargin(&node->style.margin[YGEdgeStart], widthSize); + return YGResolveValueMargin(&node->style.margin[YGEdgeStart], widthSize); } - return YGValueResolveMargin(YGComputedEdgeValue(node->style.margin, leading[axis], &YGValueZero), + return YGResolveValueMargin(YGComputedEdgeValue(node->style.margin, leading[axis], &YGValueZero), widthSize); } @@ -1012,10 +1012,10 @@ static float YGNodeTrailingMargin(const YGNodeRef node, const YGFlexDirection axis, const float widthSize) { if (YGFlexDirectionIsRow(axis) && node->style.margin[YGEdgeEnd].unit != YGUnitUndefined) { - return YGValueResolveMargin(&node->style.margin[YGEdgeEnd], widthSize); + return YGResolveValueMargin(&node->style.margin[YGEdgeEnd], widthSize); } - return YGValueResolveMargin(YGComputedEdgeValue(node->style.margin, trailing[axis], &YGValueZero), + return YGResolveValueMargin(YGComputedEdgeValue(node->style.margin, trailing[axis], &YGValueZero), widthSize); } @@ -1023,11 +1023,11 @@ static float YGNodeLeadingPadding(const YGNodeRef node, const YGFlexDirection axis, const float widthSize) { if (YGFlexDirectionIsRow(axis) && node->style.padding[YGEdgeStart].unit != YGUnitUndefined && - YGValueResolve(&node->style.padding[YGEdgeStart], widthSize) >= 0.0f) { - return YGValueResolve(&node->style.padding[YGEdgeStart], widthSize); + YGResolveValue(&node->style.padding[YGEdgeStart], widthSize) >= 0.0f) { + return YGResolveValue(&node->style.padding[YGEdgeStart], widthSize); } - return fmaxf(YGValueResolve(YGComputedEdgeValue(node->style.padding, leading[axis], &YGValueZero), + return fmaxf(YGResolveValue(YGComputedEdgeValue(node->style.padding, leading[axis], &YGValueZero), widthSize), 0.0f); } @@ -1036,11 +1036,11 @@ static float YGNodeTrailingPadding(const YGNodeRef node, const YGFlexDirection axis, const float widthSize) { if (YGFlexDirectionIsRow(axis) && node->style.padding[YGEdgeEnd].unit != YGUnitUndefined && - YGValueResolve(&node->style.padding[YGEdgeEnd], widthSize) >= 0.0f) { - return YGValueResolve(&node->style.padding[YGEdgeEnd], widthSize); + YGResolveValue(&node->style.padding[YGEdgeEnd], widthSize) >= 0.0f) { + return YGResolveValue(&node->style.padding[YGEdgeEnd], widthSize); } - return fmaxf(YGValueResolve(YGComputedEdgeValue(node->style.padding, trailing[axis], &YGValueZero), + return fmaxf(YGResolveValue(YGComputedEdgeValue(node->style.padding, trailing[axis], &YGValueZero), widthSize), 0.0f); } @@ -1143,7 +1143,7 @@ static float YGBaseline(const YGNodeRef node) { return baseline + baselineChild->layout.position[YGEdgeTop]; } -static inline YGFlexDirection YGFlexDirectionResolve(const YGFlexDirection flexDirection, +static inline YGFlexDirection YGResolveFlexDirection(const YGFlexDirection flexDirection, const YGDirection direction) { if (direction == YGDirectionRTL) { if (flexDirection == YGFlexDirectionRow) { @@ -1159,7 +1159,7 @@ static inline YGFlexDirection YGFlexDirectionResolve(const YGFlexDirection flexD static YGFlexDirection YGFlexDirectionCross(const YGFlexDirection flexDirection, const YGDirection direction) { return YGFlexDirectionIsColumn(flexDirection) - ? YGFlexDirectionResolve(YGFlexDirectionRow, direction) + ? YGResolveFlexDirection(YGFlexDirectionRow, direction) : YGFlexDirectionColumn; } @@ -1233,7 +1233,7 @@ static float YGNodeLeadingPosition(const YGNodeRef node, const YGValue *leadingPosition = YGComputedEdgeValue(node->style.position, YGEdgeStart, &YGValueUndefined); if (leadingPosition->unit != YGUnitUndefined) { - return YGValueResolve(leadingPosition, axisSize); + return YGResolveValue(leadingPosition, axisSize); } } @@ -1241,7 +1241,7 @@ static float YGNodeLeadingPosition(const YGNodeRef node, YGComputedEdgeValue(node->style.position, leading[axis], &YGValueUndefined); return leadingPosition->unit == YGUnitUndefined ? 0.0f - : YGValueResolve(leadingPosition, axisSize); + : YGResolveValue(leadingPosition, axisSize); } static float YGNodeTrailingPosition(const YGNodeRef node, @@ -1251,7 +1251,7 @@ static float YGNodeTrailingPosition(const YGNodeRef node, const YGValue *trailingPosition = YGComputedEdgeValue(node->style.position, YGEdgeEnd, &YGValueUndefined); if (trailingPosition->unit != YGUnitUndefined) { - return YGValueResolve(trailingPosition, axisSize); + return YGResolveValue(trailingPosition, axisSize); } } @@ -1259,7 +1259,7 @@ static float YGNodeTrailingPosition(const YGNodeRef node, YGComputedEdgeValue(node->style.position, trailing[axis], &YGValueUndefined); return trailingPosition->unit == YGUnitUndefined ? 0.0f - : YGValueResolve(trailingPosition, axisSize); + : YGResolveValue(trailingPosition, axisSize); } static float YGNodeBoundAxisWithinMinAndMax(const YGNodeRef node, @@ -1270,11 +1270,11 @@ static float YGNodeBoundAxisWithinMinAndMax(const YGNodeRef node, float max = YGUndefined; if (YGFlexDirectionIsColumn(axis)) { - min = YGValueResolve(&node->style.minDimensions[YGDimensionHeight], axisSize); - max = YGValueResolve(&node->style.maxDimensions[YGDimensionHeight], axisSize); + min = YGResolveValue(&node->style.minDimensions[YGDimensionHeight], axisSize); + max = YGResolveValue(&node->style.maxDimensions[YGDimensionHeight], axisSize); } else if (YGFlexDirectionIsRow(axis)) { - min = YGValueResolve(&node->style.minDimensions[YGDimensionWidth], axisSize); - max = YGValueResolve(&node->style.maxDimensions[YGDimensionWidth], axisSize); + min = YGResolveValue(&node->style.minDimensions[YGDimensionWidth], axisSize); + max = YGResolveValue(&node->style.maxDimensions[YGDimensionWidth], axisSize); } float boundValue = value; @@ -1341,7 +1341,7 @@ static void YGConstrainMaxSizeForMode(const YGNodeRef node, const float parentWidth, YGMeasureMode *mode, float *size) { - const float maxSize = YGValueResolve(&node->style.maxDimensions[dim[axis]], parentAxisSize) + + const float maxSize = YGResolveValue(&node->style.maxDimensions[dim[axis]], parentAxisSize) + YGNodeMarginForAxis(node, axis, parentWidth); switch (*mode) { case YGMeasureModeExactly: @@ -1362,7 +1362,7 @@ static void YGNodeSetPosition(const YGNodeRef node, const float mainSize, const float crossSize, const float parentWidth) { - const YGFlexDirection mainAxis = YGFlexDirectionResolve(node->style.flexDirection, direction); + const YGFlexDirection mainAxis = YGResolveFlexDirection(node->style.flexDirection, direction); const YGFlexDirection crossAxis = YGFlexDirectionCross(mainAxis, direction); const float relativePositionMain = YGNodeRelativePosition(node, mainAxis, mainSize); const float relativePositionCross = YGNodeRelativePosition(node, crossAxis, crossSize); @@ -1387,7 +1387,7 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node, const YGMeasureMode heightMode, const YGDirection direction, const YGConfigRef config) { - const YGFlexDirection mainAxis = YGFlexDirectionResolve(node->style.flexDirection, direction); + const YGFlexDirection mainAxis = YGResolveFlexDirection(node->style.flexDirection, direction); const bool isMainAxisRow = YGFlexDirectionIsRow(mainAxis); const float mainAxisSize = isMainAxisRow ? width : height; const float mainAxisParentSize = isMainAxisRow ? parentWidth : parentHeight; @@ -1398,7 +1398,7 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node, YGMeasureMode childHeightMeasureMode; const float resolvedFlexBasis = - YGValueResolve(YGNodeResolveFlexBasisPtr(child), mainAxisParentSize); + YGResolveValue(YGNodeResolveFlexBasisPtr(child), mainAxisParentSize); const bool isRowStyleDimDefined = YGNodeIsStyleDimDefined(child, YGFlexDirectionRow, parentWidth); const bool isColumnStyleDimDefined = YGNodeIsStyleDimDefined(child, YGFlexDirectionColumn, parentHeight); @@ -1413,12 +1413,12 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node, } else if (isMainAxisRow && isRowStyleDimDefined) { // The width is definite, so use that as the flex basis. child->layout.computedFlexBasis = - fmaxf(YGValueResolve(child->resolvedDimensions[YGDimensionWidth], parentWidth), + fmaxf(YGResolveValue(child->resolvedDimensions[YGDimensionWidth], parentWidth), YGNodePaddingAndBorderForAxis(child, YGFlexDirectionRow, parentWidth)); } else if (!isMainAxisRow && isColumnStyleDimDefined) { // The height is definite, so use that as the flex basis. child->layout.computedFlexBasis = - fmaxf(YGValueResolve(child->resolvedDimensions[YGDimensionHeight], parentHeight), + fmaxf(YGResolveValue(child->resolvedDimensions[YGDimensionHeight], parentHeight), YGNodePaddingAndBorderForAxis(child, YGFlexDirectionColumn, parentWidth)); } else { // Compute the flex basis and hypothetical main size (i.e. the clamped @@ -1433,12 +1433,12 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node, if (isRowStyleDimDefined) { childWidth = - YGValueResolve(child->resolvedDimensions[YGDimensionWidth], parentWidth) + marginRow; + YGResolveValue(child->resolvedDimensions[YGDimensionWidth], parentWidth) + marginRow; childWidthMeasureMode = YGMeasureModeExactly; } if (isColumnStyleDimDefined) { childHeight = - YGValueResolve(child->resolvedDimensions[YGDimensionHeight], parentHeight) + marginColumn; + YGResolveValue(child->resolvedDimensions[YGDimensionHeight], parentHeight) + marginColumn; childHeightMeasureMode = YGMeasureModeExactly; } @@ -1521,7 +1521,7 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node, const float height, const YGDirection direction, const YGConfigRef config) { - const YGFlexDirection mainAxis = YGFlexDirectionResolve(node->style.flexDirection, direction); + const YGFlexDirection mainAxis = YGResolveFlexDirection(node->style.flexDirection, direction); const YGFlexDirection crossAxis = YGFlexDirectionCross(mainAxis, direction); const bool isMainAxisRow = YGFlexDirectionIsRow(mainAxis); @@ -1534,7 +1534,7 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node, const float marginColumn = YGNodeMarginForAxis(child, YGFlexDirectionColumn, width); if (YGNodeIsStyleDimDefined(child, YGFlexDirectionRow, width)) { - childWidth = YGValueResolve(child->resolvedDimensions[YGDimensionWidth], width) + marginRow; + childWidth = YGResolveValue(child->resolvedDimensions[YGDimensionWidth], width) + marginRow; } else { // If the child doesn't have a specified width, compute the width based // on the left/right @@ -1552,7 +1552,7 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node, if (YGNodeIsStyleDimDefined(child, YGFlexDirectionColumn, height)) { childHeight = - YGValueResolve(child->resolvedDimensions[YGDimensionHeight], height) + marginColumn; + YGResolveValue(child->resolvedDimensions[YGDimensionHeight], height) + marginColumn; } else { // If the child doesn't have a specified height, compute the height // based on the top/bottom @@ -1925,9 +1925,9 @@ static void YGNodelayoutImpl(const YGNodeRef node, const YGDirection direction = YGNodeResolveDirection(node, parentDirection); node->layout.direction = direction; - const YGFlexDirection flexRowDirection = YGFlexDirectionResolve(YGFlexDirectionRow, direction); + const YGFlexDirection flexRowDirection = YGResolveFlexDirection(YGFlexDirectionRow, direction); const YGFlexDirection flexColumnDirection = - YGFlexDirectionResolve(YGFlexDirectionColumn, direction); + YGResolveFlexDirection(YGFlexDirectionColumn, direction); node->layout.margin[YGEdgeStart] = YGNodeLeadingMargin(node, flexRowDirection, parentWidth); node->layout.margin[YGEdgeEnd] = YGNodeTrailingMargin(node, flexRowDirection, parentWidth); @@ -1981,7 +1981,7 @@ static void YGNodelayoutImpl(const YGNodeRef node, } // STEP 1: CALCULATE VALUES FOR REMAINDER OF ALGORITHM - const YGFlexDirection mainAxis = YGFlexDirectionResolve(node->style.flexDirection, direction); + const YGFlexDirection mainAxis = YGResolveFlexDirection(node->style.flexDirection, direction); const YGFlexDirection crossAxis = YGFlexDirectionCross(mainAxis, direction); const bool isMainAxisRow = YGFlexDirectionIsRow(mainAxis); const YGJustify justifyContent = node->style.justifyContent; @@ -2016,16 +2016,16 @@ static void YGNodelayoutImpl(const YGNodeRef node, // STEP 2: DETERMINE AVAILABLE SIZE IN MAIN AND CROSS DIRECTIONS const float minInnerWidth = - YGValueResolve(&node->style.minDimensions[YGDimensionWidth], parentWidth) - marginAxisRow - + YGResolveValue(&node->style.minDimensions[YGDimensionWidth], parentWidth) - marginAxisRow - paddingAndBorderAxisRow; const float maxInnerWidth = - YGValueResolve(&node->style.maxDimensions[YGDimensionWidth], parentWidth) - marginAxisRow - + YGResolveValue(&node->style.maxDimensions[YGDimensionWidth], parentWidth) - marginAxisRow - paddingAndBorderAxisRow; const float minInnerHeight = - YGValueResolve(&node->style.minDimensions[YGDimensionHeight], parentHeight) - + YGResolveValue(&node->style.minDimensions[YGDimensionHeight], parentHeight) - marginAxisColumn - paddingAndBorderAxisColumn; const float maxInnerHeight = - YGValueResolve(&node->style.maxDimensions[YGDimensionHeight], parentHeight) - + YGResolveValue(&node->style.maxDimensions[YGDimensionHeight], parentHeight) - marginAxisColumn - paddingAndBorderAxisColumn; const float minInnerMainDim = isMainAxisRow ? minInnerWidth : minInnerHeight; const float maxInnerMainDim = isMainAxisRow ? maxInnerWidth : maxInnerHeight; @@ -2173,7 +2173,7 @@ static void YGNodelayoutImpl(const YGNodeRef node, if (child->style.positionType != YGPositionTypeAbsolute) { const float outerFlexBasis = - fmaxf(YGValueResolve(&child->style.minDimensions[dim[mainAxis]], mainAxisParentSize), + fmaxf(YGResolveValue(&child->style.minDimensions[dim[mainAxis]], mainAxisParentSize), child->layout.computedFlexBasis) + YGNodeMarginForAxis(child, mainAxis, availableInnerWidth); @@ -2416,7 +2416,7 @@ static void YGNodelayoutImpl(const YGNodeRef node, childCrossMeasureMode = YGFloatIsUndefined(childCrossSize) ? YGMeasureModeUndefined : YGMeasureModeAtMost; } else { - childCrossSize = YGValueResolve(currentRelativeChild->resolvedDimensions[dim[crossAxis]], + childCrossSize = YGResolveValue(currentRelativeChild->resolvedDimensions[dim[crossAxis]], availableInnerCrossDim) + marginCross; const bool isLoosePercentageMeasurement = @@ -2506,10 +2506,10 @@ static void YGNodelayoutImpl(const YGNodeRef node, if (measureModeMainDim == YGMeasureModeAtMost && remainingFreeSpace > 0) { if (node->style.minDimensions[dim[mainAxis]].unit != YGUnitUndefined && - YGValueResolve(&node->style.minDimensions[dim[mainAxis]], mainAxisParentSize) >= 0) { + YGResolveValue(&node->style.minDimensions[dim[mainAxis]], mainAxisParentSize) >= 0) { remainingFreeSpace = fmaxf(0, - YGValueResolve(&node->style.minDimensions[dim[mainAxis]], mainAxisParentSize) - + YGResolveValue(&node->style.minDimensions[dim[mainAxis]], mainAxisParentSize) - (availableInnerMainDim - remainingFreeSpace)); } else { remainingFreeSpace = 0; @@ -3386,11 +3386,11 @@ void YGNodeCalculateLayout(const YGNodeRef node, float width = YGUndefined; YGMeasureMode widthMeasureMode = YGMeasureModeUndefined; if (YGNodeIsStyleDimDefined(node, YGFlexDirectionRow, parentWidth)) { - width = YGValueResolve(node->resolvedDimensions[dim[YGFlexDirectionRow]], parentWidth) + + width = YGResolveValue(node->resolvedDimensions[dim[YGFlexDirectionRow]], parentWidth) + YGNodeMarginForAxis(node, YGFlexDirectionRow, parentWidth); widthMeasureMode = YGMeasureModeExactly; - } else if (YGValueResolve(&node->style.maxDimensions[YGDimensionWidth], parentWidth) >= 0.0f) { - width = YGValueResolve(&node->style.maxDimensions[YGDimensionWidth], parentWidth); + } else if (YGResolveValue(&node->style.maxDimensions[YGDimensionWidth], parentWidth) >= 0.0f) { + width = YGResolveValue(&node->style.maxDimensions[YGDimensionWidth], parentWidth); widthMeasureMode = YGMeasureModeAtMost; } else { width = parentWidth; @@ -3400,12 +3400,12 @@ void YGNodeCalculateLayout(const YGNodeRef node, float height = YGUndefined; YGMeasureMode heightMeasureMode = YGMeasureModeUndefined; if (YGNodeIsStyleDimDefined(node, YGFlexDirectionColumn, parentHeight)) { - height = YGValueResolve(node->resolvedDimensions[dim[YGFlexDirectionColumn]], parentHeight) + + height = YGResolveValue(node->resolvedDimensions[dim[YGFlexDirectionColumn]], parentHeight) + YGNodeMarginForAxis(node, YGFlexDirectionColumn, parentWidth); heightMeasureMode = YGMeasureModeExactly; - } else if (YGValueResolve(&node->style.maxDimensions[YGDimensionHeight], parentHeight) >= + } else if (YGResolveValue(&node->style.maxDimensions[YGDimensionHeight], parentHeight) >= 0.0f) { - height = YGValueResolve(&node->style.maxDimensions[YGDimensionHeight], parentHeight); + height = YGResolveValue(&node->style.maxDimensions[YGDimensionHeight], parentHeight); heightMeasureMode = YGMeasureModeAtMost; } else { height = parentHeight; -- 2.50.1.windows.1 From 7e2ef926eaa0c9ff9a77ac907587db02b205fd1d Mon Sep 17 00:00:00 2001 From: Kazuki Sakamoto Date: Fri, 10 Mar 2017 09:32:48 -0800 Subject: [PATCH 3/8] Add Workaround #if to GC test Summary: Closes https://github.com/facebook/yoga/pull/474 Reviewed By: emilsjolander Differential Revision: D4687978 Pulled By: splhack fbshipit-source-id: 5b411e94f76c9846eadd2f01f0c8fd511fd6cdbf --- csharp/tests/Facebook.Yoga/YogaNodeTest.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/csharp/tests/Facebook.Yoga/YogaNodeTest.cs b/csharp/tests/Facebook.Yoga/YogaNodeTest.cs index da7e6cf6..ab3b30bd 100644 --- a/csharp/tests/Facebook.Yoga/YogaNodeTest.cs +++ b/csharp/tests/Facebook.Yoga/YogaNodeTest.cs @@ -365,9 +365,8 @@ namespace Facebook.Yoga child = null; } -#if !__UNIFIED__ +#if YOGA_ENABLE_GC_TEST [Test] -#endif public void TestParentDestructor() { ForceGC(); @@ -388,6 +387,7 @@ namespace Facebook.Yoga Assert.AreEqual(instanceCount + 1, YogaNode.GetInstanceCount()); parent.Insert(0, child); } +#endif [Test] public void TestClearWithChildDestructor() -- 2.50.1.windows.1 From 136e0c7e5294629f1bc04603b38da10aefcc438c Mon Sep 17 00:00:00 2001 From: Maxime Ollivier Date: Fri, 10 Mar 2017 10:06:00 -0800 Subject: [PATCH 4/8] undo iOS sample project build Summary: Temporarily remove the iOS sample project build. Closes https://github.com/facebook/yoga/pull/475 Differential Revision: D4689718 Pulled By: emilsjolander fbshipit-source-id: 9249e9d03dfdb60e222f8c3c0f496ec67122ed62 --- .travis.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index bf922231..9455dc46 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,10 +40,7 @@ before_install: # iOS - | if [[ $TARGET = "ios" ]]; then - brew outdated xctool || brew upgrade xctool; - gem install xcpretty --no-document --quiet; - gem install cocoapods --pre --no-document --quiet; - pod install --project-directory=YogaKit/YogaKitSample/; + brew outdated xctool || brew upgrade xctool fi # Emscripten (used for js tests) @@ -105,8 +102,7 @@ script: # iOS - | if [[ $TARGET = "ios" ]]; then - buck test --verbose 0 //YogaKit:YogaKitTests --config cxx.default_platform=iphonesimulator-x86_64 && - xcodebuild build -workspace YogaKit/YogaKitSample/YogaKitSample.xcworkspace -scheme YogaKitSample -sdk iphonesimulator | xcpretty -c + buck test --verbose 0 //YogaKit:YogaKitTests --config cxx.default_platform=iphonesimulator-x86_64 fi # Android -- 2.50.1.windows.1 From 81be437a8f41bd691858d19bff838addca0e3773 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20W=C3=B6hrl?= Date: Sun, 12 Mar 2017 01:06:02 +0100 Subject: [PATCH 5/8] fix alignment with margin --- .../tests/Facebook.Yoga/YGAlignItemsTest.cs | 59 +++++++++++++++++++ gentest/fixtures/YGAlignItemsTest.html | 9 ++- .../com/facebook/yoga/YGAlignItemsTest.java | 58 ++++++++++++++++++ .../tests/Facebook.Yoga/YGAlignItemsTest.js | 58 ++++++++++++++++++ tests/YGAlignItemsTest.cpp | 59 +++++++++++++++++++ yoga/Yoga.c | 3 - 6 files changed, 241 insertions(+), 5 deletions(-) diff --git a/csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs b/csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs index d5022c10..a0dd4736 100644 --- a/csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs +++ b/csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs @@ -1587,5 +1587,64 @@ namespace Facebook.Yoga Assert.AreEqual(20f, root_child3.LayoutHeight); } + [Test] + public void Test_align_items_center_nested() + { + YogaConfig config = new YogaConfig(); + + YogaNode root = new YogaNode(config); + root.JustifyContent = YogaJustify.Center; + root.AlignItems = YogaAlign.Center; + root.PositionType = YogaPositionType.Absolute; + root.Width = 52; + root.Height = 52; + + YogaNode root_child0 = new YogaNode(config); + root_child0.AlignItems = YogaAlign.Center; + root.Insert(0, root_child0); + + YogaNode root_child0_child0 = new YogaNode(config); + root_child0_child0.MarginLeft = 10; + root_child0_child0.MarginRight = 10; + root_child0_child0.Width = 52; + root_child0_child0.Height = 52; + root_child0.Insert(0, root_child0_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(52f, root.LayoutWidth); + Assert.AreEqual(52f, root.LayoutHeight); + + Assert.AreEqual(-10f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(72f, root_child0.LayoutWidth); + Assert.AreEqual(52f, root_child0.LayoutHeight); + + Assert.AreEqual(10f, root_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0.LayoutY); + Assert.AreEqual(52f, root_child0_child0.LayoutWidth); + Assert.AreEqual(52f, root_child0_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(52f, root.LayoutWidth); + Assert.AreEqual(52f, root.LayoutHeight); + + Assert.AreEqual(-10f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(72f, root_child0.LayoutWidth); + Assert.AreEqual(52f, root_child0.LayoutHeight); + + Assert.AreEqual(10f, root_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0.LayoutY); + Assert.AreEqual(52f, root_child0_child0.LayoutWidth); + Assert.AreEqual(52f, root_child0_child0.LayoutHeight); + } + } } diff --git a/gentest/fixtures/YGAlignItemsTest.html b/gentest/fixtures/YGAlignItemsTest.html index 49aaa9aa..d1d174b2 100644 --- a/gentest/fixtures/YGAlignItemsTest.html +++ b/gentest/fixtures/YGAlignItemsTest.html @@ -133,8 +133,6 @@
- -
@@ -144,4 +142,11 @@
+
+ + +
+
+
+
\ No newline at end of file diff --git a/java/tests/com/facebook/yoga/YGAlignItemsTest.java b/java/tests/com/facebook/yoga/YGAlignItemsTest.java index 0b9533fb..5a885f6c 100644 --- a/java/tests/com/facebook/yoga/YGAlignItemsTest.java +++ b/java/tests/com/facebook/yoga/YGAlignItemsTest.java @@ -1567,4 +1567,62 @@ public class YGAlignItemsTest { assertEquals(20f, root_child3.getLayoutHeight(), 0.0f); } + @Test + public void test_align_items_center_nested() { + YogaConfig config = new YogaConfig(); + + final YogaNode root = new YogaNode(config); + root.setJustifyContent(YogaJustify.CENTER); + root.setAlignItems(YogaAlign.CENTER); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(52f); + root.setHeight(52f); + + final YogaNode root_child0 = new YogaNode(config); + root_child0.setAlignItems(YogaAlign.CENTER); + root.addChildAt(root_child0, 0); + + final YogaNode root_child0_child0 = new YogaNode(config); + root_child0_child0.setMargin(YogaEdge.LEFT, 10f); + root_child0_child0.setMargin(YogaEdge.RIGHT, 10f); + root_child0_child0.setWidth(52f); + root_child0_child0.setHeight(52f); + root_child0.addChildAt(root_child0_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(52f, root.getLayoutWidth(), 0.0f); + assertEquals(52f, root.getLayoutHeight(), 0.0f); + + assertEquals(-10f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(72f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(52f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(52f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(52f, root_child0_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(52f, root.getLayoutWidth(), 0.0f); + assertEquals(52f, root.getLayoutHeight(), 0.0f); + + assertEquals(-10f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(72f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(52f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(52f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(52f, root_child0_child0.getLayoutHeight(), 0.0f); + } + } diff --git a/javascript/tests/Facebook.Yoga/YGAlignItemsTest.js b/javascript/tests/Facebook.Yoga/YGAlignItemsTest.js index 8c4bee4c..1e59df3c 100644 --- a/javascript/tests/Facebook.Yoga/YGAlignItemsTest.js +++ b/javascript/tests/Facebook.Yoga/YGAlignItemsTest.js @@ -1562,3 +1562,61 @@ it("align_baseline_multiline_row_and_column", function () { } } }); +it("align_items_center_nested", function () { + try { + var root = Yoga.Node.create(config); + root.setJustifyContent(Yoga.JUSTIFY_CENTER); + root.setAlignItems(Yoga.ALIGN_CENTER); + root.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); + root.setWidth(52); + root.setHeight(52); + + var root_child0 = Yoga.Node.create(config); + root_child0.setAlignItems(Yoga.ALIGN_CENTER); + root.insertChild(root_child0, 0); + + var root_child0_child0 = Yoga.Node.create(config); + root_child0_child0.setMargin(Yoga.EDGE_LEFT, 10); + root_child0_child0.setMargin(Yoga.EDGE_RIGHT, 10); + root_child0_child0.setWidth(52); + root_child0_child0.setHeight(52); + root_child0.insertChild(root_child0_child0, 0); + root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR); + + console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); + console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); + console.assert(52 === root.getComputedWidth(), "52 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(52 === root.getComputedHeight(), "52 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(-10 === root_child0.getComputedLeft(), "-10 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(72 === root_child0.getComputedWidth(), "72 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(52 === root_child0.getComputedHeight(), "52 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(10 === root_child0_child0.getComputedLeft(), "10 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")"); + console.assert(52 === root_child0_child0.getComputedWidth(), "52 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")"); + console.assert(52 === root_child0_child0.getComputedHeight(), "52 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")"); + + root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL); + + console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); + console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); + console.assert(52 === root.getComputedWidth(), "52 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(52 === root.getComputedHeight(), "52 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(-10 === root_child0.getComputedLeft(), "-10 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(72 === root_child0.getComputedWidth(), "72 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(52 === root_child0.getComputedHeight(), "52 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(10 === root_child0_child0.getComputedLeft(), "10 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")"); + console.assert(52 === root_child0_child0.getComputedWidth(), "52 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")"); + console.assert(52 === root_child0_child0.getComputedHeight(), "52 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")"); + } finally { + if (typeof root !== "undefined") { + root.freeRecursive(); + } + } +}); diff --git a/tests/YGAlignItemsTest.cpp b/tests/YGAlignItemsTest.cpp index 90fefcbc..0bc0a596 100644 --- a/tests/YGAlignItemsTest.cpp +++ b/tests/YGAlignItemsTest.cpp @@ -1581,3 +1581,62 @@ TEST(YogaTest, align_baseline_multiline_row_and_column) { YGConfigFree(config); } + +TEST(YogaTest, align_items_center_nested) { + const YGConfigRef config = YGConfigNew(); + + const YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetJustifyContent(root, YGJustifyCenter); + YGNodeStyleSetAlignItems(root, YGAlignCenter); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetWidth(root, 52); + YGNodeStyleSetHeight(root, 52); + + const YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetAlignItems(root_child0, YGAlignCenter); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetMargin(root_child0_child0, YGEdgeLeft, 10); + YGNodeStyleSetMargin(root_child0_child0, YGEdgeRight, 10); + YGNodeStyleSetWidth(root_child0_child0, 52); + YGNodeStyleSetHeight(root_child0_child0, 52); + YGNodeInsertChild(root_child0, root_child0_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root_child0_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root_child0_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} diff --git a/yoga/Yoga.c b/yoga/Yoga.c index d77be50e..ee782ca3 100644 --- a/yoga/Yoga.c +++ b/yoga/Yoga.c @@ -2625,9 +2625,6 @@ static void YGNodelayoutImpl(const YGNodeRef node, parentWidth) - paddingAndBorderAxisCross; - if (measureModeCrossDim == YGMeasureModeAtMost) { - containerCrossAxis = fminf(containerCrossAxis, availableInnerCrossDim); - } } // If there's no flex wrap, the cross dimension is defined by the container. -- 2.50.1.windows.1 From a349bf1721f2d52be3bc623f0abb76e239237623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20W=C3=B6hrl?= Date: Sun, 12 Mar 2017 17:35:14 +0100 Subject: [PATCH 6/8] added tests for flex-end and without margin --- .../tests/Facebook.Yoga/YGAlignItemsTest.cs | 175 +++++++++++++++++- gentest/fixtures/YGAlignItemsTest.html | 23 ++- .../com/facebook/yoga/YGAlignItemsTest.java | 172 ++++++++++++++++- .../tests/Facebook.Yoga/YGAlignItemsTest.js | 172 ++++++++++++++++- tests/YGAlignItemsTest.cpp | 175 +++++++++++++++++- yoga/Yoga.c | 1 - 6 files changed, 710 insertions(+), 8 deletions(-) diff --git a/csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs b/csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs index a0dd4736..4d0dbd7d 100644 --- a/csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs +++ b/csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs @@ -1588,7 +1588,7 @@ namespace Facebook.Yoga } [Test] - public void Test_align_items_center_nested() + public void Test_align_items_center_child_with_margin_bigger_than_parent() { YogaConfig config = new YogaConfig(); @@ -1646,5 +1646,178 @@ namespace Facebook.Yoga Assert.AreEqual(52f, root_child0_child0.LayoutHeight); } + [Test] + public void Test_align_items_flex_end_child_with_margin_bigger_than_parent() + { + YogaConfig config = new YogaConfig(); + + YogaNode root = new YogaNode(config); + root.JustifyContent = YogaJustify.Center; + root.AlignItems = YogaAlign.Center; + root.PositionType = YogaPositionType.Absolute; + root.Width = 52; + root.Height = 52; + + YogaNode root_child0 = new YogaNode(config); + root_child0.AlignItems = YogaAlign.FlexEnd; + root.Insert(0, root_child0); + + YogaNode root_child0_child0 = new YogaNode(config); + root_child0_child0.MarginLeft = 10; + root_child0_child0.MarginRight = 10; + root_child0_child0.Width = 52; + root_child0_child0.Height = 52; + root_child0.Insert(0, root_child0_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(52f, root.LayoutWidth); + Assert.AreEqual(52f, root.LayoutHeight); + + Assert.AreEqual(-10f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(72f, root_child0.LayoutWidth); + Assert.AreEqual(52f, root_child0.LayoutHeight); + + Assert.AreEqual(10f, root_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0.LayoutY); + Assert.AreEqual(52f, root_child0_child0.LayoutWidth); + Assert.AreEqual(52f, root_child0_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(52f, root.LayoutWidth); + Assert.AreEqual(52f, root.LayoutHeight); + + Assert.AreEqual(-10f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(72f, root_child0.LayoutWidth); + Assert.AreEqual(52f, root_child0.LayoutHeight); + + Assert.AreEqual(10f, root_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0.LayoutY); + Assert.AreEqual(52f, root_child0_child0.LayoutWidth); + Assert.AreEqual(52f, root_child0_child0.LayoutHeight); + } + + [Test] + public void Test_align_items_center_child_without_margin_bigger_than_parent() + { + YogaConfig config = new YogaConfig(); + + YogaNode root = new YogaNode(config); + root.JustifyContent = YogaJustify.Center; + root.AlignItems = YogaAlign.Center; + root.PositionType = YogaPositionType.Absolute; + root.Width = 52; + root.Height = 52; + + YogaNode root_child0 = new YogaNode(config); + root_child0.AlignItems = YogaAlign.Center; + root.Insert(0, root_child0); + + YogaNode root_child0_child0 = new YogaNode(config); + root_child0_child0.Width = 72; + root_child0_child0.Height = 72; + root_child0.Insert(0, root_child0_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(52f, root.LayoutWidth); + Assert.AreEqual(52f, root.LayoutHeight); + + Assert.AreEqual(-10f, root_child0.LayoutX); + Assert.AreEqual(-10f, root_child0.LayoutY); + Assert.AreEqual(72f, root_child0.LayoutWidth); + Assert.AreEqual(72f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0.LayoutY); + Assert.AreEqual(72f, root_child0_child0.LayoutWidth); + Assert.AreEqual(72f, root_child0_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(52f, root.LayoutWidth); + Assert.AreEqual(52f, root.LayoutHeight); + + Assert.AreEqual(-10f, root_child0.LayoutX); + Assert.AreEqual(-10f, root_child0.LayoutY); + Assert.AreEqual(72f, root_child0.LayoutWidth); + Assert.AreEqual(72f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0.LayoutY); + Assert.AreEqual(72f, root_child0_child0.LayoutWidth); + Assert.AreEqual(72f, root_child0_child0.LayoutHeight); + } + + [Test] + public void Test_align_items_flex_end_child_without_margin_bigger_than_parent() + { + YogaConfig config = new YogaConfig(); + + YogaNode root = new YogaNode(config); + root.JustifyContent = YogaJustify.Center; + root.AlignItems = YogaAlign.Center; + root.PositionType = YogaPositionType.Absolute; + root.Width = 52; + root.Height = 52; + + YogaNode root_child0 = new YogaNode(config); + root_child0.AlignItems = YogaAlign.FlexEnd; + root.Insert(0, root_child0); + + YogaNode root_child0_child0 = new YogaNode(config); + root_child0_child0.Width = 72; + root_child0_child0.Height = 72; + root_child0.Insert(0, root_child0_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(52f, root.LayoutWidth); + Assert.AreEqual(52f, root.LayoutHeight); + + Assert.AreEqual(-10f, root_child0.LayoutX); + Assert.AreEqual(-10f, root_child0.LayoutY); + Assert.AreEqual(72f, root_child0.LayoutWidth); + Assert.AreEqual(72f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0.LayoutY); + Assert.AreEqual(72f, root_child0_child0.LayoutWidth); + Assert.AreEqual(72f, root_child0_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(52f, root.LayoutWidth); + Assert.AreEqual(52f, root.LayoutHeight); + + Assert.AreEqual(-10f, root_child0.LayoutX); + Assert.AreEqual(-10f, root_child0.LayoutY); + Assert.AreEqual(72f, root_child0.LayoutWidth); + Assert.AreEqual(72f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0.LayoutY); + Assert.AreEqual(72f, root_child0_child0.LayoutWidth); + Assert.AreEqual(72f, root_child0_child0.LayoutHeight); + } + } } diff --git a/gentest/fixtures/YGAlignItemsTest.html b/gentest/fixtures/YGAlignItemsTest.html index d1d174b2..b11e0f86 100644 --- a/gentest/fixtures/YGAlignItemsTest.html +++ b/gentest/fixtures/YGAlignItemsTest.html @@ -144,9 +144,26 @@
- -
+
-
\ No newline at end of file +
+ +
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+
diff --git a/java/tests/com/facebook/yoga/YGAlignItemsTest.java b/java/tests/com/facebook/yoga/YGAlignItemsTest.java index 5a885f6c..f581e34c 100644 --- a/java/tests/com/facebook/yoga/YGAlignItemsTest.java +++ b/java/tests/com/facebook/yoga/YGAlignItemsTest.java @@ -1568,7 +1568,7 @@ public class YGAlignItemsTest { } @Test - public void test_align_items_center_nested() { + public void test_align_items_center_child_with_margin_bigger_than_parent() { YogaConfig config = new YogaConfig(); final YogaNode root = new YogaNode(config); @@ -1625,4 +1625,174 @@ public class YGAlignItemsTest { assertEquals(52f, root_child0_child0.getLayoutHeight(), 0.0f); } + @Test + public void test_align_items_flex_end_child_with_margin_bigger_than_parent() { + YogaConfig config = new YogaConfig(); + + final YogaNode root = new YogaNode(config); + root.setJustifyContent(YogaJustify.CENTER); + root.setAlignItems(YogaAlign.CENTER); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(52f); + root.setHeight(52f); + + final YogaNode root_child0 = new YogaNode(config); + root_child0.setAlignItems(YogaAlign.FLEX_END); + root.addChildAt(root_child0, 0); + + final YogaNode root_child0_child0 = new YogaNode(config); + root_child0_child0.setMargin(YogaEdge.LEFT, 10f); + root_child0_child0.setMargin(YogaEdge.RIGHT, 10f); + root_child0_child0.setWidth(52f); + root_child0_child0.setHeight(52f); + root_child0.addChildAt(root_child0_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(52f, root.getLayoutWidth(), 0.0f); + assertEquals(52f, root.getLayoutHeight(), 0.0f); + + assertEquals(-10f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(72f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(52f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(52f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(52f, root_child0_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(52f, root.getLayoutWidth(), 0.0f); + assertEquals(52f, root.getLayoutHeight(), 0.0f); + + assertEquals(-10f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(72f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(52f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(52f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(52f, root_child0_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_items_center_child_without_margin_bigger_than_parent() { + YogaConfig config = new YogaConfig(); + + final YogaNode root = new YogaNode(config); + root.setJustifyContent(YogaJustify.CENTER); + root.setAlignItems(YogaAlign.CENTER); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(52f); + root.setHeight(52f); + + final YogaNode root_child0 = new YogaNode(config); + root_child0.setAlignItems(YogaAlign.CENTER); + root.addChildAt(root_child0, 0); + + final YogaNode root_child0_child0 = new YogaNode(config); + root_child0_child0.setWidth(72f); + root_child0_child0.setHeight(72f); + root_child0.addChildAt(root_child0_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(52f, root.getLayoutWidth(), 0.0f); + assertEquals(52f, root.getLayoutHeight(), 0.0f); + + assertEquals(-10f, root_child0.getLayoutX(), 0.0f); + assertEquals(-10f, root_child0.getLayoutY(), 0.0f); + assertEquals(72f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(72f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(72f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(72f, root_child0_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(52f, root.getLayoutWidth(), 0.0f); + assertEquals(52f, root.getLayoutHeight(), 0.0f); + + assertEquals(-10f, root_child0.getLayoutX(), 0.0f); + assertEquals(-10f, root_child0.getLayoutY(), 0.0f); + assertEquals(72f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(72f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(72f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(72f, root_child0_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_items_flex_end_child_without_margin_bigger_than_parent() { + YogaConfig config = new YogaConfig(); + + final YogaNode root = new YogaNode(config); + root.setJustifyContent(YogaJustify.CENTER); + root.setAlignItems(YogaAlign.CENTER); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(52f); + root.setHeight(52f); + + final YogaNode root_child0 = new YogaNode(config); + root_child0.setAlignItems(YogaAlign.FLEX_END); + root.addChildAt(root_child0, 0); + + final YogaNode root_child0_child0 = new YogaNode(config); + root_child0_child0.setWidth(72f); + root_child0_child0.setHeight(72f); + root_child0.addChildAt(root_child0_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(52f, root.getLayoutWidth(), 0.0f); + assertEquals(52f, root.getLayoutHeight(), 0.0f); + + assertEquals(-10f, root_child0.getLayoutX(), 0.0f); + assertEquals(-10f, root_child0.getLayoutY(), 0.0f); + assertEquals(72f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(72f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(72f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(72f, root_child0_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(52f, root.getLayoutWidth(), 0.0f); + assertEquals(52f, root.getLayoutHeight(), 0.0f); + + assertEquals(-10f, root_child0.getLayoutX(), 0.0f); + assertEquals(-10f, root_child0.getLayoutY(), 0.0f); + assertEquals(72f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(72f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(72f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(72f, root_child0_child0.getLayoutHeight(), 0.0f); + } + } diff --git a/javascript/tests/Facebook.Yoga/YGAlignItemsTest.js b/javascript/tests/Facebook.Yoga/YGAlignItemsTest.js index 1e59df3c..baa8e595 100644 --- a/javascript/tests/Facebook.Yoga/YGAlignItemsTest.js +++ b/javascript/tests/Facebook.Yoga/YGAlignItemsTest.js @@ -1562,7 +1562,7 @@ it("align_baseline_multiline_row_and_column", function () { } } }); -it("align_items_center_nested", function () { +it("align_items_center_child_with_margin_bigger_than_parent", function () { try { var root = Yoga.Node.create(config); root.setJustifyContent(Yoga.JUSTIFY_CENTER); @@ -1620,3 +1620,173 @@ it("align_items_center_nested", function () { } } }); +it("align_items_flex_end_child_with_margin_bigger_than_parent", function () { + try { + var root = Yoga.Node.create(config); + root.setJustifyContent(Yoga.JUSTIFY_CENTER); + root.setAlignItems(Yoga.ALIGN_CENTER); + root.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); + root.setWidth(52); + root.setHeight(52); + + var root_child0 = Yoga.Node.create(config); + root_child0.setAlignItems(Yoga.ALIGN_FLEX_END); + root.insertChild(root_child0, 0); + + var root_child0_child0 = Yoga.Node.create(config); + root_child0_child0.setMargin(Yoga.EDGE_LEFT, 10); + root_child0_child0.setMargin(Yoga.EDGE_RIGHT, 10); + root_child0_child0.setWidth(52); + root_child0_child0.setHeight(52); + root_child0.insertChild(root_child0_child0, 0); + root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR); + + console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); + console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); + console.assert(52 === root.getComputedWidth(), "52 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(52 === root.getComputedHeight(), "52 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(-10 === root_child0.getComputedLeft(), "-10 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(72 === root_child0.getComputedWidth(), "72 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(52 === root_child0.getComputedHeight(), "52 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(10 === root_child0_child0.getComputedLeft(), "10 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")"); + console.assert(52 === root_child0_child0.getComputedWidth(), "52 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")"); + console.assert(52 === root_child0_child0.getComputedHeight(), "52 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")"); + + root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL); + + console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); + console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); + console.assert(52 === root.getComputedWidth(), "52 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(52 === root.getComputedHeight(), "52 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(-10 === root_child0.getComputedLeft(), "-10 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(72 === root_child0.getComputedWidth(), "72 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(52 === root_child0.getComputedHeight(), "52 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(10 === root_child0_child0.getComputedLeft(), "10 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")"); + console.assert(52 === root_child0_child0.getComputedWidth(), "52 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")"); + console.assert(52 === root_child0_child0.getComputedHeight(), "52 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")"); + } finally { + if (typeof root !== "undefined") { + root.freeRecursive(); + } + } +}); +it("align_items_center_child_without_margin_bigger_than_parent", function () { + try { + var root = Yoga.Node.create(config); + root.setJustifyContent(Yoga.JUSTIFY_CENTER); + root.setAlignItems(Yoga.ALIGN_CENTER); + root.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); + root.setWidth(52); + root.setHeight(52); + + var root_child0 = Yoga.Node.create(config); + root_child0.setAlignItems(Yoga.ALIGN_CENTER); + root.insertChild(root_child0, 0); + + var root_child0_child0 = Yoga.Node.create(config); + root_child0_child0.setWidth(72); + root_child0_child0.setHeight(72); + root_child0.insertChild(root_child0_child0, 0); + root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR); + + console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); + console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); + console.assert(52 === root.getComputedWidth(), "52 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(52 === root.getComputedHeight(), "52 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(-10 === root_child0.getComputedLeft(), "-10 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(-10 === root_child0.getComputedTop(), "-10 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(72 === root_child0.getComputedWidth(), "72 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(72 === root_child0.getComputedHeight(), "72 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(0 === root_child0_child0.getComputedLeft(), "0 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")"); + console.assert(72 === root_child0_child0.getComputedWidth(), "72 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")"); + console.assert(72 === root_child0_child0.getComputedHeight(), "72 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")"); + + root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL); + + console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); + console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); + console.assert(52 === root.getComputedWidth(), "52 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(52 === root.getComputedHeight(), "52 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(-10 === root_child0.getComputedLeft(), "-10 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(-10 === root_child0.getComputedTop(), "-10 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(72 === root_child0.getComputedWidth(), "72 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(72 === root_child0.getComputedHeight(), "72 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(0 === root_child0_child0.getComputedLeft(), "0 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")"); + console.assert(72 === root_child0_child0.getComputedWidth(), "72 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")"); + console.assert(72 === root_child0_child0.getComputedHeight(), "72 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")"); + } finally { + if (typeof root !== "undefined") { + root.freeRecursive(); + } + } +}); +it("align_items_flex_end_child_without_margin_bigger_than_parent", function () { + try { + var root = Yoga.Node.create(config); + root.setJustifyContent(Yoga.JUSTIFY_CENTER); + root.setAlignItems(Yoga.ALIGN_CENTER); + root.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); + root.setWidth(52); + root.setHeight(52); + + var root_child0 = Yoga.Node.create(config); + root_child0.setAlignItems(Yoga.ALIGN_FLEX_END); + root.insertChild(root_child0, 0); + + var root_child0_child0 = Yoga.Node.create(config); + root_child0_child0.setWidth(72); + root_child0_child0.setHeight(72); + root_child0.insertChild(root_child0_child0, 0); + root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR); + + console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); + console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); + console.assert(52 === root.getComputedWidth(), "52 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(52 === root.getComputedHeight(), "52 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(-10 === root_child0.getComputedLeft(), "-10 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(-10 === root_child0.getComputedTop(), "-10 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(72 === root_child0.getComputedWidth(), "72 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(72 === root_child0.getComputedHeight(), "72 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(0 === root_child0_child0.getComputedLeft(), "0 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")"); + console.assert(72 === root_child0_child0.getComputedWidth(), "72 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")"); + console.assert(72 === root_child0_child0.getComputedHeight(), "72 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")"); + + root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL); + + console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); + console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); + console.assert(52 === root.getComputedWidth(), "52 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(52 === root.getComputedHeight(), "52 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(-10 === root_child0.getComputedLeft(), "-10 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(-10 === root_child0.getComputedTop(), "-10 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(72 === root_child0.getComputedWidth(), "72 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(72 === root_child0.getComputedHeight(), "72 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + console.assert(0 === root_child0_child0.getComputedLeft(), "0 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")"); + console.assert(72 === root_child0_child0.getComputedWidth(), "72 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")"); + console.assert(72 === root_child0_child0.getComputedHeight(), "72 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")"); + } finally { + if (typeof root !== "undefined") { + root.freeRecursive(); + } + } +}); diff --git a/tests/YGAlignItemsTest.cpp b/tests/YGAlignItemsTest.cpp index 0bc0a596..268b6343 100644 --- a/tests/YGAlignItemsTest.cpp +++ b/tests/YGAlignItemsTest.cpp @@ -1582,7 +1582,7 @@ TEST(YogaTest, align_baseline_multiline_row_and_column) { YGConfigFree(config); } -TEST(YogaTest, align_items_center_nested) { +TEST(YogaTest, align_items_center_child_with_margin_bigger_than_parent) { const YGConfigRef config = YGConfigNew(); const YGNodeRef root = YGNodeNewWithConfig(config); @@ -1640,3 +1640,176 @@ TEST(YogaTest, align_items_center_nested) { YGConfigFree(config); } + +TEST(YogaTest, align_items_flex_end_child_with_margin_bigger_than_parent) { + const YGConfigRef config = YGConfigNew(); + + const YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetJustifyContent(root, YGJustifyCenter); + YGNodeStyleSetAlignItems(root, YGAlignCenter); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetWidth(root, 52); + YGNodeStyleSetHeight(root, 52); + + const YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetAlignItems(root_child0, YGAlignFlexEnd); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetMargin(root_child0_child0, YGEdgeLeft, 10); + YGNodeStyleSetMargin(root_child0_child0, YGEdgeRight, 10); + YGNodeStyleSetWidth(root_child0_child0, 52); + YGNodeStyleSetHeight(root_child0_child0, 52); + YGNodeInsertChild(root_child0, root_child0_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root_child0_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root_child0_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + +TEST(YogaTest, align_items_center_child_without_margin_bigger_than_parent) { + const YGConfigRef config = YGConfigNew(); + + const YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetJustifyContent(root, YGJustifyCenter); + YGNodeStyleSetAlignItems(root, YGAlignCenter); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetWidth(root, 52); + YGNodeStyleSetHeight(root, 52); + + const YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetAlignItems(root_child0, YGAlignCenter); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetWidth(root_child0_child0, 72); + YGNodeStyleSetHeight(root_child0_child0, 72); + YGNodeInsertChild(root_child0, root_child0_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + +TEST(YogaTest, align_items_flex_end_child_without_margin_bigger_than_parent) { + const YGConfigRef config = YGConfigNew(); + + const YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetJustifyContent(root, YGJustifyCenter); + YGNodeStyleSetAlignItems(root, YGAlignCenter); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetWidth(root, 52); + YGNodeStyleSetHeight(root, 52); + + const YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetAlignItems(root_child0, YGAlignFlexEnd); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetWidth(root_child0_child0, 72); + YGNodeStyleSetHeight(root_child0_child0, 72); + YGNodeInsertChild(root_child0, root_child0_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} diff --git a/yoga/Yoga.c b/yoga/Yoga.c index ee782ca3..f0f39818 100644 --- a/yoga/Yoga.c +++ b/yoga/Yoga.c @@ -2624,7 +2624,6 @@ static void YGNodelayoutImpl(const YGNodeRef node, crossAxisParentSize, parentWidth) - paddingAndBorderAxisCross; - } // If there's no flex wrap, the cross dimension is defined by the container. -- 2.50.1.windows.1 From 0cb720db59cf6668c214552bf342e0f7a9f2d7dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20W=C3=B6hrl?= Date: Sun, 12 Mar 2017 17:45:50 +0100 Subject: [PATCH 7/8] added test for auto margin and fixed those layouts --- csharp/tests/Facebook.Yoga/YGMarginTest.cs | 175 ++++++++++++++++++ gentest/fixtures/YGMarginTest.html | 16 ++ .../tests/com/facebook/yoga/YGMarginTest.java | 171 +++++++++++++++++ .../tests/Facebook.Yoga/YGMarginTest.js | 171 +++++++++++++++++ tests/YGMarginTest.cpp | 175 ++++++++++++++++++ yoga/Yoga.c | 4 +- 6 files changed, 710 insertions(+), 2 deletions(-) diff --git a/csharp/tests/Facebook.Yoga/YGMarginTest.cs b/csharp/tests/Facebook.Yoga/YGMarginTest.cs index 9ab889a0..15177ec3 100644 --- a/csharp/tests/Facebook.Yoga/YGMarginTest.cs +++ b/csharp/tests/Facebook.Yoga/YGMarginTest.cs @@ -1436,5 +1436,180 @@ namespace Facebook.Yoga Assert.AreEqual(100f, root_child0.LayoutHeight); } + [Test] + public void Test_margin_auto_left_right_child_bigger_than_parent() + { + YogaConfig config = new YogaConfig(); + + YogaNode root = new YogaNode(config); + root.JustifyContent = YogaJustify.Center; + root.PositionType = YogaPositionType.Absolute; + root.Width = 52; + root.Height = 52; + + YogaNode root_child0 = new YogaNode(config); + root_child0.MarginLeft = YogaValue.Auto(); + root_child0.MarginRight = YogaValue.Auto(); + root_child0.Width = 72; + root_child0.Height = 72; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(52f, root.LayoutWidth); + Assert.AreEqual(52f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(-10f, root_child0.LayoutY); + Assert.AreEqual(72f, root_child0.LayoutWidth); + Assert.AreEqual(72f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(52f, root.LayoutWidth); + Assert.AreEqual(52f, root.LayoutHeight); + + Assert.AreEqual(-20f, root_child0.LayoutX); + Assert.AreEqual(-10f, root_child0.LayoutY); + Assert.AreEqual(72f, root_child0.LayoutWidth); + Assert.AreEqual(72f, root_child0.LayoutHeight); + } + + [Test] + public void Test_margin_auto_left_child_bigger_than_parent() + { + YogaConfig config = new YogaConfig(); + + YogaNode root = new YogaNode(config); + root.JustifyContent = YogaJustify.Center; + root.PositionType = YogaPositionType.Absolute; + root.Width = 52; + root.Height = 52; + + YogaNode root_child0 = new YogaNode(config); + root_child0.MarginLeft = YogaValue.Auto(); + root_child0.Width = 72; + root_child0.Height = 72; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(52f, root.LayoutWidth); + Assert.AreEqual(52f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(-10f, root_child0.LayoutY); + Assert.AreEqual(72f, root_child0.LayoutWidth); + Assert.AreEqual(72f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(52f, root.LayoutWidth); + Assert.AreEqual(52f, root.LayoutHeight); + + Assert.AreEqual(-20f, root_child0.LayoutX); + Assert.AreEqual(-10f, root_child0.LayoutY); + Assert.AreEqual(72f, root_child0.LayoutWidth); + Assert.AreEqual(72f, root_child0.LayoutHeight); + } + + [Test] + public void Test_margin_fix_left_auto_right_child_bigger_than_parent() + { + YogaConfig config = new YogaConfig(); + + YogaNode root = new YogaNode(config); + root.JustifyContent = YogaJustify.Center; + root.PositionType = YogaPositionType.Absolute; + root.Width = 52; + root.Height = 52; + + YogaNode root_child0 = new YogaNode(config); + root_child0.MarginLeft = 10; + root_child0.MarginRight = YogaValue.Auto(); + root_child0.Width = 72; + root_child0.Height = 72; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(52f, root.LayoutWidth); + Assert.AreEqual(52f, root.LayoutHeight); + + Assert.AreEqual(10f, root_child0.LayoutX); + Assert.AreEqual(-10f, root_child0.LayoutY); + Assert.AreEqual(72f, root_child0.LayoutWidth); + Assert.AreEqual(72f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(52f, root.LayoutWidth); + Assert.AreEqual(52f, root.LayoutHeight); + + Assert.AreEqual(-20f, root_child0.LayoutX); + Assert.AreEqual(-10f, root_child0.LayoutY); + Assert.AreEqual(72f, root_child0.LayoutWidth); + Assert.AreEqual(72f, root_child0.LayoutHeight); + } + + [Test] + public void Test_margin_auto_left_fix_right_child_bigger_than_parent() + { + YogaConfig config = new YogaConfig(); + + YogaNode root = new YogaNode(config); + root.JustifyContent = YogaJustify.Center; + root.PositionType = YogaPositionType.Absolute; + root.Width = 52; + root.Height = 52; + + YogaNode root_child0 = new YogaNode(config); + root_child0.MarginLeft = YogaValue.Auto(); + root_child0.MarginRight = 10; + root_child0.Width = 72; + root_child0.Height = 72; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(52f, root.LayoutWidth); + Assert.AreEqual(52f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(-10f, root_child0.LayoutY); + Assert.AreEqual(72f, root_child0.LayoutWidth); + Assert.AreEqual(72f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(52f, root.LayoutWidth); + Assert.AreEqual(52f, root.LayoutHeight); + + Assert.AreEqual(-30f, root_child0.LayoutX); + Assert.AreEqual(-10f, root_child0.LayoutY); + Assert.AreEqual(72f, root_child0.LayoutWidth); + Assert.AreEqual(72f, root_child0.LayoutHeight); + } + } } diff --git a/gentest/fixtures/YGMarginTest.html b/gentest/fixtures/YGMarginTest.html index f638853d..14aeb3d0 100644 --- a/gentest/fixtures/YGMarginTest.html +++ b/gentest/fixtures/YGMarginTest.html @@ -124,3 +124,19 @@
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
diff --git a/java/tests/com/facebook/yoga/YGMarginTest.java b/java/tests/com/facebook/yoga/YGMarginTest.java index 18406112..f0d137f2 100644 --- a/java/tests/com/facebook/yoga/YGMarginTest.java +++ b/java/tests/com/facebook/yoga/YGMarginTest.java @@ -1408,4 +1408,175 @@ public class YGMarginTest { assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); } + @Test + public void test_margin_auto_left_right_child_bigger_than_parent() { + YogaConfig config = new YogaConfig(); + + final YogaNode root = new YogaNode(config); + root.setJustifyContent(YogaJustify.CENTER); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(52f); + root.setHeight(52f); + + final YogaNode root_child0 = new YogaNode(config); + root_child0.setMarginAuto(YogaEdge.LEFT); + root_child0.setMarginAuto(YogaEdge.RIGHT); + root_child0.setWidth(72f); + root_child0.setHeight(72f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(52f, root.getLayoutWidth(), 0.0f); + assertEquals(52f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(-10f, root_child0.getLayoutY(), 0.0f); + assertEquals(72f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(72f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(52f, root.getLayoutWidth(), 0.0f); + assertEquals(52f, root.getLayoutHeight(), 0.0f); + + assertEquals(-20f, root_child0.getLayoutX(), 0.0f); + assertEquals(-10f, root_child0.getLayoutY(), 0.0f); + assertEquals(72f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(72f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_margin_auto_left_child_bigger_than_parent() { + YogaConfig config = new YogaConfig(); + + final YogaNode root = new YogaNode(config); + root.setJustifyContent(YogaJustify.CENTER); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(52f); + root.setHeight(52f); + + final YogaNode root_child0 = new YogaNode(config); + root_child0.setMarginAuto(YogaEdge.LEFT); + root_child0.setWidth(72f); + root_child0.setHeight(72f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(52f, root.getLayoutWidth(), 0.0f); + assertEquals(52f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(-10f, root_child0.getLayoutY(), 0.0f); + assertEquals(72f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(72f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(52f, root.getLayoutWidth(), 0.0f); + assertEquals(52f, root.getLayoutHeight(), 0.0f); + + assertEquals(-20f, root_child0.getLayoutX(), 0.0f); + assertEquals(-10f, root_child0.getLayoutY(), 0.0f); + assertEquals(72f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(72f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_margin_fix_left_auto_right_child_bigger_than_parent() { + YogaConfig config = new YogaConfig(); + + final YogaNode root = new YogaNode(config); + root.setJustifyContent(YogaJustify.CENTER); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(52f); + root.setHeight(52f); + + final YogaNode root_child0 = new YogaNode(config); + root_child0.setMargin(YogaEdge.LEFT, 10f); + root_child0.setMarginAuto(YogaEdge.RIGHT); + root_child0.setWidth(72f); + root_child0.setHeight(72f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(52f, root.getLayoutWidth(), 0.0f); + assertEquals(52f, root.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0.getLayoutX(), 0.0f); + assertEquals(-10f, root_child0.getLayoutY(), 0.0f); + assertEquals(72f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(72f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(52f, root.getLayoutWidth(), 0.0f); + assertEquals(52f, root.getLayoutHeight(), 0.0f); + + assertEquals(-20f, root_child0.getLayoutX(), 0.0f); + assertEquals(-10f, root_child0.getLayoutY(), 0.0f); + assertEquals(72f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(72f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_margin_auto_left_fix_right_child_bigger_than_parent() { + YogaConfig config = new YogaConfig(); + + final YogaNode root = new YogaNode(config); + root.setJustifyContent(YogaJustify.CENTER); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(52f); + root.setHeight(52f); + + final YogaNode root_child0 = new YogaNode(config); + root_child0.setMarginAuto(YogaEdge.LEFT); + root_child0.setMargin(YogaEdge.RIGHT, 10f); + root_child0.setWidth(72f); + root_child0.setHeight(72f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(52f, root.getLayoutWidth(), 0.0f); + assertEquals(52f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(-10f, root_child0.getLayoutY(), 0.0f); + assertEquals(72f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(72f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(52f, root.getLayoutWidth(), 0.0f); + assertEquals(52f, root.getLayoutHeight(), 0.0f); + + assertEquals(-30f, root_child0.getLayoutX(), 0.0f); + assertEquals(-10f, root_child0.getLayoutY(), 0.0f); + assertEquals(72f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(72f, root_child0.getLayoutHeight(), 0.0f); + } + } diff --git a/javascript/tests/Facebook.Yoga/YGMarginTest.js b/javascript/tests/Facebook.Yoga/YGMarginTest.js index 2a7bed94..2e486290 100644 --- a/javascript/tests/Facebook.Yoga/YGMarginTest.js +++ b/javascript/tests/Facebook.Yoga/YGMarginTest.js @@ -1403,3 +1403,174 @@ it("margin_should_not_be_part_of_max_width", function () { } } }); +it("margin_auto_left_right_child_bigger_than_parent", function () { + try { + var root = Yoga.Node.create(config); + root.setJustifyContent(Yoga.JUSTIFY_CENTER); + root.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); + root.setWidth(52); + root.setHeight(52); + + var root_child0 = Yoga.Node.create(config); + root_child0.setMargin(Yoga.EDGE_LEFT, "auto"); + root_child0.setMargin(Yoga.EDGE_RIGHT, "auto"); + root_child0.setWidth(72); + root_child0.setHeight(72); + root.insertChild(root_child0, 0); + root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR); + + console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); + console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); + console.assert(52 === root.getComputedWidth(), "52 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(52 === root.getComputedHeight(), "52 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(-10 === root_child0.getComputedTop(), "-10 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(72 === root_child0.getComputedWidth(), "72 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(72 === root_child0.getComputedHeight(), "72 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL); + + console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); + console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); + console.assert(52 === root.getComputedWidth(), "52 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(52 === root.getComputedHeight(), "52 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(-20 === root_child0.getComputedLeft(), "-20 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(-10 === root_child0.getComputedTop(), "-10 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(72 === root_child0.getComputedWidth(), "72 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(72 === root_child0.getComputedHeight(), "72 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + } finally { + if (typeof root !== "undefined") { + root.freeRecursive(); + } + } +}); +it("margin_auto_left_child_bigger_than_parent", function () { + try { + var root = Yoga.Node.create(config); + root.setJustifyContent(Yoga.JUSTIFY_CENTER); + root.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); + root.setWidth(52); + root.setHeight(52); + + var root_child0 = Yoga.Node.create(config); + root_child0.setMargin(Yoga.EDGE_LEFT, "auto"); + root_child0.setWidth(72); + root_child0.setHeight(72); + root.insertChild(root_child0, 0); + root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR); + + console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); + console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); + console.assert(52 === root.getComputedWidth(), "52 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(52 === root.getComputedHeight(), "52 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(-10 === root_child0.getComputedTop(), "-10 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(72 === root_child0.getComputedWidth(), "72 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(72 === root_child0.getComputedHeight(), "72 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL); + + console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); + console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); + console.assert(52 === root.getComputedWidth(), "52 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(52 === root.getComputedHeight(), "52 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(-20 === root_child0.getComputedLeft(), "-20 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(-10 === root_child0.getComputedTop(), "-10 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(72 === root_child0.getComputedWidth(), "72 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(72 === root_child0.getComputedHeight(), "72 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + } finally { + if (typeof root !== "undefined") { + root.freeRecursive(); + } + } +}); +it("margin_fix_left_auto_right_child_bigger_than_parent", function () { + try { + var root = Yoga.Node.create(config); + root.setJustifyContent(Yoga.JUSTIFY_CENTER); + root.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); + root.setWidth(52); + root.setHeight(52); + + var root_child0 = Yoga.Node.create(config); + root_child0.setMargin(Yoga.EDGE_LEFT, 10); + root_child0.setMargin(Yoga.EDGE_RIGHT, "auto"); + root_child0.setWidth(72); + root_child0.setHeight(72); + root.insertChild(root_child0, 0); + root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR); + + console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); + console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); + console.assert(52 === root.getComputedWidth(), "52 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(52 === root.getComputedHeight(), "52 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(10 === root_child0.getComputedLeft(), "10 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(-10 === root_child0.getComputedTop(), "-10 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(72 === root_child0.getComputedWidth(), "72 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(72 === root_child0.getComputedHeight(), "72 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL); + + console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); + console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); + console.assert(52 === root.getComputedWidth(), "52 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(52 === root.getComputedHeight(), "52 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(-20 === root_child0.getComputedLeft(), "-20 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(-10 === root_child0.getComputedTop(), "-10 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(72 === root_child0.getComputedWidth(), "72 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(72 === root_child0.getComputedHeight(), "72 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + } finally { + if (typeof root !== "undefined") { + root.freeRecursive(); + } + } +}); +it("margin_auto_left_fix_right_child_bigger_than_parent", function () { + try { + var root = Yoga.Node.create(config); + root.setJustifyContent(Yoga.JUSTIFY_CENTER); + root.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); + root.setWidth(52); + root.setHeight(52); + + var root_child0 = Yoga.Node.create(config); + root_child0.setMargin(Yoga.EDGE_LEFT, "auto"); + root_child0.setMargin(Yoga.EDGE_RIGHT, 10); + root_child0.setWidth(72); + root_child0.setHeight(72); + root.insertChild(root_child0, 0); + root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR); + + console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); + console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); + console.assert(52 === root.getComputedWidth(), "52 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(52 === root.getComputedHeight(), "52 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(-10 === root_child0.getComputedTop(), "-10 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(72 === root_child0.getComputedWidth(), "72 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(72 === root_child0.getComputedHeight(), "72 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL); + + console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); + console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); + console.assert(52 === root.getComputedWidth(), "52 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(52 === root.getComputedHeight(), "52 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(-30 === root_child0.getComputedLeft(), "-30 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(-10 === root_child0.getComputedTop(), "-10 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(72 === root_child0.getComputedWidth(), "72 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(72 === root_child0.getComputedHeight(), "72 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + } finally { + if (typeof root !== "undefined") { + root.freeRecursive(); + } + } +}); diff --git a/tests/YGMarginTest.cpp b/tests/YGMarginTest.cpp index 7d3c966f..28208f96 100644 --- a/tests/YGMarginTest.cpp +++ b/tests/YGMarginTest.cpp @@ -1430,3 +1430,178 @@ TEST(YogaTest, margin_should_not_be_part_of_max_width) { YGConfigFree(config); } + +TEST(YogaTest, margin_auto_left_right_child_bigger_than_parent) { + const YGConfigRef config = YGConfigNew(); + + const YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetJustifyContent(root, YGJustifyCenter); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetWidth(root, 52); + YGNodeStyleSetHeight(root, 52); + + const YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetMarginAuto(root_child0, YGEdgeLeft); + YGNodeStyleSetMarginAuto(root_child0, YGEdgeRight); + YGNodeStyleSetWidth(root_child0, 72); + YGNodeStyleSetHeight(root_child0, 72); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(-20, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + +TEST(YogaTest, margin_auto_left_child_bigger_than_parent) { + const YGConfigRef config = YGConfigNew(); + + const YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetJustifyContent(root, YGJustifyCenter); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetWidth(root, 52); + YGNodeStyleSetHeight(root, 52); + + const YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetMarginAuto(root_child0, YGEdgeLeft); + YGNodeStyleSetWidth(root_child0, 72); + YGNodeStyleSetHeight(root_child0, 72); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(-20, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + +TEST(YogaTest, margin_fix_left_auto_right_child_bigger_than_parent) { + const YGConfigRef config = YGConfigNew(); + + const YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetJustifyContent(root, YGJustifyCenter); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetWidth(root, 52); + YGNodeStyleSetHeight(root, 52); + + const YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetMargin(root_child0, YGEdgeLeft, 10); + YGNodeStyleSetMarginAuto(root_child0, YGEdgeRight); + YGNodeStyleSetWidth(root_child0, 72); + YGNodeStyleSetHeight(root_child0, 72); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(-20, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + +TEST(YogaTest, margin_auto_left_fix_right_child_bigger_than_parent) { + const YGConfigRef config = YGConfigNew(); + + const YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetJustifyContent(root, YGJustifyCenter); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetWidth(root, 52); + YGNodeStyleSetHeight(root, 52); + + const YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetMarginAuto(root_child0, YGEdgeLeft); + YGNodeStyleSetMargin(root_child0, YGEdgeRight, 10); + YGNodeStyleSetWidth(root_child0, 72); + YGNodeStyleSetHeight(root_child0, 72); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(-30, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} diff --git a/yoga/Yoga.c b/yoga/Yoga.c index f0f39818..7af34567 100644 --- a/yoga/Yoga.c +++ b/yoga/Yoga.c @@ -2731,11 +2731,11 @@ static void YGNodelayoutImpl(const YGNodeRef node, if (YGMarginLeadingValue(child, crossAxis)->unit == YGUnitAuto && YGMarginTrailingValue(child, crossAxis)->unit == YGUnitAuto) { - leadingCrossDim += remainingCrossDim / 2; + leadingCrossDim += fmaxf(0.0f, remainingCrossDim / 2); } else if (YGMarginTrailingValue(child, crossAxis)->unit == YGUnitAuto) { // No-Op } else if (YGMarginLeadingValue(child, crossAxis)->unit == YGUnitAuto) { - leadingCrossDim += remainingCrossDim; + leadingCrossDim += fmaxf(0.0f, remainingCrossDim); } else if (alignItem == YGAlignFlexStart) { // No-Op } else if (alignItem == YGAlignCenter) { -- 2.50.1.windows.1 From 5f8703f345dd2507ebe229eba92ef3d98160d79a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20W=C3=B6hrl?= Date: Sun, 12 Mar 2017 17:51:05 +0100 Subject: [PATCH 8/8] remove not required position absolute from tests --- csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs | 4 ---- csharp/tests/Facebook.Yoga/YGMarginTest.cs | 4 ---- gentest/fixtures/YGAlignItemsTest.html | 8 ++++---- gentest/fixtures/YGMarginTest.html | 8 ++++---- java/tests/com/facebook/yoga/YGAlignItemsTest.java | 4 ---- java/tests/com/facebook/yoga/YGMarginTest.java | 4 ---- javascript/tests/Facebook.Yoga/YGAlignItemsTest.js | 4 ---- javascript/tests/Facebook.Yoga/YGMarginTest.js | 4 ---- tests/YGAlignItemsTest.cpp | 4 ---- tests/YGMarginTest.cpp | 4 ---- 10 files changed, 8 insertions(+), 40 deletions(-) diff --git a/csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs b/csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs index 4d0dbd7d..7b150568 100644 --- a/csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs +++ b/csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs @@ -1595,7 +1595,6 @@ namespace Facebook.Yoga YogaNode root = new YogaNode(config); root.JustifyContent = YogaJustify.Center; root.AlignItems = YogaAlign.Center; - root.PositionType = YogaPositionType.Absolute; root.Width = 52; root.Height = 52; @@ -1654,7 +1653,6 @@ namespace Facebook.Yoga YogaNode root = new YogaNode(config); root.JustifyContent = YogaJustify.Center; root.AlignItems = YogaAlign.Center; - root.PositionType = YogaPositionType.Absolute; root.Width = 52; root.Height = 52; @@ -1713,7 +1711,6 @@ namespace Facebook.Yoga YogaNode root = new YogaNode(config); root.JustifyContent = YogaJustify.Center; root.AlignItems = YogaAlign.Center; - root.PositionType = YogaPositionType.Absolute; root.Width = 52; root.Height = 52; @@ -1770,7 +1767,6 @@ namespace Facebook.Yoga YogaNode root = new YogaNode(config); root.JustifyContent = YogaJustify.Center; root.AlignItems = YogaAlign.Center; - root.PositionType = YogaPositionType.Absolute; root.Width = 52; root.Height = 52; diff --git a/csharp/tests/Facebook.Yoga/YGMarginTest.cs b/csharp/tests/Facebook.Yoga/YGMarginTest.cs index 15177ec3..965cfc78 100644 --- a/csharp/tests/Facebook.Yoga/YGMarginTest.cs +++ b/csharp/tests/Facebook.Yoga/YGMarginTest.cs @@ -1443,7 +1443,6 @@ namespace Facebook.Yoga YogaNode root = new YogaNode(config); root.JustifyContent = YogaJustify.Center; - root.PositionType = YogaPositionType.Absolute; root.Width = 52; root.Height = 52; @@ -1487,7 +1486,6 @@ namespace Facebook.Yoga YogaNode root = new YogaNode(config); root.JustifyContent = YogaJustify.Center; - root.PositionType = YogaPositionType.Absolute; root.Width = 52; root.Height = 52; @@ -1530,7 +1528,6 @@ namespace Facebook.Yoga YogaNode root = new YogaNode(config); root.JustifyContent = YogaJustify.Center; - root.PositionType = YogaPositionType.Absolute; root.Width = 52; root.Height = 52; @@ -1574,7 +1571,6 @@ namespace Facebook.Yoga YogaNode root = new YogaNode(config); root.JustifyContent = YogaJustify.Center; - root.PositionType = YogaPositionType.Absolute; root.Width = 52; root.Height = 52; diff --git a/gentest/fixtures/YGAlignItemsTest.html b/gentest/fixtures/YGAlignItemsTest.html index b11e0f86..2c88c306 100644 --- a/gentest/fixtures/YGAlignItemsTest.html +++ b/gentest/fixtures/YGAlignItemsTest.html @@ -144,25 +144,25 @@
-
+
-
+
-
+
-
+
diff --git a/gentest/fixtures/YGMarginTest.html b/gentest/fixtures/YGMarginTest.html index 14aeb3d0..ac7a2aa9 100644 --- a/gentest/fixtures/YGMarginTest.html +++ b/gentest/fixtures/YGMarginTest.html @@ -125,18 +125,18 @@
-
+
-
+
-
+
-
+
diff --git a/java/tests/com/facebook/yoga/YGAlignItemsTest.java b/java/tests/com/facebook/yoga/YGAlignItemsTest.java index f581e34c..cea82fb5 100644 --- a/java/tests/com/facebook/yoga/YGAlignItemsTest.java +++ b/java/tests/com/facebook/yoga/YGAlignItemsTest.java @@ -1574,7 +1574,6 @@ public class YGAlignItemsTest { final YogaNode root = new YogaNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setAlignItems(YogaAlign.CENTER); - root.setPositionType(YogaPositionType.ABSOLUTE); root.setWidth(52f); root.setHeight(52f); @@ -1632,7 +1631,6 @@ public class YGAlignItemsTest { final YogaNode root = new YogaNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setAlignItems(YogaAlign.CENTER); - root.setPositionType(YogaPositionType.ABSOLUTE); root.setWidth(52f); root.setHeight(52f); @@ -1690,7 +1688,6 @@ public class YGAlignItemsTest { final YogaNode root = new YogaNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setAlignItems(YogaAlign.CENTER); - root.setPositionType(YogaPositionType.ABSOLUTE); root.setWidth(52f); root.setHeight(52f); @@ -1746,7 +1743,6 @@ public class YGAlignItemsTest { final YogaNode root = new YogaNode(config); root.setJustifyContent(YogaJustify.CENTER); root.setAlignItems(YogaAlign.CENTER); - root.setPositionType(YogaPositionType.ABSOLUTE); root.setWidth(52f); root.setHeight(52f); diff --git a/java/tests/com/facebook/yoga/YGMarginTest.java b/java/tests/com/facebook/yoga/YGMarginTest.java index f0d137f2..fe7a9518 100644 --- a/java/tests/com/facebook/yoga/YGMarginTest.java +++ b/java/tests/com/facebook/yoga/YGMarginTest.java @@ -1414,7 +1414,6 @@ public class YGMarginTest { final YogaNode root = new YogaNode(config); root.setJustifyContent(YogaJustify.CENTER); - root.setPositionType(YogaPositionType.ABSOLUTE); root.setWidth(52f); root.setHeight(52f); @@ -1457,7 +1456,6 @@ public class YGMarginTest { final YogaNode root = new YogaNode(config); root.setJustifyContent(YogaJustify.CENTER); - root.setPositionType(YogaPositionType.ABSOLUTE); root.setWidth(52f); root.setHeight(52f); @@ -1499,7 +1497,6 @@ public class YGMarginTest { final YogaNode root = new YogaNode(config); root.setJustifyContent(YogaJustify.CENTER); - root.setPositionType(YogaPositionType.ABSOLUTE); root.setWidth(52f); root.setHeight(52f); @@ -1542,7 +1539,6 @@ public class YGMarginTest { final YogaNode root = new YogaNode(config); root.setJustifyContent(YogaJustify.CENTER); - root.setPositionType(YogaPositionType.ABSOLUTE); root.setWidth(52f); root.setHeight(52f); diff --git a/javascript/tests/Facebook.Yoga/YGAlignItemsTest.js b/javascript/tests/Facebook.Yoga/YGAlignItemsTest.js index baa8e595..edd37885 100644 --- a/javascript/tests/Facebook.Yoga/YGAlignItemsTest.js +++ b/javascript/tests/Facebook.Yoga/YGAlignItemsTest.js @@ -1567,7 +1567,6 @@ it("align_items_center_child_with_margin_bigger_than_parent", function () { var root = Yoga.Node.create(config); root.setJustifyContent(Yoga.JUSTIFY_CENTER); root.setAlignItems(Yoga.ALIGN_CENTER); - root.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); root.setWidth(52); root.setHeight(52); @@ -1625,7 +1624,6 @@ it("align_items_flex_end_child_with_margin_bigger_than_parent", function () { var root = Yoga.Node.create(config); root.setJustifyContent(Yoga.JUSTIFY_CENTER); root.setAlignItems(Yoga.ALIGN_CENTER); - root.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); root.setWidth(52); root.setHeight(52); @@ -1683,7 +1681,6 @@ it("align_items_center_child_without_margin_bigger_than_parent", function () { var root = Yoga.Node.create(config); root.setJustifyContent(Yoga.JUSTIFY_CENTER); root.setAlignItems(Yoga.ALIGN_CENTER); - root.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); root.setWidth(52); root.setHeight(52); @@ -1739,7 +1736,6 @@ it("align_items_flex_end_child_without_margin_bigger_than_parent", function () { var root = Yoga.Node.create(config); root.setJustifyContent(Yoga.JUSTIFY_CENTER); root.setAlignItems(Yoga.ALIGN_CENTER); - root.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); root.setWidth(52); root.setHeight(52); diff --git a/javascript/tests/Facebook.Yoga/YGMarginTest.js b/javascript/tests/Facebook.Yoga/YGMarginTest.js index 2e486290..0ed2f1ca 100644 --- a/javascript/tests/Facebook.Yoga/YGMarginTest.js +++ b/javascript/tests/Facebook.Yoga/YGMarginTest.js @@ -1407,7 +1407,6 @@ it("margin_auto_left_right_child_bigger_than_parent", function () { try { var root = Yoga.Node.create(config); root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); root.setWidth(52); root.setHeight(52); @@ -1450,7 +1449,6 @@ it("margin_auto_left_child_bigger_than_parent", function () { try { var root = Yoga.Node.create(config); root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); root.setWidth(52); root.setHeight(52); @@ -1492,7 +1490,6 @@ it("margin_fix_left_auto_right_child_bigger_than_parent", function () { try { var root = Yoga.Node.create(config); root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); root.setWidth(52); root.setHeight(52); @@ -1535,7 +1532,6 @@ it("margin_auto_left_fix_right_child_bigger_than_parent", function () { try { var root = Yoga.Node.create(config); root.setJustifyContent(Yoga.JUSTIFY_CENTER); - root.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); root.setWidth(52); root.setHeight(52); diff --git a/tests/YGAlignItemsTest.cpp b/tests/YGAlignItemsTest.cpp index 268b6343..8fe2deff 100644 --- a/tests/YGAlignItemsTest.cpp +++ b/tests/YGAlignItemsTest.cpp @@ -1588,7 +1588,6 @@ TEST(YogaTest, align_items_center_child_with_margin_bigger_than_parent) { const YGNodeRef root = YGNodeNewWithConfig(config); YGNodeStyleSetJustifyContent(root, YGJustifyCenter); YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); YGNodeStyleSetWidth(root, 52); YGNodeStyleSetHeight(root, 52); @@ -1647,7 +1646,6 @@ TEST(YogaTest, align_items_flex_end_child_with_margin_bigger_than_parent) { const YGNodeRef root = YGNodeNewWithConfig(config); YGNodeStyleSetJustifyContent(root, YGJustifyCenter); YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); YGNodeStyleSetWidth(root, 52); YGNodeStyleSetHeight(root, 52); @@ -1706,7 +1704,6 @@ TEST(YogaTest, align_items_center_child_without_margin_bigger_than_parent) { const YGNodeRef root = YGNodeNewWithConfig(config); YGNodeStyleSetJustifyContent(root, YGJustifyCenter); YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); YGNodeStyleSetWidth(root, 52); YGNodeStyleSetHeight(root, 52); @@ -1763,7 +1760,6 @@ TEST(YogaTest, align_items_flex_end_child_without_margin_bigger_than_parent) { const YGNodeRef root = YGNodeNewWithConfig(config); YGNodeStyleSetJustifyContent(root, YGJustifyCenter); YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); YGNodeStyleSetWidth(root, 52); YGNodeStyleSetHeight(root, 52); diff --git a/tests/YGMarginTest.cpp b/tests/YGMarginTest.cpp index 28208f96..a7ff069f 100644 --- a/tests/YGMarginTest.cpp +++ b/tests/YGMarginTest.cpp @@ -1436,7 +1436,6 @@ TEST(YogaTest, margin_auto_left_right_child_bigger_than_parent) { const YGNodeRef root = YGNodeNewWithConfig(config); YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); YGNodeStyleSetWidth(root, 52); YGNodeStyleSetHeight(root, 52); @@ -1480,7 +1479,6 @@ TEST(YogaTest, margin_auto_left_child_bigger_than_parent) { const YGNodeRef root = YGNodeNewWithConfig(config); YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); YGNodeStyleSetWidth(root, 52); YGNodeStyleSetHeight(root, 52); @@ -1523,7 +1521,6 @@ TEST(YogaTest, margin_fix_left_auto_right_child_bigger_than_parent) { const YGNodeRef root = YGNodeNewWithConfig(config); YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); YGNodeStyleSetWidth(root, 52); YGNodeStyleSetHeight(root, 52); @@ -1567,7 +1564,6 @@ TEST(YogaTest, margin_auto_left_fix_right_child_bigger_than_parent) { const YGNodeRef root = YGNodeNewWithConfig(config); YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); YGNodeStyleSetWidth(root, 52); YGNodeStyleSetHeight(root, 52); -- 2.50.1.windows.1