2017-01-06 06:51:56 -08:00
|
|
|
/**
|
2018-09-11 15:27:47 -07:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2017-01-06 06:51:56 -08:00
|
|
|
*
|
2018-11-29 11:35:34 -08:00
|
|
|
* This source code is licensed under the MIT license found in the LICENSE
|
|
|
|
* file in the root directory of this source tree.
|
2017-01-06 06:51:56 -08:00
|
|
|
*/
|
|
|
|
#include <gtest/gtest.h>
|
2017-12-19 11:18:00 -08:00
|
|
|
#include <yoga/YGNode.h>
|
2017-01-06 06:51:56 -08:00
|
|
|
#include <yoga/Yoga.h>
|
|
|
|
|
|
|
|
static float _baseline(YGNodeRef node, const float width, const float height) {
|
2017-12-19 11:18:00 -08:00
|
|
|
float* baseline = (float*)node->getContext();
|
2017-01-06 06:51:56 -08:00
|
|
|
return *baseline;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(YogaTest, align_baseline_customer_func) {
|
|
|
|
const YGNodeRef root = YGNodeNew();
|
|
|
|
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignBaseline);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
|
|
|
|
|
|
|
const YGNodeRef root_child0 = YGNodeNew();
|
|
|
|
YGNodeStyleSetWidth(root_child0, 50);
|
|
|
|
YGNodeStyleSetHeight(root_child0, 50);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
|
|
|
|
|
|
|
const YGNodeRef root_child1 = YGNodeNew();
|
|
|
|
YGNodeStyleSetWidth(root_child1, 50);
|
|
|
|
YGNodeStyleSetHeight(root_child1, 20);
|
|
|
|
YGNodeInsertChild(root, root_child1, 1);
|
|
|
|
|
|
|
|
float baselineValue = 10;
|
|
|
|
const YGNodeRef root_child1_child0 = YGNodeNew();
|
2017-12-19 11:18:00 -08:00
|
|
|
root_child1_child0->setContext(&baselineValue);
|
2017-01-06 06:51:56 -08:00
|
|
|
YGNodeStyleSetWidth(root_child1_child0, 50);
|
2019-02-21 05:35:52 -08:00
|
|
|
root_child1_child0->setBaselineFunc(_baseline);
|
2017-01-06 06:51:56 -08:00
|
|
|
YGNodeStyleSetHeight(root_child1_child0, 20);
|
|
|
|
YGNodeInsertChild(root_child1, root_child1_child0, 0);
|
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
|
|
|
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
|
|
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root));
|
|
|
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root));
|
|
|
|
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
|
|
|
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1));
|
|
|
|
ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1));
|
|
|
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
|
|
|
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1));
|
|
|
|
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0));
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0));
|
|
|
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0));
|
|
|
|
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1_child0));
|
|
|
|
}
|