From e1575fbd0d5a6839f1a9031643a77ccf7092ffd2 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Tue, 14 Nov 2023 11:25:29 -0800 Subject: [PATCH] Remove yoga::Style::Ref Summary: Moves the last usages of `yoga::Style::Ref` to setters. Differential Revision: D51154501 fbshipit-source-id: 620785fcc739a2face915475a43d71722700e86d --- yoga/YGNodeStyle.cpp | 33 +++++++++++++++++++++------------ yoga/style/Style.h | 33 ++++++++++----------------------- 2 files changed, 31 insertions(+), 35 deletions(-) diff --git a/yoga/YGNodeStyle.cpp b/yoga/YGNodeStyle.cpp index c39372a33a..441b7797f7 100644 --- a/yoga/YGNodeStyle.cpp +++ b/yoga/YGNodeStyle.cpp @@ -35,6 +35,15 @@ void updateStyle(YGNodeRef node, Ref (Style::*prop)(), ValueT value) { [prop](Style& s, ValueT x) { (s.*prop)() = x; }); } +template +void updateStyle(YGNodeRef node, ValueT value) { + updateStyle( + resolveRef(node), + value, + [](Style& s, ValueT x) { return (s.*GetterT)() != x; }, + [](Style& s, ValueT x) { (s.*SetterT)(x); }); +} + template void updateIndexedStyleProp(YGNodeRef node, IdxT idx, ValueT value) { updateStyle( @@ -162,7 +171,7 @@ YGDisplay YGNodeStyleGetDisplay(const YGNodeConstRef node) { } void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) { - updateStyle(node, &Style::flex, FloatOptional{flex}); + updateStyle<&Style::flex, &Style::setFlex>(node, FloatOptional{flex}); } float YGNodeStyleGetFlex(const YGNodeConstRef nodeRef) { @@ -173,8 +182,8 @@ float YGNodeStyleGetFlex(const YGNodeConstRef nodeRef) { } void YGNodeStyleSetFlexGrow(const YGNodeRef node, const float flexGrow) { - updateStyle( - node, &Style::flexGrow, FloatOptional{flexGrow}); + updateStyle<&Style::flexGrow, &Style::setFlexGrow>( + node, FloatOptional{flexGrow}); } float YGNodeStyleGetFlexGrow(const YGNodeConstRef nodeRef) { @@ -185,8 +194,8 @@ float YGNodeStyleGetFlexGrow(const YGNodeConstRef nodeRef) { } void YGNodeStyleSetFlexShrink(const YGNodeRef node, const float flexShrink) { - updateStyle( - node, &Style::flexShrink, FloatOptional{flexShrink}); + updateStyle<&Style::flexShrink, &Style::setFlexShrink>( + node, FloatOptional{flexShrink}); } float YGNodeStyleGetFlexShrink(const YGNodeConstRef nodeRef) { @@ -198,19 +207,19 @@ float YGNodeStyleGetFlexShrink(const YGNodeConstRef nodeRef) { } void YGNodeStyleSetFlexBasis(const YGNodeRef node, const float flexBasis) { - updateStyle( - node, &Style::flexBasis, value::points(flexBasis)); + updateStyle<&Style::flexBasis, &Style::setFlexBasis>( + node, value::points(flexBasis)); } void YGNodeStyleSetFlexBasisPercent( const YGNodeRef node, const float flexBasisPercent) { - updateStyle( - node, &Style::flexBasis, value::percent(flexBasisPercent)); + updateStyle<&Style::flexBasis, &Style::setFlexBasis>( + node, value::percent(flexBasisPercent)); } void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node) { - updateStyle(node, &Style::flexBasis, value::ofAuto()); + updateStyle<&Style::flexBasis, &Style::setFlexBasis>(node, value::ofAuto()); } YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) { @@ -303,8 +312,8 @@ float YGNodeStyleGetGap(const YGNodeConstRef node, const YGGutter gutter) { } void YGNodeStyleSetAspectRatio(const YGNodeRef node, const float aspectRatio) { - updateStyle( - node, &Style::aspectRatio, FloatOptional{aspectRatio}); + updateStyle<&Style::aspectRatio, &Style::setAspectRatio>( + node, FloatOptional{aspectRatio}); } float YGNodeStyleGetAspectRatio(const YGNodeConstRef node) { diff --git a/yoga/style/Style.h b/yoga/style/Style.h index e40f1c4fb6..09f5c3c1fb 100644 --- a/yoga/style/Style.h +++ b/yoga/style/Style.h @@ -68,18 +68,6 @@ class YG_EXPORT Style { } }; - template - struct Ref { - Style& style; - operator T() const { - return style.*Prop; - } - Ref& operator=(T value) { - style.*Prop = value; - return *this; - } - }; - Style() { alignContent() = Align::FlexStart; alignItems() = Align::Stretch; @@ -202,29 +190,29 @@ class YG_EXPORT Style { FloatOptional flex() const { return flex_; } - Ref flex() { - return {*this}; + void setFlex(FloatOptional value) { + flex_ = value; } FloatOptional flexGrow() const { return flexGrow_; } - Ref flexGrow() { - return {*this}; + void setFlexGrow(FloatOptional value) { + flexGrow_ = value; } FloatOptional flexShrink() const { return flexShrink_; } - Ref flexShrink() { - return {*this}; + void setFlexShrink(FloatOptional value) { + flexShrink_ = value; } Style::Length flexBasis() const { return flexBasis_; } - Ref flexBasis() { - return {*this}; + void setFlexBasis(Style::Length value) { + flexBasis_ = value; } Style::Length margin(Edge edge) const { @@ -283,12 +271,11 @@ class YG_EXPORT Style { maxDimensions_[yoga::to_underlying(axis)] = value; } - // Yoga specific properties, not compatible with flexbox specification FloatOptional aspectRatio() const { return aspectRatio_; } - Ref aspectRatio() { - return {*this}; + void setAspectRatio(FloatOptional value) { + aspectRatio_ = value; } Length resolveColumnGap() const {