Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1811 X-link: https://github.com/facebook/react-native/pull/51298 ## Resubmit This was backed out due to being up the stack from another change that was backed out, but should be safe by itself. ## Original We want to know if an artifact created during measurement can fully be reused after final layout, but the final layout is allowed to be slightly larger due to pixel grid rounding (while still allowing reuse). It's hard to tell after the fact, whether it is larger because of this rounding (though the measure is used), or if it may be a pixel larger for valid reasons. We can expose the unsnapped dimensions of a node to give us this information, and to correlate measurement artifacts. This is most of the time the same as the layout's measured dimension, though I don't think it's safe to use this, since anything else measuring the node after could clobber this (I think `YGNodeLayoutGetOverflow` may also be prone to this as a bug). Changelog: [Internal] Reviewed By: joevilches Differential Revision: D74673119 fbshipit-source-id: 06d2eb21e28b76458ec88f4dfcaec809707d0390
101 lines
2.9 KiB
C++
101 lines
2.9 KiB
C++
/*
|
|
* 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.
|
|
*/
|
|
|
|
#include <yoga/Yoga.h>
|
|
#include <yoga/debug/AssertFatal.h>
|
|
#include <yoga/enums/Edge.h>
|
|
#include <yoga/node/Node.h>
|
|
|
|
using namespace facebook;
|
|
using namespace facebook::yoga;
|
|
|
|
namespace {
|
|
|
|
template <auto LayoutMember>
|
|
float getResolvedLayoutProperty(const YGNodeConstRef nodeRef, const Edge edge) {
|
|
const auto node = resolveRef(nodeRef);
|
|
yoga::assertFatalWithNode(
|
|
node,
|
|
edge <= Edge::End,
|
|
"Cannot get layout properties of multi-edge shorthands");
|
|
|
|
if (edge == Edge::Start) {
|
|
if (node->getLayout().direction() == Direction::RTL) {
|
|
return (node->getLayout().*LayoutMember)(PhysicalEdge::Right);
|
|
} else {
|
|
return (node->getLayout().*LayoutMember)(PhysicalEdge::Left);
|
|
}
|
|
}
|
|
|
|
if (edge == Edge::End) {
|
|
if (node->getLayout().direction() == Direction::RTL) {
|
|
return (node->getLayout().*LayoutMember)(PhysicalEdge::Left);
|
|
} else {
|
|
return (node->getLayout().*LayoutMember)(PhysicalEdge::Right);
|
|
}
|
|
}
|
|
|
|
return (node->getLayout().*LayoutMember)(static_cast<PhysicalEdge>(edge));
|
|
}
|
|
|
|
} // namespace
|
|
|
|
float YGNodeLayoutGetLeft(const YGNodeConstRef node) {
|
|
return resolveRef(node)->getLayout().position(PhysicalEdge::Left);
|
|
}
|
|
|
|
float YGNodeLayoutGetTop(const YGNodeConstRef node) {
|
|
return resolveRef(node)->getLayout().position(PhysicalEdge::Top);
|
|
}
|
|
|
|
float YGNodeLayoutGetRight(const YGNodeConstRef node) {
|
|
return resolveRef(node)->getLayout().position(PhysicalEdge::Right);
|
|
}
|
|
|
|
float YGNodeLayoutGetBottom(const YGNodeConstRef node) {
|
|
return resolveRef(node)->getLayout().position(PhysicalEdge::Bottom);
|
|
}
|
|
|
|
float YGNodeLayoutGetWidth(const YGNodeConstRef node) {
|
|
return resolveRef(node)->getLayout().dimension(Dimension::Width);
|
|
}
|
|
|
|
float YGNodeLayoutGetHeight(const YGNodeConstRef node) {
|
|
return resolveRef(node)->getLayout().dimension(Dimension::Height);
|
|
}
|
|
|
|
YGDirection YGNodeLayoutGetDirection(const YGNodeConstRef node) {
|
|
return unscopedEnum(resolveRef(node)->getLayout().direction());
|
|
}
|
|
|
|
bool YGNodeLayoutGetHadOverflow(const YGNodeConstRef node) {
|
|
return resolveRef(node)->getLayout().hadOverflow();
|
|
}
|
|
|
|
float YGNodeLayoutGetMargin(YGNodeConstRef node, YGEdge edge) {
|
|
return getResolvedLayoutProperty<&LayoutResults::margin>(
|
|
node, scopedEnum(edge));
|
|
}
|
|
|
|
float YGNodeLayoutGetBorder(YGNodeConstRef node, YGEdge edge) {
|
|
return getResolvedLayoutProperty<&LayoutResults::border>(
|
|
node, scopedEnum(edge));
|
|
}
|
|
|
|
float YGNodeLayoutGetPadding(YGNodeConstRef node, YGEdge edge) {
|
|
return getResolvedLayoutProperty<&LayoutResults::padding>(
|
|
node, scopedEnum(edge));
|
|
}
|
|
|
|
float YGNodeLayoutGetRawHeight(YGNodeConstRef node) {
|
|
return resolveRef(node)->getLayout().rawDimension(Dimension::Height);
|
|
}
|
|
|
|
float YGNodeLayoutGetRawWidth(YGNodeConstRef node) {
|
|
return resolveRef(node)->getLayout().rawDimension(Dimension::Width);
|
|
}
|