2019-06-06 19:36:56 -07:00
|
|
|
/*
|
2022-10-04 13:59:32 -07:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2016-09-26 06:11:49 -07:00
|
|
|
*
|
2019-10-15 10:30:08 -07:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-09-26 06:11:49 -07:00
|
|
|
*/
|
2019-10-15 10:30:08 -07:00
|
|
|
|
2016-09-26 06:11:49 -07:00
|
|
|
#include <gtest/gtest.h>
|
2017-12-19 11:18:00 -08:00
|
|
|
#include <yoga/YGNode.h>
|
2017-01-31 09:28:10 -08:00
|
|
|
#include <yoga/Yoga.h>
|
2016-09-26 06:11:49 -07:00
|
|
|
|
|
|
|
struct _MeasureConstraint {
|
|
|
|
float width;
|
2016-12-02 05:47:43 -08:00
|
|
|
YGMeasureMode widthMode;
|
2016-09-26 06:11:49 -07:00
|
|
|
float height;
|
2016-12-02 05:47:43 -08:00
|
|
|
YGMeasureMode heightMode;
|
2016-09-26 06:11:49 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _MeasureConstraintList {
|
|
|
|
uint32_t length;
|
2019-03-25 05:37:36 -07:00
|
|
|
struct _MeasureConstraint* constraints;
|
2016-09-26 06:11:49 -07:00
|
|
|
};
|
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
static YGSize _measure(
|
|
|
|
YGNodeRef node,
|
|
|
|
float width,
|
|
|
|
YGMeasureMode widthMode,
|
|
|
|
float height,
|
|
|
|
YGMeasureMode heightMode) {
|
2017-12-19 11:18:00 -08:00
|
|
|
struct _MeasureConstraintList* constraintList =
|
2019-03-25 05:37:36 -07:00
|
|
|
(struct _MeasureConstraintList*) node->getContext();
|
|
|
|
struct _MeasureConstraint* constraints = constraintList->constraints;
|
2016-09-26 06:11:49 -07:00
|
|
|
uint32_t currentIndex = constraintList->length;
|
|
|
|
(&constraints[currentIndex])->width = width;
|
|
|
|
(&constraints[currentIndex])->widthMode = widthMode;
|
|
|
|
(&constraints[currentIndex])->height = height;
|
|
|
|
(&constraints[currentIndex])->heightMode = heightMode;
|
|
|
|
constraintList->length = currentIndex + 1;
|
|
|
|
|
2017-01-31 09:28:10 -08:00
|
|
|
return YGSize{
|
2023-01-09 13:59:19 -08:00
|
|
|
widthMode == YGMeasureModeUndefined ? 10 : width,
|
|
|
|
heightMode == YGMeasureModeUndefined ? 10 : width,
|
2016-09-26 06:11:49 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, exactly_measure_stretched_child_column) {
|
2017-01-31 09:28:10 -08:00
|
|
|
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
2023-01-09 13:59:19 -08:00
|
|
|
0,
|
|
|
|
(struct _MeasureConstraint*) malloc(
|
2019-03-25 05:37:36 -07:00
|
|
|
10 * sizeof(struct _MeasureConstraint)),
|
2016-09-26 06:11:49 -07:00
|
|
|
};
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGNodeRef root = YGNodeNew();
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGNodeRef root_child0 = YGNodeNew();
|
2017-12-19 11:18:00 -08:00
|
|
|
// root_child0->setContext(&constraintList);
|
|
|
|
root_child0->setContext(&constraintList);
|
|
|
|
root_child0->setMeasureFunc(_measure);
|
|
|
|
// root_child0->setMeasureFunc(_measure);
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2019-07-04 18:56:08 -07:00
|
|
|
ASSERT_EQ(1u, constraintList.length);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-11-22 02:46:00 -08:00
|
|
|
ASSERT_FLOAT_EQ(100, constraintList.constraints[0].width);
|
2016-12-02 05:47:43 -08:00
|
|
|
ASSERT_EQ(YGMeasureModeExactly, constraintList.constraints[0].widthMode);
|
2016-09-29 04:09:56 -07:00
|
|
|
|
|
|
|
free(constraintList.constraints);
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-09-26 06:11:49 -07:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, exactly_measure_stretched_child_row) {
|
2017-01-31 09:28:10 -08:00
|
|
|
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
2023-01-09 13:59:19 -08:00
|
|
|
0,
|
|
|
|
(struct _MeasureConstraint*) malloc(
|
2019-03-25 05:37:36 -07:00
|
|
|
10 * sizeof(struct _MeasureConstraint)),
|
2016-09-26 06:11:49 -07:00
|
|
|
};
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGNodeRef root = YGNodeNew();
|
|
|
|
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGNodeRef root_child0 = YGNodeNew();
|
2017-12-19 11:18:00 -08:00
|
|
|
// root_child0->setContext(&constraintList);
|
|
|
|
root_child0->setContext(&constraintList);
|
|
|
|
root_child0->setMeasureFunc(_measure);
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2019-07-04 18:56:08 -07:00
|
|
|
ASSERT_EQ(1u, constraintList.length);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-11-22 02:46:00 -08:00
|
|
|
ASSERT_FLOAT_EQ(100, constraintList.constraints[0].height);
|
2016-12-02 05:47:43 -08:00
|
|
|
ASSERT_EQ(YGMeasureModeExactly, constraintList.constraints[0].heightMode);
|
2016-09-29 04:09:56 -07:00
|
|
|
|
|
|
|
free(constraintList.constraints);
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-09-26 06:11:49 -07:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, at_most_main_axis_column) {
|
2017-01-31 09:28:10 -08:00
|
|
|
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
2023-01-09 13:59:19 -08:00
|
|
|
0,
|
|
|
|
(struct _MeasureConstraint*) malloc(
|
2019-03-25 05:37:36 -07:00
|
|
|
10 * sizeof(struct _MeasureConstraint)),
|
2016-09-26 06:11:49 -07:00
|
|
|
};
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGNodeRef root = YGNodeNew();
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGNodeRef root_child0 = YGNodeNew();
|
2017-12-19 11:18:00 -08:00
|
|
|
root_child0->setContext(&constraintList);
|
|
|
|
root_child0->setMeasureFunc(_measure);
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2019-07-04 18:56:08 -07:00
|
|
|
ASSERT_EQ(1u, constraintList.length);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-11-22 02:46:00 -08:00
|
|
|
ASSERT_FLOAT_EQ(100, constraintList.constraints[0].height);
|
2016-12-02 05:47:43 -08:00
|
|
|
ASSERT_EQ(YGMeasureModeAtMost, constraintList.constraints[0].heightMode);
|
2016-09-29 04:09:56 -07:00
|
|
|
|
|
|
|
free(constraintList.constraints);
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-09-26 06:11:49 -07:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, at_most_cross_axis_column) {
|
2017-01-31 09:28:10 -08:00
|
|
|
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
2023-01-09 13:59:19 -08:00
|
|
|
0,
|
|
|
|
(struct _MeasureConstraint*) malloc(
|
2019-03-25 05:37:36 -07:00
|
|
|
10 * sizeof(struct _MeasureConstraint)),
|
2016-09-26 06:11:49 -07:00
|
|
|
};
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGNodeRef root = YGNodeNew();
|
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGNodeRef root_child0 = YGNodeNew();
|
2017-12-19 11:18:00 -08:00
|
|
|
root_child0->setContext(&constraintList);
|
|
|
|
root_child0->setMeasureFunc(_measure);
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2019-07-04 18:56:08 -07:00
|
|
|
ASSERT_EQ(1u, constraintList.length);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-11-22 02:46:00 -08:00
|
|
|
ASSERT_FLOAT_EQ(100, constraintList.constraints[0].width);
|
2016-12-02 05:47:43 -08:00
|
|
|
ASSERT_EQ(YGMeasureModeAtMost, constraintList.constraints[0].widthMode);
|
2016-09-29 04:09:56 -07:00
|
|
|
|
|
|
|
free(constraintList.constraints);
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-09-26 06:11:49 -07:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, at_most_main_axis_row) {
|
2017-01-31 09:28:10 -08:00
|
|
|
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
2023-01-09 13:59:19 -08:00
|
|
|
0,
|
|
|
|
(struct _MeasureConstraint*) malloc(
|
2019-03-25 05:37:36 -07:00
|
|
|
10 * sizeof(struct _MeasureConstraint)),
|
2016-09-26 06:11:49 -07:00
|
|
|
};
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGNodeRef root = YGNodeNew();
|
|
|
|
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGNodeRef root_child0 = YGNodeNew();
|
2017-12-19 11:18:00 -08:00
|
|
|
root_child0->setContext(&constraintList);
|
|
|
|
root_child0->setMeasureFunc(_measure);
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2019-07-04 18:56:08 -07:00
|
|
|
ASSERT_EQ(1u, constraintList.length);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-11-22 02:46:00 -08:00
|
|
|
ASSERT_FLOAT_EQ(100, constraintList.constraints[0].width);
|
2016-12-02 05:47:43 -08:00
|
|
|
ASSERT_EQ(YGMeasureModeAtMost, constraintList.constraints[0].widthMode);
|
2016-09-29 04:09:56 -07:00
|
|
|
|
|
|
|
free(constraintList.constraints);
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-09-26 06:11:49 -07:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, at_most_cross_axis_row) {
|
2017-01-31 09:28:10 -08:00
|
|
|
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
2023-01-09 13:59:19 -08:00
|
|
|
0,
|
|
|
|
(struct _MeasureConstraint*) malloc(
|
2019-03-25 05:37:36 -07:00
|
|
|
10 * sizeof(struct _MeasureConstraint)),
|
2016-09-26 06:11:49 -07:00
|
|
|
};
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGNodeRef root = YGNodeNew();
|
|
|
|
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGNodeRef root_child0 = YGNodeNew();
|
2017-12-19 11:18:00 -08:00
|
|
|
root_child0->setContext(&constraintList);
|
|
|
|
root_child0->setMeasureFunc(_measure);
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2019-07-04 18:56:08 -07:00
|
|
|
ASSERT_EQ(1u, constraintList.length);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-11-22 02:46:00 -08:00
|
|
|
ASSERT_FLOAT_EQ(100, constraintList.constraints[0].height);
|
2016-12-02 05:47:43 -08:00
|
|
|
ASSERT_EQ(YGMeasureModeAtMost, constraintList.constraints[0].heightMode);
|
2016-09-29 04:09:56 -07:00
|
|
|
|
|
|
|
free(constraintList.constraints);
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-09-26 06:11:49 -07:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, flex_child) {
|
2017-01-31 09:28:10 -08:00
|
|
|
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
2023-01-09 13:59:19 -08:00
|
|
|
0,
|
|
|
|
(struct _MeasureConstraint*) malloc(
|
2019-03-25 05:37:36 -07:00
|
|
|
10 * sizeof(struct _MeasureConstraint)),
|
2016-09-26 06:11:49 -07:00
|
|
|
};
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGNodeRef root = YGNodeNew();
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGNodeRef root_child0 = YGNodeNew();
|
|
|
|
YGNodeStyleSetFlexGrow(root_child0, 1);
|
2017-12-19 11:18:00 -08:00
|
|
|
root_child0->setContext(&constraintList);
|
|
|
|
root_child0->setMeasureFunc(_measure);
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2019-07-04 18:56:08 -07:00
|
|
|
ASSERT_EQ(2u, constraintList.length);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-11-22 02:46:00 -08:00
|
|
|
ASSERT_FLOAT_EQ(100, constraintList.constraints[0].height);
|
2016-12-02 05:47:43 -08:00
|
|
|
ASSERT_EQ(YGMeasureModeAtMost, constraintList.constraints[0].heightMode);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-11-22 02:46:00 -08:00
|
|
|
ASSERT_FLOAT_EQ(100, constraintList.constraints[1].height);
|
2016-12-02 05:47:43 -08:00
|
|
|
ASSERT_EQ(YGMeasureModeExactly, constraintList.constraints[1].heightMode);
|
2016-09-29 04:09:56 -07:00
|
|
|
|
|
|
|
free(constraintList.constraints);
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-09-26 06:11:49 -07:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, flex_child_with_flex_basis) {
|
2017-01-31 09:28:10 -08:00
|
|
|
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
2023-01-09 13:59:19 -08:00
|
|
|
0,
|
|
|
|
(struct _MeasureConstraint*) malloc(
|
2019-03-25 05:37:36 -07:00
|
|
|
10 * sizeof(struct _MeasureConstraint)),
|
2016-09-26 06:11:49 -07:00
|
|
|
};
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGNodeRef root = YGNodeNew();
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGNodeRef root_child0 = YGNodeNew();
|
|
|
|
YGNodeStyleSetFlexGrow(root_child0, 1);
|
|
|
|
YGNodeStyleSetFlexBasis(root_child0, 0);
|
2017-12-19 11:18:00 -08:00
|
|
|
root_child0->setContext(&constraintList);
|
|
|
|
root_child0->setMeasureFunc(_measure);
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2019-07-04 18:56:08 -07:00
|
|
|
ASSERT_EQ(1u, constraintList.length);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-11-22 02:46:00 -08:00
|
|
|
ASSERT_FLOAT_EQ(100, constraintList.constraints[0].height);
|
2016-12-02 05:47:43 -08:00
|
|
|
ASSERT_EQ(YGMeasureModeExactly, constraintList.constraints[0].heightMode);
|
2016-09-29 04:09:56 -07:00
|
|
|
|
|
|
|
free(constraintList.constraints);
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-09-26 06:11:49 -07:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, overflow_scroll_column) {
|
2017-01-31 09:28:10 -08:00
|
|
|
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
2023-01-09 13:59:19 -08:00
|
|
|
0,
|
|
|
|
(struct _MeasureConstraint*) malloc(
|
2019-03-25 05:37:36 -07:00
|
|
|
10 * sizeof(struct _MeasureConstraint)),
|
2016-09-26 06:11:49 -07:00
|
|
|
};
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGNodeRef root = YGNodeNew();
|
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
|
|
|
YGNodeStyleSetOverflow(root, YGOverflowScroll);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGNodeRef root_child0 = YGNodeNew();
|
2017-12-19 11:18:00 -08:00
|
|
|
root_child0->setContext(&constraintList);
|
|
|
|
root_child0->setMeasureFunc(_measure);
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2019-07-04 18:56:08 -07:00
|
|
|
ASSERT_EQ(1u, constraintList.length);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-11-22 02:46:00 -08:00
|
|
|
ASSERT_FLOAT_EQ(100, constraintList.constraints[0].width);
|
2016-12-02 05:47:43 -08:00
|
|
|
ASSERT_EQ(YGMeasureModeAtMost, constraintList.constraints[0].widthMode);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
Add feature to use percentage as value unit
Summary:
Adds the feature to use percentage as a value unit.
You can use the function ```YGPx(float)``` and ```YGPercent(float)``` for convenience.
I did some benchmarks:
```
Without Percentage Feature - Release x86:
Stack with flex: median: 0.000000 ms, stddev: 0.146683 ms
Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.136525 ms
Nested flex: median: 0.000000 ms, stddev: 0.490101 ms
Huge nested layout: median: 23.000000 ms, stddev: 0.928291 ms
Stack with flex: median: 0.000000 ms, stddev: 0.170587 ms
Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.143384 ms
Nested flex: median: 0.000000 ms, stddev: 0.477791 ms
Huge nested layout: median: 22.000000 ms, stddev: 2.129779 ms
With Percentage Feature - Release x86:
Stack with flex: median: 0.000000 ms, stddev: 0.132951 ms
Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.136525 ms
Nested flex: median: 0.000000 ms, stddev: 0.489570 ms
Huge nested layout: median: 21.000000 ms, stddev: 1.390476 ms
Closes https://github.com/facebook/yoga/pull/258
Reviewed By: dshahidehpour
Differential Revision: D4361945
Pulled By: emilsjolander
fbshipit-source-id: a8f5bc63ad352eb9410d792729e56664468cd76a
2017-01-02 05:20:37 -08:00
|
|
|
ASSERT_TRUE(YGFloatIsUndefined(constraintList.constraints[0].height));
|
2016-12-02 05:47:43 -08:00
|
|
|
ASSERT_EQ(YGMeasureModeUndefined, constraintList.constraints[0].heightMode);
|
2016-09-29 04:09:56 -07:00
|
|
|
|
|
|
|
free(constraintList.constraints);
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-09-26 06:11:49 -07:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, overflow_scroll_row) {
|
2017-01-31 09:28:10 -08:00
|
|
|
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
2023-01-09 13:59:19 -08:00
|
|
|
0,
|
|
|
|
(struct _MeasureConstraint*) malloc(
|
2019-03-25 05:37:36 -07:00
|
|
|
10 * sizeof(struct _MeasureConstraint)),
|
2016-09-26 06:11:49 -07:00
|
|
|
};
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGNodeRef root = YGNodeNew();
|
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
|
|
|
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
|
|
|
YGNodeStyleSetOverflow(root, YGOverflowScroll);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGNodeRef root_child0 = YGNodeNew();
|
2017-12-19 11:18:00 -08:00
|
|
|
root_child0->setContext(&constraintList);
|
|
|
|
root_child0->setMeasureFunc(_measure);
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2019-07-04 18:56:08 -07:00
|
|
|
ASSERT_EQ(1u, constraintList.length);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
Add feature to use percentage as value unit
Summary:
Adds the feature to use percentage as a value unit.
You can use the function ```YGPx(float)``` and ```YGPercent(float)``` for convenience.
I did some benchmarks:
```
Without Percentage Feature - Release x86:
Stack with flex: median: 0.000000 ms, stddev: 0.146683 ms
Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.136525 ms
Nested flex: median: 0.000000 ms, stddev: 0.490101 ms
Huge nested layout: median: 23.000000 ms, stddev: 0.928291 ms
Stack with flex: median: 0.000000 ms, stddev: 0.170587 ms
Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.143384 ms
Nested flex: median: 0.000000 ms, stddev: 0.477791 ms
Huge nested layout: median: 22.000000 ms, stddev: 2.129779 ms
With Percentage Feature - Release x86:
Stack with flex: median: 0.000000 ms, stddev: 0.132951 ms
Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.136525 ms
Nested flex: median: 0.000000 ms, stddev: 0.489570 ms
Huge nested layout: median: 21.000000 ms, stddev: 1.390476 ms
Closes https://github.com/facebook/yoga/pull/258
Reviewed By: dshahidehpour
Differential Revision: D4361945
Pulled By: emilsjolander
fbshipit-source-id: a8f5bc63ad352eb9410d792729e56664468cd76a
2017-01-02 05:20:37 -08:00
|
|
|
ASSERT_TRUE(YGFloatIsUndefined(constraintList.constraints[0].width));
|
2016-12-02 05:47:43 -08:00
|
|
|
ASSERT_EQ(YGMeasureModeUndefined, constraintList.constraints[0].widthMode);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-11-22 02:46:00 -08:00
|
|
|
ASSERT_FLOAT_EQ(100, constraintList.constraints[0].height);
|
2016-12-02 05:47:43 -08:00
|
|
|
ASSERT_EQ(YGMeasureModeAtMost, constraintList.constraints[0].heightMode);
|
2016-09-26 06:11:49 -07:00
|
|
|
|
2016-09-29 04:09:56 -07:00
|
|
|
free(constraintList.constraints);
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-09-29 04:09:56 -07:00
|
|
|
}
|