Add YGLayoutGetBorder, counterpart of YGLayoutGetPadding

Summary:
Followup of #335, fix #326. This commit add the `YGLayoutGetBorder(node, edge)` function, which correctly takes RTL/LTR into account when resolving `EDGE_START` & `EDGE_END`.
Closes https://github.com/facebook/yoga/pull/344

Reviewed By: dshahidehpour

Differential Revision: D4459950

Pulled By: emilsjolander

fbshipit-source-id: b57eb7a5b1c181a364913c3200a3794a2b7b31a6
This commit is contained in:
Maël Nison 2017-01-26 13:36:38 -08:00 committed by Facebook Github Bot
parent 48e346193a
commit 3a476a8321
2 changed files with 31 additions and 29 deletions

View File

@ -48,6 +48,7 @@ typedef struct YGLayout {
float position[4]; float position[4];
float dimensions[2]; float dimensions[2];
float margin[6]; float margin[6];
float border[6];
float padding[6]; float padding[6];
YGDirection direction; YGDirection direction;
@ -596,6 +597,7 @@ 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);
YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Margin, margin); YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Margin, margin);
YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Border, border);
YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Padding, padding); YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Padding, padding);
uint32_t gCurrentGenerationCount = 0; uint32_t gCurrentGenerationCount = 0;
@ -1764,39 +1766,35 @@ 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;
const YGFlexDirection flexRowDirection = YGFlexDirectionResolve(YGFlexDirectionRow, direction);
const YGFlexDirection flexColumnDirection = YGFlexDirectionResolve(YGFlexDirectionColumn, direction);
node->layout.margin[YGEdgeStart] = node->layout.margin[YGEdgeStart] =
YGNodeLeadingMargin(node, YGNodeLeadingMargin(node, flexRowDirection, parentWidth);
YGFlexDirectionResolve(YGFlexDirectionRow, direction),
parentWidth);
node->layout.margin[YGEdgeEnd] = node->layout.margin[YGEdgeEnd] =
YGNodeTrailingMargin(node, YGNodeTrailingMargin(node, flexRowDirection, parentWidth);
YGFlexDirectionResolve(YGFlexDirectionRow, direction),
parentWidth);
node->layout.margin[YGEdgeTop] = node->layout.margin[YGEdgeTop] =
YGNodeLeadingMargin(node, YGNodeLeadingMargin(node, flexColumnDirection, parentWidth);
YGFlexDirectionResolve(YGFlexDirectionColumn, direction),
parentWidth);
node->layout.margin[YGEdgeBottom] = node->layout.margin[YGEdgeBottom] =
YGNodeTrailingMargin(node, YGNodeTrailingMargin(node, flexColumnDirection, parentWidth);
YGFlexDirectionResolve(YGFlexDirectionColumn, direction),
parentWidth); node->layout.border[YGEdgeStart] =
YGNodeLeadingBorder(node, flexRowDirection);
node->layout.border[YGEdgeEnd] =
YGNodeTrailingBorder(node, flexRowDirection);
node->layout.border[YGEdgeTop] =
YGNodeLeadingBorder(node, flexColumnDirection);
node->layout.border[YGEdgeBottom] =
YGNodeTrailingBorder(node, flexColumnDirection);
node->layout.padding[YGEdgeStart] = node->layout.padding[YGEdgeStart] =
YGNodeLeadingPadding(node, YGNodeLeadingPadding(node, flexRowDirection, parentWidth);
YGFlexDirectionResolve(YGFlexDirectionRow, direction),
parentWidth);
node->layout.padding[YGEdgeEnd] = node->layout.padding[YGEdgeEnd] =
YGNodeTrailingPadding(node, YGNodeTrailingPadding(node, flexRowDirection, parentWidth);
YGFlexDirectionResolve(YGFlexDirectionRow, direction),
parentWidth);
node->layout.padding[YGEdgeTop] = node->layout.padding[YGEdgeTop] =
YGNodeLeadingPadding(node, YGNodeLeadingPadding(node, flexColumnDirection, parentWidth);
YGFlexDirectionResolve(YGFlexDirectionColumn, direction),
parentWidth);
node->layout.padding[YGEdgeBottom] = node->layout.padding[YGEdgeBottom] =
YGNodeTrailingPadding(node, YGNodeTrailingPadding(node, flexColumnDirection, parentWidth);
YGFlexDirectionResolve(YGFlexDirectionColumn, direction),
parentWidth);
if (node->measure) { if (node->measure) {
YGNodeWithMeasureFuncSetMeasuredDimensions( YGNodeWithMeasureFuncSetMeasuredDimensions(

View File

@ -139,6 +139,9 @@ WIN_EXPORT void YGNodeCopyStyle(const YGNodeRef dstNode, const YGNodeRef srcNode
#define YG_NODE_LAYOUT_PROPERTY(type, name) \ #define YG_NODE_LAYOUT_PROPERTY(type, name) \
WIN_EXPORT type YGNodeLayoutGet##name(const YGNodeRef node); WIN_EXPORT type YGNodeLayoutGet##name(const YGNodeRef node);
#define YG_NODE_LAYOUT_EDGE_PROPERTY(type, name) \
WIN_EXPORT type YGNodeLayoutGet##name(const YGNodeRef node, const YGEdge edge);
YG_NODE_PROPERTY(void *, Context, context); YG_NODE_PROPERTY(void *, Context, context);
YG_NODE_PROPERTY(YGMeasureFunc, MeasureFunc, measureFunc); YG_NODE_PROPERTY(YGMeasureFunc, MeasureFunc, measureFunc);
YG_NODE_PROPERTY(YGBaselineFunc, BaselineFunc, baselineFunc) YG_NODE_PROPERTY(YGBaselineFunc, BaselineFunc, baselineFunc)
@ -195,12 +198,13 @@ YG_NODE_LAYOUT_PROPERTY(float, Width);
YG_NODE_LAYOUT_PROPERTY(float, Height); YG_NODE_LAYOUT_PROPERTY(float, Height);
YG_NODE_LAYOUT_PROPERTY(YGDirection, Direction); YG_NODE_LAYOUT_PROPERTY(YGDirection, Direction);
// Get the computed padding for this node after performing layout. If padding was set using // Get the computed values for these nodes after performing layout. If they were set using
// 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 YGNodeStyleGetXXX. However if
// padding was set using a percentage value then the returned value is the computed value used // they were 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); YG_NODE_LAYOUT_EDGE_PROPERTY(float, Margin);
WIN_EXPORT float YGNodeLayoutGetPadding(const YGNodeRef node, const YGEdge edge); YG_NODE_LAYOUT_EDGE_PROPERTY(float, Border);
YG_NODE_LAYOUT_EDGE_PROPERTY(float, Padding);
WIN_EXPORT void YGSetLogger(YGLogger logger); WIN_EXPORT void YGSetLogger(YGLogger logger);
WIN_EXPORT void YGLog(YGLogLevel level, const char *message, ...); WIN_EXPORT void YGLog(YGLogLevel level, const char *message, ...);