Skip to content

Commit

Permalink
Sunset the value namespace
Browse files Browse the repository at this point in the history
Summary:
X-link: facebook/yoga#1720

X-link: facebook/react-native#46930

This is not really needed anymore, we can just use `StyleLength` statics instead

Changelog: [Internal]

Reviewed By: NickGerleman

Differential Revision: D63922280

fbshipit-source-id: cd953bae8e9f68574463eafc49c33c2e85ac1856
  • Loading branch information
joevilches authored and facebook-github-bot committed Oct 10, 2024
1 parent 47a9e20 commit df5149a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 67 deletions.
57 changes: 29 additions & 28 deletions lib/yoga/src/main/cpp/yoga/YGNodeStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,19 @@ float YGNodeStyleGetFlexShrink(const YGNodeConstRef nodeRef) {

void YGNodeStyleSetFlexBasis(const YGNodeRef node, const float flexBasis) {
updateStyle<&Style::flexBasis, &Style::setFlexBasis>(
node, value::points(flexBasis));
node, StyleLength::points(flexBasis));
}

void YGNodeStyleSetFlexBasisPercent(
const YGNodeRef node,
const float flexBasisPercent) {
updateStyle<&Style::flexBasis, &Style::setFlexBasis>(
node, value::percent(flexBasisPercent));
node, StyleLength::percent(flexBasisPercent));
}

void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node) {
updateStyle<&Style::flexBasis, &Style::setFlexBasis>(node, value::ofAuto());
updateStyle<&Style::flexBasis, &Style::setFlexBasis>(
node, StyleLength::ofAuto());
}

YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) {
Expand All @@ -197,17 +198,17 @@ YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) {

void YGNodeStyleSetPosition(YGNodeRef node, YGEdge edge, float points) {
updateStyle<&Style::position, &Style::setPosition>(
node, scopedEnum(edge), value::points(points));
node, scopedEnum(edge), StyleLength::points(points));
}

void YGNodeStyleSetPositionPercent(YGNodeRef node, YGEdge edge, float percent) {
updateStyle<&Style::position, &Style::setPosition>(
node, scopedEnum(edge), value::percent(percent));
node, scopedEnum(edge), StyleLength::percent(percent));
}

void YGNodeStyleSetPositionAuto(YGNodeRef node, YGEdge edge) {
updateStyle<&Style::position, &Style::setPosition>(
node, scopedEnum(edge), value::ofAuto());
node, scopedEnum(edge), StyleLength::ofAuto());
}

YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) {
Expand All @@ -216,17 +217,17 @@ YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) {

void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, float points) {
updateStyle<&Style::margin, &Style::setMargin>(
node, scopedEnum(edge), value::points(points));
node, scopedEnum(edge), StyleLength::points(points));
}

void YGNodeStyleSetMarginPercent(YGNodeRef node, YGEdge edge, float percent) {
updateStyle<&Style::margin, &Style::setMargin>(
node, scopedEnum(edge), value::percent(percent));
node, scopedEnum(edge), StyleLength::percent(percent));
}

void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge) {
updateStyle<&Style::margin, &Style::setMargin>(
node, scopedEnum(edge), value::ofAuto());
node, scopedEnum(edge), StyleLength::ofAuto());
}

YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) {
Expand All @@ -235,12 +236,12 @@ YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) {

void YGNodeStyleSetPadding(YGNodeRef node, YGEdge edge, float points) {
updateStyle<&Style::padding, &Style::setPadding>(
node, scopedEnum(edge), value::points(points));
node, scopedEnum(edge), StyleLength::points(points));
}

void YGNodeStyleSetPaddingPercent(YGNodeRef node, YGEdge edge, float percent) {
updateStyle<&Style::padding, &Style::setPadding>(
node, scopedEnum(edge), value::percent(percent));
node, scopedEnum(edge), StyleLength::percent(percent));
}

YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge) {
Expand All @@ -252,7 +253,7 @@ void YGNodeStyleSetBorder(
const YGEdge edge,
const float border) {
updateStyle<&Style::border, &Style::setBorder>(
node, scopedEnum(edge), value::points(border));
node, scopedEnum(edge), StyleLength::points(border));
}

float YGNodeStyleGetBorder(const YGNodeConstRef node, const YGEdge edge) {
Expand All @@ -269,12 +270,12 @@ void YGNodeStyleSetGap(
const YGGutter gutter,
const float gapLength) {
updateStyle<&Style::gap, &Style::setGap>(
node, scopedEnum(gutter), value::points(gapLength));
node, scopedEnum(gutter), StyleLength::points(gapLength));
}

void YGNodeStyleSetGapPercent(YGNodeRef node, YGGutter gutter, float percent) {
updateStyle<&Style::gap, &Style::setGap>(
node, scopedEnum(gutter), value::percent(percent));
node, scopedEnum(gutter), StyleLength::percent(percent));
}

float YGNodeStyleGetGap(const YGNodeConstRef node, const YGGutter gutter) {
Expand Down Expand Up @@ -307,17 +308,17 @@ YGBoxSizing YGNodeStyleGetBoxSizing(const YGNodeConstRef node) {

void YGNodeStyleSetWidth(YGNodeRef node, float points) {
updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Width, value::points(points));
node, Dimension::Width, StyleLength::points(points));
}

void YGNodeStyleSetWidthPercent(YGNodeRef node, float percent) {
updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Width, value::percent(percent));
node, Dimension::Width, StyleLength::percent(percent));
}

void YGNodeStyleSetWidthAuto(YGNodeRef node) {
updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Width, value::ofAuto());
node, Dimension::Width, StyleLength::ofAuto());
}

