Add constructor in YGLayout

Reviewed By: emilsjolander

Differential Revision: D7019653

fbshipit-source-id: 5a2655626db0915fcebe7d4517e2d0b2e2484460
This commit is contained in:
Pritesh Nandgaonkar 2018-02-20 05:41:50 -08:00 committed by Facebook Github Bot
parent b9991d33e3
commit c75ce8146f
7 changed files with 150 additions and 108 deletions

View File

@ -952,6 +952,10 @@
3DFE0D1C1DF8575800459392 /* Yoga.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 130A77081DF767AF001F9587 /* Yoga.h */; };
3EDCA8A51D3591E700450C31 /* RCTErrorInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 3EDCA8A41D3591E700450C31 /* RCTErrorInfo.m */; };
5335D5411FE81A4700883D58 /* RCTShadowView.m in Sources */ = {isa = PBXBuildFile; fileRef = 5335D5401FE81A4700883D58 /* RCTShadowView.m */; };
53438962203905BB008E0CB3 /* YGLayout.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5343895E203905B6008E0CB3 /* YGLayout.cpp */; };
53438963203905BC008E0CB3 /* YGLayout.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5343895E203905B6008E0CB3 /* YGLayout.cpp */; };
53438964203905BF008E0CB3 /* YGLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 5343895F203905B6008E0CB3 /* YGLayout.h */; };
53438965203905C0008E0CB3 /* YGLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 5343895F203905B6008E0CB3 /* YGLayout.h */; };
5352C5752038FF9500A3B97E /* YGStyle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5352C5722038FF8D00A3B97E /* YGStyle.cpp */; };
5352C5762038FF9700A3B97E /* YGStyle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5352C5722038FF8D00A3B97E /* YGStyle.cpp */; };
5352C5772038FF9A00A3B97E /* YGStyle.h in Headers */ = {isa = PBXBuildFile; fileRef = 5352C5712038FF8D00A3B97E /* YGStyle.h */; };
@ -2148,6 +2152,8 @@
3EDCA8A31D3591E700450C31 /* RCTErrorInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTErrorInfo.h; sourceTree = "<group>"; };
3EDCA8A41D3591E700450C31 /* RCTErrorInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTErrorInfo.m; sourceTree = "<group>"; };
5335D5401FE81A4700883D58 /* RCTShadowView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTShadowView.m; sourceTree = "<group>"; };
5343895E203905B6008E0CB3 /* YGLayout.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = YGLayout.cpp; sourceTree = "<group>"; };
5343895F203905B6008E0CB3 /* YGLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGLayout.h; sourceTree = "<group>"; };
5352C5712038FF8D00A3B97E /* YGStyle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGStyle.h; sourceTree = "<group>"; };
5352C5722038FF8D00A3B97E /* YGStyle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = YGStyle.cpp; sourceTree = "<group>"; };
53756E372004FFF700FBBD99 /* Utils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Utils.cpp; sourceTree = "<group>"; };
@ -2338,6 +2344,8 @@
130A77021DF767AF001F9587 /* yoga */ = {
isa = PBXGroup;
children = (
5343895E203905B6008E0CB3 /* YGLayout.cpp */,
5343895F203905B6008E0CB3 /* YGLayout.h */,
5352C5722038FF8D00A3B97E /* YGStyle.cpp */,
5352C5712038FF8D00A3B97E /* YGStyle.h */,
53756E372004FFF700FBBD99 /* Utils.cpp */,
@ -3284,6 +3292,7 @@
53756E3D2004FFFE00FBBD99 /* Utils.h in Headers */,
5376C5E71FC6DDC20083513D /* YGNodePrint.h in Headers */,
3DFE0D191DF8574D00459392 /* Yoga.h in Headers */,
53438965203905C0008E0CB3 /* YGLayout.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -3363,6 +3372,7 @@
53756E3C2004FFFC00FBBD99 /* Utils.h in Headers */,
5376C5E61FC6DDC10083513D /* YGNodePrint.h in Headers */,
133957891DF76D3500EC27BE /* YGMacros.h in Headers */,
53438964203905BF008E0CB3 /* YGLayout.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -4306,6 +4316,7 @@
53EC85E21FDEC75F0051B2B5 /* YGNode.cpp in Sources */,
53D1239A1FBF1EF2001B8A10 /* YGEnums.cpp in Sources */,
53756E3B2004FFFA00FBBD99 /* Utils.cpp in Sources */,
53438962203905BB008E0CB3 /* YGLayout.cpp in Sources */,
5376C5E41FC6DDBC0083513D /* YGNodePrint.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@ -4319,6 +4330,7 @@
53EC85E31FDEC75F0051B2B5 /* YGNode.cpp in Sources */,
53D1239B1FBF1EF4001B8A10 /* YGEnums.cpp in Sources */,
53756E3E2005000300FBBD99 /* Utils.cpp in Sources */,
53438963203905BC008E0CB3 /* YGLayout.cpp in Sources */,
5376C5E51FC6DDBD0083513D /* YGNodePrint.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

View File

@ -0,0 +1,73 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include "YGLayout.h"
const std::array<float, 2> kYGDefaultDimensionValues = {
{YGUndefined, YGUndefined}};
YGLayout::YGLayout()
: position(),
dimensions(kYGDefaultDimensionValues),
margin(),
border(),
padding(),
direction(YGDirectionInherit),
computedFlexBasisGeneration(0),
computedFlexBasis(YGUndefined),
hadOverflow(false),
generationCount(0),
lastParentDirection((YGDirection)-1),
nextCachedMeasurementsIndex(0),
cachedMeasurements(),
measuredDimensions(kYGDefaultDimensionValues),
cachedLayout({
.availableWidth = 0,
.availableHeight = 0,
.widthMeasureMode = (YGMeasureMode)-1,
.heightMeasureMode = (YGMeasureMode)-1,
.computedWidth = -1,
.computedHeight = -1,
}),
didUseLegacyFlag(false),
doesLegacyStretchFlagAffectsLayout(false) {}
bool YGLayout::operator==(YGLayout layout) const {
bool isEqual = position == layout.position &&
dimensions == layout.dimensions && margin == layout.margin &&
border == layout.border && padding == layout.padding &&
direction == layout.direction && hadOverflow == layout.hadOverflow &&
lastParentDirection == layout.lastParentDirection &&
nextCachedMeasurementsIndex == layout.nextCachedMeasurementsIndex &&
cachedLayout == layout.cachedLayout;
for (uint32_t i = 0; i < YG_MAX_CACHED_RESULT_COUNT && isEqual; ++i) {
isEqual = isEqual && cachedMeasurements[i] == layout.cachedMeasurements[i];
}
if (!YGFloatIsUndefined(computedFlexBasis) ||
!YGFloatIsUndefined(layout.computedFlexBasis)) {
isEqual = isEqual && (computedFlexBasis == layout.computedFlexBasis);
}
if (!YGFloatIsUndefined(measuredDimensions[0]) ||
!YGFloatIsUndefined(layout.measuredDimensions[0])) {
isEqual =
isEqual && (measuredDimensions[0] == layout.measuredDimensions[0]);
}
if (!YGFloatIsUndefined(measuredDimensions[1]) ||
!YGFloatIsUndefined(layout.measuredDimensions[1])) {
isEqual =
isEqual && (measuredDimensions[1] == layout.measuredDimensions[1]);
}
return isEqual;
}
bool YGLayout::operator!=(YGLayout layout) const {
return !(*this == layout);
}

View File

@ -0,0 +1,42 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#pragma once
#include "Yoga-internal.h"
struct YGLayout {
std::array<float, 4> position;
std::array<float, 2> dimensions;
std::array<float, 6> margin;
std::array<float, 6> border;
std::array<float, 6> padding;
YGDirection direction;
uint32_t computedFlexBasisGeneration;
float computedFlexBasis;
bool hadOverflow;
// Instead of recomputing the entire layout every single time, we
// cache some information to break early when nothing changed
uint32_t generationCount;
YGDirection lastParentDirection;
uint32_t nextCachedMeasurementsIndex;
std::array<YGCachedMeasurement, YG_MAX_CACHED_RESULT_COUNT>
cachedMeasurements;
std::array<float, 2> measuredDimensions;
YGCachedMeasurement cachedLayout;
bool didUseLegacyFlag;
bool doesLegacyStretchFlagAffectsLayout;
YGLayout();
bool operator==(YGLayout layout) const;
bool operator!=(YGLayout layout) const;
};

View File

@ -383,7 +383,7 @@ YGNode::YGNode()
baseline_(nullptr),
dirtied_(nullptr),
style_(YGStyle()),
layout_(gYGNodeLayoutDefaults),
layout_(YGLayout()),
lineIndex_(0),
parent_(nullptr),
children_(YGVector()),

View File

@ -7,6 +7,7 @@
#pragma once
#include <stdio.h>
#include "YGLayout.h"
#include "YGStyle.h"
#include "Yoga-internal.h"

View File

@ -8,6 +8,27 @@
*/
#include "YGStyle.h"
const YGValue kYGValueUndefined = {YGUndefined, YGUnitUndefined};
const YGValue kYGValueAuto = {YGUndefined, YGUnitAuto};
const std::array<YGValue, YGEdgeCount> kYGDefaultEdgeValuesUnit = {
{kYGValueUndefined,
kYGValueUndefined,
kYGValueUndefined,
kYGValueUndefined,
kYGValueUndefined,
kYGValueUndefined,
kYGValueUndefined,
kYGValueUndefined,
kYGValueUndefined}};
const std::array<YGValue, 2> kYGDefaultDimensionValuesAutoUnit = {
{kYGValueAuto, kYGValueAuto}};
const std::array<YGValue, 2> kYGDefaultDimensionValuesUnit = {
{kYGValueUndefined, kYGValueUndefined}};
YGStyle::YGStyle()
: direction(YGDirectionInherit),
flexDirection(YGFlexDirectionColumn),

View File

@ -41,23 +41,6 @@ bool YGValueArrayEqual(
return areEqual;
}
const YGValue kYGValueUndefined = {YGUndefined, YGUnitUndefined};
const YGValue kYGValueAuto = {YGUndefined, YGUnitAuto};
const std::array<YGValue, YGEdgeCount> kYGDefaultEdgeValuesUnit = {
{kYGValueUndefined,
kYGValueUndefined,
kYGValueUndefined,
kYGValueUndefined,
kYGValueUndefined,
kYGValueUndefined,
kYGValueUndefined,
kYGValueUndefined,
kYGValueUndefined}};
const std::array<YGValue, 2> kYGDefaultDimensionValuesAutoUnit = {
{kYGValueAuto, kYGValueAuto}};
const std::array<YGValue, 2> kYGDefaultDimensionValuesUnit = {
{kYGValueUndefined, kYGValueUndefined}};
struct YGCachedMeasurement {
float availableWidth;
float availableHeight;
@ -95,68 +78,6 @@ struct YGCachedMeasurement {
// layouts should not require more than 16 entries to fit within the cache.
#define YG_MAX_CACHED_RESULT_COUNT 16
struct YGLayout {
std::array<float, 4> position;
std::array<float, 2> dimensions;
std::array<float, 6> margin;
std::array<float, 6> border;
std::array<float, 6> padding;
YGDirection direction;
uint32_t computedFlexBasisGeneration;
float computedFlexBasis;
bool hadOverflow;
// Instead of recomputing the entire layout every single time, we
// cache some information to break early when nothing changed
uint32_t generationCount;
YGDirection lastParentDirection;
uint32_t nextCachedMeasurementsIndex;
YGCachedMeasurement cachedMeasurements[YG_MAX_CACHED_RESULT_COUNT];
std::array<float, 2> measuredDimensions;
YGCachedMeasurement cachedLayout;
bool didUseLegacyFlag;
bool doesLegacyStretchFlagAffectsLayout;
bool operator==(YGLayout layout) const {
bool isEqual = position == layout.position &&
dimensions == layout.dimensions && margin == layout.margin &&
border == layout.border && padding == layout.padding &&
direction == layout.direction && hadOverflow == layout.hadOverflow &&
lastParentDirection == layout.lastParentDirection &&
nextCachedMeasurementsIndex == layout.nextCachedMeasurementsIndex &&
cachedLayout == layout.cachedLayout;
for (uint32_t i = 0; i < YG_MAX_CACHED_RESULT_COUNT && isEqual; ++i) {
isEqual =
isEqual && cachedMeasurements[i] == layout.cachedMeasurements[i];
}
if (!YGFloatIsUndefined(computedFlexBasis) ||
!YGFloatIsUndefined(layout.computedFlexBasis)) {
isEqual = isEqual && (computedFlexBasis == layout.computedFlexBasis);
}
if (!YGFloatIsUndefined(measuredDimensions[0]) ||
!YGFloatIsUndefined(layout.measuredDimensions[0])) {
isEqual =
isEqual && (measuredDimensions[0] == layout.measuredDimensions[0]);
}
if (!YGFloatIsUndefined(measuredDimensions[1]) ||
!YGFloatIsUndefined(layout.measuredDimensions[1])) {
isEqual =
isEqual && (measuredDimensions[1] == layout.measuredDimensions[1]);
}
return isEqual;
}
bool operator!=(YGLayout layout) const {
return !(*this == layout);
}
};
struct YGConfig {
bool experimentalFeatures[YGExperimentalFeatureCount + 1];
bool useWebDefaults;
@ -172,34 +93,6 @@ static const float kDefaultFlexGrow = 0.0f;
static const float kDefaultFlexShrink = 0.0f;
static const float kWebDefaultFlexShrink = 1.0f;
static const YGLayout gYGNodeLayoutDefaults = {
.position = {},
.dimensions = {{YGUndefined, YGUndefined}},
.margin = {},
.border = {},
.padding = {},
.direction = YGDirectionInherit,
.computedFlexBasisGeneration = 0,
.computedFlexBasis = YGUndefined,
.hadOverflow = false,
.generationCount = 0,
.lastParentDirection = (YGDirection)-1,
.nextCachedMeasurementsIndex = 0,
.cachedMeasurements = {},
.measuredDimensions = {{YGUndefined, YGUndefined}},
.cachedLayout =
{
.availableWidth = 0,
.availableHeight = 0,
.widthMeasureMode = (YGMeasureMode)-1,
.heightMeasureMode = (YGMeasureMode)-1,
.computedWidth = -1,
.computedHeight = -1,
},
.didUseLegacyFlag = false,
.doesLegacyStretchFlagAffectsLayout = false,
};
extern bool YGFloatsEqual(const float a, const float b);
extern bool YGValueEqual(const YGValue a, const YGValue b);
extern const YGValue* YGComputedEdgeValue(