2019-06-06 19:36:56 -07:00
|
|
|
/*
|
2021-12-30 15:08:43 -08:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2016-11-15 08:42:33 -08:00
|
|
|
*
|
2019-10-15 10:30:08 -07:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-11-15 08:42:33 -08:00
|
|
|
*/
|
2019-10-15 10:30:08 -07:00
|
|
|
|
2016-12-05 04:58:55 -08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "YGMacros.h"
|
|
|
|
|
2019-01-11 03:09:11 -08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
namespace facebook {
|
|
|
|
namespace yoga {
|
|
|
|
namespace enums {
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
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 enums
|
|
|
|
} // namespace yoga
|
|
|
|
} // namespace facebook
|
|
|
|
#endif
|
|
|
|
|
2019-01-08 12:47:54 -08:00
|
|
|
#define YG_ENUM_DECL(NAME, ...) \
|
|
|
|
typedef YG_ENUM_BEGIN(NAME){__VA_ARGS__} YG_ENUM_END(NAME); \
|
|
|
|
WIN_EXPORT const char* NAME##ToString(NAME);
|
|
|
|
|
2019-01-11 03:09:11 -08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
#define YG_ENUM_SEQ_DECL(NAME, ...) \
|
|
|
|
YG_ENUM_DECL(NAME, __VA_ARGS__) \
|
|
|
|
YG_EXTERN_C_END \
|
|
|
|
namespace facebook { \
|
|
|
|
namespace yoga { \
|
|
|
|
namespace enums { \
|
|
|
|
template <> \
|
|
|
|
constexpr int count<NAME>() { \
|
|
|
|
return detail::n<__VA_ARGS__>(); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
YG_EXTERN_C_BEGIN
|
|
|
|
#else
|
|
|
|
#define YG_ENUM_SEQ_DECL YG_ENUM_DECL
|
|
|
|
#endif
|
|
|
|
|
2016-12-05 04:58:55 -08:00
|
|
|
YG_EXTERN_C_BEGIN
|
|
|
|
|
2019-01-11 03:09:11 -08:00
|
|
|
YG_ENUM_SEQ_DECL(
|
2019-01-08 12:47:54 -08:00
|
|
|
YGAlign,
|
2019-01-08 12:47:53 -08:00
|
|
|
YGAlignAuto,
|
|
|
|
YGAlignFlexStart,
|
|
|
|
YGAlignCenter,
|
|
|
|
YGAlignFlexEnd,
|
|
|
|
YGAlignStretch,
|
|
|
|
YGAlignBaseline,
|
|
|
|
YGAlignSpaceBetween,
|
2019-01-08 12:47:54 -08:00
|
|
|
YGAlignSpaceAround);
|
2016-11-15 08:42:33 -08:00
|
|
|
|
2019-01-11 03:09:11 -08:00
|
|
|
YG_ENUM_SEQ_DECL(YGDimension, YGDimensionWidth, YGDimensionHeight)
|
2016-11-15 08:42:33 -08:00
|
|
|
|
2019-01-11 03:09:11 -08:00
|
|
|
YG_ENUM_SEQ_DECL(
|
|
|
|
YGDirection,
|
|
|
|
YGDirectionInherit,
|
|
|
|
YGDirectionLTR,
|
|
|
|
YGDirectionRTL)
|
2016-11-15 08:42:33 -08:00
|
|
|
|
2019-01-11 03:09:11 -08:00
|
|
|
YG_ENUM_SEQ_DECL(YGDisplay, YGDisplayFlex, YGDisplayNone)
|
2017-02-06 09:31:22 -08:00
|
|
|
|
2019-01-11 03:09:11 -08:00
|
|
|
YG_ENUM_SEQ_DECL(
|
2019-01-08 12:47:54 -08:00
|
|
|
YGEdge,
|
2019-01-08 12:47:53 -08:00
|
|
|
YGEdgeLeft,
|
|
|
|
YGEdgeTop,
|
|
|
|
YGEdgeRight,
|
|
|
|
YGEdgeBottom,
|
|
|
|
YGEdgeStart,
|
|
|
|
YGEdgeEnd,
|
|
|
|
YGEdgeHorizontal,
|
|
|
|
YGEdgeVertical,
|
2019-01-08 12:47:54 -08:00
|
|
|
YGEdgeAll)
|
2016-11-15 08:42:33 -08:00
|
|
|
|
2019-01-11 03:09:11 -08:00
|
|
|
YG_ENUM_SEQ_DECL(YGExperimentalFeature, YGExperimentalFeatureWebFlexBasis)
|
2016-11-15 08:42:33 -08:00
|
|
|
|
2019-01-11 03:09:11 -08:00
|
|
|
YG_ENUM_SEQ_DECL(
|
2019-01-08 12:47:54 -08:00
|
|
|
YGFlexDirection,
|
2019-01-08 12:47:53 -08:00
|
|
|
YGFlexDirectionColumn,
|
|
|
|
YGFlexDirectionColumnReverse,
|
|
|
|
YGFlexDirectionRow,
|
2019-01-08 12:47:54 -08:00
|
|
|
YGFlexDirectionRowReverse)
|
2016-11-15 08:42:33 -08:00
|
|
|
|
2019-01-11 03:09:11 -08:00
|
|
|
YG_ENUM_SEQ_DECL(
|
2019-01-08 12:47:54 -08:00
|
|
|
YGJustify,
|
2017-11-27 03:40:01 -08:00
|
|
|
YGJustifyFlexStart,
|
|
|
|
YGJustifyCenter,
|
|
|
|
YGJustifyFlexEnd,
|
|
|
|
YGJustifySpaceBetween,
|
|
|
|
YGJustifySpaceAround,
|
2019-01-08 12:47:54 -08:00
|
|
|
YGJustifySpaceEvenly)
|
2016-11-15 08:42:33 -08:00
|
|
|
|
2019-01-11 03:09:11 -08:00
|
|
|
YG_ENUM_SEQ_DECL(
|
2019-01-08 12:47:54 -08:00
|
|
|
YGLogLevel,
|
2019-01-08 12:47:53 -08:00
|
|
|
YGLogLevelError,
|
|
|
|
YGLogLevelWarn,
|
|
|
|
YGLogLevelInfo,
|
|
|
|
YGLogLevelDebug,
|
|
|
|
YGLogLevelVerbose,
|
2019-01-08 12:47:54 -08:00
|
|
|
YGLogLevelFatal)
|
2016-11-15 08:42:33 -08:00
|
|
|
|
2019-01-11 03:09:11 -08:00
|
|
|
YG_ENUM_SEQ_DECL(
|
2019-01-08 12:47:54 -08:00
|
|
|
YGMeasureMode,
|
2019-01-08 12:47:53 -08:00
|
|
|
YGMeasureModeUndefined,
|
|
|
|
YGMeasureModeExactly,
|
2019-01-08 12:47:54 -08:00
|
|
|
YGMeasureModeAtMost)
|
2016-11-15 08:42:33 -08:00
|
|
|
|
2019-01-11 03:09:11 -08:00
|
|
|
YG_ENUM_SEQ_DECL(YGNodeType, YGNodeTypeDefault, YGNodeTypeText)
|
2017-05-11 08:09:30 -07:00
|
|
|
|
2019-01-11 03:09:11 -08:00
|
|
|
YG_ENUM_SEQ_DECL(
|
|
|
|
YGOverflow,
|
|
|
|
YGOverflowVisible,
|
|
|
|
YGOverflowHidden,
|
|
|
|
YGOverflowScroll)
|
2016-11-15 08:42:33 -08:00
|
|
|
|
2020-07-20 00:31:15 -07:00
|
|
|
YG_ENUM_SEQ_DECL(
|
|
|
|
YGPositionType,
|
|
|
|
YGPositionTypeStatic,
|
|
|
|
YGPositionTypeRelative,
|
|
|
|
YGPositionTypeAbsolute)
|
2016-11-15 08:42:33 -08:00
|
|
|
|
2019-01-08 12:47:54 -08:00
|
|
|
YG_ENUM_DECL(
|
|
|
|
YGPrintOptions,
|
2019-01-08 12:47:53 -08:00
|
|
|
YGPrintOptionsLayout = 1,
|
|
|
|
YGPrintOptionsStyle = 2,
|
2019-01-08 12:47:54 -08:00
|
|
|
YGPrintOptionsChildren = 4)
|
2016-12-05 04:58:55 -08:00
|
|
|
|
2019-01-11 03:09:11 -08:00
|
|
|
YG_ENUM_SEQ_DECL(
|
|
|
|
YGUnit,
|
|
|
|
YGUnitUndefined,
|
|
|
|
YGUnitPoint,
|
|
|
|
YGUnitPercent,
|
|
|
|
YGUnitAuto)
|
2017-02-03 04:21:50 -08:00
|
|
|
|
2019-01-11 03:09:11 -08:00
|
|
|
YG_ENUM_SEQ_DECL(YGWrap, YGWrapNoWrap, YGWrapWrap, YGWrapWrapReverse)
|
Add feature to use percentage as value unit
Summary:
Adds the feature to use percentage as a value unit.
You can use the function ```YGPx(float)``` and ```YGPercent(float)``` for convenience.
I did some benchmarks:
```
Without Percentage Feature - Release x86:
Stack with flex: median: 0.000000 ms, stddev: 0.146683 ms
Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.136525 ms
Nested flex: median: 0.000000 ms, stddev: 0.490101 ms
Huge nested layout: median: 23.000000 ms, stddev: 0.928291 ms
Stack with flex: median: 0.000000 ms, stddev: 0.170587 ms
Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.143384 ms
Nested flex: median: 0.000000 ms, stddev: 0.477791 ms
Huge nested layout: median: 22.000000 ms, stddev: 2.129779 ms
With Percentage Feature - Release x86:
Stack with flex: median: 0.000000 ms, stddev: 0.132951 ms
Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.136525 ms
Nested flex: median: 0.000000 ms, stddev: 0.489570 ms
Huge nested layout: median: 21.000000 ms, stddev: 1.390476 ms
Closes https://github.com/facebook/yoga/pull/258
Reviewed By: dshahidehpour
Differential Revision: D4361945
Pulled By: emilsjolander
fbshipit-source-id: a8f5bc63ad352eb9410d792729e56664468cd76a
2017-01-02 05:20:37 -08:00
|
|
|
|
2016-12-05 04:58:55 -08:00
|
|
|
YG_EXTERN_C_END
|
2019-01-08 12:47:54 -08:00
|
|
|
|
|
|
|
#undef YG_ENUM_DECL
|
2019-01-11 03:09:11 -08:00
|
|
|
#undef YG_ENUM_SEQ_DECL
|