Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

YGEdge -> yoga::Edge #1461

Closed
wants to merge 3 commits 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
13 changes: 2 additions & 11 deletions tests/CompactValueTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,20 +304,11 @@ TEST(YogaTest, dedicated_unit_factories) {
ASSERT_EQ(
CompactValue::of<YGUnitPercent>(123.456f),
CompactValue(YGValue{123.456f, YGUnitPercent}));
}

TEST(YogaTest, dedicated_unit_maybe_factories) {
ASSERT_EQ(
CompactValue::ofMaybe<YGUnitPoint>(-9876.5f),
CompactValue(YGValue{-9876.5f, YGUnitPoint}));
ASSERT_EQ(
CompactValue::ofMaybe<YGUnitPoint>(YGUndefined),
CompactValue::of<YGUnitPoint>(YGUndefined),
CompactValue(YGValueUndefined));
ASSERT_EQ(
CompactValue::ofMaybe<YGUnitPercent>(123.456f),
CompactValue(YGValue{123.456f, YGUnitPercent}));
ASSERT_EQ(
CompactValue::ofMaybe<YGUnitPercent>(YGUndefined),
CompactValue::of<YGUnitPercent>(YGUndefined),
CompactValue(YGValueUndefined));
}

Expand Down
8 changes: 4 additions & 4 deletions yoga/YGNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,13 @@ bool YGNodeCanUseCachedMeasurement(
float marginColumn,
YGConfigRef config) {
return yoga::canUseCachedMeasurement(
scopedEnum(widthMode),
sizingMode(scopedEnum(widthMode)),
availableWidth,
scopedEnum(heightMode),
sizingMode(scopedEnum(heightMode)),
availableHeight,
scopedEnum(lastWidthMode),
sizingMode(scopedEnum(lastWidthMode)),
lastAvailableWidth,
scopedEnum(lastHeightMode),
sizingMode(scopedEnum(lastHeightMode)),
lastAvailableHeight,
lastComputedWidth,
lastComputedHeight,
Expand Down
13 changes: 13 additions & 0 deletions yoga/YGNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,19 @@ typedef struct YGSize {
} YGSize;

/**
* Returns the computed dimensions of the node, following the contraints of
* `widthMode` and `heightMode`:
*
* YGMeasureModeUndefined: The parent has not imposed any constraint on the
* child. It can be whatever size it wants.
*
* YGMeasureModeAtMost: The child can be as large as it wants up to the
* specified size.
*
* YGMeasureModeExactly: The parent has determined an exact size for the
* child. The child is going to be given those bounds regardless of how big it
* wants to be.
*
* @returns the size of the leaf node, measured under the given contraints.
*/
typedef YGSize (*YGMeasureFunc)(
Expand Down
38 changes: 20 additions & 18 deletions yoga/YGNodeLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <yoga/Yoga.h>
#include <yoga/debug/AssertFatal.h>
#include <yoga/enums/Edge.h>
#include <yoga/node/Node.h>

using namespace facebook;
Expand All @@ -15,50 +16,48 @@ using namespace facebook::yoga;
namespace {

template <auto LayoutMember>
float getResolvedLayoutProperty(
const YGNodeConstRef nodeRef,
const YGEdge edge) {
float getResolvedLayoutProperty(const YGNodeConstRef nodeRef, const Edge edge) {
const auto node = resolveRef(nodeRef);
yoga::assertFatalWithNode(
node,
edge <= YGEdgeEnd,
edge <= Edge::End,
"Cannot get layout properties of multi-edge shorthands");

if (edge == YGEdgeStart) {
if (edge == Edge::Start) {
if (node->getLayout().direction() == Direction::RTL) {
return (node->getLayout().*LayoutMember)[YGEdgeRight];
return (node->getLayout().*LayoutMember)(Edge::Right);
} else {
return (node->getLayout().*LayoutMember)[YGEdgeLeft];
return (node->getLayout().*LayoutMember)(Edge::Left);
}
}

if (edge == YGEdgeEnd) {
if (edge == Edge::End) {
if (node->getLayout().direction() == Direction::RTL) {
return (node->getLayout().*LayoutMember)[YGEdgeLeft];
return (node->getLayout().*LayoutMember)(Edge::Left);
} else {
return (node->getLayout().*LayoutMember)[YGEdgeRight];
return (node->getLayout().*LayoutMember)(Edge::Right);
}
}

return (node->getLayout().*LayoutMember)[edge];
return (node->getLayout().*LayoutMember)(edge);
}

} // namespace

float YGNodeLayoutGetLeft(const YGNodeConstRef node) {
return resolveRef(node)->getLayout().position[YGEdgeLeft];
return resolveRef(node)->getLayout().position(Edge::Left);
}

float YGNodeLayoutGetTop(const YGNodeConstRef node) {
return resolveRef(node)->getLayout().position[YGEdgeTop];
return resolveRef(node)->getLayout().position(Edge::Top);
}

float YGNodeLayoutGetRight(const YGNodeConstRef node) {
return resolveRef(node)->getLayout().position[YGEdgeRight];
return resolveRef(node)->getLayout().position(Edge::Right);
}

float YGNodeLayoutGetBottom(const YGNodeConstRef node) {
return resolveRef(node)->getLayout().position[YGEdgeBottom];
return resolveRef(node)->getLayout().position(Edge::Bottom);
}

float YGNodeLayoutGetWidth(const YGNodeConstRef node) {
Expand All @@ -78,13 +77,16 @@ bool YGNodeLayoutGetHadOverflow(const YGNodeConstRef node) {
}

float YGNodeLayoutGetMargin(YGNodeConstRef node, YGEdge edge) {
return getResolvedLayoutProperty<&LayoutResults::margin>(node, edge);
return getResolvedLayoutProperty<&LayoutResults::margin>(
node, scopedEnum(edge));
}

float YGNodeLayoutGetBorder(YGNodeConstRef node, YGEdge edge) {
return getResolvedLayoutProperty<&LayoutResults::border>(node, edge);
return getResolvedLayoutProperty<&LayoutResults::border>(
node, scopedEnum(edge));
}

float YGNodeLayoutGetPadding(YGNodeConstRef node, YGEdge edge) {
return getResolvedLayoutProperty<&LayoutResults::padding>(node, edge);
return getResolvedLayoutProperty<&LayoutResults::padding>(
node, scopedEnum(edge));
}
Loading