diff --git a/yoga/algorithm/AbsoluteLayout.cpp b/yoga/algorithm/AbsoluteLayout.cpp index 1da6c290bf..886aae133f 100644 --- a/yoga/algorithm/AbsoluteLayout.cpp +++ b/yoga/algorithm/AbsoluteLayout.cpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace facebook::yoga { diff --git a/yoga/algorithm/CalculateLayout.cpp b/yoga/algorithm/CalculateLayout.cpp index 1aae098fef..17703605af 100644 --- a/yoga/algorithm/CalculateLayout.cpp +++ b/yoga/algorithm/CalculateLayout.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include diff --git a/yoga/algorithm/CalculateLayout.h b/yoga/algorithm/CalculateLayout.h index 955cbdbb59..1d5a3fd739 100644 --- a/yoga/algorithm/CalculateLayout.h +++ b/yoga/algorithm/CalculateLayout.h @@ -35,31 +35,4 @@ bool calculateLayoutInternal( const uint32_t depth, const uint32_t generationCount); -// Given an offset to an edge, returns the offset to the opposite edge on the -// same axis. This assumes that the width/height of both nodes is determined at -// this point. -inline float getPositionOfOppositeEdge( - float position, - FlexDirection axis, - const yoga::Node* const containingNode, - const yoga::Node* const node) { - return containingNode->getLayout().measuredDimension(dimension(axis)) - - node->getLayout().measuredDimension(dimension(axis)) - position; -} - -inline void setChildTrailingPosition( - const yoga::Node* const node, - yoga::Node* const child, - const FlexDirection axis) { - child->setLayoutPosition( - getPositionOfOppositeEdge( - child->getLayout().position(flexStartEdge(axis)), axis, node, child), - flexEndEdge(axis)); -} - -inline bool needsTrailingPosition(const FlexDirection axis) { - return axis == FlexDirection::RowReverse || - axis == FlexDirection::ColumnReverse; -} - } // namespace facebook::yoga diff --git a/yoga/algorithm/TrailingPosition.h b/yoga/algorithm/TrailingPosition.h new file mode 100644 index 0000000000..84d00edbe5 --- /dev/null +++ b/yoga/algorithm/TrailingPosition.h @@ -0,0 +1,44 @@ +/* + * 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 +#include +#include +#include + +namespace facebook::yoga { + +// Given an offset to an edge, returns the offset to the opposite edge on the +// same axis. This assumes that the width/height of both nodes is determined at +// this point. +inline float getPositionOfOppositeEdge( + float position, + FlexDirection axis, + const yoga::Node* const containingNode, + const yoga::Node* const node) { + return containingNode->getLayout().measuredDimension(dimension(axis)) - + node->getLayout().measuredDimension(dimension(axis)) - position; +} + +inline void setChildTrailingPosition( + const yoga::Node* const node, + yoga::Node* const child, + const FlexDirection axis) { + child->setLayoutPosition( + getPositionOfOppositeEdge( + child->getLayout().position(flexStartEdge(axis)), axis, node, child), + flexEndEdge(axis)); +} + +inline bool needsTrailingPosition(const FlexDirection axis) { + return axis == FlexDirection::RowReverse || + axis == FlexDirection::ColumnReverse; +} + +} // namespace facebook::yoga