run format.sh
This commit is contained in:
@@ -7,57 +7,57 @@
|
|||||||
* of patent rights can be found in the PATENTS file in the same directory.
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <yoga/Yoga.h>
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include <yoga/Yoga.h>
|
||||||
|
|
||||||
static float _baseline(YGNodeRef node) {
|
static float _baseline(YGNodeRef node) {
|
||||||
float *baseline = (float*) YGNodeGetContext(node);
|
float *baseline = (float *) YGNodeGetContext(node);
|
||||||
return *baseline;
|
return *baseline;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(YogaTest, align_baseline_customer_func) {
|
TEST(YogaTest, align_baseline_customer_func) {
|
||||||
const YGNodeRef root = YGNodeNew();
|
const YGNodeRef root = YGNodeNew();
|
||||||
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
||||||
YGNodeStyleSetAlignItems(root, YGAlignBaseline);
|
YGNodeStyleSetAlignItems(root, YGAlignBaseline);
|
||||||
YGNodeStyleSetWidth(root, 100);
|
YGNodeStyleSetWidth(root, 100);
|
||||||
YGNodeStyleSetHeight(root, 100);
|
YGNodeStyleSetHeight(root, 100);
|
||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
YGNodeStyleSetWidth(root_child0, 50);
|
YGNodeStyleSetWidth(root_child0, 50);
|
||||||
YGNodeStyleSetHeight(root_child0, 50);
|
YGNodeStyleSetHeight(root_child0, 50);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
const YGNodeRef root_child1 = YGNodeNew();
|
const YGNodeRef root_child1 = YGNodeNew();
|
||||||
YGNodeStyleSetWidth(root_child1, 50);
|
YGNodeStyleSetWidth(root_child1, 50);
|
||||||
YGNodeStyleSetHeight(root_child1, 20);
|
YGNodeStyleSetHeight(root_child1, 20);
|
||||||
YGNodeInsertChild(root, root_child1, 1);
|
YGNodeInsertChild(root, root_child1, 1);
|
||||||
|
|
||||||
float baselineValue = 10;
|
float baselineValue = 10;
|
||||||
const YGNodeRef root_child1_child0 = YGNodeNew();
|
const YGNodeRef root_child1_child0 = YGNodeNew();
|
||||||
YGNodeSetContext(root_child1_child0, &baselineValue);
|
YGNodeSetContext(root_child1_child0, &baselineValue);
|
||||||
YGNodeStyleSetWidth(root_child1_child0, 50);
|
YGNodeStyleSetWidth(root_child1_child0, 50);
|
||||||
YGNodeSetBaselineFunc(root_child1_child0, _baseline);
|
YGNodeSetBaselineFunc(root_child1_child0, _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);
|
||||||
|
|
||||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||||
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root));
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root));
|
||||||
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root));
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root));
|
||||||
|
|
||||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
||||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||||
|
|
||||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1));
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1));
|
||||||
ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1));
|
ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1));
|
||||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||||
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1));
|
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1));
|
||||||
|
|
||||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0));
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0));
|
||||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0));
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0));
|
||||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0));
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0));
|
||||||
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1_child0));
|
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1_child0));
|
||||||
}
|
}
|
||||||
|
64
yoga/Yoga.c
64
yoga/Yoga.c
@@ -335,7 +335,6 @@ YGMeasureFunc YGNodeGetMeasureFunc(const YGNodeRef node) {
|
|||||||
return node->measure;
|
return node->measure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void YGNodeSetBaselineFunc(const YGNodeRef node, YGBaselineFunc baselineFunc) {
|
void YGNodeSetBaselineFunc(const YGNodeRef node, YGBaselineFunc baselineFunc) {
|
||||||
node->baseline = baselineFunc;
|
node->baseline = baselineFunc;
|
||||||
}
|
}
|
||||||
@@ -951,61 +950,55 @@ static inline YGDirection YGNodeResolveDirection(const YGNodeRef node,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static float YGBaselineOfFirstLine(const YGNodeRef node,
|
||||||
static float YGBaselineOfFirstLine(const YGNodeRef node, const YGFlexDirection mainAxis, const float parentWidth)
|
const YGFlexDirection mainAxis,
|
||||||
{
|
const float parentWidth) {
|
||||||
if(node->baseline != NULL)
|
if (node->baseline != NULL) {
|
||||||
{
|
|
||||||
return node->baseline(node);
|
return node->baseline(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
YGNodeRef baselineChild = NULL;
|
YGNodeRef baselineChild = NULL;
|
||||||
for(uint32_t i = 0; i < YGNodeGetChildCount(node); i++)
|
for (uint32_t i = 0; i < YGNodeGetChildCount(node); i++) {
|
||||||
{
|
|
||||||
const YGNodeRef child = YGNodeGetChild(node, i);
|
const YGNodeRef child = YGNodeGetChild(node, i);
|
||||||
if(child->style.positionType == YGPositionTypeAbsolute || child->lineIndex > 0)
|
if (child->style.positionType == YGPositionTypeAbsolute || child->lineIndex > 0) {
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(YGNodeAlignItem(node, child) == YGAlignBaseline)
|
if (YGNodeAlignItem(node, child) == YGAlignBaseline) {
|
||||||
{
|
|
||||||
baselineChild = child;
|
baselineChild = child;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(baselineChild == NULL)
|
if (baselineChild == NULL) {
|
||||||
{
|
|
||||||
baselineChild = child;
|
baselineChild = child;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(baselineChild == NULL)
|
if (baselineChild == NULL) {
|
||||||
{
|
|
||||||
return YGUndefined;
|
return YGUndefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
float baseline = YGBaselineOfFirstLine(baselineChild, node->style.flexDirection, node->layout.measuredDimensions[YGDimensionWidth]);
|
float baseline = YGBaselineOfFirstLine(baselineChild,
|
||||||
if(YGFloatIsUndefined(baseline))
|
node->style.flexDirection,
|
||||||
{
|
node->layout.measuredDimensions[YGDimensionWidth]);
|
||||||
baseline = YGNodeLeadingPaddingAndBorder(baselineChild, mainAxis, parentWidth)
|
if (YGFloatIsUndefined(baseline)) {
|
||||||
+ baselineChild->layout.measuredDimensions[dim[mainAxis]];
|
baseline = YGNodeLeadingPaddingAndBorder(baselineChild, mainAxis, parentWidth) +
|
||||||
|
baselineChild->layout.measuredDimensions[dim[mainAxis]];
|
||||||
}
|
}
|
||||||
|
|
||||||
return baseline + baselineChild->layout.position[YGEdgeTop];
|
return baseline + baselineChild->layout.position[YGEdgeTop];
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline float YGBaselineForNode(const YGNodeRef node, const YGFlexDirection crossAxis, const float parentWidth)
|
static inline float YGBaselineForNode(const YGNodeRef node,
|
||||||
{
|
const YGFlexDirection crossAxis,
|
||||||
|
const float parentWidth) {
|
||||||
float baseline = YGBaselineOfFirstLine(node, crossAxis, parentWidth);
|
float baseline = YGBaselineOfFirstLine(node, crossAxis, parentWidth);
|
||||||
if(YGFloatIsUndefined(baseline))
|
if (YGFloatIsUndefined(baseline)) {
|
||||||
{
|
|
||||||
return node->layout.measuredDimensions[dim[crossAxis]];
|
return node->layout.measuredDimensions[dim[crossAxis]];
|
||||||
}
|
}
|
||||||
return baseline;
|
return baseline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline YGFlexDirection YGFlexDirectionResolve(const YGFlexDirection flexDirection,
|
static inline YGFlexDirection YGFlexDirectionResolve(const YGFlexDirection flexDirection,
|
||||||
const YGDirection direction) {
|
const YGDirection direction) {
|
||||||
if (direction == YGDirectionRTL) {
|
if (direction == YGDirectionRTL) {
|
||||||
@@ -1623,8 +1616,6 @@ static bool YGNodeFixedSizeSetMeasuredDimensions(const YGNodeRef node,
|
|||||||
// * Margins cannot be specified as 'auto'. They must be specified in terms of
|
// * Margins cannot be specified as 'auto'. They must be specified in terms of
|
||||||
// pixel
|
// pixel
|
||||||
// values, and the default value is 0.
|
// values, and the default value is 0.
|
||||||
// * The 'baseline' value is not supported for alignItems and alignSelf
|
|
||||||
// properties.
|
|
||||||
// * Values of width, maxWidth, minWidth, height, maxHeight and minHeight must
|
// * Values of width, maxWidth, minWidth, height, maxHeight and minHeight must
|
||||||
// be
|
// be
|
||||||
// specified as pixel values, not as percentages.
|
// specified as pixel values, not as percentages.
|
||||||
@@ -2487,7 +2478,8 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// STEP 8: MULTI-LINE CONTENT ALIGNMENT
|
// STEP 8: MULTI-LINE CONTENT ALIGNMENT
|
||||||
if ((node->style.alignItems == YGAlignBaseline || lineCount > 1) && performLayout && !YGFloatIsUndefined(availableInnerCrossDim)) {
|
if ((node->style.alignItems == YGAlignBaseline || lineCount > 1) && performLayout &&
|
||||||
|
!YGFloatIsUndefined(availableInnerCrossDim)) {
|
||||||
const float remainingAlignContentDim = availableInnerCrossDim - totalLineCrossDim;
|
const float remainingAlignContentDim = availableInnerCrossDim - totalLineCrossDim;
|
||||||
|
|
||||||
float crossDimLead = 0;
|
float crossDimLead = 0;
|
||||||
@@ -2519,7 +2511,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
// compute the line's height and find the endIndex
|
// compute the line's height and find the endIndex
|
||||||
float lineHeight = 0;
|
float lineHeight = 0;
|
||||||
float maxAscentForCurrentLine = 0;
|
float maxAscentForCurrentLine = 0;
|
||||||
float maxDescentForCurrentLine = 0;
|
float maxDescentForCurrentLine = 0;
|
||||||
for (ii = startIndex; ii < childCount; ii++) {
|
for (ii = startIndex; ii < childCount; ii++) {
|
||||||
const YGNodeRef child = YGNodeListGet(node->children, ii);
|
const YGNodeRef child = YGNodeListGet(node->children, ii);
|
||||||
|
|
||||||
@@ -2532,12 +2524,12 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
child->layout.measuredDimensions[dim[crossAxis]] +
|
child->layout.measuredDimensions[dim[crossAxis]] +
|
||||||
YGNodeMarginForAxis(child, crossAxis, availableInnerWidth));
|
YGNodeMarginForAxis(child, crossAxis, availableInnerWidth));
|
||||||
}
|
}
|
||||||
if (performLayout && YGNodeAlignItem(node, child) == YGAlignBaseline)
|
if (performLayout && YGNodeAlignItem(node, child) == YGAlignBaseline) {
|
||||||
{
|
|
||||||
const float ascent = YGBaselineForNode(child, crossAxis, availableInnerWidth) +
|
const float ascent = YGBaselineForNode(child, crossAxis, availableInnerWidth) +
|
||||||
YGNodeLeadingMargin(child, crossAxis, availableInnerWidth);
|
YGNodeLeadingMargin(child, crossAxis, availableInnerWidth);
|
||||||
const float descent = child->layout.measuredDimensions[dim[crossAxis]] +
|
const float descent = child->layout.measuredDimensions[dim[crossAxis]] +
|
||||||
YGNodeMarginForAxis(child, crossAxis, availableInnerWidth) - ascent;
|
YGNodeMarginForAxis(child, crossAxis, availableInnerWidth) -
|
||||||
|
ascent;
|
||||||
maxAscentForCurrentLine = fmaxf(maxAscentForCurrentLine, ascent);
|
maxAscentForCurrentLine = fmaxf(maxAscentForCurrentLine, ascent);
|
||||||
maxDescentForCurrentLine = fmaxf(maxDescentForCurrentLine, descent);
|
maxDescentForCurrentLine = fmaxf(maxDescentForCurrentLine, descent);
|
||||||
lineHeight = fmaxf(lineHeight, maxAscentForCurrentLine + maxDescentForCurrentLine);
|
lineHeight = fmaxf(lineHeight, maxAscentForCurrentLine + maxDescentForCurrentLine);
|
||||||
@@ -2580,8 +2572,8 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
}
|
}
|
||||||
case YGAlignBaseline: {
|
case YGAlignBaseline: {
|
||||||
child->layout.position[pos[crossAxis]] =
|
child->layout.position[pos[crossAxis]] =
|
||||||
currentLead + maxAscentForCurrentLine -
|
currentLead + maxAscentForCurrentLine -
|
||||||
YGBaselineForNode(child, crossAxis, availableInnerWidth);
|
YGBaselineForNode(child, crossAxis, availableInnerWidth);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case YGAlignAuto:
|
case YGAlignAuto:
|
||||||
|
@@ -50,7 +50,7 @@ typedef YGSize (*YGMeasureFunc)(YGNodeRef node,
|
|||||||
float height,
|
float height,
|
||||||
YGMeasureMode heightMode);
|
YGMeasureMode heightMode);
|
||||||
|
|
||||||
typedef float(*YGBaselineFunc)(YGNodeRef node);
|
typedef float (*YGBaselineFunc)(YGNodeRef node);
|
||||||
|
|
||||||
typedef void (*YGPrintFunc)(YGNodeRef node);
|
typedef void (*YGPrintFunc)(YGNodeRef node);
|
||||||
typedef int (*YGLogger)(YGLogLevel level, const char *format, va_list args);
|
typedef int (*YGLogger)(YGLogLevel level, const char *format, va_list args);
|
||||||
|
Reference in New Issue
Block a user