Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add equality operators to CSS data types (#48989)
Browse files Browse the repository at this point in the history
Summary:

tsia

Also added a quick helper to CSSColor used later.

Changelog: [Internal]

Reviewed By: joevilches

Differential Revision: D68741768
NickGerleman authored and facebook-github-bot committed Jan 29, 2025
1 parent 17c3429 commit 952da82
Showing 7 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -20,6 +20,8 @@ namespace facebook::react {
*/
struct CSSAngle {
float degrees{};

constexpr bool operator==(const CSSAngle& rhs) const = default;
};

template <>
Original file line number Diff line number Diff line change
@@ -25,6 +25,12 @@ struct CSSColor {
uint8_t g{};
uint8_t b{};
uint8_t a{};

constexpr bool operator==(const CSSColor& rhs) const = default;

static constexpr CSSColor black() {
return {0, 0, 0, 255};
}
};

template <>
Original file line number Diff line number Diff line change
@@ -73,10 +73,11 @@ concept CSSValidDataTypeParser = CSSFunctionBlockSink<T, ReturnT> ||
CSSSimplePreservedTokenSink<T, ReturnT>;

/**
* Concrete representation for a CSS data type, or keywords
* Concrete representation for a CSS data type
*/
template <typename T>
concept CSSDataType =
CSSValidDataTypeParser<CSSDataTypeParser<T>, std::optional<T>>;
CSSValidDataTypeParser<CSSDataTypeParser<T>, std::optional<T>> &&
std::equality_comparable<T>;

} // namespace facebook::react
Original file line number Diff line number Diff line change
@@ -21,6 +21,8 @@ namespace facebook::react {
struct CSSLength {
float value{};
CSSLengthUnit unit{CSSLengthUnit::Px};

constexpr bool operator==(const CSSLength& rhs) const = default;
};

template <>
Original file line number Diff line number Diff line change
@@ -19,6 +19,8 @@ namespace facebook::react {
*/
struct CSSNumber {
float value{};

constexpr bool operator==(const CSSNumber& rhs) const = default;
};

template <>
Original file line number Diff line number Diff line change
@@ -19,6 +19,8 @@ namespace facebook::react {
*/
struct CSSPercentage {
float value{};

constexpr bool operator==(const CSSPercentage& rhs) const = default;
};

template <>
Original file line number Diff line number Diff line change
@@ -24,6 +24,8 @@ struct CSSRatio {
float numerator{};
float denominator{};

constexpr bool operator==(const CSSRatio& rhs) const = default;

constexpr bool isDegenerate() const {
// If either number in the <ratio> is 0 or infinite, it represents a
// degenerate ratio (and, generally, won’t do anything).

0 comments on commit 952da82

Please sign in to comment.