YGValue YGNodeStyleGetWidth(YGNodeConstRef node) {
Expand All @@ -326,17 +327,17 @@ YGValue YGNodeStyleGetWidth(YGNodeConstRef node) {

void YGNodeStyleSetHeight(YGNodeRef node, float points) {
updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Height, value::points(points));
node, Dimension::Height, StyleLength::points(points));
}

void YGNodeStyleSetHeightPercent(YGNodeRef node, float percent) {
updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Height, value::percent(percent));
node, Dimension::Height, StyleLength::percent(percent));
}

void YGNodeStyleSetHeightAuto(YGNodeRef node) {
updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Height, value::ofAuto());
node, Dimension::Height, StyleLength::ofAuto());
}

YGValue YGNodeStyleGetHeight(YGNodeConstRef node) {
Expand All @@ -345,12 +346,12 @@ YGValue YGNodeStyleGetHeight(YGNodeConstRef node) {

void YGNodeStyleSetMinWidth(const YGNodeRef node, const float minWidth) {
updateStyle<&Style::minDimension, &Style::setMinDimension>(
node, Dimension::Width, value::points(minWidth));
node, Dimension::Width, StyleLength::points(minWidth));
}

void YGNodeStyleSetMinWidthPercent(const YGNodeRef node, const float minWidth) {
updateStyle<&Style::minDimension, &Style::setMinDimension>(
node, Dimension::Width, value::percent(minWidth));
node, Dimension::Width, StyleLength::percent(minWidth));
}

YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) {
Expand All @@ -359,14 +360,14 @@ YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) {

void YGNodeStyleSetMinHeight(const YGNodeRef node, const float minHeight) {
updateStyle<&Style::minDimension, &Style::setMinDimension>(
node, Dimension::Height, value::points(minHeight));
node, Dimension::Height, StyleLength::points(minHeight));
}

void YGNodeStyleSetMinHeightPercent(
const YGNodeRef node,
const float minHeight) {
updateStyle<&Style::minDimension, &Style::setMinDimension>(
node, Dimension::Height, value::percent(minHeight));
node, Dimension::Height, StyleLength::percent(minHeight));
}

YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) {
Expand All @@ -375,12 +376,12 @@ YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) {

void YGNodeStyleSetMaxWidth(const YGNodeRef node, const float maxWidth) {
updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
node, Dimension::Width, value::points(maxWidth));
node, Dimension::Width, StyleLength::points(maxWidth));
}

void YGNodeStyleSetMaxWidthPercent(const YGNodeRef node, const float maxWidth) {
updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
node, Dimension::Width, value::percent(maxWidth));
node, Dimension::Width, StyleLength::percent(maxWidth));
}

YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) {
Expand All @@ -389,14 +390,14 @@ YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) {

void YGNodeStyleSetMaxHeight(const YGNodeRef node, const float maxHeight) {
updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
node, Dimension::Height, value::points(maxHeight));
node, Dimension::Height, StyleLength::points(maxHeight));
}

void YGNodeStyleSetMaxHeightPercent(
const YGNodeRef node,
const float maxHeight) {
updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
node, Dimension::Height, value::percent(maxHeight));
node, Dimension::Height, StyleLength::percent(maxHeight));
}

YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) {
Expand Down
5 changes: 3 additions & 2 deletions lib/yoga/src/main/cpp/yoga/node/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,10 @@ Style::Length Node::processFlexBasis() const {
return flexBasis;
}
if (style_.flex().isDefined() && style_.flex().unwrap() > 0.0f) {
return config_->useWebDefaults() ? value::ofAuto() : value::points(0);
return config_->useWebDefaults() ? StyleLength::ofAuto()
: StyleLength::points(0);
}
return value::ofAuto();
return StyleLength::ofAuto();
}

FloatOptional Node::resolveFlexBasis(
Expand Down
2 changes: 1 addition & 1 deletion lib/yoga/src/main/cpp/yoga/node/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ class YG_EXPORT Node : public ::YGNode {
std::vector<Node*> children_;
const Config* config_;
std::array<Style::Length, 2> processedDimensions_{
{value::undefined(), value::undefined()}};
{StyleLength::undefined(), StyleLength::undefined()}};
};

inline Node* resolveRef(const YGNodeRef ref) {
Expand Down
32 changes: 0 additions & 32 deletions lib/yoga/src/main/cpp/yoga/style/StyleLength.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,36 +104,4 @@ inline bool inexactEquals(const StyleLength& a, const StyleLength& b) {
return a.unit() == b.unit() && inexactEquals(a.value(), b.value());
}

namespace value {

/**
* Canonical unit (one YGUnitPoint)
*/
constexpr StyleLength points(float value) {
return StyleLength::points(value);
}

/**
* Percent of reference
*/
constexpr StyleLength percent(float value) {
return StyleLength::percent(value);
}

/**
* "auto" keyword
*/
constexpr StyleLength ofAuto() {
return StyleLength::ofAuto();
}

/**
* Undefined
*/
constexpr StyleLength undefined() {
return StyleLength::undefined();
}

} // namespace value

} // namespace facebook::yoga
8 changes: 4 additions & 4 deletions lib/yoga/src/main/cpp/yoga/style/StyleValuePool.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class StyleValuePool {

StyleLength getLength(StyleValueHandle handle) const {
if (handle.isUndefined()) {
return value::undefined();
return StyleLength::undefined();
} else if (handle.isAuto()) {
return value::ofAuto();
return StyleLength::ofAuto();
} else {
assert(
handle.type() == StyleValueHandle::Type::Point ||
Expand All @@ -61,8 +61,8 @@ class StyleValuePool {
: unpackInlineInteger(handle.value());

return handle.type() == StyleValueHandle::Type::Point
? value::points(value)
: value::percent(value);
? StyleLength::points(value)
: StyleLength::percent(value);
}
}

Expand Down

0 comments on commit df5149a

Please sign in to comment.