Skip to content

Commit

Permalink
Support "align-content: space-evenly"
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Oct 13, 2023
1 parent d8666be commit 010c5e5
Show file tree
Hide file tree
Showing 16 changed files with 727 additions and 6 deletions.
1 change: 1 addition & 0 deletions enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"Baseline",
"SpaceBetween",
"SpaceAround",
"SpaceEvenly",
],
"PositionType": ["Static", "Relative", "Absolute"],
"Display": ["Flex", "None"],
Expand Down
19 changes: 19 additions & 0 deletions gentest/fixtures/YGAlignContentTest.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,25 @@
<div style="width: 50px; height: 10px;"></div>
</div>

<div id="align_content_spaceevenly_wrap" style="width: 140px; height: 120px; flex-wrap: wrap; flex-direction: row; align-content: space-evenly;">
<div style="width: 50px; height: 10px;"></div>
<div style="width: 50px; height: 10px;"></div>
<div style="width: 50px; height: 10px;"></div>
<div style="width: 50px; height: 10px;"></div>
<div style="width: 50px; height: 10px;"></div>
</div>

<!-- This tests the case where `flex-wrap: wrap` but the content does not actually wrap -->
<div id="align_content_spaceevenly_wrap_singleline" style="width: 140px; height: 120px; flex-wrap: wrap; flex-direction: row; align-content: space-evenly;">
<div style="width: 50px; height: 10px;"></div>
<div style="width: 50px; height: 10px;"></div>
</div>

<div id="align_content_spaceevenly_nowrap" style="width: 140px; height: 120px; flex-direction: row; align-content: space-evenly;">
<div style="width: 50px; height: 10px;"></div>
<div style="width: 50px; height: 10px;"></div>
</div>

<div id="align_content_stretch_row" style="width: 150px; height: 100px; flex-wrap: wrap; flex-direction: row; align-content: stretch;">
<div style="width: 50px;"></div>
<div style="width: 50px;"></div>
Expand Down
1 change: 1 addition & 0 deletions gentest/gentest-cpp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'},
Expand Down
1 change: 1 addition & 0 deletions gentest/gentest-java.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'},
Expand Down
1 change: 1 addition & 0 deletions gentest/gentest-javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'},
Expand Down
2 changes: 2 additions & 0 deletions gentest/gentest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion java/com/facebook/yoga/YogaAlign.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
}
Expand Down
218 changes: 218 additions & 0 deletions java/tests/com/facebook/yoga/YGAlignContentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions javascript/src/generated/YGEnums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export enum Align {
Baseline = 5,
SpaceBetween = 6,
SpaceAround = 7,
SpaceEvenly = 8,
}

export enum Dimension {
Expand Down Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 010c5e5

Please sign in to comment.