2016-11-11 10:50:09 -08:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2014-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
|
|
|
|
2017-12-05 08:16:49 -08:00
|
|
|
#include "Yoga.h"
|
2016-11-11 10:50:09 -08:00
|
|
|
#include <string.h>
|
2017-12-05 08:16:49 -08:00
|
|
|
#include <algorithm>
|
2017-12-19 11:18:00 -08:00
|
|
|
#include "YGNode.h"
|
2017-11-23 09:40:02 -08:00
|
|
|
#include "YGNodePrint.h"
|
2017-07-26 19:22:03 -07:00
|
|
|
#include "Yoga-internal.h"
|
2016-11-11 10:50:09 -08:00
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#include <float.h>
|
|
|
|
|
|
|
|
/* define fmaxf if < VC12 */
|
|
|
|
#if _MSC_VER < 1800
|
|
|
|
__forceinline const float fmaxf(const float a, const float b) {
|
|
|
|
return (a > b) ? a : b;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2017-05-03 09:22:35 -07:00
|
|
|
#ifdef ANDROID
|
|
|
|
static int YGAndroidLog(const YGConfigRef config,
|
|
|
|
const YGNodeRef node,
|
|
|
|
YGLogLevel level,
|
|
|
|
const char *format,
|
|
|
|
va_list args);
|
|
|
|
#else
|
|
|
|
static int YGDefaultLog(const YGConfigRef config,
|
|
|
|
const YGNodeRef node,
|
|
|
|
YGLogLevel level,
|
|
|
|
const char *format,
|
|
|
|
va_list args);
|
|
|
|
#endif
|
|
|
|
|
2017-03-01 09:19:55 -08:00
|
|
|
static YGConfig gYGConfigDefaults = {
|
|
|
|
.experimentalFeatures =
|
|
|
|
{
|
2017-11-21 10:10:30 -08:00
|
|
|
[YGExperimentalFeatureWebFlexBasis] = false,
|
2017-03-01 09:19:55 -08:00
|
|
|
},
|
2017-03-03 10:47:42 -08:00
|
|
|
.useWebDefaults = false,
|
2017-11-21 10:10:30 -08:00
|
|
|
.useLegacyStretchBehaviour = false,
|
2017-05-03 09:22:35 -07:00
|
|
|
.pointScaleFactor = 1.0f,
|
|
|
|
#ifdef ANDROID
|
|
|
|
.logger = &YGAndroidLog,
|
|
|
|
#else
|
|
|
|
.logger = &YGDefaultLog,
|
|
|
|
#endif
|
2017-11-21 10:10:30 -08:00
|
|
|
.cloneNodeCallback = nullptr,
|
|
|
|
.context = nullptr,
|
2017-03-01 09:19:55 -08:00
|
|
|
};
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
const YGValue YGValueZero = {.value = 0, .unit = YGUnitPoint};
|
|
|
|
const YGValue YGValueUndefined = {YGUndefined, YGUnitUndefined};
|
|
|
|
const YGValue YGValueAuto = {YGUndefined, YGUnitAuto};
|
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-11-11 10:50:09 -08:00
|
|
|
#ifdef ANDROID
|
|
|
|
#include <android/log.h>
|
2017-05-03 09:22:35 -07:00
|
|
|
static int YGAndroidLog(const YGConfigRef config,
|
|
|
|
const YGNodeRef node,
|
|
|
|
YGLogLevel level,
|
|
|
|
const char *format,
|
|
|
|
va_list args) {
|
2016-12-02 05:47:43 -08:00
|
|
|
int androidLevel = YGLogLevelDebug;
|
2016-11-11 10:50:09 -08:00
|
|
|
switch (level) {
|
2017-05-03 09:22:35 -07:00
|
|
|
case YGLogLevelFatal:
|
|
|
|
androidLevel = ANDROID_LOG_FATAL;
|
|
|
|
break;
|
2016-12-02 05:47:43 -08:00
|
|
|
case YGLogLevelError:
|
2016-11-11 10:50:09 -08:00
|
|
|
androidLevel = ANDROID_LOG_ERROR;
|
|
|
|
break;
|
2016-12-02 05:47:43 -08:00
|
|
|
case YGLogLevelWarn:
|
2016-11-11 10:50:09 -08:00
|
|
|
androidLevel = ANDROID_LOG_WARN;
|
|
|
|
break;
|
2016-12-02 05:47:43 -08:00
|
|
|
case YGLogLevelInfo:
|
2016-11-11 10:50:09 -08:00
|
|
|
androidLevel = ANDROID_LOG_INFO;
|
|
|
|
break;
|
2016-12-02 05:47:43 -08:00
|
|
|
case YGLogLevelDebug:
|
2016-11-11 10:50:09 -08:00
|
|
|
androidLevel = ANDROID_LOG_DEBUG;
|
|
|
|
break;
|
2016-12-02 05:47:43 -08:00
|
|
|
case YGLogLevelVerbose:
|
2016-11-11 10:50:09 -08:00
|
|
|
androidLevel = ANDROID_LOG_VERBOSE;
|
|
|
|
break;
|
|
|
|
}
|
2017-05-03 09:22:35 -07:00
|
|
|
const int result = __android_log_vprint(androidLevel, "yoga", format, args);
|
2016-11-11 10:50:09 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#else
|
2017-11-28 10:15:53 -08:00
|
|
|
#define YG_UNUSED(x) (void)(x);
|
|
|
|
|
2017-05-03 09:22:35 -07:00
|
|
|
static int YGDefaultLog(const YGConfigRef config,
|
|
|
|
const YGNodeRef node,
|
|
|
|
YGLogLevel level,
|
|
|
|
const char *format,
|
|
|
|
va_list args) {
|
2017-11-28 10:15:53 -08:00
|
|
|
YG_UNUSED(config);
|
|
|
|
YG_UNUSED(node);
|
2016-11-11 10:50:09 -08:00
|
|
|
switch (level) {
|
2016-12-02 05:47:43 -08:00
|
|
|
case YGLogLevelError:
|
2017-05-03 09:22:35 -07:00
|
|
|
case YGLogLevelFatal:
|
2016-11-11 10:50:09 -08:00
|
|
|
return vfprintf(stderr, format, args);
|
2016-12-02 05:47:43 -08:00
|
|
|
case YGLogLevelWarn:
|
|
|
|
case YGLogLevelInfo:
|
|
|
|
case YGLogLevelDebug:
|
|
|
|
case YGLogLevelVerbose:
|
2016-11-11 10:50:09 -08:00
|
|
|
default:
|
|
|
|
return vprintf(format, args);
|
|
|
|
}
|
|
|
|
}
|
2017-11-28 10:15:53 -08:00
|
|
|
|
|
|
|
#undef YG_UNUSED
|
2016-11-11 10:50:09 -08:00
|
|
|
#endif
|
|
|
|
|
2017-11-21 10:10:30 -08:00
|
|
|
bool YGFloatIsUndefined(const float value) {
|
2017-12-19 11:18:00 -08:00
|
|
|
return std::isnan(value);
|
2017-11-21 10:10:30 -08:00
|
|
|
}
|
|
|
|
|
2017-11-23 09:40:02 -08:00
|
|
|
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) {
|
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
|
|
|
if (edges[edge].unit != YGUnitUndefined) {
|
|
|
|
return &edges[edge];
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
if ((edge == YGEdgeTop || edge == YGEdgeBottom) &&
|
|
|
|
edges[YGEdgeVertical].unit != YGUnitUndefined) {
|
|
|
|
return &edges[YGEdgeVertical];
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
if ((edge == YGEdgeLeft || edge == YGEdgeRight || edge == YGEdgeStart || edge == YGEdgeEnd) &&
|
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
|
|
|
edges[YGEdgeHorizontal].unit != YGUnitUndefined) {
|
|
|
|
return &edges[YGEdgeHorizontal];
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
if (edges[YGEdgeAll].unit != YGUnitUndefined) {
|
|
|
|
return &edges[YGEdgeAll];
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
if (edge == YGEdgeStart || edge == YGEdgeEnd) {
|
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
|
|
|
return &YGValueUndefined;
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
static inline float YGResolveValue(
|
|
|
|
const YGValue value,
|
|
|
|
const float parentSize) {
|
|
|
|
switch (value.unit) {
|
2017-02-03 05:37:47 -08:00
|
|
|
case YGUnitUndefined:
|
2017-02-14 14:26:09 -08:00
|
|
|
case YGUnitAuto:
|
2017-02-03 05:37:47 -08:00
|
|
|
return YGUndefined;
|
2017-02-14 14:26:13 -08:00
|
|
|
case YGUnitPoint:
|
2017-12-19 11:18:00 -08:00
|
|
|
return value.value;
|
2017-02-03 05:37:47 -08:00
|
|
|
case YGUnitPercent:
|
2017-12-19 11:18:00 -08:00
|
|
|
return value.value * parentSize / 100.0f;
|
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
|
|
|
}
|
2017-02-03 05:37:47 -08:00
|
|
|
return YGUndefined;
|
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
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
static inline float YGResolveValueMargin(
|
|
|
|
const YGValue value,
|
|
|
|
const float parentSize) {
|
|
|
|
return value.unit == YGUnitAuto ? 0 : YGResolveValue(value, parentSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void* YGNodeGetContext(YGNodeRef node) {
|
|
|
|
return node->getContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
void YGNodeSetContext(YGNodeRef node, void* context) {
|
|
|
|
return node->setContext(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
YGMeasureFunc YGNodeGetMeasureFunc(YGNodeRef node) {
|
|
|
|
return node->getMeasure();
|
|
|
|
}
|
|
|
|
|
|
|
|
void YGNodeSetMeasureFunc(YGNodeRef node, YGMeasureFunc measureFunc) {
|
|
|
|
node->setMeasureFunc(measureFunc);
|
|
|
|
}
|
|
|
|
|
|
|
|
YGBaselineFunc YGNodeGetBaselineFunc(YGNodeRef node) {
|
|
|
|
return node->getBaseline();
|
|
|
|
}
|
|
|
|
|
|
|
|
void YGNodeSetBaselineFunc(YGNodeRef node, YGBaselineFunc baselineFunc) {
|
|
|
|
node->setBaseLineFunc(baselineFunc);
|
|
|
|
}
|
|
|
|
|
|
|
|
YGPrintFunc YGNodeGetPrintFunc(YGNodeRef node) {
|
|
|
|
return node->getPrintFunc();
|
|
|
|
}
|
|
|
|
|
|
|
|
void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc) {
|
|
|
|
node->setPrintFunc(printFunc);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool YGNodeGetHasNewLayout(YGNodeRef node) {
|
|
|
|
return node->getHasNewLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout) {
|
|
|
|
node->setHasNewLayout(hasNewLayout);
|
|
|
|
}
|
|
|
|
|
|
|
|
YGNodeType YGNodeGetNodeType(YGNodeRef node) {
|
|
|
|
return node->getNodeType();
|
|
|
|
}
|
|
|
|
|
|
|
|
void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType) {
|
|
|
|
return node->setNodeType(nodeType);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool YGNodeIsDirty(YGNodeRef node) {
|
|
|
|
return node->isDirty();
|
2017-02-14 14:26:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-06 14:37:54 -08:00
|
|
|
int32_t gNodeInstanceCount = 0;
|
2017-04-10 14:22:23 -07:00
|
|
|
int32_t gConfigInstanceCount = 0;
|
2016-12-06 14:37:54 -08:00
|
|
|
|
2017-03-01 09:19:55 -08:00
|
|
|
WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config) {
|
2017-12-19 11:18:00 -08:00
|
|
|
const YGNodeRef node = new YGNode();
|
2017-11-21 10:10:30 -08:00
|
|
|
YGAssertWithConfig(
|
|
|
|
config, node != nullptr, "Could not allocate memory for node");
|
2016-12-06 14:37:54 -08:00
|
|
|
gNodeInstanceCount++;
|
|
|
|
|
2017-03-03 10:47:42 -08:00
|
|
|
if (config->useWebDefaults) {
|
2017-12-19 11:18:00 -08:00
|
|
|
node->setStyleFlexDirection(YGFlexDirectionRow);
|
|
|
|
node->setStyleAlignContent(YGAlignStretch);
|
2017-03-03 10:47:42 -08:00
|
|
|
}
|
2017-12-19 11:18:00 -08:00
|
|
|
node->setConfig(config);
|
2016-12-06 14:37:54 -08:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2017-03-01 09:19:55 -08:00
|
|
|
YGNodeRef YGNodeNew(void) {
|
|
|
|
return YGNodeNewWithConfig(&gYGConfigDefaults);
|
|
|
|
}
|
|
|
|
|
2017-12-05 08:16:49 -08:00
|
|
|
YGNodeRef YGNodeClone(YGNodeRef oldNode) {
|
|
|
|
YGNodeRef node = new YGNode(*oldNode);
|
2017-11-21 10:10:30 -08:00
|
|
|
YGAssertWithConfig(
|
2017-12-19 11:18:00 -08:00
|
|
|
oldNode->getConfig(),
|
|
|
|
node != nullptr,
|
|
|
|
"Could not allocate memory for node");
|
Persistent Yoga
Summary:
This is meant to show a possible route format for a persistent form of Yoga. Where previous layouts can remain intact while still taking advantage of incremental layout by reusing previous subtrees.
```c
YGNodeRef YGNodeClone(const YGNodeRef node);
```
The core of this functionality is a new API to clone an existing node. This makes a new detached node with all the same values as the previous one. Conceptually this makes the original node "frozen" from that point on. It's now immutable. (This is not yet enforced at runtime in this PR but something we should add.)
Since the original is frozen, we reuse the children set from the original node. Their parent pointers still point back to the original tree though.
The cloned node is still mutable. It can have its styles updated, and nodes can be inserted or deleted. If an insertion/deletion happens on a cloned node whose children were reused, it'll first shallow clone its children automatically.
As a convenience I also added an API to clear all children:
```c
void YGNodeRemoveAllChildren(const YGNodeRef node);
```
During insert/delete, or as a result of layout a set of reused children may need to be first cloned. A kind of copy-on-write. When that happens, the host may want to respond. E.g. by updating the `context` such as by cloning any wrapper objects and attaching them to the new node.
```c
typedef void (*YGNodeClonedFunc)(YGNodeRef oldNode,
YGNodeRef newNode,
YGNodeRef parent,
int childIndex);
void YGConfigSetNodeClonedFunc(YGConfigRef config,
YGNodeClonedFunc callback);
```
This PR doesn't change any existing semantics for trees that are not first cloned.
It's possible for a single node to exist in two trees at once and be used by multiple threads. Therefore it's not safe to recursively free a whole tree when you use persistence. To solve this, any user of the library has to manually manage ref counting or tracing GC. E.g. by replicating the tree structure in a wrapper.
In a follow up we could consider moving ref counting into Yoga.
Closes https://github.com/facebook/yoga/pull/636
Reviewed By: emilsjolander
Differential Revision: D5941921
Pulled By: sebmarkbage
fbshipit-source-id: c8e93421824c112d09c4773bed4e3141b6491ccf
2017-10-17 01:02:04 -07:00
|
|
|
gNodeInstanceCount++;
|
2017-12-19 11:18:00 -08:00
|
|
|
node->setParent(nullptr);
|
Persistent Yoga
Summary:
This is meant to show a possible route format for a persistent form of Yoga. Where previous layouts can remain intact while still taking advantage of incremental layout by reusing previous subtrees.
```c
YGNodeRef YGNodeClone(const YGNodeRef node);
```
The core of this functionality is a new API to clone an existing node. This makes a new detached node with all the same values as the previous one. Conceptually this makes the original node "frozen" from that point on. It's now immutable. (This is not yet enforced at runtime in this PR but something we should add.)
Since the original is frozen, we reuse the children set from the original node. Their parent pointers still point back to the original tree though.
The cloned node is still mutable. It can have its styles updated, and nodes can be inserted or deleted. If an insertion/deletion happens on a cloned node whose children were reused, it'll first shallow clone its children automatically.
As a convenience I also added an API to clear all children:
```c
void YGNodeRemoveAllChildren(const YGNodeRef node);
```
During insert/delete, or as a result of layout a set of reused children may need to be first cloned. A kind of copy-on-write. When that happens, the host may want to respond. E.g. by updating the `context` such as by cloning any wrapper objects and attaching them to the new node.
```c
typedef void (*YGNodeClonedFunc)(YGNodeRef oldNode,
YGNodeRef newNode,
YGNodeRef parent,
int childIndex);
void YGConfigSetNodeClonedFunc(YGConfigRef config,
YGNodeClonedFunc callback);
```
This PR doesn't change any existing semantics for trees that are not first cloned.
It's possible for a single node to exist in two trees at once and be used by multiple threads. Therefore it's not safe to recursively free a whole tree when you use persistence. To solve this, any user of the library has to manually manage ref counting or tracing GC. E.g. by replicating the tree structure in a wrapper.
In a follow up we could consider moving ref counting into Yoga.
Closes https://github.com/facebook/yoga/pull/636
Reviewed By: emilsjolander
Differential Revision: D5941921
Pulled By: sebmarkbage
fbshipit-source-id: c8e93421824c112d09c4773bed4e3141b6491ccf
2017-10-17 01:02:04 -07:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2016-12-06 14:37:54 -08:00
|
|
|
void YGNodeFree(const YGNodeRef node) {
|
2017-12-19 11:18:00 -08:00
|
|
|
if (node->getParent()) {
|
|
|
|
node->getParent()->removeChild(node);
|
|
|
|
node->setParent(nullptr);
|
2016-12-06 14:37:54 -08:00
|
|
|
}
|
|
|
|
|
2016-12-16 04:39:13 -08:00
|
|
|
const uint32_t childCount = YGNodeGetChildCount(node);
|
2016-12-06 14:37:54 -08:00
|
|
|
for (uint32_t i = 0; i < childCount; i++) {
|
|
|
|
const YGNodeRef child = YGNodeGetChild(node, i);
|
2017-12-19 11:18:00 -08:00
|
|
|
child->setParent(nullptr);
|
2016-12-06 14:37:54 -08:00
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
node->clearChildren();
|
2017-11-21 10:10:30 -08:00
|
|
|
free(node);
|
2016-12-06 14:37:54 -08:00
|
|
|
gNodeInstanceCount--;
|
|
|
|
}
|
|
|
|
|
|
|
|
void YGNodeFreeRecursive(const YGNodeRef root) {
|
2016-12-16 04:39:13 -08:00
|
|
|
while (YGNodeGetChildCount(root) > 0) {
|
2016-12-06 14:37:54 -08:00
|
|
|
const YGNodeRef child = YGNodeGetChild(root, 0);
|
2017-12-19 11:18:00 -08:00
|
|
|
if (child->getParent() != root) {
|
Persistent Yoga
Summary:
This is meant to show a possible route format for a persistent form of Yoga. Where previous layouts can remain intact while still taking advantage of incremental layout by reusing previous subtrees.
```c
YGNodeRef YGNodeClone(const YGNodeRef node);
```
The core of this functionality is a new API to clone an existing node. This makes a new detached node with all the same values as the previous one. Conceptually this makes the original node "frozen" from that point on. It's now immutable. (This is not yet enforced at runtime in this PR but something we should add.)
Since the original is frozen, we reuse the children set from the original node. Their parent pointers still point back to the original tree though.
The cloned node is still mutable. It can have its styles updated, and nodes can be inserted or deleted. If an insertion/deletion happens on a cloned node whose children were reused, it'll first shallow clone its children automatically.
As a convenience I also added an API to clear all children:
```c
void YGNodeRemoveAllChildren(const YGNodeRef node);
```
During insert/delete, or as a result of layout a set of reused children may need to be first cloned. A kind of copy-on-write. When that happens, the host may want to respond. E.g. by updating the `context` such as by cloning any wrapper objects and attaching them to the new node.
```c
typedef void (*YGNodeClonedFunc)(YGNodeRef oldNode,
YGNodeRef newNode,
YGNodeRef parent,
int childIndex);
void YGConfigSetNodeClonedFunc(YGConfigRef config,
YGNodeClonedFunc callback);
```
This PR doesn't change any existing semantics for trees that are not first cloned.
It's possible for a single node to exist in two trees at once and be used by multiple threads. Therefore it's not safe to recursively free a whole tree when you use persistence. To solve this, any user of the library has to manually manage ref counting or tracing GC. E.g. by replicating the tree structure in a wrapper.
In a follow up we could consider moving ref counting into Yoga.
Closes https://github.com/facebook/yoga/pull/636
Reviewed By: emilsjolander
Differential Revision: D5941921
Pulled By: sebmarkbage
fbshipit-source-id: c8e93421824c112d09c4773bed4e3141b6491ccf
2017-10-17 01:02:04 -07:00
|
|
|
// Don't free shared nodes that we don't own.
|
|
|
|
break;
|
|
|
|
}
|
2016-12-06 14:37:54 -08:00
|
|
|
YGNodeRemoveChild(root, child);
|
|
|
|
YGNodeFreeRecursive(child);
|
|
|
|
}
|
|
|
|
YGNodeFree(root);
|
|
|
|
}
|
|
|
|
|
|
|
|
void YGNodeReset(const YGNodeRef node) {
|
2017-05-03 09:22:35 -07:00
|
|
|
YGAssertWithNode(node,
|
2017-05-12 09:03:22 -07:00
|
|
|
YGNodeGetChildCount(node) == 0,
|
|
|
|
"Cannot reset a node which still has children attached");
|
2017-11-21 10:10:30 -08:00
|
|
|
YGAssertWithNode(
|
|
|
|
node,
|
2017-12-19 11:18:00 -08:00
|
|
|
node->getParent() == nullptr,
|
2017-11-21 10:10:30 -08:00
|
|
|
"Cannot reset a node still attached to a parent");
|
2016-12-06 14:37:54 -08:00
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
node->clearChildren();
|
2017-03-01 09:19:55 -08:00
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
const YGConfigRef config = node->getConfig();
|
|
|
|
*node = YGNode();
|
2017-03-29 03:06:19 -07:00
|
|
|
if (config->useWebDefaults) {
|
2017-12-19 11:18:00 -08:00
|
|
|
node->setStyleFlexDirection(YGFlexDirectionRow);
|
|
|
|
node->setStyleAlignContent(YGAlignStretch);
|
2017-03-29 03:06:19 -07:00
|
|
|
}
|
2017-12-19 11:18:00 -08:00
|
|
|
node->setConfig(config);
|
2016-12-06 14:37:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t YGNodeGetInstanceCount(void) {
|
|
|
|
return gNodeInstanceCount;
|
|
|
|
}
|
|
|
|
|
2017-04-10 14:22:23 -07:00
|
|
|
int32_t YGConfigGetInstanceCount(void) {
|
|
|
|
return gConfigInstanceCount;
|
|
|
|
}
|
|
|
|
|
2017-05-03 09:22:35 -07:00
|
|
|
// Export only for C#
|
|
|
|
YGConfigRef YGConfigGetDefault() {
|
|
|
|
return &gYGConfigDefaults;
|
|
|
|
}
|
|
|
|
|
2017-03-01 09:19:55 -08:00
|
|
|
YGConfigRef YGConfigNew(void) {
|
2017-11-21 10:10:30 -08:00
|
|
|
const YGConfigRef config = (const YGConfigRef)malloc(sizeof(YGConfig));
|
|
|
|
YGAssert(config != nullptr, "Could not allocate memory for config");
|
2017-05-03 09:22:35 -07:00
|
|
|
|
2017-04-10 14:22:23 -07:00
|
|
|
gConfigInstanceCount++;
|
2017-03-01 09:19:55 -08:00
|
|
|
memcpy(config, &gYGConfigDefaults, sizeof(YGConfig));
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
|
|
|
void YGConfigFree(const YGConfigRef config) {
|
2017-11-21 10:10:30 -08:00
|
|
|
free(config);
|
2017-04-10 14:22:23 -07:00
|
|
|
gConfigInstanceCount--;
|
2017-03-01 09:19:55 -08:00
|
|
|
}
|
|
|
|
|
2017-04-26 11:49:26 -07:00
|
|
|
void YGConfigCopy(const YGConfigRef dest, const YGConfigRef src) {
|
|
|
|
memcpy(dest, src, sizeof(YGConfig));
|
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
void YGNodeInsertChild(const YGNodeRef node, const YGNodeRef child, const uint32_t index) {
|
2017-11-21 10:10:30 -08:00
|
|
|
YGAssertWithNode(
|
|
|
|
node,
|
2017-12-19 11:18:00 -08:00
|
|
|
child->getParent() == nullptr,
|
2017-11-21 10:10:30 -08:00
|
|
|
"Child already has a parent, it must be removed first.");
|
|
|
|
YGAssertWithNode(
|
|
|
|
node,
|
2017-12-19 11:18:00 -08:00
|
|
|
node->getMeasure() == nullptr,
|
2017-11-21 10:10:30 -08:00
|
|
|
"Cannot add child: Nodes with measure functions cannot have children.");
|
2017-05-03 09:22:35 -07:00
|
|
|
|
2018-01-08 02:48:32 -08:00
|
|
|
node->cloneChildrenIfNeeded();
|
2017-12-19 11:18:00 -08:00
|
|
|
node->insertChild(child, index);
|
|
|
|
child->setParent(node);
|
2018-01-08 02:48:35 -08:00
|
|
|
node->markDirtyAndPropogate();
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
Persistent Yoga
Summary:
This is meant to show a possible route format for a persistent form of Yoga. Where previous layouts can remain intact while still taking advantage of incremental layout by reusing previous subtrees.
```c
YGNodeRef YGNodeClone(const YGNodeRef node);
```
The core of this functionality is a new API to clone an existing node. This makes a new detached node with all the same values as the previous one. Conceptually this makes the original node "frozen" from that point on. It's now immutable. (This is not yet enforced at runtime in this PR but something we should add.)
Since the original is frozen, we reuse the children set from the original node. Their parent pointers still point back to the original tree though.
The cloned node is still mutable. It can have its styles updated, and nodes can be inserted or deleted. If an insertion/deletion happens on a cloned node whose children were reused, it'll first shallow clone its children automatically.
As a convenience I also added an API to clear all children:
```c
void YGNodeRemoveAllChildren(const YGNodeRef node);
```
During insert/delete, or as a result of layout a set of reused children may need to be first cloned. A kind of copy-on-write. When that happens, the host may want to respond. E.g. by updating the `context` such as by cloning any wrapper objects and attaching them to the new node.
```c
typedef void (*YGNodeClonedFunc)(YGNodeRef oldNode,
YGNodeRef newNode,
YGNodeRef parent,
int childIndex);
void YGConfigSetNodeClonedFunc(YGConfigRef config,
YGNodeClonedFunc callback);
```
This PR doesn't change any existing semantics for trees that are not first cloned.
It's possible for a single node to exist in two trees at once and be used by multiple threads. Therefore it's not safe to recursively free a whole tree when you use persistence. To solve this, any user of the library has to manually manage ref counting or tracing GC. E.g. by replicating the tree structure in a wrapper.
In a follow up we could consider moving ref counting into Yoga.
Closes https://github.com/facebook/yoga/pull/636
Reviewed By: emilsjolander
Differential Revision: D5941921
Pulled By: sebmarkbage
fbshipit-source-id: c8e93421824c112d09c4773bed4e3141b6491ccf
2017-10-17 01:02:04 -07:00
|
|
|
void YGNodeRemoveChild(const YGNodeRef parent, const YGNodeRef excludedChild) {
|
2018-01-08 02:48:32 -08:00
|
|
|
// This algorithm is a forked variant from cloneChildrenIfNeeded in YGNode
|
|
|
|
// that excludes a child.
|
Persistent Yoga
Summary:
This is meant to show a possible route format for a persistent form of Yoga. Where previous layouts can remain intact while still taking advantage of incremental layout by reusing previous subtrees.
```c
YGNodeRef YGNodeClone(const YGNodeRef node);
```
The core of this functionality is a new API to clone an existing node. This makes a new detached node with all the same values as the previous one. Conceptually this makes the original node "frozen" from that point on. It's now immutable. (This is not yet enforced at runtime in this PR but something we should add.)
Since the original is frozen, we reuse the children set from the original node. Their parent pointers still point back to the original tree though.
The cloned node is still mutable. It can have its styles updated, and nodes can be inserted or deleted. If an insertion/deletion happens on a cloned node whose children were reused, it'll first shallow clone its children automatically.
As a convenience I also added an API to clear all children:
```c
void YGNodeRemoveAllChildren(const YGNodeRef node);
```
During insert/delete, or as a result of layout a set of reused children may need to be first cloned. A kind of copy-on-write. When that happens, the host may want to respond. E.g. by updating the `context` such as by cloning any wrapper objects and attaching them to the new node.
```c
typedef void (*YGNodeClonedFunc)(YGNodeRef oldNode,
YGNodeRef newNode,
YGNodeRef parent,
int childIndex);
void YGConfigSetNodeClonedFunc(YGConfigRef config,
YGNodeClonedFunc callback);
```
This PR doesn't change any existing semantics for trees that are not first cloned.
It's possible for a single node to exist in two trees at once and be used by multiple threads. Therefore it's not safe to recursively free a whole tree when you use persistence. To solve this, any user of the library has to manually manage ref counting or tracing GC. E.g. by replicating the tree structure in a wrapper.
In a follow up we could consider moving ref counting into Yoga.
Closes https://github.com/facebook/yoga/pull/636
Reviewed By: emilsjolander
Differential Revision: D5941921
Pulled By: sebmarkbage
fbshipit-source-id: c8e93421824c112d09c4773bed4e3141b6491ccf
2017-10-17 01:02:04 -07:00
|
|
|
const uint32_t childCount = YGNodeGetChildCount(parent);
|
2017-12-05 08:16:49 -08:00
|
|
|
|
Persistent Yoga
Summary:
This is meant to show a possible route format for a persistent form of Yoga. Where previous layouts can remain intact while still taking advantage of incremental layout by reusing previous subtrees.
```c
YGNodeRef YGNodeClone(const YGNodeRef node);
```
The core of this functionality is a new API to clone an existing node. This makes a new detached node with all the same values as the previous one. Conceptually this makes the original node "frozen" from that point on. It's now immutable. (This is not yet enforced at runtime in this PR but something we should add.)
Since the original is frozen, we reuse the children set from the original node. Their parent pointers still point back to the original tree though.
The cloned node is still mutable. It can have its styles updated, and nodes can be inserted or deleted. If an insertion/deletion happens on a cloned node whose children were reused, it'll first shallow clone its children automatically.
As a convenience I also added an API to clear all children:
```c
void YGNodeRemoveAllChildren(const YGNodeRef node);
```
During insert/delete, or as a result of layout a set of reused children may need to be first cloned. A kind of copy-on-write. When that happens, the host may want to respond. E.g. by updating the `context` such as by cloning any wrapper objects and attaching them to the new node.
```c
typedef void (*YGNodeClonedFunc)(YGNodeRef oldNode,
YGNodeRef newNode,
YGNodeRef parent,
int childIndex);
void YGConfigSetNodeClonedFunc(YGConfigRef config,
YGNodeClonedFunc callback);
```
This PR doesn't change any existing semantics for trees that are not first cloned.
It's possible for a single node to exist in two trees at once and be used by multiple threads. Therefore it's not safe to recursively free a whole tree when you use persistence. To solve this, any user of the library has to manually manage ref counting or tracing GC. E.g. by replicating the tree structure in a wrapper.
In a follow up we could consider moving ref counting into Yoga.
Closes https://github.com/facebook/yoga/pull/636
Reviewed By: emilsjolander
Differential Revision: D5941921
Pulled By: sebmarkbage
fbshipit-source-id: c8e93421824c112d09c4773bed4e3141b6491ccf
2017-10-17 01:02:04 -07:00
|
|
|
if (childCount == 0) {
|
|
|
|
// This is an empty set. Nothing to remove.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const YGNodeRef firstChild = YGNodeGetChild(parent, 0);
|
2017-12-19 11:18:00 -08:00
|
|
|
if (firstChild->getParent() == parent) {
|
Persistent Yoga
Summary:
This is meant to show a possible route format for a persistent form of Yoga. Where previous layouts can remain intact while still taking advantage of incremental layout by reusing previous subtrees.
```c
YGNodeRef YGNodeClone(const YGNodeRef node);
```
The core of this functionality is a new API to clone an existing node. This makes a new detached node with all the same values as the previous one. Conceptually this makes the original node "frozen" from that point on. It's now immutable. (This is not yet enforced at runtime in this PR but something we should add.)
Since the original is frozen, we reuse the children set from the original node. Their parent pointers still point back to the original tree though.
The cloned node is still mutable. It can have its styles updated, and nodes can be inserted or deleted. If an insertion/deletion happens on a cloned node whose children were reused, it'll first shallow clone its children automatically.
As a convenience I also added an API to clear all children:
```c
void YGNodeRemoveAllChildren(const YGNodeRef node);
```
During insert/delete, or as a result of layout a set of reused children may need to be first cloned. A kind of copy-on-write. When that happens, the host may want to respond. E.g. by updating the `context` such as by cloning any wrapper objects and attaching them to the new node.
```c
typedef void (*YGNodeClonedFunc)(YGNodeRef oldNode,
YGNodeRef newNode,
YGNodeRef parent,
int childIndex);
void YGConfigSetNodeClonedFunc(YGConfigRef config,
YGNodeClonedFunc callback);
```
This PR doesn't change any existing semantics for trees that are not first cloned.
It's possible for a single node to exist in two trees at once and be used by multiple threads. Therefore it's not safe to recursively free a whole tree when you use persistence. To solve this, any user of the library has to manually manage ref counting or tracing GC. E.g. by replicating the tree structure in a wrapper.
In a follow up we could consider moving ref counting into Yoga.
Closes https://github.com/facebook/yoga/pull/636
Reviewed By: emilsjolander
Differential Revision: D5941921
Pulled By: sebmarkbage
fbshipit-source-id: c8e93421824c112d09c4773bed4e3141b6491ccf
2017-10-17 01:02:04 -07:00
|
|
|
// If the first child has this node as its parent, we assume that it is already unique.
|
|
|
|
// We can now try to delete a child in this list.
|
2017-12-19 11:18:00 -08:00
|
|
|
if (parent->removeChild(excludedChild)) {
|
|
|
|
excludedChild->setLayout(
|
|
|
|
YGNode().getLayout()); // layout is no longer valid
|
|
|
|
excludedChild->setParent(nullptr);
|
2018-01-08 02:48:35 -08:00
|
|
|
parent->markDirtyAndPropogate();
|
Persistent Yoga
Summary:
This is meant to show a possible route format for a persistent form of Yoga. Where previous layouts can remain intact while still taking advantage of incremental layout by reusing previous subtrees.
```c
YGNodeRef YGNodeClone(const YGNodeRef node);
```
The core of this functionality is a new API to clone an existing node. This makes a new detached node with all the same values as the previous one. Conceptually this makes the original node "frozen" from that point on. It's now immutable. (This is not yet enforced at runtime in this PR but something we should add.)
Since the original is frozen, we reuse the children set from the original node. Their parent pointers still point back to the original tree though.
The cloned node is still mutable. It can have its styles updated, and nodes can be inserted or deleted. If an insertion/deletion happens on a cloned node whose children were reused, it'll first shallow clone its children automatically.
As a convenience I also added an API to clear all children:
```c
void YGNodeRemoveAllChildren(const YGNodeRef node);
```
During insert/delete, or as a result of layout a set of reused children may need to be first cloned. A kind of copy-on-write. When that happens, the host may want to respond. E.g. by updating the `context` such as by cloning any wrapper objects and attaching them to the new node.
```c
typedef void (*YGNodeClonedFunc)(YGNodeRef oldNode,
YGNodeRef newNode,
YGNodeRef parent,
int childIndex);
void YGConfigSetNodeClonedFunc(YGConfigRef config,
YGNodeClonedFunc callback);
```
This PR doesn't change any existing semantics for trees that are not first cloned.
It's possible for a single node to exist in two trees at once and be used by multiple threads. Therefore it's not safe to recursively free a whole tree when you use persistence. To solve this, any user of the library has to manually manage ref counting or tracing GC. E.g. by replicating the tree structure in a wrapper.
In a follow up we could consider moving ref counting into Yoga.
Closes https://github.com/facebook/yoga/pull/636
Reviewed By: emilsjolander
Differential Revision: D5941921
Pulled By: sebmarkbage
fbshipit-source-id: c8e93421824c112d09c4773bed4e3141b6491ccf
2017-10-17 01:02:04 -07:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Otherwise we have to clone the node list except for the child we're trying to delete.
|
|
|
|
// We don't want to simply clone all children, because then the host will need to free
|
|
|
|
// the clone of the child that was just deleted.
|
2017-12-19 11:18:00 -08:00
|
|
|
const YGNodeClonedFunc cloneNodeCallback =
|
|
|
|
parent->getConfig()->cloneNodeCallback;
|
Persistent Yoga
Summary:
This is meant to show a possible route format for a persistent form of Yoga. Where previous layouts can remain intact while still taking advantage of incremental layout by reusing previous subtrees.
```c
YGNodeRef YGNodeClone(const YGNodeRef node);
```
The core of this functionality is a new API to clone an existing node. This makes a new detached node with all the same values as the previous one. Conceptually this makes the original node "frozen" from that point on. It's now immutable. (This is not yet enforced at runtime in this PR but something we should add.)
Since the original is frozen, we reuse the children set from the original node. Their parent pointers still point back to the original tree though.
The cloned node is still mutable. It can have its styles updated, and nodes can be inserted or deleted. If an insertion/deletion happens on a cloned node whose children were reused, it'll first shallow clone its children automatically.
As a convenience I also added an API to clear all children:
```c
void YGNodeRemoveAllChildren(const YGNodeRef node);
```
During insert/delete, or as a result of layout a set of reused children may need to be first cloned. A kind of copy-on-write. When that happens, the host may want to respond. E.g. by updating the `context` such as by cloning any wrapper objects and attaching them to the new node.
```c
typedef void (*YGNodeClonedFunc)(YGNodeRef oldNode,
YGNodeRef newNode,
YGNodeRef parent,
int childIndex);
void YGConfigSetNodeClonedFunc(YGConfigRef config,
YGNodeClonedFunc callback);
```
This PR doesn't change any existing semantics for trees that are not first cloned.
It's possible for a single node to exist in two trees at once and be used by multiple threads. Therefore it's not safe to recursively free a whole tree when you use persistence. To solve this, any user of the library has to manually manage ref counting or tracing GC. E.g. by replicating the tree structure in a wrapper.
In a follow up we could consider moving ref counting into Yoga.
Closes https://github.com/facebook/yoga/pull/636
Reviewed By: emilsjolander
Differential Revision: D5941921
Pulled By: sebmarkbage
fbshipit-source-id: c8e93421824c112d09c4773bed4e3141b6491ccf
2017-10-17 01:02:04 -07:00
|
|
|
uint32_t nextInsertIndex = 0;
|
|
|
|
for (uint32_t i = 0; i < childCount; i++) {
|
2017-12-19 11:18:00 -08:00
|
|
|
const YGNodeRef oldChild = parent->getChild(i);
|
Persistent Yoga
Summary:
This is meant to show a possible route format for a persistent form of Yoga. Where previous layouts can remain intact while still taking advantage of incremental layout by reusing previous subtrees.
```c
YGNodeRef YGNodeClone(const YGNodeRef node);
```
The core of this functionality is a new API to clone an existing node. This makes a new detached node with all the same values as the previous one. Conceptually this makes the original node "frozen" from that point on. It's now immutable. (This is not yet enforced at runtime in this PR but something we should add.)
Since the original is frozen, we reuse the children set from the original node. Their parent pointers still point back to the original tree though.
The cloned node is still mutable. It can have its styles updated, and nodes can be inserted or deleted. If an insertion/deletion happens on a cloned node whose children were reused, it'll first shallow clone its children automatically.
As a convenience I also added an API to clear all children:
```c
void YGNodeRemoveAllChildren(const YGNodeRef node);
```
During insert/delete, or as a result of layout a set of reused children may need to be first cloned. A kind of copy-on-write. When that happens, the host may want to respond. E.g. by updating the `context` such as by cloning any wrapper objects and attaching them to the new node.
```c
typedef void (*YGNodeClonedFunc)(YGNodeRef oldNode,
YGNodeRef newNode,
YGNodeRef parent,
int childIndex);
void YGConfigSetNodeClonedFunc(YGConfigRef config,
YGNodeClonedFunc callback);
```
This PR doesn't change any existing semantics for trees that are not first cloned.
It's possible for a single node to exist in two trees at once and be used by multiple threads. Therefore it's not safe to recursively free a whole tree when you use persistence. To solve this, any user of the library has to manually manage ref counting or tracing GC. E.g. by replicating the tree structure in a wrapper.
In a follow up we could consider moving ref counting into Yoga.
Closes https://github.com/facebook/yoga/pull/636
Reviewed By: emilsjolander
Differential Revision: D5941921
Pulled By: sebmarkbage
fbshipit-source-id: c8e93421824c112d09c4773bed4e3141b6491ccf
2017-10-17 01:02:04 -07:00
|
|
|
if (excludedChild == oldChild) {
|
|
|
|
// Ignore the deleted child. Don't reset its layout or parent since it is still valid
|
|
|
|
// in the other parent. However, since this parent has now changed, we need to mark it
|
|
|
|
// as dirty.
|
2018-01-08 02:48:35 -08:00
|
|
|
parent->markDirtyAndPropogate();
|
Persistent Yoga
Summary:
This is meant to show a possible route format for a persistent form of Yoga. Where previous layouts can remain intact while still taking advantage of incremental layout by reusing previous subtrees.
```c
YGNodeRef YGNodeClone(const YGNodeRef node);
```
The core of this functionality is a new API to clone an existing node. This makes a new detached node with all the same values as the previous one. Conceptually this makes the original node "frozen" from that point on. It's now immutable. (This is not yet enforced at runtime in this PR but something we should add.)
Since the original is frozen, we reuse the children set from the original node. Their parent pointers still point back to the original tree though.
The cloned node is still mutable. It can have its styles updated, and nodes can be inserted or deleted. If an insertion/deletion happens on a cloned node whose children were reused, it'll first shallow clone its children automatically.
As a convenience I also added an API to clear all children:
```c
void YGNodeRemoveAllChildren(const YGNodeRef node);
```
During insert/delete, or as a result of layout a set of reused children may need to be first cloned. A kind of copy-on-write. When that happens, the host may want to respond. E.g. by updating the `context` such as by cloning any wrapper objects and attaching them to the new node.
```c
typedef void (*YGNodeClonedFunc)(YGNodeRef oldNode,
YGNodeRef newNode,
YGNodeRef parent,
int childIndex);
void YGConfigSetNodeClonedFunc(YGConfigRef config,
YGNodeClonedFunc callback);
```
This PR doesn't change any existing semantics for trees that are not first cloned.
It's possible for a single node to exist in two trees at once and be used by multiple threads. Therefore it's not safe to recursively free a whole tree when you use persistence. To solve this, any user of the library has to manually manage ref counting or tracing GC. E.g. by replicating the tree structure in a wrapper.
In a follow up we could consider moving ref counting into Yoga.
Closes https://github.com/facebook/yoga/pull/636
Reviewed By: emilsjolander
Differential Revision: D5941921
Pulled By: sebmarkbage
fbshipit-source-id: c8e93421824c112d09c4773bed4e3141b6491ccf
2017-10-17 01:02:04 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const YGNodeRef newChild = YGNodeClone(oldChild);
|
2017-12-19 11:18:00 -08:00
|
|
|
parent->replaceChild(newChild, nextInsertIndex);
|
|
|
|
newChild->setParent(parent);
|
Persistent Yoga
Summary:
This is meant to show a possible route format for a persistent form of Yoga. Where previous layouts can remain intact while still taking advantage of incremental layout by reusing previous subtrees.
```c
YGNodeRef YGNodeClone(const YGNodeRef node);
```
The core of this functionality is a new API to clone an existing node. This makes a new detached node with all the same values as the previous one. Conceptually this makes the original node "frozen" from that point on. It's now immutable. (This is not yet enforced at runtime in this PR but something we should add.)
Since the original is frozen, we reuse the children set from the original node. Their parent pointers still point back to the original tree though.
The cloned node is still mutable. It can have its styles updated, and nodes can be inserted or deleted. If an insertion/deletion happens on a cloned node whose children were reused, it'll first shallow clone its children automatically.
As a convenience I also added an API to clear all children:
```c
void YGNodeRemoveAllChildren(const YGNodeRef node);
```
During insert/delete, or as a result of layout a set of reused children may need to be first cloned. A kind of copy-on-write. When that happens, the host may want to respond. E.g. by updating the `context` such as by cloning any wrapper objects and attaching them to the new node.
```c
typedef void (*YGNodeClonedFunc)(YGNodeRef oldNode,
YGNodeRef newNode,
YGNodeRef parent,
int childIndex);
void YGConfigSetNodeClonedFunc(YGConfigRef config,
YGNodeClonedFunc callback);
```
This PR doesn't change any existing semantics for trees that are not first cloned.
It's possible for a single node to exist in two trees at once and be used by multiple threads. Therefore it's not safe to recursively free a whole tree when you use persistence. To solve this, any user of the library has to manually manage ref counting or tracing GC. E.g. by replicating the tree structure in a wrapper.
In a follow up we could consider moving ref counting into Yoga.
Closes https://github.com/facebook/yoga/pull/636
Reviewed By: emilsjolander
Differential Revision: D5941921
Pulled By: sebmarkbage
fbshipit-source-id: c8e93421824c112d09c4773bed4e3141b6491ccf
2017-10-17 01:02:04 -07:00
|
|
|
if (cloneNodeCallback) {
|
|
|
|
cloneNodeCallback(oldChild, newChild, parent, nextInsertIndex);
|
|
|
|
}
|
|
|
|
nextInsertIndex++;
|
|
|
|
}
|
|
|
|
while (nextInsertIndex < childCount) {
|
2017-12-19 11:18:00 -08:00
|
|
|
parent->removeChild(nextInsertIndex);
|
Persistent Yoga
Summary:
This is meant to show a possible route format for a persistent form of Yoga. Where previous layouts can remain intact while still taking advantage of incremental layout by reusing previous subtrees.
```c
YGNodeRef YGNodeClone(const YGNodeRef node);
```
The core of this functionality is a new API to clone an existing node. This makes a new detached node with all the same values as the previous one. Conceptually this makes the original node "frozen" from that point on. It's now immutable. (This is not yet enforced at runtime in this PR but something we should add.)
Since the original is frozen, we reuse the children set from the original node. Their parent pointers still point back to the original tree though.
The cloned node is still mutable. It can have its styles updated, and nodes can be inserted or deleted. If an insertion/deletion happens on a cloned node whose children were reused, it'll first shallow clone its children automatically.
As a convenience I also added an API to clear all children:
```c
void YGNodeRemoveAllChildren(const YGNodeRef node);
```
During insert/delete, or as a result of layout a set of reused children may need to be first cloned. A kind of copy-on-write. When that happens, the host may want to respond. E.g. by updating the `context` such as by cloning any wrapper objects and attaching them to the new node.
```c
typedef void (*YGNodeClonedFunc)(YGNodeRef oldNode,
YGNodeRef newNode,
YGNodeRef parent,
int childIndex);
void YGConfigSetNodeClonedFunc(YGConfigRef config,
YGNodeClonedFunc callback);
```
This PR doesn't change any existing semantics for trees that are not first cloned.
It's possible for a single node to exist in two trees at once and be used by multiple threads. Therefore it's not safe to recursively free a whole tree when you use persistence. To solve this, any user of the library has to manually manage ref counting or tracing GC. E.g. by replicating the tree structure in a wrapper.
In a follow up we could consider moving ref counting into Yoga.
Closes https://github.com/facebook/yoga/pull/636
Reviewed By: emilsjolander
Differential Revision: D5941921
Pulled By: sebmarkbage
fbshipit-source-id: c8e93421824c112d09c4773bed4e3141b6491ccf
2017-10-17 01:02:04 -07:00
|
|
|
nextInsertIndex++;
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Persistent Yoga
Summary:
This is meant to show a possible route format for a persistent form of Yoga. Where previous layouts can remain intact while still taking advantage of incremental layout by reusing previous subtrees.
```c
YGNodeRef YGNodeClone(const YGNodeRef node);
```
The core of this functionality is a new API to clone an existing node. This makes a new detached node with all the same values as the previous one. Conceptually this makes the original node "frozen" from that point on. It's now immutable. (This is not yet enforced at runtime in this PR but something we should add.)
Since the original is frozen, we reuse the children set from the original node. Their parent pointers still point back to the original tree though.
The cloned node is still mutable. It can have its styles updated, and nodes can be inserted or deleted. If an insertion/deletion happens on a cloned node whose children were reused, it'll first shallow clone its children automatically.
As a convenience I also added an API to clear all children:
```c
void YGNodeRemoveAllChildren(const YGNodeRef node);
```
During insert/delete, or as a result of layout a set of reused children may need to be first cloned. A kind of copy-on-write. When that happens, the host may want to respond. E.g. by updating the `context` such as by cloning any wrapper objects and attaching them to the new node.
```c
typedef void (*YGNodeClonedFunc)(YGNodeRef oldNode,
YGNodeRef newNode,
YGNodeRef parent,
int childIndex);
void YGConfigSetNodeClonedFunc(YGConfigRef config,
YGNodeClonedFunc callback);
```
This PR doesn't change any existing semantics for trees that are not first cloned.
It's possible for a single node to exist in two trees at once and be used by multiple threads. Therefore it's not safe to recursively free a whole tree when you use persistence. To solve this, any user of the library has to manually manage ref counting or tracing GC. E.g. by replicating the tree structure in a wrapper.
In a follow up we could consider moving ref counting into Yoga.
Closes https://github.com/facebook/yoga/pull/636
Reviewed By: emilsjolander
Differential Revision: D5941921
Pulled By: sebmarkbage
fbshipit-source-id: c8e93421824c112d09c4773bed4e3141b6491ccf
2017-10-17 01:02:04 -07:00
|
|
|
void YGNodeRemoveAllChildren(const YGNodeRef parent) {
|
|
|
|
const uint32_t childCount = YGNodeGetChildCount(parent);
|
|
|
|
if (childCount == 0) {
|
|
|
|
// This is an empty set already. Nothing to do.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const YGNodeRef firstChild = YGNodeGetChild(parent, 0);
|
2017-12-19 11:18:00 -08:00
|
|
|
if (firstChild->getParent() == parent) {
|
Persistent Yoga
Summary:
This is meant to show a possible route format for a persistent form of Yoga. Where previous layouts can remain intact while still taking advantage of incremental layout by reusing previous subtrees.
```c
YGNodeRef YGNodeClone(const YGNodeRef node);
```
The core of this functionality is a new API to clone an existing node. This makes a new detached node with all the same values as the previous one. Conceptually this makes the original node "frozen" from that point on. It's now immutable. (This is not yet enforced at runtime in this PR but something we should add.)
Since the original is frozen, we reuse the children set from the original node. Their parent pointers still point back to the original tree though.
The cloned node is still mutable. It can have its styles updated, and nodes can be inserted or deleted. If an insertion/deletion happens on a cloned node whose children were reused, it'll first shallow clone its children automatically.
As a convenience I also added an API to clear all children:
```c
void YGNodeRemoveAllChildren(const YGNodeRef node);
```
During insert/delete, or as a result of layout a set of reused children may need to be first cloned. A kind of copy-on-write. When that happens, the host may want to respond. E.g. by updating the `context` such as by cloning any wrapper objects and attaching them to the new node.
```c
typedef void (*YGNodeClonedFunc)(YGNodeRef oldNode,
YGNodeRef newNode,
YGNodeRef parent,
int childIndex);
void YGConfigSetNodeClonedFunc(YGConfigRef config,
YGNodeClonedFunc callback);
```
This PR doesn't change any existing semantics for trees that are not first cloned.
It's possible for a single node to exist in two trees at once and be used by multiple threads. Therefore it's not safe to recursively free a whole tree when you use persistence. To solve this, any user of the library has to manually manage ref counting or tracing GC. E.g. by replicating the tree structure in a wrapper.
In a follow up we could consider moving ref counting into Yoga.
Closes https://github.com/facebook/yoga/pull/636
Reviewed By: emilsjolander
Differential Revision: D5941921
Pulled By: sebmarkbage
fbshipit-source-id: c8e93421824c112d09c4773bed4e3141b6491ccf
2017-10-17 01:02:04 -07:00
|
|
|
// If the first child has this node as its parent, we assume that this child set is unique.
|
|
|
|
for (uint32_t i = 0; i < childCount; i++) {
|
|
|
|
const YGNodeRef oldChild = YGNodeGetChild(parent, i);
|
2017-12-19 11:18:00 -08:00
|
|
|
oldChild->setLayout(YGNode().getLayout()); // layout is no longer valid
|
|
|
|
oldChild->setParent(nullptr);
|
Persistent Yoga
Summary:
This is meant to show a possible route format for a persistent form of Yoga. Where previous layouts can remain intact while still taking advantage of incremental layout by reusing previous subtrees.
```c
YGNodeRef YGNodeClone(const YGNodeRef node);
```
The core of this functionality is a new API to clone an existing node. This makes a new detached node with all the same values as the previous one. Conceptually this makes the original node "frozen" from that point on. It's now immutable. (This is not yet enforced at runtime in this PR but something we should add.)
Since the original is frozen, we reuse the children set from the original node. Their parent pointers still point back to the original tree though.
The cloned node is still mutable. It can have its styles updated, and nodes can be inserted or deleted. If an insertion/deletion happens on a cloned node whose children were reused, it'll first shallow clone its children automatically.
As a convenience I also added an API to clear all children:
```c
void YGNodeRemoveAllChildren(const YGNodeRef node);
```
During insert/delete, or as a result of layout a set of reused children may need to be first cloned. A kind of copy-on-write. When that happens, the host may want to respond. E.g. by updating the `context` such as by cloning any wrapper objects and attaching them to the new node.
```c
typedef void (*YGNodeClonedFunc)(YGNodeRef oldNode,
YGNodeRef newNode,
YGNodeRef parent,
int childIndex);
void YGConfigSetNodeClonedFunc(YGConfigRef config,
YGNodeClonedFunc callback);
```
This PR doesn't change any existing semantics for trees that are not first cloned.
It's possible for a single node to exist in two trees at once and be used by multiple threads. Therefore it's not safe to recursively free a whole tree when you use persistence. To solve this, any user of the library has to manually manage ref counting or tracing GC. E.g. by replicating the tree structure in a wrapper.
In a follow up we could consider moving ref counting into Yoga.
Closes https://github.com/facebook/yoga/pull/636
Reviewed By: emilsjolander
Differential Revision: D5941921
Pulled By: sebmarkbage
fbshipit-source-id: c8e93421824c112d09c4773bed4e3141b6491ccf
2017-10-17 01:02:04 -07:00
|
|
|
}
|
2017-12-19 11:18:00 -08:00
|
|
|
parent->clearChildren();
|
2018-01-08 02:48:35 -08:00
|
|
|
parent->markDirtyAndPropogate();
|
Persistent Yoga
Summary:
This is meant to show a possible route format for a persistent form of Yoga. Where previous layouts can remain intact while still taking advantage of incremental layout by reusing previous subtrees.
```c
YGNodeRef YGNodeClone(const YGNodeRef node);
```
The core of this functionality is a new API to clone an existing node. This makes a new detached node with all the same values as the previous one. Conceptually this makes the original node "frozen" from that point on. It's now immutable. (This is not yet enforced at runtime in this PR but something we should add.)
Since the original is frozen, we reuse the children set from the original node. Their parent pointers still point back to the original tree though.
The cloned node is still mutable. It can have its styles updated, and nodes can be inserted or deleted. If an insertion/deletion happens on a cloned node whose children were reused, it'll first shallow clone its children automatically.
As a convenience I also added an API to clear all children:
```c
void YGNodeRemoveAllChildren(const YGNodeRef node);
```
During insert/delete, or as a result of layout a set of reused children may need to be first cloned. A kind of copy-on-write. When that happens, the host may want to respond. E.g. by updating the `context` such as by cloning any wrapper objects and attaching them to the new node.
```c
typedef void (*YGNodeClonedFunc)(YGNodeRef oldNode,
YGNodeRef newNode,
YGNodeRef parent,
int childIndex);
void YGConfigSetNodeClonedFunc(YGConfigRef config,
YGNodeClonedFunc callback);
```
This PR doesn't change any existing semantics for trees that are not first cloned.
It's possible for a single node to exist in two trees at once and be used by multiple threads. Therefore it's not safe to recursively free a whole tree when you use persistence. To solve this, any user of the library has to manually manage ref counting or tracing GC. E.g. by replicating the tree structure in a wrapper.
In a follow up we could consider moving ref counting into Yoga.
Closes https://github.com/facebook/yoga/pull/636
Reviewed By: emilsjolander
Differential Revision: D5941921
Pulled By: sebmarkbage
fbshipit-source-id: c8e93421824c112d09c4773bed4e3141b6491ccf
2017-10-17 01:02:04 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Otherwise, we are not the owner of the child set. We don't have to do anything to clear it.
|
2017-12-19 11:18:00 -08:00
|
|
|
parent->setChildren(YGVector());
|
2018-01-08 02:48:35 -08:00
|
|
|
parent->markDirtyAndPropogate();
|
Persistent Yoga
Summary:
This is meant to show a possible route format for a persistent form of Yoga. Where previous layouts can remain intact while still taking advantage of incremental layout by reusing previous subtrees.
```c
YGNodeRef YGNodeClone(const YGNodeRef node);
```
The core of this functionality is a new API to clone an existing node. This makes a new detached node with all the same values as the previous one. Conceptually this makes the original node "frozen" from that point on. It's now immutable. (This is not yet enforced at runtime in this PR but something we should add.)
Since the original is frozen, we reuse the children set from the original node. Their parent pointers still point back to the original tree though.
The cloned node is still mutable. It can have its styles updated, and nodes can be inserted or deleted. If an insertion/deletion happens on a cloned node whose children were reused, it'll first shallow clone its children automatically.
As a convenience I also added an API to clear all children:
```c
void YGNodeRemoveAllChildren(const YGNodeRef node);
```
During insert/delete, or as a result of layout a set of reused children may need to be first cloned. A kind of copy-on-write. When that happens, the host may want to respond. E.g. by updating the `context` such as by cloning any wrapper objects and attaching them to the new node.
```c
typedef void (*YGNodeClonedFunc)(YGNodeRef oldNode,
YGNodeRef newNode,
YGNodeRef parent,
int childIndex);
void YGConfigSetNodeClonedFunc(YGConfigRef config,
YGNodeClonedFunc callback);
```
This PR doesn't change any existing semantics for trees that are not first cloned.
It's possible for a single node to exist in two trees at once and be used by multiple threads. Therefore it's not safe to recursively free a whole tree when you use persistence. To solve this, any user of the library has to manually manage ref counting or tracing GC. E.g. by replicating the tree structure in a wrapper.
In a follow up we could consider moving ref counting into Yoga.
Closes https://github.com/facebook/yoga/pull/636
Reviewed By: emilsjolander
Differential Revision: D5941921
Pulled By: sebmarkbage
fbshipit-source-id: c8e93421824c112d09c4773bed4e3141b6491ccf
2017-10-17 01:02:04 -07:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeRef YGNodeGetChild(const YGNodeRef node, const uint32_t index) {
|
2017-12-19 11:18:00 -08:00
|
|
|
if (index < node->getChildren().size()) {
|
|
|
|
return node->getChild(index);
|
2017-12-05 08:16:49 -08:00
|
|
|
}
|
|
|
|
return nullptr;
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
uint32_t YGNodeGetChildCount(const YGNodeRef node) {
|
|
|
|
return node->getChildren().size();
|
2016-12-15 08:49:51 -08:00
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
YGNodeRef YGNodeGetParent(const YGNodeRef node) {
|
|
|
|
return node->getParent();
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
void YGNodeMarkDirty(const YGNodeRef node) {
|
2017-11-21 10:10:30 -08:00
|
|
|
YGAssertWithNode(
|
|
|
|
node,
|
2017-12-19 11:18:00 -08:00
|
|
|
node->getMeasure() != nullptr,
|
2017-11-21 10:10:30 -08:00
|
|
|
"Only leaf nodes with custom measure functions"
|
|
|
|
"should manually mark themselves as dirty");
|
2017-05-03 09:22:35 -07:00
|
|
|
|
2018-01-08 02:48:35 -08:00
|
|
|
node->markDirtyAndPropogate();
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
void YGNodeCopyStyle(const YGNodeRef dstNode, const YGNodeRef srcNode) {
|
2017-12-19 11:18:00 -08:00
|
|
|
if (!(dstNode->getStyle() == srcNode->getStyle())) {
|
|
|
|
dstNode->setStyle(srcNode->getStyle());
|
2018-01-08 02:48:35 -08:00
|
|
|
dstNode->markDirtyAndPropogate();
|
2016-11-17 09:10:45 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-28 09:17:17 -08:00
|
|
|
float YGNodeStyleGetFlexGrow(const YGNodeRef node) {
|
2017-12-19 11:18:00 -08:00
|
|
|
return YGFloatIsUndefined(node->getStyle().flexGrow)
|
|
|
|
? kDefaultFlexGrow
|
|
|
|
: node->getStyle().flexGrow;
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-02-28 09:17:17 -08:00
|
|
|
float YGNodeStyleGetFlexShrink(const YGNodeRef node) {
|
2017-12-19 11:18:00 -08:00
|
|
|
return YGFloatIsUndefined(node->getStyle().flexShrink)
|
|
|
|
? (node->getConfig()->useWebDefaults ? kWebDefaultFlexShrink
|
|
|
|
: kDefaultFlexShrink)
|
|
|
|
: node->getStyle().flexShrink;
|
2017-02-28 09:17:17 -08:00
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
#define YG_NODE_STYLE_PROPERTY_SETTER_IMPL( \
|
|
|
|
type, name, paramName, instanceName) \
|
|
|
|
void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \
|
|
|
|
if (node->getStyle().instanceName != paramName) { \
|
|
|
|
YGStyle style = node->getStyle(); \
|
|
|
|
style.instanceName = paramName; \
|
|
|
|
node->setStyle(style); \
|
2018-01-08 02:48:35 -08:00
|
|
|
node->markDirtyAndPropogate(); \
|
2017-12-19 11:18:00 -08:00
|
|
|
} \
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-11-27 03:06:15 -08:00
|
|
|
#define YG_NODE_STYLE_PROPERTY_SETTER_UNIT_IMPL( \
|
|
|
|
type, name, paramName, instanceName) \
|
|
|
|
void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \
|
|
|
|
YGValue value = { \
|
|
|
|
.value = paramName, \
|
|
|
|
.unit = YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint, \
|
|
|
|
}; \
|
2017-12-19 11:18:00 -08:00
|
|
|
if ((node->getStyle().instanceName.value != value.value && \
|
2017-11-27 03:06:15 -08:00
|
|
|
value.unit != YGUnitUndefined) || \
|
2017-12-19 11:18:00 -08:00
|
|
|
node->getStyle().instanceName.unit != value.unit) { \
|
|
|
|
YGStyle style = node->getStyle(); \
|
|
|
|
style.instanceName = value; \
|
|
|
|
node->setStyle(style); \
|
2018-01-08 02:48:35 -08:00
|
|
|
node->markDirtyAndPropogate(); \
|
2017-11-27 03:06:15 -08:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
void YGNodeStyleSet##name##Percent( \
|
|
|
|
const YGNodeRef node, const type paramName) { \
|
|
|
|
YGValue value = { \
|
|
|
|
.value = paramName, \
|
|
|
|
.unit = \
|
|
|
|
YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPercent, \
|
|
|
|
}; \
|
2017-12-19 11:18:00 -08:00
|
|
|
if ((node->getStyle().instanceName.value != value.value && \
|
2017-11-27 03:06:15 -08:00
|
|
|
value.unit != YGUnitUndefined) || \
|
2017-12-19 11:18:00 -08:00
|
|
|
node->getStyle().instanceName.unit != value.unit) { \
|
|
|
|
YGStyle style = node->getStyle(); \
|
|
|
|
\
|
|
|
|
style.instanceName = value; \
|
|
|
|
node->setStyle(style); \
|
2018-01-08 02:48:35 -08:00
|
|
|
node->markDirtyAndPropogate(); \
|
2017-11-27 03:06:15 -08:00
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define YG_NODE_STYLE_PROPERTY_SETTER_UNIT_AUTO_IMPL( \
|
|
|
|
type, name, paramName, instanceName) \
|
|
|
|
void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \
|
|
|
|
YGValue value = { \
|
|
|
|
.value = paramName, \
|
|
|
|
.unit = YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint, \
|
|
|
|
}; \
|
2017-12-19 11:18:00 -08:00
|
|
|
if ((node->getStyle().instanceName.value != value.value && \
|
2017-11-27 03:06:15 -08:00
|
|
|
value.unit != YGUnitUndefined) || \
|
2017-12-19 11:18:00 -08:00
|
|
|
node->getStyle().instanceName.unit != value.unit) { \
|
|
|
|
YGStyle style = node->getStyle(); \
|
|
|
|
style.instanceName = value; \
|
|
|
|
node->setStyle(style); \
|
2018-01-08 02:48:35 -08:00
|
|
|
node->markDirtyAndPropogate(); \
|
2017-11-27 03:06:15 -08:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
void YGNodeStyleSet##name##Percent( \
|
|
|
|
const YGNodeRef node, const type paramName) { \
|
2017-12-19 11:18:00 -08:00
|
|
|
if (node->getStyle().instanceName.value != paramName || \
|
|
|
|
node->getStyle().instanceName.unit != YGUnitPercent) { \
|
|
|
|
YGStyle style = node->getStyle(); \
|
|
|
|
style.instanceName.value = paramName; \
|
|
|
|
style.instanceName.unit = \
|
2017-11-27 03:06:15 -08:00
|
|
|
YGFloatIsUndefined(paramName) ? YGUnitAuto : YGUnitPercent; \
|
2017-12-19 11:18:00 -08:00
|
|
|
node->setStyle(style); \
|
2018-01-08 02:48:35 -08:00
|
|
|
node->markDirtyAndPropogate(); \
|
2017-11-27 03:06:15 -08:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
void YGNodeStyleSet##name##Auto(const YGNodeRef node) { \
|
2017-12-19 11:18:00 -08:00
|
|
|
if (node->getStyle().instanceName.unit != YGUnitAuto) { \
|
|
|
|
YGStyle style = node->getStyle(); \
|
|
|
|
style.instanceName.value = YGUndefined; \
|
|
|
|
style.instanceName.unit = YGUnitAuto; \
|
|
|
|
node->setStyle(style); \
|
2018-01-08 02:48:35 -08:00
|
|
|
node->markDirtyAndPropogate(); \
|
2017-11-27 03:06:15 -08:00
|
|
|
} \
|
2017-02-14 14:26:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
#define YG_NODE_STYLE_PROPERTY_IMPL(type, name, paramName, instanceName) \
|
|
|
|
YG_NODE_STYLE_PROPERTY_SETTER_IMPL(type, name, paramName, instanceName) \
|
|
|
|
\
|
|
|
|
type YGNodeStyleGet##name(const YGNodeRef node) { \
|
2017-12-19 11:18:00 -08:00
|
|
|
return node->getStyle().instanceName; \
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
#define YG_NODE_STYLE_PROPERTY_UNIT_IMPL(type, name, paramName, instanceName) \
|
|
|
|
YG_NODE_STYLE_PROPERTY_SETTER_UNIT_IMPL( \
|
|
|
|
float, name, paramName, instanceName) \
|
|
|
|
\
|
|
|
|
type YGNodeStyleGet##name(const YGNodeRef node) { \
|
|
|
|
return node->getStyle().instanceName; \
|
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
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
#define YG_NODE_STYLE_PROPERTY_UNIT_AUTO_IMPL( \
|
|
|
|
type, name, paramName, instanceName) \
|
|
|
|
YG_NODE_STYLE_PROPERTY_SETTER_UNIT_AUTO_IMPL( \
|
|
|
|
float, name, paramName, instanceName) \
|
|
|
|
\
|
|
|
|
type YGNodeStyleGet##name(const YGNodeRef node) { \
|
|
|
|
return node->getStyle().instanceName; \
|
2017-02-14 14:26:09 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
#define YG_NODE_STYLE_EDGE_PROPERTY_UNIT_AUTO_IMPL(type, name, instanceName) \
|
|
|
|
void YGNodeStyleSet##name##Auto(const YGNodeRef node, const YGEdge edge) { \
|
2017-12-19 11:18:00 -08:00
|
|
|
if (node->getStyle().instanceName[edge].unit != YGUnitAuto) { \
|
|
|
|
YGStyle style = node->getStyle(); \
|
|
|
|
style.instanceName[edge].value = YGUndefined; \
|
|
|
|
style.instanceName[edge].unit = YGUnitAuto; \
|
|
|
|
node->setStyle(style); \
|
2018-01-08 02:48:35 -08:00
|
|
|
node->markDirtyAndPropogate(); \
|
2017-02-14 14:26:09 -08:00
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2017-11-27 03:06:15 -08:00
|
|
|
#define YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL( \
|
|
|
|
type, name, paramName, instanceName) \
|
|
|
|
void YGNodeStyleSet##name( \
|
|
|
|
const YGNodeRef node, const YGEdge edge, const float paramName) { \
|
|
|
|
YGValue value = { \
|
|
|
|
.value = paramName, \
|
|
|
|
.unit = YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint, \
|
|
|
|
}; \
|
2017-12-19 11:18:00 -08:00
|
|
|
if ((node->getStyle().instanceName[edge].value != value.value && \
|
2017-11-27 03:06:15 -08:00
|
|
|
value.unit != YGUnitUndefined) || \
|
2017-12-19 11:18:00 -08:00
|
|
|
node->getStyle().instanceName[edge].unit != value.unit) { \
|
|
|
|
YGStyle style = node->getStyle(); \
|
|
|
|
style.instanceName[edge] = value; \
|
|
|
|
node->setStyle(style); \
|
2018-01-08 02:48:35 -08:00
|
|
|
node->markDirtyAndPropogate(); \
|
2017-11-27 03:06:15 -08:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
void YGNodeStyleSet##name##Percent( \
|
|
|
|
const YGNodeRef node, const YGEdge edge, const float paramName) { \
|
|
|
|
YGValue value = { \
|
|
|
|
.value = paramName, \
|
|
|
|
.unit = \
|
|
|
|
YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPercent, \
|
|
|
|
}; \
|
2017-12-19 11:18:00 -08:00
|
|
|
if ((node->getStyle().instanceName[edge].value != value.value && \
|
2017-11-27 03:06:15 -08:00
|
|
|
value.unit != YGUnitUndefined) || \
|
2017-12-19 11:18:00 -08:00
|
|
|
node->getStyle().instanceName[edge].unit != value.unit) { \
|
|
|
|
YGStyle style = node->getStyle(); \
|
|
|
|
style.instanceName[edge] = value; \
|
|
|
|
node->setStyle(style); \
|
2018-01-08 02:48:35 -08:00
|
|
|
node->markDirtyAndPropogate(); \
|
2017-11-27 03:06:15 -08:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
WIN_STRUCT(type) \
|
|
|
|
YGNodeStyleGet##name(const YGNodeRef node, const YGEdge edge) { \
|
2017-12-19 11:18:00 -08:00
|
|
|
return WIN_STRUCT_REF(node->getStyle().instanceName[edge]); \
|
2017-11-27 03:06:15 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
#define YG_NODE_STYLE_EDGE_PROPERTY_IMPL(type, name, paramName, instanceName) \
|
|
|
|
void YGNodeStyleSet##name( \
|
|
|
|
const YGNodeRef node, const YGEdge edge, const float paramName) { \
|
|
|
|
YGValue value = { \
|
|
|
|
.value = paramName, \
|
|
|
|
.unit = YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint, \
|
|
|
|
}; \
|
2017-12-19 11:18:00 -08:00
|
|
|
if ((node->getStyle().instanceName[edge].value != value.value && \
|
2017-11-27 03:06:15 -08:00
|
|
|
value.unit != YGUnitUndefined) || \
|
2017-12-19 11:18:00 -08:00
|
|
|
node->getStyle().instanceName[edge].unit != value.unit) { \
|
|
|
|
YGStyle style = node->getStyle(); \
|
|
|
|
style.instanceName[edge] = value; \
|
|
|
|
node->setStyle(style); \
|
2018-01-08 02:48:35 -08:00
|
|
|
node->markDirtyAndPropogate(); \
|
2017-11-27 03:06:15 -08:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
float YGNodeStyleGet##name(const YGNodeRef node, const YGEdge edge) { \
|
2017-12-19 11:18:00 -08:00
|
|
|
return node->getStyle().instanceName[edge].value; \
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
#define YG_NODE_LAYOUT_PROPERTY_IMPL(type, name, instanceName) \
|
|
|
|
type YGNodeLayoutGet##name(const YGNodeRef node) { \
|
2017-12-19 11:18:00 -08:00
|
|
|
return node->getLayout().instanceName; \
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-11-27 02:54:59 -08:00
|
|
|
#define YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(type, name, instanceName) \
|
|
|
|
type YGNodeLayoutGet##name(const YGNodeRef node, const YGEdge edge) { \
|
|
|
|
YGAssertWithNode( \
|
|
|
|
node, \
|
|
|
|
edge <= YGEdgeEnd, \
|
|
|
|
"Cannot get layout properties of multi-edge shorthands"); \
|
|
|
|
\
|
|
|
|
if (edge == YGEdgeLeft) { \
|
2017-12-19 11:18:00 -08:00
|
|
|
if (node->getLayout().direction == YGDirectionRTL) { \
|
|
|
|
return node->getLayout().instanceName[YGEdgeEnd]; \
|
2017-11-27 02:54:59 -08:00
|
|
|
} else { \
|
2017-12-19 11:18:00 -08:00
|
|
|
return node->getLayout().instanceName[YGEdgeStart]; \
|
2017-11-27 02:54:59 -08:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
if (edge == YGEdgeRight) { \
|
2017-12-19 11:18:00 -08:00
|
|
|
if (node->getLayout().direction == YGDirectionRTL) { \
|
|
|
|
return node->getLayout().instanceName[YGEdgeStart]; \
|
2017-11-27 02:54:59 -08:00
|
|
|
} else { \
|
2017-12-19 11:18:00 -08:00
|
|
|
return node->getLayout().instanceName[YGEdgeEnd]; \
|
2017-11-27 02:54:59 -08:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
2017-12-19 11:18:00 -08:00
|
|
|
return node->getLayout().instanceName[edge]; \
|
2017-01-15 15:16:10 -08:00
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
// YG_NODE_PROPERTY_IMPL(void *, Context, context, context);
|
|
|
|
// YG_NODE_PROPERTY_IMPL(YGPrintFunc, PrintFunc, printFunc, print);
|
|
|
|
// YG_NODE_PROPERTY_IMPL(bool, HasNewLayout, hasNewLayout, hasNewLayout);
|
|
|
|
// YG_NODE_PROPERTY_IMPL(YGNodeType, NodeType, nodeType, nodeType);
|
2016-11-11 10:50:09 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YG_NODE_STYLE_PROPERTY_IMPL(YGDirection, Direction, direction, direction);
|
|
|
|
YG_NODE_STYLE_PROPERTY_IMPL(YGFlexDirection, FlexDirection, flexDirection, flexDirection);
|
|
|
|
YG_NODE_STYLE_PROPERTY_IMPL(YGJustify, JustifyContent, justifyContent, justifyContent);
|
|
|
|
YG_NODE_STYLE_PROPERTY_IMPL(YGAlign, AlignContent, alignContent, alignContent);
|
|
|
|
YG_NODE_STYLE_PROPERTY_IMPL(YGAlign, AlignItems, alignItems, alignItems);
|
|
|
|
YG_NODE_STYLE_PROPERTY_IMPL(YGAlign, AlignSelf, alignSelf, alignSelf);
|
|
|
|
YG_NODE_STYLE_PROPERTY_IMPL(YGPositionType, PositionType, positionType, positionType);
|
|
|
|
YG_NODE_STYLE_PROPERTY_IMPL(YGWrap, FlexWrap, flexWrap, flexWrap);
|
|
|
|
YG_NODE_STYLE_PROPERTY_IMPL(YGOverflow, Overflow, overflow, overflow);
|
2017-02-06 09:31:22 -08:00
|
|
|
YG_NODE_STYLE_PROPERTY_IMPL(YGDisplay, Display, display, display);
|
2016-11-11 10:50:09 -08:00
|
|
|
|
2017-02-28 09:17:17 -08:00
|
|
|
YG_NODE_STYLE_PROPERTY_IMPL(float, Flex, flex, flex);
|
2016-12-03 04:40:18 -08:00
|
|
|
YG_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexGrow, flexGrow, flexGrow);
|
|
|
|
YG_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexShrink, flexShrink, flexShrink);
|
2017-02-28 09:17:17 -08:00
|
|
|
YG_NODE_STYLE_PROPERTY_UNIT_AUTO_IMPL(YGValue, FlexBasis, flexBasis, flexBasis);
|
2016-11-11 10:50:09 -08:00
|
|
|
|
2017-02-03 11:19:40 -08:00
|
|
|
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(YGValue, Position, position, position);
|
|
|
|
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(YGValue, Margin, margin, margin);
|
2017-02-14 14:26:09 -08:00
|
|
|
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_AUTO_IMPL(YGValue, Margin, margin);
|
2017-02-03 11:19:40 -08:00
|
|
|
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(YGValue, Padding, padding, padding);
|
|
|
|
YG_NODE_STYLE_EDGE_PROPERTY_IMPL(float, Border, border, border);
|
2016-11-11 10:50:09 -08:00
|
|
|
|
2017-02-14 14:26:09 -08:00
|
|
|
YG_NODE_STYLE_PROPERTY_UNIT_AUTO_IMPL(YGValue, Width, width, dimensions[YGDimensionWidth]);
|
|
|
|
YG_NODE_STYLE_PROPERTY_UNIT_AUTO_IMPL(YGValue, Height, height, dimensions[YGDimensionHeight]);
|
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
|
|
|
YG_NODE_STYLE_PROPERTY_UNIT_IMPL(YGValue, MinWidth, minWidth, minDimensions[YGDimensionWidth]);
|
|
|
|
YG_NODE_STYLE_PROPERTY_UNIT_IMPL(YGValue, MinHeight, minHeight, minDimensions[YGDimensionHeight]);
|
|
|
|
YG_NODE_STYLE_PROPERTY_UNIT_IMPL(YGValue, MaxWidth, maxWidth, maxDimensions[YGDimensionWidth]);
|
|
|
|
YG_NODE_STYLE_PROPERTY_UNIT_IMPL(YGValue, MaxHeight, maxHeight, maxDimensions[YGDimensionHeight]);
|
2016-11-11 10:50:09 -08:00
|
|
|
|
2016-11-21 10:12:26 -08:00
|
|
|
// Yoga specific properties, not compatible with flexbox specification
|
2016-12-03 04:40:18 -08:00
|
|
|
YG_NODE_STYLE_PROPERTY_IMPL(float, AspectRatio, aspectRatio, aspectRatio);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YG_NODE_LAYOUT_PROPERTY_IMPL(float, Left, position[YGEdgeLeft]);
|
|
|
|
YG_NODE_LAYOUT_PROPERTY_IMPL(float, Top, position[YGEdgeTop]);
|
|
|
|
YG_NODE_LAYOUT_PROPERTY_IMPL(float, Right, position[YGEdgeRight]);
|
|
|
|
YG_NODE_LAYOUT_PROPERTY_IMPL(float, Bottom, position[YGEdgeBottom]);
|
|
|
|
YG_NODE_LAYOUT_PROPERTY_IMPL(float, Width, dimensions[YGDimensionWidth]);
|
|
|
|
YG_NODE_LAYOUT_PROPERTY_IMPL(float, Height, dimensions[YGDimensionHeight]);
|
|
|
|
YG_NODE_LAYOUT_PROPERTY_IMPL(YGDirection, Direction, direction);
|
2017-06-30 09:19:33 -07:00
|
|
|
YG_NODE_LAYOUT_PROPERTY_IMPL(bool, HadOverflow, hadOverflow);
|
2016-11-11 10:50:09 -08:00
|
|
|
|
2017-01-15 15:16:10 -08:00
|
|
|
YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Margin, margin);
|
2017-01-26 13:36:38 -08:00
|
|
|
YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Border, border);
|
2017-01-15 15:16:10 -08:00
|
|
|
YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Padding, padding);
|
2017-01-05 12:48:07 -08:00
|
|
|
|
2016-11-11 10:50:09 -08:00
|
|
|
uint32_t gCurrentGenerationCount = 0;
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
bool YGLayoutNodeInternal(const YGNodeRef node,
|
|
|
|
const float availableWidth,
|
|
|
|
const float availableHeight,
|
|
|
|
const YGDirection parentDirection,
|
|
|
|
const YGMeasureMode widthMeasureMode,
|
|
|
|
const YGMeasureMode heightMeasureMode,
|
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
|
|
|
const float parentWidth,
|
|
|
|
const float parentHeight,
|
2016-12-03 04:40:18 -08:00
|
|
|
const bool performLayout,
|
2017-03-01 09:19:55 -08:00
|
|
|
const char *reason,
|
|
|
|
const YGConfigRef config);
|
2016-11-11 10:50:09 -08:00
|
|
|
|
2017-11-23 09:40:02 -08:00
|
|
|
bool YGValueEqual(const YGValue a, const YGValue b) {
|
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
|
|
|
if (a.unit != b.unit) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
if (a.unit == YGUnitUndefined ||
|
|
|
|
(std::isnan(a.value) && std::isnan(b.value))) {
|
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
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fabs(a.value - b.value) < 0.0001f;
|
|
|
|
}
|
|
|
|
|
2017-11-23 09:40:02 -08:00
|
|
|
bool YGFloatsEqual(const float a, const float b) {
|
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
|
|
|
if (YGFloatIsUndefined(a)) {
|
|
|
|
return YGFloatIsUndefined(b);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
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
|
|
|
return fabs(a - b) < 0.0001f;
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-09-21 07:30:21 -07:00
|
|
|
static void YGNodePrintInternal(const YGNodeRef node,
|
|
|
|
const YGPrintOptions options) {
|
2017-11-23 09:40:02 -08:00
|
|
|
std::string str;
|
|
|
|
facebook::yoga::YGNodeToString(&str, node, options, 0);
|
|
|
|
YGLog(node, YGLogLevelDebug, str.c_str());
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
void YGNodePrint(const YGNodeRef node, const YGPrintOptions options) {
|
2017-09-21 07:30:21 -07:00
|
|
|
YGNodePrintInternal(node, options);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
const std::array<YGEdge, 4> leading = {
|
|
|
|
{YGEdgeTop, YGEdgeBottom, YGEdgeLeft, YGEdgeRight}};
|
|
|
|
|
|
|
|
const std::array<YGEdge, 4> trailing = {
|
|
|
|
{YGEdgeBottom, YGEdgeTop, YGEdgeRight, YGEdgeLeft}};
|
|
|
|
static const std::array<YGEdge, 4> pos = {{
|
|
|
|
YGEdgeTop,
|
|
|
|
YGEdgeBottom,
|
|
|
|
YGEdgeLeft,
|
|
|
|
YGEdgeRight,
|
|
|
|
}};
|
|
|
|
static const std::array<YGDimension, 4> dim = {
|
|
|
|
{YGDimensionHeight, YGDimensionHeight, YGDimensionWidth, YGDimensionWidth}};
|
2016-11-11 10:50:09 -08:00
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
bool YGFlexDirectionIsRow(const YGFlexDirection flexDirection) {
|
2016-12-02 05:47:43 -08:00
|
|
|
return flexDirection == YGFlexDirectionRow || flexDirection == YGFlexDirectionRowReverse;
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
static inline bool YGFlexDirectionIsColumn(const YGFlexDirection flexDirection) {
|
2016-12-02 05:47:43 -08:00
|
|
|
return flexDirection == YGFlexDirectionColumn || flexDirection == YGFlexDirectionColumnReverse;
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
static inline float YGNodeLeadingMargin(const YGNodeRef node,
|
|
|
|
const YGFlexDirection axis,
|
|
|
|
const float widthSize) {
|
2017-12-19 11:18:00 -08:00
|
|
|
if (YGFlexDirectionIsRow(axis) &&
|
|
|
|
node->getStyle().margin[YGEdgeStart].unit != YGUnitUndefined) {
|
|
|
|
return YGResolveValueMargin(
|
|
|
|
node->getStyle().margin[YGEdgeStart], widthSize);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
return YGResolveValueMargin(
|
|
|
|
*YGComputedEdgeValue(
|
|
|
|
node->getStyle().margin, leading[axis], &YGValueZero),
|
|
|
|
widthSize);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
static float YGNodeTrailingMargin(const YGNodeRef node,
|
|
|
|
const YGFlexDirection axis,
|
|
|
|
const float widthSize) {
|
2017-12-19 11:18:00 -08:00
|
|
|
if (YGFlexDirectionIsRow(axis) &&
|
|
|
|
node->getStyle().margin[YGEdgeEnd].unit != YGUnitUndefined) {
|
|
|
|
return YGResolveValueMargin(node->getStyle().margin[YGEdgeEnd], widthSize);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
return YGResolveValueMargin(
|
|
|
|
*YGComputedEdgeValue(
|
|
|
|
node->getStyle().margin, trailing[axis], &YGValueZero),
|
|
|
|
widthSize);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
static float YGNodeLeadingPadding(const YGNodeRef node,
|
|
|
|
const YGFlexDirection axis,
|
|
|
|
const float widthSize) {
|
2017-12-19 11:18:00 -08:00
|
|
|
if (YGFlexDirectionIsRow(axis) &&
|
|
|
|
node->getStyle().padding[YGEdgeStart].unit != YGUnitUndefined &&
|
|
|
|
YGResolveValue(node->getStyle().padding[YGEdgeStart], widthSize) >=
|
|
|
|
0.0f) {
|
|
|
|
return YGResolveValue(node->getStyle().padding[YGEdgeStart], widthSize);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
return fmaxf(
|
|
|
|
YGResolveValue(
|
|
|
|
*YGComputedEdgeValue(
|
|
|
|
node->getStyle().padding, leading[axis], &YGValueZero),
|
|
|
|
widthSize),
|
|
|
|
0.0f);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
static float YGNodeTrailingPadding(const YGNodeRef node,
|
|
|
|
const YGFlexDirection axis,
|
|
|
|
const float widthSize) {
|
2017-12-19 11:18:00 -08:00
|
|
|
if (YGFlexDirectionIsRow(axis) &&
|
|
|
|
node->getStyle().padding[YGEdgeEnd].unit != YGUnitUndefined &&
|
|
|
|
YGResolveValue(node->getStyle().padding[YGEdgeEnd], widthSize) >= 0.0f) {
|
|
|
|
return YGResolveValue(node->getStyle().padding[YGEdgeEnd], widthSize);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
return fmaxf(
|
|
|
|
YGResolveValue(
|
|
|
|
*YGComputedEdgeValue(
|
|
|
|
node->getStyle().padding, trailing[axis], &YGValueZero),
|
|
|
|
widthSize),
|
|
|
|
0.0f);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
static float YGNodeLeadingBorder(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const YGFlexDirection axis) {
|
|
|
|
if (YGFlexDirectionIsRow(axis) &&
|
|
|
|
node->getStyle().border[YGEdgeStart].unit != YGUnitUndefined &&
|
|
|
|
node->getStyle().border[YGEdgeStart].value >= 0.0f) {
|
|
|
|
return node->getStyle().border[YGEdgeStart].value;
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
return fmaxf(
|
|
|
|
YGComputedEdgeValue(node->getStyle().border, leading[axis], &YGValueZero)
|
|
|
|
->value,
|
|
|
|
0.0f);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
static float YGNodeTrailingBorder(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const YGFlexDirection axis) {
|
|
|
|
if (YGFlexDirectionIsRow(axis) &&
|
|
|
|
node->getStyle().border[YGEdgeEnd].unit != YGUnitUndefined &&
|
|
|
|
node->getStyle().border[YGEdgeEnd].value >= 0.0f) {
|
|
|
|
return node->getStyle().border[YGEdgeEnd].value;
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
return fmaxf(
|
|
|
|
YGComputedEdgeValue(node->getStyle().border, trailing[axis], &YGValueZero)
|
|
|
|
->value,
|
|
|
|
0.0f);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
static inline float YGNodeLeadingPaddingAndBorder(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const YGFlexDirection axis,
|
|
|
|
const float widthSize) {
|
|
|
|
return YGNodeLeadingPadding(node, axis, widthSize) +
|
|
|
|
YGNodeLeadingBorder(node, axis);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
static inline float YGNodeTrailingPaddingAndBorder(const YGNodeRef node,
|
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
|
|
|
const YGFlexDirection axis,
|
|
|
|
const float widthSize) {
|
|
|
|
return YGNodeTrailingPadding(node, axis, widthSize) + YGNodeTrailingBorder(node, axis);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
static inline float YGNodeMarginForAxis(const YGNodeRef node,
|
|
|
|
const YGFlexDirection axis,
|
|
|
|
const float widthSize) {
|
|
|
|
return YGNodeLeadingMargin(node, axis, widthSize) + YGNodeTrailingMargin(node, axis, widthSize);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
static inline float YGNodePaddingAndBorderForAxis(const YGNodeRef node,
|
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
|
|
|
const YGFlexDirection axis,
|
|
|
|
const float widthSize) {
|
|
|
|
return YGNodeLeadingPaddingAndBorder(node, axis, widthSize) +
|
|
|
|
YGNodeTrailingPaddingAndBorder(node, axis, widthSize);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
static inline YGAlign YGNodeAlignItem(const YGNodeRef node, const YGNodeRef child) {
|
2017-12-19 11:18:00 -08:00
|
|
|
const YGAlign align = child->getStyle().alignSelf == YGAlignAuto
|
|
|
|
? node->getStyle().alignItems
|
|
|
|
: child->getStyle().alignSelf;
|
|
|
|
if (align == YGAlignBaseline &&
|
|
|
|
YGFlexDirectionIsColumn(node->getStyle().flexDirection)) {
|
2017-01-06 06:51:56 -08:00
|
|
|
return YGAlignFlexStart;
|
|
|
|
}
|
|
|
|
return align;
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
static inline YGDirection YGNodeResolveDirection(const YGNodeRef node,
|
|
|
|
const YGDirection parentDirection) {
|
2017-12-19 11:18:00 -08:00
|
|
|
if (node->getStyle().direction == YGDirectionInherit) {
|
2016-12-02 05:47:43 -08:00
|
|
|
return parentDirection > YGDirectionInherit ? parentDirection : YGDirectionLTR;
|
2016-11-11 10:50:09 -08:00
|
|
|
} else {
|
2017-12-19 11:18:00 -08:00
|
|
|
return node->getStyle().direction;
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-06 06:51:56 -08:00
|
|
|
static float YGBaseline(const YGNodeRef node) {
|
2017-12-19 11:18:00 -08:00
|
|
|
if (node->getBaseline() != nullptr) {
|
|
|
|
const float baseline = node->getBaseline()(
|
|
|
|
node,
|
|
|
|
node->getLayout().measuredDimensions[YGDimensionWidth],
|
|
|
|
node->getLayout().measuredDimensions[YGDimensionHeight]);
|
2017-05-03 09:22:35 -07:00
|
|
|
YGAssertWithNode(node,
|
2017-05-12 09:03:22 -07:00
|
|
|
!YGFloatIsUndefined(baseline),
|
|
|
|
"Expect custom baseline function to not return NaN");
|
2017-01-06 06:51:56 -08:00
|
|
|
return baseline;
|
|
|
|
}
|
|
|
|
|
2017-11-21 10:10:30 -08:00
|
|
|
YGNodeRef baselineChild = nullptr;
|
2017-02-15 13:35:24 -08:00
|
|
|
const uint32_t childCount = YGNodeGetChildCount(node);
|
|
|
|
for (uint32_t i = 0; i < childCount; i++) {
|
2017-01-06 06:51:56 -08:00
|
|
|
const YGNodeRef child = YGNodeGetChild(node, i);
|
2017-12-19 11:18:00 -08:00
|
|
|
if (child->getLineIndex() > 0) {
|
2017-01-06 06:51:56 -08:00
|
|
|
break;
|
|
|
|
}
|
2017-12-19 11:18:00 -08:00
|
|
|
if (child->getStyle().positionType == YGPositionTypeAbsolute) {
|
2017-01-06 06:51:56 -08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (YGNodeAlignItem(node, child) == YGAlignBaseline) {
|
|
|
|
baselineChild = child;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-11-21 10:10:30 -08:00
|
|
|
if (baselineChild == nullptr) {
|
2017-01-06 06:51:56 -08:00
|
|
|
baselineChild = child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-21 10:10:30 -08:00
|
|
|
if (baselineChild == nullptr) {
|
2017-12-19 11:18:00 -08:00
|
|
|
return node->getLayout().measuredDimensions[YGDimensionHeight];
|
2017-01-06 06:51:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
const float baseline = YGBaseline(baselineChild);
|
2017-12-19 11:18:00 -08:00
|
|
|
return baseline + baselineChild->getLayout().position[YGEdgeTop];
|
2017-01-06 06:51:56 -08:00
|
|
|
}
|
|
|
|
|
2017-03-10 06:05:53 -08:00
|
|
|
static inline YGFlexDirection YGResolveFlexDirection(const YGFlexDirection flexDirection,
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGDirection direction) {
|
2016-12-02 05:47:43 -08:00
|
|
|
if (direction == YGDirectionRTL) {
|
|
|
|
if (flexDirection == YGFlexDirectionRow) {
|
|
|
|
return YGFlexDirectionRowReverse;
|
|
|
|
} else if (flexDirection == YGFlexDirectionRowReverse) {
|
|
|
|
return YGFlexDirectionRow;
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return flexDirection;
|
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
static YGFlexDirection YGFlexDirectionCross(const YGFlexDirection flexDirection,
|
|
|
|
const YGDirection direction) {
|
|
|
|
return YGFlexDirectionIsColumn(flexDirection)
|
2017-03-10 06:05:53 -08:00
|
|
|
? YGResolveFlexDirection(YGFlexDirectionRow, direction)
|
2016-12-03 04:40:18 -08:00
|
|
|
: YGFlexDirectionColumn;
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
static inline bool YGNodeIsFlex(const YGNodeRef node) {
|
2017-12-19 11:18:00 -08:00
|
|
|
return (
|
|
|
|
node->getStyle().positionType == YGPositionTypeRelative &&
|
2018-01-08 02:48:39 -08:00
|
|
|
(node->resolveFlexGrow() != 0 || node->resolveFlexShrink() != 0));
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-01-06 06:51:56 -08:00
|
|
|
static bool YGIsBaselineLayout(const YGNodeRef node) {
|
2017-12-19 11:18:00 -08:00
|
|
|
if (YGFlexDirectionIsColumn(node->getStyle().flexDirection)) {
|
2017-01-06 06:51:56 -08:00
|
|
|
return false;
|
|
|
|
}
|
2017-12-19 11:18:00 -08:00
|
|
|
if (node->getStyle().alignItems == YGAlignBaseline) {
|
2017-01-06 06:51:56 -08:00
|
|
|
return true;
|
|
|
|
}
|
2017-02-15 13:35:24 -08:00
|
|
|
const uint32_t childCount = YGNodeGetChildCount(node);
|
|
|
|
for (uint32_t i = 0; i < childCount; i++) {
|
2017-01-06 06:51:56 -08:00
|
|
|
const YGNodeRef child = YGNodeGetChild(node, i);
|
2017-12-19 11:18:00 -08:00
|
|
|
if (child->getStyle().positionType == YGPositionTypeRelative &&
|
|
|
|
child->getStyle().alignSelf == YGAlignBaseline) {
|
2017-01-06 06:51:56 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
static inline float YGNodeDimWithMargin(const YGNodeRef node,
|
|
|
|
const YGFlexDirection axis,
|
|
|
|
const float widthSize) {
|
2017-12-19 11:18:00 -08:00
|
|
|
return node->getLayout().measuredDimensions[dim[axis]] +
|
|
|
|
YGNodeLeadingMargin(node, axis, widthSize) +
|
|
|
|
YGNodeTrailingMargin(node, axis, widthSize);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-02-03 05:37:44 -08:00
|
|
|
static inline bool YGNodeIsStyleDimDefined(const YGNodeRef node,
|
|
|
|
const YGFlexDirection axis,
|
|
|
|
const float parentSize) {
|
2017-12-19 11:18:00 -08:00
|
|
|
return !(
|
|
|
|
node->getResolvedDimension(dim[axis]).unit == YGUnitAuto ||
|
|
|
|
node->getResolvedDimension(dim[axis]).unit == YGUnitUndefined ||
|
|
|
|
(node->getResolvedDimension(dim[axis]).unit == YGUnitPoint &&
|
|
|
|
node->getResolvedDimension(dim[axis]).value < 0.0f) ||
|
|
|
|
(node->getResolvedDimension(dim[axis]).unit == YGUnitPercent &&
|
|
|
|
(node->getResolvedDimension(dim[axis]).value < 0.0f ||
|
|
|
|
YGFloatIsUndefined(parentSize))));
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
static inline bool YGNodeIsLayoutDimDefined(const YGNodeRef node, const YGFlexDirection axis) {
|
2017-12-19 11:18:00 -08:00
|
|
|
const float value = node->getLayout().measuredDimensions[dim[axis]];
|
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
|
|
|
return !YGFloatIsUndefined(value) && value >= 0.0f;
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
static inline bool YGNodeIsLeadingPosDefined(const YGNodeRef node, const YGFlexDirection axis) {
|
|
|
|
return (YGFlexDirectionIsRow(axis) &&
|
2017-12-19 11:18:00 -08:00
|
|
|
YGComputedEdgeValue(
|
|
|
|
node->getStyle().position, YGEdgeStart, &YGValueUndefined)
|
|
|
|
->unit != YGUnitUndefined) ||
|
|
|
|
YGComputedEdgeValue(
|
|
|
|
node->getStyle().position, leading[axis], &YGValueUndefined)
|
|
|
|
->unit != YGUnitUndefined;
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
static inline bool YGNodeIsTrailingPosDefined(const YGNodeRef node, const YGFlexDirection axis) {
|
|
|
|
return (YGFlexDirectionIsRow(axis) &&
|
2017-12-19 11:18:00 -08:00
|
|
|
YGComputedEdgeValue(
|
|
|
|
node->getStyle().position, YGEdgeEnd, &YGValueUndefined)
|
|
|
|
->unit != YGUnitUndefined) ||
|
|
|
|
YGComputedEdgeValue(
|
|
|
|
node->getStyle().position, trailing[axis], &YGValueUndefined)
|
|
|
|
->unit != YGUnitUndefined;
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
static float YGNodeLeadingPosition(const YGNodeRef node,
|
|
|
|
const YGFlexDirection axis,
|
|
|
|
const float axisSize) {
|
2016-12-03 04:40:18 -08:00
|
|
|
if (YGFlexDirectionIsRow(axis)) {
|
2017-12-19 11:18:00 -08:00
|
|
|
const YGValue* leadingPosition = YGComputedEdgeValue(
|
|
|
|
node->getStyle().position, YGEdgeStart, &YGValueUndefined);
|
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
|
|
|
if (leadingPosition->unit != YGUnitUndefined) {
|
2017-12-19 11:18:00 -08:00
|
|
|
return YGResolveValue(
|
|
|
|
*leadingPosition,
|
|
|
|
axisSize); // leadingPosition->resolveValue(axisSize);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
const YGValue* leadingPosition = YGComputedEdgeValue(
|
|
|
|
node->getStyle().position, leading[axis], &YGValueUndefined);
|
2016-11-11 10:50:09 -08:00
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
return leadingPosition->unit == YGUnitUndefined
|
|
|
|
? 0.0f
|
|
|
|
: YGResolveValue(*leadingPosition, axisSize);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
static float YGNodeTrailingPosition(const YGNodeRef node,
|
|
|
|
const YGFlexDirection axis,
|
|
|
|
const float axisSize) {
|
2016-12-03 04:40:18 -08:00
|
|
|
if (YGFlexDirectionIsRow(axis)) {
|
2017-12-19 11:18:00 -08:00
|
|
|
const YGValue* trailingPosition = YGComputedEdgeValue(
|
|
|
|
node->getStyle().position, YGEdgeEnd, &YGValueUndefined);
|
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
|
|
|
if (trailingPosition->unit != YGUnitUndefined) {
|
2017-12-19 11:18:00 -08:00
|
|
|
return YGResolveValue(*trailingPosition, axisSize);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
const YGValue* trailingPosition = YGComputedEdgeValue(
|
|
|
|
node->getStyle().position, trailing[axis], &YGValueUndefined);
|
2016-11-11 10:50:09 -08:00
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
return trailingPosition->unit == YGUnitUndefined
|
|
|
|
? 0.0f
|
|
|
|
: YGResolveValue(*trailingPosition, axisSize);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
static float YGNodeBoundAxisWithinMinAndMax(const YGNodeRef node,
|
|
|
|
const YGFlexDirection axis,
|
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
|
|
|
const float value,
|
|
|
|
const float axisSize) {
|
2016-12-02 05:47:43 -08:00
|
|
|
float min = YGUndefined;
|
|
|
|
float max = YGUndefined;
|
2017-02-11 05:26:55 -08:00
|
|
|
|
|
|
|
if (YGFlexDirectionIsColumn(axis)) {
|
2017-12-19 11:18:00 -08:00
|
|
|
min = YGResolveValue(
|
|
|
|
node->getStyle().minDimensions[YGDimensionHeight], axisSize);
|
|
|
|
max = YGResolveValue(
|
|
|
|
node->getStyle().maxDimensions[YGDimensionHeight], axisSize);
|
2017-02-11 05:26:55 -08:00
|
|
|
} else if (YGFlexDirectionIsRow(axis)) {
|
2017-12-19 11:18:00 -08:00
|
|
|
min = YGResolveValue(
|
|
|
|
node->getStyle().minDimensions[YGDimensionWidth], axisSize);
|
|
|
|
max = YGResolveValue(
|
|
|
|
node->getStyle().maxDimensions[YGDimensionWidth], axisSize);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
float boundValue = value;
|
|
|
|
|
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
|
|
|
if (!YGFloatIsUndefined(max) && max >= 0.0f && boundValue > max) {
|
2016-11-11 10:50:09 -08:00
|
|
|
boundValue = max;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
if (!YGFloatIsUndefined(min) && min >= 0.0f && boundValue < min) {
|
2016-11-11 10:50:09 -08:00
|
|
|
boundValue = min;
|
|
|
|
}
|
|
|
|
|
|
|
|
return boundValue;
|
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
// Like YGNodeBoundAxisWithinMinAndMax but also ensures that the value doesn't go
|
2016-11-11 10:50:09 -08:00
|
|
|
// below the
|
|
|
|
// padding and border amount.
|
2016-12-03 04:40:18 -08:00
|
|
|
static inline float YGNodeBoundAxis(const YGNodeRef node,
|
|
|
|
const YGFlexDirection axis,
|
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
|
|
|
const float value,
|
|
|
|
const float axisSize,
|
|
|
|
const float widthSize) {
|
|
|
|
return fmaxf(YGNodeBoundAxisWithinMinAndMax(node, axis, value, axisSize),
|
|
|
|
YGNodePaddingAndBorderForAxis(node, axis, widthSize));
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
static void YGNodeSetChildTrailingPosition(const YGNodeRef node,
|
|
|
|
const YGNodeRef child,
|
|
|
|
const YGFlexDirection axis) {
|
2017-12-19 11:18:00 -08:00
|
|
|
const float size = child->getLayout().measuredDimensions[dim[axis]];
|
|
|
|
child->setLayoutPosition(
|
|
|
|
node->getLayout().measuredDimensions[dim[axis]] - size -
|
|
|
|
child->getLayout().position[pos[axis]],
|
|
|
|
trailing[axis]);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// If both left and right are defined, then use left. Otherwise return
|
|
|
|
// +left or -right depending on which is defined.
|
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
|
|
|
static float YGNodeRelativePosition(const YGNodeRef node,
|
|
|
|
const YGFlexDirection axis,
|
|
|
|
const float axisSize) {
|
|
|
|
return YGNodeIsLeadingPosDefined(node, axis) ? YGNodeLeadingPosition(node, axis, axisSize)
|
|
|
|
: -YGNodeTrailingPosition(node, axis, axisSize);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-03-09 03:48:33 -08:00
|
|
|
static void YGConstrainMaxSizeForMode(const YGNodeRef node,
|
|
|
|
const enum YGFlexDirection axis,
|
|
|
|
const float parentAxisSize,
|
|
|
|
const float parentWidth,
|
|
|
|
YGMeasureMode *mode,
|
|
|
|
float *size) {
|
2017-12-19 11:18:00 -08:00
|
|
|
const float maxSize =
|
|
|
|
YGResolveValue(
|
|
|
|
node->getStyle().maxDimensions[dim[axis]], parentAxisSize) +
|
|
|
|
YGNodeMarginForAxis(node, axis, parentWidth);
|
2016-11-11 10:50:09 -08:00
|
|
|
switch (*mode) {
|
2016-12-02 05:47:43 -08:00
|
|
|
case YGMeasureModeExactly:
|
|
|
|
case YGMeasureModeAtMost:
|
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
|
|
|
*size = (YGFloatIsUndefined(maxSize) || *size < maxSize) ? *size : maxSize;
|
2016-11-11 10:50:09 -08:00
|
|
|
break;
|
2016-12-02 05:47:43 -08:00
|
|
|
case YGMeasureModeUndefined:
|
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
|
|
|
if (!YGFloatIsUndefined(maxSize)) {
|
2016-12-02 05:47:43 -08:00
|
|
|
*mode = YGMeasureModeAtMost;
|
2016-11-11 10:50:09 -08:00
|
|
|
*size = maxSize;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
static void YGNodeSetPosition(const YGNodeRef node,
|
|
|
|
const YGDirection direction,
|
|
|
|
const float mainSize,
|
|
|
|
const float crossSize,
|
|
|
|
const float parentWidth) {
|
2017-04-11 13:00:02 -07:00
|
|
|
/* Root nodes should be always layouted as LTR, so we don't return negative values. */
|
2017-11-21 10:10:30 -08:00
|
|
|
const YGDirection directionRespectingRoot =
|
2017-12-19 11:18:00 -08:00
|
|
|
node->getParent() != nullptr ? direction : YGDirectionLTR;
|
|
|
|
const YGFlexDirection mainAxis = YGResolveFlexDirection(
|
|
|
|
node->getStyle().flexDirection, directionRespectingRoot);
|
2017-04-11 13:00:02 -07:00
|
|
|
const YGFlexDirection crossAxis = YGFlexDirectionCross(mainAxis, directionRespectingRoot);
|
|
|
|
|
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
|
|
|
const float relativePositionMain = YGNodeRelativePosition(node, mainAxis, mainSize);
|
|
|
|
const float relativePositionCross = YGNodeRelativePosition(node, crossAxis, crossSize);
|
2016-11-11 10:50:09 -08:00
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
node->setLayoutPosition(
|
|
|
|
YGNodeLeadingMargin(node, mainAxis, parentWidth) + relativePositionMain,
|
|
|
|
leading[mainAxis]);
|
|
|
|
node->setLayoutPosition(
|
|
|
|
YGNodeTrailingMargin(node, mainAxis, parentWidth) + relativePositionMain,
|
|
|
|
trailing[mainAxis]);
|
|
|
|
node->setLayoutPosition(
|
|
|
|
YGNodeLeadingMargin(node, crossAxis, parentWidth) + relativePositionCross,
|
|
|
|
leading[crossAxis]);
|
|
|
|
node->setLayoutPosition(
|
|
|
|
YGNodeTrailingMargin(node, crossAxis, parentWidth) +
|
|
|
|
relativePositionCross,
|
|
|
|
trailing[crossAxis]);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
static void YGNodeComputeFlexBasisForChild(const YGNodeRef node,
|
|
|
|
const YGNodeRef child,
|
|
|
|
const float width,
|
|
|
|
const YGMeasureMode widthMode,
|
|
|
|
const float height,
|
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
|
|
|
const float parentWidth,
|
|
|
|
const float parentHeight,
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGMeasureMode heightMode,
|
2017-03-01 09:19:55 -08:00
|
|
|
const YGDirection direction,
|
|
|
|
const YGConfigRef config) {
|
2017-12-19 11:18:00 -08:00
|
|
|
const YGFlexDirection mainAxis =
|
|
|
|
YGResolveFlexDirection(node->getStyle().flexDirection, direction);
|
2016-12-03 04:40:18 -08:00
|
|
|
const bool isMainAxisRow = YGFlexDirectionIsRow(mainAxis);
|
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
|
|
|
const float mainAxisSize = isMainAxisRow ? width : height;
|
|
|
|
const float mainAxisParentSize = isMainAxisRow ? parentWidth : parentHeight;
|
2016-11-11 10:50:09 -08:00
|
|
|
|
|
|
|
float childWidth;
|
|
|
|
float childHeight;
|
2016-12-02 05:47:43 -08:00
|
|
|
YGMeasureMode childWidthMeasureMode;
|
|
|
|
YGMeasureMode childHeightMeasureMode;
|
2016-11-11 10:50:09 -08:00
|
|
|
|
2017-02-03 05:37:44 -08:00
|
|
|
const float resolvedFlexBasis =
|
2017-12-19 11:18:00 -08:00
|
|
|
YGResolveValue(child->resolveFlexBasisPtr(), mainAxisParentSize);
|
2017-02-03 05:37:44 -08:00
|
|
|
const bool isRowStyleDimDefined = YGNodeIsStyleDimDefined(child, YGFlexDirectionRow, parentWidth);
|
|
|
|
const bool isColumnStyleDimDefined =
|
|
|
|
YGNodeIsStyleDimDefined(child, YGFlexDirectionColumn, parentHeight);
|
2016-11-11 10:50:09 -08:00
|
|
|
|
2017-02-03 05:37:44 -08:00
|
|
|
if (!YGFloatIsUndefined(resolvedFlexBasis) && !YGFloatIsUndefined(mainAxisSize)) {
|
2017-12-19 11:18:00 -08:00
|
|
|
if (YGFloatIsUndefined(child->getLayout().computedFlexBasis) ||
|
|
|
|
(YGConfigIsExperimentalFeatureEnabled(
|
|
|
|
child->getConfig(), YGExperimentalFeatureWebFlexBasis) &&
|
|
|
|
child->getLayout().computedFlexBasisGeneration !=
|
|
|
|
gCurrentGenerationCount)) {
|
|
|
|
child->setLayoutComputedFlexBasis(fmaxf(
|
|
|
|
resolvedFlexBasis,
|
|
|
|
YGNodePaddingAndBorderForAxis(child, mainAxis, parentWidth)));
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
} else if (isMainAxisRow && isRowStyleDimDefined) {
|
|
|
|
// The width is definite, so use that as the flex basis.
|
2017-12-19 11:18:00 -08:00
|
|
|
child->setLayoutComputedFlexBasis(fmaxf(
|
|
|
|
YGResolveValue(
|
|
|
|
child->getResolvedDimension(YGDimensionWidth), parentWidth),
|
|
|
|
YGNodePaddingAndBorderForAxis(child, YGFlexDirectionRow, parentWidth)));
|
2016-11-11 10:50:09 -08:00
|
|
|
} else if (!isMainAxisRow && isColumnStyleDimDefined) {
|
|
|
|
// The height is definite, so use that as the flex basis.
|
2017-12-19 11:18:00 -08:00
|
|
|
child->setLayoutComputedFlexBasis(fmaxf(
|
|
|
|
YGResolveValue(
|
|
|
|
child->getResolvedDimension(YGDimensionHeight), parentHeight),
|
|
|
|
YGNodePaddingAndBorderForAxis(
|
|
|
|
child, YGFlexDirectionColumn, parentWidth)));
|
2016-11-11 10:50:09 -08:00
|
|
|
} else {
|
|
|
|
// Compute the flex basis and hypothetical main size (i.e. the clamped
|
|
|
|
// flex basis).
|
2016-12-02 05:47:43 -08:00
|
|
|
childWidth = YGUndefined;
|
|
|
|
childHeight = YGUndefined;
|
|
|
|
childWidthMeasureMode = YGMeasureModeUndefined;
|
|
|
|
childHeightMeasureMode = YGMeasureModeUndefined;
|
2016-11-11 10:50:09 -08:00
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
const float marginRow =
|
|
|
|
YGNodeMarginForAxis(child, YGFlexDirectionRow, parentWidth);
|
|
|
|
const float marginColumn =
|
|
|
|
YGNodeMarginForAxis(child, YGFlexDirectionColumn, parentWidth);
|
2017-01-27 09:56:35 -08:00
|
|
|
|
2016-11-11 10:50:09 -08:00
|
|
|
if (isRowStyleDimDefined) {
|
2017-01-27 09:56:35 -08:00
|
|
|
childWidth =
|
2017-12-19 11:18:00 -08:00
|
|
|
YGResolveValue(
|
|
|
|
child->getResolvedDimension(YGDimensionWidth), parentWidth) +
|
|
|
|
marginRow;
|
2016-12-02 05:47:43 -08:00
|
|
|
childWidthMeasureMode = YGMeasureModeExactly;
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
if (isColumnStyleDimDefined) {
|
2017-02-11 08:32:50 -08:00
|
|
|
childHeight =
|
2017-12-19 11:18:00 -08:00
|
|
|
YGResolveValue(
|
|
|
|
child->getResolvedDimension(YGDimensionHeight), parentHeight) +
|
|
|
|
marginColumn;
|
2016-12-02 05:47:43 -08:00
|
|
|
childHeightMeasureMode = YGMeasureModeExactly;
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// The W3C spec doesn't say anything about the 'overflow' property,
|
|
|
|
// but all major browsers appear to implement the following logic.
|
2017-12-19 11:18:00 -08:00
|
|
|
if ((!isMainAxisRow && node->getStyle().overflow == YGOverflowScroll) ||
|
|
|
|
node->getStyle().overflow != YGOverflowScroll) {
|
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
|
|
|
if (YGFloatIsUndefined(childWidth) && !YGFloatIsUndefined(width)) {
|
2016-11-11 10:50:09 -08:00
|
|
|
childWidth = width;
|
2016-12-02 05:47:43 -08:00
|
|
|
childWidthMeasureMode = YGMeasureModeAtMost;
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
if ((isMainAxisRow && node->getStyle().overflow == YGOverflowScroll) ||
|
|
|
|
node->getStyle().overflow != YGOverflowScroll) {
|
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
|
|
|
if (YGFloatIsUndefined(childHeight) && !YGFloatIsUndefined(height)) {
|
2016-11-11 10:50:09 -08:00
|
|
|
childHeight = height;
|
2016-12-02 05:47:43 -08:00
|
|
|
childHeightMeasureMode = YGMeasureModeAtMost;
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
if (!YGFloatIsUndefined(child->getStyle().aspectRatio)) {
|
2017-08-21 03:09:09 -07:00
|
|
|
if (!isMainAxisRow && childWidthMeasureMode == YGMeasureModeExactly) {
|
2017-12-19 11:18:00 -08:00
|
|
|
childHeight = (childWidth - marginRow) / child->getStyle().aspectRatio;
|
2017-08-21 03:09:09 -07:00
|
|
|
childHeightMeasureMode = YGMeasureModeExactly;
|
|
|
|
} else if (isMainAxisRow && childHeightMeasureMode == YGMeasureModeExactly) {
|
2017-12-19 11:18:00 -08:00
|
|
|
childWidth =
|
|
|
|
(childHeight - marginColumn) * child->getStyle().aspectRatio;
|
2017-08-21 03:09:09 -07:00
|
|
|
childWidthMeasureMode = YGMeasureModeExactly;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-11 10:50:09 -08:00
|
|
|
// If child has no defined size in the cross axis and is set to stretch,
|
|
|
|
// set the cross
|
|
|
|
// axis to be measured exactly with the available inner width
|
2017-08-21 03:09:09 -07:00
|
|
|
|
|
|
|
const bool hasExactWidth = !YGFloatIsUndefined(width) && widthMode == YGMeasureModeExactly;
|
|
|
|
const bool childWidthStretch = YGNodeAlignItem(node, child) == YGAlignStretch &&
|
|
|
|
childWidthMeasureMode != YGMeasureModeExactly;
|
|
|
|
if (!isMainAxisRow && !isRowStyleDimDefined && hasExactWidth && childWidthStretch) {
|
2016-11-11 10:50:09 -08:00
|
|
|
childWidth = width;
|
2016-12-02 05:47:43 -08:00
|
|
|
childWidthMeasureMode = YGMeasureModeExactly;
|
2017-12-19 11:18:00 -08:00
|
|
|
if (!YGFloatIsUndefined(child->getStyle().aspectRatio)) {
|
|
|
|
childHeight = (childWidth - marginRow) / child->getStyle().aspectRatio;
|
2017-08-21 03:09:09 -07:00
|
|
|
childHeightMeasureMode = YGMeasureModeExactly;
|
|
|
|
}
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
2017-08-21 03:09:09 -07:00
|
|
|
|
|
|
|
const bool hasExactHeight = !YGFloatIsUndefined(height) && heightMode == YGMeasureModeExactly;
|
|
|
|
const bool childHeightStretch = YGNodeAlignItem(node, child) == YGAlignStretch &&
|
|
|
|
childHeightMeasureMode != YGMeasureModeExactly;
|
|
|
|
if (isMainAxisRow && !isColumnStyleDimDefined && hasExactHeight && childHeightStretch) {
|
2016-11-11 10:50:09 -08:00
|
|
|
childHeight = height;
|
2016-12-02 05:47:43 -08:00
|
|
|
childHeightMeasureMode = YGMeasureModeExactly;
|
2016-11-11 10:50:09 -08:00
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
if (!YGFloatIsUndefined(child->getStyle().aspectRatio)) {
|
|
|
|
childWidth =
|
|
|
|
(childHeight - marginColumn) * child->getStyle().aspectRatio;
|
2017-08-21 03:09:09 -07:00
|
|
|
childWidthMeasureMode = YGMeasureModeExactly;
|
2016-11-21 10:12:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-09 03:48:33 -08:00
|
|
|
YGConstrainMaxSizeForMode(
|
|
|
|
child, YGFlexDirectionRow, parentWidth, parentWidth, &childWidthMeasureMode, &childWidth);
|
2017-05-03 09:22:35 -07:00
|
|
|
YGConstrainMaxSizeForMode(child,
|
|
|
|
YGFlexDirectionColumn,
|
|
|
|
parentHeight,
|
|
|
|
parentWidth,
|
|
|
|
&childHeightMeasureMode,
|
|
|
|
&childHeight);
|
2016-11-11 10:50:09 -08:00
|
|
|
|
|
|
|
// Measure the child
|
2016-12-03 04:40:18 -08:00
|
|
|
YGLayoutNodeInternal(child,
|
|
|
|
childWidth,
|
|
|
|
childHeight,
|
|
|
|
direction,
|
|
|
|
childWidthMeasureMode,
|
|
|
|
childHeightMeasureMode,
|
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
|
|
|
parentWidth,
|
|
|
|
parentHeight,
|
2016-12-03 04:40:18 -08:00
|
|
|
false,
|
2017-03-01 09:19:55 -08:00
|
|
|
"measure",
|
|
|
|
config);
|
2016-11-11 10:50:09 -08:00
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
child->setLayoutComputedFlexBasis(fmaxf(
|
|
|
|
child->getLayout().measuredDimensions[dim[mainAxis]],
|
|
|
|
YGNodePaddingAndBorderForAxis(child, mainAxis, parentWidth)));
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
2017-12-19 11:18:00 -08:00
|
|
|
child->setLayoutComputedFlexBasisGeneration(gCurrentGenerationCount);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
static void YGNodeAbsoluteLayoutChild(const YGNodeRef node,
|
|
|
|
const YGNodeRef child,
|
|
|
|
const float width,
|
|
|
|
const YGMeasureMode widthMode,
|
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
|
|
|
const float height,
|
2017-03-01 09:19:55 -08:00
|
|
|
const YGDirection direction,
|
|
|
|
const YGConfigRef config) {
|
2017-12-19 11:18:00 -08:00
|
|
|
const YGFlexDirection mainAxis =
|
|
|
|
YGResolveFlexDirection(node->getStyle().flexDirection, direction);
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGFlexDirection crossAxis = YGFlexDirectionCross(mainAxis, direction);
|
|
|
|
const bool isMainAxisRow = YGFlexDirectionIsRow(mainAxis);
|
2016-11-11 10:50:09 -08:00
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
float childWidth = YGUndefined;
|
|
|
|
float childHeight = YGUndefined;
|
|
|
|
YGMeasureMode childWidthMeasureMode = YGMeasureModeUndefined;
|
|
|
|
YGMeasureMode childHeightMeasureMode = YGMeasureModeUndefined;
|
2016-11-11 10:50:09 -08:00
|
|
|
|
2017-01-27 09:56:35 -08:00
|
|
|
const float marginRow = YGNodeMarginForAxis(child, YGFlexDirectionRow, width);
|
|
|
|
const float marginColumn = YGNodeMarginForAxis(child, YGFlexDirectionColumn, width);
|
|
|
|
|
2017-02-03 05:37:44 -08:00
|
|
|
if (YGNodeIsStyleDimDefined(child, YGFlexDirectionRow, width)) {
|
2017-12-19 11:18:00 -08:00
|
|
|
childWidth =
|
|
|
|
YGResolveValue(child->getResolvedDimension(YGDimensionWidth), width) +
|
|
|
|
marginRow;
|
2016-11-11 10:50:09 -08:00
|
|
|
} else {
|
|
|
|
// If the child doesn't have a specified width, compute the width based
|
|
|
|
// on the left/right
|
|
|
|
// offsets if they're defined.
|
2016-12-03 04:40:18 -08:00
|
|
|
if (YGNodeIsLeadingPosDefined(child, YGFlexDirectionRow) &&
|
|
|
|
YGNodeIsTrailingPosDefined(child, YGFlexDirectionRow)) {
|
2017-12-19 11:18:00 -08:00
|
|
|
childWidth = node->getLayout().measuredDimensions[YGDimensionWidth] -
|
|
|
|
(YGNodeLeadingBorder(node, YGFlexDirectionRow) +
|
|
|
|
YGNodeTrailingBorder(node, YGFlexDirectionRow)) -
|
|
|
|
(YGNodeLeadingPosition(child, YGFlexDirectionRow, width) +
|
|
|
|
YGNodeTrailingPosition(child, YGFlexDirectionRow, width));
|
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
|
|
|
childWidth = YGNodeBoundAxis(child, YGFlexDirectionRow, childWidth, width, width);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-03 05:37:44 -08:00
|
|
|
if (YGNodeIsStyleDimDefined(child, YGFlexDirectionColumn, height)) {
|
2017-01-27 09:56:35 -08:00
|
|
|
childHeight =
|
2017-12-19 11:18:00 -08:00
|
|
|
YGResolveValue(child->getResolvedDimension(YGDimensionHeight), height) +
|
|
|
|
marginColumn;
|
2016-11-11 10:50:09 -08:00
|
|
|
} else {
|
|
|
|
// If the child doesn't have a specified height, compute the height
|
|
|
|
// based on the top/bottom
|
|
|
|
// offsets if they're defined.
|
2016-12-03 04:40:18 -08:00
|
|
|
if (YGNodeIsLeadingPosDefined(child, YGFlexDirectionColumn) &&
|
|
|
|
YGNodeIsTrailingPosDefined(child, YGFlexDirectionColumn)) {
|
2017-12-19 11:18:00 -08:00
|
|
|
childHeight = node->getLayout().measuredDimensions[YGDimensionHeight] -
|
|
|
|
(YGNodeLeadingBorder(node, YGFlexDirectionColumn) +
|
|
|
|
YGNodeTrailingBorder(node, YGFlexDirectionColumn)) -
|
|
|
|
(YGNodeLeadingPosition(child, YGFlexDirectionColumn, height) +
|
|
|
|
YGNodeTrailingPosition(child, YGFlexDirectionColumn, height));
|
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
|
|
|
childHeight = YGNodeBoundAxis(child, YGFlexDirectionColumn, childHeight, height, width);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-21 10:12:26 -08:00
|
|
|
// Exactly one dimension needs to be defined for us to be able to do aspect ratio
|
|
|
|
// calculation. One dimension being the anchor and the other being flexible.
|
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
|
|
|
if (YGFloatIsUndefined(childWidth) ^ YGFloatIsUndefined(childHeight)) {
|
2017-12-19 11:18:00 -08:00
|
|
|
if (!YGFloatIsUndefined(child->getStyle().aspectRatio)) {
|
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
|
|
|
if (YGFloatIsUndefined(childWidth)) {
|
2017-12-19 11:18:00 -08:00
|
|
|
childWidth = marginRow +
|
|
|
|
(childHeight - marginColumn) * child->getStyle().aspectRatio;
|
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
|
|
|
} else if (YGFloatIsUndefined(childHeight)) {
|
2017-12-19 11:18:00 -08:00
|
|
|
childHeight = marginColumn +
|
|
|
|
(childWidth - marginRow) / child->getStyle().aspectRatio;
|
2016-11-21 10:12:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-11 10:50:09 -08:00
|
|
|
// If we're still missing one or the other dimension, measure the content.
|
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
|
|
|
if (YGFloatIsUndefined(childWidth) || YGFloatIsUndefined(childHeight)) {
|
2016-11-11 10:50:09 -08:00
|
|
|
childWidthMeasureMode =
|
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
|
|
|
YGFloatIsUndefined(childWidth) ? YGMeasureModeUndefined : YGMeasureModeExactly;
|
2016-11-11 10:50:09 -08:00
|
|
|
childHeightMeasureMode =
|
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
|
|
|
YGFloatIsUndefined(childHeight) ? YGMeasureModeUndefined : YGMeasureModeExactly;
|
2016-11-11 10:50:09 -08:00
|
|
|
|
2017-01-24 17:04:54 -08:00
|
|
|
// If the size of the parent is defined then try to constrain the absolute child to that size
|
|
|
|
// as well. This allows text within the absolute child to wrap to the size of its parent.
|
|
|
|
// This is the same behavior as many browsers implement.
|
2017-01-26 13:36:39 -08:00
|
|
|
if (!isMainAxisRow && YGFloatIsUndefined(childWidth) && widthMode != YGMeasureModeUndefined &&
|
|
|
|
width > 0) {
|
2016-11-11 10:50:09 -08:00
|
|
|
childWidth = width;
|
2016-12-02 05:47:43 -08:00
|
|
|
childWidthMeasureMode = YGMeasureModeAtMost;
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGLayoutNodeInternal(child,
|
|
|
|
childWidth,
|
|
|
|
childHeight,
|
|
|
|
direction,
|
|
|
|
childWidthMeasureMode,
|
|
|
|
childHeightMeasureMode,
|
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
|
|
|
childWidth,
|
|
|
|
childHeight,
|
2016-12-03 04:40:18 -08:00
|
|
|
false,
|
2017-03-01 09:19:55 -08:00
|
|
|
"abs-measure",
|
|
|
|
config);
|
2017-12-19 11:18:00 -08:00
|
|
|
childWidth = child->getLayout().measuredDimensions[YGDimensionWidth] +
|
|
|
|
YGNodeMarginForAxis(child, YGFlexDirectionRow, width);
|
|
|
|
childHeight = child->getLayout().measuredDimensions[YGDimensionHeight] +
|
|
|
|
YGNodeMarginForAxis(child, YGFlexDirectionColumn, width);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGLayoutNodeInternal(child,
|
|
|
|
childWidth,
|
|
|
|
childHeight,
|
|
|
|
direction,
|
|
|
|
YGMeasureModeExactly,
|
|
|
|
YGMeasureModeExactly,
|
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
|
|
|
childWidth,
|
|
|
|
childHeight,
|
2016-12-03 04:40:18 -08:00
|
|
|
true,
|
2017-03-01 09:19:55 -08:00
|
|
|
"abs-layout",
|
|
|
|
config);
|
2016-11-11 10:50:09 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
if (YGNodeIsTrailingPosDefined(child, mainAxis) && !YGNodeIsLeadingPosDefined(child, mainAxis)) {
|
2017-12-19 11:18:00 -08:00
|
|
|
child->setLayoutPosition(
|
|
|
|
node->getLayout().measuredDimensions[dim[mainAxis]] -
|
|
|
|
child->getLayout().measuredDimensions[dim[mainAxis]] -
|
|
|
|
YGNodeTrailingBorder(node, mainAxis) -
|
|
|
|
YGNodeTrailingMargin(child, mainAxis, width) -
|
|
|
|
YGNodeTrailingPosition(
|
|
|
|
child, mainAxis, isMainAxisRow ? width : height),
|
|
|
|
leading[mainAxis]);
|
|
|
|
} else if (
|
|
|
|
!YGNodeIsLeadingPosDefined(child, mainAxis) &&
|
|
|
|
node->getStyle().justifyContent == YGJustifyCenter) {
|
|
|
|
child->setLayoutPosition(
|
|
|
|
(node->getLayout().measuredDimensions[dim[mainAxis]] -
|
|
|
|
child->getLayout().measuredDimensions[dim[mainAxis]]) /
|
|
|
|
2.0f,
|
|
|
|
leading[mainAxis]);
|
|
|
|
} else if (
|
|
|
|
!YGNodeIsLeadingPosDefined(child, mainAxis) &&
|
|
|
|
node->getStyle().justifyContent == YGJustifyFlexEnd) {
|
|
|
|
child->setLayoutPosition(
|
|
|
|
(node->getLayout().measuredDimensions[dim[mainAxis]] -
|
|
|
|
child->getLayout().measuredDimensions[dim[mainAxis]]),
|
|
|
|
leading[mainAxis]);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
if (YGNodeIsTrailingPosDefined(child, crossAxis) &&
|
|
|
|
!YGNodeIsLeadingPosDefined(child, crossAxis)) {
|
2017-12-19 11:18:00 -08:00
|
|
|
child->setLayoutPosition(
|
|
|
|
node->getLayout().measuredDimensions[dim[crossAxis]] -
|
|
|
|
child->getLayout().measuredDimensions[dim[crossAxis]] -
|
|
|
|
YGNodeTrailingBorder(node, crossAxis) -
|
|
|
|
YGNodeTrailingMargin(child, crossAxis, width) -
|
|
|
|
YGNodeTrailingPosition(
|
|
|
|
child, crossAxis, isMainAxisRow ? height : width),
|
|
|
|
leading[crossAxis]);
|
|
|
|
|
2017-01-26 13:36:39 -08:00
|
|
|
} else if (!YGNodeIsLeadingPosDefined(child, crossAxis) &&
|
|
|
|
YGNodeAlignItem(node, child) == YGAlignCenter) {
|
2017-12-19 11:18:00 -08:00
|
|
|
child->setLayoutPosition(
|
|
|
|
(node->getLayout().measuredDimensions[dim[crossAxis]] -
|
|
|
|
child->getLayout().measuredDimensions[dim[crossAxis]]) /
|
|
|
|
2.0f,
|
|
|
|
leading[crossAxis]);
|
|
|
|
} else if (
|
|
|
|
!YGNodeIsLeadingPosDefined(child, crossAxis) &&
|
|
|
|
((YGNodeAlignItem(node, child) == YGAlignFlexEnd) ^
|
|
|
|
(node->getStyle().flexWrap == YGWrapWrapReverse))) {
|
|
|
|
child->setLayoutPosition(
|
|
|
|
(node->getLayout().measuredDimensions[dim[crossAxis]] -
|
|
|
|
child->getLayout().measuredDimensions[dim[crossAxis]]),
|
|
|
|
leading[crossAxis]);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
static void YGNodeWithMeasureFuncSetMeasuredDimensions(const YGNodeRef node,
|
|
|
|
const float availableWidth,
|
|
|
|
const float availableHeight,
|
|
|
|
const YGMeasureMode widthMeasureMode,
|
2017-02-11 05:26:55 -08:00
|
|
|
const YGMeasureMode heightMeasureMode,
|
|
|
|
const float parentWidth,
|
|
|
|
const float parentHeight) {
|
2017-11-21 10:10:30 -08:00
|
|
|
YGAssertWithNode(
|
|
|
|
node,
|
2017-12-19 11:18:00 -08:00
|
|
|
node->getMeasure() != nullptr,
|
2017-11-21 10:10:30 -08:00
|
|
|
"Expected node to have custom measure function");
|
2016-11-21 11:03:53 -08:00
|
|
|
|
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
|
|
|
const float paddingAndBorderAxisRow =
|
|
|
|
YGNodePaddingAndBorderForAxis(node, YGFlexDirectionRow, availableWidth);
|
2016-12-03 04:40:18 -08:00
|
|
|
const float paddingAndBorderAxisColumn =
|
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
|
|
|
YGNodePaddingAndBorderForAxis(node, YGFlexDirectionColumn, availableWidth);
|
|
|
|
const float marginAxisRow = YGNodeMarginForAxis(node, YGFlexDirectionRow, availableWidth);
|
|
|
|
const float marginAxisColumn = YGNodeMarginForAxis(node, YGFlexDirectionColumn, availableWidth);
|
2016-11-21 11:03:53 -08:00
|
|
|
|
2017-05-23 11:11:37 -07:00
|
|
|
// We want to make sure we don't call measure with negative size
|
|
|
|
const float innerWidth = YGFloatIsUndefined(availableWidth)
|
2017-08-21 03:09:09 -07:00
|
|
|
? availableWidth
|
|
|
|
: fmaxf(0, availableWidth - marginAxisRow - paddingAndBorderAxisRow);
|
|
|
|
const float innerHeight =
|
|
|
|
YGFloatIsUndefined(availableHeight)
|
|
|
|
? availableHeight
|
|
|
|
: fmaxf(0, availableHeight - marginAxisColumn - paddingAndBorderAxisColumn);
|
2016-11-21 11:03:53 -08:00
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
if (widthMeasureMode == YGMeasureModeExactly && heightMeasureMode == YGMeasureModeExactly) {
|
2016-11-21 11:03:53 -08:00
|
|
|
// Don't bother sizing the text if both dimensions are already defined.
|
2017-12-19 11:18:00 -08:00
|
|
|
node->setLayoutMeasuredDimension(
|
|
|
|
YGNodeBoundAxis(
|
|
|
|
node,
|
|
|
|
YGFlexDirectionRow,
|
|
|
|
availableWidth - marginAxisRow,
|
|
|
|
parentWidth,
|
|
|
|
parentWidth),
|
|
|
|
YGDimensionWidth);
|
|
|
|
node->setLayoutMeasuredDimension(
|
|
|
|
YGNodeBoundAxis(
|
|
|
|
node,
|
|
|
|
YGFlexDirectionColumn,
|
|
|
|
availableHeight - marginAxisColumn,
|
|
|
|
parentHeight,
|
|
|
|
parentWidth),
|
|
|
|
YGDimensionHeight);
|
2016-11-21 11:03:53 -08:00
|
|
|
} else {
|
|
|
|
// Measure the text under the current constraints.
|
2017-12-19 11:18:00 -08:00
|
|
|
const YGSize measuredSize = node->getMeasure()(
|
|
|
|
node, innerWidth, widthMeasureMode, innerHeight, heightMeasureMode);
|
|
|
|
|
|
|
|
node->setLayoutMeasuredDimension(
|
|
|
|
YGNodeBoundAxis(
|
|
|
|
node,
|
|
|
|
YGFlexDirectionRow,
|
|
|
|
(widthMeasureMode == YGMeasureModeUndefined ||
|
|
|
|
widthMeasureMode == YGMeasureModeAtMost)
|
|
|
|
? measuredSize.width + paddingAndBorderAxisRow
|
|
|
|
: availableWidth - marginAxisRow,
|
|
|
|
parentWidth,
|
|
|
|
parentWidth),
|
|
|
|
YGDimensionWidth);
|
|
|
|
|
|
|
|
node->setLayoutMeasuredDimension(
|
|
|
|
YGNodeBoundAxis(
|
|
|
|
node,
|
|
|
|
YGFlexDirectionColumn,
|
|
|
|
(heightMeasureMode == YGMeasureModeUndefined ||
|
|
|
|
heightMeasureMode == YGMeasureModeAtMost)
|
|
|
|
? measuredSize.height + paddingAndBorderAxisColumn
|
|
|
|
: availableHeight - marginAxisColumn,
|
|
|
|
parentHeight,
|
|
|
|
parentWidth),
|
|
|
|
YGDimensionHeight);
|
2016-11-21 11:03:53 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-21 11:03:56 -08:00
|
|
|
// For nodes with no children, use the available values if they were provided,
|
|
|
|
// or the minimum size as indicated by the padding and border sizes.
|
2016-12-03 04:40:18 -08:00
|
|
|
static void YGNodeEmptyContainerSetMeasuredDimensions(const YGNodeRef node,
|
|
|
|
const float availableWidth,
|
|
|
|
const float availableHeight,
|
|
|
|
const YGMeasureMode widthMeasureMode,
|
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
|
|
|
const YGMeasureMode heightMeasureMode,
|
|
|
|
const float parentWidth,
|
|
|
|
const float parentHeight) {
|
|
|
|
const float paddingAndBorderAxisRow =
|
|
|
|
YGNodePaddingAndBorderForAxis(node, YGFlexDirectionRow, parentWidth);
|
2016-12-03 04:40:18 -08:00
|
|
|
const float paddingAndBorderAxisColumn =
|
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
|
|
|
YGNodePaddingAndBorderForAxis(node, YGFlexDirectionColumn, parentWidth);
|
|
|
|
const float marginAxisRow = YGNodeMarginForAxis(node, YGFlexDirectionRow, parentWidth);
|
|
|
|
const float marginAxisColumn = YGNodeMarginForAxis(node, YGFlexDirectionColumn, parentWidth);
|
2016-12-02 05:47:43 -08:00
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
node->setLayoutMeasuredDimension(
|
|
|
|
YGNodeBoundAxis(
|
|
|
|
node,
|
|
|
|
YGFlexDirectionRow,
|
|
|
|
(widthMeasureMode == YGMeasureModeUndefined ||
|
|
|
|
widthMeasureMode == YGMeasureModeAtMost)
|
|
|
|
? paddingAndBorderAxisRow
|
|
|
|
: availableWidth - marginAxisRow,
|
|
|
|
parentWidth,
|
|
|
|
parentWidth),
|
|
|
|
YGDimensionWidth);
|
|
|
|
|
|
|
|
node->setLayoutMeasuredDimension(
|
|
|
|
YGNodeBoundAxis(
|
|
|
|
node,
|
|
|
|
YGFlexDirectionColumn,
|
|
|
|
(heightMeasureMode == YGMeasureModeUndefined ||
|
|
|
|
heightMeasureMode == YGMeasureModeAtMost)
|
|
|
|
? paddingAndBorderAxisColumn
|
|
|
|
: availableHeight - marginAxisColumn,
|
|
|
|
parentHeight,
|
|
|
|
parentWidth),
|
|
|
|
YGDimensionHeight);
|
2016-12-03 04:40:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool YGNodeFixedSizeSetMeasuredDimensions(const YGNodeRef node,
|
|
|
|
const float availableWidth,
|
|
|
|
const float availableHeight,
|
|
|
|
const YGMeasureMode widthMeasureMode,
|
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
|
|
|
const YGMeasureMode heightMeasureMode,
|
|
|
|
const float parentWidth,
|
|
|
|
const float parentHeight) {
|
|
|
|
if ((widthMeasureMode == YGMeasureModeAtMost && availableWidth <= 0.0f) ||
|
|
|
|
(heightMeasureMode == YGMeasureModeAtMost && availableHeight <= 0.0f) ||
|
2016-12-02 05:47:43 -08:00
|
|
|
(widthMeasureMode == YGMeasureModeExactly && heightMeasureMode == YGMeasureModeExactly)) {
|
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
|
|
|
const float marginAxisColumn = YGNodeMarginForAxis(node, YGFlexDirectionColumn, parentWidth);
|
|
|
|
const float marginAxisRow = YGNodeMarginForAxis(node, YGFlexDirectionRow, parentWidth);
|
2016-12-02 05:47:43 -08:00
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
node->setLayoutMeasuredDimension(
|
|
|
|
YGNodeBoundAxis(
|
|
|
|
node,
|
|
|
|
YGFlexDirectionRow,
|
|
|
|
YGFloatIsUndefined(availableWidth) ||
|
|
|
|
(widthMeasureMode == YGMeasureModeAtMost &&
|
|
|
|
availableWidth < 0.0f)
|
|
|
|
? 0.0f
|
|
|
|
: availableWidth - marginAxisRow,
|
|
|
|
parentWidth,
|
|
|
|
parentWidth),
|
|
|
|
YGDimensionWidth);
|
|
|
|
|
|
|
|
node->setLayoutMeasuredDimension(
|
|
|
|
YGNodeBoundAxis(
|
|
|
|
node,
|
|
|
|
YGFlexDirectionColumn,
|
|
|
|
YGFloatIsUndefined(availableHeight) ||
|
|
|
|
(heightMeasureMode == YGMeasureModeAtMost &&
|
|
|
|
availableHeight < 0.0f)
|
|
|
|
? 0.0f
|
|
|
|
: availableHeight - marginAxisColumn,
|
|
|
|
parentHeight,
|
|
|
|
parentWidth),
|
|
|
|
YGDimensionHeight);
|
2016-11-21 11:03:57 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-02-06 09:31:22 -08:00
|
|
|
static void YGZeroOutLayoutRecursivly(const YGNodeRef node) {
|
2017-12-22 06:43:32 -08:00
|
|
|
memset(&(node->getLayout()), 0, sizeof(YGLayout));
|
2017-12-19 11:18:00 -08:00
|
|
|
node->setHasNewLayout(true);
|
2018-01-08 02:48:32 -08:00
|
|
|
node->cloneChildrenIfNeeded();
|
2017-02-15 13:35:24 -08:00
|
|
|
const uint32_t childCount = YGNodeGetChildCount(node);
|
|
|
|
for (uint32_t i = 0; i < childCount; i++) {
|
2017-12-19 11:18:00 -08:00
|
|
|
const YGNodeRef child = node->getChild(i);
|
2017-02-06 09:31:22 -08:00
|
|
|
YGZeroOutLayoutRecursivly(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-11 10:50:09 -08:00
|
|
|
//
|
|
|
|
// This is the main routine that implements a subset of the flexbox layout
|
|
|
|
// algorithm
|
2016-12-03 04:40:18 -08:00
|
|
|
// described in the W3C YG documentation: https://www.w3.org/TR/YG3-flexbox/.
|
2016-11-11 10:50:09 -08:00
|
|
|
//
|
|
|
|
// Limitations of this algorithm, compared to the full standard:
|
|
|
|
// * Display property is always assumed to be 'flex' except for Text nodes,
|
|
|
|
// which
|
|
|
|
// are assumed to be 'inline-flex'.
|
|
|
|
// * The 'zIndex' property (or any form of z ordering) is not supported. Nodes
|
|
|
|
// are
|
|
|
|
// stacked in document order.
|
|
|
|
// * The 'order' property is not supported. The order of flex items is always
|
|
|
|
// defined
|
|
|
|
// by document order.
|
|
|
|
// * The 'visibility' property is always assumed to be 'visible'. Values of
|
|
|
|
// 'collapse'
|
|
|
|
// and 'hidden' are not supported.
|
|
|
|
// * There is no support for forced breaks.
|
|
|
|
// * It does not support vertical inline directions (top-to-bottom or
|
|
|
|
// bottom-to-top text).
|
|
|
|
//
|
|
|
|
// Deviations from standard:
|
|
|
|
// * Section 4.5 of the spec indicates that all flex items have a default
|
|
|
|
// minimum
|
|
|
|
// main size. For text blocks, for example, this is the width of the widest
|
|
|
|
// word.
|
|
|
|
// Calculating the minimum width is expensive, so we forego it and assume a
|
|
|
|
// default
|
|
|
|
// minimum main size of 0.
|
|
|
|
// * Min/Max sizes in the main axis are not honored when resolving flexible
|
|
|
|
// lengths.
|
|
|
|
// * The spec indicates that the default value for 'flexDirection' is 'row',
|
|
|
|
// but
|
|
|
|
// the algorithm below assumes a default of 'column'.
|
|
|
|
//
|
|
|
|
// Input parameters:
|
|
|
|
// - node: current node to be sized and layed out
|
|
|
|
// - availableWidth & availableHeight: available size to be used for sizing
|
|
|
|
// the node
|
2016-12-02 05:47:43 -08:00
|
|
|
// or YGUndefined if the size is not available; interpretation depends on
|
2016-11-11 10:50:09 -08:00
|
|
|
// layout
|
|
|
|
// flags
|
|
|
|
// - parentDirection: the inline (text) direction within the parent
|
|
|
|
// (left-to-right or
|
|
|
|
// right-to-left)
|
|
|
|
// - widthMeasureMode: indicates the sizing rules for the width (see below
|
|
|
|
// for explanation)
|
|
|
|
// - heightMeasureMode: indicates the sizing rules for the height (see below
|
|
|
|
// for explanation)
|
|
|
|
// - performLayout: specifies whether the caller is interested in just the
|
|
|
|
// dimensions
|
|
|
|
// of the node or it requires the entire node and its subtree to be layed
|
|
|
|
// out
|
|
|
|
// (with final positions)
|
|
|
|
//
|
|
|
|
// Details:
|
|
|
|
// This routine is called recursively to lay out subtrees of flexbox
|
|
|
|
// elements. It uses the
|
|
|
|
// information in node.style, which is treated as a read-only input. It is
|
|
|
|
// responsible for
|
|
|
|
// setting the layout.direction and layout.measuredDimensions fields for the
|
|
|
|
// input node as well
|
|
|
|
// as the layout.position and layout.lineIndex fields for its child nodes.
|
|
|
|
// The
|
|
|
|
// layout.measuredDimensions field includes any border or padding for the
|
|
|
|
// node but does
|
|
|
|
// not include margins.
|
|
|
|
//
|
|
|
|
// The spec describes four different layout modes: "fill available", "max
|
|
|
|
// content", "min
|
|
|
|
// content",
|
|
|
|
// and "fit content". Of these, we don't use "min content" because we don't
|
|
|
|
// support default
|
|
|
|
// minimum main sizes (see above for details). Each of our measure modes maps
|
|
|
|
// to a layout mode
|
2016-12-03 04:40:18 -08:00
|
|
|
// from the spec (https://www.w3.org/TR/YG3-sizing/#terms):
|
2016-12-02 05:47:43 -08:00
|
|
|
// - YGMeasureModeUndefined: max content
|
|
|
|
// - YGMeasureModeExactly: fill available
|
|
|
|
// - YGMeasureModeAtMost: fit content
|
2016-11-11 10:50:09 -08:00
|
|
|
//
|
2016-12-03 04:40:18 -08:00
|
|
|
// When calling YGNodelayoutImpl and YGLayoutNodeInternal, if the caller passes
|
2016-11-11 10:50:09 -08:00
|
|
|
// an available size of
|
2016-12-02 05:47:43 -08:00
|
|
|
// undefined then it must also pass a measure mode of YGMeasureModeUndefined
|
2016-11-11 10:50:09 -08:00
|
|
|
// in that dimension.
|
|
|
|
//
|
2016-12-03 04:40:18 -08:00
|
|
|
static void YGNodelayoutImpl(const YGNodeRef node,
|
|
|
|
const float availableWidth,
|
|
|
|
const float availableHeight,
|
|
|
|
const YGDirection parentDirection,
|
|
|
|
const YGMeasureMode widthMeasureMode,
|
|
|
|
const YGMeasureMode heightMeasureMode,
|
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
|
|
|
const float parentWidth,
|
|
|
|
const float parentHeight,
|
2017-03-01 09:19:55 -08:00
|
|
|
const bool performLayout,
|
|
|
|
const YGConfigRef config) {
|
2017-05-03 09:22:35 -07:00
|
|
|
YGAssertWithNode(node,
|
2017-05-12 09:03:22 -07:00
|
|
|
YGFloatIsUndefined(availableWidth) ? widthMeasureMode == YGMeasureModeUndefined
|
|
|
|
: true,
|
|
|
|
"availableWidth is indefinite so widthMeasureMode must be "
|
|
|
|
"YGMeasureModeUndefined");
|
2017-05-03 09:22:35 -07:00
|
|
|
YGAssertWithNode(node,
|
2017-05-12 09:03:22 -07:00
|
|
|
YGFloatIsUndefined(availableHeight) ? heightMeasureMode == YGMeasureModeUndefined
|
|
|
|
: true,
|
|
|
|
"availableHeight is indefinite so heightMeasureMode must be "
|
|
|
|
"YGMeasureModeUndefined");
|
2016-11-11 10:50:09 -08:00
|
|
|
|
|
|
|
// Set the resolved resolution in the node's layout.
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGDirection direction = YGNodeResolveDirection(node, parentDirection);
|
2017-12-19 11:18:00 -08:00
|
|
|
node->setLayoutDirection(direction);
|
2016-11-11 10:50:09 -08:00
|
|
|
|
2017-03-10 06:05:53 -08:00
|
|
|
const YGFlexDirection flexRowDirection = YGResolveFlexDirection(YGFlexDirectionRow, direction);
|
2017-01-26 13:36:39 -08:00
|
|
|
const YGFlexDirection flexColumnDirection =
|
2017-03-10 06:05:53 -08:00
|
|
|
YGResolveFlexDirection(YGFlexDirectionColumn, direction);
|
2017-01-26 13:36:39 -08:00
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
node->setLayoutMargin(
|
|
|
|
YGNodeLeadingMargin(node, flexRowDirection, parentWidth), YGEdgeStart);
|
|
|
|
node->setLayoutMargin(
|
|
|
|
YGNodeTrailingMargin(node, flexRowDirection, parentWidth), YGEdgeEnd);
|
|
|
|
node->setLayoutMargin(
|
|
|
|
YGNodeLeadingMargin(node, flexColumnDirection, parentWidth), YGEdgeTop);
|
|
|
|
node->setLayoutMargin(
|
|
|
|
YGNodeTrailingMargin(node, flexColumnDirection, parentWidth),
|
|
|
|
YGEdgeBottom);
|
|
|
|
|
|
|
|
node->setLayoutBorder(
|
|
|
|
YGNodeLeadingBorder(node, flexRowDirection), YGEdgeStart);
|
|
|
|
node->setLayoutBorder(
|
|
|
|
YGNodeTrailingBorder(node, flexRowDirection), YGEdgeEnd);
|
|
|
|
node->setLayoutBorder(
|
|
|
|
YGNodeLeadingBorder(node, flexColumnDirection), YGEdgeTop);
|
|
|
|
node->setLayoutBorder(
|
|
|
|
YGNodeTrailingBorder(node, flexColumnDirection), YGEdgeBottom);
|
|
|
|
|
|
|
|
node->setLayoutPadding(
|
|
|
|
YGNodeLeadingPadding(node, flexRowDirection, parentWidth), YGEdgeStart);
|
|
|
|
node->setLayoutPadding(
|
|
|
|
YGNodeTrailingPadding(node, flexRowDirection, parentWidth), YGEdgeEnd);
|
|
|
|
node->setLayoutPadding(
|
|
|
|
YGNodeLeadingPadding(node, flexColumnDirection, parentWidth), YGEdgeTop);
|
|
|
|
node->setLayoutPadding(
|
|
|
|
YGNodeTrailingPadding(node, flexColumnDirection, parentWidth),
|
|
|
|
YGEdgeBottom);
|
|
|
|
|
|
|
|
if (node->getMeasure() != nullptr) {
|
2017-02-11 05:26:55 -08:00
|
|
|
YGNodeWithMeasureFuncSetMeasuredDimensions(node,
|
|
|
|
availableWidth,
|
|
|
|
availableHeight,
|
|
|
|
widthMeasureMode,
|
|
|
|
heightMeasureMode,
|
|
|
|
parentWidth,
|
|
|
|
parentHeight);
|
2016-11-11 10:50:09 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
const uint32_t childCount = node->getChildren().size();
|
2016-11-11 10:50:09 -08:00
|
|
|
if (childCount == 0) {
|
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
|
|
|
YGNodeEmptyContainerSetMeasuredDimensions(node,
|
|
|
|
availableWidth,
|
|
|
|
availableHeight,
|
|
|
|
widthMeasureMode,
|
|
|
|
heightMeasureMode,
|
|
|
|
parentWidth,
|
|
|
|
parentHeight);
|
2016-11-11 10:50:09 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-21 11:03:57 -08:00
|
|
|
// If we're not being asked to perform a full layout we can skip the algorithm if we already know
|
|
|
|
// the size
|
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
|
|
|
if (!performLayout && YGNodeFixedSizeSetMeasuredDimensions(node,
|
|
|
|
availableWidth,
|
|
|
|
availableHeight,
|
|
|
|
widthMeasureMode,
|
|
|
|
heightMeasureMode,
|
|
|
|
parentWidth,
|
|
|
|
parentHeight)) {
|
2016-11-21 11:03:57 -08:00
|
|
|
return;
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
Persistent Yoga
Summary:
This is meant to show a possible route format for a persistent form of Yoga. Where previous layouts can remain intact while still taking advantage of incremental layout by reusing previous subtrees.
```c
YGNodeRef YGNodeClone(const YGNodeRef node);
```
The core of this functionality is a new API to clone an existing node. This makes a new detached node with all the same values as the previous one. Conceptually this makes the original node "frozen" from that point on. It's now immutable. (This is not yet enforced at runtime in this PR but something we should add.)
Since the original is frozen, we reuse the children set from the original node. Their parent pointers still point back to the original tree though.
The cloned node is still mutable. It can have its styles updated, and nodes can be inserted or deleted. If an insertion/deletion happens on a cloned node whose children were reused, it'll first shallow clone its children automatically.
As a convenience I also added an API to clear all children:
```c
void YGNodeRemoveAllChildren(const YGNodeRef node);
```
During insert/delete, or as a result of layout a set of reused children may need to be first cloned. A kind of copy-on-write. When that happens, the host may want to respond. E.g. by updating the `context` such as by cloning any wrapper objects and attaching them to the new node.
```c
typedef void (*YGNodeClonedFunc)(YGNodeRef oldNode,
YGNodeRef newNode,
YGNodeRef parent,
int childIndex);
void YGConfigSetNodeClonedFunc(YGConfigRef config,
YGNodeClonedFunc callback);
```
This PR doesn't change any existing semantics for trees that are not first cloned.
It's possible for a single node to exist in two trees at once and be used by multiple threads. Therefore it's not safe to recursively free a whole tree when you use persistence. To solve this, any user of the library has to manually manage ref counting or tracing GC. E.g. by replicating the tree structure in a wrapper.
In a follow up we could consider moving ref counting into Yoga.
Closes https://github.com/facebook/yoga/pull/636
Reviewed By: emilsjolander
Differential Revision: D5941921
Pulled By: sebmarkbage
fbshipit-source-id: c8e93421824c112d09c4773bed4e3141b6491ccf
2017-10-17 01:02:04 -07:00
|
|
|
// At this point we know we're going to perform work. Ensure that each child has a mutable copy.
|
2018-01-08 02:48:32 -08:00
|
|
|
node->cloneChildrenIfNeeded();
|
2017-07-10 11:49:21 -07:00
|
|
|
// Reset layout flags, as they could have changed.
|
2017-12-19 11:18:00 -08:00
|
|
|
node->setLayoutHadOverflow(false);
|
2017-07-10 11:49:21 -07:00
|
|
|
|
2016-11-11 10:50:09 -08:00
|
|
|
// STEP 1: CALCULATE VALUES FOR REMAINDER OF ALGORITHM
|
2017-12-19 11:18:00 -08:00
|
|
|
const YGFlexDirection mainAxis =
|
|
|
|
YGResolveFlexDirection(node->getStyle().flexDirection, direction);
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGFlexDirection crossAxis = YGFlexDirectionCross(mainAxis, direction);
|
|
|
|
const bool isMainAxisRow = YGFlexDirectionIsRow(mainAxis);
|
2017-12-19 11:18:00 -08:00
|
|
|
const YGJustify justifyContent = node->getStyle().justifyContent;
|
|
|
|
const bool isNodeFlexWrap = node->getStyle().flexWrap != YGWrapNoWrap;
|
2016-11-11 10:50:09 -08:00
|
|
|
|
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
|
|
|
const float mainAxisParentSize = isMainAxisRow ? parentWidth : parentHeight;
|
|
|
|
const float crossAxisParentSize = isMainAxisRow ? parentHeight : parentWidth;
|
|
|
|
|
2017-11-21 10:10:30 -08:00
|
|
|
YGNodeRef firstAbsoluteChild = nullptr;
|
|
|
|
YGNodeRef currentAbsoluteChild = nullptr;
|
2016-11-11 10:50:09 -08:00
|
|
|
|
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
|
|
|
const float leadingPaddingAndBorderMain =
|
|
|
|
YGNodeLeadingPaddingAndBorder(node, mainAxis, parentWidth);
|
|
|
|
const float trailingPaddingAndBorderMain =
|
|
|
|
YGNodeTrailingPaddingAndBorder(node, mainAxis, parentWidth);
|
|
|
|
const float leadingPaddingAndBorderCross =
|
|
|
|
YGNodeLeadingPaddingAndBorder(node, crossAxis, parentWidth);
|
|
|
|
const float paddingAndBorderAxisMain = YGNodePaddingAndBorderForAxis(node, mainAxis, parentWidth);
|
|
|
|
const float paddingAndBorderAxisCross =
|
|
|
|
YGNodePaddingAndBorderForAxis(node, crossAxis, parentWidth);
|
2016-11-11 10:50:09 -08:00
|
|
|
|
2017-02-20 07:16:58 -08:00
|
|
|
YGMeasureMode measureModeMainDim = isMainAxisRow ? widthMeasureMode : heightMeasureMode;
|
|
|
|
YGMeasureMode measureModeCrossDim = isMainAxisRow ? heightMeasureMode : widthMeasureMode;
|
2016-11-11 10:50:09 -08:00
|
|
|
|
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
|
|
|
const float paddingAndBorderAxisRow =
|
|
|
|
isMainAxisRow ? paddingAndBorderAxisMain : paddingAndBorderAxisCross;
|
|
|
|
const float paddingAndBorderAxisColumn =
|
|
|
|
isMainAxisRow ? paddingAndBorderAxisCross : paddingAndBorderAxisMain;
|
2016-12-23 10:15:50 -08:00
|
|
|
|
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
|
|
|
const float marginAxisRow = YGNodeMarginForAxis(node, YGFlexDirectionRow, parentWidth);
|
|
|
|
const float marginAxisColumn = YGNodeMarginForAxis(node, YGFlexDirectionColumn, parentWidth);
|
2016-11-21 11:03:57 -08:00
|
|
|
|
2016-11-11 10:50:09 -08:00
|
|
|
// STEP 2: DETERMINE AVAILABLE SIZE IN MAIN AND CROSS DIRECTIONS
|
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
|
|
|
const float minInnerWidth =
|
2017-12-19 11:18:00 -08:00
|
|
|
YGResolveValue(
|
|
|
|
node->getStyle().minDimensions[YGDimensionWidth], parentWidth) -
|
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
|
|
|
paddingAndBorderAxisRow;
|
|
|
|
const float maxInnerWidth =
|
2017-12-19 11:18:00 -08:00
|
|
|
YGResolveValue(
|
|
|
|
node->getStyle().maxDimensions[YGDimensionWidth], parentWidth) -
|
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
|
|
|
paddingAndBorderAxisRow;
|
|
|
|
const float minInnerHeight =
|
2017-12-19 11:18:00 -08:00
|
|
|
YGResolveValue(
|
|
|
|
node->getStyle().minDimensions[YGDimensionHeight], parentHeight) -
|
2017-11-24 07:06:16 -08:00
|
|
|
paddingAndBorderAxisColumn;
|
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
|
|
|
const float maxInnerHeight =
|
2017-12-19 11:18:00 -08:00
|
|
|
YGResolveValue(
|
|
|
|
node->getStyle().maxDimensions[YGDimensionHeight], parentHeight) -
|
2017-11-24 07:06:16 -08:00
|
|
|
paddingAndBorderAxisColumn;
|
2016-12-21 11:37:32 -08:00
|
|
|
const float minInnerMainDim = isMainAxisRow ? minInnerWidth : minInnerHeight;
|
|
|
|
const float maxInnerMainDim = isMainAxisRow ? maxInnerWidth : maxInnerHeight;
|
2016-12-23 10:15:50 -08:00
|
|
|
|
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
|
|
|
// Max dimension overrides predefined dimension value; Min dimension in turn overrides both of the
|
|
|
|
// above
|
|
|
|
float availableInnerWidth = availableWidth - marginAxisRow - paddingAndBorderAxisRow;
|
|
|
|
if (!YGFloatIsUndefined(availableInnerWidth)) {
|
2017-02-28 16:27:18 -08:00
|
|
|
// We want to make sure our available width does not violate min and max constraints
|
2016-12-21 11:37:32 -08:00
|
|
|
availableInnerWidth = fmaxf(fminf(availableInnerWidth, maxInnerWidth), minInnerWidth);
|
|
|
|
}
|
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
|
|
|
|
|
|
|
float availableInnerHeight = availableHeight - marginAxisColumn - paddingAndBorderAxisColumn;
|
|
|
|
if (!YGFloatIsUndefined(availableInnerHeight)) {
|
2017-02-28 16:27:18 -08:00
|
|
|
// We want to make sure our available height does not violate min and max constraints
|
2016-12-21 11:37:32 -08:00
|
|
|
availableInnerHeight = fmaxf(fminf(availableInnerHeight, maxInnerHeight), minInnerHeight);
|
|
|
|
}
|
2016-12-23 10:15:50 -08:00
|
|
|
|
2016-12-21 11:37:32 -08:00
|
|
|
float availableInnerMainDim = isMainAxisRow ? availableInnerWidth : availableInnerHeight;
|
2016-11-11 10:50:09 -08:00
|
|
|
const float availableInnerCrossDim = isMainAxisRow ? availableInnerHeight : availableInnerWidth;
|
|
|
|
|
|
|
|
// If there is only one child with flexGrow + flexShrink it means we can set the
|
|
|
|
// computedFlexBasis to 0 instead of measuring and shrinking / flexing the child to exactly
|
|
|
|
// match the remaining space
|
2017-11-21 10:10:30 -08:00
|
|
|
YGNodeRef singleFlexChild = nullptr;
|
2017-02-20 07:16:58 -08:00
|
|
|
if (measureModeMainDim == YGMeasureModeExactly) {
|
2016-11-11 10:50:09 -08:00
|
|
|
for (uint32_t i = 0; i < childCount; i++) {
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGNodeRef child = YGNodeGetChild(node, i);
|
2016-11-11 10:50:09 -08:00
|
|
|
if (singleFlexChild) {
|
2016-12-03 04:40:18 -08:00
|
|
|
if (YGNodeIsFlex(child)) {
|
2016-11-11 10:50:09 -08:00
|
|
|
// There is already a flexible child, abort.
|
2017-11-21 10:10:30 -08:00
|
|
|
singleFlexChild = nullptr;
|
2016-11-11 10:50:09 -08:00
|
|
|
break;
|
|
|
|
}
|
2018-01-08 02:48:37 -08:00
|
|
|
} else if (
|
|
|
|
child->resolveFlexGrow() > 0.0f &&
|
2018-01-08 02:48:39 -08:00
|
|
|
child->resolveFlexShrink() > 0.0f) {
|
2016-11-11 10:50:09 -08:00
|
|
|
singleFlexChild = child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-12 09:03:23 -07:00
|
|
|
float totalOuterFlexBasis = 0;
|
2017-02-14 09:16:59 -08:00
|
|
|
|
2016-11-11 10:50:09 -08:00
|
|
|
// STEP 3: DETERMINE FLEX BASIS FOR EACH ITEM
|
|
|
|
for (uint32_t i = 0; i < childCount; i++) {
|
2017-12-19 11:18:00 -08:00
|
|
|
const YGNodeRef child = node->getChild(i);
|
|
|
|
if (child->getStyle().display == YGDisplayNone) {
|
2017-02-06 09:31:22 -08:00
|
|
|
YGZeroOutLayoutRecursivly(child);
|
2017-12-19 11:18:00 -08:00
|
|
|
child->setHasNewLayout(true);
|
|
|
|
child->setDirty(false);
|
2017-02-06 09:31:22 -08:00
|
|
|
continue;
|
|
|
|
}
|
2017-12-19 11:18:00 -08:00
|
|
|
child->resolveDimension();
|
2016-11-11 10:50:09 -08:00
|
|
|
if (performLayout) {
|
|
|
|
// Set the initial position (relative to the parent).
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGDirection childDirection = YGNodeResolveDirection(child, direction);
|
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
|
|
|
YGNodeSetPosition(child,
|
|
|
|
childDirection,
|
|
|
|
availableInnerMainDim,
|
|
|
|
availableInnerCrossDim,
|
|
|
|
availableInnerWidth);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Absolute-positioned children don't participate in flex layout. Add them
|
|
|
|
// to a list that we can process later.
|
2017-12-19 11:18:00 -08:00
|
|
|
if (child->getStyle().positionType == YGPositionTypeAbsolute) {
|
2016-11-11 10:50:09 -08:00
|
|
|
// Store a private linked list of absolutely positioned children
|
|
|
|
// so that we can efficiently traverse them later.
|
2017-11-21 10:10:30 -08:00
|
|
|
if (firstAbsoluteChild == nullptr) {
|
2016-11-11 10:50:09 -08:00
|
|
|
firstAbsoluteChild = child;
|
|
|
|
}
|
2017-11-21 10:10:30 -08:00
|
|
|
if (currentAbsoluteChild != nullptr) {
|
2017-12-19 11:18:00 -08:00
|
|
|
currentAbsoluteChild->setNextChild(child);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
currentAbsoluteChild = child;
|
2017-12-19 11:18:00 -08:00
|
|
|
child->setNextChild(nullptr);
|
2016-11-11 10:50:09 -08:00
|
|
|
} else {
|
|
|
|
if (child == singleFlexChild) {
|
2017-12-19 11:18:00 -08:00
|
|
|
child->setLayoutComputedFlexBasisGeneration(gCurrentGenerationCount);
|
|
|
|
child->setLayoutComputedFlexBasis(0);
|
2016-11-11 10:50:09 -08:00
|
|
|
} else {
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeComputeFlexBasisForChild(node,
|
|
|
|
child,
|
|
|
|
availableInnerWidth,
|
|
|
|
widthMeasureMode,
|
|
|
|
availableInnerHeight,
|
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
|
|
|
availableInnerWidth,
|
|
|
|
availableInnerHeight,
|
2016-12-03 04:40:18 -08:00
|
|
|
heightMeasureMode,
|
2017-03-01 09:19:55 -08:00
|
|
|
direction,
|
|
|
|
config);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
}
|
2017-02-14 09:16:59 -08:00
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
totalOuterFlexBasis += child->getLayout().computedFlexBasis +
|
|
|
|
YGNodeMarginForAxis(child, mainAxis, availableInnerWidth);
|
2017-05-12 09:03:23 -07:00
|
|
|
;
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-05-12 09:03:23 -07:00
|
|
|
const bool flexBasisOverflows = measureModeMainDim == YGMeasureModeUndefined
|
|
|
|
? false
|
|
|
|
: totalOuterFlexBasis > availableInnerMainDim;
|
2017-02-20 07:16:58 -08:00
|
|
|
if (isNodeFlexWrap && flexBasisOverflows && measureModeMainDim == YGMeasureModeAtMost) {
|
|
|
|
measureModeMainDim = YGMeasureModeExactly;
|
|
|
|
}
|
2017-02-14 09:16:59 -08:00
|
|
|
|
2016-11-11 10:50:09 -08:00
|
|
|
// STEP 4: COLLECT FLEX ITEMS INTO FLEX LINES
|
|
|
|
|
|
|
|
// Indexes of children that represent the first and last items in the line.
|
|
|
|
uint32_t startOfLineIndex = 0;
|
|
|
|
uint32_t endOfLineIndex = 0;
|
|
|
|
|
|
|
|
// Number of lines.
|
|
|
|
uint32_t lineCount = 0;
|
|
|
|
|
|
|
|
// Accumulated cross dimensions of all lines so far.
|
|
|
|
float totalLineCrossDim = 0;
|
|
|
|
|
|
|
|
// Max main dimension of all the lines.
|
|
|
|
float maxLineMainDim = 0;
|
|
|
|
|
|
|
|
for (; endOfLineIndex < childCount; lineCount++, startOfLineIndex = endOfLineIndex) {
|
|
|
|
// Number of items on the currently line. May be different than the
|
|
|
|
// difference
|
|
|
|
// between start and end indicates because we skip over absolute-positioned
|
|
|
|
// items.
|
|
|
|
uint32_t itemsOnLine = 0;
|
|
|
|
|
|
|
|
// sizeConsumedOnCurrentLine is accumulation of the dimensions and margin
|
|
|
|
// of all the children on the current line. This will be used in order to
|
|
|
|
// either set the dimensions of the node if none already exist or to compute
|
|
|
|
// the remaining space left for the flexible children.
|
|
|
|
float sizeConsumedOnCurrentLine = 0;
|
2017-04-11 13:00:03 -07:00
|
|
|
float sizeConsumedOnCurrentLineIncludingMinConstraint = 0;
|
2016-11-11 10:50:09 -08:00
|
|
|
|
|
|
|
float totalFlexGrowFactors = 0;
|
|
|
|
float totalFlexShrinkScaledFactors = 0;
|
|
|
|
|
|
|
|
// Maintain a linked list of the child nodes that can shrink and/or grow.
|
2017-11-21 10:10:30 -08:00
|
|
|
YGNodeRef firstRelativeChild = nullptr;
|
|
|
|
YGNodeRef currentRelativeChild = nullptr;
|
2016-11-11 10:50:09 -08:00
|
|
|
|
|
|
|
// Add items to the current line until it's full or we run out of items.
|
|
|
|
for (uint32_t i = startOfLineIndex; i < childCount; i++, endOfLineIndex++) {
|
2017-12-19 11:18:00 -08:00
|
|
|
const YGNodeRef child = node->getChild(i);
|
|
|
|
if (child->getStyle().display == YGDisplayNone) {
|
2017-02-06 09:31:22 -08:00
|
|
|
continue;
|
|
|
|
}
|
2017-12-19 11:18:00 -08:00
|
|
|
child->setLineIndex(lineCount);
|
2016-11-11 10:50:09 -08:00
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
if (child->getStyle().positionType != YGPositionTypeAbsolute) {
|
2017-04-11 13:00:03 -07:00
|
|
|
const float childMarginMainAxis = YGNodeMarginForAxis(child, mainAxis, availableInnerWidth);
|
2017-12-19 11:18:00 -08:00
|
|
|
const float flexBasisWithMaxConstraints = fminf(
|
|
|
|
YGResolveValue(
|
|
|
|
child->getStyle().maxDimensions[dim[mainAxis]],
|
|
|
|
mainAxisParentSize),
|
|
|
|
child->getLayout().computedFlexBasis);
|
|
|
|
const float flexBasisWithMinAndMaxConstraints = fmaxf(
|
|
|
|
YGResolveValue(
|
|
|
|
child->getStyle().minDimensions[dim[mainAxis]],
|
|
|
|
mainAxisParentSize),
|
|
|
|
flexBasisWithMaxConstraints);
|
2016-11-11 10:50:09 -08:00
|
|
|
|
|
|
|
// If this is a multi-line flow and this item pushes us over the
|
|
|
|
// available size, we've
|
|
|
|
// hit the end of the current line. Break out of the loop and lay out
|
|
|
|
// the current line.
|
2017-04-26 11:31:06 -07:00
|
|
|
if (sizeConsumedOnCurrentLineIncludingMinConstraint + flexBasisWithMinAndMaxConstraints +
|
|
|
|
childMarginMainAxis >
|
2017-04-11 13:00:03 -07:00
|
|
|
availableInnerMainDim &&
|
|
|
|
isNodeFlexWrap && itemsOnLine > 0) {
|
2016-11-11 10:50:09 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-04-26 11:31:06 -07:00
|
|
|
sizeConsumedOnCurrentLineIncludingMinConstraint +=
|
|
|
|
flexBasisWithMinAndMaxConstraints + childMarginMainAxis;
|
2017-05-29 07:50:46 -07:00
|
|
|
sizeConsumedOnCurrentLine += flexBasisWithMinAndMaxConstraints + childMarginMainAxis;
|
2016-11-11 10:50:09 -08:00
|
|
|
itemsOnLine++;
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
if (YGNodeIsFlex(child)) {
|
2018-01-08 02:48:37 -08:00
|
|
|
totalFlexGrowFactors += child->resolveFlexGrow();
|
2016-11-11 10:50:09 -08:00
|
|
|
|
2017-05-29 07:50:46 -07:00
|
|
|
// Unlike the grow factor, the shrink factor is scaled relative to the child dimension.
|
2018-01-08 02:48:39 -08:00
|
|
|
totalFlexShrinkScaledFactors += -child->resolveFlexShrink() *
|
2017-12-19 11:18:00 -08:00
|
|
|
child->getLayout().computedFlexBasis;
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Store a private linked list of children that need to be layed out.
|
2017-11-21 10:10:30 -08:00
|
|
|
if (firstRelativeChild == nullptr) {
|
2016-11-11 10:50:09 -08:00
|
|
|
firstRelativeChild = child;
|
|
|
|
}
|
2017-11-21 10:10:30 -08:00
|
|
|
if (currentRelativeChild != nullptr) {
|
2017-12-19 11:18:00 -08:00
|
|
|
currentRelativeChild->setNextChild(child);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
currentRelativeChild = child;
|
2017-12-19 11:18:00 -08:00
|
|
|
child->setNextChild(nullptr);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-16 07:31:19 -07:00
|
|
|
// The total flex factor needs to be floored to 1.
|
|
|
|
if (totalFlexGrowFactors > 0 && totalFlexGrowFactors < 1) {
|
|
|
|
totalFlexGrowFactors = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The total flex shrink factor needs to be floored to 1.
|
|
|
|
if (totalFlexShrinkScaledFactors > 0 && totalFlexShrinkScaledFactors < 1) {
|
|
|
|
totalFlexShrinkScaledFactors = 1;
|
|
|
|
}
|
|
|
|
|
2016-11-11 10:50:09 -08:00
|
|
|
// If we don't need to measure the cross axis, we can skip the entire flex
|
|
|
|
// step.
|
2016-12-02 05:47:43 -08:00
|
|
|
const bool canSkipFlex = !performLayout && measureModeCrossDim == YGMeasureModeExactly;
|
2016-11-11 10:50:09 -08:00
|
|
|
|
|
|
|
// In order to position the elements in the main axis, we have two
|
|
|
|
// controls. The space between the beginning and the first element
|
|
|
|
// and the space between each two elements.
|
|
|
|
float leadingMainDim = 0;
|
|
|
|
float betweenMainDim = 0;
|
|
|
|
|
|
|
|
// STEP 5: RESOLVING FLEXIBLE LENGTHS ON MAIN AXIS
|
|
|
|
// Calculate the remaining available space that needs to be allocated.
|
|
|
|
// If the main dimension size isn't known, it is computed based on
|
|
|
|
// the line length, so there's no more space left to distribute.
|
2016-12-23 10:15:50 -08:00
|
|
|
|
2017-11-27 03:09:47 -08:00
|
|
|
bool sizeBasedOnContent = false;
|
2017-02-28 16:27:18 -08:00
|
|
|
// If we don't measure with exact main dimension we want to ensure we don't violate min and max
|
|
|
|
if (measureModeMainDim != YGMeasureModeExactly) {
|
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
|
|
|
if (!YGFloatIsUndefined(minInnerMainDim) && sizeConsumedOnCurrentLine < minInnerMainDim) {
|
2016-12-21 11:37:32 -08:00
|
|
|
availableInnerMainDim = minInnerMainDim;
|
2017-05-03 09:22:35 -07:00
|
|
|
} else if (!YGFloatIsUndefined(maxInnerMainDim) &&
|
|
|
|
sizeConsumedOnCurrentLine > maxInnerMainDim) {
|
2016-12-21 11:37:32 -08:00
|
|
|
availableInnerMainDim = maxInnerMainDim;
|
2017-04-28 06:13:51 -07:00
|
|
|
} else {
|
2017-12-19 11:18:00 -08:00
|
|
|
if (!node->getConfig()->useLegacyStretchBehaviour &&
|
2018-01-08 02:48:37 -08:00
|
|
|
(totalFlexGrowFactors == 0 || node->resolveFlexGrow() == 0)) {
|
2017-04-28 06:13:51 -07:00
|
|
|
// If we don't have any children to flex or we can't flex the node itself,
|
2017-05-17 07:21:52 -07:00
|
|
|
// space we've used is all space we need. Root node also should be shrunk to minimum
|
2017-04-28 06:13:51 -07:00
|
|
|
availableInnerMainDim = sizeConsumedOnCurrentLine;
|
|
|
|
}
|
2017-12-19 11:18:00 -08:00
|
|
|
sizeBasedOnContent = !node->getConfig()->useLegacyStretchBehaviour;
|
2016-12-21 11:37:32 -08:00
|
|
|
}
|
|
|
|
}
|
2016-12-23 10:15:50 -08:00
|
|
|
|
2016-11-11 10:50:09 -08:00
|
|
|
float remainingFreeSpace = 0;
|
2017-11-27 03:09:47 -08:00
|
|
|
if (!sizeBasedOnContent && !YGFloatIsUndefined(availableInnerMainDim)) {
|
2016-11-11 10:50:09 -08:00
|
|
|
remainingFreeSpace = availableInnerMainDim - sizeConsumedOnCurrentLine;
|
|
|
|
} else if (sizeConsumedOnCurrentLine < 0) {
|
2017-05-03 09:22:35 -07:00
|
|
|
// availableInnerMainDim is indefinite which means the node is being sized based on its
|
|
|
|
// content.
|
2017-05-01 04:31:55 -07:00
|
|
|
// sizeConsumedOnCurrentLine is negative which means the node will allocate 0 points for
|
|
|
|
// its content. Consequently, remainingFreeSpace is 0 - sizeConsumedOnCurrentLine.
|
2016-11-11 10:50:09 -08:00
|
|
|
remainingFreeSpace = -sizeConsumedOnCurrentLine;
|
|
|
|
}
|
|
|
|
|
|
|
|
const float originalRemainingFreeSpace = remainingFreeSpace;
|
|
|
|
float deltaFreeSpace = 0;
|
|
|
|
|
|
|
|
if (!canSkipFlex) {
|
|
|
|
float childFlexBasis;
|
|
|
|
float flexShrinkScaledFactor;
|
|
|
|
float flexGrowFactor;
|
|
|
|
float baseMainSize;
|
|
|
|
float boundMainSize;
|
|
|
|
|
|
|
|
// Do two passes over the flex items to figure out how to distribute the
|
|
|
|
// remaining space.
|
|
|
|
// The first pass finds the items whose min/max constraints trigger,
|
|
|
|
// freezes them at those
|
|
|
|
// sizes, and excludes those sizes from the remaining space. The second
|
|
|
|
// pass sets the size
|
|
|
|
// of each flexible item. It distributes the remaining space amongst the
|
|
|
|
// items whose min/max
|
|
|
|
// constraints didn't trigger in pass 1. For the other items, it sets
|
|
|
|
// their sizes by forcing
|
|
|
|
// their min/max constraints to trigger again.
|
|
|
|
//
|
|
|
|
// This two pass approach for resolving min/max constraints deviates from
|
|
|
|
// the spec. The
|
2016-12-03 04:40:18 -08:00
|
|
|
// spec (https://www.w3.org/TR/YG-flexbox-1/#resolve-flexible-lengths)
|
2016-11-11 10:50:09 -08:00
|
|
|
// describes a process
|
|
|
|
// that needs to be repeated a variable number of times. The algorithm
|
|
|
|
// implemented here
|
|
|
|
// won't handle all cases but it was simpler to implement and it mitigates
|
|
|
|
// performance
|
|
|
|
// concerns because we know exactly how many passes it'll do.
|
|
|
|
|
|
|
|
// First pass: detect the flex items whose min/max constraints trigger
|
|
|
|
float deltaFlexShrinkScaledFactors = 0;
|
|
|
|
float deltaFlexGrowFactors = 0;
|
|
|
|
currentRelativeChild = firstRelativeChild;
|
2017-11-21 10:10:30 -08:00
|
|
|
while (currentRelativeChild != nullptr) {
|
2017-12-19 11:18:00 -08:00
|
|
|
childFlexBasis = fminf(
|
|
|
|
YGResolveValue(
|
|
|
|
currentRelativeChild->getStyle().maxDimensions[dim[mainAxis]],
|
|
|
|
mainAxisParentSize),
|
|
|
|
fmaxf(
|
|
|
|
YGResolveValue(
|
|
|
|
currentRelativeChild->getStyle()
|
|
|
|
.minDimensions[dim[mainAxis]],
|
|
|
|
mainAxisParentSize),
|
|
|
|
currentRelativeChild->getLayout().computedFlexBasis));
|
2016-11-11 10:50:09 -08:00
|
|
|
|
|
|
|
if (remainingFreeSpace < 0) {
|
2018-01-08 02:48:39 -08:00
|
|
|
flexShrinkScaledFactor =
|
|
|
|
-currentRelativeChild->resolveFlexShrink() * childFlexBasis;
|
2016-11-11 10:50:09 -08:00
|
|
|
|
|
|
|
// Is this child able to shrink?
|
|
|
|
if (flexShrinkScaledFactor != 0) {
|
|
|
|
baseMainSize =
|
|
|
|
childFlexBasis +
|
|
|
|
remainingFreeSpace / totalFlexShrinkScaledFactors * flexShrinkScaledFactor;
|
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
|
|
|
boundMainSize = YGNodeBoundAxis(currentRelativeChild,
|
|
|
|
mainAxis,
|
|
|
|
baseMainSize,
|
|
|
|
availableInnerMainDim,
|
|
|
|
availableInnerWidth);
|
2016-11-11 10:50:09 -08:00
|
|
|
if (baseMainSize != boundMainSize) {
|
|
|
|
// By excluding this item's size and flex factor from remaining,
|
|
|
|
// this item's
|
|
|
|
// min/max constraints should also trigger in the second pass
|
|
|
|
// resulting in the
|
|
|
|
// item's size calculation being identical in the first and second
|
|
|
|
// passes.
|
|
|
|
deltaFreeSpace -= boundMainSize - childFlexBasis;
|
|
|
|
deltaFlexShrinkScaledFactors -= flexShrinkScaledFactor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (remainingFreeSpace > 0) {
|
2018-01-08 02:48:37 -08:00
|
|
|
flexGrowFactor = currentRelativeChild->resolveFlexGrow();
|
2016-11-11 10:50:09 -08:00
|
|
|
|
|
|
|
// Is this child able to grow?
|
|
|
|
if (flexGrowFactor != 0) {
|
|
|
|
baseMainSize =
|
|
|
|
childFlexBasis + remainingFreeSpace / totalFlexGrowFactors * flexGrowFactor;
|
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
|
|
|
boundMainSize = YGNodeBoundAxis(currentRelativeChild,
|
|
|
|
mainAxis,
|
|
|
|
baseMainSize,
|
|
|
|
availableInnerMainDim,
|
|
|
|
availableInnerWidth);
|
2017-05-12 09:03:22 -07:00
|
|
|
|
2016-11-11 10:50:09 -08:00
|
|
|
if (baseMainSize != boundMainSize) {
|
|
|
|
// By excluding this item's size and flex factor from remaining,
|
|
|
|
// this item's
|
|
|
|
// min/max constraints should also trigger in the second pass
|
|
|
|
// resulting in the
|
|
|
|
// item's size calculation being identical in the first and second
|
|
|
|
// passes.
|
|
|
|
deltaFreeSpace -= boundMainSize - childFlexBasis;
|
|
|
|
deltaFlexGrowFactors -= flexGrowFactor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
currentRelativeChild = currentRelativeChild->getNextChild();
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
totalFlexShrinkScaledFactors += deltaFlexShrinkScaledFactors;
|
|
|
|
totalFlexGrowFactors += deltaFlexGrowFactors;
|
|
|
|
remainingFreeSpace += deltaFreeSpace;
|
|
|
|
|
|
|
|
// Second pass: resolve the sizes of the flexible items
|
|
|
|
deltaFreeSpace = 0;
|
|
|
|
currentRelativeChild = firstRelativeChild;
|
2017-11-21 10:10:30 -08:00
|
|
|
while (currentRelativeChild != nullptr) {
|
2017-12-19 11:18:00 -08:00
|
|
|
childFlexBasis = fminf(
|
|
|
|
YGResolveValue(
|
|
|
|
currentRelativeChild->getStyle().maxDimensions[dim[mainAxis]],
|
|
|
|
mainAxisParentSize),
|
|
|
|
fmaxf(
|
|
|
|
YGResolveValue(
|
|
|
|
currentRelativeChild->getStyle()
|
|
|
|
.minDimensions[dim[mainAxis]],
|
|
|
|
mainAxisParentSize),
|
|
|
|
currentRelativeChild->getLayout().computedFlexBasis));
|
2016-11-11 10:50:09 -08:00
|
|
|
float updatedMainSize = childFlexBasis;
|
|
|
|
|
|
|
|
if (remainingFreeSpace < 0) {
|
2018-01-08 02:48:39 -08:00
|
|
|
flexShrinkScaledFactor =
|
|
|
|
-currentRelativeChild->resolveFlexShrink() * childFlexBasis;
|
2016-11-11 10:50:09 -08:00
|
|
|
// Is this child able to shrink?
|
|
|
|
if (flexShrinkScaledFactor != 0) {
|
|
|
|
float childSize;
|
|
|
|
|
|
|
|
if (totalFlexShrinkScaledFactors == 0) {
|
|
|
|
childSize = childFlexBasis + flexShrinkScaledFactor;
|
|
|
|
} else {
|
|
|
|
childSize =
|
|
|
|
childFlexBasis +
|
|
|
|
(remainingFreeSpace / totalFlexShrinkScaledFactors) * flexShrinkScaledFactor;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
updatedMainSize = YGNodeBoundAxis(currentRelativeChild,
|
|
|
|
mainAxis,
|
|
|
|
childSize,
|
|
|
|
availableInnerMainDim,
|
|
|
|
availableInnerWidth);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
} else if (remainingFreeSpace > 0) {
|
2018-01-08 02:48:37 -08:00
|
|
|
flexGrowFactor = currentRelativeChild->resolveFlexGrow();
|
2016-11-11 10:50:09 -08:00
|
|
|
|
|
|
|
// Is this child able to grow?
|
|
|
|
if (flexGrowFactor != 0) {
|
|
|
|
updatedMainSize =
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeBoundAxis(currentRelativeChild,
|
|
|
|
mainAxis,
|
|
|
|
childFlexBasis +
|
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
|
|
|
remainingFreeSpace / totalFlexGrowFactors * flexGrowFactor,
|
|
|
|
availableInnerMainDim,
|
|
|
|
availableInnerWidth);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
deltaFreeSpace -= updatedMainSize - childFlexBasis;
|
|
|
|
|
2017-02-16 07:39:14 -08:00
|
|
|
const float marginMain =
|
|
|
|
YGNodeMarginForAxis(currentRelativeChild, mainAxis, availableInnerWidth);
|
|
|
|
const float marginCross =
|
|
|
|
YGNodeMarginForAxis(currentRelativeChild, crossAxis, availableInnerWidth);
|
|
|
|
|
|
|
|
float childCrossSize;
|
|
|
|
float childMainSize = updatedMainSize + marginMain;
|
|
|
|
YGMeasureMode childCrossMeasureMode;
|
|
|
|
YGMeasureMode childMainMeasureMode = YGMeasureModeExactly;
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
if (!YGFloatIsUndefined(currentRelativeChild->getStyle().aspectRatio)) {
|
|
|
|
childCrossSize = isMainAxisRow ? (childMainSize - marginMain) /
|
|
|
|
currentRelativeChild->getStyle().aspectRatio
|
|
|
|
: (childMainSize - marginMain) *
|
|
|
|
currentRelativeChild->getStyle().aspectRatio;
|
2017-08-21 03:09:09 -07:00
|
|
|
childCrossMeasureMode = YGMeasureModeExactly;
|
|
|
|
|
|
|
|
childCrossSize += marginCross;
|
2017-12-19 11:18:00 -08:00
|
|
|
} else if (
|
|
|
|
!YGFloatIsUndefined(availableInnerCrossDim) &&
|
|
|
|
!YGNodeIsStyleDimDefined(
|
|
|
|
currentRelativeChild, crossAxis, availableInnerCrossDim) &&
|
|
|
|
measureModeCrossDim == YGMeasureModeExactly &&
|
|
|
|
!(isNodeFlexWrap && flexBasisOverflows) &&
|
|
|
|
YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch &&
|
|
|
|
currentRelativeChild->marginLeadingValue(crossAxis).unit !=
|
|
|
|
YGUnitAuto &&
|
|
|
|
currentRelativeChild->marginTrailingValue(crossAxis).unit !=
|
|
|
|
YGUnitAuto) {
|
2017-02-16 07:39:14 -08:00
|
|
|
childCrossSize = availableInnerCrossDim;
|
|
|
|
childCrossMeasureMode = YGMeasureModeExactly;
|
|
|
|
} else if (!YGNodeIsStyleDimDefined(currentRelativeChild,
|
|
|
|
crossAxis,
|
|
|
|
availableInnerCrossDim)) {
|
|
|
|
childCrossSize = availableInnerCrossDim;
|
|
|
|
childCrossMeasureMode =
|
|
|
|
YGFloatIsUndefined(childCrossSize) ? YGMeasureModeUndefined : YGMeasureModeAtMost;
|
2016-11-11 10:50:09 -08:00
|
|
|
} else {
|
2017-12-19 11:18:00 -08:00
|
|
|
childCrossSize =
|
|
|
|
YGResolveValue(
|
|
|
|
currentRelativeChild->getResolvedDimension(dim[crossAxis]),
|
|
|
|
availableInnerCrossDim) +
|
|
|
|
marginCross;
|
2017-02-28 06:57:55 -08:00
|
|
|
const bool isLoosePercentageMeasurement =
|
2017-12-19 11:18:00 -08:00
|
|
|
currentRelativeChild->getResolvedDimension(dim[crossAxis]).unit ==
|
|
|
|
YGUnitPercent &&
|
2017-02-28 06:57:55 -08:00
|
|
|
measureModeCrossDim != YGMeasureModeExactly;
|
2017-12-19 11:18:00 -08:00
|
|
|
childCrossMeasureMode =
|
|
|
|
YGFloatIsUndefined(childCrossSize) || isLoosePercentageMeasurement
|
|
|
|
? YGMeasureModeUndefined
|
|
|
|
: YGMeasureModeExactly;
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
YGConstrainMaxSizeForMode(
|
|
|
|
currentRelativeChild,
|
|
|
|
mainAxis,
|
|
|
|
availableInnerMainDim,
|
|
|
|
availableInnerWidth,
|
|
|
|
&childMainMeasureMode,
|
|
|
|
&childMainSize);
|
|
|
|
YGConstrainMaxSizeForMode(
|
|
|
|
currentRelativeChild,
|
|
|
|
crossAxis,
|
|
|
|
availableInnerCrossDim,
|
|
|
|
availableInnerWidth,
|
|
|
|
&childCrossMeasureMode,
|
|
|
|
&childCrossSize);
|
2016-11-11 10:50:09 -08:00
|
|
|
|
|
|
|
const bool requiresStretchLayout =
|
2017-12-19 11:18:00 -08:00
|
|
|
!YGNodeIsStyleDimDefined(
|
|
|
|
currentRelativeChild, crossAxis, availableInnerCrossDim) &&
|
2017-11-27 05:29:15 -08:00
|
|
|
YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch &&
|
2017-12-19 11:18:00 -08:00
|
|
|
currentRelativeChild->marginLeadingValue(crossAxis).unit !=
|
|
|
|
YGUnitAuto &&
|
|
|
|
currentRelativeChild->marginTrailingValue(crossAxis).unit !=
|
|
|
|
YGUnitAuto;
|
2016-11-11 10:50:09 -08:00
|
|
|
|
2017-02-16 07:39:14 -08:00
|
|
|
const float childWidth = isMainAxisRow ? childMainSize : childCrossSize;
|
|
|
|
const float childHeight = !isMainAxisRow ? childMainSize : childCrossSize;
|
|
|
|
|
|
|
|
const YGMeasureMode childWidthMeasureMode =
|
|
|
|
isMainAxisRow ? childMainMeasureMode : childCrossMeasureMode;
|
|
|
|
const YGMeasureMode childHeightMeasureMode =
|
|
|
|
!isMainAxisRow ? childMainMeasureMode : childCrossMeasureMode;
|
|
|
|
|
2016-11-11 10:50:09 -08:00
|
|
|
// Recursively call the layout algorithm for this child with the updated
|
|
|
|
// main size.
|
2016-12-03 04:40:18 -08:00
|
|
|
YGLayoutNodeInternal(currentRelativeChild,
|
|
|
|
childWidth,
|
|
|
|
childHeight,
|
|
|
|
direction,
|
|
|
|
childWidthMeasureMode,
|
|
|
|
childHeightMeasureMode,
|
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
|
|
|
availableInnerWidth,
|
|
|
|
availableInnerHeight,
|
2016-12-03 04:40:18 -08:00
|
|
|
performLayout && !requiresStretchLayout,
|
2017-03-01 09:19:55 -08:00
|
|
|
"flex",
|
|
|
|
config);
|
2017-12-19 11:18:00 -08:00
|
|
|
node->setLayoutHadOverflow(
|
|
|
|
node->getLayout().hadOverflow |
|
|
|
|
currentRelativeChild->getLayout().hadOverflow);
|
|
|
|
currentRelativeChild = currentRelativeChild->getNextChild();
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
remainingFreeSpace = originalRemainingFreeSpace + deltaFreeSpace;
|
2017-12-19 11:18:00 -08:00
|
|
|
node->setLayoutHadOverflow(
|
|
|
|
node->getLayout().hadOverflow | (remainingFreeSpace < 0));
|
2016-11-11 10:50:09 -08:00
|
|
|
|
|
|
|
// STEP 6: MAIN-AXIS JUSTIFICATION & CROSS-AXIS SIZE DETERMINATION
|
|
|
|
|
|
|
|
// At this point, all the children have their dimensions set in the main
|
|
|
|
// axis.
|
|
|
|
// Their dimensions are also set in the cross axis with the exception of
|
|
|
|
// items
|
|
|
|
// that are aligned "stretch". We need to compute these stretch values and
|
|
|
|
// set the final positions.
|
|
|
|
|
|
|
|
// If we are using "at most" rules in the main axis. Calculate the remaining space when
|
|
|
|
// constraint by the min size defined for the main axis.
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
if (measureModeMainDim == YGMeasureModeAtMost && remainingFreeSpace > 0) {
|
2017-12-19 11:18:00 -08:00
|
|
|
if (node->getStyle().minDimensions[dim[mainAxis]].unit !=
|
|
|
|
YGUnitUndefined &&
|
|
|
|
YGResolveValue(
|
|
|
|
node->getStyle().minDimensions[dim[mainAxis]],
|
|
|
|
mainAxisParentSize) >= 0) {
|
|
|
|
remainingFreeSpace = fmaxf(
|
|
|
|
0,
|
|
|
|
YGResolveValue(
|
|
|
|
node->getStyle().minDimensions[dim[mainAxis]],
|
|
|
|
mainAxisParentSize) -
|
|
|
|
(availableInnerMainDim - remainingFreeSpace));
|
2016-11-11 10:50:09 -08:00
|
|
|
} else {
|
|
|
|
remainingFreeSpace = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-14 14:26:09 -08:00
|
|
|
int numberOfAutoMarginsOnCurrentLine = 0;
|
|
|
|
for (uint32_t i = startOfLineIndex; i < endOfLineIndex; i++) {
|
2017-12-19 11:18:00 -08:00
|
|
|
const YGNodeRef child = node->getChild(i);
|
|
|
|
if (child->getStyle().positionType == YGPositionTypeRelative) {
|
|
|
|
if (child->marginLeadingValue(mainAxis).unit == YGUnitAuto) {
|
2017-02-14 14:26:09 -08:00
|
|
|
numberOfAutoMarginsOnCurrentLine++;
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
2017-12-19 11:18:00 -08:00
|
|
|
if (child->marginTrailingValue(mainAxis).unit == YGUnitAuto) {
|
2017-02-14 14:26:09 -08:00
|
|
|
numberOfAutoMarginsOnCurrentLine++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numberOfAutoMarginsOnCurrentLine == 0) {
|
|
|
|
switch (justifyContent) {
|
|
|
|
case YGJustifyCenter:
|
|
|
|
leadingMainDim = remainingFreeSpace / 2;
|
|
|
|
break;
|
|
|
|
case YGJustifyFlexEnd:
|
|
|
|
leadingMainDim = remainingFreeSpace;
|
|
|
|
break;
|
|
|
|
case YGJustifySpaceBetween:
|
|
|
|
if (itemsOnLine > 1) {
|
|
|
|
betweenMainDim = fmaxf(remainingFreeSpace, 0) / (itemsOnLine - 1);
|
|
|
|
} else {
|
|
|
|
betweenMainDim = 0;
|
|
|
|
}
|
|
|
|
break;
|
2017-11-27 03:40:01 -08:00
|
|
|
case YGJustifySpaceEvenly:
|
|
|
|
// Space is distributed evenly across all elements
|
|
|
|
betweenMainDim = remainingFreeSpace / (itemsOnLine + 1);
|
|
|
|
leadingMainDim = betweenMainDim;
|
|
|
|
break;
|
2017-02-14 14:26:09 -08:00
|
|
|
case YGJustifySpaceAround:
|
|
|
|
// Space on the edges is half of the space between elements
|
|
|
|
betweenMainDim = remainingFreeSpace / itemsOnLine;
|
|
|
|
leadingMainDim = betweenMainDim / 2;
|
|
|
|
break;
|
|
|
|
case YGJustifyFlexStart:
|
|
|
|
break;
|
|
|
|
}
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
float mainDim = leadingPaddingAndBorderMain + leadingMainDim;
|
|
|
|
float crossDim = 0;
|
|
|
|
|
|
|
|
for (uint32_t i = startOfLineIndex; i < endOfLineIndex; i++) {
|
2017-12-19 11:18:00 -08:00
|
|
|
const YGNodeRef child = node->getChild(i);
|
|
|
|
if (child->getStyle().display == YGDisplayNone) {
|
2017-02-06 09:31:22 -08:00
|
|
|
continue;
|
|
|
|
}
|
2017-12-19 11:18:00 -08:00
|
|
|
if (child->getStyle().positionType == YGPositionTypeAbsolute &&
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeIsLeadingPosDefined(child, mainAxis)) {
|
2016-11-11 10:50:09 -08:00
|
|
|
if (performLayout) {
|
|
|
|
// In case the child is position absolute and has left/top being
|
|
|
|
// defined, we override the position to whatever the user said
|
|
|
|
// (and margin/border).
|
2017-12-19 11:18:00 -08:00
|
|
|
child->setLayoutPosition(
|
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
|
|
|
YGNodeLeadingPosition(child, mainAxis, availableInnerMainDim) +
|
2017-12-19 11:18:00 -08:00
|
|
|
YGNodeLeadingBorder(node, mainAxis) +
|
|
|
|
YGNodeLeadingMargin(child, mainAxis, availableInnerWidth),
|
|
|
|
pos[mainAxis]);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Now that we placed the element, we need to update the variables.
|
|
|
|
// We need to do that only for relative elements. Absolute elements
|
|
|
|
// do not take part in that phase.
|
2017-12-19 11:18:00 -08:00
|
|
|
if (child->getStyle().positionType == YGPositionTypeRelative) {
|
|
|
|
if (child->marginLeadingValue(mainAxis).unit == YGUnitAuto) {
|
2017-02-14 14:26:09 -08:00
|
|
|
mainDim += remainingFreeSpace / numberOfAutoMarginsOnCurrentLine;
|
|
|
|
}
|
|
|
|
|
2016-11-11 10:50:09 -08:00
|
|
|
if (performLayout) {
|
2017-12-19 11:18:00 -08:00
|
|
|
child->setLayoutPosition(
|
|
|
|
child->getLayout().position[pos[mainAxis]] + mainDim,
|
|
|
|
pos[mainAxis]);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
if (child->marginTrailingValue(mainAxis).unit == YGUnitAuto) {
|
2017-02-14 14:26:09 -08:00
|
|
|
mainDim += remainingFreeSpace / numberOfAutoMarginsOnCurrentLine;
|
|
|
|
}
|
|
|
|
|
2016-11-11 10:50:09 -08:00
|
|
|
if (canSkipFlex) {
|
|
|
|
// If we skipped the flex step, then we can't rely on the
|
|
|
|
// measuredDims because
|
2016-12-03 04:40:18 -08:00
|
|
|
// they weren't computed. This means we can't call YGNodeDimWithMargin.
|
2017-12-19 11:18:00 -08:00
|
|
|
mainDim += betweenMainDim +
|
|
|
|
YGNodeMarginForAxis(child, mainAxis, availableInnerWidth) +
|
|
|
|
child->getLayout().computedFlexBasis;
|
2016-11-11 10:50:09 -08:00
|
|
|
crossDim = availableInnerCrossDim;
|
|
|
|
} else {
|
2017-02-14 09:16:59 -08:00
|
|
|
// The main dimension is the sum of all the elements dimension plus the spacing.
|
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
|
|
|
mainDim += betweenMainDim + YGNodeDimWithMargin(child, mainAxis, availableInnerWidth);
|
2016-11-11 10:50:09 -08:00
|
|
|
|
2017-02-13 01:05:23 -08:00
|
|
|
// The cross dimension is the max of the elements dimension since
|
2017-02-14 09:16:59 -08:00
|
|
|
// there can only be one element in that cross dimension.
|
2017-02-13 01:05:23 -08:00
|
|
|
crossDim = fmaxf(crossDim, YGNodeDimWithMargin(child, crossAxis, availableInnerWidth));
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
} else if (performLayout) {
|
2017-12-19 11:18:00 -08:00
|
|
|
child->setLayoutPosition(
|
|
|
|
child->getLayout().position[pos[mainAxis]] +
|
|
|
|
YGNodeLeadingBorder(node, mainAxis) + leadingMainDim,
|
|
|
|
pos[mainAxis]);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mainDim += trailingPaddingAndBorderMain;
|
|
|
|
|
|
|
|
float containerCrossAxis = availableInnerCrossDim;
|
2016-12-02 05:47:43 -08:00
|
|
|
if (measureModeCrossDim == YGMeasureModeUndefined ||
|
|
|
|
measureModeCrossDim == YGMeasureModeAtMost) {
|
2016-11-11 10:50:09 -08:00
|
|
|
// Compute the cross axis from the max cross dimension of the children.
|
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
|
|
|
containerCrossAxis = YGNodeBoundAxis(node,
|
|
|
|
crossAxis,
|
|
|
|
crossDim + paddingAndBorderAxisCross,
|
|
|
|
crossAxisParentSize,
|
|
|
|
parentWidth) -
|
2016-11-11 10:50:09 -08:00
|
|
|
paddingAndBorderAxisCross;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there's no flex wrap, the cross dimension is defined by the container.
|
2016-12-02 05:47:43 -08:00
|
|
|
if (!isNodeFlexWrap && measureModeCrossDim == YGMeasureModeExactly) {
|
2016-11-11 10:50:09 -08:00
|
|
|
crossDim = availableInnerCrossDim;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clamp to the min/max size specified on the container.
|
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
|
|
|
crossDim = YGNodeBoundAxis(node,
|
|
|
|
crossAxis,
|
|
|
|
crossDim + paddingAndBorderAxisCross,
|
|
|
|
crossAxisParentSize,
|
|
|
|
parentWidth) -
|
2016-11-11 10:50:09 -08:00
|
|
|
paddingAndBorderAxisCross;
|
|
|
|
|
|
|
|
// STEP 7: CROSS-AXIS ALIGNMENT
|
|
|
|
// We can skip child alignment if we're just measuring the container.
|
|
|
|
if (performLayout) {
|
|
|
|
for (uint32_t i = startOfLineIndex; i < endOfLineIndex; i++) {
|
2017-12-19 11:18:00 -08:00
|
|
|
const YGNodeRef child = node->getChild(i);
|
|
|
|
if (child->getStyle().display == YGDisplayNone) {
|
2017-02-06 09:31:22 -08:00
|
|
|
continue;
|
|
|
|
}
|
2017-12-19 11:18:00 -08:00
|
|
|
if (child->getStyle().positionType == YGPositionTypeAbsolute) {
|
2016-11-11 10:50:09 -08:00
|
|
|
// If the child is absolutely positioned and has a
|
|
|
|
// top/left/bottom/right
|
|
|
|
// set, override all the previously computed positions to set it
|
|
|
|
// correctly.
|
2017-11-01 06:13:23 -07:00
|
|
|
const bool isChildLeadingPosDefined = YGNodeIsLeadingPosDefined(child, crossAxis);
|
|
|
|
if (isChildLeadingPosDefined) {
|
2017-12-19 11:18:00 -08:00
|
|
|
child->setLayoutPosition(
|
|
|
|
YGNodeLeadingPosition(
|
|
|
|
child, crossAxis, availableInnerCrossDim) +
|
|
|
|
YGNodeLeadingBorder(node, crossAxis) +
|
|
|
|
YGNodeLeadingMargin(child, crossAxis, availableInnerWidth),
|
|
|
|
pos[crossAxis]);
|
2017-11-01 06:13:23 -07:00
|
|
|
}
|
|
|
|
// If leading position is not defined or calculations result in Nan, default to border + margin
|
2017-12-19 11:18:00 -08:00
|
|
|
if (!isChildLeadingPosDefined ||
|
|
|
|
YGFloatIsUndefined(child->getLayout().position[pos[crossAxis]])) {
|
|
|
|
child->setLayoutPosition(
|
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
|
|
|
YGNodeLeadingBorder(node, crossAxis) +
|
2017-12-19 11:18:00 -08:00
|
|
|
YGNodeLeadingMargin(child, crossAxis, availableInnerWidth),
|
|
|
|
pos[crossAxis]);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
float leadingCrossDim = leadingPaddingAndBorderCross;
|
|
|
|
|
|
|
|
// For a relative children, we're either using alignItems (parent) or
|
|
|
|
// alignSelf (child) in order to determine the position in the cross
|
|
|
|
// axis
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGAlign alignItem = YGNodeAlignItem(node, child);
|
2016-11-11 10:50:09 -08:00
|
|
|
|
|
|
|
// If the child uses align stretch, we need to lay it out one more
|
|
|
|
// time, this time
|
|
|
|
// forcing the cross-axis size to be the computed cross size for the
|
|
|
|
// current line.
|
2017-02-14 14:26:09 -08:00
|
|
|
if (alignItem == YGAlignStretch &&
|
2017-12-19 11:18:00 -08:00
|
|
|
child->marginLeadingValue(crossAxis).unit != YGUnitAuto &&
|
|
|
|
child->marginTrailingValue(crossAxis).unit != YGUnitAuto) {
|
2016-11-11 10:50:09 -08:00
|
|
|
// If the child defines a definite size for its cross axis, there's
|
|
|
|
// no need to stretch.
|
2017-02-16 07:39:14 -08:00
|
|
|
if (!YGNodeIsStyleDimDefined(child, crossAxis, availableInnerCrossDim)) {
|
2017-12-19 11:18:00 -08:00
|
|
|
float childMainSize =
|
|
|
|
child->getLayout().measuredDimensions[dim[mainAxis]];
|
2017-02-16 07:39:14 -08:00
|
|
|
float childCrossSize =
|
2017-12-19 11:18:00 -08:00
|
|
|
!YGFloatIsUndefined(child->getStyle().aspectRatio)
|
|
|
|
? ((YGNodeMarginForAxis(
|
|
|
|
child, crossAxis, availableInnerWidth) +
|
|
|
|
(isMainAxisRow
|
|
|
|
? childMainSize / child->getStyle().aspectRatio
|
|
|
|
: childMainSize * child->getStyle().aspectRatio)))
|
|
|
|
: crossDim;
|
2017-02-16 07:39:14 -08:00
|
|
|
|
|
|
|
childMainSize += YGNodeMarginForAxis(child, mainAxis, availableInnerWidth);
|
|
|
|
|
|
|
|
YGMeasureMode childMainMeasureMode = YGMeasureModeExactly;
|
|
|
|
YGMeasureMode childCrossMeasureMode = YGMeasureModeExactly;
|
2017-03-09 03:48:33 -08:00
|
|
|
YGConstrainMaxSizeForMode(child,
|
|
|
|
mainAxis,
|
|
|
|
availableInnerMainDim,
|
|
|
|
availableInnerWidth,
|
2017-02-16 07:39:14 -08:00
|
|
|
&childMainMeasureMode,
|
|
|
|
&childMainSize);
|
2017-03-09 03:48:33 -08:00
|
|
|
YGConstrainMaxSizeForMode(child,
|
|
|
|
crossAxis,
|
|
|
|
availableInnerCrossDim,
|
|
|
|
availableInnerWidth,
|
2017-02-16 07:39:14 -08:00
|
|
|
&childCrossMeasureMode,
|
|
|
|
&childCrossSize);
|
|
|
|
|
|
|
|
const float childWidth = isMainAxisRow ? childMainSize : childCrossSize;
|
|
|
|
const float childHeight = !isMainAxisRow ? childMainSize : childCrossSize;
|
|
|
|
|
|
|
|
const YGMeasureMode childWidthMeasureMode =
|
2017-12-19 11:18:00 -08:00
|
|
|
YGFloatIsUndefined(childWidth) ? YGMeasureModeUndefined
|
|
|
|
: YGMeasureModeExactly;
|
2017-02-16 07:39:14 -08:00
|
|
|
const YGMeasureMode childHeightMeasureMode =
|
2017-12-19 11:18:00 -08:00
|
|
|
YGFloatIsUndefined(childHeight) ? YGMeasureModeUndefined
|
|
|
|
: YGMeasureModeExactly;
|
|
|
|
|
|
|
|
YGLayoutNodeInternal(
|
|
|
|
child,
|
|
|
|
childWidth,
|
|
|
|
childHeight,
|
|
|
|
direction,
|
|
|
|
childWidthMeasureMode,
|
|
|
|
childHeightMeasureMode,
|
|
|
|
availableInnerWidth,
|
|
|
|
availableInnerHeight,
|
|
|
|
true,
|
|
|
|
"stretch",
|
|
|
|
config);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
2017-02-14 14:26:09 -08:00
|
|
|
} else {
|
2017-12-19 11:18:00 -08:00
|
|
|
const float remainingCrossDim = containerCrossAxis -
|
|
|
|
YGNodeDimWithMargin(child, crossAxis, availableInnerWidth);
|
2016-11-11 10:50:09 -08:00
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
if (child->marginLeadingValue(crossAxis).unit == YGUnitAuto &&
|
|
|
|
child->marginTrailingValue(crossAxis).unit == YGUnitAuto) {
|
2017-03-15 05:20:38 -07:00
|
|
|
leadingCrossDim += fmaxf(0.0f, remainingCrossDim / 2);
|
2017-12-19 11:18:00 -08:00
|
|
|
} else if (
|
|
|
|
child->marginTrailingValue(crossAxis).unit == YGUnitAuto) {
|
2017-02-14 14:26:09 -08:00
|
|
|
// No-Op
|
2017-12-19 11:18:00 -08:00
|
|
|
} else if (
|
|
|
|
child->marginLeadingValue(crossAxis).unit == YGUnitAuto) {
|
2017-03-15 05:20:38 -07:00
|
|
|
leadingCrossDim += fmaxf(0.0f, remainingCrossDim);
|
2017-02-14 14:26:09 -08:00
|
|
|
} else if (alignItem == YGAlignFlexStart) {
|
|
|
|
// No-Op
|
|
|
|
} else if (alignItem == YGAlignCenter) {
|
|
|
|
leadingCrossDim += remainingCrossDim / 2;
|
|
|
|
} else {
|
2016-11-11 10:50:09 -08:00
|
|
|
leadingCrossDim += remainingCrossDim;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// And we apply the position
|
2017-12-19 11:18:00 -08:00
|
|
|
child->setLayoutPosition(
|
|
|
|
child->getLayout().position[pos[crossAxis]] + totalLineCrossDim +
|
|
|
|
leadingCrossDim,
|
|
|
|
pos[crossAxis]);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
totalLineCrossDim += crossDim;
|
|
|
|
maxLineMainDim = fmaxf(maxLineMainDim, mainDim);
|
|
|
|
}
|
|
|
|
|
|
|
|
// STEP 8: MULTI-LINE CONTENT ALIGNMENT
|
2017-02-23 08:25:16 -08:00
|
|
|
if (performLayout && (lineCount > 1 || YGIsBaselineLayout(node)) &&
|
2017-01-06 06:51:56 -08:00
|
|
|
!YGFloatIsUndefined(availableInnerCrossDim)) {
|
2016-11-11 10:50:09 -08:00
|
|
|
const float remainingAlignContentDim = availableInnerCrossDim - totalLineCrossDim;
|
|
|
|
|
|
|
|
float crossDimLead = 0;
|
|
|
|
float currentLead = leadingPaddingAndBorderCross;
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
switch (node->getStyle().alignContent) {
|
2016-12-02 05:47:43 -08:00
|
|
|
case YGAlignFlexEnd:
|
2016-11-11 10:50:09 -08:00
|
|
|
currentLead += remainingAlignContentDim;
|
|
|
|
break;
|
2016-12-02 05:47:43 -08:00
|
|
|
case YGAlignCenter:
|
2016-11-11 10:50:09 -08:00
|
|
|
currentLead += remainingAlignContentDim / 2;
|
|
|
|
break;
|
2016-12-02 05:47:43 -08:00
|
|
|
case YGAlignStretch:
|
2016-11-11 10:50:09 -08:00
|
|
|
if (availableInnerCrossDim > totalLineCrossDim) {
|
2017-02-11 08:32:48 -08:00
|
|
|
crossDimLead = remainingAlignContentDim / lineCount;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case YGAlignSpaceAround:
|
|
|
|
if (availableInnerCrossDim > totalLineCrossDim) {
|
|
|
|
currentLead += remainingAlignContentDim / (2 * lineCount);
|
|
|
|
if (lineCount > 1) {
|
|
|
|
crossDimLead = remainingAlignContentDim / lineCount;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
currentLead += remainingAlignContentDim / 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case YGAlignSpaceBetween:
|
|
|
|
if (availableInnerCrossDim > totalLineCrossDim && lineCount > 1) {
|
|
|
|
crossDimLead = remainingAlignContentDim / (lineCount - 1);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
break;
|
2016-12-02 05:47:43 -08:00
|
|
|
case YGAlignAuto:
|
|
|
|
case YGAlignFlexStart:
|
2017-01-06 06:51:56 -08:00
|
|
|
case YGAlignBaseline:
|
2016-11-11 10:50:09 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t endIndex = 0;
|
|
|
|
for (uint32_t i = 0; i < lineCount; i++) {
|
2017-02-16 07:39:14 -08:00
|
|
|
const uint32_t startIndex = endIndex;
|
2016-11-11 10:50:09 -08:00
|
|
|
uint32_t ii;
|
|
|
|
|
|
|
|
// compute the line's height and find the endIndex
|
|
|
|
float lineHeight = 0;
|
2017-01-06 06:51:56 -08:00
|
|
|
float maxAscentForCurrentLine = 0;
|
|
|
|
float maxDescentForCurrentLine = 0;
|
2016-11-11 10:50:09 -08:00
|
|
|
for (ii = startIndex; ii < childCount; ii++) {
|
2017-12-19 11:18:00 -08:00
|
|
|
const YGNodeRef child = node->getChild(ii);
|
|
|
|
if (child->getStyle().display == YGDisplayNone) {
|
2017-02-06 09:31:22 -08:00
|
|
|
continue;
|
|
|
|
}
|
2017-12-19 11:18:00 -08:00
|
|
|
if (child->getStyle().positionType == YGPositionTypeRelative) {
|
|
|
|
if (child->getLineIndex() != i) {
|
2016-11-11 10:50:09 -08:00
|
|
|
break;
|
|
|
|
}
|
2016-12-03 04:40:18 -08:00
|
|
|
if (YGNodeIsLayoutDimDefined(child, crossAxis)) {
|
2017-12-19 11:18:00 -08:00
|
|
|
lineHeight = fmaxf(
|
|
|
|
lineHeight,
|
|
|
|
child->getLayout().measuredDimensions[dim[crossAxis]] +
|
|
|
|
YGNodeMarginForAxis(child, crossAxis, availableInnerWidth));
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
2017-01-06 06:51:56 -08:00
|
|
|
if (YGNodeAlignItem(node, child) == YGAlignBaseline) {
|
|
|
|
const float ascent =
|
|
|
|
YGBaseline(child) +
|
|
|
|
YGNodeLeadingMargin(child, YGFlexDirectionColumn, availableInnerWidth);
|
|
|
|
const float descent =
|
2017-12-19 11:18:00 -08:00
|
|
|
child->getLayout().measuredDimensions[YGDimensionHeight] +
|
|
|
|
YGNodeMarginForAxis(
|
|
|
|
child, YGFlexDirectionColumn, availableInnerWidth) -
|
|
|
|
ascent;
|
2017-01-06 06:51:56 -08:00
|
|
|
maxAscentForCurrentLine = fmaxf(maxAscentForCurrentLine, ascent);
|
|
|
|
maxDescentForCurrentLine = fmaxf(maxDescentForCurrentLine, descent);
|
|
|
|
lineHeight = fmaxf(lineHeight, maxAscentForCurrentLine + maxDescentForCurrentLine);
|
|
|
|
}
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
endIndex = ii;
|
|
|
|
lineHeight += crossDimLead;
|
|
|
|
|
|
|
|
if (performLayout) {
|
|
|
|
for (ii = startIndex; ii < endIndex; ii++) {
|
2017-12-19 11:18:00 -08:00
|
|
|
const YGNodeRef child = node->getChild(ii);
|
|
|
|
if (child->getStyle().display == YGDisplayNone) {
|
2017-02-06 09:31:22 -08:00
|
|
|
continue;
|
|
|
|
}
|
2017-12-19 11:18:00 -08:00
|
|
|
if (child->getStyle().positionType == YGPositionTypeRelative) {
|
2016-12-03 04:40:18 -08:00
|
|
|
switch (YGNodeAlignItem(node, child)) {
|
2016-12-02 05:47:43 -08:00
|
|
|
case YGAlignFlexStart: {
|
2017-12-19 11:18:00 -08:00
|
|
|
child->setLayoutPosition(
|
|
|
|
currentLead +
|
|
|
|
YGNodeLeadingMargin(
|
|
|
|
child, crossAxis, availableInnerWidth),
|
|
|
|
pos[crossAxis]);
|
2016-11-11 10:50:09 -08:00
|
|
|
break;
|
|
|
|
}
|
2016-12-02 05:47:43 -08:00
|
|
|
case YGAlignFlexEnd: {
|
2017-12-19 11:18:00 -08:00
|
|
|
child->setLayoutPosition(
|
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
|
|
|
currentLead + lineHeight -
|
2017-12-19 11:18:00 -08:00
|
|
|
YGNodeTrailingMargin(
|
|
|
|
child, crossAxis, availableInnerWidth) -
|
|
|
|
child->getLayout().measuredDimensions[dim[crossAxis]],
|
|
|
|
pos[crossAxis]);
|
2016-11-11 10:50:09 -08:00
|
|
|
break;
|
|
|
|
}
|
2016-12-02 05:47:43 -08:00
|
|
|
case YGAlignCenter: {
|
2017-12-19 11:18:00 -08:00
|
|
|
float childHeight =
|
|
|
|
child->getLayout().measuredDimensions[dim[crossAxis]];
|
|
|
|
|
|
|
|
child->setLayoutPosition(
|
|
|
|
currentLead + (lineHeight - childHeight) / 2,
|
|
|
|
pos[crossAxis]);
|
2016-11-11 10:50:09 -08:00
|
|
|
break;
|
|
|
|
}
|
2016-12-02 05:47:43 -08:00
|
|
|
case YGAlignStretch: {
|
2017-12-19 11:18:00 -08:00
|
|
|
child->setLayoutPosition(
|
|
|
|
currentLead +
|
|
|
|
YGNodeLeadingMargin(
|
|
|
|
child, crossAxis, availableInnerWidth),
|
|
|
|
pos[crossAxis]);
|
2017-02-14 09:16:59 -08:00
|
|
|
|
|
|
|
// Remeasure child with the line height as it as been only measured with the
|
|
|
|
// parents height yet.
|
|
|
|
if (!YGNodeIsStyleDimDefined(child, crossAxis, availableInnerCrossDim)) {
|
2017-12-19 11:18:00 -08:00
|
|
|
const float childWidth = isMainAxisRow
|
|
|
|
? (child->getLayout()
|
|
|
|
.measuredDimensions[YGDimensionWidth] +
|
|
|
|
YGNodeMarginForAxis(
|
|
|
|
child, mainAxis, availableInnerWidth))
|
|
|
|
: lineHeight;
|
|
|
|
|
|
|
|
const float childHeight = !isMainAxisRow
|
|
|
|
? (child->getLayout()
|
|
|
|
.measuredDimensions[YGDimensionHeight] +
|
|
|
|
YGNodeMarginForAxis(
|
|
|
|
child, crossAxis, availableInnerWidth))
|
|
|
|
: lineHeight;
|
|
|
|
|
|
|
|
if (!(YGFloatsEqual(
|
|
|
|
childWidth,
|
|
|
|
child->getLayout()
|
|
|
|
.measuredDimensions[YGDimensionWidth]) &&
|
|
|
|
YGFloatsEqual(
|
|
|
|
childHeight,
|
|
|
|
child->getLayout()
|
|
|
|
.measuredDimensions[YGDimensionHeight]))) {
|
2017-02-14 09:16:59 -08:00
|
|
|
YGLayoutNodeInternal(child,
|
|
|
|
childWidth,
|
|
|
|
childHeight,
|
|
|
|
direction,
|
|
|
|
YGMeasureModeExactly,
|
|
|
|
YGMeasureModeExactly,
|
|
|
|
availableInnerWidth,
|
|
|
|
availableInnerHeight,
|
|
|
|
true,
|
2017-03-03 10:20:24 -08:00
|
|
|
"multiline-stretch",
|
2017-03-01 09:19:55 -08:00
|
|
|
config);
|
2017-02-14 09:16:59 -08:00
|
|
|
}
|
|
|
|
}
|
2016-11-11 10:50:09 -08:00
|
|
|
break;
|
|
|
|
}
|
2017-01-06 06:51:56 -08:00
|
|
|
case YGAlignBaseline: {
|
2017-12-19 11:18:00 -08:00
|
|
|
child->setLayoutPosition(
|
2017-01-06 06:51:56 -08:00
|
|
|
currentLead + maxAscentForCurrentLine - YGBaseline(child) +
|
2017-12-19 11:18:00 -08:00
|
|
|
YGNodeLeadingPosition(
|
|
|
|
child,
|
|
|
|
YGFlexDirectionColumn,
|
|
|
|
availableInnerCrossDim),
|
|
|
|
YGEdgeTop);
|
|
|
|
|
2017-01-06 06:51:56 -08:00
|
|
|
break;
|
|
|
|
}
|
2016-12-02 05:47:43 -08:00
|
|
|
case YGAlignAuto:
|
2017-02-11 08:32:48 -08:00
|
|
|
case YGAlignSpaceBetween:
|
|
|
|
case YGAlignSpaceAround:
|
2016-11-11 10:50:09 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
currentLead += lineHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// STEP 9: COMPUTING FINAL DIMENSIONS
|
2017-12-19 11:18:00 -08:00
|
|
|
|
|
|
|
node->setLayoutMeasuredDimension(
|
|
|
|
YGNodeBoundAxis(
|
|
|
|
node,
|
|
|
|
YGFlexDirectionRow,
|
|
|
|
availableWidth - marginAxisRow,
|
|
|
|
parentWidth,
|
|
|
|
parentWidth),
|
|
|
|
YGDimensionWidth);
|
|
|
|
|
|
|
|
node->setLayoutMeasuredDimension(
|
|
|
|
YGNodeBoundAxis(
|
|
|
|
node,
|
|
|
|
YGFlexDirectionColumn,
|
|
|
|
availableHeight - marginAxisColumn,
|
|
|
|
parentHeight,
|
|
|
|
parentWidth),
|
|
|
|
YGDimensionHeight);
|
2016-11-11 10:50:09 -08:00
|
|
|
|
|
|
|
// If the user didn't specify a width or height for the node, set the
|
|
|
|
// dimensions based on the children.
|
2017-01-16 11:08:46 -08:00
|
|
|
if (measureModeMainDim == YGMeasureModeUndefined ||
|
2017-12-19 11:18:00 -08:00
|
|
|
(node->getStyle().overflow != YGOverflowScroll &&
|
|
|
|
measureModeMainDim == YGMeasureModeAtMost)) {
|
2016-11-11 10:50:09 -08:00
|
|
|
// Clamp the size to the min/max size, if specified, and make sure it
|
|
|
|
// doesn't go below the padding and border amount.
|
2017-12-19 11:18:00 -08:00
|
|
|
node->setLayoutMeasuredDimension(
|
|
|
|
YGNodeBoundAxis(
|
|
|
|
node, mainAxis, maxLineMainDim, mainAxisParentSize, parentWidth),
|
|
|
|
dim[mainAxis]);
|
|
|
|
|
|
|
|
} else if (
|
|
|
|
measureModeMainDim == YGMeasureModeAtMost &&
|
|
|
|
node->getStyle().overflow == YGOverflowScroll) {
|
|
|
|
node->setLayoutMeasuredDimension(
|
|
|
|
fmaxf(
|
|
|
|
fminf(
|
|
|
|
availableInnerMainDim + paddingAndBorderAxisMain,
|
|
|
|
YGNodeBoundAxisWithinMinAndMax(
|
|
|
|
node, mainAxis, maxLineMainDim, mainAxisParentSize)),
|
|
|
|
paddingAndBorderAxisMain),
|
|
|
|
dim[mainAxis]);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-01-16 11:08:46 -08:00
|
|
|
if (measureModeCrossDim == YGMeasureModeUndefined ||
|
2017-12-19 11:18:00 -08:00
|
|
|
(node->getStyle().overflow != YGOverflowScroll &&
|
|
|
|
measureModeCrossDim == YGMeasureModeAtMost)) {
|
2016-11-11 10:50:09 -08:00
|
|
|
// Clamp the size to the min/max size, if specified, and make sure it
|
|
|
|
// doesn't go below the padding and border amount.
|
2017-12-19 11:18:00 -08:00
|
|
|
|
|
|
|
node->setLayoutMeasuredDimension(
|
|
|
|
YGNodeBoundAxis(
|
|
|
|
node,
|
|
|
|
crossAxis,
|
|
|
|
totalLineCrossDim + paddingAndBorderAxisCross,
|
|
|
|
crossAxisParentSize,
|
|
|
|
parentWidth),
|
|
|
|
dim[crossAxis]);
|
|
|
|
|
|
|
|
} else if (
|
|
|
|
measureModeCrossDim == YGMeasureModeAtMost &&
|
|
|
|
node->getStyle().overflow == YGOverflowScroll) {
|
|
|
|
node->setLayoutMeasuredDimension(
|
|
|
|
fmaxf(
|
|
|
|
fminf(
|
|
|
|
availableInnerCrossDim + paddingAndBorderAxisCross,
|
|
|
|
YGNodeBoundAxisWithinMinAndMax(
|
|
|
|
node,
|
|
|
|
crossAxis,
|
|
|
|
totalLineCrossDim + paddingAndBorderAxisCross,
|
|
|
|
crossAxisParentSize)),
|
|
|
|
paddingAndBorderAxisCross),
|
|
|
|
dim[crossAxis]);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-02-15 13:35:24 -08:00
|
|
|
// As we only wrapped in normal direction yet, we need to reverse the positions on wrap-reverse.
|
2017-12-19 11:18:00 -08:00
|
|
|
if (performLayout && node->getStyle().flexWrap == YGWrapWrapReverse) {
|
2017-02-15 13:35:24 -08:00
|
|
|
for (uint32_t i = 0; i < childCount; i++) {
|
|
|
|
const YGNodeRef child = YGNodeGetChild(node, i);
|
2017-12-19 11:18:00 -08:00
|
|
|
if (child->getStyle().positionType == YGPositionTypeRelative) {
|
|
|
|
child->setLayoutPosition(
|
|
|
|
node->getLayout().measuredDimensions[dim[crossAxis]] -
|
|
|
|
child->getLayout().position[pos[crossAxis]] -
|
|
|
|
child->getLayout().measuredDimensions[dim[crossAxis]],
|
|
|
|
pos[crossAxis]);
|
2017-02-15 13:35:24 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-11 10:50:09 -08:00
|
|
|
if (performLayout) {
|
|
|
|
// STEP 10: SIZING AND POSITIONING ABSOLUTE CHILDREN
|
2017-11-21 10:10:30 -08:00
|
|
|
for (currentAbsoluteChild = firstAbsoluteChild;
|
|
|
|
currentAbsoluteChild != nullptr;
|
2017-12-19 11:18:00 -08:00
|
|
|
currentAbsoluteChild = currentAbsoluteChild->getNextChild()) {
|
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
|
|
|
YGNodeAbsoluteLayoutChild(node,
|
|
|
|
currentAbsoluteChild,
|
|
|
|
availableInnerWidth,
|
2017-02-20 07:16:58 -08:00
|
|
|
isMainAxisRow ? measureModeMainDim : measureModeCrossDim,
|
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
|
|
|
availableInnerHeight,
|
2017-03-01 09:19:55 -08:00
|
|
|
direction,
|
|
|
|
config);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// STEP 11: SETTING TRAILING POSITIONS FOR CHILDREN
|
|
|
|
const bool needsMainTrailingPos =
|
2016-12-02 05:47:43 -08:00
|
|
|
mainAxis == YGFlexDirectionRowReverse || mainAxis == YGFlexDirectionColumnReverse;
|
2016-11-11 10:50:09 -08:00
|
|
|
const bool needsCrossTrailingPos =
|
2016-12-05 09:35:26 -08:00
|
|
|
crossAxis == YGFlexDirectionRowReverse || crossAxis == YGFlexDirectionColumnReverse;
|
2016-11-11 10:50:09 -08:00
|
|
|
|
|
|
|
// Set trailing position if necessary.
|
|
|
|
if (needsMainTrailingPos || needsCrossTrailingPos) {
|
|
|
|
for (uint32_t i = 0; i < childCount; i++) {
|
2017-12-19 11:18:00 -08:00
|
|
|
const YGNodeRef child = node->getChild(i);
|
|
|
|
if (child->getStyle().display == YGDisplayNone) {
|
2017-02-06 09:31:22 -08:00
|
|
|
continue;
|
|
|
|
}
|
2016-11-11 10:50:09 -08:00
|
|
|
if (needsMainTrailingPos) {
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeSetChildTrailingPosition(node, child, mainAxis);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (needsCrossTrailingPos) {
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeSetChildTrailingPosition(node, child, crossAxis);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t gDepth = 0;
|
|
|
|
bool gPrintTree = false;
|
|
|
|
bool gPrintChanges = false;
|
|
|
|
bool gPrintSkips = false;
|
|
|
|
|
|
|
|
static const char *spacer = " ";
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
static const char *YGSpacer(const unsigned long level) {
|
2016-11-17 20:41:44 -08:00
|
|
|
const size_t spacerLen = strlen(spacer);
|
2016-11-11 10:50:09 -08:00
|
|
|
if (level > spacerLen) {
|
|
|
|
return &spacer[0];
|
|
|
|
} else {
|
|
|
|
return &spacer[spacerLen - level];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
static const char *YGMeasureModeName(const YGMeasureMode mode, const bool performLayout) {
|
2016-12-02 05:47:43 -08:00
|
|
|
const char *kMeasureModeNames[YGMeasureModeCount] = {"UNDEFINED", "EXACTLY", "AT_MOST"};
|
|
|
|
const char *kLayoutModeNames[YGMeasureModeCount] = {"LAY_UNDEFINED",
|
|
|
|
"LAY_EXACTLY",
|
|
|
|
"LAY_AT_"
|
|
|
|
"MOST"};
|
2016-11-11 10:50:09 -08:00
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
if (mode >= YGMeasureModeCount) {
|
2016-11-11 10:50:09 -08:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
return performLayout ? kLayoutModeNames[mode] : kMeasureModeNames[mode];
|
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
static inline bool YGMeasureModeSizeIsExactAndMatchesOldMeasuredSize(YGMeasureMode sizeMode,
|
|
|
|
float size,
|
|
|
|
float lastComputedSize) {
|
|
|
|
return sizeMode == YGMeasureModeExactly && YGFloatsEqual(size, lastComputedSize);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
static inline bool YGMeasureModeOldSizeIsUnspecifiedAndStillFits(YGMeasureMode sizeMode,
|
|
|
|
float size,
|
|
|
|
YGMeasureMode lastSizeMode,
|
|
|
|
float lastComputedSize) {
|
2016-12-02 05:47:43 -08:00
|
|
|
return sizeMode == YGMeasureModeAtMost && lastSizeMode == YGMeasureModeUndefined &&
|
2017-01-26 13:36:35 -08:00
|
|
|
(size >= lastComputedSize || YGFloatsEqual(size, lastComputedSize));
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
static inline bool YGMeasureModeNewMeasureSizeIsStricterAndStillValid(YGMeasureMode sizeMode,
|
|
|
|
float size,
|
|
|
|
YGMeasureMode lastSizeMode,
|
|
|
|
float lastSize,
|
|
|
|
float lastComputedSize) {
|
2016-12-02 05:47:43 -08:00
|
|
|
return lastSizeMode == YGMeasureModeAtMost && sizeMode == YGMeasureModeAtMost &&
|
2017-01-26 13:36:35 -08:00
|
|
|
lastSize > size && (lastComputedSize <= size || YGFloatsEqual(size, lastComputedSize));
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-07-26 19:22:03 -07:00
|
|
|
float YGRoundValueToPixelGrid(const float value,
|
2017-08-21 03:09:09 -07:00
|
|
|
const float pointScaleFactor,
|
|
|
|
const bool forceCeil,
|
|
|
|
const bool forceFloor) {
|
2017-05-26 10:56:33 -07:00
|
|
|
float scaledValue = value * pointScaleFactor;
|
|
|
|
float fractial = fmodf(scaledValue, 1.0);
|
2017-05-15 06:18:24 -07:00
|
|
|
if (YGFloatsEqual(fractial, 0)) {
|
2017-07-26 19:22:03 -07:00
|
|
|
// First we check if the value is already rounded
|
2017-05-26 10:56:33 -07:00
|
|
|
scaledValue = scaledValue - fractial;
|
2017-07-26 19:22:03 -07:00
|
|
|
} else if (YGFloatsEqual(fractial, 1.0)) {
|
|
|
|
scaledValue = scaledValue - fractial + 1.0;
|
2017-05-26 10:56:33 -07:00
|
|
|
} else if (forceCeil) {
|
2017-07-26 19:22:03 -07:00
|
|
|
// Next we check if we need to use forced rounding
|
2017-08-23 02:40:04 -07:00
|
|
|
scaledValue = scaledValue - fractial + 1.0f;
|
2017-05-15 06:18:24 -07:00
|
|
|
} else if (forceFloor) {
|
2017-05-26 10:56:33 -07:00
|
|
|
scaledValue = scaledValue - fractial;
|
2017-05-15 06:18:24 -07:00
|
|
|
} else {
|
2017-07-26 19:22:03 -07:00
|
|
|
// Finally we just round the value
|
2017-11-21 10:10:30 -08:00
|
|
|
scaledValue = scaledValue - fractial +
|
|
|
|
(fractial > 0.5f || YGFloatsEqual(fractial, 0.5f) ? 1.0f : 0.0f);
|
2017-05-15 06:18:24 -07:00
|
|
|
}
|
2017-05-26 10:56:33 -07:00
|
|
|
return scaledValue / pointScaleFactor;
|
2017-05-15 06:18:24 -07:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
bool YGNodeCanUseCachedMeasurement(const YGMeasureMode widthMode,
|
|
|
|
const float width,
|
|
|
|
const YGMeasureMode heightMode,
|
|
|
|
const float height,
|
|
|
|
const YGMeasureMode lastWidthMode,
|
|
|
|
const float lastWidth,
|
|
|
|
const YGMeasureMode lastHeightMode,
|
|
|
|
const float lastHeight,
|
|
|
|
const float lastComputedWidth,
|
|
|
|
const float lastComputedHeight,
|
|
|
|
const float marginRow,
|
2017-05-15 06:18:24 -07:00
|
|
|
const float marginColumn,
|
|
|
|
const YGConfigRef config) {
|
2016-11-11 10:50:09 -08:00
|
|
|
if (lastComputedHeight < 0 || lastComputedWidth < 0) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-11-21 10:10:30 -08:00
|
|
|
bool useRoundedComparison =
|
|
|
|
config != nullptr && config->pointScaleFactor != 0;
|
2017-08-21 03:09:09 -07:00
|
|
|
const float effectiveWidth =
|
|
|
|
useRoundedComparison ? YGRoundValueToPixelGrid(width, config->pointScaleFactor, false, false)
|
|
|
|
: width;
|
|
|
|
const float effectiveHeight =
|
|
|
|
useRoundedComparison ? YGRoundValueToPixelGrid(height, config->pointScaleFactor, false, false)
|
|
|
|
: height;
|
|
|
|
const float effectiveLastWidth =
|
|
|
|
useRoundedComparison
|
|
|
|
? YGRoundValueToPixelGrid(lastWidth, config->pointScaleFactor, false, false)
|
|
|
|
: lastWidth;
|
|
|
|
const float effectiveLastHeight =
|
|
|
|
useRoundedComparison
|
|
|
|
? YGRoundValueToPixelGrid(lastHeight, config->pointScaleFactor, false, false)
|
|
|
|
: lastHeight;
|
|
|
|
|
|
|
|
const bool hasSameWidthSpec =
|
|
|
|
lastWidthMode == widthMode && YGFloatsEqual(effectiveLastWidth, effectiveWidth);
|
|
|
|
const bool hasSameHeightSpec =
|
|
|
|
lastHeightMode == heightMode && YGFloatsEqual(effectiveLastHeight, effectiveHeight);
|
2016-11-11 10:50:09 -08:00
|
|
|
|
|
|
|
const bool widthIsCompatible =
|
2016-12-03 04:40:18 -08:00
|
|
|
hasSameWidthSpec || YGMeasureModeSizeIsExactAndMatchesOldMeasuredSize(widthMode,
|
|
|
|
width - marginRow,
|
|
|
|
lastComputedWidth) ||
|
|
|
|
YGMeasureModeOldSizeIsUnspecifiedAndStillFits(widthMode,
|
|
|
|
width - marginRow,
|
|
|
|
lastWidthMode,
|
|
|
|
lastComputedWidth) ||
|
|
|
|
YGMeasureModeNewMeasureSizeIsStricterAndStillValid(
|
2016-11-11 10:50:09 -08:00
|
|
|
widthMode, width - marginRow, lastWidthMode, lastWidth, lastComputedWidth);
|
|
|
|
|
|
|
|
const bool heightIsCompatible =
|
2016-12-03 04:40:18 -08:00
|
|
|
hasSameHeightSpec || YGMeasureModeSizeIsExactAndMatchesOldMeasuredSize(heightMode,
|
|
|
|
height - marginColumn,
|
|
|
|
lastComputedHeight) ||
|
|
|
|
YGMeasureModeOldSizeIsUnspecifiedAndStillFits(heightMode,
|
|
|
|
height - marginColumn,
|
|
|
|
lastHeightMode,
|
|
|
|
lastComputedHeight) ||
|
|
|
|
YGMeasureModeNewMeasureSizeIsStricterAndStillValid(
|
2016-11-11 10:50:09 -08:00
|
|
|
heightMode, height - marginColumn, lastHeightMode, lastHeight, lastComputedHeight);
|
|
|
|
|
|
|
|
return widthIsCompatible && heightIsCompatible;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2016-12-03 04:40:18 -08:00
|
|
|
// This is a wrapper around the YGNodelayoutImpl function. It determines
|
2016-11-11 10:50:09 -08:00
|
|
|
// whether the layout request is redundant and can be skipped.
|
|
|
|
//
|
|
|
|
// Parameters:
|
2016-12-03 04:40:18 -08:00
|
|
|
// Input parameters are the same as YGNodelayoutImpl (see above)
|
2016-11-11 10:50:09 -08:00
|
|
|
// Return parameter is true if layout was performed, false if skipped
|
|
|
|
//
|
2016-12-03 04:40:18 -08:00
|
|
|
bool YGLayoutNodeInternal(const YGNodeRef node,
|
|
|
|
const float availableWidth,
|
|
|
|
const float availableHeight,
|
|
|
|
const YGDirection parentDirection,
|
|
|
|
const YGMeasureMode widthMeasureMode,
|
|
|
|
const YGMeasureMode heightMeasureMode,
|
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
|
|
|
const float parentWidth,
|
|
|
|
const float parentHeight,
|
2016-12-03 04:40:18 -08:00
|
|
|
const bool performLayout,
|
2017-03-01 09:19:55 -08:00
|
|
|
const char *reason,
|
|
|
|
const YGConfigRef config) {
|
2017-12-22 06:43:32 -08:00
|
|
|
YGLayout* layout = &node->getLayout();
|
2017-10-31 23:08:19 -07:00
|
|
|
|
2016-11-11 10:50:09 -08:00
|
|
|
gDepth++;
|
|
|
|
|
|
|
|
const bool needToVisitNode =
|
2017-12-19 11:18:00 -08:00
|
|
|
(node->isDirty() && layout->generationCount != gCurrentGenerationCount) ||
|
2016-11-11 10:50:09 -08:00
|
|
|
layout->lastParentDirection != parentDirection;
|
|
|
|
|
|
|
|
if (needToVisitNode) {
|
|
|
|
// Invalidate the cached results.
|
|
|
|
layout->nextCachedMeasurementsIndex = 0;
|
2016-12-02 05:47:43 -08:00
|
|
|
layout->cachedLayout.widthMeasureMode = (YGMeasureMode) -1;
|
|
|
|
layout->cachedLayout.heightMeasureMode = (YGMeasureMode) -1;
|
2016-11-11 10:50:09 -08:00
|
|
|
layout->cachedLayout.computedWidth = -1;
|
|
|
|
layout->cachedLayout.computedHeight = -1;
|
|
|
|
}
|
|
|
|
|
2017-11-21 10:10:30 -08:00
|
|
|
YGCachedMeasurement* cachedResults = nullptr;
|
2017-04-28 03:57:13 -07:00
|
|
|
|
2016-11-11 10:50:09 -08:00
|
|
|
// Determine whether the results are already cached. We maintain a separate
|
|
|
|
// cache for layouts and measurements. A layout operation modifies the
|
2017-04-28 03:57:13 -07:00
|
|
|
// positions
|
|
|
|
// and dimensions for nodes in the subtree. The algorithm assumes that each
|
|
|
|
// node
|
|
|
|
// gets layed out a maximum of one time per tree layout, but multiple
|
|
|
|
// measurements
|
|
|
|
// may be required to resolve all of the flex dimensions.
|
|
|
|
// We handle nodes with measure functions specially here because they are the
|
|
|
|
// most
|
|
|
|
// expensive to measure, so it's worth avoiding redundant measurements if at
|
|
|
|
// all possible.
|
2017-12-19 11:18:00 -08:00
|
|
|
if (node->getMeasure() != nullptr) {
|
2017-04-28 03:57:13 -07:00
|
|
|
const float marginAxisRow = YGNodeMarginForAxis(node, YGFlexDirectionRow, parentWidth);
|
|
|
|
const float marginAxisColumn = YGNodeMarginForAxis(node, YGFlexDirectionColumn, parentWidth);
|
2017-04-27 13:02:55 -07:00
|
|
|
|
2017-04-28 03:57:13 -07:00
|
|
|
// First, try to use the layout cache.
|
|
|
|
if (YGNodeCanUseCachedMeasurement(widthMeasureMode,
|
|
|
|
availableWidth,
|
|
|
|
heightMeasureMode,
|
|
|
|
availableHeight,
|
|
|
|
layout->cachedLayout.widthMeasureMode,
|
|
|
|
layout->cachedLayout.availableWidth,
|
|
|
|
layout->cachedLayout.heightMeasureMode,
|
|
|
|
layout->cachedLayout.availableHeight,
|
|
|
|
layout->cachedLayout.computedWidth,
|
|
|
|
layout->cachedLayout.computedHeight,
|
|
|
|
marginAxisRow,
|
2017-05-15 06:18:24 -07:00
|
|
|
marginAxisColumn,
|
|
|
|
config)) {
|
2017-04-28 03:57:13 -07:00
|
|
|
cachedResults = &layout->cachedLayout;
|
|
|
|
} else {
|
|
|
|
// Try to use the measurement cache.
|
|
|
|
for (uint32_t i = 0; i < layout->nextCachedMeasurementsIndex; i++) {
|
|
|
|
if (YGNodeCanUseCachedMeasurement(widthMeasureMode,
|
|
|
|
availableWidth,
|
|
|
|
heightMeasureMode,
|
|
|
|
availableHeight,
|
|
|
|
layout->cachedMeasurements[i].widthMeasureMode,
|
|
|
|
layout->cachedMeasurements[i].availableWidth,
|
|
|
|
layout->cachedMeasurements[i].heightMeasureMode,
|
|
|
|
layout->cachedMeasurements[i].availableHeight,
|
|
|
|
layout->cachedMeasurements[i].computedWidth,
|
|
|
|
layout->cachedMeasurements[i].computedHeight,
|
|
|
|
marginAxisRow,
|
2017-05-15 06:18:24 -07:00
|
|
|
marginAxisColumn,
|
|
|
|
config)) {
|
2017-04-28 03:57:13 -07:00
|
|
|
cachedResults = &layout->cachedMeasurements[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (performLayout) {
|
|
|
|
if (YGFloatsEqual(layout->cachedLayout.availableWidth, availableWidth) &&
|
|
|
|
YGFloatsEqual(layout->cachedLayout.availableHeight, availableHeight) &&
|
|
|
|
layout->cachedLayout.widthMeasureMode == widthMeasureMode &&
|
|
|
|
layout->cachedLayout.heightMeasureMode == heightMeasureMode) {
|
|
|
|
cachedResults = &layout->cachedLayout;
|
|
|
|
}
|
|
|
|
} else {
|
2016-11-11 10:50:09 -08:00
|
|
|
for (uint32_t i = 0; i < layout->nextCachedMeasurementsIndex; i++) {
|
2017-04-28 03:57:13 -07:00
|
|
|
if (YGFloatsEqual(layout->cachedMeasurements[i].availableWidth, availableWidth) &&
|
|
|
|
YGFloatsEqual(layout->cachedMeasurements[i].availableHeight, availableHeight) &&
|
|
|
|
layout->cachedMeasurements[i].widthMeasureMode == widthMeasureMode &&
|
|
|
|
layout->cachedMeasurements[i].heightMeasureMode == heightMeasureMode) {
|
2016-11-11 10:50:09 -08:00
|
|
|
cachedResults = &layout->cachedMeasurements[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-21 10:10:30 -08:00
|
|
|
if (!needToVisitNode && cachedResults != nullptr) {
|
2016-12-02 05:47:43 -08:00
|
|
|
layout->measuredDimensions[YGDimensionWidth] = cachedResults->computedWidth;
|
|
|
|
layout->measuredDimensions[YGDimensionHeight] = cachedResults->computedHeight;
|
2016-11-11 10:50:09 -08:00
|
|
|
|
|
|
|
if (gPrintChanges && gPrintSkips) {
|
2017-11-16 05:15:59 -08:00
|
|
|
YGLog(node, YGLogLevelVerbose, "%s%d.{[skipped] ", YGSpacer(gDepth), gDepth);
|
2017-12-19 11:18:00 -08:00
|
|
|
if (node->getPrintFunc() != nullptr) {
|
|
|
|
node->getPrintFunc()(node);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
2017-11-21 10:10:30 -08:00
|
|
|
YGLog(
|
|
|
|
node,
|
|
|
|
YGLogLevelVerbose,
|
|
|
|
"wm: %s, hm: %s, aw: %f ah: %f => d: (%f, %f) %s\n",
|
|
|
|
YGMeasureModeName(widthMeasureMode, performLayout),
|
|
|
|
YGMeasureModeName(heightMeasureMode, performLayout),
|
|
|
|
availableWidth,
|
|
|
|
availableHeight,
|
|
|
|
cachedResults->computedWidth,
|
|
|
|
cachedResults->computedHeight,
|
|
|
|
reason);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (gPrintChanges) {
|
2017-11-21 10:10:30 -08:00
|
|
|
YGLog(
|
|
|
|
node,
|
|
|
|
YGLogLevelVerbose,
|
|
|
|
"%s%d.{%s",
|
|
|
|
YGSpacer(gDepth),
|
|
|
|
gDepth,
|
|
|
|
needToVisitNode ? "*" : "");
|
2017-12-19 11:18:00 -08:00
|
|
|
if (node->getPrintFunc() != nullptr) {
|
|
|
|
node->getPrintFunc()(node);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
2017-11-21 10:10:30 -08:00
|
|
|
YGLog(
|
|
|
|
node,
|
|
|
|
YGLogLevelVerbose,
|
|
|
|
"wm: %s, hm: %s, aw: %f ah: %f %s\n",
|
|
|
|
YGMeasureModeName(widthMeasureMode, performLayout),
|
|
|
|
YGMeasureModeName(heightMeasureMode, performLayout),
|
|
|
|
availableWidth,
|
|
|
|
availableHeight,
|
|
|
|
reason);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodelayoutImpl(node,
|
|
|
|
availableWidth,
|
|
|
|
availableHeight,
|
|
|
|
parentDirection,
|
|
|
|
widthMeasureMode,
|
|
|
|
heightMeasureMode,
|
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
|
|
|
parentWidth,
|
|
|
|
parentHeight,
|
2017-03-01 09:19:55 -08:00
|
|
|
performLayout,
|
|
|
|
config);
|
2016-11-11 10:50:09 -08:00
|
|
|
|
|
|
|
if (gPrintChanges) {
|
2017-11-21 10:10:30 -08:00
|
|
|
YGLog(
|
|
|
|
node,
|
|
|
|
YGLogLevelVerbose,
|
|
|
|
"%s%d.}%s",
|
|
|
|
YGSpacer(gDepth),
|
|
|
|
gDepth,
|
|
|
|
needToVisitNode ? "*" : "");
|
2017-12-19 11:18:00 -08:00
|
|
|
if (node->getPrintFunc() != nullptr) {
|
|
|
|
node->getPrintFunc()(node);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
2017-11-21 10:10:30 -08:00
|
|
|
YGLog(
|
|
|
|
node,
|
|
|
|
YGLogLevelVerbose,
|
|
|
|
"wm: %s, hm: %s, d: (%f, %f) %s\n",
|
|
|
|
YGMeasureModeName(widthMeasureMode, performLayout),
|
|
|
|
YGMeasureModeName(heightMeasureMode, performLayout),
|
|
|
|
layout->measuredDimensions[YGDimensionWidth],
|
|
|
|
layout->measuredDimensions[YGDimensionHeight],
|
|
|
|
reason);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
layout->lastParentDirection = parentDirection;
|
|
|
|
|
2017-11-21 10:10:30 -08:00
|
|
|
if (cachedResults == nullptr) {
|
2016-12-03 04:40:18 -08:00
|
|
|
if (layout->nextCachedMeasurementsIndex == YG_MAX_CACHED_RESULT_COUNT) {
|
2016-11-11 10:50:09 -08:00
|
|
|
if (gPrintChanges) {
|
2017-11-16 05:15:59 -08:00
|
|
|
YGLog(node, YGLogLevelVerbose, "Out of cache entries!\n");
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
layout->nextCachedMeasurementsIndex = 0;
|
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGCachedMeasurement *newCacheEntry;
|
2016-11-11 10:50:09 -08:00
|
|
|
if (performLayout) {
|
|
|
|
// Use the single layout cache entry.
|
|
|
|
newCacheEntry = &layout->cachedLayout;
|
|
|
|
} else {
|
|
|
|
// Allocate a new measurement cache entry.
|
|
|
|
newCacheEntry = &layout->cachedMeasurements[layout->nextCachedMeasurementsIndex];
|
|
|
|
layout->nextCachedMeasurementsIndex++;
|
|
|
|
}
|
|
|
|
|
|
|
|
newCacheEntry->availableWidth = availableWidth;
|
|
|
|
newCacheEntry->availableHeight = availableHeight;
|
|
|
|
newCacheEntry->widthMeasureMode = widthMeasureMode;
|
|
|
|
newCacheEntry->heightMeasureMode = heightMeasureMode;
|
2016-12-02 05:47:43 -08:00
|
|
|
newCacheEntry->computedWidth = layout->measuredDimensions[YGDimensionWidth];
|
|
|
|
newCacheEntry->computedHeight = layout->measuredDimensions[YGDimensionHeight];
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (performLayout) {
|
2017-12-19 11:18:00 -08:00
|
|
|
node->setLayoutDimension(
|
|
|
|
node->getLayout().measuredDimensions[YGDimensionWidth],
|
|
|
|
YGDimensionWidth);
|
|
|
|
node->setLayoutDimension(
|
|
|
|
node->getLayout().measuredDimensions[YGDimensionHeight],
|
|
|
|
YGDimensionHeight);
|
|
|
|
|
|
|
|
node->setHasNewLayout(true);
|
|
|
|
node->setDirty(false);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
gDepth--;
|
|
|
|
layout->generationCount = gCurrentGenerationCount;
|
2017-11-21 10:10:30 -08:00
|
|
|
return (needToVisitNode || cachedResults == nullptr);
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-03-09 07:21:23 -08:00
|
|
|
void YGConfigSetPointScaleFactor(const YGConfigRef config, const float pixelsInPoint) {
|
2017-05-03 09:22:35 -07:00
|
|
|
YGAssertWithConfig(config, pixelsInPoint >= 0.0f, "Scale factor should not be less than zero");
|
|
|
|
|
2017-02-24 09:45:31 -08:00
|
|
|
// We store points for Pixel as we will use it for rounding
|
2017-03-03 10:16:41 -08:00
|
|
|
if (pixelsInPoint == 0.0f) {
|
2017-02-24 09:45:31 -08:00
|
|
|
// Zero is used to skip rounding
|
2017-03-09 07:21:23 -08:00
|
|
|
config->pointScaleFactor = 0.0f;
|
2017-02-24 09:45:31 -08:00
|
|
|
} else {
|
2017-05-26 10:56:33 -07:00
|
|
|
config->pointScaleFactor = pixelsInPoint;
|
2017-02-24 09:45:31 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-03 09:22:35 -07:00
|
|
|
static void YGRoundToPixelGrid(const YGNodeRef node,
|
|
|
|
const float pointScaleFactor,
|
|
|
|
const float absoluteLeft,
|
|
|
|
const float absoluteTop) {
|
2017-03-09 07:21:23 -08:00
|
|
|
if (pointScaleFactor == 0.0f) {
|
2017-02-24 09:45:31 -08:00
|
|
|
return;
|
|
|
|
}
|
2017-04-25 17:29:27 -07:00
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
const float nodeLeft = node->getLayout().position[YGEdgeLeft];
|
|
|
|
const float nodeTop = node->getLayout().position[YGEdgeTop];
|
2017-02-24 09:45:31 -08:00
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
const float nodeWidth = node->getLayout().dimensions[YGDimensionWidth];
|
|
|
|
const float nodeHeight = node->getLayout().dimensions[YGDimensionHeight];
|
2017-03-01 07:10:00 -08:00
|
|
|
|
2017-04-25 17:29:27 -07:00
|
|
|
const float absoluteNodeLeft = absoluteLeft + nodeLeft;
|
|
|
|
const float absoluteNodeTop = absoluteTop + nodeTop;
|
2017-03-01 07:10:00 -08:00
|
|
|
|
2017-04-25 17:29:27 -07:00
|
|
|
const float absoluteNodeRight = absoluteNodeLeft + nodeWidth;
|
|
|
|
const float absoluteNodeBottom = absoluteNodeTop + nodeHeight;
|
2017-03-01 07:10:00 -08:00
|
|
|
|
2017-04-30 03:03:43 -07:00
|
|
|
// If a node has a custom measure function we never want to round down its size as this could
|
|
|
|
// lead to unwanted text truncation.
|
2017-12-19 11:18:00 -08:00
|
|
|
const bool textRounding = node->getNodeType() == YGNodeTypeText;
|
|
|
|
|
|
|
|
node->setLayoutPosition(
|
|
|
|
YGRoundValueToPixelGrid(nodeLeft, pointScaleFactor, false, textRounding),
|
|
|
|
YGEdgeLeft);
|
2017-04-30 03:03:43 -07:00
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
node->setLayoutPosition(
|
|
|
|
YGRoundValueToPixelGrid(nodeTop, pointScaleFactor, false, textRounding),
|
|
|
|
YGEdgeTop);
|
2017-04-25 17:29:27 -07:00
|
|
|
|
2017-08-21 03:09:09 -07:00
|
|
|
// We multiply dimension by scale factor and if the result is close to the whole number, we don't
|
|
|
|
// have any fraction
|
2017-07-12 09:27:51 -07:00
|
|
|
// To verify if the result is close to whole number we want to check both floor and ceil numbers
|
|
|
|
const bool hasFractionalWidth = !YGFloatsEqual(fmodf(nodeWidth * pointScaleFactor, 1.0), 0) &&
|
|
|
|
!YGFloatsEqual(fmodf(nodeWidth * pointScaleFactor, 1.0), 1.0);
|
|
|
|
const bool hasFractionalHeight = !YGFloatsEqual(fmodf(nodeHeight * pointScaleFactor, 1.0), 0) &&
|
|
|
|
!YGFloatsEqual(fmodf(nodeHeight * pointScaleFactor, 1.0), 1.0);
|
2017-06-10 05:30:17 -07:00
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
node->setLayoutDimension(
|
|
|
|
YGRoundValueToPixelGrid(
|
|
|
|
absoluteNodeRight,
|
|
|
|
pointScaleFactor,
|
|
|
|
(textRounding && hasFractionalWidth),
|
|
|
|
(textRounding && !hasFractionalWidth)) -
|
|
|
|
YGRoundValueToPixelGrid(
|
|
|
|
absoluteNodeLeft, pointScaleFactor, false, textRounding),
|
|
|
|
YGDimensionWidth);
|
|
|
|
|
|
|
|
node->setLayoutDimension(
|
|
|
|
YGRoundValueToPixelGrid(
|
|
|
|
absoluteNodeBottom,
|
|
|
|
pointScaleFactor,
|
|
|
|
(textRounding && hasFractionalHeight),
|
|
|
|
(textRounding && !hasFractionalHeight)) -
|
|
|
|
YGRoundValueToPixelGrid(
|
|
|
|
absoluteNodeTop, pointScaleFactor, false, textRounding),
|
|
|
|
YGDimensionHeight);
|
|
|
|
|
|
|
|
const uint32_t childCount = node->getChildren().size();
|
2016-11-22 05:33:36 -08:00
|
|
|
for (uint32_t i = 0; i < childCount; i++) {
|
2017-04-25 17:29:27 -07:00
|
|
|
YGRoundToPixelGrid(YGNodeGetChild(node, i), pointScaleFactor, absoluteNodeLeft, absoluteNodeTop);
|
2016-11-22 05:33:36 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
void YGNodeCalculateLayout(const YGNodeRef node,
|
2017-02-28 08:10:34 -08:00
|
|
|
const float parentWidth,
|
|
|
|
const float parentHeight,
|
2016-12-03 04:40:18 -08:00
|
|
|
const YGDirection parentDirection) {
|
2016-11-11 10:50:09 -08:00
|
|
|
// Increment the generation count. This will force the recursive routine to
|
|
|
|
// visit
|
|
|
|
// all dirty nodes at least once. Subsequent visits will be skipped if the
|
|
|
|
// input
|
|
|
|
// parameters don't change.
|
|
|
|
gCurrentGenerationCount++;
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
node->resolveDimension();
|
2017-02-28 08:10:34 -08:00
|
|
|
float width = YGUndefined;
|
|
|
|
YGMeasureMode widthMeasureMode = YGMeasureModeUndefined;
|
|
|
|
if (YGNodeIsStyleDimDefined(node, YGFlexDirectionRow, parentWidth)) {
|
2017-12-19 11:18:00 -08:00
|
|
|
width =
|
|
|
|
YGResolveValue(
|
|
|
|
node->getResolvedDimension(dim[YGFlexDirectionRow]), parentWidth) +
|
|
|
|
YGNodeMarginForAxis(node, YGFlexDirectionRow, parentWidth);
|
2016-12-02 05:47:43 -08:00
|
|
|
widthMeasureMode = YGMeasureModeExactly;
|
2017-12-19 11:18:00 -08:00
|
|
|
} else if (
|
|
|
|
YGResolveValue(
|
|
|
|
node->getStyle().maxDimensions[YGDimensionWidth], parentWidth) >=
|
|
|
|
0.0f) {
|
|
|
|
width = YGResolveValue(
|
|
|
|
node->getStyle().maxDimensions[YGDimensionWidth], parentWidth);
|
2016-12-02 05:47:43 -08:00
|
|
|
widthMeasureMode = YGMeasureModeAtMost;
|
2017-03-01 07:10:00 -08:00
|
|
|
} else {
|
|
|
|
width = parentWidth;
|
|
|
|
widthMeasureMode = YGFloatIsUndefined(width) ? YGMeasureModeUndefined : YGMeasureModeExactly;
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-02-28 08:10:34 -08:00
|
|
|
float height = YGUndefined;
|
|
|
|
YGMeasureMode heightMeasureMode = YGMeasureModeUndefined;
|
|
|
|
if (YGNodeIsStyleDimDefined(node, YGFlexDirectionColumn, parentHeight)) {
|
2017-12-19 11:18:00 -08:00
|
|
|
height = YGResolveValue(
|
|
|
|
node->getResolvedDimension(dim[YGFlexDirectionColumn]),
|
|
|
|
parentHeight) +
|
|
|
|
YGNodeMarginForAxis(node, YGFlexDirectionColumn, parentWidth);
|
2016-12-02 05:47:43 -08:00
|
|
|
heightMeasureMode = YGMeasureModeExactly;
|
2017-12-19 11:18:00 -08:00
|
|
|
} else if (
|
|
|
|
YGResolveValue(
|
|
|
|
node->getStyle().maxDimensions[YGDimensionHeight], parentHeight) >=
|
|
|
|
0.0f) {
|
|
|
|
height = YGResolveValue(
|
|
|
|
node->getStyle().maxDimensions[YGDimensionHeight], parentHeight);
|
2016-12-02 05:47:43 -08:00
|
|
|
heightMeasureMode = YGMeasureModeAtMost;
|
2017-03-01 07:10:00 -08:00
|
|
|
} else {
|
|
|
|
height = parentHeight;
|
|
|
|
heightMeasureMode = YGFloatIsUndefined(height) ? YGMeasureModeUndefined : YGMeasureModeExactly;
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-12-19 11:18:00 -08:00
|
|
|
if (YGLayoutNodeInternal(
|
|
|
|
node,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
parentDirection,
|
|
|
|
widthMeasureMode,
|
|
|
|
heightMeasureMode,
|
|
|
|
parentWidth,
|
|
|
|
parentHeight,
|
|
|
|
true,
|
|
|
|
"initial",
|
|
|
|
node->getConfig())) {
|
|
|
|
YGNodeSetPosition(
|
|
|
|
node,
|
|
|
|
node->getLayout().direction,
|
|
|
|
parentWidth,
|
|
|
|
parentHeight,
|
|
|
|
parentWidth);
|
|
|
|
YGRoundToPixelGrid(node, node->getConfig()->pointScaleFactor, 0.0f, 0.0f);
|
2016-11-22 05:33:36 -08:00
|
|
|
|
2016-11-11 10:50:09 -08:00
|
|
|
if (gPrintTree) {
|
2017-11-21 10:10:30 -08:00
|
|
|
YGNodePrint(
|
|
|
|
node,
|
|
|
|
(YGPrintOptions)(
|
|
|
|
YGPrintOptionsLayout | YGPrintOptionsChildren |
|
|
|
|
YGPrintOptionsStyle));
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-03 09:22:35 -07:00
|
|
|
void YGConfigSetLogger(const YGConfigRef config, YGLogger logger) {
|
2017-11-21 10:10:30 -08:00
|
|
|
if (logger != nullptr) {
|
2017-05-03 09:22:35 -07:00
|
|
|
config->logger = logger;
|
2017-04-03 09:34:42 -07:00
|
|
|
} else {
|
|
|
|
#ifdef ANDROID
|
2017-05-03 09:22:35 -07:00
|
|
|
config->logger = &YGAndroidLog;
|
2017-04-03 09:34:42 -07:00
|
|
|
#else
|
2017-05-03 09:22:35 -07:00
|
|
|
config->logger = &YGDefaultLog;
|
2017-04-03 09:34:42 -07:00
|
|
|
#endif
|
|
|
|
}
|
2016-11-11 10:50:09 -08:00
|
|
|
}
|
|
|
|
|
2017-05-03 09:22:35 -07:00
|
|
|
static void YGVLog(const YGConfigRef config,
|
|
|
|
const YGNodeRef node,
|
|
|
|
YGLogLevel level,
|
|
|
|
const char *format,
|
|
|
|
va_list args) {
|
2017-11-21 10:10:30 -08:00
|
|
|
const YGConfigRef logConfig = config != nullptr ? config : &gYGConfigDefaults;
|
2017-05-03 09:22:35 -07:00
|
|
|
logConfig->logger(logConfig, node, level, format, args);
|
|
|
|
|
|
|
|
if (level == YGLogLevelFatal) {
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void YGLogWithConfig(const YGConfigRef config, YGLogLevel level, const char *format, ...) {
|
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
2017-11-21 10:10:30 -08:00
|
|
|
YGVLog(config, nullptr, level, format, args);
|
2017-05-03 09:22:35 -07:00
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
void YGLog(const YGNodeRef node, YGLogLevel level, const char *format, ...) {
|
2016-11-11 10:50:09 -08:00
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
2017-12-19 11:18:00 -08:00
|
|
|
YGVLog(
|
|
|
|
node == nullptr ? nullptr : node->getConfig(), node, level, format, args);
|
2016-11-11 10:50:09 -08:00
|
|
|
va_end(args);
|
|
|
|
}
|
2016-11-14 03:27:33 -08:00
|
|
|
|
2017-05-03 09:22:35 -07:00
|
|
|
void YGAssert(const bool condition, const char *message) {
|
|
|
|
if (!condition) {
|
2017-11-21 10:10:30 -08:00
|
|
|
YGLog(nullptr, YGLogLevelFatal, "%s\n", message);
|
2017-05-03 09:22:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void YGAssertWithNode(const YGNodeRef node, const bool condition, const char *message) {
|
|
|
|
if (!condition) {
|
|
|
|
YGLog(node, YGLogLevelFatal, "%s\n", message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void YGAssertWithConfig(const YGConfigRef config, const bool condition, const char *message) {
|
|
|
|
if (!condition) {
|
|
|
|
YGLogWithConfig(config, YGLogLevelFatal, "%s\n", message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-01 09:19:55 -08:00
|
|
|
void YGConfigSetExperimentalFeatureEnabled(const YGConfigRef config,
|
2017-05-03 09:22:35 -07:00
|
|
|
const YGExperimentalFeature feature,
|
|
|
|
const bool enabled) {
|
2017-03-01 09:19:55 -08:00
|
|
|
config->experimentalFeatures[feature] = enabled;
|
2016-11-14 03:27:33 -08:00
|
|
|
}
|
|
|
|
|
2017-03-01 09:19:55 -08:00
|
|
|
inline bool YGConfigIsExperimentalFeatureEnabled(const YGConfigRef config,
|
2017-05-03 09:22:35 -07:00
|
|
|
const YGExperimentalFeature feature) {
|
2017-03-01 09:19:55 -08:00
|
|
|
return config->experimentalFeatures[feature];
|
2016-11-14 03:27:33 -08:00
|
|
|
}
|
2016-11-15 20:20:09 -08:00
|
|
|
|
2017-03-03 10:47:42 -08:00
|
|
|
void YGConfigSetUseWebDefaults(const YGConfigRef config, const bool enabled) {
|
|
|
|
config->useWebDefaults = enabled;
|
|
|
|
}
|
|
|
|
|
2017-05-03 09:22:35 -07:00
|
|
|
void YGConfigSetUseLegacyStretchBehaviour(const YGConfigRef config,
|
|
|
|
const bool useLegacyStretchBehaviour) {
|
2017-04-28 06:13:51 -07:00
|
|
|
config->useLegacyStretchBehaviour = useLegacyStretchBehaviour;
|
|
|
|
}
|
|
|
|
|
2017-03-03 10:47:42 -08:00
|
|
|
bool YGConfigGetUseWebDefaults(const YGConfigRef config) {
|
|
|
|
return config->useWebDefaults;
|
|
|
|
}
|
|
|
|
|
2017-05-03 09:22:35 -07:00
|
|
|
void YGConfigSetContext(const YGConfigRef config, void *context) {
|
|
|
|
config->context = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *YGConfigGetContext(const YGConfigRef config) {
|
|
|
|
return config->context;
|
|
|
|
}
|
|
|
|
|
Persistent Yoga
Summary:
This is meant to show a possible route format for a persistent form of Yoga. Where previous layouts can remain intact while still taking advantage of incremental layout by reusing previous subtrees.
```c
YGNodeRef YGNodeClone(const YGNodeRef node);
```
The core of this functionality is a new API to clone an existing node. This makes a new detached node with all the same values as the previous one. Conceptually this makes the original node "frozen" from that point on. It's now immutable. (This is not yet enforced at runtime in this PR but something we should add.)
Since the original is frozen, we reuse the children set from the original node. Their parent pointers still point back to the original tree though.
The cloned node is still mutable. It can have its styles updated, and nodes can be inserted or deleted. If an insertion/deletion happens on a cloned node whose children were reused, it'll first shallow clone its children automatically.
As a convenience I also added an API to clear all children:
```c
void YGNodeRemoveAllChildren(const YGNodeRef node);
```
During insert/delete, or as a result of layout a set of reused children may need to be first cloned. A kind of copy-on-write. When that happens, the host may want to respond. E.g. by updating the `context` such as by cloning any wrapper objects and attaching them to the new node.
```c
typedef void (*YGNodeClonedFunc)(YGNodeRef oldNode,
YGNodeRef newNode,
YGNodeRef parent,
int childIndex);
void YGConfigSetNodeClonedFunc(YGConfigRef config,
YGNodeClonedFunc callback);
```
This PR doesn't change any existing semantics for trees that are not first cloned.
It's possible for a single node to exist in two trees at once and be used by multiple threads. Therefore it's not safe to recursively free a whole tree when you use persistence. To solve this, any user of the library has to manually manage ref counting or tracing GC. E.g. by replicating the tree structure in a wrapper.
In a follow up we could consider moving ref counting into Yoga.
Closes https://github.com/facebook/yoga/pull/636
Reviewed By: emilsjolander
Differential Revision: D5941921
Pulled By: sebmarkbage
fbshipit-source-id: c8e93421824c112d09c4773bed4e3141b6491ccf
2017-10-17 01:02:04 -07:00
|
|
|
void YGConfigSetNodeClonedFunc(const YGConfigRef config, const YGNodeClonedFunc callback) {
|
|
|
|
config->cloneNodeCallback = callback;
|
|
|
|
}
|