This commit is contained in:
Atul R 2021-03-07 20:32:00 +01:00
parent a77d2d67f6
commit 5b8eef255d
29 changed files with 1361 additions and 2128 deletions

View File

@ -12,7 +12,6 @@ module.exports = {
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
extends: [
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
],
parserOptions: {

View File

@ -7,8 +7,9 @@
#pragma once
#include <cstdio>
#include <cstdint>
#include <cstdio>
#include "YGEnums.h"
namespace facebook {
@ -27,8 +28,8 @@ constexpr int mask(size_t bitWidth, size_t index) {
// The number of bits necessary to represent enums defined with YG_ENUM_SEQ_DECL
template <typename Enum>
constexpr size_t bitWidthFn() {
static_assert(
enums::count<Enum>() > 0, "Enums must have at least one entries");
static_assert(enums::count<Enum>() > 0,
"Enums must have at least one entries");
return log2ceilFn(enums::count<Enum>() - 1);
}
@ -40,13 +41,13 @@ constexpr Enum getEnumData(int flags, size_t index) {
template <typename Enum>
void setEnumData(uint32_t& flags, size_t index, int newValue) {
flags = (flags & ~mask(bitWidthFn<Enum>(), index)) |
((newValue << index) & (mask(bitWidthFn<Enum>(), index)));
((newValue << index) & (mask(bitWidthFn<Enum>(), index)));
}
template <typename Enum>
void setEnumData(uint8_t& flags, size_t index, int newValue) {
flags = (flags & ~mask(bitWidthFn<Enum>(), index)) |
((newValue << index) & (mask(bitWidthFn<Enum>(), index)));
((newValue << index) & (mask(bitWidthFn<Enum>(), index)));
}
constexpr bool getBooleanData(int flags, size_t index) {
@ -61,6 +62,6 @@ inline void setBooleanData(uint8_t& flags, size_t index, bool value) {
}
}
} // namespace detail
} // namespace yoga
} // namespace facebook
} // namespace detail
} // namespace yoga
} // namespace facebook

View File

@ -7,12 +7,13 @@
#pragma once
#include "YGValue.h"
#include "YGMacros.h"
#include <cmath>
#include <cstdint>
#include <limits>
#include "YGMacros.h"
#include "YGValue.h"
static_assert(
std::numeric_limits<float>::is_iec559,
"facebook::yoga::detail::CompactValue only works with IEEE754 floats");
@ -43,7 +44,7 @@ namespace detail {
class YOGA_EXPORT CompactValue {
friend constexpr bool operator==(CompactValue, CompactValue) noexcept;
public:
public:
static constexpr auto LOWER_BOUND = 1.08420217e-19f;
static constexpr auto UPPER_BOUND_POINT = 36893485948395847680.0f;
static constexpr auto UPPER_BOUND_PERCENT = 18446742974197923840.0f;
@ -125,19 +126,18 @@ public:
data.repr &= ~PERCENT_BIT;
data.repr += BIAS;
return YGValue{
data.value, payload_.repr & 0x40000000 ? YGUnitPercent : YGUnitPoint};
return YGValue{data.value,
payload_.repr & 0x40000000 ? YGUnitPercent : YGUnitPoint};
}
bool isUndefined() const noexcept {
return (
payload_.repr != AUTO_BITS && payload_.repr != ZERO_BITS_POINT &&
payload_.repr != ZERO_BITS_PERCENT && std::isnan(payload_.value));
return (payload_.repr != AUTO_BITS && payload_.repr != ZERO_BITS_POINT &&
payload_.repr != ZERO_BITS_PERCENT && std::isnan(payload_.value));
}
bool isAuto() const noexcept { return payload_.repr == AUTO_BITS; }
private:
private:
union Payload {
float value;
uint32_t repr;
@ -179,6 +179,6 @@ constexpr bool operator!=(CompactValue a, CompactValue b) noexcept {
return !(a == b);
}
} // namespace detail
} // namespace yoga
} // namespace facebook
} // namespace detail
} // namespace yoga
} // namespace facebook

View File

