2018-07-19 16:57:04 +00:00
|
|
|
/*
|
2018-09-11 22:27:47 +00:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2018-07-19 16:57:04 +00:00
|
|
|
*
|
|
|
|
* This source code is licensed under the MIT license found in the LICENSE
|
|
|
|
* file in the root directory of this source tree.
|
2016-12-03 12:40:18 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#ifndef __cplusplus
|
|
|
|
#include <stdbool.h>
|
|
|
|
#endif
|
|
|
|
|
2018-03-01 12:00:35 +00:00
|
|
|
/** Large positive number signifies that the property(float) is undefined.
|
|
|
|
*Earlier we used to have YGundefined as NAN, but the downside of this is that
|
|
|
|
*we can't use -ffast-math compiler flag as it assumes all floating-point
|
|
|
|
*calculation involve and result into finite numbers. For more information
|
|
|
|
*regarding -ffast-math compiler flag in clang, have a look at
|
|
|
|
*https://clang.llvm.org/docs/UsersManual.html#cmdoption-ffast-math
|
|
|
|
**/
|
|
|
|
#define YGUndefined 10E20F
|
2016-12-03 12:40:18 +00:00
|
|
|
|
|
|
|
#include "YGEnums.h"
|
|
|
|
#include "YGMacros.h"
|
|
|
|
|
|
|
|
YG_EXTERN_C_BEGIN
|
|
|
|
|
|
|
|
typedef struct YGSize {
|
|
|
|
float width;
|
|
|
|
float height;
|
|
|
|
} YGSize;
|
|
|
|
|
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 13:20:37 +00:00
|
|
|
typedef struct YGValue {
|
|
|
|
float value;
|
|
|
|
YGUnit unit;
|
|
|
|
} YGValue;
|
|
|
|
|
2017-12-19 19:18:00 +00:00
|
|
|
extern const YGValue YGValueUndefined;
|
|
|
|
extern const YGValue YGValueAuto;
|
2017-01-11 11:58:03 +00:00
|
|
|
|
2018-07-23 20:24:21 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
|
|
|
extern bool operator==(const YGValue& lhs, const YGValue& rhs);
|
|
|
|
extern bool operator!=(const YGValue& lhs, const YGValue& rhs);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2018-07-19 16:57:04 +00:00
|
|
|
typedef struct YGConfig* YGConfigRef;
|
2017-12-19 19:18:00 +00:00
|
|
|
|
|
|
|
typedef struct YGNode* YGNodeRef;
|
|
|
|
|
2018-07-19 16:57:04 +00:00
|
|
|
typedef YGSize (*YGMeasureFunc)(
|
|
|
|
YGNodeRef node,
|
|
|
|
float width,
|
|
|
|
YGMeasureMode widthMode,
|
|
|
|
float height,
|
|
|
|
YGMeasureMode heightMode);
|
|
|
|
typedef float (
|
|
|
|
*YGBaselineFunc)(YGNodeRef node, const float width, const float height);
|
2018-01-10 17:45:08 +00:00
|
|
|
typedef void (*YGDirtiedFunc)(YGNodeRef node);
|
2016-12-03 12:40:18 +00:00
|
|
|
typedef void (*YGPrintFunc)(YGNodeRef node);
|
2018-07-19 16:57:04 +00:00
|
|
|
typedef int (*YGLogger)(
|
|
|
|
const YGConfigRef config,
|
|
|
|
const YGNodeRef node,
|
|
|
|
YGLogLevel level,
|
|
|
|
const char* format,
|
|
|
|
va_list args);
|
2018-04-02 01:27:08 +00:00
|
|
|
typedef YGNodeRef (
|
|
|
|
*YGCloneNodeFunc)(YGNodeRef oldNode, YGNodeRef owner, int childIndex);
|
2016-12-03 12:40:18 +00:00
|
|
|
|
|
|
|
// YGNode
|
|
|
|
WIN_EXPORT YGNodeRef YGNodeNew(void);
|
2017-03-01 17:19:55 +00:00
|
|
|
WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config);
|
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 08:02:04 +00:00
|
|
|
WIN_EXPORT YGNodeRef YGNodeClone(const YGNodeRef node);
|
2016-12-03 12:40:18 +00:00
|
|
|
WIN_EXPORT void YGNodeFree(const YGNodeRef node);
|
|
|
|
WIN_EXPORT void YGNodeFreeRecursive(const YGNodeRef node);
|
|
|
|
WIN_EXPORT void YGNodeReset(const YGNodeRef node);
|
|
|
|
WIN_EXPORT int32_t YGNodeGetInstanceCount(void);
|
|
|
|
|
2018-07-19 16:57:04 +00:00
|
|
|
WIN_EXPORT void YGNodeInsertChild(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const YGNodeRef child,
|
|
|
|
const uint32_t index);
|
2018-04-02 01:27:08 +00:00
|
|
|
|
|
|
|
// This function inserts the child YGNodeRef as a children of the node received
|
|
|
|
// by parameter and set the Owner of the child object to null. This function is
|
|
|
|
// expected to be called when using Yoga in persistent mode in order to share a
|
|
|
|
// YGNodeRef object as a child of two different Yoga trees. The child YGNodeRef
|
|
|
|
// is expected to be referenced from its original owner and from a clone of its
|
|
|
|
// original owner.
|
|
|
|
WIN_EXPORT void YGNodeInsertSharedChild(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const YGNodeRef child,
|
|
|
|
const uint32_t index);
|
2016-12-03 12:40:18 +00:00
|
|
|
WIN_EXPORT void YGNodeRemoveChild(const YGNodeRef node, const YGNodeRef 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 08:02:04 +00:00
|
|
|
WIN_EXPORT void YGNodeRemoveAllChildren(const YGNodeRef node);
|
2016-12-03 12:40:18 +00:00
|
|
|
WIN_EXPORT YGNodeRef YGNodeGetChild(const YGNodeRef node, const uint32_t index);
|
2018-04-02 01:27:06 +00:00
|
|
|
WIN_EXPORT YGNodeRef YGNodeGetOwner(const YGNodeRef node);
|
2018-06-11 11:07:38 +00:00
|
|
|
WIN_EXPORT YGNodeRef YGNodeGetParent(const YGNodeRef node);
|
2016-12-16 12:39:13 +00:00
|
|
|
WIN_EXPORT uint32_t YGNodeGetChildCount(const YGNodeRef node);
|
2018-04-02 01:27:08 +00:00
|
|
|
WIN_EXPORT void YGNodeSetChildren(
|
|
|
|
YGNodeRef const owner,
|
|
|
|
const YGNodeRef children[],
|
|
|
|
const uint32_t count);
|
2016-12-03 12:40:18 +00:00
|
|
|
|
2018-07-19 16:57:04 +00:00
|
|
|
WIN_EXPORT void YGNodeCalculateLayout(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const float availableWidth,
|
|
|
|
const float availableHeight,
|
|
|
|
const YGDirection ownerDirection);
|
2016-12-03 12:40:18 +00:00
|
|
|
|
|
|
|
// Mark a node as dirty. Only valid for nodes with a custom measure function
|
|
|
|
// set.
|
|
|
|
// YG knows when to mark all other nodes as dirty but because nodes with
|
|
|
|
// measure functions
|
|
|
|
// depends on information not known to YG they must perform this dirty
|
|
|
|
// marking manually.
|
|
|
|
WIN_EXPORT void YGNodeMarkDirty(const YGNodeRef node);
|
|
|
|
|
2018-07-19 16:57:04 +00:00
|
|
|
// This function marks the current node and all its descendants as dirty. This
|
|
|
|
// function is added to test yoga benchmarks. This function is not expected to
|
|
|
|
// be used in production as calling `YGCalculateLayout` will cause the
|
|
|
|
// recalculation of each and every node.
|
2018-02-08 12:51:12 +00:00
|
|
|
WIN_EXPORT void YGNodeMarkDirtyAndPropogateToDescendants(const YGNodeRef node);
|
|
|
|
|
2016-12-03 12:40:18 +00:00
|
|
|
WIN_EXPORT void YGNodePrint(const YGNodeRef node, const YGPrintOptions options);
|
|
|
|
|
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 13:20:37 +00:00
|
|
|
WIN_EXPORT bool YGFloatIsUndefined(const float value);
|
2016-12-03 12:40:18 +00:00
|
|
|
|
2018-07-19 16:57:04 +00:00
|
|
|
WIN_EXPORT 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,
|
|
|
|
const float marginColumn,
|
|
|
|
const YGConfigRef config);
|
|
|
|
|
|
|
|
WIN_EXPORT void YGNodeCopyStyle(
|
|
|
|
const YGNodeRef dstNode,
|
|
|
|
const YGNodeRef srcNode);
|
2016-12-03 12:40:18 +00:00
|
|
|
|
2017-12-19 19:18:00 +00:00
|
|
|
void* YGNodeGetContext(YGNodeRef node);
|
|
|
|
void YGNodeSetContext(YGNodeRef node, void* context);
|
2018-08-30 11:40:46 +00:00
|
|
|
void YGConfigSetPrintTreeFlag(YGConfigRef config, bool enabled);
|
2017-12-19 19:18:00 +00:00
|
|
|
YGMeasureFunc YGNodeGetMeasureFunc(YGNodeRef node);
|
|
|
|
void YGNodeSetMeasureFunc(YGNodeRef node, YGMeasureFunc measureFunc);
|
|
|
|
YGBaselineFunc YGNodeGetBaselineFunc(YGNodeRef node);
|
|
|
|
void YGNodeSetBaselineFunc(YGNodeRef node, YGBaselineFunc baselineFunc);
|
2018-01-15 23:35:51 +00:00
|
|
|
YGDirtiedFunc YGNodeGetDirtiedFunc(YGNodeRef node);
|
|
|
|
void YGNodeSetDirtiedFunc(YGNodeRef node, YGDirtiedFunc dirtiedFunc);
|
2017-12-19 19:18:00 +00:00
|
|
|
YGPrintFunc YGNodeGetPrintFunc(YGNodeRef node);
|
|
|
|
void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc);
|
|
|
|
bool YGNodeGetHasNewLayout(YGNodeRef node);
|
|
|
|
void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout);
|
|
|
|
YGNodeType YGNodeGetNodeType(YGNodeRef node);
|
|
|
|
void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType);
|
|
|
|
bool YGNodeIsDirty(YGNodeRef node);
|
2018-02-02 15:38:17 +00:00
|
|
|
bool YGNodeLayoutGetDidUseLegacyFlag(const YGNodeRef node);
|
2016-12-03 12:40:18 +00:00
|
|
|
|
2018-07-19 16:57:06 +00:00
|
|
|
WIN_EXPORT void YGNodeStyleSetDirection(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const YGDirection direction);
|
|
|
|
WIN_EXPORT YGDirection YGNodeStyleGetDirection(const YGNodeRef node);
|
|
|
|
|
|
|
|
WIN_EXPORT void YGNodeStyleSetFlexDirection(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const YGFlexDirection flexDirection);
|
|
|
|
WIN_EXPORT YGFlexDirection YGNodeStyleGetFlexDirection(const YGNodeRef node);
|
|
|
|
|
|
|
|
WIN_EXPORT void YGNodeStyleSetJustifyContent(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const YGJustify justifyContent);
|
|
|
|
WIN_EXPORT YGJustify YGNodeStyleGetJustifyContent(const YGNodeRef node);
|
|
|
|
|
|
|
|
WIN_EXPORT void YGNodeStyleSetAlignContent(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const YGAlign alignContent);
|
|
|
|
WIN_EXPORT YGAlign YGNodeStyleGetAlignContent(const YGNodeRef node);
|
|
|
|
|
|
|
|
WIN_EXPORT void YGNodeStyleSetAlignItems(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const YGAlign alignItems);
|
|
|
|
WIN_EXPORT YGAlign YGNodeStyleGetAlignItems(const YGNodeRef node);
|
|
|
|
|
|
|
|
WIN_EXPORT void YGNodeStyleSetAlignSelf(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const YGAlign alignSelf);
|
|
|
|
WIN_EXPORT YGAlign YGNodeStyleGetAlignSelf(const YGNodeRef node);
|
|
|
|
|
|
|
|
WIN_EXPORT void YGNodeStyleSetPositionType(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const YGPositionType positionType);
|
|
|
|
WIN_EXPORT YGPositionType YGNodeStyleGetPositionType(const YGNodeRef node);
|
|
|
|
|
|
|
|
WIN_EXPORT void YGNodeStyleSetFlexWrap(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const YGWrap flexWrap);
|
|
|
|
WIN_EXPORT YGWrap YGNodeStyleGetFlexWrap(const YGNodeRef node);
|
|
|
|
|
|
|
|
WIN_EXPORT void YGNodeStyleSetOverflow(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const YGOverflow overflow);
|
|
|
|
WIN_EXPORT YGOverflow YGNodeStyleGetOverflow(const YGNodeRef node);
|
|
|
|
|
|
|
|
WIN_EXPORT void YGNodeStyleSetDisplay(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const YGDisplay display);
|
|
|
|
WIN_EXPORT YGDisplay YGNodeStyleGetDisplay(const YGNodeRef node);
|
|
|
|
|
|
|
|
WIN_EXPORT void YGNodeStyleSetFlex(const YGNodeRef node, const float flex);
|
|
|
|
WIN_EXPORT float YGNodeStyleGetFlex(const YGNodeRef node);
|
|
|
|
|
|
|
|
WIN_EXPORT void YGNodeStyleSetFlexGrow(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const float flexGrow);
|
|
|
|
WIN_EXPORT float YGNodeStyleGetFlexGrow(const YGNodeRef node);
|
|
|
|
|
|
|
|
WIN_EXPORT void YGNodeStyleSetFlexShrink(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const float flexShrink);
|
|
|
|
WIN_EXPORT float YGNodeStyleGetFlexShrink(const YGNodeRef node);
|
|
|
|
|
|
|
|
WIN_EXPORT void YGNodeStyleSetFlexBasis(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const float flexBasis);
|
|
|
|
WIN_EXPORT void YGNodeStyleSetFlexBasisPercent(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const float flexBasis);
|
|
|
|
WIN_EXPORT void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node);
|
|
|
|
WIN_EXPORT YGValue YGNodeStyleGetFlexBasis(const YGNodeRef node);
|
|
|
|
|
|
|
|
WIN_EXPORT void YGNodeStyleSetPosition(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const YGEdge edge,
|
|
|
|
const float position);
|
|
|
|
WIN_EXPORT void YGNodeStyleSetPositionPercent(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const YGEdge edge,
|
|
|
|
const float position);
|
|
|
|
WIN_EXPORT WIN_STRUCT(YGValue)
|
|
|
|
YGNodeStyleGetPosition(const YGNodeRef node, const YGEdge edge);
|
|
|
|
|
|
|
|
WIN_EXPORT void YGNodeStyleSetMargin(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const YGEdge edge,
|
|
|
|
const float margin);
|
|
|
|
WIN_EXPORT void YGNodeStyleSetMarginPercent(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const YGEdge edge,
|
|
|
|
const float margin);
|
|
|
|
WIN_EXPORT void YGNodeStyleSetMarginAuto(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const YGEdge edge);
|
|
|
|
WIN_EXPORT YGValue
|
|
|
|
YGNodeStyleGetMargin(const YGNodeRef node, const YGEdge edge);
|
|
|
|
|
|
|
|
WIN_EXPORT void YGNodeStyleSetPadding(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const YGEdge edge,
|
|
|
|
const float padding);
|
|
|
|
WIN_EXPORT void YGNodeStyleSetPaddingPercent(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const YGEdge edge,
|
|
|
|
const float padding);
|
|
|
|
WIN_EXPORT YGValue
|
|
|
|
YGNodeStyleGetPadding(const YGNodeRef node, const YGEdge edge);
|
|
|
|
|
|
|
|
WIN_EXPORT void YGNodeStyleSetBorder(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const YGEdge edge,
|
|
|
|
const float border);
|
|
|
|
WIN_EXPORT float YGNodeStyleGetBorder(const YGNodeRef node, const YGEdge edge);
|
|
|
|
|
|
|
|
WIN_EXPORT void YGNodeStyleSetWidth(const YGNodeRef node, const float width);
|
|
|
|
WIN_EXPORT void YGNodeStyleSetWidthPercent(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const float width);
|
|
|
|
WIN_EXPORT void YGNodeStyleSetWidthAuto(const YGNodeRef node);
|
|
|
|
WIN_EXPORT YGValue YGNodeStyleGetWidth(const YGNodeRef node);
|
|
|
|
|
|
|
|
WIN_EXPORT void YGNodeStyleSetHeight(const YGNodeRef node, const float height);
|
|
|
|
WIN_EXPORT void YGNodeStyleSetHeightPercent(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const float height);
|
|
|
|
WIN_EXPORT void YGNodeStyleSetHeightAuto(const YGNodeRef node);
|
|
|
|
WIN_EXPORT YGValue YGNodeStyleGetHeight(const YGNodeRef node);
|
|
|
|
|
|
|
|
WIN_EXPORT void YGNodeStyleSetMinWidth(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const float minWidth);
|
|
|
|
WIN_EXPORT void YGNodeStyleSetMinWidthPercent(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const float minWidth);
|
|
|
|
WIN_EXPORT YGValue YGNodeStyleGetMinWidth(const YGNodeRef node);
|
|
|
|
|
|
|
|
WIN_EXPORT void YGNodeStyleSetMinHeight(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const float minHeight);
|
|
|
|
WIN_EXPORT void YGNodeStyleSetMinHeightPercent(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const float minHeight);
|
|
|
|
WIN_EXPORT YGValue YGNodeStyleGetMinHeight(const YGNodeRef node);
|
|
|
|
|
|
|
|
WIN_EXPORT void YGNodeStyleSetMaxWidth(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const float maxWidth);
|
|
|
|
WIN_EXPORT void YGNodeStyleSetMaxWidthPercent(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const float maxWidth);
|
|
|
|
WIN_EXPORT YGValue YGNodeStyleGetMaxWidth(const YGNodeRef node);
|
|
|
|
|
|
|
|
WIN_EXPORT void YGNodeStyleSetMaxHeight(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const float maxHeight);
|
|
|
|
WIN_EXPORT void YGNodeStyleSetMaxHeightPercent(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const float maxHeight);
|
|
|
|
WIN_EXPORT YGValue YGNodeStyleGetMaxHeight(const YGNodeRef node);
|
2016-12-03 12:40:18 +00:00
|
|
|
|
|
|
|
// Yoga specific properties, not compatible with flexbox specification
|
|
|
|
// Aspect ratio control the size of the undefined dimension of a node.
|
2018-07-19 16:57:04 +00:00
|
|
|
// Aspect ratio is encoded as a floating point value width/height. e.g. A value
|
|
|
|
// of 2 leads to a node with a width twice the size of its height while a value
|
|
|
|
// of 0.5 gives the opposite effect.
|
2016-12-22 10:57:15 +00:00
|
|
|
//
|
2018-07-19 16:57:04 +00:00
|
|
|
// - On a node with a set width/height aspect ratio control the size of the
|
|
|
|
// unset dimension
|
|
|
|
// - On a node with a set flex basis aspect ratio controls the size of the node
|
|
|
|
// in the cross axis if unset
|
|
|
|
// - On a node with a measure function aspect ratio works as though the measure
|
|
|
|
// function measures the flex basis
|
|
|
|
// - On a node with flex grow/shrink aspect ratio controls the size of the node
|
|
|
|
// in the cross axis if unset
|
2016-12-03 12:40:18 +00:00
|
|
|
// - Aspect ratio takes min/max dimensions into account
|
2018-07-19 16:57:06 +00:00
|
|
|
WIN_EXPORT void YGNodeStyleSetAspectRatio(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const float aspectRatio);
|
|
|
|
WIN_EXPORT float YGNodeStyleGetAspectRatio(const YGNodeRef node);
|
|
|
|
|
|
|
|
WIN_EXPORT float YGNodeLayoutGetLeft(const YGNodeRef node);
|
|
|
|
WIN_EXPORT float YGNodeLayoutGetTop(const YGNodeRef node);
|
|
|
|
WIN_EXPORT float YGNodeLayoutGetRight(const YGNodeRef node);
|
|
|
|
WIN_EXPORT float YGNodeLayoutGetBottom(const YGNodeRef node);
|
|
|
|
WIN_EXPORT float YGNodeLayoutGetWidth(const YGNodeRef node);
|
|
|
|
WIN_EXPORT float YGNodeLayoutGetHeight(const YGNodeRef node);
|
|
|
|
WIN_EXPORT YGDirection YGNodeLayoutGetDirection(const YGNodeRef node);
|
|
|
|
WIN_EXPORT bool YGNodeLayoutGetHadOverflow(const YGNodeRef node);
|
2018-03-14 15:37:55 +00:00
|
|
|
bool YGNodeLayoutGetDidLegacyStretchFlagAffectLayout(const YGNodeRef node);
|
2016-12-03 12:40:18 +00:00
|
|
|
|
2018-07-19 16:57:04 +00:00
|
|
|
// Get the computed values for these nodes after performing layout. If they were
|
|
|
|
// set using point values then the returned value will be the same as
|
|
|
|
// YGNodeStyleGetXXX. However if they were set using a percentage value then the
|
|
|
|
// returned value is the computed value used during layout.
|
2018-07-19 16:57:06 +00:00
|
|
|
WIN_EXPORT float YGNodeLayoutGetMargin(const YGNodeRef node, const YGEdge edge);
|
|
|
|
WIN_EXPORT float YGNodeLayoutGetBorder(const YGNodeRef node, const YGEdge edge);
|
|
|
|
WIN_EXPORT float YGNodeLayoutGetPadding(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const YGEdge edge);
|
2017-01-05 20:48:07 +00:00
|
|
|
|
2017-05-03 16:22:35 +00:00
|
|
|
WIN_EXPORT void YGConfigSetLogger(const YGConfigRef config, YGLogger logger);
|
2018-07-19 16:57:04 +00:00
|
|
|
WIN_EXPORT void
|
|
|
|
YGLog(const YGNodeRef node, YGLogLevel level, const char* message, ...);
|
|
|
|
WIN_EXPORT void YGLogWithConfig(
|
|
|
|
const YGConfigRef config,
|
|
|
|
YGLogLevel level,
|
|
|
|
const char* format,
|
|
|
|
...);
|
|
|
|
WIN_EXPORT void YGAssert(const bool condition, const char* message);
|
|
|
|
WIN_EXPORT void YGAssertWithNode(
|
|
|
|
const YGNodeRef node,
|
|
|
|
const bool condition,
|
|
|
|
const char* message);
|
|
|
|
WIN_EXPORT void YGAssertWithConfig(
|
|
|
|
const YGConfigRef config,
|
|
|
|
const bool condition,
|
|
|
|
const char* message);
|
2017-02-24 17:45:31 +00:00
|
|
|
// Set this to number of pixels in 1 point to round calculation results
|
|
|
|
// If you want to avoid rounding - set PointScaleFactor to 0
|
2018-07-19 16:57:04 +00:00
|
|
|
WIN_EXPORT void YGConfigSetPointScaleFactor(
|
|
|
|
const YGConfigRef config,
|
|
|
|
const float pixelsInPoint);
|
2018-03-14 15:37:55 +00:00
|
|
|
void YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
|
|
|
const YGConfigRef config,
|
|
|
|
const bool shouldDiffLayout);
|
2017-02-24 17:45:31 +00:00
|
|
|
|
2018-07-19 16:57:04 +00:00
|
|
|
// Yoga previously had an error where containers would take the maximum space
|
|
|
|
// possible instead of the minimum like they are supposed to. In practice this
|
|
|
|
// resulted in implicit behaviour similar to align-self: stretch; Because this
|
|
|
|
// was such a long-standing bug we must allow legacy users to switch back to
|
|
|
|
// this behaviour.
|
|
|
|
WIN_EXPORT void YGConfigSetUseLegacyStretchBehaviour(
|
|
|
|
const YGConfigRef config,
|
|
|
|
const bool useLegacyStretchBehaviour);
|
2017-04-28 13:13:51 +00:00
|
|
|
|
2017-03-01 17:19:55 +00:00
|
|
|
// YGConfig
|
|
|
|
WIN_EXPORT YGConfigRef YGConfigNew(void);
|
|
|
|
WIN_EXPORT void YGConfigFree(const YGConfigRef config);
|
2017-04-26 18:49:26 +00:00
|
|
|
WIN_EXPORT void YGConfigCopy(const YGConfigRef dest, const YGConfigRef src);
|
2017-04-10 21:22:23 +00:00
|
|
|
WIN_EXPORT int32_t YGConfigGetInstanceCount(void);
|
2017-03-01 17:19:55 +00:00
|
|
|
|
2018-07-19 16:57:04 +00:00
|
|
|
WIN_EXPORT void YGConfigSetExperimentalFeatureEnabled(
|
|
|
|
const YGConfigRef config,
|
|
|
|
const YGExperimentalFeature feature,
|
|
|
|
const bool enabled);
|
|
|
|
WIN_EXPORT bool YGConfigIsExperimentalFeatureEnabled(
|
|
|
|
const YGConfigRef config,
|
|
|
|
const YGExperimentalFeature feature);
|
2016-12-03 12:40:18 +00:00
|
|
|
|
2017-03-09 15:21:23 +00:00
|
|
|
// Using the web defaults is the prefered configuration for new projects.
|
2017-03-03 18:47:42 +00:00
|
|
|
// Usage of non web defaults should be considered as legacy.
|
2018-07-19 16:57:04 +00:00
|
|
|
WIN_EXPORT void YGConfigSetUseWebDefaults(
|
|
|
|
const YGConfigRef config,
|
|
|
|
const bool enabled);
|
2017-03-03 18:47:42 +00:00
|
|
|
WIN_EXPORT bool YGConfigGetUseWebDefaults(const YGConfigRef config);
|
|
|
|
|
2018-07-19 16:57:04 +00:00
|
|
|
WIN_EXPORT void YGConfigSetCloneNodeFunc(
|
|
|
|
const YGConfigRef config,
|
|
|
|
const YGCloneNodeFunc callback);
|
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 08:02:04 +00:00
|
|
|
|
2017-05-03 16:22:35 +00:00
|
|
|
// Export only for C#
|
|
|
|
WIN_EXPORT YGConfigRef YGConfigGetDefault(void);
|
|
|
|
|
2018-07-19 16:57:04 +00:00
|
|
|
WIN_EXPORT void YGConfigSetContext(const YGConfigRef config, void* context);
|
|
|
|
WIN_EXPORT void* YGConfigGetContext(const YGConfigRef config);
|
2017-05-03 16:22:35 +00:00
|
|
|
|
2017-12-07 00:25:26 +00:00
|
|
|
WIN_EXPORT float YGRoundValueToPixelGrid(
|
|
|
|
const float value,
|
|
|
|
const float pointScaleFactor,
|
|
|
|
const bool forceCeil,
|
|
|
|
const bool forceFloor);
|
|
|
|
|
2016-12-03 12:40:18 +00:00
|
|
|
YG_EXTERN_C_END
|
2018-03-25 20:56:13 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
// Calls f on each node in the tree including the given node argument.
|
2018-07-19 16:57:04 +00:00
|
|
|
extern void YGTraversePreOrder(
|
|
|
|
YGNodeRef const node,
|
|
|
|
std::function<void(YGNodeRef node)>&& f);
|
2018-03-25 20:56:13 +00:00
|
|
|
|
2018-04-02 01:27:08 +00:00
|
|
|
extern void YGNodeSetChildren(
|
|
|
|
YGNodeRef const owner,
|
|
|
|
const std::vector<YGNodeRef>& children);
|
2018-03-25 20:56:13 +00:00
|
|
|
|
|
|
|
#endif
|