forked from facebook/yoga
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move trailing position functions (facebook#1533)
Summary: Pull Request resolved: facebook#1533 X-link: facebook/react-native#42031 I have some reservations about some of the conditional setting of trailing position in general, and some of the repeated transformations that neccesitates this, but these functions don't belong in `CalculateLayout.h`. For now, just move these to their own header. Reviewed By: joevilches Differential Revision: D52292121 fbshipit-source-id: 4a998a4390a8d045af45f5424adaf049ed635e7a
- Loading branch information
1 parent
c319c36
commit 94e7336
Showing
4 changed files
with
46 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <yoga/Yoga.h> | ||
#include <yoga/algorithm/FlexDirection.h> | ||
#include <yoga/event/event.h> | ||
#include <yoga/node/Node.h> | ||
|
||
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 |