Files
yoga/yoga/YGConfig.h

109 lines
2.9 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/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"
#include "Yoga-internal.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
namespace facebook::yoga {
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
// Whether moving a node from config "a" to config "b" should dirty previously
// calculated layout results.
bool configUpdateInvalidatesLayout(YGConfigRef a, YGConfigRef b);
// Internal variants of log functions, currently used only by JNI bindings.
// TODO: Reconcile this with the public API
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
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);
using ExperimentalFeatureSet =
facebook::yoga::detail::EnumBitset<YGExperimentalFeature>;
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
#pragma pack(push)
#pragma pack(1)
// Packed structure of <32-bit options to miminize size per node.
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
struct YGConfigFlags {
bool useWebDefaults : 1;
bool printTree : 1;
bool cloneNodeUsesContext : 1;
bool loggerUsesContext : 1;
};
#pragma pack(pop)
} // namespace facebook::yoga
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;
facebook::yoga::ExperimentalFeatureSet getEnabledExperiments() const;
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 setErrata(YGErrata errata);
void addErrata(YGErrata errata);
void removeErrata(YGErrata errata);
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
YGErrata getErrata() const;
bool hasErrata(YGErrata errata) const;
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 setPointScaleFactor(float pointScaleFactor);
float getPointScaleFactor() const;
void setContext(void* context);
void* getContext() const;
void setLogger(YGLogger logger);
void setLogger(facebook::yoga::LogWithContextFn 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
void setLogger(std::nullptr_t);
void log(YGConfig*, YGNode*, YGLogLevel, void*, const char*, va_list) const;
void setCloneNodeCallback(YGCloneNodeFunc cloneNode);
void setCloneNodeCallback(facebook::yoga::CloneWithContextFn cloneNode);
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 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 {
facebook::yoga::CloneWithContextFn withContext;
YGCloneNodeFunc noContext;
} cloneNodeCallback_;
union {
facebook::yoga::LogWithContextFn withContext;
YGLogger noContext;
} logger_;
facebook::yoga::YGConfigFlags flags_{};
facebook::yoga::ExperimentalFeatureSet experimentalFeatures_{};
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
YGErrata errata_ = YGErrataNone;
float pointScaleFactor_ = 1.0f;
void* context_ = nullptr;
};