Permalink
Browse files

Change flex getters to return the set values

Summary:
Changed the flex getters to return the values they were actually set. See #421 .
Closes facebook/yoga#431

Reviewed By: astreet

Differential Revision: D4604744

Pulled By: emilsjolander

fbshipit-source-id: 02d79100ef22be866db1c3bd9d53e4447186811f
  • Loading branch information...
woehrl01 authored and facebook-github-bot committed Feb 28, 2017
1 parent 5403946 commit 80225fb9e7f1b4c56eb189d3fe9720148e3e3f1a
Showing with 31 additions and 30 deletions.
  1. +30 −29 ReactCommon/yoga/yoga/Yoga.c
  2. +1 −1 ReactCommon/yoga/yoga/Yoga.h
@@ -139,6 +139,9 @@ typedef struct YGNode {
#define YG_DEFAULT_DIMENSION_VALUES_AUTO_UNIT \
{ [YGDimensionWidth] = YG_AUTO_VALUES, [YGDimensionHeight] = YG_AUTO_VALUES, }
static const float kDefaultFlexGrow = 0.0f;
static const float kDefaultFlexShrink = 0.0f;
static YGNode gYGNodeDefaults = {
.parent = NULL,
.children = NULL,
@@ -413,27 +416,35 @@ void YGNodeCopyStyle(const YGNodeRef dstNode, const YGNodeRef srcNode) {
}
}
inline float YGNodeStyleGetFlexGrow(const YGNodeRef node) {
static inline float YGResolveFlexGrow(const YGNodeRef node) {
if (!YGFloatIsUndefined(node->style.flexGrow)) {
return node->style.flexGrow;
}
if (!YGFloatIsUndefined(node->style.flex) && node->style.flex > 0.0f) {
return node->style.flex;
}
return 0.0f;
return kDefaultFlexGrow;
}
float YGNodeStyleGetFlexGrow(const YGNodeRef node) {
return YGFloatIsUndefined(node->style.flexGrow) ? kDefaultFlexGrow : node->style.flexGrow;
}
inline float YGNodeStyleGetFlexShrink(const YGNodeRef node) {
float YGNodeStyleGetFlexShrink(const YGNodeRef node) {
return YGFloatIsUndefined(node->style.flexShrink) ? kDefaultFlexShrink : node->style.flexShrink;
}
static inline float YGNodeResolveFlexShrink(const YGNodeRef node) {
if (!YGFloatIsUndefined(node->style.flexShrink)) {
return node->style.flexShrink;
}
if (!YGFloatIsUndefined(node->style.flex) && node->style.flex < 0.0f) {
return -node->style.flex;
}
return 0.0f;
return kDefaultFlexShrink;
}
static inline const YGValue *YGNodeStyleGetFlexBasisPtr(const YGNodeRef node) {
static inline const YGValue *YGNodeResolveFlexBasisPtr(const YGNodeRef node) {
if (node->style.flexBasis.unit != YGUnitAuto && node->style.flexBasis.unit != YGUnitUndefined) {
return &node->style.flexBasis;
}
@@ -443,17 +454,6 @@ static inline const YGValue *YGNodeStyleGetFlexBasisPtr(const YGNodeRef node) {
return &YGValueAuto;
}
inline YGValue YGNodeStyleGetFlexBasis(const YGNodeRef node) {
return *YGNodeStyleGetFlexBasisPtr(node);
}
void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {
if (node->style.flex != flex) {
node->style.flex = flex;
YGNodeMarkDirtyInternal(node);
}
}
#define YG_NODE_PROPERTY_IMPL(type, name, paramName, instanceName) \
void YGNodeSet##name(const YGNodeRef node, type paramName) { \
node->instanceName = paramName; \
@@ -634,9 +634,10 @@ YG_NODE_STYLE_PROPERTY_IMPL(YGWrap, FlexWrap, flexWrap, flexWrap);
YG_NODE_STYLE_PROPERTY_IMPL(YGOverflow, Overflow, overflow, overflow);
YG_NODE_STYLE_PROPERTY_IMPL(YGDisplay, Display, display, display);
YG_NODE_STYLE_PROPERTY_IMPL(float, Flex, flex, flex);
YG_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexGrow, flexGrow, flexGrow);
YG_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexShrink, flexShrink, flexShrink);
YG_NODE_STYLE_PROPERTY_SETTER_UNIT_AUTO_IMPL(float, FlexBasis, flexBasis, flexBasis);
YG_NODE_STYLE_PROPERTY_UNIT_AUTO_IMPL(YGValue, FlexBasis, flexBasis, flexBasis);
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(YGValue, Position, position, position);
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(YGValue, Margin, margin, margin);
@@ -816,9 +817,9 @@ static void YGNodePrintInternal(const YGNodeRef node,
YGLog(YGLogLevelDebug, "alignSelf: 'stretch', ");
}
YGPrintNumberIfNotUndefinedf("flexGrow", YGNodeStyleGetFlexGrow(node));
YGPrintNumberIfNotUndefinedf("flexShrink", YGNodeStyleGetFlexShrink(node));
YGPrintNumberIfNotUndefined("flexBasis", YGNodeStyleGetFlexBasisPtr(node));
YGPrintNumberIfNotUndefinedf("flexGrow", YGResolveFlexGrow(node));
YGPrintNumberIfNotUndefinedf("flexShrink", YGNodeResolveFlexShrink(node));
YGPrintNumberIfNotUndefined("flexBasis", YGNodeResolveFlexBasisPtr(node));
if (node->style.overflow == YGOverflowHidden) {
YGLog(YGLogLevelDebug, "overflow: 'hidden', ");
@@ -1121,7 +1122,7 @@ static YGFlexDirection YGFlexDirectionCross(const YGFlexDirection flexDirection,
static inline bool YGNodeIsFlex(const YGNodeRef node) {
return (node->style.positionType == YGPositionTypeRelative &&
(YGNodeStyleGetFlexGrow(node) != 0 || YGNodeStyleGetFlexShrink(node) != 0));
(YGResolveFlexGrow(node) != 0 || YGNodeResolveFlexShrink(node) != 0));
}
static bool YGIsBaselineLayout(const YGNodeRef node) {
@@ -1330,7 +1331,7 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node,
YGMeasureMode childHeightMeasureMode;
const float resolvedFlexBasis =
YGValueResolve(YGNodeStyleGetFlexBasisPtr(child), mainAxisParentSize);
YGValueResolve(YGNodeResolveFlexBasisPtr(child), mainAxisParentSize);
const bool isRowStyleDimDefined = YGNodeIsStyleDimDefined(child, YGFlexDirectionRow, parentWidth);
const bool isColumnStyleDimDefined =
YGNodeIsStyleDimDefined(child, YGFlexDirectionColumn, parentHeight);
@@ -1983,7 +1984,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
singleFlexChild = NULL;
break;
}
} else if (YGNodeStyleGetFlexGrow(child) > 0.0f && YGNodeStyleGetFlexShrink(child) > 0.0f) {
} else if (YGResolveFlexGrow(child) > 0.0f && YGNodeResolveFlexShrink(child) > 0.0f) {
singleFlexChild = child;
}
}
@@ -2112,13 +2113,13 @@ static void YGNodelayoutImpl(const YGNodeRef node,
itemsOnLine++;
if (YGNodeIsFlex(child)) {
totalFlexGrowFactors += YGNodeStyleGetFlexGrow(child);
totalFlexGrowFactors += YGResolveFlexGrow(child);
// Unlike the grow factor, the shrink factor is scaled relative to the
// child
// dimension.
totalFlexShrinkScaledFactors +=
-YGNodeStyleGetFlexShrink(child) * child->layout.computedFlexBasis;
-YGNodeResolveFlexShrink(child) * child->layout.computedFlexBasis;
}
// Store a private linked list of children that need to be layed out.
@@ -2212,7 +2213,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
childFlexBasis = currentRelativeChild->layout.computedFlexBasis;
if (remainingFreeSpace < 0) {
flexShrinkScaledFactor = -YGNodeStyleGetFlexShrink(currentRelativeChild) * childFlexBasis;
flexShrinkScaledFactor = -YGNodeResolveFlexShrink(currentRelativeChild) * childFlexBasis;
// Is this child able to shrink?
if (flexShrinkScaledFactor != 0) {
@@ -2236,7 +2237,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
}
}
} else if (remainingFreeSpace > 0) {
flexGrowFactor = YGNodeStyleGetFlexGrow(currentRelativeChild);
flexGrowFactor = YGResolveFlexGrow(currentRelativeChild);
// Is this child able to grow?
if (flexGrowFactor != 0) {
@@ -2275,7 +2276,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
float updatedMainSize = childFlexBasis;
if (remainingFreeSpace < 0) {
flexShrinkScaledFactor = -YGNodeStyleGetFlexShrink(currentRelativeChild) * childFlexBasis;
flexShrinkScaledFactor = -YGNodeResolveFlexShrink(currentRelativeChild) * childFlexBasis;
// Is this child able to shrink?
if (flexShrinkScaledFactor != 0) {
float childSize;
@@ -2295,7 +2296,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
availableInnerWidth);
}
} else if (remainingFreeSpace > 0) {
flexGrowFactor = YGNodeStyleGetFlexGrow(currentRelativeChild);
flexGrowFactor = YGResolveFlexGrow(currentRelativeChild);
// Is this child able to grow?
if (flexGrowFactor != 0) {
@@ -167,7 +167,7 @@ YG_NODE_STYLE_PROPERTY(YGWrap, FlexWrap, flexWrap);
YG_NODE_STYLE_PROPERTY(YGOverflow, Overflow, overflow);
YG_NODE_STYLE_PROPERTY(YGDisplay, Display, display);
WIN_EXPORT void YGNodeStyleSetFlex(const YGNodeRef node, const float flex);
YG_NODE_STYLE_PROPERTY(float, Flex, flex);
YG_NODE_STYLE_PROPERTY(float, FlexGrow, flexGrow);
YG_NODE_STYLE_PROPERTY(float, FlexShrink, flexShrink);
YG_NODE_STYLE_PROPERTY_UNIT_AUTO(YGValue, FlexBasis, flexBasis);

0 comments on commit 80225fb

Please sign in to comment.