-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Differential Revision: D49133837 fbshipit-source-id: 77e501ff7319e31d9b45c20c3d39c905c28fe8bb
- Loading branch information
1 parent
dff5312
commit aa91b88
Showing
5 changed files
with
374 additions
and
341 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* 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/algorithm/FlexDirection.h> | ||
#include <yoga/algorithm/ResolveValue.h> | ||
#include <yoga/node/Node.h> | ||
#include <yoga/numeric/Comparison.h> | ||
#include <yoga/numeric/FloatOptional.h> | ||
|
||
namespace facebook::yoga { | ||
|
||
inline float paddingAndBorderForAxis( | ||
const yoga::Node* const node, | ||
const YGFlexDirection axis, | ||
const float widthSize) { | ||
return (node->getLeadingPaddingAndBorder(axis, widthSize) + | ||
node->getTrailingPaddingAndBorder(axis, widthSize)) | ||
.unwrap(); | ||
} | ||
|
||
inline FloatOptional boundAxisWithinMinAndMax( | ||
const yoga::Node* const node, | ||
const YGFlexDirection axis, | ||
const FloatOptional value, | ||
const float axisSize) { | ||
FloatOptional min; | ||
FloatOptional max; | ||
|
||
if (isColumn(axis)) { | ||
min = yoga::resolveValue( | ||
node->getStyle().minDimensions()[YGDimensionHeight], axisSize); | ||
max = yoga::resolveValue( | ||
node->getStyle().maxDimensions()[YGDimensionHeight], axisSize); | ||
} else if (isRow(axis)) { | ||
min = yoga::resolveValue( | ||
node->getStyle().minDimensions()[YGDimensionWidth], axisSize); | ||
max = yoga::resolveValue( | ||
node->getStyle().maxDimensions()[YGDimensionWidth], axisSize); | ||
} | ||
|
||
if (max >= FloatOptional{0} && value > max) { | ||
return max; | ||
} | ||
|
||
if (min >= FloatOptional{0} && value < min) { | ||
return min; | ||
} | ||
|
||
return value; | ||
} | ||
|
||
// Like boundAxisWithinMinAndMax but also ensures that the value doesn't | ||
// go below the padding and border amount. | ||
inline float boundAxis( | ||
const yoga::Node* const node, | ||
const YGFlexDirection axis, | ||
const float value, | ||
const float axisSize, | ||
const float widthSize) { | ||
return yoga::maxOrDefined( | ||
boundAxisWithinMinAndMax(node, axis, FloatOptional{value}, axisSize) | ||
.unwrap(), | ||
paddingAndBorderForAxis(node, axis, widthSize)); | ||
} | ||
|
||
} // namespace facebook::yoga |
Oops, something went wrong.