Add api for retrieving computed padding
Summary: Add API for retrieving the computed final padding of a node. Many frameworks such as React Native retrieve padding via `YGNodeStyleGetPadding` but given that we now support percentage values this is not correct anymore. Differential Revision: D4376572 fbshipit-source-id: 3ffb66e77090fc1257511bec5c933f9b0c304b9f
This commit is contained in:
committed by
Facebook Github Bot
parent
a36faf89e3
commit
bf5eeaf61e
36
yoga/Yoga.c
36
yoga/Yoga.c
@@ -47,6 +47,7 @@ typedef struct YGCachedMeasurement {
|
||||
typedef struct YGLayout {
|
||||
float position[4];
|
||||
float dimensions[2];
|
||||
float padding[6];
|
||||
YGDirection direction;
|
||||
|
||||
uint32_t computedFlexBasisGeneration;
|
||||
@@ -563,6 +564,28 @@ YG_NODE_LAYOUT_PROPERTY_IMPL(float, Width, dimensions[YGDimensionWidth]);
|
||||
YG_NODE_LAYOUT_PROPERTY_IMPL(float, Height, dimensions[YGDimensionHeight]);
|
||||
YG_NODE_LAYOUT_PROPERTY_IMPL(YGDirection, Direction, direction);
|
||||
|
||||
float YGNodeLayoutGetPadding(const YGNodeRef node, const YGEdge edge) {
|
||||
YG_ASSERT(edge <= YGEdgeEnd, "Cannot get layout paddings of multi-edge shorthands");
|
||||
|
||||
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;
|
||||
|
||||
bool YGLayoutNodeInternal(const YGNodeRef node,
|
||||
@@ -870,8 +893,8 @@ static float YGNodeLeadingPadding(const YGNodeRef node,
|
||||
}
|
||||
|
||||
return fmaxf(YGValueResolve(YGComputedEdgeValue(node->style.padding, leading[axis], &YGValueZero),
|
||||
widthSize),
|
||||
0.0f);
|
||||
widthSize),
|
||||
0.0f);
|
||||
}
|
||||
|
||||
static float YGNodeTrailingPadding(const YGNodeRef node,
|
||||
@@ -883,8 +906,8 @@ static float YGNodeTrailingPadding(const YGNodeRef node,
|
||||
}
|
||||
|
||||
return fmaxf(YGValueResolve(YGComputedEdgeValue(node->style.padding, trailing[axis], &YGValueZero),
|
||||
widthSize),
|
||||
0.0f);
|
||||
widthSize),
|
||||
0.0f);
|
||||
}
|
||||
|
||||
static float YGNodeLeadingBorder(const YGNodeRef node, const YGFlexDirection axis) {
|
||||
@@ -1657,6 +1680,11 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
||||
const YGDirection direction = YGNodeResolveDirection(node, parentDirection);
|
||||
node->layout.direction = direction;
|
||||
|
||||
node->layout.padding[YGEdgeStart] = YGNodeLeadingPadding(node, YGFlexDirectionResolve(YGFlexDirectionRow, direction), parentWidth);
|
||||
node->layout.padding[YGEdgeEnd] = YGNodeTrailingPadding(node, YGFlexDirectionResolve(YGFlexDirectionRow, direction), parentWidth);
|
||||
node->layout.padding[YGEdgeTop] = YGNodeLeadingPadding(node, YGFlexDirectionResolve(YGFlexDirectionColumn, direction), parentWidth);
|
||||
node->layout.padding[YGEdgeBottom] = YGNodeTrailingPadding(node, YGFlexDirectionResolve(YGFlexDirectionColumn, direction), parentWidth);
|
||||
|
||||
if (node->measure) {
|
||||
YGNodeWithMeasureFuncSetMeasuredDimensions(
|
||||
node, availableWidth, availableHeight, widthMeasureMode, heightMeasureMode);
|
||||
|
Reference in New Issue
Block a user