Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fixup hack for flex line size calculation #1380

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gentest/Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source "https://rubygems.org"

gem 'watir', '~>7.2.0'
gem 'webdrivers', '~> 5.2.0'
gem 'webdrivers', '~> 5.3.0'
10 changes: 5 additions & 5 deletions gentest/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
GEM
remote: https://rubygems.org/
specs:
nokogiri (1.15.2-arm64-darwin)
nokogiri (1.15.4-arm64-darwin)
racc (~> 1.4)
racc (1.7.0)
racc (1.7.1)
regexp_parser (2.8.1)
rexml (3.2.5)
rubyzip (2.3.2)
Expand All @@ -14,18 +14,18 @@ GEM
watir (7.2.2)
regexp_parser (>= 1.2, < 3)
selenium-webdriver (~> 4.2)
webdrivers (5.2.0)
webdrivers (5.3.1)
nokogiri (~> 1.6)
rubyzip (>= 1.3.0)
selenium-webdriver (~> 4.0)
selenium-webdriver (~> 4.0, < 4.11)
websocket (1.2.9)

PLATFORMS
arm64-darwin-22

DEPENDENCIES
watir (~> 7.2.0)
webdrivers (~> 5.2.0)
webdrivers (~> 5.3.0)

BUNDLED WITH
2.4.10
7 changes: 7 additions & 0 deletions gentest/fixtures/YGJustifyContentTest.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,10 @@
</div>
</div>
</div>

<div id="justify_content_space_between_indefinite_container_dim_with_free_space" style="width: 300px; height: 300x; align-items: center;">
<div style="flex-direction: row; min-width: 200px; justify-content: space-between;">
<div style="width: 50px; height: 50px;"></div>
<div style="width: 50px; height: 50px;"></div>
</div>
</div>
71 changes: 71 additions & 0 deletions java/tests/com/facebook/yoga/YGJustifyContentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,77 @@ public void test_justify_content_min_width_with_padding_child_width_lower_than_p
assertEquals(100f, root_child0_child0_child0.getLayoutHeight(), 0.0f);
}

@Test
public void test_justify_content_space_between_indefinite_container_dim_with_free_space() {
YogaConfig config = YogaConfigFactory.create();
config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ABSOLUTE_PERCENTAGE_AGAINST_PADDING_EDGE, true);

final YogaNode root = createNode(config);
root.setAlignItems(YogaAlign.CENTER);
root.setWidth(300f);

final YogaNode root_child0 = createNode(config);
root_child0.setFlexDirection(YogaFlexDirection.ROW);
root_child0.setJustifyContent(YogaJustify.SPACE_BETWEEN);
root_child0.setMinWidth(200f);
root.addChildAt(root_child0, 0);

final YogaNode root_child0_child0 = createNode(config);
root_child0_child0.setWidth(50f);
root_child0_child0.setHeight(50f);
root_child0.addChildAt(root_child0_child0, 0);

