2015-02-20 23:45:12 +00:00
|
|
|
/**
|
2016-06-15 16:44:30 +00:00
|
|
|
* Copyright (c) 2014-present, Facebook, Inc.
|
2015-02-20 23:45:12 +00:00
|
|
|
* All rights reserved.
|
2016-07-13 17:15:44 +00:00
|
|
|
*
|
2015-02-20 23:45:12 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2016-08-02 15:07:09 +00:00
|
|
|
#pragma once
|
2016-06-15 16:44:30 +00:00
|
|
|
|
2016-08-02 15:06:55 +00:00
|
|
|
#include <assert.h>
|
2016-06-15 16:44:30 +00:00
|
|
|
#include <math.h>
|
2016-08-02 15:06:55 +00:00
|
|
|
#include <stdint.h>
|
2016-08-15 16:15:02 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2016-08-02 15:06:55 +00:00
|
|
|
|
2016-06-15 16:44:30 +00:00
|
|
|
#ifndef __cplusplus
|
|
|
|
#include <stdbool.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Not defined in MSVC++
|
|
|
|
#ifndef NAN
|
2016-08-15 16:15:02 +00:00
|
|
|
static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
|
|
|
|
#define NAN (*(const float *) __nan)
|
2016-06-15 16:44:30 +00:00
|
|
|
#endif
|
|
|
|
|
2016-07-20 13:40:26 +00:00
|
|
|
#define CSSUndefined NAN
|
2016-06-15 16:44:30 +00:00
|
|
|
|
2016-07-20 14:28:06 +00:00
|
|
|
#include <CSSLayout/CSSMacros.h>
|
2016-07-13 17:15:44 +00:00
|
|
|
|
|
|
|
CSS_EXTERN_C_BEGIN
|
|
|
|
|
2016-07-20 13:40:26 +00:00
|
|
|
typedef enum CSSDirection {
|
|
|
|
CSSDirectionInherit,
|
|
|
|
CSSDirectionLTR,
|
|
|
|
CSSDirectionRTL,
|
|
|
|
} CSSDirection;
|
|
|
|
|
|
|
|
typedef enum CSSFlexDirection {
|
|
|
|
CSSFlexDirectionColumn,
|
|
|
|
CSSFlexDirectionColumnReverse,
|
|
|
|
CSSFlexDirectionRow,
|
|
|
|
CSSFlexDirectionRowReverse,
|
|
|
|
} CSSFlexDirection;
|
|
|
|
|
|
|
|
typedef enum CSSJustify {
|
|
|
|
CSSJustifyFlexStart,
|
|
|
|
CSSJustifyCenter,
|
|
|
|
CSSJustifyFlexEnd,
|
|
|
|
CSSJustifySpaceBetween,
|
|
|
|
CSSJustifySpaceAround,
|
|
|
|
} CSSJustify;
|
|
|
|
|
|
|
|
typedef enum CSSOverflow {
|
|
|
|
CSSOverflowVisible,
|
|
|
|
CSSOverflowHidden,
|
|
|
|
} CSSOverflow;
|
2016-06-15 16:44:30 +00:00
|
|
|
|
|
|
|
// Note: auto is only a valid value for alignSelf. It is NOT a valid value for
|
|
|
|
// alignItems.
|
2016-07-20 13:40:26 +00:00
|
|
|
typedef enum CSSAlign {
|
|
|
|
CSSAlignAuto,
|
|
|
|
CSSAlignFlexStart,
|
|
|
|
CSSAlignCenter,
|
|
|
|
CSSAlignFlexEnd,
|
|
|
|
CSSAlignStretch,
|
|
|
|
} CSSAlign;
|
|
|
|
|
|
|
|
typedef enum CSSPositionType {
|
|
|
|
CSSPositionTypeRelative,
|
|
|
|
CSSPositionTypeAbsolute,
|
|
|
|
} CSSPositionType;
|
|
|
|
|
|
|
|
typedef enum CSSWrapType {
|
|
|
|
CSSWrapTypeNoWrap,
|
|
|
|
CSSWrapTypeWrap,
|
|
|
|
} CSSWrapType;
|
2016-06-15 16:44:30 +00:00
|
|
|
|
2016-07-20 13:40:26 +00:00
|
|
|
typedef enum CSSMeasureMode {
|
|
|
|
CSSMeasureModeUndefined,
|
|
|
|
CSSMeasureModeExactly,
|
|
|
|
CSSMeasureModeAtMost,
|
|
|
|
CSSMeasureModeCount,
|
|
|
|
} CSSMeasureMode;
|
|
|
|
|
|
|
|
typedef enum CSSDimension {
|
|
|
|
CSSDimensionWidth,
|
|
|
|
CSSDimensionHeight,
|
|
|
|
} CSSDimension;
|
|
|
|
|
2016-08-15 16:15:10 +00:00
|
|
|
typedef enum CSSEdge {
|
|
|
|
CSSEdgeLeft,
|
|
|
|
CSSEdgeTop,
|
|
|
|
CSSEdgeRight,
|
|
|
|
CSSEdgeBottom,
|
|
|
|
CSSEdgeStart,
|
|
|
|
CSSEdgeEnd,
|
|
|
|
CSSEdgeHorizontal,
|
|
|
|
CSSEdgeVertical,
|
|
|
|
CSSEdgeAll,
|
2016-08-17 17:36:36 +00:00
|
|
|
CSSEdgeCount,
|
2016-08-15 16:15:10 +00:00
|
|
|
} CSSEdge;
|
|
|
|
|
2016-07-20 13:40:26 +00:00
|
|
|
typedef enum CSSPrintOptions {
|
|
|
|
CSSPrintOptionsLayout = 1,
|
|
|
|
CSSPrintOptionsStyle = 2,
|
|
|
|
CSSPrintOptionsChildren = 4,
|
|
|
|
} CSSPrintOptions;
|
|
|
|
|
2016-07-20 15:46:00 +00:00
|
|
|
typedef struct CSSSize {
|
|
|
|
float width;
|
|
|
|
float height;
|
|
|
|
} CSSSize;
|
|
|
|
|
2016-08-04 15:20:11 +00:00
|
|
|
typedef struct CSSNode *CSSNodeRef;
|
2016-08-15 16:15:02 +00:00
|
|
|
typedef CSSSize (*CSSMeasureFunc)(void *context,
|
|
|
|
float width,
|
|
|
|
CSSMeasureMode widthMode,
|
|
|
|
float height,
|
|
|
|
CSSMeasureMode heightMode);
|
2016-07-20 15:46:00 +00:00
|
|
|
typedef void (*CSSPrintFunc)(void *context);
|
|
|
|
|
|
|
|
// CSSNode
|
|
|
|
CSSNodeRef CSSNodeNew();
|
|
|
|
void CSSNodeInit(CSSNodeRef node);
|
|
|
|
void CSSNodeFree(CSSNodeRef node);
|
|
|
|
|
2016-08-02 15:06:55 +00:00
|
|
|
void CSSNodeInsertChild(CSSNodeRef node, CSSNodeRef child, uint32_t index);
|
2016-07-20 20:26:57 +00:00
|
|
|
void CSSNodeRemoveChild(CSSNodeRef node, CSSNodeRef child);
|
2016-08-02 15:06:55 +00:00
|
|
|
CSSNodeRef CSSNodeGetChild(CSSNodeRef node, uint32_t index);
|
|
|
|
uint32_t CSSNodeChildCount(CSSNodeRef node);
|
2016-07-20 20:26:57 +00:00
|
|
|
|
2016-08-15 16:15:02 +00:00
|
|
|
void CSSNodeCalculateLayout(CSSNodeRef node,
|
|
|
|
float availableWidth,
|
|
|
|
float availableHeight,
|
|
|
|
CSSDirection parentDirection);
|
2016-08-04 15:20:11 +00:00
|
|
|
|
|
|
|
// 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.
|
2016-07-25 10:48:50 +00:00
|
|
|
void CSSNodeMarkDirty(CSSNodeRef node);
|
2016-08-04 15:19:59 +00:00
|
|
|
bool CSSNodeIsDirty(CSSNodeRef node);
|
2016-07-25 10:48:50 +00:00
|
|
|
|
2016-07-20 15:46:00 +00:00
|
|
|
void CSSNodePrint(CSSNodeRef node, CSSPrintOptions options);
|
2016-06-15 16:44:30 +00:00
|
|
|
|
2016-08-05 13:27:39 +00:00
|
|
|
bool CSSValueIsUndefined(float value);
|
2016-06-15 16:44:30 +00:00
|
|
|
|
2016-08-15 16:15:02 +00:00
|
|
|
#define CSS_NODE_PROPERTY(type, name, paramName) \
|
|
|
|
void CSSNodeSet##name(CSSNodeRef node, type paramName); \
|
2016-08-04 15:20:11 +00:00
|
|
|
type CSSNodeGet##name(CSSNodeRef node);
|
2016-07-20 15:46:00 +00:00
|
|
|
|
2016-08-15 16:15:02 +00:00
|
|
|
#define CSS_NODE_STYLE_PROPERTY(type, name, paramName) \
|
|
|
|
void CSSNodeStyleSet##name(CSSNodeRef node, type paramName); \
|
2016-08-04 15:20:11 +00:00
|
|
|
type CSSNodeStyleGet##name(CSSNodeRef node);
|
2016-07-20 15:46:00 +00:00
|
|
|
|
2016-08-15 16:15:10 +00:00
|
|
|
#define CSS_NODE_STYLE_EDGE_PROPERTY(type, name, paramName) \
|
|
|
|
void CSSNodeStyleSet##name(CSSNodeRef node, CSSEdge edge, type paramName); \
|
|
|
|
type CSSNodeStyleGet##name(CSSNodeRef node, CSSEdge edge);
|
|
|
|
|
2016-08-04 15:20:11 +00:00
|
|
|
#define CSS_NODE_LAYOUT_PROPERTY(type, name) type CSSNodeLayoutGet##name(CSSNodeRef node);
|
2016-07-20 15:46:00 +00:00
|
|
|
|
2016-08-04 15:20:11 +00:00
|
|
|
CSS_NODE_PROPERTY(void *, Context, context);
|
2016-07-20 15:46:00 +00:00
|
|
|
CSS_NODE_PROPERTY(CSSMeasureFunc, MeasureFunc, measureFunc);
|
|
|
|
CSS_NODE_PROPERTY(CSSPrintFunc, PrintFunc, printFunc);
|
2016-07-20 15:46:04 +00:00
|
|
|
CSS_NODE_PROPERTY(bool, IsTextnode, isTextNode);
|
2016-08-01 12:24:18 +00:00
|
|
|
CSS_NODE_PROPERTY(bool, HasNewLayout, hasNewLayout);
|
2016-07-20 15:46:00 +00:00
|
|
|
|
|
|
|
CSS_NODE_STYLE_PROPERTY(CSSDirection, Direction, direction);
|
|
|
|
CSS_NODE_STYLE_PROPERTY(CSSFlexDirection, FlexDirection, flexDirection);
|
|
|
|
CSS_NODE_STYLE_PROPERTY(CSSJustify, JustifyContent, justifyContent);
|
|
|
|
CSS_NODE_STYLE_PROPERTY(CSSAlign, AlignContent, alignContent);
|
|
|
|
CSS_NODE_STYLE_PROPERTY(CSSAlign, AlignItems, alignItems);
|
|
|
|
CSS_NODE_STYLE_PROPERTY(CSSAlign, AlignSelf, alignSelf);
|
|
|
|
CSS_NODE_STYLE_PROPERTY(CSSPositionType, PositionType, positionType);
|
|
|
|
CSS_NODE_STYLE_PROPERTY(CSSWrapType, FlexWrap, flexWrap);
|
|
|
|
CSS_NODE_STYLE_PROPERTY(CSSOverflow, Overflow, overflow);
|
|
|
|
CSS_NODE_STYLE_PROPERTY(float, Flex, flex);
|
2016-08-15 16:15:05 +00:00
|
|
|
CSS_NODE_STYLE_PROPERTY(float, FlexGrow, flexGrow);
|
|
|
|
CSS_NODE_STYLE_PROPERTY(float, FlexShrink, flexShrink);
|
|
|
|
CSS_NODE_STYLE_PROPERTY(float, FlexBasis, flexBasis);
|
2016-07-20 15:46:00 +00:00
|
|
|
|
2016-08-15 16:15:10 +00:00
|
|
|
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);
|
2016-07-20 15:46:00 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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);
|
2016-07-28 21:43:40 +00:00
|
|
|
CSS_NODE_LAYOUT_PROPERTY(CSSDirection, Direction);
|
2016-07-20 15:46:00 +00:00
|
|
|
|
2016-07-13 17:15:44 +00:00
|
|
|
CSS_EXTERN_C_END
|