2018-07-18 00:57:52 -07:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014-present, Facebook, Inc.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the MIT license found in the LICENSE
|
|
|
|
* file in the root directory of this source tree.
|
2017-07-26 19:22:03 -07:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
2017-12-19 11:18:00 -08:00
|
|
|
#include <algorithm>
|
|
|
|
#include <array>
|
|
|
|
#include <cmath>
|
2017-12-05 08:16:49 -08:00
|
|
|
#include <vector>
|
2017-11-23 09:40:02 -08:00
|
|
|
#include "Yoga.h"
|
2017-07-26 19:22:03 -07:00
|
|
|
|
2017-12-05 08:16:49 -08:00
|
|
|
using YGVector = std::vector<YGNodeRef>;
|
|
|
|
|
2017-07-26 19:22:03 -07:00
|
|
|
YG_EXTERN_C_BEGIN
|
|
|
|
|
2018-07-18 00:57:52 -07:00
|
|
|
WIN_EXPORT float YGRoundValueToPixelGrid(
|
|
|
|
const float value,
|
|
|
|
const float pointScaleFactor,
|
|
|
|
const bool forceCeil,
|
|
|
|
const bool forceFloor);
|
2017-07-26 19:22:03 -07:00
|
|
|
|
|
|
|
YG_EXTERN_C_END
|
2017-11-23 09:40:02 -08:00
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
extern const std::array<YGEdge, 4> trailing;
|
|
|
|
extern const std::array<YGEdge, 4> leading;
|
|
|
|
extern bool YGValueEqual(const YGValue a, const YGValue b);
|
|
|
|
extern const YGValue YGValueUndefined;
|
|
|
|
extern const YGValue YGValueAuto;
|
|
|
|
extern const YGValue YGValueZero;
|
|
|
|
|
|
|
|
template <std::size_t size>
|
|
|
|
bool YGValueArrayEqual(
|
|
|
|
const std::array<YGValue, size> val1,
|
|
|
|
const std::array<YGValue, size> val2) {
|
|
|
|
bool areEqual = true;
|
|
|
|
for (uint32_t i = 0; i < size && areEqual; ++i) {
|
|
|
|
areEqual = YGValueEqual(val1[i], val2[i]);
|
|
|
|
}
|
|
|
|
return areEqual;
|
|
|
|
}
|
|
|
|
|
2018-02-02 07:38:17 -08:00
|
|
|
struct YGCachedMeasurement {
|
2017-11-23 09:40:02 -08:00
|
|
|
float availableWidth;
|
|
|
|
float availableHeight;
|
|
|
|
YGMeasureMode widthMeasureMode;
|
|
|
|
YGMeasureMode heightMeasureMode;
|
|
|
|
|
|
|
|
float computedWidth;
|
|
|
|
float computedHeight;
|
2018-02-02 07:38:17 -08:00
|
|
|
|
2018-02-20 05:41:52 -08:00
|
|
|
YGCachedMeasurement()
|
|
|
|
: availableWidth(0),
|
|
|
|
availableHeight(0),
|
|
|
|
widthMeasureMode((YGMeasureMode)-1),
|
|
|
|
heightMeasureMode((YGMeasureMode)-1),
|
|
|
|
computedWidth(-1),
|
|
|
|
computedHeight(-1) {}
|
|
|
|
|
2018-02-02 07:38:17 -08:00
|
|
|
bool operator==(YGCachedMeasurement measurement) const {
|
|
|
|
bool isEqual = widthMeasureMode == measurement.widthMeasureMode &&
|
|
|
|
heightMeasureMode == measurement.heightMeasureMode;
|
|
|
|
|
2018-03-01 04:00:35 -08:00
|
|
|
if (!YGFloatIsUndefined(availableWidth) ||
|
|
|
|
!YGFloatIsUndefined(measurement.availableWidth)) {
|
2018-02-02 07:38:17 -08:00
|
|
|
isEqual = isEqual && availableWidth == measurement.availableWidth;
|
|
|
|
}
|
2018-03-01 04:00:35 -08:00
|
|
|
if (!YGFloatIsUndefined(availableHeight) ||
|
|
|
|
!YGFloatIsUndefined(measurement.availableHeight)) {
|
2018-02-02 07:38:17 -08:00
|
|
|
isEqual = isEqual && availableHeight == measurement.availableHeight;
|
|
|
|
}
|
2018-03-01 04:00:35 -08:00
|
|
|
if (!YGFloatIsUndefined(computedWidth) ||
|
|
|
|
!YGFloatIsUndefined(measurement.computedWidth)) {
|
2018-02-02 07:38:17 -08:00
|
|
|
isEqual = isEqual && computedWidth == measurement.computedWidth;
|
|
|
|
}
|
2018-03-01 04:00:35 -08:00
|
|
|
if (!YGFloatIsUndefined(computedHeight) ||
|
|
|
|
!YGFloatIsUndefined(measurement.computedHeight)) {
|
2018-02-02 07:38:17 -08:00
|
|
|
isEqual = isEqual && computedHeight == measurement.computedHeight;
|
|
|
|
}
|
|
|
|
|
2018-02-09 04:47:49 -08:00
|
|
|
return isEqual;
|
2018-02-02 07:38:17 -08:00
|
|
|
}
|
|
|
|
};
|
2017-11-23 09:40:02 -08:00
|
|
|
|
|
|
|
// This value was chosen based on empiracle data. Even the most complicated
|
|
|
|
// layouts should not require more than 16 entries to fit within the cache.
|
|
|
|
#define YG_MAX_CACHED_RESULT_COUNT 16
|
|
|
|
|
|
|
|
static const float kDefaultFlexGrow = 0.0f;
|
|
|
|
static const float kDefaultFlexShrink = 0.0f;
|
|
|
|
static const float kWebDefaultFlexShrink = 1.0f;
|
|
|
|
|
|
|
|
extern bool YGFloatsEqual(const float a, const float b);
|
|
|
|
extern bool YGValueEqual(const YGValue a, const YGValue b);
|
|
|
|
extern const YGValue* YGComputedEdgeValue(
|
2017-12-19 11:18:00 -08:00
|
|
|
const std::array<YGValue, YGEdgeCount>& edges,
|
2017-11-23 09:40:02 -08:00
|
|
|
const YGEdge edge,
|
|
|
|
const YGValue* const defaultValue);
|