Non-breaking const-correctness fixes (#1365)
Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1365 X-link: https://github.com/facebook/react-native/pull/39368 This changes public Yoga API to in more places accept const structures where before they required mutable ones. `resolveRef` is added as a quick way to resolve overloaded opaque refs for different types which is a bit easier to read than static_casting, and which will propagate const-ness. We also add `YGConfigConstRef`, similar to `YGNodeConstRef`. I was a bit iffy on whether we should add something to make it easier to convert to private interface, but this doesn't seem any easier to misuse than someone who looks at the internals to find the `static_cast`. This tries to avoid more breaking changes yet, e.g. changing callbacks to require clients do not modify nodes when they are passed for logging. We also don't have const variants for returning child structures which would allow mutation of dependencies of the const object. These would need new names under the public API, since we do not have operator overloading in C. Reviewed By: rshest Differential Revision: D49130412 fbshipit-source-id: ee6b31b47f4622031c63dd52d8ac133d21bf29b7
This commit is contained in:
committed by
Facebook GitHub Bot
parent
3cb29e60a8
commit
b12a6a340c
255
yoga/Yoga.cpp
255
yoga/Yoga.cpp
@@ -99,93 +99,95 @@ YOGA_EXPORT bool YGFloatIsUndefined(const float value) {
|
|||||||
return yoga::isUndefined(value);
|
return yoga::isUndefined(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void* YGNodeGetContext(YGNodeRef node) {
|
YOGA_EXPORT void* YGNodeGetContext(YGNodeConstRef node) {
|
||||||
return static_cast<yoga::Node*>(node)->getContext();
|
return resolveRef(node)->getContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeSetContext(YGNodeRef node, void* context) {
|
YOGA_EXPORT void YGNodeSetContext(YGNodeRef node, void* context) {
|
||||||
return static_cast<yoga::Node*>(node)->setContext(context);
|
return resolveRef(node)->setContext(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT YGConfigRef YGNodeGetConfig(YGNodeRef node) {
|
YOGA_EXPORT YGConfigRef YGNodeGetConfig(YGNodeRef node) {
|
||||||
return static_cast<yoga::Node*>(node)->getConfig();
|
return resolveRef(node)->getConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeSetConfig(YGNodeRef node, YGConfigRef config) {
|
YOGA_EXPORT void YGNodeSetConfig(YGNodeRef node, YGConfigRef config) {
|
||||||
static_cast<yoga::Node*>(node)->setConfig(static_cast<yoga::Config*>(config));
|
resolveRef(node)->setConfig(resolveRef(config));
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT bool YGNodeHasMeasureFunc(YGNodeRef node) {
|
YOGA_EXPORT bool YGNodeHasMeasureFunc(YGNodeConstRef node) {
|
||||||
return static_cast<yoga::Node*>(node)->hasMeasureFunc();
|
return resolveRef(node)->hasMeasureFunc();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeSetMeasureFunc(
|
YOGA_EXPORT void YGNodeSetMeasureFunc(
|
||||||
YGNodeRef node,
|
YGNodeRef node,
|
||||||
YGMeasureFunc measureFunc) {
|
YGMeasureFunc measureFunc) {
|
||||||
static_cast<yoga::Node*>(node)->setMeasureFunc(measureFunc);
|
resolveRef(node)->setMeasureFunc(measureFunc);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT bool YGNodeHasBaselineFunc(YGNodeRef node) {
|
YOGA_EXPORT bool YGNodeHasBaselineFunc(YGNodeConstRef node) {
|
||||||
return static_cast<yoga::Node*>(node)->hasBaselineFunc();
|
return resolveRef(node)->hasBaselineFunc();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeSetBaselineFunc(
|
YOGA_EXPORT void YGNodeSetBaselineFunc(
|
||||||
YGNodeRef node,
|
YGNodeRef node,
|
||||||
YGBaselineFunc baselineFunc) {
|
YGBaselineFunc baselineFunc) {
|
||||||
static_cast<yoga::Node*>(node)->setBaselineFunc(baselineFunc);
|
resolveRef(node)->setBaselineFunc(baselineFunc);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT YGDirtiedFunc YGNodeGetDirtiedFunc(YGNodeRef node) {
|
YOGA_EXPORT YGDirtiedFunc YGNodeGetDirtiedFunc(YGNodeConstRef node) {
|
||||||
return static_cast<yoga::Node*>(node)->getDirtied();
|
return resolveRef(node)->getDirtied();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeSetDirtiedFunc(
|
YOGA_EXPORT void YGNodeSetDirtiedFunc(
|
||||||
YGNodeRef node,
|
YGNodeRef node,
|
||||||
YGDirtiedFunc dirtiedFunc) {
|
YGDirtiedFunc dirtiedFunc) {
|
||||||
static_cast<yoga::Node*>(node)->setDirtiedFunc(dirtiedFunc);
|
resolveRef(node)->setDirtiedFunc(dirtiedFunc);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc) {
|
YOGA_EXPORT void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc) {
|
||||||
static_cast<yoga::Node*>(node)->setPrintFunc(printFunc);
|
resolveRef(node)->setPrintFunc(printFunc);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT bool YGNodeGetHasNewLayout(YGNodeRef node) {
|
YOGA_EXPORT bool YGNodeGetHasNewLayout(YGNodeConstRef node) {
|
||||||
return static_cast<yoga::Node*>(node)->getHasNewLayout();
|
return resolveRef(node)->getHasNewLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGConfigSetPrintTreeFlag(YGConfigRef config, bool enabled) {
|
YOGA_EXPORT void YGConfigSetPrintTreeFlag(YGConfigRef config, bool enabled) {
|
||||||
static_cast<yoga::Config*>(config)->setShouldPrintTree(enabled);
|
resolveRef(config)->setShouldPrintTree(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout) {
|
YOGA_EXPORT void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout) {
|
||||||
static_cast<yoga::Node*>(node)->setHasNewLayout(hasNewLayout);
|
resolveRef(node)->setHasNewLayout(hasNewLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT YGNodeType YGNodeGetNodeType(YGNodeRef node) {
|
YOGA_EXPORT YGNodeType YGNodeGetNodeType(YGNodeConstRef node) {
|
||||||
return static_cast<yoga::Node*>(node)->getNodeType();
|
return resolveRef(node)->getNodeType();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType) {
|
YOGA_EXPORT void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType) {
|
||||||
return static_cast<yoga::Node*>(node)->setNodeType(nodeType);
|
return resolveRef(node)->setNodeType(nodeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT bool YGNodeIsDirty(YGNodeRef node) {
|
YOGA_EXPORT bool YGNodeIsDirty(YGNodeConstRef node) {
|
||||||
return static_cast<yoga::Node*>(node)->isDirty();
|
return resolveRef(node)->isDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeMarkDirtyAndPropagateToDescendants(
|
YOGA_EXPORT void YGNodeMarkDirtyAndPropagateToDescendants(
|
||||||
const YGNodeRef node) {
|
const YGNodeRef node) {
|
||||||
return static_cast<yoga::Node*>(node)->markDirtyAndPropagateDownwards();
|
return resolveRef(node)->markDirtyAndPropagateDownwards();
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t gConfigInstanceCount = 0;
|
int32_t gConfigInstanceCount = 0;
|
||||||
|
|
||||||
YOGA_EXPORT WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config) {
|
YOGA_EXPORT WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config) {
|
||||||
auto* node = new yoga::Node{static_cast<yoga::Config*>(config)};
|
auto* node = new yoga::Node{resolveRef(config)};
|
||||||
yoga::assertFatal(
|
yoga::assertFatal(
|
||||||
config != nullptr, "Tried to construct YGNode with null config");
|
config != nullptr, "Tried to construct YGNode with null config");
|
||||||
yoga::assertFatalWithConfig(
|
yoga::assertFatalWithConfig(
|
||||||
config, node != nullptr, "Could not allocate memory for node");
|
resolveRef(config),
|
||||||
|
node != nullptr,
|
||||||
|
"Could not allocate memory for node");
|
||||||
Event::publish<Event::NodeAllocation>(node, {config});
|
Event::publish<Event::NodeAllocation>(node, {config});
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
@@ -201,8 +203,8 @@ YOGA_EXPORT YGNodeRef YGNodeNew(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT YGNodeRef YGNodeClone(YGNodeRef oldNodeRef) {
|
YOGA_EXPORT YGNodeRef YGNodeClone(YGNodeRef oldNodeRef) {
|
||||||
auto oldNode = static_cast<yoga::Node*>(oldNodeRef);
|
auto oldNode = resolveRef(oldNodeRef);
|
||||||
auto node = new yoga::Node(*oldNode);
|
const auto node = new yoga::Node(*oldNode);
|
||||||
yoga::assertFatalWithConfig(
|
yoga::assertFatalWithConfig(
|
||||||
oldNode->getConfig(),
|
oldNode->getConfig(),
|
||||||
node != nullptr,
|
node != nullptr,
|
||||||
@@ -213,7 +215,7 @@ YOGA_EXPORT YGNodeRef YGNodeClone(YGNodeRef oldNodeRef) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeFree(const YGNodeRef nodeRef) {
|
YOGA_EXPORT void YGNodeFree(const YGNodeRef nodeRef) {
|
||||||
auto node = static_cast<yoga::Node*>(nodeRef);
|
const auto node = resolveRef(nodeRef);
|
||||||
|
|
||||||
if (auto owner = node->getOwner()) {
|
if (auto owner = node->getOwner()) {
|
||||||
owner->removeChild(node);
|
owner->removeChild(node);
|
||||||
@@ -232,13 +234,13 @@ YOGA_EXPORT void YGNodeFree(const YGNodeRef nodeRef) {
|
|||||||
|
|
||||||
YOGA_EXPORT void YGNodeDeallocate(const YGNodeRef node) {
|
YOGA_EXPORT void YGNodeDeallocate(const YGNodeRef node) {
|
||||||
Event::publish<Event::NodeDeallocation>(node, {YGNodeGetConfig(node)});
|
Event::publish<Event::NodeDeallocation>(node, {YGNodeGetConfig(node)});
|
||||||
delete static_cast<yoga::Node*>(node);
|
delete resolveRef(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeFreeRecursiveWithCleanupFunc(
|
YOGA_EXPORT void YGNodeFreeRecursiveWithCleanupFunc(
|
||||||
const YGNodeRef rootRef,
|
const YGNodeRef rootRef,
|
||||||
YGNodeCleanupFunc cleanup) {
|
YGNodeCleanupFunc cleanup) {
|
||||||
const auto root = static_cast<yoga::Node*>(rootRef);
|
const auto root = resolveRef(rootRef);
|
||||||
|
|
||||||
uint32_t skipped = 0;
|
uint32_t skipped = 0;
|
||||||
while (YGNodeGetChildCount(root) > skipped) {
|
while (YGNodeGetChildCount(root) > skipped) {
|
||||||
@@ -262,7 +264,7 @@ YOGA_EXPORT void YGNodeFreeRecursive(const YGNodeRef root) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeReset(YGNodeRef node) {
|
YOGA_EXPORT void YGNodeReset(YGNodeRef node) {
|
||||||
static_cast<yoga::Node*>(node)->reset();
|
resolveRef(node)->reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT int32_t YGConfigGetInstanceCount(void) {
|
YOGA_EXPORT int32_t YGConfigGetInstanceCount(void) {
|
||||||
@@ -280,30 +282,30 @@ YOGA_EXPORT YGConfigRef YGConfigNew(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGConfigFree(const YGConfigRef config) {
|
YOGA_EXPORT void YGConfigFree(const YGConfigRef config) {
|
||||||
delete static_cast<yoga::Config*>(config);
|
delete resolveRef(config);
|
||||||
gConfigInstanceCount--;
|
gConfigInstanceCount--;
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeSetIsReferenceBaseline(
|
YOGA_EXPORT void YGNodeSetIsReferenceBaseline(
|
||||||
YGNodeRef nodeRef,
|
YGNodeRef nodeRef,
|
||||||
bool isReferenceBaseline) {
|
bool isReferenceBaseline) {
|
||||||
auto node = static_cast<yoga::Node*>(nodeRef);
|
const auto node = resolveRef(nodeRef);
|
||||||
if (node->isReferenceBaseline() != isReferenceBaseline) {
|
if (node->isReferenceBaseline() != isReferenceBaseline) {
|
||||||
node->setIsReferenceBaseline(isReferenceBaseline);
|
node->setIsReferenceBaseline(isReferenceBaseline);
|
||||||
node->markDirtyAndPropagate();
|
node->markDirtyAndPropagate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT bool YGNodeIsReferenceBaseline(YGNodeRef node) {
|
YOGA_EXPORT bool YGNodeIsReferenceBaseline(YGNodeConstRef node) {
|
||||||
return static_cast<yoga::Node*>(node)->isReferenceBaseline();
|
return resolveRef(node)->isReferenceBaseline();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeInsertChild(
|
YOGA_EXPORT void YGNodeInsertChild(
|
||||||
const YGNodeRef ownerRef,
|
const YGNodeRef ownerRef,
|
||||||
const YGNodeRef childRef,
|
const YGNodeRef childRef,
|
||||||
const uint32_t index) {
|
const uint32_t index) {
|
||||||
auto owner = static_cast<yoga::Node*>(ownerRef);
|
auto owner = resolveRef(ownerRef);
|
||||||
auto child = static_cast<yoga::Node*>(childRef);
|
auto child = resolveRef(childRef);
|
||||||
|
|
||||||
yoga::assertFatalWithNode(
|
yoga::assertFatalWithNode(
|
||||||
owner,
|
owner,
|
||||||
@@ -324,8 +326,8 @@ YOGA_EXPORT void YGNodeSwapChild(
|
|||||||
const YGNodeRef ownerRef,
|
const YGNodeRef ownerRef,
|
||||||
const YGNodeRef childRef,
|
const YGNodeRef childRef,
|
||||||
const uint32_t index) {
|
const uint32_t index) {
|
||||||
auto owner = static_cast<yoga::Node*>(ownerRef);
|
auto owner = resolveRef(ownerRef);
|
||||||
auto child = static_cast<yoga::Node*>(childRef);
|
auto child = resolveRef(childRef);
|
||||||
|
|
||||||
owner->replaceChild(child, index);
|
owner->replaceChild(child, index);
|
||||||
child->setOwner(owner);
|
child->setOwner(owner);
|
||||||
@@ -334,8 +336,8 @@ YOGA_EXPORT void YGNodeSwapChild(
|
|||||||
YOGA_EXPORT void YGNodeRemoveChild(
|
YOGA_EXPORT void YGNodeRemoveChild(
|
||||||
const YGNodeRef ownerRef,
|
const YGNodeRef ownerRef,
|
||||||
const YGNodeRef excludedChildRef) {
|
const YGNodeRef excludedChildRef) {
|
||||||
auto owner = static_cast<yoga::Node*>(ownerRef);
|
auto owner = resolveRef(ownerRef);
|
||||||
auto excludedChild = static_cast<yoga::Node*>(excludedChildRef);
|
auto excludedChild = resolveRef(excludedChildRef);
|
||||||
|
|
||||||
if (YGNodeGetChildCount(owner) == 0) {
|
if (YGNodeGetChildCount(owner) == 0) {
|
||||||
// This is an empty set. Nothing to remove.
|
// This is an empty set. Nothing to remove.
|
||||||
@@ -356,7 +358,7 @@ YOGA_EXPORT void YGNodeRemoveChild(
|
|||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeRemoveAllChildren(const YGNodeRef ownerRef) {
|
YOGA_EXPORT void YGNodeRemoveAllChildren(const YGNodeRef ownerRef) {
|
||||||
auto owner = static_cast<yoga::Node*>(ownerRef);
|
auto owner = resolveRef(ownerRef);
|
||||||
|
|
||||||
const uint32_t childCount = YGNodeGetChildCount(owner);
|
const uint32_t childCount = YGNodeGetChildCount(owner);
|
||||||
if (childCount == 0) {
|
if (childCount == 0) {
|
||||||
@@ -386,7 +388,7 @@ YOGA_EXPORT void YGNodeSetChildren(
|
|||||||
const YGNodeRef ownerRef,
|
const YGNodeRef ownerRef,
|
||||||
const YGNodeRef* childrenRefs,
|
const YGNodeRef* childrenRefs,
|
||||||
const uint32_t count) {
|
const uint32_t count) {
|
||||||
auto owner = static_cast<yoga::Node*>(ownerRef);
|
auto owner = resolveRef(ownerRef);
|
||||||
auto children = reinterpret_cast<yoga::Node* const*>(childrenRefs);
|
auto children = reinterpret_cast<yoga::Node* const*>(childrenRefs);
|
||||||
|
|
||||||
if (!owner) {
|
if (!owner) {
|
||||||
@@ -425,7 +427,7 @@ YOGA_EXPORT void YGNodeSetChildren(
|
|||||||
|
|
||||||
YOGA_EXPORT YGNodeRef
|
YOGA_EXPORT YGNodeRef
|
||||||
YGNodeGetChild(const YGNodeRef nodeRef, const uint32_t index) {
|
YGNodeGetChild(const YGNodeRef nodeRef, const uint32_t index) {
|
||||||
auto node = static_cast<yoga::Node*>(nodeRef);
|
const auto node = resolveRef(nodeRef);
|
||||||
|
|
||||||
if (index < node->getChildren().size()) {
|
if (index < node->getChildren().size()) {
|
||||||
return node->getChild(index);
|
return node->getChild(index);
|
||||||
@@ -434,20 +436,19 @@ YGNodeGetChild(const YGNodeRef nodeRef, const uint32_t index) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT uint32_t YGNodeGetChildCount(const YGNodeConstRef node) {
|
YOGA_EXPORT uint32_t YGNodeGetChildCount(const YGNodeConstRef node) {
|
||||||
return static_cast<uint32_t>(
|
return static_cast<uint32_t>(resolveRef(node)->getChildren().size());
|
||||||
static_cast<const yoga::Node*>(node)->getChildren().size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT YGNodeRef YGNodeGetOwner(const YGNodeRef node) {
|
YOGA_EXPORT YGNodeRef YGNodeGetOwner(const YGNodeRef node) {
|
||||||
return static_cast<yoga::Node*>(node)->getOwner();
|
return resolveRef(node)->getOwner();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT YGNodeRef YGNodeGetParent(const YGNodeRef node) {
|
YOGA_EXPORT YGNodeRef YGNodeGetParent(const YGNodeRef node) {
|
||||||
return static_cast<yoga::Node*>(node)->getOwner();
|
return resolveRef(node)->getOwner();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeMarkDirty(const YGNodeRef nodeRef) {
|
YOGA_EXPORT void YGNodeMarkDirty(const YGNodeRef nodeRef) {
|
||||||
auto node = static_cast<yoga::Node*>(nodeRef);
|
const auto node = resolveRef(nodeRef);
|
||||||
|
|
||||||
yoga::assertFatalWithNode(
|
yoga::assertFatalWithNode(
|
||||||
node,
|
node,
|
||||||
@@ -460,9 +461,9 @@ YOGA_EXPORT void YGNodeMarkDirty(const YGNodeRef nodeRef) {
|
|||||||
|
|
||||||
YOGA_EXPORT void YGNodeCopyStyle(
|
YOGA_EXPORT void YGNodeCopyStyle(
|
||||||
const YGNodeRef dstNodeRef,
|
const YGNodeRef dstNodeRef,
|
||||||
const YGNodeRef srcNodeRef) {
|
const YGNodeConstRef srcNodeRef) {
|
||||||
auto dstNode = static_cast<yoga::Node*>(dstNodeRef);
|
auto dstNode = resolveRef(dstNodeRef);
|
||||||
auto srcNode = static_cast<yoga::Node*>(srcNodeRef);
|
auto srcNode = resolveRef(srcNodeRef);
|
||||||
|
|
||||||
if (!(dstNode->getStyle() == srcNode->getStyle())) {
|
if (!(dstNode->getStyle() == srcNode->getStyle())) {
|
||||||
dstNode->setStyle(srcNode->getStyle());
|
dstNode->setStyle(srcNode->getStyle());
|
||||||
@@ -471,14 +472,14 @@ YOGA_EXPORT void YGNodeCopyStyle(
|
|||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT float YGNodeStyleGetFlexGrow(const YGNodeConstRef nodeRef) {
|
YOGA_EXPORT float YGNodeStyleGetFlexGrow(const YGNodeConstRef nodeRef) {
|
||||||
auto node = static_cast<const yoga::Node*>(nodeRef);
|
const auto node = resolveRef(nodeRef);
|
||||||
return node->getStyle().flexGrow().isUndefined()
|
return node->getStyle().flexGrow().isUndefined()
|
||||||
? Style::DefaultFlexGrow
|
? Style::DefaultFlexGrow
|
||||||
: node->getStyle().flexGrow().unwrap();
|
: node->getStyle().flexGrow().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT float YGNodeStyleGetFlexShrink(const YGNodeConstRef nodeRef) {
|
YOGA_EXPORT float YGNodeStyleGetFlexShrink(const YGNodeConstRef nodeRef) {
|
||||||
auto node = static_cast<const yoga::Node*>(nodeRef);
|
const auto node = resolveRef(nodeRef);
|
||||||
return node->getStyle().flexShrink().isUndefined()
|
return node->getStyle().flexShrink().isUndefined()
|
||||||
? (node->getConfig()->useWebDefaults() ? Style::WebDefaultFlexShrink
|
? (node->getConfig()->useWebDefaults() ? Style::WebDefaultFlexShrink
|
||||||
: Style::DefaultFlexShrink)
|
: Style::DefaultFlexShrink)
|
||||||
@@ -502,7 +503,7 @@ void updateStyle(
|
|||||||
template <typename Ref, typename T>
|
template <typename Ref, typename T>
|
||||||
void updateStyle(YGNodeRef node, Ref (Style::*prop)(), T value) {
|
void updateStyle(YGNodeRef node, Ref (Style::*prop)(), T value) {
|
||||||
updateStyle(
|
updateStyle(
|
||||||
static_cast<yoga::Node*>(node),
|
resolveRef(node),
|
||||||
value,
|
value,
|
||||||
[prop](Style& s, T x) { return (s.*prop)() != x; },
|
[prop](Style& s, T x) { return (s.*prop)() != x; },
|
||||||
[prop](Style& s, T x) { (s.*prop)() = x; });
|
[prop](Style& s, T x) { (s.*prop)() = x; });
|
||||||
@@ -515,7 +516,7 @@ void updateIndexedStyleProp(
|
|||||||
Idx idx,
|
Idx idx,
|
||||||
CompactValue value) {
|
CompactValue value) {
|
||||||
updateStyle(
|
updateStyle(
|
||||||
static_cast<yoga::Node*>(node),
|
resolveRef(node),
|
||||||
value,
|
value,
|
||||||
[idx, prop](Style& s, CompactValue x) { return (s.*prop)()[idx] != x; },
|
[idx, prop](Style& s, CompactValue x) { return (s.*prop)()[idx] != x; },
|
||||||
[idx, prop](Style& s, CompactValue x) { (s.*prop)()[idx] = x; });
|
[idx, prop](Style& s, CompactValue x) { (s.*prop)()[idx] = x; });
|
||||||
@@ -536,7 +537,7 @@ YOGA_EXPORT void YGNodeStyleSetDirection(
|
|||||||
updateStyle<MSVC_HINT(direction)>(node, &Style::direction, value);
|
updateStyle<MSVC_HINT(direction)>(node, &Style::direction, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGDirection YGNodeStyleGetDirection(const YGNodeConstRef node) {
|
YOGA_EXPORT YGDirection YGNodeStyleGetDirection(const YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)->getStyle().direction();
|
return resolveRef(node)->getStyle().direction();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetFlexDirection(
|
YOGA_EXPORT void YGNodeStyleSetFlexDirection(
|
||||||
@@ -547,7 +548,7 @@ YOGA_EXPORT void YGNodeStyleSetFlexDirection(
|
|||||||
}
|
}
|
||||||
YOGA_EXPORT YGFlexDirection
|
YOGA_EXPORT YGFlexDirection
|
||||||
YGNodeStyleGetFlexDirection(const YGNodeConstRef node) {
|
YGNodeStyleGetFlexDirection(const YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)->getStyle().flexDirection();
|
return resolveRef(node)->getStyle().flexDirection();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetJustifyContent(
|
YOGA_EXPORT void YGNodeStyleSetJustifyContent(
|
||||||
@@ -557,7 +558,7 @@ YOGA_EXPORT void YGNodeStyleSetJustifyContent(
|
|||||||
node, &Style::justifyContent, justifyContent);
|
node, &Style::justifyContent, justifyContent);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGJustify YGNodeStyleGetJustifyContent(const YGNodeConstRef node) {
|
YOGA_EXPORT YGJustify YGNodeStyleGetJustifyContent(const YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)->getStyle().justifyContent();
|
return resolveRef(node)->getStyle().justifyContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetAlignContent(
|
YOGA_EXPORT void YGNodeStyleSetAlignContent(
|
||||||
@@ -567,7 +568,7 @@ YOGA_EXPORT void YGNodeStyleSetAlignContent(
|
|||||||
node, &Style::alignContent, alignContent);
|
node, &Style::alignContent, alignContent);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGAlign YGNodeStyleGetAlignContent(const YGNodeConstRef node) {
|
YOGA_EXPORT YGAlign YGNodeStyleGetAlignContent(const YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)->getStyle().alignContent();
|
return resolveRef(node)->getStyle().alignContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetAlignItems(
|
YOGA_EXPORT void YGNodeStyleSetAlignItems(
|
||||||
@@ -576,7 +577,7 @@ YOGA_EXPORT void YGNodeStyleSetAlignItems(
|
|||||||
updateStyle<MSVC_HINT(alignItems)>(node, &Style::alignItems, alignItems);
|
updateStyle<MSVC_HINT(alignItems)>(node, &Style::alignItems, alignItems);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGAlign YGNodeStyleGetAlignItems(const YGNodeConstRef node) {
|
YOGA_EXPORT YGAlign YGNodeStyleGetAlignItems(const YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)->getStyle().alignItems();
|
return resolveRef(node)->getStyle().alignItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetAlignSelf(
|
YOGA_EXPORT void YGNodeStyleSetAlignSelf(
|
||||||
@@ -585,7 +586,7 @@ YOGA_EXPORT void YGNodeStyleSetAlignSelf(
|
|||||||
updateStyle<MSVC_HINT(alignSelf)>(node, &Style::alignSelf, alignSelf);
|
updateStyle<MSVC_HINT(alignSelf)>(node, &Style::alignSelf, alignSelf);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGAlign YGNodeStyleGetAlignSelf(const YGNodeConstRef node) {
|
YOGA_EXPORT YGAlign YGNodeStyleGetAlignSelf(const YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)->getStyle().alignSelf();
|
return resolveRef(node)->getStyle().alignSelf();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetPositionType(
|
YOGA_EXPORT void YGNodeStyleSetPositionType(
|
||||||
@@ -596,7 +597,7 @@ YOGA_EXPORT void YGNodeStyleSetPositionType(
|
|||||||
}
|
}
|
||||||
YOGA_EXPORT YGPositionType
|
YOGA_EXPORT YGPositionType
|
||||||
YGNodeStyleGetPositionType(const YGNodeConstRef node) {
|
YGNodeStyleGetPositionType(const YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)->getStyle().positionType();
|
return resolveRef(node)->getStyle().positionType();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetFlexWrap(
|
YOGA_EXPORT void YGNodeStyleSetFlexWrap(
|
||||||
@@ -605,7 +606,7 @@ YOGA_EXPORT void YGNodeStyleSetFlexWrap(
|
|||||||
updateStyle<MSVC_HINT(flexWrap)>(node, &Style::flexWrap, flexWrap);
|
updateStyle<MSVC_HINT(flexWrap)>(node, &Style::flexWrap, flexWrap);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGWrap YGNodeStyleGetFlexWrap(const YGNodeConstRef node) {
|
YOGA_EXPORT YGWrap YGNodeStyleGetFlexWrap(const YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)->getStyle().flexWrap();
|
return resolveRef(node)->getStyle().flexWrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetOverflow(
|
YOGA_EXPORT void YGNodeStyleSetOverflow(
|
||||||
@@ -614,7 +615,7 @@ YOGA_EXPORT void YGNodeStyleSetOverflow(
|
|||||||
updateStyle<MSVC_HINT(overflow)>(node, &Style::overflow, overflow);
|
updateStyle<MSVC_HINT(overflow)>(node, &Style::overflow, overflow);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGOverflow YGNodeStyleGetOverflow(const YGNodeConstRef node) {
|
YOGA_EXPORT YGOverflow YGNodeStyleGetOverflow(const YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)->getStyle().overflow();
|
return resolveRef(node)->getStyle().overflow();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetDisplay(
|
YOGA_EXPORT void YGNodeStyleSetDisplay(
|
||||||
@@ -623,7 +624,7 @@ YOGA_EXPORT void YGNodeStyleSetDisplay(
|
|||||||
updateStyle<MSVC_HINT(display)>(node, &Style::display, display);
|
updateStyle<MSVC_HINT(display)>(node, &Style::display, display);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGDisplay YGNodeStyleGetDisplay(const YGNodeConstRef node) {
|
YOGA_EXPORT YGDisplay YGNodeStyleGetDisplay(const YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)->getStyle().display();
|
return resolveRef(node)->getStyle().display();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(T26792433): Change the API to accept FloatOptional.
|
// TODO(T26792433): Change the API to accept FloatOptional.
|
||||||
@@ -633,7 +634,7 @@ YOGA_EXPORT void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {
|
|||||||
|
|
||||||
// TODO(T26792433): Change the API to accept FloatOptional.
|
// TODO(T26792433): Change the API to accept FloatOptional.
|
||||||
YOGA_EXPORT float YGNodeStyleGetFlex(const YGNodeConstRef nodeRef) {
|
YOGA_EXPORT float YGNodeStyleGetFlex(const YGNodeConstRef nodeRef) {
|
||||||
auto node = static_cast<const yoga::Node*>(nodeRef);
|
const auto node = resolveRef(nodeRef);
|
||||||
return node->getStyle().flex().isUndefined()
|
return node->getStyle().flex().isUndefined()
|
||||||
? YGUndefined
|
? YGUndefined
|
||||||
: node->getStyle().flex().unwrap();
|
: node->getStyle().flex().unwrap();
|
||||||
@@ -656,8 +657,7 @@ YOGA_EXPORT void YGNodeStyleSetFlexShrink(
|
|||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) {
|
YOGA_EXPORT YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) {
|
||||||
YGValue flexBasis =
|
YGValue flexBasis = resolveRef(node)->getStyle().flexBasis();
|
||||||
static_cast<const yoga::Node*>(node)->getStyle().flexBasis();
|
|
||||||
if (flexBasis.unit == YGUnitUndefined || flexBasis.unit == YGUnitAuto) {
|
if (flexBasis.unit == YGUnitUndefined || flexBasis.unit == YGUnitAuto) {
|
||||||
// TODO(T26792433): Get rid off the use of YGUndefined at client side
|
// TODO(T26792433): Get rid off the use of YGUndefined at client side
|
||||||
flexBasis.value = YGUndefined;
|
flexBasis.value = YGUndefined;
|
||||||
@@ -701,7 +701,7 @@ YOGA_EXPORT void YGNodeStyleSetPositionPercent(
|
|||||||
node, &Style::position, edge, value);
|
node, &Style::position, edge, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) {
|
YOGA_EXPORT YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) {
|
||||||
return static_cast<const yoga::Node*>(node)->getStyle().position()[edge];
|
return resolveRef(node)->getStyle().position()[edge];
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetMargin(
|
YOGA_EXPORT void YGNodeStyleSetMargin(
|
||||||
@@ -723,7 +723,7 @@ YOGA_EXPORT void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge) {
|
|||||||
node, &Style::margin, edge, CompactValue::ofAuto());
|
node, &Style::margin, edge, CompactValue::ofAuto());
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) {
|
YOGA_EXPORT YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) {
|
||||||
return static_cast<const yoga::Node*>(node)->getStyle().margin()[edge];
|
return resolveRef(node)->getStyle().margin()[edge];
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetPadding(
|
YOGA_EXPORT void YGNodeStyleSetPadding(
|
||||||
@@ -743,7 +743,7 @@ YOGA_EXPORT void YGNodeStyleSetPaddingPercent(
|
|||||||
node, &Style::padding, edge, value);
|
node, &Style::padding, edge, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge) {
|
YOGA_EXPORT YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge) {
|
||||||
return static_cast<const yoga::Node*>(node)->getStyle().padding()[edge];
|
return resolveRef(node)->getStyle().padding()[edge];
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(T26792433): Change the API to accept FloatOptional.
|
// TODO(T26792433): Change the API to accept FloatOptional.
|
||||||
@@ -758,7 +758,7 @@ YOGA_EXPORT void YGNodeStyleSetBorder(
|
|||||||
YOGA_EXPORT float YGNodeStyleGetBorder(
|
YOGA_EXPORT float YGNodeStyleGetBorder(
|
||||||
const YGNodeConstRef node,
|
const YGNodeConstRef node,
|
||||||
const YGEdge edge) {
|
const YGEdge edge) {
|
||||||
auto border = static_cast<const yoga::Node*>(node)->getStyle().border()[edge];
|
auto border = resolveRef(node)->getStyle().border()[edge];
|
||||||
if (border.isUndefined() || border.isAuto()) {
|
if (border.isUndefined() || border.isAuto()) {
|
||||||
// TODO(T26792433): Rather than returning YGUndefined, change the api to
|
// TODO(T26792433): Rather than returning YGUndefined, change the api to
|
||||||
// return FloatOptional.
|
// return FloatOptional.
|
||||||
@@ -779,8 +779,7 @@ YOGA_EXPORT void YGNodeStyleSetGap(
|
|||||||
YOGA_EXPORT float YGNodeStyleGetGap(
|
YOGA_EXPORT float YGNodeStyleGetGap(
|
||||||
const YGNodeConstRef node,
|
const YGNodeConstRef node,
|
||||||
const YGGutter gutter) {
|
const YGGutter gutter) {
|
||||||
auto gapLength =
|
auto gapLength = resolveRef(node)->getStyle().gap()[gutter];
|
||||||
static_cast<const yoga::Node*>(node)->getStyle().gap()[gutter];
|
|
||||||
if (gapLength.isUndefined() || gapLength.isAuto()) {
|
if (gapLength.isUndefined() || gapLength.isAuto()) {
|
||||||
// TODO(T26792433): Rather than returning YGUndefined, change the api to
|
// TODO(T26792433): Rather than returning YGUndefined, change the api to
|
||||||
// return FloatOptional.
|
// return FloatOptional.
|
||||||
@@ -794,8 +793,7 @@ YOGA_EXPORT float YGNodeStyleGetGap(
|
|||||||
|
|
||||||
// TODO(T26792433): Change the API to accept FloatOptional.
|
// TODO(T26792433): Change the API to accept FloatOptional.
|
||||||
YOGA_EXPORT float YGNodeStyleGetAspectRatio(const YGNodeConstRef node) {
|
YOGA_EXPORT float YGNodeStyleGetAspectRatio(const YGNodeConstRef node) {
|
||||||
const FloatOptional op =
|
const FloatOptional op = resolveRef(node)->getStyle().aspectRatio();
|
||||||
static_cast<const yoga::Node*>(node)->getStyle().aspectRatio();
|
|
||||||
return op.isUndefined() ? YGUndefined : op.unwrap();
|
return op.isUndefined() ? YGUndefined : op.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -822,9 +820,7 @@ YOGA_EXPORT void YGNodeStyleSetWidthAuto(YGNodeRef node) {
|
|||||||
node, &Style::dimensions, YGDimensionWidth, CompactValue::ofAuto());
|
node, &Style::dimensions, YGDimensionWidth, CompactValue::ofAuto());
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetWidth(YGNodeConstRef node) {
|
YOGA_EXPORT YGValue YGNodeStyleGetWidth(YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)
|
return resolveRef(node)->getStyle().dimensions()[YGDimensionWidth];
|
||||||
->getStyle()
|
|
||||||
.dimensions()[YGDimensionWidth];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetHeight(YGNodeRef node, float points) {
|
YOGA_EXPORT void YGNodeStyleSetHeight(YGNodeRef node, float points) {
|
||||||
@@ -842,9 +838,7 @@ YOGA_EXPORT void YGNodeStyleSetHeightAuto(YGNodeRef node) {
|
|||||||
node, &Style::dimensions, YGDimensionHeight, CompactValue::ofAuto());
|
node, &Style::dimensions, YGDimensionHeight, CompactValue::ofAuto());
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetHeight(YGNodeConstRef node) {
|
YOGA_EXPORT YGValue YGNodeStyleGetHeight(YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)
|
return resolveRef(node)->getStyle().dimensions()[YGDimensionHeight];
|
||||||
->getStyle()
|
|
||||||
.dimensions()[YGDimensionHeight];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetMinWidth(
|
YOGA_EXPORT void YGNodeStyleSetMinWidth(
|
||||||
@@ -862,9 +856,7 @@ YOGA_EXPORT void YGNodeStyleSetMinWidthPercent(
|
|||||||
node, &Style::minDimensions, YGDimensionWidth, value);
|
node, &Style::minDimensions, YGDimensionWidth, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) {
|
YOGA_EXPORT YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)
|
return resolveRef(node)->getStyle().minDimensions()[YGDimensionWidth];
|
||||||
->getStyle()
|
|
||||||
.minDimensions()[YGDimensionWidth];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetMinHeight(
|
YOGA_EXPORT void YGNodeStyleSetMinHeight(
|
||||||
@@ -882,9 +874,7 @@ YOGA_EXPORT void YGNodeStyleSetMinHeightPercent(
|
|||||||
node, &Style::minDimensions, YGDimensionHeight, value);
|
node, &Style::minDimensions, YGDimensionHeight, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) {
|
YOGA_EXPORT YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)
|
return resolveRef(node)->getStyle().minDimensions()[YGDimensionHeight];
|
||||||
->getStyle()
|
|
||||||
.minDimensions()[YGDimensionHeight];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetMaxWidth(
|
YOGA_EXPORT void YGNodeStyleSetMaxWidth(
|
||||||
@@ -902,9 +892,7 @@ YOGA_EXPORT void YGNodeStyleSetMaxWidthPercent(
|
|||||||
node, &Style::maxDimensions, YGDimensionWidth, value);
|
node, &Style::maxDimensions, YGDimensionWidth, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) {
|
YOGA_EXPORT YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)
|
return resolveRef(node)->getStyle().maxDimensions()[YGDimensionWidth];
|
||||||
->getStyle()
|
|
||||||
.maxDimensions()[YGDimensionWidth];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetMaxHeight(
|
YOGA_EXPORT void YGNodeStyleSetMaxHeight(
|
||||||
@@ -922,20 +910,18 @@ YOGA_EXPORT void YGNodeStyleSetMaxHeightPercent(
|
|||||||
node, &Style::maxDimensions, YGDimensionHeight, value);
|
node, &Style::maxDimensions, YGDimensionHeight, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) {
|
YOGA_EXPORT YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)
|
return resolveRef(node)->getStyle().maxDimensions()[YGDimensionHeight];
|
||||||
->getStyle()
|
|
||||||
.maxDimensions()[YGDimensionHeight];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define YG_NODE_LAYOUT_PROPERTY_IMPL(type, name, instanceName) \
|
#define YG_NODE_LAYOUT_PROPERTY_IMPL(type, name, instanceName) \
|
||||||
YOGA_EXPORT type YGNodeLayoutGet##name(const YGNodeRef node) { \
|
YOGA_EXPORT type YGNodeLayoutGet##name(const YGNodeConstRef node) { \
|
||||||
return static_cast<yoga::Node*>(node)->getLayout().instanceName; \
|
return resolveRef(node)->getLayout().instanceName; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(type, name, instanceName) \
|
#define YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(type, name, instanceName) \
|
||||||
YOGA_EXPORT type YGNodeLayoutGet##name( \
|
YOGA_EXPORT type YGNodeLayoutGet##name( \
|
||||||
const YGNodeRef nodeRef, const YGEdge edge) { \
|
const YGNodeConstRef nodeRef, const YGEdge edge) { \
|
||||||
auto node = static_cast<yoga::Node*>(nodeRef); \
|
const auto node = resolveRef(nodeRef); \
|
||||||
yoga::assertFatalWithNode( \
|
yoga::assertFatalWithNode( \
|
||||||
node, \
|
node, \
|
||||||
edge <= YGEdgeEnd, \
|
edge <= YGEdgeEnd, \
|
||||||
@@ -975,9 +961,9 @@ YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Padding, padding)
|
|||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
YOGA_EXPORT void YGNodePrint(
|
YOGA_EXPORT void YGNodePrint(
|
||||||
const YGNodeRef nodeRef,
|
const YGNodeConstRef nodeRef,
|
||||||
const YGPrintOptions options) {
|
const YGPrintOptions options) {
|
||||||
const auto node = static_cast<yoga::Node*>(nodeRef);
|
const auto node = resolveRef(nodeRef);
|
||||||
std::string str;
|
std::string str;
|
||||||
yoga::nodeToString(str, node, options, 0);
|
yoga::nodeToString(str, node, options, 0);
|
||||||
yoga::log(node, YGLogLevelDebug, nullptr, str.c_str());
|
yoga::log(node, YGLogLevelDebug, nullptr, str.c_str());
|
||||||
@@ -986,12 +972,12 @@ YOGA_EXPORT void YGNodePrint(
|
|||||||
|
|
||||||
YOGA_EXPORT void YGConfigSetLogger(const YGConfigRef config, YGLogger logger) {
|
YOGA_EXPORT void YGConfigSetLogger(const YGConfigRef config, YGLogger logger) {
|
||||||
if (logger != nullptr) {
|
if (logger != nullptr) {
|
||||||
static_cast<yoga::Config*>(config)->setLogger(logger);
|
resolveRef(config)->setLogger(logger);
|
||||||
} else {
|
} else {
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
static_cast<yoga::Config*>(config)->setLogger(&YGAndroidLog);
|
resolveRef(config)->setLogger(&YGAndroidLog);
|
||||||
#else
|
#else
|
||||||
static_cast<yoga::Config*>(config)->setLogger(&YGDefaultLog);
|
resolveRef(config)->setLogger(&YGDefaultLog);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1000,21 +986,21 @@ YOGA_EXPORT void YGConfigSetPointScaleFactor(
|
|||||||
const YGConfigRef config,
|
const YGConfigRef config,
|
||||||
const float pixelsInPoint) {
|
const float pixelsInPoint) {
|
||||||
yoga::assertFatalWithConfig(
|
yoga::assertFatalWithConfig(
|
||||||
config,
|
resolveRef(config),
|
||||||
pixelsInPoint >= 0.0f,
|
pixelsInPoint >= 0.0f,
|
||||||
"Scale factor should not be less than zero");
|
"Scale factor should not be less than zero");
|
||||||
|
|
||||||
// We store points for Pixel as we will use it for rounding
|
// We store points for Pixel as we will use it for rounding
|
||||||
if (pixelsInPoint == 0.0f) {
|
if (pixelsInPoint == 0.0f) {
|
||||||
// Zero is used to skip rounding
|
// Zero is used to skip rounding
|
||||||
static_cast<yoga::Config*>(config)->setPointScaleFactor(0.0f);
|
resolveRef(config)->setPointScaleFactor(0.0f);
|
||||||
} else {
|
} else {
|
||||||
static_cast<yoga::Config*>(config)->setPointScaleFactor(pixelsInPoint);
|
resolveRef(config)->setPointScaleFactor(pixelsInPoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT float YGConfigGetPointScaleFactor(const YGConfigRef config) {
|
YOGA_EXPORT float YGConfigGetPointScaleFactor(const YGConfigConstRef config) {
|
||||||
return static_cast<yoga::Config*>(config)->getPointScaleFactor();
|
return resolveRef(config)->getPointScaleFactor();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT float YGRoundValueToPixelGrid(
|
YOGA_EXPORT float YGRoundValueToPixelGrid(
|
||||||
@@ -1030,63 +1016,60 @@ YOGA_EXPORT void YGConfigSetExperimentalFeatureEnabled(
|
|||||||
const YGConfigRef config,
|
const YGConfigRef config,
|
||||||
const YGExperimentalFeature feature,
|
const YGExperimentalFeature feature,
|
||||||
const bool enabled) {
|
const bool enabled) {
|
||||||
static_cast<yoga::Config*>(config)->setExperimentalFeatureEnabled(
|
resolveRef(config)->setExperimentalFeatureEnabled(feature, enabled);
|
||||||
feature, enabled);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT bool YGConfigIsExperimentalFeatureEnabled(
|
YOGA_EXPORT bool YGConfigIsExperimentalFeatureEnabled(
|
||||||
const YGConfigRef config,
|
const YGConfigConstRef config,
|
||||||
const YGExperimentalFeature feature) {
|
const YGExperimentalFeature feature) {
|
||||||
return static_cast<yoga::Config*>(config)->isExperimentalFeatureEnabled(
|
return resolveRef(config)->isExperimentalFeatureEnabled(feature);
|
||||||
feature);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGConfigSetUseWebDefaults(
|
YOGA_EXPORT void YGConfigSetUseWebDefaults(
|
||||||
const YGConfigRef config,
|
const YGConfigRef config,
|
||||||
const bool enabled) {
|
const bool enabled) {
|
||||||
static_cast<yoga::Config*>(config)->setUseWebDefaults(enabled);
|
resolveRef(config)->setUseWebDefaults(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT bool YGConfigGetUseLegacyStretchBehaviour(
|
YOGA_EXPORT bool YGConfigGetUseLegacyStretchBehaviour(
|
||||||
const YGConfigRef config) {
|
const YGConfigConstRef config) {
|
||||||
return static_cast<yoga::Config*>(config)->hasErrata(
|
return resolveRef(config)->hasErrata(YGErrataStretchFlexBasis);
|
||||||
YGErrataStretchFlexBasis);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGConfigSetUseLegacyStretchBehaviour(
|
YOGA_EXPORT void YGConfigSetUseLegacyStretchBehaviour(
|
||||||
const YGConfigRef config,
|
const YGConfigRef config,
|
||||||
const bool useLegacyStretchBehaviour) {
|
const bool useLegacyStretchBehaviour) {
|
||||||
if (useLegacyStretchBehaviour) {
|
if (useLegacyStretchBehaviour) {
|
||||||
static_cast<yoga::Config*>(config)->addErrata(YGErrataStretchFlexBasis);
|
resolveRef(config)->addErrata(YGErrataStretchFlexBasis);
|
||||||
} else {
|
} else {
|
||||||
static_cast<yoga::Config*>(config)->removeErrata(YGErrataStretchFlexBasis);
|
resolveRef(config)->removeErrata(YGErrataStretchFlexBasis);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool YGConfigGetUseWebDefaults(const YGConfigRef config) {
|
bool YGConfigGetUseWebDefaults(const YGConfigConstRef config) {
|
||||||
return static_cast<yoga::Config*>(config)->useWebDefaults();
|
return resolveRef(config)->useWebDefaults();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGConfigSetContext(const YGConfigRef config, void* context) {
|
YOGA_EXPORT void YGConfigSetContext(const YGConfigRef config, void* context) {
|
||||||
static_cast<yoga::Config*>(config)->setContext(context);
|
resolveRef(config)->setContext(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void* YGConfigGetContext(const YGConfigRef config) {
|
YOGA_EXPORT void* YGConfigGetContext(const YGConfigConstRef config) {
|
||||||
return static_cast<yoga::Config*>(config)->getContext();
|
return resolveRef(config)->getContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGConfigSetErrata(YGConfigRef config, YGErrata errata) {
|
YOGA_EXPORT void YGConfigSetErrata(YGConfigRef config, YGErrata errata) {
|
||||||
static_cast<yoga::Config*>(config)->setErrata(errata);
|
resolveRef(config)->setErrata(errata);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT YGErrata YGConfigGetErrata(YGConfigRef config) {
|
YOGA_EXPORT YGErrata YGConfigGetErrata(YGConfigConstRef config) {
|
||||||
return static_cast<yoga::Config*>(config)->getErrata();
|
return resolveRef(config)->getErrata();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGConfigSetCloneNodeFunc(
|
YOGA_EXPORT void YGConfigSetCloneNodeFunc(
|
||||||
const YGConfigRef config,
|
const YGConfigRef config,
|
||||||
const YGCloneNodeFunc callback) {
|
const YGCloneNodeFunc callback) {
|
||||||
static_cast<yoga::Config*>(config)->setCloneNodeCallback(callback);
|
resolveRef(config)->setCloneNodeCallback(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This should not be part of the public API. Remove after removing
|
// TODO: This should not be part of the public API. Remove after removing
|
||||||
@@ -1118,7 +1101,7 @@ YOGA_EXPORT bool YGNodeCanUseCachedMeasurement(
|
|||||||
lastComputedHeight,
|
lastComputedHeight,
|
||||||
marginRow,
|
marginRow,
|
||||||
marginColumn,
|
marginColumn,
|
||||||
static_cast<yoga::Config*>(config));
|
resolveRef(config));
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeCalculateLayout(
|
YOGA_EXPORT void YGNodeCalculateLayout(
|
||||||
@@ -1131,15 +1114,11 @@ YOGA_EXPORT void YGNodeCalculateLayout(
|
|||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeCalculateLayoutWithContext(
|
YOGA_EXPORT void YGNodeCalculateLayoutWithContext(
|
||||||
const YGNodeRef nodeRef,
|
const YGNodeRef node,
|
||||||
const float ownerWidth,
|
const float ownerWidth,
|
||||||
const float ownerHeight,
|
const float ownerHeight,
|
||||||
const YGDirection ownerDirection,
|
const YGDirection ownerDirection,
|
||||||
void* layoutContext) {
|
void* layoutContext) {
|
||||||
yoga::calculateLayout(
|
yoga::calculateLayout(
|
||||||
static_cast<Node*>(nodeRef),
|
resolveRef(node), ownerWidth, ownerHeight, ownerDirection, layoutContext);
|
||||||
ownerWidth,
|
|
||||||
ownerHeight,
|
|
||||||
ownerDirection,
|
|
||||||
layoutContext);
|
|
||||||
}
|
}
|
||||||
|
56
yoga/Yoga.h
56
yoga/Yoga.h
@@ -23,6 +23,7 @@ typedef struct YGSize {
|
|||||||
} YGSize;
|
} YGSize;
|
||||||
|
|
||||||
typedef struct YGConfig* YGConfigRef;
|
typedef struct YGConfig* YGConfigRef;
|
||||||
|
typedef const struct YGConfig* YGConfigConstRef;
|
||||||
|
|
||||||
typedef struct YGNode* YGNodeRef;
|
typedef struct YGNode* YGNodeRef;
|
||||||
typedef const struct YGNode* YGNodeConstRef;
|
typedef const struct YGNode* YGNodeConstRef;
|
||||||
@@ -82,7 +83,7 @@ WIN_EXPORT void YGNodeSetIsReferenceBaseline(
|
|||||||
YGNodeRef node,
|
YGNodeRef node,
|
||||||
bool isReferenceBaseline);
|
bool isReferenceBaseline);
|
||||||
|
|
||||||
WIN_EXPORT bool YGNodeIsReferenceBaseline(YGNodeRef node);
|
WIN_EXPORT bool YGNodeIsReferenceBaseline(YGNodeConstRef node);
|
||||||
|
|
||||||
WIN_EXPORT void YGNodeCalculateLayout(
|
WIN_EXPORT void YGNodeCalculateLayout(
|
||||||
YGNodeRef node,
|
YGNodeRef node,
|
||||||
@@ -104,7 +105,7 @@ WIN_EXPORT void YGNodeMarkDirty(YGNodeRef node);
|
|||||||
// `YGCalculateLayout` will cause the recalculation of each and every node.
|
// `YGCalculateLayout` will cause the recalculation of each and every node.
|
||||||
WIN_EXPORT void YGNodeMarkDirtyAndPropagateToDescendants(YGNodeRef node);
|
WIN_EXPORT void YGNodeMarkDirtyAndPropagateToDescendants(YGNodeRef node);
|
||||||
|
|
||||||
WIN_EXPORT void YGNodePrint(YGNodeRef node, YGPrintOptions options);
|
WIN_EXPORT void YGNodePrint(YGNodeConstRef node, YGPrintOptions options);
|
||||||
|
|
||||||
WIN_EXPORT bool YGFloatIsUndefined(float value);
|
WIN_EXPORT bool YGFloatIsUndefined(float value);
|
||||||
|
|
||||||
@@ -125,27 +126,27 @@ WIN_EXPORT bool YGNodeCanUseCachedMeasurement(
|
|||||||
float marginColumn,
|
float marginColumn,
|
||||||
YGConfigRef config);
|
YGConfigRef config);
|
||||||
|
|
||||||
WIN_EXPORT void YGNodeCopyStyle(YGNodeRef dstNode, YGNodeRef srcNode);
|
WIN_EXPORT void YGNodeCopyStyle(YGNodeRef dstNode, YGNodeConstRef srcNode);
|
||||||
|
|
||||||
WIN_EXPORT void* YGNodeGetContext(YGNodeRef node);
|
WIN_EXPORT void* YGNodeGetContext(YGNodeConstRef node);
|
||||||
WIN_EXPORT void YGNodeSetContext(YGNodeRef node, void* context);
|
WIN_EXPORT void YGNodeSetContext(YGNodeRef node, void* context);
|
||||||
|
|
||||||
WIN_EXPORT YGConfigRef YGNodeGetConfig(YGNodeRef node);
|
WIN_EXPORT YGConfigRef YGNodeGetConfig(YGNodeRef node);
|
||||||
WIN_EXPORT void YGNodeSetConfig(YGNodeRef node, YGConfigRef config);
|
WIN_EXPORT void YGNodeSetConfig(YGNodeRef node, YGConfigRef config);
|
||||||
|
|
||||||
void YGConfigSetPrintTreeFlag(YGConfigRef config, bool enabled);
|
void YGConfigSetPrintTreeFlag(YGConfigRef config, bool enabled);
|
||||||
bool YGNodeHasMeasureFunc(YGNodeRef node);
|
bool YGNodeHasMeasureFunc(YGNodeConstRef node);
|
||||||
WIN_EXPORT void YGNodeSetMeasureFunc(YGNodeRef node, YGMeasureFunc measureFunc);
|
WIN_EXPORT void YGNodeSetMeasureFunc(YGNodeRef node, YGMeasureFunc measureFunc);
|
||||||
bool YGNodeHasBaselineFunc(YGNodeRef node);
|
bool YGNodeHasBaselineFunc(YGNodeConstRef node);
|
||||||
void YGNodeSetBaselineFunc(YGNodeRef node, YGBaselineFunc baselineFunc);
|
void YGNodeSetBaselineFunc(YGNodeRef node, YGBaselineFunc baselineFunc);
|
||||||
YGDirtiedFunc YGNodeGetDirtiedFunc(YGNodeRef node);
|
YGDirtiedFunc YGNodeGetDirtiedFunc(YGNodeConstRef node);
|
||||||
void YGNodeSetDirtiedFunc(YGNodeRef node, YGDirtiedFunc dirtiedFunc);
|
void YGNodeSetDirtiedFunc(YGNodeRef node, YGDirtiedFunc dirtiedFunc);
|
||||||
void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc);
|
void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc);
|
||||||
WIN_EXPORT bool YGNodeGetHasNewLayout(YGNodeRef node);
|
WIN_EXPORT bool YGNodeGetHasNewLayout(YGNodeConstRef node);
|
||||||
WIN_EXPORT void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout);
|
WIN_EXPORT void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout);
|
||||||
YGNodeType YGNodeGetNodeType(YGNodeRef node);
|
YGNodeType YGNodeGetNodeType(YGNodeConstRef node);
|
||||||
void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType);
|
void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType);
|
||||||
WIN_EXPORT bool YGNodeIsDirty(YGNodeRef node);
|
WIN_EXPORT bool YGNodeIsDirty(YGNodeConstRef node);
|
||||||
|
|
||||||
WIN_EXPORT void YGNodeStyleSetDirection(YGNodeRef node, YGDirection direction);
|
WIN_EXPORT void YGNodeStyleSetDirection(YGNodeRef node, YGDirection direction);
|
||||||
WIN_EXPORT YGDirection YGNodeStyleGetDirection(YGNodeConstRef node);
|
WIN_EXPORT YGDirection YGNodeStyleGetDirection(YGNodeConstRef node);
|
||||||
@@ -280,22 +281,22 @@ WIN_EXPORT YGValue YGNodeStyleGetMaxHeight(YGNodeConstRef node);
|
|||||||
WIN_EXPORT void YGNodeStyleSetAspectRatio(YGNodeRef node, float aspectRatio);
|
WIN_EXPORT void YGNodeStyleSetAspectRatio(YGNodeRef node, float aspectRatio);
|
||||||
WIN_EXPORT float YGNodeStyleGetAspectRatio(YGNodeConstRef node);
|
WIN_EXPORT float YGNodeStyleGetAspectRatio(YGNodeConstRef node);
|
||||||
|
|
||||||
WIN_EXPORT float YGNodeLayoutGetLeft(YGNodeRef node);
|
WIN_EXPORT float YGNodeLayoutGetLeft(YGNodeConstRef node);
|
||||||
WIN_EXPORT float YGNodeLayoutGetTop(YGNodeRef node);
|
WIN_EXPORT float YGNodeLayoutGetTop(YGNodeConstRef node);
|
||||||
WIN_EXPORT float YGNodeLayoutGetRight(YGNodeRef node);
|
WIN_EXPORT float YGNodeLayoutGetRight(YGNodeConstRef node);
|
||||||
WIN_EXPORT float YGNodeLayoutGetBottom(YGNodeRef node);
|
WIN_EXPORT float YGNodeLayoutGetBottom(YGNodeConstRef node);
|
||||||
WIN_EXPORT float YGNodeLayoutGetWidth(YGNodeRef node);
|
WIN_EXPORT float YGNodeLayoutGetWidth(YGNodeConstRef node);
|
||||||
WIN_EXPORT float YGNodeLayoutGetHeight(YGNodeRef node);
|
WIN_EXPORT float YGNodeLayoutGetHeight(YGNodeConstRef node);
|
||||||
WIN_EXPORT YGDirection YGNodeLayoutGetDirection(YGNodeRef node);
|
WIN_EXPORT YGDirection YGNodeLayoutGetDirection(YGNodeConstRef node);
|
||||||
WIN_EXPORT bool YGNodeLayoutGetHadOverflow(YGNodeRef node);
|
WIN_EXPORT bool YGNodeLayoutGetHadOverflow(YGNodeConstRef node);
|
||||||
|
|
||||||
// Get the computed values for these nodes after performing layout. If they were
|
// Get the computed values for these nodes after performing layout. If they were
|
||||||
// set using point values then the returned value will be the same as
|
// set using point values then the returned value will be the same as
|
||||||
// YGNodeStyleGetXXX. However if they were set using a percentage value then the
|
// YGNodeStyleGetXXX. However if they were set using a percentage value then the
|
||||||
// returned value is the computed value used during layout.
|
// returned value is the computed value used during layout.
|
||||||
WIN_EXPORT float YGNodeLayoutGetMargin(YGNodeRef node, YGEdge edge);
|
WIN_EXPORT float YGNodeLayoutGetMargin(YGNodeConstRef node, YGEdge edge);
|
||||||
WIN_EXPORT float YGNodeLayoutGetBorder(YGNodeRef node, YGEdge edge);
|
WIN_EXPORT float YGNodeLayoutGetBorder(YGNodeConstRef node, YGEdge edge);
|
||||||
WIN_EXPORT float YGNodeLayoutGetPadding(YGNodeRef node, YGEdge edge);
|
WIN_EXPORT float YGNodeLayoutGetPadding(YGNodeConstRef node, YGEdge edge);
|
||||||
|
|
||||||
WIN_EXPORT void YGConfigSetLogger(YGConfigRef config, YGLogger logger);
|
WIN_EXPORT void YGConfigSetLogger(YGConfigRef config, YGLogger logger);
|
||||||
// Set this to number of pixels in 1 point to round calculation results If you
|
// Set this to number of pixels in 1 point to round calculation results If you
|
||||||
@@ -303,7 +304,7 @@ WIN_EXPORT void YGConfigSetLogger(YGConfigRef config, YGLogger logger);
|
|||||||
WIN_EXPORT void YGConfigSetPointScaleFactor(
|
WIN_EXPORT void YGConfigSetPointScaleFactor(
|
||||||
YGConfigRef config,
|
YGConfigRef config,
|
||||||
float pixelsInPoint);
|
float pixelsInPoint);
|
||||||
WIN_EXPORT float YGConfigGetPointScaleFactor(YGConfigRef config);
|
WIN_EXPORT float YGConfigGetPointScaleFactor(YGConfigConstRef config);
|
||||||
|
|
||||||
// Yoga previously had an error where containers would take the maximum space
|
// Yoga previously had an error where containers would take the maximum space
|
||||||
// possible instead of the minimum like they are supposed to. In practice this
|
// possible instead of the minimum like they are supposed to. In practice this
|
||||||
@@ -312,7 +313,7 @@ WIN_EXPORT float YGConfigGetPointScaleFactor(YGConfigRef config);
|
|||||||
// this behaviour.
|
// this behaviour.
|
||||||
WIN_EXPORT YG_DEPRECATED(
|
WIN_EXPORT YG_DEPRECATED(
|
||||||
"Please use "
|
"Please use "
|
||||||
"\"YGConfigGetErrata()\"") bool YGConfigGetUseLegacyStretchBehaviour(YGConfigRef
|
"\"YGConfigGetErrata()\"") bool YGConfigGetUseLegacyStretchBehaviour(YGConfigConstRef
|
||||||
config);
|
config);
|
||||||
WIN_EXPORT
|
WIN_EXPORT
|
||||||
YG_DEPRECATED(
|
YG_DEPRECATED(
|
||||||
@@ -336,26 +337,25 @@ WIN_EXPORT void YGConfigSetExperimentalFeatureEnabled(
|
|||||||
YGExperimentalFeature feature,
|
YGExperimentalFeature feature,
|
||||||
bool enabled);
|
bool enabled);
|
||||||
WIN_EXPORT bool YGConfigIsExperimentalFeatureEnabled(
|
WIN_EXPORT bool YGConfigIsExperimentalFeatureEnabled(
|
||||||
YGConfigRef config,
|
YGConfigConstRef config,
|
||||||
YGExperimentalFeature feature);
|
YGExperimentalFeature feature);
|
||||||
|
|
||||||
// Using the web defaults is the preferred configuration for new projects. Usage
|
// Using the web defaults is the preferred configuration for new projects. Usage
|
||||||
// of non web defaults should be considered as legacy.
|
// of non web defaults should be considered as legacy.
|
||||||
WIN_EXPORT void YGConfigSetUseWebDefaults(YGConfigRef config, bool enabled);
|
WIN_EXPORT void YGConfigSetUseWebDefaults(YGConfigRef config, bool enabled);
|
||||||
WIN_EXPORT bool YGConfigGetUseWebDefaults(YGConfigRef config);
|
WIN_EXPORT bool YGConfigGetUseWebDefaults(YGConfigConstRef config);
|
||||||
|
|
||||||
WIN_EXPORT void YGConfigSetCloneNodeFunc(
|
WIN_EXPORT void YGConfigSetCloneNodeFunc(
|
||||||
YGConfigRef config,
|
YGConfigRef config,
|
||||||
YGCloneNodeFunc callback);
|
YGCloneNodeFunc callback);
|
||||||
|
|
||||||
// Export only for C#
|
|
||||||
WIN_EXPORT YGConfigRef YGConfigGetDefault(void);
|
WIN_EXPORT YGConfigRef YGConfigGetDefault(void);
|
||||||
|
|
||||||
WIN_EXPORT void YGConfigSetContext(YGConfigRef config, void* context);
|
WIN_EXPORT void YGConfigSetContext(YGConfigRef config, void* context);
|
||||||
WIN_EXPORT void* YGConfigGetContext(YGConfigRef config);
|
WIN_EXPORT void* YGConfigGetContext(YGConfigConstRef config);
|
||||||
|
|
||||||
WIN_EXPORT void YGConfigSetErrata(YGConfigRef config, YGErrata errata);
|
WIN_EXPORT void YGConfigSetErrata(YGConfigRef config, YGErrata errata);
|
||||||
WIN_EXPORT YGErrata YGConfigGetErrata(YGConfigRef config);
|
WIN_EXPORT YGErrata YGConfigGetErrata(YGConfigConstRef config);
|
||||||
|
|
||||||
WIN_EXPORT float YGRoundValueToPixelGrid(
|
WIN_EXPORT float YGRoundValueToPixelGrid(
|
||||||
double value,
|
double value,
|
||||||
|
@@ -827,8 +827,10 @@ static void zeroOutLayoutRecursively(
|
|||||||
node->setLayoutDimension(0, YGDimensionHeight);
|
node->setLayoutDimension(0, YGDimensionHeight);
|
||||||
node->setHasNewLayout(true);
|
node->setHasNewLayout(true);
|
||||||
|
|
||||||
node->iterChildrenAfterCloningIfNeeded(
|
node->cloneChildrenIfNeeded(layoutContext);
|
||||||
zeroOutLayoutRecursively, layoutContext);
|
for (const auto child : node->getChildren()) {
|
||||||
|
zeroOutLayoutRecursively(child, layoutContext);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static float calculateAvailableInnerDimension(
|
static float calculateAvailableInnerDimension(
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <yoga/config/Config.h>
|
#include <yoga/config/Config.h>
|
||||||
|
#include <yoga/node/Node.h>
|
||||||
|
|
||||||
namespace facebook::yoga {
|
namespace facebook::yoga {
|
||||||
|
|
||||||
@@ -101,15 +102,28 @@ void Config::setLogger(std::nullptr_t) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Config::log(
|
void Config::log(
|
||||||
YGNodeRef node,
|
const yoga::Node* node,
|
||||||
YGLogLevel logLevel,
|
YGLogLevel logLevel,
|
||||||
void* logContext,
|
void* logContext,
|
||||||
const char* format,
|
const char* format,
|
||||||
va_list args) {
|
va_list args) const {
|
||||||
|
// TODO: Break log callback signatures to make them const correct
|
||||||
|
|
||||||
if (flags_.loggerUsesContext) {
|
if (flags_.loggerUsesContext) {
|
||||||
logger_.withContext(this, node, logLevel, logContext, format, args);
|
logger_.withContext(
|
||||||
|
const_cast<yoga::Config*>(this),
|
||||||
|
const_cast<yoga::Node*>(node),
|
||||||
|
logLevel,
|
||||||
|
logContext,
|
||||||
|
format,
|
||||||
|
args);
|
||||||
} else {
|
} else {
|
||||||
logger_.noContext(this, node, logLevel, format, args);
|
logger_.noContext(
|
||||||
|
const_cast<yoga::Config*>(this),
|
||||||
|
const_cast<yoga::Node*>(node),
|
||||||
|
logLevel,
|
||||||
|
format,
|
||||||
|
args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,6 +16,7 @@ struct YGConfig {};
|
|||||||
namespace facebook::yoga {
|
namespace facebook::yoga {
|
||||||
|
|
||||||
class Config;
|
class Config;
|
||||||
|
class Node;
|
||||||
|
|
||||||
// Whether moving a node from config "a" to config "b" should dirty previously
|
// Whether moving a node from config "a" to config "b" should dirty previously
|
||||||
// calculated layout results.
|
// calculated layout results.
|
||||||
@@ -78,7 +79,12 @@ public:
|
|||||||
void setLogger(YGLogger logger);
|
void setLogger(YGLogger logger);
|
||||||
void setLogger(LogWithContextFn logger);
|
void setLogger(LogWithContextFn logger);
|
||||||
void setLogger(std::nullptr_t);
|
void setLogger(std::nullptr_t);
|
||||||
void log(YGNodeRef, YGLogLevel, void*, const char*, va_list);
|
void log(
|
||||||
|
const yoga::Node* node,
|
||||||
|
YGLogLevel logLevel,
|
||||||
|
void* logContext,
|
||||||
|
const char* format,
|
||||||
|
va_list args) const;
|
||||||
|
|
||||||
void setCloneNodeCallback(YGCloneNodeFunc cloneNode);
|
void setCloneNodeCallback(YGCloneNodeFunc cloneNode);
|
||||||
void setCloneNodeCallback(CloneWithContextFn cloneNode);
|
void setCloneNodeCallback(CloneWithContextFn cloneNode);
|
||||||
@@ -106,4 +112,12 @@ private:
|
|||||||
void* context_ = nullptr;
|
void* context_ = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline Config* resolveRef(const YGConfigRef ref) {
|
||||||
|
return static_cast<Config*>(ref);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const Config* resolveRef(const YGConfigConstRef ref) {
|
||||||
|
return static_cast<const Config*>(ref);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace facebook::yoga
|
} // namespace facebook::yoga
|
||||||
|
@@ -22,43 +22,27 @@ namespace facebook::yoga {
|
|||||||
|
|
||||||
void assertFatal(const bool condition, const char* message) {
|
void assertFatal(const bool condition, const char* message) {
|
||||||
if (!condition) {
|
if (!condition) {
|
||||||
yoga::log(
|
yoga::log(YGLogLevelFatal, nullptr, "%s\n", message);
|
||||||
static_cast<yoga::Node*>(nullptr),
|
|
||||||
YGLogLevelFatal,
|
|
||||||
nullptr,
|
|
||||||
"%s\n",
|
|
||||||
message);
|
|
||||||
fatalWithMessage(message);
|
fatalWithMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void assertFatalWithNode(
|
void assertFatalWithNode(
|
||||||
const YGNodeConstRef node,
|
const yoga::Node* const node,
|
||||||
const bool condition,
|
const bool condition,
|
||||||
const char* message) {
|
const char* message) {
|
||||||
if (!condition) {
|
if (!condition) {
|
||||||
yoga::log(
|
yoga::log(node, YGLogLevelFatal, nullptr, "%s\n", message);
|
||||||
// TODO: Break log callbacks and make them const correct
|
|
||||||
static_cast<yoga::Node*>(const_cast<YGNodeRef>(node)),
|
|
||||||
YGLogLevelFatal,
|
|
||||||
nullptr,
|
|
||||||
"%s\n",
|
|
||||||
message);
|
|
||||||
fatalWithMessage(message);
|
fatalWithMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void assertFatalWithConfig(
|
void assertFatalWithConfig(
|
||||||
YGConfigRef config,
|
const yoga::Config* const config,
|
||||||
const bool condition,
|
const bool condition,
|
||||||
const char* message) {
|
const char* message) {
|
||||||
if (!condition) {
|
if (!condition) {
|
||||||
yoga::log(
|
yoga::log(config, YGLogLevelFatal, nullptr, "%s\n", message);
|
||||||
static_cast<yoga::Config*>(config),
|
|
||||||
YGLogLevelFatal,
|
|
||||||
nullptr,
|
|
||||||
"%s\n",
|
|
||||||
message);
|
|
||||||
fatalWithMessage(message);
|
fatalWithMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,11 +17,11 @@ namespace facebook::yoga {
|
|||||||
|
|
||||||
void assertFatal(bool condition, const char* message);
|
void assertFatal(bool condition, const char* message);
|
||||||
void assertFatalWithNode(
|
void assertFatalWithNode(
|
||||||
YGNodeConstRef node,
|
const yoga::Node* node,
|
||||||
bool condition,
|
bool condition,
|
||||||
const char* message);
|
const char* message);
|
||||||
void assertFatalWithConfig(
|
void assertFatalWithConfig(
|
||||||
YGConfigRef config,
|
const yoga::Config* config,
|
||||||
bool condition,
|
bool condition,
|
||||||
const char* message);
|
const char* message);
|
||||||
|
|
||||||
|
@@ -12,21 +12,28 @@ namespace facebook::yoga {
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void vlog(
|
void vlog(
|
||||||
yoga::Config* config,
|
const yoga::Config* config,
|
||||||
yoga::Node* node,
|
const yoga::Node* node,
|
||||||
YGLogLevel level,
|
YGLogLevel level,
|
||||||
void* context,
|
void* context,
|
||||||
const char* format,
|
const char* format,
|
||||||
va_list args) {
|
va_list args) {
|
||||||
yoga::Config* logConfig = config != nullptr
|
const yoga::Config* logConfig =
|
||||||
? config
|
config != nullptr ? config : resolveRef(YGConfigGetDefault());
|
||||||
: static_cast<yoga::Config*>(YGConfigGetDefault());
|
|
||||||
logConfig->log(node, level, context, format, args);
|
logConfig->log(const_cast<yoga::Node*>(node), level, context, format, args);
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
void log(YGLogLevel level, void* context, const char* format, ...) noexcept {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, format);
|
||||||
|
vlog(nullptr, nullptr, level, context, format, args);
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
void log(
|
void log(
|
||||||
yoga::Node* node,
|
const yoga::Node* node,
|
||||||
YGLogLevel level,
|
YGLogLevel level,
|
||||||
void* context,
|
void* context,
|
||||||
const char* format,
|
const char* format,
|
||||||
@@ -44,7 +51,7 @@ void log(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void log(
|
void log(
|
||||||
yoga::Config* config,
|
const yoga::Config* config,
|
||||||
YGLogLevel level,
|
YGLogLevel level,
|
||||||
void* context,
|
void* context,
|
||||||
const char* format,
|
const char* format,
|
||||||
|
@@ -13,15 +13,17 @@
|
|||||||
|
|
||||||
namespace facebook::yoga {
|
namespace facebook::yoga {
|
||||||
|
|
||||||
|
void log(YGLogLevel level, void*, const char* format, ...) noexcept;
|
||||||
|
|
||||||
void log(
|
void log(
|
||||||
yoga::Node* node,
|
const yoga::Node* node,
|
||||||
YGLogLevel level,
|
YGLogLevel level,
|
||||||
void*,
|
void*,
|
||||||
const char* message,
|
const char* message,
|
||||||
...) noexcept;
|
...) noexcept;
|
||||||
|
|
||||||
void log(
|
void log(
|
||||||
yoga::Config* config,
|
const yoga::Config* config,
|
||||||
YGLogLevel level,
|
YGLogLevel level,
|
||||||
void*,
|
void*,
|
||||||
const char* format,
|
const char* format,
|
||||||
|
@@ -117,7 +117,7 @@ static void appendEdgeIfNotUndefined(
|
|||||||
|
|
||||||
void nodeToString(
|
void nodeToString(
|
||||||
std::string& str,
|
std::string& str,
|
||||||
yoga::Node* node,
|
const yoga::Node* node,
|
||||||
YGPrintOptions options,
|
YGPrintOptions options,
|
||||||
uint32_t level) {
|
uint32_t level) {
|
||||||
indent(str, level);
|
indent(str, level);
|
||||||
|
@@ -18,7 +18,7 @@ namespace facebook::yoga {
|
|||||||
|
|
||||||
void nodeToString(
|
void nodeToString(
|
||||||
std::string& str,
|
std::string& str,
|
||||||
yoga::Node* node,
|
const yoga::Node* node,
|
||||||
YGPrintOptions options,
|
YGPrintOptions options,
|
||||||
uint32_t level);
|
uint32_t level);
|
||||||
|
|
||||||
|
@@ -484,7 +484,14 @@ YOGA_EXPORT void Node::clearChildren() {
|
|||||||
// Other Methods
|
// Other Methods
|
||||||
|
|
||||||
void Node::cloneChildrenIfNeeded(void* cloneContext) {
|
void Node::cloneChildrenIfNeeded(void* cloneContext) {
|
||||||
iterChildrenAfterCloningIfNeeded([](Node*, void*) {}, cloneContext);
|
int i = 0;
|
||||||
|
for (Node*& child : children_) {
|
||||||
|
if (child->getOwner() != this) {
|
||||||
|
child = resolveRef(config_->cloneNode(child, this, i, cloneContext));
|
||||||
|
child->setOwner(this);
|
||||||
|
}
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::markDirtyAndPropagate() {
|
void Node::markDirtyAndPropagate() {
|
||||||
|
@@ -11,6 +11,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <yoga/Yoga.h>
|
||||||
|
|
||||||
#include <yoga/config/Config.h>
|
#include <yoga/config/Config.h>
|
||||||
#include <yoga/node/LayoutResults.h>
|
#include <yoga/node/LayoutResults.h>
|
||||||
#include <yoga/style/CompactValue.h>
|
#include <yoga/style/CompactValue.h>
|
||||||
@@ -139,7 +141,7 @@ public:
|
|||||||
|
|
||||||
uint32_t getLineIndex() const { return lineIndex_; }
|
uint32_t getLineIndex() const { return lineIndex_; }
|
||||||
|
|
||||||
bool isReferenceBaseline() { return flags_.isReferenceBaseline; }
|
bool isReferenceBaseline() const { return flags_.isReferenceBaseline; }
|
||||||
|
|
||||||
// returns the Node that owns this Node. An owner is used to identify
|
// returns the Node that owns this Node. An owner is used to identify
|
||||||
// the YogaTree that a Node belongs to. This method will return the parent
|
// the YogaTree that a Node belongs to. This method will return the parent
|
||||||
@@ -152,23 +154,6 @@ public:
|
|||||||
|
|
||||||
const std::vector<Node*>& getChildren() const { return children_; }
|
const std::vector<Node*>& getChildren() const { return children_; }
|
||||||
|
|
||||||
// Applies a callback to all children, after cloning them if they are not
|
|
||||||
// owned.
|
|
||||||
template <typename T>
|
|
||||||
void iterChildrenAfterCloningIfNeeded(T callback, void* cloneContext) {
|
|
||||||
int i = 0;
|
|
||||||
for (Node*& child : children_) {
|
|
||||||
if (child->getOwner() != this) {
|
|
||||||
child = static_cast<Node*>(
|
|
||||||
config_->cloneNode(child, this, i, cloneContext));
|
|
||||||
child->setOwner(this);
|
|
||||||
}
|
|
||||||
i += 1;
|
|
||||||
|
|
||||||
callback(child, cloneContext);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Node* getChild(size_t index) const { return children_.at(index); }
|
Node* getChild(size_t index) const { return children_.at(index); }
|
||||||
|
|
||||||
size_t getChildCount() const { return children_.size(); }
|
size_t getChildCount() const { return children_.size(); }
|
||||||
@@ -343,4 +328,12 @@ public:
|
|||||||
void reset();
|
void reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline Node* resolveRef(const YGNodeRef ref) {
|
||||||
|
return static_cast<Node*>(ref);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const Node* resolveRef(const YGNodeConstRef ref) {
|
||||||
|
return static_cast<const Node*>(ref);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace facebook::yoga
|
} // namespace facebook::yoga
|
||||||
|
Reference in New Issue
Block a user