Make YGNode as c++ struct with properties exposed through accessors
Summary: Moved c implementation of `YGNode` to C++ struct. Not moving to C++ class as the React Classes dependent on `Yoga.h` assume it to be C. Thats why keeping `Yoga.h` C compatible. Sorry for the long diff, didn't thought that it will turn out to be this much big.Will keep an eye on number of lines next time 😉
Reviewed By: emilsjolander
Differential Revision: D6592257
fbshipit-source-id: 641e8b9462ad00731a094511f9f5608b23a6bb21
This commit is contained in:
committed by
Facebook Github Bot
parent
dbf6a12134
commit
fbd332dee8
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <yoga/YGNode.h>
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
struct _MeasureConstraint {
|
||||
@@ -27,8 +28,8 @@ static YGSize _measure(YGNodeRef node,
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode) {
|
||||
struct _MeasureConstraintList *constraintList =
|
||||
(struct _MeasureConstraintList *) YGNodeGetContext(node);
|
||||
struct _MeasureConstraintList* constraintList =
|
||||
(struct _MeasureConstraintList*)node->getContext();
|
||||
struct _MeasureConstraint *constraints = constraintList->constraints;
|
||||
uint32_t currentIndex = constraintList->length;
|
||||
(&constraints[currentIndex])->width = width;
|
||||
@@ -54,8 +55,10 @@ TEST(YogaTest, exactly_measure_stretched_child_column) {
|
||||
YGNodeStyleSetHeight(root, 100);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeSetContext(root_child0, &constraintList);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
// root_child0->setContext(&constraintList);
|
||||
root_child0->setContext(&constraintList);
|
||||
root_child0->setMeasureFunc(_measure);
|
||||
// root_child0->setMeasureFunc(_measure);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
@@ -81,8 +84,9 @@ TEST(YogaTest, exactly_measure_stretched_child_row) {
|
||||
YGNodeStyleSetHeight(root, 100);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeSetContext(root_child0, &constraintList);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
// root_child0->setContext(&constraintList);
|
||||
root_child0->setContext(&constraintList);
|
||||
root_child0->setMeasureFunc(_measure);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
@@ -107,8 +111,8 @@ TEST(YogaTest, at_most_main_axis_column) {
|
||||
YGNodeStyleSetHeight(root, 100);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeSetContext(root_child0, &constraintList);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
root_child0->setContext(&constraintList);
|
||||
root_child0->setMeasureFunc(_measure);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
@@ -134,8 +138,8 @@ TEST(YogaTest, at_most_cross_axis_column) {
|
||||
YGNodeStyleSetHeight(root, 100);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeSetContext(root_child0, &constraintList);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
root_child0->setContext(&constraintList);
|
||||
root_child0->setMeasureFunc(_measure);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
@@ -161,8 +165,8 @@ TEST(YogaTest, at_most_main_axis_row) {
|
||||
YGNodeStyleSetHeight(root, 100);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeSetContext(root_child0, &constraintList);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
root_child0->setContext(&constraintList);
|
||||
root_child0->setMeasureFunc(_measure);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
@@ -189,8 +193,8 @@ TEST(YogaTest, at_most_cross_axis_row) {
|
||||
YGNodeStyleSetHeight(root, 100);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeSetContext(root_child0, &constraintList);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
root_child0->setContext(&constraintList);
|
||||
root_child0->setMeasureFunc(_measure);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
@@ -215,8 +219,8 @@ TEST(YogaTest, flex_child) {
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeStyleSetFlexGrow(root_child0, 1);
|
||||
YGNodeSetContext(root_child0, &constraintList);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
root_child0->setContext(&constraintList);
|
||||
root_child0->setMeasureFunc(_measure);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
@@ -245,8 +249,8 @@ TEST(YogaTest, flex_child_with_flex_basis) {
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeStyleSetFlexGrow(root_child0, 1);
|
||||
YGNodeStyleSetFlexBasis(root_child0, 0);
|
||||
YGNodeSetContext(root_child0, &constraintList);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
root_child0->setContext(&constraintList);
|
||||
root_child0->setMeasureFunc(_measure);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
@@ -273,8 +277,8 @@ TEST(YogaTest, overflow_scroll_column) {
|
||||
YGNodeStyleSetWidth(root, 100);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeSetContext(root_child0, &constraintList);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
root_child0->setContext(&constraintList);
|
||||
root_child0->setMeasureFunc(_measure);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
@@ -305,8 +309,8 @@ TEST(YogaTest, overflow_scroll_row) {
|
||||
YGNodeStyleSetWidth(root, 100);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeSetContext(root_child0, &constraintList);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
root_child0->setContext(&constraintList);
|
||||
root_child0->setMeasureFunc(_measure);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
Reference in New Issue
Block a user