Move out YGValue
Summary: @public Creates a single header file for `YGValue`. This is in preparation of a more compact representation of `YGValue` within `YGStyle`. Also fixes the incorrect definition of NAN. Reviewed By: SidharthGuglani Differential Revision: D13172444 fbshipit-source-id: 4250dbcf8fe15ec3ecdee3913360a73bab633ce3
This commit is contained in:
committed by
Facebook Github Bot
parent
0962c5220c
commit
d19da9e528
29
yoga/YGValue.cpp
Normal file
29
yoga/YGValue.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
*/
|
||||
#include "YGValue.h"
|
||||
|
||||
const YGValue YGValueZero = {0, YGUnitPoint};
|
||||
const YGValue YGValueUndefined = {YGUndefined, YGUnitUndefined};
|
||||
const YGValue YGValueAuto = {YGUndefined, YGUnitAuto};
|
||||
|
||||
bool operator==(const YGValue& lhs, const YGValue& rhs) {
|
||||
if (lhs.unit != rhs.unit) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (lhs.unit) {
|
||||
case YGUnitUndefined:
|
||||
case YGUnitAuto:
|
||||
return true;
|
||||
default:
|
||||
return lhs.value == rhs.value;
|
||||
}
|
||||
}
|
||||
|
||||
bool operator!=(const YGValue& lhs, const YGValue& rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
40
yoga/YGValue.h
Normal file
40
yoga/YGValue.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its 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 <math.h>
|
||||
#include "YGEnums.h"
|
||||
#include "YGMacros.h"
|
||||
|
||||
YG_EXTERN_C_BEGIN
|
||||
|
||||
// Not defined in MSVC++
|
||||
#ifndef NAN
|
||||
static const uint32_t __nan = 0x7fc00000;
|
||||
#define NAN (*(const float*)__nan)
|
||||
#endif
|
||||
|
||||
#define YGUndefined NAN
|
||||
|
||||
typedef struct YGValue {
|
||||
float value;
|
||||
YGUnit unit;
|
||||
} YGValue;
|
||||
|
||||
extern const YGValue YGValueAuto;
|
||||
extern const YGValue YGValueUndefined;
|
||||
extern const YGValue YGValueZero;
|
||||
|
||||
YG_EXTERN_C_END
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
bool operator==(const YGValue& lhs, const YGValue& rhs);
|
||||
|
||||
bool operator!=(const YGValue& lhs, const YGValue& rhs);
|
||||
|
||||
#endif
|
@@ -39,23 +39,6 @@ static int YGDefaultLog(
|
||||
va_list args);
|
||||
#endif
|
||||
|
||||
const YGValue YGValueZero = {0, YGUnitPoint};
|
||||
const YGValue YGValueUndefined = {YGUndefined, YGUnitUndefined};
|
||||
const YGValue YGValueAuto = {YGUndefined, YGUnitAuto};
|
||||
|
||||
bool operator==(const YGValue& lhs, const YGValue& rhs) {
|
||||
if ((lhs.unit == YGUnitUndefined && rhs.unit == YGUnitUndefined) ||
|
||||
(lhs.unit == YGUnitAuto && rhs.unit == YGUnitAuto)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return lhs.unit == rhs.unit && lhs.value == rhs.value;
|
||||
}
|
||||
|
||||
bool operator!=(const YGValue& lhs, const YGValue& rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
#ifdef ANDROID
|
||||
#include <android/log.h>
|
||||
static int YGAndroidLog(
|
||||
|
28
yoga/Yoga.h
28
yoga/Yoga.h
@@ -17,16 +17,9 @@
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
// Not defined in MSVC++
|
||||
#ifndef NAN
|
||||
static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
|
||||
#define NAN (*(const float*)__nan)
|
||||
#endif
|
||||
|
||||
#define YGUndefined NAN
|
||||
|
||||
#include "YGEnums.h"
|
||||
#include "YGMacros.h"
|
||||
#include "YGValue.h"
|
||||
|
||||
YG_EXTERN_C_BEGIN
|
||||
|
||||
@@ -35,25 +28,6 @@ typedef struct YGSize {
|
||||
float height;
|
||||
} YGSize;
|
||||
|
||||
typedef struct YGValue {
|
||||
float value;
|
||||
YGUnit unit;
|
||||
} YGValue;
|
||||
|
||||
extern const YGValue YGValueUndefined;
|
||||
extern const YGValue YGValueAuto;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
YG_EXTERN_C_END
|
||||
|
||||
extern bool operator==(const YGValue& lhs, const YGValue& rhs);
|
||||
extern bool operator!=(const YGValue& lhs, const YGValue& rhs);
|
||||
|
||||
YG_EXTERN_C_BEGIN
|
||||
|
||||
#endif
|
||||
|
||||
typedef struct YGConfig* YGConfigRef;
|
||||
|
||||
typedef struct YGNode* YGNodeRef;
|
||||
|
Reference in New Issue
Block a user