Skip to content

Commit

Permalink
C++ style enums 16/N: Dimension (facebook#1403)
Browse files Browse the repository at this point in the history
Summary:
X-link: facebook/react-native#39598

Pull Request resolved: facebook#1403

Replaces all usages of YGDimension with Dimension.

Adds `yoga::to_underlying` to act like `std::to_underlying`, added in C++ 23.

This enum is oddly only used internally, and is never an input to the public API, but it handled as any other public generated enum. Potentially some more cleanup to do there.

Reviewed By: rshest

Differential Revision: D49475409

fbshipit-source-id: 56688d703cf1149740e3b689d32c8fd24d2b2413
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Sep 26, 2023
1 parent 8d24fcd commit a53aee9
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 129 deletions.
44 changes: 22 additions & 22 deletions yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,97 +662,97 @@ void YGNodeStyleSetAspectRatio(const YGNodeRef node, const float aspectRatio) {
void YGNodeStyleSetWidth(YGNodeRef node, float points) {
auto value = CompactValue::ofMaybe<YGUnitPoint>(points);
updateIndexedStyleProp<&Style::dimension, &Style::setDimension>(
node, YGDimensionWidth, value);
node, Dimension::Width, value);
}
void YGNodeStyleSetWidthPercent(YGNodeRef node, float percent) {
auto value = CompactValue::ofMaybe<YGUnitPercent>(percent);
updateIndexedStyleProp<&Style::dimension, &Style::setDimension>(
node, YGDimensionWidth, value);
node, Dimension::Width, value);
}
void YGNodeStyleSetWidthAuto(YGNodeRef node) {
updateIndexedStyleProp<&Style::dimension, &Style::setDimension>(
node, YGDimensionWidth, CompactValue::ofAuto());
node, Dimension::Width, CompactValue::ofAuto());
}
YGValue YGNodeStyleGetWidth(YGNodeConstRef node) {
return resolveRef(node)->getStyle().dimension(YGDimensionWidth);
return resolveRef(node)->getStyle().dimension(Dimension::Width);
}

void YGNodeStyleSetHeight(YGNodeRef node, float points) {
auto value = CompactValue::ofMaybe<YGUnitPoint>(points);
updateIndexedStyleProp<&Style::dimension, &Style::setDimension>(
node, YGDimensionHeight, value);
node, Dimension::Height, value);
}
void YGNodeStyleSetHeightPercent(YGNodeRef node, float percent) {
auto value = CompactValue::ofMaybe<YGUnitPercent>(percent);
updateIndexedStyleProp<&Style::dimension, &Style::setDimension>(
node, YGDimensionHeight, value);
node, Dimension::Height, value);
}
void YGNodeStyleSetHeightAuto(YGNodeRef node) {
updateIndexedStyleProp<&Style::dimension, &Style::setDimension>(
node, YGDimensionHeight, CompactValue::ofAuto());
node, Dimension::Height, CompactValue::ofAuto());
}
YGValue YGNodeStyleGetHeight(YGNodeConstRef node) {
return resolveRef(node)->getStyle().dimension(YGDimensionHeight);
return resolveRef(node)->getStyle().dimension(Dimension::Height);
}

void YGNodeStyleSetMinWidth(const YGNodeRef node, const float minWidth) {
auto value = CompactValue::ofMaybe<YGUnitPoint>(minWidth);
updateIndexedStyleProp<&Style::minDimension, &Style::setMinDimension>(
node, YGDimensionWidth, value);
node, Dimension::Width, value);
}
void YGNodeStyleSetMinWidthPercent(const YGNodeRef node, const float minWidth) {
auto value = CompactValue::ofMaybe<YGUnitPercent>(minWidth);
updateIndexedStyleProp<&Style::minDimension, &Style::setMinDimension>(
node, YGDimensionWidth, value);
node, Dimension::Width, value);
}
YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) {
return resolveRef(node)->getStyle().minDimension(YGDimensionWidth);
return resolveRef(node)->getStyle().minDimension(Dimension::Width);
}

void YGNodeStyleSetMinHeight(const YGNodeRef node, const float minHeight) {
auto value = CompactValue::ofMaybe<YGUnitPoint>(minHeight);
updateIndexedStyleProp<&Style::minDimension, &Style::setMinDimension>(
node, YGDimensionHeight, value);
node, Dimension::Height, value);
}
void YGNodeStyleSetMinHeightPercent(
const YGNodeRef node,
const float minHeight) {
auto value = CompactValue::ofMaybe<YGUnitPercent>(minHeight);
updateIndexedStyleProp<&Style::minDimension, &Style::setMinDimension>(
node, YGDimensionHeight, value);
node, Dimension::Height, value);
}
YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) {
return resolveRef(node)->getStyle().minDimension(YGDimensionHeight);
return resolveRef(node)->getStyle().minDimension(Dimension::Height);
}

