Use single function for margin, position, padding, and border
Summary: marginLeft(node, margin) -> margin(node, CSSEdgeLeft, margin) This reduces the api surface of CSSLayout as well as puts the api more in line with the java version. This also adds support for CSSEdgeAll which java has had support for for a while. This also open up the possibility of doing margin(node, CSSEdgeLeft | CSSEdgeTop, margin) in the future. Reviewed By: lucasr Differential Revision: D3715201 fbshipit-source-id: ea81ed426f0f7853bb542355c01fc16ae4360238
This commit is contained in:
committed by
Facebook Github Bot 6
parent
48e5304276
commit
a960203567
@@ -62,16 +62,6 @@ typedef struct CSSStyle {
|
||||
float flexBasis;
|
||||
float margin[6];
|
||||
float position[6];
|
||||
/**
|
||||
* You should skip all the rules that contain negative values for the
|
||||
* following attributes. For example:
|
||||
* {padding: 10, paddingLeft: -5}
|
||||
* should output:
|
||||
* {left: 10 ...}
|
||||
* the following two are incorrect:
|
||||
* {left: -5 ...}
|
||||
* {left: 0 ...}
|
||||
*/
|
||||
float padding[6];
|
||||
float border[6];
|
||||
float dimensions[2];
|
||||
|
@@ -179,6 +179,37 @@ float CSSNodeStyleGetFlex(CSSNodeRef node) {
|
||||
return node->style.instanceName; \
|
||||
}
|
||||
|
||||
#define CSS_NODE_STYLE_EDGE_PROPERTY_IMPL(type, name, paramName, instanceName) \
|
||||
void CSSNodeStyleSet##name(CSSNodeRef node, CSSEdge edge, type paramName) { \
|
||||
switch (edge) { \
|
||||
case CSSEdgeHorizontal: \
|
||||
CSSNodeStyleSet##name(node, CSSEdgeLeft, paramName); \
|
||||
CSSNodeStyleSet##name(node, CSSEdgeRight, paramName); \
|
||||
CSSNodeStyleSet##name(node, CSSEdgeStart, paramName); \
|
||||
CSSNodeStyleSet##name(node, CSSEdgeEnd, paramName); \
|
||||
break; \
|
||||
case CSSEdgeVertical: \
|
||||
CSSNodeStyleSet##name(node, CSSEdgeTop, paramName); \
|
||||
CSSNodeStyleSet##name(node, CSSEdgeBottom, paramName); \
|
||||
break; \
|
||||
case CSSEdgeAll: \
|
||||
CSSNodeStyleSet##name(node, CSSEdgeHorizontal, paramName); \
|
||||
CSSNodeStyleSet##name(node, CSSEdgeVertical, paramName); \
|
||||
break; \
|
||||
default: \
|
||||
if (node->style.instanceName[edge] != paramName) { \
|
||||
node->style.instanceName[edge] = paramName; \
|
||||
_CSSNodeMarkDirty(node); \
|
||||
} \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
type CSSNodeStyleGet##name(CSSNodeRef node, CSSEdge edge) { \
|
||||
CSS_ASSERT(edge <= CSSEdgeEnd, "Cannot get value of compound edge"); \
|
||||
return node->style.instanceName[edge]; \
|
||||
}
|
||||
|
||||
#define CSS_NODE_LAYOUT_PROPERTY_IMPL(type, name, instanceName) \
|
||||
type CSSNodeLayoutGet##name(CSSNodeRef node) { \
|
||||
return node->layout.instanceName; \
|
||||
@@ -203,33 +234,10 @@ CSS_NODE_STYLE_PROPERTY_IMPL(float, FlexGrow, flexGrow, flexGrow);
|
||||
CSS_NODE_STYLE_PROPERTY_IMPL(float, FlexShrink, flexShrink, flexShrink);
|
||||
CSS_NODE_STYLE_PROPERTY_IMPL(float, FlexBasis, flexBasis, flexBasis);
|
||||
|
||||
CSS_NODE_STYLE_PROPERTY_IMPL(float, PositionLeft, positionLeft, position[CSSPositionLeft]);
|
||||
CSS_NODE_STYLE_PROPERTY_IMPL(float, PositionTop, positionTop, position[CSSPositionTop]);
|
||||
CSS_NODE_STYLE_PROPERTY_IMPL(float, PositionRight, positionRight, position[CSSPositionRight]);
|
||||
CSS_NODE_STYLE_PROPERTY_IMPL(float, PositionBottom, positionBottom, position[CSSPositionBottom]);
|
||||
CSS_NODE_STYLE_PROPERTY_IMPL(float, PositionStart, positionStart, position[CSSPositionStart]);
|
||||
CSS_NODE_STYLE_PROPERTY_IMPL(float, PositionEnd, positionEnd, position[CSSPositionEnd]);
|
||||
|
||||
CSS_NODE_STYLE_PROPERTY_IMPL(float, MarginLeft, marginLeft, margin[CSSPositionLeft]);
|
||||
CSS_NODE_STYLE_PROPERTY_IMPL(float, MarginTop, marginTop, margin[CSSPositionTop]);
|
||||
CSS_NODE_STYLE_PROPERTY_IMPL(float, MarginRight, marginRight, margin[CSSPositionRight]);
|
||||
CSS_NODE_STYLE_PROPERTY_IMPL(float, MarginBottom, marginBottom, margin[CSSPositionBottom]);
|
||||
CSS_NODE_STYLE_PROPERTY_IMPL(float, MarginStart, marginStart, margin[CSSPositionStart]);
|
||||
CSS_NODE_STYLE_PROPERTY_IMPL(float, MarginEnd, marginEnd, margin[CSSPositionEnd]);
|
||||
|
||||
CSS_NODE_STYLE_PROPERTY_IMPL(float, PaddingLeft, paddingLeft, padding[CSSPositionLeft]);
|
||||
CSS_NODE_STYLE_PROPERTY_IMPL(float, PaddingTop, paddingTop, padding[CSSPositionTop]);
|
||||
CSS_NODE_STYLE_PROPERTY_IMPL(float, PaddingRight, paddingRight, padding[CSSPositionRight]);
|
||||
CSS_NODE_STYLE_PROPERTY_IMPL(float, PaddingBottom, paddingBottom, padding[CSSPositionBottom]);
|
||||
CSS_NODE_STYLE_PROPERTY_IMPL(float, PaddingStart, paddingStart, padding[CSSPositionStart]);
|
||||
CSS_NODE_STYLE_PROPERTY_IMPL(float, PaddingEnd, paddingEnd, padding[CSSPositionEnd]);
|
||||
|
||||
CSS_NODE_STYLE_PROPERTY_IMPL(float, BorderLeft, borderLeft, border[CSSPositionLeft]);
|
||||
CSS_NODE_STYLE_PROPERTY_IMPL(float, BorderTop, borderTop, border[CSSPositionTop]);
|
||||
CSS_NODE_STYLE_PROPERTY_IMPL(float, BorderRight, borderRight, border[CSSPositionRight]);
|
||||
CSS_NODE_STYLE_PROPERTY_IMPL(float, BorderBottom, borderBottom, border[CSSPositionBottom]);
|
||||
CSS_NODE_STYLE_PROPERTY_IMPL(float, BorderStart, borderStart, border[CSSPositionStart]);
|
||||
CSS_NODE_STYLE_PROPERTY_IMPL(float, BorderEnd, BorderEnd, border[CSSPositionEnd]);
|
||||
CSS_NODE_STYLE_EDGE_PROPERTY_IMPL(float, Position, position, position);
|
||||
CSS_NODE_STYLE_EDGE_PROPERTY_IMPL(float, Margin, margin, margin);
|
||||
CSS_NODE_STYLE_EDGE_PROPERTY_IMPL(float, Padding, padding, padding);
|
||||
CSS_NODE_STYLE_EDGE_PROPERTY_IMPL(float, Border, border, border);
|
||||
|
||||
CSS_NODE_STYLE_PROPERTY_IMPL(float, Width, width, dimensions[CSSDimensionWidth]);
|
||||
CSS_NODE_STYLE_PROPERTY_IMPL(float, Height, height, dimensions[CSSDimensionHeight]);
|
||||
|
@@ -101,6 +101,18 @@ typedef enum CSSDimension {
|
||||
CSSDimensionHeight,
|
||||
} CSSDimension;
|
||||
|
||||
typedef enum CSSEdge {
|
||||
CSSEdgeLeft,
|
||||
CSSEdgeTop,
|
||||
CSSEdgeRight,
|
||||
CSSEdgeBottom,
|
||||
CSSEdgeStart,
|
||||
CSSEdgeEnd,
|
||||
CSSEdgeHorizontal,
|
||||
CSSEdgeVertical,
|
||||
CSSEdgeAll,
|
||||
} CSSEdge;
|
||||
|
||||
typedef enum CSSPrintOptions {
|
||||
CSSPrintOptionsLayout = 1,
|
||||
CSSPrintOptionsStyle = 2,
|
||||
@@ -156,6 +168,10 @@ bool CSSValueIsUndefined(float value);
|
||||
void CSSNodeStyleSet##name(CSSNodeRef node, type paramName); \
|
||||
type CSSNodeStyleGet##name(CSSNodeRef node);
|
||||
|
||||
#define CSS_NODE_STYLE_EDGE_PROPERTY(type, name, paramName) \
|
||||
void CSSNodeStyleSet##name(CSSNodeRef node, CSSEdge edge, type paramName); \
|
||||
type CSSNodeStyleGet##name(CSSNodeRef node, CSSEdge edge);
|
||||
|
||||
#define CSS_NODE_LAYOUT_PROPERTY(type, name) type CSSNodeLayoutGet##name(CSSNodeRef node);
|
||||
|
||||
CSS_NODE_PROPERTY(void *, Context, context);
|
||||
@@ -178,33 +194,10 @@ CSS_NODE_STYLE_PROPERTY(float, FlexGrow, flexGrow);
|
||||
CSS_NODE_STYLE_PROPERTY(float, FlexShrink, flexShrink);
|
||||
CSS_NODE_STYLE_PROPERTY(float, FlexBasis, flexBasis);
|
||||
|
||||
CSS_NODE_STYLE_PROPERTY(float, PositionLeft, positionLeft);
|
||||
CSS_NODE_STYLE_PROPERTY(float, PositionTop, positionTop);
|
||||
CSS_NODE_STYLE_PROPERTY(float, PositionRight, positionRight);
|
||||
CSS_NODE_STYLE_PROPERTY(float, PositionBottom, positionBottom);
|
||||
CSS_NODE_STYLE_PROPERTY(float, PositionStart, positionStart);
|
||||
CSS_NODE_STYLE_PROPERTY(float, PositionEnd, positionEnd);
|
||||
|
||||
CSS_NODE_STYLE_PROPERTY(float, MarginLeft, marginLeft);
|
||||
CSS_NODE_STYLE_PROPERTY(float, MarginTop, marginTop);
|
||||
CSS_NODE_STYLE_PROPERTY(float, MarginRight, marginRight);
|
||||
CSS_NODE_STYLE_PROPERTY(float, MarginBottom, marginBottom);
|
||||
CSS_NODE_STYLE_PROPERTY(float, MarginStart, marginStart);
|
||||
CSS_NODE_STYLE_PROPERTY(float, MarginEnd, marginEnd);
|
||||
|
||||
CSS_NODE_STYLE_PROPERTY(float, PaddingLeft, paddingLeft);
|
||||
CSS_NODE_STYLE_PROPERTY(float, PaddingTop, paddingTop);
|
||||
CSS_NODE_STYLE_PROPERTY(float, PaddingRight, paddingRight);
|
||||
CSS_NODE_STYLE_PROPERTY(float, PaddingBottom, paddingBottom);
|
||||
CSS_NODE_STYLE_PROPERTY(float, PaddingStart, paddingStart);
|
||||
CSS_NODE_STYLE_PROPERTY(float, PaddingEnd, paddingEnd);
|
||||
|
||||
CSS_NODE_STYLE_PROPERTY(float, BorderLeft, borderLeft);
|
||||
CSS_NODE_STYLE_PROPERTY(float, BorderTop, borderTop);
|
||||
CSS_NODE_STYLE_PROPERTY(float, BorderRight, borderRight);
|
||||
CSS_NODE_STYLE_PROPERTY(float, BorderBottom, borderBottom);
|
||||
CSS_NODE_STYLE_PROPERTY(float, BorderStart, borderStart);
|
||||
CSS_NODE_STYLE_PROPERTY(float, BorderEnd, borderEnd);
|
||||
CSS_NODE_STYLE_EDGE_PROPERTY(float, Position, position);
|
||||
CSS_NODE_STYLE_EDGE_PROPERTY(float, Margin, margin);
|
||||
CSS_NODE_STYLE_EDGE_PROPERTY(float, Padding, padding);
|
||||
CSS_NODE_STYLE_EDGE_PROPERTY(float, Border, border);
|
||||
|
||||
CSS_NODE_STYLE_PROPERTY(float, Width, width);
|
||||
CSS_NODE_STYLE_PROPERTY(float, Height, height);
|
||||
|
Reference in New Issue
Block a user