Skip to content

Commit

Permalink
Separate FlexLine functionality
Browse files Browse the repository at this point in the history
Differential Revision: D49133837

fbshipit-source-id: 77e501ff7319e31d9b45c20c3d39c905c28fe8bb
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Sep 12, 2023
1 parent dff5312 commit aa91b88
Show file tree
Hide file tree
Showing 5 changed files with 374 additions and 341 deletions.
72 changes: 72 additions & 0 deletions yoga/algorithm/BoundAxis.h
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
Loading

0 comments on commit aa91b88

Please sign in to comment.