Feature auto margin #357
18
yoga/Yoga.c
18
yoga/Yoga.c
@@ -271,6 +271,7 @@ static inline const YGValue *YGComputedEdgeValue(const YGValue edges[YGEdgeCount
|
|||||||
static inline float YGValueResolve(const YGValue *const value, const float parentSize) {
|
static inline float YGValueResolve(const YGValue *const value, const float parentSize) {
|
||||||
switch (value->unit) {
|
switch (value->unit) {
|
||||||
case YGUnitUndefined:
|
case YGUnitUndefined:
|
||||||
|
case YGUnitAuto:
|
||||||
return YGUndefined;
|
return YGUndefined;
|
||||||
case YGUnitPixel:
|
case YGUnitPixel:
|
||||||
return value->value;
|
return value->value;
|
||||||
@@ -280,6 +281,10 @@ static inline float YGValueResolve(const YGValue *const value, const float paren
|
|||||||
return YGUndefined;
|
return YGUndefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline float YGValueResolveMargin(const YGValue *const value, const float parentSize) {
|
||||||
|
return value->unit == YGUnitAuto ? 0 : YGValueResolve(value, parentSize);
|
||||||
|
}
|
||||||
|
|
||||||
int32_t gNodeInstanceCount = 0;
|
int32_t gNodeInstanceCount = 0;
|
||||||
|
|
||||||
YGNodeRef YGNodeNew(void) {
|
YGNodeRef YGNodeNew(void) {
|
||||||
@@ -544,7 +549,6 @@ void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {
|
|||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(type, name, paramName, instanceName) \
|
#define YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(type, name, paramName, instanceName) \
|
||||||
void YGNodeStyleSet##name(const YGNodeRef node, const YGEdge edge, const float paramName) { \
|
void YGNodeStyleSet##name(const YGNodeRef node, const YGEdge edge, const float paramName) { \
|
||||||
if (node->style.instanceName[edge].value != paramName || \
|
if (node->style.instanceName[edge].value != paramName || \
|
||||||
@@ -635,6 +639,7 @@ YG_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexShrink, flexShrink, flexShrink);
|
|||||||
YG_NODE_STYLE_PROPERTY_SETTER_UNIT_IMPL(float, FlexBasis, flexBasis, flexBasis);
|
YG_NODE_STYLE_PROPERTY_SETTER_UNIT_IMPL(float, FlexBasis, flexBasis, flexBasis);
|
||||||
|
|
||||||
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(YGValue, Position, position, position);
|
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(YGValue, Position, position, position);
|
||||||
|
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(YGValue, Margin, margin, margin);
|
||||||
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_AUTO_IMPL(YGValue, Margin, margin);
|
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_AUTO_IMPL(YGValue, Margin, margin);
|
||||||
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(YGValue, Padding, padding, padding);
|
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(YGValue, Padding, padding, padding);
|
||||||
YG_NODE_STYLE_EDGE_PROPERTY_IMPL(float, Border, border, border);
|
YG_NODE_STYLE_EDGE_PROPERTY_IMPL(float, Border, border, border);
|
||||||
@@ -952,10 +957,10 @@ static inline float YGNodeLeadingMargin(const YGNodeRef node,
|
|||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) {
|
const float widthSize) {
|
||||||
if (YGFlexDirectionIsRow(axis) && node->style.margin[YGEdgeStart].unit != YGUnitUndefined) {
|
if (YGFlexDirectionIsRow(axis) && node->style.margin[YGEdgeStart].unit != YGUnitUndefined) {
|
||||||
return YGValueResolve(&node->style.margin[YGEdgeStart], widthSize);
|
return YGValueResolveMargin(&node->style.margin[YGEdgeStart], widthSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
return YGValueResolve(YGComputedEdgeValue(node->style.margin, leading[axis], &YGValueZero),
|
return YGValueResolveMargin(YGComputedEdgeValue(node->style.margin, leading[axis], &YGValueZero),
|
||||||
widthSize);
|
widthSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -963,10 +968,10 @@ static float YGNodeTrailingMargin(const YGNodeRef node,
|
|||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) {
|
const float widthSize) {
|
||||||
if (YGFlexDirectionIsRow(axis) && node->style.margin[YGEdgeEnd].unit != YGUnitUndefined) {
|
if (YGFlexDirectionIsRow(axis) && node->style.margin[YGEdgeEnd].unit != YGUnitUndefined) {
|
||||||
return YGValueResolve(&node->style.margin[YGEdgeEnd], widthSize);
|
return YGValueResolveMargin(&node->style.margin[YGEdgeEnd], widthSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
return YGValueResolve(YGComputedEdgeValue(node->style.margin, trailing[axis], &YGValueZero),
|
return YGValueResolveMargin(YGComputedEdgeValue(node->style.margin, trailing[axis], &YGValueZero),
|
||||||
widthSize);
|
widthSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2559,8 +2564,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
mainDim += betweenMainDim + YGNodeDimWithMargin(child, mainAxis, availableInnerWidth);
|
mainDim += betweenMainDim + YGNodeDimWithMargin(child, mainAxis, availableInnerWidth);
|
||||||
|
|
||||||
if (YGNodeIsStyleDimDefined(child, crossAxis, availableInnerCrossDim) ||
|
if (YGNodeIsStyleDimDefined(child, crossAxis, availableInnerCrossDim) ||
|
||||||
child->measure != NULL ||
|
child->measure != NULL || !isNodeFlexWrap) {
|
||||||
!isNodeFlexWrap) {
|
|
||||||
// The cross dimension is the max of the elements dimension since
|
// The cross dimension is the max of the elements dimension since
|
||||||
// there
|
// there
|
||||||
// can only be one element in that cross dimension.
|
// can only be one element in that cross dimension.
|
||||||
|
Reference in New Issue
Block a user