Files
yoga/yoga/YGConfig.h

100 lines
2.4 KiB
C
Raw Normal View History

/*
* 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-internal.h"
#include "Yoga.h"
Add YGErrata integration within C ABI (#37075) Summary: X-link: https://github.com/facebook/react-native/pull/37075 Pull Request resolved: https://github.com/facebook/yoga/pull/1255 This diff wires up YGErrata to a public API, along with existing functions to set UseLegacyStretchBehaviour. The `UseLegacyStretchBehaviour` functions will be removed after the world internally is transitioned to `YGConfigSetErrata`. This is intentionally breaking, since most users previously enabling `UseLegacyStretchBehaviour` will want to pick a new appropriate errata setting. Internally, users of the API will be moved to`YGErrataAll`. The overall change looks like: 1. Clean up YGConfig to use accessors/setters 2. Change up YGconfig internal storage 1. Fabric has a config per ShadowNode, so it makes sense to do some size optimization before adding more (free-form bools to bitfield, `std::array<bool,>` to `std::bitset` since not specialized) 3. Wire accessor/setter of UseLegacyStretchBehaviour to errata while both APIs exist 4. Add errata APIs to C ABI After this we will need to expose the ABI to more language projections, and (more involved), add usages of the API to internal consumption of Yoga before adding more errata and removing `UseLegacyStretchBehaviour`. Note that this API representation is similar, but distinct to `YGExperimentalFeature`. I think that API may also have made sense as an enum bitset, like we explicitly want for the new API, but it's not really worth changing the existing API to make that happen. Reviewed By: rshest Differential Revision: D45254097 fbshipit-source-id: 5c725ce5a77b25c1356f753d11c468587dbd8ded
2023-04-27 06:48:04 -07:00
#include "BitUtils.h"
namespace facebook {
namespace yoga {
namespace detail {
using LogWithContextFn = int (*)(
YGConfigRef config,
YGNodeRef node,
YGLogLevel level,
void* context,
const char* format,
va_list args);
using CloneWithContextFn = YGNodeRef (*)(
YGNodeRef node,
YGNodeRef owner,
int childIndex,
void* cloneContext);
#pragma pack(push)
#pragma pack(1)
struct YGConfigFlags {
bool useWebDefaults : 1;
bool printTree : 1;
bool cloneNodeUsesContext : 1;
bool loggerUsesContext : 1;
};
#pragma pack(pop)
} // namespace detail
} // namespace yoga
} // namespace facebook
struct YOGA_EXPORT YGConfig {
Add YGErrata integration within C ABI (#37075) Summary: X-link: https://github.com/facebook/react-native/pull/37075 Pull Request resolved: https://github.com/facebook/yoga/pull/1255 This diff wires up YGErrata to a public API, along with existing functions to set UseLegacyStretchBehaviour. The `UseLegacyStretchBehaviour` functions will be removed after the world internally is transitioned to `YGConfigSetErrata`. This is intentionally breaking, since most users previously enabling `UseLegacyStretchBehaviour` will want to pick a new appropriate errata setting. Internally, users of the API will be moved to`YGErrataAll`. The overall change looks like: 1. Clean up YGConfig to use accessors/setters 2. Change up YGconfig internal storage 1. Fabric has a config per ShadowNode, so it makes sense to do some size optimization before adding more (free-form bools to bitfield, `std::array<bool,>` to `std::bitset` since not specialized) 3. Wire accessor/setter of UseLegacyStretchBehaviour to errata while both APIs exist 4. Add errata APIs to C ABI After this we will need to expose the ABI to more language projections, and (more involved), add usages of the API to internal consumption of Yoga before adding more errata and removing `UseLegacyStretchBehaviour`. Note that this API representation is similar, but distinct to `YGExperimentalFeature`. I think that API may also have made sense as an enum bitset, like we explicitly want for the new API, but it's not really worth changing the existing API to make that happen. Reviewed By: rshest Differential Revision: D45254097 fbshipit-source-id: 5c725ce5a77b25c1356f753d11c468587dbd8ded
2023-04-27 06:48:04 -07:00
YGConfig(YGLogger logger);
void setUseWebDefaults(bool useWebDefaults);
bool useWebDefaults() const;
void setShouldPrintTree(bool printTree);
bool shouldPrintTree() const;
void setExperimentalFeatureEnabled(
YGExperimentalFeature feature,
bool enabled);
bool isExperimentalFeatureEnabled(YGExperimentalFeature feature) const;
void setErrata(YGErrata errata);
YGErrata getErrata() const;
void setPointScaleFactor(float pointScaleFactor);
float getPointScaleFactor() const;
void setContext(void* context);
void* getContext() const;
void setLogger(YGLogger logger);
void setLogger(facebook::yoga::detail::LogWithContextFn logger);
void setLogger(std::nullptr_t);
void log(YGConfig*, YGNode*, YGLogLevel, void*, const char*, va_list) const;
void setCloneNodeCallback(YGCloneNodeFunc cloneNode);
void setCloneNodeCallback(
facebook::yoga::detail::CloneWithContextFn cloneNode);
void setCloneNodeCallback(std::nullptr_t);
YGNodeRef cloneNode(
YGNodeRef node,
YGNodeRef owner,
int childIndex,
Add YGErrata integration within C ABI (#37075) Summary: X-link: https://github.com/facebook/react-native/pull/37075 Pull Request resolved: https://github.com/facebook/yoga/pull/1255 This diff wires up YGErrata to a public API, along with existing functions to set UseLegacyStretchBehaviour. The `UseLegacyStretchBehaviour` functions will be removed after the world internally is transitioned to `YGConfigSetErrata`. This is intentionally breaking, since most users previously enabling `UseLegacyStretchBehaviour` will want to pick a new appropriate errata setting. Internally, users of the API will be moved to`YGErrataAll`. The overall change looks like: 1. Clean up YGConfig to use accessors/setters 2. Change up YGconfig internal storage 1. Fabric has a config per ShadowNode, so it makes sense to do some size optimization before adding more (free-form bools to bitfield, `std::array<bool,>` to `std::bitset` since not specialized) 3. Wire accessor/setter of UseLegacyStretchBehaviour to errata while both APIs exist 4. Add errata APIs to C ABI After this we will need to expose the ABI to more language projections, and (more involved), add usages of the API to internal consumption of Yoga before adding more errata and removing `UseLegacyStretchBehaviour`. Note that this API representation is similar, but distinct to `YGExperimentalFeature`. I think that API may also have made sense as an enum bitset, like we explicitly want for the new API, but it's not really worth changing the existing API to make that happen. Reviewed By: rshest Differential Revision: D45254097 fbshipit-source-id: 5c725ce5a77b25c1356f753d11c468587dbd8ded
2023-04-27 06:48:04 -07:00
void* cloneContext) const;
private:
union {
Add YGErrata integration within C ABI (#37075) Summary: X-link: https://github.com/facebook/react-native/pull/37075 Pull Request resolved: https://github.com/facebook/yoga/pull/1255 This diff wires up YGErrata to a public API, along with existing functions to set UseLegacyStretchBehaviour. The `UseLegacyStretchBehaviour` functions will be removed after the world internally is transitioned to `YGConfigSetErrata`. This is intentionally breaking, since most users previously enabling `UseLegacyStretchBehaviour` will want to pick a new appropriate errata setting. Internally, users of the API will be moved to`YGErrataAll`. The overall change looks like: 1. Clean up YGConfig to use accessors/setters 2. Change up YGconfig internal storage 1. Fabric has a config per ShadowNode, so it makes sense to do some size optimization before adding more (free-form bools to bitfield, `std::array<bool,>` to `std::bitset` since not specialized) 3. Wire accessor/setter of UseLegacyStretchBehaviour to errata while both APIs exist 4. Add errata APIs to C ABI After this we will need to expose the ABI to more language projections, and (more involved), add usages of the API to internal consumption of Yoga before adding more errata and removing `UseLegacyStretchBehaviour`. Note that this API representation is similar, but distinct to `YGExperimentalFeature`. I think that API may also have made sense as an enum bitset, like we explicitly want for the new API, but it's not really worth changing the existing API to make that happen. Reviewed By: rshest Differential Revision: D45254097 fbshipit-source-id: 5c725ce5a77b25c1356f753d11c468587dbd8ded
2023-04-27 06:48:04 -07:00
facebook::yoga::detail::CloneWithContextFn withContext;
YGCloneNodeFunc noContext;
} cloneNodeCallback_;
union {
Add YGErrata integration within C ABI (#37075) Summary: X-link: https://github.com/facebook/react-native/pull/37075 Pull Request resolved: https://github.com/facebook/yoga/pull/1255 This diff wires up YGErrata to a public API, along with existing functions to set UseLegacyStretchBehaviour. The `UseLegacyStretchBehaviour` functions will be removed after the world internally is transitioned to `YGConfigSetErrata`. This is intentionally breaking, since most users previously enabling `UseLegacyStretchBehaviour` will want to pick a new appropriate errata setting. Internally, users of the API will be moved to`YGErrataAll`. The overall change looks like: 1. Clean up YGConfig to use accessors/setters 2. Change up YGconfig internal storage 1. Fabric has a config per ShadowNode, so it makes sense to do some size optimization before adding more (free-form bools to bitfield, `std::array<bool,>` to `std::bitset` since not specialized) 3. Wire accessor/setter of UseLegacyStretchBehaviour to errata while both APIs exist 4. Add errata APIs to C ABI After this we will need to expose the ABI to more language projections, and (more involved), add usages of the API to internal consumption of Yoga before adding more errata and removing `UseLegacyStretchBehaviour`. Note that this API representation is similar, but distinct to `YGExperimentalFeature`. I think that API may also have made sense as an enum bitset, like we explicitly want for the new API, but it's not really worth changing the existing API to make that happen. Reviewed By: rshest Differential Revision: D45254097 fbshipit-source-id: 5c725ce5a77b25c1356f753d11c468587dbd8ded
2023-04-27 06:48:04 -07:00
facebook::yoga::detail::LogWithContextFn withContext;
YGLogger noContext;
} logger_;
Add YGErrata integration within C ABI (#37075) Summary: X-link: https://github.com/facebook/react-native/pull/37075 Pull Request resolved: https://github.com/facebook/yoga/pull/1255 This diff wires up YGErrata to a public API, along with existing functions to set UseLegacyStretchBehaviour. The `UseLegacyStretchBehaviour` functions will be removed after the world internally is transitioned to `YGConfigSetErrata`. This is intentionally breaking, since most users previously enabling `UseLegacyStretchBehaviour` will want to pick a new appropriate errata setting. Internally, users of the API will be moved to`YGErrataAll`. The overall change looks like: 1. Clean up YGConfig to use accessors/setters 2. Change up YGconfig internal storage 1. Fabric has a config per ShadowNode, so it makes sense to do some size optimization before adding more (free-form bools to bitfield, `std::array<bool,>` to `std::bitset` since not specialized) 3. Wire accessor/setter of UseLegacyStretchBehaviour to errata while both APIs exist 4. Add errata APIs to C ABI After this we will need to expose the ABI to more language projections, and (more involved), add usages of the API to internal consumption of Yoga before adding more errata and removing `UseLegacyStretchBehaviour`. Note that this API representation is similar, but distinct to `YGExperimentalFeature`. I think that API may also have made sense as an enum bitset, like we explicitly want for the new API, but it's not really worth changing the existing API to make that happen. Reviewed By: rshest Differential Revision: D45254097 fbshipit-source-id: 5c725ce5a77b25c1356f753d11c468587dbd8ded
2023-04-27 06:48:04 -07:00
facebook::yoga::detail::YGConfigFlags flags_{};
facebook::yoga::detail::EnumBitset<YGExperimentalFeature>
experimentalFeatures_{};
YGErrata errata_ = YGErrataNone;
float pointScaleFactor_ = 1.0f;
void* context_ = nullptr;
};