Deduplicate updateStyle
overloads
Summary: @public The extra overload of `updateStyle` introduced in D15078961 can also handle `BitfieldRef`. That means that we can remove the more specific implementation previously introduced for `BitfieldRef` Reviewed By: SidharthGuglani Differential Revision: D15081069 fbshipit-source-id: 98f1f3478627974c5273c85d268ca07350f303d7
This commit is contained in:
committed by
Facebook Github Bot
parent
0a4f7bd558
commit
05d205cf89
@@ -549,15 +549,6 @@ void updateStyle(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, YGStyle::BitfieldRef<T> (YGStyle::*Prop)()>
|
|
||||||
void updateStyle(YGNode* node, T value) {
|
|
||||||
updateStyle(
|
|
||||||
node,
|
|
||||||
value,
|
|
||||||
[](YGStyle& s, T x) { return (s.*Prop)() != x; },
|
|
||||||
[](YGStyle& s, T x) { (s.*Prop)() = x; });
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Ref, typename T>
|
template <typename Ref, typename T>
|
||||||
void updateStyle(YGNode* node, Ref (YGStyle::*prop)(), T value) {
|
void updateStyle(YGNode* node, Ref (YGStyle::*prop)(), T value) {
|
||||||
updateStyle(
|
updateStyle(
|
||||||
@@ -583,8 +574,15 @@ void updateIndexedStyleProp(
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
// MSVC has trouble inferring the return type of pointer to member functions
|
||||||
|
// with const and non-const overloads, instead of preferring the non-const
|
||||||
|
// overload like clang and GCC. For the purposes of updateStyle(), we can help
|
||||||
|
// MSVC by specifying that return type explicitely. In combination with
|
||||||
|
// decltype, MSVC will prefer the non-const version.
|
||||||
|
#define MSVC_HINT(PROP) decltype(YGStyle{}.PROP())
|
||||||
|
|
||||||
void YGNodeStyleSetDirection(const YGNodeRef node, const YGDirection value) {
|
void YGNodeStyleSetDirection(const YGNodeRef node, const YGDirection value) {
|
||||||
updateStyle<YGDirection, &YGStyle::direction>(node, value);
|
updateStyle<MSVC_HINT(direction)>(node, &YGStyle::direction, value);
|
||||||
}
|
}
|
||||||
YGDirection YGNodeStyleGetDirection(const YGNodeConstRef node) {
|
YGDirection YGNodeStyleGetDirection(const YGNodeConstRef node) {
|
||||||
return node->getStyle().direction();
|
return node->getStyle().direction();
|
||||||
@@ -593,7 +591,8 @@ YGDirection YGNodeStyleGetDirection(const YGNodeConstRef node) {
|
|||||||
void YGNodeStyleSetFlexDirection(
|
void YGNodeStyleSetFlexDirection(
|
||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const YGFlexDirection flexDirection) {
|
const YGFlexDirection flexDirection) {
|
||||||
updateStyle<YGFlexDirection, &YGStyle::flexDirection>(node, flexDirection);
|
updateStyle<MSVC_HINT(flexDirection)>(
|
||||||
|
node, &YGStyle::flexDirection, flexDirection);
|
||||||
}
|
}
|
||||||
YGFlexDirection YGNodeStyleGetFlexDirection(const YGNodeConstRef node) {
|
YGFlexDirection YGNodeStyleGetFlexDirection(const YGNodeConstRef node) {
|
||||||
return node->getStyle().flexDirection();
|
return node->getStyle().flexDirection();
|
||||||
@@ -602,7 +601,8 @@ YGFlexDirection YGNodeStyleGetFlexDirection(const YGNodeConstRef node) {
|
|||||||
void YGNodeStyleSetJustifyContent(
|
void YGNodeStyleSetJustifyContent(
|
||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const YGJustify justifyContent) {
|
const YGJustify justifyContent) {
|
||||||
updateStyle<YGJustify, &YGStyle::justifyContent>(node, justifyContent);
|
updateStyle<MSVC_HINT(justifyContent)>(
|
||||||
|
node, &YGStyle::justifyContent, justifyContent);
|
||||||
}
|
}
|
||||||
YGJustify YGNodeStyleGetJustifyContent(const YGNodeConstRef node) {
|
YGJustify YGNodeStyleGetJustifyContent(const YGNodeConstRef node) {
|
||||||
return node->getStyle().justifyContent();
|
return node->getStyle().justifyContent();
|
||||||
@@ -611,21 +611,22 @@ YGJustify YGNodeStyleGetJustifyContent(const YGNodeConstRef node) {
|
|||||||
void YGNodeStyleSetAlignContent(
|
void YGNodeStyleSetAlignContent(
|
||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const YGAlign alignContent) {
|
const YGAlign alignContent) {
|
||||||
updateStyle<YGAlign, &YGStyle::alignContent>(node, alignContent);
|
updateStyle<MSVC_HINT(alignContent)>(
|
||||||
|
node, &YGStyle::alignContent, alignContent);
|
||||||
}
|
}
|
||||||
YGAlign YGNodeStyleGetAlignContent(const YGNodeConstRef node) {
|
YGAlign YGNodeStyleGetAlignContent(const YGNodeConstRef node) {
|
||||||
return node->getStyle().alignContent();
|
return node->getStyle().alignContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGNodeStyleSetAlignItems(const YGNodeRef node, const YGAlign alignItems) {
|
void YGNodeStyleSetAlignItems(const YGNodeRef node, const YGAlign alignItems) {
|
||||||
updateStyle<YGAlign, &YGStyle::alignItems>(node, alignItems);
|
updateStyle<MSVC_HINT(alignItems)>(node, &YGStyle::alignItems, alignItems);
|
||||||
}
|
}
|
||||||
YGAlign YGNodeStyleGetAlignItems(const YGNodeConstRef node) {
|
YGAlign YGNodeStyleGetAlignItems(const YGNodeConstRef node) {
|
||||||
return node->getStyle().alignItems();
|
return node->getStyle().alignItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGNodeStyleSetAlignSelf(const YGNodeRef node, const YGAlign alignSelf) {
|
void YGNodeStyleSetAlignSelf(const YGNodeRef node, const YGAlign alignSelf) {
|
||||||
updateStyle<YGAlign, &YGStyle::alignSelf>(node, alignSelf);
|
updateStyle<MSVC_HINT(alignSelf)>(node, &YGStyle::alignSelf, alignSelf);
|
||||||
}
|
}
|
||||||
YGAlign YGNodeStyleGetAlignSelf(const YGNodeConstRef node) {
|
YGAlign YGNodeStyleGetAlignSelf(const YGNodeConstRef node) {
|
||||||
return node->getStyle().alignSelf();
|
return node->getStyle().alignSelf();
|
||||||
@@ -634,40 +635,34 @@ YGAlign YGNodeStyleGetAlignSelf(const YGNodeConstRef node) {
|
|||||||
void YGNodeStyleSetPositionType(
|
void YGNodeStyleSetPositionType(
|
||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const YGPositionType positionType) {
|
const YGPositionType positionType) {
|
||||||
updateStyle<YGPositionType, &YGStyle::positionType>(node, positionType);
|
updateStyle<MSVC_HINT(positionType)>(
|
||||||
|
node, &YGStyle::positionType, positionType);
|
||||||
}
|
}
|
||||||
YGPositionType YGNodeStyleGetPositionType(const YGNodeConstRef node) {
|
YGPositionType YGNodeStyleGetPositionType(const YGNodeConstRef node) {
|
||||||
return node->getStyle().positionType();
|
return node->getStyle().positionType();
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGNodeStyleSetFlexWrap(const YGNodeRef node, const YGWrap flexWrap) {
|
void YGNodeStyleSetFlexWrap(const YGNodeRef node, const YGWrap flexWrap) {
|
||||||
updateStyle<YGWrap, &YGStyle::flexWrap>(node, flexWrap);
|
updateStyle<MSVC_HINT(flexWrap)>(node, &YGStyle::flexWrap, flexWrap);
|
||||||
}
|
}
|
||||||
YGWrap YGNodeStyleGetFlexWrap(const YGNodeConstRef node) {
|
YGWrap YGNodeStyleGetFlexWrap(const YGNodeConstRef node) {
|
||||||
return node->getStyle().flexWrap();
|
return node->getStyle().flexWrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGNodeStyleSetOverflow(const YGNodeRef node, const YGOverflow overflow) {
|
void YGNodeStyleSetOverflow(const YGNodeRef node, const YGOverflow overflow) {
|
||||||
updateStyle<YGOverflow, &YGStyle::overflow>(node, overflow);
|
updateStyle<MSVC_HINT(overflow)>(node, &YGStyle::overflow, overflow);
|
||||||
}
|
}
|
||||||
YGOverflow YGNodeStyleGetOverflow(const YGNodeConstRef node) {
|
YGOverflow YGNodeStyleGetOverflow(const YGNodeConstRef node) {
|
||||||
return node->getStyle().overflow();
|
return node->getStyle().overflow();
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGNodeStyleSetDisplay(const YGNodeRef node, const YGDisplay display) {
|
void YGNodeStyleSetDisplay(const YGNodeRef node, const YGDisplay display) {
|
||||||
updateStyle<YGDisplay, &YGStyle::display>(node, display);
|
updateStyle<MSVC_HINT(display)>(node, &YGStyle::display, display);
|
||||||
}
|
}
|
||||||
YGDisplay YGNodeStyleGetDisplay(const YGNodeConstRef node) {
|
YGDisplay YGNodeStyleGetDisplay(const YGNodeConstRef node) {
|
||||||
return node->getStyle().display();
|
return node->getStyle().display();
|
||||||
}
|
}
|
||||||
|
|
||||||
// MSVC has trouble inferring the return type of pointer to member functions
|
|
||||||
// with const and non-const overloads, instead of preferring the non-const
|
|
||||||
// overload like clang and GCC. For the purposes of updateStyle(), we can help
|
|
||||||
// MSVC by specifying that return type explicitely. In combination with
|
|
||||||
// decltype, MSVC will prefer the non-const version.
|
|
||||||
#define MSVC_HINT(PROP) decltype(YGStyle{}.PROP())
|
|
||||||
|
|
||||||
// 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) {
|
||||||
updateStyle<MSVC_HINT(flex)>(node, &YGStyle::flex, YGFloatOptional{flex});
|
updateStyle<MSVC_HINT(flex)>(node, &YGStyle::flex, YGFloatOptional{flex});
|
||||||
|
Reference in New Issue
Block a user