From 010c5e5d381bce228fceaf16e4d83237822002ce Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Fri, 13 Oct 2023 15:11:06 +0100 Subject: [PATCH] Support "align-content: space-evenly" --- enums.py | 1 + gentest/fixtures/YGAlignContentTest.html | 19 ++ gentest/gentest-cpp.js | 1 + gentest/gentest-java.js | 1 + gentest/gentest-javascript.js | 1 + gentest/gentest.js | 2 + java/com/facebook/yoga/YogaAlign.java | 4 +- .../com/facebook/yoga/YGAlignContentTest.java | 218 ++++++++++++++++ javascript/src/generated/YGEnums.ts | 2 + .../generated/YGAlignContentTest.test.ts | 236 ++++++++++++++++++ tests/NumericBitfieldTest.cpp | 4 +- tests/generated/YGAlignContentTest.cpp | 221 ++++++++++++++++ yoga/YGEnums.cpp | 2 + yoga/YGEnums.h | 3 +- yoga/algorithm/CalculateLayout.cpp | 13 + yoga/enums/Align.h | 5 +- 16 files changed, 727 insertions(+), 6 deletions(-) diff --git a/enums.py b/enums.py index 07f02249db..0c5207b22c 100755 --- a/enums.py +++ b/enums.py @@ -29,6 +29,7 @@ "Baseline", "SpaceBetween", "SpaceAround", + "SpaceEvenly", ], "PositionType": ["Static", "Relative", "Absolute"], "Display": ["Flex", "None"], diff --git a/gentest/fixtures/YGAlignContentTest.html b/gentest/fixtures/YGAlignContentTest.html index 3cecdf8d54..46cfb0093c 100644 --- a/gentest/fixtures/YGAlignContentTest.html +++ b/gentest/fixtures/YGAlignContentTest.html @@ -54,6 +54,25 @@
+
+
+
+
+
+
+
+ + +
+
+
+
+ +
+
+
+
+
diff --git a/gentest/gentest-cpp.js b/gentest/gentest-cpp.js index b174efd2fc..464eb2f67e 100644 --- a/gentest/gentest-cpp.js +++ b/gentest/gentest-cpp.js @@ -91,6 +91,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, { YGAlignStretch: {value: 'YGAlignStretch'}, YGAlignSpaceBetween: {value: 'YGAlignSpaceBetween'}, YGAlignSpaceAround: {value: 'YGAlignSpaceAround'}, + YGAlignSpaceEvenly: {value: 'YGAlignSpaceEvenly'}, YGAlignBaseline: {value: 'YGAlignBaseline'}, YGDirectionInherit: {value: 'YGDirectionInherit'}, diff --git a/gentest/gentest-java.js b/gentest/gentest-java.js index b6ec67336f..2154a611de 100644 --- a/gentest/gentest-java.js +++ b/gentest/gentest-java.js @@ -135,6 +135,7 @@ JavaEmitter.prototype = Object.create(Emitter.prototype, { YGAlignStretch: {value: 'YogaAlign.STRETCH'}, YGAlignSpaceBetween: {value: 'YogaAlign.SPACE_BETWEEN'}, YGAlignSpaceAround: {value: 'YogaAlign.SPACE_AROUND'}, + YGAlignSpaceEvenly: {value: 'YogaAlign.SPACE_EVENLY'}, YGAlignBaseline: {value: 'YogaAlign.BASELINE'}, YGDirectionInherit: {value: 'YogaDirection.INHERIT'}, diff --git a/gentest/gentest-javascript.js b/gentest/gentest-javascript.js index c2197f265a..69ebee8498 100644 --- a/gentest/gentest-javascript.js +++ b/gentest/gentest-javascript.js @@ -120,6 +120,7 @@ JavascriptEmitter.prototype = Object.create(Emitter.prototype, { YGAlignStretch: {value: 'Align.Stretch'}, YGAlignSpaceBetween: {value: 'Align.SpaceBetween'}, YGAlignSpaceAround: {value: 'Align.SpaceAround'}, + YGAlignSpaceEvenly: {value: 'Align.SpaceEvenly'}, YGAlignBaseline: {value: 'Align.Baseline'}, YGDirectionInherit: {value: 'Direction.Inherit'}, diff --git a/gentest/gentest.js b/gentest/gentest.js index af645b9288..6a83d6f589 100755 --- a/gentest/gentest.js +++ b/gentest/gentest.js @@ -608,6 +608,8 @@ function alignValue(e, value) { return e.YGAlignSpaceBetween; case 'space-around': return e.YGAlignSpaceAround; + case 'space-evenly': + return e.YGAlignSpaceEvenly; case 'baseline': return e.YGAlignBaseline; } diff --git a/java/com/facebook/yoga/YogaAlign.java b/java/com/facebook/yoga/YogaAlign.java index a60d77e0f2..00535154fc 100644 --- a/java/com/facebook/yoga/YogaAlign.java +++ b/java/com/facebook/yoga/YogaAlign.java @@ -17,7 +17,8 @@ public enum YogaAlign { STRETCH(4), BASELINE(5), SPACE_BETWEEN(6), - SPACE_AROUND(7); + SPACE_AROUND(7), + SPACE_EVENLY(8); private final int mIntValue; @@ -39,6 +40,7 @@ public static YogaAlign fromInt(int value) { case 5: return BASELINE; case 6: return SPACE_BETWEEN; case 7: return SPACE_AROUND; + case 8: return SPACE_EVENLY; default: throw new IllegalArgumentException("Unknown enum value: " + value); } } diff --git a/java/tests/com/facebook/yoga/YGAlignContentTest.java b/java/tests/com/facebook/yoga/YGAlignContentTest.java index 42f611ce5e..e54313148b 100644 --- a/java/tests/com/facebook/yoga/YGAlignContentTest.java +++ b/java/tests/com/facebook/yoga/YGAlignContentTest.java @@ -734,6 +734,224 @@ public void test_align_content_spacearound() { assertEquals(10f, root_child4.getLayoutHeight(), 0.0f); } + @Test + public void test_align_content_spaceevenly_wrap() { + YogaConfig config = YogaConfigFactory.create(); + config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ABSOLUTE_PERCENTAGE_AGAINST_PADDING_EDGE, true); + + final YogaNode root = createNode(config); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setAlignContent(YogaAlign.SPACE_EVENLY); + root.setWrap(YogaWrap.WRAP); + root.setWidth(140f); + root.setHeight(120f); + + final YogaNode root_child0 = createNode(config); + root_child0.setWidth(50f); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = createNode(config); + root_child1.setWidth(50f); + root_child1.setHeight(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = createNode(config); + root_child2.setWidth(50f); + root_child2.setHeight(10f); + root.addChildAt(root_child2, 2); + + final YogaNode root_child3 = createNode(config); + root_child3.setWidth(50f); + root_child3.setHeight(10f); + root.addChildAt(root_child3, 3); + + final YogaNode root_child4 = createNode(config); + root_child4.setWidth(50f); + root_child4.setHeight(10f); + root.addChildAt(root_child4, 4); + 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(120f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(23f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(23f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(55f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child3.getLayoutX(), 0.0f); + assertEquals(55f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child4.getLayoutX(), 0.0f); + assertEquals(88f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child4.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(120f, root.getLayoutHeight(), 0.0f); + + assertEquals(90f, root_child0.getLayoutX(), 0.0f); + assertEquals(23f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(40f, root_child1.getLayoutX(), 0.0f); + assertEquals(23f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(90f, root_child2.getLayoutX(), 0.0f); + assertEquals(55f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(40f, root_child3.getLayoutX(), 0.0f); + assertEquals(55f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(90f, root_child4.getLayoutX(), 0.0f); + assertEquals(88f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child4.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_content_spaceevenly_wrap_singleline() { + YogaConfig config = YogaConfigFactory.create(); + config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ABSOLUTE_PERCENTAGE_AGAINST_PADDING_EDGE, true); + + final YogaNode root = createNode(config); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setAlignContent(YogaAlign.SPACE_EVENLY); + root.setWrap(YogaWrap.WRAP); + root.setWidth(140f); + root.setHeight(120f); + + final YogaNode root_child0 = createNode(config); + root_child0.setWidth(50f); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = createNode(config); + root_child1.setWidth(50f); + root_child1.setHeight(10f); + root.addChildAt(root_child1, 1); + 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(120f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(55f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(55f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.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(120f, root.getLayoutHeight(), 0.0f); + + assertEquals(90f, root_child0.getLayoutX(), 0.0f); + assertEquals(55f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(40f, root_child1.getLayoutX(), 0.0f); + assertEquals(55f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_content_spaceevenly_nowrap() { + YogaConfig config = YogaConfigFactory.create(); + config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ABSOLUTE_PERCENTAGE_AGAINST_PADDING_EDGE, true); + + final YogaNode root = createNode(config); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setAlignContent(YogaAlign.SPACE_EVENLY); + root.setWidth(140f); + root.setHeight(120f); + + final YogaNode root_child0 = createNode(config); + root_child0.setWidth(50f); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = createNode(config); + root_child1.setWidth(50f); + root_child1.setHeight(10f); + root.addChildAt(root_child1, 1); + 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(120f, 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(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.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(120f, root.getLayoutHeight(), 0.0f); + + assertEquals(90f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(40f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + } + @Test public void test_align_content_stretch_row() { YogaConfig config = YogaConfigFactory.create(); diff --git a/javascript/src/generated/YGEnums.ts b/javascript/src/generated/YGEnums.ts index a78b30a3c7..9f771abb03 100644 --- a/javascript/src/generated/YGEnums.ts +++ b/javascript/src/generated/YGEnums.ts @@ -16,6 +16,7 @@ export enum Align { Baseline = 5, SpaceBetween = 6, SpaceAround = 7, + SpaceEvenly = 8, } export enum Dimension { @@ -141,6 +142,7 @@ const constants = { ALIGN_BASELINE: Align.Baseline, ALIGN_SPACE_BETWEEN: Align.SpaceBetween, ALIGN_SPACE_AROUND: Align.SpaceAround, + ALIGN_SPACE_EVENLY: Align.SpaceEvenly, DIMENSION_WIDTH: Dimension.Width, DIMENSION_HEIGHT: Dimension.Height, DIRECTION_INHERIT: Direction.Inherit, diff --git a/javascript/tests/generated/YGAlignContentTest.test.ts b/javascript/tests/generated/YGAlignContentTest.test.ts index 2d56ef4a99..841c58ddfc 100644 --- a/javascript/tests/generated/YGAlignContentTest.test.ts +++ b/javascript/tests/generated/YGAlignContentTest.test.ts @@ -776,6 +776,242 @@ test('align_content_spacearound', () => { config.free(); } }); +test('align_content_spaceevenly_wrap', () => { + const config = Yoga.Config.create(); + let root; + + config.setExperimentalFeatureEnabled(ExperimentalFeature.AbsolutePercentageAgainstPaddingEdge, true); + + try { + root = Yoga.Node.create(config); + root.setFlexDirection(FlexDirection.Row); + root.setAlignContent(Align.SpaceEvenly); + root.setFlexWrap(Wrap.Wrap); + root.setWidth(140); + root.setHeight(120); + + const root_child0 = Yoga.Node.create(config); + root_child0.setWidth(50); + root_child0.setHeight(10); + root.insertChild(root_child0, 0); + + const root_child1 = Yoga.Node.create(config); + root_child1.setWidth(50); + root_child1.setHeight(10); + root.insertChild(root_child1, 1); + + const root_child2 = Yoga.Node.create(config); + root_child2.setWidth(50); + root_child2.setHeight(10); + root.insertChild(root_child2, 2); + + const root_child3 = Yoga.Node.create(config); + root_child3.setWidth(50); + root_child3.setHeight(10); + root.insertChild(root_child3, 3); + + const root_child4 = Yoga.Node.create(config); + root_child4.setWidth(50); + root_child4.setHeight(10); + root.insertChild(root_child4, 4); + 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(120); + + expect(root_child0.getComputedLeft()).toBe(0); + expect(root_child0.getComputedTop()).toBe(23); + expect(root_child0.getComputedWidth()).toBe(50); + expect(root_child0.getComputedHeight()).toBe(10); + + expect(root_child1.getComputedLeft()).toBe(50); + expect(root_child1.getComputedTop()).toBe(23); + expect(root_child1.getComputedWidth()).toBe(50); + expect(root_child1.getComputedHeight()).toBe(10); + + expect(root_child2.getComputedLeft()).toBe(0); + expect(root_child2.getComputedTop()).toBe(55); + expect(root_child2.getComputedWidth()).toBe(50); + expect(root_child2.getComputedHeight()).toBe(10); + + expect(root_child3.getComputedLeft()).toBe(50); + expect(root_child3.getComputedTop()).toBe(55); + expect(root_child3.getComputedWidth()).toBe(50); + expect(root_child3.getComputedHeight()).toBe(10); + + expect(root_child4.getComputedLeft()).toBe(0); + expect(root_child4.getComputedTop()).toBe(88); + expect(root_child4.getComputedWidth()).toBe(50); + expect(root_child4.getComputedHeight()).toBe(10); + + 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(120); + + expect(root_child0.getComputedLeft()).toBe(90); + expect(root_child0.getComputedTop()).toBe(23); + expect(root_child0.getComputedWidth()).toBe(50); + expect(root_child0.getComputedHeight()).toBe(10); + + expect(root_child1.getComputedLeft()).toBe(40); + expect(root_child1.getComputedTop()).toBe(23); + expect(root_child1.getComputedWidth()).toBe(50); + expect(root_child1.getComputedHeight()).toBe(10); + + expect(root_child2.getComputedLeft()).toBe(90); + expect(root_child2.getComputedTop()).toBe(55); + expect(root_child2.getComputedWidth()).toBe(50); + expect(root_child2.getComputedHeight()).toBe(10); + + expect(root_child3.getComputedLeft()).toBe(40); + expect(root_child3.getComputedTop()).toBe(55); + expect(root_child3.getComputedWidth()).toBe(50); + expect(root_child3.getComputedHeight()).toBe(10); + + expect(root_child4.getComputedLeft()).toBe(90); + expect(root_child4.getComputedTop()).toBe(88); + expect(root_child4.getComputedWidth()).toBe(50); + expect(root_child4.getComputedHeight()).toBe(10); + } finally { + if (typeof root !== 'undefined') { + root.freeRecursive(); + } + + config.free(); + } +}); +test('align_content_spaceevenly_wrap_singleline', () => { + const config = Yoga.Config.create(); + let root; + + config.setExperimentalFeatureEnabled(ExperimentalFeature.AbsolutePercentageAgainstPaddingEdge, true); + + try { + root = Yoga.Node.create(config); + root.setFlexDirection(FlexDirection.Row); + root.setAlignContent(Align.SpaceEvenly); + root.setFlexWrap(Wrap.Wrap); + root.setWidth(140); + root.setHeight(120); + + const root_child0 = Yoga.Node.create(config); + root_child0.setWidth(50); + root_child0.setHeight(10); + root.insertChild(root_child0, 0); + + const root_child1 = Yoga.Node.create(config); + root_child1.setWidth(50); + root_child1.setHeight(10); + root.insertChild(root_child1, 1); + 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(120); + + expect(root_child0.getComputedLeft()).toBe(0); + expect(root_child0.getComputedTop()).toBe(55); + expect(root_child0.getComputedWidth()).toBe(50); + expect(root_child0.getComputedHeight()).toBe(10); + + expect(root_child1.getComputedLeft()).toBe(50); + expect(root_child1.getComputedTop()).toBe(55); + expect(root_child1.getComputedWidth()).toBe(50); + expect(root_child1.getComputedHeight()).toBe(10); + + 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(120); + + expect(root_child0.getComputedLeft()).toBe(90); + expect(root_child0.getComputedTop()).toBe(55); + expect(root_child0.getComputedWidth()).toBe(50); + expect(root_child0.getComputedHeight()).toBe(10); + + expect(root_child1.getComputedLeft()).toBe(40); + expect(root_child1.getComputedTop()).toBe(55); + expect(root_child1.getComputedWidth()).toBe(50); + expect(root_child1.getComputedHeight()).toBe(10); + } finally { + if (typeof root !== 'undefined') { + root.freeRecursive(); + } + + config.free(); + } +}); +test('align_content_spaceevenly_nowrap', () => { + const config = Yoga.Config.create(); + let root; + + config.setExperimentalFeatureEnabled(ExperimentalFeature.AbsolutePercentageAgainstPaddingEdge, true); + + try { + root = Yoga.Node.create(config); + root.setFlexDirection(FlexDirection.Row); + root.setAlignContent(Align.SpaceEvenly); + root.setWidth(140); + root.setHeight(120); + + const root_child0 = Yoga.Node.create(config); + root_child0.setWidth(50); + root_child0.setHeight(10); + root.insertChild(root_child0, 0); + + const root_child1 = Yoga.Node.create(config); + root_child1.setWidth(50); + root_child1.setHeight(10); + root.insertChild(root_child1, 1); + 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(120); + + expect(root_child0.getComputedLeft()).toBe(0); + expect(root_child0.getComputedTop()).toBe(0); + expect(root_child0.getComputedWidth()).toBe(50); + expect(root_child0.getComputedHeight()).toBe(10); + + expect(root_child1.getComputedLeft()).toBe(50); + expect(root_child1.getComputedTop()).toBe(0); + expect(root_child1.getComputedWidth()).toBe(50); + expect(root_child1.getComputedHeight()).toBe(10); + + 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(120); + + expect(root_child0.getComputedLeft()).toBe(90); + expect(root_child0.getComputedTop()).toBe(0); + expect(root_child0.getComputedWidth()).toBe(50); + expect(root_child0.getComputedHeight()).toBe(10); + + expect(root_child1.getComputedLeft()).toBe(40); + expect(root_child1.getComputedTop()).toBe(0); + expect(root_child1.getComputedWidth()).toBe(50); + expect(root_child1.getComputedHeight()).toBe(10); + } finally { + if (typeof root !== 'undefined') { + root.freeRecursive(); + } + + config.free(); + } +}); test('align_content_stretch_row', () => { const config = Yoga.Config.create(); let root; diff --git a/tests/NumericBitfieldTest.cpp b/tests/NumericBitfieldTest.cpp index 74f101c29b..852267718d 100644 --- a/tests/NumericBitfieldTest.cpp +++ b/tests/NumericBitfieldTest.cpp @@ -191,8 +191,8 @@ TEST(NumericBitfield, third_enum_can_be_set) { TEST(NumericBitfield, setting_values_does_not_spill_over) { uint32_t flags = 0; static constexpr size_t alignOffset = 0; - static constexpr size_t edgesOffset = 3; - static constexpr size_t boolOffset = 7; + static constexpr size_t edgesOffset = 4; + static constexpr size_t boolOffset = 8; uint32_t edge = 0xffffff; setEnumData(flags, edgesOffset, (YGEdge)edge); diff --git a/tests/generated/YGAlignContentTest.cpp b/tests/generated/YGAlignContentTest.cpp index ddb2c35d04..e4ec1a2490 100644 --- a/tests/generated/YGAlignContentTest.cpp +++ b/tests/generated/YGAlignContentTest.cpp @@ -727,6 +727,227 @@ TEST(YogaTest, align_content_spacearound) { YGConfigFree(config); } +TEST(YogaTest, align_content_spaceevenly_wrap) { + const YGConfigRef config = YGConfigNew(); + YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge, true); + + const YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetAlignContent(root, YGAlignSpaceEvenly); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + YGNodeStyleSetWidth(root, 140); + YGNodeStyleSetHeight(root, 120); + + const YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNewWithConfig(config); + YGNodeStyleSetWidth(root_child1, 50); + YGNodeStyleSetHeight(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNewWithConfig(config); + YGNodeStyleSetWidth(root_child2, 50); + YGNodeStyleSetHeight(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + + const YGNodeRef root_child3 = YGNodeNewWithConfig(config); + YGNodeStyleSetWidth(root_child3, 50); + YGNodeStyleSetHeight(root_child3, 10); + YGNodeInsertChild(root, root_child3, 3); + + const YGNodeRef root_child4 = YGNodeNewWithConfig(config); + YGNodeStyleSetWidth(root_child4, 50); + YGNodeStyleSetHeight(root_child4, 10); + YGNodeInsertChild(root, root_child4, 4); + 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(120, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(23, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(23, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(55, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(55, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(88, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); + + 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(120, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(23, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(23, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(55, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(55, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(88, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + +TEST(YogaTest, align_content_spaceevenly_wrap_singleline) { + const YGConfigRef config = YGConfigNew(); + YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge, true); + + const YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetAlignContent(root, YGAlignSpaceEvenly); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + YGNodeStyleSetWidth(root, 140); + YGNodeStyleSetHeight(root, 120); + + const YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNewWithConfig(config); + YGNodeStyleSetWidth(root_child1, 50); + YGNodeStyleSetHeight(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + 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(120, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(55, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(55, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + 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(120, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(55, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(55, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + +TEST(YogaTest, align_content_spaceevenly_nowrap) { + const YGConfigRef config = YGConfigNew(); + YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge, true); + + const YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetAlignContent(root, YGAlignSpaceEvenly); + YGNodeStyleSetWidth(root, 140); + YGNodeStyleSetHeight(root, 120); + + const YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNewWithConfig(config); + YGNodeStyleSetWidth(root_child1, 50); + YGNodeStyleSetHeight(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + 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(120, 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(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + 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(120, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + TEST(YogaTest, align_content_stretch_row) { const YGConfigRef config = YGConfigNew(); YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge, true); diff --git a/yoga/YGEnums.cpp b/yoga/YGEnums.cpp index b5916ca1ec..77e5c80237 100644 --- a/yoga/YGEnums.cpp +++ b/yoga/YGEnums.cpp @@ -27,6 +27,8 @@ const char* YGAlignToString(const YGAlign value) { return "space-between"; case YGAlignSpaceAround: return "space-around"; + case YGAlignSpaceEvenly: + return "space-evenly"; } return "unknown"; } diff --git a/yoga/YGEnums.h b/yoga/YGEnums.h index 55bbe9fc9d..ef09668c81 100644 --- a/yoga/YGEnums.h +++ b/yoga/YGEnums.h @@ -21,7 +21,8 @@ YG_ENUM_SEQ_DECL( YGAlignStretch, YGAlignBaseline, YGAlignSpaceBetween, - YGAlignSpaceAround) + YGAlignSpaceAround, + YGAlignSpaceEvenly) YG_ENUM_SEQ_DECL( YGDimension, diff --git a/yoga/algorithm/CalculateLayout.cpp b/yoga/algorithm/CalculateLayout.cpp index dc9f785eac..177f0b8181 100644 --- a/yoga/algorithm/CalculateLayout.cpp +++ b/yoga/algorithm/CalculateLayout.cpp @@ -2021,6 +2021,18 @@ static void calculateLayoutImpl( currentLead += remainingAlignContentDim / 2; } break; + case Align::SpaceEvenly: + if (availableInnerCrossDim > totalLineCrossDim) { + currentLead += + remainingAlignContentDim / static_cast(lineCount + 1); + if (lineCount > 1) { + crossDimLead = + remainingAlignContentDim / static_cast(lineCount + 1); + } + } else { + currentLead += remainingAlignContentDim / 2; + } + break; case Align::SpaceBetween: if (availableInnerCrossDim > totalLineCrossDim && lineCount > 1) { crossDimLead = @@ -2177,6 +2189,7 @@ static void calculateLayoutImpl( case Align::Auto: case Align::SpaceBetween: case Align::SpaceAround: + case Align::SpaceEvenly: break; } } diff --git a/yoga/enums/Align.h b/yoga/enums/Align.h index 95df12a790..67777fc31b 100644 --- a/yoga/enums/Align.h +++ b/yoga/enums/Align.h @@ -24,16 +24,17 @@ enum class Align : uint8_t { Baseline = YGAlignBaseline, SpaceBetween = YGAlignSpaceBetween, SpaceAround = YGAlignSpaceAround, + SpaceEvenly = YGAlignSpaceEvenly, }; template <> constexpr inline int32_t ordinalCount() { - return 8; + return 9; } template <> constexpr inline int32_t bitCount() { - return 3; + return 4; } constexpr inline Align scopedEnum(YGAlign unscoped) {