Change c files to cpp
Summary: Changed the extensions of c files to cpp and made the project build successfully Reviewed By: gkassabli Differential Revision: D6271299 fbshipit-source-id: 66c0e54ccf019d72d1fd0b4d117826e4e84fdc89
This commit is contained in:
committed by
Facebook Github Bot
parent
15231c3304
commit
02c00f2711
6
BUCK
6
BUCK
@@ -13,14 +13,14 @@ GMOCK_OVERRIDE_FLAGS = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
COMPILER_FLAGS = LIBRARY_COMPILER_FLAGS + [
|
COMPILER_FLAGS = LIBRARY_COMPILER_FLAGS + [
|
||||||
"-std=c11",
|
"-std=c++1y",
|
||||||
]
|
]
|
||||||
|
|
||||||
TEST_COMPILER_FLAGS = BASE_COMPILER_FLAGS + GMOCK_OVERRIDE_FLAGS + ["-std=c++11"]
|
TEST_COMPILER_FLAGS = BASE_COMPILER_FLAGS + GMOCK_OVERRIDE_FLAGS + ["-std=c++1y"]
|
||||||
|
|
||||||
cxx_library(
|
cxx_library(
|
||||||
name = "yoga",
|
name = "yoga",
|
||||||
srcs = glob(["yoga/*.c"]),
|
srcs = glob(["yoga/*.cpp"]),
|
||||||
header_namespace = "",
|
header_namespace = "",
|
||||||
exported_headers = subdir_glob([("", "yoga/*.h")]),
|
exported_headers = subdir_glob([("", "yoga/*.h")]),
|
||||||
compiler_flags = COMPILER_FLAGS,
|
compiler_flags = COMPILER_FLAGS,
|
||||||
|
@@ -21,8 +21,8 @@ Pod::Spec.new do |spec|
|
|||||||
'-fexceptions',
|
'-fexceptions',
|
||||||
'-Wall',
|
'-Wall',
|
||||||
'-Werror',
|
'-Werror',
|
||||||
'-std=c11',
|
'-std=c++1y',
|
||||||
'-fPIC'
|
'-fPIC'
|
||||||
]
|
]
|
||||||
spec.source_files = 'yoga/**/*.{c,h}'
|
spec.source_files = 'yoga/**/*.{c,h,cpp}'
|
||||||
end
|
end
|
||||||
|
2
enums.py
2
enums.py
@@ -161,7 +161,7 @@ with open(root + '/yoga/YGEnums.h', 'w') as f:
|
|||||||
f.write('YG_EXTERN_C_END\n')
|
f.write('YG_EXTERN_C_END\n')
|
||||||
|
|
||||||
# write out C body for printing
|
# write out C body for printing
|
||||||
with open(root + '/yoga/YGEnums.c', 'w') as f:
|
with open(root + '/yoga/YGEnums.cpp', 'w') as f:
|
||||||
f.write(LICENSE)
|
f.write(LICENSE)
|
||||||
f.write('#include "YGEnums.h"\n\n')
|
f.write('#include "YGEnums.h"\n\n')
|
||||||
for name, values in sorted(ENUMS.items()):
|
for name, values in sorted(ENUMS.items()):
|
||||||
|
@@ -7,8 +7,8 @@
|
|||||||
],
|
],
|
||||||
|
|
||||||
"sources": [
|
"sources": [
|
||||||
"sources/yoga/YGNodeList.c",
|
"sources/yoga/YGNodeList.cpp",
|
||||||
"sources/yoga/Yoga.c",
|
"sources/yoga/Yoga.cpp",
|
||||||
"sources/Config.cc",
|
"sources/Config.cc",
|
||||||
"sources/Node.cc",
|
"sources/Node.cc",
|
||||||
"sources/global.cc",
|
"sources/global.cc",
|
||||||
|
@@ -224,4 +224,3 @@ const char *YGWrapToString(const YGWrap value){
|
|||||||
}
|
}
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
|
|
@@ -11,10 +11,6 @@
|
|||||||
|
|
||||||
#include "YGNodeList.h"
|
#include "YGNodeList.h"
|
||||||
|
|
||||||
extern YGMalloc gYGMalloc;
|
|
||||||
extern YGRealloc gYGRealloc;
|
|
||||||
extern YGFree gYGFree;
|
|
||||||
|
|
||||||
struct YGNodeList {
|
struct YGNodeList {
|
||||||
uint32_t capacity;
|
uint32_t capacity;
|
||||||
uint32_t count;
|
uint32_t count;
|
||||||
@@ -22,21 +18,22 @@ struct YGNodeList {
|
|||||||
};
|
};
|
||||||
|
|
||||||
YGNodeListRef YGNodeListNew(const uint32_t initialCapacity) {
|
YGNodeListRef YGNodeListNew(const uint32_t initialCapacity) {
|
||||||
const YGNodeListRef list = gYGMalloc(sizeof(struct YGNodeList));
|
const YGNodeListRef list =
|
||||||
YGAssert(list != NULL, "Could not allocate memory for list");
|
(const YGNodeListRef)malloc(sizeof(struct YGNodeList));
|
||||||
|
YGAssert(list != nullptr, "Could not allocate memory for list");
|
||||||
|
|
||||||
list->capacity = initialCapacity;
|
list->capacity = initialCapacity;
|
||||||
list->count = 0;
|
list->count = 0;
|
||||||
list->items = gYGMalloc(sizeof(YGNodeRef) * list->capacity);
|
list->items = (YGNodeRef*)malloc(sizeof(YGNodeRef) * list->capacity);
|
||||||
YGAssert(list->items != NULL, "Could not allocate memory for items");
|
YGAssert(list->items != nullptr, "Could not allocate memory for items");
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGNodeListFree(const YGNodeListRef list) {
|
void YGNodeListFree(const YGNodeListRef list) {
|
||||||
if (list) {
|
if (list) {
|
||||||
gYGFree(list->items);
|
free(list->items);
|
||||||
gYGFree(list);
|
free(list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,8 +59,9 @@ void YGNodeListInsert(YGNodeListRef *listp, const YGNodeRef node, const uint32_t
|
|||||||
|
|
||||||
if (list->count == list->capacity) {
|
if (list->count == list->capacity) {
|
||||||
list->capacity *= 2;
|
list->capacity *= 2;
|
||||||
list->items = gYGRealloc(list->items, sizeof(YGNodeRef) * list->capacity);
|
list->items =
|
||||||
YGAssert(list->items != NULL, "Could not extend allocation for items");
|
(YGNodeRef*)realloc(list->items, sizeof(YGNodeRef) * list->capacity);
|
||||||
|
YGAssert(list->items != nullptr, "Could not extend allocation for items");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint32_t i = list->count; i > index; i--) {
|
for (uint32_t i = list->count; i > index; i--) {
|
||||||
@@ -80,18 +78,18 @@ void YGNodeListReplace(YGNodeListRef list, const uint32_t index, const YGNodeRef
|
|||||||
|
|
||||||
void YGNodeListRemoveAll(const YGNodeListRef list) {
|
void YGNodeListRemoveAll(const YGNodeListRef list) {
|
||||||
for (uint32_t i = 0; i < list->count; i++) {
|
for (uint32_t i = 0; i < list->count; i++) {
|
||||||
list->items[i] = NULL;
|
list->items[i] = nullptr;
|
||||||
}
|
}
|
||||||
list->count = 0;
|
list->count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
YGNodeRef YGNodeListRemove(const YGNodeListRef list, const uint32_t index) {
|
YGNodeRef YGNodeListRemove(const YGNodeListRef list, const uint32_t index) {
|
||||||
const YGNodeRef removed = list->items[index];
|
const YGNodeRef removed = list->items[index];
|
||||||
list->items[index] = NULL;
|
list->items[index] = nullptr;
|
||||||
|
|
||||||
for (uint32_t i = index; i < list->count - 1; i++) {
|
for (uint32_t i = index; i < list->count - 1; i++) {
|
||||||
list->items[i] = list->items[i + 1];
|
list->items[i] = list->items[i + 1];
|
||||||
list->items[i + 1] = NULL;
|
list->items[i + 1] = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
list->count--;
|
list->count--;
|
||||||
@@ -105,7 +103,7 @@ YGNodeRef YGNodeListDelete(const YGNodeListRef list, const YGNodeRef node) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
YGNodeRef YGNodeListGet(const YGNodeListRef list, const uint32_t index) {
|
YGNodeRef YGNodeListGet(const YGNodeListRef list, const uint32_t index) {
|
||||||
@@ -113,16 +111,16 @@ YGNodeRef YGNodeListGet(const YGNodeListRef list, const uint32_t index) {
|
|||||||
return list->items[index];
|
return list->items[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
YGNodeListRef YGNodeListClone(const YGNodeListRef oldList) {
|
YGNodeListRef YGNodeListClone(const YGNodeListRef oldList) {
|
||||||
if (!oldList) {
|
if (!oldList) {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
const uint32_t count = oldList->count;
|
const uint32_t count = oldList->count;
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
const YGNodeListRef newList = YGNodeListNew(count);
|
const YGNodeListRef newList = YGNodeListNew(count);
|
||||||
memcpy(newList->items, oldList->items, sizeof(YGNodeRef) * count);
|
memcpy(newList->items, oldList->items, sizeof(YGNodeRef) * count);
|
@@ -18,7 +18,6 @@
|
|||||||
#ifndef isnan
|
#ifndef isnan
|
||||||
#define isnan _isnan
|
#define isnan _isnan
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
#define inline __inline
|
#define inline __inline
|
||||||
#endif
|
#endif
|
||||||
@@ -157,55 +156,74 @@ static const float kDefaultFlexGrow = 0.0f;
|
|||||||
static const float kDefaultFlexShrink = 0.0f;
|
static const float kDefaultFlexShrink = 0.0f;
|
||||||
static const float kWebDefaultFlexShrink = 1.0f;
|
static const float kWebDefaultFlexShrink = 1.0f;
|
||||||
|
|
||||||
|
static const YGStyle gYGNodeStyleDefaults = {
|
||||||
|
.direction = YGDirectionInherit,
|
||||||
|
.flexDirection = YGFlexDirectionColumn,
|
||||||
|
.justifyContent = YGJustifyFlexStart,
|
||||||
|
.alignContent = YGAlignFlexStart,
|
||||||
|
.alignItems = YGAlignStretch,
|
||||||
|
.alignSelf = YGAlignAuto,
|
||||||
|
.positionType = YGPositionTypeRelative,
|
||||||
|
.flexWrap = YGWrapNoWrap,
|
||||||
|
.overflow = YGOverflowVisible,
|
||||||
|
.display = YGDisplayFlex,
|
||||||
|
.flex = YGUndefined,
|
||||||
|
.flexGrow = YGUndefined,
|
||||||
|
.flexShrink = YGUndefined,
|
||||||
|
.flexBasis = YG_AUTO_VALUES,
|
||||||
|
.margin = YG_DEFAULT_EDGE_VALUES_UNIT,
|
||||||
|
.position = YG_DEFAULT_EDGE_VALUES_UNIT,
|
||||||
|
.padding = YG_DEFAULT_EDGE_VALUES_UNIT,
|
||||||
|
.border = YG_DEFAULT_EDGE_VALUES_UNIT,
|
||||||
|
.dimensions = YG_DEFAULT_DIMENSION_VALUES_AUTO_UNIT,
|
||||||
|
.minDimensions = YG_DEFAULT_DIMENSION_VALUES_UNIT,
|
||||||
|
.maxDimensions = YG_DEFAULT_DIMENSION_VALUES_UNIT,
|
||||||
|
.aspectRatio = YGUndefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const YGLayout gYGNodeLayoutDefaults = {
|
||||||
|
.position = {},
|
||||||
|
.dimensions = YG_DEFAULT_DIMENSION_VALUES,
|
||||||
|
.margin = {},
|
||||||
|
.border = {},
|
||||||
|
.padding = {},
|
||||||
|
.direction = YGDirectionInherit,
|
||||||
|
.computedFlexBasisGeneration = 0,
|
||||||
|
.computedFlexBasis = YGUndefined,
|
||||||
|
.hadOverflow = false,
|
||||||
|
.generationCount = 0,
|
||||||
|
.lastParentDirection = (YGDirection)-1,
|
||||||
|
.nextCachedMeasurementsIndex = 0,
|
||||||
|
.cachedMeasurements = {},
|
||||||
|
.measuredDimensions = YG_DEFAULT_DIMENSION_VALUES,
|
||||||
|
.cachedLayout =
|
||||||
|
{
|
||||||
|
.availableWidth = 0,
|
||||||
|
.availableHeight = 0,
|
||||||
|
.widthMeasureMode = (YGMeasureMode)-1,
|
||||||
|
.heightMeasureMode = (YGMeasureMode)-1,
|
||||||
|
.computedWidth = -1,
|
||||||
|
.computedHeight = -1,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
static const YGNode gYGNodeDefaults = {
|
static const YGNode gYGNodeDefaults = {
|
||||||
.parent = NULL,
|
.style = gYGNodeStyleDefaults,
|
||||||
.children = NULL,
|
.layout = gYGNodeLayoutDefaults,
|
||||||
.hasNewLayout = true,
|
.lineIndex = 0,
|
||||||
|
.parent = nullptr,
|
||||||
|
.children = nullptr,
|
||||||
|
.nextChild = nullptr,
|
||||||
|
.measure = nullptr,
|
||||||
|
.baseline = nullptr,
|
||||||
|
.print = nullptr,
|
||||||
|
.config = nullptr,
|
||||||
|
.context = nullptr,
|
||||||
.isDirty = false,
|
.isDirty = false,
|
||||||
|
.hasNewLayout = true,
|
||||||
.nodeType = YGNodeTypeDefault,
|
.nodeType = YGNodeTypeDefault,
|
||||||
.resolvedDimensions = {[YGDimensionWidth] = &YGValueUndefined,
|
.resolvedDimensions = {[YGDimensionWidth] = &YGValueUndefined,
|
||||||
[YGDimensionHeight] = &YGValueUndefined},
|
[YGDimensionHeight] = &YGValueUndefined},
|
||||||
|
|
||||||
.style =
|
|
||||||
{
|
|
||||||
.flex = YGUndefined,
|
|
||||||
.flexGrow = YGUndefined,
|
|
||||||
.flexShrink = YGUndefined,
|
|
||||||
.flexBasis = YG_AUTO_VALUES,
|
|
||||||
.justifyContent = YGJustifyFlexStart,
|
|
||||||
.alignItems = YGAlignStretch,
|
|
||||||
.alignContent = YGAlignFlexStart,
|
|
||||||
.direction = YGDirectionInherit,
|
|
||||||
.flexDirection = YGFlexDirectionColumn,
|
|
||||||
.overflow = YGOverflowVisible,
|
|
||||||
.display = YGDisplayFlex,
|
|
||||||
.dimensions = YG_DEFAULT_DIMENSION_VALUES_AUTO_UNIT,
|
|
||||||
.minDimensions = YG_DEFAULT_DIMENSION_VALUES_UNIT,
|
|
||||||
.maxDimensions = YG_DEFAULT_DIMENSION_VALUES_UNIT,
|
|
||||||
.position = YG_DEFAULT_EDGE_VALUES_UNIT,
|
|
||||||
.margin = YG_DEFAULT_EDGE_VALUES_UNIT,
|
|
||||||
.padding = YG_DEFAULT_EDGE_VALUES_UNIT,
|
|
||||||
.border = YG_DEFAULT_EDGE_VALUES_UNIT,
|
|
||||||
.aspectRatio = YGUndefined,
|
|
||||||
},
|
|
||||||
|
|
||||||
.layout =
|
|
||||||
{
|
|
||||||
.dimensions = YG_DEFAULT_DIMENSION_VALUES,
|
|
||||||
.lastParentDirection = (YGDirection) -1,
|
|
||||||
.nextCachedMeasurementsIndex = 0,
|
|
||||||
.computedFlexBasis = YGUndefined,
|
|
||||||
.hadOverflow = false,
|
|
||||||
.measuredDimensions = YG_DEFAULT_DIMENSION_VALUES,
|
|
||||||
|
|
||||||
.cachedLayout =
|
|
||||||
{
|
|
||||||
.widthMeasureMode = (YGMeasureMode) -1,
|
|
||||||
.heightMeasureMode = (YGMeasureMode) -1,
|
|
||||||
.computedWidth = -1,
|
|
||||||
.computedHeight = -1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
@@ -225,25 +243,22 @@ static int YGDefaultLog(const YGConfigRef config,
|
|||||||
static YGConfig gYGConfigDefaults = {
|
static YGConfig gYGConfigDefaults = {
|
||||||
.experimentalFeatures =
|
.experimentalFeatures =
|
||||||
{
|
{
|
||||||
[YGExperimentalFeatureWebFlexBasis] = false,
|
[YGExperimentalFeatureWebFlexBasis] = false,
|
||||||
},
|
},
|
||||||
.useWebDefaults = false,
|
.useWebDefaults = false,
|
||||||
|
.useLegacyStretchBehaviour = false,
|
||||||
.pointScaleFactor = 1.0f,
|
.pointScaleFactor = 1.0f,
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
.logger = &YGAndroidLog,
|
.logger = &YGAndroidLog,
|
||||||
#else
|
#else
|
||||||
.logger = &YGDefaultLog,
|
.logger = &YGDefaultLog,
|
||||||
#endif
|
#endif
|
||||||
.context = NULL,
|
.cloneNodeCallback = nullptr,
|
||||||
|
.context = nullptr,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void YGNodeMarkDirtyInternal(const YGNodeRef node);
|
static void YGNodeMarkDirtyInternal(const YGNodeRef node);
|
||||||
|
|
||||||
YGMalloc gYGMalloc = &malloc;
|
|
||||||
YGCalloc gYGCalloc = &calloc;
|
|
||||||
YGRealloc gYGRealloc = &realloc;
|
|
||||||
YGFree gYGFree = &free;
|
|
||||||
|
|
||||||
static YGValue YGValueZero = {.value = 0, .unit = YGUnitPoint};
|
static YGValue YGValueZero = {.value = 0, .unit = YGUnitPoint};
|
||||||
|
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
@@ -297,6 +312,10 @@ static int YGDefaultLog(const YGConfigRef config,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool YGFloatIsUndefined(const float value) {
|
||||||
|
return isnan(value);
|
||||||
|
}
|
||||||
|
|
||||||
static inline const YGValue *YGComputedEdgeValue(const YGValue edges[YGEdgeCount],
|
static inline const YGValue *YGComputedEdgeValue(const YGValue edges[YGEdgeCount],
|
||||||
const YGEdge edge,
|
const YGEdge edge,
|
||||||
const YGValue *const defaultValue) {
|
const YGValue *const defaultValue) {
|
||||||
@@ -346,8 +365,9 @@ int32_t gNodeInstanceCount = 0;
|
|||||||
int32_t gConfigInstanceCount = 0;
|
int32_t gConfigInstanceCount = 0;
|
||||||
|
|
||||||
WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config) {
|
WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config) {
|
||||||
const YGNodeRef node = gYGMalloc(sizeof(YGNode));
|
const YGNodeRef node = (const YGNodeRef)malloc(sizeof(YGNode));
|
||||||
YGAssertWithConfig(config, node != NULL, "Could not allocate memory for node");
|
YGAssertWithConfig(
|
||||||
|
config, node != nullptr, "Could not allocate memory for node");
|
||||||
gNodeInstanceCount++;
|
gNodeInstanceCount++;
|
||||||
|
|
||||||
memcpy(node, &gYGNodeDefaults, sizeof(YGNode));
|
memcpy(node, &gYGNodeDefaults, sizeof(YGNode));
|
||||||
@@ -364,30 +384,31 @@ YGNodeRef YGNodeNew(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
YGNodeRef YGNodeClone(const YGNodeRef oldNode) {
|
YGNodeRef YGNodeClone(const YGNodeRef oldNode) {
|
||||||
const YGNodeRef node = gYGMalloc(sizeof(YGNode));
|
const YGNodeRef node = (const YGNodeRef)malloc(sizeof(YGNode));
|
||||||
YGAssertWithConfig(oldNode->config, node != NULL, "Could not allocate memory for node");
|
YGAssertWithConfig(
|
||||||
|
oldNode->config, node != nullptr, "Could not allocate memory for node");
|
||||||
gNodeInstanceCount++;
|
gNodeInstanceCount++;
|
||||||
|
|
||||||
memcpy(node, oldNode, sizeof(YGNode));
|
memcpy(node, oldNode, sizeof(YGNode));
|
||||||
node->children = YGNodeListClone(oldNode->children);
|
node->children = YGNodeListClone(oldNode->children);
|
||||||
node->parent = NULL;
|
node->parent = nullptr;
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGNodeFree(const YGNodeRef node) {
|
void YGNodeFree(const YGNodeRef node) {
|
||||||
if (node->parent) {
|
if (node->parent) {
|
||||||
YGNodeListDelete(node->parent->children, node);
|
YGNodeListDelete(node->parent->children, node);
|
||||||
node->parent = NULL;
|
node->parent = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint32_t childCount = YGNodeGetChildCount(node);
|
const uint32_t childCount = YGNodeGetChildCount(node);
|
||||||
for (uint32_t i = 0; i < childCount; i++) {
|
for (uint32_t i = 0; i < childCount; i++) {
|
||||||
const YGNodeRef child = YGNodeGetChild(node, i);
|
const YGNodeRef child = YGNodeGetChild(node, i);
|
||||||
child->parent = NULL;
|
child->parent = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
YGNodeListFree(node->children);
|
YGNodeListFree(node->children);
|
||||||
gYGFree(node);
|
free(node);
|
||||||
gNodeInstanceCount--;
|
gNodeInstanceCount--;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -408,7 +429,10 @@ void YGNodeReset(const YGNodeRef node) {
|
|||||||
YGAssertWithNode(node,
|
YGAssertWithNode(node,
|
||||||
YGNodeGetChildCount(node) == 0,
|
YGNodeGetChildCount(node) == 0,
|
||||||
"Cannot reset a node which still has children attached");
|
"Cannot reset a node which still has children attached");
|
||||||
YGAssertWithNode(node, node->parent == NULL, "Cannot reset a node still attached to a parent");
|
YGAssertWithNode(
|
||||||
|
node,
|
||||||
|
node->parent == nullptr,
|
||||||
|
"Cannot reset a node still attached to a parent");
|
||||||
|
|
||||||
YGNodeListFree(node->children);
|
YGNodeListFree(node->children);
|
||||||
|
|
||||||
@@ -435,8 +459,8 @@ YGConfigRef YGConfigGetDefault() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
YGConfigRef YGConfigNew(void) {
|
YGConfigRef YGConfigNew(void) {
|
||||||
const YGConfigRef config = gYGMalloc(sizeof(YGConfig));
|
const YGConfigRef config = (const YGConfigRef)malloc(sizeof(YGConfig));
|
||||||
YGAssert(config != NULL, "Could not allocate memory for config");
|
YGAssert(config != nullptr, "Could not allocate memory for config");
|
||||||
|
|
||||||
gConfigInstanceCount++;
|
gConfigInstanceCount++;
|
||||||
memcpy(config, &gYGConfigDefaults, sizeof(YGConfig));
|
memcpy(config, &gYGConfigDefaults, sizeof(YGConfig));
|
||||||
@@ -444,7 +468,7 @@ YGConfigRef YGConfigNew(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void YGConfigFree(const YGConfigRef config) {
|
void YGConfigFree(const YGConfigRef config) {
|
||||||
gYGFree(config);
|
free(config);
|
||||||
gConfigInstanceCount--;
|
gConfigInstanceCount--;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -463,8 +487,8 @@ static void YGNodeMarkDirtyInternal(const YGNodeRef node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void YGNodeSetMeasureFunc(const YGNodeRef node, YGMeasureFunc measureFunc) {
|
void YGNodeSetMeasureFunc(const YGNodeRef node, YGMeasureFunc measureFunc) {
|
||||||
if (measureFunc == NULL) {
|
if (measureFunc == nullptr) {
|
||||||
node->measure = NULL;
|
node->measure = nullptr;
|
||||||
// TODO: t18095186 Move nodeType to opt-in function and mark appropriate places in Litho
|
// TODO: t18095186 Move nodeType to opt-in function and mark appropriate places in Litho
|
||||||
node->nodeType = YGNodeTypeDefault;
|
node->nodeType = YGNodeTypeDefault;
|
||||||
} else {
|
} else {
|
||||||
@@ -519,12 +543,14 @@ static void YGCloneChildrenIfNeeded(const YGNodeRef parent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void YGNodeInsertChild(const YGNodeRef node, const YGNodeRef child, const uint32_t index) {
|
void YGNodeInsertChild(const YGNodeRef node, const YGNodeRef child, const uint32_t index) {
|
||||||
YGAssertWithNode(node,
|
YGAssertWithNode(
|
||||||
child->parent == NULL,
|
node,
|
||||||
"Child already has a parent, it must be removed first.");
|
child->parent == nullptr,
|
||||||
YGAssertWithNode(node,
|
"Child already has a parent, it must be removed first.");
|
||||||
node->measure == NULL,
|
YGAssertWithNode(
|
||||||
"Cannot add child: Nodes with measure functions cannot have children.");
|
node,
|
||||||
|
node->measure == nullptr,
|
||||||
|
"Cannot add child: Nodes with measure functions cannot have children.");
|
||||||
|
|
||||||
YGCloneChildrenIfNeeded(node);
|
YGCloneChildrenIfNeeded(node);
|
||||||
|
|
||||||
@@ -544,9 +570,9 @@ void YGNodeRemoveChild(const YGNodeRef parent, const YGNodeRef excludedChild) {
|
|||||||
if (firstChild->parent == parent) {
|
if (firstChild->parent == parent) {
|
||||||
// If the first child has this node as its parent, we assume that it is already unique.
|
// If the first child has this node as its parent, we assume that it is already unique.
|
||||||
// We can now try to delete a child in this list.
|
// We can now try to delete a child in this list.
|
||||||
if (YGNodeListDelete(parent->children, excludedChild) != NULL) {
|
if (YGNodeListDelete(parent->children, excludedChild) != nullptr) {
|
||||||
excludedChild->layout = gYGNodeDefaults.layout; // layout is no longer valid
|
excludedChild->layout = gYGNodeDefaults.layout; // layout is no longer valid
|
||||||
excludedChild->parent = NULL;
|
excludedChild->parent = nullptr;
|
||||||
YGNodeMarkDirtyInternal(parent);
|
YGNodeMarkDirtyInternal(parent);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -592,14 +618,14 @@ void YGNodeRemoveAllChildren(const YGNodeRef parent) {
|
|||||||
for (uint32_t i = 0; i < childCount; i++) {
|
for (uint32_t i = 0; i < childCount; i++) {
|
||||||
const YGNodeRef oldChild = YGNodeGetChild(parent, i);
|
const YGNodeRef oldChild = YGNodeGetChild(parent, i);
|
||||||
oldChild->layout = gYGNodeDefaults.layout; // layout is no longer valid
|
oldChild->layout = gYGNodeDefaults.layout; // layout is no longer valid
|
||||||
oldChild->parent = NULL;
|
oldChild->parent = nullptr;
|
||||||
}
|
}
|
||||||
YGNodeListRemoveAll(parent->children);
|
YGNodeListRemoveAll(parent->children);
|
||||||
YGNodeMarkDirtyInternal(parent);
|
YGNodeMarkDirtyInternal(parent);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Otherwise, we are not the owner of the child set. We don't have to do anything to clear it.
|
// Otherwise, we are not the owner of the child set. We don't have to do anything to clear it.
|
||||||
parent->children = NULL;
|
parent->children = nullptr;
|
||||||
YGNodeMarkDirtyInternal(parent);
|
YGNodeMarkDirtyInternal(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -616,10 +642,11 @@ uint32_t YGNodeGetChildCount(const YGNodeRef node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void YGNodeMarkDirty(const YGNodeRef node) {
|
void YGNodeMarkDirty(const YGNodeRef node) {
|
||||||
YGAssertWithNode(node,
|
YGAssertWithNode(
|
||||||
node->measure != NULL,
|
node,
|
||||||
"Only leaf nodes with custom measure functions"
|
node->measure != nullptr,
|
||||||
"should manually mark themselves as dirty");
|
"Only leaf nodes with custom measure functions"
|
||||||
|
"should manually mark themselves as dirty");
|
||||||
|
|
||||||
YGNodeMarkDirtyInternal(node);
|
YGNodeMarkDirtyInternal(node);
|
||||||
}
|
}
|
||||||
@@ -637,7 +664,7 @@ void YGNodeCopyStyle(const YGNodeRef dstNode, const YGNodeRef srcNode) {
|
|||||||
|
|
||||||
static inline float YGResolveFlexGrow(const YGNodeRef node) {
|
static inline float YGResolveFlexGrow(const YGNodeRef node) {
|
||||||
// Root nodes flexGrow should always be 0
|
// Root nodes flexGrow should always be 0
|
||||||
if (node->parent == NULL) {
|
if (node->parent == nullptr) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
if (!YGFloatIsUndefined(node->style.flexGrow)) {
|
if (!YGFloatIsUndefined(node->style.flexGrow)) {
|
||||||
@@ -661,7 +688,7 @@ float YGNodeStyleGetFlexShrink(const YGNodeRef node) {
|
|||||||
|
|
||||||
static inline float YGNodeResolveFlexShrink(const YGNodeRef node) {
|
static inline float YGNodeResolveFlexShrink(const YGNodeRef node) {
|
||||||
// Root nodes flexShrink should always be 0
|
// Root nodes flexShrink should always be 0
|
||||||
if (node->parent == NULL) {
|
if (node->parent == nullptr) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
if (!YGFloatIsUndefined(node->style.flexShrink)) {
|
if (!YGFloatIsUndefined(node->style.flexShrink)) {
|
||||||
@@ -913,10 +940,6 @@ bool YGLayoutNodeInternal(const YGNodeRef node,
|
|||||||
const char *reason,
|
const char *reason,
|
||||||
const YGConfigRef config);
|
const YGConfigRef config);
|
||||||
|
|
||||||
inline bool YGFloatIsUndefined(const float value) {
|
|
||||||
return isnan(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool YGValueEqual(const YGValue a, const YGValue b) {
|
static inline bool YGValueEqual(const YGValue a, const YGValue b) {
|
||||||
if (a.unit != b.unit) {
|
if (a.unit != b.unit) {
|
||||||
return false;
|
return false;
|
||||||
@@ -930,7 +953,7 @@ static inline bool YGValueEqual(const YGValue a, const YGValue b) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline void YGResolveDimensions(YGNodeRef node) {
|
static inline void YGResolveDimensions(YGNodeRef node) {
|
||||||
for (YGDimension dim = YGDimensionWidth; dim <= YGDimensionHeight; dim++) {
|
for (uint32_t dim = YGDimensionWidth; dim < YGDimensionCount; dim++) {
|
||||||
if (node->style.maxDimensions[dim].unit != YGUnitUndefined &&
|
if (node->style.maxDimensions[dim].unit != YGUnitUndefined &&
|
||||||
YGValueEqual(node->style.maxDimensions[dim], node->style.minDimensions[dim])) {
|
YGValueEqual(node->style.maxDimensions[dim], node->style.minDimensions[dim])) {
|
||||||
node->resolvedDimensions[dim] = &node->style.maxDimensions[dim];
|
node->resolvedDimensions[dim] = &node->style.maxDimensions[dim];
|
||||||
@@ -959,11 +982,11 @@ static void YGWriteToStringStream(YGStringStream *stream, const char *format, ..
|
|||||||
va_list argsCopy;
|
va_list argsCopy;
|
||||||
va_copy(argsCopy, args);
|
va_copy(argsCopy, args);
|
||||||
int available = stream->capacity - stream->length;
|
int available = stream->capacity - stream->length;
|
||||||
int required = vsnprintf(NULL, 0, format, args);
|
int required = vsnprintf(nullptr, 0, format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
if (required >= available) {
|
if (required >= available) {
|
||||||
char *newStr = (char *) realloc(stream->str, sizeof(char) * (stream->capacity) * 2);
|
char *newStr = (char *) realloc(stream->str, sizeof(char) * (stream->capacity) * 2);
|
||||||
if (newStr != NULL) {
|
if (newStr != nullptr) {
|
||||||
stream->str = newStr;
|
stream->str = newStr;
|
||||||
stream->capacity *= 2;
|
stream->capacity *= 2;
|
||||||
available = stream->capacity - stream->length;
|
available = stream->capacity - stream->length;
|
||||||
@@ -1037,9 +1060,9 @@ static void YGPrintEdges(YGStringStream *stream, const char *str, const YGValue
|
|||||||
if (YGFourValuesEqual(edges)) {
|
if (YGFourValuesEqual(edges)) {
|
||||||
YGPrintNumberIfNotZero(stream, str, &edges[YGEdgeLeft]);
|
YGPrintNumberIfNotZero(stream, str, &edges[YGEdgeLeft]);
|
||||||
} else {
|
} else {
|
||||||
for (YGEdge edge = YGEdgeLeft; edge < YGEdgeCount; edge++) {
|
for (uint32_t edge = 0; edge < YGEdgeCount; edge++) {
|
||||||
char buf[30];
|
char buf[30];
|
||||||
snprintf(buf, sizeof(buf), "%s-%s", str, YGEdgeToString(edge));
|
snprintf(buf, sizeof(buf), "%s-%s", str, YGEdgeToString((YGEdge)edge));
|
||||||
YGPrintNumberIfNotZero(stream, buf, &edges[edge]);
|
YGPrintNumberIfNotZero(stream, buf, &edges[edge]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1127,7 +1150,7 @@ static void YGNodeToString(YGStringStream *stream,
|
|||||||
YGPrintEdgeIfNotUndefined(stream, "bottom", node->style.position, YGEdgeBottom);
|
YGPrintEdgeIfNotUndefined(stream, "bottom", node->style.position, YGEdgeBottom);
|
||||||
YGWriteToStringStream(stream, "\" ");
|
YGWriteToStringStream(stream, "\" ");
|
||||||
|
|
||||||
if (node->measure != NULL) {
|
if (node->measure != nullptr) {
|
||||||
YGWriteToStringStream(stream, "has-custom-measure=\"true\"");
|
YGWriteToStringStream(stream, "has-custom-measure=\"true\"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1151,7 +1174,7 @@ static void YGNodePrintInternal(const YGNodeRef node,
|
|||||||
stream.str = (char *) malloc(sizeof(char) * 1024);
|
stream.str = (char *) malloc(sizeof(char) * 1024);
|
||||||
stream.length = 0;
|
stream.length = 0;
|
||||||
stream.capacity = 1024;
|
stream.capacity = 1024;
|
||||||
if (stream.str != NULL) {
|
if (stream.str != nullptr) {
|
||||||
YGNodeToString(&stream, node, options, 0);
|
YGNodeToString(&stream, node, options, 0);
|
||||||
YGLog(node, YGLogLevelDebug, stream.str);
|
YGLog(node, YGLogLevelDebug, stream.str);
|
||||||
free(stream.str);
|
free(stream.str);
|
||||||
@@ -1305,7 +1328,7 @@ static inline YGDirection YGNodeResolveDirection(const YGNodeRef node,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static float YGBaseline(const YGNodeRef node) {
|
static float YGBaseline(const YGNodeRef node) {
|
||||||
if (node->baseline != NULL) {
|
if (node->baseline != nullptr) {
|
||||||
const float baseline = node->baseline(node,
|
const float baseline = node->baseline(node,
|
||||||
node->layout.measuredDimensions[YGDimensionWidth],
|
node->layout.measuredDimensions[YGDimensionWidth],
|
||||||
node->layout.measuredDimensions[YGDimensionHeight]);
|
node->layout.measuredDimensions[YGDimensionHeight]);
|
||||||
@@ -1315,7 +1338,7 @@ static float YGBaseline(const YGNodeRef node) {
|
|||||||
return baseline;
|
return baseline;
|
||||||
}
|
}
|
||||||
|
|
||||||
YGNodeRef baselineChild = NULL;
|
YGNodeRef baselineChild = nullptr;
|
||||||
const uint32_t childCount = YGNodeGetChildCount(node);
|
const uint32_t childCount = YGNodeGetChildCount(node);
|
||||||
for (uint32_t i = 0; i < childCount; i++) {
|
for (uint32_t i = 0; i < childCount; i++) {
|
||||||
const YGNodeRef child = YGNodeGetChild(node, i);
|
const YGNodeRef child = YGNodeGetChild(node, i);
|
||||||
@@ -1330,12 +1353,12 @@ static float YGBaseline(const YGNodeRef node) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (baselineChild == NULL) {
|
if (baselineChild == nullptr) {
|
||||||
baselineChild = child;
|
baselineChild = child;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (baselineChild == NULL) {
|
if (baselineChild == nullptr) {
|
||||||
return node->layout.measuredDimensions[YGDimensionHeight];
|
return node->layout.measuredDimensions[YGDimensionHeight];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1563,7 +1586,8 @@ static void YGNodeSetPosition(const YGNodeRef node,
|
|||||||
const float crossSize,
|
const float crossSize,
|
||||||
const float parentWidth) {
|
const float parentWidth) {
|
||||||
/* Root nodes should be always layouted as LTR, so we don't return negative values. */
|
/* Root nodes should be always layouted as LTR, so we don't return negative values. */
|
||||||
const YGDirection directionRespectingRoot = node->parent != NULL ? direction : YGDirectionLTR;
|
const YGDirection directionRespectingRoot =
|
||||||
|
node->parent != nullptr ? direction : YGDirectionLTR;
|
||||||
const YGFlexDirection mainAxis =
|
const YGFlexDirection mainAxis =
|
||||||
YGResolveFlexDirection(node->style.flexDirection, directionRespectingRoot);
|
YGResolveFlexDirection(node->style.flexDirection, directionRespectingRoot);
|
||||||
const YGFlexDirection crossAxis = YGFlexDirectionCross(mainAxis, directionRespectingRoot);
|
const YGFlexDirection crossAxis = YGFlexDirectionCross(mainAxis, directionRespectingRoot);
|
||||||
@@ -1889,7 +1913,10 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions(const YGNodeRef node,
|
|||||||
const YGMeasureMode heightMeasureMode,
|
const YGMeasureMode heightMeasureMode,
|
||||||
const float parentWidth,
|
const float parentWidth,
|
||||||
const float parentHeight) {
|
const float parentHeight) {
|
||||||
YGAssertWithNode(node, node->measure != NULL, "Expected node to have custom measure function");
|
YGAssertWithNode(
|
||||||
|
node,
|
||||||
|
node->measure != nullptr,
|
||||||
|
"Expected node to have custom measure function");
|
||||||
|
|
||||||
const float paddingAndBorderAxisRow =
|
const float paddingAndBorderAxisRow =
|
||||||
YGNodePaddingAndBorderForAxis(node, YGFlexDirectionRow, availableWidth);
|
YGNodePaddingAndBorderForAxis(node, YGFlexDirectionRow, availableWidth);
|
||||||
@@ -2207,8 +2234,8 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
const float mainAxisParentSize = isMainAxisRow ? parentWidth : parentHeight;
|
const float mainAxisParentSize = isMainAxisRow ? parentWidth : parentHeight;
|
||||||
const float crossAxisParentSize = isMainAxisRow ? parentHeight : parentWidth;
|
const float crossAxisParentSize = isMainAxisRow ? parentHeight : parentWidth;
|
||||||
|
|
||||||
YGNodeRef firstAbsoluteChild = NULL;
|
YGNodeRef firstAbsoluteChild = nullptr;
|
||||||
YGNodeRef currentAbsoluteChild = NULL;
|
YGNodeRef currentAbsoluteChild = nullptr;
|
||||||
|
|
||||||
const float leadingPaddingAndBorderMain =
|
const float leadingPaddingAndBorderMain =
|
||||||
YGNodeLeadingPaddingAndBorder(node, mainAxis, parentWidth);
|
YGNodeLeadingPaddingAndBorder(node, mainAxis, parentWidth);
|
||||||
@@ -2267,14 +2294,14 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
// If there is only one child with flexGrow + flexShrink it means we can set the
|
// If there is only one child with flexGrow + flexShrink it means we can set the
|
||||||
// computedFlexBasis to 0 instead of measuring and shrinking / flexing the child to exactly
|
// computedFlexBasis to 0 instead of measuring and shrinking / flexing the child to exactly
|
||||||
// match the remaining space
|
// match the remaining space
|
||||||
YGNodeRef singleFlexChild = NULL;
|
YGNodeRef singleFlexChild = nullptr;
|
||||||
if (measureModeMainDim == YGMeasureModeExactly) {
|
if (measureModeMainDim == YGMeasureModeExactly) {
|
||||||
for (uint32_t i = 0; i < childCount; i++) {
|
for (uint32_t i = 0; i < childCount; i++) {
|
||||||
const YGNodeRef child = YGNodeGetChild(node, i);
|
const YGNodeRef child = YGNodeGetChild(node, i);
|
||||||
if (singleFlexChild) {
|
if (singleFlexChild) {
|
||||||
if (YGNodeIsFlex(child)) {
|
if (YGNodeIsFlex(child)) {
|
||||||
// There is already a flexible child, abort.
|
// There is already a flexible child, abort.
|
||||||
singleFlexChild = NULL;
|
singleFlexChild = nullptr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (YGResolveFlexGrow(child) > 0.0f && YGNodeResolveFlexShrink(child) > 0.0f) {
|
} else if (YGResolveFlexGrow(child) > 0.0f && YGNodeResolveFlexShrink(child) > 0.0f) {
|
||||||
@@ -2310,14 +2337,14 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
if (child->style.positionType == YGPositionTypeAbsolute) {
|
if (child->style.positionType == YGPositionTypeAbsolute) {
|
||||||
// Store a private linked list of absolutely positioned children
|
// Store a private linked list of absolutely positioned children
|
||||||
// so that we can efficiently traverse them later.
|
// so that we can efficiently traverse them later.
|
||||||
if (firstAbsoluteChild == NULL) {
|
if (firstAbsoluteChild == nullptr) {
|
||||||
firstAbsoluteChild = child;
|
firstAbsoluteChild = child;
|
||||||
}
|
}
|
||||||
if (currentAbsoluteChild != NULL) {
|
if (currentAbsoluteChild != nullptr) {
|
||||||
currentAbsoluteChild->nextChild = child;
|
currentAbsoluteChild->nextChild = child;
|
||||||
}
|
}
|
||||||
currentAbsoluteChild = child;
|
currentAbsoluteChild = child;
|
||||||
child->nextChild = NULL;
|
child->nextChild = nullptr;
|
||||||
} else {
|
} else {
|
||||||
if (child == singleFlexChild) {
|
if (child == singleFlexChild) {
|
||||||
child->layout.computedFlexBasisGeneration = gCurrentGenerationCount;
|
child->layout.computedFlexBasisGeneration = gCurrentGenerationCount;
|
||||||
@@ -2381,8 +2408,8 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
float totalFlexShrinkScaledFactors = 0;
|
float totalFlexShrinkScaledFactors = 0;
|
||||||
|
|
||||||
// Maintain a linked list of the child nodes that can shrink and/or grow.
|
// Maintain a linked list of the child nodes that can shrink and/or grow.
|
||||||
YGNodeRef firstRelativeChild = NULL;
|
YGNodeRef firstRelativeChild = nullptr;
|
||||||
YGNodeRef currentRelativeChild = NULL;
|
YGNodeRef currentRelativeChild = nullptr;
|
||||||
|
|
||||||
// Add items to the current line until it's full or we run out of items.
|
// Add items to the current line until it's full or we run out of items.
|
||||||
for (uint32_t i = startOfLineIndex; i < childCount; i++, endOfLineIndex++) {
|
for (uint32_t i = startOfLineIndex; i < childCount; i++, endOfLineIndex++) {
|
||||||
@@ -2426,14 +2453,14 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
if (firstRelativeChild == NULL) {
|
if (firstRelativeChild == nullptr) {
|
||||||
firstRelativeChild = child;
|
firstRelativeChild = child;
|
||||||
}
|
}
|
||||||
if (currentRelativeChild != NULL) {
|
if (currentRelativeChild != nullptr) {
|
||||||
currentRelativeChild->nextChild = child;
|
currentRelativeChild->nextChild = child;
|
||||||
}
|
}
|
||||||
currentRelativeChild = child;
|
currentRelativeChild = child;
|
||||||
child->nextChild = NULL;
|
child->nextChild = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2526,7 +2553,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
float deltaFlexShrinkScaledFactors = 0;
|
float deltaFlexShrinkScaledFactors = 0;
|
||||||
float deltaFlexGrowFactors = 0;
|
float deltaFlexGrowFactors = 0;
|
||||||
currentRelativeChild = firstRelativeChild;
|
currentRelativeChild = firstRelativeChild;
|
||||||
while (currentRelativeChild != NULL) {
|
while (currentRelativeChild != nullptr) {
|
||||||
childFlexBasis =
|
childFlexBasis =
|
||||||
fminf(YGResolveValue(¤tRelativeChild->style.maxDimensions[dim[mainAxis]],
|
fminf(YGResolveValue(¤tRelativeChild->style.maxDimensions[dim[mainAxis]],
|
||||||
mainAxisParentSize),
|
mainAxisParentSize),
|
||||||
@@ -2594,7 +2621,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
// Second pass: resolve the sizes of the flexible items
|
// Second pass: resolve the sizes of the flexible items
|
||||||
deltaFreeSpace = 0;
|
deltaFreeSpace = 0;
|
||||||
currentRelativeChild = firstRelativeChild;
|
currentRelativeChild = firstRelativeChild;
|
||||||
while (currentRelativeChild != NULL) {
|
while (currentRelativeChild != nullptr) {
|
||||||
childFlexBasis =
|
childFlexBasis =
|
||||||
fminf(YGResolveValue(¤tRelativeChild->style.maxDimensions[dim[mainAxis]],
|
fminf(YGResolveValue(¤tRelativeChild->style.maxDimensions[dim[mainAxis]],
|
||||||
mainAxisParentSize),
|
mainAxisParentSize),
|
||||||
@@ -3215,7 +3242,8 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
|
|
||||||
if (performLayout) {
|
if (performLayout) {
|
||||||
// STEP 10: SIZING AND POSITIONING ABSOLUTE CHILDREN
|
// STEP 10: SIZING AND POSITIONING ABSOLUTE CHILDREN
|
||||||
for (currentAbsoluteChild = firstAbsoluteChild; currentAbsoluteChild != NULL;
|
for (currentAbsoluteChild = firstAbsoluteChild;
|
||||||
|
currentAbsoluteChild != nullptr;
|
||||||
currentAbsoluteChild = currentAbsoluteChild->nextChild) {
|
currentAbsoluteChild = currentAbsoluteChild->nextChild) {
|
||||||
YGNodeAbsoluteLayoutChild(node,
|
YGNodeAbsoluteLayoutChild(node,
|
||||||
currentAbsoluteChild,
|
currentAbsoluteChild,
|
||||||
@@ -3322,7 +3350,8 @@ float YGRoundValueToPixelGrid(const float value,
|
|||||||
scaledValue = scaledValue - fractial;
|
scaledValue = scaledValue - fractial;
|
||||||
} else {
|
} else {
|
||||||
// Finally we just round the value
|
// Finally we just round the value
|
||||||
scaledValue = scaledValue - fractial + (fractial > 0.5f || YGFloatsEqual(fractial, 0.5f) ? 1.0f : 0.0f);
|
scaledValue = scaledValue - fractial +
|
||||||
|
(fractial > 0.5f || YGFloatsEqual(fractial, 0.5f) ? 1.0f : 0.0f);
|
||||||
}
|
}
|
||||||
return scaledValue / pointScaleFactor;
|
return scaledValue / pointScaleFactor;
|
||||||
}
|
}
|
||||||
@@ -3343,7 +3372,8 @@ bool YGNodeCanUseCachedMeasurement(const YGMeasureMode widthMode,
|
|||||||
if (lastComputedHeight < 0 || lastComputedWidth < 0) {
|
if (lastComputedHeight < 0 || lastComputedWidth < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool useRoundedComparison = config != NULL && config->pointScaleFactor != 0;
|
bool useRoundedComparison =
|
||||||
|
config != nullptr && config->pointScaleFactor != 0;
|
||||||
const float effectiveWidth =
|
const float effectiveWidth =
|
||||||
useRoundedComparison ? YGRoundValueToPixelGrid(width, config->pointScaleFactor, false, false)
|
useRoundedComparison ? YGRoundValueToPixelGrid(width, config->pointScaleFactor, false, false)
|
||||||
: width;
|
: width;
|
||||||
@@ -3425,7 +3455,7 @@ bool YGLayoutNodeInternal(const YGNodeRef node,
|
|||||||
layout->cachedLayout.computedHeight = -1;
|
layout->cachedLayout.computedHeight = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
YGCachedMeasurement *cachedResults = NULL;
|
YGCachedMeasurement* cachedResults = nullptr;
|
||||||
|
|
||||||
// Determine whether the results are already cached. We maintain a separate
|
// Determine whether the results are already cached. We maintain a separate
|
||||||
// cache for layouts and measurements. A layout operation modifies the
|
// cache for layouts and measurements. A layout operation modifies the
|
||||||
@@ -3498,7 +3528,7 @@ bool YGLayoutNodeInternal(const YGNodeRef node,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!needToVisitNode && cachedResults != NULL) {
|
if (!needToVisitNode && cachedResults != nullptr) {
|
||||||
layout->measuredDimensions[YGDimensionWidth] = cachedResults->computedWidth;
|
layout->measuredDimensions[YGDimensionWidth] = cachedResults->computedWidth;
|
||||||
layout->measuredDimensions[YGDimensionHeight] = cachedResults->computedHeight;
|
layout->measuredDimensions[YGDimensionHeight] = cachedResults->computedHeight;
|
||||||
|
|
||||||
@@ -3507,27 +3537,39 @@ bool YGLayoutNodeInternal(const YGNodeRef node,
|
|||||||
if (node->print) {
|
if (node->print) {
|
||||||
node->print(node);
|
node->print(node);
|
||||||
}
|
}
|
||||||
YGLog(node, YGLogLevelVerbose, "wm: %s, hm: %s, aw: %f ah: %f => d: (%f, %f) %s\n",
|
YGLog(
|
||||||
YGMeasureModeName(widthMeasureMode, performLayout),
|
node,
|
||||||
YGMeasureModeName(heightMeasureMode, performLayout),
|
YGLogLevelVerbose,
|
||||||
availableWidth,
|
"wm: %s, hm: %s, aw: %f ah: %f => d: (%f, %f) %s\n",
|
||||||
availableHeight,
|
YGMeasureModeName(widthMeasureMode, performLayout),
|
||||||
cachedResults->computedWidth,
|
YGMeasureModeName(heightMeasureMode, performLayout),
|
||||||
cachedResults->computedHeight,
|
availableWidth,
|
||||||
reason);
|
availableHeight,
|
||||||
|
cachedResults->computedWidth,
|
||||||
|
cachedResults->computedHeight,
|
||||||
|
reason);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (gPrintChanges) {
|
if (gPrintChanges) {
|
||||||
YGLog(node, YGLogLevelVerbose, "%s%d.{%s", YGSpacer(gDepth), gDepth, needToVisitNode ? "*" : "");
|
YGLog(
|
||||||
|
node,
|
||||||
|
YGLogLevelVerbose,
|
||||||
|
"%s%d.{%s",
|
||||||
|
YGSpacer(gDepth),
|
||||||
|
gDepth,
|
||||||
|
needToVisitNode ? "*" : "");
|
||||||
if (node->print) {
|
if (node->print) {
|
||||||
node->print(node);
|
node->print(node);
|
||||||
}
|
}
|
||||||
YGLog(node, YGLogLevelVerbose, "wm: %s, hm: %s, aw: %f ah: %f %s\n",
|
YGLog(
|
||||||
YGMeasureModeName(widthMeasureMode, performLayout),
|
node,
|
||||||
YGMeasureModeName(heightMeasureMode, performLayout),
|
YGLogLevelVerbose,
|
||||||
availableWidth,
|
"wm: %s, hm: %s, aw: %f ah: %f %s\n",
|
||||||
availableHeight,
|
YGMeasureModeName(widthMeasureMode, performLayout),
|
||||||
reason);
|
YGMeasureModeName(heightMeasureMode, performLayout),
|
||||||
|
availableWidth,
|
||||||
|
availableHeight,
|
||||||
|
reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
YGNodelayoutImpl(node,
|
YGNodelayoutImpl(node,
|
||||||
@@ -3542,21 +3584,30 @@ bool YGLayoutNodeInternal(const YGNodeRef node,
|
|||||||
config);
|
config);
|
||||||
|
|
||||||
if (gPrintChanges) {
|
if (gPrintChanges) {
|
||||||
YGLog(node, YGLogLevelVerbose, "%s%d.}%s", YGSpacer(gDepth), gDepth, needToVisitNode ? "*" : "");
|
YGLog(
|
||||||
|
node,
|
||||||
|
YGLogLevelVerbose,
|
||||||
|
"%s%d.}%s",
|
||||||
|
YGSpacer(gDepth),
|
||||||
|
gDepth,
|
||||||
|
needToVisitNode ? "*" : "");
|
||||||
if (node->print) {
|
if (node->print) {
|
||||||
node->print(node);
|
node->print(node);
|
||||||
}
|
}
|
||||||
YGLog(node, YGLogLevelVerbose, "wm: %s, hm: %s, d: (%f, %f) %s\n",
|
YGLog(
|
||||||
YGMeasureModeName(widthMeasureMode, performLayout),
|
node,
|
||||||
YGMeasureModeName(heightMeasureMode, performLayout),
|
YGLogLevelVerbose,
|
||||||
layout->measuredDimensions[YGDimensionWidth],
|
"wm: %s, hm: %s, d: (%f, %f) %s\n",
|
||||||
layout->measuredDimensions[YGDimensionHeight],
|
YGMeasureModeName(widthMeasureMode, performLayout),
|
||||||
reason);
|
YGMeasureModeName(heightMeasureMode, performLayout),
|
||||||
|
layout->measuredDimensions[YGDimensionWidth],
|
||||||
|
layout->measuredDimensions[YGDimensionHeight],
|
||||||
|
reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
layout->lastParentDirection = parentDirection;
|
layout->lastParentDirection = parentDirection;
|
||||||
|
|
||||||
if (cachedResults == NULL) {
|
if (cachedResults == nullptr) {
|
||||||
if (layout->nextCachedMeasurementsIndex == YG_MAX_CACHED_RESULT_COUNT) {
|
if (layout->nextCachedMeasurementsIndex == YG_MAX_CACHED_RESULT_COUNT) {
|
||||||
if (gPrintChanges) {
|
if (gPrintChanges) {
|
||||||
YGLog(node, YGLogLevelVerbose, "Out of cache entries!\n");
|
YGLog(node, YGLogLevelVerbose, "Out of cache entries!\n");
|
||||||
@@ -3592,7 +3643,7 @@ bool YGLayoutNodeInternal(const YGNodeRef node,
|
|||||||
|
|
||||||
gDepth--;
|
gDepth--;
|
||||||
layout->generationCount = gCurrentGenerationCount;
|
layout->generationCount = gCurrentGenerationCount;
|
||||||
return (needToVisitNode || cachedResults == NULL);
|
return (needToVisitNode || cachedResults == nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGConfigSetPointScaleFactor(const YGConfigRef config, const float pixelsInPoint) {
|
void YGConfigSetPointScaleFactor(const YGConfigRef config, const float pixelsInPoint) {
|
||||||
@@ -3719,13 +3770,17 @@ void YGNodeCalculateLayout(const YGNodeRef node,
|
|||||||
YGRoundToPixelGrid(node, node->config->pointScaleFactor, 0.0f, 0.0f);
|
YGRoundToPixelGrid(node, node->config->pointScaleFactor, 0.0f, 0.0f);
|
||||||
|
|
||||||
if (gPrintTree) {
|
if (gPrintTree) {
|
||||||
YGNodePrint(node, YGPrintOptionsLayout | YGPrintOptionsChildren | YGPrintOptionsStyle);
|
YGNodePrint(
|
||||||
|
node,
|
||||||
|
(YGPrintOptions)(
|
||||||
|
YGPrintOptionsLayout | YGPrintOptionsChildren |
|
||||||
|
YGPrintOptionsStyle));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGConfigSetLogger(const YGConfigRef config, YGLogger logger) {
|
void YGConfigSetLogger(const YGConfigRef config, YGLogger logger) {
|
||||||
if (logger != NULL) {
|
if (logger != nullptr) {
|
||||||
config->logger = logger;
|
config->logger = logger;
|
||||||
} else {
|
} else {
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
@@ -3741,7 +3796,7 @@ static void YGVLog(const YGConfigRef config,
|
|||||||
YGLogLevel level,
|
YGLogLevel level,
|
||||||
const char *format,
|
const char *format,
|
||||||
va_list args) {
|
va_list args) {
|
||||||
const YGConfigRef logConfig = config != NULL ? config : &gYGConfigDefaults;
|
const YGConfigRef logConfig = config != nullptr ? config : &gYGConfigDefaults;
|
||||||
logConfig->logger(logConfig, node, level, format, args);
|
logConfig->logger(logConfig, node, level, format, args);
|
||||||
|
|
||||||
if (level == YGLogLevelFatal) {
|
if (level == YGLogLevelFatal) {
|
||||||
@@ -3752,20 +3807,20 @@ static void YGVLog(const YGConfigRef config,
|
|||||||
void YGLogWithConfig(const YGConfigRef config, YGLogLevel level, const char *format, ...) {
|
void YGLogWithConfig(const YGConfigRef config, YGLogLevel level, const char *format, ...) {
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
YGVLog(config, NULL, level, format, args);
|
YGVLog(config, nullptr, level, format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGLog(const YGNodeRef node, YGLogLevel level, const char *format, ...) {
|
void YGLog(const YGNodeRef node, YGLogLevel level, const char *format, ...) {
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
YGVLog(node == NULL ? NULL : node->config, node, level, format, args);
|
YGVLog(node == nullptr ? nullptr : node->config, node, level, format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGAssert(const bool condition, const char *message) {
|
void YGAssert(const bool condition, const char *message) {
|
||||||
if (!condition) {
|
if (!condition) {
|
||||||
YGLog(NULL, YGLogLevelFatal, "%s\n", message);
|
YGLog(nullptr, YGLogLevelFatal, "%s\n", message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@@ -65,11 +65,6 @@ typedef void (*YGNodeClonedFunc)(YGNodeRef oldNode,
|
|||||||
YGNodeRef parent,
|
YGNodeRef parent,
|
||||||
int childIndex);
|
int childIndex);
|
||||||
|
|
||||||
typedef void *(*YGMalloc)(size_t size);
|
|
||||||
typedef void *(*YGCalloc)(size_t count, size_t size);
|
|
||||||
typedef void *(*YGRealloc)(void *ptr, size_t size);
|
|
||||||
typedef void (*YGFree)(void *ptr);
|
|
||||||
|
|
||||||
// YGNode
|
// YGNode
|
||||||
WIN_EXPORT YGNodeRef YGNodeNew(void);
|
WIN_EXPORT YGNodeRef YGNodeNew(void);
|
||||||
WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config);
|
WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config);
|
||||||
|
Reference in New Issue
Block a user