final YogaNode root_child0_child1 = createNode(config);
root_child0_child1.setWidth(50f);
root_child0_child1.setHeight(50f);
root_child0.addChildAt(root_child0_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(300f, root.getLayoutWidth(), 0.0f);
assertEquals(50f, root.getLayoutHeight(), 0.0f);

assertEquals(50f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(200f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(50f, 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(50f, root_child0_child0.getLayoutHeight(), 0.0f);

assertEquals(150f, root_child0_child1.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child1.getLayoutY(), 0.0f);
assertEquals(50f, root_child0_child1.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child0_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(300f, root.getLayoutWidth(), 0.0f);
assertEquals(50f, root.getLayoutHeight(), 0.0f);

assertEquals(50f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(200f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);

assertEquals(150f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child0_child0.getLayoutHeight(), 0.0f);

assertEquals(0f, root_child0_child1.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child1.getLayoutY(), 0.0f);
assertEquals(50f, root_child0_child1.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child0_child1.getLayoutHeight(), 0.0f);
}

private YogaNode createNode(YogaConfig config) {
return mNodeFactory.create(config);
}
Expand Down
77 changes: 77 additions & 0 deletions javascript/tests/generated/YGJustifyContentTest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1275,3 +1275,80 @@ test('justify_content_min_width_with_padding_child_width_lower_than_parent', ()
config.free();
}
});
test('justify_content_space_between_indefinite_container_dim_with_free_space', () => {
const config = Yoga.Config.create();
let root;

config.setExperimentalFeatureEnabled(ExperimentalFeature.AbsolutePercentageAgainstPaddingEdge, true);

try {
root = Yoga.Node.create(config);
root.setAlignItems(Align.Center);
root.setWidth(300);

const root_child0 = Yoga.Node.create(config);
root_child0.setFlexDirection(FlexDirection.Row);
root_child0.setJustifyContent(Justify.SpaceBetween);
root_child0.setMinWidth(200);
root.insertChild(root_child0, 0);

const root_child0_child0 = Yoga.Node.create(config);
root_child0_child0.setWidth(50);
root_child0_child0.setHeight(50);
root_child0.insertChild(root_child0_child0, 0);

const root_child0_child1 = Yoga.Node.create(config);
root_child0_child1.setWidth(50);
root_child0_child1.setHeight(50);
root_child0.insertChild(root_child0_child1, 1);
root.calculateLayout(undefined, undefined, Direction.LTR);

expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(300);
expect(root.getComputedHeight()).toBe(50);

expect(root_child0.getComputedLeft()).toBe(50);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(200);
expect(root_child0.getComputedHeight()).toBe(50);

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(50);

expect(root_child0_child1.getComputedLeft()).toBe(150);
expect(root_child0_child1.getComputedTop()).toBe(0);
expect(root_child0_child1.getComputedWidth()).toBe(50);
expect(root_child0_child1.getComputedHeight()).toBe(50);

root.calculateLayout(undefined, undefined, Direction.RTL);

expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(300);
expect(root.getComputedHeight()).toBe(50);

expect(root_child0.getComputedLeft()).toBe(50);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(200);
expect(root_child0.getComputedHeight()).toBe(50);

expect(root_child0_child0.getComputedLeft()).toBe(150);
expect(root_child0_child0.getComputedTop()).toBe(0);
expect(root_child0_child0.getComputedWidth()).toBe(50);
expect(root_child0_child0.getComputedHeight()).toBe(50);

expect(root_child0_child1.getComputedLeft()).toBe(0);
expect(root_child0_child1.getComputedTop()).toBe(0);
expect(root_child0_child1.getComputedWidth()).toBe(50);
expect(root_child0_child1.getComputedHeight()).toBe(50);
} finally {
if (typeof root !== 'undefined') {
root.freeRecursive();
}

config.free();
}
});
72 changes: 72 additions & 0 deletions tests/generated/YGJustifyContentTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1170,3 +1170,75 @@ TEST(YogaTest, justify_content_min_width_with_padding_child_width_lower_than_par

YGConfigFree(config);
}

TEST(YogaTest, justify_content_space_between_indefinite_container_dim_with_free_space) {
const YGConfigRef config = YGConfigNew();
YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge, true);

const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetAlignItems(root, YGAlignCenter);
YGNodeStyleSetWidth(root, 300);

const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow);
YGNodeStyleSetJustifyContent(root_child0, YGJustifySpaceBetween);
YGNodeStyleSetMinWidth(root_child0, 200);
YGNodeInsertChild(root, root_child0, 0);

const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root_child0_child0, 50);
YGNodeStyleSetHeight(root_child0_child0, 50);
YGNodeInsertChild(root_child0, root_child0_child0, 0);

const YGNodeRef root_child0_child1 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root_child0_child1, 50);
YGNodeStyleSetHeight(root_child0_child1, 50);
YGNodeInsertChild(root_child0, root_child0_child1, 1);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(300, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root));

ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(50, 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(50, YGNodeLayoutGetHeight(root_child0_child0));

ASSERT_FLOAT_EQ(150, YGNodeLayoutGetLeft(root_child0_child1));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child1));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child1));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_child1));

YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);

ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(300, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root));

ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));

ASSERT_FLOAT_EQ(150, YGNodeLayoutGetLeft(root_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_child0));

ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child1));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child1));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child1));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_child1));

YGNodeFreeRecursive(root);

YGConfigFree(config);
}
13 changes: 6 additions & 7 deletions yoga/algorithm/CalculateLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1306,11 +1306,6 @@ static void YGJustifyMainAxis(
const auto child = node->getChild(i);
const Style& childStyle = child->getStyle();
const LayoutResults& childLayout = child->getLayout();
const bool isLastChild = i == flexLine.endOfLineIndex - 1;
// remove the gap if it is the last element of the line
if (isLastChild) {
betweenMainDim -= gap;
}
if (childStyle.display() == YGDisplayNone) {
continue;
}
Expand Down Expand Up @@ -1344,6 +1339,10 @@ static void YGJustifyMainAxis(
leadingEdge(mainAxis));
}

if (child != flexLine.itemsInFlow.back()) {
flexLine.layout.mainDim += betweenMainDim;
}

if (child->marginTrailingValue(mainAxis).unit == YGUnitAuto) {
flexLine.layout.mainDim += flexLine.layout.remainingFreeSpace /
static_cast<float>(numberOfAutoMarginsOnCurrentLine);
Expand All @@ -1354,14 +1353,14 @@ static void YGJustifyMainAxis(
// If we skipped the flex step, then we can't rely on the measuredDims
// because they weren't computed. This means we can't call
// dimensionWithMargin.
flexLine.layout.mainDim += betweenMainDim +
flexLine.layout.mainDim +=
child->getMarginForAxis(mainAxis, availableInnerWidth).unwrap() +
childLayout.computedFlexBasis.unwrap();
flexLine.layout.crossDim = availableInnerCrossDim;
} else {
// The main dimension is the sum of all the elements dimension plus
// the spacing.
flexLine.layout.mainDim += betweenMainDim +
flexLine.layout.mainDim +=
dimensionWithMargin(child, mainAxis, availableInnerWidth);

if (isNodeBaselineLayout) {
Expand Down