void YGNodeStyleSetMaxWidth(const YGNodeRef node, const float maxWidth) {
auto value = CompactValue::ofMaybe<YGUnitPoint>(maxWidth);
updateIndexedStyleProp<&Style::maxDimension, &Style::setMaxDimension>(
node, YGDimensionWidth, value);
node, Dimension::Width, value);
}
void YGNodeStyleSetMaxWidthPercent(const YGNodeRef node, const float maxWidth) {
auto value = CompactValue::ofMaybe<YGUnitPercent>(maxWidth);
updateIndexedStyleProp<&Style::maxDimension, &Style::setMaxDimension>(
node, YGDimensionWidth, value);
node, Dimension::Width, value);
}
YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) {
return resolveRef(node)->getStyle().maxDimension(YGDimensionWidth);
return resolveRef(node)->getStyle().maxDimension(Dimension::Width);
}

void YGNodeStyleSetMaxHeight(const YGNodeRef node, const float maxHeight) {
auto value = CompactValue::ofMaybe<YGUnitPoint>(maxHeight);
updateIndexedStyleProp<&Style::maxDimension, &Style::setMaxDimension>(
node, YGDimensionHeight, value);
node, Dimension::Height, value);
}
void YGNodeStyleSetMaxHeightPercent(
const YGNodeRef node,
const float maxHeight) {
auto value = CompactValue::ofMaybe<YGUnitPercent>(maxHeight);
updateIndexedStyleProp<&Style::maxDimension, &Style::setMaxDimension>(
node, YGDimensionHeight, value);
node, Dimension::Height, value);
}
YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) {
return resolveRef(node)->getStyle().maxDimension(YGDimensionHeight);
return resolveRef(node)->getStyle().maxDimension(Dimension::Height);
}

namespace {
Expand Down Expand Up @@ -805,11 +805,11 @@ float YGNodeLayoutGetBottom(const YGNodeConstRef node) {
}

float YGNodeLayoutGetWidth(const YGNodeConstRef node) {
return resolveRef(node)->getLayout().dimension(YGDimensionWidth);
return resolveRef(node)->getLayout().dimension(Dimension::Width);
}

float YGNodeLayoutGetHeight(const YGNodeConstRef node) {
return resolveRef(node)->getLayout().dimension(YGDimensionHeight);
return resolveRef(node)->getLayout().dimension(Dimension::Height);
}

YGDirection YGNodeLayoutGetDirection(const YGNodeConstRef node) {
Expand Down
6 changes: 3 additions & 3 deletions yoga/algorithm/Baseline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ float calculateBaseline(const yoga::Node* node) {
Event::publish<Event::NodeBaselineStart>(node);

const float baseline = node->baseline(
node->getLayout().measuredDimension(YGDimensionWidth),
node->getLayout().measuredDimension(YGDimensionHeight));
node->getLayout().measuredDimension(Dimension::Width),
node->getLayout().measuredDimension(Dimension::Height));

Event::publish<Event::NodeBaselineEnd>(node);

Expand Down Expand Up @@ -53,7 +53,7 @@ float calculateBaseline(const yoga::Node* node) {
}

if (baselineChild == nullptr) {
return node->getLayout().measuredDimension(YGDimensionHeight);
return node->getLayout().measuredDimension(Dimension::Height);
}

const float baseline = calculateBaseline(baselineChild);
Expand Down
9 changes: 5 additions & 4 deletions yoga/algorithm/BoundAxis.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <yoga/algorithm/FlexDirection.h>
#include <yoga/algorithm/ResolveValue.h>
#include <yoga/enums/Dimension.h>
#include <yoga/enums/FlexDirection.h>
#include <yoga/node/Node.h>
#include <yoga/numeric/Comparison.h>
Expand All @@ -35,14 +36,14 @@ inline FloatOptional boundAxisWithinMinAndMax(

if (isColumn(axis)) {
min = yoga::resolveValue(
node->getStyle().minDimension(YGDimensionHeight), axisSize);
node->getStyle().minDimension(Dimension::Height), axisSize);
max = yoga::resolveValue(
node->getStyle().maxDimension(YGDimensionHeight), axisSize);
node->getStyle().maxDimension(Dimension::Height), axisSize);
} else if (isRow(axis)) {
min = yoga::resolveValue(
node->getStyle().minDimension(YGDimensionWidth), axisSize);
node->getStyle().minDimension(Dimension::Width), axisSize);
max = yoga::resolveValue(
node->getStyle().maxDimension(YGDimensionWidth), axisSize);
node->getStyle().maxDimension(Dimension::Width), axisSize);
}

if (max >= FloatOptional{0} && value > max) {
Expand Down
Loading

0 comments on commit a53aee9

Please sign in to comment.