Skip to content

Commit

Permalink
C++ style enums 16/N: Dimension (#39598)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #39598

X-link: facebook/yoga#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.

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D49475409

fbshipit-source-id: 7d4c31e8a84485baea0dab50b5cf16b86769fa07
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Sep 29, 2023
1 parent e21b3c8 commit 5be6f49
Show file tree
Hide file tree
Showing 17 changed files with 198 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ - (void)setUp
auto &props = *sharedProps;
props.layoutConstraints = LayoutConstraints{{0, 0}, {500, 500}};
auto &yogaStyle = props.yogaStyle;
yogaStyle.setDimension(YGDimensionWidth, yoga::CompactValue::of<YGUnitPoint>(200));
yogaStyle.setDimension(YGDimensionHeight, yoga::CompactValue::of<YGUnitPoint>(200));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::CompactValue::of<YGUnitPoint>(200));
yogaStyle.setDimension(yoga::Dimension::Height, yoga::CompactValue::of<YGUnitPoint>(200));
return sharedProps;
})
.children({
Expand All @@ -136,8 +136,8 @@ - (void)setUp
yogaStyle.positionType() = yoga::PositionType::Absolute;
yogaStyle.position()[YGEdgeLeft] = YGValue{0, YGUnitPoint};
yogaStyle.position()[YGEdgeTop] = YGValue{0, YGUnitPoint};
yogaStyle.setDimension(YGDimensionWidth, yoga::CompactValue::of<YGUnitPoint>(200));
yogaStyle.setDimension(YGDimensionHeight, yoga::CompactValue::of<YGUnitPoint>(200));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::CompactValue::of<YGUnitPoint>(200));
yogaStyle.setDimension(yoga::Dimension::Height, yoga::CompactValue::of<YGUnitPoint>(200));
return sharedProps;
})
.children({
Expand Down Expand Up @@ -216,8 +216,8 @@ - (void)setUp
yogaStyle.positionType() = yoga::PositionType::Absolute;
yogaStyle.position()[YGEdgeLeft] = YGValue{0, YGUnitPoint};
yogaStyle.position()[YGEdgeTop] = YGValue{30, YGUnitPoint};
yogaStyle.setDimension(YGDimensionWidth, yoga::CompactValue::of<YGUnitPoint>(200));
yogaStyle.setDimension(YGDimensionHeight, yoga::CompactValue::of<YGUnitPoint>(50));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::CompactValue::of<YGUnitPoint>(200));
yogaStyle.setDimension(yoga::Dimension::Height, yoga::CompactValue::of<YGUnitPoint>(50));
return sharedProps;
})
.children({
Expand Down Expand Up @@ -260,8 +260,8 @@ - (void)setUp
yogaStyle.positionType() = yoga::PositionType::Absolute;
yogaStyle.position()[YGEdgeLeft] = YGValue{0, YGUnitPoint};
yogaStyle.position()[YGEdgeTop] = YGValue{90, YGUnitPoint};
yogaStyle.setDimension(YGDimensionWidth, yoga::CompactValue::of<YGUnitPoint>(200));
yogaStyle.setDimension(YGDimensionHeight, yoga::CompactValue::of<YGUnitPoint>(50));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::CompactValue::of<YGUnitPoint>(200));
yogaStyle.setDimension(yoga::Dimension::Height, yoga::CompactValue::of<YGUnitPoint>(50));
return sharedProps;
})
.children({
Expand Down Expand Up @@ -418,8 +418,8 @@ - (void)testEntireParagraphLink
auto &props = *sharedProps;
props.layoutConstraints = LayoutConstraints{{0, 0}, {500, 500}};
auto &yogaStyle = props.yogaStyle;
yogaStyle.setDimension(YGDimensionWidth, yoga::CompactValue::of<YGUnitPoint>(200));
yogaStyle.setDimension(YGDimensionHeight, yoga::CompactValue::of<YGUnitPoint>(200));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::CompactValue::of<YGUnitPoint>(200));
yogaStyle.setDimension(yoga::Dimension::Height, yoga::CompactValue::of<YGUnitPoint>(200));
return sharedProps;
})
.children({
Expand All @@ -434,8 +434,8 @@ - (void)testEntireParagraphLink
yogaStyle.positionType() = yoga::PositionType::Absolute;
yogaStyle.position()[YGEdgeLeft] = YGValue{0, YGUnitPoint};
yogaStyle.position()[YGEdgeTop] = YGValue{0, YGUnitPoint};
yogaStyle.setDimension(YGDimensionWidth, yoga::CompactValue::of<YGUnitPoint>(200));
yogaStyle.setDimension(YGDimensionHeight, yoga::CompactValue::of<YGUnitPoint>(20));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::CompactValue::of<YGUnitPoint>(200));
yogaStyle.setDimension(yoga::Dimension::Height, yoga::CompactValue::of<YGUnitPoint>(20));
return sharedProps;
})
.children({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,11 @@ void YogaLayoutableShadowNode::setSize(Size size) const {

auto style = yogaNode_.getStyle();
style.setDimension(
YGDimensionWidth, yoga::CompactValue::ofMaybe<YGUnitPoint>(size.width));
yoga::Dimension::Width,
yoga::CompactValue::ofMaybe<YGUnitPoint>(size.width));
style.setDimension(
YGDimensionHeight, yoga::CompactValue::ofMaybe<YGUnitPoint>(size.height));
yoga::Dimension::Height,
yoga::CompactValue::ofMaybe<YGUnitPoint>(size.height));
yogaNode_.setStyle(style);
yogaNode_.setDirty(true);
}
Expand Down Expand Up @@ -631,19 +633,19 @@ void YogaLayoutableShadowNode::layoutTree(
auto ownerHeight = yogaFloatFromFloat(maximumSize.height);

yogaStyle.setMaxDimension(
YGDimensionWidth,
yoga::Dimension::Width,
yoga::CompactValue::ofMaybe<YGUnitPoint>(maximumSize.width));

yogaStyle.setMaxDimension(
YGDimensionHeight,
yoga::Dimension::Height,
yoga::CompactValue::ofMaybe<YGUnitPoint>(maximumSize.height));

yogaStyle.setMinDimension(
YGDimensionWidth,
yoga::Dimension::Width,
yoga::CompactValue::ofMaybe<YGUnitPoint>(minimumSize.width));

yogaStyle.setMinDimension(
YGDimensionHeight,
yoga::Dimension::Height,
yoga::CompactValue::ofMaybe<YGUnitPoint>(minimumSize.height));

auto direction =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ static inline T const getFieldValue(

#define REBUILD_FIELD_YG_DIMENSION(field, setter, widthStr, heightStr) \
REBUILD_YG_FIELD_SWITCH_CASE_INDEXED_SETTER( \
field, setter, YGDimensionWidth, widthStr); \
field, setter, yoga::Dimension::Width, widthStr); \
REBUILD_YG_FIELD_SWITCH_CASE_INDEXED_SETTER( \
field, setter, YGDimensionHeight, heightStr);
field, setter, yoga::Dimension::Height, heightStr);

