/* * 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 #include #include namespace facebook::yoga { inline float paddingAndBorderForAxis( const yoga::Node* const node, const FlexDirection axis, const float widthSize) { return (node->getLeadingPaddingAndBorder(axis, widthSize) + node->getTrailingPaddingAndBorder(axis, widthSize)) .unwrap(); } inline FloatOptional boundAxisWithinMinAndMax( const yoga::Node* const node, const FlexDirection axis, const FloatOptional value, const float axisSize) { FloatOptional min; FloatOptional max; if (isColumn(axis)) { min = yoga::resolveValue( node->getStyle().minDimension(YGDimensionHeight), axisSize); max = yoga::resolveValue( node->getStyle().maxDimension(YGDimensionHeight), axisSize); } else if (isRow(axis)) { min = yoga::resolveValue( node->getStyle().minDimension(YGDimensionWidth), axisSize); max = yoga::resolveValue( node->getStyle().maxDimension(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 FlexDirection 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