From 31b5e63adf6814495db5b69a70fb5c3b22cc06a2 Mon Sep 17 00:00:00 2001 From: Joe Vilches Date: Mon, 30 Sep 2024 13:28:09 -0700 Subject: [PATCH 1/4] Rename Node.h's getResolvedDimension to getDimensionLength Differential Revision: D63407730 --- yoga/algorithm/AbsoluteLayout.cpp | 4 ++-- yoga/algorithm/CalculateLayout.cpp | 24 ++++++++++++------------ yoga/node/Node.cpp | 8 ++++---- yoga/node/Node.h | 14 +++++--------- 4 files changed, 23 insertions(+), 27 deletions(-) diff --git a/yoga/algorithm/AbsoluteLayout.cpp b/yoga/algorithm/AbsoluteLayout.cpp index b3651b40..c54cbcc6 100644 --- a/yoga/algorithm/AbsoluteLayout.cpp +++ b/yoga/algorithm/AbsoluteLayout.cpp @@ -324,7 +324,7 @@ void layoutAbsoluteChild( FlexDirection::Column, containingBlockWidth); if (child->hasDefiniteLength(Dimension::Width, containingBlockWidth)) { - childWidth = child->getResolvedDimension(Dimension::Width) + childWidth = child->getProcessedDimension(Dimension::Width) .resolve(containingBlockWidth) .unwrap() + marginRow; @@ -359,7 +359,7 @@ void layoutAbsoluteChild( } if (child->hasDefiniteLength(Dimension::Height, containingBlockHeight)) { - childHeight = child->getResolvedDimension(Dimension::Height) + childHeight = child->getProcessedDimension(Dimension::Height) .resolve(containingBlockHeight) .unwrap() + marginColumn; diff --git a/yoga/algorithm/CalculateLayout.cpp b/yoga/algorithm/CalculateLayout.cpp index c9c8b001..d68b11cf 100644 --- a/yoga/algorithm/CalculateLayout.cpp +++ b/yoga/algorithm/CalculateLayout.cpp @@ -110,7 +110,7 @@ static void computeFlexBasisForChild( child, FlexDirection::Row, direction, ownerWidth)); child->setLayoutComputedFlexBasis(yoga::maxOrDefined( - child->getResolvedDimension(Dimension::Width).resolve(ownerWidth), + child->getProcessedDimension(Dimension::Width).resolve(ownerWidth), paddingAndBorder)); } else if (!isMainAxisRow && isColumnStyleDimDefined) { // The height is definite, so use that as the flex basis. @@ -118,7 +118,7 @@ static void computeFlexBasisForChild( FloatOptional(paddingAndBorderForAxis( child, FlexDirection::Column, direction, ownerWidth)); child->setLayoutComputedFlexBasis(yoga::maxOrDefined( - child->getResolvedDimension(Dimension::Height).resolve(ownerHeight), + child->getProcessedDimension(Dimension::Height).resolve(ownerHeight), paddingAndBorder)); } else { // Compute the flex basis and hypothetical main size (i.e. the clamped flex @@ -132,14 +132,14 @@ static void computeFlexBasisForChild( child->style().computeMarginForAxis(FlexDirection::Column, ownerWidth); if (isRowStyleDimDefined) { - childWidth = child->getResolvedDimension(Dimension::Width) + childWidth = child->getProcessedDimension(Dimension::Width) .resolve(ownerWidth) .unwrap() + marginRow; childWidthSizingMode = SizingMode::StretchFit; } if (isColumnStyleDimDefined) { - childHeight = child->getResolvedDimension(Dimension::Height) + childHeight = child->getProcessedDimension(Dimension::Height) .resolve(ownerHeight) .unwrap() + marginColumn; @@ -536,7 +536,7 @@ static float computeFlexBasisForChildren( } for (auto child : children) { - child->resolveDimension(); + child->processDimensions(); if (child->style().display() == Display::None) { zeroOutLayoutRecursively(child); child->setHasNewLayout(true); @@ -709,13 +709,13 @@ static float distributeFreeSpaceSecondPass( : SizingMode::FitContent; } else { childCrossSize = - currentLineChild->getResolvedDimension(dimension(crossAxis)) + currentLineChild->getProcessedDimension(dimension(crossAxis)) .resolve(availableInnerCrossDim) .unwrap() + marginCross; const bool isLoosePercentageMeasurement = - currentLineChild->getResolvedDimension(dimension(crossAxis)).unit() == - Unit::Percent && + currentLineChild->getProcessedDimension(dimension(crossAxis)) + .unit() == Unit::Percent && sizingModeCrossDim != SizingMode::StretchFit; childCrossSizingMode = yoga::isUndefined(childCrossSize) || isLoosePercentageMeasurement @@ -1781,7 +1781,7 @@ static void calculateLayoutImpl( const float unclampedCrossDim = sizingModeCrossDim == SizingMode::StretchFit ? availableInnerCrossDim + paddingAndBorderAxisCross : node->hasDefiniteLength(dimension(crossAxis), crossAxisownerSize) - ? node->getResolvedDimension(dimension(crossAxis)) + ? node->getProcessedDimension(dimension(crossAxis)) .resolve(crossAxisownerSize) .unwrap() : totalLineCrossDim + paddingAndBorderAxisCross; @@ -2354,13 +2354,13 @@ void calculateLayout( // visit all dirty nodes at least once. Subsequent visits will be skipped if // the input parameters don't change. gCurrentGenerationCount.fetch_add(1, std::memory_order_relaxed); - node->resolveDimension(); + node->processDimensions(); float width = YGUndefined; SizingMode widthSizingMode = SizingMode::MaxContent; const auto& style = node->style(); if (node->hasDefiniteLength(Dimension::Width, ownerWidth)) { width = - (node->getResolvedDimension(dimension(FlexDirection::Row)) + (node->getProcessedDimension(dimension(FlexDirection::Row)) .resolve(ownerWidth) .unwrap() + node->style().computeMarginForAxis(FlexDirection::Row, ownerWidth)); @@ -2380,7 +2380,7 @@ void calculateLayout( SizingMode heightSizingMode = SizingMode::MaxContent; if (node->hasDefiniteLength(Dimension::Height, ownerHeight)) { height = - (node->getResolvedDimension(dimension(FlexDirection::Column)) + (node->getProcessedDimension(dimension(FlexDirection::Column)) .resolve(ownerHeight) .unwrap() + node->style().computeMarginForAxis(FlexDirection::Column, ownerWidth)); diff --git a/yoga/node/Node.cpp b/yoga/node/Node.cpp index eb10f152..83e47bd6 100644 --- a/yoga/node/Node.cpp +++ b/yoga/node/Node.cpp @@ -43,7 +43,7 @@ Node::Node(Node&& node) noexcept owner_(node.owner_), children_(std::move(node.children_)), config_(node.config_), - resolvedDimensions_(node.resolvedDimensions_) { + processedDimensions_(node.processedDimensions_) { for (auto c : children_) { c->setOwner(this); } @@ -292,14 +292,14 @@ Style::Length Node::resolveFlexBasisPtr() const { return value::ofAuto(); } -void Node::resolveDimension() { +void Node::processDimensions() { for (auto dim : {Dimension::Width, Dimension::Height}) { if (style_.maxDimension(dim).isDefined() && yoga::inexactEquals( style_.maxDimension(dim), style_.minDimension(dim))) { - resolvedDimensions_[yoga::to_underlying(dim)] = style_.maxDimension(dim); + processedDimensions_[yoga::to_underlying(dim)] = style_.maxDimension(dim); } else { - resolvedDimensions_[yoga::to_underlying(dim)] = style_.dimension(dim); + processedDimensions_[yoga::to_underlying(dim)] = style_.dimension(dim); } } } diff --git a/yoga/node/Node.h b/yoga/node/Node.h index 06175b8e..8c93d43a 100644 --- a/yoga/node/Node.h +++ b/yoga/node/Node.h @@ -86,7 +86,7 @@ class YG_EXPORT Node : public ::YGNode { * https://www.w3.org/TR/css-sizing-3/#definite */ inline bool hasDefiniteLength(Dimension dimension, float ownerSize) { - auto usedValue = getResolvedDimension(dimension).resolve(ownerSize); + auto usedValue = getProcessedDimension(dimension).resolve(ownerSize); return usedValue.isDefined() && usedValue.unwrap() >= 0.0f; } @@ -152,12 +152,8 @@ class YG_EXPORT Node : public ::YGNode { return isDirty_; } - std::array getResolvedDimensions() const { - return resolvedDimensions_; - } - - Style::Length getResolvedDimension(Dimension dimension) const { - return resolvedDimensions_[static_cast(dimension)]; + Style::Length getProcessedDimension(Dimension dimension) const { + return processedDimensions_[static_cast(dimension)]; } // Setters @@ -233,7 +229,7 @@ class YG_EXPORT Node : public ::YGNode { // Other methods Style::Length resolveFlexBasisPtr() const; - void resolveDimension(); + void processDimensions(); Direction resolveDirection(Direction ownerDirection); void clearChildren(); /// Replaces the occurrences of oldChild with newChild @@ -280,7 +276,7 @@ class YG_EXPORT Node : public ::YGNode { Node* owner_ = nullptr; std::vector children_; const Config* config_; - std::array resolvedDimensions_{ + std::array processedDimensions_{ {value::undefined(), value::undefined()}}; }; -- 2.50.1.windows.1 From b7cfdf71620367590fcb9f0e307227153747a9a3 Mon Sep 17 00:00:00 2001 From: Joe Vilches Date: Mon, 30 Sep 2024 13:28:10 -0700 Subject: [PATCH 2/4] Clean up calls to dimension() with a hardcoded FlexDirection Differential Revision: D63408245 --- yoga/algorithm/CalculateLayout.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yoga/algorithm/CalculateLayout.cpp b/yoga/algorithm/CalculateLayout.cpp index d68b11cf..43f797c0 100644 --- a/yoga/algorithm/CalculateLayout.cpp +++ b/yoga/algorithm/CalculateLayout.cpp @@ -2360,7 +2360,7 @@ void calculateLayout( const auto& style = node->style(); if (node->hasDefiniteLength(Dimension::Width, ownerWidth)) { width = - (node->getProcessedDimension(dimension(FlexDirection::Row)) + (node->getProcessedDimension(Dimension::Width) .resolve(ownerWidth) .unwrap() + node->style().computeMarginForAxis(FlexDirection::Row, ownerWidth)); @@ -2380,7 +2380,7 @@ void calculateLayout( SizingMode heightSizingMode = SizingMode::MaxContent; if (node->hasDefiniteLength(Dimension::Height, ownerHeight)) { height = - (node->getProcessedDimension(dimension(FlexDirection::Column)) + (node->getProcessedDimension(Dimension::Height) .resolve(ownerHeight) .unwrap() + node->style().computeMarginForAxis(FlexDirection::Column, ownerWidth)); -- 2.50.1.windows.1 From fc590b2e6f95df66f65618c87327755a403a1074 Mon Sep 17 00:00:00 2001 From: Joe Vilches Date: Mon, 30 Sep 2024 14:09:06 -0700 Subject: [PATCH 3/4] Initial impl of content box Differential Revision: D63416833 --- gentest/fixtures/YGBoxSizingTest.html | 28 +++--- .../com/facebook/yoga/YGBoxSizingTest.java | 18 +--- .../tests/generated/YGBoxSizingTest.test.ts | 30 +++--- tests/generated/YGBoxSizingTest.cpp | 32 +------ yoga/algorithm/AbsoluteLayout.cpp | 10 +- yoga/algorithm/BoundAxis.h | 16 +++- yoga/algorithm/CalculateLayout.cpp | 95 ++++++++++++------- yoga/algorithm/FlexLine.cpp | 6 +- yoga/node/Node.h | 19 ++++ yoga/style/Style.h | 48 ++++++++++ 10 files changed, 181 insertions(+), 121 deletions(-) diff --git a/gentest/fixtures/YGBoxSizingTest.html b/gentest/fixtures/YGBoxSizingTest.html index a0a57185..44c024e7 100644 --- a/gentest/fixtures/YGBoxSizingTest.html +++ b/gentest/fixtures/YGBoxSizingTest.html @@ -1,4 +1,4 @@ -
@@ -6,7 +6,7 @@ style="width: 100px; height: 100px; padding: 5px; border-width: 10px; box-sizing: border-box"> -
@@ -14,7 +14,7 @@ style="width: 100px; height: 100px; padding: 5px; box-sizing: border-box"> -
@@ -22,7 +22,7 @@ style="width: 100px; height: 100px; border-width: 10px; box-sizing: border-box"> -
@@ -30,7 +30,7 @@ style="width: 100px; height: 100px; box-sizing: border-box"> -
@@ -46,7 +46,7 @@
-
+
@@ -60,7 +60,7 @@
-
+
@@ -70,7 +70,7 @@
-
+
@@ -80,7 +80,7 @@
-
+
@@ -90,7 +90,7 @@
-
+
@@ -100,7 +100,7 @@
-
+
@@ -110,7 +110,7 @@
-
@@ -124,7 +124,7 @@
-
@@ -134,7 +134,7 @@
-
diff --git a/java/tests/generated/com/facebook/yoga/YGBoxSizingTest.java b/java/tests/generated/com/facebook/yoga/YGBoxSizingTest.java index 2cffa0a9..6426078a 100644 --- a/java/tests/generated/com/facebook/yoga/YGBoxSizingTest.java +++ b/java/tests/generated/com/facebook/yoga/YGBoxSizingTest.java @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<84bb16d1a7ae39fb8f159ee58baef4c2>> + * @generated SignedSource<> * generated by gentest/gentest-driver.ts from gentest/fixtures/YGBoxSizingTest.html */ @@ -28,8 +28,7 @@ public class YGBoxSizingTest { @Parameterized.Parameter public TestParametrization.NodeFactory mNodeFactory; @Test - @Ignore - public void test_box_sizing_content_box() { + public void test_box_sizing_content_box_simple() { YogaConfig config = YogaConfigFactory.create(); final YogaNode root = createNode(config); @@ -96,7 +95,6 @@ public class YGBoxSizingTest { } @Test - @Ignore public void test_box_sizing_content_box_padding_only() { YogaConfig config = YogaConfigFactory.create(); @@ -156,7 +154,6 @@ public class YGBoxSizingTest { } @Test - @Ignore public void test_box_sizing_content_box_border_only() { YogaConfig config = YogaConfigFactory.create(); @@ -216,7 +213,6 @@ public class YGBoxSizingTest { } @Test - @Ignore public void test_box_sizing_content_box_no_padding_no_border() { YogaConfig config = YogaConfigFactory.create(); @@ -268,7 +264,6 @@ public class YGBoxSizingTest { } @Test - @Ignore public void test_box_sizing_content_box_children() { YogaConfig config = YogaConfigFactory.create(); @@ -456,7 +451,6 @@ public class YGBoxSizingTest { } @Test - @Ignore public void test_box_sizing_content_box_siblings() { YogaConfig config = YogaConfigFactory.create(); @@ -644,7 +638,6 @@ public class YGBoxSizingTest { } @Test - @Ignore public void test_box_sizing_content_box_max_width() { YogaConfig config = YogaConfigFactory.create(); @@ -772,7 +765,6 @@ public class YGBoxSizingTest { } @Test - @Ignore public void test_box_sizing_content_box_max_height() { YogaConfig config = YogaConfigFactory.create(); @@ -900,7 +892,6 @@ public class YGBoxSizingTest { } @Test - @Ignore public void test_box_sizing_content_box_min_width() { YogaConfig config = YogaConfigFactory.create(); @@ -1028,7 +1019,6 @@ public class YGBoxSizingTest { } @Test - @Ignore public void test_box_sizing_content_box_min_height() { YogaConfig config = YogaConfigFactory.create(); @@ -1156,7 +1146,6 @@ public class YGBoxSizingTest { } @Test - @Ignore public void test_box_sizing_content_box_no_height_no_width() { YogaConfig config = YogaConfigFactory.create(); @@ -1250,7 +1239,6 @@ public class YGBoxSizingTest { } @Test - @Ignore public void test_box_sizing_content_box_nested() { YogaConfig config = YogaConfigFactory.create(); @@ -1412,7 +1400,6 @@ public class YGBoxSizingTest { } @Test - @Ignore public void test_box_sizing_content_box_nested_alternating() { YogaConfig config = YogaConfigFactory.create(); @@ -1517,7 +1504,6 @@ public class YGBoxSizingTest { } @Test - @Ignore public void test_box_sizing_border_box_nested_alternating() { YogaConfig config = YogaConfigFactory.create(); diff --git a/javascript/tests/generated/YGBoxSizingTest.test.ts b/javascript/tests/generated/YGBoxSizingTest.test.ts index 4fd75be1..b96070ea 100644 --- a/javascript/tests/generated/YGBoxSizingTest.test.ts +++ b/javascript/tests/generated/YGBoxSizingTest.test.ts @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<40a2a45449f152b9c1f91adfc46ac6df>> + * @generated SignedSource<<5ce4b1bc764d2bf325b844053b98134e>> * generated by gentest/gentest-driver.ts from gentest/fixtures/YGBoxSizingTest.html */ @@ -28,7 +28,7 @@ import { Wrap, } from 'yoga-layout'; -test.skip('box_sizing_content_box', () => { +test('box_sizing_content_box_simple', () => { const config = Yoga.Config.create(); let root; @@ -105,7 +105,7 @@ test('box_sizing_border_box', () => { config.free(); } }); -test.skip('box_sizing_content_box_padding_only', () => { +test('box_sizing_content_box_padding_only', () => { const config = Yoga.Config.create(); let root; @@ -174,7 +174,7 @@ test('box_sizing_border_box_padding_only', () => { config.free(); } }); -test.skip('box_sizing_content_box_border_only', () => { +test('box_sizing_content_box_border_only', () => { const config = Yoga.Config.create(); let root; @@ -243,7 +243,7 @@ test('box_sizing_border_box_border_only', () => { config.free(); } }); -test.skip('box_sizing_content_box_no_padding_no_border', () => { +test('box_sizing_content_box_no_padding_no_border', () => { const config = Yoga.Config.create(); let root; @@ -304,7 +304,7 @@ test('box_sizing_border_box_no_padding_no_border', () => { config.free(); } }); -test.skip('box_sizing_content_box_children', () => { +test('box_sizing_content_box_children', () => { const config = Yoga.Config.create(); let root; @@ -501,7 +501,7 @@ test('box_sizing_border_box_children', () => { config.free(); } }); -test.skip('box_sizing_content_box_siblings', () => { +test('box_sizing_content_box_siblings', () => { const config = Yoga.Config.create(); let root; @@ -698,7 +698,7 @@ test('box_sizing_border_box_siblings', () => { config.free(); } }); -test.skip('box_sizing_content_box_max_width', () => { +test('box_sizing_content_box_max_width', () => { const config = Yoga.Config.create(); let root; @@ -835,7 +835,7 @@ test('box_sizing_border_box_max_width', () => { config.free(); } }); -test.skip('box_sizing_content_box_max_height', () => { +test('box_sizing_content_box_max_height', () => { const config = Yoga.Config.create(); let root; @@ -972,7 +972,7 @@ test('box_sizing_border_box_max_height', () => { config.free(); } }); -test.skip('box_sizing_content_box_min_width', () => { +test('box_sizing_content_box_min_width', () => { const config = Yoga.Config.create(); let root; @@ -1109,7 +1109,7 @@ test('box_sizing_border_box_min_width', () => { config.free(); } }); -test.skip('box_sizing_content_box_min_height', () => { +test('box_sizing_content_box_min_height', () => { const config = Yoga.Config.create(); let root; @@ -1246,7 +1246,7 @@ test('box_sizing_border_box_min_height', () => { config.free(); } }); -test.skip('box_sizing_content_box_no_height_no_width', () => { +test('box_sizing_content_box_no_height_no_width', () => { const config = Yoga.Config.create(); let root; @@ -1349,7 +1349,7 @@ test('box_sizing_border_box_no_height_no_width', () => { config.free(); } }); -test.skip('box_sizing_content_box_nested', () => { +test('box_sizing_content_box_nested', () => { const config = Yoga.Config.create(); let root; @@ -1520,7 +1520,7 @@ test('box_sizing_border_box_nested', () => { config.free(); } }); -test.skip('box_sizing_content_box_nested_alternating', () => { +test('box_sizing_content_box_nested_alternating', () => { const config = Yoga.Config.create(); let root; @@ -1629,7 +1629,7 @@ test.skip('box_sizing_content_box_nested_alternating', () => { config.free(); } }); -test.skip('box_sizing_border_box_nested_alternating', () => { +test('box_sizing_border_box_nested_alternating', () => { const config = Yoga.Config.create(); let root; diff --git a/tests/generated/YGBoxSizingTest.cpp b/tests/generated/YGBoxSizingTest.cpp index 1728a7a7..91b29040 100644 --- a/tests/generated/YGBoxSizingTest.cpp +++ b/tests/generated/YGBoxSizingTest.cpp @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * clang-format off - * @generated SignedSource<<38c0ba6ef126d3453c7e0b56da131566>> + * @generated SignedSource<<56d0eec106ade0bbd034067594249c76>> * generated by gentest/gentest-driver.ts from gentest/fixtures/YGBoxSizingTest.html */ @@ -13,9 +13,7 @@ #include #include "../util/TestUtil.h" -TEST(YogaTest, box_sizing_content_box) { - GTEST_SKIP(); - +TEST(YogaTest, box_sizing_content_box_simple) { YGConfigRef config = YGConfigNew(); YGNodeRef root = YGNodeNewWithConfig(config); @@ -85,8 +83,6 @@ TEST(YogaTest, box_sizing_border_box) { } TEST(YogaTest, box_sizing_content_box_padding_only) { - GTEST_SKIP(); - YGConfigRef config = YGConfigNew(); YGNodeRef root = YGNodeNewWithConfig(config); @@ -148,8 +144,6 @@ TEST(YogaTest, box_sizing_border_box_padding_only) { } TEST(YogaTest, box_sizing_content_box_border_only) { - GTEST_SKIP(); - YGConfigRef config = YGConfigNew(); YGNodeRef root = YGNodeNewWithConfig(config); @@ -211,8 +205,6 @@ TEST(YogaTest, box_sizing_border_box_border_only) { } TEST(YogaTest, box_sizing_content_box_no_padding_no_border) { - GTEST_SKIP(); - YGConfigRef config = YGConfigNew(); YGNodeRef root = YGNodeNewWithConfig(config); @@ -266,8 +258,6 @@ TEST(YogaTest, box_sizing_border_box_no_padding_no_border) { } TEST(YogaTest, box_sizing_content_box_children) { - GTEST_SKIP(); - YGConfigRef config = YGConfigNew(); YGNodeRef root = YGNodeNewWithConfig(config); @@ -457,8 +447,6 @@ TEST(YogaTest, box_sizing_border_box_children) { } TEST(YogaTest, box_sizing_content_box_siblings) { - GTEST_SKIP(); - YGConfigRef config = YGConfigNew(); YGNodeRef root = YGNodeNewWithConfig(config); @@ -648,8 +636,6 @@ TEST(YogaTest, box_sizing_border_box_siblings) { } TEST(YogaTest, box_sizing_content_box_max_width) { - GTEST_SKIP(); - YGConfigRef config = YGConfigNew(); YGNodeRef root = YGNodeNewWithConfig(config); @@ -779,8 +765,6 @@ TEST(YogaTest, box_sizing_border_box_max_width) { } TEST(YogaTest, box_sizing_content_box_max_height) { - GTEST_SKIP(); - YGConfigRef config = YGConfigNew(); YGNodeRef root = YGNodeNewWithConfig(config); @@ -910,8 +894,6 @@ TEST(YogaTest, box_sizing_border_box_max_height) { } TEST(YogaTest, box_sizing_content_box_min_width) { - GTEST_SKIP(); - YGConfigRef config = YGConfigNew(); YGNodeRef root = YGNodeNewWithConfig(config); @@ -1041,8 +1023,6 @@ TEST(YogaTest, box_sizing_border_box_min_width) { } TEST(YogaTest, box_sizing_content_box_min_height) { - GTEST_SKIP(); - YGConfigRef config = YGConfigNew(); YGNodeRef root = YGNodeNewWithConfig(config); @@ -1172,8 +1152,6 @@ TEST(YogaTest, box_sizing_border_box_min_height) { } TEST(YogaTest, box_sizing_content_box_no_height_no_width) { - GTEST_SKIP(); - YGConfigRef config = YGConfigNew(); YGNodeRef root = YGNodeNewWithConfig(config); @@ -1269,8 +1247,6 @@ TEST(YogaTest, box_sizing_border_box_no_height_no_width) { } TEST(YogaTest, box_sizing_content_box_nested) { - GTEST_SKIP(); - YGConfigRef config = YGConfigNew(); YGNodeRef root = YGNodeNewWithConfig(config); @@ -1434,8 +1410,6 @@ TEST(YogaTest, box_sizing_border_box_nested) { } TEST(YogaTest, box_sizing_content_box_nested_alternating) { - GTEST_SKIP(); - YGConfigRef config = YGConfigNew(); YGNodeRef root = YGNodeNewWithConfig(config); @@ -1541,8 +1515,6 @@ TEST(YogaTest, box_sizing_content_box_nested_alternating) { } TEST(YogaTest, box_sizing_border_box_nested_alternating) { - GTEST_SKIP(); - YGConfigRef config = YGConfigNew(); YGNodeRef root = YGNodeNewWithConfig(config); diff --git a/yoga/algorithm/AbsoluteLayout.cpp b/yoga/algorithm/AbsoluteLayout.cpp index c54cbcc6..d080844b 100644 --- a/yoga/algorithm/AbsoluteLayout.cpp +++ b/yoga/algorithm/AbsoluteLayout.cpp @@ -324,8 +324,9 @@ void layoutAbsoluteChild( FlexDirection::Column, containingBlockWidth); if (child->hasDefiniteLength(Dimension::Width, containingBlockWidth)) { - childWidth = child->getProcessedDimension(Dimension::Width) - .resolve(containingBlockWidth) + childWidth = child + ->getResolvedDimension( + direction, Dimension::Width, containingBlockWidth) .unwrap() + marginRow; } else { @@ -359,8 +360,9 @@ void layoutAbsoluteChild( } if (child->hasDefiniteLength(Dimension::Height, containingBlockHeight)) { - childHeight = child->getProcessedDimension(Dimension::Height) - .resolve(containingBlockHeight) + childHeight = child + ->getResolvedDimension( + direction, Dimension::Height, containingBlockHeight) .unwrap() + marginColumn; } else { diff --git a/yoga/algorithm/BoundAxis.h b/yoga/algorithm/BoundAxis.h index dee062a0..4342c0d5 100644 --- a/yoga/algorithm/BoundAxis.h +++ b/yoga/algorithm/BoundAxis.h @@ -29,6 +29,7 @@ inline float paddingAndBorderForAxis( inline FloatOptional boundAxisWithinMinAndMax( const yoga::Node* const node, + const Direction direction, const FlexDirection axis, const FloatOptional value, const float axisSize) { @@ -36,11 +37,15 @@ inline FloatOptional boundAxisWithinMinAndMax( FloatOptional max; if (isColumn(axis)) { - min = node->style().minDimension(Dimension::Height).resolve(axisSize); - max = node->style().maxDimension(Dimension::Height).resolve(axisSize); + min = node->style().resolvedMinDimension( + direction, Dimension::Height, axisSize); + max = node->style().resolvedMaxDimension( + direction, Dimension::Height, axisSize); } else if (isRow(axis)) { - min = node->style().minDimension(Dimension::Width).resolve(axisSize); - max = node->style().maxDimension(Dimension::Width).resolve(axisSize); + min = node->style().resolvedMinDimension( + direction, Dimension::Width, axisSize); + max = node->style().resolvedMaxDimension( + direction, Dimension::Width, axisSize); } if (max >= FloatOptional{0} && value > max) { @@ -64,7 +69,8 @@ inline float boundAxis( const float axisSize, const float widthSize) { return yoga::maxOrDefined( - boundAxisWithinMinAndMax(node, axis, FloatOptional{value}, axisSize) + boundAxisWithinMinAndMax( + node, direction, axis, FloatOptional{value}, axisSize) .unwrap(), paddingAndBorderForAxis(node, axis, direction, widthSize)); } diff --git a/yoga/algorithm/CalculateLayout.cpp b/yoga/algorithm/CalculateLayout.cpp index 43f797c0..0335f471 100644 --- a/yoga/algorithm/CalculateLayout.cpp +++ b/yoga/algorithm/CalculateLayout.cpp @@ -38,13 +38,14 @@ std::atomic gCurrentGenerationCount(0); static void constrainMaxSizeForMode( const yoga::Node* node, + Direction direction, FlexDirection axis, float ownerAxisSize, float ownerWidth, /*in_out*/ SizingMode* mode, /*in_out*/ float* size) { - const FloatOptional maxSize = - node->style().maxDimension(dimension(axis)).resolve(ownerAxisSize) + + const FloatOptional maxSize = node->style().resolvedMaxDimension( + direction, dimension(axis), ownerAxisSize) + FloatOptional(node->style().computeMarginForAxis(axis, ownerWidth)); switch (*mode) { case SizingMode::StretchFit: @@ -110,7 +111,7 @@ static void computeFlexBasisForChild( child, FlexDirection::Row, direction, ownerWidth)); child->setLayoutComputedFlexBasis(yoga::maxOrDefined( - child->getProcessedDimension(Dimension::Width).resolve(ownerWidth), + child->getResolvedDimension(direction, Dimension::Width, ownerWidth), paddingAndBorder)); } else if (!isMainAxisRow && isColumnStyleDimDefined) { // The height is definite, so use that as the flex basis. @@ -118,7 +119,7 @@ static void computeFlexBasisForChild( FloatOptional(paddingAndBorderForAxis( child, FlexDirection::Column, direction, ownerWidth)); child->setLayoutComputedFlexBasis(yoga::maxOrDefined( - child->getProcessedDimension(Dimension::Height).resolve(ownerHeight), + child->getResolvedDimension(direction, Dimension::Height, ownerHeight), paddingAndBorder)); } else { // Compute the flex basis and hypothetical main size (i.e. the clamped flex @@ -132,16 +133,16 @@ static void computeFlexBasisForChild( child->style().computeMarginForAxis(FlexDirection::Column, ownerWidth); if (isRowStyleDimDefined) { - childWidth = child->getProcessedDimension(Dimension::Width) - .resolve(ownerWidth) - .unwrap() + + childWidth = + child->getResolvedDimension(direction, Dimension::Width, ownerWidth) + .unwrap() + marginRow; childWidthSizingMode = SizingMode::StretchFit; } if (isColumnStyleDimDefined) { - childHeight = child->getProcessedDimension(Dimension::Height) - .resolve(ownerHeight) - .unwrap() + + childHeight = + child->getResolvedDimension(direction, Dimension::Height, ownerHeight) + .unwrap() + marginColumn; childHeightSizingMode = SizingMode::StretchFit; } @@ -216,6 +217,7 @@ static void computeFlexBasisForChild( constrainMaxSizeForMode( child, + direction, FlexDirection::Row, ownerWidth, ownerWidth, @@ -223,6 +225,7 @@ static void computeFlexBasisForChild( &childWidth); constrainMaxSizeForMode( child, + direction, FlexDirection::Column, ownerHeight, ownerWidth, @@ -469,6 +472,7 @@ static void zeroOutLayoutRecursively(yoga::Node* const node) { static float calculateAvailableInnerDimension( const yoga::Node* const node, + const Direction direction, const Dimension dimension, const float availableDim, const float paddingAndBorder, @@ -480,13 +484,13 @@ static float calculateAvailableInnerDimension( // We want to make sure our available height does not violate min and max // constraints const FloatOptional minDimensionOptional = - node->style().minDimension(dimension).resolve(ownerDim); + node->style().resolvedMinDimension(direction, dimension, ownerDim); const float minInnerDim = minDimensionOptional.isUndefined() ? 0.0f : minDimensionOptional.unwrap() - paddingAndBorder; const FloatOptional maxDimensionOptional = - node->style().maxDimension(dimension).resolve(ownerDim); + node->style().resolvedMaxDimension(direction, dimension, ownerDim); const float maxInnerDim = maxDimensionOptional.isUndefined() ? FLT_MAX @@ -611,6 +615,7 @@ static float distributeFreeSpaceSecondPass( for (auto currentLineChild : flexLine.itemsInFlow) { childFlexBasis = boundAxisWithinMinAndMax( currentLineChild, + direction, mainAxis, currentLineChild->getLayout().computedFlexBasis, mainAxisownerSize) @@ -709,8 +714,9 @@ static float distributeFreeSpaceSecondPass( : SizingMode::FitContent; } else { childCrossSize = - currentLineChild->getProcessedDimension(dimension(crossAxis)) - .resolve(availableInnerCrossDim) + currentLineChild + ->getResolvedDimension( + direction, dimension(crossAxis), availableInnerCrossDim) .unwrap() + marginCross; const bool isLoosePercentageMeasurement = @@ -725,6 +731,7 @@ static float distributeFreeSpaceSecondPass( constrainMaxSizeForMode( currentLineChild, + direction, mainAxis, availableInnerMainDim, availableInnerWidth, @@ -732,6 +739,7 @@ static float distributeFreeSpaceSecondPass( &childMainSize); constrainMaxSizeForMode( currentLineChild, + direction, crossAxis, availableInnerCrossDim, availableInnerWidth, @@ -812,6 +820,7 @@ static void distributeFreeSpaceFirstPass( for (auto currentLineChild : flexLine.itemsInFlow) { float childFlexBasis = boundAxisWithinMinAndMax( currentLineChild, + direction, mainAxis, currentLineChild->getLayout().computedFlexBasis, mainAxisownerSize) @@ -982,8 +991,9 @@ static void justifyMainAxis( if (sizingModeMainDim == SizingMode::FitContent && flexLine.layout.remainingFreeSpace > 0) { if (style.minDimension(dimension(mainAxis)).isDefined() && - style.minDimension(dimension(mainAxis)) - .resolve(mainAxisownerSize) + style + .resolvedMinDimension( + direction, dimension(mainAxis), mainAxisownerSize) .isDefined()) { // This condition makes sure that if the size of main dimension(after // considering child nodes main dim, leading and trailing padding etc) @@ -992,9 +1002,11 @@ static void justifyMainAxis( // `minAvailableMainDim` denotes minimum available space in which child // can be laid out, it will exclude space consumed by padding and border. - const float minAvailableMainDim = style.minDimension(dimension(mainAxis)) - .resolve(mainAxisownerSize) - .unwrap() - + const float minAvailableMainDim = + style + .resolvedMinDimension( + direction, dimension(mainAxis), mainAxisownerSize) + .unwrap() - leadingPaddingAndBorderMain - trailingPaddingAndBorderMain; const float occupiedSpaceByChildNodes = availableInnerMainDim - flexLine.layout.remainingFreeSpace; @@ -1387,12 +1399,14 @@ static void calculateLayoutImpl( float availableInnerWidth = calculateAvailableInnerDimension( node, + direction, Dimension::Width, availableWidth - marginAxisRow, paddingAndBorderAxisRow, ownerWidth); float availableInnerHeight = calculateAvailableInnerDimension( node, + direction, Dimension::Height, availableHeight - marginAxisColumn, paddingAndBorderAxisColumn, @@ -1480,16 +1494,20 @@ static void calculateLayoutImpl( if (sizingModeMainDim != SizingMode::StretchFit) { const auto& style = node->style(); const float minInnerWidth = - style.minDimension(Dimension::Width).resolve(ownerWidth).unwrap() - + style.resolvedMinDimension(direction, Dimension::Width, ownerWidth) + .unwrap() - paddingAndBorderAxisRow; const float maxInnerWidth = - style.maxDimension(Dimension::Width).resolve(ownerWidth).unwrap() - + style.resolvedMaxDimension(direction, Dimension::Width, ownerWidth) + .unwrap() - paddingAndBorderAxisRow; const float minInnerHeight = - style.minDimension(Dimension::Height).resolve(ownerHeight).unwrap() - + style.resolvedMinDimension(direction, Dimension::Height, ownerHeight) + .unwrap() - paddingAndBorderAxisColumn; const float maxInnerHeight = - style.maxDimension(Dimension::Height).resolve(ownerHeight).unwrap() - + style.resolvedMaxDimension(direction, Dimension::Height, ownerHeight) + .unwrap() - paddingAndBorderAxisColumn; const float minInnerMainDim = @@ -1688,6 +1706,7 @@ static void calculateLayoutImpl( SizingMode childCrossSizingMode = SizingMode::StretchFit; constrainMaxSizeForMode( child, + direction, mainAxis, availableInnerMainDim, availableInnerWidth, @@ -1695,6 +1714,7 @@ static void calculateLayoutImpl( &childMainSize); constrainMaxSizeForMode( child, + direction, crossAxis, availableInnerCrossDim, availableInnerWidth, @@ -1781,8 +1801,8 @@ static void calculateLayoutImpl( const float unclampedCrossDim = sizingModeCrossDim == SizingMode::StretchFit ? availableInnerCrossDim + paddingAndBorderAxisCross : node->hasDefiniteLength(dimension(crossAxis), crossAxisownerSize) - ? node->getProcessedDimension(dimension(crossAxis)) - .resolve(crossAxisownerSize) + ? node->getResolvedDimension( + direction, dimension(crossAxis), crossAxisownerSize) .unwrap() : totalLineCrossDim + paddingAndBorderAxisCross; @@ -2035,6 +2055,7 @@ static void calculateLayoutImpl( availableInnerMainDim + paddingAndBorderAxisMain, boundAxisWithinMinAndMax( node, + direction, mainAxis, FloatOptional{maxLineMainDim}, mainAxisownerSize) @@ -2067,6 +2088,7 @@ static void calculateLayoutImpl( availableInnerCrossDim + paddingAndBorderAxisCross, boundAxisWithinMinAndMax( node, + direction, crossAxis, FloatOptional{ totalLineCrossDim + paddingAndBorderAxisCross}, @@ -2355,20 +2377,21 @@ void calculateLayout( // the input parameters don't change. gCurrentGenerationCount.fetch_add(1, std::memory_order_relaxed); node->processDimensions(); + const Direction direction = node->resolveDirection(ownerDirection); float width = YGUndefined; SizingMode widthSizingMode = SizingMode::MaxContent; const auto& style = node->style(); if (node->hasDefiniteLength(Dimension::Width, ownerWidth)) { width = - (node->getProcessedDimension(Dimension::Width) - .resolve(ownerWidth) + (node->getResolvedDimension( + direction, dimension(FlexDirection::Row), ownerWidth) .unwrap() + node->style().computeMarginForAxis(FlexDirection::Row, ownerWidth)); widthSizingMode = SizingMode::StretchFit; - } else if (style.maxDimension(Dimension::Width) - .resolve(ownerWidth) + } else if (style.resolvedMaxDimension(direction, Dimension::Width, ownerWidth) .isDefined()) { - width = style.maxDimension(Dimension::Width).resolve(ownerWidth).unwrap(); + width = style.resolvedMaxDimension(direction, Dimension::Width, ownerWidth) + .unwrap(); widthSizingMode = SizingMode::FitContent; } else { width = ownerWidth; @@ -2380,16 +2403,18 @@ void calculateLayout( SizingMode heightSizingMode = SizingMode::MaxContent; if (node->hasDefiniteLength(Dimension::Height, ownerHeight)) { height = - (node->getProcessedDimension(Dimension::Height) - .resolve(ownerHeight) + (node->getResolvedDimension( + direction, dimension(FlexDirection::Column), ownerHeight) .unwrap() + node->style().computeMarginForAxis(FlexDirection::Column, ownerWidth)); heightSizingMode = SizingMode::StretchFit; - } else if (style.maxDimension(Dimension::Height) - .resolve(ownerHeight) + } else if (style + .resolvedMaxDimension( + direction, Dimension::Height, ownerHeight) .isDefined()) { height = - style.maxDimension(Dimension::Height).resolve(ownerHeight).unwrap(); + style.resolvedMaxDimension(direction, Dimension::Height, ownerHeight) + .unwrap(); heightSizingMode = SizingMode::FitContent; } else { height = ownerHeight; diff --git a/yoga/algorithm/FlexLine.cpp b/yoga/algorithm/FlexLine.cpp index d3a954ca..58a261a4 100644 --- a/yoga/algorithm/FlexLine.cpp +++ b/yoga/algorithm/FlexLine.cpp @@ -32,8 +32,9 @@ FlexLine calculateFlexLine( size_t firstElementInLineIndex = startOfLineIndex; float sizeConsumedIncludingMinConstraint = 0; - const FlexDirection mainAxis = resolveDirection( - node->style().flexDirection(), node->resolveDirection(ownerDirection)); + const Direction direction = node->resolveDirection(ownerDirection); + const FlexDirection mainAxis = + resolveDirection(node->style().flexDirection(), direction); const bool isNodeFlexWrap = node->style().flexWrap() != Wrap::NoWrap; const float gap = node->style().computeGapForAxis(mainAxis, availableInnerMainDim); @@ -67,6 +68,7 @@ FlexLine calculateFlexLine( const float flexBasisWithMinAndMaxConstraints = boundAxisWithinMinAndMax( child, + direction, mainAxis, child->getLayout().computedFlexBasis, mainAxisownerSize) diff --git a/yoga/node/Node.h b/yoga/node/Node.h index 8c93d43a..8d7ac320 100644 --- a/yoga/node/Node.h +++ b/yoga/node/Node.h @@ -156,6 +156,25 @@ class YG_EXPORT Node : public ::YGNode { return processedDimensions_[static_cast(dimension)]; } + FloatOptional getResolvedDimension( + Direction direction, + Dimension dimension, + float referenceLength) const { + FloatOptional value = + getProcessedDimension(dimension).resolve(referenceLength); + if (style_.boxSizing() == BoxSizing::BorderBox) { + return value; + } + + FloatOptional dimensionPaddingAndBorder = + FloatOptional{style_.computePaddingAndBorderForDimension( + direction, dimension, referenceLength)}; + + return value + + (dimensionPaddingAndBorder.isDefined() ? dimensionPaddingAndBorder + : FloatOptional{0.0}); + } + // Setters void setContext(void* context) { diff --git a/yoga/style/Style.h b/yoga/style/Style.h index f1600ce0..8c96dd50 100644 --- a/yoga/style/Style.h +++ b/yoga/style/Style.h @@ -189,6 +189,23 @@ class YG_EXPORT Style { pool_.store(minDimensions_[yoga::to_underlying(axis)], value); } + FloatOptional resolvedMinDimension( + Direction direction, + Dimension axis, + float referenceLength) const { + FloatOptional value = minDimension(axis).resolve(referenceLength); + if (boxSizing() == BoxSizing::BorderBox) { + return value; + } + + FloatOptional dimensionPaddingAndBorder = FloatOptional{ + computePaddingAndBorderForDimension(direction, axis, referenceLength)}; + + return value + + (dimensionPaddingAndBorder.isDefined() ? dimensionPaddingAndBorder + : FloatOptional{0.0}); + } + Style::Length maxDimension(Dimension axis) const { return pool_.getLength(maxDimensions_[yoga::to_underlying(axis)]); } @@ -196,6 +213,23 @@ class YG_EXPORT Style { pool_.store(maxDimensions_[yoga::to_underlying(axis)], value); } + FloatOptional resolvedMaxDimension( + Direction direction, + Dimension axis, + float referenceLength) const { + FloatOptional value = maxDimension(axis).resolve(referenceLength); + if (boxSizing() == BoxSizing::BorderBox) { + return value; + } + + FloatOptional dimensionPaddingAndBorder = FloatOptional{ + computePaddingAndBorderForDimension(direction, axis, referenceLength)}; + + return value + + (dimensionPaddingAndBorder.isDefined() ? dimensionPaddingAndBorder + : FloatOptional{0.0}); + } + FloatOptional aspectRatio() const { return pool_.getNumber(aspectRatio_); } @@ -446,6 +480,20 @@ class YG_EXPORT Style { computeFlexEndBorder(axis, direction); } + float computePaddingAndBorderForDimension( + Direction direction, + Dimension dimension, + float widthSize) const { + FlexDirection flexDirectionForDimension = dimension == Dimension::Width + ? FlexDirection::Row + : FlexDirection::Column; + + return computeFlexStartPaddingAndBorder( + flexDirectionForDimension, direction, widthSize) + + computeFlexEndPaddingAndBorder( + flexDirectionForDimension, direction, widthSize); + } + float computeBorderForAxis(FlexDirection axis) const { return computeInlineStartBorder(axis, Direction::LTR) + computeInlineEndBorder(axis, Direction::LTR); -- 2.50.1.windows.1 From 59c52928a1d5057c44949a8cf0335da3a5b9f286 Mon Sep 17 00:00:00 2001 From: Joe Vilches Date: Mon, 30 Sep 2024 15:20:06 -0700 Subject: [PATCH 4/4] More niche box sizing tests Summary: tsia, add some more advanced tests checking * percent widths/heights/padding/border * absolute positioned nodes with content box * containing block with content box + static * flex basis (fails now, needs follow up) * relative padding/border values All pass but flex basis Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D63423302 --- gentest/fixtures/YGBoxSizingTest.html | 119 +- .../com/facebook/yoga/YGBoxSizingTest.java | 901 ++++++++++++++- .../tests/generated/YGBoxSizingTest.test.ts | 1009 ++++++++++++++++- tests/YGMeasureTest.cpp | 78 ++ tests/generated/YGBoxSizingTest.cpp | 925 ++++++++++++++- 5 files changed, 3019 insertions(+), 13 deletions(-) diff --git a/gentest/fixtures/YGBoxSizingTest.html b/gentest/fixtures/YGBoxSizingTest.html index 44c024e7..1cf83121 100644 --- a/gentest/fixtures/YGBoxSizingTest.html +++ b/gentest/fixtures/YGBoxSizingTest.html @@ -2,32 +2,85 @@ style="width: 100px; height: 100px; padding: 5px; border-width: 10px; box-sizing: content-box">
-
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
-
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+
+
-
+
+
+
-
+
+
+ +
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
diff --git a/java/tests/generated/com/facebook/yoga/YGBoxSizingTest.java b/java/tests/generated/com/facebook/yoga/YGBoxSizingTest.java index 6426078a..bbbc3c5c 100644 --- a/java/tests/generated/com/facebook/yoga/YGBoxSizingTest.java +++ b/java/tests/generated/com/facebook/yoga/YGBoxSizingTest.java @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<> + * @generated SignedSource<<80fa9cf05afc330a721a756dfaf0d1a3>> * generated by gentest/gentest-driver.ts from gentest/fixtures/YGBoxSizingTest.html */ @@ -62,7 +62,7 @@ public class YGBoxSizingTest { } @Test - public void test_box_sizing_border_box() { + public void test_box_sizing_border_box_simple() { YogaConfig config = YogaConfigFactory.create(); final YogaNode root = createNode(config); @@ -94,6 +94,327 @@ public class YGBoxSizingTest { assertEquals(100f, root.getLayoutHeight(), 0.0f); } + @Test + public void test_box_sizing_content_box_percent() { + YogaConfig config = YogaConfigFactory.create(); + + final YogaNode root = createNode(config); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = createNode(config); + root_child0.setPadding(YogaEdge.LEFT, 4); + root_child0.setPadding(YogaEdge.TOP, 4); + root_child0.setPadding(YogaEdge.RIGHT, 4); + root_child0.setPadding(YogaEdge.BOTTOM, 4); + root_child0.setBorder(YogaEdge.LEFT, 16f); + root_child0.setBorder(YogaEdge.TOP, 16f); + root_child0.setBorder(YogaEdge.RIGHT, 16f); + root_child0.setBorder(YogaEdge.BOTTOM, 16f); + root_child0.setWidthPercent(50f); + root_child0.setHeightPercent(25f); + root_child0.setBoxSizing(YogaBoxSizing.CONTENT_BOX); + 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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(90f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(65f, 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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(90f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(65f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_box_sizing_border_box_percent() { + YogaConfig config = YogaConfigFactory.create(); + + final YogaNode root = createNode(config); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = createNode(config); + root_child0.setPadding(YogaEdge.LEFT, 4); + root_child0.setPadding(YogaEdge.TOP, 4); + root_child0.setPadding(YogaEdge.RIGHT, 4); + root_child0.setPadding(YogaEdge.BOTTOM, 4); + root_child0.setBorder(YogaEdge.LEFT, 16f); + root_child0.setBorder(YogaEdge.TOP, 16f); + root_child0.setBorder(YogaEdge.RIGHT, 16f); + root_child0.setBorder(YogaEdge.BOTTOM, 16f); + root_child0.setWidthPercent(50f); + root_child0.setHeightPercent(25f); + 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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(40f, 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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(40f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_box_sizing_content_box_absolute() { + YogaConfig config = YogaConfigFactory.create(); + + final YogaNode root = createNode(config); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = createNode(config); + root_child0.setPositionType(YogaPositionType.ABSOLUTE); + root_child0.setPadding(YogaEdge.LEFT, 12); + root_child0.setPadding(YogaEdge.TOP, 12); + root_child0.setPadding(YogaEdge.RIGHT, 12); + root_child0.setPadding(YogaEdge.BOTTOM, 12); + root_child0.setBorder(YogaEdge.LEFT, 8f); + root_child0.setBorder(YogaEdge.TOP, 8f); + root_child0.setBorder(YogaEdge.RIGHT, 8f); + root_child0.setBorder(YogaEdge.BOTTOM, 8f); + root_child0.setHeightPercent(25f); + root_child0.setBoxSizing(YogaBoxSizing.CONTENT_BOX); + 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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(40f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(65f, 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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(60f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(40f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(65f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_box_sizing_border_box_absolute() { + YogaConfig config = YogaConfigFactory.create(); + + final YogaNode root = createNode(config); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = createNode(config); + root_child0.setPositionType(YogaPositionType.ABSOLUTE); + root_child0.setPadding(YogaEdge.LEFT, 12); + root_child0.setPadding(YogaEdge.TOP, 12); + root_child0.setPadding(YogaEdge.RIGHT, 12); + root_child0.setPadding(YogaEdge.BOTTOM, 12); + root_child0.setBorder(YogaEdge.LEFT, 8f); + root_child0.setBorder(YogaEdge.TOP, 8f); + root_child0.setBorder(YogaEdge.RIGHT, 8f); + root_child0.setBorder(YogaEdge.BOTTOM, 8f); + root_child0.setHeightPercent(25f); + 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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(40f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(40f, 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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(60f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(40f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(40f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_box_sizing_content_box_comtaining_block() { + YogaConfig config = YogaConfigFactory.create(); + + final YogaNode root = createNode(config); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setPadding(YogaEdge.LEFT, 12); + root.setPadding(YogaEdge.TOP, 12); + root.setPadding(YogaEdge.RIGHT, 12); + root.setPadding(YogaEdge.BOTTOM, 12); + root.setBorder(YogaEdge.LEFT, 8f); + root.setBorder(YogaEdge.TOP, 8f); + root.setBorder(YogaEdge.RIGHT, 8f); + root.setBorder(YogaEdge.BOTTOM, 8f); + root.setWidth(100f); + root.setHeight(100f); + root.setBoxSizing(YogaBoxSizing.CONTENT_BOX); + + final YogaNode root_child0 = createNode(config); + root_child0.setPositionType(YogaPositionType.STATIC); + root.addChildAt(root_child0, 0); + + final YogaNode root_child0_child0 = createNode(config); + root_child0_child0.setPositionType(YogaPositionType.ABSOLUTE); + root_child0_child0.setWidth(50f); + root_child0_child0.setHeightPercent(25f); + 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(140f, root.getLayoutWidth(), 0.0f); + assertEquals(140f, root.getLayoutHeight(), 0.0f); + + assertEquals(20f, root_child0.getLayoutX(), 0.0f); + assertEquals(20f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(31f, 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(140f, root.getLayoutWidth(), 0.0f); + assertEquals(140f, root.getLayoutHeight(), 0.0f); + + assertEquals(20f, root_child0.getLayoutX(), 0.0f); + assertEquals(20f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(31f, root_child0_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_box_sizing_border_box_comtaining_block() { + YogaConfig config = YogaConfigFactory.create(); + + final YogaNode root = createNode(config); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setPadding(YogaEdge.LEFT, 12); + root.setPadding(YogaEdge.TOP, 12); + root.setPadding(YogaEdge.RIGHT, 12); + root.setPadding(YogaEdge.BOTTOM, 12); + root.setBorder(YogaEdge.LEFT, 8f); + root.setBorder(YogaEdge.TOP, 8f); + root.setBorder(YogaEdge.RIGHT, 8f); + root.setBorder(YogaEdge.BOTTOM, 8f); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = createNode(config); + root_child0.setPositionType(YogaPositionType.STATIC); + root.addChildAt(root_child0, 0); + + final YogaNode root_child0_child0 = createNode(config); + root_child0_child0.setPositionType(YogaPositionType.ABSOLUTE); + root_child0_child0.setWidth(50f); + root_child0_child0.setHeightPercent(25f); + 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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(20f, root_child0.getLayoutX(), 0.0f); + assertEquals(20f, root_child0.getLayoutY(), 0.0f); + assertEquals(60f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(21f, 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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(20f, root_child0.getLayoutX(), 0.0f); + assertEquals(20f, root_child0.getLayoutY(), 0.0f); + assertEquals(60f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(21f, root_child0_child0.getLayoutHeight(), 0.0f); + } + @Test public void test_box_sizing_content_box_padding_only() { YogaConfig config = YogaConfigFactory.create(); @@ -124,6 +445,50 @@ public class YGBoxSizingTest { assertEquals(110f, root.getLayoutHeight(), 0.0f); } + @Test + public void test_box_sizing_content_box_padding_only_percent() { + YogaConfig config = YogaConfigFactory.create(); + + final YogaNode root = createNode(config); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = createNode(config); + root_child0.setPaddingPercent(YogaEdge.LEFT, 10); + root_child0.setPaddingPercent(YogaEdge.TOP, 10); + root_child0.setPaddingPercent(YogaEdge.RIGHT, 10); + root_child0.setPaddingPercent(YogaEdge.BOTTOM, 10); + root_child0.setWidthPercent(50f); + root_child0.setBoxSizing(YogaBoxSizing.CONTENT_BOX); + 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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(70f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, 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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(30f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(70f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0.getLayoutHeight(), 0.0f); + } + @Test public void test_box_sizing_border_box_padding_only() { YogaConfig config = YogaConfigFactory.create(); @@ -153,6 +518,49 @@ public class YGBoxSizingTest { assertEquals(100f, root.getLayoutHeight(), 0.0f); } + @Test + public void test_box_sizing_border_box_padding_only_percent() { + YogaConfig config = YogaConfigFactory.create(); + + final YogaNode root = createNode(config); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = createNode(config); + root_child0.setPaddingPercent(YogaEdge.LEFT, 10); + root_child0.setPaddingPercent(YogaEdge.TOP, 10); + root_child0.setPaddingPercent(YogaEdge.RIGHT, 10); + root_child0.setPaddingPercent(YogaEdge.BOTTOM, 10); + root_child0.setWidthPercent(50f); + 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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, 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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0.getLayoutHeight(), 0.0f); + } + @Test public void test_box_sizing_content_box_border_only() { YogaConfig config = YogaConfigFactory.create(); @@ -183,6 +591,46 @@ public class YGBoxSizingTest { assertEquals(120f, root.getLayoutHeight(), 0.0f); } + @Test + public void test_box_sizing_content_box_border_only_percent() { + YogaConfig config = YogaConfigFactory.create(); + + final YogaNode root = createNode(config); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = createNode(config); + root_child0.setWidthPercent(50f); + root_child0.setBoxSizing(YogaBoxSizing.CONTENT_BOX); + 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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(0f, 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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child0.getLayoutHeight(), 0.0f); + } + @Test public void test_box_sizing_border_box_border_only() { YogaConfig config = YogaConfigFactory.create(); @@ -212,6 +660,45 @@ public class YGBoxSizingTest { assertEquals(100f, root.getLayoutHeight(), 0.0f); } + @Test + public void test_box_sizing_border_box_border_only_percent() { + YogaConfig config = YogaConfigFactory.create(); + + final YogaNode root = createNode(config); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = createNode(config); + root_child0.setWidthPercent(50f); + 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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(0f, 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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child0.getLayoutHeight(), 0.0f); + } + @Test public void test_box_sizing_content_box_no_padding_no_border() { YogaConfig config = YogaConfigFactory.create(); @@ -1607,6 +2094,416 @@ public class YGBoxSizingTest { assertEquals(9f, root_child0_child0_child0.getLayoutHeight(), 0.0f); } + @Test + @Ignore + public void test_box_sizing_content_box_flex_basis_row() { + YogaConfig config = YogaConfigFactory.create(); + + final YogaNode root = createNode(config); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = createNode(config); + root_child0.setFlexBasis(50f); + root_child0.setPadding(YogaEdge.LEFT, 5); + root_child0.setPadding(YogaEdge.TOP, 5); + root_child0.setPadding(YogaEdge.RIGHT, 5); + root_child0.setPadding(YogaEdge.BOTTOM, 5); + root_child0.setBorder(YogaEdge.LEFT, 10f); + root_child0.setBorder(YogaEdge.TOP, 10f); + root_child0.setBorder(YogaEdge.RIGHT, 10f); + root_child0.setBorder(YogaEdge.BOTTOM, 10f); + root_child0.setHeight(25f); + root_child0.setBoxSizing(YogaBoxSizing.CONTENT_BOX); + 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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(80f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(55f, 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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(20f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(80f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(55f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_box_sizing_border_box_flex_basis_row() { + YogaConfig config = YogaConfigFactory.create(); + + final YogaNode root = createNode(config); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = createNode(config); + root_child0.setFlexBasis(50f); + root_child0.setPadding(YogaEdge.LEFT, 5); + root_child0.setPadding(YogaEdge.TOP, 5); + root_child0.setPadding(YogaEdge.RIGHT, 5); + root_child0.setPadding(YogaEdge.BOTTOM, 5); + root_child0.setBorder(YogaEdge.LEFT, 10f); + root_child0.setBorder(YogaEdge.TOP, 10f); + root_child0.setBorder(YogaEdge.RIGHT, 10f); + root_child0.setBorder(YogaEdge.BOTTOM, 10f); + root_child0.setHeight(25f); + 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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(30f, 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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + @Ignore + public void test_box_sizing_content_box_flex_basis_column() { + YogaConfig config = YogaConfigFactory.create(); + + final YogaNode root = createNode(config); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = createNode(config); + root_child0.setFlexBasis(50f); + root_child0.setPadding(YogaEdge.LEFT, 5); + root_child0.setPadding(YogaEdge.TOP, 5); + root_child0.setPadding(YogaEdge.RIGHT, 5); + root_child0.setPadding(YogaEdge.BOTTOM, 5); + root_child0.setBorder(YogaEdge.LEFT, 10f); + root_child0.setBorder(YogaEdge.TOP, 10f); + root_child0.setBorder(YogaEdge.RIGHT, 10f); + root_child0.setBorder(YogaEdge.BOTTOM, 10f); + root_child0.setHeight(25f); + root_child0.setBoxSizing(YogaBoxSizing.CONTENT_BOX); + 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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(80f, 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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(80f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_box_sizing_border_box_flex_basis_column() { + YogaConfig config = YogaConfigFactory.create(); + + final YogaNode root = createNode(config); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = createNode(config); + root_child0.setFlexBasis(50f); + root_child0.setPadding(YogaEdge.LEFT, 5); + root_child0.setPadding(YogaEdge.TOP, 5); + root_child0.setPadding(YogaEdge.RIGHT, 5); + root_child0.setPadding(YogaEdge.BOTTOM, 5); + root_child0.setBorder(YogaEdge.LEFT, 10f); + root_child0.setBorder(YogaEdge.TOP, 10f); + root_child0.setBorder(YogaEdge.RIGHT, 10f); + root_child0.setBorder(YogaEdge.BOTTOM, 10f); + root_child0.setHeight(25f); + 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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, 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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_box_sizing_content_box_padding_start() { + YogaConfig config = YogaConfigFactory.create(); + + final YogaNode root = createNode(config); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setPadding(YogaEdge.START, 5); + root.setWidth(100f); + root.setHeight(100f); + root.setBoxSizing(YogaBoxSizing.CONTENT_BOX); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(105f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.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(105f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + } + + @Test + public void test_box_sizing_border_box_padding_start() { + YogaConfig config = YogaConfigFactory.create(); + + final YogaNode root = createNode(config); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setPadding(YogaEdge.START, 5); + root.setWidth(100f); + root.setHeight(100f); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + } + + @Test + public void test_box_sizing_content_box_padding_end() { + YogaConfig config = YogaConfigFactory.create(); + + final YogaNode root = createNode(config); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setPadding(YogaEdge.END, 5); + root.setWidth(100f); + root.setHeight(100f); + root.setBoxSizing(YogaBoxSizing.CONTENT_BOX); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(105f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.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(105f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + } + + @Test + public void test_box_sizing_border_box_padding_end() { + YogaConfig config = YogaConfigFactory.create(); + + final YogaNode root = createNode(config); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setPadding(YogaEdge.END, 5); + root.setWidth(100f); + root.setHeight(100f); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + } + + @Test + public void test_box_sizing_content_box_border_start() { + YogaConfig config = YogaConfigFactory.create(); + + final YogaNode root = createNode(config); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setBorder(YogaEdge.START, 5f); + root.setWidth(100f); + root.setHeight(100f); + root.setBoxSizing(YogaBoxSizing.CONTENT_BOX); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(105f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.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(105f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + } + + @Test + public void test_box_sizing_border_box_border_start() { + YogaConfig config = YogaConfigFactory.create(); + + final YogaNode root = createNode(config); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setBorder(YogaEdge.START, 5f); + root.setWidth(100f); + root.setHeight(100f); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + } + + @Test + public void test_box_sizing_content_box_border_end() { + YogaConfig config = YogaConfigFactory.create(); + + final YogaNode root = createNode(config); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setBorder(YogaEdge.END, 5f); + root.setWidth(100f); + root.setHeight(100f); + root.setBoxSizing(YogaBoxSizing.CONTENT_BOX); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(105f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.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(105f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + } + + @Test + public void test_box_sizing_border_box_border_end() { + YogaConfig config = YogaConfigFactory.create(); + + final YogaNode root = createNode(config); + root.setPositionType(YogaPositionType.ABSOLUTE); + root.setBorder(YogaEdge.END, 5f); + root.setWidth(100f); + root.setHeight(100f); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + } + private YogaNode createNode(YogaConfig config) { return mNodeFactory.create(config); } diff --git a/javascript/tests/generated/YGBoxSizingTest.test.ts b/javascript/tests/generated/YGBoxSizingTest.test.ts index b96070ea..fbbcba9a 100644 --- a/javascript/tests/generated/YGBoxSizingTest.test.ts +++ b/javascript/tests/generated/YGBoxSizingTest.test.ts @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<5ce4b1bc764d2bf325b844053b98134e>> + * @generated SignedSource<<48d3d46dec54df38f853a6fa17e6f0c6>> * generated by gentest/gentest-driver.ts from gentest/fixtures/YGBoxSizingTest.html */ @@ -67,7 +67,7 @@ test('box_sizing_content_box_simple', () => { config.free(); } }); -test('box_sizing_border_box', () => { +test('box_sizing_border_box_simple', () => { const config = Yoga.Config.create(); let root; @@ -105,6 +105,357 @@ test('box_sizing_border_box', () => { config.free(); } }); +test('box_sizing_content_box_percent', () => { + const config = Yoga.Config.create(); + let root; + + try { + root = Yoga.Node.create(config); + root.setPositionType(PositionType.Absolute); + root.setWidth(100); + root.setHeight(100); + + const root_child0 = Yoga.Node.create(config); + root_child0.setPadding(Edge.Left, 4); + root_child0.setPadding(Edge.Top, 4); + root_child0.setPadding(Edge.Right, 4); + root_child0.setPadding(Edge.Bottom, 4); + root_child0.setBorder(Edge.Left, 16); + root_child0.setBorder(Edge.Top, 16); + root_child0.setBorder(Edge.Right, 16); + root_child0.setBorder(Edge.Bottom, 16); + root_child0.setWidth("50%"); + root_child0.setHeight("25%"); + root_child0.setBoxSizing(BoxSizing.ContentBox); + root.insertChild(root_child0, 0); + root.calculateLayout(undefined, undefined, Direction.LTR); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + expect(root_child0.getComputedLeft()).toBe(0); + expect(root_child0.getComputedTop()).toBe(0); + expect(root_child0.getComputedWidth()).toBe(90); + expect(root_child0.getComputedHeight()).toBe(65); + + root.calculateLayout(undefined, undefined, Direction.RTL); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + expect(root_child0.getComputedLeft()).toBe(10); + expect(root_child0.getComputedTop()).toBe(0); + expect(root_child0.getComputedWidth()).toBe(90); + expect(root_child0.getComputedHeight()).toBe(65); + } finally { + if (typeof root !== 'undefined') { + root.freeRecursive(); + } + + config.free(); + } +}); +test('box_sizing_border_box_percent', () => { + const config = Yoga.Config.create(); + let root; + + try { + root = Yoga.Node.create(config); + root.setPositionType(PositionType.Absolute); + root.setWidth(100); + root.setHeight(100); + + const root_child0 = Yoga.Node.create(config); + root_child0.setPadding(Edge.Left, 4); + root_child0.setPadding(Edge.Top, 4); + root_child0.setPadding(Edge.Right, 4); + root_child0.setPadding(Edge.Bottom, 4); + root_child0.setBorder(Edge.Left, 16); + root_child0.setBorder(Edge.Top, 16); + root_child0.setBorder(Edge.Right, 16); + root_child0.setBorder(Edge.Bottom, 16); + root_child0.setWidth("50%"); + root_child0.setHeight("25%"); + root.insertChild(root_child0, 0); + root.calculateLayout(undefined, undefined, Direction.LTR); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + expect(root_child0.getComputedLeft()).toBe(0); + expect(root_child0.getComputedTop()).toBe(0); + expect(root_child0.getComputedWidth()).toBe(50); + expect(root_child0.getComputedHeight()).toBe(40); + + root.calculateLayout(undefined, undefined, Direction.RTL); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + expect(root_child0.getComputedLeft()).toBe(50); + expect(root_child0.getComputedTop()).toBe(0); + expect(root_child0.getComputedWidth()).toBe(50); + expect(root_child0.getComputedHeight()).toBe(40); + } finally { + if (typeof root !== 'undefined') { + root.freeRecursive(); + } + + config.free(); + } +}); +test('box_sizing_content_box_absolute', () => { + const config = Yoga.Config.create(); + let root; + + try { + root = Yoga.Node.create(config); + root.setPositionType(PositionType.Absolute); + root.setWidth(100); + root.setHeight(100); + + const root_child0 = Yoga.Node.create(config); + root_child0.setPositionType(PositionType.Absolute); + root_child0.setPadding(Edge.Left, 12); + root_child0.setPadding(Edge.Top, 12); + root_child0.setPadding(Edge.Right, 12); + root_child0.setPadding(Edge.Bottom, 12); + root_child0.setBorder(Edge.Left, 8); + root_child0.setBorder(Edge.Top, 8); + root_child0.setBorder(Edge.Right, 8); + root_child0.setBorder(Edge.Bottom, 8); + root_child0.setHeight("25%"); + root_child0.setBoxSizing(BoxSizing.ContentBox); + root.insertChild(root_child0, 0); + root.calculateLayout(undefined, undefined, Direction.LTR); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + expect(root_child0.getComputedLeft()).toBe(0); + expect(root_child0.getComputedTop()).toBe(0); + expect(root_child0.getComputedWidth()).toBe(40); + expect(root_child0.getComputedHeight()).toBe(65); + + root.calculateLayout(undefined, undefined, Direction.RTL); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + expect(root_child0.getComputedLeft()).toBe(60); + expect(root_child0.getComputedTop()).toBe(0); + expect(root_child0.getComputedWidth()).toBe(40); + expect(root_child0.getComputedHeight()).toBe(65); + } finally { + if (typeof root !== 'undefined') { + root.freeRecursive(); + } + + config.free(); + } +}); +test('box_sizing_border_box_absolute', () => { + const config = Yoga.Config.create(); + let root; + + try { + root = Yoga.Node.create(config); + root.setPositionType(PositionType.Absolute); + root.setWidth(100); + root.setHeight(100); + + const root_child0 = Yoga.Node.create(config); + root_child0.setPositionType(PositionType.Absolute); + root_child0.setPadding(Edge.Left, 12); + root_child0.setPadding(Edge.Top, 12); + root_child0.setPadding(Edge.Right, 12); + root_child0.setPadding(Edge.Bottom, 12); + root_child0.setBorder(Edge.Left, 8); + root_child0.setBorder(Edge.Top, 8); + root_child0.setBorder(Edge.Right, 8); + root_child0.setBorder(Edge.Bottom, 8); + root_child0.setHeight("25%"); + root.insertChild(root_child0, 0); + root.calculateLayout(undefined, undefined, Direction.LTR); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + expect(root_child0.getComputedLeft()).toBe(0); + expect(root_child0.getComputedTop()).toBe(0); + expect(root_child0.getComputedWidth()).toBe(40); + expect(root_child0.getComputedHeight()).toBe(40); + + root.calculateLayout(undefined, undefined, Direction.RTL); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + expect(root_child0.getComputedLeft()).toBe(60); + expect(root_child0.getComputedTop()).toBe(0); + expect(root_child0.getComputedWidth()).toBe(40); + expect(root_child0.getComputedHeight()).toBe(40); + } finally { + if (typeof root !== 'undefined') { + root.freeRecursive(); + } + + config.free(); + } +}); +test('box_sizing_content_box_comtaining_block', () => { + const config = Yoga.Config.create(); + let root; + + try { + root = Yoga.Node.create(config); + root.setPositionType(PositionType.Absolute); + root.setPadding(Edge.Left, 12); + root.setPadding(Edge.Top, 12); + root.setPadding(Edge.Right, 12); + root.setPadding(Edge.Bottom, 12); + root.setBorder(Edge.Left, 8); + root.setBorder(Edge.Top, 8); + root.setBorder(Edge.Right, 8); + root.setBorder(Edge.Bottom, 8); + root.setWidth(100); + root.setHeight(100); + root.setBoxSizing(BoxSizing.ContentBox); + + const root_child0 = Yoga.Node.create(config); + root_child0.setPositionType(PositionType.Static); + root.insertChild(root_child0, 0); + + const root_child0_child0 = Yoga.Node.create(config); + root_child0_child0.setPositionType(PositionType.Absolute); + root_child0_child0.setWidth(50); + root_child0_child0.setHeight("25%"); + root_child0.insertChild(root_child0_child0, 0); + root.calculateLayout(undefined, undefined, Direction.LTR); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(140); + expect(root.getComputedHeight()).toBe(140); + + expect(root_child0.getComputedLeft()).toBe(20); + expect(root_child0.getComputedTop()).toBe(20); + expect(root_child0.getComputedWidth()).toBe(100); + expect(root_child0.getComputedHeight()).toBe(0); + + expect(root_child0_child0.getComputedLeft()).toBe(0); + expect(root_child0_child0.getComputedTop()).toBe(0); + expect(root_child0_child0.getComputedWidth()).toBe(50); + expect(root_child0_child0.getComputedHeight()).toBe(31); + + root.calculateLayout(undefined, undefined, Direction.RTL); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(140); + expect(root.getComputedHeight()).toBe(140); + + expect(root_child0.getComputedLeft()).toBe(20); + expect(root_child0.getComputedTop()).toBe(20); + expect(root_child0.getComputedWidth()).toBe(100); + expect(root_child0.getComputedHeight()).toBe(0); + + expect(root_child0_child0.getComputedLeft()).toBe(50); + expect(root_child0_child0.getComputedTop()).toBe(0); + expect(root_child0_child0.getComputedWidth()).toBe(50); + expect(root_child0_child0.getComputedHeight()).toBe(31); + } finally { + if (typeof root !== 'undefined') { + root.freeRecursive(); + } + + config.free(); + } +}); +test('box_sizing_border_box_comtaining_block', () => { + const config = Yoga.Config.create(); + let root; + + try { + root = Yoga.Node.create(config); + root.setPositionType(PositionType.Absolute); + root.setPadding(Edge.Left, 12); + root.setPadding(Edge.Top, 12); + root.setPadding(Edge.Right, 12); + root.setPadding(Edge.Bottom, 12); + root.setBorder(Edge.Left, 8); + root.setBorder(Edge.Top, 8); + root.setBorder(Edge.Right, 8); + root.setBorder(Edge.Bottom, 8); + root.setWidth(100); + root.setHeight(100); + + const root_child0 = Yoga.Node.create(config); + root_child0.setPositionType(PositionType.Static); + root.insertChild(root_child0, 0); + + const root_child0_child0 = Yoga.Node.create(config); + root_child0_child0.setPositionType(PositionType.Absolute); + root_child0_child0.setWidth(50); + root_child0_child0.setHeight("25%"); + root_child0.insertChild(root_child0_child0, 0); + root.calculateLayout(undefined, undefined, Direction.LTR); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + expect(root_child0.getComputedLeft()).toBe(20); + expect(root_child0.getComputedTop()).toBe(20); + expect(root_child0.getComputedWidth()).toBe(60); + expect(root_child0.getComputedHeight()).toBe(0); + + expect(root_child0_child0.getComputedLeft()).toBe(0); + expect(root_child0_child0.getComputedTop()).toBe(0); + expect(root_child0_child0.getComputedWidth()).toBe(50); + expect(root_child0_child0.getComputedHeight()).toBe(21); + + root.calculateLayout(undefined, undefined, Direction.RTL); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + expect(root_child0.getComputedLeft()).toBe(20); + expect(root_child0.getComputedTop()).toBe(20); + expect(root_child0.getComputedWidth()).toBe(60); + expect(root_child0.getComputedHeight()).toBe(0); + + expect(root_child0_child0.getComputedLeft()).toBe(10); + expect(root_child0_child0.getComputedTop()).toBe(0); + expect(root_child0_child0.getComputedWidth()).toBe(50); + expect(root_child0_child0.getComputedHeight()).toBe(21); + } finally { + if (typeof root !== 'undefined') { + root.freeRecursive(); + } + + config.free(); + } +}); test('box_sizing_content_box_padding_only', () => { const config = Yoga.Config.create(); let root; @@ -140,6 +491,55 @@ test('box_sizing_content_box_padding_only', () => { config.free(); } }); +test('box_sizing_content_box_padding_only_percent', () => { + const config = Yoga.Config.create(); + let root; + + try { + root = Yoga.Node.create(config); + root.setPositionType(PositionType.Absolute); + root.setWidth(100); + root.setHeight(100); + + const root_child0 = Yoga.Node.create(config); + root_child0.setPadding(Edge.Left, "10%"); + root_child0.setPadding(Edge.Top, "10%"); + root_child0.setPadding(Edge.Right, "10%"); + root_child0.setPadding(Edge.Bottom, "10%"); + root_child0.setWidth("50%"); + root_child0.setBoxSizing(BoxSizing.ContentBox); + root.insertChild(root_child0, 0); + root.calculateLayout(undefined, undefined, Direction.LTR); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + expect(root_child0.getComputedLeft()).toBe(0); + expect(root_child0.getComputedTop()).toBe(0); + expect(root_child0.getComputedWidth()).toBe(70); + expect(root_child0.getComputedHeight()).toBe(20); + + root.calculateLayout(undefined, undefined, Direction.RTL); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + expect(root_child0.getComputedLeft()).toBe(30); + expect(root_child0.getComputedTop()).toBe(0); + expect(root_child0.getComputedWidth()).toBe(70); + expect(root_child0.getComputedHeight()).toBe(20); + } finally { + if (typeof root !== 'undefined') { + root.freeRecursive(); + } + + config.free(); + } +}); test('box_sizing_border_box_padding_only', () => { const config = Yoga.Config.create(); let root; @@ -174,6 +574,54 @@ test('box_sizing_border_box_padding_only', () => { config.free(); } }); +test('box_sizing_border_box_padding_only_percent', () => { + const config = Yoga.Config.create(); + let root; + + try { + root = Yoga.Node.create(config); + root.setPositionType(PositionType.Absolute); + root.setWidth(100); + root.setHeight(100); + + const root_child0 = Yoga.Node.create(config); + root_child0.setPadding(Edge.Left, "10%"); + root_child0.setPadding(Edge.Top, "10%"); + root_child0.setPadding(Edge.Right, "10%"); + root_child0.setPadding(Edge.Bottom, "10%"); + root_child0.setWidth("50%"); + root.insertChild(root_child0, 0); + root.calculateLayout(undefined, undefined, Direction.LTR); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + expect(root_child0.getComputedLeft()).toBe(0); + expect(root_child0.getComputedTop()).toBe(0); + expect(root_child0.getComputedWidth()).toBe(50); + expect(root_child0.getComputedHeight()).toBe(20); + + root.calculateLayout(undefined, undefined, Direction.RTL); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + expect(root_child0.getComputedLeft()).toBe(50); + expect(root_child0.getComputedTop()).toBe(0); + expect(root_child0.getComputedWidth()).toBe(50); + expect(root_child0.getComputedHeight()).toBe(20); + } finally { + if (typeof root !== 'undefined') { + root.freeRecursive(); + } + + config.free(); + } +}); test('box_sizing_content_box_border_only', () => { const config = Yoga.Config.create(); let root; @@ -209,6 +657,51 @@ test('box_sizing_content_box_border_only', () => { config.free(); } }); +test('box_sizing_content_box_border_only_percent', () => { + const config = Yoga.Config.create(); + let root; + + try { + root = Yoga.Node.create(config); + root.setPositionType(PositionType.Absolute); + root.setWidth(100); + root.setHeight(100); + + const root_child0 = Yoga.Node.create(config); + root_child0.setWidth("50%"); + root_child0.setBoxSizing(BoxSizing.ContentBox); + root.insertChild(root_child0, 0); + root.calculateLayout(undefined, undefined, Direction.LTR); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + expect(root_child0.getComputedLeft()).toBe(0); + expect(root_child0.getComputedTop()).toBe(0); + expect(root_child0.getComputedWidth()).toBe(50); + expect(root_child0.getComputedHeight()).toBe(0); + + root.calculateLayout(undefined, undefined, Direction.RTL); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + expect(root_child0.getComputedLeft()).toBe(50); + expect(root_child0.getComputedTop()).toBe(0); + expect(root_child0.getComputedWidth()).toBe(50); + expect(root_child0.getComputedHeight()).toBe(0); + } finally { + if (typeof root !== 'undefined') { + root.freeRecursive(); + } + + config.free(); + } +}); test('box_sizing_border_box_border_only', () => { const config = Yoga.Config.create(); let root; @@ -243,6 +736,50 @@ test('box_sizing_border_box_border_only', () => { config.free(); } }); +test('box_sizing_border_box_border_only_percent', () => { + const config = Yoga.Config.create(); + let root; + + try { + root = Yoga.Node.create(config); + root.setPositionType(PositionType.Absolute); + root.setWidth(100); + root.setHeight(100); + + const root_child0 = Yoga.Node.create(config); + root_child0.setWidth("50%"); + root.insertChild(root_child0, 0); + root.calculateLayout(undefined, undefined, Direction.LTR); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + expect(root_child0.getComputedLeft()).toBe(0); + expect(root_child0.getComputedTop()).toBe(0); + expect(root_child0.getComputedWidth()).toBe(50); + expect(root_child0.getComputedHeight()).toBe(0); + + root.calculateLayout(undefined, undefined, Direction.RTL); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + expect(root_child0.getComputedLeft()).toBe(50); + expect(root_child0.getComputedTop()).toBe(0); + expect(root_child0.getComputedWidth()).toBe(50); + expect(root_child0.getComputedHeight()).toBe(0); + } finally { + if (typeof root !== 'undefined') { + root.freeRecursive(); + } + + config.free(); + } +}); test('box_sizing_content_box_no_padding_no_border', () => { const config = Yoga.Config.create(); let root; @@ -1738,3 +2275,471 @@ test('box_sizing_border_box_nested_alternating', () => { config.free(); } }); +test.skip('box_sizing_content_box_flex_basis_row', () => { + const config = Yoga.Config.create(); + let root; + + try { + root = Yoga.Node.create(config); + root.setFlexDirection(FlexDirection.Row); + root.setPositionType(PositionType.Absolute); + root.setWidth(100); + root.setHeight(100); + + const root_child0 = Yoga.Node.create(config); + root_child0.setFlexBasis(50); + root_child0.setPadding(Edge.Left, 5); + root_child0.setPadding(Edge.Top, 5); + root_child0.setPadding(Edge.Right, 5); + root_child0.setPadding(Edge.Bottom, 5); + root_child0.setBorder(Edge.Left, 10); + root_child0.setBorder(Edge.Top, 10); + root_child0.setBorder(Edge.Right, 10); + root_child0.setBorder(Edge.Bottom, 10); + root_child0.setHeight(25); + root_child0.setBoxSizing(BoxSizing.ContentBox); + root.insertChild(root_child0, 0); + root.calculateLayout(undefined, undefined, Direction.LTR); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + expect(root_child0.getComputedLeft()).toBe(0); + expect(root_child0.getComputedTop()).toBe(0); + expect(root_child0.getComputedWidth()).toBe(80); + expect(root_child0.getComputedHeight()).toBe(55); + + root.calculateLayout(undefined, undefined, Direction.RTL); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + expect(root_child0.getComputedLeft()).toBe(20); + expect(root_child0.getComputedTop()).toBe(0); + expect(root_child0.getComputedWidth()).toBe(80); + expect(root_child0.getComputedHeight()).toBe(55); + } finally { + if (typeof root !== 'undefined') { + root.freeRecursive(); + } + + config.free(); + } +}); +test('box_sizing_border_box_flex_basis_row', () => { + const config = Yoga.Config.create(); + let root; + + try { + root = Yoga.Node.create(config); + root.setFlexDirection(FlexDirection.Row); + root.setPositionType(PositionType.Absolute); + root.setWidth(100); + root.setHeight(100); + + const root_child0 = Yoga.Node.create(config); + root_child0.setFlexBasis(50); + root_child0.setPadding(Edge.Left, 5); + root_child0.setPadding(Edge.Top, 5); + root_child0.setPadding(Edge.Right, 5); + root_child0.setPadding(Edge.Bottom, 5); + root_child0.setBorder(Edge.Left, 10); + root_child0.setBorder(Edge.Top, 10); + root_child0.setBorder(Edge.Right, 10); + root_child0.setBorder(Edge.Bottom, 10); + root_child0.setHeight(25); + root.insertChild(root_child0, 0); + root.calculateLayout(undefined, undefined, Direction.LTR); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + expect(root_child0.getComputedLeft()).toBe(0); + expect(root_child0.getComputedTop()).toBe(0); + expect(root_child0.getComputedWidth()).toBe(50); + expect(root_child0.getComputedHeight()).toBe(30); + + root.calculateLayout(undefined, undefined, Direction.RTL); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + expect(root_child0.getComputedLeft()).toBe(50); + expect(root_child0.getComputedTop()).toBe(0); + expect(root_child0.getComputedWidth()).toBe(50); + expect(root_child0.getComputedHeight()).toBe(30); + } finally { + if (typeof root !== 'undefined') { + root.freeRecursive(); + } + + config.free(); + } +}); +test.skip('box_sizing_content_box_flex_basis_column', () => { + const config = Yoga.Config.create(); + let root; + + try { + root = Yoga.Node.create(config); + root.setPositionType(PositionType.Absolute); + root.setWidth(100); + root.setHeight(100); + + const root_child0 = Yoga.Node.create(config); + root_child0.setFlexBasis(50); + root_child0.setPadding(Edge.Left, 5); + root_child0.setPadding(Edge.Top, 5); + root_child0.setPadding(Edge.Right, 5); + root_child0.setPadding(Edge.Bottom, 5); + root_child0.setBorder(Edge.Left, 10); + root_child0.setBorder(Edge.Top, 10); + root_child0.setBorder(Edge.Right, 10); + root_child0.setBorder(Edge.Bottom, 10); + root_child0.setHeight(25); + root_child0.setBoxSizing(BoxSizing.ContentBox); + root.insertChild(root_child0, 0); + root.calculateLayout(undefined, undefined, Direction.LTR); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + expect(root_child0.getComputedLeft()).toBe(0); + expect(root_child0.getComputedTop()).toBe(0); + expect(root_child0.getComputedWidth()).toBe(100); + expect(root_child0.getComputedHeight()).toBe(80); + + root.calculateLayout(undefined, undefined, Direction.RTL); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + expect(root_child0.getComputedLeft()).toBe(0); + expect(root_child0.getComputedTop()).toBe(0); + expect(root_child0.getComputedWidth()).toBe(100); + expect(root_child0.getComputedHeight()).toBe(80); + } finally { + if (typeof root !== 'undefined') { + root.freeRecursive(); + } + + config.free(); + } +}); +test('box_sizing_border_box_flex_basis_column', () => { + const config = Yoga.Config.create(); + let root; + + try { + root = Yoga.Node.create(config); + root.setPositionType(PositionType.Absolute); + root.setWidth(100); + root.setHeight(100); + + const root_child0 = Yoga.Node.create(config); + root_child0.setFlexBasis(50); + root_child0.setPadding(Edge.Left, 5); + root_child0.setPadding(Edge.Top, 5); + root_child0.setPadding(Edge.Right, 5); + root_child0.setPadding(Edge.Bottom, 5); + root_child0.setBorder(Edge.Left, 10); + root_child0.setBorder(Edge.Top, 10); + root_child0.setBorder(Edge.Right, 10); + root_child0.setBorder(Edge.Bottom, 10); + root_child0.setHeight(25); + root.insertChild(root_child0, 0); + root.calculateLayout(undefined, undefined, Direction.LTR); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + expect(root_child0.getComputedLeft()).toBe(0); + expect(root_child0.getComputedTop()).toBe(0); + expect(root_child0.getComputedWidth()).toBe(100); + expect(root_child0.getComputedHeight()).toBe(50); + + root.calculateLayout(undefined, undefined, Direction.RTL); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + expect(root_child0.getComputedLeft()).toBe(0); + expect(root_child0.getComputedTop()).toBe(0); + expect(root_child0.getComputedWidth()).toBe(100); + expect(root_child0.getComputedHeight()).toBe(50); + } finally { + if (typeof root !== 'undefined') { + root.freeRecursive(); + } + + config.free(); + } +}); +test('box_sizing_content_box_padding_start', () => { + const config = Yoga.Config.create(); + let root; + + try { + root = Yoga.Node.create(config); + root.setPositionType(PositionType.Absolute); + root.setPadding(Edge.Start, 5); + root.setWidth(100); + root.setHeight(100); + root.setBoxSizing(BoxSizing.ContentBox); + root.calculateLayout(undefined, undefined, Direction.LTR); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(105); + expect(root.getComputedHeight()).toBe(100); + + root.calculateLayout(undefined, undefined, Direction.RTL); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(105); + expect(root.getComputedHeight()).toBe(100); + } finally { + if (typeof root !== 'undefined') { + root.freeRecursive(); + } + + config.free(); + } +}); +test('box_sizing_border_box_padding_start', () => { + const config = Yoga.Config.create(); + let root; + + try { + root = Yoga.Node.create(config); + root.setPositionType(PositionType.Absolute); + root.setPadding(Edge.Start, 5); + root.setWidth(100); + root.setHeight(100); + root.calculateLayout(undefined, undefined, Direction.LTR); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + root.calculateLayout(undefined, undefined, Direction.RTL); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + } finally { + if (typeof root !== 'undefined') { + root.freeRecursive(); + } + + config.free(); + } +}); +test('box_sizing_content_box_padding_end', () => { + const config = Yoga.Config.create(); + let root; + + try { + root = Yoga.Node.create(config); + root.setPositionType(PositionType.Absolute); + root.setPadding(Edge.End, 5); + root.setWidth(100); + root.setHeight(100); + root.setBoxSizing(BoxSizing.ContentBox); + root.calculateLayout(undefined, undefined, Direction.LTR); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(105); + expect(root.getComputedHeight()).toBe(100); + + root.calculateLayout(undefined, undefined, Direction.RTL); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(105); + expect(root.getComputedHeight()).toBe(100); + } finally { + if (typeof root !== 'undefined') { + root.freeRecursive(); + } + + config.free(); + } +}); +test('box_sizing_border_box_padding_end', () => { + const config = Yoga.Config.create(); + let root; + + try { + root = Yoga.Node.create(config); + root.setPositionType(PositionType.Absolute); + root.setPadding(Edge.End, 5); + root.setWidth(100); + root.setHeight(100); + root.calculateLayout(undefined, undefined, Direction.LTR); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + root.calculateLayout(undefined, undefined, Direction.RTL); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + } finally { + if (typeof root !== 'undefined') { + root.freeRecursive(); + } + + config.free(); + } +}); +test('box_sizing_content_box_border_start', () => { + const config = Yoga.Config.create(); + let root; + + try { + root = Yoga.Node.create(config); + root.setPositionType(PositionType.Absolute); + root.setBorder(Edge.Start, 5); + root.setWidth(100); + root.setHeight(100); + root.setBoxSizing(BoxSizing.ContentBox); + root.calculateLayout(undefined, undefined, Direction.LTR); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(105); + expect(root.getComputedHeight()).toBe(100); + + root.calculateLayout(undefined, undefined, Direction.RTL); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(105); + expect(root.getComputedHeight()).toBe(100); + } finally { + if (typeof root !== 'undefined') { + root.freeRecursive(); + } + + config.free(); + } +}); +test('box_sizing_border_box_border_start', () => { + const config = Yoga.Config.create(); + let root; + + try { + root = Yoga.Node.create(config); + root.setPositionType(PositionType.Absolute); + root.setBorder(Edge.Start, 5); + root.setWidth(100); + root.setHeight(100); + root.calculateLayout(undefined, undefined, Direction.LTR); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + root.calculateLayout(undefined, undefined, Direction.RTL); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + } finally { + if (typeof root !== 'undefined') { + root.freeRecursive(); + } + + config.free(); + } +}); +test('box_sizing_content_box_border_end', () => { + const config = Yoga.Config.create(); + let root; + + try { + root = Yoga.Node.create(config); + root.setPositionType(PositionType.Absolute); + root.setBorder(Edge.End, 5); + root.setWidth(100); + root.setHeight(100); + root.setBoxSizing(BoxSizing.ContentBox); + root.calculateLayout(undefined, undefined, Direction.LTR); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(105); + expect(root.getComputedHeight()).toBe(100); + + root.calculateLayout(undefined, undefined, Direction.RTL); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(105); + expect(root.getComputedHeight()).toBe(100); + } finally { + if (typeof root !== 'undefined') { + root.freeRecursive(); + } + + config.free(); + } +}); +test('box_sizing_border_box_border_end', () => { + const config = Yoga.Config.create(); + let root; + + try { + root = Yoga.Node.create(config); + root.setPositionType(PositionType.Absolute); + root.setBorder(Edge.End, 5); + root.setWidth(100); + root.setHeight(100); + root.calculateLayout(undefined, undefined, Direction.LTR); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + + root.calculateLayout(undefined, undefined, Direction.RTL); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(100); + expect(root.getComputedHeight()).toBe(100); + } finally { + if (typeof root !== 'undefined') { + root.freeRecursive(); + } + + config.free(); + } +}); diff --git a/tests/YGMeasureTest.cpp b/tests/YGMeasureTest.cpp index eeb00b18..c88e8826 100644 --- a/tests/YGMeasureTest.cpp +++ b/tests/YGMeasureTest.cpp @@ -899,3 +899,81 @@ TEST(YogaTest, percent_padding_and_percent_margin_with_measure_func) { YGConfigFree(config); } + +static YGSize _measure_half_width_height( + YGNodeConstRef node, + float width, + YGMeasureMode /*widthMode*/, + float height, + YGMeasureMode /*heightMode*/) { + int* measureCount = (int*)YGNodeGetContext(node); + if (measureCount != nullptr) { + (*measureCount)++; + } + + return YGSize{0.5f * width, 0.5f * height}; +} + +TEST(YogaTest, measure_content_box) { + YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 200); + YGNodeStyleSetBoxSizing(root, YGBoxSizingContentBox); + YGNodeStyleSetPadding(root, YGEdgeAll, 5); + YGNodeStyleSetBorder(root, YGEdgeAll, 10); + + int measureCount = 0; + + YGNodeRef root_child0 = YGNodeNew(); + YGNodeSetContext(root_child0, &measureCount); + YGNodeSetMeasureFunc(root_child0, _measure_half_width_height); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(1, measureCount); + + ASSERT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_EQ(130, YGNodeLayoutGetWidth(root)); + ASSERT_EQ(230, YGNodeLayoutGetHeight(root)); + + ASSERT_EQ(15, YGNodeLayoutGetLeft(root_child0)); + ASSERT_EQ(15, YGNodeLayoutGetTop(root_child0)); + ASSERT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, measure_border_box) { + YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 200); + YGNodeStyleSetBoxSizing(root, YGBoxSizingBorderBox); + YGNodeStyleSetPadding(root, YGEdgeAll, 5); + YGNodeStyleSetBorder(root, YGEdgeAll, 10); + + int measureCount = 0; + + YGNodeRef root_child0 = YGNodeNew(); + YGNodeSetContext(root_child0, &measureCount); + YGNodeSetMeasureFunc(root_child0, _measure_half_width_height); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(1, measureCount); + + ASSERT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_EQ(200, YGNodeLayoutGetHeight(root)); + + ASSERT_EQ(15, YGNodeLayoutGetLeft(root_child0)); + ASSERT_EQ(15, YGNodeLayoutGetTop(root_child0)); + ASSERT_EQ(70, YGNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(85, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} diff --git a/tests/generated/YGBoxSizingTest.cpp b/tests/generated/YGBoxSizingTest.cpp index 91b29040..69438984 100644 --- a/tests/generated/YGBoxSizingTest.cpp +++ b/tests/generated/YGBoxSizingTest.cpp @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * clang-format off - * @generated SignedSource<<56d0eec106ade0bbd034067594249c76>> + * @generated SignedSource<<36f0f519320608e2c5c6eb6666be7efc>> * generated by gentest/gentest-driver.ts from gentest/fixtures/YGBoxSizingTest.html */ @@ -48,7 +48,7 @@ TEST(YogaTest, box_sizing_content_box_simple) { YGConfigFree(config); } -TEST(YogaTest, box_sizing_border_box) { +TEST(YogaTest, box_sizing_border_box_simple) { YGConfigRef config = YGConfigNew(); YGNodeRef root = YGNodeNewWithConfig(config); @@ -82,6 +82,333 @@ TEST(YogaTest, box_sizing_border_box) { YGConfigFree(config); } +TEST(YogaTest, box_sizing_content_box_percent) { + YGConfigRef config = YGConfigNew(); + + YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetPadding(root_child0, YGEdgeLeft, 4); + YGNodeStyleSetPadding(root_child0, YGEdgeTop, 4); + YGNodeStyleSetPadding(root_child0, YGEdgeRight, 4); + YGNodeStyleSetPadding(root_child0, YGEdgeBottom, 4); + YGNodeStyleSetBorder(root_child0, YGEdgeLeft, 16); + YGNodeStyleSetBorder(root_child0, YGEdgeTop, 16); + YGNodeStyleSetBorder(root_child0, YGEdgeRight, 16); + YGNodeStyleSetBorder(root_child0, YGEdgeBottom, 16); + YGNodeStyleSetWidthPercent(root_child0, 50); + YGNodeStyleSetHeightPercent(root_child0, 25); + YGNodeStyleSetBoxSizing(root_child0, YGBoxSizingContentBox); + 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(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(65, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(65, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + +TEST(YogaTest, box_sizing_border_box_percent) { + YGConfigRef config = YGConfigNew(); + + YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetPadding(root_child0, YGEdgeLeft, 4); + YGNodeStyleSetPadding(root_child0, YGEdgeTop, 4); + YGNodeStyleSetPadding(root_child0, YGEdgeRight, 4); + YGNodeStyleSetPadding(root_child0, YGEdgeBottom, 4); + YGNodeStyleSetBorder(root_child0, YGEdgeLeft, 16); + YGNodeStyleSetBorder(root_child0, YGEdgeTop, 16); + YGNodeStyleSetBorder(root_child0, YGEdgeRight, 16); + YGNodeStyleSetBorder(root_child0, YGEdgeBottom, 16); + YGNodeStyleSetWidthPercent(root_child0, 50); + YGNodeStyleSetHeightPercent(root_child0, 25); + 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(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + +TEST(YogaTest, box_sizing_content_box_absolute) { + YGConfigRef config = YGConfigNew(); + + YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); + YGNodeStyleSetPadding(root_child0, YGEdgeLeft, 12); + YGNodeStyleSetPadding(root_child0, YGEdgeTop, 12); + YGNodeStyleSetPadding(root_child0, YGEdgeRight, 12); + YGNodeStyleSetPadding(root_child0, YGEdgeBottom, 12); + YGNodeStyleSetBorder(root_child0, YGEdgeLeft, 8); + YGNodeStyleSetBorder(root_child0, YGEdgeTop, 8); + YGNodeStyleSetBorder(root_child0, YGEdgeRight, 8); + YGNodeStyleSetBorder(root_child0, YGEdgeBottom, 8); + YGNodeStyleSetHeightPercent(root_child0, 25); + YGNodeStyleSetBoxSizing(root_child0, YGBoxSizingContentBox); + 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(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(65, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(65, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + +TEST(YogaTest, box_sizing_border_box_absolute) { + YGConfigRef config = YGConfigNew(); + + YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); + YGNodeStyleSetPadding(root_child0, YGEdgeLeft, 12); + YGNodeStyleSetPadding(root_child0, YGEdgeTop, 12); + YGNodeStyleSetPadding(root_child0, YGEdgeRight, 12); + YGNodeStyleSetPadding(root_child0, YGEdgeBottom, 12); + YGNodeStyleSetBorder(root_child0, YGEdgeLeft, 8); + YGNodeStyleSetBorder(root_child0, YGEdgeTop, 8); + YGNodeStyleSetBorder(root_child0, YGEdgeRight, 8); + YGNodeStyleSetBorder(root_child0, YGEdgeBottom, 8); + YGNodeStyleSetHeightPercent(root_child0, 25); + 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(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + +TEST(YogaTest, box_sizing_content_box_comtaining_block) { + YGConfigRef config = YGConfigNew(); + + YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetPadding(root, YGEdgeLeft, 12); + YGNodeStyleSetPadding(root, YGEdgeTop, 12); + YGNodeStyleSetPadding(root, YGEdgeRight, 12); + YGNodeStyleSetPadding(root, YGEdgeBottom, 12); + YGNodeStyleSetBorder(root, YGEdgeLeft, 8); + YGNodeStyleSetBorder(root, YGEdgeTop, 8); + YGNodeStyleSetBorder(root, YGEdgeRight, 8); + YGNodeStyleSetBorder(root, YGEdgeBottom, 8); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + YGNodeStyleSetBoxSizing(root, YGBoxSizingContentBox); + + YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root_child0, YGPositionTypeStatic); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root_child0_child0, YGPositionTypeAbsolute); + YGNodeStyleSetWidth(root_child0_child0, 50); + YGNodeStyleSetHeightPercent(root_child0_child0, 25); + 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(140, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(140, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(31, YGNodeLayoutGetHeight(root_child0_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(140, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(140, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(31, YGNodeLayoutGetHeight(root_child0_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + +TEST(YogaTest, box_sizing_border_box_comtaining_block) { + YGConfigRef config = YGConfigNew(); + + YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetPadding(root, YGEdgeLeft, 12); + YGNodeStyleSetPadding(root, YGEdgeTop, 12); + YGNodeStyleSetPadding(root, YGEdgeRight, 12); + YGNodeStyleSetPadding(root, YGEdgeBottom, 12); + YGNodeStyleSetBorder(root, YGEdgeLeft, 8); + YGNodeStyleSetBorder(root, YGEdgeTop, 8); + YGNodeStyleSetBorder(root, YGEdgeRight, 8); + YGNodeStyleSetBorder(root, YGEdgeBottom, 8); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root_child0, YGPositionTypeStatic); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root_child0_child0, YGPositionTypeAbsolute); + YGNodeStyleSetWidth(root_child0_child0, 50); + YGNodeStyleSetHeightPercent(root_child0_child0, 25); + 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(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(21, YGNodeLayoutGetHeight(root_child0_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(21, YGNodeLayoutGetHeight(root_child0_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + TEST(YogaTest, box_sizing_content_box_padding_only) { YGConfigRef config = YGConfigNew(); @@ -113,6 +440,51 @@ TEST(YogaTest, box_sizing_content_box_padding_only) { YGConfigFree(config); } +TEST(YogaTest, box_sizing_content_box_padding_only_percent) { + YGConfigRef config = YGConfigNew(); + + YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetPaddingPercent(root_child0, YGEdgeLeft, 10); + YGNodeStyleSetPaddingPercent(root_child0, YGEdgeTop, 10); + YGNodeStyleSetPaddingPercent(root_child0, YGEdgeRight, 10); + YGNodeStyleSetPaddingPercent(root_child0, YGEdgeBottom, 10); + YGNodeStyleSetWidthPercent(root_child0, 50); + YGNodeStyleSetBoxSizing(root_child0, YGBoxSizingContentBox); + 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(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(70, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(70, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + TEST(YogaTest, box_sizing_border_box_padding_only) { YGConfigRef config = YGConfigNew(); @@ -143,6 +515,50 @@ TEST(YogaTest, box_sizing_border_box_padding_only) { YGConfigFree(config); } +TEST(YogaTest, box_sizing_border_box_padding_only_percent) { + YGConfigRef config = YGConfigNew(); + + YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetPaddingPercent(root_child0, YGEdgeLeft, 10); + YGNodeStyleSetPaddingPercent(root_child0, YGEdgeTop, 10); + YGNodeStyleSetPaddingPercent(root_child0, YGEdgeRight, 10); + YGNodeStyleSetPaddingPercent(root_child0, YGEdgeBottom, 10); + YGNodeStyleSetWidthPercent(root_child0, 50); + 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(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + TEST(YogaTest, box_sizing_content_box_border_only) { YGConfigRef config = YGConfigNew(); @@ -174,6 +590,47 @@ TEST(YogaTest, box_sizing_content_box_border_only) { YGConfigFree(config); } +TEST(YogaTest, box_sizing_content_box_border_only_percent) { + YGConfigRef config = YGConfigNew(); + + YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetWidthPercent(root_child0, 50); + YGNodeStyleSetBoxSizing(root_child0, YGBoxSizingContentBox); + 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(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + TEST(YogaTest, box_sizing_border_box_border_only) { YGConfigRef config = YGConfigNew(); @@ -204,6 +661,46 @@ TEST(YogaTest, box_sizing_border_box_border_only) { YGConfigFree(config); } +TEST(YogaTest, box_sizing_border_box_border_only_percent) { + YGConfigRef config = YGConfigNew(); + + YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetWidthPercent(root_child0, 50); + 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(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + TEST(YogaTest, box_sizing_content_box_no_padding_no_border) { YGConfigRef config = YGConfigNew(); @@ -1618,3 +2115,427 @@ TEST(YogaTest, box_sizing_border_box_nested_alternating) { YGConfigFree(config); } + +TEST(YogaTest, box_sizing_content_box_flex_basis_row) { + GTEST_SKIP(); + + YGConfigRef config = YGConfigNew(); + + YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetFlexBasis(root_child0, 50); + YGNodeStyleSetPadding(root_child0, YGEdgeLeft, 5); + YGNodeStyleSetPadding(root_child0, YGEdgeTop, 5); + YGNodeStyleSetPadding(root_child0, YGEdgeRight, 5); + YGNodeStyleSetPadding(root_child0, YGEdgeBottom, 5); + YGNodeStyleSetBorder(root_child0, YGEdgeLeft, 10); + YGNodeStyleSetBorder(root_child0, YGEdgeTop, 10); + YGNodeStyleSetBorder(root_child0, YGEdgeRight, 10); + YGNodeStyleSetBorder(root_child0, YGEdgeBottom, 10); + YGNodeStyleSetHeight(root_child0, 25); + YGNodeStyleSetBoxSizing(root_child0, YGBoxSizingContentBox); + 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(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(55, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(55, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + +TEST(YogaTest, box_sizing_border_box_flex_basis_row) { + YGConfigRef config = YGConfigNew(); + + YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetFlexBasis(root_child0, 50); + YGNodeStyleSetPadding(root_child0, YGEdgeLeft, 5); + YGNodeStyleSetPadding(root_child0, YGEdgeTop, 5); + YGNodeStyleSetPadding(root_child0, YGEdgeRight, 5); + YGNodeStyleSetPadding(root_child0, YGEdgeBottom, 5); + YGNodeStyleSetBorder(root_child0, YGEdgeLeft, 10); + YGNodeStyleSetBorder(root_child0, YGEdgeTop, 10); + YGNodeStyleSetBorder(root_child0, YGEdgeRight, 10); + YGNodeStyleSetBorder(root_child0, YGEdgeBottom, 10); + YGNodeStyleSetHeight(root_child0, 25); + 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(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + +TEST(YogaTest, box_sizing_content_box_flex_basis_column) { + GTEST_SKIP(); + + YGConfigRef config = YGConfigNew(); + + YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetFlexBasis(root_child0, 50); + YGNodeStyleSetPadding(root_child0, YGEdgeLeft, 5); + YGNodeStyleSetPadding(root_child0, YGEdgeTop, 5); + YGNodeStyleSetPadding(root_child0, YGEdgeRight, 5); + YGNodeStyleSetPadding(root_child0, YGEdgeBottom, 5); + YGNodeStyleSetBorder(root_child0, YGEdgeLeft, 10); + YGNodeStyleSetBorder(root_child0, YGEdgeTop, 10); + YGNodeStyleSetBorder(root_child0, YGEdgeRight, 10); + YGNodeStyleSetBorder(root_child0, YGEdgeBottom, 10); + YGNodeStyleSetHeight(root_child0, 25); + YGNodeStyleSetBoxSizing(root_child0, YGBoxSizingContentBox); + 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(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + +TEST(YogaTest, box_sizing_border_box_flex_basis_column) { + YGConfigRef config = YGConfigNew(); + + YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetFlexBasis(root_child0, 50); + YGNodeStyleSetPadding(root_child0, YGEdgeLeft, 5); + YGNodeStyleSetPadding(root_child0, YGEdgeTop, 5); + YGNodeStyleSetPadding(root_child0, YGEdgeRight, 5); + YGNodeStyleSetPadding(root_child0, YGEdgeBottom, 5); + YGNodeStyleSetBorder(root_child0, YGEdgeLeft, 10); + YGNodeStyleSetBorder(root_child0, YGEdgeTop, 10); + YGNodeStyleSetBorder(root_child0, YGEdgeRight, 10); + YGNodeStyleSetBorder(root_child0, YGEdgeBottom, 10); + YGNodeStyleSetHeight(root_child0, 25); + 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(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + +TEST(YogaTest, box_sizing_content_box_padding_start) { + YGConfigRef config = YGConfigNew(); + + YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetPadding(root, YGEdgeStart, 5); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + YGNodeStyleSetBoxSizing(root, YGBoxSizingContentBox); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(105, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(105, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + +TEST(YogaTest, box_sizing_border_box_padding_start) { + YGConfigRef config = YGConfigNew(); + + YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetPadding(root, YGEdgeStart, 5); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + +TEST(YogaTest, box_sizing_content_box_padding_end) { + YGConfigRef config = YGConfigNew(); + + YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetPadding(root, YGEdgeEnd, 5); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + YGNodeStyleSetBoxSizing(root, YGBoxSizingContentBox); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(105, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(105, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + +TEST(YogaTest, box_sizing_border_box_padding_end) { + YGConfigRef config = YGConfigNew(); + + YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetPadding(root, YGEdgeEnd, 5); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + +TEST(YogaTest, box_sizing_content_box_border_start) { + YGConfigRef config = YGConfigNew(); + + YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetBorder(root, YGEdgeStart, 5); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + YGNodeStyleSetBoxSizing(root, YGBoxSizingContentBox); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(105, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(105, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + +TEST(YogaTest, box_sizing_border_box_border_start) { + YGConfigRef config = YGConfigNew(); + + YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetBorder(root, YGEdgeStart, 5); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + +TEST(YogaTest, box_sizing_content_box_border_end) { + YGConfigRef config = YGConfigNew(); + + YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetBorder(root, YGEdgeEnd, 5); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + YGNodeStyleSetBoxSizing(root, YGBoxSizingContentBox); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(105, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(105, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + +TEST(YogaTest, box_sizing_border_box_border_end) { + YGConfigRef config = YGConfigNew(); + + YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + YGNodeStyleSetBorder(root, YGEdgeEnd, 5); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} -- 2.50.1.windows.1