#define REBUILD_FIELD_YG_GUTTER(field, rowGapStr, columnGapStr, gapStr) \
REBUILD_YG_FIELD_SWITCH_CASE_INDEXED(field, YGGutterRow, rowGapStr); \
Expand Down Expand Up @@ -349,28 +349,28 @@ SharedDebugStringConvertibleList YogaStylableProps::getDebugProps() const {
"border", yogaStyle.border(), defaultYogaStyle.border()),
debugStringConvertibleItem(
"width",
yogaStyle.dimension(YGDimensionWidth),
defaultYogaStyle.dimension(YGDimensionWidth)),
yogaStyle.dimension(yoga::Dimension::Width),
defaultYogaStyle.dimension(yoga::Dimension::Width)),
debugStringConvertibleItem(
"height",
yogaStyle.dimension(YGDimensionHeight),
defaultYogaStyle.dimension(YGDimensionHeight)),
yogaStyle.dimension(yoga::Dimension::Height),
defaultYogaStyle.dimension(yoga::Dimension::Height)),
debugStringConvertibleItem(
"minWidth",
yogaStyle.minDimension(YGDimensionWidth),
defaultYogaStyle.minDimension(YGDimensionWidth)),
yogaStyle.minDimension(yoga::Dimension::Width),
defaultYogaStyle.minDimension(yoga::Dimension::Width)),
debugStringConvertibleItem(
"minHeight",
yogaStyle.minDimension(YGDimensionHeight),
defaultYogaStyle.minDimension(YGDimensionHeight)),
yogaStyle.minDimension(yoga::Dimension::Height),
defaultYogaStyle.minDimension(yoga::Dimension::Height)),
debugStringConvertibleItem(
"maxWidth",
yogaStyle.maxDimension(YGDimensionWidth),
defaultYogaStyle.maxDimension(YGDimensionWidth)),
yogaStyle.maxDimension(yoga::Dimension::Width),
defaultYogaStyle.maxDimension(yoga::Dimension::Width)),
debugStringConvertibleItem(
"maxHeight",
yogaStyle.maxDimension(YGDimensionHeight),
defaultYogaStyle.maxDimension(YGDimensionHeight)),
yogaStyle.maxDimension(yoga::Dimension::Height),
defaultYogaStyle.maxDimension(yoga::Dimension::Height)),
debugStringConvertibleItem(
"aspectRatio",
yogaStyle.aspectRatio(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,54 +274,54 @@ static inline yoga::Style convertRawProp(
yogaStyle.border());

yogaStyle.setDimension(
YGDimensionWidth,
yoga::Dimension::Width,
convertRawProp(
context,
rawProps,
"width",
sourceValue.dimension(YGDimensionWidth),
sourceValue.dimension(yoga::Dimension::Width),
{}));
yogaStyle.setDimension(
YGDimensionHeight,
yoga::Dimension::Height,
convertRawProp(
context,
rawProps,
"height",
sourceValue.dimension(YGDimensionHeight),
sourceValue.dimension(yoga::Dimension::Height),
{}));

yogaStyle.setMinDimension(
YGDimensionWidth,
yoga::Dimension::Width,
convertRawProp(
context,
rawProps,
"minWidth",
sourceValue.minDimension(YGDimensionWidth),
sourceValue.minDimension(yoga::Dimension::Width),
{}));
yogaStyle.setMinDimension(
YGDimensionHeight,
yoga::Dimension::Height,
convertRawProp(
context,
rawProps,
"minHeight",
sourceValue.minDimension(YGDimensionHeight),
sourceValue.minDimension(yoga::Dimension::Height),
{}));

yogaStyle.setMaxDimension(
YGDimensionWidth,
yoga::Dimension::Width,
convertRawProp(
context,
rawProps,
"maxWidth",
sourceValue.maxDimension(YGDimensionWidth),
sourceValue.maxDimension(yoga::Dimension::Width),
{}));
yogaStyle.setMaxDimension(
YGDimensionHeight,
yoga::Dimension::Height,
convertRawProp(
context,
rawProps,
"maxHeight",
sourceValue.maxDimension(YGDimensionHeight),
sourceValue.maxDimension(yoga::Dimension::Height),
{}));

yogaStyle.aspectRatio() = convertRawProp(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ class LayoutTest : public ::testing::Test {
auto &props = *sharedProps;
props.layoutConstraints = LayoutConstraints{{0,0}, {500, 500}};
auto &yogaStyle = props.yogaStyle;
yogaStyle.setDimension(YGDimensionWidth, yoga::CompactValue::of<YGUnitPoint>(200));
yogaStyle.setDimension(YGDimensionHeight, yoga::CompactValue::of<YGUnitPoint>(200));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::CompactValue::of<YGUnitPoint>(200));
yogaStyle.setDimension(yoga::Dimension::Height, yoga::CompactValue::of<YGUnitPoint>(200));
return sharedProps;
})
.children({
Expand All @@ -90,8 +90,8 @@ class LayoutTest : public ::testing::Test {
auto &props = *sharedProps;
auto &yogaStyle = props.yogaStyle;
yogaStyle.positionType() = yoga::PositionType::Absolute;
yogaStyle.setDimension(YGDimensionWidth, yoga::CompactValue::of<YGUnitPoint>(50));
yogaStyle.setDimension(YGDimensionHeight, yoga::CompactValue::of<YGUnitPoint>(50));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::CompactValue::of<YGUnitPoint>(50));
yogaStyle.setDimension(yoga::Dimension::Height, yoga::CompactValue::of<YGUnitPoint>(50));
return sharedProps;
})
.children({
Expand All @@ -105,8 +105,8 @@ class LayoutTest : public ::testing::Test {
yogaStyle.positionType() = yoga::PositionType::Absolute;
yogaStyle.position()[YGEdgeLeft] = YGValue{10, YGUnitPoint};
yogaStyle.position()[YGEdgeTop] = YGValue{10, YGUnitPoint};
yogaStyle.setDimension(YGDimensionWidth, yoga::CompactValue::of<YGUnitPoint>(30));
yogaStyle.setDimension(YGDimensionHeight, yoga::CompactValue::of<YGUnitPoint>(90));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::CompactValue::of<YGUnitPoint>(30));
yogaStyle.setDimension(yoga::Dimension::Height, yoga::CompactValue::of<YGUnitPoint>(90));

if (testCase == TRANSFORM_SCALE) {
props.transform = props.transform * Transform::Scale(2, 2, 1);
Expand Down Expand Up @@ -138,8 +138,8 @@ class LayoutTest : public ::testing::Test {
yogaStyle.positionType() = yoga::PositionType::Absolute;
yogaStyle.position()[YGEdgeLeft] = YGValue{10, YGUnitPoint};
yogaStyle.position()[YGEdgeTop] = YGValue{10, YGUnitPoint};
yogaStyle.setDimension(YGDimensionWidth, yoga::CompactValue::of<YGUnitPoint>(110));
yogaStyle.setDimension(YGDimensionHeight, yoga::CompactValue::of<YGUnitPoint>(20));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::CompactValue::of<YGUnitPoint>(110));
yogaStyle.setDimension(yoga::Dimension::Height, yoga::CompactValue::of<YGUnitPoint>(20));
return sharedProps;
})
.children({
Expand All @@ -153,8 +153,8 @@ class LayoutTest : public ::testing::Test {
yogaStyle.positionType() = yoga::PositionType::Absolute;
yogaStyle.position()[YGEdgeLeft] = YGValue{70, YGUnitPoint};
yogaStyle.position()[YGEdgeTop] = YGValue{-50, YGUnitPoint};
yogaStyle.setDimension(YGDimensionWidth, yoga::CompactValue::of<YGUnitPoint>(30));
yogaStyle.setDimension(YGDimensionHeight, yoga::CompactValue::of<YGUnitPoint>(60));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::CompactValue::of<YGUnitPoint>(30));
yogaStyle.setDimension(yoga::Dimension::Height, yoga::CompactValue::of<YGUnitPoint>(60));
return sharedProps;
})
}),
Expand All @@ -168,8 +168,8 @@ class LayoutTest : public ::testing::Test {
yogaStyle.positionType() = yoga::PositionType::Absolute;
yogaStyle.position()[YGEdgeLeft] = YGValue{-60, YGUnitPoint};
yogaStyle.position()[YGEdgeTop] = YGValue{50, YGUnitPoint};
yogaStyle.setDimension(YGDimensionWidth, yoga::CompactValue::of<YGUnitPoint>(70));
yogaStyle.setDimension(YGDimensionHeight, yoga::CompactValue::of<YGUnitPoint>(20));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::CompactValue::of<YGUnitPoint>(70));
yogaStyle.setDimension(yoga::Dimension::Height, yoga::CompactValue::of<YGUnitPoint>(20));
return sharedProps;
})
})
Expand Down
Loading

0 comments on commit 5be6f49

Please sign in to comment.