Replace `YG_NODE_STYLE_PROPERTY_IMPL` macro with template
Summary: @public Replacing the `YG_NODE_STYLE_PROPERTY_IMPL` macro with template code, in order to make code easier to edit and grep. Reviewed By: astreet Differential Revision: D8868184 fbshipit-source-id: f52537376fa8d4dd53aa98bb43e93279699dbdd5
This commit is contained in:
parent
95b7fd9de6
commit
709e3bc1fe
|
@ -576,16 +576,24 @@ float YGNodeStyleGetFlexShrink(const YGNodeRef node) {
|
||||||
: node->getStyle().flexShrink.getValue();
|
: node->getStyle().flexShrink.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
#define YG_NODE_STYLE_PROPERTY_SETTER_IMPL( \
|
namespace {
|
||||||
type, name, paramName, instanceName) \
|
|
||||||
void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \
|
template <typename T, T YGStyle::*P>
|
||||||
if (node->getStyle().instanceName != paramName) { \
|
struct StyleProp {
|
||||||
YGStyle style = node->getStyle(); \
|
static T get(YGNodeRef node) {
|
||||||
style.instanceName = paramName; \
|
return node->getStyle().*P;
|
||||||
node->setStyle(style); \
|
|
||||||
node->markDirtyAndPropogate(); \
|
|
||||||
} \
|
|
||||||
}
|
}
|
||||||
|
static void set(YGNodeRef node, T newValue) {
|
||||||
|
if (node->getStyle().*P != newValue) {
|
||||||
|
YGStyle style = node->getStyle();
|
||||||
|
style.*P = newValue;
|
||||||
|
node->setStyle(style);
|
||||||
|
node->markDirtyAndPropogate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
#define YG_NODE_STYLE_PROPERTY_SETTER_UNIT_IMPL( \
|
#define YG_NODE_STYLE_PROPERTY_SETTER_UNIT_IMPL( \
|
||||||
type, name, paramName, instanceName) \
|
type, name, paramName, instanceName) \
|
||||||
|
@ -661,13 +669,6 @@ float YGNodeStyleGetFlexShrink(const YGNodeRef node) {
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define YG_NODE_STYLE_PROPERTY_IMPL(type, name, paramName, instanceName) \
|
|
||||||
YG_NODE_STYLE_PROPERTY_SETTER_IMPL(type, name, paramName, instanceName) \
|
|
||||||
\
|
|
||||||
type YGNodeStyleGet##name(const YGNodeRef node) { \
|
|
||||||
return node->getStyle().instanceName; \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define YG_NODE_STYLE_PROPERTY_UNIT_IMPL(type, name, paramName, instanceName) \
|
#define YG_NODE_STYLE_PROPERTY_UNIT_IMPL(type, name, paramName, instanceName) \
|
||||||
YG_NODE_STYLE_PROPERTY_SETTER_UNIT_IMPL( \
|
YG_NODE_STYLE_PROPERTY_SETTER_UNIT_IMPL( \
|
||||||
float, name, paramName, instanceName) \
|
float, name, paramName, instanceName) \
|
||||||
|
@ -778,33 +779,85 @@ float YGNodeStyleGetFlexShrink(const YGNodeRef node) {
|
||||||
return node->getLayout().instanceName[edge]; \
|
return node->getLayout().instanceName[edge]; \
|
||||||
}
|
}
|
||||||
|
|
||||||
// YG_NODE_PROPERTY_IMPL(void *, Context, context, context);
|
void YGNodeStyleSetDirection(
|
||||||
// YG_NODE_PROPERTY_IMPL(YGPrintFunc, PrintFunc, printFunc, print);
|
const YGNodeRef node,
|
||||||
// YG_NODE_PROPERTY_IMPL(bool, HasNewLayout, hasNewLayout, hasNewLayout);
|
const YGDirection direction) {
|
||||||
// YG_NODE_PROPERTY_IMPL(YGNodeType, NodeType, nodeType, nodeType);
|
StyleProp<YGDirection, &YGStyle::direction>::set(node, direction);
|
||||||
|
}
|
||||||
|
YGDirection YGNodeStyleGetDirection(const YGNodeRef node) {
|
||||||
|
return StyleProp<YGDirection, &YGStyle::direction>::get(node);
|
||||||
|
}
|
||||||
|
|
||||||
YG_NODE_STYLE_PROPERTY_IMPL(YGDirection, Direction, direction, direction);
|
void YGNodeStyleSetFlexDirection(
|
||||||
YG_NODE_STYLE_PROPERTY_IMPL(
|
const YGNodeRef node,
|
||||||
YGFlexDirection,
|
const YGFlexDirection flexDirection) {
|
||||||
FlexDirection,
|
StyleProp<YGFlexDirection, &YGStyle::flexDirection>::set(node, flexDirection);
|
||||||
flexDirection,
|
}
|
||||||
flexDirection);
|
YGFlexDirection YGNodeStyleGetFlexDirection(const YGNodeRef node) {
|
||||||
YG_NODE_STYLE_PROPERTY_IMPL(
|
return StyleProp<YGFlexDirection, &YGStyle::flexDirection>::get(node);
|
||||||
YGJustify,
|
}
|
||||||
JustifyContent,
|
|
||||||
justifyContent,
|
void YGNodeStyleSetJustifyContent(
|
||||||
justifyContent);
|
const YGNodeRef node,
|
||||||
YG_NODE_STYLE_PROPERTY_IMPL(YGAlign, AlignContent, alignContent, alignContent);
|
const YGJustify justifyContent) {
|
||||||
YG_NODE_STYLE_PROPERTY_IMPL(YGAlign, AlignItems, alignItems, alignItems);
|
StyleProp<YGJustify, &YGStyle::justifyContent>::set(node, justifyContent);
|
||||||
YG_NODE_STYLE_PROPERTY_IMPL(YGAlign, AlignSelf, alignSelf, alignSelf);
|
}
|
||||||
YG_NODE_STYLE_PROPERTY_IMPL(
|
YGJustify YGNodeStyleGetJustifyContent(const YGNodeRef node) {
|
||||||
YGPositionType,
|
return StyleProp<YGJustify, &YGStyle::justifyContent>::get(node);
|
||||||
PositionType,
|
}
|
||||||
positionType,
|
|
||||||
positionType);
|
void YGNodeStyleSetAlignContent(
|
||||||
YG_NODE_STYLE_PROPERTY_IMPL(YGWrap, FlexWrap, flexWrap, flexWrap);
|
const YGNodeRef node,
|
||||||
YG_NODE_STYLE_PROPERTY_IMPL(YGOverflow, Overflow, overflow, overflow);
|
const YGAlign alignContent) {
|
||||||
YG_NODE_STYLE_PROPERTY_IMPL(YGDisplay, Display, display, display);
|
StyleProp<YGAlign, &YGStyle::alignContent>::set(node, alignContent);
|
||||||
|
}
|
||||||
|
YGAlign YGNodeStyleGetAlignContent(const YGNodeRef node) {
|
||||||
|
return StyleProp<YGAlign, &YGStyle::alignContent>::get(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
void YGNodeStyleSetAlignItems(const YGNodeRef node, const YGAlign alignItems) {
|
||||||
|
StyleProp<YGAlign, &YGStyle::alignItems>::set(node, alignItems);
|
||||||
|
}
|
||||||
|
YGAlign YGNodeStyleGetAlignItems(const YGNodeRef node) {
|
||||||
|
return StyleProp<YGAlign, &YGStyle::alignItems>::get(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
void YGNodeStyleSetAlignSelf(const YGNodeRef node, const YGAlign alignSelf) {
|
||||||
|
StyleProp<YGAlign, &YGStyle::alignSelf>::set(node, alignSelf);
|
||||||
|
}
|
||||||
|
YGAlign YGNodeStyleGetAlignSelf(const YGNodeRef node) {
|
||||||
|
return StyleProp<YGAlign, &YGStyle::alignSelf>::get(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
void YGNodeStyleSetPositionType(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const YGPositionType positionType) {
|
||||||
|
StyleProp<YGPositionType, &YGStyle::positionType>::set(node, positionType);
|
||||||
|
}
|
||||||
|
YGPositionType YGNodeStyleGetPositionType(const YGNodeRef node) {
|
||||||
|
return StyleProp<YGPositionType, &YGStyle::positionType>::get(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
void YGNodeStyleSetFlexWrap(const YGNodeRef node, const YGWrap flexWrap) {
|
||||||
|
StyleProp<YGWrap, &YGStyle::flexWrap>::set(node, flexWrap);
|
||||||
|
}
|
||||||
|
YGWrap YGNodeStyleGetFlexWrap(const YGNodeRef node) {
|
||||||
|
return StyleProp<YGWrap, &YGStyle::flexWrap>::get(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
void YGNodeStyleSetOverflow(const YGNodeRef node, const YGOverflow overflow) {
|
||||||
|
StyleProp<YGOverflow, &YGStyle::overflow>::set(node, overflow);
|
||||||
|
}
|
||||||
|
YGOverflow YGNodeStyleGetOverflow(const YGNodeRef node) {
|
||||||
|
return StyleProp<YGOverflow, &YGStyle::overflow>::get(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
void YGNodeStyleSetDisplay(const YGNodeRef node, const YGDisplay display) {
|
||||||
|
StyleProp<YGDisplay, &YGStyle::display>::set(node, display);
|
||||||
|
}
|
||||||
|
YGDisplay YGNodeStyleGetDisplay(const YGNodeRef node) {
|
||||||
|
return StyleProp<YGDisplay, &YGStyle::display>::get(node);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(T26792433): Change the API to accept YGFloatOptional.
|
// TODO(T26792433): Change the API to accept YGFloatOptional.
|
||||||
void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {
|
void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {
|
||||||
|
|
Loading…
Reference in New Issue