Add YGLayoutGetMargin, counterpart of YGLayoutGetPadding
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -453,3 +453,13 @@ Layout Node::getComputedLayout(void) const
|
|||||||
|
|
||||||
return layout;
|
return layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double Node::getComputedMargin(int edge) const
|
||||||
|
{
|
||||||
|
return YGNodeLayoutGetMargin(m_node, static_cast<YGEdge>(edge));
|
||||||
|
}
|
||||||
|
|
||||||
|
double Node::getComputedPadding(int edge) const
|
||||||
|
{
|
||||||
|
return YGNodeLayoutGetPadding(m_node, static_cast<YGEdge>(edge));
|
||||||
|
}
|
||||||
|
@@ -176,6 +176,9 @@ class Node {
|
|||||||
|
|
||||||
Layout getComputedLayout(void) const;
|
Layout getComputedLayout(void) const;
|
||||||
|
|
||||||
|
double getComputedMargin(int edge) const;
|
||||||
|
double getComputedPadding(int edge) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
YGNodeRef m_node;
|
YGNodeRef m_node;
|
||||||
|
@@ -153,4 +153,7 @@ NBIND_CLASS(Node)
|
|||||||
method(getComputedHeight);
|
method(getComputedHeight);
|
||||||
|
|
||||||
method(getComputedLayout);
|
method(getComputedLayout);
|
||||||
|
|
||||||
|
method(getComputedMargin);
|
||||||
|
method(getComputedPadding);
|
||||||
}
|
}
|
||||||
|
33
javascript/tests/Facebook.Yoga/YGComputedMarginTest.js
Normal file
33
javascript/tests/Facebook.Yoga/YGComputedMarginTest.js
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2014-present, Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD-style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var Yoga = Yoga || require("../../sources/entry-" + process.env.TEST_ENTRY);
|
||||||
|
|
||||||
|
it("margin_start", function () {
|
||||||
|
var root = Yoga.Node.create();
|
||||||
|
root.setWidth(100);
|
||||||
|
root.setHeight(100);
|
||||||
|
root.setMargin(Yoga.EDGE_START, `10%`);
|
||||||
|
|
||||||
|
root.calculateLayout(100, 100, Yoga.DIRECTION_LTR);
|
||||||
|
|
||||||
|
console.assert(10 === root.getComputedMargin(Yoga.EDGE_LEFT), "10 === root.getComputedMargin(Yoga.EDGE_LEFT)");
|
||||||
|
console.assert(0 === root.getComputedMargin(Yoga.EDGE_RIGHT), "0 === root.getComputedMargin(Yoga.EDGE_RIGHT)");
|
||||||
|
|
||||||
|
root.calculateLayout(100, 100, Yoga.DIRECTION_RTL);
|
||||||
|
|
||||||
|
console.assert(0 === root.getComputedMargin(Yoga.EDGE_LEFT), "0 === root.getComputedMargin(Yoga.EDGE_LEFT)");
|
||||||
|
console.assert(10 === root.getComputedMargin(Yoga.EDGE_RIGHT), "10 === root.getComputedMargin(Yoga.EDGE_RIGHT)");
|
||||||
|
|
||||||
|
if (typeof root !== "undefined")
|
||||||
|
root.freeRecursive();
|
||||||
|
|
||||||
|
(typeof gc !== "undefined") && gc();
|
||||||
|
console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")");
|
||||||
|
});
|
33
javascript/tests/Facebook.Yoga/YGComputedPaddingTest.js
Normal file
33
javascript/tests/Facebook.Yoga/YGComputedPaddingTest.js
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2014-present, Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD-style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var Yoga = Yoga || require("../../sources/entry-" + process.env.TEST_ENTRY);
|
||||||
|
|
||||||
|
it("padding_start", function () {
|
||||||
|
var root = Yoga.Node.create();
|
||||||
|
root.setWidth(100);
|
||||||
|
root.setHeight(100);
|
||||||
|
root.setPadding(Yoga.EDGE_START, `10%`);
|
||||||
|
|
||||||
|
root.calculateLayout(100, 100, Yoga.DIRECTION_LTR);
|
||||||
|
|
||||||
|
console.assert(10 === root.getComputedPadding(Yoga.EDGE_LEFT), "10 === root.getComputedPadding(Yoga.EDGE_LEFT)");
|
||||||
|
console.assert(0 === root.getComputedPadding(Yoga.EDGE_RIGHT), "0 === root.getComputedPadding(Yoga.EDGE_RIGHT)");
|
||||||
|
|
||||||
|
root.calculateLayout(100, 100, Yoga.DIRECTION_RTL);
|
||||||
|
|
||||||
|
console.assert(0 === root.getComputedPadding(Yoga.EDGE_LEFT), "0 === root.getComputedPadding(Yoga.EDGE_LEFT)");
|
||||||
|
console.assert(10 === root.getComputedPadding(Yoga.EDGE_RIGHT), "10 === root.getComputedPadding(Yoga.EDGE_RIGHT)");
|
||||||
|
|
||||||
|
if (typeof root !== "undefined")
|
||||||
|
root.freeRecursive();
|
||||||
|
|
||||||
|
(typeof gc !== "undefined") && gc();
|
||||||
|
console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")");
|
||||||
|
});
|
30
tests/YGComputedMarginTest.cpp
Normal file
30
tests/YGComputedMarginTest.cpp
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2014-present, Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD-style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <yoga/Yoga.h>
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
TEST(YogaTest, computed_layout_margin) {
|
||||||
|
const YGNodeRef root = YGNodeNew();
|
||||||
|
YGNodeStyleSetWidth(root, 100);
|
||||||
|
YGNodeStyleSetHeight(root, 100);
|
||||||
|
YGNodeStyleSetMarginPercent(root, YGEdgeStart, 10);
|
||||||
|
|
||||||
|
YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetMargin(root, YGEdgeLeft));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetMargin(root, YGEdgeRight));
|
||||||
|
|
||||||
|
YGNodeCalculateLayout(root, 100, 100, YGDirectionRTL);
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetMargin(root, YGEdgeLeft));
|
||||||
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetMargin(root, YGEdgeRight));
|
||||||
|
|
||||||
|
YGNodeFreeRecursive(root);
|
||||||
|
}
|
64
yoga/Yoga.c
64
yoga/Yoga.c
@@ -47,6 +47,7 @@ typedef struct YGCachedMeasurement {
|
|||||||
typedef struct YGLayout {
|
typedef struct YGLayout {
|
||||||
float position[4];
|
float position[4];
|
||||||
float dimensions[2];
|
float dimensions[2];
|
||||||
|
float margin[6];
|
||||||
float padding[6];
|
float padding[6];
|
||||||
YGDirection direction;
|
YGDirection direction;
|
||||||
|
|
||||||
@@ -530,6 +531,29 @@ void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {
|
|||||||
return node->layout.instanceName; \
|
return node->layout.instanceName; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(type, name, instanceName) \
|
||||||
|
type YGNodeLayoutGet##name(const YGNodeRef node, const YGEdge edge) { \
|
||||||
|
YG_ASSERT(edge <= YGEdgeEnd, "Cannot get layout properties of multi-edge shorthands"); \
|
||||||
|
\
|
||||||
|
if (edge == YGEdgeLeft) { \
|
||||||
|
if (node->layout.direction == YGDirectionRTL) { \
|
||||||
|
return node->layout.instanceName[YGEdgeEnd]; \
|
||||||
|
} else { \
|
||||||
|
return node->layout.instanceName[YGEdgeStart]; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
if (edge == YGEdgeRight) { \
|
||||||
|
if (node->layout.direction == YGDirectionRTL) { \
|
||||||
|
return node->layout.instanceName[YGEdgeStart]; \
|
||||||
|
} else { \
|
||||||
|
return node->layout.instanceName[YGEdgeEnd]; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
return node->layout.instanceName[edge]; \
|
||||||
|
}
|
||||||
|
|
||||||
YG_NODE_PROPERTY_IMPL(void *, Context, context, context);
|
YG_NODE_PROPERTY_IMPL(void *, Context, context, context);
|
||||||
YG_NODE_PROPERTY_IMPL(YGPrintFunc, PrintFunc, printFunc, print);
|
YG_NODE_PROPERTY_IMPL(YGPrintFunc, PrintFunc, printFunc, print);
|
||||||
YG_NODE_PROPERTY_IMPL(bool, HasNewLayout, hasNewLayout, hasNewLayout);
|
YG_NODE_PROPERTY_IMPL(bool, HasNewLayout, hasNewLayout, hasNewLayout);
|
||||||
@@ -571,27 +595,8 @@ YG_NODE_LAYOUT_PROPERTY_IMPL(float, Width, dimensions[YGDimensionWidth]);
|
|||||||
YG_NODE_LAYOUT_PROPERTY_IMPL(float, Height, dimensions[YGDimensionHeight]);
|
YG_NODE_LAYOUT_PROPERTY_IMPL(float, Height, dimensions[YGDimensionHeight]);
|
||||||
YG_NODE_LAYOUT_PROPERTY_IMPL(YGDirection, Direction, direction);
|
YG_NODE_LAYOUT_PROPERTY_IMPL(YGDirection, Direction, direction);
|
||||||
|
|
||||||
float YGNodeLayoutGetPadding(const YGNodeRef node, const YGEdge edge) {
|
YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Margin, margin);
|
||||||
YG_ASSERT(edge <= YGEdgeEnd, "Cannot get layout paddings of multi-edge shorthands");
|
YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Padding, padding);
|
||||||
|
|
||||||
if (edge == YGEdgeLeft) {
|
|
||||||
if (node->layout.direction == YGDirectionRTL) {
|
|
||||||
return node->layout.padding[YGEdgeEnd];
|
|
||||||
} else {
|
|
||||||
return node->layout.padding[YGEdgeStart];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (edge == YGEdgeRight) {
|
|
||||||
if (node->layout.direction == YGDirectionRTL) {
|
|
||||||
return node->layout.padding[YGEdgeStart];
|
|
||||||
} else {
|
|
||||||
return node->layout.padding[YGEdgeEnd];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return node->layout.padding[edge];
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t gCurrentGenerationCount = 0;
|
uint32_t gCurrentGenerationCount = 0;
|
||||||
|
|
||||||
@@ -1742,6 +1747,23 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
const YGDirection direction = YGNodeResolveDirection(node, parentDirection);
|
const YGDirection direction = YGNodeResolveDirection(node, parentDirection);
|
||||||
node->layout.direction = direction;
|
node->layout.direction = direction;
|
||||||
|
|
||||||
|
node->layout.margin[YGEdgeStart] =
|
||||||
|
YGNodeLeadingMargin(node,
|
||||||
|
YGFlexDirectionResolve(YGFlexDirectionRow, direction),
|
||||||
|
parentWidth);
|
||||||
|
node->layout.margin[YGEdgeEnd] =
|
||||||
|
YGNodeTrailingMargin(node,
|
||||||
|
YGFlexDirectionResolve(YGFlexDirectionRow, direction),
|
||||||
|
parentWidth);
|
||||||
|
node->layout.margin[YGEdgeTop] =
|
||||||
|
YGNodeLeadingMargin(node,
|
||||||
|
YGFlexDirectionResolve(YGFlexDirectionColumn, direction),
|
||||||
|
parentWidth);
|
||||||
|
node->layout.margin[YGEdgeBottom] =
|
||||||
|
YGNodeTrailingMargin(node,
|
||||||
|
YGFlexDirectionResolve(YGFlexDirectionColumn, direction),
|
||||||
|
parentWidth);
|
||||||
|
|
||||||
node->layout.padding[YGEdgeStart] =
|
node->layout.padding[YGEdgeStart] =
|
||||||
YGNodeLeadingPadding(node,
|
YGNodeLeadingPadding(node,
|
||||||
YGFlexDirectionResolve(YGFlexDirectionRow, direction),
|
YGFlexDirectionResolve(YGFlexDirectionRow, direction),
|
||||||
|
@@ -199,6 +199,7 @@ YG_NODE_LAYOUT_PROPERTY(YGDirection, Direction);
|
|||||||
// pixel values then the returned value will be the same as YGNodeStyleGetPadding. However if
|
// pixel values then the returned value will be the same as YGNodeStyleGetPadding. However if
|
||||||
// padding was set using a percentage value then the returned value is the computed value used
|
// padding was set using a percentage value then the returned value is the computed value used
|
||||||
// during layout.
|
// during layout.
|
||||||
|
WIN_EXPORT float YGNodeLayoutGetMargin(const YGNodeRef node, const YGEdge edge);
|
||||||
WIN_EXPORT float YGNodeLayoutGetPadding(const YGNodeRef node, const YGEdge edge);
|
WIN_EXPORT float YGNodeLayoutGetPadding(const YGNodeRef node, const YGEdge edge);
|
||||||
|
|
||||||
WIN_EXPORT void YGSetLogger(YGLogger logger);
|
WIN_EXPORT void YGSetLogger(YGLogger logger);
|
||||||
|
Reference in New Issue
Block a user