Rename C api
Summary: This renames the core C api to use the new Yoga branding. Differential Revision: D4259190 fbshipit-source-id: 26c8b356ca464d4304f5f9dc4192bff10cea2dc9
This commit is contained in:
committed by
Facebook Github Bot
parent
f7cc614d67
commit
dda24b1e23
@@ -1,183 +0,0 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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
|
||||
|
||||
// Not defined in MSVC++
|
||||
#ifndef NAN
|
||||
static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
|
||||
#define NAN (*(const float *) __nan)
|
||||
#endif
|
||||
|
||||
#define YGUndefined NAN
|
||||
|
||||
#include "CSSEnums.h"
|
||||
#include "CSSMacros.h"
|
||||
|
||||
CSS_EXTERN_C_BEGIN
|
||||
|
||||
typedef struct CSSSize {
|
||||
float width;
|
||||
float height;
|
||||
} CSSSize;
|
||||
|
||||
typedef struct CSSNode *CSSNodeRef;
|
||||
typedef CSSSize (*CSSMeasureFunc)(CSSNodeRef node,
|
||||
float width,
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode);
|
||||
typedef void (*CSSPrintFunc)(CSSNodeRef node);
|
||||
typedef int (*CSSLogger)(YGLogLevel level, const char *format, va_list args);
|
||||
|
||||
typedef void *(*CSSMalloc)(size_t size);
|
||||
typedef void *(*CSSCalloc)(size_t count, size_t size);
|
||||
typedef void *(*CSSRealloc)(void *ptr, size_t size);
|
||||
typedef void (*CSSFree)(void *ptr);
|
||||
|
||||
// CSSNode
|
||||
WIN_EXPORT CSSNodeRef CSSNodeNew(void);
|
||||
WIN_EXPORT void CSSNodeInit(const CSSNodeRef node);
|
||||
WIN_EXPORT void CSSNodeFree(const CSSNodeRef node);
|
||||
WIN_EXPORT void CSSNodeFreeRecursive(const CSSNodeRef node);
|
||||
WIN_EXPORT void CSSNodeReset(const CSSNodeRef node);
|
||||
WIN_EXPORT int32_t CSSNodeGetInstanceCount(void);
|
||||
|
||||
WIN_EXPORT void CSSNodeInsertChild(const CSSNodeRef node,
|
||||
const CSSNodeRef child,
|
||||
const uint32_t index);
|
||||
WIN_EXPORT void CSSNodeRemoveChild(const CSSNodeRef node, const CSSNodeRef child);
|
||||
WIN_EXPORT CSSNodeRef CSSNodeGetChild(const CSSNodeRef node, const uint32_t index);
|
||||
WIN_EXPORT uint32_t CSSNodeChildCount(const CSSNodeRef node);
|
||||
|
||||
WIN_EXPORT void CSSNodeCalculateLayout(const CSSNodeRef node,
|
||||
const float availableWidth,
|
||||
const float availableHeight,
|
||||
const YGDirection parentDirection);
|
||||
|
||||
// Mark a node as dirty. Only valid for nodes with a custom measure function
|
||||
// set.
|
||||
// CSSLayout knows when to mark all other nodes as dirty but because nodes with
|
||||
// measure functions
|
||||
// depends on information not known to CSSLayout they must perform this dirty
|
||||
// marking manually.
|
||||
WIN_EXPORT void CSSNodeMarkDirty(const CSSNodeRef node);
|
||||
WIN_EXPORT bool CSSNodeIsDirty(const CSSNodeRef node);
|
||||
|
||||
WIN_EXPORT void CSSNodePrint(const CSSNodeRef node, const YGPrintOptions options);
|
||||
|
||||
WIN_EXPORT bool CSSValueIsUndefined(const float value);
|
||||
|
||||
WIN_EXPORT bool CSSNodeCanUseCachedMeasurement(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);
|
||||
|
||||
WIN_EXPORT void CSSNodeCopyStyle(const CSSNodeRef dstNode, const CSSNodeRef srcNode);
|
||||
|
||||
#define CSS_NODE_PROPERTY(type, name, paramName) \
|
||||
WIN_EXPORT void CSSNodeSet##name(const CSSNodeRef node, type paramName); \
|
||||
WIN_EXPORT type CSSNodeGet##name(const CSSNodeRef node);
|
||||
|
||||
#define CSS_NODE_STYLE_PROPERTY(type, name, paramName) \
|
||||
WIN_EXPORT void CSSNodeStyleSet##name(const CSSNodeRef node, const type paramName); \
|
||||
WIN_EXPORT type CSSNodeStyleGet##name(const CSSNodeRef node);
|
||||
|
||||
#define CSS_NODE_STYLE_EDGE_PROPERTY(type, name, paramName) \
|
||||
WIN_EXPORT void CSSNodeStyleSet##name(const CSSNodeRef node, \
|
||||
const YGEdge edge, \
|
||||
const type paramName); \
|
||||
WIN_EXPORT type CSSNodeStyleGet##name(const CSSNodeRef node, const YGEdge edge);
|
||||
|
||||
#define CSS_NODE_LAYOUT_PROPERTY(type, name) \
|
||||
WIN_EXPORT type CSSNodeLayoutGet##name(const CSSNodeRef node);
|
||||
|
||||
CSS_NODE_PROPERTY(void *, Context, context);
|
||||
CSS_NODE_PROPERTY(CSSMeasureFunc, MeasureFunc, measureFunc);
|
||||
CSS_NODE_PROPERTY(CSSPrintFunc, PrintFunc, printFunc);
|
||||
CSS_NODE_PROPERTY(bool, HasNewLayout, hasNewLayout);
|
||||
|
||||
CSS_NODE_STYLE_PROPERTY(YGDirection, Direction, direction);
|
||||
CSS_NODE_STYLE_PROPERTY(YGFlexDirection, FlexDirection, flexDirection);
|
||||
CSS_NODE_STYLE_PROPERTY(YGJustify, JustifyContent, justifyContent);
|
||||
CSS_NODE_STYLE_PROPERTY(YGAlign, AlignContent, alignContent);
|
||||
CSS_NODE_STYLE_PROPERTY(YGAlign, AlignItems, alignItems);
|
||||
CSS_NODE_STYLE_PROPERTY(YGAlign, AlignSelf, alignSelf);
|
||||
CSS_NODE_STYLE_PROPERTY(YGPositionType, PositionType, positionType);
|
||||
CSS_NODE_STYLE_PROPERTY(YGWrap, FlexWrap, flexWrap);
|
||||
CSS_NODE_STYLE_PROPERTY(YGOverflow, Overflow, overflow);
|
||||
|
||||
WIN_EXPORT void CSSNodeStyleSetFlex(const CSSNodeRef node, const float flex);
|
||||
CSS_NODE_STYLE_PROPERTY(float, FlexGrow, flexGrow);
|
||||
CSS_NODE_STYLE_PROPERTY(float, FlexShrink, flexShrink);
|
||||
CSS_NODE_STYLE_PROPERTY(float, FlexBasis, flexBasis);
|
||||
|
||||
CSS_NODE_STYLE_EDGE_PROPERTY(float, Position, position);
|
||||
CSS_NODE_STYLE_EDGE_PROPERTY(float, Margin, margin);
|
||||
CSS_NODE_STYLE_EDGE_PROPERTY(float, Padding, padding);
|
||||
CSS_NODE_STYLE_EDGE_PROPERTY(float, Border, border);
|
||||
|
||||
CSS_NODE_STYLE_PROPERTY(float, Width, width);
|
||||
CSS_NODE_STYLE_PROPERTY(float, Height, height);
|
||||
CSS_NODE_STYLE_PROPERTY(float, MinWidth, minWidth);
|
||||
CSS_NODE_STYLE_PROPERTY(float, MinHeight, minHeight);
|
||||
CSS_NODE_STYLE_PROPERTY(float, MaxWidth, maxWidth);
|
||||
CSS_NODE_STYLE_PROPERTY(float, MaxHeight, maxHeight);
|
||||
|
||||
// Yoga specific properties, not compatible with flexbox specification
|
||||
// Aspect ratio control the size of the undefined dimension of a node.
|
||||
// - 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
|
||||
// - Aspect ratio takes min/max dimensions into account
|
||||
CSS_NODE_STYLE_PROPERTY(float, AspectRatio, aspectRatio);
|
||||
|
||||
CSS_NODE_LAYOUT_PROPERTY(float, Left);
|
||||
CSS_NODE_LAYOUT_PROPERTY(float, Top);
|
||||
CSS_NODE_LAYOUT_PROPERTY(float, Right);
|
||||
CSS_NODE_LAYOUT_PROPERTY(float, Bottom);
|
||||
CSS_NODE_LAYOUT_PROPERTY(float, Width);
|
||||
CSS_NODE_LAYOUT_PROPERTY(float, Height);
|
||||
CSS_NODE_LAYOUT_PROPERTY(YGDirection, Direction);
|
||||
|
||||
WIN_EXPORT void CSSLayoutSetLogger(CSSLogger logger);
|
||||
WIN_EXPORT void CSSLog(YGLogLevel level, const char *message, ...);
|
||||
|
||||
WIN_EXPORT void CSSLayoutSetExperimentalFeatureEnabled(YGExperimentalFeature feature, bool enabled);
|
||||
WIN_EXPORT bool CSSLayoutIsExperimentalFeatureEnabled(YGExperimentalFeature feature);
|
||||
|
||||
WIN_EXPORT void CSSLayoutSetMemoryFuncs(CSSMalloc cssMalloc,
|
||||
CSSCalloc cssCalloc,
|
||||
CSSRealloc cssRealloc,
|
||||
CSSFree cssFree);
|
||||
|
||||
CSS_EXTERN_C_END
|
@@ -1,104 +0,0 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "CSSNodeList.h"
|
||||
|
||||
extern CSSMalloc gCSSMalloc;
|
||||
extern CSSRealloc gCSSRealloc;
|
||||
extern CSSFree gCSSFree;
|
||||
|
||||
struct CSSNodeList {
|
||||
uint32_t capacity;
|
||||
uint32_t count;
|
||||
CSSNodeRef *items;
|
||||
};
|
||||
|
||||
CSSNodeListRef CSSNodeListNew(const uint32_t initialCapacity) {
|
||||
const CSSNodeListRef list = gCSSMalloc(sizeof(struct CSSNodeList));
|
||||
CSS_ASSERT(list != NULL, "Could not allocate memory for list");
|
||||
|
||||
list->capacity = initialCapacity;
|
||||
list->count = 0;
|
||||
list->items = gCSSMalloc(sizeof(CSSNodeRef) * list->capacity);
|
||||
CSS_ASSERT(list->items != NULL, "Could not allocate memory for items");
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
void CSSNodeListFree(const CSSNodeListRef list) {
|
||||
if (list) {
|
||||
gCSSFree(list->items);
|
||||
gCSSFree(list);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t CSSNodeListCount(const CSSNodeListRef list) {
|
||||
if (list) {
|
||||
return list->count;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CSSNodeListAdd(CSSNodeListRef *listp, const CSSNodeRef node) {
|
||||
if (!*listp) {
|
||||
*listp = CSSNodeListNew(4);
|
||||
}
|
||||
CSSNodeListInsert(listp, node, (*listp)->count);
|
||||
}
|
||||
|
||||
void CSSNodeListInsert(CSSNodeListRef *listp, const CSSNodeRef node, const uint32_t index) {
|
||||
if (!*listp) {
|
||||
*listp = CSSNodeListNew(4);
|
||||
}
|
||||
CSSNodeListRef list = *listp;
|
||||
|
||||
if (list->count == list->capacity) {
|
||||
list->capacity *= 2;
|
||||
list->items = gCSSRealloc(list->items, sizeof(CSSNodeRef) * list->capacity);
|
||||
CSS_ASSERT(list->items != NULL, "Could not extend allocation for items");
|
||||
}
|
||||
|
||||
for (uint32_t i = list->count; i > index; i--) {
|
||||
list->items[i] = list->items[i - 1];
|
||||
}
|
||||
|
||||
list->count++;
|
||||
list->items[index] = node;
|
||||
}
|
||||
|
||||
CSSNodeRef CSSNodeListRemove(const CSSNodeListRef list, const uint32_t index) {
|
||||
const CSSNodeRef removed = list->items[index];
|
||||
list->items[index] = NULL;
|
||||
|
||||
for (uint32_t i = index; i < list->count - 1; i++) {
|
||||
list->items[i] = list->items[i + 1];
|
||||
list->items[i + 1] = NULL;
|
||||
}
|
||||
|
||||
list->count--;
|
||||
return removed;
|
||||
}
|
||||
|
||||
CSSNodeRef CSSNodeListDelete(const CSSNodeListRef list, const CSSNodeRef node) {
|
||||
for (uint32_t i = 0; i < list->count; i++) {
|
||||
if (list->items[i] == node) {
|
||||
return CSSNodeListRemove(list, i);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CSSNodeRef CSSNodeListGet(const CSSNodeListRef list, const uint32_t index) {
|
||||
if (CSSNodeListCount(list) > 0) {
|
||||
return list->items[index];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
@@ -1,33 +0,0 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "CSSLayout.h"
|
||||
#include "CSSMacros.h"
|
||||
|
||||
CSS_EXTERN_C_BEGIN
|
||||
|
||||
typedef struct CSSNodeList *CSSNodeListRef;
|
||||
|
||||
CSSNodeListRef CSSNodeListNew(const uint32_t initialCapacity);
|
||||
void CSSNodeListFree(const CSSNodeListRef list);
|
||||
uint32_t CSSNodeListCount(const CSSNodeListRef list);
|
||||
void CSSNodeListAdd(CSSNodeListRef *listp, const CSSNodeRef node);
|
||||
void CSSNodeListInsert(CSSNodeListRef *listp, const CSSNodeRef node, const uint32_t index);
|
||||
CSSNodeRef CSSNodeListRemove(const CSSNodeListRef list, const uint32_t index);
|
||||
CSSNodeRef CSSNodeListDelete(const CSSNodeListRef list, const CSSNodeRef node);
|
||||
CSSNodeRef CSSNodeListGet(const CSSNodeListRef list, const uint32_t index);
|
||||
|
||||
CSS_EXTERN_C_END
|
@@ -10,11 +10,11 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define CSS_EXTERN_C_BEGIN extern "C" {
|
||||
#define CSS_EXTERN_C_END }
|
||||
#define YG_EXTERN_C_BEGIN extern "C" {
|
||||
#define YG_EXTERN_C_END }
|
||||
#else
|
||||
#define CSS_EXTERN_C_BEGIN
|
||||
#define CSS_EXTERN_C_END
|
||||
#define YG_EXTERN_C_BEGIN
|
||||
#define YG_EXTERN_C_END
|
||||
#endif
|
||||
|
||||
#ifdef _WINDLL
|
||||
@@ -28,15 +28,15 @@
|
||||
#endif
|
||||
|
||||
#if FB_ASSERTIONS_ENABLED
|
||||
#define CSS_ABORT() abort()
|
||||
#define YG_ABORT() abort()
|
||||
#else
|
||||
#define CSS_ABORT()
|
||||
#define YG_ABORT()
|
||||
#endif
|
||||
|
||||
#ifndef CSS_ASSERT
|
||||
#define CSS_ASSERT(X, message) \
|
||||
if (!(X)) { \
|
||||
CSSLog(YGLogLevelError, "%s", message); \
|
||||
CSS_ABORT(); \
|
||||
#ifndef YG_ASSERT
|
||||
#define YG_ASSERT(X, message) \
|
||||
if (!(X)) { \
|
||||
YGLog(YGLogLevelError, "%s", message); \
|
||||
YG_ABORT(); \
|
||||
}
|
||||
#endif
|
104
CSSLayout/YGNodeList.c
Normal file
104
CSSLayout/YGNodeList.c
Normal file
@@ -0,0 +1,104 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "YGNodeList.h"
|
||||
|
||||
extern YGMalloc gYGMalloc;
|
||||
extern YGRealloc gYGRealloc;
|
||||
extern YGFree gYGFree;
|
||||
|
||||
struct YGNodeList {
|
||||
uint32_t capacity;
|
||||
uint32_t count;
|
||||
YGNodeRef *items;
|
||||
};
|
||||
|
||||
YGNodeListRef YGNodeListNew(const uint32_t initialCapacity) {
|
||||
const YGNodeListRef list = gYGMalloc(sizeof(struct YGNodeList));
|
||||
YG_ASSERT(list != NULL, "Could not allocate memory for list");
|
||||
|
||||
list->capacity = initialCapacity;
|
||||
list->count = 0;
|
||||
list->items = gYGMalloc(sizeof(YGNodeRef) * list->capacity);
|
||||
YG_ASSERT(list->items != NULL, "Could not allocate memory for items");
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
void YGNodeListFree(const YGNodeListRef list) {
|
||||
if (list) {
|
||||
gYGFree(list->items);
|
||||
gYGFree(list);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t YGNodeListCount(const YGNodeListRef list) {
|
||||
if (list) {
|
||||
return list->count;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void YGNodeListAdd(YGNodeListRef *listp, const YGNodeRef node) {
|
||||
if (!*listp) {
|
||||
*listp = YGNodeListNew(4);
|
||||
}
|
||||
YGNodeListInsert(listp, node, (*listp)->count);
|
||||
}
|
||||
|
||||
void YGNodeListInsert(YGNodeListRef *listp, const YGNodeRef node, const uint32_t index) {
|
||||
if (!*listp) {
|
||||
*listp = YGNodeListNew(4);
|
||||
}
|
||||
YGNodeListRef list = *listp;
|
||||
|
||||
if (list->count == list->capacity) {
|
||||
list->capacity *= 2;
|
||||
list->items = gYGRealloc(list->items, sizeof(YGNodeRef) * list->capacity);
|
||||
YG_ASSERT(list->items != NULL, "Could not extend allocation for items");
|
||||
}
|
||||
|
||||
for (uint32_t i = list->count; i > index; i--) {
|
||||
list->items[i] = list->items[i - 1];
|
||||
}
|
||||
|
||||
list->count++;
|
||||
list->items[index] = node;
|
||||
}
|
||||
|
||||
YGNodeRef YGNodeListRemove(const YGNodeListRef list, const uint32_t index) {
|
||||
const YGNodeRef removed = list->items[index];
|
||||
list->items[index] = NULL;
|
||||
|
||||
for (uint32_t i = index; i < list->count - 1; i++) {
|
||||
list->items[i] = list->items[i + 1];
|
||||
list->items[i + 1] = NULL;
|
||||
}
|
||||
|
||||
list->count--;
|
||||
return removed;
|
||||
}
|
||||
|
||||
YGNodeRef YGNodeListDelete(const YGNodeListRef list, const YGNodeRef node) {
|
||||
for (uint32_t i = 0; i < list->count; i++) {
|
||||
if (list->items[i] == node) {
|
||||
return YGNodeListRemove(list, i);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
YGNodeRef YGNodeListGet(const YGNodeListRef list, const uint32_t index) {
|
||||
if (YGNodeListCount(list) > 0) {
|
||||
return list->items[index];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
33
CSSLayout/YGNodeList.h
Normal file
33
CSSLayout/YGNodeList.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "YGMacros.h"
|
||||
#include "Yoga.h"
|
||||
|
||||
YG_EXTERN_C_BEGIN
|
||||
|
||||
typedef struct YGNodeList *YGNodeListRef;
|
||||
|
||||
YGNodeListRef YGNodeListNew(const uint32_t initialCapacity);
|
||||
void YGNodeListFree(const YGNodeListRef list);
|
||||
uint32_t YGNodeListCount(const YGNodeListRef list);
|
||||
void YGNodeListAdd(YGNodeListRef *listp, const YGNodeRef node);
|
||||
void YGNodeListInsert(YGNodeListRef *listp, const YGNodeRef node, const uint32_t index);
|
||||
YGNodeRef YGNodeListRemove(const YGNodeListRef list, const uint32_t index);
|
||||
YGNodeRef YGNodeListDelete(const YGNodeListRef list, const YGNodeRef node);
|
||||
YGNodeRef YGNodeListGet(const YGNodeListRef list, const uint32_t index);
|
||||
|
||||
YG_EXTERN_C_END
|
File diff suppressed because it is too large
Load Diff
181
CSSLayout/Yoga.h
Normal file
181
CSSLayout/Yoga.h
Normal file
@@ -0,0 +1,181 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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
|
||||
|
||||
// Not defined in MSVC++
|
||||
#ifndef NAN
|
||||
static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
|
||||
#define NAN (*(const float *) __nan)
|
||||
#endif
|
||||
|
||||
#define YGUndefined NAN
|
||||
|
||||
#include "YGEnums.h"
|
||||
#include "YGMacros.h"
|
||||
|
||||
YG_EXTERN_C_BEGIN
|
||||
|
||||
typedef struct YGSize {
|
||||
float width;
|
||||
float height;
|
||||
} YGSize;
|
||||
|
||||
typedef struct YGNode *YGNodeRef;
|
||||
typedef YGSize (*YGMeasureFunc)(YGNodeRef node,
|
||||
float width,
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode);
|
||||
typedef void (*YGPrintFunc)(YGNodeRef node);
|
||||
typedef int (*YGLogger)(YGLogLevel level, const char *format, va_list args);
|
||||
|
||||
typedef void *(*YGMalloc)(size_t size);
|
||||
typedef void *(*YGCalloc)(size_t count, size_t size);
|
||||
typedef void *(*YGRealloc)(void *ptr, size_t size);
|
||||
typedef void (*YGFree)(void *ptr);
|
||||
|
||||
// YGNode
|
||||
WIN_EXPORT YGNodeRef YGNodeNew(void);
|
||||
WIN_EXPORT void YGNodeInit(const YGNodeRef node);
|
||||
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);
|
||||
|
||||
WIN_EXPORT void YGNodeInsertChild(const YGNodeRef node,
|
||||
const YGNodeRef child,
|
||||
const uint32_t index);
|
||||
WIN_EXPORT void YGNodeRemoveChild(const YGNodeRef node, const YGNodeRef child);
|
||||
WIN_EXPORT YGNodeRef YGNodeGetChild(const YGNodeRef node, const uint32_t index);
|
||||
WIN_EXPORT uint32_t YGNodeChildCount(const YGNodeRef node);
|
||||
|
||||
WIN_EXPORT void YGNodeCalculateLayout(const YGNodeRef node,
|
||||
const float availableWidth,
|
||||
const float availableHeight,
|
||||
const YGDirection parentDirection);
|
||||
|
||||
// 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);
|
||||
WIN_EXPORT bool YGNodeIsDirty(const YGNodeRef node);
|
||||
|
||||
WIN_EXPORT void YGNodePrint(const YGNodeRef node, const YGPrintOptions options);
|
||||
|
||||
WIN_EXPORT bool YGValueIsUndefined(const float value);
|
||||
|
||||
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);
|
||||
|
||||
WIN_EXPORT void YGNodeCopyStyle(const YGNodeRef dstNode, const YGNodeRef srcNode);
|
||||
|
||||
#define YG_NODE_PROPERTY(type, name, paramName) \
|
||||
WIN_EXPORT void YGNodeSet##name(const YGNodeRef node, type paramName); \
|
||||
WIN_EXPORT type YGNodeGet##name(const YGNodeRef node);
|
||||
|
||||
#define YG_NODE_STYLE_PROPERTY(type, name, paramName) \
|
||||
WIN_EXPORT void YGNodeStyleSet##name(const YGNodeRef node, const type paramName); \
|
||||
WIN_EXPORT type YGNodeStyleGet##name(const YGNodeRef node);
|
||||
|
||||
#define YG_NODE_STYLE_EDGE_PROPERTY(type, name, paramName) \
|
||||
WIN_EXPORT void YGNodeStyleSet##name(const YGNodeRef node, \
|
||||
const YGEdge edge, \
|
||||
const type paramName); \
|
||||
WIN_EXPORT type YGNodeStyleGet##name(const YGNodeRef node, const YGEdge edge);
|
||||
|
||||
#define YG_NODE_LAYOUT_PROPERTY(type, name) \
|
||||
WIN_EXPORT type YGNodeLayoutGet##name(const YGNodeRef node);
|
||||
|
||||
YG_NODE_PROPERTY(void *, Context, context);
|
||||
YG_NODE_PROPERTY(YGMeasureFunc, MeasureFunc, measureFunc);
|
||||
YG_NODE_PROPERTY(YGPrintFunc, PrintFunc, printFunc);
|
||||
YG_NODE_PROPERTY(bool, HasNewLayout, hasNewLayout);
|
||||
|
||||
YG_NODE_STYLE_PROPERTY(YGDirection, Direction, direction);
|
||||
YG_NODE_STYLE_PROPERTY(YGFlexDirection, FlexDirection, flexDirection);
|
||||
YG_NODE_STYLE_PROPERTY(YGJustify, JustifyContent, justifyContent);
|
||||
YG_NODE_STYLE_PROPERTY(YGAlign, AlignContent, alignContent);
|
||||
YG_NODE_STYLE_PROPERTY(YGAlign, AlignItems, alignItems);
|
||||
YG_NODE_STYLE_PROPERTY(YGAlign, AlignSelf, alignSelf);
|
||||
YG_NODE_STYLE_PROPERTY(YGPositionType, PositionType, positionType);
|
||||
YG_NODE_STYLE_PROPERTY(YGWrap, FlexWrap, flexWrap);
|
||||
YG_NODE_STYLE_PROPERTY(YGOverflow, Overflow, overflow);
|
||||
|
||||
WIN_EXPORT void YGNodeStyleSetFlex(const YGNodeRef node, const float flex);
|
||||
YG_NODE_STYLE_PROPERTY(float, FlexGrow, flexGrow);
|
||||
YG_NODE_STYLE_PROPERTY(float, FlexShrink, flexShrink);
|
||||
YG_NODE_STYLE_PROPERTY(float, FlexBasis, flexBasis);
|
||||
|
||||
YG_NODE_STYLE_EDGE_PROPERTY(float, Position, position);
|
||||
YG_NODE_STYLE_EDGE_PROPERTY(float, Margin, margin);
|
||||
YG_NODE_STYLE_EDGE_PROPERTY(float, Padding, padding);
|
||||
YG_NODE_STYLE_EDGE_PROPERTY(float, Border, border);
|
||||
|
||||
YG_NODE_STYLE_PROPERTY(float, Width, width);
|
||||
YG_NODE_STYLE_PROPERTY(float, Height, height);
|
||||
YG_NODE_STYLE_PROPERTY(float, MinWidth, minWidth);
|
||||
YG_NODE_STYLE_PROPERTY(float, MinHeight, minHeight);
|
||||
YG_NODE_STYLE_PROPERTY(float, MaxWidth, maxWidth);
|
||||
YG_NODE_STYLE_PROPERTY(float, MaxHeight, maxHeight);
|
||||
|
||||
// Yoga specific properties, not compatible with flexbox specification
|
||||
// Aspect ratio control the size of the undefined dimension of a node.
|
||||
// - 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
|
||||
// - Aspect ratio takes min/max dimensions into account
|
||||
YG_NODE_STYLE_PROPERTY(float, AspectRatio, aspectRatio);
|
||||
|
||||
YG_NODE_LAYOUT_PROPERTY(float, Left);
|
||||
YG_NODE_LAYOUT_PROPERTY(float, Top);
|
||||
YG_NODE_LAYOUT_PROPERTY(float, Right);
|
||||
YG_NODE_LAYOUT_PROPERTY(float, Bottom);
|
||||
YG_NODE_LAYOUT_PROPERTY(float, Width);
|
||||
YG_NODE_LAYOUT_PROPERTY(float, Height);
|
||||
YG_NODE_LAYOUT_PROPERTY(YGDirection, Direction);
|
||||
|
||||
WIN_EXPORT void YGSetLogger(YGLogger logger);
|
||||
WIN_EXPORT void YGLog(YGLogLevel level, const char *message, ...);
|
||||
|
||||
WIN_EXPORT void YGSetExperimentalFeatureEnabled(YGExperimentalFeature feature, bool enabled);
|
||||
WIN_EXPORT bool YGIsExperimentalFeatureEnabled(YGExperimentalFeature feature);
|
||||
|
||||
WIN_EXPORT void
|
||||
YGSetMemoryFuncs(YGMalloc cssMalloc, YGCalloc cssCalloc, YGRealloc cssRealloc, YGFree cssFree);
|
||||
|
||||
YG_EXTERN_C_END
|
Reference in New Issue
Block a user