Revert D48767992: C++ Cleanup 6/N: YGFloatOptional
Differential Revision: D48767992 Original commit changeset: afaff0234359 Original Phabricator Diff: D48767992 fbshipit-source-id: 4666bdbb83aebbf2f7373b3a10a8c1dd0a03f92c
This commit is contained in:
committed by
Facebook GitHub Bot
parent
8a95b785a8
commit
7cf0483b17
@@ -8,19 +8,18 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include <yoga/numeric/Comparison.h>
|
#include <yoga/numeric/Comparison.h>
|
||||||
#include <yoga/numeric/FloatOptional.h>
|
#include <yoga/YGFloatOptional.h>
|
||||||
#include <yoga/YGValue.h>
|
#include <yoga/YGValue.h>
|
||||||
|
|
||||||
using namespace facebook;
|
using namespace facebook;
|
||||||
using namespace facebook::yoga;
|
|
||||||
|
|
||||||
constexpr auto empty = FloatOptional{};
|
constexpr auto empty = YGFloatOptional{};
|
||||||
constexpr auto zero = FloatOptional{0.0f};
|
constexpr auto zero = YGFloatOptional{0.0f};
|
||||||
constexpr auto one = FloatOptional{1.0f};
|
constexpr auto one = YGFloatOptional{1.0f};
|
||||||
constexpr auto positive = FloatOptional{1234.5f};
|
constexpr auto positive = YGFloatOptional{1234.5f};
|
||||||
constexpr auto negative = FloatOptional{-9876.5f};
|
constexpr auto negative = YGFloatOptional{-9876.5f};
|
||||||
|
|
||||||
TEST(FloatOptional, value) {
|
TEST(YGFloatOptional, value) {
|
||||||
ASSERT_TRUE(YGFloatIsUndefined(empty.unwrap()));
|
ASSERT_TRUE(YGFloatIsUndefined(empty.unwrap()));
|
||||||
ASSERT_EQ(zero.unwrap(), 0.0f);
|
ASSERT_EQ(zero.unwrap(), 0.0f);
|
||||||
ASSERT_EQ(one.unwrap(), 1.0f);
|
ASSERT_EQ(one.unwrap(), 1.0f);
|
||||||
@@ -34,7 +33,7 @@ TEST(FloatOptional, value) {
|
|||||||
ASSERT_FALSE(negative.isUndefined());
|
ASSERT_FALSE(negative.isUndefined());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FloatOptional, equality) {
|
TEST(YGFloatOptional, equality) {
|
||||||
ASSERT_TRUE(empty == empty);
|
ASSERT_TRUE(empty == empty);
|
||||||
ASSERT_TRUE(empty == YGUndefined);
|
ASSERT_TRUE(empty == YGUndefined);
|
||||||
ASSERT_FALSE(empty == zero);
|
ASSERT_FALSE(empty == zero);
|
||||||
@@ -59,7 +58,7 @@ TEST(FloatOptional, equality) {
|
|||||||
ASSERT_FALSE(negative == zero);
|
ASSERT_FALSE(negative == zero);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FloatOptional, inequality) {
|
TEST(YGFloatOptional, inequality) {
|
||||||
ASSERT_FALSE(empty != empty);
|
ASSERT_FALSE(empty != empty);
|
||||||
ASSERT_FALSE(empty != YGUndefined);
|
ASSERT_FALSE(empty != YGUndefined);
|
||||||
ASSERT_TRUE(empty != zero);
|
ASSERT_TRUE(empty != zero);
|
||||||
@@ -84,7 +83,7 @@ TEST(FloatOptional, inequality) {
|
|||||||
ASSERT_TRUE(negative != zero);
|
ASSERT_TRUE(negative != zero);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FloatOptional, greater_than_with_undefined) {
|
TEST(YGFloatOptional, greater_than_with_undefined) {
|
||||||
ASSERT_FALSE(empty > empty);
|
ASSERT_FALSE(empty > empty);
|
||||||
ASSERT_FALSE(empty > zero);
|
ASSERT_FALSE(empty > zero);
|
||||||
ASSERT_FALSE(empty > one);
|
ASSERT_FALSE(empty > one);
|
||||||
@@ -96,7 +95,7 @@ TEST(FloatOptional, greater_than_with_undefined) {
|
|||||||
ASSERT_FALSE(negative > empty);
|
ASSERT_FALSE(negative > empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FloatOptional, greater_than) {
|
TEST(YGFloatOptional, greater_than) {
|
||||||
ASSERT_TRUE(zero > negative);
|
ASSERT_TRUE(zero > negative);
|
||||||
ASSERT_FALSE(zero > zero);
|
ASSERT_FALSE(zero > zero);
|
||||||
ASSERT_FALSE(zero > positive);
|
ASSERT_FALSE(zero > positive);
|
||||||
@@ -106,10 +105,10 @@ TEST(FloatOptional, greater_than) {
|
|||||||
ASSERT_TRUE(one > zero);
|
ASSERT_TRUE(one > zero);
|
||||||
ASSERT_FALSE(one > positive);
|
ASSERT_FALSE(one > positive);
|
||||||
|
|
||||||
ASSERT_TRUE(negative > FloatOptional{-INFINITY});
|
ASSERT_TRUE(negative > YGFloatOptional{-INFINITY});
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FloatOptional, less_than_with_undefined) {
|
TEST(YGFloatOptional, less_than_with_undefined) {
|
||||||
ASSERT_FALSE(empty < empty);
|
ASSERT_FALSE(empty < empty);
|
||||||
ASSERT_FALSE(zero < empty);
|
ASSERT_FALSE(zero < empty);
|
||||||
ASSERT_FALSE(one < empty);
|
ASSERT_FALSE(one < empty);
|
||||||
@@ -121,7 +120,7 @@ TEST(FloatOptional, less_than_with_undefined) {
|
|||||||
ASSERT_FALSE(empty < negative);
|
ASSERT_FALSE(empty < negative);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FloatOptional, less_than) {
|
TEST(YGFloatOptional, less_than) {
|
||||||
ASSERT_TRUE(negative < zero);
|
ASSERT_TRUE(negative < zero);
|
||||||
ASSERT_FALSE(zero < zero);
|
ASSERT_FALSE(zero < zero);
|
||||||
ASSERT_FALSE(positive < zero);
|
ASSERT_FALSE(positive < zero);
|
||||||
@@ -131,10 +130,10 @@ TEST(FloatOptional, less_than) {
|
|||||||
ASSERT_TRUE(zero < one);
|
ASSERT_TRUE(zero < one);
|
||||||
ASSERT_FALSE(positive < one);
|
ASSERT_FALSE(positive < one);
|
||||||
|
|
||||||
ASSERT_TRUE(FloatOptional{-INFINITY} < negative);
|
ASSERT_TRUE(YGFloatOptional{-INFINITY} < negative);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FloatOptional, greater_than_equals_with_undefined) {
|
TEST(YGFloatOptional, greater_than_equals_with_undefined) {
|
||||||
ASSERT_TRUE(empty >= empty);
|
ASSERT_TRUE(empty >= empty);
|
||||||
ASSERT_FALSE(empty >= zero);
|
ASSERT_FALSE(empty >= zero);
|
||||||
ASSERT_FALSE(empty >= one);
|
ASSERT_FALSE(empty >= one);
|
||||||
@@ -146,7 +145,7 @@ TEST(FloatOptional, greater_than_equals_with_undefined) {
|
|||||||
ASSERT_FALSE(negative >= empty);
|
ASSERT_FALSE(negative >= empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FloatOptional, greater_than_equals) {
|
TEST(YGFloatOptional, greater_than_equals) {
|
||||||
ASSERT_TRUE(zero >= negative);
|
ASSERT_TRUE(zero >= negative);
|
||||||
ASSERT_TRUE(zero >= zero);
|
ASSERT_TRUE(zero >= zero);
|
||||||
ASSERT_FALSE(zero >= positive);
|
ASSERT_FALSE(zero >= positive);
|
||||||
@@ -156,10 +155,10 @@ TEST(FloatOptional, greater_than_equals) {
|
|||||||
ASSERT_TRUE(one >= zero);
|
ASSERT_TRUE(one >= zero);
|
||||||
ASSERT_FALSE(one >= positive);
|
ASSERT_FALSE(one >= positive);
|
||||||
|
|
||||||
ASSERT_TRUE(negative >= FloatOptional{-INFINITY});
|
ASSERT_TRUE(negative >= YGFloatOptional{-INFINITY});
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FloatOptional, less_than_equals_with_undefined) {
|
TEST(YGFloatOptional, less_than_equals_with_undefined) {
|
||||||
ASSERT_TRUE(empty <= empty);
|
ASSERT_TRUE(empty <= empty);
|
||||||
ASSERT_FALSE(zero <= empty);
|
ASSERT_FALSE(zero <= empty);
|
||||||
ASSERT_FALSE(one <= empty);
|
ASSERT_FALSE(one <= empty);
|
||||||
@@ -171,7 +170,7 @@ TEST(FloatOptional, less_than_equals_with_undefined) {
|
|||||||
ASSERT_FALSE(empty <= negative);
|
ASSERT_FALSE(empty <= negative);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FloatOptional, less_than_equals) {
|
TEST(YGFloatOptional, less_than_equals) {
|
||||||
ASSERT_TRUE(negative <= zero);
|
ASSERT_TRUE(negative <= zero);
|
||||||
ASSERT_TRUE(zero <= zero);
|
ASSERT_TRUE(zero <= zero);
|
||||||
ASSERT_FALSE(positive <= zero);
|
ASSERT_FALSE(positive <= zero);
|
||||||
@@ -181,32 +180,32 @@ TEST(FloatOptional, less_than_equals) {
|
|||||||
ASSERT_TRUE(zero <= one);
|
ASSERT_TRUE(zero <= one);
|
||||||
ASSERT_FALSE(positive <= one);
|
ASSERT_FALSE(positive <= one);
|
||||||
|
|
||||||
ASSERT_TRUE(FloatOptional{-INFINITY} <= negative);
|
ASSERT_TRUE(YGFloatOptional{-INFINITY} <= negative);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FloatOptional, addition) {
|
TEST(YGFloatOptional, addition) {
|
||||||
auto n = negative.unwrap();
|
auto n = negative.unwrap();
|
||||||
auto p = positive.unwrap();
|
auto p = positive.unwrap();
|
||||||
|
|
||||||
ASSERT_EQ(zero + one, one);
|
ASSERT_EQ(zero + one, one);
|
||||||
ASSERT_EQ(negative + positive, FloatOptional{n + p});
|
ASSERT_EQ(negative + positive, YGFloatOptional{n + p});
|
||||||
ASSERT_EQ(empty + zero, empty);
|
ASSERT_EQ(empty + zero, empty);
|
||||||
ASSERT_EQ(empty + empty, empty);
|
ASSERT_EQ(empty + empty, empty);
|
||||||
ASSERT_EQ(negative + empty, empty);
|
ASSERT_EQ(negative + empty, empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(YGFloatOptiona, maxOrDefined) {
|
TEST(YGFloatOptionalTest, maxOrDefined) {
|
||||||
ASSERT_EQ(yoga::maxOrDefined(empty, empty), empty);
|
ASSERT_EQ(yoga::maxOrDefined(empty, empty), empty);
|
||||||
ASSERT_EQ(yoga::maxOrDefined(empty, positive), positive);
|
ASSERT_EQ(yoga::maxOrDefined(empty, positive), positive);
|
||||||
ASSERT_EQ(yoga::maxOrDefined(negative, empty), negative);
|
ASSERT_EQ(yoga::maxOrDefined(negative, empty), negative);
|
||||||
ASSERT_EQ(yoga::maxOrDefined(negative, FloatOptional{-INFINITY}), negative);
|
ASSERT_EQ(yoga::maxOrDefined(negative, YGFloatOptional{-INFINITY}), negative);
|
||||||
ASSERT_EQ(
|
ASSERT_EQ(
|
||||||
yoga::maxOrDefined(FloatOptional{1.0f}, FloatOptional{1.125f}),
|
yoga::maxOrDefined(YGFloatOptional{1.0f}, YGFloatOptional{1.125f}),
|
||||||
FloatOptional{1.125f});
|
YGFloatOptional{1.125f});
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FloatOptional, unwrap) {
|
TEST(YGFloatOptionalTest, unwrap) {
|
||||||
ASSERT_TRUE(YGFloatIsUndefined(empty.unwrap()));
|
ASSERT_TRUE(YGFloatIsUndefined(empty.unwrap()));
|
||||||
ASSERT_EQ(zero.unwrap(), 0.0f);
|
ASSERT_EQ(zero.unwrap(), 0.0f);
|
||||||
ASSERT_EQ(FloatOptional{123456.78f}.unwrap(), 123456.78f);
|
ASSERT_EQ(YGFloatOptional{123456.78f}.unwrap(), 123456.78f);
|
||||||
}
|
}
|
@@ -154,24 +154,24 @@ ACCESSOR_TEST(display, YGDisplayFlex, YGDisplayNone, YGDisplayFlex)
|
|||||||
|
|
||||||
ACCESSOR_TEST(
|
ACCESSOR_TEST(
|
||||||
flex,
|
flex,
|
||||||
FloatOptional{},
|
YGFloatOptional{},
|
||||||
FloatOptional{123.45f},
|
YGFloatOptional{123.45f},
|
||||||
FloatOptional{-9.87f},
|
YGFloatOptional{-9.87f},
|
||||||
FloatOptional{})
|
YGFloatOptional{})
|
||||||
|
|
||||||
ACCESSOR_TEST(
|
ACCESSOR_TEST(
|
||||||
flexGrow,
|
flexGrow,
|
||||||
FloatOptional{},
|
YGFloatOptional{},
|
||||||
FloatOptional{123.45f},
|
YGFloatOptional{123.45f},
|
||||||
FloatOptional{-9.87f},
|
YGFloatOptional{-9.87f},
|
||||||
FloatOptional{})
|
YGFloatOptional{})
|
||||||
|
|
||||||
ACCESSOR_TEST(
|
ACCESSOR_TEST(
|
||||||
flexShrink,
|
flexShrink,
|
||||||
FloatOptional{},
|
YGFloatOptional{},
|
||||||
FloatOptional{123.45f},
|
YGFloatOptional{123.45f},
|
||||||
FloatOptional{-9.87f},
|
YGFloatOptional{-9.87f},
|
||||||
FloatOptional{})
|
YGFloatOptional{})
|
||||||
|
|
||||||
ACCESSOR_TEST(
|
ACCESSOR_TEST(
|
||||||
flexBasis,
|
flexBasis,
|
||||||
@@ -243,11 +243,11 @@ INDEX_ACCESSOR_TEST(
|
|||||||
|
|
||||||
ACCESSOR_TEST(
|
ACCESSOR_TEST(
|
||||||
aspectRatio,
|
aspectRatio,
|
||||||
FloatOptional{},
|
YGFloatOptional{},
|
||||||
FloatOptional{-123.45f},
|
YGFloatOptional{-123.45f},
|
||||||
FloatOptional{9876.5f},
|
YGFloatOptional{9876.5f},
|
||||||
FloatOptional{0.0f},
|
YGFloatOptional{0.0f},
|
||||||
FloatOptional{});
|
YGFloatOptional{});
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
70
yoga/YGFloatOptional.h
Normal file
70
yoga/YGFloatOptional.h
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* 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 <cmath>
|
||||||
|
#include <limits>
|
||||||
|
#include <yoga/Yoga-internal.h>
|
||||||
|
|
||||||
|
struct YGFloatOptional {
|
||||||
|
private:
|
||||||
|
float value_ = std::numeric_limits<float>::quiet_NaN();
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit constexpr YGFloatOptional(float value) : value_(value) {}
|
||||||
|
constexpr YGFloatOptional() = default;
|
||||||
|
|
||||||
|
// returns the wrapped value, or a value x with YGIsUndefined(x) == true
|
||||||
|
constexpr float unwrap() const { return value_; }
|
||||||
|
|
||||||
|
bool isUndefined() const { return std::isnan(value_); }
|
||||||
|
};
|
||||||
|
|
||||||
|
// operators take YGFloatOptional by value, as it is a 32bit value
|
||||||
|
|
||||||
|
inline bool operator==(YGFloatOptional lhs, YGFloatOptional rhs) {
|
||||||
|
return lhs.unwrap() == rhs.unwrap() ||
|
||||||
|
(lhs.isUndefined() && rhs.isUndefined());
|
||||||
|
}
|
||||||
|
inline bool operator!=(YGFloatOptional lhs, YGFloatOptional rhs) {
|
||||||
|
return !(lhs == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator==(YGFloatOptional lhs, float rhs) {
|
||||||
|
return lhs == YGFloatOptional{rhs};
|
||||||
|
}
|
||||||
|
inline bool operator!=(YGFloatOptional lhs, float rhs) {
|
||||||
|
return !(lhs == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator==(float lhs, YGFloatOptional rhs) {
|
||||||
|
return rhs == lhs;
|
||||||
|
}
|
||||||
|
inline bool operator!=(float lhs, YGFloatOptional rhs) {
|
||||||
|
return !(lhs == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline YGFloatOptional operator+(YGFloatOptional lhs, YGFloatOptional rhs) {
|
||||||
|
return YGFloatOptional{lhs.unwrap() + rhs.unwrap()};
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator>(YGFloatOptional lhs, YGFloatOptional rhs) {
|
||||||
|
return lhs.unwrap() > rhs.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator<(YGFloatOptional lhs, YGFloatOptional rhs) {
|
||||||
|
return lhs.unwrap() < rhs.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator>=(YGFloatOptional lhs, YGFloatOptional rhs) {
|
||||||
|
return lhs > rhs || lhs == rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator<=(YGFloatOptional lhs, YGFloatOptional rhs) {
|
||||||
|
return lhs < rhs || lhs == rhs;
|
||||||
|
}
|
@@ -636,12 +636,12 @@ YOGA_EXPORT YGDisplay YGNodeStyleGetDisplay(const YGNodeConstRef node) {
|
|||||||
return static_cast<const yoga::Node*>(node)->getStyle().display();
|
return static_cast<const yoga::Node*>(node)->getStyle().display();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(T26792433): Change the API to accept FloatOptional.
|
// TODO(T26792433): Change the API to accept YGFloatOptional.
|
||||||
YOGA_EXPORT void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {
|
YOGA_EXPORT void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {
|
||||||
updateStyle<MSVC_HINT(flex)>(node, &Style::flex, FloatOptional{flex});
|
updateStyle<MSVC_HINT(flex)>(node, &Style::flex, YGFloatOptional{flex});
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(T26792433): Change the API to accept FloatOptional.
|
// TODO(T26792433): Change the API to accept YGFloatOptional.
|
||||||
YOGA_EXPORT float YGNodeStyleGetFlex(const YGNodeConstRef nodeRef) {
|
YOGA_EXPORT float YGNodeStyleGetFlex(const YGNodeConstRef nodeRef) {
|
||||||
auto node = static_cast<const yoga::Node*>(nodeRef);
|
auto node = static_cast<const yoga::Node*>(nodeRef);
|
||||||
return node->getStyle().flex().isUndefined()
|
return node->getStyle().flex().isUndefined()
|
||||||
@@ -649,20 +649,20 @@ YOGA_EXPORT float YGNodeStyleGetFlex(const YGNodeConstRef nodeRef) {
|
|||||||
: node->getStyle().flex().unwrap();
|
: node->getStyle().flex().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(T26792433): Change the API to accept FloatOptional.
|
// TODO(T26792433): Change the API to accept YGFloatOptional.
|
||||||
YOGA_EXPORT void YGNodeStyleSetFlexGrow(
|
YOGA_EXPORT void YGNodeStyleSetFlexGrow(
|
||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const float flexGrow) {
|
const float flexGrow) {
|
||||||
updateStyle<MSVC_HINT(flexGrow)>(
|
updateStyle<MSVC_HINT(flexGrow)>(
|
||||||
node, &Style::flexGrow, FloatOptional{flexGrow});
|
node, &Style::flexGrow, YGFloatOptional{flexGrow});
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(T26792433): Change the API to accept FloatOptional.
|
// TODO(T26792433): Change the API to accept YGFloatOptional.
|
||||||
YOGA_EXPORT void YGNodeStyleSetFlexShrink(
|
YOGA_EXPORT void YGNodeStyleSetFlexShrink(
|
||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const float flexShrink) {
|
const float flexShrink) {
|
||||||
updateStyle<MSVC_HINT(flexShrink)>(
|
updateStyle<MSVC_HINT(flexShrink)>(
|
||||||
node, &Style::flexShrink, FloatOptional{flexShrink});
|
node, &Style::flexShrink, YGFloatOptional{flexShrink});
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) {
|
YOGA_EXPORT YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) {
|
||||||
@@ -756,7 +756,7 @@ YOGA_EXPORT YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge) {
|
|||||||
return static_cast<const yoga::Node*>(node)->getStyle().padding()[edge];
|
return static_cast<const yoga::Node*>(node)->getStyle().padding()[edge];
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(T26792433): Change the API to accept FloatOptional.
|
// TODO(T26792433): Change the API to accept YGFloatOptional.
|
||||||
YOGA_EXPORT void YGNodeStyleSetBorder(
|
YOGA_EXPORT void YGNodeStyleSetBorder(
|
||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const YGEdge edge,
|
const YGEdge edge,
|
||||||
@@ -771,7 +771,7 @@ YOGA_EXPORT float YGNodeStyleGetBorder(
|
|||||||
auto border = static_cast<const yoga::Node*>(node)->getStyle().border()[edge];
|
auto border = static_cast<const yoga::Node*>(node)->getStyle().border()[edge];
|
||||||
if (border.isUndefined() || border.isAuto()) {
|
if (border.isUndefined() || border.isAuto()) {
|
||||||
// TODO(T26792433): Rather than returning YGUndefined, change the api to
|
// TODO(T26792433): Rather than returning YGUndefined, change the api to
|
||||||
// return FloatOptional.
|
// return YGFloatOptional.
|
||||||
return YGUndefined;
|
return YGUndefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -793,7 +793,7 @@ YOGA_EXPORT float YGNodeStyleGetGap(
|
|||||||
static_cast<const yoga::Node*>(node)->getStyle().gap()[gutter];
|
static_cast<const yoga::Node*>(node)->getStyle().gap()[gutter];
|
||||||
if (gapLength.isUndefined() || gapLength.isAuto()) {
|
if (gapLength.isUndefined() || gapLength.isAuto()) {
|
||||||
// TODO(T26792433): Rather than returning YGUndefined, change the api to
|
// TODO(T26792433): Rather than returning YGUndefined, change the api to
|
||||||
// return FloatOptional.
|
// return YGFloatOptional.
|
||||||
return YGUndefined;
|
return YGUndefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -802,19 +802,19 @@ YOGA_EXPORT float YGNodeStyleGetGap(
|
|||||||
|
|
||||||
// Yoga specific properties, not compatible with flexbox specification
|
// Yoga specific properties, not compatible with flexbox specification
|
||||||
|
|
||||||
// TODO(T26792433): Change the API to accept FloatOptional.
|
// TODO(T26792433): Change the API to accept YGFloatOptional.
|
||||||
YOGA_EXPORT float YGNodeStyleGetAspectRatio(const YGNodeConstRef node) {
|
YOGA_EXPORT float YGNodeStyleGetAspectRatio(const YGNodeConstRef node) {
|
||||||
const FloatOptional op =
|
const YGFloatOptional op =
|
||||||
static_cast<const yoga::Node*>(node)->getStyle().aspectRatio();
|
static_cast<const yoga::Node*>(node)->getStyle().aspectRatio();
|
||||||
return op.isUndefined() ? YGUndefined : op.unwrap();
|
return op.isUndefined() ? YGUndefined : op.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(T26792433): Change the API to accept FloatOptional.
|
// TODO(T26792433): Change the API to accept YGFloatOptional.
|
||||||
YOGA_EXPORT void YGNodeStyleSetAspectRatio(
|
YOGA_EXPORT void YGNodeStyleSetAspectRatio(
|
||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const float aspectRatio) {
|
const float aspectRatio) {
|
||||||
updateStyle<MSVC_HINT(aspectRatio)>(
|
updateStyle<MSVC_HINT(aspectRatio)>(
|
||||||
node, &Style::aspectRatio, FloatOptional{aspectRatio});
|
node, &Style::aspectRatio, YGFloatOptional{aspectRatio});
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetWidth(YGNodeRef node, float points) {
|
YOGA_EXPORT void YGNodeStyleSetWidth(YGNodeRef node, float points) {
|
||||||
@@ -1150,13 +1150,13 @@ static inline bool YGNodeIsLayoutDimDefined(
|
|||||||
return !YGFloatIsUndefined(value) && value >= 0.0f;
|
return !YGFloatIsUndefined(value) && value >= 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FloatOptional YGNodeBoundAxisWithinMinAndMax(
|
static YGFloatOptional YGNodeBoundAxisWithinMinAndMax(
|
||||||
const yoga::Node* const node,
|
const yoga::Node* const node,
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const FloatOptional value,
|
const YGFloatOptional value,
|
||||||
const float axisSize) {
|
const float axisSize) {
|
||||||
FloatOptional min;
|
YGFloatOptional min;
|
||||||
FloatOptional max;
|
YGFloatOptional max;
|
||||||
|
|
||||||
if (isColumn(axis)) {
|
if (isColumn(axis)) {
|
||||||
min = yoga::resolveValue(
|
min = yoga::resolveValue(
|
||||||
@@ -1170,11 +1170,11 @@ static FloatOptional YGNodeBoundAxisWithinMinAndMax(
|
|||||||
node->getStyle().maxDimensions()[YGDimensionWidth], axisSize);
|
node->getStyle().maxDimensions()[YGDimensionWidth], axisSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (max >= FloatOptional{0} && value > max) {
|
if (max >= YGFloatOptional{0} && value > max) {
|
||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (min >= FloatOptional{0} && value < min) {
|
if (min >= YGFloatOptional{0} && value < min) {
|
||||||
return min;
|
return min;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1190,7 +1190,8 @@ static inline float YGNodeBoundAxis(
|
|||||||
const float axisSize,
|
const float axisSize,
|
||||||
const float widthSize) {
|
const float widthSize) {
|
||||||
return yoga::maxOrDefined(
|
return yoga::maxOrDefined(
|
||||||
YGNodeBoundAxisWithinMinAndMax(node, axis, FloatOptional{value}, axisSize)
|
YGNodeBoundAxisWithinMinAndMax(
|
||||||
|
node, axis, YGFloatOptional{value}, axisSize)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
YGNodePaddingAndBorderForAxis(node, axis, widthSize));
|
YGNodePaddingAndBorderForAxis(node, axis, widthSize));
|
||||||
}
|
}
|
||||||
@@ -1213,10 +1214,10 @@ static void YGConstrainMaxSizeForMode(
|
|||||||
const float ownerWidth,
|
const float ownerWidth,
|
||||||
YGMeasureMode* mode,
|
YGMeasureMode* mode,
|
||||||
float* size) {
|
float* size) {
|
||||||
const FloatOptional maxSize =
|
const YGFloatOptional maxSize =
|
||||||
yoga::resolveValue(
|
yoga::resolveValue(
|
||||||
node->getStyle().maxDimensions()[dim[axis]], ownerAxisSize) +
|
node->getStyle().maxDimensions()[dim[axis]], ownerAxisSize) +
|
||||||
FloatOptional(node->getMarginForAxis(axis, ownerWidth));
|
YGFloatOptional(node->getMarginForAxis(axis, ownerWidth));
|
||||||
switch (*mode) {
|
switch (*mode) {
|
||||||
case YGMeasureModeExactly:
|
case YGMeasureModeExactly:
|
||||||
case YGMeasureModeAtMost:
|
case YGMeasureModeAtMost:
|
||||||
@@ -1259,7 +1260,7 @@ static void YGNodeComputeFlexBasisForChild(
|
|||||||
YGMeasureMode childWidthMeasureMode;
|
YGMeasureMode childWidthMeasureMode;
|
||||||
YGMeasureMode childHeightMeasureMode;
|
YGMeasureMode childHeightMeasureMode;
|
||||||
|
|
||||||
const FloatOptional resolvedFlexBasis =
|
const YGFloatOptional resolvedFlexBasis =
|
||||||
yoga::resolveValue(child->resolveFlexBasisPtr(), mainAxisownerSize);
|
yoga::resolveValue(child->resolveFlexBasisPtr(), mainAxisownerSize);
|
||||||
const bool isRowStyleDimDefined =
|
const bool isRowStyleDimDefined =
|
||||||
YGNodeIsStyleDimDefined(child, YGFlexDirectionRow, ownerWidth);
|
YGNodeIsStyleDimDefined(child, YGFlexDirectionRow, ownerWidth);
|
||||||
@@ -1271,14 +1272,14 @@ static void YGNodeComputeFlexBasisForChild(
|
|||||||
(child->getConfig()->isExperimentalFeatureEnabled(
|
(child->getConfig()->isExperimentalFeatureEnabled(
|
||||||
YGExperimentalFeatureWebFlexBasis) &&
|
YGExperimentalFeatureWebFlexBasis) &&
|
||||||
child->getLayout().computedFlexBasisGeneration != generationCount)) {
|
child->getLayout().computedFlexBasisGeneration != generationCount)) {
|
||||||
const FloatOptional paddingAndBorder = FloatOptional(
|
const YGFloatOptional paddingAndBorder = YGFloatOptional(
|
||||||
YGNodePaddingAndBorderForAxis(child, mainAxis, ownerWidth));
|
YGNodePaddingAndBorderForAxis(child, mainAxis, ownerWidth));
|
||||||
child->setLayoutComputedFlexBasis(
|
child->setLayoutComputedFlexBasis(
|
||||||
yoga::maxOrDefined(resolvedFlexBasis, paddingAndBorder));
|
yoga::maxOrDefined(resolvedFlexBasis, paddingAndBorder));
|
||||||
}
|
}
|
||||||
} else if (isMainAxisRow && isRowStyleDimDefined) {
|
} else if (isMainAxisRow && isRowStyleDimDefined) {
|
||||||
// The width is definite, so use that as the flex basis.
|
// The width is definite, so use that as the flex basis.
|
||||||
const FloatOptional paddingAndBorder = FloatOptional(
|
const YGFloatOptional paddingAndBorder = YGFloatOptional(
|
||||||
YGNodePaddingAndBorderForAxis(child, YGFlexDirectionRow, ownerWidth));
|
YGNodePaddingAndBorderForAxis(child, YGFlexDirectionRow, ownerWidth));
|
||||||
|
|
||||||
child->setLayoutComputedFlexBasis(yoga::maxOrDefined(
|
child->setLayoutComputedFlexBasis(yoga::maxOrDefined(
|
||||||
@@ -1287,8 +1288,8 @@ static void YGNodeComputeFlexBasisForChild(
|
|||||||
paddingAndBorder));
|
paddingAndBorder));
|
||||||
} else if (!isMainAxisRow && isColumnStyleDimDefined) {
|
} else if (!isMainAxisRow && isColumnStyleDimDefined) {
|
||||||
// The height is definite, so use that as the flex basis.
|
// The height is definite, so use that as the flex basis.
|
||||||
const FloatOptional paddingAndBorder =
|
const YGFloatOptional paddingAndBorder =
|
||||||
FloatOptional(YGNodePaddingAndBorderForAxis(
|
YGFloatOptional(YGNodePaddingAndBorderForAxis(
|
||||||
child, YGFlexDirectionColumn, ownerWidth));
|
child, YGFlexDirectionColumn, ownerWidth));
|
||||||
child->setLayoutComputedFlexBasis(yoga::maxOrDefined(
|
child->setLayoutComputedFlexBasis(yoga::maxOrDefined(
|
||||||
yoga::resolveValue(
|
yoga::resolveValue(
|
||||||
@@ -1425,7 +1426,7 @@ static void YGNodeComputeFlexBasisForChild(
|
|||||||
depth,
|
depth,
|
||||||
generationCount);
|
generationCount);
|
||||||
|
|
||||||
child->setLayoutComputedFlexBasis(FloatOptional(yoga::maxOrDefined(
|
child->setLayoutComputedFlexBasis(YGFloatOptional(yoga::maxOrDefined(
|
||||||
child->getLayout().measuredDimensions[dim[mainAxis]],
|
child->getLayout().measuredDimensions[dim[mainAxis]],
|
||||||
YGNodePaddingAndBorderForAxis(child, mainAxis, ownerWidth))));
|
YGNodePaddingAndBorderForAxis(child, mainAxis, ownerWidth))));
|
||||||
}
|
}
|
||||||
@@ -1875,13 +1876,13 @@ static float YGNodeCalculateAvailableInnerDim(
|
|||||||
if (!YGFloatIsUndefined(availableInnerDim)) {
|
if (!YGFloatIsUndefined(availableInnerDim)) {
|
||||||
// We want to make sure our available height does not violate min and max
|
// We want to make sure our available height does not violate min and max
|
||||||
// constraints
|
// constraints
|
||||||
const FloatOptional minDimensionOptional = yoga::resolveValue(
|
const YGFloatOptional minDimensionOptional = yoga::resolveValue(
|
||||||
node->getStyle().minDimensions()[dimension], ownerDim);
|
node->getStyle().minDimensions()[dimension], ownerDim);
|
||||||
const float minInnerDim = minDimensionOptional.isUndefined()
|
const float minInnerDim = minDimensionOptional.isUndefined()
|
||||||
? 0.0f
|
? 0.0f
|
||||||
: minDimensionOptional.unwrap() - paddingAndBorder;
|
: minDimensionOptional.unwrap() - paddingAndBorder;
|
||||||
|
|
||||||
const FloatOptional maxDimensionOptional = yoga::resolveValue(
|
const YGFloatOptional maxDimensionOptional = yoga::resolveValue(
|
||||||
node->getStyle().maxDimensions()[dimension], ownerDim);
|
node->getStyle().maxDimensions()[dimension], ownerDim);
|
||||||
|
|
||||||
const float maxInnerDim = maxDimensionOptional.isUndefined()
|
const float maxInnerDim = maxDimensionOptional.isUndefined()
|
||||||
@@ -1957,7 +1958,7 @@ static float YGNodeComputeFlexBasisForChildren(
|
|||||||
}
|
}
|
||||||
if (child == singleFlexChild) {
|
if (child == singleFlexChild) {
|
||||||
child->setLayoutComputedFlexBasisGeneration(generationCount);
|
child->setLayoutComputedFlexBasisGeneration(generationCount);
|
||||||
child->setLayoutComputedFlexBasis(FloatOptional(0));
|
child->setLayoutComputedFlexBasis(YGFloatOptional(0));
|
||||||
} else {
|
} else {
|
||||||
YGNodeComputeFlexBasisForChild(
|
YGNodeComputeFlexBasisForChild(
|
||||||
node,
|
node,
|
||||||
@@ -3521,7 +3522,7 @@ static void YGNodelayoutImpl(
|
|||||||
YGNodeBoundAxisWithinMinAndMax(
|
YGNodeBoundAxisWithinMinAndMax(
|
||||||
node,
|
node,
|
||||||
mainAxis,
|
mainAxis,
|
||||||
FloatOptional{maxLineMainDim},
|
YGFloatOptional{maxLineMainDim},
|
||||||
mainAxisownerSize)
|
mainAxisownerSize)
|
||||||
.unwrap()),
|
.unwrap()),
|
||||||
paddingAndBorderAxisMain),
|
paddingAndBorderAxisMain),
|
||||||
@@ -3552,7 +3553,7 @@ static void YGNodelayoutImpl(
|
|||||||
YGNodeBoundAxisWithinMinAndMax(
|
YGNodeBoundAxisWithinMinAndMax(
|
||||||
node,
|
node,
|
||||||
crossAxis,
|
crossAxis,
|
||||||
FloatOptional{
|
YGFloatOptional{
|
||||||
totalLineCrossDim + paddingAndBorderAxisCross},
|
totalLineCrossDim + paddingAndBorderAxisCross},
|
||||||
crossAxisownerSize)
|
crossAxisownerSize)
|
||||||
.unwrap()),
|
.unwrap()),
|
||||||
|
@@ -8,22 +8,24 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
#include <yoga/numeric/FloatOptional.h>
|
#include <yoga/YGFloatOptional.h>
|
||||||
|
|
||||||
namespace facebook::yoga {
|
namespace facebook::yoga {
|
||||||
|
|
||||||
inline FloatOptional resolveValue(const YGValue value, const float ownerSize) {
|
inline YGFloatOptional resolveValue(
|
||||||
|
const YGValue value,
|
||||||
|
const float ownerSize) {
|
||||||
switch (value.unit) {
|
switch (value.unit) {
|
||||||
case YGUnitPoint:
|
case YGUnitPoint:
|
||||||
return FloatOptional{value.value};
|
return YGFloatOptional{value.value};
|
||||||
case YGUnitPercent:
|
case YGUnitPercent:
|
||||||
return FloatOptional{value.value * ownerSize * 0.01f};
|
return YGFloatOptional{value.value * ownerSize * 0.01f};
|
||||||
default:
|
default:
|
||||||
return FloatOptional{};
|
return YGFloatOptional{};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline FloatOptional resolveValue(CompactValue value, float ownerSize) {
|
inline YGFloatOptional resolveValue(CompactValue value, float ownerSize) {
|
||||||
return resolveValue((YGValue) value, ownerSize);
|
return resolveValue((YGValue) value, ownerSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -45,7 +45,7 @@ static void appendFormattedString(std::string& str, const char* fmt, ...) {
|
|||||||
static void appendFloatOptionalIfDefined(
|
static void appendFloatOptionalIfDefined(
|
||||||
std::string& base,
|
std::string& base,
|
||||||
const std::string key,
|
const std::string key,
|
||||||
const FloatOptional num) {
|
const YGFloatOptional num) {
|
||||||
if (!num.isUndefined()) {
|
if (!num.isUndefined()) {
|
||||||
appendFormattedString(base, "%s: %g; ", key.c_str(), num.unwrap());
|
appendFormattedString(base, "%s: %g; ", key.c_str(), num.unwrap());
|
||||||
}
|
}
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <yoga/BitUtils.h>
|
#include <yoga/BitUtils.h>
|
||||||
#include <yoga/numeric/FloatOptional.h>
|
#include <yoga/YGFloatOptional.h>
|
||||||
#include <yoga/Yoga-internal.h>
|
#include <yoga/Yoga-internal.h>
|
||||||
|
|
||||||
namespace facebook::yoga {
|
namespace facebook::yoga {
|
||||||
@@ -28,7 +28,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
uint32_t computedFlexBasisGeneration = 0;
|
uint32_t computedFlexBasisGeneration = 0;
|
||||||
FloatOptional computedFlexBasis = {};
|
YGFloatOptional computedFlexBasis = {};
|
||||||
|
|
||||||
// Instead of recomputing the entire layout every single time, we cache some
|
// Instead of recomputing the entire layout every single time, we cache some
|
||||||
// information to break early when nothing changed
|
// information to break early when nothing changed
|
||||||
|
@@ -110,7 +110,7 @@ CompactValue Node::computeColumnGap(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FloatOptional Node::getLeadingPosition(
|
YGFloatOptional Node::getLeadingPosition(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float axisSize) const {
|
const float axisSize) const {
|
||||||
auto leadingPosition = isRow(axis)
|
auto leadingPosition = isRow(axis)
|
||||||
@@ -124,7 +124,7 @@ FloatOptional Node::getLeadingPosition(
|
|||||||
return yoga::resolveValue(leadingPosition, axisSize);
|
return yoga::resolveValue(leadingPosition, axisSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
FloatOptional Node::getTrailingPosition(
|
YGFloatOptional Node::getTrailingPosition(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float axisSize) const {
|
const float axisSize) const {
|
||||||
auto trailingPosition = isRow(axis)
|
auto trailingPosition = isRow(axis)
|
||||||
@@ -162,7 +162,7 @@ bool Node::isTrailingPosDefined(const YGFlexDirection axis) const {
|
|||||||
return !trailingPosition.isUndefined();
|
return !trailingPosition.isUndefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
FloatOptional Node::getLeadingMargin(
|
YGFloatOptional Node::getLeadingMargin(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const {
|
const float widthSize) const {
|
||||||
auto leadingMargin = isRow(axis)
|
auto leadingMargin = isRow(axis)
|
||||||
@@ -170,11 +170,11 @@ FloatOptional Node::getLeadingMargin(
|
|||||||
style_.margin(), YGEdgeStart, leading[axis], CompactValue::ofZero())
|
style_.margin(), YGEdgeStart, leading[axis], CompactValue::ofZero())
|
||||||
: computeEdgeValueForColumn(
|
: computeEdgeValueForColumn(
|
||||||
style_.margin(), leading[axis], CompactValue::ofZero());
|
style_.margin(), leading[axis], CompactValue::ofZero());
|
||||||
return leadingMargin.isAuto() ? FloatOptional{0}
|
return leadingMargin.isAuto() ? YGFloatOptional{0}
|
||||||
: yoga::resolveValue(leadingMargin, widthSize);
|
: yoga::resolveValue(leadingMargin, widthSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
FloatOptional Node::getTrailingMargin(
|
YGFloatOptional Node::getTrailingMargin(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const {
|
const float widthSize) const {
|
||||||
auto trailingMargin = isRow(axis)
|
auto trailingMargin = isRow(axis)
|
||||||
@@ -183,17 +183,17 @@ FloatOptional Node::getTrailingMargin(
|
|||||||
: computeEdgeValueForColumn(
|
: computeEdgeValueForColumn(
|
||||||
style_.margin(), trailing[axis], CompactValue::ofZero());
|
style_.margin(), trailing[axis], CompactValue::ofZero());
|
||||||
return trailingMargin.isAuto()
|
return trailingMargin.isAuto()
|
||||||
? FloatOptional{0}
|
? YGFloatOptional{0}
|
||||||
: yoga::resolveValue(trailingMargin, widthSize);
|
: yoga::resolveValue(trailingMargin, widthSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
FloatOptional Node::getMarginForAxis(
|
YGFloatOptional Node::getMarginForAxis(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const {
|
const float widthSize) const {
|
||||||
return getLeadingMargin(axis, widthSize) + getTrailingMargin(axis, widthSize);
|
return getLeadingMargin(axis, widthSize) + getTrailingMargin(axis, widthSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
FloatOptional Node::getGapForAxis(
|
YGFloatOptional Node::getGapForAxis(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const {
|
const float widthSize) const {
|
||||||
auto gap = isRow(axis)
|
auto gap = isRow(axis)
|
||||||
@@ -325,7 +325,7 @@ void Node::setLayoutLastOwnerDirection(YGDirection direction) {
|
|||||||
layout_.lastOwnerDirection = direction;
|
layout_.lastOwnerDirection = direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::setLayoutComputedFlexBasis(const FloatOptional computedFlexBasis) {
|
void Node::setLayoutComputedFlexBasis(const YGFloatOptional computedFlexBasis) {
|
||||||
layout_.computedFlexBasis = computedFlexBasis;
|
layout_.computedFlexBasis = computedFlexBasis;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,16 +352,16 @@ void Node::setLayoutDimension(float dimension, int index) {
|
|||||||
|
|
||||||
// If both left and right are defined, then use left. Otherwise return +left or
|
// If both left and right are defined, then use left. Otherwise return +left or
|
||||||
// -right depending on which is defined.
|
// -right depending on which is defined.
|
||||||
FloatOptional Node::relativePosition(
|
YGFloatOptional Node::relativePosition(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float axisSize) const {
|
const float axisSize) const {
|
||||||
if (isLeadingPositionDefined(axis)) {
|
if (isLeadingPositionDefined(axis)) {
|
||||||
return getLeadingPosition(axis, axisSize);
|
return getLeadingPosition(axis, axisSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
FloatOptional trailingPosition = getTrailingPosition(axis, axisSize);
|
YGFloatOptional trailingPosition = getTrailingPosition(axis, axisSize);
|
||||||
if (!trailingPosition.isUndefined()) {
|
if (!trailingPosition.isUndefined()) {
|
||||||
trailingPosition = FloatOptional{-1 * trailingPosition.unwrap()};
|
trailingPosition = YGFloatOptional{-1 * trailingPosition.unwrap()};
|
||||||
}
|
}
|
||||||
return trailingPosition;
|
return trailingPosition;
|
||||||
}
|
}
|
||||||
@@ -383,9 +383,9 @@ void Node::setPosition(
|
|||||||
// Here we should check for `YGPositionTypeStatic` and in this case zero inset
|
// Here we should check for `YGPositionTypeStatic` and in this case zero inset
|
||||||
// properties (left, right, top, bottom, begin, end).
|
// properties (left, right, top, bottom, begin, end).
|
||||||
// https://www.w3.org/TR/css-position-3/#valdef-position-static
|
// https://www.w3.org/TR/css-position-3/#valdef-position-static
|
||||||
const FloatOptional relativePositionMain =
|
const YGFloatOptional relativePositionMain =
|
||||||
relativePosition(mainAxis, mainSize);
|
relativePosition(mainAxis, mainSize);
|
||||||
const FloatOptional relativePositionCross =
|
const YGFloatOptional relativePositionCross =
|
||||||
relativePosition(crossAxis, crossSize);
|
relativePosition(crossAxis, crossSize);
|
||||||
|
|
||||||
setLayoutPosition(
|
setLayoutPosition(
|
||||||
@@ -468,7 +468,7 @@ void Node::cloneChildrenIfNeeded(void* cloneContext) {
|
|||||||
void Node::markDirtyAndPropagate() {
|
void Node::markDirtyAndPropagate() {
|
||||||
if (!flags_.isDirty) {
|
if (!flags_.isDirty) {
|
||||||
setDirty(true);
|
setDirty(true);
|
||||||
setLayoutComputedFlexBasis(FloatOptional());
|
setLayoutComputedFlexBasis(YGFloatOptional());
|
||||||
if (owner_) {
|
if (owner_) {
|
||||||
owner_->markDirtyAndPropagate();
|
owner_->markDirtyAndPropagate();
|
||||||
}
|
}
|
||||||
@@ -534,7 +534,7 @@ float Node::getTrailingBorder(const YGFlexDirection axis) const {
|
|||||||
return fmaxf(trailingBorder.value, 0.0f);
|
return fmaxf(trailingBorder.value, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
FloatOptional Node::getLeadingPadding(
|
YGFloatOptional Node::getLeadingPadding(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const {
|
const float widthSize) const {
|
||||||
auto leadingPadding = isRow(axis)
|
auto leadingPadding = isRow(axis)
|
||||||
@@ -546,10 +546,10 @@ FloatOptional Node::getLeadingPadding(
|
|||||||
: computeEdgeValueForColumn(
|
: computeEdgeValueForColumn(
|
||||||
style_.padding(), leading[axis], CompactValue::ofZero());
|
style_.padding(), leading[axis], CompactValue::ofZero());
|
||||||
return yoga::maxOrDefined(
|
return yoga::maxOrDefined(
|
||||||
yoga::resolveValue(leadingPadding, widthSize), FloatOptional(0.0f));
|
yoga::resolveValue(leadingPadding, widthSize), YGFloatOptional(0.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
FloatOptional Node::getTrailingPadding(
|
YGFloatOptional Node::getTrailingPadding(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const {
|
const float widthSize) const {
|
||||||
auto trailingPadding = isRow(axis)
|
auto trailingPadding = isRow(axis)
|
||||||
@@ -558,21 +558,21 @@ FloatOptional Node::getTrailingPadding(
|
|||||||
: computeEdgeValueForColumn(
|
: computeEdgeValueForColumn(
|
||||||
style_.padding(), trailing[axis], CompactValue::ofZero());
|
style_.padding(), trailing[axis], CompactValue::ofZero());
|
||||||
return yoga::maxOrDefined(
|
return yoga::maxOrDefined(
|
||||||
yoga::resolveValue(trailingPadding, widthSize), FloatOptional(0.0f));
|
yoga::resolveValue(trailingPadding, widthSize), YGFloatOptional(0.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
FloatOptional Node::getLeadingPaddingAndBorder(
|
YGFloatOptional Node::getLeadingPaddingAndBorder(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const {
|
const float widthSize) const {
|
||||||
return getLeadingPadding(axis, widthSize) +
|
return getLeadingPadding(axis, widthSize) +
|
||||||
FloatOptional(getLeadingBorder(axis));
|
YGFloatOptional(getLeadingBorder(axis));
|
||||||
}
|
}
|
||||||
|
|
||||||
FloatOptional Node::getTrailingPaddingAndBorder(
|
YGFloatOptional Node::getTrailingPaddingAndBorder(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const {
|
const float widthSize) const {
|
||||||
return getTrailingPadding(axis, widthSize) +
|
return getTrailingPadding(axis, widthSize) +
|
||||||
FloatOptional(getTrailingBorder(axis));
|
YGFloatOptional(getTrailingBorder(axis));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::reset() {
|
void Node::reset() {
|
||||||
|
@@ -66,7 +66,7 @@ private:
|
|||||||
std::array<YGValue, 2> resolvedDimensions_ = {
|
std::array<YGValue, 2> resolvedDimensions_ = {
|
||||||
{YGValueUndefined, YGValueUndefined}};
|
{YGValueUndefined, YGValueUndefined}};
|
||||||
|
|
||||||
FloatOptional relativePosition(
|
YGFloatOptional relativePosition(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float axisSize) const;
|
const float axisSize) const;
|
||||||
|
|
||||||
@@ -203,39 +203,40 @@ public:
|
|||||||
CompactValue defaultValue);
|
CompactValue defaultValue);
|
||||||
|
|
||||||
// Methods related to positions, margin, padding and border
|
// Methods related to positions, margin, padding and border
|
||||||
FloatOptional getLeadingPosition(
|
YGFloatOptional getLeadingPosition(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float axisSize) const;
|
const float axisSize) const;
|
||||||
bool isLeadingPositionDefined(const YGFlexDirection axis) const;
|
bool isLeadingPositionDefined(const YGFlexDirection axis) const;
|
||||||
bool isTrailingPosDefined(const YGFlexDirection axis) const;
|
bool isTrailingPosDefined(const YGFlexDirection axis) const;
|
||||||
FloatOptional getTrailingPosition(
|
YGFloatOptional getTrailingPosition(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float axisSize) const;
|
const float axisSize) const;
|
||||||
FloatOptional getLeadingMargin(
|
YGFloatOptional getLeadingMargin(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const;
|
const float widthSize) const;
|
||||||
FloatOptional getTrailingMargin(
|
YGFloatOptional getTrailingMargin(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const;
|
const float widthSize) const;
|
||||||
float getLeadingBorder(const YGFlexDirection flexDirection) const;
|
float getLeadingBorder(const YGFlexDirection flexDirection) const;
|
||||||
float getTrailingBorder(const YGFlexDirection flexDirection) const;
|
float getTrailingBorder(const YGFlexDirection flexDirection) const;
|
||||||
FloatOptional getLeadingPadding(
|
YGFloatOptional getLeadingPadding(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const;
|
const float widthSize) const;
|
||||||
FloatOptional getTrailingPadding(
|
YGFloatOptional getTrailingPadding(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const;
|
const float widthSize) const;
|
||||||
FloatOptional getLeadingPaddingAndBorder(
|
YGFloatOptional getLeadingPaddingAndBorder(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const;
|
const float widthSize) const;
|
||||||
FloatOptional getTrailingPaddingAndBorder(
|
YGFloatOptional getTrailingPaddingAndBorder(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const;
|
const float widthSize) const;
|
||||||
FloatOptional getMarginForAxis(
|
YGFloatOptional getMarginForAxis(
|
||||||
|
const YGFlexDirection axis,
|
||||||
|
const float widthSize) const;
|
||||||
|
YGFloatOptional getGapForAxis(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const;
|
const float widthSize) const;
|
||||||
FloatOptional getGapForAxis(const YGFlexDirection axis, const float widthSize)
|
|
||||||
const;
|
|
||||||
// Setters
|
// Setters
|
||||||
|
|
||||||
void setContext(void* context) { context_ = context; }
|
void setContext(void* context) { context_ = context; }
|
||||||
@@ -298,7 +299,7 @@ public:
|
|||||||
|
|
||||||
void setDirty(bool isDirty);
|
void setDirty(bool isDirty);
|
||||||
void setLayoutLastOwnerDirection(YGDirection direction);
|
void setLayoutLastOwnerDirection(YGDirection direction);
|
||||||
void setLayoutComputedFlexBasis(const FloatOptional computedFlexBasis);
|
void setLayoutComputedFlexBasis(const YGFloatOptional computedFlexBasis);
|
||||||
void setLayoutComputedFlexBasisGeneration(
|
void setLayoutComputedFlexBasisGeneration(
|
||||||
uint32_t computedFlexBasisGeneration);
|
uint32_t computedFlexBasisGeneration);
|
||||||
void setLayoutMeasuredDimension(float measuredDimension, int index);
|
void setLayoutMeasuredDimension(float measuredDimension, int index);
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
#include <yoga/numeric/FloatOptional.h>
|
#include <yoga/YGFloatOptional.h>
|
||||||
#include <yoga/style/CompactValue.h>
|
#include <yoga/style/CompactValue.h>
|
||||||
|
|
||||||
namespace facebook::yoga {
|
namespace facebook::yoga {
|
||||||
@@ -30,7 +30,7 @@ inline float minOrDefined(const float a, const float b) {
|
|||||||
return std::isnan(a) ? b : a;
|
return std::isnan(a) ? b : a;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline FloatOptional maxOrDefined(FloatOptional op1, FloatOptional op2) {
|
inline YGFloatOptional maxOrDefined(YGFloatOptional op1, YGFloatOptional op2) {
|
||||||
if (op1 >= op2) {
|
if (op1 >= op2) {
|
||||||
return op1;
|
return op1;
|
||||||
}
|
}
|
||||||
|
@@ -1,74 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 <cmath>
|
|
||||||
#include <limits>
|
|
||||||
#include <yoga/Yoga-internal.h>
|
|
||||||
|
|
||||||
namespace facebook::yoga {
|
|
||||||
|
|
||||||
struct FloatOptional {
|
|
||||||
private:
|
|
||||||
float value_ = std::numeric_limits<float>::quiet_NaN();
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit constexpr FloatOptional(float value) : value_(value) {}
|
|
||||||
constexpr FloatOptional() = default;
|
|
||||||
|
|
||||||
// returns the wrapped value, or a value x with YGIsUndefined(x) == true
|
|
||||||
constexpr float unwrap() const { return value_; }
|
|
||||||
|
|
||||||
bool isUndefined() const { return std::isnan(value_); }
|
|
||||||
};
|
|
||||||
|
|
||||||
// operators take FloatOptional by value, as it is a 32bit value
|
|
||||||
|
|
||||||
inline bool operator==(FloatOptional lhs, FloatOptional rhs) {
|
|
||||||
return lhs.unwrap() == rhs.unwrap() ||
|
|
||||||
(lhs.isUndefined() && rhs.isUndefined());
|
|
||||||
}
|
|
||||||
inline bool operator!=(FloatOptional lhs, FloatOptional rhs) {
|
|
||||||
return !(lhs == rhs);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool operator==(FloatOptional lhs, float rhs) {
|
|
||||||
return lhs == FloatOptional{rhs};
|
|
||||||
}
|
|
||||||
inline bool operator!=(FloatOptional lhs, float rhs) {
|
|
||||||
return !(lhs == rhs);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool operator==(float lhs, FloatOptional rhs) {
|
|
||||||
return rhs == lhs;
|
|
||||||
}
|
|
||||||
inline bool operator!=(float lhs, FloatOptional rhs) {
|
|
||||||
return !(lhs == rhs);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline FloatOptional operator+(FloatOptional lhs, FloatOptional rhs) {
|
|
||||||
return FloatOptional{lhs.unwrap() + rhs.unwrap()};
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool operator>(FloatOptional lhs, FloatOptional rhs) {
|
|
||||||
return lhs.unwrap() > rhs.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool operator<(FloatOptional lhs, FloatOptional rhs) {
|
|
||||||
return lhs.unwrap() < rhs.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool operator>=(FloatOptional lhs, FloatOptional rhs) {
|
|
||||||
return lhs > rhs || lhs == rhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool operator<=(FloatOptional lhs, FloatOptional rhs) {
|
|
||||||
return lhs < rhs || lhs == rhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace facebook::yoga
|
|
@@ -13,10 +13,10 @@
|
|||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
|
#include <yoga/YGFloatOptional.h>
|
||||||
#include <yoga/Yoga-internal.h>
|
#include <yoga/Yoga-internal.h>
|
||||||
#include <yoga/BitUtils.h>
|
#include <yoga/BitUtils.h>
|
||||||
|
|
||||||
#include <yoga/numeric/FloatOptional.h>
|
|
||||||
#include <yoga/style/CompactValue.h>
|
#include <yoga/style/CompactValue.h>
|
||||||
|
|
||||||
namespace facebook::yoga {
|
namespace facebook::yoga {
|
||||||
@@ -105,9 +105,9 @@ private:
|
|||||||
|
|
||||||
uint32_t flags = 0;
|
uint32_t flags = 0;
|
||||||
|
|
||||||
FloatOptional flex_ = {};
|
YGFloatOptional flex_ = {};
|
||||||
FloatOptional flexGrow_ = {};
|
YGFloatOptional flexGrow_ = {};
|
||||||
FloatOptional flexShrink_ = {};
|
YGFloatOptional flexShrink_ = {};
|
||||||
CompactValue flexBasis_ = CompactValue::ofAuto();
|
CompactValue flexBasis_ = CompactValue::ofAuto();
|
||||||
Edges margin_ = {};
|
Edges margin_ = {};
|
||||||
Edges position_ = {};
|
Edges position_ = {};
|
||||||
@@ -118,7 +118,7 @@ private:
|
|||||||
Dimensions minDimensions_ = {};
|
Dimensions minDimensions_ = {};
|
||||||
Dimensions maxDimensions_ = {};
|
Dimensions maxDimensions_ = {};
|
||||||
// Yoga specific properties, not compatible with flexbox specification
|
// Yoga specific properties, not compatible with flexbox specification
|
||||||
FloatOptional aspectRatio_ = {};
|
YGFloatOptional aspectRatio_ = {};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// for library users needing a type
|
// for library users needing a type
|
||||||
@@ -187,14 +187,14 @@ public:
|
|||||||
}
|
}
|
||||||
BitfieldRef<YGDisplay> display() { return {*this, displayOffset}; }
|
BitfieldRef<YGDisplay> display() { return {*this, displayOffset}; }
|
||||||
|
|
||||||
FloatOptional flex() const { return flex_; }
|
YGFloatOptional flex() const { return flex_; }
|
||||||
Ref<FloatOptional, &Style::flex_> flex() { return {*this}; }
|
Ref<YGFloatOptional, &Style::flex_> flex() { return {*this}; }
|
||||||
|
|
||||||
FloatOptional flexGrow() const { return flexGrow_; }
|
YGFloatOptional flexGrow() const { return flexGrow_; }
|
||||||
Ref<FloatOptional, &Style::flexGrow_> flexGrow() { return {*this}; }
|
Ref<YGFloatOptional, &Style::flexGrow_> flexGrow() { return {*this}; }
|
||||||
|
|
||||||
FloatOptional flexShrink() const { return flexShrink_; }
|
YGFloatOptional flexShrink() const { return flexShrink_; }
|
||||||
Ref<FloatOptional, &Style::flexShrink_> flexShrink() { return {*this}; }
|
Ref<YGFloatOptional, &Style::flexShrink_> flexShrink() { return {*this}; }
|
||||||
|
|
||||||
CompactValue flexBasis() const { return flexBasis_; }
|
CompactValue flexBasis() const { return flexBasis_; }
|
||||||
Ref<CompactValue, &Style::flexBasis_> flexBasis() { return {*this}; }
|
Ref<CompactValue, &Style::flexBasis_> flexBasis() { return {*this}; }
|
||||||
@@ -228,8 +228,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Yoga specific properties, not compatible with flexbox specification
|
// Yoga specific properties, not compatible with flexbox specification
|
||||||
FloatOptional aspectRatio() const { return aspectRatio_; }
|
YGFloatOptional aspectRatio() const { return aspectRatio_; }
|
||||||
Ref<FloatOptional, &Style::aspectRatio_> aspectRatio() { return {*this}; }
|
Ref<YGFloatOptional, &Style::aspectRatio_> aspectRatio() { return {*this}; }
|
||||||
};
|
};
|
||||||
|
|
||||||
YOGA_EXPORT bool operator==(const Style& lhs, const Style& rhs);
|
YOGA_EXPORT bool operator==(const Style& lhs, const Style& rhs);
|
||||||
|
Reference in New Issue
Block a user