Revert D48712710: C++ Cleanup 3/N: Reorganize YGNode
Differential Revision: D48712710 Original commit changeset: d28eae38469a Original Phabricator Diff: D48712710 fbshipit-source-id: 7a10b071edcf045ce98bbf8f9deca0d0e2e80a14
This commit is contained in:
committed by
Facebook GitHub Bot
parent
6ca56e87ce
commit
ea7f61a3db
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
// TODO: Reconcile missing layoutContext functionality from callbacks in the C
|
// TODO: Reconcile missing layoutContext functionality from callbacks in the C
|
||||||
// API and use that
|
// API and use that
|
||||||
#include <yoga/node/Node.h>
|
#include <yoga/YGNode.h>
|
||||||
|
|
||||||
using namespace facebook;
|
using namespace facebook;
|
||||||
using namespace facebook::yoga;
|
using namespace facebook::yoga;
|
||||||
@@ -688,7 +688,7 @@ static void jni_YGNodeSetHasMeasureFuncJNI(
|
|||||||
jobject /*obj*/,
|
jobject /*obj*/,
|
||||||
jlong nativePointer,
|
jlong nativePointer,
|
||||||
jboolean hasMeasureFunc) {
|
jboolean hasMeasureFunc) {
|
||||||
static_cast<yoga::Node*>(_jlong2YGNodeRef(nativePointer))
|
_jlong2YGNodeRef(nativePointer)
|
||||||
->setMeasureFunc(hasMeasureFunc ? YGJNIMeasureFunc : nullptr);
|
->setMeasureFunc(hasMeasureFunc ? YGJNIMeasureFunc : nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -715,7 +715,7 @@ static void jni_YGNodeSetHasBaselineFuncJNI(
|
|||||||
jobject /*obj*/,
|
jobject /*obj*/,
|
||||||
jlong nativePointer,
|
jlong nativePointer,
|
||||||
jboolean hasBaselineFunc) {
|
jboolean hasBaselineFunc) {
|
||||||
static_cast<yoga::Node*>(_jlong2YGNodeRef(nativePointer))
|
_jlong2YGNodeRef(nativePointer)
|
||||||
->setBaselineFunc(hasBaselineFunc ? YGJNIBaselineFunc : nullptr);
|
->setBaselineFunc(hasBaselineFunc ? YGJNIBaselineFunc : nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -14,12 +14,11 @@
|
|||||||
#include "jni.h"
|
#include "jni.h"
|
||||||
|
|
||||||
class PtrJNodeMapVanilla {
|
class PtrJNodeMapVanilla {
|
||||||
std::map<YGNodeConstRef, size_t> ptrsToIdxs_{};
|
std::map<YGNodeRef, size_t> ptrsToIdxs_;
|
||||||
jobjectArray javaNodes_{};
|
jobjectArray javaNodes_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PtrJNodeMapVanilla() = default;
|
PtrJNodeMapVanilla() : ptrsToIdxs_{}, javaNodes_{} {}
|
||||||
|
|
||||||
PtrJNodeMapVanilla(jlongArray javaNativePointers, jobjectArray javaNodes)
|
PtrJNodeMapVanilla(jlongArray javaNativePointers, jobjectArray javaNodes)
|
||||||
: javaNodes_{javaNodes} {
|
: javaNodes_{javaNodes} {
|
||||||
using namespace facebook::yoga::vanillajni;
|
using namespace facebook::yoga::vanillajni;
|
||||||
@@ -31,11 +30,11 @@ public:
|
|||||||
javaNativePointers, 0, nativePointersSize, nativePointers.data());
|
javaNativePointers, 0, nativePointersSize, nativePointers.data());
|
||||||
|
|
||||||
for (size_t i = 0; i < nativePointersSize; ++i) {
|
for (size_t i = 0; i < nativePointersSize; ++i) {
|
||||||
ptrsToIdxs_[(YGNodeConstRef) nativePointers[i]] = i;
|
ptrsToIdxs_[(YGNodeRef) nativePointers[i]] = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
facebook::yoga::vanillajni::ScopedLocalRef<jobject> ref(YGNodeConstRef node) {
|
facebook::yoga::vanillajni::ScopedLocalRef<jobject> ref(YGNodeRef node) {
|
||||||
using namespace facebook::yoga::vanillajni;
|
using namespace facebook::yoga::vanillajni;
|
||||||
|
|
||||||
JNIEnv* env = getCurrentEnv();
|
JNIEnv* env = getCurrentEnv();
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
#include <yoga/event/event.h>
|
#include <yoga/event/event.h>
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
#include <yoga/YGEnums.h>
|
#include <yoga/YGEnums.h>
|
||||||
|
#include <yoga/YGNode.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@@ -29,7 +30,7 @@ struct TypedEventTestData<Event::LayoutPassEnd> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct EventArgs {
|
struct EventArgs {
|
||||||
const YGNodeConstRef node;
|
const YGNode* node;
|
||||||
Event::Type type;
|
Event::Type type;
|
||||||
std::unique_ptr<void, std::function<void(void*)>> dataPtr;
|
std::unique_ptr<void, std::function<void(void*)>> dataPtr;
|
||||||
std::unique_ptr<void, std::function<void(void*)>> eventTestDataPtr;
|
std::unique_ptr<void, std::function<void(void*)>> eventTestDataPtr;
|
||||||
@@ -47,7 +48,7 @@ struct EventArgs {
|
|||||||
|
|
||||||
class EventTest : public ::testing::Test {
|
class EventTest : public ::testing::Test {
|
||||||
ScopedEventSubscription subscription = {&EventTest::listen};
|
ScopedEventSubscription subscription = {&EventTest::listen};
|
||||||
static void listen(YGNodeConstRef, Event::Type, Event::Data);
|
static void listen(const YGNode&, Event::Type, Event::Data);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static std::vector<EventArgs> events;
|
static std::vector<EventArgs> events;
|
||||||
@@ -283,16 +284,16 @@ TEST_F(EventTest, baseline_functions_get_wrapped) {
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
template <Event::Type E>
|
template <Event::Type E>
|
||||||
EventArgs createArgs(YGNodeConstRef node, const Event::Data data) {
|
EventArgs createArgs(const YGNode& node, const Event::Data data) {
|
||||||
using Data = Event::TypedData<E>;
|
using Data = Event::TypedData<E>;
|
||||||
auto deleteData = [](void* x) { delete static_cast<Data*>(x); };
|
auto deleteData = [](void* x) { delete static_cast<Data*>(x); };
|
||||||
|
|
||||||
return {node, E, {new Data{(data.get<E>())}, deleteData}, nullptr};
|
return {&node, E, {new Data{(data.get<E>())}, deleteData}, nullptr};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <Event::Type E>
|
template <Event::Type E>
|
||||||
EventArgs createArgs(
|
EventArgs createArgs(
|
||||||
YGNodeConstRef node,
|
const YGNode& node,
|
||||||
const Event::Data data,
|
const Event::Data data,
|
||||||
TypedEventTestData<E> eventTestData) {
|
TypedEventTestData<E> eventTestData) {
|
||||||
using EventTestData = TypedEventTestData<E>;
|
using EventTestData = TypedEventTestData<E>;
|
||||||
@@ -308,10 +309,7 @@ EventArgs createArgs(
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void EventTest::listen(
|
void EventTest::listen(const YGNode& node, Event::Type type, Event::Data data) {
|
||||||
YGNodeConstRef node,
|
|
||||||
Event::Type type,
|
|
||||||
Event::Data data) {
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Event::NodeAllocation:
|
case Event::NodeAllocation:
|
||||||
events.push_back(createArgs<Event::NodeAllocation>(node, data));
|
events.push_back(createArgs<Event::NodeAllocation>(node, data));
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include <yoga/YGNode.h>
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
|
|
||||||
static float _baselineFunc(
|
static float _baselineFunc(
|
||||||
@@ -196,7 +197,7 @@ TEST(YogaTest, align_baseline_parent_using_child_in_column_as_reference) {
|
|||||||
|
|
||||||
const YGNodeRef root_child1_child1 =
|
const YGNodeRef root_child1_child1 =
|
||||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||||
YGNodeSetBaselineFunc(root_child1_child1, _baselineFunc);
|
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||||
YGNodeInsertChild(root_child1, root_child1_child1, 1);
|
YGNodeInsertChild(root_child1, root_child1_child1, 1);
|
||||||
|
|
||||||
@@ -241,7 +242,7 @@ TEST(
|
|||||||
|
|
||||||
const YGNodeRef root_child1_child1 =
|
const YGNodeRef root_child1_child1 =
|
||||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||||
YGNodeSetBaselineFunc(root_child1_child1, _baselineFunc);
|
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||||
YGNodeStyleSetPadding(root_child1_child1, YGEdgeLeft, 100);
|
YGNodeStyleSetPadding(root_child1_child1, YGEdgeLeft, 100);
|
||||||
YGNodeStyleSetPadding(root_child1_child1, YGEdgeRight, 100);
|
YGNodeStyleSetPadding(root_child1_child1, YGEdgeRight, 100);
|
||||||
@@ -294,7 +295,7 @@ TEST(
|
|||||||
|
|
||||||
const YGNodeRef root_child1_child1 =
|
const YGNodeRef root_child1_child1 =
|
||||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||||
YGNodeSetBaselineFunc(root_child1_child1, _baselineFunc);
|
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||||
YGNodeInsertChild(root_child1, root_child1_child1, 1);
|
YGNodeInsertChild(root_child1, root_child1_child1, 1);
|
||||||
|
|
||||||
@@ -343,7 +344,7 @@ TEST(
|
|||||||
|
|
||||||
const YGNodeRef root_child1_child1 =
|
const YGNodeRef root_child1_child1 =
|
||||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||||
YGNodeSetBaselineFunc(root_child1_child1, _baselineFunc);
|
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||||
YGNodeInsertChild(root_child1, root_child1_child1, 1);
|
YGNodeInsertChild(root_child1, root_child1_child1, 1);
|
||||||
|
|
||||||
@@ -388,7 +389,7 @@ TEST(
|
|||||||
|
|
||||||
const YGNodeRef root_child1_child1 =
|
const YGNodeRef root_child1_child1 =
|
||||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||||
YGNodeSetBaselineFunc(root_child1_child1, _baselineFunc);
|
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||||
YGNodeStyleSetMargin(root_child1_child1, YGEdgeLeft, 100);
|
YGNodeStyleSetMargin(root_child1_child1, YGEdgeLeft, 100);
|
||||||
YGNodeStyleSetMargin(root_child1_child1, YGEdgeRight, 100);
|
YGNodeStyleSetMargin(root_child1_child1, YGEdgeRight, 100);
|
||||||
@@ -435,7 +436,7 @@ TEST(YogaTest, align_baseline_parent_using_child_in_row_as_reference) {
|
|||||||
|
|
||||||
const YGNodeRef root_child1_child1 =
|
const YGNodeRef root_child1_child1 =
|
||||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||||
YGNodeSetBaselineFunc(root_child1_child1, _baselineFunc);
|
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||||
YGNodeInsertChild(root_child1, root_child1_child1, 1);
|
YGNodeInsertChild(root_child1, root_child1_child1, 1);
|
||||||
|
|
||||||
@@ -480,7 +481,7 @@ TEST(
|
|||||||
|
|
||||||
const YGNodeRef root_child1_child1 =
|
const YGNodeRef root_child1_child1 =
|
||||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||||
YGNodeSetBaselineFunc(root_child1_child1, _baselineFunc);
|
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||||
YGNodeStyleSetPadding(root_child1_child1, YGEdgeLeft, 100);
|
YGNodeStyleSetPadding(root_child1_child1, YGEdgeLeft, 100);
|
||||||
YGNodeStyleSetPadding(root_child1_child1, YGEdgeRight, 100);
|
YGNodeStyleSetPadding(root_child1_child1, YGEdgeRight, 100);
|
||||||
@@ -529,7 +530,7 @@ TEST(
|
|||||||
|
|
||||||
const YGNodeRef root_child1_child1 =
|
const YGNodeRef root_child1_child1 =
|
||||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||||
YGNodeSetBaselineFunc(root_child1_child1, _baselineFunc);
|
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||||
YGNodeStyleSetMargin(root_child1_child1, YGEdgeLeft, 100);
|
YGNodeStyleSetMargin(root_child1_child1, YGEdgeLeft, 100);
|
||||||
YGNodeStyleSetMargin(root_child1_child1, YGEdgeRight, 100);
|
YGNodeStyleSetMargin(root_child1_child1, YGEdgeRight, 100);
|
||||||
@@ -669,7 +670,7 @@ TEST(
|
|||||||
|
|
||||||
const YGNodeRef root_child1_child1 =
|
const YGNodeRef root_child1_child1 =
|
||||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||||
YGNodeSetBaselineFunc(root_child1_child1, _baselineFunc);
|
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||||
YGNodeInsertChild(root_child1, root_child1_child1, 1);
|
YGNodeInsertChild(root_child1, root_child1_child1, 1);
|
||||||
|
|
||||||
@@ -720,7 +721,7 @@ TEST(
|
|||||||
|
|
||||||
const YGNodeRef root_child1_child1 =
|
const YGNodeRef root_child1_child1 =
|
||||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||||
YGNodeSetBaselineFunc(root_child1_child1, _baselineFunc);
|
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||||
YGNodeInsertChild(root_child1, root_child1_child1, 1);
|
YGNodeInsertChild(root_child1, root_child1_child1, 1);
|
||||||
|
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include <yoga/YGNode.h>
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
|
|
||||||
static YGSize _measure(
|
static YGSize _measure(
|
||||||
@@ -448,7 +449,7 @@ TEST(YogaTest, aspect_ratio_with_measure_func) {
|
|||||||
YGNodeStyleSetHeight(root, 100);
|
YGNodeStyleSetHeight(root, 100);
|
||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
root_child0->setMeasureFunc(_measure);
|
||||||
YGNodeStyleSetAspectRatio(root_child0, 1);
|
YGNodeStyleSetAspectRatio(root_child0, 1);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
|
@@ -6,13 +6,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include <yoga/YGNode.h>
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
|
|
||||||
static float _baseline(
|
static float _baseline(
|
||||||
YGNodeRef node,
|
YGNodeRef node,
|
||||||
const float /*width*/,
|
const float /*width*/,
|
||||||
const float /*height*/) {
|
const float /*height*/) {
|
||||||
float* baseline = (float*) YGNodeGetContext(node);
|
float* baseline = (float*) node->getContext();
|
||||||
return *baseline;
|
return *baseline;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,9 +36,9 @@ TEST(YogaTest, align_baseline_customer_func) {
|
|||||||
|
|
||||||
float baselineValue = 10;
|
float baselineValue = 10;
|
||||||
const YGNodeRef root_child1_child0 = YGNodeNew();
|
const YGNodeRef root_child1_child0 = YGNodeNew();
|
||||||
YGNodeSetContext(root_child1_child0, &baselineValue);
|
root_child1_child0->setContext(&baselineValue);
|
||||||
YGNodeStyleSetWidth(root_child1_child0, 50);
|
YGNodeStyleSetWidth(root_child1_child0, 50);
|
||||||
YGNodeSetBaselineFunc(root_child1_child0, _baseline);
|
root_child1_child0->setBaselineFunc(_baseline);
|
||||||
YGNodeStyleSetHeight(root_child1_child0, 20);
|
YGNodeStyleSetHeight(root_child1_child0, 20);
|
||||||
YGNodeInsertChild(root_child1, root_child1_child0, 0);
|
YGNodeInsertChild(root_child1, root_child1_child0, 0);
|
||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
@@ -6,13 +6,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/YGNode.h>
|
||||||
#include <yoga/node/Node.h>
|
|
||||||
|
|
||||||
using namespace facebook;
|
|
||||||
|
|
||||||
static void _dirtied(YGNodeRef node) {
|
static void _dirtied(YGNodeRef node) {
|
||||||
int* dirtiedCount = (int*) YGNodeGetContext(node);
|
int* dirtiedCount = (int*) node->getContext();
|
||||||
(*dirtiedCount)++;
|
(*dirtiedCount)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,17 +22,17 @@ TEST(YogaTest, dirtied) {
|
|||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
|
||||||
int dirtiedCount = 0;
|
int dirtiedCount = 0;
|
||||||
YGNodeSetContext(root, &dirtiedCount);
|
root->setContext(&dirtiedCount);
|
||||||
YGNodeSetDirtiedFunc(root, _dirtied);
|
root->setDirtiedFunc(_dirtied);
|
||||||
|
|
||||||
ASSERT_EQ(0, dirtiedCount);
|
ASSERT_EQ(0, dirtiedCount);
|
||||||
|
|
||||||
// `_dirtied` MUST be called in case of explicit dirtying.
|
// `_dirtied` MUST be called in case of explicit dirtying.
|
||||||
static_cast<yoga::Node*>(root)->setDirty(true);
|
root->setDirty(true);
|
||||||
ASSERT_EQ(1, dirtiedCount);
|
ASSERT_EQ(1, dirtiedCount);
|
||||||
|
|
||||||
// `_dirtied` MUST be called ONCE.
|
// `_dirtied` MUST be called ONCE.
|
||||||
static_cast<yoga::Node*>(root)->setDirty(true);
|
root->setDirty(true);
|
||||||
ASSERT_EQ(1, dirtiedCount);
|
ASSERT_EQ(1, dirtiedCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,17 +55,17 @@ TEST(YogaTest, dirtied_propagation) {
|
|||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
|
||||||
int dirtiedCount = 0;
|
int dirtiedCount = 0;
|
||||||
YGNodeSetContext(root, &dirtiedCount);
|
root->setContext(&dirtiedCount);
|
||||||
YGNodeSetDirtiedFunc(root, _dirtied);
|
root->setDirtiedFunc(_dirtied);
|
||||||
|
|
||||||
ASSERT_EQ(0, dirtiedCount);
|
ASSERT_EQ(0, dirtiedCount);
|
||||||
|
|
||||||
// `_dirtied` MUST be called for the first time.
|
// `_dirtied` MUST be called for the first time.
|
||||||
static_cast<yoga::Node*>(root_child0)->markDirtyAndPropagate();
|
root_child0->markDirtyAndPropagate();
|
||||||
ASSERT_EQ(1, dirtiedCount);
|
ASSERT_EQ(1, dirtiedCount);
|
||||||
|
|
||||||
// `_dirtied` must NOT be called for the second time.
|
// `_dirtied` must NOT be called for the second time.
|
||||||
static_cast<yoga::Node*>(root_child0)->markDirtyAndPropagate();
|
root_child0->markDirtyAndPropagate();
|
||||||
ASSERT_EQ(1, dirtiedCount);
|
ASSERT_EQ(1, dirtiedCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,20 +88,20 @@ TEST(YogaTest, dirtied_hierarchy) {
|
|||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
|
||||||
int dirtiedCount = 0;
|
int dirtiedCount = 0;
|
||||||
YGNodeSetContext(root_child0, &dirtiedCount);
|
root_child0->setContext(&dirtiedCount);
|
||||||
YGNodeSetDirtiedFunc(root_child0, _dirtied);
|
root_child0->setDirtiedFunc(_dirtied);
|
||||||
|
|
||||||
ASSERT_EQ(0, dirtiedCount);
|
ASSERT_EQ(0, dirtiedCount);
|
||||||
|
|
||||||
// `_dirtied` must NOT be called for descendants.
|
// `_dirtied` must NOT be called for descendants.
|
||||||
static_cast<yoga::Node*>(root)->markDirtyAndPropagate();
|
root->markDirtyAndPropagate();
|
||||||
ASSERT_EQ(0, dirtiedCount);
|
ASSERT_EQ(0, dirtiedCount);
|
||||||
|
|
||||||
// `_dirtied` must NOT be called for the sibling node.
|
// `_dirtied` must NOT be called for the sibling node.
|
||||||
static_cast<yoga::Node*>(root_child1)->markDirtyAndPropagate();
|
root_child1->markDirtyAndPropagate();
|
||||||
ASSERT_EQ(0, dirtiedCount);
|
ASSERT_EQ(0, dirtiedCount);
|
||||||
|
|
||||||
// `_dirtied` MUST be called in case of explicit dirtying.
|
// `_dirtied` MUST be called in case of explicit dirtying.
|
||||||
static_cast<yoga::Node*>(root_child0)->markDirtyAndPropagate();
|
root_child0->markDirtyAndPropagate();
|
||||||
ASSERT_EQ(1, dirtiedCount);
|
ASSERT_EQ(1, dirtiedCount);
|
||||||
}
|
}
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/YGNode.h>
|
||||||
|
|
||||||
TEST(YogaTest, dirty_propagation) {
|
TEST(YogaTest, dirty_propagation) {
|
||||||
const YGNodeRef root = YGNodeNew();
|
const YGNodeRef root = YGNodeNew();
|
||||||
@@ -28,15 +28,15 @@ TEST(YogaTest, dirty_propagation) {
|
|||||||
|
|
||||||
YGNodeStyleSetWidth(root_child0, 20);
|
YGNodeStyleSetWidth(root_child0, 20);
|
||||||
|
|
||||||
EXPECT_TRUE(YGNodeIsDirty(root_child0));
|
EXPECT_TRUE(root_child0->isDirty());
|
||||||
EXPECT_FALSE(YGNodeIsDirty(root_child1));
|
EXPECT_FALSE(root_child1->isDirty());
|
||||||
EXPECT_TRUE(YGNodeIsDirty(root));
|
EXPECT_TRUE(root->isDirty());
|
||||||
|
|
||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
|
||||||
EXPECT_FALSE(YGNodeIsDirty(root_child0));
|
EXPECT_FALSE(root_child0->isDirty());
|
||||||
EXPECT_FALSE(YGNodeIsDirty(root_child1));
|
EXPECT_FALSE(root_child1->isDirty());
|
||||||
EXPECT_FALSE(YGNodeIsDirty(root));
|
EXPECT_FALSE(root->isDirty());
|
||||||
|
|
||||||
YGNodeFreeRecursive(root);
|
YGNodeFreeRecursive(root);
|
||||||
}
|
}
|
||||||
@@ -61,9 +61,9 @@ TEST(YogaTest, dirty_propagation_only_if_prop_changed) {
|
|||||||
|
|
||||||
YGNodeStyleSetWidth(root_child0, 50);
|
YGNodeStyleSetWidth(root_child0, 50);
|
||||||
|
|
||||||
EXPECT_FALSE(YGNodeIsDirty(root_child0));
|
EXPECT_FALSE(root_child0->isDirty());
|
||||||
EXPECT_FALSE(YGNodeIsDirty(root_child1));
|
EXPECT_FALSE(root_child1->isDirty());
|
||||||
EXPECT_FALSE(YGNodeIsDirty(root));
|
EXPECT_FALSE(root->isDirty());
|
||||||
|
|
||||||
YGNodeFreeRecursive(root);
|
YGNodeFreeRecursive(root);
|
||||||
}
|
}
|
||||||
@@ -91,26 +91,26 @@ TEST(YogaTest, dirty_propagation_changing_layout_config) {
|
|||||||
|
|
||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
|
||||||
EXPECT_FALSE(YGNodeIsDirty(root));
|
EXPECT_FALSE(root->isDirty());
|
||||||
EXPECT_FALSE(YGNodeIsDirty(root_child0));
|
EXPECT_FALSE(root_child0->isDirty());
|
||||||
EXPECT_FALSE(YGNodeIsDirty(root_child1));
|
EXPECT_FALSE(root_child1->isDirty());
|
||||||
EXPECT_FALSE(YGNodeIsDirty(root_child0_child0));
|
EXPECT_FALSE(root_child0_child0->isDirty());
|
||||||
|
|
||||||
YGConfigRef newConfig = YGConfigNew();
|
YGConfigRef newConfig = YGConfigNew();
|
||||||
YGConfigSetErrata(newConfig, YGErrataStretchFlexBasis);
|
YGConfigSetErrata(newConfig, YGErrataStretchFlexBasis);
|
||||||
YGNodeSetConfig(root_child0, newConfig);
|
YGNodeSetConfig(root_child0, newConfig);
|
||||||
|
|
||||||
EXPECT_TRUE(YGNodeIsDirty(root));
|
EXPECT_TRUE(root->isDirty());
|
||||||
EXPECT_TRUE(YGNodeIsDirty(root_child0));
|
EXPECT_TRUE(root_child0->isDirty());
|
||||||
EXPECT_FALSE(YGNodeIsDirty(root_child1));
|
EXPECT_FALSE(root_child1->isDirty());
|
||||||
EXPECT_FALSE(YGNodeIsDirty(root_child0_child0));
|
EXPECT_FALSE(root_child0_child0->isDirty());
|
||||||
|
|
||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
|
||||||
EXPECT_FALSE(YGNodeIsDirty(root));
|
EXPECT_FALSE(root->isDirty());
|
||||||
EXPECT_FALSE(YGNodeIsDirty(root_child0));
|
EXPECT_FALSE(root_child0->isDirty());
|
||||||
EXPECT_FALSE(YGNodeIsDirty(root_child1));
|
EXPECT_FALSE(root_child1->isDirty());
|
||||||
EXPECT_FALSE(YGNodeIsDirty(root_child0_child0));
|
EXPECT_FALSE(root_child0_child0->isDirty());
|
||||||
|
|
||||||
YGConfigFree(newConfig);
|
YGConfigFree(newConfig);
|
||||||
YGNodeFreeRecursive(root);
|
YGNodeFreeRecursive(root);
|
||||||
@@ -139,10 +139,10 @@ TEST(YogaTest, dirty_propagation_changing_benign_config) {
|
|||||||
|
|
||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
|
||||||
EXPECT_FALSE(YGNodeIsDirty(root));
|
EXPECT_FALSE(root->isDirty());
|
||||||
EXPECT_FALSE(YGNodeIsDirty(root_child0));
|
EXPECT_FALSE(root_child0->isDirty());
|
||||||
EXPECT_FALSE(YGNodeIsDirty(root_child1));
|
EXPECT_FALSE(root_child1->isDirty());
|
||||||
EXPECT_FALSE(YGNodeIsDirty(root_child0_child0));
|
EXPECT_FALSE(root_child0_child0->isDirty());
|
||||||
|
|
||||||
YGConfigRef newConfig = YGConfigNew();
|
YGConfigRef newConfig = YGConfigNew();
|
||||||
YGConfigSetLogger(
|
YGConfigSetLogger(
|
||||||
@@ -152,10 +152,10 @@ TEST(YogaTest, dirty_propagation_changing_benign_config) {
|
|||||||
});
|
});
|
||||||
YGNodeSetConfig(root_child0, newConfig);
|
YGNodeSetConfig(root_child0, newConfig);
|
||||||
|
|
||||||
EXPECT_FALSE(YGNodeIsDirty(root));
|
EXPECT_FALSE(root->isDirty());
|
||||||
EXPECT_FALSE(YGNodeIsDirty(root_child0));
|
EXPECT_FALSE(root_child0->isDirty());
|
||||||
EXPECT_FALSE(YGNodeIsDirty(root_child1));
|
EXPECT_FALSE(root_child1->isDirty());
|
||||||
EXPECT_FALSE(YGNodeIsDirty(root_child0_child0));
|
EXPECT_FALSE(root_child0_child0->isDirty());
|
||||||
|
|
||||||
YGConfigFree(newConfig);
|
YGConfigFree(newConfig);
|
||||||
YGNodeFreeRecursive(root);
|
YGNodeFreeRecursive(root);
|
||||||
@@ -224,11 +224,11 @@ TEST(YogaTest, dirty_node_only_if_children_are_actually_removed) {
|
|||||||
|
|
||||||
const YGNodeRef child1 = YGNodeNew();
|
const YGNodeRef child1 = YGNodeNew();
|
||||||
YGNodeRemoveChild(root, child1);
|
YGNodeRemoveChild(root, child1);
|
||||||
EXPECT_FALSE(YGNodeIsDirty(root));
|
EXPECT_FALSE(root->isDirty());
|
||||||
YGNodeFree(child1);
|
YGNodeFree(child1);
|
||||||
|
|
||||||
YGNodeRemoveChild(root, child0);
|
YGNodeRemoveChild(root, child0);
|
||||||
EXPECT_TRUE(YGNodeIsDirty(root));
|
EXPECT_TRUE(root->isDirty());
|
||||||
YGNodeFree(child0);
|
YGNodeFree(child0);
|
||||||
|
|
||||||
YGNodeFreeRecursive(root);
|
YGNodeFreeRecursive(root);
|
||||||
@@ -241,11 +241,12 @@ TEST(YogaTest, dirty_node_only_if_undefined_values_gets_set_to_undefined) {
|
|||||||
YGNodeStyleSetMinWidth(root, YGUndefined);
|
YGNodeStyleSetMinWidth(root, YGUndefined);
|
||||||
|
|
||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
EXPECT_FALSE(YGNodeIsDirty(root));
|
|
||||||
|
EXPECT_FALSE(root->isDirty());
|
||||||
|
|
||||||
YGNodeStyleSetMinWidth(root, YGUndefined);
|
YGNodeStyleSetMinWidth(root, YGUndefined);
|
||||||
|
|
||||||
EXPECT_FALSE(YGNodeIsDirty(root));
|
EXPECT_FALSE(root->isDirty());
|
||||||
|
|
||||||
YGNodeFreeRecursive(root);
|
YGNodeFreeRecursive(root);
|
||||||
}
|
}
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include <yoga/YGNode.h>
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
|
|
||||||
static YGSize _measureMax(
|
static YGSize _measureMax(
|
||||||
@@ -14,7 +15,7 @@ static YGSize _measureMax(
|
|||||||
YGMeasureMode widthMode,
|
YGMeasureMode widthMode,
|
||||||
float height,
|
float height,
|
||||||
YGMeasureMode heightMode) {
|
YGMeasureMode heightMode) {
|
||||||
int* measureCount = (int*) YGNodeGetContext(node);
|
int* measureCount = (int*) node->getContext();
|
||||||
(*measureCount)++;
|
(*measureCount)++;
|
||||||
|
|
||||||
return YGSize{
|
return YGSize{
|
||||||
@@ -29,7 +30,7 @@ static YGSize _measureMin(
|
|||||||
YGMeasureMode widthMode,
|
YGMeasureMode widthMode,
|
||||||
float height,
|
float height,
|
||||||
YGMeasureMode heightMode) {
|
YGMeasureMode heightMode) {
|
||||||
int* measureCount = (int*) YGNodeGetContext(node);
|
int* measureCount = (int*) node->getContext();
|
||||||
*measureCount = *measureCount + 1;
|
*measureCount = *measureCount + 1;
|
||||||
return YGSize{
|
return YGSize{
|
||||||
widthMode == YGMeasureModeUndefined ||
|
widthMode == YGMeasureModeUndefined ||
|
||||||
@@ -49,7 +50,7 @@ static YGSize _measure_84_49(
|
|||||||
YGMeasureMode /*widthMode*/,
|
YGMeasureMode /*widthMode*/,
|
||||||
float /*height*/,
|
float /*height*/,
|
||||||
YGMeasureMode /*heightMode*/) {
|
YGMeasureMode /*heightMode*/) {
|
||||||
int* measureCount = (int*) YGNodeGetContext(node);
|
int* measureCount = (int*) node->getContext();
|
||||||
if (measureCount) {
|
if (measureCount) {
|
||||||
(*measureCount)++;
|
(*measureCount)++;
|
||||||
}
|
}
|
||||||
@@ -66,8 +67,8 @@ TEST(YogaTest, measure_once_single_flexible_child) {
|
|||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
int measureCount = 0;
|
int measureCount = 0;
|
||||||
YGNodeSetContext(root_child0, &measureCount);
|
root_child0->setContext(&measureCount);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measureMax);
|
root_child0->setMeasureFunc(_measureMax);
|
||||||
YGNodeStyleSetFlexGrow(root_child0, 1);
|
YGNodeStyleSetFlexGrow(root_child0, 1);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
@@ -83,8 +84,8 @@ TEST(YogaTest, remeasure_with_same_exact_width_larger_than_needed_height) {
|
|||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
int measureCount = 0;
|
int measureCount = 0;
|
||||||
YGNodeSetContext(root_child0, &measureCount);
|
root_child0->setContext(&measureCount);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measureMin);
|
root_child0->setMeasureFunc(_measureMin);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);
|
YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);
|
||||||
@@ -101,8 +102,8 @@ TEST(YogaTest, remeasure_with_same_atmost_width_larger_than_needed_height) {
|
|||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
int measureCount = 0;
|
int measureCount = 0;
|
||||||
YGNodeSetContext(root_child0, &measureCount);
|
root_child0->setContext(&measureCount);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measureMin);
|
root_child0->setMeasureFunc(_measureMin);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);
|
YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);
|
||||||
@@ -119,8 +120,8 @@ TEST(YogaTest, remeasure_with_computed_width_larger_than_needed_height) {
|
|||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
int measureCount = 0;
|
int measureCount = 0;
|
||||||
YGNodeSetContext(root_child0, &measureCount);
|
root_child0->setContext(&measureCount);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measureMin);
|
root_child0->setMeasureFunc(_measureMin);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);
|
YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);
|
||||||
@@ -138,8 +139,8 @@ TEST(YogaTest, remeasure_with_atmost_computed_width_undefined_height) {
|
|||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
int measureCount = 0;
|
int measureCount = 0;
|
||||||
YGNodeSetContext(root_child0, &measureCount);
|
root_child0->setContext(&measureCount);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measureMin);
|
root_child0->setMeasureFunc(_measureMin);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
YGNodeCalculateLayout(root, 100, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, 100, YGUndefined, YGDirectionLTR);
|
||||||
@@ -166,8 +167,8 @@ TEST(
|
|||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
const YGNodeRef root_child0_child0 = YGNodeNew();
|
const YGNodeRef root_child0_child0 = YGNodeNew();
|
||||||
YGNodeSetContext(root_child0_child0, &measureCount);
|
root_child0_child0->setContext(&measureCount);
|
||||||
YGNodeSetMeasureFunc(root_child0_child0, _measure_84_49);
|
root_child0_child0->setMeasureFunc(_measure_84_49);
|
||||||
YGNodeInsertChild(root_child0, root_child0_child0, 0);
|
YGNodeInsertChild(root_child0, root_child0_child0, 0);
|
||||||
|
|
||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include <yoga/YGNode.h>
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
|
|
||||||
struct _MeasureConstraint {
|
struct _MeasureConstraint {
|
||||||
@@ -27,7 +28,7 @@ static YGSize _measure(
|
|||||||
float height,
|
float height,
|
||||||
YGMeasureMode heightMode) {
|
YGMeasureMode heightMode) {
|
||||||
struct _MeasureConstraintList* constraintList =
|
struct _MeasureConstraintList* constraintList =
|
||||||
(struct _MeasureConstraintList*) YGNodeGetContext(node);
|
(struct _MeasureConstraintList*) node->getContext();
|
||||||
struct _MeasureConstraint* constraints = constraintList->constraints;
|
struct _MeasureConstraint* constraints = constraintList->constraints;
|
||||||
uint32_t currentIndex = constraintList->length;
|
uint32_t currentIndex = constraintList->length;
|
||||||
(&constraints[currentIndex])->width = width;
|
(&constraints[currentIndex])->width = width;
|
||||||
@@ -54,8 +55,10 @@ TEST(YogaTest, exactly_measure_stretched_child_column) {
|
|||||||
YGNodeStyleSetHeight(root, 100);
|
YGNodeStyleSetHeight(root, 100);
|
||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
YGNodeSetContext(root_child0, &constraintList);
|
// root_child0->setContext(&constraintList);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
root_child0->setContext(&constraintList);
|
||||||
|
root_child0->setMeasureFunc(_measure);
|
||||||
|
// root_child0->setMeasureFunc(_measure);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
@@ -82,8 +85,9 @@ TEST(YogaTest, exactly_measure_stretched_child_row) {
|
|||||||
YGNodeStyleSetHeight(root, 100);
|
YGNodeStyleSetHeight(root, 100);
|
||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
YGNodeSetContext(root_child0, &constraintList);
|
// root_child0->setContext(&constraintList);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
root_child0->setContext(&constraintList);
|
||||||
|
root_child0->setMeasureFunc(_measure);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
@@ -109,8 +113,8 @@ TEST(YogaTest, at_most_main_axis_column) {
|
|||||||
YGNodeStyleSetHeight(root, 100);
|
YGNodeStyleSetHeight(root, 100);
|
||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
YGNodeSetContext(root_child0, &constraintList);
|
root_child0->setContext(&constraintList);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
root_child0->setMeasureFunc(_measure);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
@@ -137,8 +141,8 @@ TEST(YogaTest, at_most_cross_axis_column) {
|
|||||||
YGNodeStyleSetHeight(root, 100);
|
YGNodeStyleSetHeight(root, 100);
|
||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
YGNodeSetContext(root_child0, &constraintList);
|
root_child0->setContext(&constraintList);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
root_child0->setMeasureFunc(_measure);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
@@ -165,8 +169,8 @@ TEST(YogaTest, at_most_main_axis_row) {
|
|||||||
YGNodeStyleSetHeight(root, 100);
|
YGNodeStyleSetHeight(root, 100);
|
||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
YGNodeSetContext(root_child0, &constraintList);
|
root_child0->setContext(&constraintList);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
root_child0->setMeasureFunc(_measure);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
@@ -194,8 +198,8 @@ TEST(YogaTest, at_most_cross_axis_row) {
|
|||||||
YGNodeStyleSetHeight(root, 100);
|
YGNodeStyleSetHeight(root, 100);
|
||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
YGNodeSetContext(root_child0, &constraintList);
|
root_child0->setContext(&constraintList);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
root_child0->setMeasureFunc(_measure);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
@@ -221,8 +225,8 @@ TEST(YogaTest, flex_child) {
|
|||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
YGNodeStyleSetFlexGrow(root_child0, 1);
|
YGNodeStyleSetFlexGrow(root_child0, 1);
|
||||||
YGNodeSetContext(root_child0, &constraintList);
|
root_child0->setContext(&constraintList);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
root_child0->setMeasureFunc(_measure);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
@@ -252,8 +256,8 @@ TEST(YogaTest, flex_child_with_flex_basis) {
|
|||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
YGNodeStyleSetFlexGrow(root_child0, 1);
|
YGNodeStyleSetFlexGrow(root_child0, 1);
|
||||||
YGNodeStyleSetFlexBasis(root_child0, 0);
|
YGNodeStyleSetFlexBasis(root_child0, 0);
|
||||||
YGNodeSetContext(root_child0, &constraintList);
|
root_child0->setContext(&constraintList);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
root_child0->setMeasureFunc(_measure);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
@@ -281,8 +285,8 @@ TEST(YogaTest, overflow_scroll_column) {
|
|||||||
YGNodeStyleSetWidth(root, 100);
|
YGNodeStyleSetWidth(root, 100);
|
||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
YGNodeSetContext(root_child0, &constraintList);
|
root_child0->setContext(&constraintList);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
root_child0->setMeasureFunc(_measure);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
@@ -314,8 +318,8 @@ TEST(YogaTest, overflow_scroll_row) {
|
|||||||
YGNodeStyleSetWidth(root, 100);
|
YGNodeStyleSetWidth(root, 100);
|
||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
YGNodeSetContext(root_child0, &constraintList);
|
root_child0->setContext(&constraintList);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
root_child0->setMeasureFunc(_measure);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include <yoga/YGNode.h>
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
|
|
||||||
static YGSize _measure(
|
static YGSize _measure(
|
||||||
@@ -14,7 +15,7 @@ static YGSize _measure(
|
|||||||
YGMeasureMode /*widthMode*/,
|
YGMeasureMode /*widthMode*/,
|
||||||
float /*height*/,
|
float /*height*/,
|
||||||
YGMeasureMode /*heightMode*/) {
|
YGMeasureMode /*heightMode*/) {
|
||||||
int* measureCount = (int*) YGNodeGetContext(node);
|
int* measureCount = (int*) node->getContext();
|
||||||
if (measureCount) {
|
if (measureCount) {
|
||||||
(*measureCount)++;
|
(*measureCount)++;
|
||||||
}
|
}
|
||||||
@@ -55,8 +56,8 @@ TEST(YogaTest, dont_measure_single_grow_shrink_child) {
|
|||||||
int measureCount = 0;
|
int measureCount = 0;
|
||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
YGNodeSetContext(root_child0, &measureCount);
|
root_child0->setContext(&measureCount);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
root_child0->setMeasureFunc(_measure);
|
||||||
YGNodeStyleSetFlexGrow(root_child0, 1);
|
YGNodeStyleSetFlexGrow(root_child0, 1);
|
||||||
YGNodeStyleSetFlexShrink(root_child0, 1);
|
YGNodeStyleSetFlexShrink(root_child0, 1);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
@@ -78,8 +79,8 @@ TEST(YogaTest, measure_absolute_child_with_no_constraints) {
|
|||||||
|
|
||||||
const YGNodeRef root_child0_child0 = YGNodeNew();
|
const YGNodeRef root_child0_child0 = YGNodeNew();
|
||||||
YGNodeStyleSetPositionType(root_child0_child0, YGPositionTypeAbsolute);
|
YGNodeStyleSetPositionType(root_child0_child0, YGPositionTypeAbsolute);
|
||||||
YGNodeSetContext(root_child0_child0, &measureCount);
|
root_child0_child0->setContext(&measureCount);
|
||||||
YGNodeSetMeasureFunc(root_child0_child0, _measure);
|
root_child0_child0->setMeasureFunc(_measure);
|
||||||
YGNodeInsertChild(root_child0, root_child0_child0, 0);
|
YGNodeInsertChild(root_child0, root_child0_child0, 0);
|
||||||
|
|
||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
@@ -98,8 +99,8 @@ TEST(YogaTest, dont_measure_when_min_equals_max) {
|
|||||||
int measureCount = 0;
|
int measureCount = 0;
|
||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
YGNodeSetContext(root_child0, &measureCount);
|
root_child0->setContext(&measureCount);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
root_child0->setMeasureFunc(_measure);
|
||||||
YGNodeStyleSetMinWidth(root_child0, 10);
|
YGNodeStyleSetMinWidth(root_child0, 10);
|
||||||
YGNodeStyleSetMaxWidth(root_child0, 10);
|
YGNodeStyleSetMaxWidth(root_child0, 10);
|
||||||
YGNodeStyleSetMinHeight(root_child0, 10);
|
YGNodeStyleSetMinHeight(root_child0, 10);
|
||||||
@@ -126,8 +127,8 @@ TEST(YogaTest, dont_measure_when_min_equals_max_percentages) {
|
|||||||
int measureCount = 0;
|
int measureCount = 0;
|
||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
YGNodeSetContext(root_child0, &measureCount);
|
root_child0->setContext(&measureCount);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
root_child0->setMeasureFunc(_measure);
|
||||||
YGNodeStyleSetMinWidthPercent(root_child0, 10);
|
YGNodeStyleSetMinWidthPercent(root_child0, 10);
|
||||||
YGNodeStyleSetMaxWidthPercent(root_child0, 10);
|
YGNodeStyleSetMaxWidthPercent(root_child0, 10);
|
||||||
YGNodeStyleSetMinHeightPercent(root_child0, 10);
|
YGNodeStyleSetMinHeightPercent(root_child0, 10);
|
||||||
@@ -151,7 +152,7 @@ TEST(YogaTest, measure_nodes_with_margin_auto_and_stretch) {
|
|||||||
YGNodeStyleSetHeight(root, 500);
|
YGNodeStyleSetHeight(root, 500);
|
||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
root_child0->setMeasureFunc(_measure);
|
||||||
YGNodeStyleSetMarginAuto(root_child0, YGEdgeLeft);
|
YGNodeStyleSetMarginAuto(root_child0, YGEdgeLeft);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
@@ -174,8 +175,8 @@ TEST(YogaTest, dont_measure_when_min_equals_max_mixed_width_percent) {
|
|||||||
int measureCount = 0;
|
int measureCount = 0;
|
||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
YGNodeSetContext(root_child0, &measureCount);
|
root_child0->setContext(&measureCount);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
root_child0->setMeasureFunc(_measure);
|
||||||
YGNodeStyleSetMinWidthPercent(root_child0, 10);
|
YGNodeStyleSetMinWidthPercent(root_child0, 10);
|
||||||
YGNodeStyleSetMaxWidthPercent(root_child0, 10);
|
YGNodeStyleSetMaxWidthPercent(root_child0, 10);
|
||||||
YGNodeStyleSetMinHeight(root_child0, 10);
|
YGNodeStyleSetMinHeight(root_child0, 10);
|
||||||
@@ -202,8 +203,8 @@ TEST(YogaTest, dont_measure_when_min_equals_max_mixed_height_percent) {
|
|||||||
int measureCount = 0;
|
int measureCount = 0;
|
||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
YGNodeSetContext(root_child0, &measureCount);
|
root_child0->setContext(&measureCount);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
root_child0->setMeasureFunc(_measure);
|
||||||
YGNodeStyleSetMinWidth(root_child0, 10);
|
YGNodeStyleSetMinWidth(root_child0, 10);
|
||||||
YGNodeStyleSetMaxWidth(root_child0, 10);
|
YGNodeStyleSetMaxWidth(root_child0, 10);
|
||||||
YGNodeStyleSetMinHeightPercent(root_child0, 10);
|
YGNodeStyleSetMinHeightPercent(root_child0, 10);
|
||||||
@@ -227,7 +228,7 @@ TEST(YogaTest, measure_enough_size_should_be_in_single_line) {
|
|||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
YGNodeStyleSetAlignSelf(root_child0, YGAlignFlexStart);
|
YGNodeStyleSetAlignSelf(root_child0, YGAlignFlexStart);
|
||||||
YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
root_child0->setMeasureFunc(_simulate_wrapping_text);
|
||||||
|
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
@@ -246,7 +247,7 @@ TEST(YogaTest, measure_not_enough_size_should_wrap) {
|
|||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
YGNodeStyleSetAlignSelf(root_child0, YGAlignFlexStart);
|
YGNodeStyleSetAlignSelf(root_child0, YGAlignFlexStart);
|
||||||
// YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
// YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
||||||
YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
root_child0->setMeasureFunc(_simulate_wrapping_text);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
@@ -268,8 +269,8 @@ TEST(YogaTest, measure_zero_space_should_grow) {
|
|||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionColumn);
|
YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionColumn);
|
||||||
YGNodeStyleSetPadding(root_child0, YGEdgeAll, 100);
|
YGNodeStyleSetPadding(root_child0, YGEdgeAll, 100);
|
||||||
YGNodeSetContext(root_child0, &measureCount);
|
root_child0->setContext(&measureCount);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
root_child0->setMeasureFunc(_measure);
|
||||||
|
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
@@ -294,7 +295,8 @@ TEST(YogaTest, measure_flex_direction_row_and_padding) {
|
|||||||
YGNodeStyleSetHeight(root, 50);
|
YGNodeStyleSetHeight(root, 50);
|
||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||||
YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
root_child0->setMeasureFunc(_simulate_wrapping_text);
|
||||||
|
// YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
|
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
|
||||||
@@ -333,7 +335,7 @@ TEST(YogaTest, measure_flex_direction_column_and_padding) {
|
|||||||
YGNodeStyleSetHeight(root, 50);
|
YGNodeStyleSetHeight(root, 50);
|
||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||||
YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
root_child0->setMeasureFunc(_simulate_wrapping_text);
|
||||||
// YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
// YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
@@ -374,7 +376,7 @@ TEST(YogaTest, measure_flex_direction_row_no_padding) {
|
|||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||||
// YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
// YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
||||||
YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
root_child0->setMeasureFunc(_simulate_wrapping_text);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
|
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
|
||||||
@@ -414,7 +416,7 @@ TEST(YogaTest, measure_flex_direction_row_no_padding_align_items_flexstart) {
|
|||||||
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||||
YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
root_child0->setMeasureFunc(_simulate_wrapping_text);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
|
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
|
||||||
@@ -453,7 +455,7 @@ TEST(YogaTest, measure_with_fixed_size) {
|
|||||||
YGNodeStyleSetHeight(root, 50);
|
YGNodeStyleSetHeight(root, 50);
|
||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||||
YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
root_child0->setMeasureFunc(_simulate_wrapping_text);
|
||||||
YGNodeStyleSetWidth(root_child0, 10);
|
YGNodeStyleSetWidth(root_child0, 10);
|
||||||
YGNodeStyleSetHeight(root_child0, 10);
|
YGNodeStyleSetHeight(root_child0, 10);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
@@ -494,7 +496,7 @@ TEST(YogaTest, measure_with_flex_shrink) {
|
|||||||
YGNodeStyleSetHeight(root, 50);
|
YGNodeStyleSetHeight(root, 50);
|
||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||||
YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
root_child0->setMeasureFunc(_simulate_wrapping_text);
|
||||||
YGNodeStyleSetFlexShrink(root_child0, 1);
|
YGNodeStyleSetFlexShrink(root_child0, 1);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
@@ -533,7 +535,7 @@ TEST(YogaTest, measure_no_padding) {
|
|||||||
YGNodeStyleSetHeight(root, 50);
|
YGNodeStyleSetHeight(root, 50);
|
||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||||
YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text);
|
root_child0->setMeasureFunc(_simulate_wrapping_text);
|
||||||
YGNodeStyleSetFlexShrink(root_child0, 1);
|
YGNodeStyleSetFlexShrink(root_child0, 1);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
@@ -566,7 +568,7 @@ TEST(YogaTest, measure_no_padding) {
|
|||||||
#if GTEST_HAS_DEATH_TEST
|
#if GTEST_HAS_DEATH_TEST
|
||||||
TEST(YogaDeathTest, cannot_add_child_to_node_with_measure_func) {
|
TEST(YogaDeathTest, cannot_add_child_to_node_with_measure_func) {
|
||||||
const YGNodeRef root = YGNodeNew();
|
const YGNodeRef root = YGNodeNew();
|
||||||
YGNodeSetMeasureFunc(root, _measure);
|
root->setMeasureFunc(_measure);
|
||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
#if defined(__cpp_exceptions)
|
#if defined(__cpp_exceptions)
|
||||||
@@ -583,10 +585,9 @@ TEST(YogaDeathTest, cannot_add_nonnull_measure_func_to_non_leaf_node) {
|
|||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
#if defined(__cpp_exceptions)
|
#if defined(__cpp_exceptions)
|
||||||
ASSERT_THROW(YGNodeSetMeasureFunc(root, _measure), std::logic_error);
|
ASSERT_THROW(root->setMeasureFunc(_measure), std::logic_error);
|
||||||
#else // !defined(__cpp_exceptions)
|
#else // !defined(__cpp_exceptions)
|
||||||
ASSERT_DEATH(
|
ASSERT_DEATH(root->setMeasureFunc(_measure), "Cannot set measure function.*");
|
||||||
YGNodeSetMeasureFunc(root, _measure), "Cannot set measure function.*");
|
|
||||||
#endif // defined(__cpp_exceptions)
|
#endif // defined(__cpp_exceptions)
|
||||||
YGNodeFreeRecursive(root);
|
YGNodeFreeRecursive(root);
|
||||||
}
|
}
|
||||||
@@ -596,8 +597,8 @@ TEST(YogaDeathTest, cannot_add_nonnull_measure_func_to_non_leaf_node) {
|
|||||||
TEST(YogaTest, can_nullify_measure_func_on_any_node) {
|
TEST(YogaTest, can_nullify_measure_func_on_any_node) {
|
||||||
const YGNodeRef root = YGNodeNew();
|
const YGNodeRef root = YGNodeNew();
|
||||||
YGNodeInsertChild(root, YGNodeNew(), 0);
|
YGNodeInsertChild(root, YGNodeNew(), 0);
|
||||||
YGNodeSetMeasureFunc(root, nullptr);
|
root->setMeasureFunc(nullptr);
|
||||||
ASSERT_TRUE(!YGNodeHasMeasureFunc(root));
|
ASSERT_TRUE(!root->hasMeasureFunc());
|
||||||
YGNodeFreeRecursive(root);
|
YGNodeFreeRecursive(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -610,7 +611,7 @@ TEST(YogaTest, cant_call_negative_measure) {
|
|||||||
YGNodeStyleSetHeight(root, 10);
|
YGNodeStyleSetHeight(root, 10);
|
||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measure_assert_negative);
|
root_child0->setMeasureFunc(_measure_assert_negative);
|
||||||
YGNodeStyleSetMargin(root_child0, YGEdgeTop, 20);
|
YGNodeStyleSetMargin(root_child0, YGEdgeTop, 20);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
@@ -629,7 +630,7 @@ TEST(YogaTest, cant_call_negative_measure_horizontal) {
|
|||||||
YGNodeStyleSetHeight(root, 20);
|
YGNodeStyleSetHeight(root, 20);
|
||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measure_assert_negative);
|
root_child0->setMeasureFunc(_measure_assert_negative);
|
||||||
YGNodeStyleSetMargin(root_child0, YGEdgeStart, 20);
|
YGNodeStyleSetMargin(root_child0, YGEdgeStart, 20);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
@@ -673,7 +674,7 @@ TEST(YogaTest, percent_with_text_node) {
|
|||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
|
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
|
||||||
YGNodeSetMeasureFunc(root_child1, _measure_90_10);
|
root_child1->setMeasureFunc(_measure_90_10);
|
||||||
YGNodeStyleSetMaxWidthPercent(root_child1, 50);
|
YGNodeStyleSetMaxWidthPercent(root_child1, 50);
|
||||||
YGNodeStyleSetPaddingPercent(root_child1, YGEdgeTop, 50);
|
YGNodeStyleSetPaddingPercent(root_child1, YGEdgeTop, 50);
|
||||||
YGNodeInsertChild(root, root_child1, 1);
|
YGNodeInsertChild(root, root_child1, 1);
|
||||||
@@ -712,28 +713,28 @@ TEST(YogaTest, percent_margin_with_measure_func) {
|
|||||||
YGNodeStyleSetWidth(root_child0, 100);
|
YGNodeStyleSetWidth(root_child0, 100);
|
||||||
YGNodeStyleSetHeight(root_child0, 100);
|
YGNodeStyleSetHeight(root_child0, 100);
|
||||||
YGNodeStyleSetMargin(root_child0, YGEdgeTop, 0);
|
YGNodeStyleSetMargin(root_child0, YGEdgeTop, 0);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measure_100_100);
|
root_child0->setMeasureFunc(_measure_100_100);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
|
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
|
||||||
YGNodeStyleSetWidth(root_child1, 100);
|
YGNodeStyleSetWidth(root_child1, 100);
|
||||||
YGNodeStyleSetHeight(root_child1, 100);
|
YGNodeStyleSetHeight(root_child1, 100);
|
||||||
YGNodeStyleSetMargin(root_child1, YGEdgeTop, 100);
|
YGNodeStyleSetMargin(root_child1, YGEdgeTop, 100);
|
||||||
YGNodeSetMeasureFunc(root_child1, _measure_100_100);
|
root_child1->setMeasureFunc(_measure_100_100);
|
||||||
YGNodeInsertChild(root, root_child1, 1);
|
YGNodeInsertChild(root, root_child1, 1);
|
||||||
|
|
||||||
const YGNodeRef root_child2 = YGNodeNewWithConfig(config);
|
const YGNodeRef root_child2 = YGNodeNewWithConfig(config);
|
||||||
YGNodeStyleSetWidth(root_child2, 100);
|
YGNodeStyleSetWidth(root_child2, 100);
|
||||||
YGNodeStyleSetHeight(root_child2, 100);
|
YGNodeStyleSetHeight(root_child2, 100);
|
||||||
YGNodeStyleSetMarginPercent(root_child2, YGEdgeTop, 10);
|
YGNodeStyleSetMarginPercent(root_child2, YGEdgeTop, 10);
|
||||||
YGNodeSetMeasureFunc(root_child2, _measure_100_100);
|
root_child2->setMeasureFunc(_measure_100_100);
|
||||||
YGNodeInsertChild(root, root_child2, 2);
|
YGNodeInsertChild(root, root_child2, 2);
|
||||||
|
|
||||||
const YGNodeRef root_child3 = YGNodeNewWithConfig(config);
|
const YGNodeRef root_child3 = YGNodeNewWithConfig(config);
|
||||||
YGNodeStyleSetWidth(root_child3, 100);
|
YGNodeStyleSetWidth(root_child3, 100);
|
||||||
YGNodeStyleSetHeight(root_child3, 100);
|
YGNodeStyleSetHeight(root_child3, 100);
|
||||||
YGNodeStyleSetMarginPercent(root_child3, YGEdgeTop, 20);
|
YGNodeStyleSetMarginPercent(root_child3, YGEdgeTop, 20);
|
||||||
YGNodeSetMeasureFunc(root_child3, _measure_100_100);
|
root_child3->setMeasureFunc(_measure_100_100);
|
||||||
YGNodeInsertChild(root, root_child3, 3);
|
YGNodeInsertChild(root, root_child3, 3);
|
||||||
|
|
||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
@@ -782,24 +783,24 @@ TEST(YogaTest, percent_padding_with_measure_func) {
|
|||||||
YGNodeStyleSetWidth(root_child0, 100);
|
YGNodeStyleSetWidth(root_child0, 100);
|
||||||
YGNodeStyleSetHeight(root_child0, 100);
|
YGNodeStyleSetHeight(root_child0, 100);
|
||||||
YGNodeStyleSetPadding(root_child0, YGEdgeTop, 0);
|
YGNodeStyleSetPadding(root_child0, YGEdgeTop, 0);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measure_100_100);
|
root_child0->setMeasureFunc(_measure_100_100);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
|
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
|
||||||
YGNodeStyleSetWidth(root_child1, 100);
|
YGNodeStyleSetWidth(root_child1, 100);
|
||||||
YGNodeStyleSetHeight(root_child1, 100);
|
YGNodeStyleSetHeight(root_child1, 100);
|
||||||
YGNodeStyleSetPadding(root_child1, YGEdgeTop, 100);
|
YGNodeStyleSetPadding(root_child1, YGEdgeTop, 100);
|
||||||
YGNodeSetMeasureFunc(root_child1, _measure_100_100);
|
root_child1->setMeasureFunc(_measure_100_100);
|
||||||
YGNodeInsertChild(root, root_child1, 1);
|
YGNodeInsertChild(root, root_child1, 1);
|
||||||
|
|
||||||
const YGNodeRef root_child2 = YGNodeNewWithConfig(config);
|
const YGNodeRef root_child2 = YGNodeNewWithConfig(config);
|
||||||
YGNodeStyleSetPaddingPercent(root_child2, YGEdgeTop, 10);
|
YGNodeStyleSetPaddingPercent(root_child2, YGEdgeTop, 10);
|
||||||
YGNodeSetMeasureFunc(root_child2, _measure_100_100);
|
root_child2->setMeasureFunc(_measure_100_100);
|
||||||
YGNodeInsertChild(root, root_child2, 2);
|
YGNodeInsertChild(root, root_child2, 2);
|
||||||
|
|
||||||
const YGNodeRef root_child3 = YGNodeNewWithConfig(config);
|
const YGNodeRef root_child3 = YGNodeNewWithConfig(config);
|
||||||
YGNodeStyleSetPaddingPercent(root_child3, YGEdgeTop, 20);
|
YGNodeStyleSetPaddingPercent(root_child3, YGEdgeTop, 20);
|
||||||
YGNodeSetMeasureFunc(root_child3, _measure_100_100);
|
root_child3->setMeasureFunc(_measure_100_100);
|
||||||
YGNodeInsertChild(root, root_child3, 3);
|
YGNodeInsertChild(root, root_child3, 3);
|
||||||
|
|
||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
@@ -848,26 +849,26 @@ TEST(YogaTest, percent_padding_and_percent_margin_with_measure_func) {
|
|||||||
YGNodeStyleSetWidth(root_child0, 100);
|
YGNodeStyleSetWidth(root_child0, 100);
|
||||||
YGNodeStyleSetHeight(root_child0, 100);
|
YGNodeStyleSetHeight(root_child0, 100);
|
||||||
YGNodeStyleSetPadding(root_child0, YGEdgeTop, 0);
|
YGNodeStyleSetPadding(root_child0, YGEdgeTop, 0);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measure_100_100);
|
root_child0->setMeasureFunc(_measure_100_100);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
|
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
|
||||||
YGNodeStyleSetWidth(root_child1, 100);
|
YGNodeStyleSetWidth(root_child1, 100);
|
||||||
YGNodeStyleSetHeight(root_child1, 100);
|
YGNodeStyleSetHeight(root_child1, 100);
|
||||||
YGNodeStyleSetPadding(root_child1, YGEdgeTop, 100);
|
YGNodeStyleSetPadding(root_child1, YGEdgeTop, 100);
|
||||||
YGNodeSetMeasureFunc(root_child1, _measure_100_100);
|
root_child1->setMeasureFunc(_measure_100_100);
|
||||||
YGNodeInsertChild(root, root_child1, 1);
|
YGNodeInsertChild(root, root_child1, 1);
|
||||||
|
|
||||||
const YGNodeRef root_child2 = YGNodeNewWithConfig(config);
|
const YGNodeRef root_child2 = YGNodeNewWithConfig(config);
|
||||||
YGNodeStyleSetPaddingPercent(root_child2, YGEdgeTop, 10);
|
YGNodeStyleSetPaddingPercent(root_child2, YGEdgeTop, 10);
|
||||||
YGNodeStyleSetMarginPercent(root_child2, YGEdgeTop, 10);
|
YGNodeStyleSetMarginPercent(root_child2, YGEdgeTop, 10);
|
||||||
YGNodeSetMeasureFunc(root_child2, _measure_100_100);
|
root_child2->setMeasureFunc(_measure_100_100);
|
||||||
YGNodeInsertChild(root, root_child2, 2);
|
YGNodeInsertChild(root, root_child2, 2);
|
||||||
|
|
||||||
const YGNodeRef root_child3 = YGNodeNewWithConfig(config);
|
const YGNodeRef root_child3 = YGNodeNewWithConfig(config);
|
||||||
YGNodeStyleSetPaddingPercent(root_child3, YGEdgeTop, 20);
|
YGNodeStyleSetPaddingPercent(root_child3, YGEdgeTop, 20);
|
||||||
YGNodeStyleSetMarginPercent(root_child3, YGEdgeTop, 20);
|
YGNodeStyleSetMarginPercent(root_child3, YGEdgeTop, 20);
|
||||||
YGNodeSetMeasureFunc(root_child3, _measure_100_100);
|
root_child3->setMeasureFunc(_measure_100_100);
|
||||||
YGNodeInsertChild(root, root_child3, 3);
|
YGNodeInsertChild(root, root_child3, 3);
|
||||||
|
|
||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
@@ -6,33 +6,33 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <yoga/node/Node.h>
|
#include <yoga/YGNode.h>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
using namespace facebook::yoga;
|
|
||||||
|
|
||||||
inline bool operator==(const YGSize& lhs, const YGSize& rhs) {
|
inline bool operator==(const YGSize& lhs, const YGSize& rhs) {
|
||||||
return lhs.width == rhs.width && lhs.height == rhs.height;
|
return lhs.width == rhs.width && lhs.height == rhs.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Node, hasMeasureFunc_initial) {
|
void PrintTo(const YGSize&, std::ostream*);
|
||||||
auto n = Node{};
|
|
||||||
|
TEST(YGNode, hasMeasureFunc_initial) {
|
||||||
|
auto n = YGNode{};
|
||||||
ASSERT_FALSE(n.hasMeasureFunc());
|
ASSERT_FALSE(n.hasMeasureFunc());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Node, hasMeasureFunc_with_measure_fn) {
|
TEST(YGNode, hasMeasureFunc_with_measure_fn) {
|
||||||
auto n = Node{};
|
auto n = YGNode{};
|
||||||
n.setMeasureFunc([](YGNodeRef, float, YGMeasureMode, float, YGMeasureMode) {
|
n.setMeasureFunc([](YGNode*, float, YGMeasureMode, float, YGMeasureMode) {
|
||||||
return YGSize{};
|
return YGSize{};
|
||||||
});
|
});
|
||||||
ASSERT_TRUE(n.hasMeasureFunc());
|
ASSERT_TRUE(n.hasMeasureFunc());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Node, measure_with_measure_fn) {
|
TEST(YGNode, measure_with_measure_fn) {
|
||||||
auto n = Node{};
|
auto n = YGNode{};
|
||||||
|
|
||||||
n.setMeasureFunc(
|
n.setMeasureFunc(
|
||||||
[](YGNodeRef, float w, YGMeasureMode wm, float h, YGMeasureMode hm) {
|
[](YGNode*, float w, YGMeasureMode wm, float h, YGMeasureMode hm) {
|
||||||
return YGSize{w * static_cast<int>(wm), h / static_cast<int>(hm)};
|
return YGSize{w * static_cast<int>(wm), h / static_cast<int>(hm)};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -41,10 +41,10 @@ TEST(Node, measure_with_measure_fn) {
|
|||||||
(YGSize{23, 12}));
|
(YGSize{23, 12}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Node, measure_with_context_measure_fn) {
|
TEST(YGNode, measure_with_context_measure_fn) {
|
||||||
auto n = Node{};
|
auto n = YGNode{};
|
||||||
n.setMeasureFunc(
|
n.setMeasureFunc(
|
||||||
[](YGNodeRef, float, YGMeasureMode, float, YGMeasureMode, void* ctx) {
|
[](YGNode*, float, YGMeasureMode, float, YGMeasureMode, void* ctx) {
|
||||||
return *(YGSize*) ctx;
|
return *(YGSize*) ctx;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -54,14 +54,14 @@ TEST(Node, measure_with_context_measure_fn) {
|
|||||||
result);
|
result);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Node, switching_measure_fn_types) {
|
TEST(YGNode, switching_measure_fn_types) {
|
||||||
auto n = Node{};
|
auto n = YGNode{};
|
||||||
n.setMeasureFunc(
|
n.setMeasureFunc(
|
||||||
[](YGNodeRef, float, YGMeasureMode, float, YGMeasureMode, void*) {
|
[](YGNode*, float, YGMeasureMode, float, YGMeasureMode, void*) {
|
||||||
return YGSize{};
|
return YGSize{};
|
||||||
});
|
});
|
||||||
n.setMeasureFunc(
|
n.setMeasureFunc(
|
||||||
[](YGNodeRef, float w, YGMeasureMode wm, float h, YGMeasureMode hm) {
|
[](YGNode*, float w, YGMeasureMode wm, float h, YGMeasureMode hm) {
|
||||||
return YGSize{w * static_cast<int>(wm), h / static_cast<int>(hm)};
|
return YGSize{w * static_cast<int>(wm), h / static_cast<int>(hm)};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -70,9 +70,9 @@ TEST(Node, switching_measure_fn_types) {
|
|||||||
(YGSize{23, 12}));
|
(YGSize{23, 12}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Node, hasMeasureFunc_after_unset) {
|
TEST(YGNode, hasMeasureFunc_after_unset) {
|
||||||
auto n = Node{};
|
auto n = YGNode{};
|
||||||
n.setMeasureFunc([](YGNodeRef, float, YGMeasureMode, float, YGMeasureMode) {
|
n.setMeasureFunc([](YGNode*, float, YGMeasureMode, float, YGMeasureMode) {
|
||||||
return YGSize{};
|
return YGSize{};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -80,10 +80,10 @@ TEST(Node, hasMeasureFunc_after_unset) {
|
|||||||
ASSERT_FALSE(n.hasMeasureFunc());
|
ASSERT_FALSE(n.hasMeasureFunc());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Node, hasMeasureFunc_after_unset_context) {
|
TEST(YGNode, hasMeasureFunc_after_unset_context) {
|
||||||
auto n = Node{};
|
auto n = YGNode{};
|
||||||
n.setMeasureFunc(
|
n.setMeasureFunc(
|
||||||
[](YGNodeRef, float, YGMeasureMode, float, YGMeasureMode, void*) {
|
[](YGNode*, float, YGMeasureMode, float, YGMeasureMode, void*) {
|
||||||
return YGSize{};
|
return YGSize{};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -91,27 +91,27 @@ TEST(Node, hasMeasureFunc_after_unset_context) {
|
|||||||
ASSERT_FALSE(n.hasMeasureFunc());
|
ASSERT_FALSE(n.hasMeasureFunc());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Node, hasBaselineFunc_initial) {
|
TEST(YGNode, hasBaselineFunc_initial) {
|
||||||
auto n = Node{};
|
auto n = YGNode{};
|
||||||
ASSERT_FALSE(n.hasBaselineFunc());
|
ASSERT_FALSE(n.hasBaselineFunc());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Node, hasBaselineFunc_with_baseline_fn) {
|
TEST(YGNode, hasBaselineFunc_with_baseline_fn) {
|
||||||
auto n = Node{};
|
auto n = YGNode{};
|
||||||
n.setBaselineFunc([](YGNodeRef, float, float) { return 0.0f; });
|
n.setBaselineFunc([](YGNode*, float, float) { return 0.0f; });
|
||||||
ASSERT_TRUE(n.hasBaselineFunc());
|
ASSERT_TRUE(n.hasBaselineFunc());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Node, baseline_with_baseline_fn) {
|
TEST(YGNode, baseline_with_baseline_fn) {
|
||||||
auto n = Node{};
|
auto n = YGNode{};
|
||||||
n.setBaselineFunc([](YGNodeRef, float w, float h) { return w + h; });
|
n.setBaselineFunc([](YGNode*, float w, float h) { return w + h; });
|
||||||
|
|
||||||
ASSERT_EQ(n.baseline(1.25f, 2.5f, nullptr), 3.75f);
|
ASSERT_EQ(n.baseline(1.25f, 2.5f, nullptr), 3.75f);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Node, baseline_with_context_baseline_fn) {
|
TEST(YGNode, baseline_with_context_baseline_fn) {
|
||||||
auto n = Node{};
|
auto n = YGNode{};
|
||||||
n.setBaselineFunc([](YGNodeRef, float w, float h, void* ctx) {
|
n.setBaselineFunc([](YGNode*, float w, float h, void* ctx) {
|
||||||
return w + h + *(float*) ctx;
|
return w + h + *(float*) ctx;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -119,25 +119,29 @@ TEST(Node, baseline_with_context_baseline_fn) {
|
|||||||
ASSERT_EQ(n.baseline(1.25f, 2.5f, &ctx), -6.25f);
|
ASSERT_EQ(n.baseline(1.25f, 2.5f, &ctx), -6.25f);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Node, hasBaselineFunc_after_unset) {
|
TEST(YGNode, hasBaselineFunc_after_unset) {
|
||||||
auto n = Node{};
|
auto n = YGNode{};
|
||||||
n.setBaselineFunc([](YGNodeRef, float, float) { return 0.0f; });
|
n.setBaselineFunc([](YGNode*, float, float) { return 0.0f; });
|
||||||
|
|
||||||
n.setBaselineFunc(nullptr);
|
n.setBaselineFunc(nullptr);
|
||||||
ASSERT_FALSE(n.hasBaselineFunc());
|
ASSERT_FALSE(n.hasBaselineFunc());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Node, hasBaselineFunc_after_unset_context) {
|
TEST(YGNode, hasBaselineFunc_after_unset_context) {
|
||||||
auto n = Node{};
|
auto n = YGNode{};
|
||||||
n.setBaselineFunc([](YGNodeRef, float, float, void*) { return 0.0f; });
|
n.setBaselineFunc([](YGNode*, float, float, void*) { return 0.0f; });
|
||||||
|
|
||||||
n.setMeasureFunc(nullptr);
|
n.setMeasureFunc(nullptr);
|
||||||
ASSERT_FALSE(n.hasMeasureFunc());
|
ASSERT_FALSE(n.hasMeasureFunc());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Node, switching_baseline_fn_types) {
|
TEST(YGNode, switching_baseline_fn_types) {
|
||||||
auto n = Node{};
|
auto n = YGNode{};
|
||||||
n.setBaselineFunc([](YGNodeRef, float, float, void*) { return 0.0f; });
|
n.setBaselineFunc([](YGNode*, float, float, void*) { return 0.0f; });
|
||||||
n.setBaselineFunc([](YGNodeRef, float, float) { return 1.0f; });
|
n.setBaselineFunc([](YGNode*, float, float) { return 1.0f; });
|
||||||
ASSERT_EQ(n.baseline(1, 2, nullptr), 1.0f);
|
ASSERT_EQ(n.baseline(1, 2, nullptr), 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PrintTo(const YGSize& size, std::ostream* os) {
|
||||||
|
*os << "YGSize{" << size.width << ", " << size.height << "}";
|
||||||
|
}
|
||||||
|
@@ -7,11 +7,10 @@
|
|||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
#include <yoga/node/Node.h>
|
#include <yoga/YGNode.h>
|
||||||
|
|
||||||
#include "util/TestUtil.h"
|
#include "util/TestUtil.h"
|
||||||
|
|
||||||
using namespace facebook;
|
|
||||||
using facebook::yoga::test::TestUtil;
|
using facebook::yoga::test::TestUtil;
|
||||||
|
|
||||||
TEST(YogaTest, cloning_shared_root) {
|
TEST(YogaTest, cloning_shared_root) {
|
||||||
@@ -274,10 +273,9 @@ TEST(YogaTest, mixed_shared_and_owned_children) {
|
|||||||
YGNodeInsertChild(root1, root1_child0, 0);
|
YGNodeInsertChild(root1, root1_child0, 0);
|
||||||
YGNodeInsertChild(root1, root1_child2, 1);
|
YGNodeInsertChild(root1, root1_child2, 1);
|
||||||
|
|
||||||
auto children = static_cast<yoga::Node*>(root1)->getChildren();
|
auto children = root1->getChildren();
|
||||||
children.insert(children.begin() + 1, static_cast<yoga::Node*>(root0_child0));
|
children.insert(children.begin() + 1, root0_child0);
|
||||||
static_cast<yoga::Node*>(root1)->setChildren(children);
|
root1->setChildren(children);
|
||||||
|
|
||||||
auto secondChild = YGNodeGetChild(root1, 1);
|
auto secondChild = YGNodeGetChild(root1, 1);
|
||||||
ASSERT_EQ(secondChild, YGNodeGetChild(root0, 0));
|
ASSERT_EQ(secondChild, YGNodeGetChild(root0, 0));
|
||||||
ASSERT_EQ(YGNodeGetChild(secondChild, 0), YGNodeGetChild(root0_child0, 0));
|
ASSERT_EQ(YGNodeGetChild(secondChild, 0), YGNodeGetChild(root0_child0, 0));
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include <yoga/YGNode.h>
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
|
|
||||||
static YGSize _measureFloor(
|
static YGSize _measureFloor(
|
||||||
@@ -49,7 +50,7 @@ TEST(YogaTest, rounding_feature_with_custom_measure_func_floor) {
|
|||||||
const YGNodeRef root = YGNodeNewWithConfig(config);
|
const YGNodeRef root = YGNodeNewWithConfig(config);
|
||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measureFloor);
|
root_child0->setMeasureFunc(_measureFloor);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
YGConfigSetPointScaleFactor(config, 0.0f);
|
YGConfigSetPointScaleFactor(config, 0.0f);
|
||||||
@@ -97,7 +98,7 @@ TEST(YogaTest, rounding_feature_with_custom_measure_func_ceil) {
|
|||||||
const YGNodeRef root = YGNodeNewWithConfig(config);
|
const YGNodeRef root = YGNodeNewWithConfig(config);
|
||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measureCeil);
|
root_child0->setMeasureFunc(_measureCeil);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
YGConfigSetPointScaleFactor(config, 1.0f);
|
YGConfigSetPointScaleFactor(config, 1.0f);
|
||||||
@@ -120,7 +121,7 @@ TEST(
|
|||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||||
YGNodeStyleSetPosition(root_child0, YGEdgeLeft, 73.625);
|
YGNodeStyleSetPosition(root_child0, YGEdgeLeft, 73.625);
|
||||||
YGNodeSetMeasureFunc(root_child0, _measureFractial);
|
root_child0->setMeasureFunc(_measureFractial);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
YGConfigSetPointScaleFactor(config, 2.0f);
|
YGConfigSetPointScaleFactor(config, 2.0f);
|
||||||
|
@@ -6,15 +6,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/YGNode.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
TEST(YogaTest, copy_style_same) {
|
TEST(YogaTest, copy_style_same) {
|
||||||
const YGNodeRef node0 = YGNodeNew();
|
const YGNodeRef node0 = YGNodeNew();
|
||||||
const YGNodeRef node1 = YGNodeNew();
|
const YGNodeRef node1 = YGNodeNew();
|
||||||
ASSERT_FALSE(YGNodeIsDirty(node0));
|
ASSERT_FALSE(node0->isDirty());
|
||||||
|
|
||||||
YGNodeCopyStyle(node0, node1);
|
YGNodeCopyStyle(node0, node1);
|
||||||
ASSERT_FALSE(YGNodeIsDirty(node0));
|
ASSERT_FALSE(node0->isDirty());
|
||||||
|
|
||||||
YGNodeFree(node0);
|
YGNodeFree(node0);
|
||||||
YGNodeFree(node1);
|
YGNodeFree(node1);
|
||||||
@@ -22,7 +23,7 @@ TEST(YogaTest, copy_style_same) {
|
|||||||
|
|
||||||
TEST(YogaTest, copy_style_modified) {
|
TEST(YogaTest, copy_style_modified) {
|
||||||
const YGNodeRef node0 = YGNodeNew();
|
const YGNodeRef node0 = YGNodeNew();
|
||||||
ASSERT_FALSE(YGNodeIsDirty(node0));
|
ASSERT_FALSE(node0->isDirty());
|
||||||
ASSERT_EQ(YGFlexDirectionColumn, YGNodeStyleGetFlexDirection(node0));
|
ASSERT_EQ(YGFlexDirectionColumn, YGNodeStyleGetFlexDirection(node0));
|
||||||
ASSERT_FALSE(YGNodeStyleGetMaxHeight(node0).unit != YGUnitUndefined);
|
ASSERT_FALSE(YGNodeStyleGetMaxHeight(node0).unit != YGUnitUndefined);
|
||||||
|
|
||||||
@@ -31,7 +32,7 @@ TEST(YogaTest, copy_style_modified) {
|
|||||||
YGNodeStyleSetMaxHeight(node1, 10);
|
YGNodeStyleSetMaxHeight(node1, 10);
|
||||||
|
|
||||||
YGNodeCopyStyle(node0, node1);
|
YGNodeCopyStyle(node0, node1);
|
||||||
ASSERT_TRUE(YGNodeIsDirty(node0));
|
ASSERT_TRUE(node0->isDirty());
|
||||||
ASSERT_EQ(YGFlexDirectionRow, YGNodeStyleGetFlexDirection(node0));
|
ASSERT_EQ(YGFlexDirectionRow, YGNodeStyleGetFlexDirection(node0));
|
||||||
ASSERT_FLOAT_EQ(10, YGNodeStyleGetMaxHeight(node0).value);
|
ASSERT_FLOAT_EQ(10, YGNodeStyleGetMaxHeight(node0).value);
|
||||||
|
|
||||||
@@ -44,14 +45,14 @@ TEST(YogaTest, copy_style_modified_same) {
|
|||||||
YGNodeStyleSetFlexDirection(node0, YGFlexDirectionRow);
|
YGNodeStyleSetFlexDirection(node0, YGFlexDirectionRow);
|
||||||
YGNodeStyleSetMaxHeight(node0, 10);
|
YGNodeStyleSetMaxHeight(node0, 10);
|
||||||
YGNodeCalculateLayout(node0, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(node0, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
ASSERT_FALSE(YGNodeIsDirty(node0));
|
ASSERT_FALSE(node0->isDirty());
|
||||||
|
|
||||||
const YGNodeRef node1 = YGNodeNew();
|
const YGNodeRef node1 = YGNodeNew();
|
||||||
YGNodeStyleSetFlexDirection(node1, YGFlexDirectionRow);
|
YGNodeStyleSetFlexDirection(node1, YGFlexDirectionRow);
|
||||||
YGNodeStyleSetMaxHeight(node1, 10);
|
YGNodeStyleSetMaxHeight(node1, 10);
|
||||||
|
|
||||||
YGNodeCopyStyle(node0, node1);
|
YGNodeCopyStyle(node0, node1);
|
||||||
ASSERT_FALSE(YGNodeIsDirty(node0));
|
ASSERT_FALSE(node0->isDirty());
|
||||||
|
|
||||||
YGNodeFree(node0);
|
YGNodeFree(node0);
|
||||||
YGNodeFree(node1);
|
YGNodeFree(node1);
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
#include <yoga/config/Config.h>
|
#include <yoga/config/Config.h>
|
||||||
#include <yoga/node/Node.h>
|
#include <yoga/YGNode.h>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@@ -22,7 +22,7 @@ struct ConfigCloningTest : public ::testing::Test {
|
|||||||
void SetUp() override;
|
void SetUp() override;
|
||||||
void TearDown() override;
|
void TearDown() override;
|
||||||
|
|
||||||
static yoga::Node clonedNode;
|
static YGNode clonedNode;
|
||||||
static YGNodeRef cloneNode(YGNodeRef, YGNodeRef, int) { return &clonedNode; }
|
static YGNodeRef cloneNode(YGNodeRef, YGNodeRef, int) { return &clonedNode; }
|
||||||
static YGNodeRef doNotClone(YGNodeRef, YGNodeRef, int) { return nullptr; }
|
static YGNodeRef doNotClone(YGNodeRef, YGNodeRef, int) { return nullptr; }
|
||||||
};
|
};
|
||||||
@@ -30,7 +30,7 @@ struct ConfigCloningTest : public ::testing::Test {
|
|||||||
TEST_F(ConfigCloningTest, uses_values_provided_by_cloning_callback) {
|
TEST_F(ConfigCloningTest, uses_values_provided_by_cloning_callback) {
|
||||||
config->setCloneNodeCallback(cloneNode);
|
config->setCloneNodeCallback(cloneNode);
|
||||||
|
|
||||||
yoga::Node node{}, owner{};
|
YGNode node{}, owner{};
|
||||||
auto clone = config->cloneNode(&node, &owner, 0, nullptr);
|
auto clone = config->cloneNode(&node, &owner, 0, nullptr);
|
||||||
|
|
||||||
ASSERT_EQ(clone, &clonedNode);
|
ASSERT_EQ(clone, &clonedNode);
|
||||||
@@ -41,7 +41,7 @@ TEST_F(
|
|||||||
falls_back_to_regular_cloning_if_callback_returns_null) {
|
falls_back_to_regular_cloning_if_callback_returns_null) {
|
||||||
config->setCloneNodeCallback(doNotClone);
|
config->setCloneNodeCallback(doNotClone);
|
||||||
|
|
||||||
yoga::Node node{}, owner{};
|
YGNode node{}, owner{};
|
||||||
auto clone = config->cloneNode(&node, &owner, 0, nullptr);
|
auto clone = config->cloneNode(&node, &owner, 0, nullptr);
|
||||||
|
|
||||||
ASSERT_NE(clone, nullptr);
|
ASSERT_NE(clone, nullptr);
|
||||||
@@ -53,7 +53,7 @@ TEST_F(ConfigCloningTest, can_clone_with_context) {
|
|||||||
return (YGNodeRef) context;
|
return (YGNodeRef) context;
|
||||||
});
|
});
|
||||||
|
|
||||||
yoga::Node node{}, owner{}, clone{};
|
YGNode node{}, owner{}, clone{};
|
||||||
ASSERT_EQ(config->cloneNode(&node, &owner, 0, &clone), &clone);
|
ASSERT_EQ(config->cloneNode(&node, &owner, 0, &clone), &clone);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,4 +65,4 @@ void ConfigCloningTest::TearDown() {
|
|||||||
config.reset();
|
config.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
yoga::Node ConfigCloningTest::clonedNode = {};
|
YGNode ConfigCloningTest::clonedNode = {};
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include "TestUtil.h"
|
#include "TestUtil.h"
|
||||||
|
|
||||||
#include <yoga/node/Node.h>
|
#include <yoga/YGNode.h>
|
||||||
#include <yoga/event/event.h>
|
#include <yoga/event/event.h>
|
||||||
|
|
||||||
namespace facebook::yoga::test {
|
namespace facebook::yoga::test {
|
||||||
@@ -17,7 +17,7 @@ int nodeInstanceCount = 0;
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void yogaEventSubscriber(
|
void yogaEventSubscriber(
|
||||||
YGNodeConstRef /*node*/,
|
const YGNode& /*node*/,
|
||||||
Event::Type eventType,
|
Event::Type eventType,
|
||||||
const Event::Data& /*eventData*/) {
|
const Event::Data& /*eventData*/) {
|
||||||
|
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <yoga/node/Node.h>
|
#include "YGNode.h"
|
||||||
#include <yoga/Yoga-internal.h>
|
#include <yoga/Yoga-internal.h>
|
||||||
#include <yoga/style/CompactValue.h>
|
#include <yoga/style/CompactValue.h>
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ struct YGCollectFlexItemsRowValues {
|
|||||||
float totalFlexGrowFactors;
|
float totalFlexGrowFactors;
|
||||||
float totalFlexShrinkScaledFactors;
|
float totalFlexShrinkScaledFactors;
|
||||||
uint32_t endOfLineIndex;
|
uint32_t endOfLineIndex;
|
||||||
std::vector<facebook::yoga::Node*> relativeChildren;
|
std::vector<YGNodeRef> relativeChildren;
|
||||||
float remainingFreeSpace;
|
float remainingFreeSpace;
|
||||||
// The size of the mainDim for the row after considering size, padding, margin
|
// The size of the mainDim for the row after considering size, padding, margin
|
||||||
// and border of flex items. This is used to calculate maxLineDim after going
|
// and border of flex items. This is used to calculate maxLineDim after going
|
||||||
|
@@ -5,12 +5,12 @@
|
|||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <yoga/node/LayoutResults.h>
|
#include "YGLayout.h"
|
||||||
#include <yoga/Utils.h>
|
#include "Utils.h"
|
||||||
|
|
||||||
namespace facebook::yoga {
|
using namespace facebook;
|
||||||
|
|
||||||
bool LayoutResults::operator==(LayoutResults layout) const {
|
bool YGLayout::operator==(YGLayout layout) const {
|
||||||
bool isEqual = YGFloatArrayEqual(position, layout.position) &&
|
bool isEqual = YGFloatArrayEqual(position, layout.position) &&
|
||||||
YGFloatArrayEqual(dimensions, layout.dimensions) &&
|
YGFloatArrayEqual(dimensions, layout.dimensions) &&
|
||||||
YGFloatArrayEqual(margin, layout.margin) &&
|
YGFloatArrayEqual(margin, layout.margin) &&
|
||||||
@@ -40,5 +40,3 @@ bool LayoutResults::operator==(LayoutResults layout) const {
|
|||||||
|
|
||||||
return isEqual;
|
return isEqual;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace facebook::yoga
|
|
@@ -11,9 +11,7 @@
|
|||||||
#include <yoga/YGFloatOptional.h>
|
#include <yoga/YGFloatOptional.h>
|
||||||
#include <yoga/Yoga-internal.h>
|
#include <yoga/Yoga-internal.h>
|
||||||
|
|
||||||
namespace facebook::yoga {
|
struct YGLayout {
|
||||||
|
|
||||||
struct LayoutResults {
|
|
||||||
std::array<float, 4> position = {};
|
std::array<float, 4> position = {};
|
||||||
std::array<float, 2> dimensions = {{YGUndefined, YGUndefined}};
|
std::array<float, 2> dimensions = {{YGUndefined, YGUndefined}};
|
||||||
std::array<float, 4> margin = {};
|
std::array<float, 4> margin = {};
|
||||||
@@ -60,8 +58,6 @@ public:
|
|||||||
flags, hadOverflowOffset, hadOverflow);
|
flags, hadOverflowOffset, hadOverflow);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(LayoutResults layout) const;
|
bool operator==(YGLayout layout) const;
|
||||||
bool operator!=(LayoutResults layout) const { return !(*this == layout); }
|
bool operator!=(YGLayout layout) const { return !(*this == layout); }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace facebook::yoga
|
|
@@ -5,15 +5,18 @@
|
|||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <yoga/node/Node.h>
|
#include "YGNode.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <yoga/Utils.h>
|
#include "Utils.h"
|
||||||
|
|
||||||
namespace facebook::yoga {
|
using namespace facebook;
|
||||||
|
using namespace facebook::yoga;
|
||||||
|
using facebook::yoga::CompactValue;
|
||||||
|
|
||||||
Node::Node(yoga::Config* config) : config_{config} {
|
YGNode::YGNode(yoga::Config* config) : config_{config} {
|
||||||
YGAssert(config != nullptr, "Attempting to construct Node with null config");
|
YGAssert(
|
||||||
|
config != nullptr, "Attempting to construct YGNode with null config");
|
||||||
|
|
||||||
flags_.hasNewLayout = true;
|
flags_.hasNewLayout = true;
|
||||||
if (config->useWebDefaults()) {
|
if (config->useWebDefaults()) {
|
||||||
@@ -21,7 +24,7 @@ Node::Node(yoga::Config* config) : config_{config} {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Node::Node(Node&& node) {
|
YGNode::YGNode(YGNode&& node) {
|
||||||
context_ = node.context_;
|
context_ = node.context_;
|
||||||
flags_ = node.flags_;
|
flags_ = node.flags_;
|
||||||
measure_ = node.measure_;
|
measure_ = node.measure_;
|
||||||
@@ -40,7 +43,7 @@ Node::Node(Node&& node) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::print(void* printContext) {
|
void YGNode::print(void* printContext) {
|
||||||
if (print_.noContext != nullptr) {
|
if (print_.noContext != nullptr) {
|
||||||
if (flags_.printUsesContext) {
|
if (flags_.printUsesContext) {
|
||||||
print_.withContext(this, printContext);
|
print_.withContext(this, printContext);
|
||||||
@@ -50,7 +53,7 @@ void Node::print(void* printContext) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CompactValue Node::computeEdgeValueForRow(
|
CompactValue YGNode::computeEdgeValueForRow(
|
||||||
const Style::Edges& edges,
|
const Style::Edges& edges,
|
||||||
YGEdge rowEdge,
|
YGEdge rowEdge,
|
||||||
YGEdge edge,
|
YGEdge edge,
|
||||||
@@ -68,7 +71,7 @@ CompactValue Node::computeEdgeValueForRow(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CompactValue Node::computeEdgeValueForColumn(
|
CompactValue YGNode::computeEdgeValueForColumn(
|
||||||
const Style::Edges& edges,
|
const Style::Edges& edges,
|
||||||
YGEdge edge,
|
YGEdge edge,
|
||||||
CompactValue defaultValue) {
|
CompactValue defaultValue) {
|
||||||
@@ -83,7 +86,7 @@ CompactValue Node::computeEdgeValueForColumn(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CompactValue Node::computeRowGap(
|
CompactValue YGNode::computeRowGap(
|
||||||
const Style::Gutters& gutters,
|
const Style::Gutters& gutters,
|
||||||
CompactValue defaultValue) {
|
CompactValue defaultValue) {
|
||||||
if (!gutters[YGGutterRow].isUndefined()) {
|
if (!gutters[YGGutterRow].isUndefined()) {
|
||||||
@@ -95,7 +98,7 @@ CompactValue Node::computeRowGap(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CompactValue Node::computeColumnGap(
|
CompactValue YGNode::computeColumnGap(
|
||||||
const Style::Gutters& gutters,
|
const Style::Gutters& gutters,
|
||||||
CompactValue defaultValue) {
|
CompactValue defaultValue) {
|
||||||
if (!gutters[YGGutterColumn].isUndefined()) {
|
if (!gutters[YGGutterColumn].isUndefined()) {
|
||||||
@@ -107,7 +110,7 @@ CompactValue Node::computeColumnGap(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YGFloatOptional Node::getLeadingPosition(
|
YGFloatOptional YGNode::getLeadingPosition(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float axisSize) const {
|
const float axisSize) const {
|
||||||
auto leadingPosition = YGFlexDirectionIsRow(axis)
|
auto leadingPosition = YGFlexDirectionIsRow(axis)
|
||||||
@@ -121,7 +124,7 @@ YGFloatOptional Node::getLeadingPosition(
|
|||||||
return YGResolveValue(leadingPosition, axisSize);
|
return YGResolveValue(leadingPosition, axisSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
YGFloatOptional Node::getTrailingPosition(
|
YGFloatOptional YGNode::getTrailingPosition(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float axisSize) const {
|
const float axisSize) const {
|
||||||
auto trailingPosition = YGFlexDirectionIsRow(axis)
|
auto trailingPosition = YGFlexDirectionIsRow(axis)
|
||||||
@@ -135,7 +138,7 @@ YGFloatOptional Node::getTrailingPosition(
|
|||||||
return YGResolveValue(trailingPosition, axisSize);
|
return YGResolveValue(trailingPosition, axisSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Node::isLeadingPositionDefined(const YGFlexDirection axis) const {
|
bool YGNode::isLeadingPositionDefined(const YGFlexDirection axis) const {
|
||||||
auto leadingPosition = YGFlexDirectionIsRow(axis)
|
auto leadingPosition = YGFlexDirectionIsRow(axis)
|
||||||
? computeEdgeValueForRow(
|
? computeEdgeValueForRow(
|
||||||
style_.position(),
|
style_.position(),
|
||||||
@@ -147,7 +150,7 @@ bool Node::isLeadingPositionDefined(const YGFlexDirection axis) const {
|
|||||||
return !leadingPosition.isUndefined();
|
return !leadingPosition.isUndefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Node::isTrailingPosDefined(const YGFlexDirection axis) const {
|
bool YGNode::isTrailingPosDefined(const YGFlexDirection axis) const {
|
||||||
auto trailingPosition = YGFlexDirectionIsRow(axis)
|
auto trailingPosition = YGFlexDirectionIsRow(axis)
|
||||||
? computeEdgeValueForRow(
|
? computeEdgeValueForRow(
|
||||||
style_.position(),
|
style_.position(),
|
||||||
@@ -159,7 +162,7 @@ bool Node::isTrailingPosDefined(const YGFlexDirection axis) const {
|
|||||||
return !trailingPosition.isUndefined();
|
return !trailingPosition.isUndefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
YGFloatOptional Node::getLeadingMargin(
|
YGFloatOptional YGNode::getLeadingMargin(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const {
|
const float widthSize) const {
|
||||||
auto leadingMargin = YGFlexDirectionIsRow(axis)
|
auto leadingMargin = YGFlexDirectionIsRow(axis)
|
||||||
@@ -170,7 +173,7 @@ YGFloatOptional Node::getLeadingMargin(
|
|||||||
return YGResolveValueMargin(leadingMargin, widthSize);
|
return YGResolveValueMargin(leadingMargin, widthSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
YGFloatOptional Node::getTrailingMargin(
|
YGFloatOptional YGNode::getTrailingMargin(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const {
|
const float widthSize) const {
|
||||||
auto trailingMargin = YGFlexDirectionIsRow(axis)
|
auto trailingMargin = YGFlexDirectionIsRow(axis)
|
||||||
@@ -181,13 +184,13 @@ YGFloatOptional Node::getTrailingMargin(
|
|||||||
return YGResolveValueMargin(trailingMargin, widthSize);
|
return YGResolveValueMargin(trailingMargin, widthSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
YGFloatOptional Node::getMarginForAxis(
|
YGFloatOptional YGNode::getMarginForAxis(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const {
|
const float widthSize) const {
|
||||||
return getLeadingMargin(axis, widthSize) + getTrailingMargin(axis, widthSize);
|
return getLeadingMargin(axis, widthSize) + getTrailingMargin(axis, widthSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
YGFloatOptional Node::getGapForAxis(
|
YGFloatOptional YGNode::getGapForAxis(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const {
|
const float widthSize) const {
|
||||||
auto gap = YGFlexDirectionIsRow(axis)
|
auto gap = YGFlexDirectionIsRow(axis)
|
||||||
@@ -196,7 +199,7 @@ YGFloatOptional Node::getGapForAxis(
|
|||||||
return YGResolveValue(gap, widthSize);
|
return YGResolveValue(gap, widthSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
YGSize Node::measure(
|
YGSize YGNode::measure(
|
||||||
float width,
|
float width,
|
||||||
YGMeasureMode widthMode,
|
YGMeasureMode widthMode,
|
||||||
float height,
|
float height,
|
||||||
@@ -208,7 +211,7 @@ YGSize Node::measure(
|
|||||||
: measure_.noContext(this, width, widthMode, height, heightMode);
|
: measure_.noContext(this, width, widthMode, height, heightMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Node::baseline(float width, float height, void* layoutContext) {
|
float YGNode::baseline(float width, float height, void* layoutContext) {
|
||||||
return flags_.baselineUsesContext
|
return flags_.baselineUsesContext
|
||||||
? baseline_.withContext(this, width, height, layoutContext)
|
? baseline_.withContext(this, width, height, layoutContext)
|
||||||
: baseline_.noContext(this, width, height);
|
: baseline_.noContext(this, width, height);
|
||||||
@@ -216,7 +219,7 @@ float Node::baseline(float width, float height, void* layoutContext) {
|
|||||||
|
|
||||||
// Setters
|
// Setters
|
||||||
|
|
||||||
void Node::setMeasureFunc(decltype(Node::measure_) measureFunc) {
|
void YGNode::setMeasureFunc(decltype(YGNode::measure_) measureFunc) {
|
||||||
if (measureFunc.noContext == nullptr) {
|
if (measureFunc.noContext == nullptr) {
|
||||||
// TODO: t18095186 Move nodeType to opt-in function and mark appropriate
|
// TODO: t18095186 Move nodeType to opt-in function and mark appropriate
|
||||||
// places in Litho
|
// places in Litho
|
||||||
@@ -235,38 +238,38 @@ void Node::setMeasureFunc(decltype(Node::measure_) measureFunc) {
|
|||||||
measure_ = measureFunc;
|
measure_ = measureFunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::setMeasureFunc(YGMeasureFunc measureFunc) {
|
void YGNode::setMeasureFunc(YGMeasureFunc measureFunc) {
|
||||||
flags_.measureUsesContext = false;
|
flags_.measureUsesContext = false;
|
||||||
decltype(Node::measure_) m;
|
decltype(YGNode::measure_) m;
|
||||||
m.noContext = measureFunc;
|
m.noContext = measureFunc;
|
||||||
setMeasureFunc(m);
|
setMeasureFunc(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void Node::setMeasureFunc(MeasureWithContextFn measureFunc) {
|
YOGA_EXPORT void YGNode::setMeasureFunc(MeasureWithContextFn measureFunc) {
|
||||||
flags_.measureUsesContext = true;
|
flags_.measureUsesContext = true;
|
||||||
decltype(Node::measure_) m;
|
decltype(YGNode::measure_) m;
|
||||||
m.withContext = measureFunc;
|
m.withContext = measureFunc;
|
||||||
setMeasureFunc(m);
|
setMeasureFunc(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::replaceChild(Node* child, uint32_t index) {
|
void YGNode::replaceChild(YGNodeRef child, uint32_t index) {
|
||||||
children_[index] = child;
|
children_[index] = child;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::replaceChild(Node* oldChild, Node* newChild) {
|
void YGNode::replaceChild(YGNodeRef oldChild, YGNodeRef newChild) {
|
||||||
std::replace(children_.begin(), children_.end(), oldChild, newChild);
|
std::replace(children_.begin(), children_.end(), oldChild, newChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::insertChild(Node* child, uint32_t index) {
|
void YGNode::insertChild(YGNodeRef child, uint32_t index) {
|
||||||
children_.insert(children_.begin() + index, child);
|
children_.insert(children_.begin() + index, child);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::setConfig(yoga::Config* config) {
|
void YGNode::setConfig(yoga::Config* config) {
|
||||||
YGAssert(config != nullptr, "Attempting to set a null config on a Node");
|
YGAssert(config != nullptr, "Attempting to set a null config on a YGNode");
|
||||||
YGAssertWithConfig(
|
YGAssertWithConfig(
|
||||||
config,
|
config,
|
||||||
config->useWebDefaults() == config_->useWebDefaults(),
|
config->useWebDefaults() == config_->useWebDefaults(),
|
||||||
"UseWebDefaults may not be changed after constructing a Node");
|
"UseWebDefaults may not be changed after constructing a YGNode");
|
||||||
|
|
||||||
if (yoga::configUpdateInvalidatesLayout(config_, config)) {
|
if (yoga::configUpdateInvalidatesLayout(config_, config)) {
|
||||||
markDirtyAndPropagate();
|
markDirtyAndPropagate();
|
||||||
@@ -275,7 +278,7 @@ void Node::setConfig(yoga::Config* config) {
|
|||||||
config_ = config;
|
config_ = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::setDirty(bool isDirty) {
|
void YGNode::setDirty(bool isDirty) {
|
||||||
if (isDirty == flags_.isDirty) {
|
if (isDirty == flags_.isDirty) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -285,8 +288,8 @@ void Node::setDirty(bool isDirty) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Node::removeChild(Node* child) {
|
bool YGNode::removeChild(YGNodeRef child) {
|
||||||
std::vector<Node*>::iterator p =
|
std::vector<YGNodeRef>::iterator p =
|
||||||
std::find(children_.begin(), children_.end(), child);
|
std::find(children_.begin(), children_.end(), child);
|
||||||
if (p != children_.end()) {
|
if (p != children_.end()) {
|
||||||
children_.erase(p);
|
children_.erase(p);
|
||||||
@@ -295,58 +298,59 @@ bool Node::removeChild(Node* child) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::removeChild(uint32_t index) {
|
void YGNode::removeChild(uint32_t index) {
|
||||||
children_.erase(children_.begin() + index);
|
children_.erase(children_.begin() + index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::setLayoutDirection(YGDirection direction) {
|
void YGNode::setLayoutDirection(YGDirection direction) {
|
||||||
layout_.setDirection(direction);
|
layout_.setDirection(direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::setLayoutMargin(float margin, int index) {
|
void YGNode::setLayoutMargin(float margin, int index) {
|
||||||
layout_.margin[index] = margin;
|
layout_.margin[index] = margin;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::setLayoutBorder(float border, int index) {
|
void YGNode::setLayoutBorder(float border, int index) {
|
||||||
layout_.border[index] = border;
|
layout_.border[index] = border;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::setLayoutPadding(float padding, int index) {
|
void YGNode::setLayoutPadding(float padding, int index) {
|
||||||
layout_.padding[index] = padding;
|
layout_.padding[index] = padding;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::setLayoutLastOwnerDirection(YGDirection direction) {
|
void YGNode::setLayoutLastOwnerDirection(YGDirection direction) {
|
||||||
layout_.lastOwnerDirection = direction;
|
layout_.lastOwnerDirection = direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::setLayoutComputedFlexBasis(const YGFloatOptional computedFlexBasis) {
|
void YGNode::setLayoutComputedFlexBasis(
|
||||||
|
const YGFloatOptional computedFlexBasis) {
|
||||||
layout_.computedFlexBasis = computedFlexBasis;
|
layout_.computedFlexBasis = computedFlexBasis;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::setLayoutPosition(float position, int index) {
|
void YGNode::setLayoutPosition(float position, int index) {
|
||||||
layout_.position[index] = position;
|
layout_.position[index] = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::setLayoutComputedFlexBasisGeneration(
|
void YGNode::setLayoutComputedFlexBasisGeneration(
|
||||||
uint32_t computedFlexBasisGeneration) {
|
uint32_t computedFlexBasisGeneration) {
|
||||||
layout_.computedFlexBasisGeneration = computedFlexBasisGeneration;
|
layout_.computedFlexBasisGeneration = computedFlexBasisGeneration;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::setLayoutMeasuredDimension(float measuredDimension, int index) {
|
void YGNode::setLayoutMeasuredDimension(float measuredDimension, int index) {
|
||||||
layout_.measuredDimensions[index] = measuredDimension;
|
layout_.measuredDimensions[index] = measuredDimension;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::setLayoutHadOverflow(bool hadOverflow) {
|
void YGNode::setLayoutHadOverflow(bool hadOverflow) {
|
||||||
layout_.setHadOverflow(hadOverflow);
|
layout_.setHadOverflow(hadOverflow);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::setLayoutDimension(float dimension, int index) {
|
void YGNode::setLayoutDimension(float dimension, int index) {
|
||||||
layout_.dimensions[index] = dimension;
|
layout_.dimensions[index] = dimension;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If both left and right are defined, then use left. Otherwise return +left or
|
// If both left and right are defined, then use left. Otherwise return +left or
|
||||||
// -right depending on which is defined.
|
// -right depending on which is defined.
|
||||||
YGFloatOptional Node::relativePosition(
|
YGFloatOptional YGNode::relativePosition(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float axisSize) const {
|
const float axisSize) const {
|
||||||
if (isLeadingPositionDefined(axis)) {
|
if (isLeadingPositionDefined(axis)) {
|
||||||
@@ -360,7 +364,7 @@ YGFloatOptional Node::relativePosition(
|
|||||||
return trailingPosition;
|
return trailingPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::setPosition(
|
void YGNode::setPosition(
|
||||||
const YGDirection direction,
|
const YGDirection direction,
|
||||||
const float mainSize,
|
const float mainSize,
|
||||||
const float crossSize,
|
const float crossSize,
|
||||||
@@ -398,7 +402,7 @@ void Node::setPosition(
|
|||||||
trailing[crossAxis]);
|
trailing[crossAxis]);
|
||||||
}
|
}
|
||||||
|
|
||||||
YGValue Node::marginLeadingValue(const YGFlexDirection axis) const {
|
YGValue YGNode::marginLeadingValue(const YGFlexDirection axis) const {
|
||||||
if (YGFlexDirectionIsRow(axis) &&
|
if (YGFlexDirectionIsRow(axis) &&
|
||||||
!style_.margin()[YGEdgeStart].isUndefined()) {
|
!style_.margin()[YGEdgeStart].isUndefined()) {
|
||||||
return style_.margin()[YGEdgeStart];
|
return style_.margin()[YGEdgeStart];
|
||||||
@@ -407,7 +411,7 @@ YGValue Node::marginLeadingValue(const YGFlexDirection axis) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YGValue Node::marginTrailingValue(const YGFlexDirection axis) const {
|
YGValue YGNode::marginTrailingValue(const YGFlexDirection axis) const {
|
||||||
if (YGFlexDirectionIsRow(axis) && !style_.margin()[YGEdgeEnd].isUndefined()) {
|
if (YGFlexDirectionIsRow(axis) && !style_.margin()[YGEdgeEnd].isUndefined()) {
|
||||||
return style_.margin()[YGEdgeEnd];
|
return style_.margin()[YGEdgeEnd];
|
||||||
} else {
|
} else {
|
||||||
@@ -415,7 +419,7 @@ YGValue Node::marginTrailingValue(const YGFlexDirection axis) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YGValue Node::resolveFlexBasisPtr() const {
|
YGValue YGNode::resolveFlexBasisPtr() const {
|
||||||
YGValue flexBasis = style_.flexBasis();
|
YGValue flexBasis = style_.flexBasis();
|
||||||
if (flexBasis.unit != YGUnitAuto && flexBasis.unit != YGUnitUndefined) {
|
if (flexBasis.unit != YGUnitAuto && flexBasis.unit != YGUnitUndefined) {
|
||||||
return flexBasis;
|
return flexBasis;
|
||||||
@@ -426,7 +430,7 @@ YGValue Node::resolveFlexBasisPtr() const {
|
|||||||
return YGValueAuto;
|
return YGValueAuto;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::resolveDimension() {
|
void YGNode::resolveDimension() {
|
||||||
using namespace yoga;
|
using namespace yoga;
|
||||||
const Style& style = getStyle();
|
const Style& style = getStyle();
|
||||||
for (auto dim : {YGDimensionWidth, YGDimensionHeight}) {
|
for (auto dim : {YGDimensionWidth, YGDimensionHeight}) {
|
||||||
@@ -439,7 +443,7 @@ void Node::resolveDimension() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YGDirection Node::resolveDirection(const YGDirection ownerDirection) {
|
YGDirection YGNode::resolveDirection(const YGDirection ownerDirection) {
|
||||||
if (style_.direction() == YGDirectionInherit) {
|
if (style_.direction() == YGDirectionInherit) {
|
||||||
return ownerDirection > YGDirectionInherit ? ownerDirection
|
return ownerDirection > YGDirectionInherit ? ownerDirection
|
||||||
: YGDirectionLTR;
|
: YGDirectionLTR;
|
||||||
@@ -448,18 +452,18 @@ YGDirection Node::resolveDirection(const YGDirection ownerDirection) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void Node::clearChildren() {
|
YOGA_EXPORT void YGNode::clearChildren() {
|
||||||
children_.clear();
|
children_.clear();
|
||||||
children_.shrink_to_fit();
|
children_.shrink_to_fit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Other Methods
|
// Other Methods
|
||||||
|
|
||||||
void Node::cloneChildrenIfNeeded(void* cloneContext) {
|
void YGNode::cloneChildrenIfNeeded(void* cloneContext) {
|
||||||
iterChildrenAfterCloningIfNeeded([](Node*, void*) {}, cloneContext);
|
iterChildrenAfterCloningIfNeeded([](YGNodeRef, void*) {}, cloneContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::markDirtyAndPropagate() {
|
void YGNode::markDirtyAndPropagate() {
|
||||||
if (!flags_.isDirty) {
|
if (!flags_.isDirty) {
|
||||||
setDirty(true);
|
setDirty(true);
|
||||||
setLayoutComputedFlexBasis(YGFloatOptional());
|
setLayoutComputedFlexBasis(YGFloatOptional());
|
||||||
@@ -469,14 +473,14 @@ void Node::markDirtyAndPropagate() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::markDirtyAndPropagateDownwards() {
|
void YGNode::markDirtyAndPropagateDownwards() {
|
||||||
flags_.isDirty = true;
|
flags_.isDirty = true;
|
||||||
for_each(children_.begin(), children_.end(), [](Node* childNode) {
|
for_each(children_.begin(), children_.end(), [](YGNodeRef childNode) {
|
||||||
childNode->markDirtyAndPropagateDownwards();
|
childNode->markDirtyAndPropagateDownwards();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
float Node::resolveFlexGrow() const {
|
float YGNode::resolveFlexGrow() const {
|
||||||
// Root nodes flexGrow should always be 0
|
// Root nodes flexGrow should always be 0
|
||||||
if (owner_ == nullptr) {
|
if (owner_ == nullptr) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
@@ -490,7 +494,7 @@ float Node::resolveFlexGrow() const {
|
|||||||
return kDefaultFlexGrow;
|
return kDefaultFlexGrow;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Node::resolveFlexShrink() const {
|
float YGNode::resolveFlexShrink() const {
|
||||||
if (owner_ == nullptr) {
|
if (owner_ == nullptr) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
@@ -504,13 +508,13 @@ float Node::resolveFlexShrink() const {
|
|||||||
return config_->useWebDefaults() ? kWebDefaultFlexShrink : kDefaultFlexShrink;
|
return config_->useWebDefaults() ? kWebDefaultFlexShrink : kDefaultFlexShrink;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Node::isNodeFlexible() {
|
bool YGNode::isNodeFlexible() {
|
||||||
return (
|
return (
|
||||||
(style_.positionType() != YGPositionTypeAbsolute) &&
|
(style_.positionType() != YGPositionTypeAbsolute) &&
|
||||||
(resolveFlexGrow() != 0 || resolveFlexShrink() != 0));
|
(resolveFlexGrow() != 0 || resolveFlexShrink() != 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
float Node::getLeadingBorder(const YGFlexDirection axis) const {
|
float YGNode::getLeadingBorder(const YGFlexDirection axis) const {
|
||||||
YGValue leadingBorder = YGFlexDirectionIsRow(axis)
|
YGValue leadingBorder = YGFlexDirectionIsRow(axis)
|
||||||
? computeEdgeValueForRow(
|
? computeEdgeValueForRow(
|
||||||
style_.border(), YGEdgeStart, leading[axis], CompactValue::ofZero())
|
style_.border(), YGEdgeStart, leading[axis], CompactValue::ofZero())
|
||||||
@@ -519,7 +523,7 @@ float Node::getLeadingBorder(const YGFlexDirection axis) const {
|
|||||||
return fmaxf(leadingBorder.value, 0.0f);
|
return fmaxf(leadingBorder.value, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Node::getTrailingBorder(const YGFlexDirection axis) const {
|
float YGNode::getTrailingBorder(const YGFlexDirection axis) const {
|
||||||
YGValue trailingBorder = YGFlexDirectionIsRow(axis)
|
YGValue trailingBorder = YGFlexDirectionIsRow(axis)
|
||||||
? computeEdgeValueForRow(
|
? computeEdgeValueForRow(
|
||||||
style_.border(), YGEdgeEnd, trailing[axis], CompactValue::ofZero())
|
style_.border(), YGEdgeEnd, trailing[axis], CompactValue::ofZero())
|
||||||
@@ -528,7 +532,7 @@ float Node::getTrailingBorder(const YGFlexDirection axis) const {
|
|||||||
return fmaxf(trailingBorder.value, 0.0f);
|
return fmaxf(trailingBorder.value, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
YGFloatOptional Node::getLeadingPadding(
|
YGFloatOptional YGNode::getLeadingPadding(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const {
|
const float widthSize) const {
|
||||||
auto leadingPadding = YGFlexDirectionIsRow(axis)
|
auto leadingPadding = YGFlexDirectionIsRow(axis)
|
||||||
@@ -543,7 +547,7 @@ YGFloatOptional Node::getLeadingPadding(
|
|||||||
YGResolveValue(leadingPadding, widthSize), YGFloatOptional(0.0f));
|
YGResolveValue(leadingPadding, widthSize), YGFloatOptional(0.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
YGFloatOptional Node::getTrailingPadding(
|
YGFloatOptional YGNode::getTrailingPadding(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const {
|
const float widthSize) const {
|
||||||
auto trailingPadding = YGFlexDirectionIsRow(axis)
|
auto trailingPadding = YGFlexDirectionIsRow(axis)
|
||||||
@@ -555,21 +559,21 @@ YGFloatOptional Node::getTrailingPadding(
|
|||||||
YGResolveValue(trailingPadding, widthSize), YGFloatOptional(0.0f));
|
YGResolveValue(trailingPadding, widthSize), YGFloatOptional(0.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
YGFloatOptional Node::getLeadingPaddingAndBorder(
|
YGFloatOptional YGNode::getLeadingPaddingAndBorder(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const {
|
const float widthSize) const {
|
||||||
return getLeadingPadding(axis, widthSize) +
|
return getLeadingPadding(axis, widthSize) +
|
||||||
YGFloatOptional(getLeadingBorder(axis));
|
YGFloatOptional(getLeadingBorder(axis));
|
||||||
}
|
}
|
||||||
|
|
||||||
YGFloatOptional Node::getTrailingPaddingAndBorder(
|
YGFloatOptional YGNode::getTrailingPaddingAndBorder(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const {
|
const float widthSize) const {
|
||||||
return getTrailingPadding(axis, widthSize) +
|
return getTrailingPadding(axis, widthSize) +
|
||||||
YGFloatOptional(getTrailingBorder(axis));
|
YGFloatOptional(getTrailingBorder(axis));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::reset() {
|
void YGNode::reset() {
|
||||||
YGAssertWithNode(
|
YGAssertWithNode(
|
||||||
this,
|
this,
|
||||||
children_.size() == 0,
|
children_.size() == 0,
|
||||||
@@ -577,7 +581,5 @@ void Node::reset() {
|
|||||||
YGAssertWithNode(
|
YGAssertWithNode(
|
||||||
this, owner_ == nullptr, "Cannot reset a node still attached to a owner");
|
this, owner_ == nullptr, "Cannot reset a node still attached to a owner");
|
||||||
|
|
||||||
*this = Node{getConfig()};
|
*this = YGNode{getConfig()};
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace facebook::yoga
|
|
@@ -10,20 +10,15 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <yoga/config/Config.h>
|
#include <yoga/config/Config.h>
|
||||||
#include <yoga/node/LayoutResults.h>
|
#include "YGLayout.h"
|
||||||
#include <yoga/Yoga-internal.h>
|
#include <yoga/Yoga-internal.h>
|
||||||
|
|
||||||
#include <yoga/style/CompactValue.h>
|
#include <yoga/style/CompactValue.h>
|
||||||
#include <yoga/style/Style.h>
|
#include <yoga/style/Style.h>
|
||||||
|
|
||||||
// Tag struct used to form the opaque YGNodeRef for the public C API
|
|
||||||
struct YGNode {};
|
|
||||||
|
|
||||||
namespace facebook::yoga {
|
|
||||||
|
|
||||||
#pragma pack(push)
|
#pragma pack(push)
|
||||||
#pragma pack(1)
|
#pragma pack(1)
|
||||||
struct NodeFlags {
|
struct YGNodeFlags {
|
||||||
bool hasNewLayout : 1;
|
bool hasNewLayout : 1;
|
||||||
bool isReferenceBaseline : 1;
|
bool isReferenceBaseline : 1;
|
||||||
bool isDirty : 1;
|
bool isDirty : 1;
|
||||||
@@ -34,8 +29,7 @@ struct NodeFlags {
|
|||||||
};
|
};
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
class YOGA_EXPORT Node : public ::YGNode {
|
struct YOGA_EXPORT YGNode {
|
||||||
public:
|
|
||||||
using MeasureWithContextFn =
|
using MeasureWithContextFn =
|
||||||
YGSize (*)(YGNode*, float, YGMeasureMode, float, YGMeasureMode, void*);
|
YGSize (*)(YGNode*, float, YGMeasureMode, float, YGMeasureMode, void*);
|
||||||
using BaselineWithContextFn = float (*)(YGNode*, float, float, void*);
|
using BaselineWithContextFn = float (*)(YGNode*, float, float, void*);
|
||||||
@@ -43,7 +37,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void* context_ = nullptr;
|
void* context_ = nullptr;
|
||||||
NodeFlags flags_ = {};
|
YGNodeFlags flags_ = {};
|
||||||
union {
|
union {
|
||||||
YGMeasureFunc noContext;
|
YGMeasureFunc noContext;
|
||||||
MeasureWithContextFn withContext;
|
MeasureWithContextFn withContext;
|
||||||
@@ -57,12 +51,12 @@ private:
|
|||||||
PrintWithContextFn withContext;
|
PrintWithContextFn withContext;
|
||||||
} print_ = {nullptr};
|
} print_ = {nullptr};
|
||||||
YGDirtiedFunc dirtied_ = nullptr;
|
YGDirtiedFunc dirtied_ = nullptr;
|
||||||
Style style_ = {};
|
facebook::yoga::Style style_ = {};
|
||||||
LayoutResults layout_ = {};
|
YGLayout layout_ = {};
|
||||||
uint32_t lineIndex_ = 0;
|
uint32_t lineIndex_ = 0;
|
||||||
Node* owner_ = nullptr;
|
YGNodeRef owner_ = nullptr;
|
||||||
std::vector<Node*> children_ = {};
|
YGVector children_ = {};
|
||||||
Config* config_;
|
facebook::yoga::Config* config_;
|
||||||
std::array<YGValue, 2> resolvedDimensions_ = {
|
std::array<YGValue, 2> resolvedDimensions_ = {
|
||||||
{YGValueUndefined, YGValueUndefined}};
|
{YGValueUndefined, YGValueUndefined}};
|
||||||
|
|
||||||
@@ -83,24 +77,27 @@ private:
|
|||||||
// them (potentially incorrect) or ignore them (danger of leaks). Only ever
|
// them (potentially incorrect) or ignore them (danger of leaks). Only ever
|
||||||
// use this after checking that there are no children.
|
// use this after checking that there are no children.
|
||||||
// DO NOT CHANGE THE VISIBILITY OF THIS METHOD!
|
// DO NOT CHANGE THE VISIBILITY OF THIS METHOD!
|
||||||
Node& operator=(Node&&) = default;
|
YGNode& operator=(YGNode&&) = default;
|
||||||
|
|
||||||
|
using CompactValue = facebook::yoga::CompactValue;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Node() : Node{static_cast<Config*>(YGConfigGetDefault())} {
|
YGNode()
|
||||||
|
: YGNode{static_cast<facebook::yoga::Config*>(YGConfigGetDefault())} {
|
||||||
flags_.hasNewLayout = true;
|
flags_.hasNewLayout = true;
|
||||||
}
|
}
|
||||||
explicit Node(Config* config);
|
explicit YGNode(facebook::yoga::Config* config);
|
||||||
~Node() = default; // cleanup of owner/children relationships in YGNodeFree
|
~YGNode() = default; // cleanup of owner/children relationships in YGNodeFree
|
||||||
|
|
||||||
Node(Node&&);
|
YGNode(YGNode&&);
|
||||||
|
|
||||||
// Does not expose true value semantics, as children are not cloned eagerly.
|
// Does not expose true value semantics, as children are not cloned eagerly.
|
||||||
// Should we remove this?
|
// Should we remove this?
|
||||||
Node(const Node& node) = default;
|
YGNode(const YGNode& node) = default;
|
||||||
|
|
||||||
// assignment means potential leaks of existing children, or alternatively
|
// assignment means potential leaks of existing children, or alternatively
|
||||||
// freeing unowned memory, double free, or freeing stack memory.
|
// freeing unowned memory, double free, or freeing stack memory.
|
||||||
Node& operator=(const Node&) = delete;
|
YGNode& operator=(const YGNode&) = delete;
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
void* getContext() const { return context_; }
|
void* getContext() const { return context_; }
|
||||||
@@ -128,39 +125,38 @@ public:
|
|||||||
YGDirtiedFunc getDirtied() const { return dirtied_; }
|
YGDirtiedFunc getDirtied() const { return dirtied_; }
|
||||||
|
|
||||||
// For Performance reasons passing as reference.
|
// For Performance reasons passing as reference.
|
||||||
Style& getStyle() { return style_; }
|
facebook::yoga::Style& getStyle() { return style_; }
|
||||||
|
|
||||||
const Style& getStyle() const { return style_; }
|
const facebook::yoga::Style& getStyle() const { return style_; }
|
||||||
|
|
||||||
// For Performance reasons passing as reference.
|
// For Performance reasons passing as reference.
|
||||||
LayoutResults& getLayout() { return layout_; }
|
YGLayout& getLayout() { return layout_; }
|
||||||
|
|
||||||
const LayoutResults& getLayout() const { return layout_; }
|
const YGLayout& getLayout() const { return layout_; }
|
||||||
|
|
||||||
uint32_t getLineIndex() const { return lineIndex_; }
|
uint32_t getLineIndex() const { return lineIndex_; }
|
||||||
|
|
||||||
bool isReferenceBaseline() { return flags_.isReferenceBaseline; }
|
bool isReferenceBaseline() { return flags_.isReferenceBaseline; }
|
||||||
|
|
||||||
// returns the Node that owns this Node. An owner is used to identify
|
// returns the YGNodeRef that owns this YGNode. An owner is used to identify
|
||||||
// the YogaTree that a Node belongs to. This method will return the parent
|
// the YogaTree that a YGNode belongs to. This method will return the parent
|
||||||
// of the Node when a Node only belongs to one YogaTree or nullptr when
|
// of the YGNode when a YGNode only belongs to one YogaTree or nullptr when
|
||||||
// the Node is shared between two or more YogaTrees.
|
// the YGNode is shared between two or more YogaTrees.
|
||||||
Node* getOwner() const { return owner_; }
|
YGNodeRef getOwner() const { return owner_; }
|
||||||
|
|
||||||
// Deprecated, use getOwner() instead.
|
// Deprecated, use getOwner() instead.
|
||||||
Node* getParent() const { return getOwner(); }
|
YGNodeRef getParent() const { return getOwner(); }
|
||||||
|
|
||||||
const std::vector<Node*>& getChildren() const { return children_; }
|
const YGVector& getChildren() const { return children_; }
|
||||||
|
|
||||||
// Applies a callback to all children, after cloning them if they are not
|
// Applies a callback to all children, after cloning them if they are not
|
||||||
// owned.
|
// owned.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void iterChildrenAfterCloningIfNeeded(T callback, void* cloneContext) {
|
void iterChildrenAfterCloningIfNeeded(T callback, void* cloneContext) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Node*& child : children_) {
|
for (YGNodeRef& child : children_) {
|
||||||
if (child->getOwner() != this) {
|
if (child->getOwner() != this) {
|
||||||
child = static_cast<Node*>(
|
child = config_->cloneNode(child, this, i, cloneContext);
|
||||||
config_->cloneNode(child, this, i, cloneContext));
|
|
||||||
child->setOwner(this);
|
child->setOwner(this);
|
||||||
}
|
}
|
||||||
i += 1;
|
i += 1;
|
||||||
@@ -169,9 +165,9 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Node* getChild(uint32_t index) const { return children_.at(index); }
|
YGNodeRef getChild(uint32_t index) const { return children_.at(index); }
|
||||||
|
|
||||||
Config* getConfig() const { return config_; }
|
facebook::yoga::Config* getConfig() const { return config_; }
|
||||||
|
|
||||||
bool isDirty() const { return flags_.isDirty; }
|
bool isDirty() const { return flags_.isDirty; }
|
||||||
|
|
||||||
@@ -184,22 +180,22 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static CompactValue computeEdgeValueForColumn(
|
static CompactValue computeEdgeValueForColumn(
|
||||||
const Style::Edges& edges,
|
const facebook::yoga::Style::Edges& edges,
|
||||||
YGEdge edge,
|
YGEdge edge,
|
||||||
CompactValue defaultValue);
|
CompactValue defaultValue);
|
||||||
|
|
||||||
static CompactValue computeEdgeValueForRow(
|
static CompactValue computeEdgeValueForRow(
|
||||||
const Style::Edges& edges,
|
const facebook::yoga::Style::Edges& edges,
|
||||||
YGEdge rowEdge,
|
YGEdge rowEdge,
|
||||||
YGEdge edge,
|
YGEdge edge,
|
||||||
CompactValue defaultValue);
|
CompactValue defaultValue);
|
||||||
|
|
||||||
static CompactValue computeRowGap(
|
static CompactValue computeRowGap(
|
||||||
const Style::Gutters& gutters,
|
const facebook::yoga::Style::Gutters& gutters,
|
||||||
CompactValue defaultValue);
|
CompactValue defaultValue);
|
||||||
|
|
||||||
static CompactValue computeColumnGap(
|
static CompactValue computeColumnGap(
|
||||||
const Style::Gutters& gutters,
|
const facebook::yoga::Style::Gutters& gutters,
|
||||||
CompactValue defaultValue);
|
CompactValue defaultValue);
|
||||||
|
|
||||||
// Methods related to positions, margin, padding and border
|
// Methods related to positions, margin, padding and border
|
||||||
@@ -279,9 +275,9 @@ public:
|
|||||||
|
|
||||||
void setDirtiedFunc(YGDirtiedFunc dirtiedFunc) { dirtied_ = dirtiedFunc; }
|
void setDirtiedFunc(YGDirtiedFunc dirtiedFunc) { dirtied_ = dirtiedFunc; }
|
||||||
|
|
||||||
void setStyle(const Style& style) { style_ = style; }
|
void setStyle(const facebook::yoga::Style& style) { style_ = style; }
|
||||||
|
|
||||||
void setLayout(const LayoutResults& layout) { layout_ = layout; }
|
void setLayout(const YGLayout& layout) { layout_ = layout; }
|
||||||
|
|
||||||
void setLineIndex(uint32_t lineIndex) { lineIndex_ = lineIndex; }
|
void setLineIndex(uint32_t lineIndex) { lineIndex_ = lineIndex; }
|
||||||
|
|
||||||
@@ -289,13 +285,13 @@ public:
|
|||||||
flags_.isReferenceBaseline = isReferenceBaseline;
|
flags_.isReferenceBaseline = isReferenceBaseline;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setOwner(Node* owner) { owner_ = owner; }
|
void setOwner(YGNodeRef owner) { owner_ = owner; }
|
||||||
|
|
||||||
void setChildren(const std::vector<Node*>& children) { children_ = children; }
|
void setChildren(const YGVector& children) { children_ = children; }
|
||||||
|
|
||||||
// TODO: rvalue override for setChildren
|
// TODO: rvalue override for setChildren
|
||||||
|
|
||||||
void setConfig(Config* config);
|
void setConfig(facebook::yoga::Config* config);
|
||||||
|
|
||||||
void setDirty(bool isDirty);
|
void setDirty(bool isDirty);
|
||||||
void setLayoutLastOwnerDirection(YGDirection direction);
|
void setLayoutLastOwnerDirection(YGDirection direction);
|
||||||
@@ -325,11 +321,11 @@ public:
|
|||||||
YGDirection resolveDirection(const YGDirection ownerDirection);
|
YGDirection resolveDirection(const YGDirection ownerDirection);
|
||||||
void clearChildren();
|
void clearChildren();
|
||||||
/// Replaces the occurrences of oldChild with newChild
|
/// Replaces the occurrences of oldChild with newChild
|
||||||
void replaceChild(Node* oldChild, Node* newChild);
|
void replaceChild(YGNodeRef oldChild, YGNodeRef newChild);
|
||||||
void replaceChild(Node* child, uint32_t index);
|
void replaceChild(YGNodeRef child, uint32_t index);
|
||||||
void insertChild(Node* child, uint32_t index);
|
void insertChild(YGNodeRef child, uint32_t index);
|
||||||
/// Removes the first occurrence of child
|
/// Removes the first occurrence of child
|
||||||
bool removeChild(Node* child);
|
bool removeChild(YGNodeRef child);
|
||||||
void removeChild(uint32_t index);
|
void removeChild(uint32_t index);
|
||||||
|
|
||||||
void cloneChildrenIfNeeded(void*);
|
void cloneChildrenIfNeeded(void*);
|
||||||
@@ -339,5 +335,3 @@ public:
|
|||||||
bool isNodeFlexible();
|
bool isNodeFlexible();
|
||||||
void reset();
|
void reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace facebook::yoga
|
|
@@ -12,8 +12,9 @@
|
|||||||
#include <yoga/YGEnums.h>
|
#include <yoga/YGEnums.h>
|
||||||
|
|
||||||
#include "YGNodePrint.h"
|
#include "YGNodePrint.h"
|
||||||
|
#include "YGNode.h"
|
||||||
#include <yoga/Yoga-internal.h>
|
#include <yoga/Yoga-internal.h>
|
||||||
#include <yoga/Utils.h>
|
#include "Utils.h"
|
||||||
|
|
||||||
namespace facebook::yoga {
|
namespace facebook::yoga {
|
||||||
typedef std::string string;
|
typedef std::string string;
|
||||||
@@ -91,7 +92,7 @@ static void appendEdges(
|
|||||||
const string& key,
|
const string& key,
|
||||||
const Style::Edges& edges) {
|
const Style::Edges& edges) {
|
||||||
if (areFourValuesEqual(edges)) {
|
if (areFourValuesEqual(edges)) {
|
||||||
auto edgeValue = yoga::Node::computeEdgeValueForColumn(
|
auto edgeValue = YGNode::computeEdgeValueForColumn(
|
||||||
edges, YGEdgeLeft, CompactValue::ofZero());
|
edges, YGEdgeLeft, CompactValue::ofZero());
|
||||||
appendNumberIfNotZero(base, key, edgeValue);
|
appendNumberIfNotZero(base, key, edgeValue);
|
||||||
} else {
|
} else {
|
||||||
@@ -109,16 +110,16 @@ static void appendEdgeIfNotUndefined(
|
|||||||
const YGEdge edge) {
|
const YGEdge edge) {
|
||||||
// TODO: this doesn't take RTL / YGEdgeStart / YGEdgeEnd into account
|
// TODO: this doesn't take RTL / YGEdgeStart / YGEdgeEnd into account
|
||||||
auto value = (edge == YGEdgeLeft || edge == YGEdgeRight)
|
auto value = (edge == YGEdgeLeft || edge == YGEdgeRight)
|
||||||
? yoga::Node::computeEdgeValueForRow(
|
? YGNode::computeEdgeValueForRow(
|
||||||
edges, edge, edge, CompactValue::ofUndefined())
|
edges, edge, edge, CompactValue::ofUndefined())
|
||||||
: yoga::Node::computeEdgeValueForColumn(
|
: YGNode::computeEdgeValueForColumn(
|
||||||
edges, edge, CompactValue::ofUndefined());
|
edges, edge, CompactValue::ofUndefined());
|
||||||
appendNumberIfNotUndefined(base, str, value);
|
appendNumberIfNotUndefined(base, str, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGNodeToString(
|
void YGNodeToString(
|
||||||
std::string& str,
|
std::string& str,
|
||||||
yoga::Node* node,
|
YGNodeRef node,
|
||||||
YGPrintOptions options,
|
YGPrintOptions options,
|
||||||
uint32_t level) {
|
uint32_t level) {
|
||||||
indent(str, level);
|
indent(str, level);
|
||||||
@@ -140,27 +141,27 @@ void YGNodeToString(
|
|||||||
if (options & YGPrintOptionsStyle) {
|
if (options & YGPrintOptionsStyle) {
|
||||||
appendFormattedString(str, "style=\"");
|
appendFormattedString(str, "style=\"");
|
||||||
const auto& style = node->getStyle();
|
const auto& style = node->getStyle();
|
||||||
if (style.flexDirection() != yoga::Node{}.getStyle().flexDirection()) {
|
if (style.flexDirection() != YGNode().getStyle().flexDirection()) {
|
||||||
appendFormattedString(
|
appendFormattedString(
|
||||||
str,
|
str,
|
||||||
"flex-direction: %s; ",
|
"flex-direction: %s; ",
|
||||||
YGFlexDirectionToString(style.flexDirection()));
|
YGFlexDirectionToString(style.flexDirection()));
|
||||||
}
|
}
|
||||||
if (style.justifyContent() != yoga::Node{}.getStyle().justifyContent()) {
|
if (style.justifyContent() != YGNode().getStyle().justifyContent()) {
|
||||||
appendFormattedString(
|
appendFormattedString(
|
||||||
str,
|
str,
|
||||||
"justify-content: %s; ",
|
"justify-content: %s; ",
|
||||||
YGJustifyToString(style.justifyContent()));
|
YGJustifyToString(style.justifyContent()));
|
||||||
}
|
}
|
||||||
if (style.alignItems() != yoga::Node{}.getStyle().alignItems()) {
|
if (style.alignItems() != YGNode().getStyle().alignItems()) {
|
||||||
appendFormattedString(
|
appendFormattedString(
|
||||||
str, "align-items: %s; ", YGAlignToString(style.alignItems()));
|
str, "align-items: %s; ", YGAlignToString(style.alignItems()));
|
||||||
}
|
}
|
||||||
if (style.alignContent() != yoga::Node{}.getStyle().alignContent()) {
|
if (style.alignContent() != YGNode().getStyle().alignContent()) {
|
||||||
appendFormattedString(
|
appendFormattedString(
|
||||||
str, "align-content: %s; ", YGAlignToString(style.alignContent()));
|
str, "align-content: %s; ", YGAlignToString(style.alignContent()));
|
||||||
}
|
}
|
||||||
if (style.alignSelf() != yoga::Node{}.getStyle().alignSelf()) {
|
if (style.alignSelf() != YGNode().getStyle().alignSelf()) {
|
||||||
appendFormattedString(
|
appendFormattedString(
|
||||||
str, "align-self: %s; ", YGAlignToString(style.alignSelf()));
|
str, "align-self: %s; ", YGAlignToString(style.alignSelf()));
|
||||||
}
|
}
|
||||||
@@ -169,17 +170,17 @@ void YGNodeToString(
|
|||||||
appendNumberIfNotAuto(str, "flex-basis", style.flexBasis());
|
appendNumberIfNotAuto(str, "flex-basis", style.flexBasis());
|
||||||
appendFloatOptionalIfDefined(str, "flex", style.flex());
|
appendFloatOptionalIfDefined(str, "flex", style.flex());
|
||||||
|
|
||||||
if (style.flexWrap() != yoga::Node{}.getStyle().flexWrap()) {
|
if (style.flexWrap() != YGNode().getStyle().flexWrap()) {
|
||||||
appendFormattedString(
|
appendFormattedString(
|
||||||
str, "flex-wrap: %s; ", YGWrapToString(style.flexWrap()));
|
str, "flex-wrap: %s; ", YGWrapToString(style.flexWrap()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (style.overflow() != yoga::Node{}.getStyle().overflow()) {
|
if (style.overflow() != YGNode().getStyle().overflow()) {
|
||||||
appendFormattedString(
|
appendFormattedString(
|
||||||
str, "overflow: %s; ", YGOverflowToString(style.overflow()));
|
str, "overflow: %s; ", YGOverflowToString(style.overflow()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (style.display() != yoga::Node{}.getStyle().display()) {
|
if (style.display() != YGNode().getStyle().display()) {
|
||||||
appendFormattedString(
|
appendFormattedString(
|
||||||
str, "display: %s; ", YGDisplayToString(style.display()));
|
str, "display: %s; ", YGDisplayToString(style.display()));
|
||||||
}
|
}
|
||||||
@@ -187,16 +188,15 @@ void YGNodeToString(
|
|||||||
appendEdges(str, "padding", style.padding());
|
appendEdges(str, "padding", style.padding());
|
||||||
appendEdges(str, "border", style.border());
|
appendEdges(str, "border", style.border());
|
||||||
|
|
||||||
if (yoga::Node::computeColumnGap(
|
if (YGNode::computeColumnGap(style.gap(), CompactValue::ofUndefined()) !=
|
||||||
style.gap(), CompactValue::ofUndefined()) !=
|
YGNode::computeColumnGap(
|
||||||
yoga::Node::computeColumnGap(
|
YGNode().getStyle().gap(), CompactValue::ofUndefined())) {
|
||||||
yoga::Node{}.getStyle().gap(), CompactValue::ofUndefined())) {
|
|
||||||
appendNumberIfNotUndefined(
|
appendNumberIfNotUndefined(
|
||||||
str, "column-gap", style.gap()[YGGutterColumn]);
|
str, "column-gap", style.gap()[YGGutterColumn]);
|
||||||
}
|
}
|
||||||
if (yoga::Node::computeRowGap(style.gap(), CompactValue::ofUndefined()) !=
|
if (YGNode::computeRowGap(style.gap(), CompactValue::ofUndefined()) !=
|
||||||
yoga::Node::computeRowGap(
|
YGNode::computeRowGap(
|
||||||
yoga::Node{}.getStyle().gap(), CompactValue::ofUndefined())) {
|
YGNode().getStyle().gap(), CompactValue::ofUndefined())) {
|
||||||
appendNumberIfNotUndefined(str, "row-gap", style.gap()[YGGutterRow]);
|
appendNumberIfNotUndefined(str, "row-gap", style.gap()[YGGutterRow]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,7 +211,7 @@ void YGNodeToString(
|
|||||||
appendNumberIfNotAuto(
|
appendNumberIfNotAuto(
|
||||||
str, "min-height", style.minDimensions()[YGDimensionHeight]);
|
str, "min-height", style.minDimensions()[YGDimensionHeight]);
|
||||||
|
|
||||||
if (style.positionType() != yoga::Node{}.getStyle().positionType()) {
|
if (style.positionType() != YGNode().getStyle().positionType()) {
|
||||||
appendFormattedString(
|
appendFormattedString(
|
||||||
str, "position: %s; ", YGPositionTypeToString(style.positionType()));
|
str, "position: %s; ", YGPositionTypeToString(style.positionType()));
|
||||||
}
|
}
|
||||||
@@ -232,7 +232,7 @@ void YGNodeToString(
|
|||||||
if (options & YGPrintOptionsChildren && childCount > 0) {
|
if (options & YGPrintOptionsChildren && childCount > 0) {
|
||||||
for (uint32_t i = 0; i < childCount; i++) {
|
for (uint32_t i = 0; i < childCount; i++) {
|
||||||
appendFormattedString(str, "\n");
|
appendFormattedString(str, "\n");
|
||||||
YGNodeToString(str, node->getChild(i), options, level + 1);
|
YGNodeToString(str, YGNodeGetChild(node, i), options, level + 1);
|
||||||
}
|
}
|
||||||
appendFormattedString(str, "\n");
|
appendFormattedString(str, "\n");
|
||||||
indent(str, level);
|
indent(str, level);
|
||||||
|
@@ -12,13 +12,12 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
#include <yoga/node/Node.h>
|
|
||||||
|
|
||||||
namespace facebook::yoga {
|
namespace facebook::yoga {
|
||||||
|
|
||||||
void YGNodeToString(
|
void YGNodeToString(
|
||||||
std::string& str,
|
std::string& str,
|
||||||
yoga::Node* node,
|
YGNodeRef node,
|
||||||
YGPrintOptions options,
|
YGPrintOptions options,
|
||||||
uint32_t level);
|
uint32_t level);
|
||||||
|
|
||||||
|
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
#include <yoga/style/CompactValue.h>
|
#include <yoga/style/CompactValue.h>
|
||||||
|
|
||||||
|
using YGVector = std::vector<YGNodeRef>;
|
||||||
|
|
||||||
YG_EXTERN_C_BEGIN
|
YG_EXTERN_C_BEGIN
|
||||||
|
|
||||||
void YGNodeCalculateLayoutWithContext(
|
void YGNodeCalculateLayoutWithContext(
|
||||||
|
364
yoga/Yoga.cpp
364
yoga/Yoga.cpp
File diff suppressed because it is too large
Load Diff
@@ -79,7 +79,7 @@ WIN_EXPORT void YGNodeRemoveAllChildren(YGNodeRef node);
|
|||||||
WIN_EXPORT YGNodeRef YGNodeGetChild(YGNodeRef node, uint32_t index);
|
WIN_EXPORT YGNodeRef YGNodeGetChild(YGNodeRef node, uint32_t index);
|
||||||
WIN_EXPORT YGNodeRef YGNodeGetOwner(YGNodeRef node);
|
WIN_EXPORT YGNodeRef YGNodeGetOwner(YGNodeRef node);
|
||||||
WIN_EXPORT YGNodeRef YGNodeGetParent(YGNodeRef node);
|
WIN_EXPORT YGNodeRef YGNodeGetParent(YGNodeRef node);
|
||||||
WIN_EXPORT uint32_t YGNodeGetChildCount(YGNodeConstRef node);
|
WIN_EXPORT uint32_t YGNodeGetChildCount(YGNodeRef node);
|
||||||
WIN_EXPORT void YGNodeSetChildren(
|
WIN_EXPORT void YGNodeSetChildren(
|
||||||
YGNodeRef owner,
|
YGNodeRef owner,
|
||||||
const YGNodeRef* children,
|
const YGNodeRef* children,
|
||||||
|
@@ -73,10 +73,7 @@ void Event::subscribe(std::function<Subscriber>&& subscriber) {
|
|||||||
push(new Node{std::move(subscriber)});
|
push(new Node{std::move(subscriber)});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Event::publish(
|
void Event::publish(const YGNode& node, Type eventType, const Data& eventData) {
|
||||||
YGNodeConstRef node,
|
|
||||||
Type eventType,
|
|
||||||
const Data& eventData) {
|
|
||||||
for (auto subscriber = subscribers.load(std::memory_order_relaxed);
|
for (auto subscriber = subscribers.load(std::memory_order_relaxed);
|
||||||
subscriber != nullptr;
|
subscriber != nullptr;
|
||||||
subscriber = subscriber->next) {
|
subscriber = subscriber->next) {
|
||||||
|
@@ -7,13 +7,15 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <yoga/Yoga.h>
|
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <yoga/YGEnums.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
struct YGConfig;
|
||||||
|
struct YGNode;
|
||||||
|
|
||||||
namespace facebook::yoga {
|
namespace facebook::yoga {
|
||||||
|
|
||||||
enum struct LayoutType : int {
|
enum struct LayoutType : int {
|
||||||
@@ -61,7 +63,7 @@ struct YOGA_EXPORT Event {
|
|||||||
NodeBaselineEnd,
|
NodeBaselineEnd,
|
||||||
};
|
};
|
||||||
class Data;
|
class Data;
|
||||||
using Subscriber = void(YGNodeConstRef, Type, Data);
|
using Subscriber = void(const YGNode&, Type, Data);
|
||||||
using Subscribers = std::vector<std::function<Subscriber>>;
|
using Subscribers = std::vector<std::function<Subscriber>>;
|
||||||
|
|
||||||
template <Type E>
|
template <Type E>
|
||||||
@@ -85,22 +87,27 @@ struct YOGA_EXPORT Event {
|
|||||||
static void subscribe(std::function<Subscriber>&& subscriber);
|
static void subscribe(std::function<Subscriber>&& subscriber);
|
||||||
|
|
||||||
template <Type E>
|
template <Type E>
|
||||||
static void publish(YGNodeConstRef node, const TypedData<E>& eventData = {}) {
|
static void publish(const YGNode& node, const TypedData<E>& eventData = {}) {
|
||||||
publish(node, E, Data{eventData});
|
publish(node, E, Data{eventData});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <Type E>
|
||||||
|
static void publish(const YGNode* node, const TypedData<E>& eventData = {}) {
|
||||||
|
publish<E>(*node, eventData);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void publish(YGNodeConstRef, Type, const Data&);
|
static void publish(const YGNode&, Type, const Data&);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct Event::TypedData<Event::NodeAllocation> {
|
struct Event::TypedData<Event::NodeAllocation> {
|
||||||
YGConfigRef config;
|
YGConfig* config;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct Event::TypedData<Event::NodeDeallocation> {
|
struct Event::TypedData<Event::NodeDeallocation> {
|
||||||
YGConfigRef config;
|
YGConfig* config;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include <yoga/config/Config.h>
|
#include <yoga/config/Config.h>
|
||||||
#include <yoga/node/Node.h>
|
#include "YGNode.h"
|
||||||
|
|
||||||
namespace facebook::yoga::detail {
|
namespace facebook::yoga::detail {
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ namespace {
|
|||||||
|
|
||||||
void vlog(
|
void vlog(
|
||||||
yoga::Config* config,
|
yoga::Config* config,
|
||||||
yoga::Node* node,
|
YGNode* node,
|
||||||
YGLogLevel level,
|
YGLogLevel level,
|
||||||
void* context,
|
void* context,
|
||||||
const char* format,
|
const char* format,
|
||||||
@@ -30,7 +30,7 @@ void vlog(
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
YOGA_EXPORT void Log::log(
|
YOGA_EXPORT void Log::log(
|
||||||
yoga::Node* node,
|
YGNode* node,
|
||||||
YGLogLevel level,
|
YGLogLevel level,
|
||||||
void* context,
|
void* context,
|
||||||
const char* format,
|
const char* format,
|
||||||
|
@@ -8,14 +8,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <yoga/YGEnums.h>
|
#include <yoga/YGEnums.h>
|
||||||
#include <yoga/node/Node.h>
|
|
||||||
#include <yoga/config/Config.h>
|
#include <yoga/config/Config.h>
|
||||||
|
|
||||||
|
struct YGNode;
|
||||||
|
struct YGConfig;
|
||||||
|
|
||||||
namespace facebook::yoga::detail {
|
namespace facebook::yoga::detail {
|
||||||
|
|
||||||
struct Log {
|
struct Log {
|
||||||
static void log(
|
static void log(
|
||||||
yoga::Node* node,
|
YGNode* node,
|
||||||
YGLogLevel level,
|
YGLogLevel level,
|
||||||
void*,
|
void*,
|
||||||
const char* message,
|
const char* message,
|
||||||
|
Reference in New Issue
Block a user