Skip to content
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
76 changes: 76 additions & 0 deletions tests/YGComputedMarginTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

#include <array>
#include <gtest/gtest.h>
#include <yoga/Yoga.h>

Expand All @@ -26,3 +27,78 @@ TEST(YogaTest, computed_layout_margin) {

YGNodeFreeRecursive(root);
}

TEST(YogaTest, margin_side_overrides_horizontal_and_vertical) {
const std::array<YGEdge, 6> edges = {
{YGEdgeTop, YGEdgeBottom, YGEdgeStart, YGEdgeEnd, YGEdgeLeft, YGEdgeRight}};

for (float edgeValue = 0; edgeValue < 2; ++edgeValue) {
for (const auto& edge : edges) {
YGEdge horizontalOrVertical = edge == YGEdgeTop || edge == YGEdgeBottom
? YGEdgeVertical
: YGEdgeHorizontal;

const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 100);
YGNodeStyleSetMargin(root, horizontalOrVertical, 10);
YGNodeStyleSetMargin(root, edge, edgeValue);

YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);

ASSERT_FLOAT_EQ(edgeValue, YGNodeLayoutGetMargin(root, edge));

YGNodeFreeRecursive(root);
}
}
}

TEST(YogaTest, margin_side_overrides_all) {
const std::array<YGEdge, 6> edges = {
{YGEdgeTop, YGEdgeBottom, YGEdgeStart, YGEdgeEnd, YGEdgeLeft, YGEdgeRight}};

for (float edgeValue = 0; edgeValue < 2; ++edgeValue) {
for (const auto& edge : edges) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 100);
YGNodeStyleSetMargin(root, YGEdgeAll, 10);
YGNodeStyleSetMargin(root, edge, edgeValue);

YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);

ASSERT_FLOAT_EQ(edgeValue, YGNodeLayoutGetMargin(root, edge));

YGNodeFreeRecursive(root);
}
}
}

TEST(YogaTest, margin_horizontal_and_vertical_overrides_all) {
const std::array<YGEdge, 2> directions = {
{YGEdgeHorizontal, YGEdgeVertical}};

for (float directionValue = 0; directionValue < 2; ++directionValue) {
for (const auto& direction : directions) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 100);
YGNodeStyleSetMargin(root, YGEdgeAll, 10);
YGNodeStyleSetMargin(root, direction, directionValue);

YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);

if (direction == YGEdgeVertical) {
ASSERT_FLOAT_EQ(directionValue, YGNodeLayoutGetMargin(root, YGEdgeTop));
ASSERT_FLOAT_EQ(directionValue, YGNodeLayoutGetMargin(root, YGEdgeBottom));
} else {
ASSERT_FLOAT_EQ(directionValue, YGNodeLayoutGetMargin(root, YGEdgeStart));
ASSERT_FLOAT_EQ(directionValue, YGNodeLayoutGetMargin(root, YGEdgeEnd));
ASSERT_FLOAT_EQ(directionValue, YGNodeLayoutGetMargin(root, YGEdgeLeft));
ASSERT_FLOAT_EQ(directionValue, YGNodeLayoutGetMargin(root, YGEdgeRight));
}

YGNodeFreeRecursive(root);
}
}
}
76 changes: 76 additions & 0 deletions tests/YGComputedPaddingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

#include <array>
#include <gtest/gtest.h>
#include <yoga/Yoga.h>

Expand All @@ -26,3 +27,78 @@ TEST(YogaTest, computed_layout_padding) {

YGNodeFreeRecursive(root);
}

TEST(YogaTest, padding_side_overrides_horizontal_and_vertical) {
const std::array<YGEdge, 6> edges = {
{YGEdgeTop, YGEdgeBottom, YGEdgeStart, YGEdgeEnd, YGEdgeLeft, YGEdgeRight}};

for (float edgeValue = 0; edgeValue < 2; ++edgeValue) {
for (const auto& edge : edges) {
YGEdge horizontalOrVertical = edge == YGEdgeTop || edge == YGEdgeBottom
? YGEdgeVertical
: YGEdgeHorizontal;

const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 100);
YGNodeStyleSetPadding(root, horizontalOrVertical, 10);
YGNodeStyleSetPadding(root, edge, edgeValue);

YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);

ASSERT_FLOAT_EQ(edgeValue, YGNodeLayoutGetPadding(root, edge));

YGNodeFreeRecursive(root);
}
}
}

TEST(YogaTest, padding_side_overrides_all) {
const std::array<YGEdge, 6> edges = {
{YGEdgeTop, YGEdgeBottom, YGEdgeStart, YGEdgeEnd, YGEdgeLeft, YGEdgeRight}};

for (float edgeValue = 0; edgeValue < 2; ++edgeValue) {
for (const auto& edge : edges) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 100);
YGNodeStyleSetPadding(root, YGEdgeAll, 10);
YGNodeStyleSetPadding(root, edge, edgeValue);

YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);

ASSERT_FLOAT_EQ(edgeValue, YGNodeLayoutGetPadding(root, edge));

YGNodeFreeRecursive(root);
}
}
}

TEST(YogaTest, padding_horizontal_and_vertical_overrides_all) {
const std::array<YGEdge, 2> directions = {
{YGEdgeHorizontal, YGEdgeVertical}};

for (float directionValue = 0; directionValue < 2; ++directionValue) {
for (const auto& direction : directions) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 100);
YGNodeStyleSetPadding(root, YGEdgeAll, 10);
YGNodeStyleSetPadding(root, direction, directionValue);

YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);

if (direction == YGEdgeVertical) {
ASSERT_FLOAT_EQ(directionValue, YGNodeLayoutGetPadding(root, YGEdgeTop));
ASSERT_FLOAT_EQ(directionValue, YGNodeLayoutGetPadding(root, YGEdgeBottom));
} else {
ASSERT_FLOAT_EQ(directionValue, YGNodeLayoutGetPadding(root, YGEdgeStart));
ASSERT_FLOAT_EQ(directionValue, YGNodeLayoutGetPadding(root, YGEdgeEnd));
ASSERT_FLOAT_EQ(directionValue, YGNodeLayoutGetPadding(root, YGEdgeLeft));
ASSERT_FLOAT_EQ(directionValue, YGNodeLayoutGetPadding(root, YGEdgeRight));
}

YGNodeFreeRecursive(root);
}
}
}
2 changes: 1 addition & 1 deletion yoga/YGNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ YGFloatOptional YGNode::getLeadingPadding(
YGResolveValue(style_.padding[YGEdgeStart], widthSize);
if (YGFlexDirectionIsRow(axis) &&
style_.padding[YGEdgeStart].unit != YGUnitUndefined &&
!paddingEdgeStart.isUndefined() && paddingEdgeStart.getValue() > 0.0f) {
!paddingEdgeStart.isUndefined() && paddingEdgeStart.getValue() >= 0.0f) {
return paddingEdgeStart;
}

Expand Down