mirror of
https://github.com/status-im/react-native.git
synced 2025-02-23 14:48:25 +00:00
User-defined literals for YGValue
Summary: @public Adds `_pt` and `_percent` user defined literals to create `YGValue` instances. This allows to create `YGValue`s in the following form: ``` use namespace facebook::yoga::literals; auto a = 123_pt; // == YGValue{123.0f, YGUnitPoint} auto b = -12.5_percent; // == YGValue{-12.5f, YGUnitPercent} ``` Reviewed By: SidharthGuglani Differential Revision: D13942100 fbshipit-source-id: ce1e2f9431c3e2a99c6e11896a712539cc535e0d
This commit is contained in:
parent
c599625df0
commit
5184f0d7a3
@ -54,4 +54,30 @@ inline bool operator!=(const YGValue& lhs, const YGValue& rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
inline YGValue operator-(const YGValue& value) {
|
||||
return {-value.value, value.unit};
|
||||
}
|
||||
|
||||
namespace facebook {
|
||||
namespace yoga {
|
||||
namespace literals {
|
||||
|
||||
inline YGValue operator"" _pt(long double value) {
|
||||
return YGValue{static_cast<float>(value), YGUnitPoint};
|
||||
}
|
||||
inline YGValue operator"" _pt(unsigned long long value) {
|
||||
return operator"" _pt(static_cast<long double>(value));
|
||||
}
|
||||
|
||||
inline YGValue operator"" _percent(long double value) {
|
||||
return YGValue{static_cast<float>(value), YGUnitPercent};
|
||||
}
|
||||
inline YGValue operator"" _percent(unsigned long long value) {
|
||||
return operator"" _percent(static_cast<long double>(value));
|
||||
}
|
||||
|
||||
} // namespace literals
|
||||
} // namespace yoga
|
||||
} // namespace facebook
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user