Changed the type of computedFlexBasis to YGFloatOptional in YGLayout
Summary: Changed the type of computedFlexBasis to YGFloatOptional in YGLayout Reviewed By: emilsjolander Differential Revision: D7340413 fbshipit-source-id: 39247b2b582a682e602f49f58b4bbd2bf0c995af
This commit is contained in:
committed by
Facebook Github Bot
parent
77b720f9a5
commit
5b109578d3
@@ -5,14 +5,16 @@
|
|||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
struct YGFloatOptional {
|
struct YGFloatOptional {
|
||||||
private:
|
private:
|
||||||
float value_;
|
float value_;
|
||||||
bool isUndefined_;
|
bool isUndefined_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
YGFloatOptional(const float& value);
|
explicit YGFloatOptional(const float& value);
|
||||||
YGFloatOptional();
|
explicit YGFloatOptional();
|
||||||
|
|
||||||
// Program will terminate if the value of an undefined is accessed. Please
|
// Program will terminate if the value of an undefined is accessed. Please
|
||||||
// make sure to check if the optional is defined before calling this function.
|
// make sure to check if the optional is defined before calling this function.
|
||||||
|
@@ -19,7 +19,7 @@ YGLayout::YGLayout()
|
|||||||
padding(),
|
padding(),
|
||||||
direction(YGDirectionInherit),
|
direction(YGDirectionInherit),
|
||||||
computedFlexBasisGeneration(0),
|
computedFlexBasisGeneration(0),
|
||||||
computedFlexBasis(YGUndefined),
|
computedFlexBasis(YGFloatOptional()),
|
||||||
hadOverflow(false),
|
hadOverflow(false),
|
||||||
generationCount(0),
|
generationCount(0),
|
||||||
lastOwnerDirection((YGDirection)-1),
|
lastOwnerDirection((YGDirection)-1),
|
||||||
@@ -39,16 +39,13 @@ bool YGLayout::operator==(YGLayout layout) const {
|
|||||||
direction == layout.direction && hadOverflow == layout.hadOverflow &&
|
direction == layout.direction && hadOverflow == layout.hadOverflow &&
|
||||||
lastOwnerDirection == layout.lastOwnerDirection &&
|
lastOwnerDirection == layout.lastOwnerDirection &&
|
||||||
nextCachedMeasurementsIndex == layout.nextCachedMeasurementsIndex &&
|
nextCachedMeasurementsIndex == layout.nextCachedMeasurementsIndex &&
|
||||||
cachedLayout == layout.cachedLayout;
|
cachedLayout == layout.cachedLayout &&
|
||||||
|
computedFlexBasis == layout.computedFlexBasis;
|
||||||
|
|
||||||
for (uint32_t i = 0; i < YG_MAX_CACHED_RESULT_COUNT && isEqual; ++i) {
|
for (uint32_t i = 0; i < YG_MAX_CACHED_RESULT_COUNT && isEqual; ++i) {
|
||||||
isEqual = isEqual && cachedMeasurements[i] == layout.cachedMeasurements[i];
|
isEqual = isEqual && cachedMeasurements[i] == layout.cachedMeasurements[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!YGFloatIsUndefined(computedFlexBasis) ||
|
|
||||||
!YGFloatIsUndefined(layout.computedFlexBasis)) {
|
|
||||||
isEqual = isEqual && (computedFlexBasis == layout.computedFlexBasis);
|
|
||||||
}
|
|
||||||
if (!YGFloatIsUndefined(measuredDimensions[0]) ||
|
if (!YGFloatIsUndefined(measuredDimensions[0]) ||
|
||||||
!YGFloatIsUndefined(layout.measuredDimensions[0])) {
|
!YGFloatIsUndefined(layout.measuredDimensions[0])) {
|
||||||
isEqual =
|
isEqual =
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "YGFloatOptional.h"
|
||||||
#include "Yoga-internal.h"
|
#include "Yoga-internal.h"
|
||||||
|
|
||||||
struct YGLayout {
|
struct YGLayout {
|
||||||
@@ -17,7 +18,7 @@ struct YGLayout {
|
|||||||
YGDirection direction;
|
YGDirection direction;
|
||||||
|
|
||||||
uint32_t computedFlexBasisGeneration;
|
uint32_t computedFlexBasisGeneration;
|
||||||
float computedFlexBasis;
|
YGFloatOptional computedFlexBasis;
|
||||||
bool hadOverflow;
|
bool hadOverflow;
|
||||||
|
|
||||||
// Instead of recomputing the entire layout every single time, we
|
// Instead of recomputing the entire layout every single time, we
|
||||||
|
@@ -312,7 +312,8 @@ void YGNode::setLayoutLastOwnerDirection(YGDirection direction) {
|
|||||||
layout_.lastOwnerDirection = direction;
|
layout_.lastOwnerDirection = direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGNode::setLayoutComputedFlexBasis(float computedFlexBasis) {
|
void YGNode::setLayoutComputedFlexBasis(
|
||||||
|
const YGFloatOptional& computedFlexBasis) {
|
||||||
layout_.computedFlexBasis = computedFlexBasis;
|
layout_.computedFlexBasis = computedFlexBasis;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -579,7 +580,7 @@ void YGNode::cloneChildrenIfNeeded() {
|
|||||||
void YGNode::markDirtyAndPropogate() {
|
void YGNode::markDirtyAndPropogate() {
|
||||||
if (!isDirty_) {
|
if (!isDirty_) {
|
||||||
setDirty(true);
|
setDirty(true);
|
||||||
setLayoutComputedFlexBasis(YGUndefined);
|
setLayoutComputedFlexBasis(YGFloatOptional());
|
||||||
if (owner_) {
|
if (owner_) {
|
||||||
owner_->markDirtyAndPropogate();
|
owner_->markDirtyAndPropogate();
|
||||||
}
|
}
|
||||||
|
@@ -126,7 +126,7 @@ struct YGNode {
|
|||||||
void setConfig(YGConfigRef config);
|
void setConfig(YGConfigRef config);
|
||||||
void setDirty(bool isDirty);
|
void setDirty(bool isDirty);
|
||||||
void setLayoutLastOwnerDirection(YGDirection direction);
|
void setLayoutLastOwnerDirection(YGDirection direction);
|
||||||
void setLayoutComputedFlexBasis(float computedFlexBasis);
|
void setLayoutComputedFlexBasis(const YGFloatOptional& computedFlexBasis);
|
||||||
void setLayoutComputedFlexBasisGeneration(
|
void setLayoutComputedFlexBasisGeneration(
|
||||||
uint32_t computedFlexBasisGeneration);
|
uint32_t computedFlexBasisGeneration);
|
||||||
void setLayoutMeasuredDimension(float measuredDimension, int index);
|
void setLayoutMeasuredDimension(float measuredDimension, int index);
|
||||||
|
@@ -1220,35 +1220,41 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node,
|
|||||||
YGMeasureMode childWidthMeasureMode;
|
YGMeasureMode childWidthMeasureMode;
|
||||||
YGMeasureMode childHeightMeasureMode;
|
YGMeasureMode childHeightMeasureMode;
|
||||||
|
|
||||||
const float resolvedFlexBasis =
|
const YGFloatOptional resolvedFlexBasis =
|
||||||
YGUnwrapFloatOptional(YGResolveValue(child->resolveFlexBasisPtr(), mainAxisownerSize));
|
YGResolveValue(child->resolveFlexBasisPtr(), mainAxisownerSize);
|
||||||
const bool isRowStyleDimDefined = YGNodeIsStyleDimDefined(child, YGFlexDirectionRow, ownerWidth);
|
const bool isRowStyleDimDefined = YGNodeIsStyleDimDefined(child, YGFlexDirectionRow, ownerWidth);
|
||||||
const bool isColumnStyleDimDefined =
|
const bool isColumnStyleDimDefined =
|
||||||
YGNodeIsStyleDimDefined(child, YGFlexDirectionColumn, ownerHeight);
|
YGNodeIsStyleDimDefined(child, YGFlexDirectionColumn, ownerHeight);
|
||||||
|
|
||||||
if (!YGFloatIsUndefined(resolvedFlexBasis) && !YGFloatIsUndefined(mainAxisSize)) {
|
if (!resolvedFlexBasis.isUndefined() && !YGFloatIsUndefined(mainAxisSize)) {
|
||||||
if (YGFloatIsUndefined(child->getLayout().computedFlexBasis) ||
|
if (child->getLayout().computedFlexBasis.isUndefined() ||
|
||||||
(YGConfigIsExperimentalFeatureEnabled(
|
(YGConfigIsExperimentalFeatureEnabled(
|
||||||
child->getConfig(), YGExperimentalFeatureWebFlexBasis) &&
|
child->getConfig(), YGExperimentalFeatureWebFlexBasis) &&
|
||||||
child->getLayout().computedFlexBasisGeneration !=
|
child->getLayout().computedFlexBasisGeneration !=
|
||||||
gCurrentGenerationCount)) {
|
gCurrentGenerationCount)) {
|
||||||
child->setLayoutComputedFlexBasis(YGFloatMax(
|
const YGFloatOptional& paddingAndBorder = YGFloatOptional(
|
||||||
resolvedFlexBasis,
|
YGNodePaddingAndBorderForAxis(child, mainAxis, ownerWidth));
|
||||||
YGNodePaddingAndBorderForAxis(child, mainAxis, ownerWidth)));
|
child->setLayoutComputedFlexBasis(
|
||||||
|
YGFloatOptionalMax(resolvedFlexBasis, paddingAndBorder));
|
||||||
}
|
}
|
||||||
} else if (isMainAxisRow && isRowStyleDimDefined) {
|
} else if (isMainAxisRow && isRowStyleDimDefined) {
|
||||||
// The width is definite, so use that as the flex basis.
|
// The width is definite, so use that as the flex basis.
|
||||||
child->setLayoutComputedFlexBasis(YGFloatMax(
|
const YGFloatOptional& paddingAndBorder = YGFloatOptional(
|
||||||
YGUnwrapFloatOptional(YGResolveValue(
|
YGNodePaddingAndBorderForAxis(child, YGFlexDirectionRow, ownerWidth));
|
||||||
child->getResolvedDimension(YGDimensionWidth), ownerWidth)),
|
|
||||||
YGNodePaddingAndBorderForAxis(child, YGFlexDirectionRow, ownerWidth)));
|
child->setLayoutComputedFlexBasis(YGFloatOptionalMax(
|
||||||
|
YGResolveValue(
|
||||||
|
child->getResolvedDimension(YGDimensionWidth), ownerWidth),
|
||||||
|
paddingAndBorder));
|
||||||
} else if (!isMainAxisRow && isColumnStyleDimDefined) {
|
} else if (!isMainAxisRow && isColumnStyleDimDefined) {
|
||||||
// The height is definite, so use that as the flex basis.
|
// The height is definite, so use that as the flex basis.
|
||||||
child->setLayoutComputedFlexBasis(YGFloatMax(
|
const YGFloatOptional& paddingAndBorder =
|
||||||
YGUnwrapFloatOptional(YGResolveValue(
|
YGFloatOptional(YGNodePaddingAndBorderForAxis(
|
||||||
child->getResolvedDimension(YGDimensionHeight), ownerHeight)),
|
child, YGFlexDirectionColumn, ownerWidth));
|
||||||
YGNodePaddingAndBorderForAxis(
|
child->setLayoutComputedFlexBasis(YGFloatOptionalMax(
|
||||||
child, YGFlexDirectionColumn, ownerWidth)));
|
YGResolveValue(
|
||||||
|
child->getResolvedDimension(YGDimensionHeight), ownerHeight),
|
||||||
|
paddingAndBorder));
|
||||||
} else {
|
} else {
|
||||||
// Compute the flex basis and hypothetical main size (i.e. the clamped
|
// Compute the flex basis and hypothetical main size (i.e. the clamped
|
||||||
// flex basis).
|
// flex basis).
|
||||||
@@ -1361,9 +1367,9 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node,
|
|||||||
"measure",
|
"measure",
|
||||||
config);
|
config);
|
||||||
|
|
||||||
child->setLayoutComputedFlexBasis(YGFloatMax(
|
child->setLayoutComputedFlexBasis(YGFloatOptional(YGFloatMax(
|
||||||
child->getLayout().measuredDimensions[dim[mainAxis]],
|
child->getLayout().measuredDimensions[dim[mainAxis]],
|
||||||
YGNodePaddingAndBorderForAxis(child, mainAxis, ownerWidth)));
|
YGNodePaddingAndBorderForAxis(child, mainAxis, ownerWidth))));
|
||||||
}
|
}
|
||||||
child->setLayoutComputedFlexBasisGeneration(gCurrentGenerationCount);
|
child->setLayoutComputedFlexBasisGeneration(gCurrentGenerationCount);
|
||||||
}
|
}
|
||||||
@@ -1825,7 +1831,7 @@ static void YGNodeComputeFlexBasisForChildren(
|
|||||||
}
|
}
|
||||||
if (child == singleFlexChild) {
|
if (child == singleFlexChild) {
|
||||||
child->setLayoutComputedFlexBasisGeneration(gCurrentGenerationCount);
|
child->setLayoutComputedFlexBasisGeneration(gCurrentGenerationCount);
|
||||||
child->setLayoutComputedFlexBasis(0);
|
child->setLayoutComputedFlexBasis(YGFloatOptional(0));
|
||||||
} else {
|
} else {
|
||||||
YGNodeComputeFlexBasisForChild(
|
YGNodeComputeFlexBasisForChild(
|
||||||
node,
|
node,
|
||||||
@@ -1840,7 +1846,8 @@ static void YGNodeComputeFlexBasisForChildren(
|
|||||||
config);
|
config);
|
||||||
}
|
}
|
||||||
|
|
||||||
totalOuterFlexBasis += child->getLayout().computedFlexBasis +
|
totalOuterFlexBasis +=
|
||||||
|
YGUnwrapFloatOptional(child->getLayout().computedFlexBasis) +
|
||||||
child->getMarginForAxis(mainAxis, availableInnerWidth);
|
child->getMarginForAxis(mainAxis, availableInnerWidth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1880,7 +1887,7 @@ static YGCollectFlexItemsRowValues YGCalculateCollectFlexItemsRowValues(
|
|||||||
YGUnwrapFloatOptional(YGNodeBoundAxisWithinMinAndMax(
|
YGUnwrapFloatOptional(YGNodeBoundAxisWithinMinAndMax(
|
||||||
child,
|
child,
|
||||||
mainAxis,
|
mainAxis,
|
||||||
child->getLayout().computedFlexBasis,
|
YGUnwrapFloatOptional(child->getLayout().computedFlexBasis),
|
||||||
mainAxisownerSize));
|
mainAxisownerSize));
|
||||||
|
|
||||||
// If this is a multi-line flow and this item pushes us over the
|
// If this is a multi-line flow and this item pushes us over the
|
||||||
@@ -1906,7 +1913,8 @@ static YGCollectFlexItemsRowValues YGCalculateCollectFlexItemsRowValues(
|
|||||||
// 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 dimension.
|
// child dimension.
|
||||||
flexAlgoRowMeasurement.totalFlexShrinkScaledFactors +=
|
flexAlgoRowMeasurement.totalFlexShrinkScaledFactors +=
|
||||||
-child->resolveFlexShrink() * child->getLayout().computedFlexBasis;
|
-child->resolveFlexShrink() *
|
||||||
|
YGUnwrapFloatOptional(child->getLayout().computedFlexBasis);
|
||||||
}
|
}
|
||||||
|
|
||||||
flexAlgoRowMeasurement.relativeChildren.push_back(child);
|
flexAlgoRowMeasurement.relativeChildren.push_back(child);
|
||||||
@@ -1956,7 +1964,8 @@ static float YGDistributeFreeSpaceSecondPass(
|
|||||||
childFlexBasis = YGUnwrapFloatOptional(YGNodeBoundAxisWithinMinAndMax(
|
childFlexBasis = YGUnwrapFloatOptional(YGNodeBoundAxisWithinMinAndMax(
|
||||||
currentRelativeChild,
|
currentRelativeChild,
|
||||||
mainAxis,
|
mainAxis,
|
||||||
currentRelativeChild->getLayout().computedFlexBasis,
|
YGUnwrapFloatOptional(
|
||||||
|
currentRelativeChild->getLayout().computedFlexBasis),
|
||||||
mainAxisownerSize));
|
mainAxisownerSize));
|
||||||
float updatedMainSize = childFlexBasis;
|
float updatedMainSize = childFlexBasis;
|
||||||
|
|
||||||
@@ -2131,7 +2140,8 @@ static void YGDistributeFreeSpaceFirstPass(
|
|||||||
float childFlexBasis = YGUnwrapFloatOptional(YGNodeBoundAxisWithinMinAndMax(
|
float childFlexBasis = YGUnwrapFloatOptional(YGNodeBoundAxisWithinMinAndMax(
|
||||||
currentRelativeChild,
|
currentRelativeChild,
|
||||||
mainAxis,
|
mainAxis,
|
||||||
currentRelativeChild->getLayout().computedFlexBasis,
|
YGUnwrapFloatOptional(
|
||||||
|
currentRelativeChild->getLayout().computedFlexBasis),
|
||||||
mainAxisownerSize));
|
mainAxisownerSize));
|
||||||
|
|
||||||
if (collectedFlexItemsValues.remainingFreeSpace < 0) {
|
if (collectedFlexItemsValues.remainingFreeSpace < 0) {
|
||||||
@@ -2417,7 +2427,7 @@ static void YGJustifyMainAxis(
|
|||||||
// YGNodeDimWithMargin.
|
// YGNodeDimWithMargin.
|
||||||
collectedFlexItemsValues.mainDim += betweenMainDim +
|
collectedFlexItemsValues.mainDim += betweenMainDim +
|
||||||
child->getMarginForAxis(mainAxis, availableInnerWidth) +
|
child->getMarginForAxis(mainAxis, availableInnerWidth) +
|
||||||
childLayout.computedFlexBasis;
|
YGUnwrapFloatOptional(childLayout.computedFlexBasis);
|
||||||
collectedFlexItemsValues.crossDim = availableInnerCrossDim;
|
collectedFlexItemsValues.crossDim = availableInnerCrossDim;
|
||||||
} else {
|
} else {
|
||||||
// The main dimension is the sum of all the elements dimension plus
|
// The main dimension is the sum of all the elements dimension plus
|
||||||
|
Reference in New Issue
Block a user