C++ Cleanup 6/N: YGFloatOptional (#1356)
Summary: X-link: https://github.com/facebook/react-native/pull/39224 Pull Request resolved: https://github.com/facebook/yoga/pull/1356 X-link: https://github.com/facebook/react-native/pull/39196 ## This diff This renames YGFloatOptional to FloatOptional, adds it to a namespace, and moves it to a subdirectory. This needs Fabric updates because Fabric uses Yoga internals for props storage. ## This stack The organization of the C++ internals of Yoga are in need of attention. 1. Some of the C++ internals are namespaced, but others not. 2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these) 2. Most of the files are in a flat hierarchy, except for event tracing in its own folder 3. Some files and functions begin with YG, others don’t 4. Some functions are uppercase, others are not 5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about 6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h) 7. There is no clear indication from file structure or type naming what is private vs not 8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers This stack does some much needed spring cleaning: 1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy 3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended 4. Utils files are split 5. Most C++ internals drop the YG prefix 6. Most C++ internal function names are all lower camel case 7. We start to split up Yoga.cpp 8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings 9. It is not possible to use private APIs without static casting handles to internal classes This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well. These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer. Changelog: [Internal] bypass-github-export-checks Reviewed By: shwanton Differential Revision: D48847256 fbshipit-source-id: ab9729a4a02ab90d974183425935f4d274db5732
This commit is contained in:
committed by
Facebook GitHub Bot
parent
c029041707
commit
989f352e03
@@ -8,18 +8,19 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include <yoga/numeric/Comparison.h>
|
#include <yoga/numeric/Comparison.h>
|
||||||
#include <yoga/YGFloatOptional.h>
|
#include <yoga/numeric/FloatOptional.h>
|
||||||
#include <yoga/YGValue.h>
|
#include <yoga/YGValue.h>
|
||||||
|
|
||||||
using namespace facebook;
|
using namespace facebook;
|
||||||
|
using namespace facebook::yoga;
|
||||||
|
|
||||||
constexpr auto empty = YGFloatOptional{};
|
constexpr auto empty = FloatOptional{};
|
||||||
constexpr auto zero = YGFloatOptional{0.0f};
|
constexpr auto zero = FloatOptional{0.0f};
|
||||||
constexpr auto one = YGFloatOptional{1.0f};
|
constexpr auto one = FloatOptional{1.0f};
|
||||||
constexpr auto positive = YGFloatOptional{1234.5f};
|
constexpr auto positive = FloatOptional{1234.5f};
|
||||||
constexpr auto negative = YGFloatOptional{-9876.5f};
|
constexpr auto negative = FloatOptional{-9876.5f};
|
||||||
|
|
||||||
TEST(YGFloatOptional, value) {
|
TEST(FloatOptional, 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);
|
||||||
@@ -33,7 +34,7 @@ TEST(YGFloatOptional, value) {
|
|||||||
ASSERT_FALSE(negative.isUndefined());
|
ASSERT_FALSE(negative.isUndefined());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(YGFloatOptional, equality) {
|
TEST(FloatOptional, 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);
|
||||||
@@ -58,7 +59,7 @@ TEST(YGFloatOptional, equality) {
|
|||||||
ASSERT_FALSE(negative == zero);
|
ASSERT_FALSE(negative == zero);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(YGFloatOptional, inequality) {
|
TEST(FloatOptional, 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);
|
||||||
@@ -83,7 +84,7 @@ TEST(YGFloatOptional, inequality) {
|
|||||||
ASSERT_TRUE(negative != zero);
|
ASSERT_TRUE(negative != zero);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(YGFloatOptional, greater_than_with_undefined) {
|
TEST(FloatOptional, 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);
|
||||||
@@ -95,7 +96,7 @@ TEST(YGFloatOptional, greater_than_with_undefined) {
|
|||||||
ASSERT_FALSE(negative > empty);
|
ASSERT_FALSE(negative > empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(YGFloatOptional, greater_than) {
|
TEST(FloatOptional, 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);
|
||||||
@@ -105,10 +106,10 @@ TEST(YGFloatOptional, greater_than) {
|
|||||||
ASSERT_TRUE(one > zero);
|
ASSERT_TRUE(one > zero);
|
||||||
ASSERT_FALSE(one > positive);
|
ASSERT_FALSE(one > positive);
|
||||||
|
|
||||||
ASSERT_TRUE(negative > YGFloatOptional{-INFINITY});
|
ASSERT_TRUE(negative > FloatOptional{-INFINITY});
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(YGFloatOptional, less_than_with_undefined) {
|
TEST(FloatOptional, 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);
|
||||||
@@ -120,7 +121,7 @@ TEST(YGFloatOptional, less_than_with_undefined) {
|
|||||||
ASSERT_FALSE(empty < negative);
|
ASSERT_FALSE(empty < negative);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(YGFloatOptional, less_than) {
|
TEST(FloatOptional, 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);
|
||||||
@@ -130,10 +131,10 @@ TEST(YGFloatOptional, less_than) {
|
|||||||
ASSERT_TRUE(zero < one);
|
ASSERT_TRUE(zero < one);
|
||||||
ASSERT_FALSE(positive < one);
|
ASSERT_FALSE(positive < one);
|
||||||
|
|
||||||
ASSERT_TRUE(YGFloatOptional{-INFINITY} < negative);
|
ASSERT_TRUE(FloatOptional{-INFINITY} < negative);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(YGFloatOptional, greater_than_equals_with_undefined) {
|
TEST(FloatOptional, 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);
|
||||||
@@ -145,7 +146,7 @@ TEST(YGFloatOptional, greater_than_equals_with_undefined) {
|
|||||||
ASSERT_FALSE(negative >= empty);
|
ASSERT_FALSE(negative >= empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(YGFloatOptional, greater_than_equals) {
|
TEST(FloatOptional, 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);
|
||||||
@@ -155,10 +156,10 @@ TEST(YGFloatOptional, greater_than_equals) {
|
|||||||
ASSERT_TRUE(one >= zero);
|
ASSERT_TRUE(one >= zero);
|
||||||
ASSERT_FALSE(one >= positive);
|
ASSERT_FALSE(one >= positive);
|
||||||
|
|
||||||
ASSERT_TRUE(negative >= YGFloatOptional{-INFINITY});
|
ASSERT_TRUE(negative >= FloatOptional{-INFINITY});
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(YGFloatOptional, less_than_equals_with_undefined) {
|
TEST(FloatOptional, 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);
|
||||||
@@ -170,7 +171,7 @@ TEST(YGFloatOptional, less_than_equals_with_undefined) {
|
|||||||
ASSERT_FALSE(empty <= negative);
|
ASSERT_FALSE(empty <= negative);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(YGFloatOptional, less_than_equals) {
|
TEST(FloatOptional, 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);
|
||||||
@@ -180,32 +181,32 @@ TEST(YGFloatOptional, less_than_equals) {
|
|||||||
ASSERT_TRUE(zero <= one);
|
ASSERT_TRUE(zero <= one);
|
||||||
ASSERT_FALSE(positive <= one);
|
ASSERT_FALSE(positive <= one);
|
||||||
|
|
||||||
ASSERT_TRUE(YGFloatOptional{-INFINITY} <= negative);
|
ASSERT_TRUE(FloatOptional{-INFINITY} <= negative);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(YGFloatOptional, addition) {
|
TEST(FloatOptional, 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, YGFloatOptional{n + p});
|
ASSERT_EQ(negative + positive, FloatOptional{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(YGFloatOptionalTest, maxOrDefined) {
|
TEST(YGFloatOptiona, 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, YGFloatOptional{-INFINITY}), negative);
|
ASSERT_EQ(yoga::maxOrDefined(negative, FloatOptional{-INFINITY}), negative);
|
||||||
ASSERT_EQ(
|
ASSERT_EQ(
|
||||||
yoga::maxOrDefined(YGFloatOptional{1.0f}, YGFloatOptional{1.125f}),
|
yoga::maxOrDefined(FloatOptional{1.0f}, FloatOptional{1.125f}),
|
||||||
YGFloatOptional{1.125f});
|
FloatOptional{1.125f});
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(YGFloatOptionalTest, unwrap) {
|
TEST(FloatOptional, 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(YGFloatOptional{123456.78f}.unwrap(), 123456.78f);
|
ASSERT_EQ(FloatOptional{123456.78f}.unwrap(), 123456.78f);
|
||||||
}
|
}
|
@@ -154,24 +154,24 @@ ACCESSOR_TEST(display, YGDisplayFlex, YGDisplayNone, YGDisplayFlex)
|
|||||||
|
|
||||||
ACCESSOR_TEST(
|
ACCESSOR_TEST(
|
||||||
flex,
|
flex,
|
||||||
YGFloatOptional{},
|
FloatOptional{},
|
||||||
YGFloatOptional{123.45f},
|
FloatOptional{123.45f},
|
||||||
YGFloatOptional{-9.87f},
|
FloatOptional{-9.87f},
|
||||||
YGFloatOptional{})
|
FloatOptional{})
|
||||||
|
|
||||||
ACCESSOR_TEST(
|
ACCESSOR_TEST(
|
||||||
flexGrow,
|
flexGrow,
|
||||||
YGFloatOptional{},
|
FloatOptional{},
|
||||||
YGFloatOptional{123.45f},
|
FloatOptional{123.45f},
|
||||||
YGFloatOptional{-9.87f},
|
FloatOptional{-9.87f},
|
||||||
YGFloatOptional{})
|
FloatOptional{})
|
||||||
|
|
||||||
ACCESSOR_TEST(
|
ACCESSOR_TEST(
|
||||||
flexShrink,
|
flexShrink,
|
||||||
YGFloatOptional{},
|
FloatOptional{},
|
||||||
YGFloatOptional{123.45f},
|
FloatOptional{123.45f},
|
||||||
YGFloatOptional{-9.87f},
|
FloatOptional{-9.87f},
|
||||||
YGFloatOptional{})
|
FloatOptional{})
|
||||||
|
|
||||||
ACCESSOR_TEST(
|
ACCESSOR_TEST(
|
||||||
flexBasis,
|
flexBasis,
|
||||||
@@ -243,11 +243,11 @@ INDEX_ACCESSOR_TEST(
|
|||||||
|
|
||||||
ACCESSOR_TEST(
|
ACCESSOR_TEST(
|
||||||
aspectRatio,
|
aspectRatio,
|
||||||
YGFloatOptional{},
|
FloatOptional{},
|
||||||
YGFloatOptional{-123.45f},
|
FloatOptional{-123.45f},
|
||||||
YGFloatOptional{9876.5f},
|
FloatOptional{9876.5f},
|
||||||
YGFloatOptional{0.0f},
|
FloatOptional{0.0f},
|
||||||
YGFloatOptional{});
|
FloatOptional{});
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -1,70 +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>
|
|
||||||
|
|
||||||
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 YGFloatOptional.
|
// TODO(T26792433): Change the API to accept FloatOptional.
|
||||||
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, YGFloatOptional{flex});
|
updateStyle<MSVC_HINT(flex)>(node, &Style::flex, FloatOptional{flex});
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(T26792433): Change the API to accept YGFloatOptional.
|
// TODO(T26792433): Change the API to accept FloatOptional.
|
||||||
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 YGFloatOptional.
|
// TODO(T26792433): Change the API to accept FloatOptional.
|
||||||
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, YGFloatOptional{flexGrow});
|
node, &Style::flexGrow, FloatOptional{flexGrow});
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(T26792433): Change the API to accept YGFloatOptional.
|
// TODO(T26792433): Change the API to accept FloatOptional.
|
||||||
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, YGFloatOptional{flexShrink});
|
node, &Style::flexShrink, FloatOptional{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 YGFloatOptional.
|
// TODO(T26792433): Change the API to accept FloatOptional.
|
||||||
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 YGFloatOptional.
|
// return FloatOptional.
|
||||||
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 YGFloatOptional.
|
// return FloatOptional.
|
||||||
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 YGFloatOptional.
|
// TODO(T26792433): Change the API to accept FloatOptional.
|
||||||
YOGA_EXPORT float YGNodeStyleGetAspectRatio(const YGNodeConstRef node) {
|
YOGA_EXPORT float YGNodeStyleGetAspectRatio(const YGNodeConstRef node) {
|
||||||
const YGFloatOptional op =
|
const FloatOptional 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 YGFloatOptional.
|
// TODO(T26792433): Change the API to accept FloatOptional.
|
||||||
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, YGFloatOptional{aspectRatio});
|
node, &Style::aspectRatio, FloatOptional{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 YGFloatOptional YGNodeBoundAxisWithinMinAndMax(
|
static FloatOptional YGNodeBoundAxisWithinMinAndMax(
|
||||||
const yoga::Node* const node,
|
const yoga::Node* const node,
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const YGFloatOptional value,
|
const FloatOptional value,
|
||||||
const float axisSize) {
|
const float axisSize) {
|
||||||
YGFloatOptional min;
|
FloatOptional min;
|
||||||
YGFloatOptional max;
|
FloatOptional max;
|
||||||
|
|
||||||
if (isColumn(axis)) {
|
if (isColumn(axis)) {
|
||||||
min = yoga::resolveValue(
|
min = yoga::resolveValue(
|
||||||
@@ -1170,11 +1170,11 @@ static YGFloatOptional YGNodeBoundAxisWithinMinAndMax(
|
|||||||
node->getStyle().maxDimensions()[YGDimensionWidth], axisSize);
|
node->getStyle().maxDimensions()[YGDimensionWidth], axisSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (max >= YGFloatOptional{0} && value > max) {
|
if (max >= FloatOptional{0} && value > max) {
|
||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (min >= YGFloatOptional{0} && value < min) {
|
if (min >= FloatOptional{0} && value < min) {
|
||||||
return min;
|
return min;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1190,8 +1190,7 @@ static inline float YGNodeBoundAxis(
|
|||||||
const float axisSize,
|
const float axisSize,
|
||||||
const float widthSize) {
|
const float widthSize) {
|
||||||
return yoga::maxOrDefined(
|
return yoga::maxOrDefined(
|
||||||
YGNodeBoundAxisWithinMinAndMax(
|
YGNodeBoundAxisWithinMinAndMax(node, axis, FloatOptional{value}, axisSize)
|
||||||
node, axis, YGFloatOptional{value}, axisSize)
|
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
YGNodePaddingAndBorderForAxis(node, axis, widthSize));
|
YGNodePaddingAndBorderForAxis(node, axis, widthSize));
|
||||||
}
|
}
|
||||||
@@ -1214,10 +1213,10 @@ static void YGConstrainMaxSizeForMode(
|
|||||||
const float ownerWidth,
|
const float ownerWidth,
|
||||||
YGMeasureMode* mode,
|
YGMeasureMode* mode,
|
||||||
float* size) {
|
float* size) {
|
||||||
const YGFloatOptional maxSize =
|
const FloatOptional maxSize =
|
||||||
yoga::resolveValue(
|
yoga::resolveValue(
|
||||||
node->getStyle().maxDimensions()[dim[axis]], ownerAxisSize) +
|
node->getStyle().maxDimensions()[dim[axis]], ownerAxisSize) +
|
||||||
YGFloatOptional(node->getMarginForAxis(axis, ownerWidth));
|
FloatOptional(node->getMarginForAxis(axis, ownerWidth));
|
||||||
switch (*mode) {
|
switch (*mode) {
|
||||||
case YGMeasureModeExactly:
|
case YGMeasureModeExactly:
|
||||||
case YGMeasureModeAtMost:
|
case YGMeasureModeAtMost:
|
||||||
@@ -1260,7 +1259,7 @@ static void YGNodeComputeFlexBasisForChild(
|
|||||||
YGMeasureMode childWidthMeasureMode;
|
YGMeasureMode childWidthMeasureMode;
|
||||||
YGMeasureMode childHeightMeasureMode;
|
YGMeasureMode childHeightMeasureMode;
|
||||||
|
|
||||||
const YGFloatOptional resolvedFlexBasis =
|
const FloatOptional 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);
|
||||||
@@ -1272,14 +1271,14 @@ static void YGNodeComputeFlexBasisForChild(
|
|||||||
(child->getConfig()->isExperimentalFeatureEnabled(
|
(child->getConfig()->isExperimentalFeatureEnabled(
|
||||||
YGExperimentalFeatureWebFlexBasis) &&
|
YGExperimentalFeatureWebFlexBasis) &&
|
||||||
child->getLayout().computedFlexBasisGeneration != generationCount)) {
|
child->getLayout().computedFlexBasisGeneration != generationCount)) {
|
||||||
const YGFloatOptional paddingAndBorder = YGFloatOptional(
|
const FloatOptional paddingAndBorder = FloatOptional(
|
||||||
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 YGFloatOptional paddingAndBorder = YGFloatOptional(
|
const FloatOptional paddingAndBorder = FloatOptional(
|
||||||
YGNodePaddingAndBorderForAxis(child, YGFlexDirectionRow, ownerWidth));
|
YGNodePaddingAndBorderForAxis(child, YGFlexDirectionRow, ownerWidth));
|
||||||
|
|
||||||
child->setLayoutComputedFlexBasis(yoga::maxOrDefined(
|
child->setLayoutComputedFlexBasis(yoga::maxOrDefined(
|
||||||
@@ -1288,8 +1287,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 YGFloatOptional paddingAndBorder =
|
const FloatOptional paddingAndBorder =
|
||||||
YGFloatOptional(YGNodePaddingAndBorderForAxis(
|
FloatOptional(YGNodePaddingAndBorderForAxis(
|
||||||
child, YGFlexDirectionColumn, ownerWidth));
|
child, YGFlexDirectionColumn, ownerWidth));
|
||||||
child->setLayoutComputedFlexBasis(yoga::maxOrDefined(
|
child->setLayoutComputedFlexBasis(yoga::maxOrDefined(
|
||||||
yoga::resolveValue(
|
yoga::resolveValue(
|
||||||
@@ -1426,7 +1425,7 @@ static void YGNodeComputeFlexBasisForChild(
|
|||||||
depth,
|
depth,
|
||||||
generationCount);
|
generationCount);
|
||||||
|
|
||||||
child->setLayoutComputedFlexBasis(YGFloatOptional(yoga::maxOrDefined(
|
child->setLayoutComputedFlexBasis(FloatOptional(yoga::maxOrDefined(
|
||||||
child->getLayout().measuredDimensions[dim[mainAxis]],
|
child->getLayout().measuredDimensions[dim[mainAxis]],
|
||||||
YGNodePaddingAndBorderForAxis(child, mainAxis, ownerWidth))));
|
YGNodePaddingAndBorderForAxis(child, mainAxis, ownerWidth))));
|
||||||
}
|
}
|
||||||
@@ -1876,13 +1875,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 YGFloatOptional minDimensionOptional = yoga::resolveValue(
|
const FloatOptional 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 YGFloatOptional maxDimensionOptional = yoga::resolveValue(
|
const FloatOptional maxDimensionOptional = yoga::resolveValue(
|
||||||
node->getStyle().maxDimensions()[dimension], ownerDim);
|
node->getStyle().maxDimensions()[dimension], ownerDim);
|
||||||
|
|
||||||
const float maxInnerDim = maxDimensionOptional.isUndefined()
|
const float maxInnerDim = maxDimensionOptional.isUndefined()
|
||||||
@@ -1958,7 +1957,7 @@ static float YGNodeComputeFlexBasisForChildren(
|
|||||||
}
|
}
|
||||||
if (child == singleFlexChild) {
|
if (child == singleFlexChild) {
|
||||||
child->setLayoutComputedFlexBasisGeneration(generationCount);
|
child->setLayoutComputedFlexBasisGeneration(generationCount);
|
||||||
child->setLayoutComputedFlexBasis(YGFloatOptional(0));
|
child->setLayoutComputedFlexBasis(FloatOptional(0));
|
||||||
} else {
|
} else {
|
||||||
YGNodeComputeFlexBasisForChild(
|
YGNodeComputeFlexBasisForChild(
|
||||||
node,
|
node,
|
||||||
@@ -3522,7 +3521,7 @@ static void YGNodelayoutImpl(
|
|||||||
YGNodeBoundAxisWithinMinAndMax(
|
YGNodeBoundAxisWithinMinAndMax(
|
||||||
node,
|
node,
|
||||||
mainAxis,
|
mainAxis,
|
||||||
YGFloatOptional{maxLineMainDim},
|
FloatOptional{maxLineMainDim},
|
||||||
mainAxisownerSize)
|
mainAxisownerSize)
|
||||||
.unwrap()),
|
.unwrap()),
|
||||||
paddingAndBorderAxisMain),
|
paddingAndBorderAxisMain),
|
||||||
@@ -3553,7 +3552,7 @@ static void YGNodelayoutImpl(
|
|||||||
YGNodeBoundAxisWithinMinAndMax(
|
YGNodeBoundAxisWithinMinAndMax(
|
||||||
node,
|
node,
|
||||||
crossAxis,
|
crossAxis,
|
||||||
YGFloatOptional{
|
FloatOptional{
|
||||||
totalLineCrossDim + paddingAndBorderAxisCross},
|
totalLineCrossDim + paddingAndBorderAxisCross},
|
||||||
crossAxisownerSize)
|
crossAxisownerSize)
|
||||||
.unwrap()),
|
.unwrap()),
|
||||||
|
@@ -8,24 +8,22 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
#include <yoga/YGFloatOptional.h>
|
#include <yoga/numeric/FloatOptional.h>
|
||||||
|
|
||||||
namespace facebook::yoga {
|
namespace facebook::yoga {
|
||||||
|
|
||||||
inline YGFloatOptional resolveValue(
|
inline FloatOptional resolveValue(const YGValue value, const float ownerSize) {
|
||||||
const YGValue value,
|
|
||||||
const float ownerSize) {
|
|
||||||
switch (value.unit) {
|
switch (value.unit) {
|
||||||
case YGUnitPoint:
|
case YGUnitPoint:
|
||||||
return YGFloatOptional{value.value};
|
return FloatOptional{value.value};
|
||||||
case YGUnitPercent:
|
case YGUnitPercent:
|
||||||
return YGFloatOptional{value.value * ownerSize * 0.01f};
|
return FloatOptional{value.value * ownerSize * 0.01f};
|
||||||
default:
|
default:
|
||||||
return YGFloatOptional{};
|
return FloatOptional{};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline YGFloatOptional resolveValue(CompactValue value, float ownerSize) {
|
inline FloatOptional 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 YGFloatOptional num) {
|
const FloatOptional 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/YGFloatOptional.h>
|
#include <yoga/numeric/FloatOptional.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;
|
||||||
YGFloatOptional computedFlexBasis = {};
|
FloatOptional 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(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YGFloatOptional Node::getLeadingPosition(
|
FloatOptional 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 @@ YGFloatOptional Node::getLeadingPosition(
|
|||||||
return yoga::resolveValue(leadingPosition, axisSize);
|
return yoga::resolveValue(leadingPosition, axisSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
YGFloatOptional Node::getTrailingPosition(
|
FloatOptional 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
YGFloatOptional Node::getLeadingMargin(
|
FloatOptional 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 @@ YGFloatOptional 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() ? YGFloatOptional{0}
|
return leadingMargin.isAuto() ? FloatOptional{0}
|
||||||
: yoga::resolveValue(leadingMargin, widthSize);
|
: yoga::resolveValue(leadingMargin, widthSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
YGFloatOptional Node::getTrailingMargin(
|
FloatOptional 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 @@ YGFloatOptional Node::getTrailingMargin(
|
|||||||
: computeEdgeValueForColumn(
|
: computeEdgeValueForColumn(
|
||||||
style_.margin(), trailing[axis], CompactValue::ofZero());
|
style_.margin(), trailing[axis], CompactValue::ofZero());
|
||||||
return trailingMargin.isAuto()
|
return trailingMargin.isAuto()
|
||||||
? YGFloatOptional{0}
|
? FloatOptional{0}
|
||||||
: yoga::resolveValue(trailingMargin, widthSize);
|
: yoga::resolveValue(trailingMargin, widthSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
YGFloatOptional Node::getMarginForAxis(
|
FloatOptional 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
YGFloatOptional Node::getGapForAxis(
|
FloatOptional 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 YGFloatOptional computedFlexBasis) {
|
void Node::setLayoutComputedFlexBasis(const FloatOptional 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.
|
||||||
YGFloatOptional Node::relativePosition(
|
FloatOptional 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
YGFloatOptional trailingPosition = getTrailingPosition(axis, axisSize);
|
FloatOptional trailingPosition = getTrailingPosition(axis, axisSize);
|
||||||
if (!trailingPosition.isUndefined()) {
|
if (!trailingPosition.isUndefined()) {
|
||||||
trailingPosition = YGFloatOptional{-1 * trailingPosition.unwrap()};
|
trailingPosition = FloatOptional{-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 YGFloatOptional relativePositionMain =
|
const FloatOptional relativePositionMain =
|
||||||
relativePosition(mainAxis, mainSize);
|
relativePosition(mainAxis, mainSize);
|
||||||
const YGFloatOptional relativePositionCross =
|
const FloatOptional 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(YGFloatOptional());
|
setLayoutComputedFlexBasis(FloatOptional());
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
YGFloatOptional Node::getLeadingPadding(
|
FloatOptional 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 @@ YGFloatOptional 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), YGFloatOptional(0.0f));
|
yoga::resolveValue(leadingPadding, widthSize), FloatOptional(0.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
YGFloatOptional Node::getTrailingPadding(
|
FloatOptional 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 @@ YGFloatOptional 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), YGFloatOptional(0.0f));
|
yoga::resolveValue(trailingPadding, widthSize), FloatOptional(0.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
YGFloatOptional Node::getLeadingPaddingAndBorder(
|
FloatOptional Node::getLeadingPaddingAndBorder(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const {
|
const float widthSize) const {
|
||||||
return getLeadingPadding(axis, widthSize) +
|
return getLeadingPadding(axis, widthSize) +
|
||||||
YGFloatOptional(getLeadingBorder(axis));
|
FloatOptional(getLeadingBorder(axis));
|
||||||
}
|
}
|
||||||
|
|
||||||
YGFloatOptional Node::getTrailingPaddingAndBorder(
|
FloatOptional Node::getTrailingPaddingAndBorder(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const {
|
const float widthSize) const {
|
||||||
return getTrailingPadding(axis, widthSize) +
|
return getTrailingPadding(axis, widthSize) +
|
||||||
YGFloatOptional(getTrailingBorder(axis));
|
FloatOptional(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}};
|
||||||
|
|
||||||
YGFloatOptional relativePosition(
|
FloatOptional relativePosition(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float axisSize) const;
|
const float axisSize) const;
|
||||||
|
|
||||||
@@ -203,40 +203,39 @@ public:
|
|||||||
CompactValue defaultValue);
|
CompactValue defaultValue);
|
||||||
|
|
||||||
// Methods related to positions, margin, padding and border
|
// Methods related to positions, margin, padding and border
|
||||||
YGFloatOptional getLeadingPosition(
|
FloatOptional 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;
|
||||||
YGFloatOptional getTrailingPosition(
|
FloatOptional getTrailingPosition(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float axisSize) const;
|
const float axisSize) const;
|
||||||
YGFloatOptional getLeadingMargin(
|
FloatOptional getLeadingMargin(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const;
|
const float widthSize) const;
|
||||||
YGFloatOptional getTrailingMargin(
|
FloatOptional 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;
|
||||||
YGFloatOptional getLeadingPadding(
|
FloatOptional getLeadingPadding(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const;
|
const float widthSize) const;
|
||||||
YGFloatOptional getTrailingPadding(
|
FloatOptional getTrailingPadding(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const;
|
const float widthSize) const;
|
||||||
YGFloatOptional getLeadingPaddingAndBorder(
|
FloatOptional getLeadingPaddingAndBorder(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const;
|
const float widthSize) const;
|
||||||
YGFloatOptional getTrailingPaddingAndBorder(
|
FloatOptional getTrailingPaddingAndBorder(
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) const;
|
const float widthSize) const;
|
||||||
YGFloatOptional getMarginForAxis(
|
FloatOptional 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; }
|
||||||
@@ -299,7 +298,7 @@ public:
|
|||||||
|
|
||||||
void setDirty(bool isDirty);
|
void setDirty(bool isDirty);
|
||||||
void setLayoutLastOwnerDirection(YGDirection direction);
|
void setLayoutLastOwnerDirection(YGDirection direction);
|
||||||
void setLayoutComputedFlexBasis(const YGFloatOptional computedFlexBasis);
|
void setLayoutComputedFlexBasis(const FloatOptional 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/YGFloatOptional.h>
|
#include <yoga/numeric/FloatOptional.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 YGFloatOptional maxOrDefined(YGFloatOptional op1, YGFloatOptional op2) {
|
inline FloatOptional maxOrDefined(FloatOptional op1, FloatOptional op2) {
|
||||||
if (op1 >= op2) {
|
if (op1 >= op2) {
|
||||||
return op1;
|
return op1;
|
||||||
}
|
}
|
||||||
|
74
yoga/numeric/FloatOptional.h
Normal file
74
yoga/numeric/FloatOptional.h
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
YGFloatOptional flex_ = {};
|
FloatOptional flex_ = {};
|
||||||
YGFloatOptional flexGrow_ = {};
|
FloatOptional flexGrow_ = {};
|
||||||
YGFloatOptional flexShrink_ = {};
|
FloatOptional 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
|
||||||
YGFloatOptional aspectRatio_ = {};
|
FloatOptional 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}; }
|
||||||
|
|
||||||
YGFloatOptional flex() const { return flex_; }
|
FloatOptional flex() const { return flex_; }
|
||||||
Ref<YGFloatOptional, &Style::flex_> flex() { return {*this}; }
|
Ref<FloatOptional, &Style::flex_> flex() { return {*this}; }
|
||||||
|
|
||||||
YGFloatOptional flexGrow() const { return flexGrow_; }
|
FloatOptional flexGrow() const { return flexGrow_; }
|
||||||
Ref<YGFloatOptional, &Style::flexGrow_> flexGrow() { return {*this}; }
|
Ref<FloatOptional, &Style::flexGrow_> flexGrow() { return {*this}; }
|
||||||
|
|
||||||
YGFloatOptional flexShrink() const { return flexShrink_; }
|
FloatOptional flexShrink() const { return flexShrink_; }
|
||||||
Ref<YGFloatOptional, &Style::flexShrink_> flexShrink() { return {*this}; }
|
Ref<FloatOptional, &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
|
||||||
YGFloatOptional aspectRatio() const { return aspectRatio_; }
|
FloatOptional aspectRatio() const { return aspectRatio_; }
|
||||||
Ref<YGFloatOptional, &Style::aspectRatio_> aspectRatio() { return {*this}; }
|
Ref<FloatOptional, &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