diff --git a/csharp/Yoga/Yoga.vcxproj b/csharp/Yoga/Yoga.vcxproj
index d93172c9..489492cb 100755
--- a/csharp/Yoga/Yoga.vcxproj
+++ b/csharp/Yoga/Yoga.vcxproj
@@ -227,19 +227,31 @@
-
+
+
+
+
-
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
false
diff --git a/csharp/Yoga/Yoga.vcxproj.filters b/csharp/Yoga/Yoga.vcxproj.filters
index 46d05f8a..3243c630 100755
--- a/csharp/Yoga/Yoga.vcxproj.filters
+++ b/csharp/Yoga/Yoga.vcxproj.filters
@@ -21,19 +21,40 @@
Header Files
-
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
Header Files
Header Files
-
+
Header Files
-
+
Header Files
-
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
Header Files
@@ -44,15 +65,36 @@
Source Files
-
- Source Files
-
-
- Source Files
-
Source Files
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
diff --git a/yoga/YGConfig.cpp b/yoga/YGConfig.cpp
new file mode 100644
index 00000000..5cee5278
--- /dev/null
+++ b/yoga/YGConfig.cpp
@@ -0,0 +1,19 @@
+/**
+ * Copyright (c) 2014-present, Facebook, Inc.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
+
+#include "YGConfig.h"
+
+const std::array
+ kYGDefaultExperimentalFeatures = {{false}};
+
+YGConfig::YGConfig(YGLogger logger)
+ : experimentalFeatures(kYGDefaultExperimentalFeatures),
+ useWebDefaults(false),
+ useLegacyStretchBehaviour(false),
+ shouldDiffLayoutWithoutLegacyStretchBehaviour(false),
+ pointScaleFactor(1.0f), logger(logger), cloneNodeCallback(nullptr),
+ context(nullptr) {}
diff --git a/yoga/YGConfig.h b/yoga/YGConfig.h
new file mode 100644
index 00000000..0f655d1b
--- /dev/null
+++ b/yoga/YGConfig.h
@@ -0,0 +1,23 @@
+/**
+ * Copyright (c) 2014-present, Facebook, Inc.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
+
+#pragma once
+#include "Yoga-internal.h"
+#include "Yoga.h"
+
+struct YGConfig {
+ std::array experimentalFeatures;
+ bool useWebDefaults;
+ bool useLegacyStretchBehaviour;
+ bool shouldDiffLayoutWithoutLegacyStretchBehaviour;
+ float pointScaleFactor;
+ YGLogger logger;
+ YGCloneNodeFunc cloneNodeCallback;
+ void* context;
+
+ YGConfig(YGLogger logger);
+};
diff --git a/yoga/YGNode.h b/yoga/YGNode.h
index 5f7038f4..96541a57 100644
--- a/yoga/YGNode.h
+++ b/yoga/YGNode.h
@@ -7,6 +7,7 @@
#pragma once
#include
+#include "YGConfig.h"
#include "YGLayout.h"
#include "YGStyle.h"
#include "Yoga-internal.h"
diff --git a/yoga/Yoga-internal.h b/yoga/Yoga-internal.h
index d11f8c29..be1d9632 100644
--- a/yoga/Yoga-internal.h
+++ b/yoga/Yoga-internal.h
@@ -87,16 +87,6 @@ struct YGCachedMeasurement {
// layouts should not require more than 16 entries to fit within the cache.
#define YG_MAX_CACHED_RESULT_COUNT 16
-struct YGConfig {
- bool experimentalFeatures[YGExperimentalFeatureCount + 1];
- bool useWebDefaults;
- bool useLegacyStretchBehaviour;
- bool shouldDiffLayoutWithoutLegacyStretchBehaviour;
- float pointScaleFactor;
- YGLogger logger;
- YGCloneNodeFunc cloneNodeCallback;
- void* context;
-};
static const float kDefaultFlexGrow = 0.0f;
static const float kDefaultFlexShrink = 0.0f;
diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp
index 11c0fddd..ca0b834b 100644
--- a/yoga/Yoga.cpp
+++ b/yoga/Yoga.cpp
@@ -41,25 +41,7 @@ static int YGDefaultLog(const YGConfigRef config,
va_list args);
#endif
-static YGConfig gYGConfigDefaults = {
- .experimentalFeatures =
- {
- [YGExperimentalFeatureWebFlexBasis] = false,
- },
- .useWebDefaults = false,
- .useLegacyStretchBehaviour = false,
- .shouldDiffLayoutWithoutLegacyStretchBehaviour = false,
- .pointScaleFactor = 1.0f,
-#ifdef ANDROID
- .logger = &YGAndroidLog,
-#else
- .logger = &YGDefaultLog,
-#endif
- .cloneNodeCallback = nullptr,
- .context = nullptr,
-};
-
-const YGValue YGValueZero = {.value = 0, .unit = YGUnitPoint};
+const YGValue YGValueZero = {0, YGUnitPoint};
const YGValue YGValueUndefined = {YGUndefined, YGUnitUndefined};
const YGValue YGValueAuto = {YGUndefined, YGUnitAuto};
@@ -246,8 +228,13 @@ WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config) {
return node;
}
+YGConfigRef YGConfigGetDefault() {
+ static YGConfigRef defaultConfig = YGConfigNew();
+ return defaultConfig;
+}
+
YGNodeRef YGNodeNew(void) {
- return YGNodeNewWithConfig(&gYGConfigDefaults);
+ return YGNodeNewWithConfig(YGConfigGetDefault());
}
YGNodeRef YGNodeClone(YGNodeRef oldNode) {
@@ -363,19 +350,13 @@ int32_t YGConfigGetInstanceCount(void) {
return gConfigInstanceCount;
}
-// Export only for C#
-YGConfigRef YGConfigGetDefault() {
- return &gYGConfigDefaults;
-}
-
YGConfigRef YGConfigNew(void) {
- const YGConfigRef config = (const YGConfigRef)malloc(sizeof(YGConfig));
- YGAssert(config != nullptr, "Could not allocate memory for config");
- if (config == nullptr) {
- abort();
- }
+ #ifdef ANDROID
+ const YGConfigRef config = new YGConfig(YGAndroidLog);
+ #else
+ const YGConfigRef config = new YGConfig(YGDefaultLog);
+ #endif
gConfigInstanceCount++;
- memcpy(config, &gYGConfigDefaults, sizeof(YGConfig));
return config;
}
@@ -590,79 +571,78 @@ float YGNodeStyleGetFlexShrink(const YGNodeRef node) {
} \
}
-#define YG_NODE_STYLE_PROPERTY_SETTER_UNIT_IMPL( \
- type, name, paramName, instanceName) \
- void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \
- YGValue value = { \
- .value = YGFloatSanitize(paramName), \
- .unit = YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint, \
- }; \
- if ((node->getStyle().instanceName.value != value.value && \
- value.unit != YGUnitUndefined) || \
- node->getStyle().instanceName.unit != value.unit) { \
- YGStyle style = node->getStyle(); \
- style.instanceName = value; \
- node->setStyle(style); \
- node->markDirtyAndPropogate(); \
- } \
- } \
- \
- void YGNodeStyleSet##name##Percent( \
- const YGNodeRef node, const type paramName) { \
- YGValue value = { \
- .value = YGFloatSanitize(paramName), \
- .unit = \
- YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPercent, \
- }; \
- if ((node->getStyle().instanceName.value != value.value && \
- value.unit != YGUnitUndefined) || \
- node->getStyle().instanceName.unit != value.unit) { \
- YGStyle style = node->getStyle(); \
- \
- style.instanceName = value; \
- node->setStyle(style); \
- node->markDirtyAndPropogate(); \
- } \
+#define YG_NODE_STYLE_PROPERTY_SETTER_UNIT_IMPL( \
+ type, name, paramName, instanceName) \
+ void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \
+ YGValue value = { \
+ YGFloatSanitize(paramName), \
+ YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint, \
+ }; \
+ if ((node->getStyle().instanceName.value != value.value && \
+ value.unit != YGUnitUndefined) || \
+ node->getStyle().instanceName.unit != value.unit) { \
+ YGStyle style = node->getStyle(); \
+ style.instanceName = value; \
+ node->setStyle(style); \
+ node->markDirtyAndPropogate(); \
+ } \
+ } \
+ \
+ void YGNodeStyleSet##name##Percent( \
+ const YGNodeRef node, const type paramName) { \
+ YGValue value = { \
+ YGFloatSanitize(paramName), \
+ YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPercent, \
+ }; \
+ if ((node->getStyle().instanceName.value != value.value && \
+ value.unit != YGUnitUndefined) || \
+ node->getStyle().instanceName.unit != value.unit) { \
+ YGStyle style = node->getStyle(); \
+ \
+ style.instanceName = value; \
+ node->setStyle(style); \
+ node->markDirtyAndPropogate(); \
+ } \
}
-#define YG_NODE_STYLE_PROPERTY_SETTER_UNIT_AUTO_IMPL( \
- type, name, paramName, instanceName) \
- void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \
- YGValue value = { \
- .value = YGFloatSanitize(paramName), \
- .unit = YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint, \
- }; \
- if ((node->getStyle().instanceName.value != value.value && \
- value.unit != YGUnitUndefined) || \
- node->getStyle().instanceName.unit != value.unit) { \
- YGStyle style = node->getStyle(); \
- style.instanceName = value; \
- node->setStyle(style); \
- node->markDirtyAndPropogate(); \
- } \
- } \
- \
- void YGNodeStyleSet##name##Percent( \
- const YGNodeRef node, const type paramName) { \
- if (node->getStyle().instanceName.value != YGFloatSanitize(paramName) || \
- node->getStyle().instanceName.unit != YGUnitPercent) { \
- YGStyle style = node->getStyle(); \
- style.instanceName.value = YGFloatSanitize(paramName); \
- style.instanceName.unit = \
- YGFloatIsUndefined(paramName) ? YGUnitAuto : YGUnitPercent; \
- node->setStyle(style); \
- node->markDirtyAndPropogate(); \
- } \
- } \
- \
- void YGNodeStyleSet##name##Auto(const YGNodeRef node) { \
- if (node->getStyle().instanceName.unit != YGUnitAuto) { \
- YGStyle style = node->getStyle(); \
- style.instanceName.value = 0; \
- style.instanceName.unit = YGUnitAuto; \
- node->setStyle(style); \
- node->markDirtyAndPropogate(); \
- } \
+#define YG_NODE_STYLE_PROPERTY_SETTER_UNIT_AUTO_IMPL( \
+ type, name, paramName, instanceName) \
+ void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \
+ YGValue value = { \
+ YGFloatSanitize(paramName), \
+ YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint, \
+ }; \
+ if ((node->getStyle().instanceName.value != value.value && \
+ value.unit != YGUnitUndefined) || \
+ node->getStyle().instanceName.unit != value.unit) { \
+ YGStyle style = node->getStyle(); \
+ style.instanceName = value; \
+ node->setStyle(style); \
+ node->markDirtyAndPropogate(); \
+ } \
+ } \
+ \
+ void YGNodeStyleSet##name##Percent( \
+ const YGNodeRef node, const type paramName) { \
+ if (node->getStyle().instanceName.value != YGFloatSanitize(paramName) || \
+ node->getStyle().instanceName.unit != YGUnitPercent) { \
+ YGStyle style = node->getStyle(); \
+ style.instanceName.value = YGFloatSanitize(paramName); \
+ style.instanceName.unit = \
+ YGFloatIsUndefined(paramName) ? YGUnitAuto : YGUnitPercent; \
+ node->setStyle(style); \
+ node->markDirtyAndPropogate(); \
+ } \
+ } \
+ \
+ void YGNodeStyleSet##name##Auto(const YGNodeRef node) { \
+ if (node->getStyle().instanceName.unit != YGUnitAuto) { \
+ YGStyle style = node->getStyle(); \
+ style.instanceName.value = 0; \
+ style.instanceName.unit = YGUnitAuto; \
+ node->setStyle(style); \
+ node->markDirtyAndPropogate(); \
+ } \
}
#define YG_NODE_STYLE_PROPERTY_IMPL(type, name, paramName, instanceName) \
@@ -708,48 +688,47 @@ float YGNodeStyleGetFlexShrink(const YGNodeRef node) {
} \
}
-#define YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL( \
- type, name, paramName, instanceName) \
- void YGNodeStyleSet##name( \
- const YGNodeRef node, const YGEdge edge, const float paramName) { \
- YGValue value = { \
- .value = YGFloatSanitize(paramName), \
- .unit = YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint, \
- }; \
- if ((node->getStyle().instanceName[edge].value != value.value && \
- value.unit != YGUnitUndefined) || \
- node->getStyle().instanceName[edge].unit != value.unit) { \
- YGStyle style = node->getStyle(); \
- style.instanceName[edge] = value; \
- node->setStyle(style); \
- node->markDirtyAndPropogate(); \
- } \
- } \
- \
- void YGNodeStyleSet##name##Percent( \
- const YGNodeRef node, const YGEdge edge, const float paramName) { \
- YGValue value = { \
- .value = YGFloatSanitize(paramName), \
- .unit = \
- YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPercent, \
- }; \
- if ((node->getStyle().instanceName[edge].value != value.value && \
- value.unit != YGUnitUndefined) || \
- node->getStyle().instanceName[edge].unit != value.unit) { \
- YGStyle style = node->getStyle(); \
- style.instanceName[edge] = value; \
- node->setStyle(style); \
- node->markDirtyAndPropogate(); \
- } \
- } \
- \
- WIN_STRUCT(type) \
- YGNodeStyleGet##name(const YGNodeRef node, const YGEdge edge) { \
- YGValue value = node->getStyle().instanceName[edge]; \
- if (value.unit == YGUnitUndefined || value.unit == YGUnitAuto) { \
- value.value = YGUndefined; \
- } \
- return WIN_STRUCT_REF(value); \
+#define YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL( \
+ type, name, paramName, instanceName) \
+ void YGNodeStyleSet##name( \
+ const YGNodeRef node, const YGEdge edge, const float paramName) { \
+ YGValue value = { \
+ YGFloatSanitize(paramName), \
+ YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint, \
+ }; \
+ if ((node->getStyle().instanceName[edge].value != value.value && \
+ value.unit != YGUnitUndefined) || \
+ node->getStyle().instanceName[edge].unit != value.unit) { \
+ YGStyle style = node->getStyle(); \
+ style.instanceName[edge] = value; \
+ node->setStyle(style); \
+ node->markDirtyAndPropogate(); \
+ } \
+ } \
+ \
+ void YGNodeStyleSet##name##Percent( \
+ const YGNodeRef node, const YGEdge edge, const float paramName) { \
+ YGValue value = { \
+ YGFloatSanitize(paramName), \
+ YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPercent, \
+ }; \
+ if ((node->getStyle().instanceName[edge].value != value.value && \
+ value.unit != YGUnitUndefined) || \
+ node->getStyle().instanceName[edge].unit != value.unit) { \
+ YGStyle style = node->getStyle(); \
+ style.instanceName[edge] = value; \
+ node->setStyle(style); \
+ node->markDirtyAndPropogate(); \
+ } \
+ } \
+ \
+ WIN_STRUCT(type) \
+ YGNodeStyleGet##name(const YGNodeRef node, const YGEdge edge) { \
+ YGValue value = node->getStyle().instanceName[edge]; \
+ if (value.unit == YGUnitUndefined || value.unit == YGUnitAuto) { \
+ value.value = YGUndefined; \
+ } \
+ return WIN_STRUCT_REF(value); \
}
#define YG_NODE_LAYOUT_PROPERTY_IMPL(type, name, instanceName) \
@@ -858,8 +837,8 @@ YGValue YGNodeStyleGetFlexBasis(const YGNodeRef node) {
void YGNodeStyleSetFlexBasis(const YGNodeRef node, const float flexBasis) {
YGValue value = {
- .value = YGFloatSanitize(flexBasis),
- .unit = YGFloatIsUndefined(flexBasis) ? YGUnitUndefined : YGUnitPoint,
+ YGFloatSanitize(flexBasis),
+ YGFloatIsUndefined(flexBasis) ? YGUnitUndefined : YGUnitPoint,
};
if ((node->getStyle().flexBasis.value != value.value &&
value.unit != YGUnitUndefined) ||
@@ -906,8 +885,8 @@ void YGNodeStyleSetBorder(
const YGEdge edge,
const float border) {
YGValue value = {
- .value = YGFloatSanitize(border),
- .unit = YGFloatIsUndefined(border) ? YGUnitUndefined : YGUnitPoint,
+ YGFloatSanitize(border),
+ YGFloatIsUndefined(border) ? YGUnitUndefined : YGUnitPoint,
};
if ((node->getStyle().border[edge].value != value.value &&
value.unit != YGUnitUndefined) ||
@@ -3977,7 +3956,7 @@ static void YGVLog(const YGConfigRef config,
YGLogLevel level,
const char *format,
va_list args) {
- const YGConfigRef logConfig = config != nullptr ? config : &gYGConfigDefaults;
+ const YGConfigRef logConfig = config != nullptr ? config : YGConfigGetDefault();
logConfig->logger(logConfig, node, level, format, args);
if (level == YGLogLevelFatal) {