Change flex getters to return the set values

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

Reviewed By: astreet

Differential Revision: D4604744

Pulled By: emilsjolander

fbshipit-source-id: 02d79100ef22be866db1c3bd9d53e4447186811f
This commit is contained in:
Lukas Wöhrl 2017-02-28 09:17:17 -08:00 committed by Facebook Github Bot
parent 5403946f09
commit 80225fb9e7
2 changed files with 31 additions and 30 deletions

View File

@ -139,6 +139,9 @@ typedef struct YGNode {
#define YG_DEFAULT_DIMENSION_VALUES_AUTO_UNIT \ #define YG_DEFAULT_DIMENSION_VALUES_AUTO_UNIT \
{ [YGDimensionWidth] = YG_AUTO_VALUES, [YGDimensionHeight] = YG_AUTO_VALUES, } { [YGDimensionWidth] = YG_AUTO_VALUES, [YGDimensionHeight] = YG_AUTO_VALUES, }
static const float kDefaultFlexGrow = 0.0f;
static const float kDefaultFlexShrink = 0.0f;
static YGNode gYGNodeDefaults = { static YGNode gYGNodeDefaults = {
.parent = NULL, .parent = NULL,
.children = 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)) { if (!YGFloatIsUndefined(node->style.flexGrow)) {
return node->style.flexGrow; return node->style.flexGrow;
} }
if (!YGFloatIsUndefined(node->style.flex) && node->style.flex > 0.0f) { if (!YGFloatIsUndefined(node->style.flex) && node->style.flex > 0.0f) {
return node->style.flex; return node->style.flex;
} }
return 0.0f; return kDefaultFlexGrow;
} }
inline float YGNodeStyleGetFlexShrink(const YGNodeRef node) { float YGNodeStyleGetFlexGrow(const YGNodeRef node) {
return YGFloatIsUndefined(node->style.flexGrow) ? kDefaultFlexGrow : node->style.flexGrow;
}
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)) { if (!YGFloatIsUndefined(node->style.flexShrink)) {
return node->style.flexShrink; return node->style.flexShrink;
} }
if (!YGFloatIsUndefined(node->style.flex) && node->style.flex < 0.0f) { if (!YGFloatIsUndefined(node->style.flex) && node->style.flex < 0.0f) {
return -node->style.flex; 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) { if (node->style.flexBasis.unit != YGUnitAuto && node->style.flexBasis.unit != YGUnitUndefined) {
return &node->style.flexBasis; return &node->style.flexBasis;
} }
@ -443,17 +454,6 @@ static inline const YGValue *YGNodeStyleGetFlexBasisPtr(const YGNodeRef node) {
return &YGValueAuto; 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) \ #define YG_NODE_PROPERTY_IMPL(type, name, paramName, instanceName) \
void YGNodeSet##name(const YGNodeRef node, type paramName) { \ void YGNodeSet##name(const YGNodeRef node, type paramName) { \
node->instanceName = 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(YGOverflow, Overflow, overflow, overflow);
YG_NODE_STYLE_PROPERTY_IMPL(YGDisplay, Display, display, display); 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, FlexGrow, flexGrow, flexGrow);
YG_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexShrink, flexShrink, flexShrink); 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, Position, position, position);
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(YGValue, Margin, margin, margin); 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', "); YGLog(YGLogLevelDebug, "alignSelf: 'stretch', ");
} }
YGPrintNumberIfNotUndefinedf("flexGrow", YGNodeStyleGetFlexGrow(node)); YGPrintNumberIfNotUndefinedf("flexGrow", YGResolveFlexGrow(node));
YGPrintNumberIfNotUndefinedf("flexShrink", YGNodeStyleGetFlexShrink(node)); YGPrintNumberIfNotUndefinedf("flexShrink", YGNodeResolveFlexShrink(node));
YGPrintNumberIfNotUndefined("flexBasis", YGNodeStyleGetFlexBasisPtr(node)); YGPrintNumberIfNotUndefined("flexBasis", YGNodeResolveFlexBasisPtr(node));
if (node->style.overflow == YGOverflowHidden) { if (node->style.overflow == YGOverflowHidden) {
YGLog(YGLogLevelDebug, "overflow: 'hidden', "); YGLog(YGLogLevelDebug, "overflow: 'hidden', ");
@ -1121,7 +1122,7 @@ static YGFlexDirection YGFlexDirectionCross(const YGFlexDirection flexDirection,
static inline bool YGNodeIsFlex(const YGNodeRef node) { static inline bool YGNodeIsFlex(const YGNodeRef node) {
return (node->style.positionType == YGPositionTypeRelative && return (node->style.positionType == YGPositionTypeRelative &&
(YGNodeStyleGetFlexGrow(node) != 0 || YGNodeStyleGetFlexShrink(node) != 0)); (YGResolveFlexGrow(node) != 0 || YGNodeResolveFlexShrink(node) != 0));
} }
static bool YGIsBaselineLayout(const YGNodeRef node) { static bool YGIsBaselineLayout(const YGNodeRef node) {
@ -1330,7 +1331,7 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node,
YGMeasureMode childHeightMeasureMode; YGMeasureMode childHeightMeasureMode;
const float resolvedFlexBasis = const float resolvedFlexBasis =
YGValueResolve(YGNodeStyleGetFlexBasisPtr(child), mainAxisParentSize); YGValueResolve(YGNodeResolveFlexBasisPtr(child), mainAxisParentSize);
const bool isRowStyleDimDefined = YGNodeIsStyleDimDefined(child, YGFlexDirectionRow, parentWidth); const bool isRowStyleDimDefined = YGNodeIsStyleDimDefined(child, YGFlexDirectionRow, parentWidth);
const bool isColumnStyleDimDefined = const bool isColumnStyleDimDefined =
YGNodeIsStyleDimDefined(child, YGFlexDirectionColumn, parentHeight); YGNodeIsStyleDimDefined(child, YGFlexDirectionColumn, parentHeight);
@ -1983,7 +1984,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
singleFlexChild = NULL; singleFlexChild = NULL;
break; break;
} }
} else if (YGNodeStyleGetFlexGrow(child) > 0.0f && YGNodeStyleGetFlexShrink(child) > 0.0f) { } else if (YGResolveFlexGrow(child) > 0.0f && YGNodeResolveFlexShrink(child) > 0.0f) {
singleFlexChild = child; singleFlexChild = child;
} }
} }
@ -2112,13 +2113,13 @@ static void YGNodelayoutImpl(const YGNodeRef node,
itemsOnLine++; itemsOnLine++;
if (YGNodeIsFlex(child)) { if (YGNodeIsFlex(child)) {
totalFlexGrowFactors += YGNodeStyleGetFlexGrow(child); totalFlexGrowFactors += YGResolveFlexGrow(child);
// Unlike the grow factor, the shrink factor is scaled relative to the // Unlike the grow factor, the shrink factor is scaled relative to the
// child // child
// dimension. // dimension.
totalFlexShrinkScaledFactors += totalFlexShrinkScaledFactors +=
-YGNodeStyleGetFlexShrink(child) * child->layout.computedFlexBasis; -YGNodeResolveFlexShrink(child) * child->layout.computedFlexBasis;
} }
// Store a private linked list of children that need to be layed out. // 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; childFlexBasis = currentRelativeChild->layout.computedFlexBasis;
if (remainingFreeSpace < 0) { if (remainingFreeSpace < 0) {
flexShrinkScaledFactor = -YGNodeStyleGetFlexShrink(currentRelativeChild) * childFlexBasis; flexShrinkScaledFactor = -YGNodeResolveFlexShrink(currentRelativeChild) * childFlexBasis;
// Is this child able to shrink? // Is this child able to shrink?
if (flexShrinkScaledFactor != 0) { if (flexShrinkScaledFactor != 0) {
@ -2236,7 +2237,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
} }
} }
} else if (remainingFreeSpace > 0) { } else if (remainingFreeSpace > 0) {
flexGrowFactor = YGNodeStyleGetFlexGrow(currentRelativeChild); flexGrowFactor = YGResolveFlexGrow(currentRelativeChild);
// Is this child able to grow? // Is this child able to grow?
if (flexGrowFactor != 0) { if (flexGrowFactor != 0) {
@ -2275,7 +2276,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
float updatedMainSize = childFlexBasis; float updatedMainSize = childFlexBasis;
if (remainingFreeSpace < 0) { if (remainingFreeSpace < 0) {
flexShrinkScaledFactor = -YGNodeStyleGetFlexShrink(currentRelativeChild) * childFlexBasis; flexShrinkScaledFactor = -YGNodeResolveFlexShrink(currentRelativeChild) * childFlexBasis;
// Is this child able to shrink? // Is this child able to shrink?
if (flexShrinkScaledFactor != 0) { if (flexShrinkScaledFactor != 0) {
float childSize; float childSize;
@ -2295,7 +2296,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
availableInnerWidth); availableInnerWidth);
} }
} else if (remainingFreeSpace > 0) { } else if (remainingFreeSpace > 0) {
flexGrowFactor = YGNodeStyleGetFlexGrow(currentRelativeChild); flexGrowFactor = YGResolveFlexGrow(currentRelativeChild);
// Is this child able to grow? // Is this child able to grow?
if (flexGrowFactor != 0) { if (flexGrowFactor != 0) {

View File

@ -167,7 +167,7 @@ YG_NODE_STYLE_PROPERTY(YGWrap, FlexWrap, flexWrap);
YG_NODE_STYLE_PROPERTY(YGOverflow, Overflow, overflow); YG_NODE_STYLE_PROPERTY(YGOverflow, Overflow, overflow);
YG_NODE_STYLE_PROPERTY(YGDisplay, Display, display); 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, FlexGrow, flexGrow);
YG_NODE_STYLE_PROPERTY(float, FlexShrink, flexShrink); YG_NODE_STYLE_PROPERTY(float, FlexShrink, flexShrink);
YG_NODE_STYLE_PROPERTY_UNIT_AUTO(YGValue, FlexBasis, flexBasis); YG_NODE_STYLE_PROPERTY_UNIT_AUTO(YGValue, FlexBasis, flexBasis);