@ -6,16 +6,16 @@
*/
#include "Utils.h"
#include <stdexcept>
using namespace facebook;
YGFlexDirection YGFlexDirectionCross(
const YGFlexDirection flexDirection,
const YGDirection direction) {
YGFlexDirection YGFlexDirectionCross(const YGFlexDirection flexDirection,
const YGDirection direction) {
return YGFlexDirectionIsColumn(flexDirection)
? YGResolveFlexDirection(YGFlexDirectionRow, direction)
: YGFlexDirectionColumn;
? YGResolveFlexDirection(YGFlexDirectionRow, direction)
: YGFlexDirectionColumn;
}
float YGFloatMax(const float a, const float b) {

View File

@ -6,9 +6,9 @@
*/
#pragma once
#include "CompactValue.h"
#include "YGNode.h"
#include "Yoga-internal.h"
#include "CompactValue.h"
// This struct is an helper model to hold the data for step 4 of flexbox algo,
// which is collecting the flex items in a line.
@ -54,10 +54,9 @@ struct YGCollectFlexItemsRowValues {
};
bool YGValueEqual(const YGValue& a, const YGValue& b);
inline bool YGValueEqual(
facebook::yoga::detail::CompactValue a,
facebook::yoga::detail::CompactValue b) {
return YGValueEqual((YGValue) a, (YGValue) b);
inline bool YGValueEqual(facebook::yoga::detail::CompactValue a,
facebook::yoga::detail::CompactValue b) {
return YGValueEqual((YGValue)a, (YGValue)b);
}
// This custom float equality function returns true if either absolute
@ -68,9 +67,8 @@ bool YGDoubleEqual(const double a, const double b);
float YGFloatMax(const float a, const float b);
YGFloatOptional YGFloatOptionalMax(
const YGFloatOptional op1,
const YGFloatOptional op2);
YGFloatOptional YGFloatOptionalMax(const YGFloatOptional op1,
const YGFloatOptional op2);
float YGFloatMin(const float a, const float b);
@ -78,9 +76,8 @@ float YGFloatMin(const float a, const float b);
// YGFloatsEqual, as the default float comparison operator will not work(Look
// at the comments of YGFloatsEqual function).
template <std::size_t size>
bool YGFloatArrayEqual(
const std::array<float, size>& val1,
const std::array<float, size>& val2) {
bool YGFloatArrayEqual(const std::array<float, size>& val1,
const std::array<float, size>& val2) {
bool areEqual = true;
for (std::size_t i = 0; i < size && areEqual; ++i) {
areEqual = YGFloatsEqual(val1[i], val2[i]);
@ -91,18 +88,16 @@ bool YGFloatArrayEqual(
// This function returns 0 if YGFloatIsUndefined(val) is true and val otherwise
float YGFloatSanitize(const float val);
YGFlexDirection YGFlexDirectionCross(
const YGFlexDirection flexDirection,
const YGDirection direction);
YGFlexDirection YGFlexDirectionCross(const YGFlexDirection flexDirection,
const YGDirection direction);
inline bool YGFlexDirectionIsRow(const YGFlexDirection flexDirection) {
return flexDirection == YGFlexDirectionRow ||
flexDirection == YGFlexDirectionRowReverse;
flexDirection == YGFlexDirectionRowReverse;
}
inline YGFloatOptional YGResolveValue(
const YGValue value,
const float ownerSize) {
inline YGFloatOptional YGResolveValue(const YGValue value,
const float ownerSize) {
switch (value.unit) {
case YGUnitPoint:
return YGFloatOptional{value.value};
@ -113,20 +108,18 @@ inline YGFloatOptional YGResolveValue(
}
}
inline YGFloatOptional YGResolveValue(
yoga::detail::CompactValue value,
float ownerSize) {
return YGResolveValue((YGValue) value, ownerSize);
inline YGFloatOptional YGResolveValue(yoga::detail::CompactValue value,
float ownerSize) {
return YGResolveValue((YGValue)value, ownerSize);
}
inline bool YGFlexDirectionIsColumn(const YGFlexDirection flexDirection) {
return flexDirection == YGFlexDirectionColumn ||
flexDirection == YGFlexDirectionColumnReverse;
flexDirection == YGFlexDirectionColumnReverse;
}
inline YGFlexDirection YGResolveFlexDirection(
const YGFlexDirection flexDirection,
const YGDirection direction) {
const YGFlexDirection flexDirection, const YGDirection direction) {
if (direction == YGDirectionRTL) {
if (flexDirection == YGFlexDirectionRow) {
return YGFlexDirectionRowReverse;
@ -138,9 +131,8 @@ inline YGFlexDirection YGResolveFlexDirection(
return flexDirection;
}
inline YGFloatOptional YGResolveValueMargin(
yoga::detail::CompactValue value,
const float ownerSize) {
inline YGFloatOptional YGResolveValueMargin(yoga::detail::CompactValue value,
const float ownerSize) {
return value.isAuto() ? YGFloatOptional{0} : YGResolveValue(value, ownerSize);
}

View File

@ -12,13 +12,8 @@ YGConfig::YGConfig(YGLogger logger) : cloneNodeCallback_{nullptr} {
loggerUsesContext_ = false;
}
void YGConfig::log(
YGConfig* config,
YGNode* node,
YGLogLevel logLevel,
void* logContext,
const char* format,
va_list args) {
void YGConfig::log(YGConfig* config, YGNode* node, YGLogLevel logLevel,
void* logContext, const char* format, va_list args) {
if (loggerUsesContext_) {
logger_.withContext(config, node, logLevel, logContext, format, args);
} else {
@ -26,16 +21,14 @@ void YGConfig::log(
}
}
YGNodeRef YGConfig::cloneNode(
YGNodeRef node,
YGNodeRef owner,
int childIndex,
void* cloneContext) {
YGNodeRef YGConfig::cloneNode(YGNodeRef node, YGNodeRef owner, int childIndex,
void* cloneContext) {
YGNodeRef clone = nullptr;
if (cloneNodeCallback_.noContext != nullptr) {
clone = cloneNodeUsesContext_
? cloneNodeCallback_.withContext(node, owner, childIndex, cloneContext)
: cloneNodeCallback_.noContext(node, owner, childIndex);
? cloneNodeCallback_.withContext(node, owner, childIndex,
cloneContext)
: cloneNodeCallback_.noContext(node, owner, childIndex);
}
if (clone == nullptr) {
clone = YGNodeClone(node);

View File

@ -10,20 +10,13 @@
#include "Yoga.h"
struct YOGA_EXPORT YGConfig {
using LogWithContextFn = int (*)(
YGConfigRef config,
YGNodeRef node,
YGLogLevel level,
void* context,
const char* format,
va_list args);
using CloneWithContextFn = YGNodeRef (*)(
YGNodeRef node,
YGNodeRef owner,
int childIndex,
void* cloneContext);
using LogWithContextFn = int (*)(YGConfigRef config, YGNodeRef node,
YGLogLevel level, void* context,
const char* format, va_list args);
using CloneWithContextFn = YGNodeRef (*)(YGNodeRef node, YGNodeRef owner,
int childIndex, void* cloneContext);
private:
private:
union {
CloneWithContextFn withContext;
YGCloneNodeFunc noContext;
@ -35,7 +28,7 @@ private:
bool cloneNodeUsesContext_;
bool loggerUsesContext_;
public:
public:
bool useWebDefaults = false;
bool useLegacyStretchBehaviour = false;
bool shouldDiffLayoutWithoutLegacyStretchBehaviour = false;
@ -57,11 +50,8 @@ public:
}
void setLogger(std::nullptr_t) { setLogger(YGLogger{nullptr}); }
YGNodeRef cloneNode(
YGNodeRef node,
YGNodeRef owner,
int childIndex,
void* cloneContext);
YGNodeRef cloneNode(YGNodeRef node, YGNodeRef owner, int childIndex,
void* cloneContext);
void setCloneNodeCallback(YGCloneNodeFunc cloneNode) {
cloneNodeCallback_.noContext = cloneNode;
cloneNodeUsesContext_ = false;

View File

@ -15,18 +15,18 @@ namespace yoga {
namespace enums {
template <typename T>
constexpr int count(); // can't use `= delete` due to a defect in clang < 3.9
constexpr int count(); // can't use `= delete` due to a defect in clang < 3.9
namespace detail {
template <int... xs>
constexpr int n() {
return sizeof...(xs);
}
} // namespace detail
} // namespace detail
} // namespace enums
} // namespace yoga
} // namespace facebook
} // namespace enums
} // namespace yoga
} // namespace facebook
#endif
#define YG_ENUM_DECL(NAME, ...) \
@ -54,98 +54,50 @@ constexpr int n() {
YG_EXTERN_C_BEGIN
YG_ENUM_SEQ_DECL(
YGAlign,
YGAlignAuto,
YGAlignFlexStart,
YGAlignCenter,
YGAlignFlexEnd,
YGAlignStretch,
YGAlignBaseline,
YGAlignSpaceBetween,
YGAlignSpaceAround);
YG_ENUM_SEQ_DECL(YGAlign, YGAlignAuto, YGAlignFlexStart, YGAlignCenter,
YGAlignFlexEnd, YGAlignStretch, YGAlignBaseline,
YGAlignSpaceBetween, YGAlignSpaceAround);
YG_ENUM_SEQ_DECL(YGDimension, YGDimensionWidth, YGDimensionHeight)
YG_ENUM_SEQ_DECL(
YGDirection,
YGDirectionInherit,
YGDirectionLTR,
YGDirectionRTL)
YG_ENUM_SEQ_DECL(YGDirection, YGDirectionInherit, YGDirectionLTR,
YGDirectionRTL)
YG_ENUM_SEQ_DECL(YGDisplay, YGDisplayFlex, YGDisplayNone)
YG_ENUM_SEQ_DECL(
YGEdge,
YGEdgeLeft,
YGEdgeTop,
YGEdgeRight,
YGEdgeBottom,
YGEdgeStart,
YGEdgeEnd,
YGEdgeHorizontal,
YGEdgeVertical,
YGEdgeAll)
YG_ENUM_SEQ_DECL(YGEdge, YGEdgeLeft, YGEdgeTop, YGEdgeRight, YGEdgeBottom,
YGEdgeStart, YGEdgeEnd, YGEdgeHorizontal, YGEdgeVertical,
YGEdgeAll)
YG_ENUM_SEQ_DECL(YGExperimentalFeature, YGExperimentalFeatureWebFlexBasis)
YG_ENUM_SEQ_DECL(
YGFlexDirection,
YGFlexDirectionColumn,
YGFlexDirectionColumnReverse,
YGFlexDirectionRow,
YGFlexDirectionRowReverse)
YG_ENUM_SEQ_DECL(YGFlexDirection, YGFlexDirectionColumn,
YGFlexDirectionColumnReverse, YGFlexDirectionRow,
YGFlexDirectionRowReverse)
YG_ENUM_SEQ_DECL(
YGJustify,
YGJustifyFlexStart,
YGJustifyCenter,
YGJustifyFlexEnd,
YGJustifySpaceBetween,
YGJustifySpaceAround,
YGJustifySpaceEvenly)
YG_ENUM_SEQ_DECL(YGJustify, YGJustifyFlexStart, YGJustifyCenter,
YGJustifyFlexEnd, YGJustifySpaceBetween, YGJustifySpaceAround,
YGJustifySpaceEvenly)
YG_ENUM_SEQ_DECL(
YGLogLevel,
YGLogLevelError,
YGLogLevelWarn,
YGLogLevelInfo,
YGLogLevelDebug,
YGLogLevelVerbose,
YGLogLevelFatal)
YG_ENUM_SEQ_DECL(YGLogLevel, YGLogLevelError, YGLogLevelWarn, YGLogLevelInfo,
YGLogLevelDebug, YGLogLevelVerbose, YGLogLevelFatal)
YG_ENUM_SEQ_DECL(
YGMeasureMode,
YGMeasureModeUndefined,
YGMeasureModeExactly,
YGMeasureModeAtMost)
YG_ENUM_SEQ_DECL(YGMeasureMode, YGMeasureModeUndefined, YGMeasureModeExactly,
YGMeasureModeAtMost)
YG_ENUM_SEQ_DECL(YGNodeType, YGNodeTypeDefault, YGNodeTypeText)
YG_ENUM_SEQ_DECL(
YGOverflow,
YGOverflowVisible,
YGOverflowHidden,
YGOverflowScroll)
YG_ENUM_SEQ_DECL(YGOverflow, YGOverflowVisible, YGOverflowHidden,
YGOverflowScroll)
YG_ENUM_SEQ_DECL(
YGPositionType,
YGPositionTypeStatic,
YGPositionTypeRelative,
YGPositionTypeAbsolute)
YG_ENUM_SEQ_DECL(YGPositionType, YGPositionTypeStatic, YGPositionTypeRelative,
YGPositionTypeAbsolute)
YG_ENUM_DECL(
YGPrintOptions,
YGPrintOptionsLayout = 1,
YGPrintOptionsStyle = 2,
YGPrintOptionsChildren = 4)
YG_ENUM_DECL(YGPrintOptions, YGPrintOptionsLayout = 1, YGPrintOptionsStyle = 2,
YGPrintOptionsChildren = 4)
YG_ENUM_SEQ_DECL(
YGUnit,
YGUnitUndefined,
YGUnitPoint,
YGUnitPercent,
YGUnitAuto)
YG_ENUM_SEQ_DECL(YGUnit, YGUnitUndefined, YGUnitPoint, YGUnitPercent,
YGUnitAuto)
YG_ENUM_SEQ_DECL(YGWrap, YGWrapNoWrap, YGWrapWrap, YGWrapWrapReverse)

View File

@ -9,13 +9,14 @@
#include <cmath>
#include <limits>
#include "Yoga-internal.h"
struct YGFloatOptional {
private:
private:
float value_ = std::numeric_limits<float>::quiet_NaN();
public:
public:
explicit constexpr YGFloatOptional(float value) : value_(value) {}
constexpr YGFloatOptional() = default;
@ -29,7 +30,7 @@ public:
inline bool operator==(YGFloatOptional lhs, YGFloatOptional rhs) {
return lhs.unwrap() == rhs.unwrap() ||
(lhs.isUndefined() && rhs.isUndefined());
(lhs.isUndefined() && rhs.isUndefined());
}
inline bool operator!=(YGFloatOptional lhs, YGFloatOptional rhs) {
return !(lhs == rhs);
@ -38,16 +39,10 @@ inline bool operator!=(YGFloatOptional lhs, YGFloatOptional 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!=(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 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()};

View File

@ -6,12 +6,14 @@
*/
#include "YGLayout.h"
#include "Utils.h"
using namespace facebook;
bool YGLayout::operator==(YGLayout layout) const {
bool isEqual = YGFloatArrayEqual(position, layout.position) &&
bool isEqual =
YGFloatArrayEqual(position, layout.position) &&
YGFloatArrayEqual(dimensions, layout.dimensions) &&
YGFloatArrayEqual(margin, layout.margin) &&
YGFloatArrayEqual(border, layout.border) &&

View File

@ -19,7 +19,7 @@ struct YGLayout {
std::array<float, 4> border = {};
std::array<float, 4> padding = {};
private:
private:
static constexpr size_t directionOffset = 0;
static constexpr size_t didUseLegacyFlagOffset =
directionOffset + facebook::yoga::detail::bitWidthFn<YGDirection>();
@ -29,7 +29,7 @@ private:
doesLegacyStretchFlagAffectsLayoutOffset + 1;
uint8_t flags = 0;
public:
public:
uint32_t computedFlexBasisGeneration = 0;
YGFloatOptional computedFlexBasis = {};
@ -46,18 +46,18 @@ public:
YGCachedMeasurement cachedLayout = YGCachedMeasurement();
YGDirection direction() const {
return facebook::yoga::detail::getEnumData<YGDirection>(
flags, directionOffset);
return facebook::yoga::detail::getEnumData<YGDirection>(flags,
directionOffset);
}
void setDirection(YGDirection direction) {
facebook::yoga::detail::setEnumData<YGDirection>(
flags, directionOffset, direction);
facebook::yoga::detail::setEnumData<YGDirection>(flags, directionOffset,
direction);
}
bool didUseLegacyFlag() const {
return facebook::yoga::detail::getBooleanData(
flags, didUseLegacyFlagOffset);
return facebook::yoga::detail::getBooleanData(flags,
didUseLegacyFlagOffset);
}
void setDidUseLegacyFlag(bool val) {
@ -78,8 +78,8 @@ public:
return facebook::yoga::detail::getBooleanData(flags, hadOverflowOffset);
}
void setHadOverflow(bool hadOverflow) {
facebook::yoga::detail::setBooleanData(
flags, hadOverflowOffset, hadOverflow);
facebook::yoga::detail::setBooleanData(flags, hadOverflowOffset,
hadOverflow);
}
bool operator==(YGLayout layout) const;

View File

@ -6,8 +6,10 @@
*/
#include "YGNode.h"
#include <algorithm>
#include <iostream>
#include "CompactValue.h"
#include "Utils.h"
@ -50,114 +52,104 @@ void YGNode::print(void* printContext) {
}
}
YGFloatOptional YGNode::getLeadingPosition(
const YGFlexDirection axis,
const float axisSize) const {
YGFloatOptional YGNode::getLeadingPosition(const YGFlexDirection axis,
const float axisSize) const {
if (YGFlexDirectionIsRow(axis)) {
auto leadingPosition = YGComputedEdgeValue(
style_.position(), YGEdgeStart, CompactValue::ofUndefined());
auto leadingPosition = YGComputedEdgeValue(style_.position(), YGEdgeStart,
CompactValue::ofUndefined());
if (!leadingPosition.isUndefined()) {
return YGResolveValue(leadingPosition, axisSize);
}
}
auto leadingPosition = YGComputedEdgeValue(
style_.position(), leading[axis], CompactValue::ofUndefined());
auto leadingPosition = YGComputedEdgeValue(style_.position(), leading[axis],
CompactValue::ofUndefined());
return leadingPosition.isUndefined()
? YGFloatOptional{0}
: YGResolveValue(leadingPosition, axisSize);
? YGFloatOptional{0}
: YGResolveValue(leadingPosition, axisSize);
}
YGFloatOptional YGNode::getTrailingPosition(
const YGFlexDirection axis,
const float axisSize) const {
YGFloatOptional YGNode::getTrailingPosition(const YGFlexDirection axis,
const float axisSize) const {
if (YGFlexDirectionIsRow(axis)) {
auto trailingPosition = YGComputedEdgeValue(
style_.position(), YGEdgeEnd, CompactValue::ofUndefined());
auto trailingPosition = YGComputedEdgeValue(style_.position(), YGEdgeEnd,
CompactValue::ofUndefined());
if (!trailingPosition.isUndefined()) {
return YGResolveValue(trailingPosition, axisSize);
}
}
auto trailingPosition = YGComputedEdgeValue(
style_.position(), trailing[axis], CompactValue::ofUndefined());
auto trailingPosition = YGComputedEdgeValue(style_.position(), trailing[axis],
CompactValue::ofUndefined());
return trailingPosition.isUndefined()
? YGFloatOptional{0}
: YGResolveValue(trailingPosition, axisSize);
? YGFloatOptional{0}
: YGResolveValue(trailingPosition, axisSize);
}
bool YGNode::isLeadingPositionDefined(const YGFlexDirection axis) const {
return (YGFlexDirectionIsRow(axis) &&
!YGComputedEdgeValue(
style_.position(), YGEdgeStart, CompactValue::ofUndefined())
!YGComputedEdgeValue(style_.position(), YGEdgeStart,
CompactValue::ofUndefined())
.isUndefined()) ||
!YGComputedEdgeValue(
style_.position(), leading[axis], CompactValue::ofUndefined())
.isUndefined();
!YGComputedEdgeValue(style_.position(), leading[axis],
CompactValue::ofUndefined())
.isUndefined();
}
bool YGNode::isTrailingPosDefined(const YGFlexDirection axis) const {
return (YGFlexDirectionIsRow(axis) &&
!YGComputedEdgeValue(
style_.position(), YGEdgeEnd, CompactValue::ofUndefined())
!YGComputedEdgeValue(style_.position(), YGEdgeEnd,
CompactValue::ofUndefined())
.isUndefined()) ||
!YGComputedEdgeValue(
style_.position(), trailing[axis], CompactValue::ofUndefined())
.isUndefined();
!YGComputedEdgeValue(style_.position(), trailing[axis],
CompactValue::ofUndefined())
.isUndefined();
}
YGFloatOptional YGNode::getLeadingMargin(
const YGFlexDirection axis,
const float widthSize) const {
YGFloatOptional YGNode::getLeadingMargin(const YGFlexDirection axis,
const float widthSize) const {
if (YGFlexDirectionIsRow(axis) &&
!style_.margin()[YGEdgeStart].isUndefined()) {
return YGResolveValueMargin(style_.margin()[YGEdgeStart], widthSize);
}
return YGResolveValueMargin(
YGComputedEdgeValue(
style_.margin(), leading[axis], CompactValue::ofZero()),
YGComputedEdgeValue(style_.margin(), leading[axis],
CompactValue::ofZero()),
widthSize);
}
YGFloatOptional YGNode::getTrailingMargin(
const YGFlexDirection axis,
const float widthSize) const {
YGFloatOptional YGNode::getTrailingMargin(const YGFlexDirection axis,
const float widthSize) const {
if (YGFlexDirectionIsRow(axis) && !style_.margin()[YGEdgeEnd].isUndefined()) {
return YGResolveValueMargin(style_.margin()[YGEdgeEnd], widthSize);
}
return YGResolveValueMargin(
YGComputedEdgeValue(
style_.margin(), trailing[axis], CompactValue::ofZero()),
YGComputedEdgeValue(style_.margin(), trailing[axis],
CompactValue::ofZero()),
widthSize);
}
YGFloatOptional YGNode::getMarginForAxis(
const YGFlexDirection axis,
const float widthSize) const {
YGFloatOptional YGNode::getMarginForAxis(const YGFlexDirection axis,
const float widthSize) const {
return getLeadingMargin(axis, widthSize) + getTrailingMargin(axis, widthSize);
}
YGSize YGNode::measure(
float width,
YGMeasureMode widthMode,
float height,
YGMeasureMode heightMode,
void* layoutContext) {
YGSize YGNode::measure(float width, YGMeasureMode widthMode, float height,
YGMeasureMode heightMode, void* layoutContext) {
return facebook::yoga::detail::getBooleanData(flags, measureUsesContext_)
? measure_.withContext(
this, width, widthMode, height, heightMode, layoutContext)
: measure_.noContext(this, width, widthMode, height, heightMode);
? measure_.withContext(this, width, widthMode, height, heightMode,
layoutContext)
: measure_.noContext(this, width, widthMode, height, heightMode);
}
float YGNode::baseline(float width, float height, void* layoutContext) {
return facebook::yoga::detail::getBooleanData(flags, baselineUsesContext_)
? baseline_.withContext(this, width, height, layoutContext)
: baseline_.noContext(this, width, height);
? baseline_.withContext(this, width, height, layoutContext)
: baseline_.noContext(this, width, height);
}
// Setters
@ -169,8 +161,7 @@ void YGNode::setMeasureFunc(decltype(YGNode::measure_) measureFunc) {
setNodeType(YGNodeTypeDefault);
} else {
YGAssertWithNode(
this,
children_.size() == 0,
this, children_.size() == 0,
"Cannot set measure function: Nodes with measure functions cannot have "
"children.");
// TODO: t18095186 Move nodeType to opt-in function and mark appropriate
@ -279,9 +270,8 @@ void YGNode::setLayoutDimension(float dimension, int index) {
// If both left and right are defined, then use left. Otherwise return +left or
// -right depending on which is defined.
YGFloatOptional YGNode::relativePosition(
const YGFlexDirection axis,
const float axisSize) const {
YGFloatOptional YGNode::relativePosition(const YGFlexDirection axis,
const float axisSize) const {
if (isLeadingPositionDefined(axis)) {
return getLeadingPosition(axis, axisSize);
}
@ -293,11 +283,8 @@ YGFloatOptional YGNode::relativePosition(
return trailingPosition;
}
void YGNode::setPosition(
const YGDirection direction,
const float mainSize,
const float crossSize,
const float ownerWidth) {
void YGNode::setPosition(const YGDirection direction, const float mainSize,
const float crossSize, const float ownerWidth) {
/* Root nodes should be always layouted as LTR, so we don't return negative
* values. */
const YGDirection directionRespectingRoot =
@ -355,8 +342,8 @@ YGValue YGNode::resolveFlexBasisPtr() const {
}
if (!style_.flex().isUndefined() && style_.flex().unwrap() > 0.0f) {
return facebook::yoga::detail::getBooleanData(flags, useWebDefaults_)
? YGValueAuto
: YGValueZero;
? YGValueAuto
: YGValueZero;
}
return YGValueAuto;
}
@ -437,14 +424,13 @@ float YGNode::resolveFlexShrink() const {
return -style_.flex().unwrap();
}
return facebook::yoga::detail::getBooleanData(flags, useWebDefaults_)
? kWebDefaultFlexShrink
: kDefaultFlexShrink;
? kWebDefaultFlexShrink
: kDefaultFlexShrink;
}
bool YGNode::isNodeFlexible() {
return (
(style_.positionType() != YGPositionTypeAbsolute) &&
(resolveFlexGrow() != 0 || resolveFlexShrink() != 0));
return ((style_.positionType() != YGPositionTypeAbsolute) &&
(resolveFlexGrow() != 0 || resolveFlexShrink() != 0));
}
float YGNode::getLeadingBorder(const YGFlexDirection axis) const {
@ -457,8 +443,8 @@ float YGNode::getLeadingBorder(const YGFlexDirection axis) const {
}
}
leadingBorder = YGComputedEdgeValue(
style_.border(), leading[axis], CompactValue::ofZero());
leadingBorder = YGComputedEdgeValue(style_.border(), leading[axis],
CompactValue::ofZero());
return YGFloatMax(leadingBorder.value, 0.0f);
}
@ -472,14 +458,13 @@ float YGNode::getTrailingBorder(const YGFlexDirection flexDirection) const {
}
}
trailingBorder = YGComputedEdgeValue(
style_.border(), trailing[flexDirection], CompactValue::ofZero());
trailingBorder = YGComputedEdgeValue(style_.border(), trailing[flexDirection],
CompactValue::ofZero());
return YGFloatMax(trailingBorder.value, 0.0f);
}
YGFloatOptional YGNode::getLeadingPadding(
const YGFlexDirection axis,
const float widthSize) const {
YGFloatOptional YGNode::getLeadingPadding(const YGFlexDirection axis,
const float widthSize) const {
const YGFloatOptional paddingEdgeStart =
YGResolveValue(style_.padding()[YGEdgeStart], widthSize);
if (YGFlexDirectionIsRow(axis) &&
@ -488,42 +473,39 @@ YGFloatOptional YGNode::getLeadingPadding(
return paddingEdgeStart;
}
YGFloatOptional resolvedValue = YGResolveValue(
YGComputedEdgeValue(
style_.padding(), leading[axis], CompactValue::ofZero()),
widthSize);
YGFloatOptional resolvedValue =
YGResolveValue(YGComputedEdgeValue(style_.padding(), leading[axis],
CompactValue::ofZero()),
widthSize);
return YGFloatOptionalMax(resolvedValue, YGFloatOptional(0.0f));
}
YGFloatOptional YGNode::getTrailingPadding(
const YGFlexDirection axis,
const float widthSize) const {
YGFloatOptional YGNode::getTrailingPadding(const YGFlexDirection axis,
const float widthSize) const {
const YGFloatOptional paddingEdgeEnd =
YGResolveValue(style_.padding()[YGEdgeEnd], widthSize);
if (YGFlexDirectionIsRow(axis) && paddingEdgeEnd >= YGFloatOptional{0.0f}) {
return paddingEdgeEnd;
}
YGFloatOptional resolvedValue = YGResolveValue(
YGComputedEdgeValue(
style_.padding(), trailing[axis], CompactValue::ofZero()),
widthSize);
YGFloatOptional resolvedValue =
YGResolveValue(YGComputedEdgeValue(style_.padding(), trailing[axis],
CompactValue::ofZero()),
widthSize);
return YGFloatOptionalMax(resolvedValue, YGFloatOptional(0.0f));
}
YGFloatOptional YGNode::getLeadingPaddingAndBorder(
const YGFlexDirection axis,
const float widthSize) const {
const YGFlexDirection axis, const float widthSize) const {
return getLeadingPadding(axis, widthSize) +
YGFloatOptional(getLeadingBorder(axis));
YGFloatOptional(getLeadingBorder(axis));
}
YGFloatOptional YGNode::getTrailingPaddingAndBorder(
const YGFlexDirection axis,
const float widthSize) const {
const YGFlexDirection axis, const float widthSize) const {
return getTrailingPadding(axis, widthSize) +
YGFloatOptional(getTrailingBorder(axis));
YGFloatOptional(getTrailingBorder(axis));
}
bool YGNode::didUseLegacyFlag() {
@ -574,12 +556,10 @@ bool YGNode::isLayoutTreeEqualToNode(const YGNode& node) const {
}
void YGNode::reset() {
YGAssertWithNode(
this,
children_.size() == 0,
"Cannot reset a node which still has children attached");
YGAssertWithNode(
this, owner_ == nullptr, "Cannot reset a node still attached to a owner");
YGAssertWithNode(this, children_.size() == 0,
"Cannot reset a node which still has children attached");
YGAssertWithNode(this, owner_ == nullptr,
"Cannot reset a node still attached to a owner");
clearChildren();

View File

@ -9,25 +9,27 @@
#ifdef __cplusplus
#include <cstdint>
#include <stdio.h>
#include <cstdint>
#include "BitUtils.h"
#include "CompactValue.h"
#include "YGConfig.h"
#include "YGLayout.h"
#include "YGStyle.h"
#include "YGMacros.h"
#include "YGStyle.h"
#include "Yoga-internal.h"
YGConfigRef YGConfigGetDefault();
struct YOGA_EXPORT YGNode {
using MeasureWithContextFn =
YGSize (*)(YGNode*, float, YGMeasureMode, float, YGMeasureMode, void*);
using MeasureWithContextFn = YGSize (*)(YGNode*, float, YGMeasureMode, float,
YGMeasureMode, void*);
using BaselineWithContextFn = float (*)(YGNode*, float, float, void*);
using PrintWithContextFn = void (*)(YGNode*, void*);
private:
private:
static constexpr size_t hasNewLayout_ = 0;
static constexpr size_t isReferenceBaseline_ = 1;
static constexpr size_t isDirty_ = 2;
@ -62,9 +64,8 @@ private:
std::array<YGValue, 2> resolvedDimensions_ = {
{YGValueUndefined, YGValueUndefined}};
YGFloatOptional relativePosition(
const YGFlexDirection axis,
const float axisSize) const;
YGFloatOptional relativePosition(const YGFlexDirection axis,
const float axisSize) const;
void setMeasureFunc(decltype(measure_));
void setBaselineFunc(decltype(baseline_));
@ -84,14 +85,14 @@ private:
using CompactValue = facebook::yoga::detail::CompactValue;
public:
public:
YGNode() : YGNode{YGConfigGetDefault()} {}
explicit YGNode(const YGConfigRef config) : config_{config} {
if (config->useWebDefaults) {
useWebDefaults();
}
};
~YGNode() = default; // cleanup of owner/children relationships in YGNodeFree
~YGNode() = default; // cleanup of owner/children relationships in YGNodeFree
YGNode(YGNode&&);
@ -194,37 +195,28 @@ public:
}
// Methods related to positions, margin, padding and border
YGFloatOptional getLeadingPosition(
const YGFlexDirection axis,
const float axisSize) const;
YGFloatOptional getLeadingPosition(const YGFlexDirection axis,
const float axisSize) const;
bool isLeadingPositionDefined(const YGFlexDirection axis) const;
bool isTrailingPosDefined(const YGFlexDirection axis) const;
YGFloatOptional getTrailingPosition(
const YGFlexDirection axis,
const float axisSize) const;
YGFloatOptional getLeadingMargin(
const YGFlexDirection axis,
const float widthSize) const;
YGFloatOptional getTrailingMargin(
const YGFlexDirection axis,
const float widthSize) const;
YGFloatOptional getTrailingPosition(const YGFlexDirection axis,
const float axisSize) const;
YGFloatOptional getLeadingMargin(const YGFlexDirection axis,
const float widthSize) const;
YGFloatOptional getTrailingMargin(const YGFlexDirection axis,
const float widthSize) const;
float getLeadingBorder(const YGFlexDirection flexDirection) const;
float getTrailingBorder(const YGFlexDirection flexDirection) const;
YGFloatOptional getLeadingPadding(
const YGFlexDirection axis,
const float widthSize) const;
YGFloatOptional getTrailingPadding(
const YGFlexDirection axis,
const float widthSize) const;
YGFloatOptional getLeadingPaddingAndBorder(
const YGFlexDirection axis,
const float widthSize) const;
YGFloatOptional getTrailingPaddingAndBorder(
const YGFlexDirection axis,
const float widthSize) const;
YGFloatOptional getMarginForAxis(
const YGFlexDirection axis,
const float widthSize) const;
YGFloatOptional getLeadingPadding(const YGFlexDirection axis,
const float widthSize) const;
YGFloatOptional getTrailingPadding(const YGFlexDirection axis,
const float widthSize) const;
YGFloatOptional getLeadingPaddingAndBorder(const YGFlexDirection axis,
const float widthSize) const;
YGFloatOptional getTrailingPaddingAndBorder(const YGFlexDirection axis,
const float widthSize) const;
YGFloatOptional getMarginForAxis(const YGFlexDirection axis,
const float widthSize) const;
// Setters
void setContext(void* context) { context_ = context; }
@ -244,8 +236,8 @@ public:
}
void setNodeType(YGNodeType nodeType) {
return facebook::yoga::detail::setEnumData<YGNodeType>(
flags, nodeType_, nodeType);
return facebook::yoga::detail::setEnumData<YGNodeType>(flags, nodeType_,
nodeType);
}
void setMeasureFunc(YGMeasureFunc measureFunc);
@ -275,8 +267,8 @@ public:
void setLineIndex(uint32_t lineIndex) { lineIndex_ = lineIndex; }
void setIsReferenceBaseline(bool isReferenceBaseline) {
facebook::yoga::detail::setBooleanData(
flags, isReferenceBaseline_, isReferenceBaseline);
facebook::yoga::detail::setBooleanData(flags, isReferenceBaseline_,
isReferenceBaseline);
}
void setOwner(YGNodeRef owner) { owner_ = owner; }
@ -300,11 +292,8 @@ public:
void setLayoutBorder(float border, int index);
void setLayoutPadding(float padding, int index);
void setLayoutPosition(float position, int index);
void setPosition(
const YGDirection direction,
const float mainSize,
const float crossSize,
const float ownerWidth);
void setPosition(const YGDirection direction, const float mainSize,
const float crossSize, const float ownerWidth);
void setLayoutDoesLegacyFlagAffectsLayout(bool doesLegacyFlagAffectsLayout);
void setLayoutDidUseLegacyFlag(bool didUseLegacyFlag);
void markDirtyAndPropogateDownwards();

View File

@ -7,11 +7,13 @@
#ifdef DEBUG
#include "YGNodePrint.h"
#include <stdarg.h>
#include "Utils.h"
#include "YGEnums.h"
#include "YGNode.h"
#include "Yoga-internal.h"
#include "Utils.h"
namespace facebook {
namespace yoga {
@ -25,7 +27,7 @@ static void indent(string& base, uint32_t level) {
static bool areFourValuesEqual(const YGStyle::Edges& four) {
return YGValueEqual(four[0], four[1]) && YGValueEqual(four[0], four[2]) &&
YGValueEqual(four[0], four[3]);
YGValueEqual(four[0], four[3]);
}
static void appendFormatedString(string& str, const char* fmt, ...) {
@ -41,43 +43,35 @@ static void appendFormatedString(string& str, const char* fmt, ...) {
str.append(result);
}
static void appendFloatOptionalIfDefined(
string& base,
const string key,
const YGFloatOptional num) {
static void appendFloatOptionalIfDefined(string& base, const string key,
const YGFloatOptional num) {
if (!num.isUndefined()) {
appendFormatedString(base, "%s: %g; ", key.c_str(), num.unwrap());
}
}
static void appendNumberIfNotUndefined(
string& base,
const string key,
const YGValue number) {
static void appendNumberIfNotUndefined(string& base, const string key,
const YGValue number) {
if (number.unit != YGUnitUndefined) {
if (number.unit == YGUnitAuto) {
base.append(key + ": auto; ");
} else {
string unit = number.unit == YGUnitPoint ? "px" : "%%";
appendFormatedString(
base, "%s: %g%s; ", key.c_str(), number.value, unit.c_str());
appendFormatedString(base, "%s: %g%s; ", key.c_str(), number.value,
unit.c_str());
}
}
}
static void appendNumberIfNotAuto(
string& base,
const string& key,
const YGValue number) {
static void appendNumberIfNotAuto(string& base, const string& key,
const YGValue number) {
if (number.unit != YGUnitAuto) {
appendNumberIfNotUndefined(base, key, number);
}
}
static void appendNumberIfNotZero(
string& base,
const string& str,
const YGValue number) {
static void appendNumberIfNotZero(string& base, const string& str,
const YGValue number) {
if (number.unit == YGUnitAuto) {
base.append(str + ": auto; ");
} else if (!YGFloatsEqual(number.value, 0)) {
@ -85,10 +79,8 @@ static void appendNumberIfNotZero(
}
}
static void appendEdges(
string& base,
const string& key,
const YGStyle::Edges& edges) {
static void appendEdges(string& base, const string& key,
const YGStyle::Edges& edges) {
if (areFourValuesEqual(edges)) {
appendNumberIfNotZero(base, key, edges[YGEdgeLeft]);
} else {
@ -99,35 +91,29 @@ static void appendEdges(
}
}
static void appendEdgeIfNotUndefined(
string& base,
const string& str,
const YGStyle::Edges& edges,
const YGEdge edge) {
static void appendEdgeIfNotUndefined(string& base, const string& str,
const YGStyle::Edges& edges,
const YGEdge edge) {
appendNumberIfNotUndefined(
base,
str,
base, str,
YGComputedEdgeValue(edges, edge, detail::CompactValue::ofUndefined()));
}
void YGNodeToString(
std::string& str,
YGNodeRef node,
YGPrintOptions options,
uint32_t level) {
void YGNodeToString(std::string& str, YGNodeRef node, YGPrintOptions options,
uint32_t level) {
indent(str, level);
appendFormatedString(str, "<div ");
if (options & YGPrintOptionsLayout) {
appendFormatedString(str, "layout=\"");
appendFormatedString(
str, "width: %g; ", node->getLayout().dimensions[YGDimensionWidth]);
appendFormatedString(
str, "height: %g; ", node->getLayout().dimensions[YGDimensionHeight]);
appendFormatedString(
str, "top: %g; ", node->getLayout().position[YGEdgeTop]);
appendFormatedString(
str, "left: %g;", node->getLayout().position[YGEdgeLeft]);
appendFormatedString(str, "width: %g; ",
node->getLayout().dimensions[YGDimensionWidth]);
appendFormatedString(str, "height: %g; ",
node->getLayout().dimensions[YGDimensionHeight]);
appendFormatedString(str, "top: %g; ",
node->getLayout().position[YGEdgeTop]);
appendFormatedString(str, "left: %g;",
node->getLayout().position[YGEdgeLeft]);
appendFormatedString(str, "\" ");
}
@ -135,28 +121,24 @@ void YGNodeToString(
appendFormatedString(str, "style=\"");
const auto& style = node->getStyle();
if (style.flexDirection() != YGNode().getStyle().flexDirection()) {
appendFormatedString(
str,
"flex-direction: %s; ",
YGFlexDirectionToString(style.flexDirection()));
appendFormatedString(str, "flex-direction: %s; ",
YGFlexDirectionToString(style.flexDirection()));
}
if (style.justifyContent() != YGNode().getStyle().justifyContent()) {
appendFormatedString(
str,
"justify-content: %s; ",
YGJustifyToString(style.justifyContent()));
appendFormatedString(str, "justify-content: %s; ",
YGJustifyToString(style.justifyContent()));
}
if (style.alignItems() != YGNode().getStyle().alignItems()) {
appendFormatedString(
str, "align-items: %s; ", YGAlignToString(style.alignItems()));
appendFormatedString(str, "align-items: %s; ",
YGAlignToString(style.alignItems()));
}
if (style.alignContent() != YGNode().getStyle().alignContent()) {
appendFormatedString(
str, "align-content: %s; ", YGAlignToString(style.alignContent()));
appendFormatedString(str, "align-content: %s; ",
YGAlignToString(style.alignContent()));
}
if (style.alignSelf() != YGNode().getStyle().alignSelf()) {
appendFormatedString(
str, "align-self: %s; ", YGAlignToString(style.alignSelf()));
appendFormatedString(str, "align-self: %s; ",
YGAlignToString(style.alignSelf()));
}
appendFloatOptionalIfDefined(str, "flex-grow", style.flexGrow());
appendFloatOptionalIfDefined(str, "flex-shrink", style.flexShrink());
@ -164,18 +146,18 @@ void YGNodeToString(
appendFloatOptionalIfDefined(str, "flex", style.flex());
if (style.flexWrap() != YGNode().getStyle().flexWrap()) {
appendFormatedString(
str, "flex-wrap: %s; ", YGWrapToString(style.flexWrap()));
appendFormatedString(str, "flex-wrap: %s; ",
YGWrapToString(style.flexWrap()));
}
if (style.overflow() != YGNode().getStyle().overflow()) {
appendFormatedString(
str, "overflow: %s; ", YGOverflowToString(style.overflow()));
appendFormatedString(str, "overflow: %s; ",
YGOverflowToString(style.overflow()));
}
if (style.display() != YGNode().getStyle().display()) {
appendFormatedString(
str, "display: %s; ", YGDisplayToString(style.display()));
appendFormatedString(str, "display: %s; ",
YGDisplayToString(style.display()));
}
appendEdges(str, "margin", style.margin());
appendEdges(str, "padding", style.padding());
@ -183,18 +165,18 @@ void YGNodeToString(
appendNumberIfNotAuto(str, "width", style.dimensions()[YGDimensionWidth]);
appendNumberIfNotAuto(str, "height", style.dimensions()[YGDimensionHeight]);
appendNumberIfNotAuto(
str, "max-width", style.maxDimensions()[YGDimensionWidth]);
appendNumberIfNotAuto(
str, "max-height", style.maxDimensions()[YGDimensionHeight]);
appendNumberIfNotAuto(
str, "min-width", style.minDimensions()[YGDimensionWidth]);
appendNumberIfNotAuto(
str, "min-height", style.minDimensions()[YGDimensionHeight]);
appendNumberIfNotAuto(str, "max-width",
style.maxDimensions()[YGDimensionWidth]);
appendNumberIfNotAuto(str, "max-height",
style.maxDimensions()[YGDimensionHeight]);
appendNumberIfNotAuto(str, "min-width",
style.minDimensions()[YGDimensionWidth]);
appendNumberIfNotAuto(str, "min-height",
style.minDimensions()[YGDimensionHeight]);
if (style.positionType() != YGNode().getStyle().positionType()) {
appendFormatedString(
str, "position: %s; ", YGPositionTypeToString(style.positionType()));
appendFormatedString(str, "position: %s; ",
YGPositionTypeToString(style.positionType()));
}
appendEdgeIfNotUndefined(str, "left", style.position(), YGEdgeLeft);
@ -220,6 +202,6 @@ void YGNodeToString(
}
appendFormatedString(str, "</div>");
}
} // namespace yoga
} // namespace facebook
} // namespace yoga
} // namespace facebook
#endif

View File

@ -14,12 +14,9 @@
namespace facebook {
namespace yoga {
void YGNodeToString(
std::string& str,
YGNodeRef node,
YGPrintOptions options,
uint32_t level);
void YGNodeToString(std::string& str, YGNodeRef node, YGPrintOptions options,
uint32_t level);
} // namespace yoga
} // namespace facebook
} // namespace yoga
} // namespace facebook
#endif

View File

@ -6,11 +6,13 @@
*/
#include "YGStyle.h"
#include "Utils.h"
// Yoga specific properties, not compatible with flexbox specification
bool operator==(const YGStyle& lhs, const YGStyle& rhs) {
bool areNonFloatValuesEqual = lhs.direction() == rhs.direction() &&
bool areNonFloatValuesEqual =
lhs.direction() == rhs.direction() &&
lhs.flexDirection() == rhs.flexDirection() &&
lhs.justifyContent() == rhs.justifyContent() &&
lhs.alignContent() == rhs.alignContent() &&
@ -27,20 +29,22 @@ bool operator==(const YGStyle& lhs, const YGStyle& rhs) {
lhs.maxDimensions() == rhs.maxDimensions();
areNonFloatValuesEqual = areNonFloatValuesEqual &&
lhs.flex().isUndefined() == rhs.flex().isUndefined();
lhs.flex().isUndefined() == rhs.flex().isUndefined();
if (areNonFloatValuesEqual && !lhs.flex().isUndefined() &&
!rhs.flex().isUndefined()) {
areNonFloatValuesEqual = areNonFloatValuesEqual && lhs.flex() == rhs.flex();
}
areNonFloatValuesEqual = areNonFloatValuesEqual &&
areNonFloatValuesEqual =
areNonFloatValuesEqual &&
lhs.flexGrow().isUndefined() == rhs.flexGrow().isUndefined();
if (areNonFloatValuesEqual && !lhs.flexGrow().isUndefined()) {
areNonFloatValuesEqual =
areNonFloatValuesEqual && lhs.flexGrow() == rhs.flexGrow();
}
areNonFloatValuesEqual = areNonFloatValuesEqual &&
areNonFloatValuesEqual =
areNonFloatValuesEqual &&
lhs.flexShrink().isUndefined() == rhs.flexShrink().isUndefined();
if (areNonFloatValuesEqual && !rhs.flexShrink().isUndefined()) {
areNonFloatValuesEqual =

View File

@ -13,12 +13,13 @@
#include <array>
#include <cstdint>
#include <type_traits>
#include "BitUtils.h"
#include "CompactValue.h"
#include "YGEnums.h"
#include "YGFloatOptional.h"
#include "Yoga-internal.h"
#include "Yoga.h"
#include "BitUtils.h"
class YOGA_EXPORT YGStyle {
template <typename Enum>
@ -26,7 +27,7 @@ class YOGA_EXPORT YGStyle {
facebook::yoga::detail::Values<facebook::yoga::enums::count<Enum>()>;
using CompactValue = facebook::yoga::detail::CompactValue;
public:
public:
using Dimensions = Values<YGDimension>;
using Edges = Values<YGEdge>;
@ -71,7 +72,7 @@ public:
style.*Prop = values;
return *this;
}
operator const Values<Idx>&() const { return style.*Prop; }
operator const Values<Idx> &() const { return style.*Prop; }
Ref operator[](Idx idx) { return {style, idx}; }
CompactValue operator[](Idx idx) const { return (style.*Prop)[idx]; }
};
@ -82,11 +83,12 @@ public:
}
~YGStyle() = default;
private:
private:
static constexpr size_t directionOffset = 0;
static constexpr size_t flexdirectionOffset =
directionOffset + facebook::yoga::detail::bitWidthFn<YGDirection>();
static constexpr size_t justifyContentOffset = flexdirectionOffset +
static constexpr size_t justifyContentOffset =
flexdirectionOffset +
facebook::yoga::detail::bitWidthFn<YGFlexDirection>();
static constexpr size_t alignContentOffset =
justifyContentOffset + facebook::yoga::detail::bitWidthFn<YGJustify>();
@ -119,13 +121,13 @@ private:
// Yoga specific properties, not compatible with flexbox specification
YGFloatOptional aspectRatio_ = {};
public:
public:
// for library users needing a type
using ValueRepr = std::remove_reference<decltype(margin_[0])>::type;
YGDirection direction() const {
return facebook::yoga::detail::getEnumData<YGDirection>(
flags, directionOffset);
return facebook::yoga::detail::getEnumData<YGDirection>(flags,
directionOffset);
}
BitfieldRef<YGDirection> direction() { return {*this, directionOffset}; }
@ -138,22 +140,22 @@ public:
}
YGJustify justifyContent() const {
return facebook::yoga::detail::getEnumData<YGJustify>(
flags, justifyContentOffset);
return facebook::yoga::detail::getEnumData<YGJustify>(flags,
justifyContentOffset);
}
BitfieldRef<YGJustify> justifyContent() {
return {*this, justifyContentOffset};
}
YGAlign alignContent() const {
return facebook::yoga::detail::getEnumData<YGAlign>(
flags, alignContentOffset);
return facebook::yoga::detail::getEnumData<YGAlign>(flags,
alignContentOffset);
}
BitfieldRef<YGAlign> alignContent() { return {*this, alignContentOffset}; }
YGAlign alignItems() const {
return facebook::yoga::detail::getEnumData<YGAlign>(
flags, alignItemsOffset);
return facebook::yoga::detail::getEnumData<YGAlign>(flags,
alignItemsOffset);
}
BitfieldRef<YGAlign> alignItems() { return {*this, alignItemsOffset}; }
@ -176,8 +178,8 @@ public:
BitfieldRef<YGWrap> flexWrap() { return {*this, flexWrapOffset}; }
YGOverflow overflow() const {
return facebook::yoga::detail::getEnumData<YGOverflow>(
flags, overflowOffset);
return facebook::yoga::detail::getEnumData<YGOverflow>(flags,
overflowOffset);
}
BitfieldRef<YGOverflow> overflow() { return {*this, overflowOffset}; }

View File

@ -8,6 +8,7 @@
#pragma once
#include <math.h>
#include "YGEnums.h"
#include "YGMacros.h"
@ -23,7 +24,7 @@ YG_EXTERN_C_BEGIN
// Not defined in MSVC++
#ifndef NAN
static const uint32_t __nan = 0x7fc00000;
#define NAN (*(const float*) __nan)
#define NAN (*(const float*)__nan)
#endif
#define YGUndefined NAN
@ -88,8 +89,8 @@ inline YGValue operator"" _percent(unsigned long long value) {
return operator"" _percent(static_cast<long double>(value));
}
} // namespace literals
} // namespace yoga
} // namespace facebook
} // namespace literals
} // namespace yoga
} // namespace facebook
#endif

View File

@ -10,6 +10,7 @@
#include <array>
#include <cmath>
#include <vector>
#include "CompactValue.h"
#include "Yoga.h"
@ -17,24 +18,20 @@ using YGVector = std::vector<YGNodeRef>;
YG_EXTERN_C_BEGIN
void YGNodeCalculateLayoutWithContext(
YGNodeRef node,
float availableWidth,
float availableHeight,
YGDirection ownerDirection,
void* layoutContext);
void YGNodeCalculateLayoutWithContext(YGNodeRef node, float availableWidth,
float availableHeight,
YGDirection ownerDirection,
void* layoutContext);
YG_EXTERN_C_END
namespace facebook {
namespace yoga {
inline bool isUndefined(float value) {
return std::isnan(value);
}
inline bool isUndefined(float value) { return std::isnan(value); }
} // namespace yoga
} // namespace facebook
} // namespace yoga
} // namespace facebook
using namespace facebook;
@ -63,7 +60,7 @@ struct YGCachedMeasurement {
bool operator==(YGCachedMeasurement measurement) const {
bool isEqual = widthMeasureMode == measurement.widthMeasureMode &&
heightMeasureMode == measurement.heightMeasureMode;
heightMeasureMode == measurement.heightMeasureMode;
if (!yoga::isUndefined(availableWidth) ||
!yoga::isUndefined(measurement.availableWidth)) {
@ -96,10 +93,10 @@ namespace detail {
template <size_t Size>
class Values {
private:
private:
std::array<CompactValue, Size> values_;
public:
public:
Values() = default;
explicit Values(const YGValue& defaultValue) noexcept {
values_.fill(defaultValue);
@ -135,9 +132,9 @@ public:
Values& operator=(const Values& other) = default;
};
} // namespace detail
} // namespace yoga
} // namespace facebook
} // namespace detail
} // namespace yoga
} // namespace facebook
static const float kDefaultFlexGrow = 0.0f;
static const float kDefaultFlexShrink = 0.0f;
@ -147,5 +144,4 @@ extern bool YGFloatsEqual(const float a, const float b);
extern facebook::yoga::detail::CompactValue YGComputedEdgeValue(
const facebook::yoga::detail::Values<
facebook::yoga::enums::count<YGEdge>()>& edges,
YGEdge edge,
facebook::yoga::detail::CompactValue defaultValue);
YGEdge edge, facebook::yoga::detail::CompactValue defaultValue);

File diff suppressed because it is too large Load Diff

View File

@ -34,45 +34,33 @@ typedef struct YGConfig* YGConfigRef;
typedef struct YGNode* YGNodeRef;
typedef const struct YGNode* YGNodeConstRef;
typedef YGSize (*YGMeasureFunc)(
YGNodeRef node,
float width,
YGMeasureMode widthMode,
float height,
YGMeasureMode heightMode);
typedef YGSize (*YGMeasureFunc)(YGNodeRef node, float width,
YGMeasureMode widthMode, float height,
YGMeasureMode heightMode);
typedef float (*YGBaselineFunc)(YGNodeRef node, float width, float height);
typedef void (*YGDirtiedFunc)(YGNodeRef node);
typedef void (*YGPrintFunc)(YGNodeRef node);
typedef void (*YGNodeCleanupFunc)(YGNodeRef node);
typedef int (*YGLogger)(
YGConfigRef config,
YGNodeRef node,
YGLogLevel level,
const char* format,
va_list args);
typedef YGNodeRef (
*YGCloneNodeFunc)(YGNodeRef oldNode, YGNodeRef owner, int childIndex);
typedef int (*YGLogger)(YGConfigRef config, YGNodeRef node, YGLogLevel level,
const char* format, va_list args);
typedef YGNodeRef (*YGCloneNodeFunc)(YGNodeRef oldNode, YGNodeRef owner,
int childIndex);
// YGNode
WIN_EXPORT YGNodeRef YGNodeNew(void);
WIN_EXPORT YGNodeRef YGNodeNewWithConfig(YGConfigRef config);
WIN_EXPORT YGNodeRef YGNodeClone(YGNodeRef node);
WIN_EXPORT void YGNodeFree(YGNodeRef node);
WIN_EXPORT void YGNodeFreeRecursiveWithCleanupFunc(
YGNodeRef node,
YGNodeCleanupFunc cleanup);
WIN_EXPORT void YGNodeFreeRecursiveWithCleanupFunc(YGNodeRef node,
YGNodeCleanupFunc cleanup);
WIN_EXPORT void YGNodeFreeRecursive(YGNodeRef node);
WIN_EXPORT void YGNodeReset(YGNodeRef node);
WIN_EXPORT void YGNodeInsertChild(
YGNodeRef node,
YGNodeRef child,
uint32_t index);
WIN_EXPORT void YGNodeInsertChild(YGNodeRef node, YGNodeRef child,
uint32_t index);
WIN_EXPORT void YGNodeSwapChild(
YGNodeRef node,
YGNodeRef child,
uint32_t index);
WIN_EXPORT void YGNodeSwapChild(YGNodeRef node, YGNodeRef child,
uint32_t index);
WIN_EXPORT void YGNodeRemoveChild(YGNodeRef node, YGNodeRef child);
WIN_EXPORT void YGNodeRemoveAllChildren(YGNodeRef node);
@ -80,22 +68,17 @@ WIN_EXPORT YGNodeRef YGNodeGetChild(YGNodeRef node, uint32_t index);
WIN_EXPORT YGNodeRef YGNodeGetOwner(YGNodeRef node);
WIN_EXPORT YGNodeRef YGNodeGetParent(YGNodeRef node);
WIN_EXPORT uint32_t YGNodeGetChildCount(YGNodeRef node);
WIN_EXPORT void YGNodeSetChildren(
YGNodeRef owner,
const YGNodeRef children[],
uint32_t count);
WIN_EXPORT void YGNodeSetChildren(YGNodeRef owner, const YGNodeRef children[],
uint32_t count);
WIN_EXPORT void YGNodeSetIsReferenceBaseline(
YGNodeRef node,
bool isReferenceBaseline);
WIN_EXPORT void YGNodeSetIsReferenceBaseline(YGNodeRef node,
bool isReferenceBaseline);
WIN_EXPORT bool YGNodeIsReferenceBaseline(YGNodeRef node);
WIN_EXPORT void YGNodeCalculateLayout(
YGNodeRef node,
float availableWidth,
float availableHeight,
YGDirection ownerDirection);
WIN_EXPORT void YGNodeCalculateLayout(YGNodeRef node, float availableWidth,
float availableHeight,
YGDirection ownerDirection);
// Mark a node as dirty. Only valid for nodes with a custom measure function
// set.
@ -116,18 +99,10 @@ WIN_EXPORT void YGNodePrint(YGNodeRef node, YGPrintOptions options);
WIN_EXPORT bool YGFloatIsUndefined(float value);
WIN_EXPORT bool YGNodeCanUseCachedMeasurement(
YGMeasureMode widthMode,
float width,
YGMeasureMode heightMode,
float height,
YGMeasureMode lastWidthMode,
float lastWidth,
YGMeasureMode lastHeightMode,
float lastHeight,
float lastComputedWidth,
float lastComputedHeight,
float marginRow,
float marginColumn,
YGMeasureMode widthMode, float width, YGMeasureMode heightMode,
float height, YGMeasureMode lastWidthMode, float lastWidth,
YGMeasureMode lastHeightMode, float lastHeight, float lastComputedWidth,
float lastComputedHeight, float marginRow, float marginColumn,
YGConfigRef config);
WIN_EXPORT void YGNodeCopyStyle(YGNodeRef dstNode, YGNodeRef srcNode);
@ -152,19 +127,16 @@ bool YGNodeLayoutGetDidUseLegacyFlag(YGNodeRef node);
WIN_EXPORT void YGNodeStyleSetDirection(YGNodeRef node, YGDirection direction);
WIN_EXPORT YGDirection YGNodeStyleGetDirection(YGNodeConstRef node);
WIN_EXPORT void YGNodeStyleSetFlexDirection(
YGNodeRef node,
YGFlexDirection flexDirection);
WIN_EXPORT void YGNodeStyleSetFlexDirection(YGNodeRef node,
YGFlexDirection flexDirection);
WIN_EXPORT YGFlexDirection YGNodeStyleGetFlexDirection(YGNodeConstRef node);
WIN_EXPORT void YGNodeStyleSetJustifyContent(
YGNodeRef node,
YGJustify justifyContent);
WIN_EXPORT void YGNodeStyleSetJustifyContent(YGNodeRef node,
YGJustify justifyContent);
WIN_EXPORT YGJustify YGNodeStyleGetJustifyContent(YGNodeConstRef node);
WIN_EXPORT void YGNodeStyleSetAlignContent(
YGNodeRef node,
YGAlign alignContent);
WIN_EXPORT void YGNodeStyleSetAlignContent(YGNodeRef node,
YGAlign alignContent);
WIN_EXPORT YGAlign YGNodeStyleGetAlignContent(YGNodeConstRef node);
WIN_EXPORT void YGNodeStyleSetAlignItems(YGNodeRef node, YGAlign alignItems);
@ -173,9 +145,8 @@ WIN_EXPORT YGAlign YGNodeStyleGetAlignItems(YGNodeConstRef node);
WIN_EXPORT void YGNodeStyleSetAlignSelf(YGNodeRef node, YGAlign alignSelf);
WIN_EXPORT YGAlign YGNodeStyleGetAlignSelf(YGNodeConstRef node);
WIN_EXPORT void YGNodeStyleSetPositionType(
YGNodeRef node,
YGPositionType positionType);
WIN_EXPORT void YGNodeStyleSetPositionType(YGNodeRef node,
YGPositionType positionType);
WIN_EXPORT YGPositionType YGNodeStyleGetPositionType(YGNodeConstRef node);
WIN_EXPORT void YGNodeStyleSetFlexWrap(YGNodeRef node, YGWrap flexWrap);
@ -201,32 +172,22 @@ WIN_EXPORT void YGNodeStyleSetFlexBasisPercent(YGNodeRef node, float flexBasis);
WIN_EXPORT void YGNodeStyleSetFlexBasisAuto(YGNodeRef node);
WIN_EXPORT YGValue YGNodeStyleGetFlexBasis(YGNodeConstRef node);
WIN_EXPORT void YGNodeStyleSetPosition(
YGNodeRef node,
YGEdge edge,
float position);
WIN_EXPORT void YGNodeStyleSetPositionPercent(
YGNodeRef node,
YGEdge edge,
float position);
WIN_EXPORT void YGNodeStyleSetPosition(YGNodeRef node, YGEdge edge,
float position);
WIN_EXPORT void YGNodeStyleSetPositionPercent(YGNodeRef node, YGEdge edge,
float position);
WIN_EXPORT YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge);
WIN_EXPORT void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, float margin);
WIN_EXPORT void YGNodeStyleSetMarginPercent(
YGNodeRef node,
YGEdge edge,
float margin);
WIN_EXPORT void YGNodeStyleSetMarginPercent(YGNodeRef node, YGEdge edge,
float margin);
WIN_EXPORT void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge);
WIN_EXPORT YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge);
WIN_EXPORT void YGNodeStyleSetPadding(
YGNodeRef node,
YGEdge edge,
float padding);
WIN_EXPORT void YGNodeStyleSetPaddingPercent(
YGNodeRef node,
YGEdge edge,
float padding);
WIN_EXPORT void YGNodeStyleSetPadding(YGNodeRef node, YGEdge edge,
float padding);
WIN_EXPORT void YGNodeStyleSetPaddingPercent(YGNodeRef node, YGEdge edge,
float padding);
WIN_EXPORT YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge);
WIN_EXPORT void YGNodeStyleSetBorder(YGNodeRef node, YGEdge edge, float border);
@ -296,22 +257,16 @@ WIN_EXPORT float YGNodeLayoutGetPadding(YGNodeRef node, YGEdge edge);
WIN_EXPORT void YGConfigSetLogger(YGConfigRef config, YGLogger logger);
WIN_EXPORT void YGAssert(bool condition, const char* message);
WIN_EXPORT void YGAssertWithNode(
YGNodeRef node,
bool condition,
const char* message);
WIN_EXPORT void YGAssertWithConfig(
YGConfigRef config,
bool condition,
const char* message);
WIN_EXPORT void YGAssertWithNode(YGNodeRef node, bool condition,
const char* message);
WIN_EXPORT void YGAssertWithConfig(YGConfigRef config, bool condition,
const char* message);
// Set this to number of pixels in 1 point to round calculation results If you
// want to avoid rounding - set PointScaleFactor to 0
WIN_EXPORT void YGConfigSetPointScaleFactor(
YGConfigRef config,
float pixelsInPoint);
WIN_EXPORT void YGConfigSetPointScaleFactor(YGConfigRef config,
float pixelsInPoint);
void YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
YGConfigRef config,
bool shouldDiffLayout);
YGConfigRef config, bool shouldDiffLayout);
// Yoga previously had an error where containers would take the maximum space
// possible instead of the minimum like they are supposed to. In practice this
@ -319,8 +274,7 @@ void YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
// was such a long-standing bug we must allow legacy users to switch back to
// this behaviour.
WIN_EXPORT void YGConfigSetUseLegacyStretchBehaviour(
YGConfigRef config,
bool useLegacyStretchBehaviour);
YGConfigRef config, bool useLegacyStretchBehaviour);
// YGConfig
WIN_EXPORT YGConfigRef YGConfigNew(void);
@ -329,21 +283,17 @@ WIN_EXPORT void YGConfigCopy(YGConfigRef dest, YGConfigRef src);
WIN_EXPORT int32_t YGConfigGetInstanceCount(void);
WIN_EXPORT void YGConfigSetExperimentalFeatureEnabled(
YGConfigRef config,
YGExperimentalFeature feature,
bool enabled);
YGConfigRef config, YGExperimentalFeature feature, bool enabled);
WIN_EXPORT bool YGConfigIsExperimentalFeatureEnabled(
YGConfigRef config,
YGExperimentalFeature feature);
YGConfigRef config, YGExperimentalFeature feature);
// Using the web defaults is the preferred configuration for new projects. Usage
// of non web defaults should be considered as legacy.
WIN_EXPORT void YGConfigSetUseWebDefaults(YGConfigRef config, bool enabled);
WIN_EXPORT bool YGConfigGetUseWebDefaults(YGConfigRef config);
WIN_EXPORT void YGConfigSetCloneNodeFunc(
YGConfigRef config,
YGCloneNodeFunc callback);
WIN_EXPORT void YGConfigSetCloneNodeFunc(YGConfigRef config,
YGCloneNodeFunc callback);
// Export only for C#
WIN_EXPORT YGConfigRef YGConfigGetDefault(void);
@ -351,11 +301,8 @@ WIN_EXPORT YGConfigRef YGConfigGetDefault(void);
WIN_EXPORT void YGConfigSetContext(YGConfigRef config, void* context);
WIN_EXPORT void* YGConfigGetContext(YGConfigRef config);
WIN_EXPORT float YGRoundValueToPixelGrid(
double value,
double pointScaleFactor,
bool forceCeil,
bool forceFloor);
WIN_EXPORT float YGRoundValueToPixelGrid(double value, double pointScaleFactor,
bool forceCeil, bool forceFloor);
YG_EXTERN_C_END
@ -365,9 +312,8 @@ YG_EXTERN_C_END
#include <vector>
// Calls f on each node in the tree including the given node argument.
void YGTraversePreOrder(
YGNodeRef node,
std::function<void(YGNodeRef node)>&& f);
void YGTraversePreOrder(YGNodeRef node,
std::function<void(YGNodeRef node)>&& f);
void YGNodeSetChildren(YGNodeRef owner, const std::vector<YGNodeRef>& children);

View File

@ -6,6 +6,7 @@
*/
#include "event.h"
#include <atomic>
#include <memory>
@ -59,7 +60,7 @@ Node* push(Node* newHead) {
return oldHead;
}
} // namespace
} // namespace
void Event::reset() {
auto head = push(nullptr);
@ -76,11 +77,10 @@ void Event::subscribe(std::function<Subscriber>&& subscriber) {
void Event::publish(const YGNode& node, Type eventType, const Data& eventData) {
for (auto subscriber = subscribers.load(std::memory_order_relaxed);
subscriber != nullptr;
subscriber = subscriber->next) {
subscriber != nullptr; subscriber = subscriber->next) {
subscriber->subscriber(node, eventType, eventData);
}
}
} // namespace yoga
} // namespace facebook
} // namespace yoga
} // namespace facebook

View File

@ -7,11 +7,12 @@
#pragma once
#include <stdint.h>
#include <yoga/YGEnums.h>
#include <array>
#include <functional>
#include <vector>
#include <array>
#include <yoga/YGEnums.h>
#include <stdint.h>
struct YGConfig;
struct YGNode;
@ -73,7 +74,7 @@ struct YOGA_EXPORT Event {
class Data {
const void* data_;
public:
public:
template <Type E>
Data(const TypedData<E>& data) : data_{&data} {}
@ -99,7 +100,7 @@ struct YOGA_EXPORT Event {
publish<E>(*node, eventData);
}
private:
private:
static void publish(const YGNode&, Type, const Data&);
};
@ -142,5 +143,5 @@ struct Event::TypedData<Event::NodeLayout> {
void* layoutContext;
};
} // namespace yoga
} // namespace facebook
} // namespace yoga
} // namespace facebook

View File

@ -7,26 +7,24 @@
#pragma once
#include "experiments.h"
#include <bitset>
#include "experiments.h"
namespace facebook {
namespace yoga {
namespace internal {
namespace detail {
extern std::bitset<sizeof(int)> enabledExperiments;
} // namespace detail
} // namespace detail
inline bool isEnabled(Experiment experiment) {
return detail::enabledExperiments.test(static_cast<size_t>(experiment));
}
inline void disableAllExperiments() {
detail::enabledExperiments = 0;
}
inline void disableAllExperiments() { detail::enabledExperiments = 0; }
} // namespace internal
} // namespace yoga
} // namespace facebook
} // namespace internal
} // namespace yoga
} // namespace facebook

View File

@ -6,6 +6,7 @@
*/
#include "experiments.h"
#include "experiments-inl.h"
namespace facebook {
@ -16,7 +17,7 @@ namespace detail {
std::bitset<sizeof(int)> enabledExperiments = 0;
} // namespace detail
} // namespace detail
void enable(Experiment experiment) {
detail::enabledExperiments.set(static_cast<size_t>(experiment));
@ -33,6 +34,6 @@ bool toggle(Experiment experiment) {
return previousState;
}
} // namespace internal
} // namespace yoga
} // namespace facebook
} // namespace internal
} // namespace yoga
} // namespace facebook

View File

@ -21,6 +21,6 @@ void enable(Experiment);
void disable(Experiment);
bool toggle(Experiment);
} // namespace internal
} // namespace yoga
} // namespace facebook
} // namespace internal
} // namespace yoga
} // namespace facebook

View File

@ -7,9 +7,9 @@
#include "log.h"
#include "Yoga.h"
#include "YGConfig.h"
#include "YGNode.h"
#include "Yoga.h"
namespace facebook {
namespace yoga {
@ -17,48 +17,30 @@ namespace detail {
namespace {
void vlog(
YGConfig* config,
YGNode* node,
YGLogLevel level,
void* context,
const char* format,
va_list args) {
void vlog(YGConfig* config, YGNode* node, YGLogLevel level, void* context,
const char* format, va_list args) {
YGConfig* logConfig = config != nullptr ? config : YGConfigGetDefault();
logConfig->log(logConfig, node, level, context, format, args);
}
} // namespace
} // namespace
YOGA_EXPORT void Log::log(
YGNode* node,
YGLogLevel level,
void* context,
const char* format,
...) noexcept {
YOGA_EXPORT void Log::log(YGNode* node, YGLogLevel level, void* context,
const char* format, ...) noexcept {
va_list args;
va_start(args, format);
vlog(
node == nullptr ? nullptr : node->getConfig(),
node,
level,
context,
format,
args);
vlog(node == nullptr ? nullptr : node->getConfig(), node, level, context,
format, args);
va_end(args);
}
void Log::log(
YGConfig* config,
YGLogLevel level,
void* context,
const char* format,
...) noexcept {
void Log::log(YGConfig* config, YGLogLevel level, void* context,
const char* format, ...) noexcept {
va_list args;
va_start(args, format);
vlog(config, nullptr, level, context, format, args);
va_end(args);
}
} // namespace detail
} // namespace yoga
} // namespace facebook
} // namespace detail
} // namespace yoga
} // namespace facebook

View File

@ -18,21 +18,13 @@ namespace yoga {
namespace detail {
struct Log {
static void log(
YGNode* node,
YGLogLevel level,
void*,
const char* message,
...) noexcept;
static void log(YGNode* node, YGLogLevel level, void*, const char* message,
...) noexcept;
static void log(
YGConfig* config,
YGLogLevel level,
void*,
const char* format,
...) noexcept;
static void log(YGConfig* config, YGLogLevel level, void*, const char* format,
...) noexcept;
};
} // namespace detail
} // namespace yoga
} // namespace facebook
} // namespace detail
} // namespace yoga
} // namespace facebook

View File

@ -3,7 +3,6 @@ import { QLabel } from './lib/QtWidgets/QLabel';
import { QScrollArea } from './lib/QtWidgets/QScrollArea';
import { FlexLayout } from './lib/core/FlexLayout';
import { WidgetEventTypes } from './lib/core/EventWidget';
import { SizeConstraint } from './lib/QtWidgets/QLayout';
const win = new QMainWindow();
win.resize(500, 500);