C++ style enums 3/N: ExperimentalFeature (#1386)
Summary: X-link: https://github.com/facebook/react-native/pull/39448 Pull Request resolved: https://github.com/facebook/yoga/pull/1386 This converts usages of YGExperimentalFeature to ExperimentalFeature Reviewed By: rozele Differential Revision: D49269440 fbshipit-source-id: 0fcb4f380e214a6aadcac457df5a989789bb05d2
This commit is contained in:
committed by
Facebook GitHub Bot
parent
9129a0af87
commit
42e1f2c737
@@ -851,13 +851,14 @@ void YGConfigSetExperimentalFeatureEnabled(
|
|||||||
const YGConfigRef config,
|
const YGConfigRef config,
|
||||||
const YGExperimentalFeature feature,
|
const YGExperimentalFeature feature,
|
||||||
const bool enabled) {
|
const bool enabled) {
|
||||||
resolveRef(config)->setExperimentalFeatureEnabled(feature, enabled);
|
resolveRef(config)->setExperimentalFeatureEnabled(
|
||||||
|
scopedEnum(feature), enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool YGConfigIsExperimentalFeatureEnabled(
|
bool YGConfigIsExperimentalFeatureEnabled(
|
||||||
const YGConfigConstRef config,
|
const YGConfigConstRef config,
|
||||||
const YGExperimentalFeature feature) {
|
const YGExperimentalFeature feature) {
|
||||||
return resolveRef(config)->isExperimentalFeatureEnabled(feature);
|
return resolveRef(config)->isExperimentalFeatureEnabled(scopedEnum(feature));
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGConfigSetUseWebDefaults(const YGConfigRef config, const bool enabled) {
|
void YGConfigSetUseWebDefaults(const YGConfigRef config, const bool enabled) {
|
||||||
|
@@ -154,7 +154,7 @@ static void computeFlexBasisForChild(
|
|||||||
if (!resolvedFlexBasis.isUndefined() && !yoga::isUndefined(mainAxisSize)) {
|
if (!resolvedFlexBasis.isUndefined() && !yoga::isUndefined(mainAxisSize)) {
|
||||||
if (child->getLayout().computedFlexBasis.isUndefined() ||
|
if (child->getLayout().computedFlexBasis.isUndefined() ||
|
||||||
(child->getConfig()->isExperimentalFeatureEnabled(
|
(child->getConfig()->isExperimentalFeatureEnabled(
|
||||||
YGExperimentalFeatureWebFlexBasis) &&
|
ExperimentalFeature::WebFlexBasis) &&
|
||||||
child->getLayout().computedFlexBasisGeneration != generationCount)) {
|
child->getLayout().computedFlexBasisGeneration != generationCount)) {
|
||||||
const FloatOptional paddingAndBorder =
|
const FloatOptional paddingAndBorder =
|
||||||
FloatOptional(paddingAndBorderForAxis(child, mainAxis, ownerWidth));
|
FloatOptional(paddingAndBorderForAxis(child, mainAxis, ownerWidth));
|
||||||
@@ -479,7 +479,7 @@ static void layoutAbsoluteChild(
|
|||||||
leadingEdge(mainAxis));
|
leadingEdge(mainAxis));
|
||||||
} else if (
|
} else if (
|
||||||
node->getConfig()->isExperimentalFeatureEnabled(
|
node->getConfig()->isExperimentalFeatureEnabled(
|
||||||
YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge) &&
|
ExperimentalFeature::AbsolutePercentageAgainstPaddingEdge) &&
|
||||||
child->isLeadingPositionDefined(mainAxis)) {
|
child->isLeadingPositionDefined(mainAxis)) {
|
||||||
child->setLayoutPosition(
|
child->setLayoutPosition(
|
||||||
child->getLeadingPosition(
|
child->getLeadingPosition(
|
||||||
@@ -526,7 +526,7 @@ static void layoutAbsoluteChild(
|
|||||||
leadingEdge(crossAxis));
|
leadingEdge(crossAxis));
|
||||||
} else if (
|
} else if (
|
||||||
node->getConfig()->isExperimentalFeatureEnabled(
|
node->getConfig()->isExperimentalFeatureEnabled(
|
||||||
YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge) &&
|
ExperimentalFeature::AbsolutePercentageAgainstPaddingEdge) &&
|
||||||
child->isLeadingPositionDefined(crossAxis)) {
|
child->isLeadingPositionDefined(crossAxis)) {
|
||||||
child->setLayoutPosition(
|
child->setLayoutPosition(
|
||||||
child->getLeadingPosition(
|
child->getLeadingPosition(
|
||||||
@@ -2323,7 +2323,7 @@ static void calculateLayoutImpl(
|
|||||||
}
|
}
|
||||||
const bool absolutePercentageAgainstPaddingEdge =
|
const bool absolutePercentageAgainstPaddingEdge =
|
||||||
node->getConfig()->isExperimentalFeatureEnabled(
|
node->getConfig()->isExperimentalFeatureEnabled(
|
||||||
YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge);
|
ExperimentalFeature::AbsolutePercentageAgainstPaddingEdge);
|
||||||
|
|
||||||
layoutAbsoluteChild(
|
layoutAbsoluteChild(
|
||||||
node,
|
node,
|
||||||
|
@@ -1,19 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
||||||
*
|
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <yoga/YGEnums.h>
|
|
||||||
#include <bitset>
|
|
||||||
|
|
||||||
namespace facebook::yoga {
|
|
||||||
|
|
||||||
// std::bitset with one bit for each option defined in YG_ENUM_SEQ_DECL
|
|
||||||
template <typename Enum>
|
|
||||||
using EnumBitset = std::bitset<enums::count<Enum>()>;
|
|
||||||
|
|
||||||
} // namespace facebook::yoga
|
|
@@ -41,16 +41,16 @@ bool Config::shouldPrintTree() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Config::setExperimentalFeatureEnabled(
|
void Config::setExperimentalFeatureEnabled(
|
||||||
YGExperimentalFeature feature,
|
ExperimentalFeature feature,
|
||||||
bool enabled) {
|
bool enabled) {
|
||||||
experimentalFeatures_.set(feature, enabled);
|
experimentalFeatures_.set(static_cast<size_t>(feature), enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Config::isExperimentalFeatureEnabled(YGExperimentalFeature feature) const {
|
bool Config::isExperimentalFeatureEnabled(ExperimentalFeature feature) const {
|
||||||
return experimentalFeatures_.test(feature);
|
return experimentalFeatures_.test(static_cast<size_t>(feature));
|
||||||
}
|
}
|
||||||
|
|
||||||
EnumBitset<YGExperimentalFeature> Config::getEnabledExperiments() const {
|
ExperimentalFeatureSet Config::getEnabledExperiments() const {
|
||||||
return experimentalFeatures_;
|
return experimentalFeatures_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -7,8 +7,10 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <bitset>
|
||||||
|
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
#include <yoga/bits/EnumBitset.h>
|
#include <yoga/enums/ExperimentalFeature.h>
|
||||||
|
|
||||||
// Tag struct used to form the opaque YGConfigRef for the public C API
|
// Tag struct used to form the opaque YGConfigRef for the public C API
|
||||||
struct YGConfig {};
|
struct YGConfig {};
|
||||||
@@ -18,6 +20,8 @@ namespace facebook::yoga {
|
|||||||
class Config;
|
class Config;
|
||||||
class Node;
|
class Node;
|
||||||
|
|
||||||
|
using ExperimentalFeatureSet = std::bitset<ordinalCount<ExperimentalFeature>()>;
|
||||||
|
|
||||||
// Whether moving a node from an old to new config should dirty previously
|
// Whether moving a node from an old to new config should dirty previously
|
||||||
// calculated layout results.
|
// calculated layout results.
|
||||||
bool configUpdateInvalidatesLayout(
|
bool configUpdateInvalidatesLayout(
|
||||||
@@ -43,11 +47,9 @@ class YG_EXPORT Config : public ::YGConfig {
|
|||||||
void setShouldPrintTree(bool printTree);
|
void setShouldPrintTree(bool printTree);
|
||||||
bool shouldPrintTree() const;
|
bool shouldPrintTree() const;
|
||||||
|
|
||||||
void setExperimentalFeatureEnabled(
|
void setExperimentalFeatureEnabled(ExperimentalFeature feature, bool enabled);
|
||||||
YGExperimentalFeature feature,
|
bool isExperimentalFeatureEnabled(ExperimentalFeature feature) const;
|
||||||
bool enabled);
|
ExperimentalFeatureSet getEnabledExperiments() const;
|
||||||
bool isExperimentalFeatureEnabled(YGExperimentalFeature feature) const;
|
|
||||||
EnumBitset<YGExperimentalFeature> getEnabledExperiments() const;
|
|
||||||
|
|
||||||
void setErrata(YGErrata errata);
|
void setErrata(YGErrata errata);
|
||||||
void addErrata(YGErrata errata);
|
void addErrata(YGErrata errata);
|
||||||
@@ -79,7 +81,7 @@ class YG_EXPORT Config : public ::YGConfig {
|
|||||||
YGLogger logger_;
|
YGLogger logger_;
|
||||||
|
|
||||||
ConfigFlags flags_{};
|
ConfigFlags flags_{};
|
||||||
EnumBitset<YGExperimentalFeature> experimentalFeatures_{};
|
ExperimentalFeatureSet experimentalFeatures_{};
|
||||||
YGErrata errata_ = YGErrataNone;
|
YGErrata errata_ = YGErrataNone;
|
||||||
float pointScaleFactor_ = 1.0f;
|
float pointScaleFactor_ = 1.0f;
|
||||||
void* context_ = nullptr;
|
void* context_ = nullptr;
|
||||||
|
@@ -10,9 +10,9 @@
|
|||||||
namespace facebook::yoga {
|
namespace facebook::yoga {
|
||||||
|
|
||||||
template <typename EnumT>
|
template <typename EnumT>
|
||||||
constexpr inline int32_t ordinalCount() = delete;
|
constexpr inline int32_t ordinalCount();
|
||||||
|
|
||||||
template <typename EnumT>
|
template <typename EnumT>
|
||||||
constexpr inline int32_t bitCount() = delete;
|
constexpr inline int32_t bitCount();
|
||||||
|
|
||||||
} // namespace facebook::yoga
|
} // namespace facebook::yoga
|
||||||
|
Reference in New Issue
Block a user