Moved YGFloatOptional from C struct to C++ struct
Summary: Earlier `YGfloatOptional` was plain struct with no privacy around the variables. This diff adds privacy and also enforces checks when one tries to access value of an undefined `YGFloatOptional` This diff also adds a behaviour in which when a value of an undefined YGFloatOptional is accessed, it will normally terminate(Several cleanup steps are performed). Reviewed By: emilsjolander Differential Revision: D7288555 fbshipit-source-id: f61cc92c8fd0d48d2fc1f4d0e6fcef155f19ff8a
This commit is contained in:
committed by
Facebook Github Bot
parent
ae86824636
commit
5d7b75a47a
@@ -13,7 +13,6 @@
|
||||
#include "YGNode.h"
|
||||
#include "YGNodePrint.h"
|
||||
#include "Yoga-internal.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <float.h>
|
||||
|
||||
@@ -511,16 +510,16 @@ void YGNodeCopyStyle(const YGNodeRef dstNode, const YGNodeRef srcNode) {
|
||||
}
|
||||
|
||||
float YGNodeStyleGetFlexGrow(const YGNodeRef node) {
|
||||
return node->getStyle().flexGrow.isUndefined
|
||||
return node->getStyle().flexGrow.isUndefined()
|
||||
? kDefaultFlexGrow
|
||||
: node->getStyle().flexGrow.value;
|
||||
: node->getStyle().flexGrow.getValue();
|
||||
}
|
||||
|
||||
float YGNodeStyleGetFlexShrink(const YGNodeRef node) {
|
||||
return node->getStyle().flexShrink.isUndefined
|
||||
return node->getStyle().flexShrink.isUndefined()
|
||||
? (node->getConfig()->useWebDefaults ? kWebDefaultFlexShrink
|
||||
: kDefaultFlexShrink)
|
||||
: node->getStyle().flexShrink.value;
|
||||
: node->getStyle().flexShrink.getValue();
|
||||
}
|
||||
|
||||
#define YG_NODE_STYLE_PROPERTY_SETTER_IMPL( \
|
||||
@@ -744,9 +743,9 @@ void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {
|
||||
if (!YGFloatOptionalFloatEquals(node->getStyle().flex, flex)) {
|
||||
YGStyle style = node->getStyle();
|
||||
if (YGFloatIsUndefined(flex)) {
|
||||
style.flex = {true, 0};
|
||||
style.flex = YGFloatOptional();
|
||||
} else {
|
||||
style.flex = {false, flex};
|
||||
style.flex = YGFloatOptional(flex);
|
||||
}
|
||||
node->setStyle(style);
|
||||
node->markDirtyAndPropogate();
|
||||
@@ -755,8 +754,8 @@ void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {
|
||||
|
||||
// TODO(T26792433): Change the API to accept YGFloatOptional.
|
||||
float YGNodeStyleGetFlex(const YGNodeRef node) {
|
||||
return node->getStyle().flex.isUndefined ? YGUndefined
|
||||
: node->getStyle().flex.value;
|
||||
return node->getStyle().flex.isUndefined() ? YGUndefined
|
||||
: node->getStyle().flex.getValue();
|
||||
}
|
||||
|
||||
// TODO(T26792433): Change the API to accept YGFloatOptional.
|
||||
@@ -764,9 +763,9 @@ void YGNodeStyleSetFlexGrow(const YGNodeRef node, const float flexGrow) {
|
||||
if (!YGFloatOptionalFloatEquals(node->getStyle().flexGrow, flexGrow)) {
|
||||
YGStyle style = node->getStyle();
|
||||
if (YGFloatIsUndefined(flexGrow)) {
|
||||
style.flexGrow = {true, 0};
|
||||
style.flexGrow = YGFloatOptional();
|
||||
} else {
|
||||
style.flexGrow = {false, flexGrow};
|
||||
style.flexGrow = YGFloatOptional(flexGrow);
|
||||
}
|
||||
node->setStyle(style);
|
||||
node->markDirtyAndPropogate();
|
||||
@@ -778,9 +777,9 @@ void YGNodeStyleSetFlexShrink(const YGNodeRef node, const float flexShrink) {
|
||||
if (!YGFloatOptionalFloatEquals(node->getStyle().flexShrink, flexShrink)) {
|
||||
YGStyle style = node->getStyle();
|
||||
if (YGFloatIsUndefined(flexShrink)) {
|
||||
style.flexShrink = {true, 0};
|
||||
style.flexShrink = YGFloatOptional();
|
||||
} else {
|
||||
style.flexShrink = {false, flexShrink};
|
||||
style.flexShrink = YGFloatOptional(flexShrink);
|
||||
}
|
||||
node->setStyle(style);
|
||||
node->markDirtyAndPropogate();
|
||||
@@ -1669,13 +1668,15 @@ static float YGNodeCalculateAvailableInnerDim(
|
||||
// We want to make sure our available height does not violate min and max
|
||||
// constraints
|
||||
const YGFloatOptional minDimensionOptional = YGResolveValue(node->getStyle().minDimensions[dimension], parentDim);
|
||||
const float minInnerDim = minDimensionOptional.isUndefined
|
||||
const float minInnerDim = minDimensionOptional.isUndefined()
|
||||
? 0.0f
|
||||
: minDimensionOptional.value - paddingAndBorder;
|
||||
: minDimensionOptional.getValue() - paddingAndBorder;
|
||||
|
||||
const YGFloatOptional maxDimensionOptional = YGResolveValue(node->getStyle().maxDimensions[dimension], parentDim) ;
|
||||
|
||||
const float maxInnerDim = maxDimensionOptional.isUndefined ? FLT_MAX : maxDimensionOptional.value - paddingAndBorder;
|
||||
const float maxInnerDim = maxDimensionOptional.isUndefined()
|
||||
? FLT_MAX
|
||||
: maxDimensionOptional.getValue() - paddingAndBorder;
|
||||
availableInnerDim =
|
||||
YGFloatMax(YGFloatMin(availableInnerDim, maxInnerDim), minInnerDim);
|
||||
}
|
||||
@@ -2207,7 +2208,8 @@ static void YGJustifyMainAxis(
|
||||
if (measureModeMainDim == YGMeasureModeAtMost &&
|
||||
collectedFlexItemsValues.remainingFreeSpace > 0) {
|
||||
if (style.minDimensions[dim[mainAxis]].unit != YGUnitUndefined &&
|
||||
!YGResolveValue(style.minDimensions[dim[mainAxis]], mainAxisParentSize).isUndefined) {
|
||||
!YGResolveValue(style.minDimensions[dim[mainAxis]], mainAxisParentSize)
|
||||
.isUndefined()) {
|
||||
collectedFlexItemsValues.remainingFreeSpace = YGFloatMax(
|
||||
0,
|
||||
YGUnwrapFloatOptional(YGResolveValue(
|
||||
@@ -3713,8 +3715,8 @@ void YGNodeCalculateLayout(
|
||||
node->getMarginForAxis(YGFlexDirectionRow, parentWidth);
|
||||
widthMeasureMode = YGMeasureModeExactly;
|
||||
} else if (!YGResolveValue(
|
||||
node->getStyle().maxDimensions[YGDimensionWidth],
|
||||
parentWidth).isUndefined) {
|
||||
node->getStyle().maxDimensions[YGDimensionWidth], parentWidth)
|
||||
.isUndefined()) {
|
||||
width = YGUnwrapFloatOptional(YGResolveValue(
|
||||
node->getStyle().maxDimensions[YGDimensionWidth], parentWidth));
|
||||
widthMeasureMode = YGMeasureModeAtMost;
|
||||
@@ -3732,8 +3734,10 @@ void YGNodeCalculateLayout(
|
||||
parentHeight)) +
|
||||
node->getMarginForAxis(YGFlexDirectionColumn, parentWidth);
|
||||
heightMeasureMode = YGMeasureModeExactly;
|
||||
} else if (!YGResolveValue(node->getStyle().maxDimensions[YGDimensionHeight],
|
||||
parentHeight).isUndefined) {
|
||||
} else if (!YGResolveValue(
|
||||
node->getStyle().maxDimensions[YGDimensionHeight],
|
||||
parentHeight)
|
||||
.isUndefined()) {
|
||||
height = YGUnwrapFloatOptional(YGResolveValue(node->getStyle().maxDimensions[YGDimensionHeight], parentHeight));
|
||||
heightMeasureMode = YGMeasureModeAtMost;
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user