diff --git a/.gitignore b/.gitignore index 2a22d83c..5b346768 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,6 @@ /buck-out/ /.buckconfig.local /.buckd -/lib/gtest/googletest-*/ /gentest/test.html # Visual studio code diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..16b40a6e --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lib/gtest/googletest"] + path = lib/gtest/googletest + url = https://github.com/google/googletest.git diff --git a/.hgignore b/.hgignore index 875f1d7d..5b346768 100644 --- a/.hgignore +++ b/.hgignore @@ -4,8 +4,7 @@ /buck-out/ /.buckconfig.local /.buckd -/lib/gtest/googletest-*/ /gentest/test.html # Visual studio code -.vscode \ No newline at end of file +.vscode diff --git a/.travis.yml b/.travis.yml index 5e205105..618dbb0a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,12 +14,17 @@ before_install: - brew update - brew tap facebook/fb - brew install buck + - brew cask install java - brew outdated xctool || brew upgrade xctool + - brew install mono + - export JAVA_HOME=$(/usr/libexec/java_home -v 1.8) + - export PATH=$JAVA_HOME/bin:$PATH script: - - buck test //:CSSLayout + - buck test //:yoga - buck test //java:java - - buck test //uikit/CSSLayout:CSSLayout - - buck run //benchmark:benchmark + - buck test //YogaKit:YogaKit --config cxx.default_platform=iphonesimulator-x86_64 --config cxx.cflags=-DTRAVIS_CI + - sh csharp/tests/Facebook.Yoga/test_macos.sh + - buck run //benchmark:benchmark - git checkout HEAD^ - - buck run //benchmark:benchmark + - buck run //benchmark:benchmark diff --git a/BUCK b/BUCK index 7c7358ff..09e39b43 100644 --- a/BUCK +++ b/BUCK @@ -5,7 +5,7 @@ # 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_defs('//CSSLAYOUT_DEFS') +include_defs('//YOGA_DEFS') BASE_COMPILER_FLAGS = [ '-fno-omit-frame-pointer', @@ -20,18 +20,20 @@ GMOCK_OVERRIDE_FLAGS = [ '-Wno-inconsistent-missing-override', ] -COMPILER_FLAGS = BASE_COMPILER_FLAGS + ['-std=c11'] +COMPILER_FLAGS = BASE_COMPILER_FLAGS + ['-std=c11', '-fPIC'] TEST_COMPILER_FLAGS = BASE_COMPILER_FLAGS + GMOCK_OVERRIDE_FLAGS + ['-std=c++11'] cxx_library( - name = 'CSSLayout', - srcs = glob(['CSSLayout/*.c']), + name = 'yoga', + soname = 'libyogacore.$(ext)', + srcs = glob(['yoga/*.c']), tests=[':tests'], - exported_headers = subdir_glob([('', 'CSSLayout/*.h')]), + exported_headers = subdir_glob([('', 'yoga/*.h')]), header_namespace = '', - force_static = True, compiler_flags = COMPILER_FLAGS, - deps = [], + deps = [] if THIS_IS_FBOBJC else [ + yoga_dep('lib/fb:ndklog'), + ], visibility = ['PUBLIC'], ) @@ -41,7 +43,7 @@ cxx_test( srcs = glob(['tests/*.cpp']), compiler_flags = TEST_COMPILER_FLAGS, deps = [ - ':CSSLayout', + ':yoga', GTEST_TARGET, ], visibility = ['PUBLIC'], diff --git a/CONTRIBUTING b/CONTRIBUTING index eac38f3d..07c37f21 100644 --- a/CONTRIBUTING +++ b/CONTRIBUTING @@ -1,10 +1,7 @@ -# Contributing to css-layout +# Contributing to yoga We want to make contributing to this project as easy and transparent as possible. -## Our Development Process -All the development is happening on GitHub first and we have internal tools to sync down to Facebook codebase. - ## Pull Requests We actively welcome your pull requests. 1. Fork the repo and create your branch from `master`. @@ -32,5 +29,5 @@ outlined on that page and do not file a public issue. * format.sh ## License -By contributing to css-layout, you agree that your contributions will be licensed +By contributing to yoga, you agree that your contributions will be licensed under its BSD license. diff --git a/CSSLayout/CSSLayout.c b/CSSLayout/CSSLayout.c deleted file mode 100644 index 31792c2e..00000000 --- a/CSSLayout/CSSLayout.c +++ /dev/null @@ -1,2462 +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 - -#include "CSSLayout.h" -#include "CSSNodeList.h" - -#ifdef _MSC_VER -#include -#define isnan _isnan - -/* 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 - -typedef struct CSSCachedMeasurement { - float availableWidth; - float availableHeight; - CSSMeasureMode widthMeasureMode; - CSSMeasureMode heightMeasureMode; - - float computedWidth; - float computedHeight; -} CSSCachedMeasurement; - -// This value was chosen based on empiracle data. Even the most complicated -// layouts should not require more than 16 entries to fit within the cache. -enum { CSS_MAX_CACHED_RESULT_COUNT = 16 }; - -typedef struct CSSLayout { - float position[4]; - float dimensions[2]; - CSSDirection direction; - - float computedFlexBasis; - - // Instead of recomputing the entire layout every single time, we - // cache some information to break early when nothing changed - uint32_t generationCount; - CSSDirection lastParentDirection; - - uint32_t nextCachedMeasurementsIndex; - CSSCachedMeasurement cachedMeasurements[CSS_MAX_CACHED_RESULT_COUNT]; - float measuredDimensions[2]; - - CSSCachedMeasurement cachedLayout; -} CSSLayout; - -typedef struct CSSStyle { - CSSDirection direction; - CSSFlexDirection flexDirection; - CSSJustify justifyContent; - CSSAlign alignContent; - CSSAlign alignItems; - CSSAlign alignSelf; - CSSPositionType positionType; - CSSWrapType flexWrap; - CSSOverflow overflow; - float flex; - float flexGrow; - float flexShrink; - float flexBasis; - float margin[CSSEdgeCount]; - float position[CSSEdgeCount]; - float padding[CSSEdgeCount]; - float border[CSSEdgeCount]; - float dimensions[2]; - float minDimensions[2]; - float maxDimensions[2]; -} CSSStyle; - -typedef struct CSSNode { - CSSStyle style; - CSSLayout layout; - uint32_t lineIndex; - bool hasNewLayout; - bool isTextNode; - CSSNodeRef parent; - CSSNodeListRef children; - bool isDirty; - bool isVisible; - - struct CSSNode *nextChild; - - CSSMeasureFunc measure; - CSSPrintFunc print; - void *context; -} CSSNode; - -static void _CSSNodeMarkDirty(const CSSNodeRef node); - -#ifdef ANDROID -#include -static int _csslayoutAndroidLog(const char *format, ...) { - va_list args; - va_start(args, format); - const int result = __android_log_vprint(ANDROID_LOG_DEBUG, "css-layout", format, args); - va_end(args); - return result; -} -static CSSLogger gLogger = &_csslayoutAndroidLog; -#else -static CSSLogger gLogger = &printf; -#endif - -static inline float computedEdgeValue(const float edges[CSSEdgeCount], - const CSSEdge edge, - const float defaultValue) { - CSS_ASSERT(edge <= CSSEdgeEnd, "Cannot get computed value of multi-edge shorthands"); - - if (!CSSValueIsUndefined(edges[edge])) { - return edges[edge]; - } - - if ((edge == CSSEdgeTop || edge == CSSEdgeBottom) && - !CSSValueIsUndefined(edges[CSSEdgeVertical])) { - return edges[CSSEdgeVertical]; - } - - if ((edge == CSSEdgeLeft || edge == CSSEdgeRight || edge == CSSEdgeStart || edge == CSSEdgeEnd) && - !CSSValueIsUndefined(edges[CSSEdgeHorizontal])) { - return edges[CSSEdgeHorizontal]; - } - - if (!CSSValueIsUndefined(edges[CSSEdgeAll])) { - return edges[CSSEdgeAll]; - } - - if (edge == CSSEdgeStart || edge == CSSEdgeEnd) { - return CSSUndefined; - } - - return defaultValue; -} - -static int32_t gNodeInstanceCount = 0; - -CSSNodeRef CSSNodeNew(void) { - const CSSNodeRef node = calloc(1, sizeof(CSSNode)); - CSS_ASSERT(node, "Could not allocate memory for node"); - gNodeInstanceCount++; - - CSSNodeInit(node); - return node; -} - -void CSSNodeFree(const CSSNodeRef node) { - if (node->parent) { - CSSNodeListDelete(node->parent->children, node); - node->parent = NULL; - } - - const uint32_t childCount = CSSNodeChildCount(node); - for (uint32_t i = 0; i < childCount; i++) { - const CSSNodeRef child = CSSNodeGetChild(node, i); - child->parent = NULL; - } - - CSSNodeListFree(node->children); - free(node); - gNodeInstanceCount--; -} - -void CSSNodeFreeRecursive(const CSSNodeRef root) { - while (CSSNodeChildCount(root) > 0) { - const CSSNodeRef child = CSSNodeGetChild(root, 0); - CSSNodeRemoveChild(root, child); - CSSNodeFreeRecursive(child); - } - CSSNodeFree(root); -} - -void CSSNodeReset(const CSSNodeRef node) { - CSS_ASSERT(CSSNodeChildCount(node) == 0, "Cannot reset a node which still has children attached"); - CSS_ASSERT(node->parent == NULL, "Cannot reset a node still attached to a parent"); - - CSSNodeListFree(node->children); - memset(node, 0, sizeof(CSSNode)); - CSSNodeInit(node); -} - -int32_t CSSNodeGetInstanceCount(void) { - return gNodeInstanceCount; -} - -void CSSNodeInit(const CSSNodeRef node) { - node->parent = NULL; - node->children = NULL; - node->hasNewLayout = true; - node->isDirty = false; - node->isVisible = true; - - node->style.flex = CSSUndefined; - node->style.flexGrow = CSSUndefined; - node->style.flexShrink = CSSUndefined; - node->style.flexBasis = CSSUndefined; - - node->style.alignItems = CSSAlignStretch; - node->style.alignContent = CSSAlignFlexStart; - - node->style.direction = CSSDirectionInherit; - node->style.flexDirection = CSSFlexDirectionColumn; - - node->style.overflow = CSSOverflowVisible; - - // Some of the fields default to undefined and not 0 - node->style.dimensions[CSSDimensionWidth] = CSSUndefined; - node->style.dimensions[CSSDimensionHeight] = CSSUndefined; - - node->style.minDimensions[CSSDimensionWidth] = CSSUndefined; - node->style.minDimensions[CSSDimensionHeight] = CSSUndefined; - - node->style.maxDimensions[CSSDimensionWidth] = CSSUndefined; - node->style.maxDimensions[CSSDimensionHeight] = CSSUndefined; - - for (CSSEdge edge = CSSEdgeLeft; edge < CSSEdgeCount; edge++) { - node->style.position[edge] = CSSUndefined; - node->style.margin[edge] = CSSUndefined; - node->style.padding[edge] = CSSUndefined; - node->style.border[edge] = CSSUndefined; - } - - node->layout.dimensions[CSSDimensionWidth] = CSSUndefined; - node->layout.dimensions[CSSDimensionHeight] = CSSUndefined; - - // Such that the comparison is always going to be false - node->layout.lastParentDirection = (CSSDirection) -1; - node->layout.nextCachedMeasurementsIndex = 0; - node->layout.computedFlexBasis = CSSUndefined; - - node->layout.measuredDimensions[CSSDimensionWidth] = CSSUndefined; - node->layout.measuredDimensions[CSSDimensionHeight] = CSSUndefined; - node->layout.cachedLayout.widthMeasureMode = (CSSMeasureMode) -1; - node->layout.cachedLayout.heightMeasureMode = (CSSMeasureMode) -1; - node->layout.cachedLayout.computedWidth = -1; - node->layout.cachedLayout.computedHeight = -1; -} - -static void _CSSNodeMarkDirty(const CSSNodeRef node) { - if (!node->isDirty) { - node->isDirty = true; - node->layout.computedFlexBasis = CSSUndefined; - if (node->parent) { - _CSSNodeMarkDirty(node->parent); - } - } -} - -void CSSNodeInsertChild(const CSSNodeRef node, const CSSNodeRef child, const uint32_t index) { - CSS_ASSERT(child->parent == NULL, "Child already has a parent, it must be removed first."); - CSSNodeListInsert(&node->children, child, index); - child->parent = node; - _CSSNodeMarkDirty(node); -} - -void CSSNodeRemoveChild(const CSSNodeRef node, const CSSNodeRef child) { - CSSNodeListDelete(node->children, child); - child->parent = NULL; - _CSSNodeMarkDirty(node); -} - -CSSNodeRef CSSNodeGetChild(const CSSNodeRef node, const uint32_t index) { - return CSSNodeListGet(node->children, index); -} - -inline uint32_t CSSNodeChildCount(const CSSNodeRef node) { - return CSSNodeListCount(node->children); -} - -void CSSNodeMarkDirty(const CSSNodeRef node) { - CSS_ASSERT(node->measure != NULL || CSSNodeChildCount(node) > 0, - "Only leaf nodes with custom measure functions" - "should manually mark themselves as dirty"); - _CSSNodeMarkDirty(node); -} - -bool CSSNodeIsDirty(const CSSNodeRef node) { - return node->isDirty; -} - -void CSSNodeHide(const CSSNodeRef node) { - node->isVisible = false; - node->isDirty = false; /* See https://github.com/facebook/css-layout/issues/241 */ - _CSSNodeMarkDirty(node); -} - -void CSSNodeShow(const CSSNodeRef node) { - node->isVisible = true; - node->isDirty = false; /* See https://github.com/facebook/css-layout/issues/241 */ - _CSSNodeMarkDirty(node); -} - -WIN_EXPORT bool CSSNodeIsVisible(const CSSNodeRef node) { - return node->isVisible; -} - -inline float CSSNodeStyleGetFlexGrow(CSSNodeRef node) { - if (!CSSValueIsUndefined(node->style.flexGrow)) { - return node->style.flexGrow; - } - if (!CSSValueIsUndefined(node->style.flex) && node->style.flex > 0) { - return node->style.flex; - } - return 0; -} - -inline float CSSNodeStyleGetFlexShrink(CSSNodeRef node) { - if (!CSSValueIsUndefined(node->style.flexShrink)) { - return node->style.flexShrink; - } - if (!CSSValueIsUndefined(node->style.flex) && node->style.flex < 0) { - return -node->style.flex; - } - return 0; -} - -inline float CSSNodeStyleGetFlexBasis(CSSNodeRef node) { - if (!CSSValueIsUndefined(node->style.flexBasis)) { - return node->style.flexBasis; - } - if (!CSSValueIsUndefined(node->style.flex)) { - return node->style.flex > 0 ? 0 : CSSUndefined; - } - return CSSUndefined; -} - -void CSSNodeStyleSetFlex(const CSSNodeRef node, const float flex) { - if (node->style.flex != flex) { - node->style.flex = flex; - _CSSNodeMarkDirty(node); - } -} - -#define CSS_NODE_PROPERTY_IMPL(type, name, paramName, instanceName) \ - void CSSNodeSet##name(const CSSNodeRef node, type paramName) { \ - node->instanceName = paramName; \ - } \ - \ - type CSSNodeGet##name(const CSSNodeRef node) { \ - return node->instanceName; \ - } - -#define CSS_NODE_STYLE_PROPERTY_SETTER_IMPL(type, name, paramName, instanceName) \ - void CSSNodeStyleSet##name(const CSSNodeRef node, const type paramName) { \ - if (node->style.instanceName != paramName) { \ - node->style.instanceName = paramName; \ - _CSSNodeMarkDirty(node); \ - } \ - } - -#define CSS_NODE_STYLE_PROPERTY_IMPL(type, name, paramName, instanceName) \ - CSS_NODE_STYLE_PROPERTY_SETTER_IMPL(type, name, paramName, instanceName) \ - \ - type CSSNodeStyleGet##name(const CSSNodeRef node) { \ - return node->style.instanceName; \ - } - -#define CSS_NODE_STYLE_EDGE_PROPERTY_IMPL(type, name, paramName, instanceName, defaultValue) \ - void CSSNodeStyleSet##name(const CSSNodeRef node, const CSSEdge edge, const type paramName) { \ - if (node->style.instanceName[edge] != paramName) { \ - node->style.instanceName[edge] = paramName; \ - _CSSNodeMarkDirty(node); \ - } \ - } \ - \ - type CSSNodeStyleGet##name(const CSSNodeRef node, const CSSEdge edge) { \ - return computedEdgeValue(node->style.instanceName, edge, defaultValue); \ - } - -#define CSS_NODE_LAYOUT_PROPERTY_IMPL(type, name, instanceName) \ - type CSSNodeLayoutGet##name(const CSSNodeRef node) { \ - return node->layout.instanceName; \ - } - -CSS_NODE_PROPERTY_IMPL(void *, Context, context, context); -CSS_NODE_PROPERTY_IMPL(CSSMeasureFunc, MeasureFunc, measureFunc, measure); -CSS_NODE_PROPERTY_IMPL(CSSPrintFunc, PrintFunc, printFunc, print); -CSS_NODE_PROPERTY_IMPL(bool, IsTextnode, isTextNode, isTextNode); -CSS_NODE_PROPERTY_IMPL(bool, HasNewLayout, hasNewLayout, hasNewLayout); - -CSS_NODE_STYLE_PROPERTY_IMPL(CSSDirection, Direction, direction, direction); -CSS_NODE_STYLE_PROPERTY_IMPL(CSSFlexDirection, FlexDirection, flexDirection, flexDirection); -CSS_NODE_STYLE_PROPERTY_IMPL(CSSJustify, JustifyContent, justifyContent, justifyContent); -CSS_NODE_STYLE_PROPERTY_IMPL(CSSAlign, AlignContent, alignContent, alignContent); -CSS_NODE_STYLE_PROPERTY_IMPL(CSSAlign, AlignItems, alignItems, alignItems); -CSS_NODE_STYLE_PROPERTY_IMPL(CSSAlign, AlignSelf, alignSelf, alignSelf); -CSS_NODE_STYLE_PROPERTY_IMPL(CSSPositionType, PositionType, positionType, positionType); -CSS_NODE_STYLE_PROPERTY_IMPL(CSSWrapType, FlexWrap, flexWrap, flexWrap); -CSS_NODE_STYLE_PROPERTY_IMPL(CSSOverflow, Overflow, overflow, overflow); - -CSS_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexGrow, flexGrow, flexGrow); -CSS_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexShrink, flexShrink, flexShrink); -CSS_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexBasis, flexBasis, flexBasis); - -CSS_NODE_STYLE_EDGE_PROPERTY_IMPL(float, Position, position, position, CSSUndefined); -CSS_NODE_STYLE_EDGE_PROPERTY_IMPL(float, Margin, margin, margin, 0); -CSS_NODE_STYLE_EDGE_PROPERTY_IMPL(float, Padding, padding, padding, 0); -CSS_NODE_STYLE_EDGE_PROPERTY_IMPL(float, Border, border, border, 0); - -CSS_NODE_STYLE_PROPERTY_IMPL(float, Width, width, dimensions[CSSDimensionWidth]); -CSS_NODE_STYLE_PROPERTY_IMPL(float, Height, height, dimensions[CSSDimensionHeight]); -CSS_NODE_STYLE_PROPERTY_IMPL(float, MinWidth, minWidth, minDimensions[CSSDimensionWidth]); -CSS_NODE_STYLE_PROPERTY_IMPL(float, MinHeight, minHeight, minDimensions[CSSDimensionHeight]); -CSS_NODE_STYLE_PROPERTY_IMPL(float, MaxWidth, maxWidth, maxDimensions[CSSDimensionWidth]); -CSS_NODE_STYLE_PROPERTY_IMPL(float, MaxHeight, maxHeight, maxDimensions[CSSDimensionHeight]); - -CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Left, position[CSSEdgeLeft]); -CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Top, position[CSSEdgeTop]); -CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Right, position[CSSEdgeRight]); -CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Bottom, position[CSSEdgeBottom]); -CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Width, dimensions[CSSDimensionWidth]); -CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Height, dimensions[CSSDimensionHeight]); -CSS_NODE_LAYOUT_PROPERTY_IMPL(CSSDirection, Direction, direction); - -uint32_t gCurrentGenerationCount = 0; - -bool layoutNodeInternal(const CSSNodeRef node, - const float availableWidth, - const float availableHeight, - const CSSDirection parentDirection, - const CSSMeasureMode widthMeasureMode, - const CSSMeasureMode heightMeasureMode, - const bool performLayout, - const char *reason); - -inline bool CSSValueIsUndefined(const float value) { - return isnan(value); -} - -static inline bool eq(const float a, const float b) { - if (CSSValueIsUndefined(a)) { - return CSSValueIsUndefined(b); - } - return fabs(a - b) < 0.0001; -} - -static void indent(const uint32_t n) { - for (uint32_t i = 0; i < n; i++) { - gLogger(" "); - } -} - -static void printNumberIfNotZero(const char *str, const float number) { - if (!eq(number, 0)) { - gLogger("%s: %g, ", str, number); - } -} - -static void printNumberIfNotUndefined(const char *str, const float number) { - if (!CSSValueIsUndefined(number)) { - gLogger("%s: %g, ", str, number); - } -} - -static bool eqFour(const float four[4]) { - return eq(four[0], four[1]) && eq(four[0], four[2]) && eq(four[0], four[3]); -} - -static void _CSSNodePrint(const CSSNodeRef node, - const CSSPrintOptions options, - const uint32_t level) { - indent(level); - gLogger("{"); - - if (node->print) { - node->print(node); - } - - if (options & CSSPrintOptionsLayout) { - gLogger("layout: {"); - gLogger("width: %g, ", node->layout.dimensions[CSSDimensionWidth]); - gLogger("height: %g, ", node->layout.dimensions[CSSDimensionHeight]); - gLogger("top: %g, ", node->layout.position[CSSEdgeTop]); - gLogger("left: %g", node->layout.position[CSSEdgeLeft]); - gLogger("}, "); - } - - if (options & CSSPrintOptionsStyle) { - if (node->style.flexDirection == CSSFlexDirectionColumn) { - gLogger("flexDirection: 'column', "); - } else if (node->style.flexDirection == CSSFlexDirectionColumnReverse) { - gLogger("flexDirection: 'column-reverse', "); - } else if (node->style.flexDirection == CSSFlexDirectionRow) { - gLogger("flexDirection: 'row', "); - } else if (node->style.flexDirection == CSSFlexDirectionRowReverse) { - gLogger("flexDirection: 'row-reverse', "); - } - - if (node->style.justifyContent == CSSJustifyCenter) { - gLogger("justifyContent: 'center', "); - } else if (node->style.justifyContent == CSSJustifyFlexEnd) { - gLogger("justifyContent: 'flex-end', "); - } else if (node->style.justifyContent == CSSJustifySpaceAround) { - gLogger("justifyContent: 'space-around', "); - } else if (node->style.justifyContent == CSSJustifySpaceBetween) { - gLogger("justifyContent: 'space-between', "); - } - - if (node->style.alignItems == CSSAlignCenter) { - gLogger("alignItems: 'center', "); - } else if (node->style.alignItems == CSSAlignFlexEnd) { - gLogger("alignItems: 'flex-end', "); - } else if (node->style.alignItems == CSSAlignStretch) { - gLogger("alignItems: 'stretch', "); - } - - if (node->style.alignContent == CSSAlignCenter) { - gLogger("alignContent: 'center', "); - } else if (node->style.alignContent == CSSAlignFlexEnd) { - gLogger("alignContent: 'flex-end', "); - } else if (node->style.alignContent == CSSAlignStretch) { - gLogger("alignContent: 'stretch', "); - } - - if (node->style.alignSelf == CSSAlignFlexStart) { - gLogger("alignSelf: 'flex-start', "); - } else if (node->style.alignSelf == CSSAlignCenter) { - gLogger("alignSelf: 'center', "); - } else if (node->style.alignSelf == CSSAlignFlexEnd) { - gLogger("alignSelf: 'flex-end', "); - } else if (node->style.alignSelf == CSSAlignStretch) { - gLogger("alignSelf: 'stretch', "); - } - - printNumberIfNotUndefined("flexGrow", CSSNodeStyleGetFlexGrow(node)); - printNumberIfNotUndefined("flexShrink", CSSNodeStyleGetFlexShrink(node)); - printNumberIfNotUndefined("flexBasis", CSSNodeStyleGetFlexBasis(node)); - - if (node->style.overflow == CSSOverflowHidden) { - gLogger("overflow: 'hidden', "); - } else if (node->style.overflow == CSSOverflowVisible) { - gLogger("overflow: 'visible', "); - } else if (node->style.overflow == CSSOverflowScroll) { - gLogger("overflow: 'scroll', "); - } - - if (eqFour(node->style.margin)) { - printNumberIfNotZero("margin", computedEdgeValue(node->style.margin, CSSEdgeLeft, 0)); - } else { - printNumberIfNotZero("marginLeft", computedEdgeValue(node->style.margin, CSSEdgeLeft, 0)); - printNumberIfNotZero("marginRight", computedEdgeValue(node->style.margin, CSSEdgeRight, 0)); - printNumberIfNotZero("marginTop", computedEdgeValue(node->style.margin, CSSEdgeTop, 0)); - printNumberIfNotZero("marginBottom", computedEdgeValue(node->style.margin, CSSEdgeBottom, 0)); - printNumberIfNotZero("marginStart", computedEdgeValue(node->style.margin, CSSEdgeStart, 0)); - printNumberIfNotZero("marginEnd", computedEdgeValue(node->style.margin, CSSEdgeEnd, 0)); - } - - if (eqFour(node->style.padding)) { - printNumberIfNotZero("padding", computedEdgeValue(node->style.padding, CSSEdgeLeft, 0)); - } else { - printNumberIfNotZero("paddingLeft", computedEdgeValue(node->style.padding, CSSEdgeLeft, 0)); - printNumberIfNotZero("paddingRight", computedEdgeValue(node->style.padding, CSSEdgeRight, 0)); - printNumberIfNotZero("paddingTop", computedEdgeValue(node->style.padding, CSSEdgeTop, 0)); - printNumberIfNotZero("paddingBottom", - computedEdgeValue(node->style.padding, CSSEdgeBottom, 0)); - printNumberIfNotZero("paddingStart", computedEdgeValue(node->style.padding, CSSEdgeStart, 0)); - printNumberIfNotZero("paddingEnd", computedEdgeValue(node->style.padding, CSSEdgeEnd, 0)); - } - - if (eqFour(node->style.border)) { - printNumberIfNotZero("borderWidth", computedEdgeValue(node->style.border, CSSEdgeLeft, 0)); - } else { - printNumberIfNotZero("borderLeftWidth", - computedEdgeValue(node->style.border, CSSEdgeLeft, 0)); - printNumberIfNotZero("borderRightWidth", - computedEdgeValue(node->style.border, CSSEdgeRight, 0)); - printNumberIfNotZero("borderTopWidth", computedEdgeValue(node->style.border, CSSEdgeTop, 0)); - printNumberIfNotZero("borderBottomWidth", - computedEdgeValue(node->style.border, CSSEdgeBottom, 0)); - printNumberIfNotZero("borderStartWidth", - computedEdgeValue(node->style.border, CSSEdgeStart, 0)); - printNumberIfNotZero("borderEndWidth", computedEdgeValue(node->style.border, CSSEdgeEnd, 0)); - } - - printNumberIfNotUndefined("width", node->style.dimensions[CSSDimensionWidth]); - printNumberIfNotUndefined("height", node->style.dimensions[CSSDimensionHeight]); - printNumberIfNotUndefined("maxWidth", node->style.maxDimensions[CSSDimensionWidth]); - printNumberIfNotUndefined("maxHeight", node->style.maxDimensions[CSSDimensionHeight]); - printNumberIfNotUndefined("minWidth", node->style.minDimensions[CSSDimensionWidth]); - printNumberIfNotUndefined("minHeight", node->style.minDimensions[CSSDimensionHeight]); - - if (node->style.positionType == CSSPositionTypeAbsolute) { - gLogger("position: 'absolute', "); - } - - printNumberIfNotUndefined("left", - computedEdgeValue(node->style.position, CSSEdgeLeft, CSSUndefined)); - printNumberIfNotUndefined("right", - computedEdgeValue(node->style.position, CSSEdgeRight, CSSUndefined)); - printNumberIfNotUndefined("top", - computedEdgeValue(node->style.position, CSSEdgeTop, CSSUndefined)); - printNumberIfNotUndefined("bottom", - computedEdgeValue(node->style.position, CSSEdgeBottom, CSSUndefined)); - } - - const uint32_t childCount = CSSNodeListCount(node->children); - if (options & CSSPrintOptionsChildren && childCount > 0) { - gLogger("children: [\n"); - for (uint32_t i = 0; i < childCount; i++) { - _CSSNodePrint(CSSNodeGetChild(node, i), options, level + 1); - } - indent(level); - gLogger("]},\n"); - } else { - gLogger("},\n"); - } -} - -void CSSNodePrint(const CSSNodeRef node, const CSSPrintOptions options) { - _CSSNodePrint(node, options, 0); -} - -static const CSSEdge leading[4] = { - [CSSFlexDirectionColumn] = CSSEdgeTop, - [CSSFlexDirectionColumnReverse] = CSSEdgeBottom, - [CSSFlexDirectionRow] = CSSEdgeLeft, - [CSSFlexDirectionRowReverse] = CSSEdgeRight, -}; -static const CSSEdge trailing[4] = { - [CSSFlexDirectionColumn] = CSSEdgeBottom, - [CSSFlexDirectionColumnReverse] = CSSEdgeTop, - [CSSFlexDirectionRow] = CSSEdgeRight, - [CSSFlexDirectionRowReverse] = CSSEdgeLeft, -}; -static const CSSEdge pos[4] = { - [CSSFlexDirectionColumn] = CSSEdgeTop, - [CSSFlexDirectionColumnReverse] = CSSEdgeBottom, - [CSSFlexDirectionRow] = CSSEdgeLeft, - [CSSFlexDirectionRowReverse] = CSSEdgeRight, -}; -static const CSSDimension dim[4] = { - [CSSFlexDirectionColumn] = CSSDimensionHeight, - [CSSFlexDirectionColumnReverse] = CSSDimensionHeight, - [CSSFlexDirectionRow] = CSSDimensionWidth, - [CSSFlexDirectionRowReverse] = CSSDimensionWidth, -}; - -static inline bool isRowDirection(const CSSFlexDirection flexDirection) { - return flexDirection == CSSFlexDirectionRow || flexDirection == CSSFlexDirectionRowReverse; -} - -static inline bool isColumnDirection(const CSSFlexDirection flexDirection) { - return flexDirection == CSSFlexDirectionColumn || flexDirection == CSSFlexDirectionColumnReverse; -} - -static inline float getLeadingMargin(const CSSNodeRef node, const CSSFlexDirection axis) { - if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.margin[CSSEdgeStart])) { - return node->style.margin[CSSEdgeStart]; - } - - return computedEdgeValue(node->style.margin, leading[axis], 0); -} - -static float getTrailingMargin(const CSSNodeRef node, const CSSFlexDirection axis) { - if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.margin[CSSEdgeEnd])) { - return node->style.margin[CSSEdgeEnd]; - } - - return computedEdgeValue(node->style.margin, trailing[axis], 0); -} - -static float getLeadingPadding(const CSSNodeRef node, const CSSFlexDirection axis) { - if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.padding[CSSEdgeStart]) && - node->style.padding[CSSEdgeStart] >= 0) { - return node->style.padding[CSSEdgeStart]; - } - - return fmaxf(computedEdgeValue(node->style.padding, leading[axis], 0), 0); -} - -static float getTrailingPadding(const CSSNodeRef node, const CSSFlexDirection axis) { - if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.padding[CSSEdgeEnd]) && - node->style.padding[CSSEdgeEnd] >= 0) { - return node->style.padding[CSSEdgeEnd]; - } - - return fmaxf(computedEdgeValue(node->style.padding, trailing[axis], 0), 0); -} - -static float getLeadingBorder(const CSSNodeRef node, const CSSFlexDirection axis) { - if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.border[CSSEdgeStart]) && - node->style.border[CSSEdgeStart] >= 0) { - return node->style.border[CSSEdgeStart]; - } - - return fmaxf(computedEdgeValue(node->style.border, leading[axis], 0), 0); -} - -static float getTrailingBorder(const CSSNodeRef node, const CSSFlexDirection axis) { - if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.border[CSSEdgeEnd]) && - node->style.border[CSSEdgeEnd] >= 0) { - return node->style.border[CSSEdgeEnd]; - } - - return fmaxf(computedEdgeValue(node->style.border, trailing[axis], 0), 0); -} - -static inline float getLeadingPaddingAndBorder(const CSSNodeRef node, const CSSFlexDirection axis) { - return getLeadingPadding(node, axis) + getLeadingBorder(node, axis); -} - -static inline float getTrailingPaddingAndBorder(const CSSNodeRef node, - const CSSFlexDirection axis) { - return getTrailingPadding(node, axis) + getTrailingBorder(node, axis); -} - -static inline float getMarginAxis(const CSSNodeRef node, const CSSFlexDirection axis) { - return getLeadingMargin(node, axis) + getTrailingMargin(node, axis); -} - -static inline float getPaddingAndBorderAxis(const CSSNodeRef node, const CSSFlexDirection axis) { - return getLeadingPaddingAndBorder(node, axis) + getTrailingPaddingAndBorder(node, axis); -} - -static inline CSSAlign getAlignItem(const CSSNodeRef node, const CSSNodeRef child) { - return child->style.alignSelf == CSSAlignAuto ? node->style.alignItems : child->style.alignSelf; -} - -static inline CSSDirection resolveDirection(const CSSNodeRef node, - const CSSDirection parentDirection) { - if (node->style.direction == CSSDirectionInherit) { - return parentDirection > CSSDirectionInherit ? parentDirection : CSSDirectionLTR; - } else { - return node->style.direction; - } -} - -static inline CSSFlexDirection resolveAxis(const CSSFlexDirection flexDirection, - const CSSDirection direction) { - if (direction == CSSDirectionRTL) { - if (flexDirection == CSSFlexDirectionRow) { - return CSSFlexDirectionRowReverse; - } else if (flexDirection == CSSFlexDirectionRowReverse) { - return CSSFlexDirectionRow; - } - } - - return flexDirection; -} - -static CSSFlexDirection getCrossFlexDirection(const CSSFlexDirection flexDirection, - const CSSDirection direction) { - return isColumnDirection(flexDirection) ? resolveAxis(CSSFlexDirectionRow, direction) - : CSSFlexDirectionColumn; -} - -static inline bool isFlex(const CSSNodeRef node) { - return (node->style.positionType == CSSPositionTypeRelative && - (node->style.flexGrow != 0 || node->style.flexShrink != 0 || node->style.flex != 0)); -} - -static inline float getDimWithMargin(const CSSNodeRef node, const CSSFlexDirection axis) { - return node->layout.measuredDimensions[dim[axis]] + getLeadingMargin(node, axis) + - getTrailingMargin(node, axis); -} - -static inline bool isStyleDimDefined(const CSSNodeRef node, const CSSFlexDirection axis) { - const float value = node->style.dimensions[dim[axis]]; - return !CSSValueIsUndefined(value) && value >= 0.0; -} - -static inline bool isLayoutDimDefined(const CSSNodeRef node, const CSSFlexDirection axis) { - const float value = node->layout.measuredDimensions[dim[axis]]; - return !CSSValueIsUndefined(value) && value >= 0.0; -} - -static inline bool isLeadingPosDefined(const CSSNodeRef node, const CSSFlexDirection axis) { - return (isRowDirection(axis) && - !CSSValueIsUndefined( - computedEdgeValue(node->style.position, CSSEdgeStart, CSSUndefined))) || - !CSSValueIsUndefined(computedEdgeValue(node->style.position, leading[axis], CSSUndefined)); -} - -static inline bool isTrailingPosDefined(const CSSNodeRef node, const CSSFlexDirection axis) { - return (isRowDirection(axis) && - !CSSValueIsUndefined( - computedEdgeValue(node->style.position, CSSEdgeEnd, CSSUndefined))) || - !CSSValueIsUndefined( - computedEdgeValue(node->style.position, trailing[axis], CSSUndefined)); -} - -static float getLeadingPosition(const CSSNodeRef node, const CSSFlexDirection axis) { - if (isRowDirection(axis)) { - const float leadingPosition = - computedEdgeValue(node->style.position, CSSEdgeStart, CSSUndefined); - if (!CSSValueIsUndefined(leadingPosition)) { - return leadingPosition; - } - } - - const float leadingPosition = - computedEdgeValue(node->style.position, leading[axis], CSSUndefined); - - return CSSValueIsUndefined(leadingPosition) ? 0 : leadingPosition; -} - -static float getTrailingPosition(const CSSNodeRef node, const CSSFlexDirection axis) { - if (isRowDirection(axis)) { - const float trailingPosition = - computedEdgeValue(node->style.position, CSSEdgeEnd, CSSUndefined); - if (!CSSValueIsUndefined(trailingPosition)) { - return trailingPosition; - } - } - - const float trailingPosition = - computedEdgeValue(node->style.position, trailing[axis], CSSUndefined); - - return CSSValueIsUndefined(trailingPosition) ? 0 : trailingPosition; -} - -static float boundAxisWithinMinAndMax(const CSSNodeRef node, - const CSSFlexDirection axis, - const float value) { - float min = CSSUndefined; - float max = CSSUndefined; - - if (isColumnDirection(axis)) { - min = node->style.minDimensions[CSSDimensionHeight]; - max = node->style.maxDimensions[CSSDimensionHeight]; - } else if (isRowDirection(axis)) { - min = node->style.minDimensions[CSSDimensionWidth]; - max = node->style.maxDimensions[CSSDimensionWidth]; - } - - float boundValue = value; - - if (!CSSValueIsUndefined(max) && max >= 0.0 && boundValue > max) { - boundValue = max; - } - - if (!CSSValueIsUndefined(min) && min >= 0.0 && boundValue < min) { - boundValue = min; - } - - return boundValue; -} - -// Like boundAxisWithinMinAndMax but also ensures that the value doesn't go -// below the -// padding and border amount. -static inline float boundAxis(const CSSNodeRef node, - const CSSFlexDirection axis, - const float value) { - return fmaxf(boundAxisWithinMinAndMax(node, axis, value), getPaddingAndBorderAxis(node, axis)); -} - -static void setTrailingPosition(const CSSNodeRef node, - const CSSNodeRef child, - const CSSFlexDirection axis) { - const float size = child->layout.measuredDimensions[dim[axis]]; - child->layout.position[trailing[axis]] = - node->layout.measuredDimensions[dim[axis]] - size - child->layout.position[pos[axis]]; -} - -// If both left and right are defined, then use left. Otherwise return -// +left or -right depending on which is defined. -static float getRelativePosition(const CSSNodeRef node, const CSSFlexDirection axis) { - return isLeadingPosDefined(node, axis) ? getLeadingPosition(node, axis) - : -getTrailingPosition(node, axis); -} - -static void setPosition(const CSSNodeRef node, const CSSDirection direction) { - const CSSFlexDirection mainAxis = resolveAxis(node->style.flexDirection, direction); - const CSSFlexDirection crossAxis = getCrossFlexDirection(mainAxis, direction); - const float relativePositionMain = getRelativePosition(node, mainAxis); - const float relativePositionCross = getRelativePosition(node, crossAxis); - - node->layout.position[leading[mainAxis]] = - getLeadingMargin(node, mainAxis) + relativePositionMain; - node->layout.position[trailing[mainAxis]] = - getTrailingMargin(node, mainAxis) + relativePositionMain; - node->layout.position[leading[crossAxis]] = - getLeadingMargin(node, crossAxis) + relativePositionCross; - node->layout.position[trailing[crossAxis]] = - getTrailingMargin(node, crossAxis) + relativePositionCross; -} - -static void computeChildFlexBasis(const CSSNodeRef node, - const CSSNodeRef child, - const float width, - const CSSMeasureMode widthMode, - const float height, - const CSSMeasureMode heightMode, - const CSSDirection direction) { - const CSSFlexDirection mainAxis = resolveAxis(node->style.flexDirection, direction); - const bool isMainAxisRow = isRowDirection(mainAxis); - - float childWidth; - float childHeight; - CSSMeasureMode childWidthMeasureMode; - CSSMeasureMode childHeightMeasureMode; - - const bool isRowStyleDimDefined = isStyleDimDefined(child, CSSFlexDirectionRow); - const bool isColumnStyleDimDefined = isStyleDimDefined(child, CSSFlexDirectionColumn); - - if (!CSSValueIsUndefined(CSSNodeStyleGetFlexBasis(child)) && - !CSSValueIsUndefined(isMainAxisRow ? width : height)) { - if (CSSValueIsUndefined(child->layout.computedFlexBasis)) { - child->layout.computedFlexBasis = - fmaxf(CSSNodeStyleGetFlexBasis(child), getPaddingAndBorderAxis(child, mainAxis)); - } - } else if (isMainAxisRow && isRowStyleDimDefined) { - // The width is definite, so use that as the flex basis. - child->layout.computedFlexBasis = fmaxf(child->style.dimensions[CSSDimensionWidth], - getPaddingAndBorderAxis(child, CSSFlexDirectionRow)); - } else if (!isMainAxisRow && isColumnStyleDimDefined) { - // The height is definite, so use that as the flex basis. - child->layout.computedFlexBasis = fmaxf(child->style.dimensions[CSSDimensionHeight], - getPaddingAndBorderAxis(child, CSSFlexDirectionColumn)); - } else { - // Compute the flex basis and hypothetical main size (i.e. the clamped - // flex basis). - childWidth = CSSUndefined; - childHeight = CSSUndefined; - childWidthMeasureMode = CSSMeasureModeUndefined; - childHeightMeasureMode = CSSMeasureModeUndefined; - - if (isRowStyleDimDefined) { - childWidth = - child->style.dimensions[CSSDimensionWidth] + getMarginAxis(child, CSSFlexDirectionRow); - childWidthMeasureMode = CSSMeasureModeExactly; - } - if (isColumnStyleDimDefined) { - childHeight = child->style.dimensions[CSSDimensionHeight] + - getMarginAxis(child, CSSFlexDirectionColumn); - childHeightMeasureMode = CSSMeasureModeExactly; - } - - // The W3C spec doesn't say anything about the 'overflow' property, - // but all major browsers appear to implement the following logic. - if ((!isMainAxisRow && node->style.overflow == CSSOverflowScroll) || - node->style.overflow != CSSOverflowScroll) { - if (CSSValueIsUndefined(childWidth) && !CSSValueIsUndefined(width)) { - childWidth = width; - childWidthMeasureMode = CSSMeasureModeAtMost; - } - } - - if ((isMainAxisRow && node->style.overflow == CSSOverflowScroll) || - node->style.overflow != CSSOverflowScroll) { - if (CSSValueIsUndefined(childHeight) && !CSSValueIsUndefined(height)) { - childHeight = height; - childHeightMeasureMode = CSSMeasureModeAtMost; - } - } - - // 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 - if (!isMainAxisRow && !CSSValueIsUndefined(width) && !isRowStyleDimDefined && - widthMode == CSSMeasureModeExactly && getAlignItem(node, child) == CSSAlignStretch) { - childWidth = width; - childWidthMeasureMode = CSSMeasureModeExactly; - } - if (isMainAxisRow && !CSSValueIsUndefined(height) && !isColumnStyleDimDefined && - heightMode == CSSMeasureModeExactly && getAlignItem(node, child) == CSSAlignStretch) { - childHeight = height; - childHeightMeasureMode = CSSMeasureModeExactly; - } - - // Measure the child - layoutNodeInternal(child, - childWidth, - childHeight, - direction, - childWidthMeasureMode, - childHeightMeasureMode, - false, - "measure"); - - child->layout.computedFlexBasis = - fmaxf(isMainAxisRow ? child->layout.measuredDimensions[CSSDimensionWidth] - : child->layout.measuredDimensions[CSSDimensionHeight], - getPaddingAndBorderAxis(child, mainAxis)); - } -} - -static void absoluteLayoutChild(const CSSNodeRef node, - const CSSNodeRef child, - const float width, - const CSSMeasureMode widthMode, - const CSSDirection direction) { - const CSSFlexDirection mainAxis = resolveAxis(node->style.flexDirection, direction); - const CSSFlexDirection crossAxis = getCrossFlexDirection(mainAxis, direction); - const bool isMainAxisRow = isRowDirection(mainAxis); - - float childWidth = CSSUndefined; - float childHeight = CSSUndefined; - CSSMeasureMode childWidthMeasureMode = CSSMeasureModeUndefined; - CSSMeasureMode childHeightMeasureMode = CSSMeasureModeUndefined; - - if (isStyleDimDefined(child, CSSFlexDirectionRow)) { - childWidth = - child->style.dimensions[CSSDimensionWidth] + getMarginAxis(child, CSSFlexDirectionRow); - } else { - // If the child doesn't have a specified width, compute the width based - // on the left/right - // offsets if they're defined. - if (isLeadingPosDefined(child, CSSFlexDirectionRow) && - isTrailingPosDefined(child, CSSFlexDirectionRow)) { - childWidth = node->layout.measuredDimensions[CSSDimensionWidth] - - (getLeadingBorder(node, CSSFlexDirectionRow) + - getTrailingBorder(node, CSSFlexDirectionRow)) - - (getLeadingPosition(child, CSSFlexDirectionRow) + - getTrailingPosition(child, CSSFlexDirectionRow)); - childWidth = boundAxis(child, CSSFlexDirectionRow, childWidth); - } - } - - if (isStyleDimDefined(child, CSSFlexDirectionColumn)) { - childHeight = - child->style.dimensions[CSSDimensionHeight] + getMarginAxis(child, CSSFlexDirectionColumn); - } else { - // If the child doesn't have a specified height, compute the height - // based on the top/bottom - // offsets if they're defined. - if (isLeadingPosDefined(child, CSSFlexDirectionColumn) && - isTrailingPosDefined(child, CSSFlexDirectionColumn)) { - childHeight = node->layout.measuredDimensions[CSSDimensionHeight] - - (getLeadingBorder(node, CSSFlexDirectionColumn) + - getTrailingBorder(node, CSSFlexDirectionColumn)) - - (getLeadingPosition(child, CSSFlexDirectionColumn) + - getTrailingPosition(child, CSSFlexDirectionColumn)); - childHeight = boundAxis(child, CSSFlexDirectionColumn, childHeight); - } - } - - // If we're still missing one or the other dimension, measure the content. - if (CSSValueIsUndefined(childWidth) || CSSValueIsUndefined(childHeight)) { - childWidthMeasureMode = - CSSValueIsUndefined(childWidth) ? CSSMeasureModeUndefined : CSSMeasureModeExactly; - childHeightMeasureMode = - CSSValueIsUndefined(childHeight) ? CSSMeasureModeUndefined : CSSMeasureModeExactly; - - // According to the spec, if the main size is not definite and the - // child's inline axis is parallel to the main axis (i.e. it's - // horizontal), the child should be sized using "UNDEFINED" in - // the main size. Otherwise use "AT_MOST" in the cross axis. - if (!isMainAxisRow && CSSValueIsUndefined(childWidth) && widthMode != CSSMeasureModeUndefined) { - childWidth = width; - childWidthMeasureMode = CSSMeasureModeAtMost; - } - - layoutNodeInternal(child, - childWidth, - childHeight, - direction, - childWidthMeasureMode, - childHeightMeasureMode, - false, - "abs-measure"); - childWidth = child->layout.measuredDimensions[CSSDimensionWidth] + - getMarginAxis(child, CSSFlexDirectionRow); - childHeight = child->layout.measuredDimensions[CSSDimensionHeight] + - getMarginAxis(child, CSSFlexDirectionColumn); - } - - layoutNodeInternal(child, - childWidth, - childHeight, - direction, - CSSMeasureModeExactly, - CSSMeasureModeExactly, - true, - "abs-layout"); - - if (isTrailingPosDefined(child, mainAxis) && !isLeadingPosDefined(child, mainAxis)) { - child->layout.position[leading[mainAxis]] = node->layout.measuredDimensions[dim[mainAxis]] - - child->layout.measuredDimensions[dim[mainAxis]] - - getTrailingPosition(child, mainAxis); - } - - if (isTrailingPosDefined(child, crossAxis) && !isLeadingPosDefined(child, crossAxis)) { - child->layout.position[leading[crossAxis]] = node->layout.measuredDimensions[dim[crossAxis]] - - child->layout.measuredDimensions[dim[crossAxis]] - - getTrailingPosition(child, crossAxis); - } -} - -// -// This is the main routine that implements a subset of the flexbox layout -// algorithm -// described in the W3C CSS documentation: https://www.w3.org/TR/css3-flexbox/. -// -// 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. -// * The 'wrap' property supports only 'nowrap' (which is the default) or -// 'wrap'. The -// rarely-used 'wrap-reverse' is not supported. -// * Rather than allowing arbitrary combinations of flexGrow, flexShrink and -// flexBasis, this algorithm supports only the three most common -// combinations: -// flex: 0 is equiavlent to flex: 0 0 auto -// flex: n (where n is a positive value) is equivalent to flex: n 1 auto -// If POSITIVE_FLEX_IS_AUTO is 0, then it is equivalent to flex: n 0 0 -// This is faster because the content doesn't need to be measured, but -// it's -// less flexible because the basis is always 0 and can't be overriden -// with -// the width/height attributes. -// flex: -1 (or any negative value) is equivalent to flex: 0 1 auto -// * Margins cannot be specified as 'auto'. They must be specified in terms of -// pixel -// values, and the default value is 0. -// * The 'baseline' value is not supported for alignItems and alignSelf -// properties. -// * Values of width, maxWidth, minWidth, height, maxHeight and minHeight must -// be -// specified as pixel values, not as percentages. -// * There is no support for calculation of dimensions based on intrinsic -// aspect ratios -// (e.g. images). -// * 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 -// or CSSUndefined if the size is not available; interpretation depends on -// 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 -// from the spec (https://www.w3.org/TR/css3-sizing/#terms): -// - CSSMeasureModeUndefined: max content -// - CSSMeasureModeExactly: fill available -// - CSSMeasureModeAtMost: fit content -// -// When calling layoutNodeImpl and layoutNodeInternal, if the caller passes -// an available size of -// undefined then it must also pass a measure mode of CSSMeasureModeUndefined -// in that dimension. -// -static void layoutNodeImpl(const CSSNodeRef node, - const float availableWidth, - const float availableHeight, - const CSSDirection parentDirection, - const CSSMeasureMode widthMeasureMode, - const CSSMeasureMode heightMeasureMode, - const bool performLayout) { - - CSS_ASSERT(CSSValueIsUndefined(availableWidth) ? widthMeasureMode == CSSMeasureModeUndefined - : true, - "availableWidth is indefinite so widthMeasureMode must be " - "CSSMeasureModeUndefined"); - CSS_ASSERT(CSSValueIsUndefined(availableHeight) ? heightMeasureMode == CSSMeasureModeUndefined - : true, - "availableHeight is indefinite so heightMeasureMode must be " - "CSSMeasureModeUndefined"); - - const float paddingAndBorderAxisRow = getPaddingAndBorderAxis(node, CSSFlexDirectionRow); - const float paddingAndBorderAxisColumn = getPaddingAndBorderAxis(node, CSSFlexDirectionColumn); - const float marginAxisRow = getMarginAxis(node, CSSFlexDirectionRow); - const float marginAxisColumn = getMarginAxis(node, CSSFlexDirectionColumn); - - // Set the resolved resolution in the node's layout. - const CSSDirection direction = resolveDirection(node, parentDirection); - node->layout.direction = direction; - - // For content (text) nodes, determine the dimensions based on the text - // contents. - if (node->measure && CSSNodeChildCount(node) == 0) { - const float innerWidth = availableWidth - marginAxisRow - paddingAndBorderAxisRow; - const float innerHeight = availableHeight - marginAxisColumn - paddingAndBorderAxisColumn; - - if (widthMeasureMode == CSSMeasureModeExactly && heightMeasureMode == CSSMeasureModeExactly) { - // Don't bother sizing the text if both dimensions are already defined. - node->layout.measuredDimensions[CSSDimensionWidth] = - boundAxis(node, CSSFlexDirectionRow, availableWidth - marginAxisRow); - node->layout.measuredDimensions[CSSDimensionHeight] = - boundAxis(node, CSSFlexDirectionColumn, availableHeight - marginAxisColumn); - } else if (innerWidth <= 0 || innerHeight <= 0) { - // Don't bother sizing the text if there's no horizontal or vertical - // space. - node->layout.measuredDimensions[CSSDimensionWidth] = boundAxis(node, CSSFlexDirectionRow, 0); - node->layout.measuredDimensions[CSSDimensionHeight] = - boundAxis(node, CSSFlexDirectionColumn, 0); - } else { - // Measure the text under the current constraints. - const CSSSize measuredSize = - node->measure(node, innerWidth, widthMeasureMode, innerHeight, heightMeasureMode); - - node->layout.measuredDimensions[CSSDimensionWidth] = - boundAxis(node, - CSSFlexDirectionRow, - (widthMeasureMode == CSSMeasureModeUndefined || - widthMeasureMode == CSSMeasureModeAtMost) - ? measuredSize.width + paddingAndBorderAxisRow - : availableWidth - marginAxisRow); - node->layout.measuredDimensions[CSSDimensionHeight] = - boundAxis(node, - CSSFlexDirectionColumn, - (heightMeasureMode == CSSMeasureModeUndefined || - heightMeasureMode == CSSMeasureModeAtMost) - ? measuredSize.height + paddingAndBorderAxisColumn - : availableHeight - marginAxisColumn); - } - - return; - } - - // 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. - const uint32_t childCount = CSSNodeListCount(node->children); - if (childCount == 0) { - node->layout.measuredDimensions[CSSDimensionWidth] = - boundAxis(node, - CSSFlexDirectionRow, - (widthMeasureMode == CSSMeasureModeUndefined || - widthMeasureMode == CSSMeasureModeAtMost) - ? paddingAndBorderAxisRow - : availableWidth - marginAxisRow); - node->layout.measuredDimensions[CSSDimensionHeight] = - boundAxis(node, - CSSFlexDirectionColumn, - (heightMeasureMode == CSSMeasureModeUndefined || - heightMeasureMode == CSSMeasureModeAtMost) - ? paddingAndBorderAxisColumn - : availableHeight - marginAxisColumn); - return; - } - - // If we're not being asked to perform a full layout, we can handle a number - // of common - // cases here without incurring the cost of the remaining function. - if (!performLayout) { - // If we're being asked to size the content with an at most constraint but - // there is no available - // width, - // the measurement will always be zero. - if (widthMeasureMode == CSSMeasureModeAtMost && availableWidth <= 0 && - heightMeasureMode == CSSMeasureModeAtMost && availableHeight <= 0) { - node->layout.measuredDimensions[CSSDimensionWidth] = boundAxis(node, CSSFlexDirectionRow, 0); - node->layout.measuredDimensions[CSSDimensionHeight] = - boundAxis(node, CSSFlexDirectionColumn, 0); - return; - } - - if (widthMeasureMode == CSSMeasureModeAtMost && availableWidth <= 0) { - node->layout.measuredDimensions[CSSDimensionWidth] = boundAxis(node, CSSFlexDirectionRow, 0); - node->layout.measuredDimensions[CSSDimensionHeight] = - boundAxis(node, - CSSFlexDirectionColumn, - CSSValueIsUndefined(availableHeight) ? 0 - : (availableHeight - marginAxisColumn)); - return; - } - - if (heightMeasureMode == CSSMeasureModeAtMost && availableHeight <= 0) { - node->layout.measuredDimensions[CSSDimensionWidth] = - boundAxis(node, - CSSFlexDirectionRow, - CSSValueIsUndefined(availableWidth) ? 0 : (availableWidth - marginAxisRow)); - node->layout.measuredDimensions[CSSDimensionHeight] = - boundAxis(node, CSSFlexDirectionColumn, 0); - return; - } - - // If we're being asked to use an exact width/height, there's no need to - // measure the children. - if (widthMeasureMode == CSSMeasureModeExactly && heightMeasureMode == CSSMeasureModeExactly) { - node->layout.measuredDimensions[CSSDimensionWidth] = - boundAxis(node, CSSFlexDirectionRow, availableWidth - marginAxisRow); - node->layout.measuredDimensions[CSSDimensionHeight] = - boundAxis(node, CSSFlexDirectionColumn, availableHeight - marginAxisColumn); - return; - } - } - - // STEP 1: CALCULATE VALUES FOR REMAINDER OF ALGORITHM - const CSSFlexDirection mainAxis = resolveAxis(node->style.flexDirection, direction); - const CSSFlexDirection crossAxis = getCrossFlexDirection(mainAxis, direction); - const bool isMainAxisRow = isRowDirection(mainAxis); - const CSSJustify justifyContent = node->style.justifyContent; - const bool isNodeFlexWrap = node->style.flexWrap == CSSWrapTypeWrap; - - CSSNodeRef firstAbsoluteChild = NULL; - CSSNodeRef currentAbsoluteChild = NULL; - - const float leadingPaddingAndBorderMain = getLeadingPaddingAndBorder(node, mainAxis); - const float trailingPaddingAndBorderMain = getTrailingPaddingAndBorder(node, mainAxis); - const float leadingPaddingAndBorderCross = getLeadingPaddingAndBorder(node, crossAxis); - const float paddingAndBorderAxisMain = getPaddingAndBorderAxis(node, mainAxis); - const float paddingAndBorderAxisCross = getPaddingAndBorderAxis(node, crossAxis); - - const CSSMeasureMode measureModeMainDim = isMainAxisRow ? widthMeasureMode : heightMeasureMode; - const CSSMeasureMode measureModeCrossDim = isMainAxisRow ? heightMeasureMode : widthMeasureMode; - - // STEP 2: DETERMINE AVAILABLE SIZE IN MAIN AND CROSS DIRECTIONS - const float availableInnerWidth = availableWidth - marginAxisRow - paddingAndBorderAxisRow; - const float availableInnerHeight = - availableHeight - marginAxisColumn - paddingAndBorderAxisColumn; - const float availableInnerMainDim = isMainAxisRow ? availableInnerWidth : availableInnerHeight; - const float availableInnerCrossDim = isMainAxisRow ? availableInnerHeight : availableInnerWidth; - - // STEP 3: DETERMINE FLEX BASIS FOR EACH ITEM - for (uint32_t i = 0; i < childCount; i++) { - const CSSNodeRef child = CSSNodeListGet(node->children, i); - if (NULL != child && false == CSSNodeIsVisible(child)) { - continue; - } - - if (performLayout) { - // Set the initial position (relative to the parent). - const CSSDirection childDirection = resolveDirection(child, direction); - setPosition(child, childDirection); - } - - // Absolute-positioned children don't participate in flex layout. Add them - // to a list that we can process later. - if (child->style.positionType == CSSPositionTypeAbsolute) { - // Store a private linked list of absolutely positioned children - // so that we can efficiently traverse them later. - if (firstAbsoluteChild == NULL) { - firstAbsoluteChild = child; - } - if (currentAbsoluteChild != NULL) { - currentAbsoluteChild->nextChild = child; - } - currentAbsoluteChild = child; - child->nextChild = NULL; - } else { - computeChildFlexBasis(node, - child, - availableInnerWidth, - widthMeasureMode, - availableInnerHeight, - heightMeasureMode, - direction); - } - } - - // 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; - - float totalFlexGrowFactors = 0; - float totalFlexShrinkScaledFactors = 0; - - // Maintain a linked list of the child nodes that can shrink and/or grow. - CSSNodeRef firstRelativeChild = NULL; - CSSNodeRef currentRelativeChild = NULL; - - // 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++) { - const CSSNodeRef child = CSSNodeListGet(node->children, i); - if (NULL != child && false == CSSNodeIsVisible(child)) { - continue; - } - - child->lineIndex = lineCount; - - if (child->style.positionType != CSSPositionTypeAbsolute) { - const float outerFlexBasis = - child->layout.computedFlexBasis + getMarginAxis(child, mainAxis); - - // 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. - if (sizeConsumedOnCurrentLine + outerFlexBasis > availableInnerMainDim && isNodeFlexWrap && - itemsOnLine > 0) { - break; - } - - sizeConsumedOnCurrentLine += outerFlexBasis; - itemsOnLine++; - - if (isFlex(child)) { - totalFlexGrowFactors += CSSNodeStyleGetFlexGrow(child); - - // Unlike the grow factor, the shrink factor is scaled relative to the - // child - // dimension. - totalFlexShrinkScaledFactors += - -CSSNodeStyleGetFlexShrink(child) * child->layout.computedFlexBasis; - } - - // Store a private linked list of children that need to be layed out. - if (firstRelativeChild == NULL) { - firstRelativeChild = child; - } - if (currentRelativeChild != NULL) { - currentRelativeChild->nextChild = child; - } - currentRelativeChild = child; - child->nextChild = NULL; - } - } - - // If we don't need to measure the cross axis, we can skip the entire flex - // step. - const bool canSkipFlex = !performLayout && measureModeCrossDim == CSSMeasureModeExactly; - - // 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. - float remainingFreeSpace = 0; - if (!CSSValueIsUndefined(availableInnerMainDim)) { - remainingFreeSpace = availableInnerMainDim - sizeConsumedOnCurrentLine; - } else if (sizeConsumedOnCurrentLine < 0) { - // availableInnerMainDim is indefinite which means the node is being sized - // based on its - // content. - // sizeConsumedOnCurrentLine is negative which means the node will - // allocate 0 pixels for - // its content. Consequently, remainingFreeSpace is 0 - - // sizeConsumedOnCurrentLine. - 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 - // spec (https://www.w3.org/TR/css-flexbox-1/#resolve-flexible-lengths) - // 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; - while (currentRelativeChild != NULL) { - childFlexBasis = currentRelativeChild->layout.computedFlexBasis; - - if (remainingFreeSpace < 0) { - flexShrinkScaledFactor = - -CSSNodeStyleGetFlexShrink(currentRelativeChild) * childFlexBasis; - - // Is this child able to shrink? - if (flexShrinkScaledFactor != 0) { - baseMainSize = - childFlexBasis + - remainingFreeSpace / totalFlexShrinkScaledFactors * flexShrinkScaledFactor; - boundMainSize = boundAxis(currentRelativeChild, mainAxis, baseMainSize); - 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) { - flexGrowFactor = CSSNodeStyleGetFlexGrow(currentRelativeChild); - - // Is this child able to grow? - if (flexGrowFactor != 0) { - baseMainSize = - childFlexBasis + remainingFreeSpace / totalFlexGrowFactors * flexGrowFactor; - boundMainSize = boundAxis(currentRelativeChild, mainAxis, baseMainSize); - 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; - } - } - } - - currentRelativeChild = currentRelativeChild->nextChild; - } - - totalFlexShrinkScaledFactors += deltaFlexShrinkScaledFactors; - totalFlexGrowFactors += deltaFlexGrowFactors; - remainingFreeSpace += deltaFreeSpace; - - // Second pass: resolve the sizes of the flexible items - deltaFreeSpace = 0; - currentRelativeChild = firstRelativeChild; - while (currentRelativeChild != NULL) { - childFlexBasis = currentRelativeChild->layout.computedFlexBasis; - float updatedMainSize = childFlexBasis; - - if (remainingFreeSpace < 0) { - flexShrinkScaledFactor = - -CSSNodeStyleGetFlexShrink(currentRelativeChild) * childFlexBasis; - // Is this child able to shrink? - if (flexShrinkScaledFactor != 0) { - float childSize; - - if (totalFlexShrinkScaledFactors == 0) { - childSize = childFlexBasis + flexShrinkScaledFactor; - } else { - childSize = - childFlexBasis + - (remainingFreeSpace / totalFlexShrinkScaledFactors) * flexShrinkScaledFactor; - } - - updatedMainSize = boundAxis(currentRelativeChild, mainAxis, childSize); - } - } else if (remainingFreeSpace > 0) { - flexGrowFactor = CSSNodeStyleGetFlexGrow(currentRelativeChild); - - // Is this child able to grow? - if (flexGrowFactor != 0) { - updatedMainSize = - boundAxis(currentRelativeChild, - mainAxis, - childFlexBasis + - remainingFreeSpace / totalFlexGrowFactors * flexGrowFactor); - } - } - - deltaFreeSpace -= updatedMainSize - childFlexBasis; - - float childWidth; - float childHeight; - CSSMeasureMode childWidthMeasureMode; - CSSMeasureMode childHeightMeasureMode; - - if (isMainAxisRow) { - childWidth = updatedMainSize + getMarginAxis(currentRelativeChild, CSSFlexDirectionRow); - childWidthMeasureMode = CSSMeasureModeExactly; - - if (!CSSValueIsUndefined(availableInnerCrossDim) && - !isStyleDimDefined(currentRelativeChild, CSSFlexDirectionColumn) && - heightMeasureMode == CSSMeasureModeExactly && - getAlignItem(node, currentRelativeChild) == CSSAlignStretch) { - childHeight = availableInnerCrossDim; - childHeightMeasureMode = CSSMeasureModeExactly; - } else if (!isStyleDimDefined(currentRelativeChild, CSSFlexDirectionColumn)) { - childHeight = availableInnerCrossDim; - childHeightMeasureMode = - CSSValueIsUndefined(childHeight) ? CSSMeasureModeUndefined : CSSMeasureModeAtMost; - } else { - childHeight = currentRelativeChild->style.dimensions[CSSDimensionHeight] + - getMarginAxis(currentRelativeChild, CSSFlexDirectionColumn); - childHeightMeasureMode = CSSMeasureModeExactly; - } - } else { - childHeight = - updatedMainSize + getMarginAxis(currentRelativeChild, CSSFlexDirectionColumn); - childHeightMeasureMode = CSSMeasureModeExactly; - - if (!CSSValueIsUndefined(availableInnerCrossDim) && - !isStyleDimDefined(currentRelativeChild, CSSFlexDirectionRow) && - widthMeasureMode == CSSMeasureModeExactly && - getAlignItem(node, currentRelativeChild) == CSSAlignStretch) { - childWidth = availableInnerCrossDim; - childWidthMeasureMode = CSSMeasureModeExactly; - } else if (!isStyleDimDefined(currentRelativeChild, CSSFlexDirectionRow)) { - childWidth = availableInnerCrossDim; - childWidthMeasureMode = - CSSValueIsUndefined(childWidth) ? CSSMeasureModeUndefined : CSSMeasureModeAtMost; - } else { - childWidth = currentRelativeChild->style.dimensions[CSSDimensionWidth] + - getMarginAxis(currentRelativeChild, CSSFlexDirectionRow); - childWidthMeasureMode = CSSMeasureModeExactly; - } - } - - const bool requiresStretchLayout = - !isStyleDimDefined(currentRelativeChild, crossAxis) && - getAlignItem(node, currentRelativeChild) == CSSAlignStretch; - - // Recursively call the layout algorithm for this child with the updated - // main size. - layoutNodeInternal(currentRelativeChild, - childWidth, - childHeight, - direction, - childWidthMeasureMode, - childHeightMeasureMode, - performLayout && !requiresStretchLayout, - "flex"); - - currentRelativeChild = currentRelativeChild->nextChild; - } - } - - remainingFreeSpace = originalRemainingFreeSpace + deltaFreeSpace; - - // 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. - - if (measureModeMainDim == CSSMeasureModeAtMost && remainingFreeSpace > 0) { - if (!CSSValueIsUndefined(node->style.minDimensions[dim[mainAxis]]) && - node->style.minDimensions[dim[mainAxis]] >= 0) { - remainingFreeSpace = fmax(0, - node->style.minDimensions[dim[mainAxis]] - - (availableInnerMainDim - remainingFreeSpace)); - } else { - remainingFreeSpace = 0; - } - } - - switch (justifyContent) { - case CSSJustifyCenter: - leadingMainDim = remainingFreeSpace / 2; - break; - case CSSJustifyFlexEnd: - leadingMainDim = remainingFreeSpace; - break; - case CSSJustifySpaceBetween: - if (itemsOnLine > 1) { - betweenMainDim = fmaxf(remainingFreeSpace, 0) / (itemsOnLine - 1); - } else { - betweenMainDim = 0; - } - break; - case CSSJustifySpaceAround: - // Space on the edges is half of the space between elements - betweenMainDim = remainingFreeSpace / itemsOnLine; - leadingMainDim = betweenMainDim / 2; - break; - case CSSJustifyFlexStart: - break; - } - - float mainDim = leadingPaddingAndBorderMain + leadingMainDim; - float crossDim = 0; - - for (uint32_t i = startOfLineIndex; i < endOfLineIndex; i++) { - const CSSNodeRef child = CSSNodeListGet(node->children, i); - if (NULL != child && false == CSSNodeIsVisible(child)) { - continue; - } - - if (child->style.positionType == CSSPositionTypeAbsolute && - isLeadingPosDefined(child, mainAxis)) { - 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). - child->layout.position[pos[mainAxis]] = getLeadingPosition(child, mainAxis) + - getLeadingBorder(node, mainAxis) + - getLeadingMargin(child, mainAxis); - } - } else { - if (performLayout) { - // If the child is position absolute (without top/left) or relative, - // we put it at the current accumulated offset. - child->layout.position[pos[mainAxis]] += mainDim; - } - - // 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. - if (child->style.positionType == CSSPositionTypeRelative) { - if (canSkipFlex) { - // If we skipped the flex step, then we can't rely on the - // measuredDims because - // they weren't computed. This means we can't call getDimWithMargin. - mainDim += - betweenMainDim + getMarginAxis(child, mainAxis) + child->layout.computedFlexBasis; - crossDim = availableInnerCrossDim; - } else { - // The main dimension is the sum of all the elements dimension plus - // the spacing. - mainDim += betweenMainDim + getDimWithMargin(child, mainAxis); - - // The cross dimension is the max of the elements dimension since - // there - // can only be one element in that cross dimension. - crossDim = fmaxf(crossDim, getDimWithMargin(child, crossAxis)); - } - } - } - } - - mainDim += trailingPaddingAndBorderMain; - - float containerCrossAxis = availableInnerCrossDim; - if (measureModeCrossDim == CSSMeasureModeUndefined || - measureModeCrossDim == CSSMeasureModeAtMost) { - // Compute the cross axis from the max cross dimension of the children. - containerCrossAxis = boundAxis(node, crossAxis, crossDim + paddingAndBorderAxisCross) - - paddingAndBorderAxisCross; - - if (measureModeCrossDim == CSSMeasureModeAtMost) { - containerCrossAxis = fminf(containerCrossAxis, availableInnerCrossDim); - } - } - - // If there's no flex wrap, the cross dimension is defined by the container. - if (!isNodeFlexWrap && measureModeCrossDim == CSSMeasureModeExactly) { - crossDim = availableInnerCrossDim; - } - - // Clamp to the min/max size specified on the container. - crossDim = boundAxis(node, crossAxis, crossDim + paddingAndBorderAxisCross) - - 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++) { - const CSSNodeRef child = CSSNodeListGet(node->children, i); - if (NULL != child && false == CSSNodeIsVisible(child)) { - continue; - } - - if (child->style.positionType == CSSPositionTypeAbsolute) { - // If the child is absolutely positioned and has a - // top/left/bottom/right - // set, override all the previously computed positions to set it - // correctly. - if (isLeadingPosDefined(child, crossAxis)) { - child->layout.position[pos[crossAxis]] = getLeadingPosition(child, crossAxis) + - getLeadingBorder(node, crossAxis) + - getLeadingMargin(child, crossAxis); - } else { - child->layout.position[pos[crossAxis]] = - leadingPaddingAndBorderCross + getLeadingMargin(child, crossAxis); - } - } 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 - const CSSAlign alignItem = getAlignItem(node, child); - - // 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. - if (alignItem == CSSAlignStretch) { - const bool isCrossSizeDefinite = - (isMainAxisRow && isStyleDimDefined(child, CSSFlexDirectionColumn)) || - (!isMainAxisRow && isStyleDimDefined(child, CSSFlexDirectionRow)); - - float childWidth; - float childHeight; - CSSMeasureMode childWidthMeasureMode; - CSSMeasureMode childHeightMeasureMode; - - if (isMainAxisRow) { - childHeight = crossDim; - childWidth = child->layout.measuredDimensions[CSSDimensionWidth] + - getMarginAxis(child, CSSFlexDirectionRow); - } else { - childWidth = crossDim; - childHeight = child->layout.measuredDimensions[CSSDimensionHeight] + - getMarginAxis(child, CSSFlexDirectionColumn); - } - - // If the child defines a definite size for its cross axis, there's - // no need to stretch. - if (!isCrossSizeDefinite) { - childWidthMeasureMode = - CSSValueIsUndefined(childWidth) ? CSSMeasureModeUndefined : CSSMeasureModeExactly; - childHeightMeasureMode = CSSValueIsUndefined(childHeight) ? CSSMeasureModeUndefined - : CSSMeasureModeExactly; - layoutNodeInternal(child, - childWidth, - childHeight, - direction, - childWidthMeasureMode, - childHeightMeasureMode, - true, - "stretch"); - } - } else if (alignItem != CSSAlignFlexStart) { - const float remainingCrossDim = containerCrossAxis - getDimWithMargin(child, crossAxis); - - if (alignItem == CSSAlignCenter) { - leadingCrossDim += remainingCrossDim / 2; - } else { // CSSAlignFlexEnd - leadingCrossDim += remainingCrossDim; - } - } - - // And we apply the position - child->layout.position[pos[crossAxis]] += totalLineCrossDim + leadingCrossDim; - } - } - } - - totalLineCrossDim += crossDim; - maxLineMainDim = fmaxf(maxLineMainDim, mainDim); - } - - // STEP 8: MULTI-LINE CONTENT ALIGNMENT - if (lineCount > 1 && performLayout && !CSSValueIsUndefined(availableInnerCrossDim)) { - const float remainingAlignContentDim = availableInnerCrossDim - totalLineCrossDim; - - float crossDimLead = 0; - float currentLead = leadingPaddingAndBorderCross; - - switch (node->style.alignContent) { - case CSSAlignFlexEnd: - currentLead += remainingAlignContentDim; - break; - case CSSAlignCenter: - currentLead += remainingAlignContentDim / 2; - break; - case CSSAlignStretch: - if (availableInnerCrossDim > totalLineCrossDim) { - crossDimLead = (remainingAlignContentDim / lineCount); - } - break; - case CSSAlignAuto: - case CSSAlignFlexStart: - break; - } - - uint32_t endIndex = 0; - for (uint32_t i = 0; i < lineCount; i++) { - uint32_t startIndex = endIndex; - uint32_t ii; - - // compute the line's height and find the endIndex - float lineHeight = 0; - for (ii = startIndex; ii < childCount; ii++) { - const CSSNodeRef child = CSSNodeListGet(node->children, ii); - if (NULL != child && false == CSSNodeIsVisible(child)) { - continue; - } - - if (child->style.positionType == CSSPositionTypeRelative) { - if (child->lineIndex != i) { - break; - } - - if (isLayoutDimDefined(child, crossAxis)) { - lineHeight = fmaxf(lineHeight, - child->layout.measuredDimensions[dim[crossAxis]] + - getMarginAxis(child, crossAxis)); - } - } - } - endIndex = ii; - lineHeight += crossDimLead; - - if (performLayout) { - for (ii = startIndex; ii < endIndex; ii++) { - const CSSNodeRef child = CSSNodeListGet(node->children, ii); - if (NULL != child && false == CSSNodeIsVisible(child)) { - continue; - } - - if (child->style.positionType == CSSPositionTypeRelative) { - switch (getAlignItem(node, child)) { - case CSSAlignFlexStart: { - child->layout.position[pos[crossAxis]] = - currentLead + getLeadingMargin(child, crossAxis); - break; - } - case CSSAlignFlexEnd: { - child->layout.position[pos[crossAxis]] = - currentLead + lineHeight - getTrailingMargin(child, crossAxis) - - child->layout.measuredDimensions[dim[crossAxis]]; - break; - } - case CSSAlignCenter: { - float childHeight = child->layout.measuredDimensions[dim[crossAxis]]; - child->layout.position[pos[crossAxis]] = - currentLead + (lineHeight - childHeight) / 2; - break; - } - case CSSAlignStretch: { - child->layout.position[pos[crossAxis]] = - currentLead + getLeadingMargin(child, crossAxis); - // TODO(prenaux): Correctly set the height of items with indefinite - // (auto) crossAxis dimension. - break; - } - case CSSAlignAuto: - break; - } - } - } - } - - currentLead += lineHeight; - } - } - - // STEP 9: COMPUTING FINAL DIMENSIONS - node->layout.measuredDimensions[CSSDimensionWidth] = - boundAxis(node, CSSFlexDirectionRow, availableWidth - marginAxisRow); - node->layout.measuredDimensions[CSSDimensionHeight] = - boundAxis(node, CSSFlexDirectionColumn, availableHeight - marginAxisColumn); - - // If the user didn't specify a width or height for the node, set the - // dimensions based on the children. - if (measureModeMainDim == CSSMeasureModeUndefined) { - // Clamp the size to the min/max size, if specified, and make sure it - // doesn't go below the padding and border amount. - node->layout.measuredDimensions[dim[mainAxis]] = boundAxis(node, mainAxis, maxLineMainDim); - } else if (measureModeMainDim == CSSMeasureModeAtMost) { - node->layout.measuredDimensions[dim[mainAxis]] = - fmaxf(fminf(availableInnerMainDim + paddingAndBorderAxisMain, - boundAxisWithinMinAndMax(node, mainAxis, maxLineMainDim)), - paddingAndBorderAxisMain); - } - - if (measureModeCrossDim == CSSMeasureModeUndefined) { - // Clamp the size to the min/max size, if specified, and make sure it - // doesn't go below the padding and border amount. - node->layout.measuredDimensions[dim[crossAxis]] = - boundAxis(node, crossAxis, totalLineCrossDim + paddingAndBorderAxisCross); - } else if (measureModeCrossDim == CSSMeasureModeAtMost) { - node->layout.measuredDimensions[dim[crossAxis]] = - fmaxf(fminf(availableInnerCrossDim + paddingAndBorderAxisCross, - boundAxisWithinMinAndMax(node, - crossAxis, - totalLineCrossDim + paddingAndBorderAxisCross)), - paddingAndBorderAxisCross); - } - - if (performLayout) { - // STEP 10: SIZING AND POSITIONING ABSOLUTE CHILDREN - for (currentAbsoluteChild = firstAbsoluteChild; currentAbsoluteChild != NULL; - currentAbsoluteChild = currentAbsoluteChild->nextChild) { - absoluteLayoutChild( - node, currentAbsoluteChild, availableInnerWidth, widthMeasureMode, direction); - } - - // STEP 11: SETTING TRAILING POSITIONS FOR CHILDREN - const bool needsMainTrailingPos = - mainAxis == CSSFlexDirectionRowReverse || mainAxis == CSSFlexDirectionColumnReverse; - const bool needsCrossTrailingPos = - CSSFlexDirectionRowReverse || crossAxis == CSSFlexDirectionColumnReverse; - - // Set trailing position if necessary. - if (needsMainTrailingPos || needsCrossTrailingPos) { - for (uint32_t i = 0; i < childCount; i++) { - const CSSNodeRef child = CSSNodeListGet(node->children, i); - if (NULL != child && false == CSSNodeIsVisible(child)) { - continue; - } - - if (needsMainTrailingPos) { - setTrailingPosition(node, child, mainAxis); - } - - if (needsCrossTrailingPos) { - setTrailingPosition(node, child, crossAxis); - } - } - } - } -} - -uint32_t gDepth = 0; -bool gPrintTree = true; -bool gPrintChanges = true; -bool gPrintSkips = true; - -static const char *spacer = " "; - -static const char *getSpacer(const unsigned long level) { - const unsigned long spacerLen = strlen(spacer); - if (level > spacerLen) { - return &spacer[0]; - } else { - return &spacer[spacerLen - level]; - } -} - -static const char *getModeName(const CSSMeasureMode mode, const bool performLayout) { - const char *kMeasureModeNames[CSSMeasureModeCount] = {"UNDEFINED", "EXACTLY", "AT_MOST"}; - const char *kLayoutModeNames[CSSMeasureModeCount] = {"LAY_UNDEFINED", - "LAY_EXACTLY", - "LAY_AT_" - "MOST"}; - - if (mode >= CSSMeasureModeCount) { - return ""; - } - - return performLayout ? kLayoutModeNames[mode] : kMeasureModeNames[mode]; -} - -static inline bool newSizeIsExactAndMatchesOldMeasuredSize(CSSMeasureMode sizeMode, - float size, - float lastComputedSize) { - return sizeMode == CSSMeasureModeExactly && eq(size, lastComputedSize); -} - -static inline bool oldSizeIsUnspecifiedAndStillFits(CSSMeasureMode sizeMode, - float size, - CSSMeasureMode lastSizeMode, - float lastComputedSize) { - return sizeMode == CSSMeasureModeAtMost && lastSizeMode == CSSMeasureModeUndefined && - size >= lastComputedSize; -} - -static inline bool newMeasureSizeIsStricterAndStillValid(CSSMeasureMode sizeMode, - float size, - CSSMeasureMode lastSizeMode, - float lastSize, - float lastComputedSize) { - return lastSizeMode == CSSMeasureModeAtMost && sizeMode == CSSMeasureModeAtMost && - lastSize > size && lastComputedSize <= size; -} - -bool CSSNodeCanUseCachedMeasurement(const bool isTextNode, - const CSSMeasureMode widthMode, - const float width, - const CSSMeasureMode heightMode, - const float height, - const CSSMeasureMode lastWidthMode, - const float lastWidth, - const CSSMeasureMode lastHeightMode, - const float lastHeight, - const float lastComputedWidth, - const float lastComputedHeight, - const float marginRow, - const float marginColumn) { - - if (lastComputedHeight < 0 || lastComputedWidth < 0) { - return false; - } - - const bool hasSameWidthSpec = lastWidthMode == widthMode && eq(lastWidth, width); - const bool hasSameHeightSpec = lastHeightMode == heightMode && eq(lastHeight, height); - - const bool widthIsCompatible = - hasSameWidthSpec || - newSizeIsExactAndMatchesOldMeasuredSize(widthMode, width - marginRow, lastComputedWidth) || - oldSizeIsUnspecifiedAndStillFits(widthMode, - width - marginRow, - lastWidthMode, - lastComputedWidth) || - newMeasureSizeIsStricterAndStillValid( - widthMode, width - marginRow, lastWidthMode, lastWidth, lastComputedWidth); - - const bool heightIsCompatible = isTextNode || hasSameHeightSpec || - newSizeIsExactAndMatchesOldMeasuredSize(heightMode, - height - marginColumn, - lastComputedHeight) || - oldSizeIsUnspecifiedAndStillFits(heightMode, - height - marginColumn, - lastHeightMode, - lastComputedHeight) || - newMeasureSizeIsStricterAndStillValid(heightMode, - height - marginColumn, - lastHeightMode, - lastHeight, - lastComputedHeight); - - return widthIsCompatible && heightIsCompatible; -} - -// -// This is a wrapper around the layoutNodeImpl function. It determines -// whether the layout request is redundant and can be skipped. -// -// Parameters: -// Input parameters are the same as layoutNodeImpl (see above) -// Return parameter is true if layout was performed, false if skipped -// -bool layoutNodeInternal(const CSSNodeRef node, - const float availableWidth, - const float availableHeight, - const CSSDirection parentDirection, - const CSSMeasureMode widthMeasureMode, - const CSSMeasureMode heightMeasureMode, - const bool performLayout, - const char *reason) { - CSSLayout *layout = &node->layout; - - gDepth++; - -#if 0 - printf("---\n"); - printf("node->isDirty: %c\n", (node->isDirty) ? 'y' : 'n'); - printf("layout->generationCount != gCurrentGenerationCount: %c\n", layout->generationCount != gCurrentGenerationCount ? 'y' : 'n'); - printf("layout->lastParentDirection != parentDirection: %c\n", layout->lastParentDirection != parentDirection ? 'y' : 'n'); -#endif - - const bool needToVisitNode = - (node->isDirty && layout->generationCount != gCurrentGenerationCount) || - layout->lastParentDirection != parentDirection; - - if (needToVisitNode) { - - // Invalidate the cached results. - layout->nextCachedMeasurementsIndex = 0; - layout->cachedLayout.widthMeasureMode = (CSSMeasureMode) -1; - layout->cachedLayout.heightMeasureMode = (CSSMeasureMode) -1; - layout->cachedLayout.computedWidth = -1; - layout->cachedLayout.computedHeight = -1; - } - - CSSCachedMeasurement *cachedResults = NULL; - - // Determine whether the results are already cached. We maintain a separate - // cache for layouts and measurements. A layout operation modifies the - // 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. - if (node->measure && CSSNodeChildCount(node) == 0) { - const float marginAxisRow = getMarginAxis(node, CSSFlexDirectionRow); - const float marginAxisColumn = getMarginAxis(node, CSSFlexDirectionColumn); - - // First, try to use the layout cache. - if (CSSNodeCanUseCachedMeasurement(node->isTextNode, - widthMeasureMode, - availableWidth, - heightMeasureMode, - availableHeight, - layout->cachedLayout.widthMeasureMode, - layout->cachedLayout.availableWidth, - layout->cachedLayout.heightMeasureMode, - layout->cachedLayout.availableHeight, - layout->cachedLayout.computedWidth, - layout->cachedLayout.computedHeight, - marginAxisRow, - marginAxisColumn)) { - cachedResults = &layout->cachedLayout; - } else { - // Try to use the measurement cache. - for (uint32_t i = 0; i < layout->nextCachedMeasurementsIndex; i++) { - if (CSSNodeCanUseCachedMeasurement(node->isTextNode, - 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, - marginAxisColumn)) { - cachedResults = &layout->cachedMeasurements[i]; - break; - } - } - } - } else if (performLayout) { - if (eq(layout->cachedLayout.availableWidth, availableWidth) && - eq(layout->cachedLayout.availableHeight, availableHeight) && - layout->cachedLayout.widthMeasureMode == widthMeasureMode && - layout->cachedLayout.heightMeasureMode == heightMeasureMode) { - cachedResults = &layout->cachedLayout; - } - } else { - for (uint32_t i = 0; i < layout->nextCachedMeasurementsIndex; i++) { - if (eq(layout->cachedMeasurements[i].availableWidth, availableWidth) && - eq(layout->cachedMeasurements[i].availableHeight, availableHeight) && - layout->cachedMeasurements[i].widthMeasureMode == widthMeasureMode && - layout->cachedMeasurements[i].heightMeasureMode == heightMeasureMode) { - cachedResults = &layout->cachedMeasurements[i]; - break; - } - } - } - - if (!needToVisitNode && cachedResults != NULL) { - layout->measuredDimensions[CSSDimensionWidth] = cachedResults->computedWidth; - layout->measuredDimensions[CSSDimensionHeight] = cachedResults->computedHeight; - - if (gPrintChanges && gPrintSkips) { - printf("%s%d.{[skipped] ", getSpacer(gDepth), gDepth); - if (node->print) { - node->print(node); - } - printf("wm: %s, hm: %s, aw: %f ah: %f => d: (%f, %f) %s\n", - getModeName(widthMeasureMode, performLayout), - getModeName(heightMeasureMode, performLayout), - availableWidth, - availableHeight, - cachedResults->computedWidth, - cachedResults->computedHeight, - reason); - } - } else { - if (gPrintChanges) { - printf("%s%d.{%s", getSpacer(gDepth), gDepth, needToVisitNode ? "*" : ""); - if (node->print) { - node->print(node); - } - printf("wm: %s, hm: %s, aw: %f ah: %f %s\n", - getModeName(widthMeasureMode, performLayout), - getModeName(heightMeasureMode, performLayout), - availableWidth, - availableHeight, - reason); - } - - layoutNodeImpl(node, - availableWidth, - availableHeight, - parentDirection, - widthMeasureMode, - heightMeasureMode, - performLayout); - - if (gPrintChanges) { - printf("%s%d.}%s", getSpacer(gDepth), gDepth, needToVisitNode ? "*" : ""); - if (node->print) { - node->print(node); - } - printf("wm: %s, hm: %s, d: (%f, %f) %s\n", - getModeName(widthMeasureMode, performLayout), - getModeName(heightMeasureMode, performLayout), - layout->measuredDimensions[CSSDimensionWidth], - layout->measuredDimensions[CSSDimensionHeight], - reason); - } - - layout->lastParentDirection = parentDirection; - - if (cachedResults == NULL) { - if (layout->nextCachedMeasurementsIndex == CSS_MAX_CACHED_RESULT_COUNT) { - if (gPrintChanges) { - printf("Out of cache entries!\n"); - } - layout->nextCachedMeasurementsIndex = 0; - } - - CSSCachedMeasurement *newCacheEntry; - 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; - newCacheEntry->computedWidth = layout->measuredDimensions[CSSDimensionWidth]; - newCacheEntry->computedHeight = layout->measuredDimensions[CSSDimensionHeight]; - } - } - - if (performLayout) { - node->layout.dimensions[CSSDimensionWidth] = node->layout.measuredDimensions[CSSDimensionWidth]; - node->layout.dimensions[CSSDimensionHeight] = - node->layout.measuredDimensions[CSSDimensionHeight]; - node->hasNewLayout = true; - node->isDirty = false; - } - - gDepth--; - layout->generationCount = gCurrentGenerationCount; - return (needToVisitNode || cachedResults == NULL); -} - -void CSSNodeCalculateLayout(const CSSNodeRef node, - const float availableWidth, - const float availableHeight, - const CSSDirection parentDirection) { - // 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++; - - float width = availableWidth; - float height = availableHeight; - CSSMeasureMode widthMeasureMode = CSSMeasureModeUndefined; - CSSMeasureMode heightMeasureMode = CSSMeasureModeUndefined; - - if (!CSSValueIsUndefined(width)) { - widthMeasureMode = CSSMeasureModeExactly; - } else if (isStyleDimDefined(node, CSSFlexDirectionRow)) { - width = - node->style.dimensions[dim[CSSFlexDirectionRow]] + getMarginAxis(node, CSSFlexDirectionRow); - widthMeasureMode = CSSMeasureModeExactly; - } else if (node->style.maxDimensions[CSSDimensionWidth] >= 0.0) { - width = node->style.maxDimensions[CSSDimensionWidth]; - widthMeasureMode = CSSMeasureModeAtMost; - } - - if (!CSSValueIsUndefined(height)) { - heightMeasureMode = CSSMeasureModeExactly; - } else if (isStyleDimDefined(node, CSSFlexDirectionColumn)) { - height = node->style.dimensions[dim[CSSFlexDirectionColumn]] + - getMarginAxis(node, CSSFlexDirectionColumn); - heightMeasureMode = CSSMeasureModeExactly; - } else if (node->style.maxDimensions[CSSDimensionHeight] >= 0.0) { - height = node->style.maxDimensions[CSSDimensionHeight]; - heightMeasureMode = CSSMeasureModeAtMost; - } - - if (layoutNodeInternal(node, - width, - height, - parentDirection, - widthMeasureMode, - heightMeasureMode, - true, - "initia" - "l")) { - setPosition(node, node->layout.direction); - - if (gPrintTree) { - CSSNodePrint(node, CSSPrintOptionsLayout | CSSPrintOptionsChildren | CSSPrintOptionsStyle); - } - } -} - -void CSSLayoutSetLogger(CSSLogger logger) { - gLogger = logger; -} - -#ifdef CSS_ASSERT_FAIL_ENABLED -static CSSAssertFailFunc gAssertFailFunc; - -void CSSAssertSetFailFunc(CSSAssertFailFunc func) { - gAssertFailFunc = func; -} - -void CSSAssertFail(const char *message) { - if (gAssertFailFunc) { - (*gAssertFailFunc)(message); - } -} -#endif diff --git a/CSSLayout/CSSLayout.h b/CSSLayout/CSSLayout.h deleted file mode 100644 index 4abed17b..00000000 --- a/CSSLayout/CSSLayout.h +++ /dev/null @@ -1,249 +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 -#include -#include -#include -#include -#include - -#ifndef __cplusplus -#include -#endif - -// Not defined in MSVC++ -#ifndef NAN -static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff}; -#define NAN (*(const float *) __nan) -#endif - -#define CSSUndefined NAN - -#include "CSSMacros.h" - -CSS_EXTERN_C_BEGIN - -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, - CSSOverflowScroll, -} CSSOverflow; - -// Note: auto is only a valid value for alignSelf. It is NOT a valid value for -// alignItems. -typedef enum CSSAlign { - CSSAlignAuto, - CSSAlignFlexStart, - CSSAlignCenter, - CSSAlignFlexEnd, - CSSAlignStretch, -} CSSAlign; - -typedef enum CSSPositionType { - CSSPositionTypeRelative, - CSSPositionTypeAbsolute, -} CSSPositionType; - -typedef enum CSSWrapType { - CSSWrapTypeNoWrap, - CSSWrapTypeWrap, -} CSSWrapType; - -typedef enum CSSMeasureMode { - CSSMeasureModeUndefined, - CSSMeasureModeExactly, - CSSMeasureModeAtMost, - CSSMeasureModeCount, -} CSSMeasureMode; - -typedef enum CSSDimension { - CSSDimensionWidth, - CSSDimensionHeight, -} CSSDimension; - -typedef enum CSSEdge { - CSSEdgeLeft, - CSSEdgeTop, - CSSEdgeRight, - CSSEdgeBottom, - CSSEdgeStart, - CSSEdgeEnd, - CSSEdgeHorizontal, - CSSEdgeVertical, - CSSEdgeAll, - CSSEdgeCount, -} CSSEdge; - -typedef enum CSSPrintOptions { - CSSPrintOptionsLayout = 1, - CSSPrintOptionsStyle = 2, - CSSPrintOptionsChildren = 4, -} CSSPrintOptions; - -typedef struct CSSSize { - float width; - float height; -} CSSSize; - -typedef struct CSSNode *CSSNodeRef; -typedef CSSSize (*CSSMeasureFunc)(CSSNodeRef node, - float width, - CSSMeasureMode widthMode, - float height, - CSSMeasureMode heightMode); -typedef void (*CSSPrintFunc)(CSSNodeRef node); -typedef int (*CSSLogger)(const char *format, ...); - -#ifdef CSS_ASSERT_FAIL_ENABLED -typedef void (*CSSAssertFailFunc)(const char *message); -#endif - -// 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 CSSDirection 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 CSSNodeHide(const CSSNodeRef node); -WIN_EXPORT void CSSNodeShow(const CSSNodeRef node); -WIN_EXPORT bool CSSNodeIsVisible(const CSSNodeRef node); - - -WIN_EXPORT void CSSNodePrint(const CSSNodeRef node, const CSSPrintOptions options); - -WIN_EXPORT bool CSSValueIsUndefined(const float value); - -WIN_EXPORT bool CSSNodeCanUseCachedMeasurement(const bool isTextNode, - const CSSMeasureMode widthMode, - const float width, - const CSSMeasureMode heightMode, - const float height, - const CSSMeasureMode lastWidthMode, - const float lastWidth, - const CSSMeasureMode lastHeightMode, - const float lastHeight, - const float lastComputedWidth, - const float lastComputedHeight, - const float marginRow, - const float marginColumn); - -#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 CSSEdge edge, \ - const type paramName); \ - WIN_EXPORT type CSSNodeStyleGet##name(const CSSNodeRef node, const CSSEdge 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, IsTextnode, isTextNode); -CSS_NODE_PROPERTY(bool, HasNewLayout, hasNewLayout); - -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); - -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); - -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(CSSDirection, Direction); - -WIN_EXPORT void CSSLayoutSetLogger(CSSLogger logger); - -#ifdef CSS_ASSERT_FAIL_ENABLED -// Assert -WIN_EXPORT void CSSAssertSetFailFunc(CSSAssertFailFunc func); -WIN_EXPORT void CSSAssertFail(const char *message); -#endif - -CSS_EXTERN_C_END diff --git a/CSSLayout/CSSNodeList.c b/CSSLayout/CSSNodeList.c deleted file mode 100644 index d48cf4b3..00000000 --- a/CSSLayout/CSSNodeList.c +++ /dev/null @@ -1,100 +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" - -struct CSSNodeList { - uint32_t capacity; - uint32_t count; - CSSNodeRef *items; -}; - -CSSNodeListRef CSSNodeListNew(const uint32_t initialCapacity) { - const CSSNodeListRef list = malloc(sizeof(struct CSSNodeList)); - CSS_ASSERT(list != NULL, "Could not allocate memory for list"); - - list->capacity = initialCapacity; - list->count = 0; - list->items = malloc(sizeof(CSSNodeRef) * list->capacity); - CSS_ASSERT(list->items != NULL, "Could not allocate memory for items"); - - return list; -} - -void CSSNodeListFree(const CSSNodeListRef list) { - if (list) { - free(list->items); - free(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 = realloc(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; -} diff --git a/CSSLayout/CSSNodeList.h b/CSSLayout/CSSNodeList.h deleted file mode 100644 index 155fcf6e..00000000 --- a/CSSLayout/CSSNodeList.h +++ /dev/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 -#include -#include -#include - -#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 diff --git a/LICENSE b/LICENSE index 864c3963..2b3f0e4f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ BSD License -For css-layout software +For yoga software Copyright (c) 2014-present, Facebook, Inc. All rights reserved. diff --git a/LICENSE-examples b/LICENSE-examples new file mode 100644 index 00000000..87f537d4 --- /dev/null +++ b/LICENSE-examples @@ -0,0 +1,9 @@ +The examples provided by Facebook are for non-commercial testing and evaluation +purposes only. Facebook reserves all rights not expressly granted. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/PATENTS b/PATENTS index 4dc338f2..78780735 100644 --- a/PATENTS +++ b/PATENTS @@ -1,6 +1,6 @@ Additional Grant of Patent Rights Version 2 -"Software" means the CSS Layout software distributed by Facebook, Inc. +"Software" means the yoga software distributed by Facebook, Inc. Facebook, Inc. (“Facebook”) hereby grants to each recipient of the Software (“you”) a perpetual, worldwide, royalty-free, non-exclusive, irrevocable diff --git a/README.md b/README.md index 37479cfe..1e066668 100644 --- a/README.md +++ b/README.md @@ -1,156 +1,28 @@ -# CSSLayout [![Build Status](https://travis-ci.org/facebook/css-layout.svg?branch=master)](https://travis-ci.org/facebook/css-layout) +# Yoga [![Build Status](https://travis-ci.org/facebook/yoga.svg?branch=master)](https://travis-ci.org/facebook/yoga) -## Goals -CSSLayout is a cross-platform implementation of flexbox. The goal of CSSLayout is allow native developers to have the same expressive layout system as developers developing for the modern web are used to. CSSLayout allows developers for web, android, iOS, and windows to use the same layout primitives across platforms. This saves time, increases collaboration between platform teams, and makes it easier for developers to work on multiple platforms. +## Building +Yoga builds with [buck](https://buckbuild.com). Make sure you install buck before contributing to Yoga. Yoga's main implementation is in C, with bindings to supported languages and frameworks. When making changes to Yoga please ensure the changes are also propagated to these bindings when applicable. -The goal of CSSLayout is not to re-implement all of css. CSSLayout only targets flexbox, and does not have any plans on implementing support for tables, floats, or any other css concepts. CSSLayout also does not plan on supporting styling properties which do not affect layout such as color or background properties. +## Testing +For any changes you make you should ensure that all the tests are passing. In case you make any fixes or additions to the library please also add tests for that change to ensure we don't break anything in the future. Tests are located in the `tests` directory. Run the tests by executing `buck test //:yoga`. - -## Differences from web -CSSLayout tries to stay as close as possible to the web implementation of flexbox. There are however certain cases where CSSLayout differs from the web implementation. - -### Default values -CSSLayout has chosen to make changes to the default values of certain properties. These default values were chosen based on our usage of the library. When testing layout with tools such as JSFiddle you can apply the following css style to ensure the defaults match those of CSSLayout. Or fork the [following JSFiddle](http://jsfiddle.net/vjeux/y11txxv9/). - -```css -div, span { - box-sizing: border-box; - position: relative; - - display: flex; - flex-direction: column; - align-items: stretch; - flex-shrink: 0; - align-content: flex-start; - - border: 0 solid black; - margin: 0; - padding: 0; - min-width: 0; -} -``` - -- `box-sizing: border-box` is the most convenient way to express the relation between `width` and `borderWidth`. -- Everything is `display: flex` by default. All the behaviors of `block` and `inline-block` can be expressed in term of `flex` but not the opposite. -- All the flex elements are oriented from top to bottom, left to right and do not shrink. This is how things are laid out using the default CSS settings and what you'd expect. -- Everything is `position: relative`. This makes `position: absolute` target the direct parent and not some parent which is either `relative` or `absolute`. If you want to position an element relative to something else, you should move it in the DOM instead of relying of CSS. It also makes `top, left, right, bottom` do something when not specifying `position: absolute`. - -### Size units -CSSLayout currently only supports pixel sizes. The reason being that we have not seen the need for any other units. We would like to support percentage units sometime in the future. - -### -start and -end properties -We think supporting RTL locales is very important. Therefor CSSLayout supports non-standards -start and -end suffixed versions of margin, padding, border, and position. - - -## Usage - -### C -The full API can be found in `CSSLayout/CSSLayout.h`. - -```c -CSSNodeRef root = CSSNodeNew(); -CSSNodeStyleSetWidth(root, 100); -CSSNodeStyleSetHeight(root, 100); - -for (uint32_t i = 0; i < 10; i++) { - CSSNodeRef child = CSSNodeNew(); - CSSNodeStyleSetHeight(child, 10); - CSSNodeInsertChild(root, child, 0); -} - -CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - -// Get for resulting layout -CSSNodeLayoutGetLeft(root); -CSSNodeLayoutGetTop(root); -CSSNodeLayoutGetWidth(root); -CSSNodeLayoutGetHeight(root); -``` - -### Java -The full API can be found in `java/com/facebook/csslayout/CSSNode.java`. - -```java -CSSNode root = new CSSNode(); -root.setStyleWidth(100); -root.setStyleHeight(100); - -for (int i = 0; i < 10; i++) { - CSSNode child = new CSSNode(); - child.setStyleHeight(10); - root.addChildAt(child, 0); -} - -root.calculateLayout(new CSSLayoutContext()); - -// Get for resulting layout -root.getLayoutX(); -root.getLayoutY(); -root.getLayoutWidth(); -root.getLayoutHeight(); -``` - -### UIKit -The full API can be found in `uikit/CSSLayout/UIView+CSSLayout.h`. - -```objective-c -UIView *root = [UIView new]; -[root css_setUsesFlexbox:YES]; -[root css_setWidth:100]; -[root css_setHeight:100]; - -for (NSUInteger i = 0; i < 10; i++) { - UIView *child = [UIView new]; - [child css_setUsesFlexbox:YES]; - [child css_setHeight:10]; - [root addSubview:child]; -} - -// Resulting layout will be set on the UIView hierarchy frames. -[root css_applyLayout]; -``` - -### .NET -The full API can be found in `csharp/Facebook.CSSLayout/CSSNode.cs`. - -```csharp -var root = new CSSNode(); -root.StyleWidth = 100; -root.StyleHeight = 100; - -for (var i = 0; i < 10; i++) -{ - var child = new CSSNode(); - child.StyleHeight = 10; - root.Insert(0, child); -} - -// Get for resulting layout -root.LayoutX; -root.LayoutY; -root.LayoutWidth; -root.LayoutHeight; -``` - -## Contributing -To contribute to CSSLayout you need to first install [buck](https://buckbuild.com) which is the build system used by CSSLayout. CSSLayout is implemented in C with language bindings for Java, Objective-C, and .NET. When making changes to `CSSLayout/CSSLayout.h` please ensure to update `java/jni/CSSJNI.h`, `java/com/facebook/csslayout/CSSNode.java`, `uikit/CSSLayout/UIView+CSSLayout.m`, and `csharp/Facebook.CSSLayout/CSSNode.cs` to reflect the API change. Before submitting any code please run `format.sh` to ensure the code matches the project's code style. - -Before making any larger changes to CSSLayout please open an issue with a RFC so the changes can be discussed first. Generally we are very open to changes and improvements that will benefit the community. - -### Testing -For any changes you make you should ensure that all the tests are passing. In case you make any fixes or additions to the library please also add at least one test to ensure we don't break anything in the future. Tests are located in `tests/CSSLayoutTest.cpp`. Run the tests by executing `buck test //:CSSLayout`. - -Instead of manually writing a test which ensures parity with web implementations of flexbox you can run `gentest/gentest.rb` to generated a test for you. You can write html which you want to verify in CSSLayout, in `gentest/fixtures` folder, such as the following. +Instead of manually writing a test which ensures parity with web implementations of Flexbox you can run `gentest/gentest.rb` to generated a test for you. You can write html which you want to verify in Yoga, in `gentest/fixtures` folder, such as the following. ```html -
+
``` -Run `gentest/gentest.rb` to generate test code and re-run `buck test //:CSSLayout` to validate the behavior. One test case will be generated for every root `div` in the input html. +Run `gentest/gentest.rb` to generate test code and re-run `buck test //:yoga` to validate the behavior. One test case will be generated for every root `div` in the input html. You may need to install the latest watir-webdriver gem (`gem install watir-webdriver`) and [ChromeDriver](https://sites.google.com/a/chromium.org/chromedriver/) to run `gentest/gentest.rb` Ruby script. -### Benchmarks -Benchmarks are located in `benchmarks/CSSBenchmark.c` and can be run with `buck run //benchmarks:benchmarks`. If you think your change has affected performance please run this before and after your change to validate that nothing has regressed. +### .NET +.NET testing is not integrated in buck yet, you might need to set up .NET testing environment. We have a script which to launch C# test on macOS, `csharp/tests/Facebook.Yoga/test_macos.sh`. + +## Code style +For the main C implementation of Yoga clang-format is used to ensure a consistent code style. Please run `bash format.sh` before submitting a pull request. For other languages just try to follow the current code style. + +## Benchmarks +Benchmarks are located in `benchmarks/YGBenchmark.c` and can be run with `buck run //benchmarks:benchmarks`. If you think your change has affected performance please run this before and after your change to validate that nothing has regressed. Benchmarks are run on every commit in CI. diff --git a/CSSLAYOUT_DEFS b/YOGA_DEFS similarity index 76% rename from CSSLAYOUT_DEFS rename to YOGA_DEFS index c73f54ff..137b96fd 100644 --- a/CSSLAYOUT_DEFS +++ b/YOGA_DEFS @@ -1,20 +1,23 @@ -CSSLAYOUT_ROOT = '//...' +YOGA_ROOT = '//...' INFER_ANNOTATIONS_TARGET = '//lib/infer-annotations:infer-annotations' JSR_305_TARGET = '//lib/jsr-305:jsr-305' JUNIT_TARGET = '//lib/junit:junit' PROGRUARD_ANNOTATIONS_TARGET = '//java/com/facebook/proguard/annotations:annotations' SOLOADER_TARGET = '//lib/soloader:soloader' GTEST_TARGET = '//lib/gtest:gtest' -GTEST_DL_URL = 'https://github.com/google/googletest/archive/release-1.7.0.zip' -JNI_DEPS = ['//lib/fb:fbjni'] +JNI_TARGET = '//lib/jni:jni' +FBJNI_TARGET = '//lib/fb:fbjni' + +THIS_IS_FBOBJC = False CXX_LIBRARY_WHITELIST = [ + '//:yoga', '//lib/fb:fbjni', '//java:jni', ] -def csslayout_dep(dep): +def yoga_dep(dep): return '//' + dep class allow_unsafe_import: diff --git a/uikit/CSSLayout/BUCK b/YogaKit/BUCK similarity index 55% rename from uikit/CSSLayout/BUCK rename to YogaKit/BUCK index 2c9ec8fd..4a781038 100644 --- a/uikit/CSSLayout/BUCK +++ b/YogaKit/BUCK @@ -5,14 +5,32 @@ # 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_defs('//CSSLAYOUT_DEFS') +include_defs('//YOGA_DEFS') -UIKIT_CSSLAYOUT_COMPILER_FLAGS = ['-fobjc-arc'] +COMPILER_FLAGS = [ + '-fobjc-arc', + '-Wconditional-uninitialized', + '-Wdangling-else', + '-Wdeprecated-declarations', + '-Wimplicit-retain-self', + '-Wincomplete-implementation', + '-Wobjc-method-access', + '-Wobjc-missing-super-calls', + '-Wmismatched-return-types', + '-Wreturn-type', + '-Wno-global-constructors', + '-Wno-shadow', + '-Wunused-const-variable', + '-Wunused-function', + '-Wunused-property-ivar', + '-Wunused-result', + '-Wunused-value', +] apple_library( - name = 'CSSLayout', - compiler_flags = UIKIT_CSSLAYOUT_COMPILER_FLAGS, - tests = [':CSSLayoutTests'], + name = 'YogaKit', + compiler_flags = COMPILER_FLAGS, + tests = [':YogaKitTests'], srcs = glob(['*.m']), exported_headers = glob(['*.h']), frameworks = [ @@ -20,14 +38,14 @@ apple_library( '$SDKROOT/System/Library/Frameworks/UIKit.framework', ], deps = [ - csslayout_dep(':CSSLayout'), + yoga_dep(':yoga'), ], visibility = ['PUBLIC'], ) apple_test( - name = 'CSSLayoutTests', - compiler_flags = UIKIT_CSSLAYOUT_COMPILER_FLAGS, + name = 'YogaKitTests', + compiler_flags = COMPILER_FLAGS, info_plist = 'Tests/Info.plist', srcs = glob(['Tests/**/*.m']), frameworks = [ @@ -35,7 +53,7 @@ apple_test( '$PLATFORM_DIR/Developer/Library/Frameworks/XCTest.framework', ], deps = [ - ':CSSLayout', + ':YogaKit', ], visibility = ['PUBLIC'], ) diff --git a/uikit/CSSLayout/Tests/Info.plist b/YogaKit/Tests/Info.plist similarity index 100% rename from uikit/CSSLayout/Tests/Info.plist rename to YogaKit/Tests/Info.plist diff --git a/YogaKit/Tests/YogaKitTests.m b/YogaKit/Tests/YogaKitTests.m new file mode 100644 index 00000000..21b7f4ba --- /dev/null +++ b/YogaKit/Tests/YogaKitTests.m @@ -0,0 +1,271 @@ +/** + * 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. + */ + +#import + +#import "UIView+Yoga.h" + +@interface YogaKitTests : XCTestCase +@end + +@implementation YogaKitTests + +#ifndef TRAVIS_CI + +- (void)testNodesAreDeallocedWithSingleView +{ + XCTAssertEqual(0, YGNodeGetInstanceCount()); + + UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; + [view yg_setFlexBasis:1]; + XCTAssertEqual(1, YGNodeGetInstanceCount()); + view = nil; + + XCTAssertEqual(0, YGNodeGetInstanceCount()); +} + +- (void)testNodesAreDeallocedCascade +{ + XCTAssertEqual(0, YGNodeGetInstanceCount()); + + UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; + [view yg_setFlexBasis:1]; + + for (int i=0; i<10; i++) { + UIView *subview = [[UIView alloc] initWithFrame:CGRectZero]; + [subview yg_setFlexBasis:1]; + [view addSubview:subview]; + } + XCTAssertEqual(11, YGNodeGetInstanceCount()); + view = nil; + + XCTAssertEqual(0, YGNodeGetInstanceCount()); +} + +#endif + +- (void)testUsesYoga +{ + UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; + XCTAssertFalse([view yg_usesYoga]); + + [view yg_setUsesYoga:YES]; + XCTAssertTrue([view yg_usesYoga]); + + [view yg_setUsesYoga:NO]; + XCTAssertFalse([view yg_usesYoga]); +} + +- (void)testSizeThatFitsAsserts +{ + UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; + dispatch_sync(dispatch_queue_create("com.facebook.Yoga.testing", DISPATCH_QUEUE_SERIAL), ^(void){ + XCTAssertThrows([view yg_intrinsicSize]); + }); +} + +- (void)testSizeThatFitsSmoke +{ + UIView *container = [[UIView alloc] initWithFrame:CGRectZero]; + [container yg_setUsesYoga:YES]; + [container yg_setFlexDirection:YGFlexDirectionRow]; + [container yg_setAlignItems:YGAlignFlexStart]; + + UILabel *longTextLabel = [[UILabel alloc] initWithFrame:CGRectZero]; + longTextLabel.text = @"This is a very very very very very very very very long piece of text."; + longTextLabel.lineBreakMode = NSLineBreakByTruncatingTail; + longTextLabel.numberOfLines = 1; + [longTextLabel yg_setUsesYoga:YES]; + [longTextLabel yg_setFlexShrink:1]; + [container addSubview:longTextLabel]; + + UIView *textBadgeView = [[UIView alloc] initWithFrame:CGRectZero]; + [textBadgeView yg_setUsesYoga:YES]; + [textBadgeView yg_setMargin:3.0 forEdge:YGEdgeLeft]; + [textBadgeView yg_setWidth:10]; + [textBadgeView yg_setHeight:10]; + [container addSubview:textBadgeView]; + + const CGSize containerSize = [container yg_intrinsicSize]; + XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(514,21), containerSize), @"Size is actually %@", NSStringFromCGSize(containerSize)); +} + +- (void)testFrameAndOriginPlacement +{ + const CGSize containerSize = CGSizeMake(320, 50); + + UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, containerSize.width, containerSize.height)]; + [container yg_setUsesYoga:YES]; + [container yg_setFlexDirection:YGFlexDirectionRow]; + + for (int i = 0; i < 3; i++) { + UIView *subview = [[UIView alloc] initWithFrame:CGRectZero]; + [subview yg_setUsesYoga:YES]; + [subview yg_setFlexGrow:1]; + + [container addSubview:subview]; + } + [container yg_applyLayout]; + + XCTAssertFalse(CGRectIntersectsRect([container.subviews objectAtIndex:0].frame, [container.subviews objectAtIndex:1].frame)); + XCTAssertFalse(CGRectIntersectsRect([container.subviews objectAtIndex:1].frame, [container.subviews objectAtIndex:2].frame)); + XCTAssertFalse(CGRectIntersectsRect([container.subviews objectAtIndex:0].frame, [container.subviews objectAtIndex:2].frame)); + + CGFloat totalWidth = 0; + for (UIView *view in container.subviews) { + totalWidth += view.bounds.size.width; + } + + XCTAssertEqual(containerSize.width, totalWidth, @"The container's width is %.6f, the subviews take up %.6f", containerSize.width, totalWidth); +} + +- (void)testThatLayoutIsCorrectWhenWeSwapViewOrder +{ + const CGSize containerSize = CGSizeMake(300, 50); + + UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, containerSize.width, containerSize.height)]; + [container yg_setUsesYoga:YES]; + [container yg_setFlexDirection:YGFlexDirectionRow]; + + UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero]; + [subview1 yg_setUsesYoga:YES]; + [subview1 yg_setFlexGrow:1]; + [container addSubview:subview1]; + + UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero]; + [subview2 yg_setUsesYoga:YES]; + [subview2 yg_setFlexGrow:1]; + [container addSubview:subview2]; + + UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero]; + [subview3 yg_setUsesYoga:YES]; + [subview3 yg_setFlexGrow:1]; + [container addSubview:subview3]; + + [container yg_applyLayout]; + + XCTAssertTrue(CGRectEqualToRect(subview1.frame, CGRectMake(0, 0, 100, 50))); + XCTAssertTrue(CGRectEqualToRect(subview2.frame, CGRectMake(100, 0, 100, 50)), @"It's actually %@", NSStringFromCGRect(subview2.frame)); + XCTAssertTrue(CGRectEqualToRect(subview3.frame, CGRectMake(200, 0, 100, 50))); + + [container exchangeSubviewAtIndex:2 withSubviewAtIndex:0]; + [subview2 yg_setIncludeInLayout:NO]; + [container yg_applyLayout]; + + XCTAssertTrue(CGRectEqualToRect(subview3.frame, CGRectMake(0, 0, 150, 50))); + XCTAssertTrue(CGRectEqualToRect(subview1.frame, CGRectMake(150, 0, 150, 50))); + + // this frame shouldn't have been modified since last time. + XCTAssertTrue(CGRectEqualToRect(subview2.frame, CGRectMake(100, 0, 100, 50))); +} + +- (void)testThatWeRespectIncludeInLayoutFlag +{ + const CGSize containerSize = CGSizeMake(300, 50); + + UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, containerSize.width, containerSize.height)]; + [container yg_setUsesYoga:YES]; + [container yg_setFlexDirection:YGFlexDirectionRow]; + + UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero]; + [subview1 yg_setUsesYoga:YES]; + [subview1 yg_setFlexGrow:1]; + [container addSubview:subview1]; + + UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero]; + [subview2 yg_setUsesYoga:YES]; + [subview2 yg_setFlexGrow:1]; + [container addSubview:subview2]; + + UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero]; + [subview3 yg_setUsesYoga:YES]; + [subview3 yg_setFlexGrow:1]; + [container addSubview:subview3]; + + [container yg_applyLayout]; + + for (UIView *view in container.subviews) { + XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(100, 50), subview1.bounds.size), @"Actual size is %@", NSStringFromCGSize(view.bounds.size)); + } + + [subview3 yg_setIncludeInLayout:NO]; + [container yg_applyLayout]; + + XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(150, 50), subview1.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview1.bounds.size)); + XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(150, 50), subview2.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview2.bounds.size)); + + // We don't set the frame to zero, so, it should be set to what it was previously at. + XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(100, 50), subview3.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview3.bounds.size)); +} + +- (void)testThatNumberOfChildrenIsCorrectWhenWeIgnoreSubviews +{ + UIView *container = [[UIView alloc] initWithFrame:CGRectZero]; + [container yg_setUsesYoga:YES]; + [container yg_setFlexDirection:YGFlexDirectionRow]; + + UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero]; + [subview1 yg_setUsesYoga:YES]; + [subview1 yg_setIncludeInLayout:NO]; + [container addSubview:subview1]; + + UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero]; + [subview2 yg_setUsesYoga:YES]; + [subview2 yg_setIncludeInLayout:NO]; + [container addSubview:subview2]; + + UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero]; + [subview3 yg_setUsesYoga:YES]; + [subview3 yg_setIncludeInLayout:YES]; + [container addSubview:subview3]; + + [container yg_applyLayout]; + XCTAssertEqual(1, [container yg_numberOfChildren]); + + [subview2 yg_setIncludeInLayout:YES]; + [container yg_applyLayout]; + XCTAssertEqual(2, [container yg_numberOfChildren]); +} + +- (void)testThatViewNotIncludedInFirstLayoutPassAreIncludedInSecond +{ + UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)]; + [container yg_setUsesYoga:YES]; + [container yg_setFlexDirection:YGFlexDirectionRow]; + + UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero]; + [subview1 yg_setUsesYoga:YES]; + [subview1 yg_setFlexGrow:1]; + [container addSubview:subview1]; + + UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero]; + [subview2 yg_setUsesYoga:YES]; + [subview2 yg_setFlexGrow:1]; + [container addSubview:subview2]; + + UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero]; + [subview3 yg_setUsesYoga:YES]; + [subview3 yg_setFlexGrow:1]; + [subview3 yg_setIncludeInLayout:NO]; + [container addSubview:subview3]; + + [container yg_applyLayout]; + + XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(150, 50), subview1.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview1.bounds.size)); + XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(150, 50), subview2.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview2.bounds.size)); + XCTAssertTrue(CGSizeEqualToSize(CGSizeZero, subview3.bounds.size), @"Actual size %@", NSStringFromCGSize(subview3.bounds.size)); + + [subview3 yg_setIncludeInLayout:YES]; + [container yg_applyLayout]; + for (UIView *view in container.subviews) { + XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(100, 50), subview1.bounds.size), @"Actual size is %@", NSStringFromCGSize(view.bounds.size)); + } +} + +@end diff --git a/YogaKit/UIView+Yoga.h b/YogaKit/UIView+Yoga.h new file mode 100644 index 00000000..97bb2532 --- /dev/null +++ b/YogaKit/UIView+Yoga.h @@ -0,0 +1,72 @@ +/** + * 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. + */ + +#import +#import + +@interface UIView (Yoga) + +/** + The property that decides if we should include this view when calculating layout. Defaults to YES. + */ +@property (nonatomic, readwrite, assign, setter=yg_setIncludeInLayout:) BOOL yg_includeInLayout; + +/** + The property that decides during layout/sizing whether or not yg_* properties should be applied. Defaults to NO. + */ +@property (nonatomic, readwrite, assign, setter=yg_setUsesYoga:) BOOL yg_usesYoga; + +- (void)yg_setDirection:(YGDirection)direction; +- (void)yg_setFlexDirection:(YGFlexDirection)flexDirection; +- (void)yg_setJustifyContent:(YGJustify)justifyContent; +- (void)yg_setAlignContent:(YGAlign)alignContent; +- (void)yg_setAlignItems:(YGAlign)alignItems; +- (void)yg_setAlignSelf:(YGAlign)alignSelf; +- (void)yg_setPositionType:(YGPositionType)positionType; +- (void)yg_setFlexWrap:(YGWrap)flexWrap; + +- (void)yg_setFlexGrow:(CGFloat)flexGrow; +- (void)yg_setFlexShrink:(CGFloat)flexShrink; +- (void)yg_setFlexBasis:(CGFloat)flexBasis; + +- (void)yg_setPosition:(CGFloat)position forEdge:(YGEdge)edge; +- (void)yg_setMargin:(CGFloat)margin forEdge:(YGEdge)edge; +- (void)yg_setPadding:(CGFloat)padding forEdge:(YGEdge)edge; + +- (void)yg_setWidth:(CGFloat)width; +- (void)yg_setHeight:(CGFloat)height; +- (void)yg_setMinWidth:(CGFloat)minWidth; +- (void)yg_setMinHeight:(CGFloat)minHeight; +- (void)yg_setMaxWidth:(CGFloat)maxWidth; +- (void)yg_setMaxHeight:(CGFloat)maxHeight; + +// Yoga specific properties, not compatible with flexbox specification +- (void)yg_setAspectRatio:(CGFloat)aspectRatio; + +/** + Get the resolved direction of this node. This won't be YGDirectionInherit + */ +- (YGDirection)yg_resolvedDirection; + +/** + Perform a layout calculation and update the frames of the views in the hierarchy with th results + */ +- (void)yg_applyLayout; + +/** + Returns the size of the view if no constraints were given. This could equivalent to calling [self sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)]; + */ +- (CGSize)yg_intrinsicSize; + +/** + Returns the number of children that are using Flexbox. + */ +- (NSUInteger)yg_numberOfChildren; + +@end diff --git a/YogaKit/UIView+Yoga.m b/YogaKit/UIView+Yoga.m new file mode 100644 index 00000000..0ad7bddc --- /dev/null +++ b/YogaKit/UIView+Yoga.m @@ -0,0 +1,379 @@ +/** + * 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. + */ + +#import "UIView+Yoga.h" + +#import + +@interface YGNodeBridge : NSObject +@property (nonatomic, assign, readonly) YGNodeRef cnode; +@end + +@implementation YGNodeBridge + ++ (void)initialize +{ + YGSetExperimentalFeatureEnabled(YGExperimentalFeatureWebFlexBasis, true); +} + +- (instancetype)init +{ + if ([super init]) { + _cnode = YGNodeNew(); + } + + return self; +} + +- (void)dealloc +{ + YGNodeFree(_cnode); +} +@end + +@implementation UIView (Yoga) + +- (BOOL)yg_usesYoga +{ + NSNumber *usesYoga = objc_getAssociatedObject(self, @selector(yg_usesYoga)); + return [usesYoga boolValue]; +} + +- (BOOL)yg_includeInLayout +{ + NSNumber *includeInLayout = objc_getAssociatedObject(self, @selector(yg_includeInLayout)); + return (includeInLayout != nil) ? [includeInLayout boolValue] : YES; +} + +- (NSUInteger)yg_numberOfChildren +{ + return YGNodeChildCount([self ygNode]); +} + +#pragma mark - Setters + +- (void)yg_setIncludeInLayout:(BOOL)includeInLayout +{ + objc_setAssociatedObject( + self, + @selector(yg_includeInLayout), + @(includeInLayout), + OBJC_ASSOCIATION_RETAIN_NONATOMIC); +} + +- (void)yg_setUsesYoga:(BOOL)enabled +{ + objc_setAssociatedObject( + self, + @selector(yg_usesYoga), + @(enabled), + OBJC_ASSOCIATION_RETAIN_NONATOMIC); +} + +- (void)yg_setDirection:(YGDirection)direction +{ + YGNodeStyleSetDirection([self ygNode], direction); +} + +- (void)yg_setFlexDirection:(YGFlexDirection)flexDirection +{ + YGNodeStyleSetFlexDirection([self ygNode], flexDirection); +} + +- (void)yg_setJustifyContent:(YGJustify)justifyContent +{ + YGNodeStyleSetJustifyContent([self ygNode], justifyContent); +} + +- (void)yg_setAlignContent:(YGAlign)alignContent +{ + YGNodeStyleSetAlignContent([self ygNode], alignContent); +} + +- (void)yg_setAlignItems:(YGAlign)alignItems +{ + YGNodeStyleSetAlignItems([self ygNode], alignItems); +} + +- (void)yg_setAlignSelf:(YGAlign)alignSelf +{ + YGNodeStyleSetAlignSelf([self ygNode], alignSelf); +} + +- (void)yg_setPositionType:(YGPositionType)positionType +{ + YGNodeStyleSetPositionType([self ygNode], positionType); +} + +- (void)yg_setFlexWrap:(YGWrap)flexWrap +{ + YGNodeStyleSetFlexWrap([self ygNode], flexWrap); +} + +- (void)yg_setFlexGrow:(CGFloat)flexGrow +{ + YGNodeStyleSetFlexGrow([self ygNode], flexGrow); +} + +- (void)yg_setFlexShrink:(CGFloat)flexShrink +{ + YGNodeStyleSetFlexShrink([self ygNode], flexShrink); +} + +- (void)yg_setFlexBasis:(CGFloat)flexBasis +{ + YGNodeStyleSetFlexBasis([self ygNode], flexBasis); +} + +- (void)yg_setPosition:(CGFloat)position forEdge:(YGEdge)edge +{ + YGNodeStyleSetPosition([self ygNode], edge, position); +} + +- (void)yg_setMargin:(CGFloat)margin forEdge:(YGEdge)edge +{ + YGNodeStyleSetMargin([self ygNode], edge, margin); +} + +- (void)yg_setPadding:(CGFloat)padding forEdge:(YGEdge)edge +{ + YGNodeStyleSetPadding([self ygNode], edge, padding); +} + +- (void)yg_setWidth:(CGFloat)width +{ + YGNodeStyleSetWidth([self ygNode], width); +} + +- (void)yg_setHeight:(CGFloat)height +{ + YGNodeStyleSetHeight([self ygNode], height); +} + +- (void)yg_setMinWidth:(CGFloat)minWidth +{ + YGNodeStyleSetMinWidth([self ygNode], minWidth); +} + +- (void)yg_setMinHeight:(CGFloat)minHeight +{ + YGNodeStyleSetMinHeight([self ygNode], minHeight); +} + +- (void)yg_setMaxWidth:(CGFloat)maxWidth +{ + YGNodeStyleSetMaxWidth([self ygNode], maxWidth); +} + +- (void)yg_setMaxHeight:(CGFloat)maxHeight +{ + YGNodeStyleSetMaxHeight([self ygNode], maxHeight); +} + +- (void)yg_setAspectRatio:(CGFloat)aspectRatio +{ + YGNodeStyleSetAspectRatio([self ygNode], aspectRatio); +} + +#pragma mark - Layout and Sizing + +- (YGDirection)yg_resolvedDirection +{ + return YGNodeLayoutGetDirection([self ygNode]); +} + +- (void)yg_applyLayout +{ + [self calculateLayoutWithSize:self.bounds.size]; + YGApplyLayoutToViewHierarchy(self); +} + +- (CGSize)yg_intrinsicSize +{ + const CGSize constrainedSize = { + .width = YGUndefined, + .height = YGUndefined, + }; + return [self calculateLayoutWithSize:constrainedSize]; +} + +#pragma mark - Private + +- (YGNodeRef)ygNode +{ + YGNodeBridge *node = objc_getAssociatedObject(self, @selector(ygNode)); + if (!node) { + node = [YGNodeBridge new]; + YGNodeSetContext(node.cnode, (__bridge void *) self); + objc_setAssociatedObject(self, @selector(ygNode), node, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + } + + return node.cnode; +} + +- (CGSize)calculateLayoutWithSize:(CGSize)size +{ + NSAssert([NSThread isMainThread], @"YG Layout calculation must be done on main."); + NSAssert([self yg_usesYoga], @"YG Layout is not enabled for this view."); + + YGAttachNodesFromViewHierachy(self); + + const YGNodeRef node = [self ygNode]; + YGNodeCalculateLayout( + node, + size.width, + size.height, + YGNodeStyleGetDirection(node)); + + return (CGSize) { + .width = YGNodeLayoutGetWidth(node), + .height = YGNodeLayoutGetHeight(node), + }; +} + +static YGSize YGMeasureView( + YGNodeRef node, + float width, + YGMeasureMode widthMode, + float height, + YGMeasureMode heightMode) +{ + const CGFloat constrainedWidth = (widthMode == YGMeasureModeUndefined) ? CGFLOAT_MAX : width; + const CGFloat constrainedHeight = (heightMode == YGMeasureModeUndefined) ? CGFLOAT_MAX: height; + + UIView *view = (__bridge UIView*) YGNodeGetContext(node); + const CGSize sizeThatFits = [view sizeThatFits:(CGSize) { + .width = constrainedWidth, + .height = constrainedHeight, + }]; + + return (YGSize) { + .width = YGSanitizeMeasurement(constrainedWidth, sizeThatFits.width, widthMode), + .height = YGSanitizeMeasurement(constrainedHeight, sizeThatFits.height, heightMode), + }; +} + +static CGFloat YGSanitizeMeasurement( + CGFloat constrainedSize, + CGFloat measuredSize, + YGMeasureMode measureMode) +{ + CGFloat result; + if (measureMode == YGMeasureModeExactly) { + result = constrainedSize; + } else if (measureMode == YGMeasureModeAtMost) { + result = MIN(constrainedSize, measuredSize); + } else { + result = measuredSize; + } + + return result; +} + +static void YGAttachNodesFromViewHierachy(UIView *view) { + YGNodeRef node = [view ygNode]; + + // Only leaf nodes should have a measure function + if (![view yg_usesYoga] || view.subviews.count == 0) { + YGNodeSetMeasureFunc(node, YGMeasureView); + YGRemoveAllChildren(node); + } else { + YGNodeSetMeasureFunc(node, NULL); + + // Create a list of all the subviews that we are going to use for layout. + NSMutableArray *subviewsToInclude = [[NSMutableArray alloc] initWithCapacity:view.subviews.count]; + for (UIView *subview in view.subviews) { + if ([subview yg_includeInLayout]) { + [subviewsToInclude addObject:subview]; + } + } + + BOOL shouldReconstructChildList = NO; + if (YGNodeChildCount(node) != subviewsToInclude.count) { + shouldReconstructChildList = YES; + } else { + for (int i = 0; i < subviewsToInclude.count; i++) { + if (YGNodeGetChild(node, i) != [subviewsToInclude[i] ygNode]) { + shouldReconstructChildList = YES; + break; + } + } + } + + if (shouldReconstructChildList) { + YGRemoveAllChildren(node); + + for (int i = 0 ; i < subviewsToInclude.count; i++) { + UIView *const subview = subviewsToInclude[i]; + YGNodeInsertChild(node, [subview ygNode], i); + YGAttachNodesFromViewHierachy(subview); + } + } + } +} + +static void YGRemoveAllChildren(const YGNodeRef node) +{ + if (node == NULL) { + return; + } + + while (YGNodeChildCount(node) > 0) { + YGNodeRemoveChild(node, YGNodeGetChild(node, YGNodeChildCount(node) - 1)); + } +} + +static CGFloat YGRoundPixelValue(CGFloat value) +{ + static CGFloat scale; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^(){ + scale = [UIScreen mainScreen].scale; + }); + + return round(value * scale) / scale; +} + +static void YGApplyLayoutToViewHierarchy(UIView *view) { + NSCAssert([NSThread isMainThread], @"Framesetting should only be done on the main thread."); + if (![view yg_includeInLayout]) { + return; + } + + YGNodeRef node = [view ygNode]; + const CGPoint topLeft = { + YGNodeLayoutGetLeft(node), + YGNodeLayoutGetTop(node), + }; + + const CGPoint bottomRight = { + topLeft.x + YGNodeLayoutGetWidth(node), + topLeft.y + YGNodeLayoutGetHeight(node), + }; + + view.frame = (CGRect) { + .origin = { + .x = YGRoundPixelValue(topLeft.x), + .y = YGRoundPixelValue(topLeft.y), + }, + .size = { + .width = YGRoundPixelValue(bottomRight.x) - YGRoundPixelValue(topLeft.x), + .height = YGRoundPixelValue(bottomRight.y) - YGRoundPixelValue(topLeft.y), + }, + }; + + const BOOL isLeaf = ![view yg_usesYoga] || view.subviews.count == 0; + if (!isLeaf) { + for (NSUInteger i = 0; i < view.subviews.count; i++) { + YGApplyLayoutToViewHierarchy(view.subviews[i]); + } + } +} + +@end diff --git a/YogaKit/YogaKitSample/YogaKitSample.xcodeproj/project.pbxproj b/YogaKit/YogaKitSample/YogaKitSample.xcodeproj/project.pbxproj new file mode 100644 index 00000000..7232ec9f --- /dev/null +++ b/YogaKit/YogaKitSample/YogaKitSample.xcodeproj/project.pbxproj @@ -0,0 +1,376 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 13687D481DF8748400E7C260 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13687D471DF8748400E7C260 /* main.m */; }; + 13687D4B1DF8748400E7C260 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13687D4A1DF8748400E7C260 /* AppDelegate.m */; }; + 13687D4E1DF8748400E7C260 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 13687D4D1DF8748400E7C260 /* ViewController.m */; }; + 13687D531DF8748400E7C260 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13687D521DF8748400E7C260 /* Assets.xcassets */; }; + 13687D781DF878C600E7C260 /* YGEnums.h in yoga */ = {isa = PBXBuildFile; fileRef = 13687D5E1DF8778F00E7C260 /* YGEnums.h */; }; + 13687D791DF878C600E7C260 /* YGMacros.h in yoga */ = {isa = PBXBuildFile; fileRef = 13687D5F1DF8778F00E7C260 /* YGMacros.h */; }; + 13687D7A1DF878C600E7C260 /* Yoga.h in yoga */ = {isa = PBXBuildFile; fileRef = 13687D631DF8778F00E7C260 /* Yoga.h */; }; + 13687D7C1DF878DD00E7C260 /* UIView+Yoga.h in YogaKit */ = {isa = PBXBuildFile; fileRef = 13687D691DF8778F00E7C260 /* UIView+Yoga.h */; }; + 13687D801DF87CEC00E7C260 /* UIView+Yoga.m in Sources */ = {isa = PBXBuildFile; fileRef = 13687D6A1DF8778F00E7C260 /* UIView+Yoga.m */; }; + 13687D811DF87CF200E7C260 /* YGNodeList.c in Sources */ = {isa = PBXBuildFile; fileRef = 13687D601DF8778F00E7C260 /* YGNodeList.c */; }; + 13687D821DF87CF200E7C260 /* Yoga.c in Sources */ = {isa = PBXBuildFile; fileRef = 13687D621DF8778F00E7C260 /* Yoga.c */; }; + 13687D851DF87D1E00E7C260 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 13687D841DF87D1E00E7C260 /* UIKit.framework */; }; + 13687D871DF87D2400E7C260 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 13687D861DF87D2400E7C260 /* Foundation.framework */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 13687D771DF878A000E7C260 /* yoga */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = include/yoga; + dstSubfolderSpec = 16; + files = ( + 13687D781DF878C600E7C260 /* YGEnums.h in yoga */, + 13687D791DF878C600E7C260 /* YGMacros.h in yoga */, + 13687D7A1DF878C600E7C260 /* Yoga.h in yoga */, + ); + name = yoga; + runOnlyForDeploymentPostprocessing = 0; + }; + 13687D7B1DF878CE00E7C260 /* YogaKit */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = include/YogaKit; + dstSubfolderSpec = 16; + files = ( + 13687D7C1DF878DD00E7C260 /* UIView+Yoga.h in YogaKit */, + ); + name = YogaKit; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 13687D431DF8748400E7C260 /* YogaKitSample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = YogaKitSample.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 13687D471DF8748400E7C260 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 13687D491DF8748400E7C260 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 13687D4A1DF8748400E7C260 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 13687D4C1DF8748400E7C260 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; + 13687D4D1DF8748400E7C260 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; + 13687D521DF8748400E7C260 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 13687D571DF8748400E7C260 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 13687D5E1DF8778F00E7C260 /* YGEnums.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = YGEnums.h; sourceTree = ""; }; + 13687D5F1DF8778F00E7C260 /* YGMacros.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = YGMacros.h; sourceTree = ""; }; + 13687D601DF8778F00E7C260 /* YGNodeList.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = YGNodeList.c; sourceTree = ""; }; + 13687D611DF8778F00E7C260 /* YGNodeList.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = YGNodeList.h; sourceTree = ""; }; + 13687D621DF8778F00E7C260 /* Yoga.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = Yoga.c; sourceTree = ""; }; + 13687D631DF8778F00E7C260 /* Yoga.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Yoga.h; sourceTree = ""; }; + 13687D691DF8778F00E7C260 /* UIView+Yoga.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIView+Yoga.h"; sourceTree = ""; }; + 13687D6A1DF8778F00E7C260 /* UIView+Yoga.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIView+Yoga.m"; sourceTree = ""; }; + 13687D841DF87D1E00E7C260 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; + 13687D861DF87D2400E7C260 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 13687D401DF8748300E7C260 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 13687D871DF87D2400E7C260 /* Foundation.framework in Frameworks */, + 13687D851DF87D1E00E7C260 /* UIKit.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 13687D3A1DF8748300E7C260 = { + isa = PBXGroup; + children = ( + 13687D5D1DF8778F00E7C260 /* yoga */, + 13687D641DF8778F00E7C260 /* YogaKit */, + 13687D451DF8748400E7C260 /* YogaKitSample */, + 13687D441DF8748400E7C260 /* Products */, + 13687D831DF87D1E00E7C260 /* Frameworks */, + ); + sourceTree = ""; + }; + 13687D441DF8748400E7C260 /* Products */ = { + isa = PBXGroup; + children = ( + 13687D431DF8748400E7C260 /* YogaKitSample.app */, + ); + name = Products; + sourceTree = ""; + }; + 13687D451DF8748400E7C260 /* YogaKitSample */ = { + isa = PBXGroup; + children = ( + 13687D491DF8748400E7C260 /* AppDelegate.h */, + 13687D4A1DF8748400E7C260 /* AppDelegate.m */, + 13687D4C1DF8748400E7C260 /* ViewController.h */, + 13687D4D1DF8748400E7C260 /* ViewController.m */, + 13687D521DF8748400E7C260 /* Assets.xcassets */, + 13687D571DF8748400E7C260 /* Info.plist */, + 13687D461DF8748400E7C260 /* Supporting Files */, + ); + path = YogaKitSample; + sourceTree = ""; + }; + 13687D461DF8748400E7C260 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 13687D471DF8748400E7C260 /* main.m */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + 13687D5D1DF8778F00E7C260 /* yoga */ = { + isa = PBXGroup; + children = ( + 13687D5E1DF8778F00E7C260 /* YGEnums.h */, + 13687D5F1DF8778F00E7C260 /* YGMacros.h */, + 13687D601DF8778F00E7C260 /* YGNodeList.c */, + 13687D611DF8778F00E7C260 /* YGNodeList.h */, + 13687D621DF8778F00E7C260 /* Yoga.c */, + 13687D631DF8778F00E7C260 /* Yoga.h */, + ); + name = yoga; + path = ../../yoga; + sourceTree = ""; + }; + 13687D641DF8778F00E7C260 /* YogaKit */ = { + isa = PBXGroup; + children = ( + 13687D691DF8778F00E7C260 /* UIView+Yoga.h */, + 13687D6A1DF8778F00E7C260 /* UIView+Yoga.m */, + ); + name = YogaKit; + path = ..; + sourceTree = ""; + }; + 13687D831DF87D1E00E7C260 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 13687D861DF87D2400E7C260 /* Foundation.framework */, + 13687D841DF87D1E00E7C260 /* UIKit.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 13687D421DF8748300E7C260 /* YogaKitSample */ = { + isa = PBXNativeTarget; + buildConfigurationList = 13687D5A1DF8748400E7C260 /* Build configuration list for PBXNativeTarget "YogaKitSample" */; + buildPhases = ( + 13687D771DF878A000E7C260 /* yoga */, + 13687D7B1DF878CE00E7C260 /* YogaKit */, + 13687D3F1DF8748300E7C260 /* Sources */, + 13687D401DF8748300E7C260 /* Frameworks */, + 13687D411DF8748300E7C260 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = YogaKitSample; + productName = YogaKitSample; + productReference = 13687D431DF8748400E7C260 /* YogaKitSample.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 13687D3B1DF8748300E7C260 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0810; + ORGANIZATIONNAME = facebook; + TargetAttributes = { + 13687D421DF8748300E7C260 = { + CreatedOnToolsVersion = 8.1; + ProvisioningStyle = Automatic; + }; + }; + }; + buildConfigurationList = 13687D3E1DF8748300E7C260 /* Build configuration list for PBXProject "YogaKitSample" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 13687D3A1DF8748300E7C260; + productRefGroup = 13687D441DF8748400E7C260 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 13687D421DF8748300E7C260 /* YogaKitSample */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 13687D411DF8748300E7C260 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 13687D531DF8748400E7C260 /* Assets.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 13687D3F1DF8748300E7C260 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 13687D801DF87CEC00E7C260 /* UIView+Yoga.m in Sources */, + 13687D4E1DF8748400E7C260 /* ViewController.m in Sources */, + 13687D4B1DF8748400E7C260 /* AppDelegate.m in Sources */, + 13687D821DF87CF200E7C260 /* Yoga.c in Sources */, + 13687D811DF87CF200E7C260 /* YGNodeList.c in Sources */, + 13687D481DF8748400E7C260 /* main.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 13687D581DF8748400E7C260 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVES = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 10.1; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + }; + name = Debug; + }; + 13687D591DF8748400E7C260 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVES = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 10.1; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 13687D5B1DF8748400E7C260 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + INFOPLIST_FILE = YogaKitSample/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.facebook.YogaKitSample; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 13687D5C1DF8748400E7C260 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + INFOPLIST_FILE = YogaKitSample/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.facebook.YogaKitSample; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 13687D3E1DF8748300E7C260 /* Build configuration list for PBXProject "YogaKitSample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 13687D581DF8748400E7C260 /* Debug */, + 13687D591DF8748400E7C260 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 13687D5A1DF8748400E7C260 /* Build configuration list for PBXNativeTarget "YogaKitSample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 13687D5B1DF8748400E7C260 /* Debug */, + 13687D5C1DF8748400E7C260 /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; +/* End XCConfigurationList section */ + }; + rootObject = 13687D3B1DF8748300E7C260 /* Project object */; +} diff --git a/YogaKit/YogaKitSample/YogaKitSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/YogaKit/YogaKitSample/YogaKitSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..b8f12e0b --- /dev/null +++ b/YogaKit/YogaKitSample/YogaKitSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/YogaKit/YogaKitSample/YogaKitSample.xcodeproj/project.xcworkspace/xcuserdata/emilsj.xcuserdatad/UserInterfaceState.xcuserstate b/YogaKit/YogaKitSample/YogaKitSample.xcodeproj/project.xcworkspace/xcuserdata/emilsj.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 00000000..47db969a Binary files /dev/null and b/YogaKit/YogaKitSample/YogaKitSample.xcodeproj/project.xcworkspace/xcuserdata/emilsj.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/YogaKit/YogaKitSample/YogaKitSample.xcodeproj/xcuserdata/emilsj.xcuserdatad/xcschemes/YogaKitSample.xcscheme b/YogaKit/YogaKitSample/YogaKitSample.xcodeproj/xcuserdata/emilsj.xcuserdatad/xcschemes/YogaKitSample.xcscheme new file mode 100644 index 00000000..e785e85e --- /dev/null +++ b/YogaKit/YogaKitSample/YogaKitSample.xcodeproj/xcuserdata/emilsj.xcuserdatad/xcschemes/YogaKitSample.xcscheme @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/YogaKit/YogaKitSample/YogaKitSample.xcodeproj/xcuserdata/emilsj.xcuserdatad/xcschemes/xcschememanagement.plist b/YogaKit/YogaKitSample/YogaKitSample.xcodeproj/xcuserdata/emilsj.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 00000000..336f995f --- /dev/null +++ b/YogaKit/YogaKitSample/YogaKitSample.xcodeproj/xcuserdata/emilsj.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,22 @@ + + + + + SchemeUserState + + YogaKitSample.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + 13687D421DF8748300E7C260 + + primary + + + + + diff --git a/YogaKit/YogaKitSample/YogaKitSample/AppDelegate.h b/YogaKit/YogaKitSample/YogaKitSample/AppDelegate.h new file mode 100644 index 00000000..dd7af882 --- /dev/null +++ b/YogaKit/YogaKitSample/YogaKitSample/AppDelegate.h @@ -0,0 +1,16 @@ +/** + * Copyright 2014-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the license found in the + * LICENSE-examples file in the root directory of this source tree. + */ + +#import + +@interface AppDelegate : UIResponder + +@property (strong, nonatomic) UIWindow *window; + +@end + diff --git a/YogaKit/YogaKitSample/YogaKitSample/AppDelegate.m b/YogaKit/YogaKitSample/YogaKitSample/AppDelegate.m new file mode 100644 index 00000000..d1840bc7 --- /dev/null +++ b/YogaKit/YogaKitSample/YogaKitSample/AppDelegate.m @@ -0,0 +1,27 @@ +/** + * Copyright 2014-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the license found in the + * LICENSE-examples file in the root directory of this source tree. + */ + +#import "AppDelegate.h" +#import "ViewController.h" + +@interface AppDelegate () + +@end + +@implementation AppDelegate + + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; + self.window.rootViewController = [ViewController new]; + self.window.backgroundColor = [UIColor whiteColor]; + [self.window makeKeyAndVisible]; + return YES; +} + +@end diff --git a/YogaKit/YogaKitSample/YogaKitSample/Assets.xcassets/AppIcon.appiconset/Contents.json b/YogaKit/YogaKitSample/YogaKitSample/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 00000000..b8236c65 --- /dev/null +++ b/YogaKit/YogaKitSample/YogaKitSample/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,48 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/YogaKit/YogaKitSample/YogaKitSample/Info.plist b/YogaKit/YogaKitSample/YogaKitSample/Info.plist new file mode 100644 index 00000000..22ca2cd4 --- /dev/null +++ b/YogaKit/YogaKitSample/YogaKitSample/Info.plist @@ -0,0 +1,36 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/YogaKit/YogaKitSample/YogaKitSample/ViewController.h b/YogaKit/YogaKitSample/YogaKitSample/ViewController.h new file mode 100644 index 00000000..f5642871 --- /dev/null +++ b/YogaKit/YogaKitSample/YogaKitSample/ViewController.h @@ -0,0 +1,15 @@ +/** + * Copyright 2014-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the license found in the + * LICENSE-examples file in the root directory of this source tree. + */ + +#import + +@interface ViewController : UIViewController + + +@end + diff --git a/YogaKit/YogaKitSample/YogaKitSample/ViewController.m b/YogaKit/YogaKitSample/YogaKitSample/ViewController.m new file mode 100644 index 00000000..a13dae6f --- /dev/null +++ b/YogaKit/YogaKitSample/YogaKitSample/ViewController.m @@ -0,0 +1,60 @@ +/** + * Copyright 2014-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the license found in the + * LICENSE-examples file in the root directory of this source tree. + */ + +#import "ViewController.h" + +#import + +@interface ViewController () + +@end + +@implementation ViewController + +- (void)viewDidLoad +{ + UIView *root = self.view; + root.backgroundColor = [UIColor redColor]; + [root yg_setUsesYoga:YES]; + [root yg_setWidth:self.view.bounds.size.width]; + [root yg_setHeight:self.view.bounds.size.height]; + [root yg_setAlignItems:YGAlignCenter]; + [root yg_setJustifyContent:YGJustifyCenter]; + + UIView *child1 = [UIView new]; + child1.backgroundColor = [UIColor blueColor]; + [child1 yg_setUsesYoga:YES]; + [child1 yg_setWidth:100]; + [child1 yg_setHeight:100]; + + UIView *child2 = [UIView new]; + child2.backgroundColor = [UIColor greenColor]; + child2.frame = (CGRect) { + .size = { + .width = 200, + .height = 100, + } + }; + + UIView *child3 = [UIView new]; + child3.backgroundColor = [UIColor yellowColor]; + child3.frame = (CGRect) { + .size = { + .width = 100, + .height = 100, + } + }; + + [child2 addSubview:child3]; + [root addSubview:child1]; + [root addSubview:child2]; + [root yg_applyLayout]; +} + + +@end diff --git a/YogaKit/YogaKitSample/YogaKitSample/main.m b/YogaKit/YogaKitSample/YogaKitSample/main.m new file mode 100644 index 00000000..bbef0040 --- /dev/null +++ b/YogaKit/YogaKitSample/YogaKitSample/main.m @@ -0,0 +1,16 @@ +/** + * Copyright 2014-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the license found in the + * LICENSE-examples file in the root directory of this source tree. + */ + +#import +#import "AppDelegate.h" + +int main(int argc, char * argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +} diff --git a/benchmark/BUCK b/benchmark/BUCK index 918600b2..1dd388cc 100644 --- a/benchmark/BUCK +++ b/benchmark/BUCK @@ -5,7 +5,7 @@ # 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_defs('//CSSLAYOUT_DEFS') +include_defs('//YOGA_DEFS') cxx_binary( name = 'benchmark', @@ -21,7 +21,7 @@ cxx_binary( '-std=c11', ], deps = [ - csslayout_dep(':CSSLayout'), + yoga_dep(':yoga'), ], visibility = ['PUBLIC'], ) diff --git a/benchmark/CSSBenchmark.c b/benchmark/CSSBenchmark.c deleted file mode 100644 index e08a1df7..00000000 --- a/benchmark/CSSBenchmark.c +++ /dev/null @@ -1,119 +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 "CSSBenchmark.h" - -#include - -static CSSSize _measure(CSSNodeRef node, - float width, - CSSMeasureMode widthMode, - float height, - CSSMeasureMode heightMode) { - return (CSSSize){ - .width = widthMode == CSSMeasureModeUndefined ? 10 : width, - .height = heightMode == CSSMeasureModeUndefined ? 10 : width, - }; -} - -CSS_BENCHMARKS({ - - CSS_BENCHMARK("Stack with flex", { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - for (uint32_t i = 0; i < 10; i++) { - const CSSNodeRef child = CSSNodeNew(); - CSSNodeSetMeasureFunc(child, _measure); - CSSNodeStyleSetFlex(child, 1); - CSSNodeInsertChild(root, child, 0); - } - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - CSSNodeFreeRecursive(root); - }); - - CSS_BENCHMARK("Align stretch in undefined axis", { - const CSSNodeRef root = CSSNodeNew(); - - for (uint32_t i = 0; i < 10; i++) { - const CSSNodeRef child = CSSNodeNew(); - CSSNodeStyleSetHeight(child, 20); - CSSNodeSetMeasureFunc(child, _measure); - CSSNodeInsertChild(root, child, 0); - } - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - CSSNodeFreeRecursive(root); - }); - - CSS_BENCHMARK("Nested flex", { - const CSSNodeRef root = CSSNodeNew(); - - for (uint32_t i = 0; i < 10; i++) { - const CSSNodeRef child = CSSNodeNew(); - CSSNodeSetMeasureFunc(child, _measure); - CSSNodeStyleSetFlex(child, 1); - CSSNodeInsertChild(root, child, 0); - - for (uint32_t ii = 0; ii < 10; ii++) { - const CSSNodeRef grandChild = CSSNodeNew(); - CSSNodeSetMeasureFunc(grandChild, _measure); - CSSNodeStyleSetFlex(grandChild, 1); - CSSNodeInsertChild(child, grandChild, 0); - } - } - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - CSSNodeFreeRecursive(root); - }); - - CSS_BENCHMARK("Huge nested layout", { - const CSSNodeRef root = CSSNodeNew(); - - for (uint32_t i = 0; i < 10; i++) { - const CSSNodeRef child = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(child, 1); - CSSNodeStyleSetWidth(child, 10); - CSSNodeStyleSetHeight(child, 10); - CSSNodeInsertChild(root, child, 0); - - for (uint32_t ii = 0; ii < 10; ii++) { - const CSSNodeRef grandChild = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(grandChild, CSSFlexDirectionRow); - CSSNodeStyleSetFlexGrow(grandChild, 1); - CSSNodeStyleSetWidth(grandChild, 10); - CSSNodeStyleSetHeight(grandChild, 10); - CSSNodeInsertChild(child, grandChild, 0); - - for (uint32_t iii = 0; iii < 10; iii++) { - const CSSNodeRef grandGrandChild = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(grandGrandChild, 1); - CSSNodeStyleSetWidth(grandGrandChild, 10); - CSSNodeStyleSetHeight(grandGrandChild, 10); - CSSNodeInsertChild(grandChild, grandGrandChild, 0); - - for (uint32_t iii = 0; iii < 10; iii++) { - const CSSNodeRef grandGrandGrandChild = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(grandGrandGrandChild, CSSFlexDirectionRow); - CSSNodeStyleSetFlexGrow(grandGrandGrandChild, 1); - CSSNodeStyleSetWidth(grandGrandGrandChild, 10); - CSSNodeStyleSetHeight(grandGrandGrandChild, 10); - CSSNodeInsertChild(grandGrandChild, grandGrandGrandChild, 0); - } - } - } - } - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - CSSNodeFreeRecursive(root); - }); - -}); diff --git a/benchmark/YGBenchmark.c b/benchmark/YGBenchmark.c new file mode 100644 index 00000000..2e816359 --- /dev/null +++ b/benchmark/YGBenchmark.c @@ -0,0 +1,118 @@ +/** + * 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 "YGBenchmark.h" + +#include + +static YGSize _measure(YGNodeRef node, + float width, + YGMeasureMode widthMode, + float height, + YGMeasureMode heightMode) { + return (YGSize){ + .width = widthMode == YGMeasureModeUndefined ? 10 : width, + .height = heightMode == YGMeasureModeUndefined ? 10 : width, + }; +} + +YGBENCHMARKS({ + + YGBENCHMARK("Stack with flex", { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + for (uint32_t i = 0; i < 10; i++) { + const YGNodeRef child = YGNodeNew(); + YGNodeSetMeasureFunc(child, _measure); + YGNodeStyleSetFlex(child, 1); + YGNodeInsertChild(root, child, 0); + } + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + YGNodeFreeRecursive(root); + }); + + YGBENCHMARK("Align stretch in undefined axis", { + const YGNodeRef root = YGNodeNew(); + + for (uint32_t i = 0; i < 10; i++) { + const YGNodeRef child = YGNodeNew(); + YGNodeStyleSetHeight(child, 20); + YGNodeSetMeasureFunc(child, _measure); + YGNodeInsertChild(root, child, 0); + } + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + YGNodeFreeRecursive(root); + }); + + YGBENCHMARK("Nested flex", { + const YGNodeRef root = YGNodeNew(); + + for (uint32_t i = 0; i < 10; i++) { + const YGNodeRef child = YGNodeNew(); + YGNodeStyleSetFlex(child, 1); + YGNodeInsertChild(root, child, 0); + + for (uint32_t ii = 0; ii < 10; ii++) { + const YGNodeRef grandChild = YGNodeNew(); + YGNodeSetMeasureFunc(grandChild, _measure); + YGNodeStyleSetFlex(grandChild, 1); + YGNodeInsertChild(child, grandChild, 0); + } + } + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + YGNodeFreeRecursive(root); + }); + + YGBENCHMARK("Huge nested layout", { + const YGNodeRef root = YGNodeNew(); + + for (uint32_t i = 0; i < 10; i++) { + const YGNodeRef child = YGNodeNew(); + YGNodeStyleSetFlexGrow(child, 1); + YGNodeStyleSetWidth(child, 10); + YGNodeStyleSetHeight(child, 10); + YGNodeInsertChild(root, child, 0); + + for (uint32_t ii = 0; ii < 10; ii++) { + const YGNodeRef grandChild = YGNodeNew(); + YGNodeStyleSetFlexDirection(grandChild, YGFlexDirectionRow); + YGNodeStyleSetFlexGrow(grandChild, 1); + YGNodeStyleSetWidth(grandChild, 10); + YGNodeStyleSetHeight(grandChild, 10); + YGNodeInsertChild(child, grandChild, 0); + + for (uint32_t iii = 0; iii < 10; iii++) { + const YGNodeRef grandGrandChild = YGNodeNew(); + YGNodeStyleSetFlexGrow(grandGrandChild, 1); + YGNodeStyleSetWidth(grandGrandChild, 10); + YGNodeStyleSetHeight(grandGrandChild, 10); + YGNodeInsertChild(grandChild, grandGrandChild, 0); + + for (uint32_t iii = 0; iii < 10; iii++) { + const YGNodeRef grandGrandGrandChild = YGNodeNew(); + YGNodeStyleSetFlexDirection(grandGrandGrandChild, YGFlexDirectionRow); + YGNodeStyleSetFlexGrow(grandGrandGrandChild, 1); + YGNodeStyleSetWidth(grandGrandGrandChild, 10); + YGNodeStyleSetHeight(grandGrandGrandChild, 10); + YGNodeInsertChild(grandGrandChild, grandGrandGrandChild, 0); + } + } + } + } + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + YGNodeFreeRecursive(root); + }); + +}); diff --git a/benchmark/CSSBenchmark.h b/benchmark/YGBenchmark.h similarity index 95% rename from benchmark/CSSBenchmark.h rename to benchmark/YGBenchmark.h index f1314e98..4ebd2841 100644 --- a/benchmark/CSSBenchmark.h +++ b/benchmark/YGBenchmark.h @@ -17,7 +17,7 @@ #define NUM_REPETITIONS 1000 -#define CSS_BENCHMARKS(BLOCK) \ +#define YGBENCHMARKS(BLOCK) \ int main(int argc, char const *argv[]) { \ clock_t __start; \ clock_t __endTimes[NUM_REPETITIONS]; \ @@ -25,7 +25,7 @@ return 0; \ } -#define CSS_BENCHMARK(NAME, BLOCK) \ +#define YGBENCHMARK(NAME, BLOCK) \ __start = clock(); \ for (uint32_t __i = 0; __i < NUM_REPETITIONS; __i++) { \ { BLOCK } \ diff --git a/csharp/.gitignore b/csharp/.gitignore index 4e1cd4a5..533ef745 100644 --- a/csharp/.gitignore +++ b/csharp/.gitignore @@ -30,6 +30,11 @@ bld/ # MSTest test Results [Tt]est[Rr]esult*/ [Bb]uild[Ll]og.* +csharp/tests/Facebook.Yoga/NUnit-[0-9\.]+/ +csharp/tests/Facebook.Yoga/YogaTest.dll +csharp/tests/Facebook.Yoga/YogaTest.dll.mdb +csharp/tests/Facebook.Yoga/libyoga.dylib +csharp/tests/Facebook.Yoga/libyoga.dylib.dSYM/ # NUNIT *.VisualState.xml @@ -262,4 +267,4 @@ paket-files/ # Python Tools for Visual Studio (PTVS) __pycache__/ -*.pyc \ No newline at end of file +*.pyc diff --git a/csharp/.hgignore b/csharp/.hgignore index 4e1cd4a5..4dd1c600 100644 --- a/csharp/.hgignore +++ b/csharp/.hgignore @@ -34,6 +34,11 @@ bld/ # NUNIT *.VisualState.xml TestResult.xml +csharp/tests/Facebook.Yoga/NUnit-[0-9\.]+/ +csharp/tests/Facebook.Yoga/YogaTest.dll +csharp/tests/Facebook.Yoga/YogaTest.dll.mdb +csharp/tests/Facebook.Yoga/libyoga.dylib +csharp/tests/Facebook.Yoga/libyoga.dylib.dSYM/ # Build Results of an ATL Project [Dd]ebugPS/ @@ -262,4 +267,4 @@ paket-files/ # Python Tools for Visual Studio (PTVS) __pycache__/ -*.pyc \ No newline at end of file +*.pyc diff --git a/csharp/BUCK b/csharp/BUCK index 0e88d124..8223450a 100644 --- a/csharp/BUCK +++ b/csharp/BUCK @@ -6,15 +6,15 @@ # of patent rights can be found in the PATENTS file in the same directory. csharp_library( - name = 'csslibnet46', - dll_name = 'Facebook.CSSLayout.dll', + name = 'yogalibnet46', + dll_name = 'Facebook.Yoga.dll', framework_ver = 'net46', srcs = glob(['**/*.cs']), ) csharp_library( - name = 'csslibnet45', - dll_name = 'Facebook.CSSLayout.dll', + name = 'yogalibnet45', + dll_name = 'Facebook.Yoga.dll', framework_ver = 'net45', srcs = glob(['**/*.cs']), ) diff --git a/csharp/Facebook.CSSLayout/CSSAssert.cs b/csharp/Facebook.CSSLayout/CSSAssert.cs deleted file mode 100644 index 848c9119..00000000 --- a/csharp/Facebook.CSSLayout/CSSAssert.cs +++ /dev/null @@ -1,35 +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. - */ - -using System; -using System.Runtime.InteropServices; - -namespace Facebook.CSSLayout -{ - internal static class CSSAssert - { - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void FailFunc(string message); - - private static bool _assertInitialized; - private static FailFunc _failFunc; - - public static void Initialize() - { - if (!_assertInitialized) - { - _failFunc = (message) => { - throw new InvalidOperationException(message); - }; - Native.CSSAssertSetFailFunc(_failFunc); - _assertInitialized = true; - } - } - } -} diff --git a/csharp/Facebook.CSSLayout/CSSNode.cs b/csharp/Facebook.CSSLayout/CSSNode.cs deleted file mode 100644 index 1648617f..00000000 --- a/csharp/Facebook.CSSLayout/CSSNode.cs +++ /dev/null @@ -1,567 +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. - */ - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Text; - -namespace Facebook.CSSLayout -{ - public class CSSNode : IEnumerable - { - private IntPtr _cssNode; - private WeakReference _parent; - private List _children; - private MeasureFunction _measureFunction; - private CSSMeasureFunc _cssMeasureFunc; - private object _data; - - public CSSNode() - { - CSSAssert.Initialize(); - CSSLogger.Initialize(); - - _cssNode = Native.CSSNodeNew(); - if (_cssNode == IntPtr.Zero) - { - throw new InvalidOperationException("Failed to allocate native memory"); - } - } - - ~CSSNode() - { - Native.CSSNodeFree(_cssNode); - } - - public void Reset() - { - _measureFunction = null; - _data = null; - - Native.CSSNodeReset(_cssNode); - } - - public bool IsDirty - { - get - { - return Native.CSSNodeIsDirty(_cssNode); - } - } - - public virtual void MarkDirty() - { - Native.CSSNodeMarkDirty(_cssNode); - } - - public bool IsTextNode - { - get - { - return Native.CSSNodeGetIsTextnode(_cssNode); - } - - set - { - Native.CSSNodeSetIsTextnode(_cssNode, value); - } - } - - public bool HasNewLayout - { - get - { - return Native.CSSNodeGetHasNewLayout(_cssNode); - } - } - - public void MarkHasNewLayout() - { - Native.CSSNodeSetHasNewLayout(_cssNode, true); - } - - public CSSNode Parent - { - get - { - return _parent != null ? _parent.Target as CSSNode : null; - } - } - - public bool IsMeasureDefined - { - get - { - return _measureFunction != null; - } - } - - public CSSDirection StyleDirection - { - get - { - return Native.CSSNodeStyleGetDirection(_cssNode); - } - - set - { - Native.CSSNodeStyleSetDirection(_cssNode, value); - } - } - - public CSSFlexDirection FlexDirection - { - get - { - return Native.CSSNodeStyleGetFlexDirection(_cssNode); - } - - set - { - Native.CSSNodeStyleSetFlexDirection(_cssNode, value); - } - } - - public CSSJustify JustifyContent - { - get - { - return Native.CSSNodeStyleGetJustifyContent(_cssNode); - } - - set - { - Native.CSSNodeStyleSetJustifyContent(_cssNode, value); - } - } - - public CSSAlign AlignItems - { - get - { - return Native.CSSNodeStyleGetAlignItems(_cssNode); - } - - set - { - Native.CSSNodeStyleSetAlignItems(_cssNode, value); - } - } - - public CSSAlign AlignSelf - { - get - { - return Native.CSSNodeStyleGetAlignSelf(_cssNode); - } - - set - { - Native.CSSNodeStyleSetAlignSelf(_cssNode, value); - } - } - - public CSSAlign AlignContent - { - get - { - return Native.CSSNodeStyleGetAlignContent(_cssNode); - } - - set - { - Native.CSSNodeStyleSetAlignContent(_cssNode, value); - } - } - - public CSSPositionType PositionType - { - get - { - return Native.CSSNodeStyleGetPositionType(_cssNode); - } - - set - { - Native.CSSNodeStyleSetPositionType(_cssNode, value); - } - } - - public CSSWrap Wrap - { - get - { - return Native.CSSNodeStyleGetFlexWrap(_cssNode); - } - - set - { - Native.CSSNodeStyleSetFlexWrap(_cssNode, value); - } - } - - public float Flex - { - set - { - Native.CSSNodeStyleSetFlex(_cssNode, value); - } - } - - public float FlexGrow - { - get - { - return Native.CSSNodeStyleGetFlexGrow(_cssNode); - } - - set - { - Native.CSSNodeStyleSetFlexGrow(_cssNode, value); - } - } - - public float FlexShrink - { - get - { - return Native.CSSNodeStyleGetFlexShrink(_cssNode); - } - - set - { - Native.CSSNodeStyleSetFlexShrink(_cssNode, value); - } - } - - public float FlexBasis - { - get - { - return Native.CSSNodeStyleGetFlexBasis(_cssNode); - } - - set - { - Native.CSSNodeStyleSetFlexBasis(_cssNode, value); - } - } - - public float GetMargin(CSSEdge edge) - { - return Native.CSSNodeStyleGetMargin(_cssNode, edge); - } - - public void SetMargin(CSSEdge edge, float value) - { - Native.CSSNodeStyleSetMargin(_cssNode, edge, value); - } - - public float GetPadding(CSSEdge edge) - { - return Native.CSSNodeStyleGetPadding(_cssNode, edge); - } - - public void SetPadding(CSSEdge edge, float padding) - { - Native.CSSNodeStyleSetPadding(_cssNode, edge, padding); - } - - public float GetBorder(CSSEdge edge) - { - return Native.CSSNodeStyleGetBorder(_cssNode, edge); - } - - public void SetBorder(CSSEdge edge, float border) - { - Native.CSSNodeStyleSetBorder(_cssNode, edge, border); - } - - public float GetPosition(CSSEdge edge) - { - return Native.CSSNodeStyleGetPosition(_cssNode, edge); - } - - public void SetPosition(CSSEdge edge, float position) - { - Native.CSSNodeStyleSetPosition(_cssNode, edge, position); - } - - public float StyleWidth - { - get - { - return Native.CSSNodeStyleGetWidth(_cssNode); - } - - set - { - Native.CSSNodeStyleSetWidth(_cssNode, value); - } - } - - public float StyleHeight - { - get - { - return Native.CSSNodeStyleGetHeight(_cssNode); - } - - set - { - Native.CSSNodeStyleSetHeight(_cssNode, value); - } - } - - public float StyleMaxWidth - { - get - { - return Native.CSSNodeStyleGetMaxWidth(_cssNode); - } - - set - { - Native.CSSNodeStyleSetMaxWidth(_cssNode, value); - } - } - - public float StyleMaxHeight - { - get - { - return Native.CSSNodeStyleGetMaxHeight(_cssNode); - } - - set - { - Native.CSSNodeStyleSetMaxHeight(_cssNode, value); - } - } - - public float StyleMinWidth - { - get - { - return Native.CSSNodeStyleGetMinWidth(_cssNode); - } - - set - { - Native.CSSNodeStyleSetMinWidth(_cssNode, value); - } - } - - public float StyleMinHeight - { - get - { - return Native.CSSNodeStyleGetMinHeight(_cssNode); - } - - set - { - Native.CSSNodeStyleSetMinHeight(_cssNode, value); - } - } - - public float LayoutX - { - get - { - return Native.CSSNodeLayoutGetLeft(_cssNode); - } - } - - public float LayoutY - { - get - { - return Native.CSSNodeLayoutGetTop(_cssNode); - } - } - - public float LayoutWidth - { - get - { - return Native.CSSNodeLayoutGetWidth(_cssNode); - } - } - - public float LayoutHeight - { - get - { - return Native.CSSNodeLayoutGetHeight(_cssNode); - } - } - - public CSSDirection LayoutDirection - { - get - { - return Native.CSSNodeLayoutGetDirection(_cssNode); - } - } - - public CSSOverflow Overflow - { - get - { - return Native.CSSNodeStyleGetOverflow(_cssNode); - } - - set - { - Native.CSSNodeStyleSetOverflow(_cssNode, value); - } - } - - public object Data - { - get - { - return _data; - } - - set - { - _data = value; - } - } - - public CSSNode this[int index] - { - get - { - return _children[index]; - } - } - - public int Count - { - get - { - return _children != null ? _children.Count : 0; - } - } - - public void MarkLayoutSeen() - { - Native.CSSNodeSetHasNewLayout(_cssNode, false); - } - - public bool ValuesEqual(float f1, float f2) - { - if (float.IsNaN(f1) || float.IsNaN(f2)) - { - return float.IsNaN(f1) && float.IsNaN(f2); - } - - return Math.Abs(f2 - f1) < float.Epsilon; - } - - public void Insert(int index, CSSNode node) - { - if (_children == null) - { - _children = new List(4); - } - _children.Insert(index, node); - node._parent = new WeakReference(this); - Native.CSSNodeInsertChild(_cssNode, node._cssNode, (uint)index); - } - - public void RemoveAt(int index) - { - var child = _children[index]; - child._parent = null; - _children.RemoveAt(index); - Native.CSSNodeRemoveChild(_cssNode, child._cssNode); - } - - public void Clear() - { - if (_children != null) - { - while (_children.Count > 0) - { - RemoveAt(_children.Count-1); - } - } - } - - public int IndexOf(CSSNode node) - { - return _children != null ? _children.IndexOf(node) : -1; - } - - public void SetMeasureFunction(MeasureFunction measureFunction) - { - _measureFunction = measureFunction; - _cssMeasureFunc = measureFunction != null ? MeasureInternal : (CSSMeasureFunc)null; - Native.CSSNodeSetMeasureFunc(_cssNode, _cssMeasureFunc); - } - - public void CalculateLayout() - { - Native.CSSNodeCalculateLayout( - _cssNode, - CSSConstants.Undefined, - CSSConstants.Undefined, - Native.CSSNodeStyleGetDirection(_cssNode)); - } - - private CSSSize MeasureInternal( - IntPtr node, - float width, - CSSMeasureMode widthMode, - float height, - CSSMeasureMode heightMode) - { - if (_measureFunction == null) - { - throw new InvalidOperationException("Measure function is not defined."); - } - - long output = _measureFunction(this, width, widthMode, height, heightMode); - return new CSSSize { width = MeasureOutput.GetWidth(output), height = MeasureOutput.GetHeight(output) }; - } - - public string Print(CSSPrintOptions options = - CSSPrintOptions.Layout|CSSPrintOptions.Style|CSSPrintOptions.Children) - { - StringBuilder sb = new StringBuilder(); - CSSLogger.Logger = (message) => {sb.Append(message);}; - Native.CSSNodePrint(_cssNode, options); - CSSLogger.Logger = null; - return sb.ToString(); - } - - public IEnumerator GetEnumerator() - { - return _children != null ? ((IEnumerable)_children).GetEnumerator() : - System.Linq.Enumerable.Empty().GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return _children != null ? ((IEnumerable)_children).GetEnumerator() : - System.Linq.Enumerable.Empty().GetEnumerator(); - } - - public static int GetInstanceCount() - { - return Native.CSSNodeGetInstanceCount(); - } - } -} diff --git a/csharp/Facebook.CSSLayout/Native.cs b/csharp/Facebook.CSSLayout/Native.cs deleted file mode 100644 index 163f0049..00000000 --- a/csharp/Facebook.CSSLayout/Native.cs +++ /dev/null @@ -1,279 +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. - */ - -using System; -using System.Runtime.InteropServices; - -namespace Facebook.CSSLayout -{ - internal static class Native - { -#if UNITY_IOS && !UNITY_EDITOR - private const string DllName = "__Internal"; -#else - private const string DllName = "CSSLayout"; -#endif - - [DllImport(DllName)] - public static extern void CSSInteropSetLogger( - [MarshalAs(UnmanagedType.FunctionPtr)] CSSLogger.Func func); - - [DllImport(DllName)] - public static extern void CSSAssertSetFailFunc( - [MarshalAs(UnmanagedType.FunctionPtr)] CSSAssert.FailFunc func); - - [DllImport(DllName)] - public static extern IntPtr CSSNodeNew(); - - [DllImport(DllName)] - public static extern void CSSNodeInit(IntPtr cssNode); - - [DllImport(DllName)] - public static extern void CSSNodeFree(IntPtr cssNode); - - [DllImport(DllName)] - public static extern void CSSNodeReset(IntPtr cssNode); - - [DllImport(DllName)] - public static extern int CSSNodeGetInstanceCount(); - - [DllImport(DllName)] - public static extern void CSSNodeInsertChild(IntPtr node, IntPtr child, uint index); - - [DllImport(DllName)] - public static extern void CSSNodeRemoveChild(IntPtr node, IntPtr child); - - [DllImport(DllName)] - public static extern IntPtr CSSNodeGetChild(IntPtr node, uint index); - - [DllImport(DllName)] - public static extern uint CSSNodeChildCount(IntPtr node); - - [DllImport(DllName)] - public static extern void CSSNodeCalculateLayout(IntPtr node, - float availableWidth, - float availableHeight, - CSSDirection parentDirection); - - [DllImport(DllName)] - public static extern void CSSNodeMarkDirty(IntPtr node); - - [DllImport(DllName)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool CSSNodeIsDirty(IntPtr node); - - [DllImport(DllName)] - public static extern void CSSNodePrint(IntPtr node, CSSPrintOptions options); - - [DllImport(DllName)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool CSSValueIsUndefined(float value); - - #region CSS_NODE_PROPERTY - - [DllImport(DllName)] - public static extern void CSSNodeSetContext(IntPtr node, IntPtr context); - - [DllImport(DllName)] - public static extern IntPtr CSSNodeGetContext(IntPtr node); - - [DllImport(DllName)] - public static extern void CSSNodeSetMeasureFunc( - IntPtr node, - [MarshalAs(UnmanagedType.FunctionPtr)] CSSMeasureFunc measureFunc); - - [DllImport(DllName)] - [return: MarshalAs(UnmanagedType.FunctionPtr)] - public static extern CSSMeasureFunc CSSNodeGetMeasureFunc(IntPtr node); - - [DllImport(DllName)] - public static extern void CSSNodeSetIsTextnode(IntPtr node, [MarshalAs(UnmanagedType.I1)] bool isTextNode); - - [DllImport(DllName)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool CSSNodeGetIsTextnode(IntPtr node); - - [DllImport(DllName)] - public static extern void CSSNodeSetHasNewLayout(IntPtr node, [MarshalAs(UnmanagedType.I1)] bool hasNewLayout); - - [DllImport(DllName)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool CSSNodeGetHasNewLayout(IntPtr node); - - #endregion - - #region CSS_NODE_STYLE_PROPERTY - - [DllImport(DllName)] - public static extern void CSSNodeStyleSetDirection(IntPtr node, CSSDirection direction); - - [DllImport(DllName)] - public static extern CSSDirection CSSNodeStyleGetDirection(IntPtr node); - - [DllImport(DllName)] - public static extern void CSSNodeStyleSetFlexDirection(IntPtr node, CSSFlexDirection flexDirection); - - [DllImport(DllName)] - public static extern CSSFlexDirection CSSNodeStyleGetFlexDirection(IntPtr node); - - [DllImport(DllName)] - public static extern void CSSNodeStyleSetJustifyContent(IntPtr node, CSSJustify justifyContent); - - [DllImport(DllName)] - public static extern CSSJustify CSSNodeStyleGetJustifyContent(IntPtr node); - - [DllImport(DllName)] - public static extern void CSSNodeStyleSetAlignContent(IntPtr node, CSSAlign alignContent); - - [DllImport(DllName)] - public static extern CSSAlign CSSNodeStyleGetAlignContent(IntPtr node); - - [DllImport(DllName)] - public static extern void CSSNodeStyleSetAlignItems(IntPtr node, CSSAlign alignItems); - - [DllImport(DllName)] - public static extern CSSAlign CSSNodeStyleGetAlignItems(IntPtr node); - - [DllImport(DllName)] - public static extern void CSSNodeStyleSetAlignSelf(IntPtr node, CSSAlign alignSelf); - - [DllImport(DllName)] - public static extern CSSAlign CSSNodeStyleGetAlignSelf(IntPtr node); - - [DllImport(DllName)] - public static extern void CSSNodeStyleSetPositionType(IntPtr node, CSSPositionType positionType); - - [DllImport(DllName)] - public static extern CSSPositionType CSSNodeStyleGetPositionType(IntPtr node); - - [DllImport(DllName)] - public static extern void CSSNodeStyleSetFlexWrap(IntPtr node, CSSWrap flexWrap); - - [DllImport(DllName)] - public static extern CSSWrap CSSNodeStyleGetFlexWrap(IntPtr node); - - [DllImport(DllName)] - public static extern void CSSNodeStyleSetOverflow(IntPtr node, CSSOverflow flexWrap); - - [DllImport(DllName)] - public static extern CSSOverflow CSSNodeStyleGetOverflow(IntPtr node); - - [DllImport(DllName)] - public static extern void CSSNodeStyleSetFlex(IntPtr node, float flex); - - [DllImport(DllName)] - public static extern void CSSNodeStyleSetFlexGrow(IntPtr node, float flexGrow); - - [DllImport(DllName)] - public static extern float CSSNodeStyleGetFlexGrow(IntPtr node); - - [DllImport(DllName)] - public static extern void CSSNodeStyleSetFlexShrink(IntPtr node, float flexShrink); - - [DllImport(DllName)] - public static extern float CSSNodeStyleGetFlexShrink(IntPtr node); - - [DllImport(DllName)] - public static extern void CSSNodeStyleSetFlexBasis(IntPtr node, float flexBasis); - - [DllImport(DllName)] - public static extern float CSSNodeStyleGetFlexBasis(IntPtr node); - - [DllImport(DllName)] - public static extern void CSSNodeStyleSetWidth(IntPtr node, float width); - - [DllImport(DllName)] - public static extern float CSSNodeStyleGetWidth(IntPtr node); - - [DllImport(DllName)] - public static extern void CSSNodeStyleSetHeight(IntPtr node, float height); - - [DllImport(DllName)] - public static extern float CSSNodeStyleGetHeight(IntPtr node); - - [DllImport(DllName)] - public static extern void CSSNodeStyleSetMinWidth(IntPtr node, float minWidth); - - [DllImport(DllName)] - public static extern float CSSNodeStyleGetMinWidth(IntPtr node); - - [DllImport(DllName)] - public static extern void CSSNodeStyleSetMinHeight(IntPtr node, float minHeight); - - [DllImport(DllName)] - public static extern float CSSNodeStyleGetMinHeight(IntPtr node); - - [DllImport(DllName)] - public static extern void CSSNodeStyleSetMaxWidth(IntPtr node, float maxWidth); - - [DllImport(DllName)] - public static extern float CSSNodeStyleGetMaxWidth(IntPtr node); - - [DllImport(DllName)] - public static extern void CSSNodeStyleSetMaxHeight(IntPtr node, float maxHeight); - - [DllImport(DllName)] - public static extern float CSSNodeStyleGetMaxHeight(IntPtr node); - - #endregion - - #region CSS_NODE_STYLE_EDGE_PROPERTY - - [DllImport(DllName)] - public static extern void CSSNodeStyleSetPosition(IntPtr node, CSSEdge edge, float position); - - [DllImport(DllName)] - public static extern float CSSNodeStyleGetPosition(IntPtr node, CSSEdge edge); - - [DllImport(DllName)] - public static extern void CSSNodeStyleSetMargin(IntPtr node, CSSEdge edge, float margin); - - [DllImport(DllName)] - public static extern float CSSNodeStyleGetMargin(IntPtr node, CSSEdge edge); - - [DllImport(DllName)] - public static extern void CSSNodeStyleSetPadding(IntPtr node, CSSEdge edge, float padding); - - [DllImport(DllName)] - public static extern float CSSNodeStyleGetPadding(IntPtr node, CSSEdge edge); - - [DllImport(DllName)] - public static extern void CSSNodeStyleSetBorder(IntPtr node, CSSEdge edge, float border); - - [DllImport(DllName)] - public static extern float CSSNodeStyleGetBorder(IntPtr node, CSSEdge edge); - - #endregion - - #region CSS_NODE_LAYOUT_PROPERTY - - [DllImport(DllName)] - public static extern float CSSNodeLayoutGetLeft(IntPtr node); - - [DllImport(DllName)] - public static extern float CSSNodeLayoutGetTop(IntPtr node); - - [DllImport(DllName)] - public static extern float CSSNodeLayoutGetRight(IntPtr node); - - [DllImport(DllName)] - public static extern float CSSNodeLayoutGetBottom(IntPtr node); - - [DllImport(DllName)] - public static extern float CSSNodeLayoutGetWidth(IntPtr node); - - [DllImport(DllName)] - public static extern float CSSNodeLayoutGetHeight(IntPtr node); - - [DllImport(DllName)] - public static extern CSSDirection CSSNodeLayoutGetDirection(IntPtr node); - - #endregion - } -} diff --git a/csharp/Facebook.CSSLayout.sln b/csharp/Facebook.Yoga.sln similarity index 88% rename from csharp/Facebook.CSSLayout.sln rename to csharp/Facebook.Yoga.sln index 5c67bda9..3e8b4078 100644 --- a/csharp/Facebook.CSSLayout.sln +++ b/csharp/Facebook.Yoga.sln @@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CSSLayout", "CSSLayout\CSSLayout.vcxproj", "{0446C86B-F47B-4C46-B673-C7AE0CFF35D5}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Yoga", "Yoga\Yoga.vcxproj", "{0446C86B-F47B-4C46-B673-C7AE0CFF35D5}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Facebook.CSSLayout", "Facebook.CSSLayout\Facebook.CSSLayout.xproj", "{75BB7605-E54B-4EDE-8F5A-FF1F24464236}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Facebook.Yoga", "Facebook.Yoga\Facebook.Yoga.xproj", "{75BB7605-E54B-4EDE-8F5A-FF1F24464236}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/csharp/Facebook.CSSLayout/Facebook.CSSLayout.xproj b/csharp/Facebook.Yoga/Facebook.Yoga.xproj similarity index 95% rename from csharp/Facebook.CSSLayout/Facebook.CSSLayout.xproj rename to csharp/Facebook.Yoga/Facebook.Yoga.xproj index 2f3cd6f2..0341d153 100644 --- a/csharp/Facebook.CSSLayout/Facebook.CSSLayout.xproj +++ b/csharp/Facebook.Yoga/Facebook.Yoga.xproj @@ -8,7 +8,7 @@ 75bb7605-e54b-4ede-8f5a-ff1f24464236 - Facebook.CSSLayout + Facebook.Yoga .\obj .\bin\ v4.5.2 diff --git a/csharp/Facebook.CSSLayout/MeasureFunction.cs b/csharp/Facebook.Yoga/MeasureFunction.cs similarity index 60% rename from csharp/Facebook.CSSLayout/MeasureFunction.cs rename to csharp/Facebook.Yoga/MeasureFunction.cs index b727dfc5..f25ec6da 100644 --- a/csharp/Facebook.CSSLayout/MeasureFunction.cs +++ b/csharp/Facebook.Yoga/MeasureFunction.cs @@ -7,12 +7,12 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -namespace Facebook.CSSLayout +namespace Facebook.Yoga { - public delegate long MeasureFunction( - CSSNode node, - float width, - CSSMeasureMode widthMode, - float height, - CSSMeasureMode heightMode); + public delegate long MeasureFunction( + YogaNode node, + float width, + YogaMeasureMode widthMode, + float height, + YogaMeasureMode heightMode); } diff --git a/csharp/Facebook.CSSLayout/MeasureOutput.cs b/csharp/Facebook.Yoga/MeasureOutput.cs similarity index 62% rename from csharp/Facebook.CSSLayout/MeasureOutput.cs rename to csharp/Facebook.Yoga/MeasureOutput.cs index 5fabf348..380b5b2c 100644 --- a/csharp/Facebook.CSSLayout/MeasureOutput.cs +++ b/csharp/Facebook.Yoga/MeasureOutput.cs @@ -7,23 +7,28 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -namespace Facebook.CSSLayout +namespace Facebook.Yoga { public class MeasureOutput { + public static long Make(double width, double height) + { + return Make((int) width, (int) height); + } + public static long Make(int width, int height) { - return (long)(((ulong) width) << 32 | ((ulong) height)); + return (long)(((ulong) width) << 32 | ((uint) height)); } public static int GetWidth(long measureOutput) { - return (int) (0xFFFFFFFF & (measureOutput >> 32)); + return (int) (0xFFFFFFFF & (measureOutput >> 32)); } public static int GetHeight(long measureOutput) { - return (int) (0xFFFFFFFF & measureOutput); + return (int) (0xFFFFFFFF & measureOutput); } } } diff --git a/csharp/Facebook.Yoga/Native.cs b/csharp/Facebook.Yoga/Native.cs new file mode 100644 index 00000000..7786b8cf --- /dev/null +++ b/csharp/Facebook.Yoga/Native.cs @@ -0,0 +1,286 @@ +/** + * 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. + */ + +using System; +using System.Runtime.InteropServices; + +namespace Facebook.Yoga +{ + internal static class Native + { +#if UNITY_IOS && !UNITY_EDITOR + private const string DllName = "__Internal"; +#else + private const string DllName = "yoga"; +#endif + + [DllImport(DllName)] + public static extern void YGInteropSetLogger( + [MarshalAs(UnmanagedType.FunctionPtr)] YogaLogger.Func func); + + [DllImport(DllName)] + public static extern IntPtr YGNodeNew(); + + [DllImport(DllName)] + public static extern void YGNodeInit(IntPtr node); + + [DllImport(DllName)] + public static extern void YGNodeFree(IntPtr node); + + [DllImport(DllName)] + public static extern void YGNodeReset(IntPtr node); + + [DllImport(DllName)] + public static extern int YGNodeGetInstanceCount(); + + [DllImport(DllName)] + public static extern void YGSetExperimentalFeatureEnabled( + YogaExperimentalFeature feature, + bool enabled); + + [DllImport(DllName)] + public static extern bool YGIsExperimentalFeatureEnabled( + YogaExperimentalFeature feature); + + [DllImport(DllName)] + public static extern void YGNodeInsertChild(IntPtr node, IntPtr child, uint index); + + [DllImport(DllName)] + public static extern void YGNodeRemoveChild(IntPtr node, IntPtr child); + + [DllImport(DllName)] + public static extern IntPtr YGNodeGetChild(IntPtr node, uint index); + + [DllImport(DllName)] + public static extern uint YGNodeChildCount(IntPtr node); + + [DllImport(DllName)] + public static extern void YGNodeCalculateLayout(IntPtr node, + float availableWidth, + float availableHeight, + YogaDirection parentDirection); + + [DllImport(DllName)] + public static extern void YGNodeMarkDirty(IntPtr node); + + [DllImport(DllName)] + [return: MarshalAs(UnmanagedType.I1)] + public static extern bool YGNodeIsDirty(IntPtr node); + + [DllImport(DllName)] + public static extern void YGNodePrint(IntPtr node, YogaPrintOptions options); + + [DllImport(DllName)] + [return: MarshalAs(UnmanagedType.I1)] + public static extern bool YGValueIsUndefined(float value); + + [DllImport(DllName)] + public static extern void YGNodeCopyStyle(IntPtr dstNode, IntPtr srcNode); + + #region YG_NODE_PROPERTY + + [DllImport(DllName)] + public static extern void YGNodeSetContext(IntPtr node, IntPtr context); + + [DllImport(DllName)] + public static extern IntPtr YGNodeGetContext(IntPtr node); + + [DllImport(DllName)] + public static extern void YGNodeSetMeasureFunc( + IntPtr node, + [MarshalAs(UnmanagedType.FunctionPtr)] YogaMeasureFunc measureFunc); + + [DllImport(DllName)] + [return: MarshalAs(UnmanagedType.FunctionPtr)] + public static extern YogaMeasureFunc YGNodeGetMeasureFunc(IntPtr node); + + [DllImport(DllName)] + public static extern void YGNodeSetHasNewLayout(IntPtr node, [MarshalAs(UnmanagedType.I1)] bool hasNewLayout); + + [DllImport(DllName)] + [return: MarshalAs(UnmanagedType.I1)] + public static extern bool YGNodeGetHasNewLayout(IntPtr node); + + #endregion + + #region YG_NODE_STYLE_PROPERTY + + [DllImport(DllName)] + public static extern void YGNodeStyleSetDirection(IntPtr node, YogaDirection direction); + + [DllImport(DllName)] + public static extern YogaDirection YGNodeStyleGetDirection(IntPtr node); + + [DllImport(DllName)] + public static extern void YGNodeStyleSetFlexDirection(IntPtr node, YogaFlexDirection flexDirection); + + [DllImport(DllName)] + public static extern YogaFlexDirection YGNodeStyleGetFlexDirection(IntPtr node); + + [DllImport(DllName)] + public static extern void YGNodeStyleSetJustifyContent(IntPtr node, YogaJustify justifyContent); + + [DllImport(DllName)] + public static extern YogaJustify YGNodeStyleGetJustifyContent(IntPtr node); + + [DllImport(DllName)] + public static extern void YGNodeStyleSetAlignContent(IntPtr node, YogaAlign alignContent); + + [DllImport(DllName)] + public static extern YogaAlign YGNodeStyleGetAlignContent(IntPtr node); + + [DllImport(DllName)] + public static extern void YGNodeStyleSetAlignItems(IntPtr node, YogaAlign alignItems); + + [DllImport(DllName)] + public static extern YogaAlign YGNodeStyleGetAlignItems(IntPtr node); + + [DllImport(DllName)] + public static extern void YGNodeStyleSetAlignSelf(IntPtr node, YogaAlign alignSelf); + + [DllImport(DllName)] + public static extern YogaAlign YGNodeStyleGetAlignSelf(IntPtr node); + + [DllImport(DllName)] + public static extern void YGNodeStyleSetPositionType(IntPtr node, YogaPositionType positionType); + + [DllImport(DllName)] + public static extern YogaPositionType YGNodeStyleGetPositionType(IntPtr node); + + [DllImport(DllName)] + public static extern void YGNodeStyleSetFlexWrap(IntPtr node, YogaWrap flexWrap); + + [DllImport(DllName)] + public static extern YogaWrap YGNodeStyleGetFlexWrap(IntPtr node); + + [DllImport(DllName)] + public static extern void YGNodeStyleSetOverflow(IntPtr node, YogaOverflow flexWrap); + + [DllImport(DllName)] + public static extern YogaOverflow YGNodeStyleGetOverflow(IntPtr node); + + [DllImport(DllName)] + public static extern void YGNodeStyleSetFlex(IntPtr node, float flex); + + [DllImport(DllName)] + public static extern void YGNodeStyleSetFlexGrow(IntPtr node, float flexGrow); + + [DllImport(DllName)] + public static extern float YGNodeStyleGetFlexGrow(IntPtr node); + + [DllImport(DllName)] + public static extern void YGNodeStyleSetFlexShrink(IntPtr node, float flexShrink); + + [DllImport(DllName)] + public static extern float YGNodeStyleGetFlexShrink(IntPtr node); + + [DllImport(DllName)] + public static extern void YGNodeStyleSetFlexBasis(IntPtr node, float flexBasis); + + [DllImport(DllName)] + public static extern float YGNodeStyleGetFlexBasis(IntPtr node); + + [DllImport(DllName)] + public static extern void YGNodeStyleSetWidth(IntPtr node, float width); + + [DllImport(DllName)] + public static extern float YGNodeStyleGetWidth(IntPtr node); + + [DllImport(DllName)] + public static extern void YGNodeStyleSetHeight(IntPtr node, float height); + + [DllImport(DllName)] + public static extern float YGNodeStyleGetHeight(IntPtr node); + + [DllImport(DllName)] + public static extern void YGNodeStyleSetMinWidth(IntPtr node, float minWidth); + + [DllImport(DllName)] + public static extern float YGNodeStyleGetMinWidth(IntPtr node); + + [DllImport(DllName)] + public static extern void YGNodeStyleSetMinHeight(IntPtr node, float minHeight); + + [DllImport(DllName)] + public static extern float YGNodeStyleGetMinHeight(IntPtr node); + + [DllImport(DllName)] + public static extern void YGNodeStyleSetMaxWidth(IntPtr node, float maxWidth); + + [DllImport(DllName)] + public static extern float YGNodeStyleGetMaxWidth(IntPtr node); + + [DllImport(DllName)] + public static extern void YGNodeStyleSetMaxHeight(IntPtr node, float maxHeight); + + [DllImport(DllName)] + public static extern float YGNodeStyleGetMaxHeight(IntPtr node); + + [DllImport(DllName)] + public static extern void YGNodeStyleSetAspectRatio(IntPtr node, float aspectRatio); + + [DllImport(DllName)] + public static extern float YGNodeStyleGetAspectRatio(IntPtr node); + + #endregion + + #region YG_NODE_STYLE_EDGE_PROPERTY + + [DllImport(DllName)] + public static extern void YGNodeStyleSetPosition(IntPtr node, YogaEdge edge, float position); + + [DllImport(DllName)] + public static extern float YGNodeStyleGetPosition(IntPtr node, YogaEdge edge); + + [DllImport(DllName)] + public static extern void YGNodeStyleSetMargin(IntPtr node, YogaEdge edge, float margin); + + [DllImport(DllName)] + public static extern float YGNodeStyleGetMargin(IntPtr node, YogaEdge edge); + + [DllImport(DllName)] + public static extern void YGNodeStyleSetPadding(IntPtr node, YogaEdge edge, float padding); + + [DllImport(DllName)] + public static extern float YGNodeStyleGetPadding(IntPtr node, YogaEdge edge); + + [DllImport(DllName)] + public static extern void YGNodeStyleSetBorder(IntPtr node, YogaEdge edge, float border); + + [DllImport(DllName)] + public static extern float YGNodeStyleGetBorder(IntPtr node, YogaEdge edge); + + #endregion + + #region YG_NODE_LAYOUT_PROPERTY + + [DllImport(DllName)] + public static extern float YGNodeLayoutGetLeft(IntPtr node); + + [DllImport(DllName)] + public static extern float YGNodeLayoutGetTop(IntPtr node); + + [DllImport(DllName)] + public static extern float YGNodeLayoutGetRight(IntPtr node); + + [DllImport(DllName)] + public static extern float YGNodeLayoutGetBottom(IntPtr node); + + [DllImport(DllName)] + public static extern float YGNodeLayoutGetWidth(IntPtr node); + + [DllImport(DllName)] + public static extern float YGNodeLayoutGetHeight(IntPtr node); + + [DllImport(DllName)] + public static extern YogaDirection YGNodeLayoutGetDirection(IntPtr node); + + #endregion + } +} diff --git a/csharp/Facebook.CSSLayout/Properties/AssemblyInfo.cs b/csharp/Facebook.Yoga/Properties/AssemblyInfo.cs similarity index 96% rename from csharp/Facebook.CSSLayout/Properties/AssemblyInfo.cs rename to csharp/Facebook.Yoga/Properties/AssemblyInfo.cs index 95d38201..bc0b9929 100644 --- a/csharp/Facebook.CSSLayout/Properties/AssemblyInfo.cs +++ b/csharp/Facebook.Yoga/Properties/AssemblyInfo.cs @@ -16,7 +16,7 @@ using System.Runtime.InteropServices; // associated with an assembly. [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Facebook, Inc.")] -[assembly: AssemblyProduct("Facebook.CSSLayout")] +[assembly: AssemblyProduct("Facebook.Yoga")] [assembly: AssemblyTrademark("Copyright (c) 2014-present, Facebook, Inc.")] // Setting ComVisible to false makes the types in this assembly not visible diff --git a/csharp/Facebook.Yoga/Spacing.cs b/csharp/Facebook.Yoga/Spacing.cs new file mode 100644 index 00000000..c1c53c96 --- /dev/null +++ b/csharp/Facebook.Yoga/Spacing.cs @@ -0,0 +1,31 @@ +/** + * 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. + */ + +namespace Facebook.Yoga +{ + public class Spacing + { + public float? Top; + public float? Bottom; + public float? Left; + public float? Right; + + public Spacing( + float? top = null, + float? bottom = null, + float? left = null, + float? right = null) + { + Top = top; + Bottom = bottom; + Left = left; + Right = right; + } + } +} diff --git a/csharp/Facebook.CSSLayout/CSSAlign.cs b/csharp/Facebook.Yoga/YogaAlign.cs similarity index 83% rename from csharp/Facebook.CSSLayout/CSSAlign.cs rename to csharp/Facebook.Yoga/YogaAlign.cs index 685fea75..80835d73 100644 --- a/csharp/Facebook.CSSLayout/CSSAlign.cs +++ b/csharp/Facebook.Yoga/YogaAlign.cs @@ -1,4 +1,4 @@ -/** +/** * Copyright (c) 2014-present, Facebook, Inc. * All rights reserved. * @@ -7,14 +7,14 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -namespace Facebook.CSSLayout +namespace Facebook.Yoga { - public enum CSSAlign + public enum YogaAlign { Auto, FlexStart, Center, FlexEnd, - Stretch + Stretch, } } diff --git a/csharp/Facebook.CSSLayout/CSSConstants.cs b/csharp/Facebook.Yoga/YogaConstants.cs similarity index 88% rename from csharp/Facebook.CSSLayout/CSSConstants.cs rename to csharp/Facebook.Yoga/YogaConstants.cs index a57d62f2..3e12aa14 100644 --- a/csharp/Facebook.CSSLayout/CSSConstants.cs +++ b/csharp/Facebook.Yoga/YogaConstants.cs @@ -7,9 +7,9 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -namespace Facebook.CSSLayout +namespace Facebook.Yoga { - public static class CSSConstants + public static class YogaConstants { public const float Undefined = float.NaN; diff --git a/csharp/Facebook.CSSLayout/CSSDimension.cs b/csharp/Facebook.Yoga/YogaDimension.cs similarity index 80% rename from csharp/Facebook.CSSLayout/CSSDimension.cs rename to csharp/Facebook.Yoga/YogaDimension.cs index a8fd2b26..2b011c9d 100644 --- a/csharp/Facebook.CSSLayout/CSSDimension.cs +++ b/csharp/Facebook.Yoga/YogaDimension.cs @@ -1,4 +1,4 @@ -/** +/** * Copyright (c) 2014-present, Facebook, Inc. * All rights reserved. * @@ -7,11 +7,11 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -namespace Facebook.CSSLayout +namespace Facebook.Yoga { - public enum CSSDimension + public enum YogaDimension { Width, - Height + Height, } } diff --git a/csharp/Facebook.CSSLayout/CSSDIrection.cs b/csharp/Facebook.Yoga/YogaDirection.cs similarity index 76% rename from csharp/Facebook.CSSLayout/CSSDIrection.cs rename to csharp/Facebook.Yoga/YogaDirection.cs index 1a455709..000e37a7 100644 --- a/csharp/Facebook.CSSLayout/CSSDIrection.cs +++ b/csharp/Facebook.Yoga/YogaDirection.cs @@ -1,4 +1,4 @@ -/** +/** * Copyright (c) 2014-present, Facebook, Inc. * All rights reserved. * @@ -7,12 +7,12 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -namespace Facebook.CSSLayout +namespace Facebook.Yoga { - public enum CSSDirection + public enum YogaDirection { Inherit, - LeftToRight, - RightToLeft + LTR, + RTL, } } diff --git a/csharp/Facebook.CSSLayout/CSSEdge.cs b/csharp/Facebook.Yoga/YogaEdge.cs similarity index 85% rename from csharp/Facebook.CSSLayout/CSSEdge.cs rename to csharp/Facebook.Yoga/YogaEdge.cs index f4877f87..aaed3d30 100644 --- a/csharp/Facebook.CSSLayout/CSSEdge.cs +++ b/csharp/Facebook.Yoga/YogaEdge.cs @@ -1,4 +1,4 @@ -/** +/** * Copyright (c) 2014-present, Facebook, Inc. * All rights reserved. * @@ -7,9 +7,9 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -namespace Facebook.CSSLayout +namespace Facebook.Yoga { - public enum CSSEdge + public enum YogaEdge { Left, Top, @@ -20,6 +20,5 @@ namespace Facebook.CSSLayout Horizontal, Vertical, All, - Count, } } diff --git a/csharp/Facebook.Yoga/YogaExperimentalFeature.cs b/csharp/Facebook.Yoga/YogaExperimentalFeature.cs new file mode 100644 index 00000000..0f8156cb --- /dev/null +++ b/csharp/Facebook.Yoga/YogaExperimentalFeature.cs @@ -0,0 +1,17 @@ +/** + * 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. + */ + +namespace Facebook.Yoga +{ + public enum YogaExperimentalFeature + { + Rounding, + WebFlexBasis, + } +} diff --git a/csharp/Facebook.CSSLayout/CSSFlexDirection.cs b/csharp/Facebook.Yoga/YogaFlexDirection.cs similarity index 85% rename from csharp/Facebook.CSSLayout/CSSFlexDirection.cs rename to csharp/Facebook.Yoga/YogaFlexDirection.cs index a06f7533..385a2884 100644 --- a/csharp/Facebook.CSSLayout/CSSFlexDirection.cs +++ b/csharp/Facebook.Yoga/YogaFlexDirection.cs @@ -1,4 +1,4 @@ -/** +/** * Copyright (c) 2014-present, Facebook, Inc. * All rights reserved. * @@ -7,9 +7,9 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -namespace Facebook.CSSLayout +namespace Facebook.Yoga { - public enum CSSFlexDirection + public enum YogaFlexDirection { Column, ColumnReverse, diff --git a/csharp/Facebook.CSSLayout/CSSJustify.cs b/csharp/Facebook.Yoga/YogaJustify.cs similarity index 86% rename from csharp/Facebook.CSSLayout/CSSJustify.cs rename to csharp/Facebook.Yoga/YogaJustify.cs index 93e1566f..9f1e9163 100644 --- a/csharp/Facebook.CSSLayout/CSSJustify.cs +++ b/csharp/Facebook.Yoga/YogaJustify.cs @@ -1,4 +1,4 @@ -/** +/** * Copyright (c) 2014-present, Facebook, Inc. * All rights reserved. * @@ -7,9 +7,9 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -namespace Facebook.CSSLayout +namespace Facebook.Yoga { - public enum CSSJustify + public enum YogaJustify { FlexStart, Center, diff --git a/csharp/Facebook.Yoga/YogaLogLevel.cs b/csharp/Facebook.Yoga/YogaLogLevel.cs new file mode 100644 index 00000000..ce41ba48 --- /dev/null +++ b/csharp/Facebook.Yoga/YogaLogLevel.cs @@ -0,0 +1,20 @@ +/** + * 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. + */ + +namespace Facebook.Yoga +{ + public enum YogaLogLevel + { + Error, + Warn, + Info, + Debug, + Verbose, + } +} diff --git a/csharp/Facebook.CSSLayout/CSSLogger.cs b/csharp/Facebook.Yoga/YogaLogger.cs similarity index 64% rename from csharp/Facebook.CSSLayout/CSSLogger.cs rename to csharp/Facebook.Yoga/YogaLogger.cs index a5a95d0f..e5d79b79 100644 --- a/csharp/Facebook.CSSLayout/CSSLogger.cs +++ b/csharp/Facebook.Yoga/YogaLogger.cs @@ -10,12 +10,12 @@ using System; using System.Runtime.InteropServices; -namespace Facebook.CSSLayout +namespace Facebook.Yoga { - internal static class CSSLogger + internal static class YogaLogger { [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void Func(string message); + public delegate void Func(YogaLogLevel level, string message); private static bool _initialized; private static Func _managedLogger = null; @@ -26,13 +26,18 @@ namespace Facebook.CSSLayout { if (!_initialized) { - _managedLogger = (message) => { + _managedLogger = (level, message) => { if (Logger != null) { - Logger(message); + Logger(level, message); + } + + if (level == YogaLogLevel.Error) + { + throw new InvalidOperationException(message); } }; - Native.CSSInteropSetLogger(_managedLogger); + Native.YGInteropSetLogger(_managedLogger); _initialized = true; } } diff --git a/csharp/Facebook.CSSLayout/CSSMeasureFunc.cs b/csharp/Facebook.Yoga/YogaMeasureFunc.cs similarity index 73% rename from csharp/Facebook.CSSLayout/CSSMeasureFunc.cs rename to csharp/Facebook.Yoga/YogaMeasureFunc.cs index cd5744d5..0474292a 100644 --- a/csharp/Facebook.CSSLayout/CSSMeasureFunc.cs +++ b/csharp/Facebook.Yoga/YogaMeasureFunc.cs @@ -10,13 +10,13 @@ using System; using System.Runtime.InteropServices; -namespace Facebook.CSSLayout +namespace Facebook.Yoga { [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate CSSSize CSSMeasureFunc( - IntPtr node, + public delegate YogaSize YogaMeasureFunc( + IntPtr node, float width, - CSSMeasureMode widthMode, + YogaMeasureMode widthMode, float height, - CSSMeasureMode heightMode); + YogaMeasureMode heightMode); } diff --git a/csharp/Facebook.CSSLayout/CSSMeasureMode.cs b/csharp/Facebook.Yoga/YogaMeasureMode.cs similarity index 82% rename from csharp/Facebook.CSSLayout/CSSMeasureMode.cs rename to csharp/Facebook.Yoga/YogaMeasureMode.cs index ff82545c..f044b266 100644 --- a/csharp/Facebook.CSSLayout/CSSMeasureMode.cs +++ b/csharp/Facebook.Yoga/YogaMeasureMode.cs @@ -1,4 +1,4 @@ -/** +/** * Copyright (c) 2014-present, Facebook, Inc. * All rights reserved. * @@ -7,13 +7,12 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -namespace Facebook.CSSLayout +namespace Facebook.Yoga { - public enum CSSMeasureMode + public enum YogaMeasureMode { Undefined, Exactly, AtMost, - Count, } } diff --git a/csharp/Facebook.Yoga/YogaNode.Create.cs b/csharp/Facebook.Yoga/YogaNode.Create.cs new file mode 100644 index 00000000..a7df02d0 --- /dev/null +++ b/csharp/Facebook.Yoga/YogaNode.Create.cs @@ -0,0 +1,233 @@ +/** + * 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. + */ + +using System; + +namespace Facebook.Yoga +{ + public partial class YogaNode + { + public static YogaNode Create( + YogaDirection? styleDirection = null, + YogaFlexDirection? flexDirection = null, + YogaJustify? justifyContent = null, + YogaAlign? alignContent = null, + YogaAlign? alignItems = null, + YogaAlign? alignSelf = null, + YogaPositionType? positionType = null, + YogaWrap? wrap = null, + YogaOverflow? overflow = null, + float? flex = null, + float? flexGrow = null, + float? flexShrink = null, + float? flexBasis = null, + Spacing position = null, + Spacing margin = null, + Spacing padding = null, + Spacing border = null, + float? Width = null, + float? Height = null, + float? MaxWidth = null, + float? MaxHeight = null, + float? MinWidth = null, + float? MinHeight = null) + { + YogaNode node = new YogaNode(); + + if (styleDirection.HasValue) + { + node.StyleDirection = styleDirection.Value; + } + + if (flexDirection.HasValue) + { + node.FlexDirection = flexDirection.Value; + } + + if (justifyContent.HasValue) + { + node.JustifyContent = justifyContent.Value; + } + + if (alignContent.HasValue) + { + node.AlignContent = alignContent.Value; + } + + if (alignItems.HasValue) + { + node.AlignItems = alignItems.Value; + } + + if (alignSelf.HasValue) + { + node.AlignSelf = alignSelf.Value; + } + + if (positionType.HasValue) + { + node.PositionType = positionType.Value; + } + + if (wrap.HasValue) + { + node.Wrap = wrap.Value; + } + + if (overflow.HasValue) + { + node.Overflow = overflow.Value; + } + + if (flex.HasValue) + { + node.Flex = flex.Value; + } + + if (flexGrow.HasValue) + { + node.FlexGrow = flexGrow.Value; + } + + if (flexShrink.HasValue) + { + node.FlexShrink = flexShrink.Value; + } + + if (flexBasis.HasValue) + { + node.FlexBasis = flexBasis.Value; + } + + if (position != null) + { + if (position.Top.HasValue) + { + node.SetPosition(YogaEdge.Top, position.Top.Value); + } + + if (position.Bottom.HasValue) + { + node.SetPosition(YogaEdge.Bottom, position.Bottom.Value); + } + + if (position.Left.HasValue) + { + node.SetPosition(YogaEdge.Left, position.Left.Value); + } + + if (position.Right.HasValue) + { + node.SetPosition(YogaEdge.Right, position.Right.Value); + } + } + + if (margin != null) + { + if (margin.Top.HasValue) + { + node.SetMargin(YogaEdge.Top, margin.Top.Value); + } + + if (margin.Bottom.HasValue) + { + node.SetMargin(YogaEdge.Bottom, margin.Bottom.Value); + } + + if (margin.Left.HasValue) + { + node.SetMargin(YogaEdge.Left, margin.Left.Value); + } + + if (margin.Right.HasValue) + { + node.SetMargin(YogaEdge.Right, margin.Right.Value); + } + } + + if (padding != null) + { + if (padding.Top.HasValue) + { + node.SetPadding(YogaEdge.Top, padding.Top.Value); + } + + if (padding.Bottom.HasValue) + { + node.SetPadding(YogaEdge.Bottom, padding.Bottom.Value); + } + + if (padding.Left.HasValue) + { + node.SetPadding(YogaEdge.Left, padding.Left.Value); + } + + if (padding.Right.HasValue) + { + node.SetPadding(YogaEdge.Right, padding.Right.Value); + } + } + + if (border != null) + { + if (border.Top.HasValue) + { + node.SetBorder(YogaEdge.Top, border.Top.Value); + } + + if (border.Bottom.HasValue) + { + node.SetBorder(YogaEdge.Bottom, border.Bottom.Value); + } + + if (border.Left.HasValue) + { + node.SetBorder(YogaEdge.Left, border.Left.Value); + } + + if (border.Right.HasValue) + { + node.SetBorder(YogaEdge.Right, border.Right.Value); + } + } + + if (Width.HasValue) + { + node.Width = Width.Value; + } + + if (Height.HasValue) + { + node.Height = Height.Value; + } + + if (MinWidth.HasValue) + { + node.MinWidth = MinWidth.Value; + } + + if (MinHeight.HasValue) + { + node.MinHeight = MinHeight.Value; + } + + if (MaxWidth.HasValue) + { + node.MaxWidth = MaxWidth.Value; + } + + if (MaxHeight.HasValue) + { + node.MaxHeight = MaxHeight.Value; + } + + return node; + } + } +} diff --git a/csharp/Facebook.Yoga/YogaNode.cs b/csharp/Facebook.Yoga/YogaNode.cs new file mode 100644 index 00000000..9211b28e --- /dev/null +++ b/csharp/Facebook.Yoga/YogaNode.cs @@ -0,0 +1,584 @@ +/** + * 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. + */ + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; + +namespace Facebook.Yoga +{ + public partial class YogaNode : IEnumerable + { + private IntPtr _ygNode; + private WeakReference _parent; + private List _children; + private MeasureFunction _measureFunction; + private YogaMeasureFunc _ygMeasureFunc; + private object _data; + + public YogaNode() + { + YogaLogger.Initialize(); + + _ygNode = Native.YGNodeNew(); + if (_ygNode == IntPtr.Zero) + { + throw new InvalidOperationException("Failed to allocate native memory"); + } + } + + ~YogaNode() + { + Native.YGNodeFree(_ygNode); + } + + public void Reset() + { + _measureFunction = null; + _data = null; + + Native.YGNodeReset(_ygNode); + } + + public bool IsDirty + { + get + { + return Native.YGNodeIsDirty(_ygNode); + } + } + + public virtual void MarkDirty() + { + Native.YGNodeMarkDirty(_ygNode); + } + + public bool HasNewLayout + { + get + { + return Native.YGNodeGetHasNewLayout(_ygNode); + } + } + + public void MarkHasNewLayout() + { + Native.YGNodeSetHasNewLayout(_ygNode, true); + } + + public YogaNode Parent + { + get + { + return _parent != null ? _parent.Target as YogaNode : null; + } + } + + public bool IsMeasureDefined + { + get + { + return _measureFunction != null; + } + } + + public void CopyStyle(YogaNode srcNode) + { + Native.YGNodeCopyStyle(_ygNode, srcNode._ygNode); + } + + public YogaDirection StyleDirection + { + get + { + return Native.YGNodeStyleGetDirection(_ygNode); + } + + set + { + Native.YGNodeStyleSetDirection(_ygNode, value); + } + } + + public YogaFlexDirection FlexDirection + { + get + { + return Native.YGNodeStyleGetFlexDirection(_ygNode); + } + + set + { + Native.YGNodeStyleSetFlexDirection(_ygNode, value); + } + } + + public YogaJustify JustifyContent + { + get + { + return Native.YGNodeStyleGetJustifyContent(_ygNode); + } + + set + { + Native.YGNodeStyleSetJustifyContent(_ygNode, value); + } + } + + public YogaAlign AlignItems + { + get + { + return Native.YGNodeStyleGetAlignItems(_ygNode); + } + + set + { + Native.YGNodeStyleSetAlignItems(_ygNode, value); + } + } + + public YogaAlign AlignSelf + { + get + { + return Native.YGNodeStyleGetAlignSelf(_ygNode); + } + + set + { + Native.YGNodeStyleSetAlignSelf(_ygNode, value); + } + } + + public YogaAlign AlignContent + { + get + { + return Native.YGNodeStyleGetAlignContent(_ygNode); + } + + set + { + Native.YGNodeStyleSetAlignContent(_ygNode, value); + } + } + + public YogaPositionType PositionType + { + get + { + return Native.YGNodeStyleGetPositionType(_ygNode); + } + + set + { + Native.YGNodeStyleSetPositionType(_ygNode, value); + } + } + + public YogaWrap Wrap + { + get + { + return Native.YGNodeStyleGetFlexWrap(_ygNode); + } + + set + { + Native.YGNodeStyleSetFlexWrap(_ygNode, value); + } + } + + public float Flex + { + set + { + Native.YGNodeStyleSetFlex(_ygNode, value); + } + } + + public float FlexGrow + { + get + { + return Native.YGNodeStyleGetFlexGrow(_ygNode); + } + + set + { + Native.YGNodeStyleSetFlexGrow(_ygNode, value); + } + } + + public float FlexShrink + { + get + { + return Native.YGNodeStyleGetFlexShrink(_ygNode); + } + + set + { + Native.YGNodeStyleSetFlexShrink(_ygNode, value); + } + } + + public float FlexBasis + { + get + { + return Native.YGNodeStyleGetFlexBasis(_ygNode); + } + + set + { + Native.YGNodeStyleSetFlexBasis(_ygNode, value); + } + } + + public float GetMargin(YogaEdge edge) + { + return Native.YGNodeStyleGetMargin(_ygNode, edge); + } + + public void SetMargin(YogaEdge edge, float value) + { + Native.YGNodeStyleSetMargin(_ygNode, edge, value); + } + + public float GetPadding(YogaEdge edge) + { + return Native.YGNodeStyleGetPadding(_ygNode, edge); + } + + public void SetPadding(YogaEdge edge, float padding) + { + Native.YGNodeStyleSetPadding(_ygNode, edge, padding); + } + + public float GetBorder(YogaEdge edge) + { + return Native.YGNodeStyleGetBorder(_ygNode, edge); + } + + public void SetBorder(YogaEdge edge, float border) + { + Native.YGNodeStyleSetBorder(_ygNode, edge, border); + } + + public float GetPosition(YogaEdge edge) + { + return Native.YGNodeStyleGetPosition(_ygNode, edge); + } + + public void SetPosition(YogaEdge edge, float position) + { + Native.YGNodeStyleSetPosition(_ygNode, edge, position); + } + + public float Width + { + get + { + return Native.YGNodeStyleGetWidth(_ygNode); + } + + set + { + Native.YGNodeStyleSetWidth(_ygNode, value); + } + } + + public float Height + { + get + { + return Native.YGNodeStyleGetHeight(_ygNode); + } + + set + { + Native.YGNodeStyleSetHeight(_ygNode, value); + } + } + + public float MaxWidth + { + get + { + return Native.YGNodeStyleGetMaxWidth(_ygNode); + } + + set + { + Native.YGNodeStyleSetMaxWidth(_ygNode, value); + } + } + + public float MaxHeight + { + get + { + return Native.YGNodeStyleGetMaxHeight(_ygNode); + } + + set + { + Native.YGNodeStyleSetMaxHeight(_ygNode, value); + } + } + + public float MinWidth + { + get + { + return Native.YGNodeStyleGetMinWidth(_ygNode); + } + + set + { + Native.YGNodeStyleSetMinWidth(_ygNode, value); + } + } + + public float MinHeight + { + get + { + return Native.YGNodeStyleGetMinHeight(_ygNode); + } + + set + { + Native.YGNodeStyleSetMinHeight(_ygNode, value); + } + } + + public float StyleAspectRatio + { + get + { + return Native.YGNodeStyleGetAspectRatio(_ygNode); + } + + set + { + Native.YGNodeStyleSetAspectRatio(_ygNode, value); + } + } + + public float LayoutX + { + get + { + return Native.YGNodeLayoutGetLeft(_ygNode); + } + } + + public float LayoutY + { + get + { + return Native.YGNodeLayoutGetTop(_ygNode); + } + } + + public float LayoutWidth + { + get + { + return Native.YGNodeLayoutGetWidth(_ygNode); + } + } + + public float LayoutHeight + { + get + { + return Native.YGNodeLayoutGetHeight(_ygNode); + } + } + + public YogaDirection LayoutDirection + { + get + { + return Native.YGNodeLayoutGetDirection(_ygNode); + } + } + + public YogaOverflow Overflow + { + get + { + return Native.YGNodeStyleGetOverflow(_ygNode); + } + + set + { + Native.YGNodeStyleSetOverflow(_ygNode, value); + } + } + + public object Data + { + get + { + return _data; + } + + set + { + _data = value; + } + } + + public YogaNode this[int index] + { + get + { + return _children[index]; + } + } + + public int Count + { + get + { + return _children != null ? _children.Count : 0; + } + } + + public void MarkLayoutSeen() + { + Native.YGNodeSetHasNewLayout(_ygNode, false); + } + + public bool ValuesEqual(float f1, float f2) + { + if (float.IsNaN(f1) || float.IsNaN(f2)) + { + return float.IsNaN(f1) && float.IsNaN(f2); + } + + return Math.Abs(f2 - f1) < float.Epsilon; + } + + public void Insert(int index, YogaNode node) + { + if (_children == null) + { + _children = new List(4); + } + _children.Insert(index, node); + node._parent = new WeakReference(this); + Native.YGNodeInsertChild(_ygNode, node._ygNode, (uint)index); + } + + public void RemoveAt(int index) + { + var child = _children[index]; + child._parent = null; + _children.RemoveAt(index); + Native.YGNodeRemoveChild(_ygNode, child._ygNode); + } + + public void Clear() + { + if (_children != null) + { + while (_children.Count > 0) + { + RemoveAt(_children.Count-1); + } + } + } + + public int IndexOf(YogaNode node) + { + return _children != null ? _children.IndexOf(node) : -1; + } + + public void SetMeasureFunction(MeasureFunction measureFunction) + { + _measureFunction = measureFunction; + _ygMeasureFunc = measureFunction != null ? MeasureInternal : (YogaMeasureFunc)null; + Native.YGNodeSetMeasureFunc(_ygNode, _ygMeasureFunc); + } + + public void CalculateLayout() + { + Native.YGNodeCalculateLayout( + _ygNode, + YogaConstants.Undefined, + YogaConstants.Undefined, + Native.YGNodeStyleGetDirection(_ygNode)); + } + + private YogaSize MeasureInternal( + IntPtr node, + float width, + YogaMeasureMode widthMode, + float height, + YogaMeasureMode heightMode) + { + if (_measureFunction == null) + { + throw new InvalidOperationException("Measure function is not defined."); + } + + long output = _measureFunction(this, width, widthMode, height, heightMode); + return new YogaSize { width = MeasureOutput.GetWidth(output), height = MeasureOutput.GetHeight(output) }; + } + + public string Print(YogaPrintOptions options = + YogaPrintOptions.Layout|YogaPrintOptions.Style|YogaPrintOptions.Children) + { + StringBuilder sb = new StringBuilder(); + YogaLogger.Func orig = YogaLogger.Logger; + YogaLogger.Logger = (level, message) => {sb.Append(message);}; + Native.YGNodePrint(_ygNode, options); + YogaLogger.Logger = orig; + return sb.ToString(); + } + + public IEnumerator GetEnumerator() + { + return _children != null ? ((IEnumerable)_children).GetEnumerator() : + System.Linq.Enumerable.Empty().GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return _children != null ? ((IEnumerable)_children).GetEnumerator() : + System.Linq.Enumerable.Empty().GetEnumerator(); + } + + public static int GetInstanceCount() + { + return Native.YGNodeGetInstanceCount(); + } + + public static void SetExperimentalFeatureEnabled( + YogaExperimentalFeature feature, + bool enabled) + { + Native.YGSetExperimentalFeatureEnabled(feature, enabled); + } + + public static bool IsExperimentalFeatureEnabled(YogaExperimentalFeature feature) + { + return Native.YGIsExperimentalFeatureEnabled(feature); + } + } +} diff --git a/csharp/Facebook.CSSLayout/CSSOverflow.cs b/csharp/Facebook.Yoga/YogaOverflow.cs similarity index 82% rename from csharp/Facebook.CSSLayout/CSSOverflow.cs rename to csharp/Facebook.Yoga/YogaOverflow.cs index df1492ec..29b2a5de 100644 --- a/csharp/Facebook.CSSLayout/CSSOverflow.cs +++ b/csharp/Facebook.Yoga/YogaOverflow.cs @@ -1,4 +1,4 @@ -/** +/** * Copyright (c) 2014-present, Facebook, Inc. * All rights reserved. * @@ -7,11 +7,12 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -namespace Facebook.CSSLayout +namespace Facebook.Yoga { - public enum CSSOverflow + public enum YogaOverflow { Visible, Hidden, + Scroll, } } diff --git a/csharp/Facebook.CSSLayout/CSSPositionType.cs b/csharp/Facebook.Yoga/YogaPositionType.cs similarity index 80% rename from csharp/Facebook.CSSLayout/CSSPositionType.cs rename to csharp/Facebook.Yoga/YogaPositionType.cs index ac12484d..8225b3f4 100644 --- a/csharp/Facebook.CSSLayout/CSSPositionType.cs +++ b/csharp/Facebook.Yoga/YogaPositionType.cs @@ -1,4 +1,4 @@ -/** +/** * Copyright (c) 2014-present, Facebook, Inc. * All rights reserved. * @@ -7,11 +7,11 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -namespace Facebook.CSSLayout +namespace Facebook.Yoga { - public enum CSSPositionType + public enum YogaPositionType { Relative, - Absolute + Absolute, } } diff --git a/csharp/Facebook.CSSLayout/CSSPrintOptions.cs b/csharp/Facebook.Yoga/YogaPrintOptions.cs similarity index 84% rename from csharp/Facebook.CSSLayout/CSSPrintOptions.cs rename to csharp/Facebook.Yoga/YogaPrintOptions.cs index 8d608f4e..be3723f0 100644 --- a/csharp/Facebook.CSSLayout/CSSPrintOptions.cs +++ b/csharp/Facebook.Yoga/YogaPrintOptions.cs @@ -1,4 +1,4 @@ -/** +/** * Copyright (c) 2014-present, Facebook, Inc. * All rights reserved. * @@ -7,9 +7,9 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -namespace Facebook.CSSLayout +namespace Facebook.Yoga { - public enum CSSPrintOptions + public enum YogaPrintOptions { Layout = 1, Style = 2, diff --git a/csharp/Facebook.CSSLayout/CSSSize.cs b/csharp/Facebook.Yoga/YogaSize.cs similarity index 89% rename from csharp/Facebook.CSSLayout/CSSSize.cs rename to csharp/Facebook.Yoga/YogaSize.cs index 5fd3a291..d46f82fb 100644 --- a/csharp/Facebook.CSSLayout/CSSSize.cs +++ b/csharp/Facebook.Yoga/YogaSize.cs @@ -9,10 +9,10 @@ using System.Runtime.InteropServices; -namespace Facebook.CSSLayout +namespace Facebook.Yoga { [StructLayout(LayoutKind.Sequential)] - public struct CSSSize + public struct YogaSize { public float width; public float height; diff --git a/csharp/Facebook.CSSLayout/CSSWrap.cs b/csharp/Facebook.Yoga/YogaWrap.cs similarity index 85% rename from csharp/Facebook.CSSLayout/CSSWrap.cs rename to csharp/Facebook.Yoga/YogaWrap.cs index 15425b28..3d88ad04 100644 --- a/csharp/Facebook.CSSLayout/CSSWrap.cs +++ b/csharp/Facebook.Yoga/YogaWrap.cs @@ -1,4 +1,4 @@ -/** +/** * Copyright (c) 2014-present, Facebook, Inc. * All rights reserved. * @@ -7,9 +7,9 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -namespace Facebook.CSSLayout +namespace Facebook.Yoga { - public enum CSSWrap + public enum YogaWrap { NoWrap, Wrap, diff --git a/csharp/Facebook.CSSLayout/project.json b/csharp/Facebook.Yoga/project.json similarity index 100% rename from csharp/Facebook.CSSLayout/project.json rename to csharp/Facebook.Yoga/project.json diff --git a/csharp/CSSLayout/CSSInterop.cpp b/csharp/Yoga/YGInterop.cpp similarity index 61% rename from csharp/CSSLayout/CSSInterop.cpp rename to csharp/Yoga/YGInterop.cpp index 56c5597e..fc2043dc 100644 --- a/csharp/CSSLayout/CSSInterop.cpp +++ b/csharp/Yoga/YGInterop.cpp @@ -7,24 +7,21 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -#include "CSSInterop.h" +#include "YGInterop.h" -static CSSInteropLoggerFunc gManagedFunc; +static YGInteropLoggerFunc gManagedFunc; -static int unmanagedLogger(const char *format, ...) { +static int unmanagedLogger(YGLogLevel level, const char *format, va_list args) { int result = 0; if (gManagedFunc) { - va_list args; - va_start(args, format); char buffer[256]; result = vsnprintf(buffer, sizeof(buffer), format, args); - (*gManagedFunc)(buffer); - va_end(args); + (*gManagedFunc)(level, buffer); } return result; } -void CSSInteropSetLogger(CSSInteropLoggerFunc managedFunc) { +void YGInteropSetLogger(YGInteropLoggerFunc managedFunc) { gManagedFunc = managedFunc; - CSSLayoutSetLogger(&unmanagedLogger); + YGSetLogger(&unmanagedLogger); } diff --git a/csharp/CSSLayout/CSSInterop.h b/csharp/Yoga/YGInterop.h similarity index 61% rename from csharp/CSSLayout/CSSInterop.h rename to csharp/Yoga/YGInterop.h index 7533cfd3..7494977f 100644 --- a/csharp/CSSLayout/CSSInterop.h +++ b/csharp/Yoga/YGInterop.h @@ -9,12 +9,12 @@ #pragma once -#include +#include -CSS_EXTERN_C_BEGIN +YG_EXTERN_C_BEGIN -typedef void (*CSSInteropLoggerFunc)(const char *message); +typedef void (*YGInteropLoggerFunc)(YGLogLevel level, const char *message); -WIN_EXPORT void CSSInteropSetLogger(CSSInteropLoggerFunc managedFunc); +WIN_EXPORT void YGInteropSetLogger(YGInteropLoggerFunc managedFunc); -CSS_EXTERN_C_END +YG_EXTERN_C_END diff --git a/csharp/CSSLayout/CSSLayout.vcxproj b/csharp/Yoga/Yoga.vcxproj similarity index 86% rename from csharp/CSSLayout/CSSLayout.vcxproj rename to csharp/Yoga/Yoga.vcxproj index 199eb3e8..b3704474 100755 --- a/csharp/CSSLayout/CSSLayout.vcxproj +++ b/csharp/Yoga/Yoga.vcxproj @@ -21,7 +21,7 @@ {0446C86B-F47B-4C46-B673-C7AE0CFF35D5} Win32Proj - CSSLayout + Yoga 10.0.14393.0 @@ -87,7 +87,7 @@ Level3 Disabled - WIN32;_DEBUG;_WINDOWS;_USRDLL;CSSLAYOUT_EXPORTS;CSS_ASSERT_FAIL_ENABLED;FB_ASSERTIONS_ENABLED=0;%(PreprocessorDefinitions) + WIN32;_DEBUG;_WINDOWS;_USRDLL;YOGA_EXPORTS;FB_ASSERTIONS_ENABLED=0;%(PreprocessorDefinitions) true $(ProjectDir)..\..\;%(AdditionalIncludeDirectories) @@ -102,7 +102,7 @@ Level3 Disabled - _DEBUG;_WINDOWS;_USRDLL;CSSLAYOUT_EXPORTS;CSS_ASSERT_FAIL_ENABLED;FB_ASSERTIONS_ENABLED=0;%(PreprocessorDefinitions) + _DEBUG;_WINDOWS;_USRDLL;YOGA_EXPORTS;FB_ASSERTIONS_ENABLED=0;%(PreprocessorDefinitions) true $(ProjectDir)..\..\;%(AdditionalIncludeDirectories) @@ -119,7 +119,7 @@ MaxSpeed true true - WIN32;NDEBUG;_WINDOWS;_USRDLL;CSSLAYOUT_EXPORTS;CSS_ASSERT_FAIL_ENABLED;FB_ASSERTIONS_ENABLED=0;%(PreprocessorDefinitions) + WIN32;NDEBUG;_WINDOWS;_USRDLL;YOGA_EXPORTS;FB_ASSERTIONS_ENABLED=0;%(PreprocessorDefinitions) true $(ProjectDir)..\..\;%(AdditionalIncludeDirectories) @@ -138,7 +138,7 @@ MaxSpeed true true - NDEBUG;_WINDOWS;_USRDLL;CSSLAYOUT_EXPORTS;CSS_ASSERT_FAIL_ENABLED;FB_ASSERTIONS_ENABLED=0;%(PreprocessorDefinitions) + NDEBUG;_WINDOWS;_USRDLL;YOGA_EXPORTS;FB_ASSERTIONS_ENABLED=0;%(PreprocessorDefinitions) true $(ProjectDir)..\..\;%(AdditionalIncludeDirectories) @@ -150,17 +150,17 @@ - - - - + + + + - - - + + + false @@ -180,4 +180,4 @@ - \ No newline at end of file + diff --git a/csharp/CSSLayout/CSSLayout.vcxproj.filters b/csharp/Yoga/Yoga.vcxproj.filters similarity index 81% rename from csharp/CSSLayout/CSSLayout.vcxproj.filters rename to csharp/Yoga/Yoga.vcxproj.filters index 07197766..c3afcf63 100755 --- a/csharp/CSSLayout/CSSLayout.vcxproj.filters +++ b/csharp/Yoga/Yoga.vcxproj.filters @@ -21,16 +21,16 @@ Header Files - + Header Files - + Header Files - + Header Files - + Header Files @@ -41,14 +41,14 @@ Source Files - + Source Files - + Source Files - + Source Files - \ No newline at end of file + diff --git a/csharp/CSSLayout/dllmain.cpp b/csharp/Yoga/dllmain.cpp similarity index 100% rename from csharp/CSSLayout/dllmain.cpp rename to csharp/Yoga/dllmain.cpp diff --git a/csharp/CSSLayout/stdafx.cpp b/csharp/Yoga/stdafx.cpp similarity index 91% rename from csharp/CSSLayout/stdafx.cpp rename to csharp/Yoga/stdafx.cpp index 53e7c346..cdee8426 100644 --- a/csharp/CSSLayout/stdafx.cpp +++ b/csharp/Yoga/stdafx.cpp @@ -8,7 +8,7 @@ */ // stdafx.cpp : source file that includes just the standard includes -// CSSLayout.pch will be the pre-compiled header +// Yoga.pch will be the pre-compiled header // stdafx.obj will contain the pre-compiled type information #include "stdafx.h" diff --git a/csharp/CSSLayout/stdafx.h b/csharp/Yoga/stdafx.h similarity index 100% rename from csharp/CSSLayout/stdafx.h rename to csharp/Yoga/stdafx.h diff --git a/csharp/CSSLayout/targetver.h b/csharp/Yoga/targetver.h similarity index 100% rename from csharp/CSSLayout/targetver.h rename to csharp/Yoga/targetver.h diff --git a/csharp/tests/Facebook.CSSLayout/CSSLayoutAbsolutePositionTest.cs b/csharp/tests/Facebook.CSSLayout/CSSLayoutAbsolutePositionTest.cs deleted file mode 100644 index c9ae2bb6..00000000 --- a/csharp/tests/Facebook.CSSLayout/CSSLayoutAbsolutePositionTest.cs +++ /dev/null @@ -1,266 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
-
-
- * - */ - -using System; -using NUnit.Framework; - -namespace Facebook.CSSLayout -{ - [TestFixture] - public class CSSLayoutAbsolutePositionTest - { - [Test] - public void Test_absolute_layout_width_height_start_top() - { - CSSNode root = new CSSNode(); - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.PositionType = CSSPositionType.Absolute; - root_child0.SetPosition(CSSEdge.Start, 10); - root_child0.SetPosition(CSSEdge.Top, 10); - root_child0.StyleWidth = 10; - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(10, root_child0.LayoutX); - Assert.AreEqual(10, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(80, root_child0.LayoutX); - Assert.AreEqual(10, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - } - - [Test] - public void Test_absolute_layout_width_height_end_bottom() - { - CSSNode root = new CSSNode(); - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.PositionType = CSSPositionType.Absolute; - root_child0.SetPosition(CSSEdge.End, 10); - root_child0.SetPosition(CSSEdge.Bottom, 10); - root_child0.StyleWidth = 10; - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(80, root_child0.LayoutX); - Assert.AreEqual(80, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(10, root_child0.LayoutX); - Assert.AreEqual(80, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - } - - [Test] - public void Test_absolute_layout_start_top_end_bottom() - { - CSSNode root = new CSSNode(); - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.PositionType = CSSPositionType.Absolute; - root_child0.SetPosition(CSSEdge.Start, 10); - root_child0.SetPosition(CSSEdge.Top, 10); - root_child0.SetPosition(CSSEdge.End, 10); - root_child0.SetPosition(CSSEdge.Bottom, 10); - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(10, root_child0.LayoutX); - Assert.AreEqual(10, root_child0.LayoutY); - Assert.AreEqual(80, root_child0.LayoutWidth); - Assert.AreEqual(80, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(10, root_child0.LayoutX); - Assert.AreEqual(10, root_child0.LayoutY); - Assert.AreEqual(80, root_child0.LayoutWidth); - Assert.AreEqual(80, root_child0.LayoutHeight); - } - - [Test] - public void Test_absolute_layout_width_height_start_top_end_bottom() - { - CSSNode root = new CSSNode(); - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.PositionType = CSSPositionType.Absolute; - root_child0.SetPosition(CSSEdge.Start, 10); - root_child0.SetPosition(CSSEdge.Top, 10); - root_child0.SetPosition(CSSEdge.End, 10); - root_child0.SetPosition(CSSEdge.Bottom, 10); - root_child0.StyleWidth = 10; - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(10, root_child0.LayoutX); - Assert.AreEqual(10, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(80, root_child0.LayoutX); - Assert.AreEqual(10, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - } - - [Test] - public void Test_do_not_clamp_height_of_absolute_node_to_height_of_its_overflow_hidden_parent() - { - CSSNode root = new CSSNode(); - root.FlexDirection = CSSFlexDirection.Row; - root.Overflow = CSSOverflow.Hidden; - root.StyleWidth = 50; - root.StyleHeight = 50; - - CSSNode root_child0 = new CSSNode(); - root_child0.PositionType = CSSPositionType.Absolute; - root.Insert(0, root_child0); - - CSSNode root_child0_child0 = new CSSNode(); - root_child0_child0.StyleWidth = 100; - root_child0_child0.StyleHeight = 100; - root_child0.Insert(0, root_child0_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(50, root.LayoutWidth); - Assert.AreEqual(50, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(100, root_child0.LayoutWidth); - Assert.AreEqual(100, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child0_child0.LayoutX); - Assert.AreEqual(0, root_child0_child0.LayoutY); - Assert.AreEqual(100, root_child0_child0.LayoutWidth); - Assert.AreEqual(100, root_child0_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(50, root.LayoutWidth); - Assert.AreEqual(50, root.LayoutHeight); - - Assert.AreEqual(-50, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(100, root_child0.LayoutWidth); - Assert.AreEqual(100, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child0_child0.LayoutX); - Assert.AreEqual(0, root_child0_child0.LayoutY); - Assert.AreEqual(100, root_child0_child0.LayoutWidth); - Assert.AreEqual(100, root_child0_child0.LayoutHeight); - } - - } -} diff --git a/csharp/tests/Facebook.CSSLayout/CSSLayoutAlignContentTest.cs b/csharp/tests/Facebook.CSSLayout/CSSLayoutAlignContentTest.cs deleted file mode 100644 index 4ceef498..00000000 --- a/csharp/tests/Facebook.CSSLayout/CSSLayoutAlignContentTest.cs +++ /dev/null @@ -1,450 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
-
-
-
-
- -
-
-
-
-
-
-
- -
-
-
-
-
-
-
- -
-
-
-
-
-
-
- * - */ - -using System; -using NUnit.Framework; - -namespace Facebook.CSSLayout -{ - [TestFixture] - public class CSSLayoutAlignContentTest - { - [Test] - public void Test_align_content_flex_start() - { - CSSNode root = new CSSNode(); - root.Wrap = CSSWrap.Wrap; - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleWidth = 50; - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.StyleWidth = 50; - root_child1.StyleHeight = 10; - root.Insert(1, root_child1); - - CSSNode root_child2 = new CSSNode(); - root_child2.StyleWidth = 50; - root_child2.StyleHeight = 10; - root.Insert(2, root_child2); - - CSSNode root_child3 = new CSSNode(); - root_child3.StyleWidth = 50; - root_child3.StyleHeight = 10; - root.Insert(3, root_child3); - - CSSNode root_child4 = new CSSNode(); - root_child4.StyleWidth = 50; - root_child4.StyleHeight = 10; - root.Insert(4, root_child4); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(50, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(10, root_child1.LayoutY); - Assert.AreEqual(50, root_child1.LayoutWidth); - Assert.AreEqual(10, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(20, root_child2.LayoutY); - Assert.AreEqual(50, root_child2.LayoutWidth); - Assert.AreEqual(10, root_child2.LayoutHeight); - - Assert.AreEqual(0, root_child3.LayoutX); - Assert.AreEqual(30, root_child3.LayoutY); - Assert.AreEqual(50, root_child3.LayoutWidth); - Assert.AreEqual(10, root_child3.LayoutHeight); - - Assert.AreEqual(0, root_child4.LayoutX); - Assert.AreEqual(40, root_child4.LayoutY); - Assert.AreEqual(50, root_child4.LayoutWidth); - Assert.AreEqual(10, root_child4.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(50, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(50, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - Assert.AreEqual(50, root_child1.LayoutX); - Assert.AreEqual(10, root_child1.LayoutY); - Assert.AreEqual(50, root_child1.LayoutWidth); - Assert.AreEqual(10, root_child1.LayoutHeight); - - Assert.AreEqual(50, root_child2.LayoutX); - Assert.AreEqual(20, root_child2.LayoutY); - Assert.AreEqual(50, root_child2.LayoutWidth); - Assert.AreEqual(10, root_child2.LayoutHeight); - - Assert.AreEqual(50, root_child3.LayoutX); - Assert.AreEqual(30, root_child3.LayoutY); - Assert.AreEqual(50, root_child3.LayoutWidth); - Assert.AreEqual(10, root_child3.LayoutHeight); - - Assert.AreEqual(50, root_child4.LayoutX); - Assert.AreEqual(40, root_child4.LayoutY); - Assert.AreEqual(50, root_child4.LayoutWidth); - Assert.AreEqual(10, root_child4.LayoutHeight); - } - - [Test] - public void Test_align_content_flex_end() - { - CSSNode root = new CSSNode(); - root.AlignContent = CSSAlign.FlexEnd; - root.Wrap = CSSWrap.Wrap; - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleWidth = 50; - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.StyleWidth = 50; - root_child1.StyleHeight = 10; - root.Insert(1, root_child1); - - CSSNode root_child2 = new CSSNode(); - root_child2.StyleWidth = 50; - root_child2.StyleHeight = 10; - root.Insert(2, root_child2); - - CSSNode root_child3 = new CSSNode(); - root_child3.StyleWidth = 50; - root_child3.StyleHeight = 10; - root.Insert(3, root_child3); - - CSSNode root_child4 = new CSSNode(); - root_child4.StyleWidth = 50; - root_child4.StyleHeight = 10; - root.Insert(4, root_child4); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(50, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(10, root_child1.LayoutY); - Assert.AreEqual(50, root_child1.LayoutWidth); - Assert.AreEqual(10, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(20, root_child2.LayoutY); - Assert.AreEqual(50, root_child2.LayoutWidth); - Assert.AreEqual(10, root_child2.LayoutHeight); - - Assert.AreEqual(0, root_child3.LayoutX); - Assert.AreEqual(30, root_child3.LayoutY); - Assert.AreEqual(50, root_child3.LayoutWidth); - Assert.AreEqual(10, root_child3.LayoutHeight); - - Assert.AreEqual(0, root_child4.LayoutX); - Assert.AreEqual(40, root_child4.LayoutY); - Assert.AreEqual(50, root_child4.LayoutWidth); - Assert.AreEqual(10, root_child4.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(50, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(50, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - Assert.AreEqual(50, root_child1.LayoutX); - Assert.AreEqual(10, root_child1.LayoutY); - Assert.AreEqual(50, root_child1.LayoutWidth); - Assert.AreEqual(10, root_child1.LayoutHeight); - - Assert.AreEqual(50, root_child2.LayoutX); - Assert.AreEqual(20, root_child2.LayoutY); - Assert.AreEqual(50, root_child2.LayoutWidth); - Assert.AreEqual(10, root_child2.LayoutHeight); - - Assert.AreEqual(50, root_child3.LayoutX); - Assert.AreEqual(30, root_child3.LayoutY); - Assert.AreEqual(50, root_child3.LayoutWidth); - Assert.AreEqual(10, root_child3.LayoutHeight); - - Assert.AreEqual(50, root_child4.LayoutX); - Assert.AreEqual(40, root_child4.LayoutY); - Assert.AreEqual(50, root_child4.LayoutWidth); - Assert.AreEqual(10, root_child4.LayoutHeight); - } - - [Test] - public void Test_align_content_center() - { - CSSNode root = new CSSNode(); - root.AlignContent = CSSAlign.Center; - root.Wrap = CSSWrap.Wrap; - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleWidth = 50; - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.StyleWidth = 50; - root_child1.StyleHeight = 10; - root.Insert(1, root_child1); - - CSSNode root_child2 = new CSSNode(); - root_child2.StyleWidth = 50; - root_child2.StyleHeight = 10; - root.Insert(2, root_child2); - - CSSNode root_child3 = new CSSNode(); - root_child3.StyleWidth = 50; - root_child3.StyleHeight = 10; - root.Insert(3, root_child3); - - CSSNode root_child4 = new CSSNode(); - root_child4.StyleWidth = 50; - root_child4.StyleHeight = 10; - root.Insert(4, root_child4); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(50, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(10, root_child1.LayoutY); - Assert.AreEqual(50, root_child1.LayoutWidth); - Assert.AreEqual(10, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(20, root_child2.LayoutY); - Assert.AreEqual(50, root_child2.LayoutWidth); - Assert.AreEqual(10, root_child2.LayoutHeight); - - Assert.AreEqual(0, root_child3.LayoutX); - Assert.AreEqual(30, root_child3.LayoutY); - Assert.AreEqual(50, root_child3.LayoutWidth); - Assert.AreEqual(10, root_child3.LayoutHeight); - - Assert.AreEqual(0, root_child4.LayoutX); - Assert.AreEqual(40, root_child4.LayoutY); - Assert.AreEqual(50, root_child4.LayoutWidth); - Assert.AreEqual(10, root_child4.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(50, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(50, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - Assert.AreEqual(50, root_child1.LayoutX); - Assert.AreEqual(10, root_child1.LayoutY); - Assert.AreEqual(50, root_child1.LayoutWidth); - Assert.AreEqual(10, root_child1.LayoutHeight); - - Assert.AreEqual(50, root_child2.LayoutX); - Assert.AreEqual(20, root_child2.LayoutY); - Assert.AreEqual(50, root_child2.LayoutWidth); - Assert.AreEqual(10, root_child2.LayoutHeight); - - Assert.AreEqual(50, root_child3.LayoutX); - Assert.AreEqual(30, root_child3.LayoutY); - Assert.AreEqual(50, root_child3.LayoutWidth); - Assert.AreEqual(10, root_child3.LayoutHeight); - - Assert.AreEqual(50, root_child4.LayoutX); - Assert.AreEqual(40, root_child4.LayoutY); - Assert.AreEqual(50, root_child4.LayoutWidth); - Assert.AreEqual(10, root_child4.LayoutHeight); - } - - [Test] - public void Test_align_content_stretch() - { - CSSNode root = new CSSNode(); - root.AlignContent = CSSAlign.Stretch; - root.Wrap = CSSWrap.Wrap; - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleWidth = 50; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.StyleWidth = 50; - root.Insert(1, root_child1); - - CSSNode root_child2 = new CSSNode(); - root_child2.StyleWidth = 50; - root.Insert(2, root_child2); - - CSSNode root_child3 = new CSSNode(); - root_child3.StyleWidth = 50; - root.Insert(3, root_child3); - - CSSNode root_child4 = new CSSNode(); - root_child4.StyleWidth = 50; - root.Insert(4, root_child4); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(50, root_child0.LayoutWidth); - Assert.AreEqual(0, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(0, root_child1.LayoutY); - Assert.AreEqual(50, root_child1.LayoutWidth); - Assert.AreEqual(0, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(0, root_child2.LayoutY); - Assert.AreEqual(50, root_child2.LayoutWidth); - Assert.AreEqual(0, root_child2.LayoutHeight); - - Assert.AreEqual(0, root_child3.LayoutX); - Assert.AreEqual(0, root_child3.LayoutY); - Assert.AreEqual(50, root_child3.LayoutWidth); - Assert.AreEqual(0, root_child3.LayoutHeight); - - Assert.AreEqual(0, root_child4.LayoutX); - Assert.AreEqual(0, root_child4.LayoutY); - Assert.AreEqual(50, root_child4.LayoutWidth); - Assert.AreEqual(0, root_child4.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(50, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(50, root_child0.LayoutWidth); - Assert.AreEqual(0, root_child0.LayoutHeight); - - Assert.AreEqual(50, root_child1.LayoutX); - Assert.AreEqual(0, root_child1.LayoutY); - Assert.AreEqual(50, root_child1.LayoutWidth); - Assert.AreEqual(0, root_child1.LayoutHeight); - - Assert.AreEqual(50, root_child2.LayoutX); - Assert.AreEqual(0, root_child2.LayoutY); - Assert.AreEqual(50, root_child2.LayoutWidth); - Assert.AreEqual(0, root_child2.LayoutHeight); - - Assert.AreEqual(50, root_child3.LayoutX); - Assert.AreEqual(0, root_child3.LayoutY); - Assert.AreEqual(50, root_child3.LayoutWidth); - Assert.AreEqual(0, root_child3.LayoutHeight); - - Assert.AreEqual(50, root_child4.LayoutX); - Assert.AreEqual(0, root_child4.LayoutY); - Assert.AreEqual(50, root_child4.LayoutWidth); - Assert.AreEqual(0, root_child4.LayoutHeight); - } - - } -} diff --git a/csharp/tests/Facebook.CSSLayout/CSSLayoutAlignItemsTest.cs b/csharp/tests/Facebook.CSSLayout/CSSLayoutAlignItemsTest.cs deleted file mode 100644 index 17bc2355..00000000 --- a/csharp/tests/Facebook.CSSLayout/CSSLayoutAlignItemsTest.cs +++ /dev/null @@ -1,194 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
- -
-
-
- -
-
-
- -
-
-
- * - */ - -using System; -using NUnit.Framework; - -namespace Facebook.CSSLayout -{ - [TestFixture] - public class CSSLayoutAlignItemsTest - { - [Test] - public void Test_align_items_stretch() - { - CSSNode root = new CSSNode(); - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(100, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(100, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - } - - [Test] - public void Test_align_items_center() - { - CSSNode root = new CSSNode(); - root.AlignItems = CSSAlign.Center; - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleWidth = 10; - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(45, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(45, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - } - - [Test] - public void Test_align_items_flex_start() - { - CSSNode root = new CSSNode(); - root.AlignItems = CSSAlign.FlexStart; - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleWidth = 10; - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(90, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - } - - [Test] - public void Test_align_items_flex_end() - { - CSSNode root = new CSSNode(); - root.AlignItems = CSSAlign.FlexEnd; - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleWidth = 10; - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(90, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - } - - } -} diff --git a/csharp/tests/Facebook.CSSLayout/CSSLayoutAlignSelfTest.cs b/csharp/tests/Facebook.CSSLayout/CSSLayoutAlignSelfTest.cs deleted file mode 100644 index ba34aaa8..00000000 --- a/csharp/tests/Facebook.CSSLayout/CSSLayoutAlignSelfTest.cs +++ /dev/null @@ -1,197 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
- -
-
-
- -
-
-
- -
-
-
- * - */ - -using System; -using NUnit.Framework; - -namespace Facebook.CSSLayout -{ - [TestFixture] - public class CSSLayoutAlignSelfTest - { - [Test] - public void Test_align_self_center() - { - CSSNode root = new CSSNode(); - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.AlignSelf = CSSAlign.Center; - root_child0.StyleWidth = 10; - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(45, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(45, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - } - - [Test] - public void Test_align_self_flex_end() - { - CSSNode root = new CSSNode(); - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.AlignSelf = CSSAlign.FlexEnd; - root_child0.StyleWidth = 10; - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(90, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - } - - [Test] - public void Test_align_self_flex_start() - { - CSSNode root = new CSSNode(); - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.AlignSelf = CSSAlign.FlexStart; - root_child0.StyleWidth = 10; - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(90, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - } - - [Test] - public void Test_align_self_flex_end_override_flex_start() - { - CSSNode root = new CSSNode(); - root.AlignItems = CSSAlign.FlexStart; - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.AlignSelf = CSSAlign.FlexEnd; - root_child0.StyleWidth = 10; - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(90, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - } - - } -} diff --git a/csharp/tests/Facebook.CSSLayout/CSSLayoutBorderTest.cs b/csharp/tests/Facebook.CSSLayout/CSSLayoutBorderTest.cs deleted file mode 100644 index 2fb8edea..00000000 --- a/csharp/tests/Facebook.CSSLayout/CSSLayoutBorderTest.cs +++ /dev/null @@ -1,234 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- * - */ - -using System; -using NUnit.Framework; - -namespace Facebook.CSSLayout -{ - [TestFixture] - public class CSSLayoutBorderTest - { - [Test] - public void Test_border_no_size() - { - CSSNode root = new CSSNode(); - root.SetBorder(CSSEdge.Left, 10); - root.SetBorder(CSSEdge.Top, 10); - root.SetBorder(CSSEdge.Right, 10); - root.SetBorder(CSSEdge.Bottom, 10); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(20, root.LayoutWidth); - Assert.AreEqual(20, root.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(20, root.LayoutWidth); - Assert.AreEqual(20, root.LayoutHeight); - } - - [Test] - public void Test_border_container_match_child() - { - CSSNode root = new CSSNode(); - root.SetBorder(CSSEdge.Left, 10); - root.SetBorder(CSSEdge.Top, 10); - root.SetBorder(CSSEdge.Right, 10); - root.SetBorder(CSSEdge.Bottom, 10); - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleWidth = 10; - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(30, root.LayoutWidth); - Assert.AreEqual(30, root.LayoutHeight); - - Assert.AreEqual(10, root_child0.LayoutX); - Assert.AreEqual(10, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(30, root.LayoutWidth); - Assert.AreEqual(30, root.LayoutHeight); - - Assert.AreEqual(10, root_child0.LayoutX); - Assert.AreEqual(10, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - } - - [Test] - public void Test_border_flex_child() - { - CSSNode root = new CSSNode(); - root.SetBorder(CSSEdge.Left, 10); - root.SetBorder(CSSEdge.Top, 10); - root.SetBorder(CSSEdge.Right, 10); - root.SetBorder(CSSEdge.Bottom, 10); - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.FlexGrow = 1; - root_child0.StyleWidth = 10; - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(10, root_child0.LayoutX); - Assert.AreEqual(10, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(80, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(80, root_child0.LayoutX); - Assert.AreEqual(10, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(80, root_child0.LayoutHeight); - } - - [Test] - public void Test_border_stretch_child() - { - CSSNode root = new CSSNode(); - root.SetBorder(CSSEdge.Left, 10); - root.SetBorder(CSSEdge.Top, 10); - root.SetBorder(CSSEdge.Right, 10); - root.SetBorder(CSSEdge.Bottom, 10); - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(10, root_child0.LayoutX); - Assert.AreEqual(10, root_child0.LayoutY); - Assert.AreEqual(80, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(10, root_child0.LayoutX); - Assert.AreEqual(10, root_child0.LayoutY); - Assert.AreEqual(80, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - } - - [Test] - public void Test_border_center_child() - { - CSSNode root = new CSSNode(); - root.JustifyContent = CSSJustify.Center; - root.AlignItems = CSSAlign.Center; - root.SetBorder(CSSEdge.Start, 10); - root.SetBorder(CSSEdge.End, 20); - root.SetBorder(CSSEdge.Bottom, 20); - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleWidth = 10; - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(40, root_child0.LayoutX); - Assert.AreEqual(35, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(50, root_child0.LayoutX); - Assert.AreEqual(35, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - } - - } -} diff --git a/csharp/tests/Facebook.CSSLayout/CSSLayoutFlexDirectionTest.cs b/csharp/tests/Facebook.CSSLayout/CSSLayoutFlexDirectionTest.cs deleted file mode 100644 index 6b4a4dc1..00000000 --- a/csharp/tests/Facebook.CSSLayout/CSSLayoutFlexDirectionTest.cs +++ /dev/null @@ -1,452 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- * - */ - -using System; -using NUnit.Framework; - -namespace Facebook.CSSLayout -{ - [TestFixture] - public class CSSLayoutFlexDirectionTest - { - [Test] - public void Test_flex_direction_column_no_height() - { - CSSNode root = new CSSNode(); - root.StyleWidth = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.StyleHeight = 10; - root.Insert(1, root_child1); - - CSSNode root_child2 = new CSSNode(); - root_child2.StyleHeight = 10; - root.Insert(2, root_child2); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(30, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(100, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(10, root_child1.LayoutY); - Assert.AreEqual(100, root_child1.LayoutWidth); - Assert.AreEqual(10, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(20, root_child2.LayoutY); - Assert.AreEqual(100, root_child2.LayoutWidth); - Assert.AreEqual(10, root_child2.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(30, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(100, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(10, root_child1.LayoutY); - Assert.AreEqual(100, root_child1.LayoutWidth); - Assert.AreEqual(10, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(20, root_child2.LayoutY); - Assert.AreEqual(100, root_child2.LayoutWidth); - Assert.AreEqual(10, root_child2.LayoutHeight); - } - - [Test] - public void Test_flex_direction_row_no_width() - { - CSSNode root = new CSSNode(); - root.FlexDirection = CSSFlexDirection.Row; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleWidth = 10; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.StyleWidth = 10; - root.Insert(1, root_child1); - - CSSNode root_child2 = new CSSNode(); - root_child2.StyleWidth = 10; - root.Insert(2, root_child2); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(30, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(100, root_child0.LayoutHeight); - - Assert.AreEqual(10, root_child1.LayoutX); - Assert.AreEqual(0, root_child1.LayoutY); - Assert.AreEqual(10, root_child1.LayoutWidth); - Assert.AreEqual(100, root_child1.LayoutHeight); - - Assert.AreEqual(20, root_child2.LayoutX); - Assert.AreEqual(0, root_child2.LayoutY); - Assert.AreEqual(10, root_child2.LayoutWidth); - Assert.AreEqual(100, root_child2.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(30, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(20, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(100, root_child0.LayoutHeight); - - Assert.AreEqual(10, root_child1.LayoutX); - Assert.AreEqual(0, root_child1.LayoutY); - Assert.AreEqual(10, root_child1.LayoutWidth); - Assert.AreEqual(100, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(0, root_child2.LayoutY); - Assert.AreEqual(10, root_child2.LayoutWidth); - Assert.AreEqual(100, root_child2.LayoutHeight); - } - - [Test] - public void Test_flex_direction_column() - { - CSSNode root = new CSSNode(); - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.StyleHeight = 10; - root.Insert(1, root_child1); - - CSSNode root_child2 = new CSSNode(); - root_child2.StyleHeight = 10; - root.Insert(2, root_child2); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(100, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(10, root_child1.LayoutY); - Assert.AreEqual(100, root_child1.LayoutWidth); - Assert.AreEqual(10, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(20, root_child2.LayoutY); - Assert.AreEqual(100, root_child2.LayoutWidth); - Assert.AreEqual(10, root_child2.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(100, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(10, root_child1.LayoutY); - Assert.AreEqual(100, root_child1.LayoutWidth); - Assert.AreEqual(10, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(20, root_child2.LayoutY); - Assert.AreEqual(100, root_child2.LayoutWidth); - Assert.AreEqual(10, root_child2.LayoutHeight); - } - - [Test] - public void Test_flex_direction_row() - { - CSSNode root = new CSSNode(); - root.FlexDirection = CSSFlexDirection.Row; - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleWidth = 10; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.StyleWidth = 10; - root.Insert(1, root_child1); - - CSSNode root_child2 = new CSSNode(); - root_child2.StyleWidth = 10; - root.Insert(2, root_child2); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(100, root_child0.LayoutHeight); - - Assert.AreEqual(10, root_child1.LayoutX); - Assert.AreEqual(0, root_child1.LayoutY); - Assert.AreEqual(10, root_child1.LayoutWidth); - Assert.AreEqual(100, root_child1.LayoutHeight); - - Assert.AreEqual(20, root_child2.LayoutX); - Assert.AreEqual(0, root_child2.LayoutY); - Assert.AreEqual(10, root_child2.LayoutWidth); - Assert.AreEqual(100, root_child2.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(90, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(100, root_child0.LayoutHeight); - - Assert.AreEqual(80, root_child1.LayoutX); - Assert.AreEqual(0, root_child1.LayoutY); - Assert.AreEqual(10, root_child1.LayoutWidth); - Assert.AreEqual(100, root_child1.LayoutHeight); - - Assert.AreEqual(70, root_child2.LayoutX); - Assert.AreEqual(0, root_child2.LayoutY); - Assert.AreEqual(10, root_child2.LayoutWidth); - Assert.AreEqual(100, root_child2.LayoutHeight); - } - - [Test] - public void Test_flex_direction_column_reverse() - { - CSSNode root = new CSSNode(); - root.FlexDirection = CSSFlexDirection.ColumnReverse; - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.StyleHeight = 10; - root.Insert(1, root_child1); - - CSSNode root_child2 = new CSSNode(); - root_child2.StyleHeight = 10; - root.Insert(2, root_child2); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(90, root_child0.LayoutY); - Assert.AreEqual(100, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(80, root_child1.LayoutY); - Assert.AreEqual(100, root_child1.LayoutWidth); - Assert.AreEqual(10, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(70, root_child2.LayoutY); - Assert.AreEqual(100, root_child2.LayoutWidth); - Assert.AreEqual(10, root_child2.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(90, root_child0.LayoutY); - Assert.AreEqual(100, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(80, root_child1.LayoutY); - Assert.AreEqual(100, root_child1.LayoutWidth); - Assert.AreEqual(10, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(70, root_child2.LayoutY); - Assert.AreEqual(100, root_child2.LayoutWidth); - Assert.AreEqual(10, root_child2.LayoutHeight); - } - - [Test] - public void Test_flex_direction_row_reverse() - { - CSSNode root = new CSSNode(); - root.FlexDirection = CSSFlexDirection.RowReverse; - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleWidth = 10; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.StyleWidth = 10; - root.Insert(1, root_child1); - - CSSNode root_child2 = new CSSNode(); - root_child2.StyleWidth = 10; - root.Insert(2, root_child2); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(90, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(100, root_child0.LayoutHeight); - - Assert.AreEqual(80, root_child1.LayoutX); - Assert.AreEqual(0, root_child1.LayoutY); - Assert.AreEqual(10, root_child1.LayoutWidth); - Assert.AreEqual(100, root_child1.LayoutHeight); - - Assert.AreEqual(70, root_child2.LayoutX); - Assert.AreEqual(0, root_child2.LayoutY); - Assert.AreEqual(10, root_child2.LayoutWidth); - Assert.AreEqual(100, root_child2.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(100, root_child0.LayoutHeight); - - Assert.AreEqual(10, root_child1.LayoutX); - Assert.AreEqual(0, root_child1.LayoutY); - Assert.AreEqual(10, root_child1.LayoutWidth); - Assert.AreEqual(100, root_child1.LayoutHeight); - - Assert.AreEqual(20, root_child2.LayoutX); - Assert.AreEqual(0, root_child2.LayoutY); - Assert.AreEqual(10, root_child2.LayoutWidth); - Assert.AreEqual(100, root_child2.LayoutHeight); - } - - } -} diff --git a/csharp/tests/Facebook.CSSLayout/CSSLayoutFlexTest.cs b/csharp/tests/Facebook.CSSLayout/CSSLayoutFlexTest.cs deleted file mode 100644 index 90c99330..00000000 --- a/csharp/tests/Facebook.CSSLayout/CSSLayoutFlexTest.cs +++ /dev/null @@ -1,403 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
-
- -
-
-
-
- -
-
-
-
- -
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- * - */ - -using System; -using NUnit.Framework; - -namespace Facebook.CSSLayout -{ - [TestFixture] - public class CSSLayoutFlexTest - { - [Test] - public void Test_flex_basis_flex_grow_column() - { - CSSNode root = new CSSNode(); - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.FlexGrow = 1; - root_child0.FlexBasis = 50; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.FlexGrow = 1; - root.Insert(1, root_child1); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(100, root_child0.LayoutWidth); - Assert.AreEqual(75, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(75, root_child1.LayoutY); - Assert.AreEqual(100, root_child1.LayoutWidth); - Assert.AreEqual(25, root_child1.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(100, root_child0.LayoutWidth); - Assert.AreEqual(75, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(75, root_child1.LayoutY); - Assert.AreEqual(100, root_child1.LayoutWidth); - Assert.AreEqual(25, root_child1.LayoutHeight); - } - - [Test] - public void Test_flex_basis_flex_grow_row() - { - CSSNode root = new CSSNode(); - root.FlexDirection = CSSFlexDirection.Row; - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.FlexGrow = 1; - root_child0.FlexBasis = 50; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.FlexGrow = 1; - root.Insert(1, root_child1); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(75, root_child0.LayoutWidth); - Assert.AreEqual(100, root_child0.LayoutHeight); - - Assert.AreEqual(75, root_child1.LayoutX); - Assert.AreEqual(0, root_child1.LayoutY); - Assert.AreEqual(25, root_child1.LayoutWidth); - Assert.AreEqual(100, root_child1.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(25, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(75, root_child0.LayoutWidth); - Assert.AreEqual(100, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(0, root_child1.LayoutY); - Assert.AreEqual(25, root_child1.LayoutWidth); - Assert.AreEqual(100, root_child1.LayoutHeight); - } - - [Test] - public void Test_flex_basis_flex_shrink_column() - { - CSSNode root = new CSSNode(); - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.FlexShrink = 1; - root_child0.FlexBasis = 100; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.FlexBasis = 50; - root.Insert(1, root_child1); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(100, root_child0.LayoutWidth); - Assert.AreEqual(50, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(50, root_child1.LayoutY); - Assert.AreEqual(100, root_child1.LayoutWidth); - Assert.AreEqual(50, root_child1.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(100, root_child0.LayoutWidth); - Assert.AreEqual(50, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(50, root_child1.LayoutY); - Assert.AreEqual(100, root_child1.LayoutWidth); - Assert.AreEqual(50, root_child1.LayoutHeight); - } - - [Test] - public void Test_flex_basis_flex_shrink_row() - { - CSSNode root = new CSSNode(); - root.FlexDirection = CSSFlexDirection.Row; - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.FlexShrink = 1; - root_child0.FlexBasis = 100; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.FlexBasis = 50; - root.Insert(1, root_child1); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(50, root_child0.LayoutWidth); - Assert.AreEqual(100, root_child0.LayoutHeight); - - Assert.AreEqual(50, root_child1.LayoutX); - Assert.AreEqual(0, root_child1.LayoutY); - Assert.AreEqual(50, root_child1.LayoutWidth); - Assert.AreEqual(100, root_child1.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(50, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(50, root_child0.LayoutWidth); - Assert.AreEqual(100, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(0, root_child1.LayoutY); - Assert.AreEqual(50, root_child1.LayoutWidth); - Assert.AreEqual(100, root_child1.LayoutHeight); - } - - [Test] - public void Test_flex_shrink_to_zero() - { - CSSNode root = new CSSNode(); - root.StyleHeight = 75; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleWidth = 50; - root_child0.StyleHeight = 50; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.FlexShrink = 1; - root_child1.StyleWidth = 50; - root_child1.StyleHeight = 50; - root.Insert(1, root_child1); - - CSSNode root_child2 = new CSSNode(); - root_child2.StyleWidth = 50; - root_child2.StyleHeight = 50; - root.Insert(2, root_child2); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(50, root.LayoutWidth); - Assert.AreEqual(75, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(50, root_child0.LayoutWidth); - Assert.AreEqual(50, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(50, root_child1.LayoutY); - Assert.AreEqual(50, root_child1.LayoutWidth); - Assert.AreEqual(0, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(50, root_child2.LayoutY); - Assert.AreEqual(50, root_child2.LayoutWidth); - Assert.AreEqual(50, root_child2.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(50, root.LayoutWidth); - Assert.AreEqual(75, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(50, root_child0.LayoutWidth); - Assert.AreEqual(50, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(50, root_child1.LayoutY); - Assert.AreEqual(50, root_child1.LayoutWidth); - Assert.AreEqual(0, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(50, root_child2.LayoutY); - Assert.AreEqual(50, root_child2.LayoutWidth); - Assert.AreEqual(50, root_child2.LayoutHeight); - } - - [Test] - public void Test_flex_basis_overrides_main_size() - { - CSSNode root = new CSSNode(); - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.FlexGrow = 1; - root_child0.FlexBasis = 50; - root_child0.StyleHeight = 20; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.FlexGrow = 1; - root_child1.StyleHeight = 10; - root.Insert(1, root_child1); - - CSSNode root_child2 = new CSSNode(); - root_child2.FlexGrow = 1; - root_child2.StyleHeight = 10; - root.Insert(2, root_child2); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(100, root_child0.LayoutWidth); - Assert.AreEqual(60, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(60, root_child1.LayoutY); - Assert.AreEqual(100, root_child1.LayoutWidth); - Assert.AreEqual(20, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(80, root_child2.LayoutY); - Assert.AreEqual(100, root_child2.LayoutWidth); - Assert.AreEqual(20, root_child2.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(100, root_child0.LayoutWidth); - Assert.AreEqual(60, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(60, root_child1.LayoutY); - Assert.AreEqual(100, root_child1.LayoutWidth); - Assert.AreEqual(20, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(80, root_child2.LayoutY); - Assert.AreEqual(100, root_child2.LayoutWidth); - Assert.AreEqual(20, root_child2.LayoutHeight); - } - - } -} diff --git a/csharp/tests/Facebook.CSSLayout/CSSLayoutFlexWrapTest.cs b/csharp/tests/Facebook.CSSLayout/CSSLayoutFlexWrapTest.cs deleted file mode 100644 index 2a0b3f8c..00000000 --- a/csharp/tests/Facebook.CSSLayout/CSSLayoutFlexWrapTest.cs +++ /dev/null @@ -1,389 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- * - */ - -using System; -using NUnit.Framework; - -namespace Facebook.CSSLayout -{ - [TestFixture] - public class CSSLayoutFlexWrapTest - { - [Test] - public void Test_wrap_column() - { - CSSNode root = new CSSNode(); - root.Wrap = CSSWrap.Wrap; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleWidth = 30; - root_child0.StyleHeight = 30; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.StyleWidth = 30; - root_child1.StyleHeight = 30; - root.Insert(1, root_child1); - - CSSNode root_child2 = new CSSNode(); - root_child2.StyleWidth = 30; - root_child2.StyleHeight = 30; - root.Insert(2, root_child2); - - CSSNode root_child3 = new CSSNode(); - root_child3.StyleWidth = 30; - root_child3.StyleHeight = 30; - root.Insert(3, root_child3); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(60, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(30, root_child0.LayoutWidth); - Assert.AreEqual(30, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(30, root_child1.LayoutY); - Assert.AreEqual(30, root_child1.LayoutWidth); - Assert.AreEqual(30, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(60, root_child2.LayoutY); - Assert.AreEqual(30, root_child2.LayoutWidth); - Assert.AreEqual(30, root_child2.LayoutHeight); - - Assert.AreEqual(30, root_child3.LayoutX); - Assert.AreEqual(0, root_child3.LayoutY); - Assert.AreEqual(30, root_child3.LayoutWidth); - Assert.AreEqual(30, root_child3.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(60, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(30, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(30, root_child0.LayoutWidth); - Assert.AreEqual(30, root_child0.LayoutHeight); - - Assert.AreEqual(30, root_child1.LayoutX); - Assert.AreEqual(30, root_child1.LayoutY); - Assert.AreEqual(30, root_child1.LayoutWidth); - Assert.AreEqual(30, root_child1.LayoutHeight); - - Assert.AreEqual(30, root_child2.LayoutX); - Assert.AreEqual(60, root_child2.LayoutY); - Assert.AreEqual(30, root_child2.LayoutWidth); - Assert.AreEqual(30, root_child2.LayoutHeight); - - Assert.AreEqual(0, root_child3.LayoutX); - Assert.AreEqual(0, root_child3.LayoutY); - Assert.AreEqual(30, root_child3.LayoutWidth); - Assert.AreEqual(30, root_child3.LayoutHeight); - } - - [Test] - public void Test_wrap_row() - { - CSSNode root = new CSSNode(); - root.FlexDirection = CSSFlexDirection.Row; - root.Wrap = CSSWrap.Wrap; - root.StyleWidth = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleWidth = 30; - root_child0.StyleHeight = 30; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.StyleWidth = 30; - root_child1.StyleHeight = 30; - root.Insert(1, root_child1); - - CSSNode root_child2 = new CSSNode(); - root_child2.StyleWidth = 30; - root_child2.StyleHeight = 30; - root.Insert(2, root_child2); - - CSSNode root_child3 = new CSSNode(); - root_child3.StyleWidth = 30; - root_child3.StyleHeight = 30; - root.Insert(3, root_child3); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(60, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(30, root_child0.LayoutWidth); - Assert.AreEqual(30, root_child0.LayoutHeight); - - Assert.AreEqual(30, root_child1.LayoutX); - Assert.AreEqual(0, root_child1.LayoutY); - Assert.AreEqual(30, root_child1.LayoutWidth); - Assert.AreEqual(30, root_child1.LayoutHeight); - - Assert.AreEqual(60, root_child2.LayoutX); - Assert.AreEqual(0, root_child2.LayoutY); - Assert.AreEqual(30, root_child2.LayoutWidth); - Assert.AreEqual(30, root_child2.LayoutHeight); - - Assert.AreEqual(0, root_child3.LayoutX); - Assert.AreEqual(30, root_child3.LayoutY); - Assert.AreEqual(30, root_child3.LayoutWidth); - Assert.AreEqual(30, root_child3.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(60, root.LayoutHeight); - - Assert.AreEqual(70, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(30, root_child0.LayoutWidth); - Assert.AreEqual(30, root_child0.LayoutHeight); - - Assert.AreEqual(40, root_child1.LayoutX); - Assert.AreEqual(0, root_child1.LayoutY); - Assert.AreEqual(30, root_child1.LayoutWidth); - Assert.AreEqual(30, root_child1.LayoutHeight); - - Assert.AreEqual(10, root_child2.LayoutX); - Assert.AreEqual(0, root_child2.LayoutY); - Assert.AreEqual(30, root_child2.LayoutWidth); - Assert.AreEqual(30, root_child2.LayoutHeight); - - Assert.AreEqual(70, root_child3.LayoutX); - Assert.AreEqual(30, root_child3.LayoutY); - Assert.AreEqual(30, root_child3.LayoutWidth); - Assert.AreEqual(30, root_child3.LayoutHeight); - } - - [Test] - public void Test_wrap_row_align_items_flex_end() - { - CSSNode root = new CSSNode(); - root.FlexDirection = CSSFlexDirection.Row; - root.AlignItems = CSSAlign.FlexEnd; - root.Wrap = CSSWrap.Wrap; - root.StyleWidth = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleWidth = 30; - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.StyleWidth = 30; - root_child1.StyleHeight = 20; - root.Insert(1, root_child1); - - CSSNode root_child2 = new CSSNode(); - root_child2.StyleWidth = 30; - root_child2.StyleHeight = 30; - root.Insert(2, root_child2); - - CSSNode root_child3 = new CSSNode(); - root_child3.StyleWidth = 30; - root_child3.StyleHeight = 30; - root.Insert(3, root_child3); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(60, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(20, root_child0.LayoutY); - Assert.AreEqual(30, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - Assert.AreEqual(30, root_child1.LayoutX); - Assert.AreEqual(10, root_child1.LayoutY); - Assert.AreEqual(30, root_child1.LayoutWidth); - Assert.AreEqual(20, root_child1.LayoutHeight); - - Assert.AreEqual(60, root_child2.LayoutX); - Assert.AreEqual(0, root_child2.LayoutY); - Assert.AreEqual(30, root_child2.LayoutWidth); - Assert.AreEqual(30, root_child2.LayoutHeight); - - Assert.AreEqual(0, root_child3.LayoutX); - Assert.AreEqual(30, root_child3.LayoutY); - Assert.AreEqual(30, root_child3.LayoutWidth); - Assert.AreEqual(30, root_child3.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(60, root.LayoutHeight); - - Assert.AreEqual(70, root_child0.LayoutX); - Assert.AreEqual(20, root_child0.LayoutY); - Assert.AreEqual(30, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - Assert.AreEqual(40, root_child1.LayoutX); - Assert.AreEqual(10, root_child1.LayoutY); - Assert.AreEqual(30, root_child1.LayoutWidth); - Assert.AreEqual(20, root_child1.LayoutHeight); - - Assert.AreEqual(10, root_child2.LayoutX); - Assert.AreEqual(0, root_child2.LayoutY); - Assert.AreEqual(30, root_child2.LayoutWidth); - Assert.AreEqual(30, root_child2.LayoutHeight); - - Assert.AreEqual(70, root_child3.LayoutX); - Assert.AreEqual(30, root_child3.LayoutY); - Assert.AreEqual(30, root_child3.LayoutWidth); - Assert.AreEqual(30, root_child3.LayoutHeight); - } - - [Test] - public void Test_wrap_row_align_items_center() - { - CSSNode root = new CSSNode(); - root.FlexDirection = CSSFlexDirection.Row; - root.AlignItems = CSSAlign.Center; - root.Wrap = CSSWrap.Wrap; - root.StyleWidth = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleWidth = 30; - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.StyleWidth = 30; - root_child1.StyleHeight = 20; - root.Insert(1, root_child1); - - CSSNode root_child2 = new CSSNode(); - root_child2.StyleWidth = 30; - root_child2.StyleHeight = 30; - root.Insert(2, root_child2); - - CSSNode root_child3 = new CSSNode(); - root_child3.StyleWidth = 30; - root_child3.StyleHeight = 30; - root.Insert(3, root_child3); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(60, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(10, root_child0.LayoutY); - Assert.AreEqual(30, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - Assert.AreEqual(30, root_child1.LayoutX); - Assert.AreEqual(5, root_child1.LayoutY); - Assert.AreEqual(30, root_child1.LayoutWidth); - Assert.AreEqual(20, root_child1.LayoutHeight); - - Assert.AreEqual(60, root_child2.LayoutX); - Assert.AreEqual(0, root_child2.LayoutY); - Assert.AreEqual(30, root_child2.LayoutWidth); - Assert.AreEqual(30, root_child2.LayoutHeight); - - Assert.AreEqual(0, root_child3.LayoutX); - Assert.AreEqual(30, root_child3.LayoutY); - Assert.AreEqual(30, root_child3.LayoutWidth); - Assert.AreEqual(30, root_child3.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(60, root.LayoutHeight); - - Assert.AreEqual(70, root_child0.LayoutX); - Assert.AreEqual(10, root_child0.LayoutY); - Assert.AreEqual(30, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - Assert.AreEqual(40, root_child1.LayoutX); - Assert.AreEqual(5, root_child1.LayoutY); - Assert.AreEqual(30, root_child1.LayoutWidth); - Assert.AreEqual(20, root_child1.LayoutHeight); - - Assert.AreEqual(10, root_child2.LayoutX); - Assert.AreEqual(0, root_child2.LayoutY); - Assert.AreEqual(30, root_child2.LayoutWidth); - Assert.AreEqual(30, root_child2.LayoutHeight); - - Assert.AreEqual(70, root_child3.LayoutX); - Assert.AreEqual(30, root_child3.LayoutY); - Assert.AreEqual(30, root_child3.LayoutWidth); - Assert.AreEqual(30, root_child3.LayoutHeight); - } - - } -} diff --git a/csharp/tests/Facebook.CSSLayout/CSSLayoutJustifyContentTest.cs b/csharp/tests/Facebook.CSSLayout/CSSLayoutJustifyContentTest.cs deleted file mode 100644 index b1368e8e..00000000 --- a/csharp/tests/Facebook.CSSLayout/CSSLayoutJustifyContentTest.cs +++ /dev/null @@ -1,746 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- * - */ - -using System; -using NUnit.Framework; - -namespace Facebook.CSSLayout -{ - [TestFixture] - public class CSSLayoutJustifyContentTest - { - [Test] - public void Test_justify_content_row_flex_start() - { - CSSNode root = new CSSNode(); - root.FlexDirection = CSSFlexDirection.Row; - root.StyleWidth = 102; - root.StyleHeight = 102; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleWidth = 10; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.StyleWidth = 10; - root.Insert(1, root_child1); - - CSSNode root_child2 = new CSSNode(); - root_child2.StyleWidth = 10; - root.Insert(2, root_child2); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(102, root.LayoutWidth); - Assert.AreEqual(102, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(102, root_child0.LayoutHeight); - - Assert.AreEqual(10, root_child1.LayoutX); - Assert.AreEqual(0, root_child1.LayoutY); - Assert.AreEqual(10, root_child1.LayoutWidth); - Assert.AreEqual(102, root_child1.LayoutHeight); - - Assert.AreEqual(20, root_child2.LayoutX); - Assert.AreEqual(0, root_child2.LayoutY); - Assert.AreEqual(10, root_child2.LayoutWidth); - Assert.AreEqual(102, root_child2.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(102, root.LayoutWidth); - Assert.AreEqual(102, root.LayoutHeight); - - Assert.AreEqual(92, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(102, root_child0.LayoutHeight); - - Assert.AreEqual(82, root_child1.LayoutX); - Assert.AreEqual(0, root_child1.LayoutY); - Assert.AreEqual(10, root_child1.LayoutWidth); - Assert.AreEqual(102, root_child1.LayoutHeight); - - Assert.AreEqual(72, root_child2.LayoutX); - Assert.AreEqual(0, root_child2.LayoutY); - Assert.AreEqual(10, root_child2.LayoutWidth); - Assert.AreEqual(102, root_child2.LayoutHeight); - } - - [Test] - public void Test_justify_content_row_flex_end() - { - CSSNode root = new CSSNode(); - root.FlexDirection = CSSFlexDirection.Row; - root.JustifyContent = CSSJustify.FlexEnd; - root.StyleWidth = 102; - root.StyleHeight = 102; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleWidth = 10; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.StyleWidth = 10; - root.Insert(1, root_child1); - - CSSNode root_child2 = new CSSNode(); - root_child2.StyleWidth = 10; - root.Insert(2, root_child2); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(102, root.LayoutWidth); - Assert.AreEqual(102, root.LayoutHeight); - - Assert.AreEqual(72, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(102, root_child0.LayoutHeight); - - Assert.AreEqual(82, root_child1.LayoutX); - Assert.AreEqual(0, root_child1.LayoutY); - Assert.AreEqual(10, root_child1.LayoutWidth); - Assert.AreEqual(102, root_child1.LayoutHeight); - - Assert.AreEqual(92, root_child2.LayoutX); - Assert.AreEqual(0, root_child2.LayoutY); - Assert.AreEqual(10, root_child2.LayoutWidth); - Assert.AreEqual(102, root_child2.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(102, root.LayoutWidth); - Assert.AreEqual(102, root.LayoutHeight); - - Assert.AreEqual(20, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(102, root_child0.LayoutHeight); - - Assert.AreEqual(10, root_child1.LayoutX); - Assert.AreEqual(0, root_child1.LayoutY); - Assert.AreEqual(10, root_child1.LayoutWidth); - Assert.AreEqual(102, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(0, root_child2.LayoutY); - Assert.AreEqual(10, root_child2.LayoutWidth); - Assert.AreEqual(102, root_child2.LayoutHeight); - } - - [Test] - public void Test_justify_content_row_center() - { - CSSNode root = new CSSNode(); - root.FlexDirection = CSSFlexDirection.Row; - root.JustifyContent = CSSJustify.Center; - root.StyleWidth = 102; - root.StyleHeight = 102; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleWidth = 10; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.StyleWidth = 10; - root.Insert(1, root_child1); - - CSSNode root_child2 = new CSSNode(); - root_child2.StyleWidth = 10; - root.Insert(2, root_child2); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(102, root.LayoutWidth); - Assert.AreEqual(102, root.LayoutHeight); - - Assert.AreEqual(36, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(102, root_child0.LayoutHeight); - - Assert.AreEqual(46, root_child1.LayoutX); - Assert.AreEqual(0, root_child1.LayoutY); - Assert.AreEqual(10, root_child1.LayoutWidth); - Assert.AreEqual(102, root_child1.LayoutHeight); - - Assert.AreEqual(56, root_child2.LayoutX); - Assert.AreEqual(0, root_child2.LayoutY); - Assert.AreEqual(10, root_child2.LayoutWidth); - Assert.AreEqual(102, root_child2.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(102, root.LayoutWidth); - Assert.AreEqual(102, root.LayoutHeight); - - Assert.AreEqual(56, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(102, root_child0.LayoutHeight); - - Assert.AreEqual(46, root_child1.LayoutX); - Assert.AreEqual(0, root_child1.LayoutY); - Assert.AreEqual(10, root_child1.LayoutWidth); - Assert.AreEqual(102, root_child1.LayoutHeight); - - Assert.AreEqual(36, root_child2.LayoutX); - Assert.AreEqual(0, root_child2.LayoutY); - Assert.AreEqual(10, root_child2.LayoutWidth); - Assert.AreEqual(102, root_child2.LayoutHeight); - } - - [Test] - public void Test_justify_content_row_space_between() - { - CSSNode root = new CSSNode(); - root.FlexDirection = CSSFlexDirection.Row; - root.JustifyContent = CSSJustify.SpaceBetween; - root.StyleWidth = 102; - root.StyleHeight = 102; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleWidth = 10; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.StyleWidth = 10; - root.Insert(1, root_child1); - - CSSNode root_child2 = new CSSNode(); - root_child2.StyleWidth = 10; - root.Insert(2, root_child2); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(102, root.LayoutWidth); - Assert.AreEqual(102, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(102, root_child0.LayoutHeight); - - Assert.AreEqual(46, root_child1.LayoutX); - Assert.AreEqual(0, root_child1.LayoutY); - Assert.AreEqual(10, root_child1.LayoutWidth); - Assert.AreEqual(102, root_child1.LayoutHeight); - - Assert.AreEqual(92, root_child2.LayoutX); - Assert.AreEqual(0, root_child2.LayoutY); - Assert.AreEqual(10, root_child2.LayoutWidth); - Assert.AreEqual(102, root_child2.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(102, root.LayoutWidth); - Assert.AreEqual(102, root.LayoutHeight); - - Assert.AreEqual(92, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(102, root_child0.LayoutHeight); - - Assert.AreEqual(46, root_child1.LayoutX); - Assert.AreEqual(0, root_child1.LayoutY); - Assert.AreEqual(10, root_child1.LayoutWidth); - Assert.AreEqual(102, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(0, root_child2.LayoutY); - Assert.AreEqual(10, root_child2.LayoutWidth); - Assert.AreEqual(102, root_child2.LayoutHeight); - } - - [Test] - public void Test_justify_content_row_space_around() - { - CSSNode root = new CSSNode(); - root.FlexDirection = CSSFlexDirection.Row; - root.JustifyContent = CSSJustify.SpaceAround; - root.StyleWidth = 102; - root.StyleHeight = 102; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleWidth = 10; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.StyleWidth = 10; - root.Insert(1, root_child1); - - CSSNode root_child2 = new CSSNode(); - root_child2.StyleWidth = 10; - root.Insert(2, root_child2); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(102, root.LayoutWidth); - Assert.AreEqual(102, root.LayoutHeight); - - Assert.AreEqual(12, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(102, root_child0.LayoutHeight); - - Assert.AreEqual(46, root_child1.LayoutX); - Assert.AreEqual(0, root_child1.LayoutY); - Assert.AreEqual(10, root_child1.LayoutWidth); - Assert.AreEqual(102, root_child1.LayoutHeight); - - Assert.AreEqual(80, root_child2.LayoutX); - Assert.AreEqual(0, root_child2.LayoutY); - Assert.AreEqual(10, root_child2.LayoutWidth); - Assert.AreEqual(102, root_child2.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(102, root.LayoutWidth); - Assert.AreEqual(102, root.LayoutHeight); - - Assert.AreEqual(80, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(102, root_child0.LayoutHeight); - - Assert.AreEqual(46, root_child1.LayoutX); - Assert.AreEqual(0, root_child1.LayoutY); - Assert.AreEqual(10, root_child1.LayoutWidth); - Assert.AreEqual(102, root_child1.LayoutHeight); - - Assert.AreEqual(12, root_child2.LayoutX); - Assert.AreEqual(0, root_child2.LayoutY); - Assert.AreEqual(10, root_child2.LayoutWidth); - Assert.AreEqual(102, root_child2.LayoutHeight); - } - - [Test] - public void Test_justify_content_column_flex_start() - { - CSSNode root = new CSSNode(); - root.StyleWidth = 102; - root.StyleHeight = 102; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root.Insert(1, root_child1); - - CSSNode root_child2 = new CSSNode(); - root_child2.StyleHeight = 10; - root.Insert(2, root_child2); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(102, root.LayoutWidth); - Assert.AreEqual(102, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(102, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(10, root_child1.LayoutY); - Assert.AreEqual(102, root_child1.LayoutWidth); - Assert.AreEqual(0, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(10, root_child2.LayoutY); - Assert.AreEqual(102, root_child2.LayoutWidth); - Assert.AreEqual(10, root_child2.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(102, root.LayoutWidth); - Assert.AreEqual(102, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(102, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(10, root_child1.LayoutY); - Assert.AreEqual(102, root_child1.LayoutWidth); - Assert.AreEqual(0, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(10, root_child2.LayoutY); - Assert.AreEqual(102, root_child2.LayoutWidth); - Assert.AreEqual(10, root_child2.LayoutHeight); - } - - [Test] - public void Test_justify_content_column_flex_end() - { - CSSNode root = new CSSNode(); - root.JustifyContent = CSSJustify.FlexEnd; - root.StyleWidth = 102; - root.StyleHeight = 102; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.StyleHeight = 10; - root.Insert(1, root_child1); - - CSSNode root_child2 = new CSSNode(); - root_child2.StyleHeight = 10; - root.Insert(2, root_child2); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(102, root.LayoutWidth); - Assert.AreEqual(102, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(72, root_child0.LayoutY); - Assert.AreEqual(102, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(82, root_child1.LayoutY); - Assert.AreEqual(102, root_child1.LayoutWidth); - Assert.AreEqual(10, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(92, root_child2.LayoutY); - Assert.AreEqual(102, root_child2.LayoutWidth); - Assert.AreEqual(10, root_child2.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(102, root.LayoutWidth); - Assert.AreEqual(102, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(72, root_child0.LayoutY); - Assert.AreEqual(102, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(82, root_child1.LayoutY); - Assert.AreEqual(102, root_child1.LayoutWidth); - Assert.AreEqual(10, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(92, root_child2.LayoutY); - Assert.AreEqual(102, root_child2.LayoutWidth); - Assert.AreEqual(10, root_child2.LayoutHeight); - } - - [Test] - public void Test_justify_content_column_center() - { - CSSNode root = new CSSNode(); - root.JustifyContent = CSSJustify.Center; - root.StyleWidth = 102; - root.StyleHeight = 102; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.StyleHeight = 10; - root.Insert(1, root_child1); - - CSSNode root_child2 = new CSSNode(); - root_child2.StyleHeight = 10; - root.Insert(2, root_child2); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(102, root.LayoutWidth); - Assert.AreEqual(102, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(36, root_child0.LayoutY); - Assert.AreEqual(102, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(46, root_child1.LayoutY); - Assert.AreEqual(102, root_child1.LayoutWidth); - Assert.AreEqual(10, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(56, root_child2.LayoutY); - Assert.AreEqual(102, root_child2.LayoutWidth); - Assert.AreEqual(10, root_child2.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(102, root.LayoutWidth); - Assert.AreEqual(102, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(36, root_child0.LayoutY); - Assert.AreEqual(102, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(46, root_child1.LayoutY); - Assert.AreEqual(102, root_child1.LayoutWidth); - Assert.AreEqual(10, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(56, root_child2.LayoutY); - Assert.AreEqual(102, root_child2.LayoutWidth); - Assert.AreEqual(10, root_child2.LayoutHeight); - } - - [Test] - public void Test_justify_content_column_space_between() - { - CSSNode root = new CSSNode(); - root.JustifyContent = CSSJustify.SpaceBetween; - root.StyleWidth = 102; - root.StyleHeight = 102; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.StyleHeight = 10; - root.Insert(1, root_child1); - - CSSNode root_child2 = new CSSNode(); - root_child2.StyleHeight = 10; - root.Insert(2, root_child2); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(102, root.LayoutWidth); - Assert.AreEqual(102, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(102, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(46, root_child1.LayoutY); - Assert.AreEqual(102, root_child1.LayoutWidth); - Assert.AreEqual(10, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(92, root_child2.LayoutY); - Assert.AreEqual(102, root_child2.LayoutWidth); - Assert.AreEqual(10, root_child2.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(102, root.LayoutWidth); - Assert.AreEqual(102, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(102, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(46, root_child1.LayoutY); - Assert.AreEqual(102, root_child1.LayoutWidth); - Assert.AreEqual(10, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(92, root_child2.LayoutY); - Assert.AreEqual(102, root_child2.LayoutWidth); - Assert.AreEqual(10, root_child2.LayoutHeight); - } - - [Test] - public void Test_justify_content_column_space_around() - { - CSSNode root = new CSSNode(); - root.JustifyContent = CSSJustify.SpaceAround; - root.StyleWidth = 102; - root.StyleHeight = 102; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.StyleHeight = 10; - root.Insert(1, root_child1); - - CSSNode root_child2 = new CSSNode(); - root_child2.StyleHeight = 10; - root.Insert(2, root_child2); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(102, root.LayoutWidth); - Assert.AreEqual(102, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(12, root_child0.LayoutY); - Assert.AreEqual(102, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(46, root_child1.LayoutY); - Assert.AreEqual(102, root_child1.LayoutWidth); - Assert.AreEqual(10, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(80, root_child2.LayoutY); - Assert.AreEqual(102, root_child2.LayoutWidth); - Assert.AreEqual(10, root_child2.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(102, root.LayoutWidth); - Assert.AreEqual(102, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(12, root_child0.LayoutY); - Assert.AreEqual(102, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(46, root_child1.LayoutY); - Assert.AreEqual(102, root_child1.LayoutWidth); - Assert.AreEqual(10, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(80, root_child2.LayoutY); - Assert.AreEqual(102, root_child2.LayoutWidth); - Assert.AreEqual(10, root_child2.LayoutHeight); - } - - } -} diff --git a/csharp/tests/Facebook.CSSLayout/CSSLayoutMarginTest.cs b/csharp/tests/Facebook.CSSLayout/CSSLayoutMarginTest.cs deleted file mode 100644 index 7e7955ea..00000000 --- a/csharp/tests/Facebook.CSSLayout/CSSLayoutMarginTest.cs +++ /dev/null @@ -1,479 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
-
- -
-
-
-
- * - */ - -using System; -using NUnit.Framework; - -namespace Facebook.CSSLayout -{ - [TestFixture] - public class CSSLayoutMarginTest - { - [Test] - public void Test_margin_start() - { - CSSNode root = new CSSNode(); - root.FlexDirection = CSSFlexDirection.Row; - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.SetMargin(CSSEdge.Start, 10); - root_child0.StyleWidth = 10; - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(10, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(100, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(80, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(100, root_child0.LayoutHeight); - } - - [Test] - public void Test_margin_top() - { - CSSNode root = new CSSNode(); - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.SetMargin(CSSEdge.Top, 10); - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(10, root_child0.LayoutY); - Assert.AreEqual(100, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(10, root_child0.LayoutY); - Assert.AreEqual(100, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - } - - [Test] - public void Test_margin_end() - { - CSSNode root = new CSSNode(); - root.FlexDirection = CSSFlexDirection.Row; - root.JustifyContent = CSSJustify.FlexEnd; - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.SetMargin(CSSEdge.End, 10); - root_child0.StyleWidth = 10; - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(80, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(100, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(10, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(100, root_child0.LayoutHeight); - } - - [Test] - public void Test_margin_bottom() - { - CSSNode root = new CSSNode(); - root.JustifyContent = CSSJustify.FlexEnd; - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.SetMargin(CSSEdge.Bottom, 10); - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(80, root_child0.LayoutY); - Assert.AreEqual(100, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(80, root_child0.LayoutY); - Assert.AreEqual(100, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - } - - [Test] - public void Test_margin_and_flex_row() - { - CSSNode root = new CSSNode(); - root.FlexDirection = CSSFlexDirection.Row; - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.FlexGrow = 1; - root_child0.SetMargin(CSSEdge.Start, 10); - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(10, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(90, root_child0.LayoutWidth); - Assert.AreEqual(100, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(90, root_child0.LayoutWidth); - Assert.AreEqual(100, root_child0.LayoutHeight); - } - - [Test] - public void Test_margin_and_flex_column() - { - CSSNode root = new CSSNode(); - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.FlexGrow = 1; - root_child0.SetMargin(CSSEdge.Top, 10); - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(10, root_child0.LayoutY); - Assert.AreEqual(100, root_child0.LayoutWidth); - Assert.AreEqual(90, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(10, root_child0.LayoutY); - Assert.AreEqual(100, root_child0.LayoutWidth); - Assert.AreEqual(90, root_child0.LayoutHeight); - } - - [Test] - public void Test_margin_and_stretch_row() - { - CSSNode root = new CSSNode(); - root.FlexDirection = CSSFlexDirection.Row; - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.FlexGrow = 1; - root_child0.SetMargin(CSSEdge.Top, 10); - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(10, root_child0.LayoutY); - Assert.AreEqual(100, root_child0.LayoutWidth); - Assert.AreEqual(90, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(10, root_child0.LayoutY); - Assert.AreEqual(100, root_child0.LayoutWidth); - Assert.AreEqual(90, root_child0.LayoutHeight); - } - - [Test] - public void Test_margin_and_stretch_column() - { - CSSNode root = new CSSNode(); - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.FlexGrow = 1; - root_child0.SetMargin(CSSEdge.Start, 10); - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(10, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(90, root_child0.LayoutWidth); - Assert.AreEqual(100, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(90, root_child0.LayoutWidth); - Assert.AreEqual(100, root_child0.LayoutHeight); - } - - [Test] - public void Test_margin_with_sibling_row() - { - CSSNode root = new CSSNode(); - root.FlexDirection = CSSFlexDirection.Row; - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.FlexGrow = 1; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.FlexGrow = 1; - root.Insert(1, root_child1); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(50, root_child0.LayoutWidth); - Assert.AreEqual(100, root_child0.LayoutHeight); - - Assert.AreEqual(50, root_child1.LayoutX); - Assert.AreEqual(0, root_child1.LayoutY); - Assert.AreEqual(50, root_child1.LayoutWidth); - Assert.AreEqual(100, root_child1.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(50, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(50, root_child0.LayoutWidth); - Assert.AreEqual(100, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(0, root_child1.LayoutY); - Assert.AreEqual(50, root_child1.LayoutWidth); - Assert.AreEqual(100, root_child1.LayoutHeight); - } - - [Test] - public void Test_margin_with_sibling_column() - { - CSSNode root = new CSSNode(); - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.FlexGrow = 1; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.FlexGrow = 1; - root.Insert(1, root_child1); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(100, root_child0.LayoutWidth); - Assert.AreEqual(50, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(50, root_child1.LayoutY); - Assert.AreEqual(100, root_child1.LayoutWidth); - Assert.AreEqual(50, root_child1.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(100, root_child0.LayoutWidth); - Assert.AreEqual(50, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(50, root_child1.LayoutY); - Assert.AreEqual(100, root_child1.LayoutWidth); - Assert.AreEqual(50, root_child1.LayoutHeight); - } - - } -} diff --git a/csharp/tests/Facebook.CSSLayout/CSSLayoutMinMaxDimensionTest.cs b/csharp/tests/Facebook.CSSLayout/CSSLayoutMinMaxDimensionTest.cs deleted file mode 100644 index 73a2a84f..00000000 --- a/csharp/tests/Facebook.CSSLayout/CSSLayoutMinMaxDimensionTest.cs +++ /dev/null @@ -1,387 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
- -
-
-
- -
-
-
-
- -
-
-
-
- -
-
-
- -
-
-
- -
-
-
-
-
- * - */ - -using System; -using NUnit.Framework; - -namespace Facebook.CSSLayout -{ - [TestFixture] - public class CSSLayoutMinMaxDimensionTest - { - [Test] - public void Test_max_width() - { - CSSNode root = new CSSNode(); - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleMaxWidth = 50; - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(50, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(50, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(50, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - } - - [Test] - public void Test_max_height() - { - CSSNode root = new CSSNode(); - root.FlexDirection = CSSFlexDirection.Row; - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleWidth = 10; - root_child0.StyleMaxHeight = 50; - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(50, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(90, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(50, root_child0.LayoutHeight); - } - - [Test] - public void Test_min_height() - { - CSSNode root = new CSSNode(); - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.FlexGrow = 1; - root_child0.StyleMinHeight = 60; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.FlexGrow = 1; - root.Insert(1, root_child1); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(100, root_child0.LayoutWidth); - Assert.AreEqual(80, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(80, root_child1.LayoutY); - Assert.AreEqual(100, root_child1.LayoutWidth); - Assert.AreEqual(20, root_child1.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(100, root_child0.LayoutWidth); - Assert.AreEqual(80, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(80, root_child1.LayoutY); - Assert.AreEqual(100, root_child1.LayoutWidth); - Assert.AreEqual(20, root_child1.LayoutHeight); - } - - [Test] - public void Test_min_width() - { - CSSNode root = new CSSNode(); - root.FlexDirection = CSSFlexDirection.Row; - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.FlexGrow = 1; - root_child0.StyleMinWidth = 60; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.FlexGrow = 1; - root.Insert(1, root_child1); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(80, root_child0.LayoutWidth); - Assert.AreEqual(100, root_child0.LayoutHeight); - - Assert.AreEqual(80, root_child1.LayoutX); - Assert.AreEqual(0, root_child1.LayoutY); - Assert.AreEqual(20, root_child1.LayoutWidth); - Assert.AreEqual(100, root_child1.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(20, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(80, root_child0.LayoutWidth); - Assert.AreEqual(100, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(0, root_child1.LayoutY); - Assert.AreEqual(20, root_child1.LayoutWidth); - Assert.AreEqual(100, root_child1.LayoutHeight); - } - - [Test] - public void Test_justify_content_min_max() - { - CSSNode root = new CSSNode(); - root.JustifyContent = CSSJustify.Center; - root.StyleWidth = 100; - root.StyleMinHeight = 100; - root.StyleMaxHeight = 200; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleWidth = 60; - root_child0.StyleHeight = 60; - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(20, root_child0.LayoutY); - Assert.AreEqual(60, root_child0.LayoutWidth); - Assert.AreEqual(60, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(40, root_child0.LayoutX); - Assert.AreEqual(20, root_child0.LayoutY); - Assert.AreEqual(60, root_child0.LayoutWidth); - Assert.AreEqual(60, root_child0.LayoutHeight); - } - - [Test] - public void Test_align_items_min_max() - { - CSSNode root = new CSSNode(); - root.AlignItems = CSSAlign.Center; - root.StyleMinWidth = 100; - root.StyleMaxWidth = 200; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleWidth = 60; - root_child0.StyleHeight = 60; - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(20, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(60, root_child0.LayoutWidth); - Assert.AreEqual(60, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(20, root_child0.LayoutX); - Assert.AreEqual(0, root_child0.LayoutY); - Assert.AreEqual(60, root_child0.LayoutWidth); - Assert.AreEqual(60, root_child0.LayoutHeight); - } - - [Test] - public void Test_justify_content_overflow_min_max() - { - CSSNode root = new CSSNode(); - root.JustifyContent = CSSJustify.Center; - root.StyleMinHeight = 100; - root.StyleMaxHeight = 110; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleWidth = 50; - root_child0.StyleHeight = 50; - root.Insert(0, root_child0); - - CSSNode root_child1 = new CSSNode(); - root_child1.StyleWidth = 50; - root_child1.StyleHeight = 50; - root.Insert(1, root_child1); - - CSSNode root_child2 = new CSSNode(); - root_child2.StyleWidth = 50; - root_child2.StyleHeight = 50; - root.Insert(2, root_child2); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(50, root.LayoutWidth); - Assert.AreEqual(110, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(-20, root_child0.LayoutY); - Assert.AreEqual(50, root_child0.LayoutWidth); - Assert.AreEqual(50, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(30, root_child1.LayoutY); - Assert.AreEqual(50, root_child1.LayoutWidth); - Assert.AreEqual(50, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(80, root_child2.LayoutY); - Assert.AreEqual(50, root_child2.LayoutWidth); - Assert.AreEqual(50, root_child2.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(50, root.LayoutWidth); - Assert.AreEqual(110, root.LayoutHeight); - - Assert.AreEqual(0, root_child0.LayoutX); - Assert.AreEqual(-20, root_child0.LayoutY); - Assert.AreEqual(50, root_child0.LayoutWidth); - Assert.AreEqual(50, root_child0.LayoutHeight); - - Assert.AreEqual(0, root_child1.LayoutX); - Assert.AreEqual(30, root_child1.LayoutY); - Assert.AreEqual(50, root_child1.LayoutWidth); - Assert.AreEqual(50, root_child1.LayoutHeight); - - Assert.AreEqual(0, root_child2.LayoutX); - Assert.AreEqual(80, root_child2.LayoutY); - Assert.AreEqual(50, root_child2.LayoutWidth); - Assert.AreEqual(50, root_child2.LayoutHeight); - } - - } -} diff --git a/csharp/tests/Facebook.CSSLayout/CSSLayoutPaddingTest.cs b/csharp/tests/Facebook.CSSLayout/CSSLayoutPaddingTest.cs deleted file mode 100644 index 8ede76d2..00000000 --- a/csharp/tests/Facebook.CSSLayout/CSSLayoutPaddingTest.cs +++ /dev/null @@ -1,234 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- * - */ - -using System; -using NUnit.Framework; - -namespace Facebook.CSSLayout -{ - [TestFixture] - public class CSSLayoutPaddingTest - { - [Test] - public void Test_padding_no_size() - { - CSSNode root = new CSSNode(); - root.SetPadding(CSSEdge.Left, 10); - root.SetPadding(CSSEdge.Top, 10); - root.SetPadding(CSSEdge.Right, 10); - root.SetPadding(CSSEdge.Bottom, 10); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(20, root.LayoutWidth); - Assert.AreEqual(20, root.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(20, root.LayoutWidth); - Assert.AreEqual(20, root.LayoutHeight); - } - - [Test] - public void Test_padding_container_match_child() - { - CSSNode root = new CSSNode(); - root.SetPadding(CSSEdge.Left, 10); - root.SetPadding(CSSEdge.Top, 10); - root.SetPadding(CSSEdge.Right, 10); - root.SetPadding(CSSEdge.Bottom, 10); - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleWidth = 10; - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(30, root.LayoutWidth); - Assert.AreEqual(30, root.LayoutHeight); - - Assert.AreEqual(10, root_child0.LayoutX); - Assert.AreEqual(10, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(30, root.LayoutWidth); - Assert.AreEqual(30, root.LayoutHeight); - - Assert.AreEqual(10, root_child0.LayoutX); - Assert.AreEqual(10, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - } - - [Test] - public void Test_padding_flex_child() - { - CSSNode root = new CSSNode(); - root.SetPadding(CSSEdge.Left, 10); - root.SetPadding(CSSEdge.Top, 10); - root.SetPadding(CSSEdge.Right, 10); - root.SetPadding(CSSEdge.Bottom, 10); - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.FlexGrow = 1; - root_child0.StyleWidth = 10; - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(10, root_child0.LayoutX); - Assert.AreEqual(10, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(80, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(80, root_child0.LayoutX); - Assert.AreEqual(10, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(80, root_child0.LayoutHeight); - } - - [Test] - public void Test_padding_stretch_child() - { - CSSNode root = new CSSNode(); - root.SetPadding(CSSEdge.Left, 10); - root.SetPadding(CSSEdge.Top, 10); - root.SetPadding(CSSEdge.Right, 10); - root.SetPadding(CSSEdge.Bottom, 10); - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(10, root_child0.LayoutX); - Assert.AreEqual(10, root_child0.LayoutY); - Assert.AreEqual(80, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(10, root_child0.LayoutX); - Assert.AreEqual(10, root_child0.LayoutY); - Assert.AreEqual(80, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - } - - [Test] - public void Test_padding_center_child() - { - CSSNode root = new CSSNode(); - root.JustifyContent = CSSJustify.Center; - root.AlignItems = CSSAlign.Center; - root.SetPadding(CSSEdge.Start, 10); - root.SetPadding(CSSEdge.End, 20); - root.SetPadding(CSSEdge.Bottom, 20); - root.StyleWidth = 100; - root.StyleHeight = 100; - - CSSNode root_child0 = new CSSNode(); - root_child0.StyleWidth = 10; - root_child0.StyleHeight = 10; - root.Insert(0, root_child0); - root.StyleDirection = CSSDirection.LeftToRight; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(40, root_child0.LayoutX); - Assert.AreEqual(35, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - - root.StyleDirection = CSSDirection.RightToLeft; - root.CalculateLayout(); - - Assert.AreEqual(0, root.LayoutX); - Assert.AreEqual(0, root.LayoutY); - Assert.AreEqual(100, root.LayoutWidth); - Assert.AreEqual(100, root.LayoutHeight); - - Assert.AreEqual(50, root_child0.LayoutX); - Assert.AreEqual(35, root_child0.LayoutY); - Assert.AreEqual(10, root_child0.LayoutWidth); - Assert.AreEqual(10, root_child0.LayoutHeight); - } - - } -} diff --git a/csharp/tests/Facebook.Yoga/YGAbsolutePositionTest.cs b/csharp/tests/Facebook.Yoga/YGAbsolutePositionTest.cs new file mode 100644 index 00000000..c9d49cc0 --- /dev/null +++ b/csharp/tests/Facebook.Yoga/YGAbsolutePositionTest.cs @@ -0,0 +1,314 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGAbsolutePositionTest.html + +using System; +using NUnit.Framework; + +namespace Facebook.Yoga +{ + [TestFixture] + public class YGAbsolutePositionTest + { + [Test] + public void Test_absolute_layout_width_height_start_top() + { + YogaNode root = new YogaNode(); + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.PositionType = YogaPositionType.Absolute; + root_child0.SetPosition(YogaEdge.Start, 10f); + root_child0.SetPosition(YogaEdge.Top, 10f); + root_child0.Width = 10f; + root_child0.Height = 10f; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(10f, root_child0.LayoutX); + Assert.AreEqual(10f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(80f, root_child0.LayoutX); + Assert.AreEqual(10f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + } + + [Test] + public void Test_absolute_layout_width_height_end_bottom() + { + YogaNode root = new YogaNode(); + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.PositionType = YogaPositionType.Absolute; + root_child0.SetPosition(YogaEdge.End, 10f); + root_child0.SetPosition(YogaEdge.Bottom, 10f); + root_child0.Width = 10f; + root_child0.Height = 10f; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(80f, root_child0.LayoutX); + Assert.AreEqual(80f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(10f, root_child0.LayoutX); + Assert.AreEqual(80f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + } + + [Test] + public void Test_absolute_layout_start_top_end_bottom() + { + YogaNode root = new YogaNode(); + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.PositionType = YogaPositionType.Absolute; + root_child0.SetPosition(YogaEdge.Start, 10f); + root_child0.SetPosition(YogaEdge.Top, 10f); + root_child0.SetPosition(YogaEdge.End, 10f); + root_child0.SetPosition(YogaEdge.Bottom, 10f); + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(10f, root_child0.LayoutX); + Assert.AreEqual(10f, root_child0.LayoutY); + Assert.AreEqual(80f, root_child0.LayoutWidth); + Assert.AreEqual(80f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(10f, root_child0.LayoutX); + Assert.AreEqual(10f, root_child0.LayoutY); + Assert.AreEqual(80f, root_child0.LayoutWidth); + Assert.AreEqual(80f, root_child0.LayoutHeight); + } + + [Test] + public void Test_absolute_layout_width_height_start_top_end_bottom() + { + YogaNode root = new YogaNode(); + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.PositionType = YogaPositionType.Absolute; + root_child0.SetPosition(YogaEdge.Start, 10f); + root_child0.SetPosition(YogaEdge.Top, 10f); + root_child0.SetPosition(YogaEdge.End, 10f); + root_child0.SetPosition(YogaEdge.Bottom, 10f); + root_child0.Width = 10f; + root_child0.Height = 10f; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(10f, root_child0.LayoutX); + Assert.AreEqual(10f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(80f, root_child0.LayoutX); + Assert.AreEqual(10f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + } + + [Test] + public void Test_do_not_clamp_height_of_absolute_node_to_height_of_its_overflow_hidden_parent() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.Overflow = YogaOverflow.Hidden; + root.Width = 50f; + root.Height = 50f; + + YogaNode root_child0 = new YogaNode(); + root_child0.PositionType = YogaPositionType.Absolute; + root_child0.SetPosition(YogaEdge.Start, 0f); + root_child0.SetPosition(YogaEdge.Top, 0f); + root.Insert(0, root_child0); + + YogaNode root_child0_child0 = new YogaNode(); + root_child0_child0.Width = 100f; + root_child0_child0.Height = 100f; + root_child0.Insert(0, root_child0_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(50f, root.LayoutWidth); + Assert.AreEqual(50f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0.LayoutY); + Assert.AreEqual(100f, root_child0_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(50f, root.LayoutWidth); + Assert.AreEqual(50f, root.LayoutHeight); + + Assert.AreEqual(-50f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0.LayoutY); + Assert.AreEqual(100f, root_child0_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0_child0.LayoutHeight); + } + + [Test] + public void Test_absolute_layout_within_border() + { + YogaNode root = new YogaNode(); + root.SetMargin(YogaEdge.Left, 10f); + root.SetMargin(YogaEdge.Top, 10f); + root.SetMargin(YogaEdge.Right, 10f); + root.SetMargin(YogaEdge.Bottom, 10f); + root.SetPadding(YogaEdge.Left, 10f); + root.SetPadding(YogaEdge.Top, 10f); + root.SetPadding(YogaEdge.Right, 10f); + root.SetPadding(YogaEdge.Bottom, 10f); + root.SetBorder(YogaEdge.Left, 10f); + root.SetBorder(YogaEdge.Top, 10f); + root.SetBorder(YogaEdge.Right, 10f); + root.SetBorder(YogaEdge.Bottom, 10f); + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.PositionType = YogaPositionType.Absolute; + root_child0.SetPosition(YogaEdge.Left, 0f); + root_child0.SetPosition(YogaEdge.Top, 0f); + root_child0.Width = 50f; + root_child0.Height = 50f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.PositionType = YogaPositionType.Absolute; + root_child1.SetPosition(YogaEdge.Right, 0f); + root_child1.SetPosition(YogaEdge.Bottom, 0f); + root_child1.Width = 50f; + root_child1.Height = 50f; + root.Insert(1, root_child1); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(10f, root.LayoutX); + Assert.AreEqual(10f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(10f, root_child0.LayoutX); + Assert.AreEqual(10f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(50f, root_child0.LayoutHeight); + + Assert.AreEqual(40f, root_child1.LayoutX); + Assert.AreEqual(40f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(50f, root_child1.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(10f, root.LayoutX); + Assert.AreEqual(10f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(10f, root_child0.LayoutX); + Assert.AreEqual(10f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(50f, root_child0.LayoutHeight); + + Assert.AreEqual(40f, root_child1.LayoutX); + Assert.AreEqual(40f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(50f, root_child1.LayoutHeight); + } + + } +} diff --git a/csharp/tests/Facebook.Yoga/YGAlignContentTest.cs b/csharp/tests/Facebook.Yoga/YGAlignContentTest.cs new file mode 100644 index 00000000..598b1dd7 --- /dev/null +++ b/csharp/tests/Facebook.Yoga/YGAlignContentTest.cs @@ -0,0 +1,415 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGAlignContentTest.html + +using System; +using NUnit.Framework; + +namespace Facebook.Yoga +{ + [TestFixture] + public class YGAlignContentTest + { + [Test] + public void Test_align_content_flex_start() + { + YogaNode root = new YogaNode(); + root.Wrap = YogaWrap.Wrap; + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 50f; + root_child0.Height = 10f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Width = 50f; + root_child1.Height = 10f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 50f; + root_child2.Height = 10f; + root.Insert(2, root_child2); + + YogaNode root_child3 = new YogaNode(); + root_child3.Width = 50f; + root_child3.Height = 10f; + root.Insert(3, root_child3); + + YogaNode root_child4 = new YogaNode(); + root_child4.Width = 50f; + root_child4.Height = 10f; + root.Insert(4, root_child4); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(10f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(10f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(20f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(10f, root_child2.LayoutHeight); + + Assert.AreEqual(0f, root_child3.LayoutX); + Assert.AreEqual(30f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(10f, root_child3.LayoutHeight); + + Assert.AreEqual(0f, root_child4.LayoutX); + Assert.AreEqual(40f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(10f, root_child4.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(50f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(10f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(10f, root_child1.LayoutHeight); + + Assert.AreEqual(50f, root_child2.LayoutX); + Assert.AreEqual(20f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(10f, root_child2.LayoutHeight); + + Assert.AreEqual(50f, root_child3.LayoutX); + Assert.AreEqual(30f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(10f, root_child3.LayoutHeight); + + Assert.AreEqual(50f, root_child4.LayoutX); + Assert.AreEqual(40f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(10f, root_child4.LayoutHeight); + } + + [Test] + public void Test_align_content_flex_end() + { + YogaNode root = new YogaNode(); + root.AlignContent = YogaAlign.FlexEnd; + root.Wrap = YogaWrap.Wrap; + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 50f; + root_child0.Height = 10f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Width = 50f; + root_child1.Height = 10f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 50f; + root_child2.Height = 10f; + root.Insert(2, root_child2); + + YogaNode root_child3 = new YogaNode(); + root_child3.Width = 50f; + root_child3.Height = 10f; + root.Insert(3, root_child3); + + YogaNode root_child4 = new YogaNode(); + root_child4.Width = 50f; + root_child4.Height = 10f; + root.Insert(4, root_child4); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(10f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(10f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(20f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(10f, root_child2.LayoutHeight); + + Assert.AreEqual(0f, root_child3.LayoutX); + Assert.AreEqual(30f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(10f, root_child3.LayoutHeight); + + Assert.AreEqual(0f, root_child4.LayoutX); + Assert.AreEqual(40f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(10f, root_child4.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(50f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(10f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(10f, root_child1.LayoutHeight); + + Assert.AreEqual(50f, root_child2.LayoutX); + Assert.AreEqual(20f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(10f, root_child2.LayoutHeight); + + Assert.AreEqual(50f, root_child3.LayoutX); + Assert.AreEqual(30f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(10f, root_child3.LayoutHeight); + + Assert.AreEqual(50f, root_child4.LayoutX); + Assert.AreEqual(40f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(10f, root_child4.LayoutHeight); + } + + [Test] + public void Test_align_content_center() + { + YogaNode root = new YogaNode(); + root.AlignContent = YogaAlign.Center; + root.Wrap = YogaWrap.Wrap; + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 50f; + root_child0.Height = 10f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Width = 50f; + root_child1.Height = 10f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 50f; + root_child2.Height = 10f; + root.Insert(2, root_child2); + + YogaNode root_child3 = new YogaNode(); + root_child3.Width = 50f; + root_child3.Height = 10f; + root.Insert(3, root_child3); + + YogaNode root_child4 = new YogaNode(); + root_child4.Width = 50f; + root_child4.Height = 10f; + root.Insert(4, root_child4); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(10f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(10f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(20f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(10f, root_child2.LayoutHeight); + + Assert.AreEqual(0f, root_child3.LayoutX); + Assert.AreEqual(30f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(10f, root_child3.LayoutHeight); + + Assert.AreEqual(0f, root_child4.LayoutX); + Assert.AreEqual(40f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(10f, root_child4.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(50f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(10f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(10f, root_child1.LayoutHeight); + + Assert.AreEqual(50f, root_child2.LayoutX); + Assert.AreEqual(20f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(10f, root_child2.LayoutHeight); + + Assert.AreEqual(50f, root_child3.LayoutX); + Assert.AreEqual(30f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(10f, root_child3.LayoutHeight); + + Assert.AreEqual(50f, root_child4.LayoutX); + Assert.AreEqual(40f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(10f, root_child4.LayoutHeight); + } + + [Test] + public void Test_align_content_stretch() + { + YogaNode root = new YogaNode(); + root.AlignContent = YogaAlign.Stretch; + root.Wrap = YogaWrap.Wrap; + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 50f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Width = 50f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 50f; + root.Insert(2, root_child2); + + YogaNode root_child3 = new YogaNode(); + root_child3.Width = 50f; + root.Insert(3, root_child3); + + YogaNode root_child4 = new YogaNode(); + root_child4.Width = 50f; + root.Insert(4, root_child4); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(0f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(0f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(0f, root_child2.LayoutHeight); + + Assert.AreEqual(0f, root_child3.LayoutX); + Assert.AreEqual(0f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(0f, root_child3.LayoutHeight); + + Assert.AreEqual(0f, root_child4.LayoutX); + Assert.AreEqual(0f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(0f, root_child4.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(50f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(0f, root_child0.LayoutHeight); + + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(0f, root_child1.LayoutHeight); + + Assert.AreEqual(50f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(0f, root_child2.LayoutHeight); + + Assert.AreEqual(50f, root_child3.LayoutX); + Assert.AreEqual(0f, root_child3.LayoutY); + Assert.AreEqual(50f, root_child3.LayoutWidth); + Assert.AreEqual(0f, root_child3.LayoutHeight); + + Assert.AreEqual(50f, root_child4.LayoutX); + Assert.AreEqual(0f, root_child4.LayoutY); + Assert.AreEqual(50f, root_child4.LayoutWidth); + Assert.AreEqual(0f, root_child4.LayoutHeight); + } + + } +} diff --git a/csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs b/csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs new file mode 100644 index 00000000..33b4c0d2 --- /dev/null +++ b/csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs @@ -0,0 +1,175 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGAlignItemsTest.html + +using System; +using NUnit.Framework; + +namespace Facebook.Yoga +{ + [TestFixture] + public class YGAlignItemsTest + { + [Test] + public void Test_align_items_stretch() + { + YogaNode root = new YogaNode(); + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Height = 10f; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + } + + [Test] + public void Test_align_items_center() + { + YogaNode root = new YogaNode(); + root.AlignItems = YogaAlign.Center; + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 10f; + root_child0.Height = 10f; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(45f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(45f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + } + + [Test] + public void Test_align_items_flex_start() + { + YogaNode root = new YogaNode(); + root.AlignItems = YogaAlign.FlexStart; + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 10f; + root_child0.Height = 10f; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(90f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + } + + [Test] + public void Test_align_items_flex_end() + { + YogaNode root = new YogaNode(); + root.AlignItems = YogaAlign.FlexEnd; + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 10f; + root_child0.Height = 10f; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(90f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + } + + } +} diff --git a/csharp/tests/Facebook.Yoga/YGAlignSelfTest.cs b/csharp/tests/Facebook.Yoga/YGAlignSelfTest.cs new file mode 100644 index 00000000..c564cf93 --- /dev/null +++ b/csharp/tests/Facebook.Yoga/YGAlignSelfTest.cs @@ -0,0 +1,178 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGAlignSelfTest.html + +using System; +using NUnit.Framework; + +namespace Facebook.Yoga +{ + [TestFixture] + public class YGAlignSelfTest + { + [Test] + public void Test_align_self_center() + { + YogaNode root = new YogaNode(); + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.AlignSelf = YogaAlign.Center; + root_child0.Width = 10f; + root_child0.Height = 10f; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(45f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(45f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + } + + [Test] + public void Test_align_self_flex_end() + { + YogaNode root = new YogaNode(); + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.AlignSelf = YogaAlign.FlexEnd; + root_child0.Width = 10f; + root_child0.Height = 10f; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(90f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + } + + [Test] + public void Test_align_self_flex_start() + { + YogaNode root = new YogaNode(); + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.AlignSelf = YogaAlign.FlexStart; + root_child0.Width = 10f; + root_child0.Height = 10f; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(90f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + } + + [Test] + public void Test_align_self_flex_end_override_flex_start() + { + YogaNode root = new YogaNode(); + root.AlignItems = YogaAlign.FlexStart; + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.AlignSelf = YogaAlign.FlexEnd; + root_child0.Width = 10f; + root_child0.Height = 10f; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(90f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + } + + } +} diff --git a/csharp/tests/Facebook.Yoga/YGBorderTest.cs b/csharp/tests/Facebook.Yoga/YGBorderTest.cs new file mode 100644 index 00000000..613fe115 --- /dev/null +++ b/csharp/tests/Facebook.Yoga/YGBorderTest.cs @@ -0,0 +1,212 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGBorderTest.html + +using System; +using NUnit.Framework; + +namespace Facebook.Yoga +{ + [TestFixture] + public class YGBorderTest + { + [Test] + public void Test_border_no_size() + { + YogaNode root = new YogaNode(); + root.SetBorder(YogaEdge.Left, 10f); + root.SetBorder(YogaEdge.Top, 10f); + root.SetBorder(YogaEdge.Right, 10f); + root.SetBorder(YogaEdge.Bottom, 10f); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(20f, root.LayoutWidth); + Assert.AreEqual(20f, root.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(20f, root.LayoutWidth); + Assert.AreEqual(20f, root.LayoutHeight); + } + + [Test] + public void Test_border_container_match_child() + { + YogaNode root = new YogaNode(); + root.SetBorder(YogaEdge.Left, 10f); + root.SetBorder(YogaEdge.Top, 10f); + root.SetBorder(YogaEdge.Right, 10f); + root.SetBorder(YogaEdge.Bottom, 10f); + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 10f; + root_child0.Height = 10f; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(30f, root.LayoutWidth); + Assert.AreEqual(30f, root.LayoutHeight); + + Assert.AreEqual(10f, root_child0.LayoutX); + Assert.AreEqual(10f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(30f, root.LayoutWidth); + Assert.AreEqual(30f, root.LayoutHeight); + + Assert.AreEqual(10f, root_child0.LayoutX); + Assert.AreEqual(10f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + } + + [Test] + public void Test_border_flex_child() + { + YogaNode root = new YogaNode(); + root.SetBorder(YogaEdge.Left, 10f); + root.SetBorder(YogaEdge.Top, 10f); + root.SetBorder(YogaEdge.Right, 10f); + root.SetBorder(YogaEdge.Bottom, 10f); + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.FlexGrow = 1f; + root_child0.Width = 10f; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(10f, root_child0.LayoutX); + Assert.AreEqual(10f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(80f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(80f, root_child0.LayoutX); + Assert.AreEqual(10f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(80f, root_child0.LayoutHeight); + } + + [Test] + public void Test_border_stretch_child() + { + YogaNode root = new YogaNode(); + root.SetBorder(YogaEdge.Left, 10f); + root.SetBorder(YogaEdge.Top, 10f); + root.SetBorder(YogaEdge.Right, 10f); + root.SetBorder(YogaEdge.Bottom, 10f); + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Height = 10f; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(10f, root_child0.LayoutX); + Assert.AreEqual(10f, root_child0.LayoutY); + Assert.AreEqual(80f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(10f, root_child0.LayoutX); + Assert.AreEqual(10f, root_child0.LayoutY); + Assert.AreEqual(80f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + } + + [Test] + public void Test_border_center_child() + { + YogaNode root = new YogaNode(); + root.JustifyContent = YogaJustify.Center; + root.AlignItems = YogaAlign.Center; + root.SetBorder(YogaEdge.Start, 10f); + root.SetBorder(YogaEdge.End, 20f); + root.SetBorder(YogaEdge.Bottom, 20f); + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 10f; + root_child0.Height = 10f; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(40f, root_child0.LayoutX); + Assert.AreEqual(35f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(50f, root_child0.LayoutX); + Assert.AreEqual(35f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + } + + } +} diff --git a/csharp/tests/Facebook.Yoga/YGFlexDirectionTest.cs b/csharp/tests/Facebook.Yoga/YGFlexDirectionTest.cs new file mode 100644 index 00000000..10a1257a --- /dev/null +++ b/csharp/tests/Facebook.Yoga/YGFlexDirectionTest.cs @@ -0,0 +1,413 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGFlexDirectionTest.html + +using System; +using NUnit.Framework; + +namespace Facebook.Yoga +{ + [TestFixture] + public class YGFlexDirectionTest + { + [Test] + public void Test_flex_direction_column_no_height() + { + YogaNode root = new YogaNode(); + root.Width = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Height = 10f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Height = 10f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Height = 10f; + root.Insert(2, root_child2); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(30f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(10f, root_child1.LayoutY); + Assert.AreEqual(100f, root_child1.LayoutWidth); + Assert.AreEqual(10f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(20f, root_child2.LayoutY); + Assert.AreEqual(100f, root_child2.LayoutWidth); + Assert.AreEqual(10f, root_child2.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(30f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(10f, root_child1.LayoutY); + Assert.AreEqual(100f, root_child1.LayoutWidth); + Assert.AreEqual(10f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(20f, root_child2.LayoutY); + Assert.AreEqual(100f, root_child2.LayoutWidth); + Assert.AreEqual(10f, root_child2.LayoutHeight); + } + + [Test] + public void Test_flex_direction_row_no_width() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 10f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Width = 10f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 10f; + root.Insert(2, root_child2); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(30f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + Assert.AreEqual(10f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(10f, root_child1.LayoutWidth); + Assert.AreEqual(100f, root_child1.LayoutHeight); + + Assert.AreEqual(20f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(10f, root_child2.LayoutWidth); + Assert.AreEqual(100f, root_child2.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(30f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(20f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + Assert.AreEqual(10f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(10f, root_child1.LayoutWidth); + Assert.AreEqual(100f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(10f, root_child2.LayoutWidth); + Assert.AreEqual(100f, root_child2.LayoutHeight); + } + + [Test] + public void Test_flex_direction_column() + { + YogaNode root = new YogaNode(); + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Height = 10f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Height = 10f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Height = 10f; + root.Insert(2, root_child2); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(10f, root_child1.LayoutY); + Assert.AreEqual(100f, root_child1.LayoutWidth); + Assert.AreEqual(10f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(20f, root_child2.LayoutY); + Assert.AreEqual(100f, root_child2.LayoutWidth); + Assert.AreEqual(10f, root_child2.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(10f, root_child1.LayoutY); + Assert.AreEqual(100f, root_child1.LayoutWidth); + Assert.AreEqual(10f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(20f, root_child2.LayoutY); + Assert.AreEqual(100f, root_child2.LayoutWidth); + Assert.AreEqual(10f, root_child2.LayoutHeight); + } + + [Test] + public void Test_flex_direction_row() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 10f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Width = 10f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 10f; + root.Insert(2, root_child2); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + Assert.AreEqual(10f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(10f, root_child1.LayoutWidth); + Assert.AreEqual(100f, root_child1.LayoutHeight); + + Assert.AreEqual(20f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(10f, root_child2.LayoutWidth); + Assert.AreEqual(100f, root_child2.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(90f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + Assert.AreEqual(80f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(10f, root_child1.LayoutWidth); + Assert.AreEqual(100f, root_child1.LayoutHeight); + + Assert.AreEqual(70f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(10f, root_child2.LayoutWidth); + Assert.AreEqual(100f, root_child2.LayoutHeight); + } + + [Test] + public void Test_flex_direction_column_reverse() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.ColumnReverse; + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Height = 10f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Height = 10f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Height = 10f; + root.Insert(2, root_child2); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(90f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(80f, root_child1.LayoutY); + Assert.AreEqual(100f, root_child1.LayoutWidth); + Assert.AreEqual(10f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(70f, root_child2.LayoutY); + Assert.AreEqual(100f, root_child2.LayoutWidth); + Assert.AreEqual(10f, root_child2.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(90f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(80f, root_child1.LayoutY); + Assert.AreEqual(100f, root_child1.LayoutWidth); + Assert.AreEqual(10f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(70f, root_child2.LayoutY); + Assert.AreEqual(100f, root_child2.LayoutWidth); + Assert.AreEqual(10f, root_child2.LayoutHeight); + } + + [Test] + public void Test_flex_direction_row_reverse() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.RowReverse; + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 10f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Width = 10f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 10f; + root.Insert(2, root_child2); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(90f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + Assert.AreEqual(80f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(10f, root_child1.LayoutWidth); + Assert.AreEqual(100f, root_child1.LayoutHeight); + + Assert.AreEqual(70f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(10f, root_child2.LayoutWidth); + Assert.AreEqual(100f, root_child2.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + Assert.AreEqual(10f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(10f, root_child1.LayoutWidth); + Assert.AreEqual(100f, root_child1.LayoutHeight); + + Assert.AreEqual(20f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(10f, root_child2.LayoutWidth); + Assert.AreEqual(100f, root_child2.LayoutHeight); + } + + } +} diff --git a/csharp/tests/Facebook.Yoga/YGFlexTest.cs b/csharp/tests/Facebook.Yoga/YGFlexTest.cs new file mode 100644 index 00000000..05036680 --- /dev/null +++ b/csharp/tests/Facebook.Yoga/YGFlexTest.cs @@ -0,0 +1,419 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGFlexTest.html + +using System; +using NUnit.Framework; + +namespace Facebook.Yoga +{ + [TestFixture] + public class YGFlexTest + { + [Test] + public void Test_flex_basis_flex_grow_column() + { + YogaNode root = new YogaNode(); + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.FlexGrow = 1f; + root_child0.FlexBasis = 50f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.FlexGrow = 1f; + root.Insert(1, root_child1); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(75f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(75f, root_child1.LayoutY); + Assert.AreEqual(100f, root_child1.LayoutWidth); + Assert.AreEqual(25f, root_child1.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(75f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(75f, root_child1.LayoutY); + Assert.AreEqual(100f, root_child1.LayoutWidth); + Assert.AreEqual(25f, root_child1.LayoutHeight); + } + + [Test] + public void Test_flex_basis_flex_grow_row() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.FlexGrow = 1f; + root_child0.FlexBasis = 50f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.FlexGrow = 1f; + root.Insert(1, root_child1); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(75f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + Assert.AreEqual(75f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(25f, root_child1.LayoutWidth); + Assert.AreEqual(100f, root_child1.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(25f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(75f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(25f, root_child1.LayoutWidth); + Assert.AreEqual(100f, root_child1.LayoutHeight); + } + + [Test] + public void Test_flex_basis_flex_shrink_column() + { + YogaNode root = new YogaNode(); + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.FlexShrink = 1f; + root_child0.FlexBasis = 100f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.FlexBasis = 50f; + root.Insert(1, root_child1); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(50f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(50f, root_child1.LayoutY); + Assert.AreEqual(100f, root_child1.LayoutWidth); + Assert.AreEqual(50f, root_child1.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(50f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(50f, root_child1.LayoutY); + Assert.AreEqual(100f, root_child1.LayoutWidth); + Assert.AreEqual(50f, root_child1.LayoutHeight); + } + + [Test] + public void Test_flex_basis_flex_shrink_row() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.FlexShrink = 1f; + root_child0.FlexBasis = 100f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.FlexBasis = 50f; + root.Insert(1, root_child1); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(100f, root_child1.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(50f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(100f, root_child1.LayoutHeight); + } + + [Test] + public void Test_flex_shrink_to_zero() + { + YogaNode root = new YogaNode(); + root.Height = 75f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 50f; + root_child0.Height = 50f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.FlexShrink = 1f; + root_child1.Width = 50f; + root_child1.Height = 50f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 50f; + root_child2.Height = 50f; + root.Insert(2, root_child2); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(50f, root.LayoutWidth); + Assert.AreEqual(75f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(50f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(50f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(0f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(50f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(50f, root_child2.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(50f, root.LayoutWidth); + Assert.AreEqual(75f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(50f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(50f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(0f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(50f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(50f, root_child2.LayoutHeight); + } + + [Test] + public void Test_flex_basis_overrides_main_size() + { + YogaNode root = new YogaNode(); + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.FlexGrow = 1f; + root_child0.FlexBasis = 50f; + root_child0.Height = 20f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.FlexGrow = 1f; + root_child1.Height = 10f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.FlexGrow = 1f; + root_child2.Height = 10f; + root.Insert(2, root_child2); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(60f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(60f, root_child1.LayoutY); + Assert.AreEqual(100f, root_child1.LayoutWidth); + Assert.AreEqual(20f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(80f, root_child2.LayoutY); + Assert.AreEqual(100f, root_child2.LayoutWidth); + Assert.AreEqual(20f, root_child2.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(60f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(60f, root_child1.LayoutY); + Assert.AreEqual(100f, root_child1.LayoutWidth); + Assert.AreEqual(20f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(80f, root_child2.LayoutY); + Assert.AreEqual(100f, root_child2.LayoutWidth); + Assert.AreEqual(20f, root_child2.LayoutHeight); + } + + [Test] + public void Test_flex_grow_shrink_at_most() + { + YogaNode root = new YogaNode(); + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root.Insert(0, root_child0); + + YogaNode root_child0_child0 = new YogaNode(); + root_child0_child0.FlexGrow = 1f; + root_child0_child0.FlexShrink = 1f; + root_child0.Insert(0, root_child0_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(0f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0.LayoutY); + Assert.AreEqual(100f, root_child0_child0.LayoutWidth); + Assert.AreEqual(0f, root_child0_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(0f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0.LayoutY); + Assert.AreEqual(100f, root_child0_child0.LayoutWidth); + Assert.AreEqual(0f, root_child0_child0.LayoutHeight); + } + + } +} diff --git a/csharp/tests/Facebook.Yoga/YGFlexWrapTest.cs b/csharp/tests/Facebook.Yoga/YGFlexWrapTest.cs new file mode 100644 index 00000000..d5c88f7f --- /dev/null +++ b/csharp/tests/Facebook.Yoga/YGFlexWrapTest.cs @@ -0,0 +1,358 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGFlexWrapTest.html + +using System; +using NUnit.Framework; + +namespace Facebook.Yoga +{ + [TestFixture] + public class YGFlexWrapTest + { + [Test] + public void Test_wrap_column() + { + YogaNode root = new YogaNode(); + root.Wrap = YogaWrap.Wrap; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 30f; + root_child0.Height = 30f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Width = 30f; + root_child1.Height = 30f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 30f; + root_child2.Height = 30f; + root.Insert(2, root_child2); + + YogaNode root_child3 = new YogaNode(); + root_child3.Width = 30f; + root_child3.Height = 30f; + root.Insert(3, root_child3); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(60f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(30f, root_child0.LayoutWidth); + Assert.AreEqual(30f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(30f, root_child1.LayoutY); + Assert.AreEqual(30f, root_child1.LayoutWidth); + Assert.AreEqual(30f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(60f, root_child2.LayoutY); + Assert.AreEqual(30f, root_child2.LayoutWidth); + Assert.AreEqual(30f, root_child2.LayoutHeight); + + Assert.AreEqual(30f, root_child3.LayoutX); + Assert.AreEqual(0f, root_child3.LayoutY); + Assert.AreEqual(30f, root_child3.LayoutWidth); + Assert.AreEqual(30f, root_child3.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(60f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(30f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(30f, root_child0.LayoutWidth); + Assert.AreEqual(30f, root_child0.LayoutHeight); + + Assert.AreEqual(30f, root_child1.LayoutX); + Assert.AreEqual(30f, root_child1.LayoutY); + Assert.AreEqual(30f, root_child1.LayoutWidth); + Assert.AreEqual(30f, root_child1.LayoutHeight); + + Assert.AreEqual(30f, root_child2.LayoutX); + Assert.AreEqual(60f, root_child2.LayoutY); + Assert.AreEqual(30f, root_child2.LayoutWidth); + Assert.AreEqual(30f, root_child2.LayoutHeight); + + Assert.AreEqual(0f, root_child3.LayoutX); + Assert.AreEqual(0f, root_child3.LayoutY); + Assert.AreEqual(30f, root_child3.LayoutWidth); + Assert.AreEqual(30f, root_child3.LayoutHeight); + } + + [Test] + public void Test_wrap_row() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.Wrap = YogaWrap.Wrap; + root.Width = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 30f; + root_child0.Height = 30f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Width = 30f; + root_child1.Height = 30f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 30f; + root_child2.Height = 30f; + root.Insert(2, root_child2); + + YogaNode root_child3 = new YogaNode(); + root_child3.Width = 30f; + root_child3.Height = 30f; + root.Insert(3, root_child3); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(60f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(30f, root_child0.LayoutWidth); + Assert.AreEqual(30f, root_child0.LayoutHeight); + + Assert.AreEqual(30f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(30f, root_child1.LayoutWidth); + Assert.AreEqual(30f, root_child1.LayoutHeight); + + Assert.AreEqual(60f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(30f, root_child2.LayoutWidth); + Assert.AreEqual(30f, root_child2.LayoutHeight); + + Assert.AreEqual(0f, root_child3.LayoutX); + Assert.AreEqual(30f, root_child3.LayoutY); + Assert.AreEqual(30f, root_child3.LayoutWidth); + Assert.AreEqual(30f, root_child3.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(60f, root.LayoutHeight); + + Assert.AreEqual(70f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(30f, root_child0.LayoutWidth); + Assert.AreEqual(30f, root_child0.LayoutHeight); + + Assert.AreEqual(40f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(30f, root_child1.LayoutWidth); + Assert.AreEqual(30f, root_child1.LayoutHeight); + + Assert.AreEqual(10f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(30f, root_child2.LayoutWidth); + Assert.AreEqual(30f, root_child2.LayoutHeight); + + Assert.AreEqual(70f, root_child3.LayoutX); + Assert.AreEqual(30f, root_child3.LayoutY); + Assert.AreEqual(30f, root_child3.LayoutWidth); + Assert.AreEqual(30f, root_child3.LayoutHeight); + } + + [Test] + public void Test_wrap_row_align_items_flex_end() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.AlignItems = YogaAlign.FlexEnd; + root.Wrap = YogaWrap.Wrap; + root.Width = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 30f; + root_child0.Height = 10f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Width = 30f; + root_child1.Height = 20f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 30f; + root_child2.Height = 30f; + root.Insert(2, root_child2); + + YogaNode root_child3 = new YogaNode(); + root_child3.Width = 30f; + root_child3.Height = 30f; + root.Insert(3, root_child3); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(60f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(20f, root_child0.LayoutY); + Assert.AreEqual(30f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(30f, root_child1.LayoutX); + Assert.AreEqual(10f, root_child1.LayoutY); + Assert.AreEqual(30f, root_child1.LayoutWidth); + Assert.AreEqual(20f, root_child1.LayoutHeight); + + Assert.AreEqual(60f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(30f, root_child2.LayoutWidth); + Assert.AreEqual(30f, root_child2.LayoutHeight); + + Assert.AreEqual(0f, root_child3.LayoutX); + Assert.AreEqual(30f, root_child3.LayoutY); + Assert.AreEqual(30f, root_child3.LayoutWidth); + Assert.AreEqual(30f, root_child3.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(60f, root.LayoutHeight); + + Assert.AreEqual(70f, root_child0.LayoutX); + Assert.AreEqual(20f, root_child0.LayoutY); + Assert.AreEqual(30f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(40f, root_child1.LayoutX); + Assert.AreEqual(10f, root_child1.LayoutY); + Assert.AreEqual(30f, root_child1.LayoutWidth); + Assert.AreEqual(20f, root_child1.LayoutHeight); + + Assert.AreEqual(10f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(30f, root_child2.LayoutWidth); + Assert.AreEqual(30f, root_child2.LayoutHeight); + + Assert.AreEqual(70f, root_child3.LayoutX); + Assert.AreEqual(30f, root_child3.LayoutY); + Assert.AreEqual(30f, root_child3.LayoutWidth); + Assert.AreEqual(30f, root_child3.LayoutHeight); + } + + [Test] + public void Test_wrap_row_align_items_center() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.AlignItems = YogaAlign.Center; + root.Wrap = YogaWrap.Wrap; + root.Width = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 30f; + root_child0.Height = 10f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Width = 30f; + root_child1.Height = 20f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 30f; + root_child2.Height = 30f; + root.Insert(2, root_child2); + + YogaNode root_child3 = new YogaNode(); + root_child3.Width = 30f; + root_child3.Height = 30f; + root.Insert(3, root_child3); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(60f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(10f, root_child0.LayoutY); + Assert.AreEqual(30f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(30f, root_child1.LayoutX); + Assert.AreEqual(5f, root_child1.LayoutY); + Assert.AreEqual(30f, root_child1.LayoutWidth); + Assert.AreEqual(20f, root_child1.LayoutHeight); + + Assert.AreEqual(60f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(30f, root_child2.LayoutWidth); + Assert.AreEqual(30f, root_child2.LayoutHeight); + + Assert.AreEqual(0f, root_child3.LayoutX); + Assert.AreEqual(30f, root_child3.LayoutY); + Assert.AreEqual(30f, root_child3.LayoutWidth); + Assert.AreEqual(30f, root_child3.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(60f, root.LayoutHeight); + + Assert.AreEqual(70f, root_child0.LayoutX); + Assert.AreEqual(10f, root_child0.LayoutY); + Assert.AreEqual(30f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(40f, root_child1.LayoutX); + Assert.AreEqual(5f, root_child1.LayoutY); + Assert.AreEqual(30f, root_child1.LayoutWidth); + Assert.AreEqual(20f, root_child1.LayoutHeight); + + Assert.AreEqual(10f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(30f, root_child2.LayoutWidth); + Assert.AreEqual(30f, root_child2.LayoutHeight); + + Assert.AreEqual(70f, root_child3.LayoutX); + Assert.AreEqual(30f, root_child3.LayoutY); + Assert.AreEqual(30f, root_child3.LayoutWidth); + Assert.AreEqual(30f, root_child3.LayoutHeight); + } + + } +} diff --git a/csharp/tests/Facebook.Yoga/YGJustifyContentTest.cs b/csharp/tests/Facebook.Yoga/YGJustifyContentTest.cs new file mode 100644 index 00000000..7c8bb4d1 --- /dev/null +++ b/csharp/tests/Facebook.Yoga/YGJustifyContentTest.cs @@ -0,0 +1,683 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGJustifyContentTest.html + +using System; +using NUnit.Framework; + +namespace Facebook.Yoga +{ + [TestFixture] + public class YGJustifyContentTest + { + [Test] + public void Test_justify_content_row_flex_start() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.Width = 102f; + root.Height = 102f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 10f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Width = 10f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 10f; + root.Insert(2, root_child2); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(102f, root.LayoutWidth); + Assert.AreEqual(102f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(102f, root_child0.LayoutHeight); + + Assert.AreEqual(10f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(10f, root_child1.LayoutWidth); + Assert.AreEqual(102f, root_child1.LayoutHeight); + + Assert.AreEqual(20f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(10f, root_child2.LayoutWidth); + Assert.AreEqual(102f, root_child2.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(102f, root.LayoutWidth); + Assert.AreEqual(102f, root.LayoutHeight); + + Assert.AreEqual(92f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(102f, root_child0.LayoutHeight); + + Assert.AreEqual(82f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(10f, root_child1.LayoutWidth); + Assert.AreEqual(102f, root_child1.LayoutHeight); + + Assert.AreEqual(72f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(10f, root_child2.LayoutWidth); + Assert.AreEqual(102f, root_child2.LayoutHeight); + } + + [Test] + public void Test_justify_content_row_flex_end() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.JustifyContent = YogaJustify.FlexEnd; + root.Width = 102f; + root.Height = 102f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 10f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Width = 10f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 10f; + root.Insert(2, root_child2); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(102f, root.LayoutWidth); + Assert.AreEqual(102f, root.LayoutHeight); + + Assert.AreEqual(72f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(102f, root_child0.LayoutHeight); + + Assert.AreEqual(82f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(10f, root_child1.LayoutWidth); + Assert.AreEqual(102f, root_child1.LayoutHeight); + + Assert.AreEqual(92f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(10f, root_child2.LayoutWidth); + Assert.AreEqual(102f, root_child2.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(102f, root.LayoutWidth); + Assert.AreEqual(102f, root.LayoutHeight); + + Assert.AreEqual(20f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(102f, root_child0.LayoutHeight); + + Assert.AreEqual(10f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(10f, root_child1.LayoutWidth); + Assert.AreEqual(102f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(10f, root_child2.LayoutWidth); + Assert.AreEqual(102f, root_child2.LayoutHeight); + } + + [Test] + public void Test_justify_content_row_center() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.JustifyContent = YogaJustify.Center; + root.Width = 102f; + root.Height = 102f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 10f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Width = 10f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 10f; + root.Insert(2, root_child2); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(102f, root.LayoutWidth); + Assert.AreEqual(102f, root.LayoutHeight); + + Assert.AreEqual(36f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(102f, root_child0.LayoutHeight); + + Assert.AreEqual(46f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(10f, root_child1.LayoutWidth); + Assert.AreEqual(102f, root_child1.LayoutHeight); + + Assert.AreEqual(56f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(10f, root_child2.LayoutWidth); + Assert.AreEqual(102f, root_child2.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(102f, root.LayoutWidth); + Assert.AreEqual(102f, root.LayoutHeight); + + Assert.AreEqual(56f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(102f, root_child0.LayoutHeight); + + Assert.AreEqual(46f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(10f, root_child1.LayoutWidth); + Assert.AreEqual(102f, root_child1.LayoutHeight); + + Assert.AreEqual(36f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(10f, root_child2.LayoutWidth); + Assert.AreEqual(102f, root_child2.LayoutHeight); + } + + [Test] + public void Test_justify_content_row_space_between() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.JustifyContent = YogaJustify.SpaceBetween; + root.Width = 102f; + root.Height = 102f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 10f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Width = 10f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 10f; + root.Insert(2, root_child2); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(102f, root.LayoutWidth); + Assert.AreEqual(102f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(102f, root_child0.LayoutHeight); + + Assert.AreEqual(46f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(10f, root_child1.LayoutWidth); + Assert.AreEqual(102f, root_child1.LayoutHeight); + + Assert.AreEqual(92f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(10f, root_child2.LayoutWidth); + Assert.AreEqual(102f, root_child2.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(102f, root.LayoutWidth); + Assert.AreEqual(102f, root.LayoutHeight); + + Assert.AreEqual(92f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(102f, root_child0.LayoutHeight); + + Assert.AreEqual(46f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(10f, root_child1.LayoutWidth); + Assert.AreEqual(102f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(10f, root_child2.LayoutWidth); + Assert.AreEqual(102f, root_child2.LayoutHeight); + } + + [Test] + public void Test_justify_content_row_space_around() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.JustifyContent = YogaJustify.SpaceAround; + root.Width = 102f; + root.Height = 102f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 10f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Width = 10f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 10f; + root.Insert(2, root_child2); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(102f, root.LayoutWidth); + Assert.AreEqual(102f, root.LayoutHeight); + + Assert.AreEqual(12f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(102f, root_child0.LayoutHeight); + + Assert.AreEqual(46f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(10f, root_child1.LayoutWidth); + Assert.AreEqual(102f, root_child1.LayoutHeight); + + Assert.AreEqual(80f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(10f, root_child2.LayoutWidth); + Assert.AreEqual(102f, root_child2.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(102f, root.LayoutWidth); + Assert.AreEqual(102f, root.LayoutHeight); + + Assert.AreEqual(80f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(102f, root_child0.LayoutHeight); + + Assert.AreEqual(46f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(10f, root_child1.LayoutWidth); + Assert.AreEqual(102f, root_child1.LayoutHeight); + + Assert.AreEqual(12f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(10f, root_child2.LayoutWidth); + Assert.AreEqual(102f, root_child2.LayoutHeight); + } + + [Test] + public void Test_justify_content_column_flex_start() + { + YogaNode root = new YogaNode(); + root.Width = 102f; + root.Height = 102f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Height = 10f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Height = 10f; + root.Insert(2, root_child2); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(102f, root.LayoutWidth); + Assert.AreEqual(102f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(102f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(10f, root_child1.LayoutY); + Assert.AreEqual(102f, root_child1.LayoutWidth); + Assert.AreEqual(0f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(10f, root_child2.LayoutY); + Assert.AreEqual(102f, root_child2.LayoutWidth); + Assert.AreEqual(10f, root_child2.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(102f, root.LayoutWidth); + Assert.AreEqual(102f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(102f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(10f, root_child1.LayoutY); + Assert.AreEqual(102f, root_child1.LayoutWidth); + Assert.AreEqual(0f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(10f, root_child2.LayoutY); + Assert.AreEqual(102f, root_child2.LayoutWidth); + Assert.AreEqual(10f, root_child2.LayoutHeight); + } + + [Test] + public void Test_justify_content_column_flex_end() + { + YogaNode root = new YogaNode(); + root.JustifyContent = YogaJustify.FlexEnd; + root.Width = 102f; + root.Height = 102f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Height = 10f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Height = 10f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Height = 10f; + root.Insert(2, root_child2); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(102f, root.LayoutWidth); + Assert.AreEqual(102f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(72f, root_child0.LayoutY); + Assert.AreEqual(102f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(82f, root_child1.LayoutY); + Assert.AreEqual(102f, root_child1.LayoutWidth); + Assert.AreEqual(10f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(92f, root_child2.LayoutY); + Assert.AreEqual(102f, root_child2.LayoutWidth); + Assert.AreEqual(10f, root_child2.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(102f, root.LayoutWidth); + Assert.AreEqual(102f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(72f, root_child0.LayoutY); + Assert.AreEqual(102f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(82f, root_child1.LayoutY); + Assert.AreEqual(102f, root_child1.LayoutWidth); + Assert.AreEqual(10f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(92f, root_child2.LayoutY); + Assert.AreEqual(102f, root_child2.LayoutWidth); + Assert.AreEqual(10f, root_child2.LayoutHeight); + } + + [Test] + public void Test_justify_content_column_center() + { + YogaNode root = new YogaNode(); + root.JustifyContent = YogaJustify.Center; + root.Width = 102f; + root.Height = 102f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Height = 10f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Height = 10f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Height = 10f; + root.Insert(2, root_child2); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(102f, root.LayoutWidth); + Assert.AreEqual(102f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(36f, root_child0.LayoutY); + Assert.AreEqual(102f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(46f, root_child1.LayoutY); + Assert.AreEqual(102f, root_child1.LayoutWidth); + Assert.AreEqual(10f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(56f, root_child2.LayoutY); + Assert.AreEqual(102f, root_child2.LayoutWidth); + Assert.AreEqual(10f, root_child2.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(102f, root.LayoutWidth); + Assert.AreEqual(102f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(36f, root_child0.LayoutY); + Assert.AreEqual(102f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(46f, root_child1.LayoutY); + Assert.AreEqual(102f, root_child1.LayoutWidth); + Assert.AreEqual(10f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(56f, root_child2.LayoutY); + Assert.AreEqual(102f, root_child2.LayoutWidth); + Assert.AreEqual(10f, root_child2.LayoutHeight); + } + + [Test] + public void Test_justify_content_column_space_between() + { + YogaNode root = new YogaNode(); + root.JustifyContent = YogaJustify.SpaceBetween; + root.Width = 102f; + root.Height = 102f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Height = 10f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Height = 10f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Height = 10f; + root.Insert(2, root_child2); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(102f, root.LayoutWidth); + Assert.AreEqual(102f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(102f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(46f, root_child1.LayoutY); + Assert.AreEqual(102f, root_child1.LayoutWidth); + Assert.AreEqual(10f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(92f, root_child2.LayoutY); + Assert.AreEqual(102f, root_child2.LayoutWidth); + Assert.AreEqual(10f, root_child2.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(102f, root.LayoutWidth); + Assert.AreEqual(102f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(102f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(46f, root_child1.LayoutY); + Assert.AreEqual(102f, root_child1.LayoutWidth); + Assert.AreEqual(10f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(92f, root_child2.LayoutY); + Assert.AreEqual(102f, root_child2.LayoutWidth); + Assert.AreEqual(10f, root_child2.LayoutHeight); + } + + [Test] + public void Test_justify_content_column_space_around() + { + YogaNode root = new YogaNode(); + root.JustifyContent = YogaJustify.SpaceAround; + root.Width = 102f; + root.Height = 102f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Height = 10f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Height = 10f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Height = 10f; + root.Insert(2, root_child2); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(102f, root.LayoutWidth); + Assert.AreEqual(102f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(12f, root_child0.LayoutY); + Assert.AreEqual(102f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(46f, root_child1.LayoutY); + Assert.AreEqual(102f, root_child1.LayoutWidth); + Assert.AreEqual(10f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(80f, root_child2.LayoutY); + Assert.AreEqual(102f, root_child2.LayoutWidth); + Assert.AreEqual(10f, root_child2.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(102f, root.LayoutWidth); + Assert.AreEqual(102f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(12f, root_child0.LayoutY); + Assert.AreEqual(102f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(46f, root_child1.LayoutY); + Assert.AreEqual(102f, root_child1.LayoutWidth); + Assert.AreEqual(10f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(80f, root_child2.LayoutY); + Assert.AreEqual(102f, root_child2.LayoutWidth); + Assert.AreEqual(10f, root_child2.LayoutHeight); + } + + } +} diff --git a/csharp/tests/Facebook.Yoga/YGMarginTest.cs b/csharp/tests/Facebook.Yoga/YGMarginTest.cs new file mode 100644 index 00000000..fa9ddee2 --- /dev/null +++ b/csharp/tests/Facebook.Yoga/YGMarginTest.cs @@ -0,0 +1,434 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGMarginTest.html + +using System; +using NUnit.Framework; + +namespace Facebook.Yoga +{ + [TestFixture] + public class YGMarginTest + { + [Test] + public void Test_margin_start() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.SetMargin(YogaEdge.Start, 10f); + root_child0.Width = 10f; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(10f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(80f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + } + + [Test] + public void Test_margin_top() + { + YogaNode root = new YogaNode(); + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.SetMargin(YogaEdge.Top, 10f); + root_child0.Height = 10f; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(10f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(10f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + } + + [Test] + public void Test_margin_end() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.JustifyContent = YogaJustify.FlexEnd; + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.SetMargin(YogaEdge.End, 10f); + root_child0.Width = 10f; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(80f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(10f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + } + + [Test] + public void Test_margin_bottom() + { + YogaNode root = new YogaNode(); + root.JustifyContent = YogaJustify.FlexEnd; + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.SetMargin(YogaEdge.Bottom, 10f); + root_child0.Height = 10f; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(80f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(80f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + } + + [Test] + public void Test_margin_and_flex_row() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.FlexGrow = 1f; + root_child0.SetMargin(YogaEdge.Start, 10f); + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(10f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(90f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(90f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + } + + [Test] + public void Test_margin_and_flex_column() + { + YogaNode root = new YogaNode(); + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.FlexGrow = 1f; + root_child0.SetMargin(YogaEdge.Top, 10f); + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(10f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(90f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(10f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(90f, root_child0.LayoutHeight); + } + + [Test] + public void Test_margin_and_stretch_row() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.FlexGrow = 1f; + root_child0.SetMargin(YogaEdge.Top, 10f); + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(10f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(90f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(10f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(90f, root_child0.LayoutHeight); + } + + [Test] + public void Test_margin_and_stretch_column() + { + YogaNode root = new YogaNode(); + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.FlexGrow = 1f; + root_child0.SetMargin(YogaEdge.Start, 10f); + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(10f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(90f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(90f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + } + + [Test] + public void Test_margin_with_sibling_row() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.FlexGrow = 1f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.FlexGrow = 1f; + root.Insert(1, root_child1); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + Assert.AreEqual(50f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(100f, root_child1.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(50f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(100f, root_child1.LayoutHeight); + } + + [Test] + public void Test_margin_with_sibling_column() + { + YogaNode root = new YogaNode(); + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.FlexGrow = 1f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.FlexGrow = 1f; + root.Insert(1, root_child1); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(50f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(50f, root_child1.LayoutY); + Assert.AreEqual(100f, root_child1.LayoutWidth); + Assert.AreEqual(50f, root_child1.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(50f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(50f, root_child1.LayoutY); + Assert.AreEqual(100f, root_child1.LayoutWidth); + Assert.AreEqual(50f, root_child1.LayoutHeight); + } + + } +} diff --git a/csharp/tests/Facebook.Yoga/YGMinMaxDimensionTest.cs b/csharp/tests/Facebook.Yoga/YGMinMaxDimensionTest.cs new file mode 100644 index 00000000..04413d41 --- /dev/null +++ b/csharp/tests/Facebook.Yoga/YGMinMaxDimensionTest.cs @@ -0,0 +1,458 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGMinMaxDimensionTest.html + +using System; +using NUnit.Framework; + +namespace Facebook.Yoga +{ + [TestFixture] + public class YGMinMaxDimensionTest + { + [Test] + public void Test_max_width() + { + YogaNode root = new YogaNode(); + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.MaxWidth = 50f; + root_child0.Height = 10f; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(50f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + } + + [Test] + public void Test_max_height() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 10f; + root_child0.MaxHeight = 50f; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(50f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(90f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(50f, root_child0.LayoutHeight); + } + + [Test] + public void Test_min_height() + { + YogaNode root = new YogaNode(); + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.FlexGrow = 1f; + root_child0.MinHeight = 60f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.FlexGrow = 1f; + root.Insert(1, root_child1); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(80f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(80f, root_child1.LayoutY); + Assert.AreEqual(100f, root_child1.LayoutWidth); + Assert.AreEqual(20f, root_child1.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(80f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(80f, root_child1.LayoutY); + Assert.AreEqual(100f, root_child1.LayoutWidth); + Assert.AreEqual(20f, root_child1.LayoutHeight); + } + + [Test] + public void Test_min_width() + { + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.FlexGrow = 1f; + root_child0.MinWidth = 60f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.FlexGrow = 1f; + root.Insert(1, root_child1); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(80f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + Assert.AreEqual(80f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(20f, root_child1.LayoutWidth); + Assert.AreEqual(100f, root_child1.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(20f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(80f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(20f, root_child1.LayoutWidth); + Assert.AreEqual(100f, root_child1.LayoutHeight); + } + + [Test] + public void Test_justify_content_min_max() + { + YogaNode root = new YogaNode(); + root.JustifyContent = YogaJustify.Center; + root.Width = 100f; + root.MinHeight = 100f; + root.MaxHeight = 200f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 60f; + root_child0.Height = 60f; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(20f, root_child0.LayoutY); + Assert.AreEqual(60f, root_child0.LayoutWidth); + Assert.AreEqual(60f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(40f, root_child0.LayoutX); + Assert.AreEqual(20f, root_child0.LayoutY); + Assert.AreEqual(60f, root_child0.LayoutWidth); + Assert.AreEqual(60f, root_child0.LayoutHeight); + } + + [Test] + public void Test_align_items_min_max() + { + YogaNode root = new YogaNode(); + root.AlignItems = YogaAlign.Center; + root.MinWidth = 100f; + root.MaxWidth = 200f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 60f; + root_child0.Height = 60f; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(20f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(60f, root_child0.LayoutWidth); + Assert.AreEqual(60f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(20f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(60f, root_child0.LayoutWidth); + Assert.AreEqual(60f, root_child0.LayoutHeight); + } + + [Test] + public void Test_justify_content_overflow_min_max() + { + YogaNode root = new YogaNode(); + root.JustifyContent = YogaJustify.Center; + root.MinHeight = 100f; + root.MaxHeight = 110f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 50f; + root_child0.Height = 50f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.Width = 50f; + root_child1.Height = 50f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.Width = 50f; + root_child2.Height = 50f; + root.Insert(2, root_child2); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(50f, root.LayoutWidth); + Assert.AreEqual(110f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(-20f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(50f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(30f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(50f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(80f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(50f, root_child2.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(50f, root.LayoutWidth); + Assert.AreEqual(110f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(-20f, root_child0.LayoutY); + Assert.AreEqual(50f, root_child0.LayoutWidth); + Assert.AreEqual(50f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(30f, root_child1.LayoutY); + Assert.AreEqual(50f, root_child1.LayoutWidth); + Assert.AreEqual(50f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(80f, root_child2.LayoutY); + Assert.AreEqual(50f, root_child2.LayoutWidth); + Assert.AreEqual(50f, root_child2.LayoutHeight); + } + + [Test] + public void Test_flex_grow_within_max_width() + { + YogaNode root = new YogaNode(); + root.Width = 200f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.FlexDirection = YogaFlexDirection.Row; + root_child0.MaxWidth = 100f; + root.Insert(0, root_child0); + + YogaNode root_child0_child0 = new YogaNode(); + root_child0_child0.FlexGrow = 1f; + root_child0_child0.Height = 20f; + root_child0.Insert(0, root_child0_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(200f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(20f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0.LayoutY); + Assert.AreEqual(100f, root_child0_child0.LayoutWidth); + Assert.AreEqual(20f, root_child0_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(200f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(100f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(20f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0.LayoutY); + Assert.AreEqual(100f, root_child0_child0.LayoutWidth); + Assert.AreEqual(20f, root_child0_child0.LayoutHeight); + } + + [Test] + public void Test_flex_grow_within_constrained_max_width() + { + YogaNode root = new YogaNode(); + root.Width = 200f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.FlexDirection = YogaFlexDirection.Row; + root_child0.MaxWidth = 300f; + root.Insert(0, root_child0); + + YogaNode root_child0_child0 = new YogaNode(); + root_child0_child0.FlexGrow = 1f; + root_child0_child0.Height = 20f; + root_child0.Insert(0, root_child0_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(200f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(200f, root_child0.LayoutWidth); + Assert.AreEqual(20f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0.LayoutY); + Assert.AreEqual(200f, root_child0_child0.LayoutWidth); + Assert.AreEqual(20f, root_child0_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(200f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(200f, root_child0.LayoutWidth); + Assert.AreEqual(20f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child0_child0.LayoutX); + Assert.AreEqual(0f, root_child0_child0.LayoutY); + Assert.AreEqual(200f, root_child0_child0.LayoutWidth); + Assert.AreEqual(20f, root_child0_child0.LayoutHeight); + } + + } +} diff --git a/csharp/tests/Facebook.Yoga/YGPaddingTest.cs b/csharp/tests/Facebook.Yoga/YGPaddingTest.cs new file mode 100644 index 00000000..7fde4e5e --- /dev/null +++ b/csharp/tests/Facebook.Yoga/YGPaddingTest.cs @@ -0,0 +1,256 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGPaddingTest.html + +using System; +using NUnit.Framework; + +namespace Facebook.Yoga +{ + [TestFixture] + public class YGPaddingTest + { + [Test] + public void Test_padding_no_size() + { + YogaNode root = new YogaNode(); + root.SetPadding(YogaEdge.Left, 10f); + root.SetPadding(YogaEdge.Top, 10f); + root.SetPadding(YogaEdge.Right, 10f); + root.SetPadding(YogaEdge.Bottom, 10f); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(20f, root.LayoutWidth); + Assert.AreEqual(20f, root.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(20f, root.LayoutWidth); + Assert.AreEqual(20f, root.LayoutHeight); + } + + [Test] + public void Test_padding_container_match_child() + { + YogaNode root = new YogaNode(); + root.SetPadding(YogaEdge.Left, 10f); + root.SetPadding(YogaEdge.Top, 10f); + root.SetPadding(YogaEdge.Right, 10f); + root.SetPadding(YogaEdge.Bottom, 10f); + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 10f; + root_child0.Height = 10f; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(30f, root.LayoutWidth); + Assert.AreEqual(30f, root.LayoutHeight); + + Assert.AreEqual(10f, root_child0.LayoutX); + Assert.AreEqual(10f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(30f, root.LayoutWidth); + Assert.AreEqual(30f, root.LayoutHeight); + + Assert.AreEqual(10f, root_child0.LayoutX); + Assert.AreEqual(10f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + } + + [Test] + public void Test_padding_flex_child() + { + YogaNode root = new YogaNode(); + root.SetPadding(YogaEdge.Left, 10f); + root.SetPadding(YogaEdge.Top, 10f); + root.SetPadding(YogaEdge.Right, 10f); + root.SetPadding(YogaEdge.Bottom, 10f); + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.FlexGrow = 1f; + root_child0.Width = 10f; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(10f, root_child0.LayoutX); + Assert.AreEqual(10f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(80f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(80f, root_child0.LayoutX); + Assert.AreEqual(10f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(80f, root_child0.LayoutHeight); + } + + [Test] + public void Test_padding_stretch_child() + { + YogaNode root = new YogaNode(); + root.SetPadding(YogaEdge.Left, 10f); + root.SetPadding(YogaEdge.Top, 10f); + root.SetPadding(YogaEdge.Right, 10f); + root.SetPadding(YogaEdge.Bottom, 10f); + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Height = 10f; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(10f, root_child0.LayoutX); + Assert.AreEqual(10f, root_child0.LayoutY); + Assert.AreEqual(80f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(10f, root_child0.LayoutX); + Assert.AreEqual(10f, root_child0.LayoutY); + Assert.AreEqual(80f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + } + + [Test] + public void Test_padding_center_child() + { + YogaNode root = new YogaNode(); + root.JustifyContent = YogaJustify.Center; + root.AlignItems = YogaAlign.Center; + root.SetPadding(YogaEdge.Start, 10f); + root.SetPadding(YogaEdge.End, 20f); + root.SetPadding(YogaEdge.Bottom, 20f); + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.Width = 10f; + root_child0.Height = 10f; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(40f, root_child0.LayoutX); + Assert.AreEqual(35f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(50f, root_child0.LayoutX); + Assert.AreEqual(35f, root_child0.LayoutY); + Assert.AreEqual(10f, root_child0.LayoutWidth); + Assert.AreEqual(10f, root_child0.LayoutHeight); + } + + [Test] + public void Test_child_with_padding_align_end() + { + YogaNode root = new YogaNode(); + root.JustifyContent = YogaJustify.FlexEnd; + root.AlignItems = YogaAlign.FlexEnd; + root.Width = 200f; + root.Height = 200f; + + YogaNode root_child0 = new YogaNode(); + root_child0.SetPadding(YogaEdge.Left, 20f); + root_child0.SetPadding(YogaEdge.Top, 20f); + root_child0.SetPadding(YogaEdge.Right, 20f); + root_child0.SetPadding(YogaEdge.Bottom, 20f); + root_child0.Width = 100f; + root_child0.Height = 100f; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(200f, root.LayoutWidth); + Assert.AreEqual(200f, root.LayoutHeight); + + Assert.AreEqual(100f, root_child0.LayoutX); + Assert.AreEqual(100f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(200f, root.LayoutWidth); + Assert.AreEqual(200f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(100f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + } + + } +} diff --git a/csharp/tests/Facebook.Yoga/YGRoundingTest.cs b/csharp/tests/Facebook.Yoga/YGRoundingTest.cs new file mode 100644 index 00000000..62da0f0c --- /dev/null +++ b/csharp/tests/Facebook.Yoga/YGRoundingTest.cs @@ -0,0 +1,807 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGRoundingTest.html + +using System; +using NUnit.Framework; + +namespace Facebook.Yoga +{ + [TestFixture] + public class YGRoundingTest + { + [Test] + public void Test_rounding_flex_basis_flex_grow_row_width_of_100() + { + YogaNode.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true); + + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.Width = 100f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.FlexGrow = 1f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.FlexGrow = 1f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.FlexGrow = 1f; + root.Insert(2, root_child2); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(33f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + Assert.AreEqual(33f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(34f, root_child1.LayoutWidth); + Assert.AreEqual(100f, root_child1.LayoutHeight); + + Assert.AreEqual(67f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(33f, root_child2.LayoutWidth); + Assert.AreEqual(100f, root_child2.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(67f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(33f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + Assert.AreEqual(33f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(34f, root_child1.LayoutWidth); + Assert.AreEqual(100f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(33f, root_child2.LayoutWidth); + Assert.AreEqual(100f, root_child2.LayoutHeight); + + YogaNode.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, false); + } + + [Test] + public void Test_rounding_flex_basis_flex_grow_row_prime_number_width() + { + YogaNode.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true); + + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.Width = 113f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.FlexGrow = 1f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.FlexGrow = 1f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.FlexGrow = 1f; + root.Insert(2, root_child2); + + YogaNode root_child3 = new YogaNode(); + root_child3.FlexGrow = 1f; + root.Insert(3, root_child3); + + YogaNode root_child4 = new YogaNode(); + root_child4.FlexGrow = 1f; + root.Insert(4, root_child4); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(113f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(23f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + Assert.AreEqual(23f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(22f, root_child1.LayoutWidth); + Assert.AreEqual(100f, root_child1.LayoutHeight); + + Assert.AreEqual(45f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(23f, root_child2.LayoutWidth); + Assert.AreEqual(100f, root_child2.LayoutHeight); + + Assert.AreEqual(68f, root_child3.LayoutX); + Assert.AreEqual(0f, root_child3.LayoutY); + Assert.AreEqual(22f, root_child3.LayoutWidth); + Assert.AreEqual(100f, root_child3.LayoutHeight); + + Assert.AreEqual(90f, root_child4.LayoutX); + Assert.AreEqual(0f, root_child4.LayoutY); + Assert.AreEqual(23f, root_child4.LayoutWidth); + Assert.AreEqual(100f, root_child4.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(113f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(90f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(23f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + Assert.AreEqual(68f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(22f, root_child1.LayoutWidth); + Assert.AreEqual(100f, root_child1.LayoutHeight); + + Assert.AreEqual(45f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(23f, root_child2.LayoutWidth); + Assert.AreEqual(100f, root_child2.LayoutHeight); + + Assert.AreEqual(23f, root_child3.LayoutX); + Assert.AreEqual(0f, root_child3.LayoutY); + Assert.AreEqual(22f, root_child3.LayoutWidth); + Assert.AreEqual(100f, root_child3.LayoutHeight); + + Assert.AreEqual(0f, root_child4.LayoutX); + Assert.AreEqual(0f, root_child4.LayoutY); + Assert.AreEqual(23f, root_child4.LayoutWidth); + Assert.AreEqual(100f, root_child4.LayoutHeight); + + YogaNode.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, false); + } + + [Test] + public void Test_rounding_flex_basis_flex_shrink_row() + { + YogaNode.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true); + + YogaNode root = new YogaNode(); + root.FlexDirection = YogaFlexDirection.Row; + root.Width = 101f; + root.Height = 100f; + + YogaNode root_child0 = new YogaNode(); + root_child0.FlexShrink = 1f; + root_child0.FlexBasis = 100f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.FlexBasis = 25f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.FlexBasis = 25f; + root.Insert(2, root_child2); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(101f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(51f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + Assert.AreEqual(51f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(25f, root_child1.LayoutWidth); + Assert.AreEqual(100f, root_child1.LayoutHeight); + + Assert.AreEqual(76f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(25f, root_child2.LayoutWidth); + Assert.AreEqual(100f, root_child2.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(101f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(50f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(51f, root_child0.LayoutWidth); + Assert.AreEqual(100f, root_child0.LayoutHeight); + + Assert.AreEqual(25f, root_child1.LayoutX); + Assert.AreEqual(0f, root_child1.LayoutY); + Assert.AreEqual(25f, root_child1.LayoutWidth); + Assert.AreEqual(100f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(0f, root_child2.LayoutY); + Assert.AreEqual(25f, root_child2.LayoutWidth); + Assert.AreEqual(100f, root_child2.LayoutHeight); + + YogaNode.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, false); + } + + [Test] + public void Test_rounding_flex_basis_overrides_main_size() + { + YogaNode.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true); + + YogaNode root = new YogaNode(); + root.Width = 100f; + root.Height = 113f; + + YogaNode root_child0 = new YogaNode(); + root_child0.FlexGrow = 1f; + root_child0.FlexBasis = 50f; + root_child0.Height = 20f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.FlexGrow = 1f; + root_child1.Height = 10f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.FlexGrow = 1f; + root_child2.Height = 10f; + root.Insert(2, root_child2); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(113f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(64f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(64f, root_child1.LayoutY); + Assert.AreEqual(100f, root_child1.LayoutWidth); + Assert.AreEqual(25f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(89f, root_child2.LayoutY); + Assert.AreEqual(100f, root_child2.LayoutWidth); + Assert.AreEqual(24f, root_child2.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(113f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(64f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(64f, root_child1.LayoutY); + Assert.AreEqual(100f, root_child1.LayoutWidth); + Assert.AreEqual(25f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(89f, root_child2.LayoutY); + Assert.AreEqual(100f, root_child2.LayoutWidth); + Assert.AreEqual(24f, root_child2.LayoutHeight); + + YogaNode.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, false); + } + + [Test] + public void Test_rounding_total_fractial() + { + YogaNode.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true); + + YogaNode root = new YogaNode(); + root.Width = 87.4f; + root.Height = 113.4f; + + YogaNode root_child0 = new YogaNode(); + root_child0.FlexGrow = 0.7f; + root_child0.FlexBasis = 50.3f; + root_child0.Height = 20.3f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.FlexGrow = 1.6f; + root_child1.Height = 10f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.FlexGrow = 1.1f; + root_child2.Height = 10.7f; + root.Insert(2, root_child2); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(87f, root.LayoutWidth); + Assert.AreEqual(113f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(87f, root_child0.LayoutWidth); + Assert.AreEqual(59f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(59f, root_child1.LayoutY); + Assert.AreEqual(87f, root_child1.LayoutWidth); + Assert.AreEqual(30f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(89f, root_child2.LayoutY); + Assert.AreEqual(87f, root_child2.LayoutWidth); + Assert.AreEqual(24f, root_child2.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(87f, root.LayoutWidth); + Assert.AreEqual(113f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(87f, root_child0.LayoutWidth); + Assert.AreEqual(59f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(59f, root_child1.LayoutY); + Assert.AreEqual(87f, root_child1.LayoutWidth); + Assert.AreEqual(30f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(89f, root_child2.LayoutY); + Assert.AreEqual(87f, root_child2.LayoutWidth); + Assert.AreEqual(24f, root_child2.LayoutHeight); + + YogaNode.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, false); + } + + [Test] + public void Test_rounding_total_fractial_nested() + { + YogaNode.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true); + + YogaNode root = new YogaNode(); + root.Width = 87.4f; + root.Height = 113.4f; + + YogaNode root_child0 = new YogaNode(); + root_child0.FlexGrow = 0.7f; + root_child0.FlexBasis = 50.3f; + root_child0.Height = 20.3f; + root.Insert(0, root_child0); + + YogaNode root_child0_child0 = new YogaNode(); + root_child0_child0.FlexGrow = 1f; + root_child0_child0.FlexBasis = 0.3f; + root_child0_child0.SetPosition(YogaEdge.Bottom, 13.3f); + root_child0_child0.Height = 9.9f; + root_child0.Insert(0, root_child0_child0); + + YogaNode root_child0_child1 = new YogaNode(); + root_child0_child1.FlexGrow = 4f; + root_child0_child1.FlexBasis = 0.3f; + root_child0_child1.SetPosition(YogaEdge.Top, 13.3f); + root_child0_child1.Height = 1.1f; + root_child0.Insert(1, root_child0_child1); + + YogaNode root_child1 = new YogaNode(); + root_child1.FlexGrow = 1.6f; + root_child1.Height = 10f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.FlexGrow = 1.1f; + root_child2.Height = 10.7f; + root.Insert(2, root_child2); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(87f, root.LayoutWidth); + Assert.AreEqual(113f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(87f, root_child0.LayoutWidth); + Assert.AreEqual(59f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child0_child0.LayoutX); + Assert.AreEqual(-13f, root_child0_child0.LayoutY); + Assert.AreEqual(87f, root_child0_child0.LayoutWidth); + Assert.AreEqual(12f, root_child0_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child0_child1.LayoutX); + Assert.AreEqual(25f, root_child0_child1.LayoutY); + Assert.AreEqual(87f, root_child0_child1.LayoutWidth); + Assert.AreEqual(47f, root_child0_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(59f, root_child1.LayoutY); + Assert.AreEqual(87f, root_child1.LayoutWidth); + Assert.AreEqual(30f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(89f, root_child2.LayoutY); + Assert.AreEqual(87f, root_child2.LayoutWidth); + Assert.AreEqual(24f, root_child2.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(87f, root.LayoutWidth); + Assert.AreEqual(113f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(87f, root_child0.LayoutWidth); + Assert.AreEqual(59f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child0_child0.LayoutX); + Assert.AreEqual(-13f, root_child0_child0.LayoutY); + Assert.AreEqual(87f, root_child0_child0.LayoutWidth); + Assert.AreEqual(12f, root_child0_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child0_child1.LayoutX); + Assert.AreEqual(25f, root_child0_child1.LayoutY); + Assert.AreEqual(87f, root_child0_child1.LayoutWidth); + Assert.AreEqual(47f, root_child0_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(59f, root_child1.LayoutY); + Assert.AreEqual(87f, root_child1.LayoutWidth); + Assert.AreEqual(30f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(89f, root_child2.LayoutY); + Assert.AreEqual(87f, root_child2.LayoutWidth); + Assert.AreEqual(24f, root_child2.LayoutHeight); + + YogaNode.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, false); + } + + [Test] + public void Test_rounding_fractial_input_1() + { + YogaNode.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true); + + YogaNode root = new YogaNode(); + root.Width = 100f; + root.Height = 113.4f; + + YogaNode root_child0 = new YogaNode(); + root_child0.FlexGrow = 1f; + root_child0.FlexBasis = 50f; + root_child0.Height = 20f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.FlexGrow = 1f; + root_child1.Height = 10f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.FlexGrow = 1f; + root_child2.Height = 10f; + root.Insert(2, root_child2); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(113f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(64f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(64f, root_child1.LayoutY); + Assert.AreEqual(100f, root_child1.LayoutWidth); + Assert.AreEqual(25f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(89f, root_child2.LayoutY); + Assert.AreEqual(100f, root_child2.LayoutWidth); + Assert.AreEqual(24f, root_child2.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(113f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(64f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(64f, root_child1.LayoutY); + Assert.AreEqual(100f, root_child1.LayoutWidth); + Assert.AreEqual(25f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(89f, root_child2.LayoutY); + Assert.AreEqual(100f, root_child2.LayoutWidth); + Assert.AreEqual(24f, root_child2.LayoutHeight); + + YogaNode.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, false); + } + + [Test] + public void Test_rounding_fractial_input_2() + { + YogaNode.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true); + + YogaNode root = new YogaNode(); + root.Width = 100f; + root.Height = 113.6f; + + YogaNode root_child0 = new YogaNode(); + root_child0.FlexGrow = 1f; + root_child0.FlexBasis = 50f; + root_child0.Height = 20f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.FlexGrow = 1f; + root_child1.Height = 10f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.FlexGrow = 1f; + root_child2.Height = 10f; + root.Insert(2, root_child2); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(114f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(65f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(65f, root_child1.LayoutY); + Assert.AreEqual(100f, root_child1.LayoutWidth); + Assert.AreEqual(24f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(89f, root_child2.LayoutY); + Assert.AreEqual(100f, root_child2.LayoutWidth); + Assert.AreEqual(25f, root_child2.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(114f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(65f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(65f, root_child1.LayoutY); + Assert.AreEqual(100f, root_child1.LayoutWidth); + Assert.AreEqual(24f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(89f, root_child2.LayoutY); + Assert.AreEqual(100f, root_child2.LayoutWidth); + Assert.AreEqual(25f, root_child2.LayoutHeight); + + YogaNode.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, false); + } + + [Test] + public void Test_rounding_fractial_input_3() + { + YogaNode.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true); + + YogaNode root = new YogaNode(); + root.SetPosition(YogaEdge.Top, 0.3f); + root.Width = 100f; + root.Height = 113.4f; + + YogaNode root_child0 = new YogaNode(); + root_child0.FlexGrow = 1f; + root_child0.FlexBasis = 50f; + root_child0.Height = 20f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.FlexGrow = 1f; + root_child1.Height = 10f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.FlexGrow = 1f; + root_child2.Height = 10f; + root.Insert(2, root_child2); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(114f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(64f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(64f, root_child1.LayoutY); + Assert.AreEqual(100f, root_child1.LayoutWidth); + Assert.AreEqual(25f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(89f, root_child2.LayoutY); + Assert.AreEqual(100f, root_child2.LayoutWidth); + Assert.AreEqual(24f, root_child2.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(114f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(64f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(64f, root_child1.LayoutY); + Assert.AreEqual(100f, root_child1.LayoutWidth); + Assert.AreEqual(25f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(89f, root_child2.LayoutY); + Assert.AreEqual(100f, root_child2.LayoutWidth); + Assert.AreEqual(24f, root_child2.LayoutHeight); + + YogaNode.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, false); + } + + [Test] + public void Test_rounding_fractial_input_4() + { + YogaNode.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true); + + YogaNode root = new YogaNode(); + root.SetPosition(YogaEdge.Top, 0.7f); + root.Width = 100f; + root.Height = 113.4f; + + YogaNode root_child0 = new YogaNode(); + root_child0.FlexGrow = 1f; + root_child0.FlexBasis = 50f; + root_child0.Height = 20f; + root.Insert(0, root_child0); + + YogaNode root_child1 = new YogaNode(); + root_child1.FlexGrow = 1f; + root_child1.Height = 10f; + root.Insert(1, root_child1); + + YogaNode root_child2 = new YogaNode(); + root_child2.FlexGrow = 1f; + root_child2.Height = 10f; + root.Insert(2, root_child2); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(1f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(113f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(64f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(64f, root_child1.LayoutY); + Assert.AreEqual(100f, root_child1.LayoutWidth); + Assert.AreEqual(25f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(89f, root_child2.LayoutY); + Assert.AreEqual(100f, root_child2.LayoutWidth); + Assert.AreEqual(24f, root_child2.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(1f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(113f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(100f, root_child0.LayoutWidth); + Assert.AreEqual(64f, root_child0.LayoutHeight); + + Assert.AreEqual(0f, root_child1.LayoutX); + Assert.AreEqual(64f, root_child1.LayoutY); + Assert.AreEqual(100f, root_child1.LayoutWidth); + Assert.AreEqual(25f, root_child1.LayoutHeight); + + Assert.AreEqual(0f, root_child2.LayoutX); + Assert.AreEqual(89f, root_child2.LayoutY); + Assert.AreEqual(100f, root_child2.LayoutWidth); + Assert.AreEqual(24f, root_child2.LayoutHeight); + + YogaNode.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, false); + } + + } +} diff --git a/csharp/tests/Facebook.Yoga/YogaNodeCreateTest.cs b/csharp/tests/Facebook.Yoga/YogaNodeCreateTest.cs new file mode 100644 index 00000000..d7cd8d8e --- /dev/null +++ b/csharp/tests/Facebook.Yoga/YogaNodeCreateTest.cs @@ -0,0 +1,143 @@ +/** + * 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. + */ + +using NUnit.Framework; +using System; + +/** + * Tests for {@link YogaNode}. + */ +namespace Facebook.Yoga +{ + [TestFixture] + public class YogaNodeCreateTest + { + [Test] + public void TestSimple() + { + YogaNode nodeDefault = new YogaNode(); + YogaNode nodeCreated = YogaNode.Create(flexDirection: YogaFlexDirection.Row); + Assert.AreEqual(YogaFlexDirection.Row, nodeCreated.FlexDirection); + Assert.IsFalse(nodeDefault.IsDirty); + nodeDefault.CopyStyle(nodeCreated); + Assert.IsTrue(nodeDefault.IsDirty); + } + + [Test] + public void TestSame() + { + YogaNode nodeDefault = new YogaNode(); + YogaNode nodeCreated = YogaNode.Create(); + Assert.IsFalse(nodeDefault.IsDirty); + nodeDefault.CopyStyle(nodeCreated); + Assert.IsFalse(nodeDefault.IsDirty); + } + + [Test] + public void TestMultiple() + { + YogaNode node = YogaNode.Create( + positionType: YogaPositionType.Absolute, + wrap: YogaWrap.Wrap, + position: new Spacing(top:6, right:4), + margin: new Spacing(bottom:5, left:3)); + + Assert.AreEqual(YogaFlexDirection.Column, node.FlexDirection); + Assert.AreEqual(YogaPositionType.Absolute, node.PositionType); + Assert.AreEqual(YogaWrap.Wrap, node.Wrap); + Assert.AreEqual(6, node.GetPosition(YogaEdge.Top)); + Assert.IsTrue(YogaConstants.IsUndefined(node.GetPosition(YogaEdge.Bottom))); + Assert.AreEqual(4, node.GetPosition(YogaEdge.Right)); + Assert.IsTrue(YogaConstants.IsUndefined(node.GetPosition(YogaEdge.Left))); + Assert.AreEqual(0, node.GetMargin(YogaEdge.Top)); + Assert.AreEqual(5, node.GetMargin(YogaEdge.Bottom)); + Assert.AreEqual(3, node.GetMargin(YogaEdge.Left)); + Assert.AreEqual(0, node.GetMargin(YogaEdge.Right)); + } + + [Test] + public void TestFull() + { + YogaNode node = YogaNode.Create( + styleDirection: YogaDirection.RTL, + flexDirection: YogaFlexDirection.RowReverse, + + justifyContent: YogaJustify.SpaceAround, + alignContent: YogaAlign.Center, + alignItems: YogaAlign.FlexEnd, + alignSelf: YogaAlign.Stretch, + + positionType: YogaPositionType.Absolute, + wrap: YogaWrap.Wrap, + overflow: YogaOverflow.Scroll, + + flex: 1, + flexGrow: 2, + flexShrink: 3, + flexBasis: 4, + + position: new Spacing(top: 5, bottom: 6, left: 7, right: 8), + margin: new Spacing(top: 9, bottom: 10, left: 11, right: 12), + padding: new Spacing(top: 13, bottom: 14, left: 15, right: 16), + border: new Spacing(top: 17, bottom: 18, left: 19, right: 20), + + Width: 21, + Height: 22, + MinWidth: 23, + MinHeight: 24, + MaxWidth: 25, + MaxHeight: 26); + + Assert.AreEqual(YogaDirection.RTL, node.StyleDirection); + Assert.AreEqual(YogaFlexDirection.RowReverse, node.FlexDirection); + + Assert.AreEqual(YogaJustify.SpaceAround, node.JustifyContent); + Assert.AreEqual(YogaAlign.Center, node.AlignContent); + Assert.AreEqual(YogaAlign.FlexEnd, node.AlignItems); + Assert.AreEqual(YogaAlign.Stretch, node.AlignSelf); + + Assert.AreEqual(YogaPositionType.Absolute, node.PositionType); + Assert.AreEqual(YogaWrap.Wrap, node.Wrap); + Assert.AreEqual(YogaOverflow.Scroll, node.Overflow); + + Assert.AreEqual(2, node.FlexGrow); + Assert.AreEqual(3, node.FlexShrink); + Assert.AreEqual(4, node.FlexBasis); + node.FlexGrow = YogaConstants.Undefined; + Assert.AreEqual(1, node.FlexGrow); + + Assert.AreEqual(5, node.GetPosition(YogaEdge.Top)); + Assert.AreEqual(6, node.GetPosition(YogaEdge.Bottom)); + Assert.AreEqual(7, node.GetPosition(YogaEdge.Left)); + Assert.AreEqual(8, node.GetPosition(YogaEdge.Right)); + + Assert.AreEqual(9, node.GetMargin(YogaEdge.Top)); + Assert.AreEqual(10, node.GetMargin(YogaEdge.Bottom)); + Assert.AreEqual(11, node.GetMargin(YogaEdge.Left)); + Assert.AreEqual(12, node.GetMargin(YogaEdge.Right)); + + Assert.AreEqual(13, node.GetPadding(YogaEdge.Top)); + Assert.AreEqual(14, node.GetPadding(YogaEdge.Bottom)); + Assert.AreEqual(15, node.GetPadding(YogaEdge.Left)); + Assert.AreEqual(16, node.GetPadding(YogaEdge.Right)); + + Assert.AreEqual(17, node.GetBorder(YogaEdge.Top)); + Assert.AreEqual(18, node.GetBorder(YogaEdge.Bottom)); + Assert.AreEqual(19, node.GetBorder(YogaEdge.Left)); + Assert.AreEqual(20, node.GetBorder(YogaEdge.Right)); + + Assert.AreEqual(21, node.Width); + Assert.AreEqual(22, node.Height); + Assert.AreEqual(23, node.MinWidth); + Assert.AreEqual(24, node.MinHeight); + Assert.AreEqual(25, node.MaxWidth); + Assert.AreEqual(26, node.MaxHeight); + } + } +} diff --git a/csharp/tests/Facebook.CSSLayout/CSSNodeTest.cs b/csharp/tests/Facebook.Yoga/YogaNodeTest.cs similarity index 51% rename from csharp/tests/Facebook.CSSLayout/CSSNodeTest.cs rename to csharp/tests/Facebook.Yoga/YogaNodeTest.cs index f46ef24d..5cf1002b 100644 --- a/csharp/tests/Facebook.CSSLayout/CSSNodeTest.cs +++ b/csharp/tests/Facebook.Yoga/YogaNodeTest.cs @@ -11,18 +11,18 @@ using NUnit.Framework; using System; /** - * Tests for {@link CSSNode}. + * Tests for {@link YogaNode}. */ -namespace Facebook.CSSLayout +namespace Facebook.Yoga { [TestFixture] - public class CSSNodeTest + public class YogaNodeTest { [Test] public void TestAddChildGetParent() { - CSSNode parent = new CSSNode(); - CSSNode child = new CSSNode(); + YogaNode parent = new YogaNode(); + YogaNode child = new YogaNode(); Assert.IsNull(child.Parent); Assert.AreEqual(0, parent.Count); @@ -42,22 +42,22 @@ namespace Facebook.CSSLayout [Test] public void TestChildren() { - CSSNode parent = new CSSNode(); - foreach (CSSNode node in parent) { + YogaNode parent = new YogaNode(); + foreach (YogaNode node in parent) { Assert.Fail(node.ToString()); } - CSSNode child0 = new CSSNode(); + YogaNode child0 = new YogaNode(); Assert.AreEqual(-1, parent.IndexOf(child0)); parent.Insert(0, child0); - foreach (CSSNode node in parent) { + foreach (YogaNode node in parent) { Assert.AreEqual(0, parent.IndexOf(node)); } - CSSNode child1 = new CSSNode(); + YogaNode child1 = new YogaNode(); parent.Insert(1, child1); int index = 0; - foreach (CSSNode node in parent) { + foreach (YogaNode node in parent) { Assert.AreEqual(index++, parent.IndexOf(node)); } @@ -76,7 +76,7 @@ namespace Facebook.CSSLayout [ExpectedException("System.NullReferenceException")] public void TestRemoveAtFromEmpty() { - CSSNode parent = new CSSNode(); + YogaNode parent = new YogaNode(); parent.RemoveAt(0); } @@ -84,8 +84,8 @@ namespace Facebook.CSSLayout [ExpectedException("System.ArgumentOutOfRangeException")] public void TestRemoveAtOutOfRange() { - CSSNode parent = new CSSNode(); - CSSNode child = new CSSNode(); + YogaNode parent = new YogaNode(); + YogaNode child = new YogaNode(); parent.Insert(0, child); parent.RemoveAt(1); } @@ -94,9 +94,9 @@ namespace Facebook.CSSLayout [ExpectedException("System.InvalidOperationException")] public void TestCannotAddChildToMultipleParents() { - CSSNode parent1 = new CSSNode(); - CSSNode parent2 = new CSSNode(); - CSSNode child = new CSSNode(); + YogaNode parent1 = new YogaNode(); + YogaNode parent2 = new YogaNode(); + YogaNode child = new YogaNode(); parent1.Insert(0, child); parent2.Insert(0, child); @@ -105,19 +105,19 @@ namespace Facebook.CSSLayout [Test] public void TestReset() { - int instanceCount = CSSNode.GetInstanceCount(); - CSSNode node = new CSSNode(); - Assert.AreEqual(instanceCount + 1, CSSNode.GetInstanceCount()); + int instanceCount = YogaNode.GetInstanceCount(); + YogaNode node = new YogaNode(); + Assert.AreEqual(instanceCount + 1, YogaNode.GetInstanceCount()); node.Reset(); - Assert.AreEqual(instanceCount + 1, CSSNode.GetInstanceCount()); + Assert.AreEqual(instanceCount + 1, YogaNode.GetInstanceCount()); } [Test] [ExpectedException("System.InvalidOperationException")] public void TestResetParent() { - CSSNode parent = new CSSNode(); - CSSNode child = new CSSNode(); + YogaNode parent = new YogaNode(); + YogaNode child = new YogaNode(); parent.Insert(0, child); parent.Reset(); } @@ -126,8 +126,8 @@ namespace Facebook.CSSLayout [ExpectedException("System.InvalidOperationException")] public void TestResetChild() { - CSSNode parent = new CSSNode(); - CSSNode child = new CSSNode(); + YogaNode parent = new YogaNode(); + YogaNode child = new YogaNode(); parent.Insert(0, child); child.Reset(); } @@ -135,72 +135,121 @@ namespace Facebook.CSSLayout [Test] public void TestClear() { - int instanceCount = CSSNode.GetInstanceCount(); - CSSNode parent = new CSSNode(); - Assert.AreEqual(instanceCount + 1, CSSNode.GetInstanceCount()); - CSSNode child = new CSSNode(); - Assert.AreEqual(instanceCount + 2, CSSNode.GetInstanceCount()); + int instanceCount = YogaNode.GetInstanceCount(); + YogaNode parent = new YogaNode(); + Assert.AreEqual(instanceCount + 1, YogaNode.GetInstanceCount()); + YogaNode child = new YogaNode(); + Assert.AreEqual(instanceCount + 2, YogaNode.GetInstanceCount()); parent.Insert(0, child); Assert.AreEqual(1, parent.Count); Assert.AreEqual(parent, child.Parent); parent.Clear(); Assert.AreEqual(0, parent.Count); Assert.IsNull(child.Parent); - Assert.AreEqual(instanceCount + 2, CSSNode.GetInstanceCount()); + Assert.AreEqual(instanceCount + 2, YogaNode.GetInstanceCount()); } [Test] public void TestMeasureFunc() { - CSSNode node = new CSSNode(); + YogaNode node = new YogaNode(); node.SetMeasureFunction((_, width, widthMode, height, heightMode) => { return MeasureOutput.Make(100, 150); }); node.CalculateLayout(); - Assert.AreEqual(100, (int)node.LayoutWidth); - Assert.AreEqual(150, (int)node.LayoutHeight); + Assert.AreEqual(100, node.LayoutWidth); + Assert.AreEqual(150, node.LayoutHeight); + } + + [Test] + public void TestMeasureFuncWithFloat() + { + YogaNode node = new YogaNode(); + node.SetMeasureFunction((_, width, widthMode, height, heightMode) => { + return MeasureOutput.Make(123.4f, 81.7f); + }); + node.CalculateLayout(); + Assert.AreEqual(123, node.LayoutWidth); + Assert.AreEqual(81, node.LayoutHeight); + } + + [Test] + [ExpectedException("System.InvalidOperationException")] + public void TestChildWithMeasureFunc() + { + YogaNode node = new YogaNode(); + node.SetMeasureFunction((_, width, widthMode, height, heightMode) => { + return MeasureOutput.Make(100, 150); + }); + YogaNode child = new YogaNode(); + node.Insert(0, child); + } + + [Test] + [ExpectedException("System.InvalidOperationException")] + public void TestMeasureFuncWithChild() + { + YogaNode node = new YogaNode(); + YogaNode child = new YogaNode(); + node.Insert(0, child); + node.SetMeasureFunction((_, width, widthMode, height, heightMode) => { + return MeasureOutput.Make(100, 150); + }); } [Test] public void TestPrint() { - CSSNode parent = new CSSNode(); - parent.StyleWidth = 100; - parent.StyleHeight = 120; - CSSNode child0 = new CSSNode(); - child0.StyleWidth = 30; - child0.StyleHeight = 40; - CSSNode child1 = new CSSNode(); - child1.StyleWidth = 35; - child1.StyleHeight = 45; + YogaNode parent = new YogaNode(); + parent.Width = 100; + parent.Height = 120; + YogaNode child0 = new YogaNode(); + child0.Width = 30; + child0.Height = 40; + YogaNode child1 = new YogaNode(); + child1.Width = 35; + child1.Height = 45; parent.Insert(0, child0); parent.Insert(0, child1); parent.CalculateLayout(); Assert.AreEqual(parent.Print(), "{layout: {width: 100, height: 120, top: 0, left: 0}, flexDirection: 'column', alignItems: 'stretch', flexGrow: 0, flexShrink: 0, overflow: 'visible', width: 100, height: 120, children: [\n {layout: {width: 35, height: 45, top: 0, left: 0}, flexDirection: 'column', alignItems: 'stretch', flexGrow: 0, flexShrink: 0, overflow: 'visible', width: 35, height: 45, },\n {layout: {width: 30, height: 40, top: 45, left: 0}, flexDirection: 'column', alignItems: 'stretch', flexGrow: 0, flexShrink: 0, overflow: 'visible', width: 30, height: 40, },\n]},\n"); } + [Test] + public void TestCopyStyle() + { + YogaNode node0 = new YogaNode(); + Assert.IsTrue(YogaConstants.IsUndefined(node0.MaxHeight)); + + YogaNode node1 = new YogaNode(); + node1.MaxHeight = 100; + + node0.CopyStyle(node1); + Assert.AreEqual(100, node0.MaxHeight); + } + +#if !UNITY_EDITOR private void ForceGC() { GC.Collect(GC.MaxGeneration); GC.WaitForPendingFinalizers(); } -#if !UNITY_EDITOR [Test] public void TestDestructor() { ForceGC(); - int instanceCount = CSSNode.GetInstanceCount(); + int instanceCount = YogaNode.GetInstanceCount(); TestDestructorForGC(instanceCount); ForceGC(); - Assert.AreEqual(instanceCount, CSSNode.GetInstanceCount()); + Assert.AreEqual(instanceCount, YogaNode.GetInstanceCount()); } private void TestDestructorForGC(int instanceCount) { - CSSNode node = new CSSNode(); + YogaNode node = new YogaNode(); Assert.IsNotNull(node); - Assert.AreEqual(instanceCount + 1, CSSNode.GetInstanceCount()); + Assert.AreEqual(instanceCount + 1, YogaNode.GetInstanceCount()); node = null; } @@ -208,32 +257,32 @@ namespace Facebook.CSSLayout public void TestDestructorWithChildren() { ForceGC(); - int instanceCount = CSSNode.GetInstanceCount(); + int instanceCount = YogaNode.GetInstanceCount(); TestDestructorWithChildrenForGC1(instanceCount); ForceGC(); - Assert.AreEqual(instanceCount, CSSNode.GetInstanceCount()); + Assert.AreEqual(instanceCount, YogaNode.GetInstanceCount()); } private void TestDestructorWithChildrenForGC1(int instanceCount) { - CSSNode node = new CSSNode(); - Assert.AreEqual(instanceCount + 1, CSSNode.GetInstanceCount()); + YogaNode node = new YogaNode(); + Assert.AreEqual(instanceCount + 1, YogaNode.GetInstanceCount()); TestDestructorWithChildrenForGC2(node, instanceCount + 1); ForceGC(); - Assert.AreEqual(instanceCount + 2, CSSNode.GetInstanceCount()); + Assert.AreEqual(instanceCount + 2, YogaNode.GetInstanceCount()); TestDestructorWithChildrenForGC2(node, instanceCount + 2); ForceGC(); - Assert.AreEqual(instanceCount + 3, CSSNode.GetInstanceCount()); + Assert.AreEqual(instanceCount + 3, YogaNode.GetInstanceCount()); node = null; } - private void TestDestructorWithChildrenForGC2(CSSNode parent, int instanceCount) + private void TestDestructorWithChildrenForGC2(YogaNode parent, int instanceCount) { - CSSNode child = new CSSNode(); - Assert.AreEqual(instanceCount + 1, CSSNode.GetInstanceCount()); + YogaNode child = new YogaNode(); + Assert.AreEqual(instanceCount + 1, YogaNode.GetInstanceCount()); parent.Insert(0, child); child = null; @@ -243,21 +292,21 @@ namespace Facebook.CSSLayout public void TestParentDestructor() { ForceGC(); - int instanceCount = CSSNode.GetInstanceCount(); - CSSNode child = new CSSNode(); - Assert.AreEqual(instanceCount + 1, CSSNode.GetInstanceCount()); + int instanceCount = YogaNode.GetInstanceCount(); + YogaNode child = new YogaNode(); + Assert.AreEqual(instanceCount + 1, YogaNode.GetInstanceCount()); TestParentDestructorForGC(child, instanceCount + 1); ForceGC(); Assert.IsNull(child.Parent); - Assert.AreEqual(instanceCount + 1, CSSNode.GetInstanceCount()); + Assert.AreEqual(instanceCount + 1, YogaNode.GetInstanceCount()); } - private void TestParentDestructorForGC(CSSNode child, int instanceCount) + private void TestParentDestructorForGC(YogaNode child, int instanceCount) { - CSSNode parent = new CSSNode(); - Assert.AreEqual(instanceCount + 1, CSSNode.GetInstanceCount()); + YogaNode parent = new YogaNode(); + Assert.AreEqual(instanceCount + 1, YogaNode.GetInstanceCount()); parent.Insert(0, child); } @@ -265,22 +314,22 @@ namespace Facebook.CSSLayout public void TestClearWithChildDestructor() { ForceGC(); - int instanceCount = CSSNode.GetInstanceCount(); - CSSNode node = new CSSNode(); - Assert.AreEqual(instanceCount + 1, CSSNode.GetInstanceCount()); + int instanceCount = YogaNode.GetInstanceCount(); + YogaNode node = new YogaNode(); + Assert.AreEqual(instanceCount + 1, YogaNode.GetInstanceCount()); TestClearWithChildDestructorForGC(node, instanceCount + 1); ForceGC(); - Assert.AreEqual(instanceCount + 2, CSSNode.GetInstanceCount()); + Assert.AreEqual(instanceCount + 2, YogaNode.GetInstanceCount()); node.Clear(); Assert.AreEqual(0, node.Count); ForceGC(); - Assert.AreEqual(instanceCount + 1, CSSNode.GetInstanceCount()); + Assert.AreEqual(instanceCount + 1, YogaNode.GetInstanceCount()); } - private void TestClearWithChildDestructorForGC(CSSNode parent, int instanceCount) + private void TestClearWithChildDestructorForGC(YogaNode parent, int instanceCount) { - CSSNode child = new CSSNode(); - Assert.AreEqual(instanceCount + 1, CSSNode.GetInstanceCount()); + YogaNode child = new YogaNode(); + Assert.AreEqual(instanceCount + 1, YogaNode.GetInstanceCount()); parent.Insert(0, child); } @@ -288,20 +337,20 @@ namespace Facebook.CSSLayout public void TestMeasureFuncWithDestructor() { ForceGC(); - int instanceCount = CSSNode.GetInstanceCount(); - CSSNode parent = new CSSNode(); - Assert.AreEqual(instanceCount + 1, CSSNode.GetInstanceCount()); + int instanceCount = YogaNode.GetInstanceCount(); + YogaNode parent = new YogaNode(); + Assert.AreEqual(instanceCount + 1, YogaNode.GetInstanceCount()); TestMeasureFuncWithDestructorForGC(parent); ForceGC(); - Assert.AreEqual(instanceCount + 2, CSSNode.GetInstanceCount()); + Assert.AreEqual(instanceCount + 2, YogaNode.GetInstanceCount()); parent.CalculateLayout(); Assert.AreEqual(120, (int)parent.LayoutWidth); Assert.AreEqual(130, (int)parent.LayoutHeight); } - private void TestMeasureFuncWithDestructorForGC(CSSNode parent) + private void TestMeasureFuncWithDestructorForGC(YogaNode parent) { - CSSNode child = new CSSNode(); + YogaNode child = new YogaNode(); parent.Insert(0, child); child.SetMeasureFunction((_, width, widthMode, height, heightMode) => { return MeasureOutput.Make(120, 130); diff --git a/csharp/tests/Facebook.Yoga/test_macos.sh b/csharp/tests/Facebook.Yoga/test_macos.sh new file mode 100755 index 00000000..7df36893 --- /dev/null +++ b/csharp/tests/Facebook.Yoga/test_macos.sh @@ -0,0 +1,33 @@ +#!/bin/sh +if clang --version >/dev/null 2>&1; then true; else + echo "ERROR: Can't execute clang. You need to install Xcode and command line tools." + exit 1 +fi + +if mcs --version >/dev/null 2>&1; then true; else + echo "ERROR: Can't execute mcs. You need to install Mono from http://www.mono-project.com/download/ and re-login to apply PATH environment." + exit 1 +fi + +if mono --version >/dev/null 2>&1; then true; else + echo "ERROR: Can't execute mono64. You need to install Mono from http://www.mono-project.com/download/ and re-login to apply PATH environment." + exit 1 +fi + +cd "$( dirname "$0" )" + +NUNIT=NUnit-2.6.4/bin +if [ -d $NUNIT \ + -a -f $NUNIT/nunit-console.exe \ + -a -f $NUNIT/lib/nunit-console-runner.dll \ + -a -f $NUNIT/lib/nunit.core.dll \ + -a -f $NUNIT/lib/nunit.core.interfaces.dll \ + -a -f $NUNIT/lib/nunit.util.dll ]; then true; else + curl -L -O https://github.com/nunit/nunitv2/releases/download/2.6.4/NUnit-2.6.4.zip + unzip -qq NUnit-2.6.4.zip + rm NUnit-2.6.4.zip +fi + +clang -g -Wall -Wextra -dynamiclib -o libyoga.dylib -I../../.. ../../../yoga/*.c ../../Yoga/YGInterop.cpp +mcs -debug -t:library -r:$NUNIT/nunit.framework.dll -out:YogaTest.dll *.cs ../../../csharp/Facebook.Yoga/*cs +MONO_PATH=$NUNIT mono --arch=64 --debug $NUNIT/nunit-console.exe YogaTest.dll diff --git a/enums.py b/enums.py new file mode 100644 index 00000000..d2fc6dc0 --- /dev/null +++ b/enums.py @@ -0,0 +1,189 @@ +# 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. + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals +import os + +ENUMS = { + 'Direction': [ + 'Inherit', + 'LTR', + 'RTL', + ], + 'FlexDirection': [ + 'Column', + 'ColumnReverse', + 'Row', + 'RowReverse', + ], + 'Justify': [ + 'FlexStart', + 'Center', + 'FlexEnd', + 'SpaceBetween', + 'SpaceAround', + ], + 'Overflow': [ + 'Visible', + 'Hidden', + 'Scroll', + ], + 'Align': [ + 'Auto', + 'FlexStart', + 'Center', + 'FlexEnd', + 'Stretch', + ], + 'PositionType': [ + 'Relative', + 'Absolute', + ], + 'Wrap': [ + 'NoWrap', + 'Wrap', + ], + 'MeasureMode': [ + 'Undefined', + 'Exactly', + 'AtMost', + ], + 'Dimension': [ + 'Width', + 'Height', + ], + 'Edge': [ + 'Left', + 'Top', + 'Right', + 'Bottom', + 'Start', + 'End', + 'Horizontal', + 'Vertical', + 'All', + ], + 'LogLevel': [ + 'Error', + 'Warn', + 'Info', + 'Debug', + 'Verbose', + ], + 'ExperimentalFeature': [ + 'Rounding', + # Mimic web flex-basis behavior. + 'WebFlexBasis', + ], + 'PrintOptions': [ + ('Layout', 1), + ('Style', 2), + ('Children', 4), + ], +} + +LICENSE = """/** + * 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. + */ + +""" + +def to_java_upper(symbol): + symbol = str(symbol) + out = '' + for i in range(0, len(symbol)): + c = symbol[i] + if str.istitle(c) and i is not 0 and not str.istitle(symbol[i - 1]): + out += '_' + out += c.upper() + return out + + +root = os.path.dirname(__file__) + +# write out C header +with open(root + '/yoga/YGEnums.h', 'w') as f: + f.write(LICENSE) + f.write('#pragma once\n\n') + f.write('#include "YGMacros.h"\n\n') + f.write('YG_EXTERN_C_BEGIN\n\n') + for name, values in ENUMS.items(): + f.write('typedef enum YG%s {\n' % name) + for value in values: + if isinstance(value, tuple): + f.write(' YG%s%s = %d,\n' % (name, value[0], value[1])) + else: + f.write(' YG%s%s,\n' % (name, value)) + f.write(' YG%sCount,\n' % name) + f.write('} YG%s;\n' % name) + f.write('\n') + f.write('YG_EXTERN_C_END\n') + +# write out java files +for name, values in ENUMS.items(): + with open(root + '/java/com/facebook/yoga/Yoga%s.java' % name, 'w') as f: + f.write(LICENSE) + f.write('package com.facebook.yoga;\n\n') + f.write('import com.facebook.proguard.annotations.DoNotStrip;\n\n') + f.write('@DoNotStrip\n') + f.write('public enum Yoga%s {\n' % name) + if len(values) > 0: + for value in values: + if isinstance(value, tuple): + f.write(' %s(%d)' % (to_java_upper(value[0]), value[1])) + else: + f.write(' %s(%d)' % (to_java_upper(value), values.index(value))) + if values.index(value) is len(values) - 1: + f.write(';\n') + else: + f.write(',\n') + else: + f.write('__EMPTY(-1);') + f.write('\n') + f.write(' private int mIntValue;\n') + f.write('\n') + f.write(' Yoga%s(int intValue) {\n' % name) + f.write(' mIntValue = intValue;\n') + f.write(' }\n') + f.write('\n') + f.write(' public int intValue() {\n') + f.write(' return mIntValue;\n') + f.write(' }\n') + f.write('\n') + f.write(' public static Yoga%s fromInt(int value) {\n' % name) + f.write(' switch (value) {\n') + for value in values: + if isinstance(value, tuple): + f.write(' case %d: return %s;\n' % (value[1], to_java_upper(value[0]))) + else: + f.write(' case %d: return %s;\n' % (values.index(value), to_java_upper(value))) + f.write(' default: throw new IllegalArgumentException("Unkown enum value: " + value);\n') + f.write(' }\n') + f.write(' }\n') + f.write('}\n') + +# write out csharp files +for name, values in ENUMS.items(): + with open(root + '/csharp/Facebook.Yoga/Yoga%s.cs' % name, 'w') as f: + f.write(LICENSE) + f.write('namespace Facebook.Yoga\n{\n') + f.write(' public enum Yoga%s\n {\n' % name) + for value in values: + if isinstance(value, tuple): + f.write(' %s = %d,\n' % (value[0], value[1])) + else: + f.write(' %s,\n' % value) + f.write(' }\n') + f.write('}\n') diff --git a/format.sh b/format.sh index 01464ab2..c8affc49 100755 --- a/format.sh +++ b/format.sh @@ -29,7 +29,6 @@ clang-format \ SpaceAfterCStyleCast: true, \ UseTab: Never, \ }" "$@" \ - -i $(dirname $0)/CSSLayout/*.{h,c,cpp} \ - $(dirname $0)/tests/CSSLayoutTestUtils/*.{h,c,cpp} \ + -i $(dirname $0)/yoga/*.{h,c,cpp} \ $(dirname $0)/benchmarks/*.{h,c,cpp} \ $(dirname $0)/java/jni/*.{h,c,cpp} diff --git a/gentest/fixtures/CSSLayoutAbsolutePositionTest.html b/gentest/fixtures/YGAbsolutePositionTest.html similarity index 73% rename from gentest/fixtures/CSSLayoutAbsolutePositionTest.html rename to gentest/fixtures/YGAbsolutePositionTest.html index bb6e5673..8530e045 100644 --- a/gentest/fixtures/CSSLayoutAbsolutePositionTest.html +++ b/gentest/fixtures/YGAbsolutePositionTest.html @@ -15,7 +15,12 @@
-
+
+ +
+
+
+
diff --git a/gentest/fixtures/CSSLayoutAlignContentTest.html b/gentest/fixtures/YGAlignContentTest.html similarity index 100% rename from gentest/fixtures/CSSLayoutAlignContentTest.html rename to gentest/fixtures/YGAlignContentTest.html diff --git a/gentest/fixtures/CSSLayoutAlignItemsTest.html b/gentest/fixtures/YGAlignItemsTest.html similarity index 100% rename from gentest/fixtures/CSSLayoutAlignItemsTest.html rename to gentest/fixtures/YGAlignItemsTest.html diff --git a/gentest/fixtures/CSSLayoutAlignSelfTest.html b/gentest/fixtures/YGAlignSelfTest.html similarity index 100% rename from gentest/fixtures/CSSLayoutAlignSelfTest.html rename to gentest/fixtures/YGAlignSelfTest.html diff --git a/gentest/fixtures/CSSLayoutBorderTest.html b/gentest/fixtures/YGBorderTest.html similarity index 100% rename from gentest/fixtures/CSSLayoutBorderTest.html rename to gentest/fixtures/YGBorderTest.html diff --git a/gentest/fixtures/CSSLayoutFlexDirectionTest.html b/gentest/fixtures/YGFlexDirectionTest.html similarity index 100% rename from gentest/fixtures/CSSLayoutFlexDirectionTest.html rename to gentest/fixtures/YGFlexDirectionTest.html diff --git a/gentest/fixtures/CSSLayoutFlexTest.html b/gentest/fixtures/YGFlexTest.html similarity index 89% rename from gentest/fixtures/CSSLayoutFlexTest.html rename to gentest/fixtures/YGFlexTest.html index 5689a6e7..30da202e 100644 --- a/gentest/fixtures/CSSLayoutFlexTest.html +++ b/gentest/fixtures/YGFlexTest.html @@ -29,3 +29,9 @@
+ +
+
+
+
+
diff --git a/gentest/fixtures/CSSLayoutFlexWrapTest.html b/gentest/fixtures/YGFlexWrapTest.html similarity index 100% rename from gentest/fixtures/CSSLayoutFlexWrapTest.html rename to gentest/fixtures/YGFlexWrapTest.html diff --git a/gentest/fixtures/CSSLayoutJustifyContentTest.html b/gentest/fixtures/YGJustifyContentTest.html similarity index 100% rename from gentest/fixtures/CSSLayoutJustifyContentTest.html rename to gentest/fixtures/YGJustifyContentTest.html diff --git a/gentest/fixtures/CSSLayoutMarginTest.html b/gentest/fixtures/YGMarginTest.html similarity index 100% rename from gentest/fixtures/CSSLayoutMarginTest.html rename to gentest/fixtures/YGMarginTest.html diff --git a/gentest/fixtures/CSSLayoutMinMaxDimensionTest.html b/gentest/fixtures/YGMinMaxDimensionTest.html similarity index 74% rename from gentest/fixtures/CSSLayoutMinMaxDimensionTest.html rename to gentest/fixtures/YGMinMaxDimensionTest.html index d2925c04..6e469707 100644 --- a/gentest/fixtures/CSSLayoutMinMaxDimensionTest.html +++ b/gentest/fixtures/YGMinMaxDimensionTest.html @@ -29,3 +29,15 @@
+ +
+
+
+
+
+ +
+
+
+
+
diff --git a/gentest/fixtures/CSSLayoutPaddingTest.html b/gentest/fixtures/YGPaddingTest.html similarity index 77% rename from gentest/fixtures/CSSLayoutPaddingTest.html rename to gentest/fixtures/YGPaddingTest.html index 1f679780..f1616fe4 100644 --- a/gentest/fixtures/CSSLayoutPaddingTest.html +++ b/gentest/fixtures/YGPaddingTest.html @@ -16,3 +16,7 @@
+ +
+
+
diff --git a/gentest/fixtures/YGRoundingTest.html b/gentest/fixtures/YGRoundingTest.html new file mode 100644 index 00000000..c66e6b16 --- /dev/null +++ b/gentest/fixtures/YGRoundingTest.html @@ -0,0 +1,64 @@ +
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+
diff --git a/gentest/gentest-cpp.js b/gentest/gentest-cpp.js index dc0427b9..0333dd7c 100644 --- a/gentest/gentest-cpp.js +++ b/gentest/gentest-cpp.js @@ -7,6 +7,10 @@ * of patent rights can be found in the PATENTS file in the same directory. */ +function toFloatString(n) { + return n + (Number(n) == n && n % 1 !== 0 ? 'f' : ''); +} + var CPPEmitter = function() { Emitter.call(this, 'cpp', ' '); }; @@ -16,26 +20,41 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, { emitPrologue:{value:function() { this.push([ - '#include ', + '#include ', '#include ', '', ]); }}, - emitTestPrologue:{value:function(name) { - this.push('TEST(CSSLayoutTest, ' + name + ') {'); + emitTestPrologue:{value:function(name, experiments) { + this.push('TEST(YogaTest, ' + name + ') {'); this.pushIndent(); + + if (experiments.length > 0) { + for (var i in experiments) { + this.push('YGSetExperimentalFeatureEnabled(YGExperimentalFeature' + experiments[i] +', true);'); + } + this.push(''); + } }}, emitTestTreePrologue:{value:function(nodeName) { - this.push('const CSSNodeRef ' + nodeName + ' = CSSNodeNew();'); + this.push('const YGNodeRef ' + nodeName + ' = YGNodeNew();'); }}, - emitTestEpilogue:{value:function() { + emitTestEpilogue:{value:function(experiments) { this.push([ '', - 'CSSNodeFreeRecursive(root);', + 'YGNodeFreeRecursive(root);', ]); + + if (experiments.length > 0) { + this.push(''); + for (var i in experiments) { + this.push('YGSetExperimentalFeatureEnabled(YGExperimentalFeature' + experiments[i] +', false);'); + } + } + this.popIndent(); this.push([ '}', @@ -47,157 +66,157 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, { }}, AssertEQ:{value:function(v0, v1) { - this.push('ASSERT_EQ(' + v0 + ', ' + v1 + ');'); + this.push('ASSERT_FLOAT_EQ(' + toFloatString(v0) + ', ' + v1 + ');'); }}, - CSSAlignAuto:{value:'CSSAlignAuto'}, - CSSAlignCenter:{value:'CSSAlignCenter'}, - CSSAlignFlexEnd:{value:'CSSAlignFlexEnd'}, - CSSAlignFlexStart:{value:'CSSAlignFlexStart'}, - CSSAlignStretch:{value:'CSSAlignStretch'}, + YGAlignAuto:{value:'YGAlignAuto'}, + YGAlignCenter:{value:'YGAlignCenter'}, + YGAlignFlexEnd:{value:'YGAlignFlexEnd'}, + YGAlignFlexStart:{value:'YGAlignFlexStart'}, + YGAlignStretch:{value:'YGAlignStretch'}, - CSSDirectionInherit:{value:'CSSDirectionInherit'}, - CSSDirectionLTR:{value:'CSSDirectionLTR'}, - CSSDirectionRTL:{value:'CSSDirectionRTL'}, + YGDirectionInherit:{value:'YGDirectionInherit'}, + YGDirectionLTR:{value:'YGDirectionLTR'}, + YGDirectionRTL:{value:'YGDirectionRTL'}, - CSSEdgeBottom:{value:'CSSEdgeBottom'}, - CSSEdgeEnd:{value:'CSSEdgeEnd'}, - CSSEdgeLeft:{value:'CSSEdgeLeft'}, - CSSEdgeRight:{value:'CSSEdgeRight'}, - CSSEdgeStart:{value:'CSSEdgeStart'}, - CSSEdgeTop:{value:'CSSEdgeTop'}, + YGEdgeBottom:{value:'YGEdgeBottom'}, + YGEdgeEnd:{value:'YGEdgeEnd'}, + YGEdgeLeft:{value:'YGEdgeLeft'}, + YGEdgeRight:{value:'YGEdgeRight'}, + YGEdgeStart:{value:'YGEdgeStart'}, + YGEdgeTop:{value:'YGEdgeTop'}, - CSSFlexDirectionColumn:{value:'CSSFlexDirectionColumn'}, - CSSFlexDirectionColumnReverse:{value:'CSSFlexDirectionColumnReverse'}, - CSSFlexDirectionRow:{value:'CSSFlexDirectionRow'}, - CSSFlexDirectionRowReverse:{value:'CSSFlexDirectionRowReverse'}, + YGFlexDirectionColumn:{value:'YGFlexDirectionColumn'}, + YGFlexDirectionColumnReverse:{value:'YGFlexDirectionColumnReverse'}, + YGFlexDirectionRow:{value:'YGFlexDirectionRow'}, + YGFlexDirectionRowReverse:{value:'YGFlexDirectionRowReverse'}, - CSSJustifyCenter:{value:'CSSJustifyCenter'}, - CSSJustifyFlexEnd:{value:'CSSJustifyFlexEnd'}, - CSSJustifyFlexStart:{value:'CSSJustifyFlexStart'}, - CSSJustifySpaceAround:{value:'CSSJustifySpaceAround'}, - CSSJustifySpaceBetween:{value:'CSSJustifySpaceBetween'}, + YGJustifyCenter:{value:'YGJustifyCenter'}, + YGJustifyFlexEnd:{value:'YGJustifyFlexEnd'}, + YGJustifyFlexStart:{value:'YGJustifyFlexStart'}, + YGJustifySpaceAround:{value:'YGJustifySpaceAround'}, + YGJustifySpaceBetween:{value:'YGJustifySpaceBetween'}, - CSSOverflowHidden:{value:'CSSOverflowHidden'}, - CSSOverflowVisible:{value:'CSSOverflowVisible'}, + YGOverflowHidden:{value:'YGOverflowHidden'}, + YGOverflowVisible:{value:'YGOverflowVisible'}, - CSSPositionTypeAbsolute:{value:'CSSPositionTypeAbsolute'}, - CSSPositionTypeRelative:{value:'CSSPositionTypeRelative'}, + YGPositionTypeAbsolute:{value:'YGPositionTypeAbsolute'}, + YGPositionTypeRelative:{value:'YGPositionTypeRelative'}, - CSSWrapTypeNoWrap:{value:'CSSWrapTypeNoWrap'}, - CSSWrapTypeWrap:{value:'CSSWrapTypeWrap'}, + YGWrapNoWrap:{value:'YGWrapNoWrap'}, + YGWrapWrap:{value:'YGWrapWrap'}, - CSSUndefined:{value:'CSSUndefined'}, + YGUndefined:{value:'YGUndefined'}, - CSSNodeCalculateLayout:{value:function(node, dir) { - this.push('CSSNodeCalculateLayout(' + node + ', CSSUndefined, CSSUndefined, ' + dir + ');'); + YGNodeCalculateLayout:{value:function(node, dir) { + this.push('YGNodeCalculateLayout(' + node + ', YGUndefined, YGUndefined, ' + dir + ');'); }}, - CSSNodeInsertChild:{value:function(parentName, nodeName, index) { - this.push('CSSNodeInsertChild(' + parentName + ', ' + nodeName + ', ' + index + ');'); + YGNodeInsertChild:{value:function(parentName, nodeName, index) { + this.push('YGNodeInsertChild(' + parentName + ', ' + nodeName + ', ' + index + ');'); }}, - CSSNodeLayoutGetLeft:{value:function(nodeName) { - return 'CSSNodeLayoutGetLeft(' + nodeName + ')'; + YGNodeLayoutGetLeft:{value:function(nodeName) { + return 'YGNodeLayoutGetLeft(' + nodeName + ')'; }}, - CSSNodeLayoutGetTop:{value:function(nodeName) { - return 'CSSNodeLayoutGetTop(' + nodeName + ')'; + YGNodeLayoutGetTop:{value:function(nodeName) { + return 'YGNodeLayoutGetTop(' + nodeName + ')'; }}, - CSSNodeLayoutGetWidth:{value:function(nodeName) { - return 'CSSNodeLayoutGetWidth(' + nodeName + ')'; + YGNodeLayoutGetWidth:{value:function(nodeName) { + return 'YGNodeLayoutGetWidth(' + nodeName + ')'; }}, - CSSNodeLayoutGetHeight:{value:function(nodeName) { - return 'CSSNodeLayoutGetHeight(' + nodeName + ')'; + YGNodeLayoutGetHeight:{value:function(nodeName) { + return 'YGNodeLayoutGetHeight(' + nodeName + ')'; }}, - CSSNodeStyleSetAlignContent:{value:function(nodeName, value) { - this.push('CSSNodeStyleSetAlignContent(' + nodeName + ', ' + value + ');'); + YGNodeStyleSetAlignContent:{value:function(nodeName, value) { + this.push('YGNodeStyleSetAlignContent(' + nodeName + ', ' + value + ');'); }}, - CSSNodeStyleSetAlignItems:{value:function(nodeName, value) { - this.push('CSSNodeStyleSetAlignItems(' + nodeName + ', ' + value + ');'); + YGNodeStyleSetAlignItems:{value:function(nodeName, value) { + this.push('YGNodeStyleSetAlignItems(' + nodeName + ', ' + value + ');'); }}, - CSSNodeStyleSetAlignSelf:{value:function(nodeName, value) { - this.push('CSSNodeStyleSetAlignSelf(' + nodeName + ', ' + value + ');'); + YGNodeStyleSetAlignSelf:{value:function(nodeName, value) { + this.push('YGNodeStyleSetAlignSelf(' + nodeName + ', ' + value + ');'); }}, - CSSNodeStyleSetBorder:{value:function(nodeName, edge, value) { - this.push('CSSNodeStyleSetBorder(' + nodeName + ', ' + edge + ', ' + value + ');'); + YGNodeStyleSetBorder:{value:function(nodeName, edge, value) { + this.push('YGNodeStyleSetBorder(' + nodeName + ', ' + edge + ', ' + toFloatString(value) + ');'); }}, - CSSNodeStyleSetDirection:{value:function(nodeName, value) { - this.push('CSSNodeStyleSetDirection(' + nodeName + ', ' + value + ');'); + YGNodeStyleSetDirection:{value:function(nodeName, value) { + this.push('YGNodeStyleSetDirection(' + nodeName + ', ' + value + ');'); }}, - CSSNodeStyleSetFlexBasis:{value:function(nodeName, value) { - this.push('CSSNodeStyleSetFlexBasis(' + nodeName + ', ' + value + ');'); + YGNodeStyleSetFlexBasis:{value:function(nodeName, value) { + this.push('YGNodeStyleSetFlexBasis(' + nodeName + ', ' + toFloatString(value) + ');'); }}, - CSSNodeStyleSetFlexDirection:{value:function(nodeName, value) { - this.push('CSSNodeStyleSetFlexDirection(' + nodeName + ', ' + value + ');'); + YGNodeStyleSetFlexDirection:{value:function(nodeName, value) { + this.push('YGNodeStyleSetFlexDirection(' + nodeName + ', ' + value + ');'); }}, - CSSNodeStyleSetFlexGrow:{value:function(nodeName, value) { - this.push('CSSNodeStyleSetFlexGrow(' + nodeName + ', ' + value + ');'); + YGNodeStyleSetFlexGrow:{value:function(nodeName, value) { + this.push('YGNodeStyleSetFlexGrow(' + nodeName + ', ' + toFloatString(value) + ');'); }}, - CSSNodeStyleSetFlexShrink:{value:function(nodeName, value) { - this.push('CSSNodeStyleSetFlexShrink(' + nodeName + ', ' + value + ');'); + YGNodeStyleSetFlexShrink:{value:function(nodeName, value) { + this.push('YGNodeStyleSetFlexShrink(' + nodeName + ', ' + toFloatString(value) + ');'); }}, - CSSNodeStyleSetFlexWrap:{value:function(nodeName, value) { - this.push('CSSNodeStyleSetFlexWrap(' + nodeName + ', ' + value + ');'); + YGNodeStyleSetFlexWrap:{value:function(nodeName, value) { + this.push('YGNodeStyleSetFlexWrap(' + nodeName + ', ' + value + ');'); }}, - CSSNodeStyleSetHeight:{value:function(nodeName, value) { - this.push('CSSNodeStyleSetHeight(' + nodeName + ', ' + value + ');'); + YGNodeStyleSetHeight:{value:function(nodeName, value) { + this.push('YGNodeStyleSetHeight(' + nodeName + ', ' + toFloatString(value) + ');'); }}, - CSSNodeStyleSetJustifyContent:{value:function(nodeName, value) { - this.push('CSSNodeStyleSetJustifyContent(' + nodeName + ', ' + value + ');'); + YGNodeStyleSetJustifyContent:{value:function(nodeName, value) { + this.push('YGNodeStyleSetJustifyContent(' + nodeName + ', ' + value + ');'); }}, - CSSNodeStyleSetMargin:{value:function(nodeName, edge, value) { - this.push('CSSNodeStyleSetMargin(' + nodeName + ', ' + edge + ', ' + value + ');'); + YGNodeStyleSetMargin:{value:function(nodeName, edge, value) { + this.push('YGNodeStyleSetMargin(' + nodeName + ', ' + edge + ', ' + toFloatString(value) + ');'); }}, - CSSNodeStyleSetMaxHeight:{value:function(nodeName, value) { - this.push('CSSNodeStyleSetMaxHeight(' + nodeName + ', ' + value + ');'); + YGNodeStyleSetMaxHeight:{value:function(nodeName, value) { + this.push('YGNodeStyleSetMaxHeight(' + nodeName + ', ' + toFloatString(value) + ');'); }}, - CSSNodeStyleSetMaxWidth:{value:function(nodeName, value) { - this.push('CSSNodeStyleSetMaxWidth(' + nodeName + ', ' + value + ');'); + YGNodeStyleSetMaxWidth:{value:function(nodeName, value) { + this.push('YGNodeStyleSetMaxWidth(' + nodeName + ', ' + toFloatString(value) + ');'); }}, - CSSNodeStyleSetMinHeight:{value:function(nodeName, value) { - this.push('CSSNodeStyleSetMinHeight(' + nodeName + ', ' + value + ');'); + YGNodeStyleSetMinHeight:{value:function(nodeName, value) { + this.push('YGNodeStyleSetMinHeight(' + nodeName + ', ' + toFloatString(value) + ');'); }}, - CSSNodeStyleSetMinWidth:{value:function(nodeName, value) { - this.push('CSSNodeStyleSetMinWidth(' + nodeName + ', ' + value + ');'); + YGNodeStyleSetMinWidth:{value:function(nodeName, value) { + this.push('YGNodeStyleSetMinWidth(' + nodeName + ', ' + toFloatString(value) + ');'); }}, - CSSNodeStyleSetOverflow:{value:function(nodeName, value) { - this.push('CSSNodeStyleSetOverflow(' + nodeName + ', ' + value + ');'); + YGNodeStyleSetOverflow:{value:function(nodeName, value) { + this.push('YGNodeStyleSetOverflow(' + nodeName + ', ' + value + ');'); }}, - CSSNodeStyleSetPadding:{value:function(nodeName, edge, value) { - this.push('CSSNodeStyleSetPadding(' + nodeName + ', ' + edge + ', ' + value + ');'); + YGNodeStyleSetPadding:{value:function(nodeName, edge, value) { + this.push('YGNodeStyleSetPadding(' + nodeName + ', ' + edge + ', ' + toFloatString(value) + ');'); }}, - CSSNodeStyleSetPosition:{value:function(nodeName, edge, value) { - this.push('CSSNodeStyleSetPosition(' + nodeName + ', ' + edge + ', ' + value + ');'); + YGNodeStyleSetPosition:{value:function(nodeName, edge, value) { + this.push('YGNodeStyleSetPosition(' + nodeName + ', ' + edge + ', ' + toFloatString(value) + ');'); }}, - CSSNodeStyleSetPositionType:{value:function(nodeName, value) { - this.push('CSSNodeStyleSetPositionType(' + nodeName + ', ' + value + ');'); + YGNodeStyleSetPositionType:{value:function(nodeName, value) { + this.push('YGNodeStyleSetPositionType(' + nodeName + ', ' + value + ');'); }}, - CSSNodeStyleSetWidth:{value:function(nodeName, value) { - this.push('CSSNodeStyleSetWidth(' + nodeName + ', ' + value + ');'); + YGNodeStyleSetWidth:{value:function(nodeName, value) { + this.push('YGNodeStyleSetWidth(' + nodeName + ', ' + toFloatString(value) + ');'); }}, }); diff --git a/gentest/gentest-cs.js b/gentest/gentest-cs.js index c2046ef0..0dbbb498 100644 --- a/gentest/gentest-cs.js +++ b/gentest/gentest-cs.js @@ -19,30 +19,44 @@ CSEmitter.prototype = Object.create(Emitter.prototype, { 'using System;', 'using NUnit.Framework;', '', - 'namespace Facebook.CSSLayout', + 'namespace Facebook.Yoga', '{', ]); this.pushIndent(); this.push([ '[TestFixture]', - 'public class CSSNodeLayoutTest', + 'public class YogaTest', '{', ]); this.pushIndent(); }}, - emitTestPrologue:{value:function(name) { + emitTestPrologue:{value:function(name, experiments) { this.push('[Test]'); this.push('public void Test_' + name + '()'); this.push('{'); this.pushIndent(); + + if (experiments.length > 0) { + for (var i in experiments) { + this.push('YogaNode.SetExperimentalFeatureEnabled(YogaExperimentalFeature.' + experiments[i] +', true);'); + } + this.push(''); + } }}, emitTestTreePrologue:{value:function(nodeName) { - this.push('CSSNode ' + nodeName + ' = new CSSNode();'); + this.push('YogaNode ' + nodeName + ' = new YogaNode();'); }}, - emitTestEpilogue:{value:function() { + emitTestEpilogue:{value:function(experiments) { + if (experiments.length > 0) { + this.push(''); + for (var i in experiments) { + this.push('YogaNode.SetExperimentalFeatureEnabled(YogaExperimentalFeature.' + experiments[i] +', false);'); + } + } + this.popIndent(); this.push([ '}', @@ -61,158 +75,158 @@ CSEmitter.prototype = Object.create(Emitter.prototype, { }}, AssertEQ:{value:function(v0, v1) { - this.push('Assert.AreEqual(' + v0 + ', ' + v1 + ');'); + this.push('Assert.AreEqual(' + v0 + 'f, ' + v1 + ');'); }}, - CSSAlignAuto:{value:'CSSAlign.Auto'}, - CSSAlignCenter:{value:'CSSAlign.Center'}, - CSSAlignFlexEnd:{value:'CSSAlign.FlexEnd'}, - CSSAlignFlexStart:{value:'CSSAlign.FlexStart'}, - CSSAlignStretch:{value:'CSSAlign.Stretch'}, + YGAlignAuto:{value:'YogaAlign.Auto'}, + YGAlignCenter:{value:'YogaAlign.Center'}, + YGAlignFlexEnd:{value:'YogaAlign.FlexEnd'}, + YGAlignFlexStart:{value:'YogaAlign.FlexStart'}, + YGAlignStretch:{value:'YogaAlign.Stretch'}, - CSSDirectionInherit:{value:'CSSDirection.Inherit'}, - CSSDirectionLTR:{value:'CSSDirection.LeftToRight'}, - CSSDirectionRTL:{value:'CSSDirection.RightToLeft'}, + YGDirectionInherit:{value:'YogaDirection.Inherit'}, + YGDirectionLTR:{value:'YogaDirection.LTR'}, + YGDirectionRTL:{value:'YogaDirection.RTL'}, - CSSEdgeBottom:{value:'CSSEdge.Bottom'}, - CSSEdgeEnd:{value:'CSSEdge.End'}, - CSSEdgeLeft:{value:'CSSEdge.Left'}, - CSSEdgeRight:{value:'CSSEdge.Right'}, - CSSEdgeStart:{value:'CSSEdge.Start'}, - CSSEdgeTop:{value:'CSSEdge.Top'}, + YGEdgeBottom:{value:'YogaEdge.Bottom'}, + YGEdgeEnd:{value:'YogaEdge.End'}, + YGEdgeLeft:{value:'YogaEdge.Left'}, + YGEdgeRight:{value:'YogaEdge.Right'}, + YGEdgeStart:{value:'YogaEdge.Start'}, + YGEdgeTop:{value:'YogaEdge.Top'}, - CSSFlexDirectionColumn:{value:'CSSFlexDirection.Column'}, - CSSFlexDirectionColumnReverse:{value:'CSSFlexDirection.ColumnReverse'}, - CSSFlexDirectionRow:{value:'CSSFlexDirection.Row'}, - CSSFlexDirectionRowReverse:{value:'CSSFlexDirection.RowReverse'}, + YGFlexDirectionColumn:{value:'YogaFlexDirection.Column'}, + YGFlexDirectionColumnReverse:{value:'YogaFlexDirection.ColumnReverse'}, + YGFlexDirectionRow:{value:'YogaFlexDirection.Row'}, + YGFlexDirectionRowReverse:{value:'YogaFlexDirection.RowReverse'}, - CSSJustifyCenter:{value:'CSSJustify.Center'}, - CSSJustifyFlexEnd:{value:'CSSJustify.FlexEnd'}, - CSSJustifyFlexStart:{value:'CSSJustify.FlexStart'}, - CSSJustifySpaceAround:{value:'CSSJustify.SpaceAround'}, - CSSJustifySpaceBetween:{value:'CSSJustify.SpaceBetween'}, + YGJustifyCenter:{value:'YogaJustify.Center'}, + YGJustifyFlexEnd:{value:'YogaJustify.FlexEnd'}, + YGJustifyFlexStart:{value:'YogaJustify.FlexStart'}, + YGJustifySpaceAround:{value:'YogaJustify.SpaceAround'}, + YGJustifySpaceBetween:{value:'YogaJustify.SpaceBetween'}, - CSSOverflowHidden:{value:'CSSOverflow.Hidden'}, - CSSOverflowVisible:{value:'CSSOverflow.Visible'}, + YGOverflowHidden:{value:'YogaOverflow.Hidden'}, + YGOverflowVisible:{value:'YogaOverflow.Visible'}, - CSSPositionTypeAbsolute:{value:'CSSPositionType.Absolute'}, - CSSPositionTypeRelative:{value:'CSSPositionType.Relative'}, + YGPositionTypeAbsolute:{value:'YogaPositionType.Absolute'}, + YGPositionTypeRelative:{value:'YogaPositionType.Relative'}, - CSSUndefined:{value:'CSSConstants.Undefined'}, + YGUndefined:{value:'YogaConstants.Undefined'}, - CSSWrapTypeNoWrap:{value:'CSSWrap.NoWrap'}, - CSSWrapTypeWrap:{value:'CSSWrap.Wrap'}, + YGWrapNoWrap:{value:'YogaWrap.NoWrap'}, + YGWrapWrap:{value:'YogaWrap.Wrap'}, - CSSNodeCalculateLayout:{value:function(node, dir) { + YGNodeCalculateLayout:{value:function(node, dir) { this.push(node + '.StyleDirection = ' + dir + ';'); this.push(node + '.CalculateLayout();'); }}, - CSSNodeInsertChild:{value:function(parentName, nodeName, index) { + YGNodeInsertChild:{value:function(parentName, nodeName, index) { this.push(parentName + '.Insert(' + index + ', ' + nodeName + ');'); }}, - CSSNodeLayoutGetLeft:{value:function(nodeName) { + YGNodeLayoutGetLeft:{value:function(nodeName) { return nodeName + '.LayoutX'; }}, - CSSNodeLayoutGetTop:{value:function(nodeName) { + YGNodeLayoutGetTop:{value:function(nodeName) { return nodeName + '.LayoutY'; }}, - CSSNodeLayoutGetWidth:{value:function(nodeName) { + YGNodeLayoutGetWidth:{value:function(nodeName) { return nodeName + '.LayoutWidth'; }}, - CSSNodeLayoutGetHeight:{value:function(nodeName) { + YGNodeLayoutGetHeight:{value:function(nodeName) { return nodeName + '.LayoutHeight'; }}, - CSSNodeStyleSetAlignContent:{value:function(nodeName, value) { + YGNodeStyleSetAlignContent:{value:function(nodeName, value) { this.push(nodeName + '.AlignContent = ' + value + ';'); }}, - CSSNodeStyleSetAlignItems:{value:function(nodeName, value) { + YGNodeStyleSetAlignItems:{value:function(nodeName, value) { this.push(nodeName + '.AlignItems = ' + value + ';'); }}, - CSSNodeStyleSetAlignSelf:{value:function(nodeName, value) { + YGNodeStyleSetAlignSelf:{value:function(nodeName, value) { this.push(nodeName + '.AlignSelf = ' + value + ';'); }}, - CSSNodeStyleSetBorder:{value:function(nodeName, edge, value) { - this.push(nodeName + '.SetBorder(' + edge + ', ' + value + ');'); + YGNodeStyleSetBorder:{value:function(nodeName, edge, value) { + this.push(nodeName + '.SetBorder(' + edge + ', ' + value + 'f);'); }}, - CSSNodeStyleSetDirection:{value:function(nodeName, value) { + YGNodeStyleSetDirection:{value:function(nodeName, value) { this.push(nodeName + '.StyleDirection = ' + value + ';'); }}, - CSSNodeStyleSetFlexBasis:{value:function(nodeName, value) { - this.push(nodeName + '.FlexBasis = ' + value + ';'); + YGNodeStyleSetFlexBasis:{value:function(nodeName, value) { + this.push(nodeName + '.FlexBasis = ' + value + 'f;'); }}, - CSSNodeStyleSetFlexDirection:{value:function(nodeName, value) { + YGNodeStyleSetFlexDirection:{value:function(nodeName, value) { this.push(nodeName + '.FlexDirection = ' + value + ';'); }}, - CSSNodeStyleSetFlexGrow:{value:function(nodeName, value) { - this.push(nodeName + '.FlexGrow = ' + value + ';'); + YGNodeStyleSetFlexGrow:{value:function(nodeName, value) { + this.push(nodeName + '.FlexGrow = ' + value + 'f;'); }}, - CSSNodeStyleSetFlexShrink:{value:function(nodeName, value) { - this.push(nodeName + '.FlexShrink = ' + value + ';'); + YGNodeStyleSetFlexShrink:{value:function(nodeName, value) { + this.push(nodeName + '.FlexShrink = ' + value + 'f;'); }}, - CSSNodeStyleSetFlexWrap:{value:function(nodeName, value) { + YGNodeStyleSetFlexWrap:{value:function(nodeName, value) { this.push(nodeName + '.Wrap = ' + value + ';'); }}, - CSSNodeStyleSetHeight:{value:function(nodeName, value) { - this.push(nodeName + '.StyleHeight = ' + value + ';'); + YGNodeStyleSetHeight:{value:function(nodeName, value) { + this.push(nodeName + '.Height = ' + value + 'f;'); }}, - CSSNodeStyleSetJustifyContent:{value:function(nodeName, value) { + YGNodeStyleSetJustifyContent:{value:function(nodeName, value) { this.push(nodeName + '.JustifyContent = ' + value + ';'); }}, - CSSNodeStyleSetMargin:{value:function(nodeName, edge, value) { - this.push(nodeName + '.SetMargin(' + edge + ', ' + value + ');'); + YGNodeStyleSetMargin:{value:function(nodeName, edge, value) { + this.push(nodeName + '.SetMargin(' + edge + ', ' + value + 'f);'); }}, - CSSNodeStyleSetMaxHeight:{value:function(nodeName, value) { - this.push(nodeName + '.StyleMaxHeight = ' + value + ';'); + YGNodeStyleSetMaxHeight:{value:function(nodeName, value) { + this.push(nodeName + '.MaxHeight = ' + value + 'f;'); }}, - CSSNodeStyleSetMaxWidth:{value:function(nodeName, value) { - this.push(nodeName + '.StyleMaxWidth = ' + value + ';'); + YGNodeStyleSetMaxWidth:{value:function(nodeName, value) { + this.push(nodeName + '.MaxWidth = ' + value + 'f;'); }}, - CSSNodeStyleSetMinHeight:{value:function(nodeName, value) { - this.push(nodeName + '.StyleMinHeight = ' + value + ';'); + YGNodeStyleSetMinHeight:{value:function(nodeName, value) { + this.push(nodeName + '.MinHeight = ' + value + 'f;'); }}, - CSSNodeStyleSetMinWidth:{value:function(nodeName, value) { - this.push(nodeName + '.StyleMinWidth = ' + value + ';'); + YGNodeStyleSetMinWidth:{value:function(nodeName, value) { + this.push(nodeName + '.MinWidth = ' + value + 'f;'); }}, - CSSNodeStyleSetOverflow:{value:function(nodeName, value) { + YGNodeStyleSetOverflow:{value:function(nodeName, value) { this.push(nodeName + '.Overflow = ' + value + ';'); }}, - CSSNodeStyleSetPadding:{value:function(nodeName, edge, value) { - this.push(nodeName + '.SetPadding(' + edge + ', ' + value + ');'); + YGNodeStyleSetPadding:{value:function(nodeName, edge, value) { + this.push(nodeName + '.SetPadding(' + edge + ', ' + value + 'f);'); }}, - CSSNodeStyleSetPosition:{value:function(nodeName, edge, value) { - this.push(nodeName + '.SetPosition(' + edge + ', ' + value + ');'); + YGNodeStyleSetPosition:{value:function(nodeName, edge, value) { + this.push(nodeName + '.SetPosition(' + edge + ', ' + value + 'f);'); }}, - CSSNodeStyleSetPositionType:{value:function(nodeName, value) { + YGNodeStyleSetPositionType:{value:function(nodeName, value) { this.push(nodeName + '.PositionType = ' + value + ';'); }}, - CSSNodeStyleSetWidth:{value:function(nodeName, value) { - this.push(nodeName + '.StyleWidth = ' + value + ';'); + YGNodeStyleSetWidth:{value:function(nodeName, value) { + this.push(nodeName + '.Width = ' + value + 'f;'); }}, }); diff --git a/gentest/gentest-java.js b/gentest/gentest-java.js index f1dbb06b..7034c617 100644 --- a/gentest/gentest-java.js +++ b/gentest/gentest-java.js @@ -11,33 +11,59 @@ var JavaEmitter = function() { Emitter.call(this, 'java', ' '); }; +function toJavaUpper(symbol) { + var out = ''; + for (var i = 0; i < symbol.length; i++) { + var c = symbol[i]; + if (c == c.toUpperCase() && i != 0 && symbol[i - 1] != symbol[i - 1].toUpperCase()) { + out += '_'; + } + out += c.toUpperCase(); + } + return out; +} + JavaEmitter.prototype = Object.create(Emitter.prototype, { constructor:{value:JavaEmitter}, emitPrologue:{value:function() { this.push([ - 'package com.facebook.csslayout;', + 'package com.facebook.yoga;', '', 'import org.junit.Test;', '', 'import static org.junit.Assert.assertEquals;', '', - 'public class CSSNodeLayoutTest {', + 'public class YogaTest {', ]); this.pushIndent(); }}, - emitTestPrologue:{value:function(name) { + emitTestPrologue:{value:function(name, experiments) { this.push('@Test'); this.push('public void test_' + name + '() {'); this.pushIndent(); + + if (experiments.length > 0) { + for (var i in experiments) { + this.push('YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.' + toJavaUpper(experiments[i]) +', true);'); + } + this.push(''); + } }}, emitTestTreePrologue:{value:function(nodeName) { - this.push('final CSSNode ' + nodeName + ' = new CSSNode();'); + this.push('final YogaNode ' + nodeName + ' = new YogaNode();'); }}, - emitTestEpilogue:{value:function() { + emitTestEpilogue:{value:function(experiments) { + if (experiments.length > 0) { + this.push(''); + for (var i in experiments) { + this.push('YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.' + toJavaUpper(experiments[i]) +', false);'); + } + } + this.popIndent(); this.push([ '}', @@ -54,158 +80,158 @@ JavaEmitter.prototype = Object.create(Emitter.prototype, { }}, AssertEQ:{value:function(v0, v1) { - this.push('assertEquals(' + v0 + ', ' + v1 + ', 0.0f);'); + this.push('assertEquals(' + v0 + 'f, ' + v1 + ', 0.0f);'); }}, - CSSAlignAuto:{value:'CSSAlign.AUTO'}, - CSSAlignCenter:{value:'CSSAlign.CENTER'}, - CSSAlignFlexEnd:{value:'CSSAlign.FLEX_END'}, - CSSAlignFlexStart:{value:'CSSAlign.FLEX_START'}, - CSSAlignStretch:{value:'CSSAlign.STRETCH'}, + YGAlignAuto:{value:'YogaAlign.AUTO'}, + YGAlignCenter:{value:'YogaAlign.CENTER'}, + YGAlignFlexEnd:{value:'YogaAlign.FLEX_END'}, + YGAlignFlexStart:{value:'YogaAlign.FLEX_START'}, + YGAlignStretch:{value:'YogaAlign.STRETCH'}, - CSSDirectionInherit:{value:'CSSDirection.INHERIT'}, - CSSDirectionLTR:{value:'CSSDirection.LTR'}, - CSSDirectionRTL:{value:'CSSDirection.RTL'}, + YGDirectionInherit:{value:'YogaDirection.INHERIT'}, + YGDirectionLTR:{value:'YogaDirection.LTR'}, + YGDirectionRTL:{value:'YogaDirection.RTL'}, - CSSEdgeBottom:{value:'Spacing.BOTTOM'}, - CSSEdgeEnd:{value:'Spacing.END'}, - CSSEdgeLeft:{value:'Spacing.LEFT'}, - CSSEdgeRight:{value:'Spacing.RIGHT'}, - CSSEdgeStart:{value:'Spacing.START'}, - CSSEdgeTop:{value:'Spacing.TOP'}, + YGEdgeBottom:{value:'YogaEdge.BOTTOM'}, + YGEdgeEnd:{value:'YogaEdge.END'}, + YGEdgeLeft:{value:'YogaEdge.LEFT'}, + YGEdgeRight:{value:'YogaEdge.RIGHT'}, + YGEdgeStart:{value:'YogaEdge.START'}, + YGEdgeTop:{value:'YogaEdge.TOP'}, - CSSFlexDirectionColumn:{value:'CSSFlexDirection.COLUMN'}, - CSSFlexDirectionColumnReverse:{value:'CSSFlexDirection.COLUMN_REVERSE'}, - CSSFlexDirectionRow:{value:'CSSFlexDirection.ROW'}, - CSSFlexDirectionRowReverse:{value:'CSSFlexDirection.ROW_REVERSE'}, + YGFlexDirectionColumn:{value:'YogaFlexDirection.COLUMN'}, + YGFlexDirectionColumnReverse:{value:'YogaFlexDirection.COLUMN_REVERSE'}, + YGFlexDirectionRow:{value:'YogaFlexDirection.ROW'}, + YGFlexDirectionRowReverse:{value:'YogaFlexDirection.ROW_REVERSE'}, - CSSJustifyCenter:{value:'CSSJustify.CENTER'}, - CSSJustifyFlexEnd:{value:'CSSJustify.FLEX_END'}, - CSSJustifyFlexStart:{value:'CSSJustify.FLEX_START'}, - CSSJustifySpaceAround:{value:'CSSJustify.SPACE_AROUND'}, - CSSJustifySpaceBetween:{value:'CSSJustify.SPACE_BETWEEN'}, + YGJustifyCenter:{value:'YogaJustify.CENTER'}, + YGJustifyFlexEnd:{value:'YogaJustify.FLEX_END'}, + YGJustifyFlexStart:{value:'YogaJustify.FLEX_START'}, + YGJustifySpaceAround:{value:'YogaJustify.SPACE_AROUND'}, + YGJustifySpaceBetween:{value:'YogaJustify.SPACE_BETWEEN'}, - CSSOverflowHidden:{value:'CSSOverflow.HIDDEN'}, - CSSOverflowVisible:{value:'CSSOverflow.VISIBLE'}, + YGOverflowHidden:{value:'YogaOverflow.HIDDEN'}, + YGOverflowVisible:{value:'YogaOverflow.VISIBLE'}, - CSSPositionTypeAbsolute:{value:'CSSPositionType.ABSOLUTE'}, - CSSPositionTypeRelative:{value:'CSSPositionType.RELATIVE'}, + YGPositionTypeAbsolute:{value:'YogaPositionType.ABSOLUTE'}, + YGPositionTypeRelative:{value:'YogaPositionType.RELATIVE'}, - CSSUndefined:{value:'CSSConstants.UNDEFINED'}, + YGUndefined:{value:'YogaConstants.UNDEFINED'}, - CSSWrapTypeNoWrap:{value:'CSSWrap.NO_WRAP'}, - CSSWrapTypeWrap:{value:'CSSWrap.WRAP'}, + YGWrapNoWrap:{value:'YogaWrap.NO_WRAP'}, + YGWrapWrap:{value:'YogaWrap.WRAP'}, - CSSNodeCalculateLayout:{value:function(node, dir) { + YGNodeCalculateLayout:{value:function(node, dir) { this.push(node + '.setDirection(' + dir + ');'); - this.push(node + '.calculateLayout(null);'); + this.push(node + '.calculateLayout();'); }}, - CSSNodeInsertChild:{value:function(parentName, nodeName, index) { + YGNodeInsertChild:{value:function(parentName, nodeName, index) { this.push(parentName + '.addChildAt(' + nodeName + ', ' + index + ');'); }}, - CSSNodeLayoutGetLeft:{value:function(nodeName) { + YGNodeLayoutGetLeft:{value:function(nodeName) { return nodeName + '.getLayoutX()'; }}, - CSSNodeLayoutGetTop:{value:function(nodeName) { + YGNodeLayoutGetTop:{value:function(nodeName) { return nodeName + '.getLayoutY()'; }}, - CSSNodeLayoutGetWidth:{value:function(nodeName) { + YGNodeLayoutGetWidth:{value:function(nodeName) { return nodeName + '.getLayoutWidth()'; }}, - CSSNodeLayoutGetHeight:{value:function(nodeName) { + YGNodeLayoutGetHeight:{value:function(nodeName) { return nodeName + '.getLayoutHeight()'; }}, - CSSNodeStyleSetAlignContent:{value:function(nodeName, value) { + YGNodeStyleSetAlignContent:{value:function(nodeName, value) { this.push(nodeName + '.setAlignContent(' + value + ');'); }}, - CSSNodeStyleSetAlignItems:{value:function(nodeName, value) { + YGNodeStyleSetAlignItems:{value:function(nodeName, value) { this.push(nodeName + '.setAlignItems(' + value + ');'); }}, - CSSNodeStyleSetAlignSelf:{value:function(nodeName, value) { + YGNodeStyleSetAlignSelf:{value:function(nodeName, value) { this.push(nodeName + '.setAlignSelf(' + value + ');'); }}, - CSSNodeStyleSetBorder:{value:function(nodeName, edge, value) { - this.push(nodeName + '.setBorder(' + edge + ', ' + value + ');'); + YGNodeStyleSetBorder:{value:function(nodeName, edge, value) { + this.push(nodeName + '.setBorder(' + edge + ', ' + value + 'f);'); }}, - CSSNodeStyleSetDirection:{value:function(nodeName, value) { + YGNodeStyleSetDirection:{value:function(nodeName, value) { this.push(nodeName + '.setDirection(' + value + ');'); }}, - CSSNodeStyleSetFlexBasis:{value:function(nodeName, value) { - this.push(nodeName + '.setFlexBasis(' + value + ');'); + YGNodeStyleSetFlexBasis:{value:function(nodeName, value) { + this.push(nodeName + '.setFlexBasis(' + value + 'f);'); }}, - CSSNodeStyleSetFlexDirection:{value:function(nodeName, value) { + YGNodeStyleSetFlexDirection:{value:function(nodeName, value) { this.push(nodeName + '.setFlexDirection(' + value + ');'); }}, - CSSNodeStyleSetFlexGrow:{value:function(nodeName, value) { - this.push(nodeName + '.setFlexGrow(' + value + ');'); + YGNodeStyleSetFlexGrow:{value:function(nodeName, value) { + this.push(nodeName + '.setFlexGrow(' + value + 'f);'); }}, - CSSNodeStyleSetFlexShrink:{value:function(nodeName, value) { - this.push(nodeName + '.setFlexShrink(' + value + ');'); + YGNodeStyleSetFlexShrink:{value:function(nodeName, value) { + this.push(nodeName + '.setFlexShrink(' + value + 'f);'); }}, - CSSNodeStyleSetFlexWrap:{value:function(nodeName, value) { + YGNodeStyleSetFlexWrap:{value:function(nodeName, value) { this.push(nodeName + '.setWrap(' + value + ');'); }}, - CSSNodeStyleSetHeight:{value:function(nodeName, value) { - this.push(nodeName + '.setStyleHeight(' + value + ');'); + YGNodeStyleSetHeight:{value:function(nodeName, value) { + this.push(nodeName + '.setHeight(' + value + 'f);'); }}, - CSSNodeStyleSetJustifyContent:{value:function(nodeName, value) { + YGNodeStyleSetJustifyContent:{value:function(nodeName, value) { this.push(nodeName + '.setJustifyContent(' + value + ');'); }}, - CSSNodeStyleSetMargin:{value:function(nodeName, edge, value) { - this.push(nodeName + '.setMargin(' + edge + ', ' + value + ');'); + YGNodeStyleSetMargin:{value:function(nodeName, edge, value) { + this.push(nodeName + '.setMargin(' + edge + ', ' + value + 'f);'); }}, - CSSNodeStyleSetMaxHeight:{value:function(nodeName, value) { - this.push(nodeName + '.setStyleMaxHeight(' + value + ');'); + YGNodeStyleSetMaxHeight:{value:function(nodeName, value) { + this.push(nodeName + '.setMaxHeight(' + value + 'f);'); }}, - CSSNodeStyleSetMaxWidth:{value:function(nodeName, value) { - this.push(nodeName + '.setStyleMaxWidth(' + value + ');'); + YGNodeStyleSetMaxWidth:{value:function(nodeName, value) { + this.push(nodeName + '.setMaxWidth(' + value + 'f);'); }}, - CSSNodeStyleSetMinHeight:{value:function(nodeName, value) { - this.push(nodeName + '.setStyleMinHeight(' + value + ');'); + YGNodeStyleSetMinHeight:{value:function(nodeName, value) { + this.push(nodeName + '.setMinHeight(' + value + 'f);'); }}, - CSSNodeStyleSetMinWidth:{value:function(nodeName, value) { - this.push(nodeName + '.setStyleMinWidth(' + value + ');'); + YGNodeStyleSetMinWidth:{value:function(nodeName, value) { + this.push(nodeName + '.setMinWidth(' + value + 'f);'); }}, - CSSNodeStyleSetOverflow:{value:function(nodeName, value) { + YGNodeStyleSetOverflow:{value:function(nodeName, value) { this.push(nodeName + '.setOverflow(' + value + ');'); }}, - CSSNodeStyleSetPadding:{value:function(nodeName, edge, value) { + YGNodeStyleSetPadding:{value:function(nodeName, edge, value) { this.push(nodeName + '.setPadding(' + edge + ', ' + value + ');'); }}, - CSSNodeStyleSetPosition:{value:function(nodeName, edge, value) { - this.push(nodeName + '.setPosition(' + edge + ', ' + value + ');'); + YGNodeStyleSetPosition:{value:function(nodeName, edge, value) { + this.push(nodeName + '.setPosition(' + edge + ', ' + value + 'f);'); }}, - CSSNodeStyleSetPositionType:{value:function(nodeName, value) { + YGNodeStyleSetPositionType:{value:function(nodeName, value) { this.push(nodeName + '.setPositionType(' + value + ');'); }}, - CSSNodeStyleSetWidth:{value:function(nodeName, value) { - this.push(nodeName + '.setStyleWidth(' + value + ');'); + YGNodeStyleSetWidth:{value:function(nodeName, value) { + this.push(nodeName + '.setWidth(' + value + 'f);'); }}, }); diff --git a/gentest/gentest.js b/gentest/gentest.js index a680a9d0..196a8c1e 100755 --- a/gentest/gentest.js +++ b/gentest/gentest.js @@ -46,36 +46,7 @@ function printTest(e, LTRContainer, RTLContainer, genericContainer) { ' * of patent rights can be found in the PATENTS file in the same directory.', ' */', '', - '/**', - ' * @Generated by gentest/gentest.sh with the following input', - ' *', - ]); - - var indentation = 0; - e.push(genericContainer.innerHTML.split('\n').map(function(line) { - return line.trim(); - }).filter(function(line) { - return line.length > 0 && line !== '
'; - }).map(function(line) { - var result; - if (line.indexOf('= 0) { - e.CSSNodeStyleSetPosition(nodeName, e.CSSEdgeStart, pixelValue(e, node.style[style])); + e.YGNodeStyleSetPosition(nodeName, e.YGEdgeStart, pixelValue(e, node.style[style])); } else { - e.CSSNodeStyleSetPosition(nodeName, e.CSSEdgeLeft, pixelValue(e, node.style[style])); + e.YGNodeStyleSetPosition(nodeName, e.YGEdgeLeft, pixelValue(e, node.style[style])); } break; case 'top': - e.CSSNodeStyleSetPosition(nodeName, e.CSSEdgeTop, pixelValue(e, node.style[style])); + e.YGNodeStyleSetPosition(nodeName, e.YGEdgeTop, pixelValue(e, node.style[style])); break; case 'right': if (genericNode.rawStyle.indexOf('end:') >= 0) { - e.CSSNodeStyleSetPosition(nodeName, e.CSSEdgeEnd, pixelValue(e, node.style[style])); + e.YGNodeStyleSetPosition(nodeName, e.YGEdgeEnd, pixelValue(e, node.style[style])); } else { - e.CSSNodeStyleSetPosition(nodeName, e.CSSEdgeRight, pixelValue(e, node.style[style])); + e.YGNodeStyleSetPosition(nodeName, e.YGEdgeRight, pixelValue(e, node.style[style])); } break; case 'bottom': - e.CSSNodeStyleSetPosition(nodeName, e.CSSEdgeBottom, pixelValue(e, node.style[style])); + e.YGNodeStyleSetPosition(nodeName, e.YGEdgeBottom, pixelValue(e, node.style[style])); break; case 'margin-left': if (genericNode.rawStyle.indexOf('margin-start:') >= 0) { - e.CSSNodeStyleSetMargin(nodeName, e.CSSEdgeStart, pixelValue(e, node.style[style])); + e.YGNodeStyleSetMargin(nodeName, e.YGEdgeStart, pixelValue(e, node.style[style])); } else { - e.CSSNodeStyleSetMargin(nodeName, e.CSSEdgeLeft, pixelValue(e, node.style[style])); + e.YGNodeStyleSetMargin(nodeName, e.YGEdgeLeft, pixelValue(e, node.style[style])); } break; case 'margin-top': - e.CSSNodeStyleSetMargin(nodeName, e.CSSEdgeTop, pixelValue(e, node.style[style])); + e.YGNodeStyleSetMargin(nodeName, e.YGEdgeTop, pixelValue(e, node.style[style])); break; case 'margin-right': if (genericNode.rawStyle.indexOf('margin-end:') >= 0) { - e.CSSNodeStyleSetMargin(nodeName, e.CSSEdgeEnd, pixelValue(e, node.style[style])); + e.YGNodeStyleSetMargin(nodeName, e.YGEdgeEnd, pixelValue(e, node.style[style])); } else { - e.CSSNodeStyleSetMargin(nodeName, e.CSSEdgeRight, pixelValue(e, node.style[style])); + e.YGNodeStyleSetMargin(nodeName, e.YGEdgeRight, pixelValue(e, node.style[style])); } break; case 'margin-bottom': - e.CSSNodeStyleSetMargin(nodeName, e.CSSEdgeBottom, pixelValue(e, node.style[style])); + e.YGNodeStyleSetMargin(nodeName, e.YGEdgeBottom, pixelValue(e, node.style[style])); break; case 'padding-left': if (genericNode.rawStyle.indexOf('padding-start:') >= 0) { - e.CSSNodeStyleSetPadding(nodeName, e.CSSEdgeStart, pixelValue(e, node.style[style])); + e.YGNodeStyleSetPadding(nodeName, e.YGEdgeStart, pixelValue(e, node.style[style])); } else { - e.CSSNodeStyleSetPadding(nodeName, e.CSSEdgeLeft, pixelValue(e, node.style[style])); + e.YGNodeStyleSetPadding(nodeName, e.YGEdgeLeft, pixelValue(e, node.style[style])); } break; case 'padding-top': - e.CSSNodeStyleSetPadding(nodeName, e.CSSEdgeTop, pixelValue(e, node.style[style])); + e.YGNodeStyleSetPadding(nodeName, e.YGEdgeTop, pixelValue(e, node.style[style])); break; case 'padding-right': if (genericNode.rawStyle.indexOf('padding-end:') >= 0) { - e.CSSNodeStyleSetPadding(nodeName, e.CSSEdgeEnd, pixelValue(e, node.style[style])); + e.YGNodeStyleSetPadding(nodeName, e.YGEdgeEnd, pixelValue(e, node.style[style])); } else { - e.CSSNodeStyleSetPadding(nodeName, e.CSSEdgeRight, pixelValue(e, node.style[style])); + e.YGNodeStyleSetPadding(nodeName, e.YGEdgeRight, pixelValue(e, node.style[style])); } break; case 'padding-bottom': - e.CSSNodeStyleSetPadding(nodeName, e.CSSEdgeBottom, pixelValue(e, node.style[style])); + e.YGNodeStyleSetPadding(nodeName, e.YGEdgeBottom, pixelValue(e, node.style[style])); break; case 'border-left-width': if (genericNode.rawStyle.indexOf('border-start-width:') >= 0) { - e.CSSNodeStyleSetBorder(nodeName, e.CSSEdgeStart, pixelValue(e, node.style[style])); + e.YGNodeStyleSetBorder(nodeName, e.YGEdgeStart, pixelValue(e, node.style[style])); } else { - e.CSSNodeStyleSetBorder(nodeName, e.CSSEdgeLeft, pixelValue(e, node.style[style])); + e.YGNodeStyleSetBorder(nodeName, e.YGEdgeLeft, pixelValue(e, node.style[style])); } break; case 'border-top-width': - e.CSSNodeStyleSetBorder(nodeName, e.CSSEdgeTop, pixelValue(e, node.style[style])); + e.YGNodeStyleSetBorder(nodeName, e.YGEdgeTop, pixelValue(e, node.style[style])); break; case 'border-right-width': if (genericNode.rawStyle.indexOf('border-end-width:') >= 0) { - e.CSSNodeStyleSetBorder(nodeName, e.CSSEdgeEnd, pixelValue(e, node.style[style])); + e.YGNodeStyleSetBorder(nodeName, e.YGEdgeEnd, pixelValue(e, node.style[style])); } else { - e.CSSNodeStyleSetBorder(nodeName, e.CSSEdgeRight, pixelValue(e, node.style[style])); + e.YGNodeStyleSetBorder(nodeName, e.YGEdgeRight, pixelValue(e, node.style[style])); } break; case 'border-bottom-width': - e.CSSNodeStyleSetBorder(nodeName, e.CSSEdgeBottom, pixelValue(e, node.style[style])); + e.YGNodeStyleSetBorder(nodeName, e.YGEdgeBottom, pixelValue(e, node.style[style])); break; case 'width': - e.CSSNodeStyleSetWidth(nodeName, pixelValue(e, node.style[style])); + e.YGNodeStyleSetWidth(nodeName, pixelValue(e, node.style[style])); break; case 'min-width': - e.CSSNodeStyleSetMinWidth(nodeName, pixelValue(e, node.style[style])); + e.YGNodeStyleSetMinWidth(nodeName, pixelValue(e, node.style[style])); break; case 'max-width': - e.CSSNodeStyleSetMaxWidth(nodeName, pixelValue(e, node.style[style])); + e.YGNodeStyleSetMaxWidth(nodeName, pixelValue(e, node.style[style])); break; case 'height': - e.CSSNodeStyleSetHeight(nodeName, pixelValue(e, node.style[style])); + e.YGNodeStyleSetHeight(nodeName, pixelValue(e, node.style[style])); break; case 'min-height': - e.CSSNodeStyleSetMinHeight(nodeName, pixelValue(e, node.style[style])); + e.YGNodeStyleSetMinHeight(nodeName, pixelValue(e, node.style[style])); break; case 'max-height': - e.CSSNodeStyleSetMaxHeight(nodeName, pixelValue(e, node.style[style])); + e.YGNodeStyleSetMaxHeight(nodeName, pixelValue(e, node.style[style])); break; } } } if (parentName) { - e.CSSNodeInsertChild(parentName, nodeName, index); + e.YGNodeInsertChild(parentName, nodeName, index); } for (var i = 0; i < node.children.length; i++) { @@ -347,66 +318,66 @@ function setupTestTree(e, parent, node, genericNode, nodeName, parentName, index function overflowValue(e, value) { switch (value) { - case 'visible': return e.CSSOverflowVisible; - case 'hidden': return e.CSSOverflowHidden; + case 'visible': return e.YGOverflowVisible; + case 'hidden': return e.YGOverflowHidden; } } function wrapValue(e, value) { switch (value) { - case 'wrap': return e.CSSWrapTypeWrap; - case 'nowrap': return e.CSSWrapTypeNoWrap; + case 'wrap': return e.YGWrapWrap; + case 'nowrap': return e.YGWrapNoWrap; } } function flexDirectionValue(e, value) { switch (value) { - case 'row': return e.CSSFlexDirectionRow; - case 'row-reverse': return e.CSSFlexDirectionRowReverse; - case 'column': return e.CSSFlexDirectionColumn; - case 'column-reverse': return e.CSSFlexDirectionColumnReverse; + case 'row': return e.YGFlexDirectionRow; + case 'row-reverse': return e.YGFlexDirectionRowReverse; + case 'column': return e.YGFlexDirectionColumn; + case 'column-reverse': return e.YGFlexDirectionColumnReverse; } } function justifyValue(e, value) { switch (value) { - case 'center': return e.CSSJustifyCenter; - case 'space-around': return e.CSSJustifySpaceAround; - case 'space-between': return e.CSSJustifySpaceBetween; - case 'flex-start': return e.CSSJustifyFlexStart; - case 'flex-end': return e.CSSJustifyFlexEnd; + case 'center': return e.YGJustifyCenter; + case 'space-around': return e.YGJustifySpaceAround; + case 'space-between': return e.YGJustifySpaceBetween; + case 'flex-start': return e.YGJustifyFlexStart; + case 'flex-end': return e.YGJustifyFlexEnd; } } function positionValue(e, value) { switch (value) { - case 'absolute': return e.CSSPositionTypeAbsolute; - default: return e.CSSPositionTypeRelative + case 'absolute': return e.YGPositionTypeAbsolute; + default: return e.YGPositionTypeRelative } } function directionValue(e, value) { switch (value) { - case 'ltr': return e.CSSDirectionLTR; - case 'rtl': return e.CSSDirectionRTL; - case 'inherit': return e.CSSDirectionInherit; + case 'ltr': return e.YGDirectionLTR; + case 'rtl': return e.YGDirectionRTL; + case 'inherit': return e.YGDirectionInherit; } } function alignValue(e, value) { switch (value) { - case 'auto': return e.CSSAlignAuto; - case 'center': return e.CSSAlignCenter; - case 'stretch': return e.CSSAlignStretch; - case 'flex-start': return e.CSSAlignFlexStart; - case 'flex-end': return e.CSSAlignFlexEnd; + case 'auto': return e.YGAlignAuto; + case 'center': return e.YGAlignCenter; + case 'stretch': return e.YGAlignStretch; + case 'flex-start': return e.YGAlignFlexStart; + case 'flex-end': return e.YGAlignFlexEnd; } } function pixelValue(e, value) { switch (value) { - case 'auto': return e.CSSUndefined; - case 'undefined': return e.CSSUndefined; + case 'auto': return e.YGUndefined; + case 'undefined': return e.YGUndefined; default: return value.replace('px', ''); } } @@ -415,6 +386,15 @@ function getDefaultStyleValue(style) { if (style == 'position') { return 'relative'; } + switch (style) { + case 'left': + case 'top': + case 'right': + case 'bottom': + case 'start': + case 'end': + return 'undefined'; + } var node = document.getElementById('default'); return getComputedStyle(node, null).getPropertyValue(style); } @@ -431,16 +411,19 @@ function calculateTree(root) { width: child.offsetWidth, height: child.offsetHeight, children: calculateTree(child), - style: getCSSLayoutStyle(child), + style: getYogaStyle(child), declaredStyle: child.style, rawStyle: child.getAttribute('style'), + experiments: child.getAttribute('experiments') + ? child.getAttribute('experiments').split(' ') + : [], }); } return rootLayout; } -function getCSSLayoutStyle(node) { +function getYogaStyle(node) { return [ 'direction', 'flex-direction', diff --git a/gentest/gentest.rb b/gentest/gentest.rb index 828cb595..4293866d 100644 --- a/gentest/gentest.rb +++ b/gentest/gentest.rb @@ -1,10 +1,17 @@ #!/usr/bin/env ruby + require 'watir-webdriver' require 'fileutils' + caps = Selenium::WebDriver::Remote::Capabilities.chrome( - "loggingPrefs"=>{"browser"=>"ALL", "performance"=>"ALL"}) + "loggingPrefs"=>{ + "browser"=>"ALL", + "performance"=>"ALL" + } +) browser = Watir::Browser.new(:chrome, :desired_capabilities => caps) Dir.chdir(File.dirname($0)) + Dir['fixtures/*.html'].each do |file| fixture = File.read(file) name = File.basename(file, '.*') @@ -22,7 +29,7 @@ Dir['fixtures/*.html'].each do |file| template = File.open('test-template.html').read f = File.open('test.html', 'w') - f.write sprintf(template, ltr_fixture, rtl_fixture, fixture) + f.write sprintf(template, name, ltr_fixture, rtl_fixture, fixture) f.close FileUtils.copy('test.html', "#{name}.html") if $DEBUG @@ -33,12 +40,12 @@ Dir['fixtures/*.html'].each do |file| f.write eval(logs[0].message.sub(/^[^"]*/, '')) f.close - f = File.open("../java/tests/com/facebook/csslayout/#{name}.java", 'w') - f.write eval(logs[1].message.sub(/^[^"]*/, '')).sub('CSSNodeLayoutTest', name) + f = File.open("../java/tests/com/facebook/yoga/#{name}.java", 'w') + f.write eval(logs[1].message.sub(/^[^"]*/, '')).sub('YogaTest', name) f.close - f = File.open("../csharp/tests/Facebook.CSSLayout/#{name}.cs", 'w') - f.write eval(logs[2].message.sub(/^[^"]*/, '')).sub('CSSNodeLayoutTest', name) + f = File.open("../csharp/tests/Facebook.Yoga/#{name}.cs", 'w') + f.write eval(logs[2].message.sub(/^[^"]*/, '')).sub('YogaTest', name) f.close end File.delete('test.html') diff --git a/gentest/test-template.html b/gentest/test-template.html index 9e0364c3..0b4102f7 100644 --- a/gentest/test-template.html +++ b/gentest/test-template.html @@ -2,7 +2,7 @@ - test page + %s diff --git a/java/BUCK b/java/BUCK index 67c1217e..70775d15 100644 --- a/java/BUCK +++ b/java/BUCK @@ -5,32 +5,35 @@ # 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_defs('//CSSLAYOUT_DEFS') +include_defs('//YOGA_DEFS') cxx_library( name = 'jni', - soname = 'libcsslayout.$(ext)', + soname = 'libyoga.$(ext)', srcs = glob(['jni/*.cpp']), header_namespace = '', compiler_flags = [ '-fno-omit-frame-pointer', '-fexceptions', + '-fPIC', '-Wall', '-Werror', '-O3', '-std=c++11', ], - deps = JNI_DEPS + [ - csslayout_dep(':CSSLayout'), + deps = [ + FBJNI_TARGET, + JNI_TARGET, + yoga_dep(':yoga'), ], visibility = ['PUBLIC'], ) java_library( name = 'java', - srcs = glob(['com/facebook/csslayout/*.java']), + srcs = glob(['com/facebook/yoga/*.java']), tests=[ - csslayout_dep('/java:tests'), + yoga_dep('java:tests'), ], source = '1.7', target = '1.7', @@ -47,10 +50,11 @@ java_library( java_test( name = 'tests', srcs = glob(['tests/**/*.java']), + use_cxx_libraries = True, + cxx_library_whitelist = CXX_LIBRARY_WHITELIST, deps = [ ':java', JUNIT_TARGET, ], - use_cxx_libraries = True, - cxx_library_whitelist = CXX_LIBRARY_WHITELIST, + visibility = ['PUBLIC'], ) diff --git a/java/com/facebook/csslayout/CSSAlign.java b/java/com/facebook/csslayout/CSSAlign.java deleted file mode 100644 index 3e3cb0e9..00000000 --- a/java/com/facebook/csslayout/CSSAlign.java +++ /dev/null @@ -1,18 +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. - */ - -package com.facebook.csslayout; - -public enum CSSAlign { - AUTO, - FLEX_START, - CENTER, - FLEX_END, - STRETCH, -} diff --git a/java/com/facebook/csslayout/CSSCachedMeasurement.java b/java/com/facebook/csslayout/CSSCachedMeasurement.java deleted file mode 100644 index deb1de6a..00000000 --- a/java/com/facebook/csslayout/CSSCachedMeasurement.java +++ /dev/null @@ -1,20 +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. - */ - -package com.facebook.csslayout; - -public class CSSCachedMeasurement { - public float availableWidth; - public float availableHeight; - public CSSMeasureMode widthMeasureMode = null; - public CSSMeasureMode heightMeasureMode = null; - - public float computedWidth; - public float computedHeight; -} diff --git a/java/com/facebook/csslayout/CSSDirection.java b/java/com/facebook/csslayout/CSSDirection.java deleted file mode 100644 index 0c27a929..00000000 --- a/java/com/facebook/csslayout/CSSDirection.java +++ /dev/null @@ -1,16 +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. - */ - -package com.facebook.csslayout; - -public enum CSSDirection { - INHERIT, - LTR, - RTL, -} diff --git a/java/com/facebook/csslayout/CSSFlexDirection.java b/java/com/facebook/csslayout/CSSFlexDirection.java deleted file mode 100644 index 30f92bd0..00000000 --- a/java/com/facebook/csslayout/CSSFlexDirection.java +++ /dev/null @@ -1,17 +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. - */ - -package com.facebook.csslayout; - -public enum CSSFlexDirection { - COLUMN, - COLUMN_REVERSE, - ROW, - ROW_REVERSE -} diff --git a/java/com/facebook/csslayout/CSSJustify.java b/java/com/facebook/csslayout/CSSJustify.java deleted file mode 100644 index dfcc1cd2..00000000 --- a/java/com/facebook/csslayout/CSSJustify.java +++ /dev/null @@ -1,18 +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. - */ - -package com.facebook.csslayout; - -public enum CSSJustify { - FLEX_START, - CENTER, - FLEX_END, - SPACE_BETWEEN, - SPACE_AROUND, -} diff --git a/java/com/facebook/csslayout/CSSLayout.java b/java/com/facebook/csslayout/CSSLayout.java deleted file mode 100644 index 9bddaf91..00000000 --- a/java/com/facebook/csslayout/CSSLayout.java +++ /dev/null @@ -1,77 +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. - */ - -package com.facebook.csslayout; - -import java.util.Arrays; - -/** - * Where the output of {@link LayoutEngine#layoutNode(CSSNodeDEPRECATED, float)} will go in the CSSNodeDEPRECATED. - */ -public class CSSLayout { - // This value was chosen based on empiracle data. Even the most complicated - // layouts should not require more than 16 entries to fit within the cache. - public static final int MAX_CACHED_RESULT_COUNT = 16; - - public static final int POSITION_LEFT = 0; - public static final int POSITION_TOP = 1; - public static final int POSITION_RIGHT = 2; - public static final int POSITION_BOTTOM = 3; - - public static final int DIMENSION_WIDTH = 0; - public static final int DIMENSION_HEIGHT = 1; - - public float[] position = new float[4]; - public float[] dimensions = new float[2]; - public CSSDirection direction = CSSDirection.LTR; - - public float computedFlexBasis; - - public int generationCount; - public CSSDirection lastParentDirection; - - public int nextCachedMeasurementsIndex; - public CSSCachedMeasurement[] cachedMeasurements = new CSSCachedMeasurement[MAX_CACHED_RESULT_COUNT]; - public float[] measuredDimensions = new float[2]; - - public CSSCachedMeasurement cachedLayout = new CSSCachedMeasurement(); - - CSSLayout() { - resetResult(); - } - - public void resetResult() { - Arrays.fill(position, 0); - Arrays.fill(dimensions, CSSConstants.UNDEFINED); - direction = CSSDirection.LTR; - - computedFlexBasis = CSSConstants.UNDEFINED; - - generationCount = 0; - lastParentDirection = null; - - nextCachedMeasurementsIndex = 0; - measuredDimensions[DIMENSION_WIDTH] = CSSConstants.UNDEFINED; - measuredDimensions[DIMENSION_HEIGHT] = CSSConstants.UNDEFINED; - - cachedLayout.widthMeasureMode = null; - cachedLayout.heightMeasureMode = null; - } - - @Override - public String toString() { - return "layout: {" + - "left: " + position[POSITION_LEFT] + ", " + - "top: " + position[POSITION_TOP] + ", " + - "width: " + dimensions[DIMENSION_WIDTH] + ", " + - "height: " + dimensions[DIMENSION_HEIGHT] + ", " + - "direction: " + direction + - "}"; - } -} diff --git a/java/com/facebook/csslayout/CSSLayoutContext.java b/java/com/facebook/csslayout/CSSLayoutContext.java deleted file mode 100644 index 91e4f0ba..00000000 --- a/java/com/facebook/csslayout/CSSLayoutContext.java +++ /dev/null @@ -1,22 +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. - */ - -package com.facebook.csslayout; - -/** - * A context for holding values local to a given instance of layout computation. - * - * This is necessary for making layout thread-safe. A separate instance should - * be used when {@link CSSNodeDEPRECATED#calculateLayout} is called concurrently on - * different node hierarchies. - */ -public class CSSLayoutContext { - /*package*/ final MeasureOutput measureOutput = new MeasureOutput(); - int currentGenerationCount; -} diff --git a/java/com/facebook/csslayout/CSSMeasureMode.java b/java/com/facebook/csslayout/CSSMeasureMode.java deleted file mode 100644 index e8ebb34f..00000000 --- a/java/com/facebook/csslayout/CSSMeasureMode.java +++ /dev/null @@ -1,16 +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. - */ - -package com.facebook.csslayout; - -public enum CSSMeasureMode { - UNDEFINED, - EXACTLY, - AT_MOST, -} diff --git a/java/com/facebook/csslayout/CSSNode.java b/java/com/facebook/csslayout/CSSNode.java deleted file mode 100644 index f07ad7de..00000000 --- a/java/com/facebook/csslayout/CSSNode.java +++ /dev/null @@ -1,529 +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. - */ - -package com.facebook.csslayout; - -import javax.annotation.Nullable; - -import java.util.List; -import java.util.ArrayList; - -import com.facebook.proguard.annotations.DoNotStrip; -import com.facebook.soloader.SoLoader; - -public class CSSNode implements CSSNodeAPI { - - static { - try { - SoLoader.loadLibrary("csslayout"); - } catch (Exception ignored) { - // The user probably didn't call SoLoader.init(). Fall back to System.loadLibrary() instead. - System.out.println("Falling back to System.loadLibrary()"); - System.loadLibrary("csslayout"); - } - } - - /** - * Get native instance count. Useful for testing only. - */ - static native int jni_CSSNodeGetInstanceCount(); - - private CSSNode mParent; - private List mChildren; - private MeasureFunction mMeasureFunction; - private long mNativePointer; - private Object mData; - - private boolean mHasSetPadding = false; - private boolean mHasSetMargin = false; - private boolean mHasSetBorder = false; - private boolean mHasSetPosition = false; - - @DoNotStrip - private float mWidth = CSSConstants.UNDEFINED; - @DoNotStrip - private float mHeight = CSSConstants.UNDEFINED; - @DoNotStrip - private float mTop = CSSConstants.UNDEFINED; - @DoNotStrip - private float mLeft = CSSConstants.UNDEFINED; - @DoNotStrip - private int mLayoutDirection = 0; - - private native long jni_CSSNodeNew(); - public CSSNode() { - mNativePointer = jni_CSSNodeNew(); - if (mNativePointer == 0) { - throw new IllegalStateException("Failed to allocate native memory"); - } - - mChildren = new ArrayList<>(4); - } - - private native void jni_CSSNodeFree(long nativePointer); - @Override - protected void finalize() throws Throwable { - try { - jni_CSSNodeFree(mNativePointer); - } finally { - super.finalize(); - } - } - - private native void jni_CSSNodeReset(long nativePointer); - @Override - public void reset() { - mHasSetPadding = false; - mHasSetMargin = false; - mHasSetBorder = false; - mHasSetPosition = false; - - mWidth = CSSConstants.UNDEFINED; - mHeight = CSSConstants.UNDEFINED; - mTop = CSSConstants.UNDEFINED; - mLeft = CSSConstants.UNDEFINED; - mLayoutDirection = 0; - - mMeasureFunction = null; - mData = null; - - jni_CSSNodeReset(mNativePointer); - } - - @Override - public int getChildCount() { - return mChildren.size(); - } - - @Override - public CSSNode getChildAt(int i) { - return mChildren.get(i); - } - - private native void jni_CSSNodeInsertChild(long nativePointer, long childPointer, int index); - @Override - public void addChildAt(CSSNode child, int i) { - if (child.mParent != null) { - throw new IllegalStateException("Child already has a parent, it must be removed first."); - } - - mChildren.add(i, child); - child.mParent = this; - jni_CSSNodeInsertChild(mNativePointer, child.mNativePointer, i); - } - - private native void jni_CSSNodeRemoveChild(long nativePointer, long childPointer); - @Override - public CSSNode removeChildAt(int i) { - - final CSSNode child = mChildren.remove(i); - child.mParent = null; - jni_CSSNodeRemoveChild(mNativePointer, child.mNativePointer); - return child; - } - - @Override - public @Nullable - CSSNode getParent() { - return mParent; - } - - @Override - public int indexOf(CSSNode child) { - return mChildren.indexOf(child); - } - - private native void jni_CSSNodeSetIsTextNode(long nativePointer, boolean isTextNode); - @Override - public void setIsTextNode(boolean isTextNode) { - jni_CSSNodeSetIsTextNode(mNativePointer, isTextNode); - } - - private native boolean jni_CSSNodeGetIsTextNode(long nativePointer); - @Override - public boolean isTextNode() { - return jni_CSSNodeGetIsTextNode(mNativePointer); - } - - private native void jni_CSSNodeCalculateLayout(long nativePointer); - @Override - public void calculateLayout(CSSLayoutContext layoutContext) { - jni_CSSNodeCalculateLayout(mNativePointer); - } - - private native boolean jni_CSSNodeHasNewLayout(long nativePointer); - @Override - public boolean hasNewLayout() { - return jni_CSSNodeHasNewLayout(mNativePointer); - } - - private native void jni_CSSNodeMarkDirty(long nativePointer); - @Override - public void dirty() { - jni_CSSNodeMarkDirty(mNativePointer); - } - - private native boolean jni_CSSNodeIsDirty(long nativePointer); - @Override - public boolean isDirty() { - return jni_CSSNodeIsDirty(mNativePointer); - } - - private native void jni_CSSNodeMarkLayoutSeen(long nativePointer); - @Override - public void markLayoutSeen() { - jni_CSSNodeMarkLayoutSeen(mNativePointer); - } - - private native int jni_CSSNodeStyleGetDirection(long nativePointer); - @Override - public CSSDirection getStyleDirection() { - return CSSDirection.values()[jni_CSSNodeStyleGetDirection(mNativePointer)]; - } - - private native void jni_CSSNodeStyleSetDirection(long nativePointer, int direction); - @Override - public void setDirection(CSSDirection direction) { - jni_CSSNodeStyleSetDirection(mNativePointer, direction.ordinal()); - } - - private native int jni_CSSNodeStyleGetFlexDirection(long nativePointer); - @Override - public CSSFlexDirection getFlexDirection() { - return CSSFlexDirection.values()[jni_CSSNodeStyleGetFlexDirection(mNativePointer)]; - } - - private native void jni_CSSNodeStyleSetFlexDirection(long nativePointer, int flexDirection); - @Override - public void setFlexDirection(CSSFlexDirection flexDirection) { - jni_CSSNodeStyleSetFlexDirection(mNativePointer, flexDirection.ordinal()); - } - - private native int jni_CSSNodeStyleGetJustifyContent(long nativePointer); - @Override - public CSSJustify getJustifyContent() { - return CSSJustify.values()[jni_CSSNodeStyleGetJustifyContent(mNativePointer)]; - } - - private native void jni_CSSNodeStyleSetJustifyContent(long nativePointer, int justifyContent); - @Override - public void setJustifyContent(CSSJustify justifyContent) { - jni_CSSNodeStyleSetJustifyContent(mNativePointer, justifyContent.ordinal()); - } - - private native int jni_CSSNodeStyleGetAlignItems(long nativePointer); - @Override - public CSSAlign getAlignItems() { - return CSSAlign.values()[jni_CSSNodeStyleGetAlignItems(mNativePointer)]; - } - - private native void jni_CSSNodeStyleSetAlignItems(long nativePointer, int alignItems); - @Override - public void setAlignItems(CSSAlign alignItems) { - jni_CSSNodeStyleSetAlignItems(mNativePointer, alignItems.ordinal()); - } - - private native int jni_CSSNodeStyleGetAlignSelf(long nativePointer); - @Override - public CSSAlign getAlignSelf() { - return CSSAlign.values()[jni_CSSNodeStyleGetAlignSelf(mNativePointer)]; - } - - private native void jni_CSSNodeStyleSetAlignSelf(long nativePointer, int alignSelf); - @Override - public void setAlignSelf(CSSAlign alignSelf) { - jni_CSSNodeStyleSetAlignSelf(mNativePointer, alignSelf.ordinal()); - } - - private native int jni_CSSNodeStyleGetAlignContent(long nativePointer); - @Override - public CSSAlign getAlignContent() { - return CSSAlign.values()[jni_CSSNodeStyleGetAlignContent(mNativePointer)]; - } - - private native void jni_CSSNodeStyleSetAlignContent(long nativePointer, int alignContent); - @Override - public void setAlignContent(CSSAlign alignContent) { - jni_CSSNodeStyleSetAlignContent(mNativePointer, alignContent.ordinal()); - } - - private native int jni_CSSNodeStyleGetPositionType(long nativePointer); - @Override - public CSSPositionType getPositionType() { - return CSSPositionType.values()[jni_CSSNodeStyleGetPositionType(mNativePointer)]; - } - - private native void jni_CSSNodeStyleSetPositionType(long nativePointer, int positionType); - @Override - public void setPositionType(CSSPositionType positionType) { - jni_CSSNodeStyleSetPositionType(mNativePointer, positionType.ordinal()); - } - - private native void jni_CSSNodeStyleSetFlexWrap(long nativePointer, int wrapType); - @Override - public void setWrap(CSSWrap flexWrap) { - jni_CSSNodeStyleSetFlexWrap(mNativePointer, flexWrap.ordinal()); - } - - private native int jni_CSSNodeStyleGetOverflow(long nativePointer); - @Override - public CSSOverflow getOverflow() { - return CSSOverflow.values()[jni_CSSNodeStyleGetOverflow(mNativePointer)]; - } - - private native void jni_CSSNodeStyleSetOverflow(long nativePointer, int overflow); - @Override - public void setOverflow(CSSOverflow overflow) { - jni_CSSNodeStyleSetOverflow(mNativePointer, overflow.ordinal()); - } - - private native void jni_CSSNodeStyleSetFlex(long nativePointer, float flex); - @Override - public void setFlex(float flex) { - jni_CSSNodeStyleSetFlex(mNativePointer, flex); - } - - private native float jni_CSSNodeStyleGetFlexGrow(long nativePointer); - @Override - public float getFlexGrow() { - return jni_CSSNodeStyleGetFlexGrow(mNativePointer); - } - - private native void jni_CSSNodeStyleSetFlexGrow(long nativePointer, float flexGrow); - @Override - public void setFlexGrow(float flexGrow) { - jni_CSSNodeStyleSetFlexGrow(mNativePointer, flexGrow); - } - - private native float jni_CSSNodeStyleGetFlexShrink(long nativePointer); - @Override - public float getFlexShrink() { - return jni_CSSNodeStyleGetFlexShrink(mNativePointer); - } - - private native void jni_CSSNodeStyleSetFlexShrink(long nativePointer, float flexShrink); - @Override - public void setFlexShrink(float flexShrink) { - jni_CSSNodeStyleSetFlexShrink(mNativePointer, flexShrink); - } - - private native float jni_CSSNodeStyleGetFlexBasis(long nativePointer); - @Override - public float getFlexBasis() { - return jni_CSSNodeStyleGetFlexBasis(mNativePointer); - } - - private native void jni_CSSNodeStyleSetFlexBasis(long nativePointer, float flexBasis); - @Override - public void setFlexBasis(float flexBasis) { - jni_CSSNodeStyleSetFlexBasis(mNativePointer, flexBasis); - } - - private native float jni_CSSNodeStyleGetMargin(long nativePointer, int edge); - @Override - public float getMargin(int spacingType) { - if (!mHasSetMargin) { - return spacingType < Spacing.START ? 0 : CSSConstants.UNDEFINED; - } - return jni_CSSNodeStyleGetMargin(mNativePointer, spacingType); - } - - private native void jni_CSSNodeStyleSetMargin(long nativePointer, int edge, float margin); - @Override - public void setMargin(int spacingType, float margin) { - mHasSetMargin = true; - jni_CSSNodeStyleSetMargin(mNativePointer, spacingType, margin); - } - - private native float jni_CSSNodeStyleGetPadding(long nativePointer, int edge); - @Override - public float getPadding(int spacingType) { - if (!mHasSetPadding) { - return spacingType < Spacing.START ? 0 : CSSConstants.UNDEFINED; - } - return jni_CSSNodeStyleGetPadding(mNativePointer, spacingType); - } - - private native void jni_CSSNodeStyleSetPadding(long nativePointer, int edge, float padding); - @Override - public void setPadding(int spacingType, float padding) { - mHasSetPadding = true; - jni_CSSNodeStyleSetPadding(mNativePointer, spacingType, padding); - } - - private native float jni_CSSNodeStyleGetBorder(long nativePointer, int edge); - @Override - public float getBorder(int spacingType) { - if (!mHasSetBorder) { - return spacingType < Spacing.START ? 0 : CSSConstants.UNDEFINED; - } - return jni_CSSNodeStyleGetBorder(mNativePointer, spacingType); - } - - private native void jni_CSSNodeStyleSetBorder(long nativePointer, int edge, float border); - @Override - public void setBorder(int spacingType, float border) { - mHasSetBorder = true; - jni_CSSNodeStyleSetBorder(mNativePointer, spacingType, border); - } - - private native float jni_CSSNodeStyleGetPosition(long nativePointer, int edge); - @Override - public float getPosition(int spacingType) { - if (!mHasSetPosition) { - return CSSConstants.UNDEFINED; - } - return jni_CSSNodeStyleGetPosition(mNativePointer, spacingType); - } - - private native void jni_CSSNodeStyleSetPosition(long nativePointer, int edge, float position); - @Override - public void setPosition(int spacingType, float position) { - mHasSetPosition = true; - jni_CSSNodeStyleSetPosition(mNativePointer, spacingType, position); - } - - private native float jni_CSSNodeStyleGetWidth(long nativePointer); - @Override - public float getStyleWidth() { - return jni_CSSNodeStyleGetWidth(mNativePointer); - } - - private native void jni_CSSNodeStyleSetWidth(long nativePointer, float width); - @Override - public void setStyleWidth(float width) { - jni_CSSNodeStyleSetWidth(mNativePointer, width); - } - - private native float jni_CSSNodeStyleGetHeight(long nativePointer); - @Override - public float getStyleHeight() { - return jni_CSSNodeStyleGetHeight(mNativePointer); - } - - private native void jni_CSSNodeStyleSetHeight(long nativePointer, float height); - @Override - public void setStyleHeight(float height) { - jni_CSSNodeStyleSetHeight(mNativePointer, height); - } - - private native float jni_CSSNodeStyleGetMinWidth(long nativePointer); - @Override - public float getStyleMinWidth() { - return jni_CSSNodeStyleGetMinWidth(mNativePointer); - } - - private native void jni_CSSNodeStyleSetMinWidth(long nativePointer, float minWidth); - @Override - public void setStyleMinWidth(float minWidth) { - jni_CSSNodeStyleSetMinWidth(mNativePointer, minWidth); - } - - private native float jni_CSSNodeStyleGetMinHeight(long nativePointer); - @Override - public float getStyleMinHeight() { - return jni_CSSNodeStyleGetMinHeight(mNativePointer); - } - - private native void jni_CSSNodeStyleSetMinHeight(long nativePointer, float minHeight); - @Override - public void setStyleMinHeight(float minHeight) { - jni_CSSNodeStyleSetMinHeight(mNativePointer, minHeight); - } - - private native float jni_CSSNodeStyleGetMaxWidth(long nativePointer); - @Override - public float getStyleMaxWidth() { - return jni_CSSNodeStyleGetMaxWidth(mNativePointer); - } - - private native void jni_CSSNodeStyleSetMaxWidth(long nativePointer, float maxWidth); - @Override - public void setStyleMaxWidth(float maxWidth) { - jni_CSSNodeStyleSetMaxWidth(mNativePointer, maxWidth); - } - - private native float jni_CSSNodeStyleGetMaxHeight(long nativePointer); - @Override - public float getStyleMaxHeight() { - return jni_CSSNodeStyleGetMaxHeight(mNativePointer); - } - - private native void jni_CSSNodeStyleSetMaxHeight(long nativePointer, float maxheight); - @Override - public void setStyleMaxHeight(float maxheight) { - jni_CSSNodeStyleSetMaxHeight(mNativePointer, maxheight); - } - - @Override - public float getLayoutX() { - return mLeft; - } - - @Override - public float getLayoutY() { - return mTop; - } - - @Override - public float getLayoutWidth() { - return mWidth; - } - - @Override - public float getLayoutHeight() { - return mHeight; - } - - @Override - public CSSDirection getLayoutDirection() { - return CSSDirection.values()[mLayoutDirection]; - } - - private native void jni_CSSNodeSetHasMeasureFunc(long nativePointer, boolean hasMeasureFunc); - @Override - public void setMeasureFunction(MeasureFunction measureFunction) { - mMeasureFunction = measureFunction; - jni_CSSNodeSetHasMeasureFunc(mNativePointer, measureFunction != null); - } - - @DoNotStrip - public long measure(float width, int widthMode, float height, int heightMode) { - if (!isMeasureDefined()) { - throw new RuntimeException("Measure function isn't defined!"); - } - - return mMeasureFunction.measure( - this, - width, - CSSMeasureMode.values()[widthMode], - height, - CSSMeasureMode.values()[heightMode]); - } - - @Override - public boolean isMeasureDefined() { - return mMeasureFunction != null; - } - - @Override - public boolean valuesEqual(float f1, float f2) { - return FloatUtil.floatsEqual(f1, f2); - } - - @Override - public void setData(Object data) { - mData = data; - } - - @Override - public Object getData() { - return mData; - } -} diff --git a/java/com/facebook/csslayout/CSSNodeAPI.java b/java/com/facebook/csslayout/CSSNodeAPI.java deleted file mode 100644 index 5a5de382..00000000 --- a/java/com/facebook/csslayout/CSSNodeAPI.java +++ /dev/null @@ -1,94 +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. - */ - -package com.facebook.csslayout; - -public interface CSSNodeAPI { - - interface MeasureFunction { - /** - * Return a value created by MeasureOutput.make(width, height); - */ - long measure( - CSSNodeAPI node, - float width, - CSSMeasureMode widthMode, - float height, - CSSMeasureMode heightMode); - } - - int getChildCount(); - CSSNodeType getChildAt(int i); - void addChildAt(CSSNodeType child, int i); - CSSNodeType removeChildAt(int i); - CSSNodeType getParent(); - int indexOf(CSSNodeType child); - void setMeasureFunction(MeasureFunction measureFunction); - boolean isMeasureDefined(); - void setIsTextNode(boolean isTextNode); - boolean isTextNode(); - void calculateLayout(CSSLayoutContext layoutContext); - boolean isDirty(); - boolean hasNewLayout(); - void dirty(); - void markLayoutSeen(); - boolean valuesEqual(float f1, float f2); - CSSDirection getStyleDirection(); - void setDirection(CSSDirection direction); - CSSFlexDirection getFlexDirection(); - void setFlexDirection(CSSFlexDirection flexDirection); - CSSJustify getJustifyContent(); - void setJustifyContent(CSSJustify justifyContent); - CSSAlign getAlignItems(); - void setAlignItems(CSSAlign alignItems); - CSSAlign getAlignSelf(); - void setAlignSelf(CSSAlign alignSelf); - CSSAlign getAlignContent(); - void setAlignContent(CSSAlign alignContent); - CSSPositionType getPositionType(); - void setPositionType(CSSPositionType positionType); - void setWrap(CSSWrap flexWrap); - void setFlex(float flex); - float getFlexGrow(); - void setFlexGrow(float flexGrow); - float getFlexShrink(); - void setFlexShrink(float flexShrink); - float getFlexBasis(); - void setFlexBasis(float flexBasis); - float getMargin(int spacingType); - void setMargin(int spacingType, float margin); - float getPadding(int spacingType); - void setPadding(int spacingType, float padding); - float getBorder(int spacingType); - void setBorder(int spacingType, float border); - float getPosition(int spacingType); - void setPosition(int spacingType, float position); - float getStyleWidth(); - void setStyleWidth(float width); - float getStyleHeight(); - void setStyleHeight(float height); - float getStyleMaxWidth(); - void setStyleMaxWidth(float maxWidth); - float getStyleMinWidth(); - void setStyleMinWidth(float minWidth); - float getStyleMaxHeight(); - void setStyleMaxHeight(float maxHeight); - float getStyleMinHeight(); - void setStyleMinHeight(float minHeight); - float getLayoutX(); - float getLayoutY(); - float getLayoutWidth(); - float getLayoutHeight(); - CSSDirection getLayoutDirection(); - CSSOverflow getOverflow(); - void setOverflow(CSSOverflow overflow); - void setData(Object data); - Object getData(); - void reset(); -} diff --git a/java/com/facebook/csslayout/CSSNodeDEPRECATED.java b/java/com/facebook/csslayout/CSSNodeDEPRECATED.java deleted file mode 100644 index 05632cf8..00000000 --- a/java/com/facebook/csslayout/CSSNodeDEPRECATED.java +++ /dev/null @@ -1,632 +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. - */ - -package com.facebook.csslayout; - -import javax.annotation.Nullable; - -import java.util.ArrayList; - -import com.facebook.infer.annotation.Assertions; - -import static com.facebook.csslayout.CSSLayout.DIMENSION_HEIGHT; -import static com.facebook.csslayout.CSSLayout.DIMENSION_WIDTH; -import static com.facebook.csslayout.CSSLayout.POSITION_LEFT; -import static com.facebook.csslayout.CSSLayout.POSITION_TOP; - -/** - * A CSS Node. It has a style object you can manipulate at {@link #style}. After calling - * {@link #calculateLayout()}, {@link #layout} will be filled with the results of the layout. - */ -public class CSSNodeDEPRECATED implements CSSNodeAPI { - - private enum LayoutState { - /** - * Some property of this node or its children has changes and the current values in - * {@link #layout} are not valid. - */ - DIRTY, - - /** - * This node has a new layout relative to the last time {@link #markLayoutSeen()} was called. - */ - HAS_NEW_LAYOUT, - - /** - * {@link #layout} is valid for the node's properties and this layout has been marked as - * having been seen. - */ - UP_TO_DATE, - } - - // VisibleForTesting - final CSSStyle style = new CSSStyle(); - final CSSLayout layout = new CSSLayout(); - final CachedCSSLayout lastLayout = new CachedCSSLayout(); - - public int lineIndex = 0; - - CSSNodeDEPRECATED nextChild; - - private @Nullable ArrayList mChildren; - private @Nullable CSSNodeDEPRECATED mParent; - private @Nullable MeasureFunction mMeasureFunction = null; - private LayoutState mLayoutState = LayoutState.DIRTY; - private boolean mIsTextNode = false; - private Object mData; - - @Override - public int getChildCount() { - return mChildren == null ? 0 : mChildren.size(); - } - - @Override - public CSSNodeDEPRECATED getChildAt(int i) { - Assertions.assertNotNull(mChildren); - return mChildren.get(i); - } - - @Override - public void addChildAt(CSSNodeDEPRECATED child, int i) { - if (child.mParent != null) { - throw new IllegalStateException("Child already has a parent, it must be removed first."); - } - if (mChildren == null) { - // 4 is kinda arbitrary, but the default of 10 seems really high for an average View. - mChildren = new ArrayList<>(4); - } - - mChildren.add(i, child); - child.mParent = this; - dirty(); - } - - @Override - public CSSNodeDEPRECATED removeChildAt(int i) { - Assertions.assertNotNull(mChildren); - CSSNodeDEPRECATED removed = mChildren.remove(i); - removed.mParent = null; - dirty(); - return removed; - } - - @Override - public @Nullable - CSSNodeDEPRECATED getParent() { - return mParent; - } - - /** - * @return the index of the given child, or -1 if the child doesn't exist in this node. - */ - @Override - public int indexOf(CSSNodeDEPRECATED child) { - Assertions.assertNotNull(mChildren); - return mChildren.indexOf(child); - } - - @Override - public void setMeasureFunction(MeasureFunction measureFunction) { - if (mMeasureFunction != measureFunction) { - mMeasureFunction = measureFunction; - dirty(); - } - } - - @Override - public boolean isMeasureDefined() { - return mMeasureFunction != null; - } - - @Override - public void setIsTextNode(boolean isTextNode) { - mIsTextNode = isTextNode; - } - - @Override - public boolean isTextNode() { - return mIsTextNode; - } - - long measure(float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode) { - if (!isMeasureDefined()) { - throw new RuntimeException("Measure function isn't defined!"); - } - return Assertions.assertNotNull(mMeasureFunction).measure(this, width, widthMode, height, heightMode); - } - - /** - * Performs the actual layout and saves the results in {@link #layout} - */ - @Override - public void calculateLayout(CSSLayoutContext layoutContext) { - LayoutEngine.layoutNode(layoutContext, this, CSSConstants.UNDEFINED, CSSConstants.UNDEFINED, null); - } - - /** - * See {@link LayoutState#DIRTY}. - */ - @Override - public boolean isDirty() { - return mLayoutState == LayoutState.DIRTY; - } - - /** - * See {@link LayoutState#HAS_NEW_LAYOUT}. - */ - @Override - public boolean hasNewLayout() { - return mLayoutState == LayoutState.HAS_NEW_LAYOUT; - } - - @Override - public void dirty() { - if (mLayoutState == LayoutState.DIRTY) { - return; - } else if (mLayoutState == LayoutState.HAS_NEW_LAYOUT) { - throw new IllegalStateException("Previous layout was ignored! markLayoutSeen() never called"); - } - - mLayoutState = LayoutState.DIRTY; - layout.computedFlexBasis = CSSConstants.UNDEFINED; - - if (mParent != null) { - mParent.dirty(); - } - } - - void markHasNewLayout() { - mLayoutState = LayoutState.HAS_NEW_LAYOUT; - } - - /** - * Tells the node that the current values in {@link #layout} have been seen. Subsequent calls - * to {@link #hasNewLayout()} will return false until this node is laid out with new parameters. - * You must call this each time the layout is generated if the node has a new layout. - */ - @Override - public void markLayoutSeen() { - if (!hasNewLayout()) { - throw new IllegalStateException("Expected node to have a new layout to be seen!"); - } - - mLayoutState = LayoutState.UP_TO_DATE; - } - - private void toStringWithIndentation(StringBuilder result, int level) { - // Spaces and tabs are dropped by IntelliJ logcat integration, so rely on __ instead. - StringBuilder indentation = new StringBuilder(); - for (int i = 0; i < level; ++i) { - indentation.append("__"); - } - - result.append(indentation.toString()); - result.append(layout.toString()); - - if (getChildCount() == 0) { - return; - } - - result.append(", children: [\n"); - for (int i = 0; i < getChildCount(); i++) { - getChildAt(i).toStringWithIndentation(result, level + 1); - result.append("\n"); - } - result.append(indentation + "]"); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - this.toStringWithIndentation(sb, 0); - return sb.toString(); - } - - @Override - public boolean valuesEqual(float f1, float f2) { - return FloatUtil.floatsEqual(f1, f2); - } - - /** - * Get this node's direction, as defined in the style. - */ - @Override - public CSSDirection getStyleDirection() { - return style.direction; - } - - @Override - public void setDirection(CSSDirection direction) { - if (style.direction != direction) { - style.direction = direction; - dirty(); - } - } - - /** - * Get this node's flex direction, as defined by style. - */ - @Override - public CSSFlexDirection getFlexDirection() { - return style.flexDirection; - } - - @Override - public void setFlexDirection(CSSFlexDirection flexDirection) { - if (style.flexDirection != flexDirection) { - style.flexDirection = flexDirection; - dirty(); - } - } - - /** - * Get this node's justify content, as defined by style. - */ - @Override - public CSSJustify getJustifyContent() { - return style.justifyContent; - } - - @Override - public void setJustifyContent(CSSJustify justifyContent) { - if (style.justifyContent != justifyContent) { - style.justifyContent = justifyContent; - dirty(); - } - } - - /** - * Get this node's align items, as defined by style. - */ - @Override - public CSSAlign getAlignItems() { - return style.alignItems; - } - - @Override - public void setAlignItems(CSSAlign alignItems) { - if (style.alignItems != alignItems) { - style.alignItems = alignItems; - dirty(); - } - } - - /** - * Get this node's align items, as defined by style. - */ - @Override - public CSSAlign getAlignSelf() { - return style.alignSelf; - } - - @Override - public void setAlignSelf(CSSAlign alignSelf) { - if (style.alignSelf != alignSelf) { - style.alignSelf = alignSelf; - dirty(); - } - } - - @Override - public CSSAlign getAlignContent() { - return style.alignContent; - } - - @Override - public void setAlignContent(CSSAlign alignContent) { - if (style.alignContent != alignContent) { - style.alignContent = alignContent; - dirty(); - } - } - - /** - * Get this node's position type, as defined by style. - */ - @Override - public CSSPositionType getPositionType() { - return style.positionType; - } - - @Override - public void setPositionType(CSSPositionType positionType) { - if (style.positionType != positionType) { - style.positionType = positionType; - dirty(); - } - } - - @Override - public void setWrap(CSSWrap flexWrap) { - if (style.flexWrap != flexWrap) { - style.flexWrap = flexWrap; - dirty(); - } - } - - @Override - public void setFlex(float flex) { - if (CSSConstants.isUndefined(flex) || flex == 0) { - setFlexGrow(0); - setFlexShrink(0); - setFlexBasis(CSSConstants.UNDEFINED); - } else if (flex > 0) { - setFlexGrow(flex); - setFlexShrink(0); - setFlexBasis(0); - } else { - setFlexGrow(0); - setFlexShrink(-flex); - setFlexBasis(CSSConstants.UNDEFINED); - } - } - - @Override - public float getFlexGrow() { - return style.flexGrow; - } - - @Override - public void setFlexGrow(float flexGrow) { - if (!valuesEqual(style.flexGrow, flexGrow)) { - style.flexGrow = flexGrow; - dirty(); - } - } - - @Override - public float getFlexShrink() { - return style.flexShrink; - } - - @Override - public void setFlexShrink(float flexShrink) { - if (!valuesEqual(style.flexShrink, flexShrink)) { - style.flexShrink = flexShrink; - dirty(); - } - } - - @Override - public float getFlexBasis() { - return style.flexBasis; - } - - @Override - public void setFlexBasis(float flexBasis) { - if (!valuesEqual(style.flexBasis, flexBasis)) { - style.flexBasis = flexBasis; - dirty(); - } - } - - /** - * Get this node's margin, as defined by style + default margin. - */ - @Override - public float getMargin(int spacingType) { - return style.margin.get(spacingType); - } - - @Override - public void setMargin(int spacingType, float margin) { - if (style.margin.set(spacingType, margin)) { - dirty(); - } - } - - /** - * Get this node's padding, as defined by style + default padding. - */ - @Override - public float getPadding(int spacingType) { - return style.padding.get(spacingType); - } - - @Override - public void setPadding(int spacingType, float padding) { - if (style.padding.set(spacingType, padding)) { - dirty(); - } - } - - /** - * Get this node's border, as defined by style. - */ - @Override - public float getBorder(int spacingType) { - return style.border.get(spacingType); - } - - @Override - public void setBorder(int spacingType, float border) { - if (style.border.set(spacingType, border)) { - dirty(); - } - } - - /** - * Get this node's position, as defined by style. - */ - @Override - public float getPosition(int spacingType) { - return style.position.get(spacingType); - } - - @Override - public void setPosition(int spacingType, float position) { - if (style.position.set(spacingType, position)) { - dirty(); - } - } - - /** - * Get this node's width, as defined in the style. - */ - @Override - public float getStyleWidth() { - return style.dimensions[DIMENSION_WIDTH]; - } - - @Override - public void setStyleWidth(float width) { - if (!valuesEqual(style.dimensions[DIMENSION_WIDTH], width)) { - style.dimensions[DIMENSION_WIDTH] = width; - dirty(); - } - } - - /** - * Get this node's height, as defined in the style. - */ - @Override - public float getStyleHeight() { - return style.dimensions[DIMENSION_HEIGHT]; - } - - @Override - public void setStyleHeight(float height) { - if (!valuesEqual(style.dimensions[DIMENSION_HEIGHT], height)) { - style.dimensions[DIMENSION_HEIGHT] = height; - dirty(); - } - } - - /** - * Get this node's max width, as defined in the style - */ - @Override - public float getStyleMaxWidth() { - return style.maxWidth; - } - - @Override - public void setStyleMaxWidth(float maxWidth) { - if (!valuesEqual(style.maxWidth, maxWidth)) { - style.maxWidth = maxWidth; - dirty(); - } - } - - /** - * Get this node's min width, as defined in the style - */ - @Override - public float getStyleMinWidth() { - return style.minWidth; - } - - @Override - public void setStyleMinWidth(float minWidth) { - if (!valuesEqual(style.minWidth, minWidth)) { - style.minWidth = minWidth; - dirty(); - } - } - - /** - * Get this node's max height, as defined in the style - */ - @Override - public float getStyleMaxHeight() { - return style.maxHeight; - } - - @Override - public void setStyleMaxHeight(float maxHeight) { - if (!valuesEqual(style.maxHeight, maxHeight)) { - style.maxHeight = maxHeight; - dirty(); - } - } - - /** - * Get this node's min height, as defined in the style - */ - @Override - public float getStyleMinHeight() { - return style.minHeight; - } - - @Override - public void setStyleMinHeight(float minHeight) { - if (!valuesEqual(style.minHeight, minHeight)) { - style.minHeight = minHeight; - dirty(); - } - } - - @Override - public float getLayoutX() { - return layout.position[POSITION_LEFT]; - } - - @Override - public float getLayoutY() { - return layout.position[POSITION_TOP]; - } - - @Override - public float getLayoutWidth() { - return layout.dimensions[DIMENSION_WIDTH]; - } - - @Override - public float getLayoutHeight() { - return layout.dimensions[DIMENSION_HEIGHT]; - } - - @Override - public CSSDirection getLayoutDirection() { - return layout.direction; - } - - /** - * Get this node's overflow property, as defined in the style - */ - @Override - public CSSOverflow getOverflow() { - return style.overflow; - } - - @Override - public void setOverflow(CSSOverflow overflow) { - if (style.overflow != overflow) { - style.overflow = overflow; - dirty(); - } - } - - @Override - public void setData(Object data) { - mData = data; - } - - @Override - public Object getData() { - return mData; - } - - /** - * Resets this instance to its default state. This method is meant to be used when - * recycling {@link CSSNodeDEPRECATED} instances. - */ - @Override - public void reset() { - if (mParent != null || (mChildren != null && mChildren.size() > 0)) { - throw new IllegalStateException("You should not free an attached CSSNodeDEPRECATED"); - } - - style.reset(); - layout.resetResult(); - lineIndex = 0; - mLayoutState = LayoutState.DIRTY; - mMeasureFunction = null; - } -} diff --git a/java/com/facebook/csslayout/CSSOverflow.java b/java/com/facebook/csslayout/CSSOverflow.java deleted file mode 100644 index 9aae8225..00000000 --- a/java/com/facebook/csslayout/CSSOverflow.java +++ /dev/null @@ -1,16 +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. - */ - -package com.facebook.csslayout; - -public enum CSSOverflow { - VISIBLE, - HIDDEN, - SCROLL, -} diff --git a/java/com/facebook/csslayout/CSSStyle.java b/java/com/facebook/csslayout/CSSStyle.java deleted file mode 100644 index c17ce527..00000000 --- a/java/com/facebook/csslayout/CSSStyle.java +++ /dev/null @@ -1,76 +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. - */ - -package com.facebook.csslayout; - -import java.util.Arrays; - -/** - * The CSS style definition for a {@link CSSNodeDEPRECATED}. - */ -public class CSSStyle { - - public CSSDirection direction; - public CSSFlexDirection flexDirection; - public CSSJustify justifyContent; - public CSSAlign alignContent; - public CSSAlign alignItems; - public CSSAlign alignSelf; - public CSSPositionType positionType; - public CSSWrap flexWrap; - public CSSOverflow overflow; - public float flexGrow; - public float flexShrink; - public float flexBasis; - - public Spacing margin = new Spacing(); - public Spacing padding = new Spacing(); - public Spacing border = new Spacing(); - public Spacing position = new Spacing(CSSConstants.UNDEFINED); - - public float[] dimensions = new float[2]; - - public float minWidth = CSSConstants.UNDEFINED; - public float minHeight = CSSConstants.UNDEFINED; - - public float maxWidth = CSSConstants.UNDEFINED; - public float maxHeight = CSSConstants.UNDEFINED; - - CSSStyle() { - reset(); - } - - void reset() { - direction = CSSDirection.INHERIT; - flexDirection = CSSFlexDirection.COLUMN; - justifyContent = CSSJustify.FLEX_START; - alignContent = CSSAlign.FLEX_START; - alignItems = CSSAlign.STRETCH; - alignSelf = CSSAlign.AUTO; - positionType = CSSPositionType.RELATIVE; - flexWrap = CSSWrap.NOWRAP; - overflow = CSSOverflow.VISIBLE; - flexGrow = 0; - flexShrink = 0; - flexBasis = CSSConstants.UNDEFINED; - - margin.reset(); - padding.reset(); - border.reset(); - position.reset(); - - Arrays.fill(dimensions, CSSConstants.UNDEFINED); - - minWidth = CSSConstants.UNDEFINED; - minHeight = CSSConstants.UNDEFINED; - - maxWidth = CSSConstants.UNDEFINED; - maxHeight = CSSConstants.UNDEFINED; - } -} diff --git a/java/com/facebook/csslayout/CSSWrap.java b/java/com/facebook/csslayout/CSSWrap.java deleted file mode 100644 index 895bb5d5..00000000 --- a/java/com/facebook/csslayout/CSSWrap.java +++ /dev/null @@ -1,15 +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. - */ - -package com.facebook.csslayout; - -public enum CSSWrap { - NOWRAP, - WRAP, -} diff --git a/java/com/facebook/csslayout/CachedCSSLayout.java b/java/com/facebook/csslayout/CachedCSSLayout.java deleted file mode 100644 index a012a5ba..00000000 --- a/java/com/facebook/csslayout/CachedCSSLayout.java +++ /dev/null @@ -1,23 +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. - */ - -package com.facebook.csslayout; - -/** - * CSSLayout with additional information about the conditions under which it was generated. - * {@link #requestedWidth} and {@link #requestedHeight} are the width and height the parent set on - * this node before calling layout visited us. - */ -public class CachedCSSLayout extends CSSLayout { - - public float requestedWidth = CSSConstants.UNDEFINED; - public float requestedHeight = CSSConstants.UNDEFINED; - public float parentMaxWidth = CSSConstants.UNDEFINED; - public float parentMaxHeight = CSSConstants.UNDEFINED; -} diff --git a/java/com/facebook/csslayout/FloatUtil.java b/java/com/facebook/csslayout/FloatUtil.java deleted file mode 100644 index 8b211e8d..00000000 --- a/java/com/facebook/csslayout/FloatUtil.java +++ /dev/null @@ -1,22 +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. - */ - -package com.facebook.csslayout; - -public class FloatUtil { - - private static final float EPSILON = .00001f; - - public static boolean floatsEqual(float f1, float f2) { - if (Float.isNaN(f1) || Float.isNaN(f2)) { - return Float.isNaN(f1) && Float.isNaN(f2); - } - return Math.abs(f2 - f1) < EPSILON; - } -} diff --git a/java/com/facebook/csslayout/LayoutEngine.java b/java/com/facebook/csslayout/LayoutEngine.java deleted file mode 100644 index 79d33bce..00000000 --- a/java/com/facebook/csslayout/LayoutEngine.java +++ /dev/null @@ -1,1402 +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. - */ - -package com.facebook.csslayout; - -import com.facebook.infer.annotation.Assertions; - -import static com.facebook.csslayout.CSSLayout.DIMENSION_HEIGHT; -import static com.facebook.csslayout.CSSLayout.DIMENSION_WIDTH; -import static com.facebook.csslayout.CSSLayout.POSITION_BOTTOM; -import static com.facebook.csslayout.CSSLayout.POSITION_LEFT; -import static com.facebook.csslayout.CSSLayout.POSITION_RIGHT; -import static com.facebook.csslayout.CSSLayout.POSITION_TOP; - -/** - * Calculates layouts based on CSS style. See {@link #layoutNode(CSSNodeDEPRECATED, float, float)}. - */ -public class LayoutEngine { - - private static final int CSS_FLEX_DIRECTION_COLUMN = - CSSFlexDirection.COLUMN.ordinal(); - private static final int CSS_FLEX_DIRECTION_COLUMN_REVERSE = - CSSFlexDirection.COLUMN_REVERSE.ordinal(); - private static final int CSS_FLEX_DIRECTION_ROW = - CSSFlexDirection.ROW.ordinal(); - private static final int CSS_FLEX_DIRECTION_ROW_REVERSE = - CSSFlexDirection.ROW_REVERSE.ordinal(); - - private static final int CSS_POSITION_RELATIVE = CSSPositionType.RELATIVE.ordinal(); - private static final int CSS_POSITION_ABSOLUTE = CSSPositionType.ABSOLUTE.ordinal(); - - private static final int[] leading = { - POSITION_TOP, - POSITION_BOTTOM, - POSITION_LEFT, - POSITION_RIGHT, - }; - - private static final int[] trailing = { - POSITION_BOTTOM, - POSITION_TOP, - POSITION_RIGHT, - POSITION_LEFT, - }; - - private static final int[] pos = { - POSITION_TOP, - POSITION_BOTTOM, - POSITION_LEFT, - POSITION_RIGHT, - }; - - private static final int[] dim = { - DIMENSION_HEIGHT, - DIMENSION_HEIGHT, - DIMENSION_WIDTH, - DIMENSION_WIDTH, - }; - - private static final int[] leadingSpacing = { - Spacing.TOP, - Spacing.BOTTOM, - Spacing.START, - Spacing.START - }; - - private static final int[] trailingSpacing = { - Spacing.BOTTOM, - Spacing.TOP, - Spacing.END, - Spacing.END - }; - - private static boolean isFlexBasisAuto(CSSNodeDEPRECATED node) { - return CSSConstants.isUndefined(node.style.flexBasis); - } - - private static float getFlexGrowFactor(CSSNodeDEPRECATED node) { - return node.style.flexGrow; - } - - private static float getFlexShrinkFactor(CSSNodeDEPRECATED node) { - return node.style.flexShrink; - } - - - private static float boundAxisWithinMinAndMax(CSSNodeDEPRECATED node, int axis, float value) { - float min = CSSConstants.UNDEFINED; - float max = CSSConstants.UNDEFINED; - - if (axis == CSS_FLEX_DIRECTION_COLUMN || - axis == CSS_FLEX_DIRECTION_COLUMN_REVERSE) { - min = node.style.minHeight; - max = node.style.maxHeight; - } else if (axis == CSS_FLEX_DIRECTION_ROW || - axis == CSS_FLEX_DIRECTION_ROW_REVERSE) { - min = node.style.minWidth; - max = node.style.maxWidth; - } - - float boundValue = value; - - if (!Float.isNaN(max) && max >= 0.0 && boundValue > max) { - boundValue = max; - } - if (!Float.isNaN(min) && min >= 0.0 && boundValue < min) { - boundValue = min; - } - - return boundValue; - } - - private static float boundAxis(CSSNodeDEPRECATED node, int axis, float value) { - float paddingAndBorderAxis = - node.style.padding.getWithFallback(leadingSpacing[axis], leading[axis]) + - node.style.border.getWithFallback(leadingSpacing[axis], leading[axis]) + - node.style.padding.getWithFallback(trailingSpacing[axis], trailing[axis]) + - node.style.border.getWithFallback(trailingSpacing[axis], trailing[axis]); - return Math.max(boundAxisWithinMinAndMax(node, axis, value), paddingAndBorderAxis); - } - - private static float getRelativePosition(CSSNodeDEPRECATED node, int axis) { - float lead = node.style.position.getWithFallback(leadingSpacing[axis], leading[axis]); - if (!Float.isNaN(lead)) { - return lead; - } - - float trailingPos = node.style.position.getWithFallback(trailingSpacing[axis], trailing[axis]); - return Float.isNaN(trailingPos) ? 0 : -trailingPos; - } - - private static void setPosition(CSSNodeDEPRECATED node, CSSDirection direction) { - int mainAxis = resolveAxis(getFlexDirection(node), direction); - int crossAxis = getCrossFlexDirection(mainAxis, direction); - - node.layout.position[leading[mainAxis]] = node.style.margin.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + - getRelativePosition(node, mainAxis); - node.layout.position[trailing[mainAxis]] = node.style.margin.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]) + - getRelativePosition(node, mainAxis); - node.layout.position[leading[crossAxis]] = node.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + - getRelativePosition(node, crossAxis); - node.layout.position[trailing[crossAxis]] = node.style.margin.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]) + - getRelativePosition(node, crossAxis); - } - - private static int resolveAxis( - int axis, - CSSDirection direction) { - if (direction == CSSDirection.RTL) { - if (axis == CSS_FLEX_DIRECTION_ROW) { - return CSS_FLEX_DIRECTION_ROW_REVERSE; - } else if (axis == CSS_FLEX_DIRECTION_ROW_REVERSE) { - return CSS_FLEX_DIRECTION_ROW; - } - } - - return axis; - } - - private static CSSDirection resolveDirection(CSSNodeDEPRECATED node, CSSDirection parentDirection) { - CSSDirection direction = node.style.direction; - if (direction == CSSDirection.INHERIT) { - direction = (parentDirection == null ? CSSDirection.LTR : parentDirection); - } - - return direction; - } - - private static int getFlexDirection(CSSNodeDEPRECATED node) { - return node.style.flexDirection.ordinal(); - } - - private static int getCrossFlexDirection( - int axis, - CSSDirection direction) { - if (axis == CSS_FLEX_DIRECTION_COLUMN || - axis == CSS_FLEX_DIRECTION_COLUMN_REVERSE) { - return resolveAxis(CSS_FLEX_DIRECTION_ROW, direction); - } else { - return CSS_FLEX_DIRECTION_COLUMN; - } - } - - private static CSSAlign getAlignItem(CSSNodeDEPRECATED node, CSSNodeDEPRECATED child) { - if (child.style.alignSelf != CSSAlign.AUTO) { - return child.style.alignSelf; - } - return node.style.alignItems; - } - - private static boolean isMeasureDefined(CSSNodeDEPRECATED node) { - return node.isMeasureDefined(); - } - - /*package*/ static void layoutNode( - CSSLayoutContext layoutContext, - CSSNodeDEPRECATED node, - float availableWidth, - float availableHeight, - CSSDirection parentDirection) { - // 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. - layoutContext.currentGenerationCount++; - - CSSMeasureMode widthMeasureMode = CSSMeasureMode.UNDEFINED; - CSSMeasureMode heightMeasureMode = CSSMeasureMode.UNDEFINED; - - if (!Float.isNaN(availableWidth)) { - widthMeasureMode = CSSMeasureMode.EXACTLY; - } else if (node.style.dimensions[DIMENSION_WIDTH] >= 0.0) { - float marginAxisRow = (node.style.margin.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_ROW], leading[CSS_FLEX_DIRECTION_ROW]) + node.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_ROW], trailing[CSS_FLEX_DIRECTION_ROW])); - availableWidth = node.style.dimensions[DIMENSION_WIDTH] + marginAxisRow; - widthMeasureMode = CSSMeasureMode.EXACTLY; - } else if (node.style.maxWidth >= 0.0) { - availableWidth = node.style.maxWidth; - widthMeasureMode = CSSMeasureMode.AT_MOST; - } - - if (!Float.isNaN(availableHeight)) { - heightMeasureMode = CSSMeasureMode.EXACTLY; - } else if (node.style.dimensions[DIMENSION_HEIGHT] >= 0.0) { - float marginAxisColumn = (node.style.margin.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + node.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN])); - availableHeight = node.style.dimensions[DIMENSION_HEIGHT] + marginAxisColumn; - heightMeasureMode = CSSMeasureMode.EXACTLY; - } else if (node.style.maxHeight >= 0.0) { - availableHeight = node.style.maxHeight; - heightMeasureMode = CSSMeasureMode.AT_MOST; - } - - if (layoutNodeInternal(layoutContext, node, availableWidth, availableHeight, parentDirection, widthMeasureMode, heightMeasureMode, true, "initial")) { - setPosition(node, node.layout.direction); - } - } - - /*package*/ static boolean canUseCachedMeasurement( - boolean isTextNode, - float availableWidth, - float availableHeight, - float marginRow, - float marginColumn, - CSSMeasureMode widthMeasureMode, - CSSMeasureMode heightMeasureMode, - CSSCachedMeasurement cachedLayout) { - - boolean isHeightSame = - (cachedLayout.heightMeasureMode == CSSMeasureMode.UNDEFINED && heightMeasureMode == CSSMeasureMode.UNDEFINED) || - (cachedLayout.heightMeasureMode == heightMeasureMode && FloatUtil.floatsEqual(cachedLayout.availableHeight, availableHeight)); - - boolean isWidthSame = - (cachedLayout.widthMeasureMode == CSSMeasureMode.UNDEFINED && widthMeasureMode == CSSMeasureMode.UNDEFINED) || - (cachedLayout.widthMeasureMode == widthMeasureMode && FloatUtil.floatsEqual(cachedLayout.availableWidth, availableWidth)); - - if (isHeightSame && isWidthSame) { - return true; - } - - boolean isHeightValid = - (cachedLayout.heightMeasureMode == CSSMeasureMode.UNDEFINED && heightMeasureMode == CSSMeasureMode.AT_MOST && cachedLayout.computedHeight <= (availableHeight - marginColumn)) || - (heightMeasureMode == CSSMeasureMode.EXACTLY && FloatUtil.floatsEqual(cachedLayout.computedHeight, availableHeight - marginColumn)); - - if (isWidthSame && isHeightValid) { - return true; - } - - boolean isWidthValid = - (cachedLayout.widthMeasureMode == CSSMeasureMode.UNDEFINED && widthMeasureMode == CSSMeasureMode.AT_MOST && cachedLayout.computedWidth <= (availableWidth - marginRow)) || - (widthMeasureMode == CSSMeasureMode.EXACTLY && FloatUtil.floatsEqual(cachedLayout.computedWidth, availableWidth - marginRow)); - - if (isHeightSame && isWidthValid) { - return true; - } - - if (isHeightValid && isWidthValid) { - return true; - } - - // We know this to be text so we can apply some more specialized heuristics. - if (isTextNode) { - if (isWidthSame) { - if (heightMeasureMode == CSSMeasureMode.UNDEFINED) { - // Width is the same and height is not restricted. Re-use cahced value. - return true; - } - - if (heightMeasureMode == CSSMeasureMode.AT_MOST && - cachedLayout.computedHeight < (availableHeight - marginColumn)) { - // Width is the same and height restriction is greater than the cached height. Re-use cached value. - return true; - } - - // Width is the same but height restriction imposes smaller height than previously measured. - // Update the cached value to respect the new height restriction. - cachedLayout.computedHeight = availableHeight - marginColumn; - return true; - } - - if (cachedLayout.widthMeasureMode == CSSMeasureMode.UNDEFINED) { - if (widthMeasureMode == CSSMeasureMode.UNDEFINED || - (widthMeasureMode == CSSMeasureMode.AT_MOST && - cachedLayout.computedWidth <= (availableWidth - marginRow))) { - // Previsouly this text was measured with no width restriction, if width is now restricted - // but to a larger value than the previsouly measured width we can re-use the measurement - // as we know it will fit. - return true; - } - } - } - - return false; - } - - // - // This is a wrapper around the layoutNodeImpl function. It determines - // whether the layout request is redundant and can be skipped. - // - // Parameters: - // Input parameters are the same as layoutNodeImpl (see below) - // Return parameter is true if layout was performed, false if skipped - // - private static boolean layoutNodeInternal( - CSSLayoutContext layoutContext, - CSSNodeDEPRECATED node, - float availableWidth, - float availableHeight, - CSSDirection parentDirection, - CSSMeasureMode widthMeasureMode, - CSSMeasureMode heightMeasureMode, - boolean performLayout, - String reason) { - CSSLayout layout = node.layout; - - boolean needToVisitNode = (node.isDirty() && layout.generationCount != layoutContext.currentGenerationCount) || - layout.lastParentDirection != parentDirection; - - if (needToVisitNode) { - // Invalidate the cached results. - layout.nextCachedMeasurementsIndex = 0; - layout.cachedLayout.widthMeasureMode = null; - layout.cachedLayout.heightMeasureMode = null; - } - - CSSCachedMeasurement cachedResults = null; - - // Determine whether the results are already cached. We maintain a separate - // cache for layouts and measurements. A layout operation modifies the 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. - if (isMeasureDefined(node)) { - float marginAxisRow = - node.style.margin.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_ROW], leading[CSS_FLEX_DIRECTION_ROW]) + - node.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_ROW], trailing[CSS_FLEX_DIRECTION_ROW]); - float marginAxisColumn = - node.style.margin.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + - node.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]); - - // First, try to use the layout cache. - if (canUseCachedMeasurement(node.isTextNode(), availableWidth, availableHeight, marginAxisRow, marginAxisColumn, - widthMeasureMode, heightMeasureMode, layout.cachedLayout)) { - cachedResults = layout.cachedLayout; - } else { - // Try to use the measurement cache. - for (int i = 0; i < layout.nextCachedMeasurementsIndex; i++) { - if (canUseCachedMeasurement(node.isTextNode(), availableWidth, availableHeight, marginAxisRow, marginAxisColumn, - widthMeasureMode, heightMeasureMode, layout.cachedMeasurements[i])) { - cachedResults = layout.cachedMeasurements[i]; - break; - } - } - } - } else if (performLayout) { - if (FloatUtil.floatsEqual(layout.cachedLayout.availableWidth, availableWidth) && - FloatUtil.floatsEqual(layout.cachedLayout.availableHeight, availableHeight) && - layout.cachedLayout.widthMeasureMode == widthMeasureMode && - layout.cachedLayout.heightMeasureMode == heightMeasureMode) { - - cachedResults = layout.cachedLayout; - } - } else { - for (int i = 0; i < layout.nextCachedMeasurementsIndex; i++) { - if (FloatUtil.floatsEqual(layout.cachedMeasurements[i].availableWidth, availableWidth) && - FloatUtil.floatsEqual(layout.cachedMeasurements[i].availableHeight, availableHeight) && - layout.cachedMeasurements[i].widthMeasureMode == widthMeasureMode && - layout.cachedMeasurements[i].heightMeasureMode == heightMeasureMode) { - - cachedResults = layout.cachedMeasurements[i]; - break; - } - } - } - - if (!needToVisitNode && cachedResults != null) { - layout.measuredDimensions[DIMENSION_WIDTH] = cachedResults.computedWidth; - layout.measuredDimensions[DIMENSION_HEIGHT] = cachedResults.computedHeight; - } else { - layoutNodeImpl(layoutContext, node, availableWidth, availableHeight, parentDirection, widthMeasureMode, heightMeasureMode, performLayout); - - layout.lastParentDirection = parentDirection; - - if (cachedResults == null) { - if (layout.nextCachedMeasurementsIndex == CSSLayout.MAX_CACHED_RESULT_COUNT) { - layout.nextCachedMeasurementsIndex = 0; - } - - CSSCachedMeasurement newCacheEntry = null; - if (performLayout) { - // Use the single layout cache entry. - newCacheEntry = layout.cachedLayout; - } else { - // Allocate a new measurement cache entry. - newCacheEntry = layout.cachedMeasurements[layout.nextCachedMeasurementsIndex]; - if (newCacheEntry == null) { - newCacheEntry = new CSSCachedMeasurement(); - layout.cachedMeasurements[layout.nextCachedMeasurementsIndex] = newCacheEntry; - } - layout.nextCachedMeasurementsIndex++; - } - - newCacheEntry.availableWidth = availableWidth; - newCacheEntry.availableHeight = availableHeight; - newCacheEntry.widthMeasureMode = widthMeasureMode; - newCacheEntry.heightMeasureMode = heightMeasureMode; - newCacheEntry.computedWidth = layout.measuredDimensions[DIMENSION_WIDTH]; - newCacheEntry.computedHeight = layout.measuredDimensions[DIMENSION_HEIGHT]; - } - } - - if (performLayout) { - node.layout.dimensions[DIMENSION_WIDTH] = node.layout.measuredDimensions[DIMENSION_WIDTH]; - node.layout.dimensions[DIMENSION_HEIGHT] = node.layout.measuredDimensions[DIMENSION_HEIGHT]; - node.markHasNewLayout(); - } - - layout.generationCount = layoutContext.currentGenerationCount; - return (needToVisitNode || cachedResults == null); - } - - - // - // This is the main routine that implements a subset of the flexbox layout algorithm - // described in the W3C CSS documentation: https://www.w3.org/TR/css3-flexbox/. - // - // 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. - // * The 'wrap' property supports only 'nowrap' (which is the default) or 'wrap'. The - // rarely-used 'wrap-reverse' is not supported. - // * Rather than allowing arbitrary combinations of flexGrow, flexShrink and - // flexBasis, this algorithm supports only the three most common combinations: - // flex: 0 is equiavlent to flex: 0 0 auto - // flex: n (where n is a positive value) is equivalent to flex: n 1 auto - // If POSITIVE_FLEX_IS_AUTO is 0, then it is equivalent to flex: n 0 0 - // This is faster because the content doesn't need to be measured, but it's - // less flexible because the basis is always 0 and can't be overriden with - // the width/height attributes. - // flex: -1 (or any negative value) is equivalent to flex: 0 1 auto - // * Margins cannot be specified as 'auto'. They must be specified in terms of pixel - // values, and the default value is 0. - // * The 'baseline' value is not supported for alignItems and alignSelf properties. - // * Values of width, maxWidth, minWidth, height, maxHeight and minHeight must be - // specified as pixel values, not as percentages. - // * There is no support for calculation of dimensions based on intrinsic aspect ratios - // (e.g. images). - // * 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 - // or CSS_UNDEFINED if the size is not available; interpretation depends on 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.measured_dimensions fields for the input node as well - // as the layout.position and layout.line_index fields for its child nodes. The - // layout.measured_dimensions 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 - // from the spec (https://www.w3.org/TR/css3-sizing/#terms): - // - CSS_MEASURE_MODE_UNDEFINED: max content - // - CSS_MEASURE_MODE_EXACTLY: fill available - // - CSS_MEASURE_MODE_AT_MOST: fit content - // - // When calling layoutNodeImpl and layoutNodeInternal, if the caller passes an available size of - // undefined then it must also pass a measure mode of CSS_MEASURE_MODE_UNDEFINED in that dimension. - // - private static void layoutNodeImpl( - CSSLayoutContext layoutContext, - CSSNodeDEPRECATED node, - float availableWidth, - float availableHeight, - CSSDirection parentDirection, - CSSMeasureMode widthMeasureMode, - CSSMeasureMode heightMeasureMode, - boolean performLayout) { - - Assertions.assertCondition(Float.isNaN(availableWidth) ? widthMeasureMode == CSSMeasureMode.UNDEFINED : true, "availableWidth is indefinite so widthMeasureMode must be CSSMeasureMode.UNDEFINED"); - Assertions.assertCondition(Float.isNaN(availableHeight) ? heightMeasureMode == CSSMeasureMode.UNDEFINED : true, "availableHeight is indefinite so heightMeasureMode must be CSSMeasureMode.UNDEFINED"); - - float paddingAndBorderAxisRow = ((node.style.padding.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_ROW], leading[CSS_FLEX_DIRECTION_ROW]) + node.style.border.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_ROW], leading[CSS_FLEX_DIRECTION_ROW])) + (node.style.padding.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_ROW], trailing[CSS_FLEX_DIRECTION_ROW]) + node.style.border.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_ROW], trailing[CSS_FLEX_DIRECTION_ROW]))); - float paddingAndBorderAxisColumn = ((node.style.padding.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN])) + (node.style.padding.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]))); - float marginAxisRow = (node.style.margin.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_ROW], leading[CSS_FLEX_DIRECTION_ROW]) + node.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_ROW], trailing[CSS_FLEX_DIRECTION_ROW])); - float marginAxisColumn = (node.style.margin.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + node.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN])); - - // Set the resolved resolution in the node's layout. - CSSDirection direction = resolveDirection(node, parentDirection); - node.layout.direction = direction; - - // For content (text) nodes, determine the dimensions based on the text contents. - if (isMeasureDefined(node)) { - float innerWidth = availableWidth - marginAxisRow - paddingAndBorderAxisRow; - float innerHeight = availableHeight - marginAxisColumn - paddingAndBorderAxisColumn; - - if (widthMeasureMode == CSSMeasureMode.EXACTLY && heightMeasureMode == CSSMeasureMode.EXACTLY) { - - // Don't bother sizing the text if both dimensions are already defined. - node.layout.measuredDimensions[DIMENSION_WIDTH] = boundAxis(node, CSS_FLEX_DIRECTION_ROW, availableWidth - marginAxisRow); - node.layout.measuredDimensions[DIMENSION_HEIGHT] = boundAxis(node, CSS_FLEX_DIRECTION_COLUMN, availableHeight - marginAxisColumn); - } else if (innerWidth <= 0 || innerHeight <= 0) { - - // Don't bother sizing the text if there's no horizontal or vertical space. - node.layout.measuredDimensions[DIMENSION_WIDTH] = boundAxis(node, CSS_FLEX_DIRECTION_ROW, 0); - node.layout.measuredDimensions[DIMENSION_HEIGHT] = boundAxis(node, CSS_FLEX_DIRECTION_COLUMN, 0); - } else { - - // Measure the text under the current constraints. - long measureOutput = node.measure( - innerWidth, - widthMeasureMode, - innerHeight, - heightMeasureMode - ); - - int outputWidth = MeasureOutput.getWidth(measureOutput); - int outputHeight = MeasureOutput.getHeight(measureOutput); - - node.layout.measuredDimensions[DIMENSION_WIDTH] = boundAxis(node, CSS_FLEX_DIRECTION_ROW, - (widthMeasureMode == CSSMeasureMode.UNDEFINED || widthMeasureMode == CSSMeasureMode.AT_MOST) ? - outputWidth + paddingAndBorderAxisRow : - availableWidth - marginAxisRow); - node.layout.measuredDimensions[DIMENSION_HEIGHT] = boundAxis(node, CSS_FLEX_DIRECTION_COLUMN, - (heightMeasureMode == CSSMeasureMode.UNDEFINED || heightMeasureMode == CSSMeasureMode.AT_MOST) ? - outputHeight + paddingAndBorderAxisColumn : - availableHeight - marginAxisColumn); - } - - return; - } - - // 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. - int childCount = node.getChildCount(); - if (childCount == 0) { - node.layout.measuredDimensions[DIMENSION_WIDTH] = boundAxis(node, CSS_FLEX_DIRECTION_ROW, - (widthMeasureMode == CSSMeasureMode.UNDEFINED || widthMeasureMode == CSSMeasureMode.AT_MOST) ? - paddingAndBorderAxisRow : - availableWidth - marginAxisRow); - node.layout.measuredDimensions[DIMENSION_HEIGHT] = boundAxis(node, CSS_FLEX_DIRECTION_COLUMN, - (heightMeasureMode == CSSMeasureMode.UNDEFINED || heightMeasureMode == CSSMeasureMode.AT_MOST) ? - paddingAndBorderAxisColumn : - availableHeight - marginAxisColumn); - return; - } - - // If we're not being asked to perform a full layout, we can handle a number of common - // cases here without incurring the cost of the remaining function. - if (!performLayout) { - // If we're being asked to size the content with an at most constraint but there is no available width, - // the measurement will always be zero. - if (widthMeasureMode == CSSMeasureMode.AT_MOST && availableWidth <= 0 && - heightMeasureMode == CSSMeasureMode.AT_MOST && availableHeight <= 0) { - node.layout.measuredDimensions[DIMENSION_WIDTH] = boundAxis(node, CSS_FLEX_DIRECTION_ROW, 0); - node.layout.measuredDimensions[DIMENSION_HEIGHT] = boundAxis(node, CSS_FLEX_DIRECTION_COLUMN, 0); - return; - } - - if (widthMeasureMode == CSSMeasureMode.AT_MOST && availableWidth <= 0) { - node.layout.measuredDimensions[DIMENSION_WIDTH] = boundAxis(node, CSS_FLEX_DIRECTION_ROW, 0); - node.layout.measuredDimensions[DIMENSION_HEIGHT] = boundAxis(node, CSS_FLEX_DIRECTION_COLUMN, Float.isNaN(availableHeight) ? 0 : (availableHeight - marginAxisColumn)); - return; - } - - if (heightMeasureMode == CSSMeasureMode.AT_MOST && availableHeight <= 0) { - node.layout.measuredDimensions[DIMENSION_WIDTH] = boundAxis(node, CSS_FLEX_DIRECTION_ROW, Float.isNaN(availableWidth) ? 0 : (availableWidth - marginAxisRow)); - node.layout.measuredDimensions[DIMENSION_HEIGHT] = boundAxis(node, CSS_FLEX_DIRECTION_COLUMN, 0); - return; - } - - // If we're being asked to use an exact width/height, there's no need to measure the children. - if (widthMeasureMode == CSSMeasureMode.EXACTLY && heightMeasureMode == CSSMeasureMode.EXACTLY) { - node.layout.measuredDimensions[DIMENSION_WIDTH] = boundAxis(node, CSS_FLEX_DIRECTION_ROW, availableWidth - marginAxisRow); - node.layout.measuredDimensions[DIMENSION_HEIGHT] = boundAxis(node, CSS_FLEX_DIRECTION_COLUMN, availableHeight - marginAxisColumn); - return; - } - } - - // STEP 1: CALCULATE VALUES FOR REMAINDER OF ALGORITHM - int mainAxis = resolveAxis(getFlexDirection(node), direction); - int crossAxis = getCrossFlexDirection(mainAxis, direction); - boolean isMainAxisRow = (mainAxis == CSS_FLEX_DIRECTION_ROW || mainAxis == CSS_FLEX_DIRECTION_ROW_REVERSE); - CSSJustify justifyContent = node.style.justifyContent; - boolean isNodeFlexWrap = (node.style.flexWrap == CSSWrap.WRAP); - - CSSNodeDEPRECATED firstAbsoluteChild = null; - CSSNodeDEPRECATED currentAbsoluteChild = null; - - float leadingPaddingAndBorderMain = (node.style.padding.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + node.style.border.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis])); - float trailingPaddingAndBorderMain = (node.style.padding.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]) + node.style.border.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis])); - float leadingPaddingAndBorderCross = (node.style.padding.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + node.style.border.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis])); - float paddingAndBorderAxisMain = ((node.style.padding.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + node.style.border.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis])) + (node.style.padding.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]) + node.style.border.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]))); - float paddingAndBorderAxisCross = ((node.style.padding.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + node.style.border.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis])) + (node.style.padding.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]) + node.style.border.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]))); - - CSSMeasureMode measureModeMainDim = isMainAxisRow ? widthMeasureMode : heightMeasureMode; - CSSMeasureMode measureModeCrossDim = isMainAxisRow ? heightMeasureMode : widthMeasureMode; - - // STEP 2: DETERMINE AVAILABLE SIZE IN MAIN AND CROSS DIRECTIONS - float availableInnerWidth = availableWidth - marginAxisRow - paddingAndBorderAxisRow; - float availableInnerHeight = availableHeight - marginAxisColumn - paddingAndBorderAxisColumn; - float availableInnerMainDim = isMainAxisRow ? availableInnerWidth : availableInnerHeight; - float availableInnerCrossDim = isMainAxisRow ? availableInnerHeight : availableInnerWidth; - - // STEP 3: DETERMINE FLEX BASIS FOR EACH ITEM - CSSNodeDEPRECATED child; - int i; - float childWidth; - float childHeight; - CSSMeasureMode childWidthMeasureMode; - CSSMeasureMode childHeightMeasureMode; - for (i = 0; i < childCount; i++) { - child = node.getChildAt(i); - - if (performLayout) { - // Set the initial position (relative to the parent). - CSSDirection childDirection = resolveDirection(child, direction); - setPosition(child, childDirection); - } - - // Absolute-positioned children don't participate in flex layout. Add them - // to a list that we can process later. - if (child.style.positionType == CSSPositionType.ABSOLUTE) { - - // Store a private linked list of absolutely positioned children - // so that we can efficiently traverse them later. - if (firstAbsoluteChild == null) { - firstAbsoluteChild = child; - } - if (currentAbsoluteChild != null) { - currentAbsoluteChild.nextChild = child; - } - currentAbsoluteChild = child; - child.nextChild = null; - } else { - - if (isMainAxisRow && (child.style.dimensions[dim[CSS_FLEX_DIRECTION_ROW]] >= 0.0)) { - - // The width is definite, so use that as the flex basis. - child.layout.computedFlexBasis = Math.max(child.style.dimensions[DIMENSION_WIDTH], ((child.style.padding.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_ROW], leading[CSS_FLEX_DIRECTION_ROW]) + child.style.border.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_ROW], leading[CSS_FLEX_DIRECTION_ROW])) + (child.style.padding.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_ROW], trailing[CSS_FLEX_DIRECTION_ROW]) + child.style.border.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_ROW], trailing[CSS_FLEX_DIRECTION_ROW])))); - } else if (!isMainAxisRow && (child.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] >= 0.0)) { - - // The height is definite, so use that as the flex basis. - child.layout.computedFlexBasis = Math.max(child.style.dimensions[DIMENSION_HEIGHT], ((child.style.padding.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + child.style.border.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN])) + (child.style.padding.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]) + child.style.border.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN])))); - } else if (!isFlexBasisAuto(child) && !Float.isNaN(availableInnerMainDim)) { - if (Float.isNaN(child.layout.computedFlexBasis)) { - child.layout.computedFlexBasis = Math.max(child.style.flexBasis, ((child.style.padding.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + child.style.border.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis])) + (child.style.padding.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]) + child.style.border.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis])))); - } - } else { - - // Compute the flex basis and hypothetical main size (i.e. the clamped flex basis). - childWidth = CSSConstants.UNDEFINED; - childHeight = CSSConstants.UNDEFINED; - childWidthMeasureMode = CSSMeasureMode.UNDEFINED; - childHeightMeasureMode = CSSMeasureMode.UNDEFINED; - - if ((child.style.dimensions[dim[CSS_FLEX_DIRECTION_ROW]] >= 0.0)) { - childWidth = child.style.dimensions[DIMENSION_WIDTH] + (child.style.margin.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_ROW], leading[CSS_FLEX_DIRECTION_ROW]) + child.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_ROW], trailing[CSS_FLEX_DIRECTION_ROW])); - childWidthMeasureMode = CSSMeasureMode.EXACTLY; - } - if ((child.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] >= 0.0)) { - childHeight = child.style.dimensions[DIMENSION_HEIGHT] + (child.style.margin.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + child.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN])); - childHeightMeasureMode = CSSMeasureMode.EXACTLY; - } - - // The W3C spec doesn't say anything about the 'overflow' property, - // but all major browsers appear to implement the following logic. - if ((!isMainAxisRow && node.style.overflow == CSSOverflow.SCROLL) || node.style.overflow != CSSOverflow.SCROLL) { - if (Float.isNaN(childWidth) && !Float.isNaN(availableInnerWidth)) { - childWidth = availableInnerWidth; - childWidthMeasureMode = CSSMeasureMode.AT_MOST; - } - } - - if ((isMainAxisRow && node.style.overflow == CSSOverflow.SCROLL) || node.style.overflow != CSSOverflow.SCROLL) { - if (Float.isNaN(childHeight) && !Float.isNaN(availableInnerHeight)) { - childHeight = availableInnerHeight; - childHeightMeasureMode = CSSMeasureMode.AT_MOST; - } - } - - // 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 - if (!isMainAxisRow && - !Float.isNaN(availableInnerWidth) && - !(child.style.dimensions[dim[CSS_FLEX_DIRECTION_ROW]] >= 0.0) && - widthMeasureMode == CSSMeasureMode.EXACTLY && - getAlignItem(node, child) == CSSAlign.STRETCH) { - childWidth = availableInnerWidth; - childWidthMeasureMode = CSSMeasureMode.EXACTLY; - } - if (isMainAxisRow && - !Float.isNaN(availableInnerHeight) && - !(child.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] >= 0.0) && - heightMeasureMode == CSSMeasureMode.EXACTLY && - getAlignItem(node, child) == CSSAlign.STRETCH) { - childHeight = availableInnerHeight; - childHeightMeasureMode = CSSMeasureMode.EXACTLY; - } - - // Measure the child - layoutNodeInternal(layoutContext, child, childWidth, childHeight, direction, childWidthMeasureMode, childHeightMeasureMode, false, "measure"); - - child.layout.computedFlexBasis = Math.max(isMainAxisRow ? child.layout.measuredDimensions[DIMENSION_WIDTH] : child.layout.measuredDimensions[DIMENSION_HEIGHT], ((child.style.padding.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + child.style.border.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis])) + (child.style.padding.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis]) + child.style.border.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis])))); - } - } - } - - // STEP 4: COLLECT FLEX ITEMS INTO FLEX LINES - - // Indexes of children that represent the first and last items in the line. - int startOfLineIndex = 0; - int endOfLineIndex = 0; - - // Number of lines. - int lineCount = 0; - - // Accumulated cross dimensions of all lines so far. - float totalLineCrossDim = 0; - - // Max main dimension of all the lines. - float maxLineMainDim = 0; - - while (endOfLineIndex < childCount) { - - // 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. - int 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; - - float totalFlexGrowFactors = 0; - float totalFlexShrinkScaledFactors = 0; - - i = startOfLineIndex; - - // Maintain a linked list of the child nodes that can shrink and/or grow. - CSSNodeDEPRECATED firstRelativeChild = null; - CSSNodeDEPRECATED currentRelativeChild = null; - - // Add items to the current line until it's full or we run out of items. - while (i < childCount) { - child = node.getChildAt(i); - child.lineIndex = lineCount; - - if (child.style.positionType != CSSPositionType.ABSOLUTE) { - float outerFlexBasis = child.layout.computedFlexBasis + (child.style.margin.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + child.style.margin.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis])); - - // 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. - if (sizeConsumedOnCurrentLine + outerFlexBasis > availableInnerMainDim && isNodeFlexWrap && itemsOnLine > 0) { - break; - } - - sizeConsumedOnCurrentLine += outerFlexBasis; - itemsOnLine++; - - if ((child.style.positionType == CSSPositionType.RELATIVE && (child.style.flexGrow != 0 || child.style.flexShrink != 0))) { - totalFlexGrowFactors += getFlexGrowFactor(child); - - // Unlike the grow factor, the shrink factor is scaled relative to the child - // dimension. - totalFlexShrinkScaledFactors += getFlexShrinkFactor(child) * child.layout.computedFlexBasis; - } - - // Store a private linked list of children that need to be layed out. - if (firstRelativeChild == null) { - firstRelativeChild = child; - } - if (currentRelativeChild != null) { - currentRelativeChild.nextChild = child; - } - currentRelativeChild = child; - child.nextChild = null; - } - - i++; - endOfLineIndex++; - } - - // If we don't need to measure the cross axis, we can skip the entire flex step. - boolean canSkipFlex = !performLayout && measureModeCrossDim == CSSMeasureMode.EXACTLY; - - // 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. - float remainingFreeSpace = 0; - if (!Float.isNaN(availableInnerMainDim)) { - remainingFreeSpace = availableInnerMainDim - sizeConsumedOnCurrentLine; - } else if (sizeConsumedOnCurrentLine < 0) { - // availableInnerMainDim is indefinite which means the node is being sized based on its content. - // sizeConsumedOnCurrentLine is negative which means the node will allocate 0 pixels for - // its content. Consequently, remainingFreeSpace is 0 - sizeConsumedOnCurrentLine. - remainingFreeSpace = -sizeConsumedOnCurrentLine; - } - - 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 - // spec (https://www.w3.org/TR/css-flexbox-1/#resolve-flexible-lengths) 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; - while (currentRelativeChild != null) { - childFlexBasis = currentRelativeChild.layout.computedFlexBasis; - - if (remainingFreeSpace < 0) { - flexShrinkScaledFactor = getFlexShrinkFactor(currentRelativeChild) * childFlexBasis; - - // Is this child able to shrink? - if (flexShrinkScaledFactor != 0) { - baseMainSize = childFlexBasis + - remainingFreeSpace / totalFlexShrinkScaledFactors * flexShrinkScaledFactor; - boundMainSize = boundAxis(currentRelativeChild, mainAxis, baseMainSize); - 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) { - flexGrowFactor = getFlexGrowFactor(currentRelativeChild); - - // Is this child able to grow? - if (flexGrowFactor != 0) { - baseMainSize = childFlexBasis + - remainingFreeSpace / totalFlexGrowFactors * flexGrowFactor; - boundMainSize = boundAxis(currentRelativeChild, mainAxis, baseMainSize); - 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; - } - } - } - - currentRelativeChild = currentRelativeChild.nextChild; - } - - totalFlexShrinkScaledFactors += deltaFlexShrinkScaledFactors; - totalFlexGrowFactors += deltaFlexGrowFactors; - remainingFreeSpace += deltaFreeSpace; - - // Second pass: resolve the sizes of the flexible items - deltaFreeSpace = 0; - currentRelativeChild = firstRelativeChild; - while (currentRelativeChild != null) { - childFlexBasis = currentRelativeChild.layout.computedFlexBasis; - float updatedMainSize = childFlexBasis; - - if (remainingFreeSpace < 0) { - flexShrinkScaledFactor = getFlexShrinkFactor(currentRelativeChild) * childFlexBasis; - - // Is this child able to shrink? - if (flexShrinkScaledFactor != 0) { - updatedMainSize = boundAxis(currentRelativeChild, mainAxis, childFlexBasis + - remainingFreeSpace / totalFlexShrinkScaledFactors * flexShrinkScaledFactor); - } - } else if (remainingFreeSpace > 0) { - flexGrowFactor = getFlexGrowFactor(currentRelativeChild); - - // Is this child able to grow? - if (flexGrowFactor != 0) { - updatedMainSize = boundAxis(currentRelativeChild, mainAxis, childFlexBasis + - remainingFreeSpace / totalFlexGrowFactors * flexGrowFactor); - } - } - - deltaFreeSpace -= updatedMainSize - childFlexBasis; - - if (isMainAxisRow) { - childWidth = updatedMainSize + (currentRelativeChild.style.margin.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_ROW], leading[CSS_FLEX_DIRECTION_ROW]) + currentRelativeChild.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_ROW], trailing[CSS_FLEX_DIRECTION_ROW])); - childWidthMeasureMode = CSSMeasureMode.EXACTLY; - - if (!Float.isNaN(availableInnerCrossDim) && - !(currentRelativeChild.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] >= 0.0) && - heightMeasureMode == CSSMeasureMode.EXACTLY && - getAlignItem(node, currentRelativeChild) == CSSAlign.STRETCH) { - childHeight = availableInnerCrossDim; - childHeightMeasureMode = CSSMeasureMode.EXACTLY; - } else if (!(currentRelativeChild.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] >= 0.0)) { - childHeight = availableInnerCrossDim; - childHeightMeasureMode = Float.isNaN(childHeight) ? CSSMeasureMode.UNDEFINED : CSSMeasureMode.AT_MOST; - } else { - childHeight = currentRelativeChild.style.dimensions[DIMENSION_HEIGHT] + (currentRelativeChild.style.margin.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + currentRelativeChild.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN])); - childHeightMeasureMode = CSSMeasureMode.EXACTLY; - } - } else { - childHeight = updatedMainSize + (currentRelativeChild.style.margin.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + currentRelativeChild.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN])); - childHeightMeasureMode = CSSMeasureMode.EXACTLY; - - if (!Float.isNaN(availableInnerCrossDim) && - !(currentRelativeChild.style.dimensions[dim[CSS_FLEX_DIRECTION_ROW]] >= 0.0) && - widthMeasureMode == CSSMeasureMode.EXACTLY && - getAlignItem(node, currentRelativeChild) == CSSAlign.STRETCH) { - childWidth = availableInnerCrossDim; - childWidthMeasureMode = CSSMeasureMode.EXACTLY; - } else if (!(currentRelativeChild.style.dimensions[dim[CSS_FLEX_DIRECTION_ROW]] >= 0.0)) { - childWidth = availableInnerCrossDim; - childWidthMeasureMode = Float.isNaN(childWidth) ? CSSMeasureMode.UNDEFINED : CSSMeasureMode.AT_MOST; - } else { - childWidth = currentRelativeChild.style.dimensions[DIMENSION_WIDTH] + (currentRelativeChild.style.margin.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_ROW], leading[CSS_FLEX_DIRECTION_ROW]) + currentRelativeChild.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_ROW], trailing[CSS_FLEX_DIRECTION_ROW])); - childWidthMeasureMode = CSSMeasureMode.EXACTLY; - } - } - - boolean requiresStretchLayout = !(currentRelativeChild.style.dimensions[dim[crossAxis]] >= 0.0) && - getAlignItem(node, currentRelativeChild) == CSSAlign.STRETCH; - - // Recursively call the layout algorithm for this child with the updated main size. - layoutNodeInternal(layoutContext, currentRelativeChild, childWidth, childHeight, direction, childWidthMeasureMode, childHeightMeasureMode, performLayout && !requiresStretchLayout, "flex"); - - currentRelativeChild = currentRelativeChild.nextChild; - } - } - - remainingFreeSpace = originalRemainingFreeSpace + deltaFreeSpace; - - // 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, we won't distribute - // any remaining space at this point. - if (measureModeMainDim == CSSMeasureMode.AT_MOST) { - remainingFreeSpace = 0; - } - - // Use justifyContent to figure out how to allocate the remaining space - // available in the main axis. - if (justifyContent != CSSJustify.FLEX_START) { - if (justifyContent == CSSJustify.CENTER) { - leadingMainDim = remainingFreeSpace / 2; - } else if (justifyContent == CSSJustify.FLEX_END) { - leadingMainDim = remainingFreeSpace; - } else if (justifyContent == CSSJustify.SPACE_BETWEEN) { - remainingFreeSpace = Math.max(remainingFreeSpace, 0); - if (itemsOnLine > 1) { - betweenMainDim = remainingFreeSpace / (itemsOnLine - 1); - } else { - betweenMainDim = 0; - } - } else if (justifyContent == CSSJustify.SPACE_AROUND) { - // Space on the edges is half of the space between elements - betweenMainDim = remainingFreeSpace / itemsOnLine; - leadingMainDim = betweenMainDim / 2; - } - } - - float mainDim = leadingPaddingAndBorderMain + leadingMainDim; - float crossDim = 0; - - for (i = startOfLineIndex; i < endOfLineIndex; ++i) { - child = node.getChildAt(i); - - if (child.style.positionType == CSSPositionType.ABSOLUTE && - !Float.isNaN(child.style.position.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]))) { - 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). - child.layout.position[pos[mainAxis]] = - (Float.isNaN(child.style.position.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis])) ? - 0 : - child.style.position.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis])) + - node.style.border.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + - child.style.margin.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]); - } - } else { - if (performLayout) { - // If the child is position absolute (without top/left) or relative, - // we put it at the current accumulated offset. - child.layout.position[pos[mainAxis]] += mainDim; - } - - // 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. - if (child.style.positionType == CSSPositionType.RELATIVE) { - if (canSkipFlex) { - // If we skipped the flex step, then we can't rely on the measuredDims because - // they weren't computed. This means we can't call getDimWithMargin. - mainDim += betweenMainDim + (child.style.margin.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + child.style.margin.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis])) + child.layout.computedFlexBasis; - crossDim = availableInnerCrossDim; - } else { - // The main dimension is the sum of all the elements dimension plus - // the spacing. - mainDim += betweenMainDim + (child.layout.measuredDimensions[dim[mainAxis]] + child.style.margin.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]) + child.style.margin.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis])); - - // The cross dimension is the max of the elements dimension since there - // can only be one element in that cross dimension. - crossDim = Math.max(crossDim, (child.layout.measuredDimensions[dim[crossAxis]] + child.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + child.style.margin.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]))); - } - } - } - } - - mainDim += trailingPaddingAndBorderMain; - - float containerCrossAxis = availableInnerCrossDim; - if (measureModeCrossDim == CSSMeasureMode.UNDEFINED || measureModeCrossDim == CSSMeasureMode.AT_MOST) { - // Compute the cross axis from the max cross dimension of the children. - containerCrossAxis = boundAxis(node, crossAxis, crossDim + paddingAndBorderAxisCross) - paddingAndBorderAxisCross; - - if (measureModeCrossDim == CSSMeasureMode.AT_MOST) { - containerCrossAxis = Math.min(containerCrossAxis, availableInnerCrossDim); - } - } - - // If there's no flex wrap, the cross dimension is defined by the container. - if (!isNodeFlexWrap && measureModeCrossDim == CSSMeasureMode.EXACTLY) { - crossDim = availableInnerCrossDim; - } - - // Clamp to the min/max size specified on the container. - crossDim = boundAxis(node, crossAxis, crossDim + paddingAndBorderAxisCross) - paddingAndBorderAxisCross; - - // STEP 7: CROSS-AXIS ALIGNMENT - // We can skip child alignment if we're just measuring the container. - if (performLayout) { - for (i = startOfLineIndex; i < endOfLineIndex; ++i) { - child = node.getChildAt(i); - - if (child.style.positionType == CSSPositionType.ABSOLUTE) { - // If the child is absolutely positioned and has a top/left/bottom/right - // set, override all the previously computed positions to set it correctly. - if (!Float.isNaN(child.style.position.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]))) { - child.layout.position[pos[crossAxis]] = - (Float.isNaN(child.style.position.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis])) ? - 0 : - child.style.position.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis])) + - node.style.border.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + - child.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]); - } else { - child.layout.position[pos[crossAxis]] = leadingPaddingAndBorderCross + - child.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]); - } - } 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 - CSSAlign alignItem = getAlignItem(node, child); - - // 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. - if (alignItem == CSSAlign.STRETCH) { - childWidth = child.layout.measuredDimensions[DIMENSION_WIDTH] + (child.style.margin.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_ROW], leading[CSS_FLEX_DIRECTION_ROW]) + child.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_ROW], trailing[CSS_FLEX_DIRECTION_ROW])); - childHeight = child.layout.measuredDimensions[DIMENSION_HEIGHT] + (child.style.margin.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + child.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN])); - boolean isCrossSizeDefinite = false; - - if (isMainAxisRow) { - isCrossSizeDefinite = (child.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] >= 0.0); - childHeight = crossDim; - } else { - isCrossSizeDefinite = (child.style.dimensions[dim[CSS_FLEX_DIRECTION_ROW]] >= 0.0); - childWidth = crossDim; - } - - // If the child defines a definite size for its cross axis, there's no need to stretch. - if (!isCrossSizeDefinite) { - childWidthMeasureMode = Float.isNaN(childWidth) ? CSSMeasureMode.UNDEFINED : CSSMeasureMode.EXACTLY; - childHeightMeasureMode = Float.isNaN(childHeight) ? CSSMeasureMode.UNDEFINED : CSSMeasureMode.EXACTLY; - layoutNodeInternal(layoutContext, child, childWidth, childHeight, direction, childWidthMeasureMode, childHeightMeasureMode, true, "stretch"); - } - } else if (alignItem != CSSAlign.FLEX_START) { - float remainingCrossDim = containerCrossAxis - (child.layout.measuredDimensions[dim[crossAxis]] + child.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + child.style.margin.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis])); - - if (alignItem == CSSAlign.CENTER) { - leadingCrossDim += remainingCrossDim / 2; - } else { // CSSAlign.FLEX_END - leadingCrossDim += remainingCrossDim; - } - } - - // And we apply the position - child.layout.position[pos[crossAxis]] += totalLineCrossDim + leadingCrossDim; - } - } - } - - totalLineCrossDim += crossDim; - maxLineMainDim = Math.max(maxLineMainDim, mainDim); - - // Reset variables for new line. - lineCount++; - startOfLineIndex = endOfLineIndex; - endOfLineIndex = startOfLineIndex; - } - - // STEP 8: MULTI-LINE CONTENT ALIGNMENT - if (lineCount > 1 && performLayout && !Float.isNaN(availableInnerCrossDim)) { - float remainingAlignContentDim = availableInnerCrossDim - totalLineCrossDim; - - float crossDimLead = 0; - float currentLead = leadingPaddingAndBorderCross; - - CSSAlign alignContent = node.style.alignContent; - if (alignContent == CSSAlign.FLEX_END) { - currentLead += remainingAlignContentDim; - } else if (alignContent == CSSAlign.CENTER) { - currentLead += remainingAlignContentDim / 2; - } else if (alignContent == CSSAlign.STRETCH) { - if (availableInnerCrossDim > totalLineCrossDim) { - crossDimLead = (remainingAlignContentDim / lineCount); - } - } - - int endIndex = 0; - for (i = 0; i < lineCount; ++i) { - int startIndex = endIndex; - int j; - - // compute the line's height and find the endIndex - float lineHeight = 0; - for (j = startIndex; j < childCount; ++j) { - child = node.getChildAt(j); - if (child.style.positionType != CSSPositionType.RELATIVE) { - continue; - } - if (child.lineIndex != i) { - break; - } - if ((child.layout.measuredDimensions[dim[crossAxis]] >= 0.0)) { - lineHeight = Math.max(lineHeight, - child.layout.measuredDimensions[dim[crossAxis]] + (child.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]) + child.style.margin.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]))); - } - } - endIndex = j; - lineHeight += crossDimLead; - - if (performLayout) { - for (j = startIndex; j < endIndex; ++j) { - child = node.getChildAt(j); - if (child.style.positionType != CSSPositionType.RELATIVE) { - continue; - } - - CSSAlign alignContentAlignItem = getAlignItem(node, child); - if (alignContentAlignItem == CSSAlign.FLEX_START) { - child.layout.position[pos[crossAxis]] = currentLead + child.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]); - } else if (alignContentAlignItem == CSSAlign.FLEX_END) { - child.layout.position[pos[crossAxis]] = currentLead + lineHeight - child.style.margin.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis]) - child.layout.measuredDimensions[dim[crossAxis]]; - } else if (alignContentAlignItem == CSSAlign.CENTER) { - childHeight = child.layout.measuredDimensions[dim[crossAxis]]; - child.layout.position[pos[crossAxis]] = currentLead + (lineHeight - childHeight) / 2; - } else if (alignContentAlignItem == CSSAlign.STRETCH) { - child.layout.position[pos[crossAxis]] = currentLead + child.style.margin.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]); - // TODO(prenaux): Correctly set the height of items with indefinite - // (auto) crossAxis dimension. - } - } - } - - currentLead += lineHeight; - } - } - - // STEP 9: COMPUTING FINAL DIMENSIONS - node.layout.measuredDimensions[DIMENSION_WIDTH] = boundAxis(node, CSS_FLEX_DIRECTION_ROW, availableWidth - marginAxisRow); - node.layout.measuredDimensions[DIMENSION_HEIGHT] = boundAxis(node, CSS_FLEX_DIRECTION_COLUMN, availableHeight - marginAxisColumn); - - // If the user didn't specify a width or height for the node, set the - // dimensions based on the children. - if (measureModeMainDim == CSSMeasureMode.UNDEFINED) { - // Clamp the size to the min/max size, if specified, and make sure it - // doesn't go below the padding and border amount. - node.layout.measuredDimensions[dim[mainAxis]] = boundAxis(node, mainAxis, maxLineMainDim); - } else if (measureModeMainDim == CSSMeasureMode.AT_MOST) { - node.layout.measuredDimensions[dim[mainAxis]] = Math.max( - Math.min(availableInnerMainDim + paddingAndBorderAxisMain, - boundAxisWithinMinAndMax(node, mainAxis, maxLineMainDim)), - paddingAndBorderAxisMain); - } - - if (measureModeCrossDim == CSSMeasureMode.UNDEFINED) { - // Clamp the size to the min/max size, if specified, and make sure it - // doesn't go below the padding and border amount. - node.layout.measuredDimensions[dim[crossAxis]] = boundAxis(node, crossAxis, totalLineCrossDim + paddingAndBorderAxisCross); - } else if (measureModeCrossDim == CSSMeasureMode.AT_MOST) { - node.layout.measuredDimensions[dim[crossAxis]] = Math.max( - Math.min(availableInnerCrossDim + paddingAndBorderAxisCross, - boundAxisWithinMinAndMax(node, crossAxis, totalLineCrossDim + paddingAndBorderAxisCross)), - paddingAndBorderAxisCross); - } - - // STEP 10: SIZING AND POSITIONING ABSOLUTE CHILDREN - currentAbsoluteChild = firstAbsoluteChild; - while (currentAbsoluteChild != null) { - // Now that we know the bounds of the container, perform layout again on the - // absolutely-positioned children. - if (performLayout) { - - childWidth = CSSConstants.UNDEFINED; - childHeight = CSSConstants.UNDEFINED; - - if ((currentAbsoluteChild.style.dimensions[dim[CSS_FLEX_DIRECTION_ROW]] >= 0.0)) { - childWidth = currentAbsoluteChild.style.dimensions[DIMENSION_WIDTH] + (currentAbsoluteChild.style.margin.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_ROW], leading[CSS_FLEX_DIRECTION_ROW]) + currentAbsoluteChild.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_ROW], trailing[CSS_FLEX_DIRECTION_ROW])); - } else { - // If the child doesn't have a specified width, compute the width based on the left/right offsets if they're defined. - if (!Float.isNaN(currentAbsoluteChild.style.position.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_ROW], leading[CSS_FLEX_DIRECTION_ROW])) && - !Float.isNaN(currentAbsoluteChild.style.position.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_ROW], trailing[CSS_FLEX_DIRECTION_ROW]))) { - childWidth = node.layout.measuredDimensions[DIMENSION_WIDTH] - - (node.style.border.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_ROW], leading[CSS_FLEX_DIRECTION_ROW]) + node.style.border.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_ROW], trailing[CSS_FLEX_DIRECTION_ROW])) - - ((Float.isNaN(currentAbsoluteChild.style.position.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_ROW], leading[CSS_FLEX_DIRECTION_ROW])) ? - 0 : - currentAbsoluteChild.style.position.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_ROW], leading[CSS_FLEX_DIRECTION_ROW])) + - (Float.isNaN(currentAbsoluteChild.style.position.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_ROW], trailing[CSS_FLEX_DIRECTION_ROW])) ? - 0 : - currentAbsoluteChild.style.position.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_ROW], trailing[CSS_FLEX_DIRECTION_ROW]))); - childWidth = boundAxis(currentAbsoluteChild, CSS_FLEX_DIRECTION_ROW, childWidth); - } - } - - if ((currentAbsoluteChild.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] >= 0.0)) { - childHeight = currentAbsoluteChild.style.dimensions[DIMENSION_HEIGHT] + (currentAbsoluteChild.style.margin.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + currentAbsoluteChild.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN])); - } else { - // If the child doesn't have a specified height, compute the height based on the top/bottom offsets if they're defined. - if (!Float.isNaN(currentAbsoluteChild.style.position.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN])) && - !Float.isNaN(currentAbsoluteChild.style.position.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]))) { - childHeight = node.layout.measuredDimensions[DIMENSION_HEIGHT] - - (node.style.border.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN])) - - ((Float.isNaN(currentAbsoluteChild.style.position.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN])) ? - 0 : - currentAbsoluteChild.style.position.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN])) + - (Float.isNaN(currentAbsoluteChild.style.position.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN])) ? - 0 : - currentAbsoluteChild.style.position.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]))); - childHeight = boundAxis(currentAbsoluteChild, CSS_FLEX_DIRECTION_COLUMN, childHeight); - } - } - - // If we're still missing one or the other dimension, measure the content. - if (Float.isNaN(childWidth) || Float.isNaN(childHeight)) { - childWidthMeasureMode = Float.isNaN(childWidth) ? CSSMeasureMode.UNDEFINED : CSSMeasureMode.EXACTLY; - childHeightMeasureMode = Float.isNaN(childHeight) ? CSSMeasureMode.UNDEFINED : CSSMeasureMode.EXACTLY; - - // According to the spec, if the main size is not definite and the - // child's inline axis is parallel to the main axis (i.e. it's - // horizontal), the child should be sized using "UNDEFINED" in - // the main size. Otherwise use "AT_MOST" in the cross axis. - if (!isMainAxisRow && Float.isNaN(childWidth) && !Float.isNaN(availableInnerWidth)) { - childWidth = availableInnerWidth; - childWidthMeasureMode = CSSMeasureMode.AT_MOST; - } - - layoutNodeInternal(layoutContext, currentAbsoluteChild, childWidth, childHeight, direction, childWidthMeasureMode, childHeightMeasureMode, false, "abs-measure"); - childWidth = currentAbsoluteChild.layout.measuredDimensions[DIMENSION_WIDTH] + (currentAbsoluteChild.style.margin.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_ROW], leading[CSS_FLEX_DIRECTION_ROW]) + currentAbsoluteChild.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_ROW], trailing[CSS_FLEX_DIRECTION_ROW])); - childHeight = currentAbsoluteChild.layout.measuredDimensions[DIMENSION_HEIGHT] + (currentAbsoluteChild.style.margin.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + currentAbsoluteChild.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN])); - } - - layoutNodeInternal(layoutContext, currentAbsoluteChild, childWidth, childHeight, direction, CSSMeasureMode.EXACTLY, CSSMeasureMode.EXACTLY, true, "abs-layout"); - - if (!Float.isNaN(currentAbsoluteChild.style.position.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis])) && - Float.isNaN(currentAbsoluteChild.style.position.getWithFallback(leadingSpacing[mainAxis], leading[mainAxis]))) { - currentAbsoluteChild.layout.position[leading[mainAxis]] = - node.layout.measuredDimensions[dim[mainAxis]] - - currentAbsoluteChild.layout.measuredDimensions[dim[mainAxis]] - - (Float.isNaN(currentAbsoluteChild.style.position.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis])) ? 0 : currentAbsoluteChild.style.position.getWithFallback(trailingSpacing[mainAxis], trailing[mainAxis])); - } - - if (!Float.isNaN(currentAbsoluteChild.style.position.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis])) && - Float.isNaN(currentAbsoluteChild.style.position.getWithFallback(leadingSpacing[crossAxis], leading[crossAxis]))) { - currentAbsoluteChild.layout.position[leading[crossAxis]] = - node.layout.measuredDimensions[dim[crossAxis]] - - currentAbsoluteChild.layout.measuredDimensions[dim[crossAxis]] - - (Float.isNaN(currentAbsoluteChild.style.position.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis])) ? 0 : currentAbsoluteChild.style.position.getWithFallback(trailingSpacing[crossAxis], trailing[crossAxis])); - } - } - - currentAbsoluteChild = currentAbsoluteChild.nextChild; - } - - // STEP 11: SETTING TRAILING POSITIONS FOR CHILDREN - if (performLayout) { - boolean needsMainTrailingPos = false; - boolean needsCrossTrailingPos = false; - - if (mainAxis == CSS_FLEX_DIRECTION_ROW_REVERSE || - mainAxis == CSS_FLEX_DIRECTION_COLUMN_REVERSE) { - needsMainTrailingPos = true; - } - - if (crossAxis == CSS_FLEX_DIRECTION_ROW_REVERSE || - crossAxis == CSS_FLEX_DIRECTION_COLUMN_REVERSE) { - needsCrossTrailingPos = true; - } - - // Set trailing position if necessary. - if (needsMainTrailingPos || needsCrossTrailingPos) { - for (i = 0; i < childCount; ++i) { - child = node.getChildAt(i); - - if (needsMainTrailingPos) { - child.layout.position[trailing[mainAxis]] = - node.layout.measuredDimensions[dim[mainAxis]] - - child.layout.measuredDimensions[dim[mainAxis]] - - child.layout.position[pos[mainAxis]]; - } - - if (needsCrossTrailingPos) { - child.layout.position[trailing[crossAxis]] = - node.layout.measuredDimensions[dim[crossAxis]] - - child.layout.measuredDimensions[dim[crossAxis]] - - child.layout.position[pos[crossAxis]]; - } - } - } - } - } -} diff --git a/java/com/facebook/csslayout/Spacing.java b/java/com/facebook/csslayout/Spacing.java deleted file mode 100644 index 017f9f07..00000000 --- a/java/com/facebook/csslayout/Spacing.java +++ /dev/null @@ -1,190 +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. - */ - -package com.facebook.csslayout; - -import java.util.Arrays; - -/** - * Class representing CSS spacing (padding, margin, and borders). This is mostly necessary to - * properly implement interactions and updates for properties like margin, marginLeft, and - * marginHorizontal. - */ -public class Spacing { - - /** - * Spacing type that represents the left direction. E.g. {@code marginLeft}. - */ - public static final int LEFT = 0; - /** - * Spacing type that represents the top direction. E.g. {@code marginTop}. - */ - public static final int TOP = 1; - /** - * Spacing type that represents the right direction. E.g. {@code marginRight}. - */ - public static final int RIGHT = 2; - /** - * Spacing type that represents the bottom direction. E.g. {@code marginBottom}. - */ - public static final int BOTTOM = 3; - /** - * Spacing type that represents start direction e.g. left in left-to-right, right in right-to-left. - */ - public static final int START = 4; - /** - * Spacing type that represents end direction e.g. right in left-to-right, left in right-to-left. - */ - public static final int END = 5; - /** - * Spacing type that represents horizontal direction (left and right). E.g. - * {@code marginHorizontal}. - */ - public static final int HORIZONTAL = 6; - /** - * Spacing type that represents vertical direction (top and bottom). E.g. {@code marginVertical}. - */ - public static final int VERTICAL = 7; - /** - * Spacing type that represents all directions (left, top, right, bottom). E.g. {@code margin}. - */ - public static final int ALL = 8; - - private static final int[] sFlagsMap = { - 1, /*LEFT*/ - 2, /*TOP*/ - 4, /*RIGHT*/ - 8, /*BOTTOM*/ - 16, /*START*/ - 32, /*END*/ - 64, /*HORIZONTAL*/ - 128, /*VERTICAL*/ - 256, /*ALL*/ - }; - - private final float[] mSpacing = newFullSpacingArray(); - private int mValueFlags = 0; - private float mDefaultValue; - private boolean mHasAliasesSet; - - public Spacing() { - this(0); - } - - public Spacing(float defaultValue) { - mDefaultValue = defaultValue; - } - - /** - * Set a spacing value. - * - * @param spacingType one of {@link #LEFT}, {@link #TOP}, {@link #RIGHT}, {@link #BOTTOM}, - * {@link #VERTICAL}, {@link #HORIZONTAL}, {@link #ALL} - * @param value the value for this direction - * @return {@code true} if the spacing has changed, or {@code false} if the same value was already - * set - */ - public boolean set(int spacingType, float value) { - if (!FloatUtil.floatsEqual(mSpacing[spacingType], value)) { - mSpacing[spacingType] = value; - - if (CSSConstants.isUndefined(value)) { - mValueFlags &= ~sFlagsMap[spacingType]; - } else { - mValueFlags |= sFlagsMap[spacingType]; - } - - mHasAliasesSet = - (mValueFlags & sFlagsMap[ALL]) != 0 || - (mValueFlags & sFlagsMap[VERTICAL]) != 0 || - (mValueFlags & sFlagsMap[HORIZONTAL]) != 0; - - return true; - } - - return false; - } - - /** - * Get the spacing for a direction. This takes into account any default values that have been set. - * - * @param spacingType one of {@link #LEFT}, {@link #TOP}, {@link #RIGHT}, {@link #BOTTOM} - */ - public float get(int spacingType) { - float defaultValue = (spacingType == START || spacingType == END - ? CSSConstants.UNDEFINED - : mDefaultValue); - - if (mValueFlags == 0) { - return defaultValue; - } - - if ((mValueFlags & sFlagsMap[spacingType]) != 0) { - return mSpacing[spacingType]; - } - - if (mHasAliasesSet) { - int secondType = spacingType == TOP || spacingType == BOTTOM ? VERTICAL : HORIZONTAL; - if ((mValueFlags & sFlagsMap[secondType]) != 0) { - return mSpacing[secondType]; - } else if ((mValueFlags & sFlagsMap[ALL]) != 0) { - return mSpacing[ALL]; - } - } - - return defaultValue; - } - - /** - * Get the raw value (that was set using {@link #set(int, float)}), without taking into account - * any default values. - * - * @param spacingType one of {@link #LEFT}, {@link #TOP}, {@link #RIGHT}, {@link #BOTTOM}, - * {@link #VERTICAL}, {@link #HORIZONTAL}, {@link #ALL} - */ - public float getRaw(int spacingType) { - return mSpacing[spacingType]; - } - - /** - * Resets the spacing instance to its default state. This method is meant to be used when - * recycling {@link Spacing} instances. - */ - public void reset() { - Arrays.fill(mSpacing, CSSConstants.UNDEFINED); - mHasAliasesSet = false; - mValueFlags = 0; - } - - /** - * Try to get start value and fallback to given type if not defined. This is used privately - * by the layout engine as a more efficient way to fetch direction-aware values by - * avoid extra method invocations. - */ - float getWithFallback(int spacingType, int fallbackType) { - return - (mValueFlags & sFlagsMap[spacingType]) != 0 - ? mSpacing[spacingType] - : get(fallbackType); - } - - private static float[] newFullSpacingArray() { - return new float[] { - CSSConstants.UNDEFINED, - CSSConstants.UNDEFINED, - CSSConstants.UNDEFINED, - CSSConstants.UNDEFINED, - CSSConstants.UNDEFINED, - CSSConstants.UNDEFINED, - CSSConstants.UNDEFINED, - CSSConstants.UNDEFINED, - CSSConstants.UNDEFINED, - }; - } -} diff --git a/java/com/facebook/proguard/annotations/BUCK b/java/com/facebook/proguard/annotations/BUCK index f9bfb1a5..2af11a81 100644 --- a/java/com/facebook/proguard/annotations/BUCK +++ b/java/com/facebook/proguard/annotations/BUCK @@ -5,7 +5,7 @@ # 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_defs('//CSSLAYOUT_DEFS') +include_defs('//YOGA_DEFS') java_library( name = 'annotations', @@ -13,5 +13,5 @@ java_library( source = '1.7', target = '1.7', deps = [], - visibility = [CSSLAYOUT_ROOT], + visibility = [YOGA_ROOT], ) diff --git a/java/com/facebook/yoga/YogaAlign.java b/java/com/facebook/yoga/YogaAlign.java new file mode 100644 index 00000000..74bcde73 --- /dev/null +++ b/java/com/facebook/yoga/YogaAlign.java @@ -0,0 +1,42 @@ +/** + * 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. + */ + +package com.facebook.yoga; + +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public enum YogaAlign { + AUTO(0), + FLEX_START(1), + CENTER(2), + FLEX_END(3), + STRETCH(4); + + private int mIntValue; + + YogaAlign(int intValue) { + mIntValue = intValue; + } + + public int intValue() { + return mIntValue; + } + + public static YogaAlign fromInt(int value) { + switch (value) { + case 0: return AUTO; + case 1: return FLEX_START; + case 2: return CENTER; + case 3: return FLEX_END; + case 4: return STRETCH; + default: throw new IllegalArgumentException("Unkown enum value: " + value); + } + } +} diff --git a/java/com/facebook/csslayout/CSSConstants.java b/java/com/facebook/yoga/YogaConstants.java similarity index 88% rename from java/com/facebook/csslayout/CSSConstants.java rename to java/com/facebook/yoga/YogaConstants.java index 01a0d597..93dc9f81 100644 --- a/java/com/facebook/csslayout/CSSConstants.java +++ b/java/com/facebook/yoga/YogaConstants.java @@ -7,9 +7,9 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -package com.facebook.csslayout; +package com.facebook.yoga; -public class CSSConstants { +public class YogaConstants { public static final float UNDEFINED = Float.NaN; diff --git a/java/com/facebook/yoga/YogaDimension.java b/java/com/facebook/yoga/YogaDimension.java new file mode 100644 index 00000000..dfa3c093 --- /dev/null +++ b/java/com/facebook/yoga/YogaDimension.java @@ -0,0 +1,36 @@ +/** + * 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. + */ + +package com.facebook.yoga; + +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public enum YogaDimension { + WIDTH(0), + HEIGHT(1); + + private int mIntValue; + + YogaDimension(int intValue) { + mIntValue = intValue; + } + + public int intValue() { + return mIntValue; + } + + public static YogaDimension fromInt(int value) { + switch (value) { + case 0: return WIDTH; + case 1: return HEIGHT; + default: throw new IllegalArgumentException("Unkown enum value: " + value); + } + } +} diff --git a/java/com/facebook/yoga/YogaDirection.java b/java/com/facebook/yoga/YogaDirection.java new file mode 100644 index 00000000..f0955bd7 --- /dev/null +++ b/java/com/facebook/yoga/YogaDirection.java @@ -0,0 +1,38 @@ +/** + * 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. + */ + +package com.facebook.yoga; + +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public enum YogaDirection { + INHERIT(0), + LTR(1), + RTL(2); + + private int mIntValue; + + YogaDirection(int intValue) { + mIntValue = intValue; + } + + public int intValue() { + return mIntValue; + } + + public static YogaDirection fromInt(int value) { + switch (value) { + case 0: return INHERIT; + case 1: return LTR; + case 2: return RTL; + default: throw new IllegalArgumentException("Unkown enum value: " + value); + } + } +} diff --git a/java/com/facebook/yoga/YogaEdge.java b/java/com/facebook/yoga/YogaEdge.java new file mode 100644 index 00000000..8c6c7a74 --- /dev/null +++ b/java/com/facebook/yoga/YogaEdge.java @@ -0,0 +1,50 @@ +/** + * 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. + */ + +package com.facebook.yoga; + +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public enum YogaEdge { + LEFT(0), + TOP(1), + RIGHT(2), + BOTTOM(3), + START(4), + END(5), + HORIZONTAL(6), + VERTICAL(7), + ALL(8); + + private int mIntValue; + + YogaEdge(int intValue) { + mIntValue = intValue; + } + + public int intValue() { + return mIntValue; + } + + public static YogaEdge fromInt(int value) { + switch (value) { + case 0: return LEFT; + case 1: return TOP; + case 2: return RIGHT; + case 3: return BOTTOM; + case 4: return START; + case 5: return END; + case 6: return HORIZONTAL; + case 7: return VERTICAL; + case 8: return ALL; + default: throw new IllegalArgumentException("Unkown enum value: " + value); + } + } +} diff --git a/java/com/facebook/yoga/YogaExperimentalFeature.java b/java/com/facebook/yoga/YogaExperimentalFeature.java new file mode 100644 index 00000000..19c540ca --- /dev/null +++ b/java/com/facebook/yoga/YogaExperimentalFeature.java @@ -0,0 +1,36 @@ +/** + * 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. + */ + +package com.facebook.yoga; + +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public enum YogaExperimentalFeature { + ROUNDING(0), + WEB_FLEX_BASIS(1); + + private int mIntValue; + + YogaExperimentalFeature(int intValue) { + mIntValue = intValue; + } + + public int intValue() { + return mIntValue; + } + + public static YogaExperimentalFeature fromInt(int value) { + switch (value) { + case 0: return ROUNDING; + case 1: return WEB_FLEX_BASIS; + default: throw new IllegalArgumentException("Unkown enum value: " + value); + } + } +} diff --git a/java/com/facebook/yoga/YogaFlexDirection.java b/java/com/facebook/yoga/YogaFlexDirection.java new file mode 100644 index 00000000..d01cc96a --- /dev/null +++ b/java/com/facebook/yoga/YogaFlexDirection.java @@ -0,0 +1,40 @@ +/** + * 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. + */ + +package com.facebook.yoga; + +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public enum YogaFlexDirection { + COLUMN(0), + COLUMN_REVERSE(1), + ROW(2), + ROW_REVERSE(3); + + private int mIntValue; + + YogaFlexDirection(int intValue) { + mIntValue = intValue; + } + + public int intValue() { + return mIntValue; + } + + public static YogaFlexDirection fromInt(int value) { + switch (value) { + case 0: return COLUMN; + case 1: return COLUMN_REVERSE; + case 2: return ROW; + case 3: return ROW_REVERSE; + default: throw new IllegalArgumentException("Unkown enum value: " + value); + } + } +} diff --git a/java/com/facebook/yoga/YogaJustify.java b/java/com/facebook/yoga/YogaJustify.java new file mode 100644 index 00000000..be481bf3 --- /dev/null +++ b/java/com/facebook/yoga/YogaJustify.java @@ -0,0 +1,42 @@ +/** + * 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. + */ + +package com.facebook.yoga; + +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public enum YogaJustify { + FLEX_START(0), + CENTER(1), + FLEX_END(2), + SPACE_BETWEEN(3), + SPACE_AROUND(4); + + private int mIntValue; + + YogaJustify(int intValue) { + mIntValue = intValue; + } + + public int intValue() { + return mIntValue; + } + + public static YogaJustify fromInt(int value) { + switch (value) { + case 0: return FLEX_START; + case 1: return CENTER; + case 2: return FLEX_END; + case 3: return SPACE_BETWEEN; + case 4: return SPACE_AROUND; + default: throw new IllegalArgumentException("Unkown enum value: " + value); + } + } +} diff --git a/java/com/facebook/yoga/YogaLogLevel.java b/java/com/facebook/yoga/YogaLogLevel.java new file mode 100644 index 00000000..b6b33caa --- /dev/null +++ b/java/com/facebook/yoga/YogaLogLevel.java @@ -0,0 +1,42 @@ +/** + * 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. + */ + +package com.facebook.yoga; + +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public enum YogaLogLevel { + ERROR(0), + WARN(1), + INFO(2), + DEBUG(3), + VERBOSE(4); + + private int mIntValue; + + YogaLogLevel(int intValue) { + mIntValue = intValue; + } + + public int intValue() { + return mIntValue; + } + + public static YogaLogLevel fromInt(int value) { + switch (value) { + case 0: return ERROR; + case 1: return WARN; + case 2: return INFO; + case 3: return DEBUG; + case 4: return VERBOSE; + default: throw new IllegalArgumentException("Unkown enum value: " + value); + } + } +} diff --git a/java/com/facebook/yoga/YogaLogger.java b/java/com/facebook/yoga/YogaLogger.java new file mode 100644 index 00000000..a856b7be --- /dev/null +++ b/java/com/facebook/yoga/YogaLogger.java @@ -0,0 +1,22 @@ +/** + * 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. + */ + +package com.facebook.yoga; + +import com.facebook.proguard.annotations.DoNotStrip; + +/** + * Inteface for recieving logs from native layer. Use by setting YogaNode.setLogger(myLogger); + * See YogaLogLevel for the different log levels. + */ +@DoNotStrip +public interface YogaLogger { + @DoNotStrip + void log(YogaLogLevel level, String message); +} diff --git a/java/com/facebook/yoga/YogaMeasureFunction.java b/java/com/facebook/yoga/YogaMeasureFunction.java new file mode 100644 index 00000000..6570e5b5 --- /dev/null +++ b/java/com/facebook/yoga/YogaMeasureFunction.java @@ -0,0 +1,26 @@ +/** + * 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. + */ + +package com.facebook.yoga; + +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public interface YogaMeasureFunction { + /** + * Return a value created by YogaMeasureOutput.make(width, height); + */ + @DoNotStrip + long measure( + YogaNodeAPI node, + float width, + YogaMeasureMode widthMode, + float height, + YogaMeasureMode heightMode); +} diff --git a/java/com/facebook/yoga/YogaMeasureMode.java b/java/com/facebook/yoga/YogaMeasureMode.java new file mode 100644 index 00000000..68fb6c5d --- /dev/null +++ b/java/com/facebook/yoga/YogaMeasureMode.java @@ -0,0 +1,38 @@ +/** + * 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. + */ + +package com.facebook.yoga; + +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public enum YogaMeasureMode { + UNDEFINED(0), + EXACTLY(1), + AT_MOST(2); + + private int mIntValue; + + YogaMeasureMode(int intValue) { + mIntValue = intValue; + } + + public int intValue() { + return mIntValue; + } + + public static YogaMeasureMode fromInt(int value) { + switch (value) { + case 0: return UNDEFINED; + case 1: return EXACTLY; + case 2: return AT_MOST; + default: throw new IllegalArgumentException("Unkown enum value: " + value); + } + } +} diff --git a/java/com/facebook/csslayout/MeasureOutput.java b/java/com/facebook/yoga/YogaMeasureOutput.java similarity index 92% rename from java/com/facebook/csslayout/MeasureOutput.java rename to java/com/facebook/yoga/YogaMeasureOutput.java index 5ec9fe35..7bb845a0 100644 --- a/java/com/facebook/csslayout/MeasureOutput.java +++ b/java/com/facebook/yoga/YogaMeasureOutput.java @@ -7,12 +7,12 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -package com.facebook.csslayout; +package com.facebook.yoga; /** * Helpers for building measure output value. */ -public class MeasureOutput { +public class YogaMeasureOutput { public static long make(float width, float height) { return make((int) width, (int) height); diff --git a/java/com/facebook/yoga/YogaNode.java b/java/com/facebook/yoga/YogaNode.java new file mode 100644 index 00000000..2aa11faa --- /dev/null +++ b/java/com/facebook/yoga/YogaNode.java @@ -0,0 +1,549 @@ +/** + * 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. + */ + +package com.facebook.yoga; + +import javax.annotation.Nullable; + +import java.util.List; +import java.util.ArrayList; + +import com.facebook.proguard.annotations.DoNotStrip; +import com.facebook.soloader.SoLoader; + +@DoNotStrip +public class YogaNode implements YogaNodeAPI { + + static { + SoLoader.loadLibrary("yoga"); + } + + /** + * Get native instance count. Useful for testing only. + */ + static native int jni_YGNodeGetInstanceCount(); + static native void jni_YGLog(int level, String message); + + private static native void jni_YGSetLogger(Object logger); + public static void setLogger(YogaLogger logger) { + jni_YGSetLogger(logger); + } + + private static native void jni_YGSetExperimentalFeatureEnabled( + int feature, + boolean enabled); + public static void setExperimentalFeatureEnabled( + YogaExperimentalFeature feature, + boolean enabled) { + jni_YGSetExperimentalFeatureEnabled(feature.intValue(), enabled); + } + + private static native boolean jni_YGIsExperimentalFeatureEnabled(int feature); + public static boolean isExperimentalFeatureEnabled(YogaExperimentalFeature feature) { + return jni_YGIsExperimentalFeatureEnabled(feature.intValue()); + } + + private YogaNode mParent; + private List mChildren; + private YogaMeasureFunction mMeasureFunction; + private long mNativePointer; + private Object mData; + + private boolean mHasSetPadding = false; + private boolean mHasSetMargin = false; + private boolean mHasSetBorder = false; + private boolean mHasSetPosition = false; + + @DoNotStrip + private float mWidth = YogaConstants.UNDEFINED; + @DoNotStrip + private float mHeight = YogaConstants.UNDEFINED; + @DoNotStrip + private float mTop = YogaConstants.UNDEFINED; + @DoNotStrip + private float mLeft = YogaConstants.UNDEFINED; + @DoNotStrip + private int mLayoutDirection = 0; + + private native long jni_YGNodeNew(); + public YogaNode() { + mNativePointer = jni_YGNodeNew(); + if (mNativePointer == 0) { + throw new IllegalStateException("Failed to allocate native memory"); + } + } + + private native void jni_YGNodeFree(long nativePointer); + @Override + protected void finalize() throws Throwable { + try { + jni_YGNodeFree(mNativePointer); + } finally { + super.finalize(); + } + } + + private native void jni_YGNodeReset(long nativePointer); + @Override + public void reset() { + mHasSetPadding = false; + mHasSetMargin = false; + mHasSetBorder = false; + mHasSetPosition = false; + + mWidth = YogaConstants.UNDEFINED; + mHeight = YogaConstants.UNDEFINED; + mTop = YogaConstants.UNDEFINED; + mLeft = YogaConstants.UNDEFINED; + mLayoutDirection = 0; + + mMeasureFunction = null; + mData = null; + + jni_YGNodeReset(mNativePointer); + } + + @Override + public int getChildCount() { + return mChildren == null ? 0 : mChildren.size(); + } + + @Override + public YogaNode getChildAt(int i) { + return mChildren.get(i); + } + + private native void jni_YGNodeInsertChild(long nativePointer, long childPointer, int index); + @Override + public void addChildAt(YogaNode child, int i) { + if (child.mParent != null) { + throw new IllegalStateException("Child already has a parent, it must be removed first."); + } + + if (mChildren == null) { + mChildren = new ArrayList<>(4); + } + mChildren.add(i, child); + child.mParent = this; + jni_YGNodeInsertChild(mNativePointer, child.mNativePointer, i); + } + + private native void jni_YGNodeRemoveChild(long nativePointer, long childPointer); + @Override + public YogaNode removeChildAt(int i) { + + final YogaNode child = mChildren.remove(i); + child.mParent = null; + jni_YGNodeRemoveChild(mNativePointer, child.mNativePointer); + return child; + } + + @Override + public @Nullable + YogaNode getParent() { + return mParent; + } + + @Override + public int indexOf(YogaNode child) { + return mChildren == null ? -1 : mChildren.indexOf(child); + } + + private native void jni_YGNodeCalculateLayout(long nativePointer); + @Override + public void calculateLayout() { + jni_YGNodeCalculateLayout(mNativePointer); + } + + private native boolean jni_YGNodeHasNewLayout(long nativePointer); + @Override + public boolean hasNewLayout() { + return jni_YGNodeHasNewLayout(mNativePointer); + } + + private native void jni_YGNodeMarkDirty(long nativePointer); + @Override + public void dirty() { + jni_YGNodeMarkDirty(mNativePointer); + } + + private native boolean jni_YGNodeIsDirty(long nativePointer); + @Override + public boolean isDirty() { + return jni_YGNodeIsDirty(mNativePointer); + } + + private native void jni_YGNodeMarkLayoutSeen(long nativePointer); + @Override + public void markLayoutSeen() { + jni_YGNodeMarkLayoutSeen(mNativePointer); + } + + private native void jni_YGNodeCopyStyle(long dstNativePointer, long srcNativePointer); + @Override + public void copyStyle(YogaNode srcNode) { + jni_YGNodeCopyStyle(mNativePointer, srcNode.mNativePointer); + } + + private native int jni_YGNodeStyleGetDirection(long nativePointer); + @Override + public YogaDirection getStyleDirection() { + return YogaDirection.values()[jni_YGNodeStyleGetDirection(mNativePointer)]; + } + + private native void jni_YGNodeStyleSetDirection(long nativePointer, int direction); + @Override + public void setDirection(YogaDirection direction) { + jni_YGNodeStyleSetDirection(mNativePointer, direction.intValue()); + } + + private native int jni_YGNodeStyleGetFlexDirection(long nativePointer); + @Override + public YogaFlexDirection getFlexDirection() { + return YogaFlexDirection.values()[jni_YGNodeStyleGetFlexDirection(mNativePointer)]; + } + + private native void jni_YGNodeStyleSetFlexDirection(long nativePointer, int flexDirection); + @Override + public void setFlexDirection(YogaFlexDirection flexDirection) { + jni_YGNodeStyleSetFlexDirection(mNativePointer, flexDirection.intValue()); + } + + private native int jni_YGNodeStyleGetJustifyContent(long nativePointer); + @Override + public YogaJustify getJustifyContent() { + return YogaJustify.values()[jni_YGNodeStyleGetJustifyContent(mNativePointer)]; + } + + private native void jni_YGNodeStyleSetJustifyContent(long nativePointer, int justifyContent); + @Override + public void setJustifyContent(YogaJustify justifyContent) { + jni_YGNodeStyleSetJustifyContent(mNativePointer, justifyContent.intValue()); + } + + private native int jni_YGNodeStyleGetAlignItems(long nativePointer); + @Override + public YogaAlign getAlignItems() { + return YogaAlign.values()[jni_YGNodeStyleGetAlignItems(mNativePointer)]; + } + + private native void jni_YGNodeStyleSetAlignItems(long nativePointer, int alignItems); + @Override + public void setAlignItems(YogaAlign alignItems) { + jni_YGNodeStyleSetAlignItems(mNativePointer, alignItems.intValue()); + } + + private native int jni_YGNodeStyleGetAlignSelf(long nativePointer); + @Override + public YogaAlign getAlignSelf() { + return YogaAlign.values()[jni_YGNodeStyleGetAlignSelf(mNativePointer)]; + } + + private native void jni_YGNodeStyleSetAlignSelf(long nativePointer, int alignSelf); + @Override + public void setAlignSelf(YogaAlign alignSelf) { + jni_YGNodeStyleSetAlignSelf(mNativePointer, alignSelf.intValue()); + } + + private native int jni_YGNodeStyleGetAlignContent(long nativePointer); + @Override + public YogaAlign getAlignContent() { + return YogaAlign.values()[jni_YGNodeStyleGetAlignContent(mNativePointer)]; + } + + private native void jni_YGNodeStyleSetAlignContent(long nativePointer, int alignContent); + @Override + public void setAlignContent(YogaAlign alignContent) { + jni_YGNodeStyleSetAlignContent(mNativePointer, alignContent.intValue()); + } + + private native int jni_YGNodeStyleGetPositionType(long nativePointer); + @Override + public YogaPositionType getPositionType() { + return YogaPositionType.values()[jni_YGNodeStyleGetPositionType(mNativePointer)]; + } + + private native void jni_YGNodeStyleSetPositionType(long nativePointer, int positionType); + @Override + public void setPositionType(YogaPositionType positionType) { + jni_YGNodeStyleSetPositionType(mNativePointer, positionType.intValue()); + } + + private native void jni_YGNodeStyleSetFlexWrap(long nativePointer, int wrapType); + @Override + public void setWrap(YogaWrap flexWrap) { + jni_YGNodeStyleSetFlexWrap(mNativePointer, flexWrap.intValue()); + } + + private native int jni_YGNodeStyleGetOverflow(long nativePointer); + @Override + public YogaOverflow getOverflow() { + return YogaOverflow.values()[jni_YGNodeStyleGetOverflow(mNativePointer)]; + } + + private native void jni_YGNodeStyleSetOverflow(long nativePointer, int overflow); + @Override + public void setOverflow(YogaOverflow overflow) { + jni_YGNodeStyleSetOverflow(mNativePointer, overflow.intValue()); + } + + private native void jni_YGNodeStyleSetFlex(long nativePointer, float flex); + @Override + public void setFlex(float flex) { + jni_YGNodeStyleSetFlex(mNativePointer, flex); + } + + private native float jni_YGNodeStyleGetFlexGrow(long nativePointer); + @Override + public float getFlexGrow() { + return jni_YGNodeStyleGetFlexGrow(mNativePointer); + } + + private native void jni_YGNodeStyleSetFlexGrow(long nativePointer, float flexGrow); + @Override + public void setFlexGrow(float flexGrow) { + jni_YGNodeStyleSetFlexGrow(mNativePointer, flexGrow); + } + + private native float jni_YGNodeStyleGetFlexShrink(long nativePointer); + @Override + public float getFlexShrink() { + return jni_YGNodeStyleGetFlexShrink(mNativePointer); + } + + private native void jni_YGNodeStyleSetFlexShrink(long nativePointer, float flexShrink); + @Override + public void setFlexShrink(float flexShrink) { + jni_YGNodeStyleSetFlexShrink(mNativePointer, flexShrink); + } + + private native float jni_YGNodeStyleGetFlexBasis(long nativePointer); + @Override + public float getFlexBasis() { + return jni_YGNodeStyleGetFlexBasis(mNativePointer); + } + + private native void jni_YGNodeStyleSetFlexBasis(long nativePointer, float flexBasis); + @Override + public void setFlexBasis(float flexBasis) { + jni_YGNodeStyleSetFlexBasis(mNativePointer, flexBasis); + } + + private native float jni_YGNodeStyleGetMargin(long nativePointer, int edge); + @Override + public float getMargin(YogaEdge edge) { + if (!mHasSetMargin) { + return edge.intValue() < YogaEdge.START.intValue() ? 0 : YogaConstants.UNDEFINED; + } + return jni_YGNodeStyleGetMargin(mNativePointer, edge.intValue()); + } + + private native void jni_YGNodeStyleSetMargin(long nativePointer, int edge, float margin); + @Override + public void setMargin(YogaEdge edge, float margin) { + mHasSetMargin = true; + jni_YGNodeStyleSetMargin(mNativePointer, edge.intValue(), margin); + } + + private native float jni_YGNodeStyleGetPadding(long nativePointer, int edge); + @Override + public float getPadding(YogaEdge edge) { + if (!mHasSetPadding) { + return edge.intValue() < YogaEdge.START.intValue() ? 0 : YogaConstants.UNDEFINED; + } + return jni_YGNodeStyleGetPadding(mNativePointer, edge.intValue()); + } + + private native void jni_YGNodeStyleSetPadding(long nativePointer, int edge, float padding); + @Override + public void setPadding(YogaEdge edge, float padding) { + mHasSetPadding = true; + jni_YGNodeStyleSetPadding(mNativePointer, edge.intValue(), padding); + } + + private native float jni_YGNodeStyleGetBorder(long nativePointer, int edge); + @Override + public float getBorder(YogaEdge edge) { + if (!mHasSetBorder) { + return edge.intValue() < YogaEdge.START.intValue() ? 0 : YogaConstants.UNDEFINED; + } + return jni_YGNodeStyleGetBorder(mNativePointer, edge.intValue()); + } + + private native void jni_YGNodeStyleSetBorder(long nativePointer, int edge, float border); + @Override + public void setBorder(YogaEdge edge, float border) { + mHasSetBorder = true; + jni_YGNodeStyleSetBorder(mNativePointer, edge.intValue(), border); + } + + private native float jni_YGNodeStyleGetPosition(long nativePointer, int edge); + @Override + public float getPosition(YogaEdge edge) { + if (!mHasSetPosition) { + return YogaConstants.UNDEFINED; + } + return jni_YGNodeStyleGetPosition(mNativePointer, edge.intValue()); + } + + private native void jni_YGNodeStyleSetPosition(long nativePointer, int edge, float position); + @Override + public void setPosition(YogaEdge edge, float position) { + mHasSetPosition = true; + jni_YGNodeStyleSetPosition(mNativePointer, edge.intValue(), position); + } + + private native float jni_YGNodeStyleGetWidth(long nativePointer); + @Override + public float getWidth() { + return jni_YGNodeStyleGetWidth(mNativePointer); + } + + private native void jni_YGNodeStyleSetWidth(long nativePointer, float width); + @Override + public void setWidth(float width) { + jni_YGNodeStyleSetWidth(mNativePointer, width); + } + + private native float jni_YGNodeStyleGetHeight(long nativePointer); + @Override + public float getHeight() { + return jni_YGNodeStyleGetHeight(mNativePointer); + } + + private native void jni_YGNodeStyleSetHeight(long nativePointer, float height); + @Override + public void setHeight(float height) { + jni_YGNodeStyleSetHeight(mNativePointer, height); + } + + private native float jni_YGNodeStyleGetMinWidth(long nativePointer); + @Override + public float getMinWidth() { + return jni_YGNodeStyleGetMinWidth(mNativePointer); + } + + private native void jni_YGNodeStyleSetMinWidth(long nativePointer, float minWidth); + @Override + public void setMinWidth(float minWidth) { + jni_YGNodeStyleSetMinWidth(mNativePointer, minWidth); + } + + private native float jni_YGNodeStyleGetMinHeight(long nativePointer); + @Override + public float getMinHeight() { + return jni_YGNodeStyleGetMinHeight(mNativePointer); + } + + private native void jni_YGNodeStyleSetMinHeight(long nativePointer, float minHeight); + @Override + public void setMinHeight(float minHeight) { + jni_YGNodeStyleSetMinHeight(mNativePointer, minHeight); + } + + private native float jni_YGNodeStyleGetMaxWidth(long nativePointer); + @Override + public float getMaxWidth() { + return jni_YGNodeStyleGetMaxWidth(mNativePointer); + } + + private native void jni_YGNodeStyleSetMaxWidth(long nativePointer, float maxWidth); + @Override + public void setMaxWidth(float maxWidth) { + jni_YGNodeStyleSetMaxWidth(mNativePointer, maxWidth); + } + + private native float jni_YGNodeStyleGetMaxHeight(long nativePointer); + @Override + public float getMaxHeight() { + return jni_YGNodeStyleGetMaxHeight(mNativePointer); + } + + private native void jni_YGNodeStyleSetMaxHeight(long nativePointer, float maxheight); + @Override + public void setMaxHeight(float maxheight) { + jni_YGNodeStyleSetMaxHeight(mNativePointer, maxheight); + } + + private native float jni_YGNodeStyleGetAspectRatio(long nativePointer); + public float getAspectRatio() { + return jni_YGNodeStyleGetAspectRatio(mNativePointer); + } + + private native void jni_YGNodeStyleSetAspectRatio(long nativePointer, float aspectRatio); + public void setAspectRatio(float aspectRatio) { + jni_YGNodeStyleSetAspectRatio(mNativePointer, aspectRatio); + } + + @Override + public float getLayoutX() { + return mLeft; + } + + @Override + public float getLayoutY() { + return mTop; + } + + @Override + public float getLayoutWidth() { + return mWidth; + } + + @Override + public float getLayoutHeight() { + return mHeight; + } + + @Override + public YogaDirection getLayoutDirection() { + return YogaDirection.values()[mLayoutDirection]; + } + + private native void jni_YGNodeSetHasMeasureFunc(long nativePointer, boolean hasMeasureFunc); + @Override + public void setMeasureFunction(YogaMeasureFunction measureFunction) { + mMeasureFunction = measureFunction; + jni_YGNodeSetHasMeasureFunc(mNativePointer, measureFunction != null); + } + + // Implementation Note: Why this method needs to stay final + // + // We cache the jmethodid for this method in Yoga code. This means that even if a subclass + // were to override measure, we'd still call this implementation from layout code since the + // overriding method will have a different jmethodid. This is final to prevent that mistake. + @DoNotStrip + public final long measure(float width, int widthMode, float height, int heightMode) { + if (!isMeasureDefined()) { + throw new RuntimeException("Measure function isn't defined!"); + } + + return mMeasureFunction.measure( + this, + width, + YogaMeasureMode.values()[widthMode], + height, + YogaMeasureMode.values()[heightMode]); + } + + @Override + public boolean isMeasureDefined() { + return mMeasureFunction != null; + } + + @Override + public void setData(Object data) { + mData = data; + } + + @Override + public Object getData() { + return mData; + } +} diff --git a/java/com/facebook/yoga/YogaNodeAPI.java b/java/com/facebook/yoga/YogaNodeAPI.java new file mode 100644 index 00000000..cb3b5be8 --- /dev/null +++ b/java/com/facebook/yoga/YogaNodeAPI.java @@ -0,0 +1,80 @@ +/** + * 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. + */ + +package com.facebook.yoga; + +// This only exists for legacy reasons. It will be removed sometime in the near future. +public interface YogaNodeAPI { + int getChildCount(); + YogaNodeType getChildAt(int i); + void addChildAt(YogaNodeType child, int i); + YogaNodeType removeChildAt(int i); + YogaNodeType getParent(); + int indexOf(YogaNodeType child); + void setMeasureFunction(YogaMeasureFunction measureFunction); + boolean isMeasureDefined(); + void calculateLayout(); + boolean isDirty(); + boolean hasNewLayout(); + void dirty(); + void markLayoutSeen(); + void copyStyle(YogaNodeType srcNode); + YogaDirection getStyleDirection(); + void setDirection(YogaDirection direction); + YogaFlexDirection getFlexDirection(); + void setFlexDirection(YogaFlexDirection flexDirection); + YogaJustify getJustifyContent(); + void setJustifyContent(YogaJustify justifyContent); + YogaAlign getAlignItems(); + void setAlignItems(YogaAlign alignItems); + YogaAlign getAlignSelf(); + void setAlignSelf(YogaAlign alignSelf); + YogaAlign getAlignContent(); + void setAlignContent(YogaAlign alignContent); + YogaPositionType getPositionType(); + void setPositionType(YogaPositionType positionType); + void setWrap(YogaWrap flexWrap); + void setFlex(float flex); + float getFlexGrow(); + void setFlexGrow(float flexGrow); + float getFlexShrink(); + void setFlexShrink(float flexShrink); + float getFlexBasis(); + void setFlexBasis(float flexBasis); + float getMargin(YogaEdge edge); + void setMargin(YogaEdge edge, float margin); + float getPadding(YogaEdge edge); + void setPadding(YogaEdge edge, float padding); + float getBorder(YogaEdge edge); + void setBorder(YogaEdge edge, float border); + float getPosition(YogaEdge edge); + void setPosition(YogaEdge edge, float position); + float getWidth(); + void setWidth(float width); + float getHeight(); + void setHeight(float height); + float getMaxWidth(); + void setMaxWidth(float maxWidth); + float getMinWidth(); + void setMinWidth(float minWidth); + float getMaxHeight(); + void setMaxHeight(float maxHeight); + float getMinHeight(); + void setMinHeight(float minHeight); + float getLayoutX(); + float getLayoutY(); + float getLayoutWidth(); + float getLayoutHeight(); + YogaDirection getLayoutDirection(); + YogaOverflow getOverflow(); + void setOverflow(YogaOverflow overflow); + void setData(Object data); + Object getData(); + void reset(); +} diff --git a/java/com/facebook/yoga/YogaOverflow.java b/java/com/facebook/yoga/YogaOverflow.java new file mode 100644 index 00000000..d0509e24 --- /dev/null +++ b/java/com/facebook/yoga/YogaOverflow.java @@ -0,0 +1,38 @@ +/** + * 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. + */ + +package com.facebook.yoga; + +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public enum YogaOverflow { + VISIBLE(0), + HIDDEN(1), + SCROLL(2); + + private int mIntValue; + + YogaOverflow(int intValue) { + mIntValue = intValue; + } + + public int intValue() { + return mIntValue; + } + + public static YogaOverflow fromInt(int value) { + switch (value) { + case 0: return VISIBLE; + case 1: return HIDDEN; + case 2: return SCROLL; + default: throw new IllegalArgumentException("Unkown enum value: " + value); + } + } +} diff --git a/java/com/facebook/yoga/YogaPositionType.java b/java/com/facebook/yoga/YogaPositionType.java new file mode 100644 index 00000000..fe2d4fd2 --- /dev/null +++ b/java/com/facebook/yoga/YogaPositionType.java @@ -0,0 +1,36 @@ +/** + * 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. + */ + +package com.facebook.yoga; + +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public enum YogaPositionType { + RELATIVE(0), + ABSOLUTE(1); + + private int mIntValue; + + YogaPositionType(int intValue) { + mIntValue = intValue; + } + + public int intValue() { + return mIntValue; + } + + public static YogaPositionType fromInt(int value) { + switch (value) { + case 0: return RELATIVE; + case 1: return ABSOLUTE; + default: throw new IllegalArgumentException("Unkown enum value: " + value); + } + } +} diff --git a/java/com/facebook/yoga/YogaPrintOptions.java b/java/com/facebook/yoga/YogaPrintOptions.java new file mode 100644 index 00000000..dae28660 --- /dev/null +++ b/java/com/facebook/yoga/YogaPrintOptions.java @@ -0,0 +1,38 @@ +/** + * 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. + */ + +package com.facebook.yoga; + +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public enum YogaPrintOptions { + LAYOUT(1), + STYLE(2), + CHILDREN(4); + + private int mIntValue; + + YogaPrintOptions(int intValue) { + mIntValue = intValue; + } + + public int intValue() { + return mIntValue; + } + + public static YogaPrintOptions fromInt(int value) { + switch (value) { + case 1: return LAYOUT; + case 2: return STYLE; + case 4: return CHILDREN; + default: throw new IllegalArgumentException("Unkown enum value: " + value); + } + } +} diff --git a/java/com/facebook/yoga/YogaWrap.java b/java/com/facebook/yoga/YogaWrap.java new file mode 100644 index 00000000..91cc3d5a --- /dev/null +++ b/java/com/facebook/yoga/YogaWrap.java @@ -0,0 +1,36 @@ +/** + * 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. + */ + +package com.facebook.yoga; + +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public enum YogaWrap { + NO_WRAP(0), + WRAP(1); + + private int mIntValue; + + YogaWrap(int intValue) { + mIntValue = intValue; + } + + public int intValue() { + return mIntValue; + } + + public static YogaWrap fromInt(int value) { + switch (value) { + case 0: return NO_WRAP; + case 1: return WRAP; + default: throw new IllegalArgumentException("Unkown enum value: " + value); + } + } +} diff --git a/java/jni/CSSJNI.cpp b/java/jni/CSSJNI.cpp deleted file mode 100644 index 3d9d488b..00000000 --- a/java/jni/CSSJNI.cpp +++ /dev/null @@ -1,269 +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 -#include -#include - -using namespace facebook::jni; -using namespace std; - -static void _jniTransferLayoutDirection(CSSNodeRef node, alias_ref javaNode) { - static auto layoutDirectionField = javaNode->getClass()->getField("mLayoutDirection"); - javaNode->setFieldValue(layoutDirectionField, static_cast(CSSNodeLayoutGetDirection(node))); -} - -static void _jniTransferLayoutOutputsRecursive(CSSNodeRef root) { - auto javaNode = adopt_local( - Environment::current()->NewLocalRef(reinterpret_cast(CSSNodeGetContext(root)))); - - static auto widthField = javaNode->getClass()->getField("mWidth"); - static auto heightField = javaNode->getClass()->getField("mHeight"); - static auto leftField = javaNode->getClass()->getField("mLeft"); - static auto topField = javaNode->getClass()->getField("mTop"); - - javaNode->setFieldValue(widthField, CSSNodeLayoutGetWidth(root)); - javaNode->setFieldValue(heightField, CSSNodeLayoutGetHeight(root)); - javaNode->setFieldValue(leftField, CSSNodeLayoutGetLeft(root)); - javaNode->setFieldValue(topField, CSSNodeLayoutGetTop(root)); - _jniTransferLayoutDirection(root, javaNode); - - for (uint32_t i = 0; i < CSSNodeChildCount(root); i++) { - _jniTransferLayoutOutputsRecursive(CSSNodeGetChild(root, i)); - } -} - -static void _jniPrint(CSSNodeRef node) { - auto obj = adopt_local(Environment::current()->NewLocalRef(reinterpret_cast(CSSNodeGetContext(node)))); - cout << obj->toString() << endl; -} - -static CSSSize _jniMeasureFunc(CSSNodeRef node, - float width, - CSSMeasureMode widthMode, - float height, - CSSMeasureMode heightMode) { - auto obj = adopt_local(Environment::current()->NewLocalRef(reinterpret_cast(CSSNodeGetContext(node)))); - - static auto measureFunc = - obj->getClass()->getMethod("measure"); - - _jniTransferLayoutDirection(node, obj); - const auto measureResult = measureFunc(obj, width, widthMode, height, heightMode); - - static_assert(sizeof(measureResult) == 8, - "Expected measureResult to be 8 bytes, or two 32 bit ints"); - - const float measuredWidth = static_cast(0xFFFFFFFF & (measureResult >> 32)); - const float measuredHeight = static_cast(0xFFFFFFFF & measureResult); - - return CSSSize{measuredWidth, measuredHeight}; -} - -static inline CSSNodeRef _jlong2CSSNodeRef(jlong addr) { - return reinterpret_cast(static_cast(addr)); -} - -jint jni_CSSNodeGetInstanceCount(alias_ref clazz) { - return CSSNodeGetInstanceCount(); -} - -jlong jni_CSSNodeNew(alias_ref thiz) { - const CSSNodeRef node = CSSNodeNew(); - CSSNodeSetContext(node, Environment::current()->NewWeakGlobalRef(thiz.get())); - CSSNodeSetPrintFunc(node, _jniPrint); - return reinterpret_cast(node); -} - -void jni_CSSNodeFree(alias_ref thiz, jlong nativePointer) { - Environment::current()->DeleteWeakGlobalRef( - reinterpret_cast(CSSNodeGetContext(_jlong2CSSNodeRef(nativePointer)))); - CSSNodeFree(_jlong2CSSNodeRef(nativePointer)); -} - -void jni_CSSNodeReset(alias_ref thiz, jlong nativePointer) { - const CSSNodeRef node = _jlong2CSSNodeRef(nativePointer); - void *context = CSSNodeGetContext(node); - CSSNodeReset(node); - CSSNodeSetContext(node, context); - CSSNodeSetPrintFunc(node, _jniPrint); -} - -void jni_CSSNodeInsertChild(alias_ref, - jlong nativePointer, - jlong childPointer, - jint index) { - CSSNodeInsertChild(_jlong2CSSNodeRef(nativePointer), _jlong2CSSNodeRef(childPointer), index); -} - -void jni_CSSNodeRemoveChild(alias_ref, jlong nativePointer, jlong childPointer) { - CSSNodeRemoveChild(_jlong2CSSNodeRef(nativePointer), _jlong2CSSNodeRef(childPointer)); -} - -void jni_CSSNodeCalculateLayout(alias_ref, jlong nativePointer) { - const CSSNodeRef root = _jlong2CSSNodeRef(nativePointer); - CSSNodeCalculateLayout(root, - CSSUndefined, - CSSUndefined, - CSSNodeStyleGetDirection(_jlong2CSSNodeRef(nativePointer))); - _jniTransferLayoutOutputsRecursive(root); -} - -void jni_CSSNodeMarkDirty(alias_ref, jlong nativePointer) { - CSSNodeMarkDirty(_jlong2CSSNodeRef(nativePointer)); -} - -jboolean jni_CSSNodeIsDirty(alias_ref, jlong nativePointer) { - return (jboolean) CSSNodeIsDirty(_jlong2CSSNodeRef(nativePointer)); -} - -void jni_CSSNodeSetHasMeasureFunc(alias_ref, - jlong nativePointer, - jboolean hasMeasureFunc) { - CSSNodeSetMeasureFunc(_jlong2CSSNodeRef(nativePointer), hasMeasureFunc ? _jniMeasureFunc : NULL); -} - -void jni_CSSNodeSetIsTextNode(alias_ref, jlong nativePointer, jboolean isTextNode) { - CSSNodeSetIsTextnode(_jlong2CSSNodeRef(nativePointer), isTextNode); -} - -jboolean jni_CSSNodeGetIsTextNode(alias_ref, jlong nativePointer) { - return (jboolean) CSSNodeGetIsTextnode(_jlong2CSSNodeRef(nativePointer)); -} - -jboolean jni_CSSNodeHasNewLayout(alias_ref, jlong nativePointer) { - return (jboolean) CSSNodeGetHasNewLayout(_jlong2CSSNodeRef(nativePointer)); -} - -void jni_CSSNodeMarkLayoutSeen(alias_ref, jlong nativePointer) { - CSSNodeSetHasNewLayout(_jlong2CSSNodeRef(nativePointer), false); -} - -#define CSS_NODE_JNI_STYLE_PROP(javatype, type, name) \ - javatype jni_CSSNodeStyleGet##name(alias_ref, jlong nativePointer) { \ - return (javatype) CSSNodeStyleGet##name(_jlong2CSSNodeRef(nativePointer)); \ - } \ - \ - void jni_CSSNodeStyleSet##name(alias_ref, jlong nativePointer, javatype value) { \ - CSSNodeStyleSet##name(_jlong2CSSNodeRef(nativePointer), static_cast(value)); \ - } - -#define CSS_NODE_JNI_STYLE_EDGE_PROP(javatype, type, name) \ - javatype jni_CSSNodeStyleGet##name(alias_ref, jlong nativePointer, jint edge) { \ - return (javatype) CSSNodeStyleGet##name(_jlong2CSSNodeRef(nativePointer), \ - static_cast(edge)); \ - } \ - \ - void jni_CSSNodeStyleSet##name(alias_ref, \ - jlong nativePointer, \ - jint edge, \ - javatype value) { \ - CSSNodeStyleSet##name(_jlong2CSSNodeRef(nativePointer), \ - static_cast(edge), \ - static_cast(value)); \ - } - -CSS_NODE_JNI_STYLE_PROP(jint, CSSDirection, Direction); -CSS_NODE_JNI_STYLE_PROP(jint, CSSFlexDirection, FlexDirection); -CSS_NODE_JNI_STYLE_PROP(jint, CSSJustify, JustifyContent); -CSS_NODE_JNI_STYLE_PROP(jint, CSSAlign, AlignItems); -CSS_NODE_JNI_STYLE_PROP(jint, CSSAlign, AlignSelf); -CSS_NODE_JNI_STYLE_PROP(jint, CSSAlign, AlignContent); -CSS_NODE_JNI_STYLE_PROP(jint, CSSPositionType, PositionType); -CSS_NODE_JNI_STYLE_PROP(jint, CSSWrapType, FlexWrap); -CSS_NODE_JNI_STYLE_PROP(jint, CSSOverflow, Overflow); - -void jni_CSSNodeStyleSetFlex(alias_ref, jlong nativePointer, jfloat value) { - CSSNodeStyleSetFlex(_jlong2CSSNodeRef(nativePointer), static_cast(value)); -} -CSS_NODE_JNI_STYLE_PROP(jfloat, float, FlexGrow); -CSS_NODE_JNI_STYLE_PROP(jfloat, float, FlexShrink); -CSS_NODE_JNI_STYLE_PROP(jfloat, float, FlexBasis); - -CSS_NODE_JNI_STYLE_EDGE_PROP(jfloat, float, Position); -CSS_NODE_JNI_STYLE_EDGE_PROP(jfloat, float, Margin); -CSS_NODE_JNI_STYLE_EDGE_PROP(jfloat, float, Padding); -CSS_NODE_JNI_STYLE_EDGE_PROP(jfloat, float, Border); - -CSS_NODE_JNI_STYLE_PROP(jfloat, float, Width); -CSS_NODE_JNI_STYLE_PROP(jfloat, float, MinWidth); -CSS_NODE_JNI_STYLE_PROP(jfloat, float, MaxWidth); -CSS_NODE_JNI_STYLE_PROP(jfloat, float, Height); -CSS_NODE_JNI_STYLE_PROP(jfloat, float, MinHeight); -CSS_NODE_JNI_STYLE_PROP(jfloat, float, MaxHeight); - -#define CSSMakeNativeMethod(name) makeNativeMethod(#name, name) - -jint JNI_OnLoad(JavaVM *vm, void *) { - return initialize(vm, [] { - registerNatives("com/facebook/csslayout/CSSNode", - { - CSSMakeNativeMethod(jni_CSSNodeNew), - CSSMakeNativeMethod(jni_CSSNodeFree), - CSSMakeNativeMethod(jni_CSSNodeReset), - CSSMakeNativeMethod(jni_CSSNodeInsertChild), - CSSMakeNativeMethod(jni_CSSNodeRemoveChild), - CSSMakeNativeMethod(jni_CSSNodeSetIsTextNode), - CSSMakeNativeMethod(jni_CSSNodeGetIsTextNode), - CSSMakeNativeMethod(jni_CSSNodeCalculateLayout), - CSSMakeNativeMethod(jni_CSSNodeHasNewLayout), - CSSMakeNativeMethod(jni_CSSNodeMarkDirty), - CSSMakeNativeMethod(jni_CSSNodeIsDirty), - CSSMakeNativeMethod(jni_CSSNodeMarkLayoutSeen), - CSSMakeNativeMethod(jni_CSSNodeSetHasMeasureFunc), - - CSSMakeNativeMethod(jni_CSSNodeStyleGetDirection), - CSSMakeNativeMethod(jni_CSSNodeStyleSetDirection), - CSSMakeNativeMethod(jni_CSSNodeStyleGetFlexDirection), - CSSMakeNativeMethod(jni_CSSNodeStyleSetFlexDirection), - CSSMakeNativeMethod(jni_CSSNodeStyleGetJustifyContent), - CSSMakeNativeMethod(jni_CSSNodeStyleSetJustifyContent), - CSSMakeNativeMethod(jni_CSSNodeStyleGetAlignItems), - CSSMakeNativeMethod(jni_CSSNodeStyleSetAlignItems), - CSSMakeNativeMethod(jni_CSSNodeStyleGetAlignSelf), - CSSMakeNativeMethod(jni_CSSNodeStyleSetAlignSelf), - CSSMakeNativeMethod(jni_CSSNodeStyleGetAlignContent), - CSSMakeNativeMethod(jni_CSSNodeStyleSetAlignContent), - CSSMakeNativeMethod(jni_CSSNodeStyleGetPositionType), - CSSMakeNativeMethod(jni_CSSNodeStyleSetPositionType), - CSSMakeNativeMethod(jni_CSSNodeStyleSetFlexWrap), - CSSMakeNativeMethod(jni_CSSNodeStyleGetOverflow), - CSSMakeNativeMethod(jni_CSSNodeStyleSetOverflow), - CSSMakeNativeMethod(jni_CSSNodeStyleSetFlex), - CSSMakeNativeMethod(jni_CSSNodeStyleGetFlexGrow), - CSSMakeNativeMethod(jni_CSSNodeStyleSetFlexGrow), - CSSMakeNativeMethod(jni_CSSNodeStyleGetFlexShrink), - CSSMakeNativeMethod(jni_CSSNodeStyleSetFlexShrink), - CSSMakeNativeMethod(jni_CSSNodeStyleGetFlexBasis), - CSSMakeNativeMethod(jni_CSSNodeStyleSetFlexBasis), - CSSMakeNativeMethod(jni_CSSNodeStyleGetMargin), - CSSMakeNativeMethod(jni_CSSNodeStyleSetMargin), - CSSMakeNativeMethod(jni_CSSNodeStyleGetPadding), - CSSMakeNativeMethod(jni_CSSNodeStyleSetPadding), - CSSMakeNativeMethod(jni_CSSNodeStyleGetBorder), - CSSMakeNativeMethod(jni_CSSNodeStyleSetBorder), - CSSMakeNativeMethod(jni_CSSNodeStyleGetPosition), - CSSMakeNativeMethod(jni_CSSNodeStyleSetPosition), - CSSMakeNativeMethod(jni_CSSNodeStyleGetWidth), - CSSMakeNativeMethod(jni_CSSNodeStyleSetWidth), - CSSMakeNativeMethod(jni_CSSNodeStyleGetHeight), - CSSMakeNativeMethod(jni_CSSNodeStyleSetHeight), - CSSMakeNativeMethod(jni_CSSNodeStyleGetMinWidth), - CSSMakeNativeMethod(jni_CSSNodeStyleSetMinWidth), - CSSMakeNativeMethod(jni_CSSNodeStyleGetMinHeight), - CSSMakeNativeMethod(jni_CSSNodeStyleSetMinHeight), - CSSMakeNativeMethod(jni_CSSNodeStyleGetMaxWidth), - CSSMakeNativeMethod(jni_CSSNodeStyleSetMaxWidth), - CSSMakeNativeMethod(jni_CSSNodeStyleGetMaxHeight), - CSSMakeNativeMethod(jni_CSSNodeStyleSetMaxHeight), - - CSSMakeNativeMethod(jni_CSSNodeGetInstanceCount), - }); - }); -} diff --git a/java/jni/YGJNI.cpp b/java/jni/YGJNI.cpp new file mode 100644 index 00000000..bf17f087 --- /dev/null +++ b/java/jni/YGJNI.cpp @@ -0,0 +1,333 @@ +/** + * 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 +#include +#include + +using namespace facebook::jni; +using namespace std; + +static inline weak_ref *YGNodeJobject(YGNodeRef node) { + return reinterpret_cast *>(YGNodeGetContext(node)); +} + +static void YGTransferLayoutDirection(YGNodeRef node, alias_ref javaNode) { + static auto layoutDirectionField = javaNode->getClass()->getField("mLayoutDirection"); + javaNode->setFieldValue(layoutDirectionField, static_cast(YGNodeLayoutGetDirection(node))); +} + +static void YGTransferLayoutOutputsRecursive(YGNodeRef root) { + if (auto obj = YGNodeJobject(root)->lockLocal()) { + static auto widthField = obj->getClass()->getField("mWidth"); + static auto heightField = obj->getClass()->getField("mHeight"); + static auto leftField = obj->getClass()->getField("mLeft"); + static auto topField = obj->getClass()->getField("mTop"); + + obj->setFieldValue(widthField, YGNodeLayoutGetWidth(root)); + obj->setFieldValue(heightField, YGNodeLayoutGetHeight(root)); + obj->setFieldValue(leftField, YGNodeLayoutGetLeft(root)); + obj->setFieldValue(topField, YGNodeLayoutGetTop(root)); + YGTransferLayoutDirection(root, obj); + + for (uint32_t i = 0; i < YGNodeChildCount(root); i++) { + YGTransferLayoutOutputsRecursive(YGNodeGetChild(root, i)); + } + } else { + YGLog(YGLogLevelError, "Java YGNode was GCed during layout calculation\n"); + } +} + +static void YGPrint(YGNodeRef node) { + if (auto obj = YGNodeJobject(node)->lockLocal()) { + cout << obj->toString() << endl; + } else { + YGLog(YGLogLevelError, "Java YGNode was GCed during layout calculation\n"); + } +} + +static YGSize YGJNIMeasureFunc(YGNodeRef node, + float width, + YGMeasureMode widthMode, + float height, + YGMeasureMode heightMode) { + if (auto obj = YGNodeJobject(node)->lockLocal()) { + static auto measureFunc = findClassLocal("com/facebook/yoga/YogaNode") + ->getMethod("measure"); + + YGTransferLayoutDirection(node, obj); + const auto measureResult = measureFunc(obj, width, widthMode, height, heightMode); + + static_assert(sizeof(measureResult) == 8, + "Expected measureResult to be 8 bytes, or two 32 bit ints"); + + const float measuredWidth = static_cast(0xFFFFFFFF & (measureResult >> 32)); + const float measuredHeight = static_cast(0xFFFFFFFF & measureResult); + + return YGSize{measuredWidth, measuredHeight}; + } else { + YGLog(YGLogLevelError, "Java YGNode was GCed during layout calculation\n"); + return YGSize{ + widthMode == YGMeasureModeUndefined ? 0 : width, + heightMode == YGMeasureModeUndefined ? 0 : height, + }; + } +} + +struct JYogaLogLevel : public JavaClass { + static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaLogLevel;"; +}; + +static global_ref *jLogger; +static int YGLog(YGLogLevel level, const char *format, va_list args) { + char buffer[256]; + int result = vsnprintf(buffer, sizeof(buffer), format, args); + + static auto logFunc = findClassLocal("com/facebook/yoga/YogaLogger") + ->getMethod, jstring)>("log"); + + static auto logLevelFromInt = + JYogaLogLevel::javaClassStatic()->getStaticMethod("fromInt"); + + logFunc(jLogger->get(), + logLevelFromInt(JYogaLogLevel::javaClassStatic(), static_cast(level)), + Environment::current()->NewStringUTF(buffer)); + + return result; +} + +static inline YGNodeRef _jlong2YGNodeRef(jlong addr) { + return reinterpret_cast(static_cast(addr)); +} + +void jni_YGSetLogger(alias_ref clazz, alias_ref logger) { + if (jLogger) { + jLogger->releaseAlias(); + delete jLogger; + } + + if (logger) { + jLogger = new global_ref(make_global(logger)); + YGSetLogger(YGLog); + } else { + jLogger = NULL; + YGSetLogger(NULL); + } +} + +void jni_YGLog(alias_ref clazz, jint level, jstring message) { + const char *nMessage = Environment::current()->GetStringUTFChars(message, 0); + YGLog(static_cast(level), "%s", nMessage); + Environment::current()->ReleaseStringUTFChars(message, nMessage); +} + +void jni_YGSetExperimentalFeatureEnabled(alias_ref clazz, jint feature, jboolean enabled) { + YGSetExperimentalFeatureEnabled(static_cast(feature), enabled); +} + +jboolean jni_YGIsExperimentalFeatureEnabled(alias_ref clazz, jint feature) { + return YGIsExperimentalFeatureEnabled(static_cast(feature)); +} + +jint jni_YGNodeGetInstanceCount(alias_ref clazz) { + return YGNodeGetInstanceCount(); +} + +jlong jni_YGNodeNew(alias_ref thiz) { + const YGNodeRef node = YGNodeNew(); + YGNodeSetContext(node, new weak_ref(make_weak(thiz))); + YGNodeSetPrintFunc(node, YGPrint); + return reinterpret_cast(node); +} + +void jni_YGNodeFree(alias_ref thiz, jlong nativePointer) { + const YGNodeRef node = _jlong2YGNodeRef(nativePointer); + delete YGNodeJobject(node); + YGNodeFree(node); +} + +void jni_YGNodeReset(alias_ref thiz, jlong nativePointer) { + const YGNodeRef node = _jlong2YGNodeRef(nativePointer); + void *context = YGNodeGetContext(node); + YGNodeReset(node); + YGNodeSetContext(node, context); + YGNodeSetPrintFunc(node, YGPrint); +} + +void jni_YGNodeInsertChild(alias_ref, jlong nativePointer, jlong childPointer, jint index) { + YGNodeInsertChild(_jlong2YGNodeRef(nativePointer), _jlong2YGNodeRef(childPointer), index); +} + +void jni_YGNodeRemoveChild(alias_ref, jlong nativePointer, jlong childPointer) { + YGNodeRemoveChild(_jlong2YGNodeRef(nativePointer), _jlong2YGNodeRef(childPointer)); +} + +void jni_YGNodeCalculateLayout(alias_ref, jlong nativePointer) { + const YGNodeRef root = _jlong2YGNodeRef(nativePointer); + YGNodeCalculateLayout(root, + YGUndefined, + YGUndefined, + YGNodeStyleGetDirection(_jlong2YGNodeRef(nativePointer))); + YGTransferLayoutOutputsRecursive(root); +} + +void jni_YGNodeMarkDirty(alias_ref, jlong nativePointer) { + YGNodeMarkDirty(_jlong2YGNodeRef(nativePointer)); +} + +jboolean jni_YGNodeIsDirty(alias_ref, jlong nativePointer) { + return (jboolean) YGNodeIsDirty(_jlong2YGNodeRef(nativePointer)); +} + +void jni_YGNodeSetHasMeasureFunc(alias_ref, jlong nativePointer, jboolean hasMeasureFunc) { + YGNodeSetMeasureFunc(_jlong2YGNodeRef(nativePointer), hasMeasureFunc ? YGJNIMeasureFunc : NULL); +} + +jboolean jni_YGNodeHasNewLayout(alias_ref, jlong nativePointer) { + return (jboolean) YGNodeGetHasNewLayout(_jlong2YGNodeRef(nativePointer)); +} + +void jni_YGNodeMarkLayoutSeen(alias_ref, jlong nativePointer) { + YGNodeSetHasNewLayout(_jlong2YGNodeRef(nativePointer), false); +} + +void jni_YGNodeCopyStyle(alias_ref, jlong dstNativePointer, jlong srcNativePointer) { + YGNodeCopyStyle(_jlong2YGNodeRef(dstNativePointer), _jlong2YGNodeRef(srcNativePointer)); +} + +#define YG_NODE_JNI_STYLE_PROP(javatype, type, name) \ + javatype jni_YGNodeStyleGet##name(alias_ref, jlong nativePointer) { \ + return (javatype) YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer)); \ + } \ + \ + void jni_YGNodeStyleSet##name(alias_ref, jlong nativePointer, javatype value) { \ + YGNodeStyleSet##name(_jlong2YGNodeRef(nativePointer), static_cast(value)); \ + } + +#define YG_NODE_JNI_STYLE_EDGE_PROP(javatype, type, name) \ + javatype jni_YGNodeStyleGet##name(alias_ref, jlong nativePointer, jint edge) { \ + return (javatype) YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer), \ + static_cast(edge)); \ + } \ + \ + void jni_YGNodeStyleSet##name(alias_ref, \ + jlong nativePointer, \ + jint edge, \ + javatype value) { \ + YGNodeStyleSet##name(_jlong2YGNodeRef(nativePointer), \ + static_cast(edge), \ + static_cast(value)); \ + } + +YG_NODE_JNI_STYLE_PROP(jint, YGDirection, Direction); +YG_NODE_JNI_STYLE_PROP(jint, YGFlexDirection, FlexDirection); +YG_NODE_JNI_STYLE_PROP(jint, YGJustify, JustifyContent); +YG_NODE_JNI_STYLE_PROP(jint, YGAlign, AlignItems); +YG_NODE_JNI_STYLE_PROP(jint, YGAlign, AlignSelf); +YG_NODE_JNI_STYLE_PROP(jint, YGAlign, AlignContent); +YG_NODE_JNI_STYLE_PROP(jint, YGPositionType, PositionType); +YG_NODE_JNI_STYLE_PROP(jint, YGWrap, FlexWrap); +YG_NODE_JNI_STYLE_PROP(jint, YGOverflow, Overflow); + +void jni_YGNodeStyleSetFlex(alias_ref, jlong nativePointer, jfloat value) { + YGNodeStyleSetFlex(_jlong2YGNodeRef(nativePointer), static_cast(value)); +} +YG_NODE_JNI_STYLE_PROP(jfloat, float, FlexGrow); +YG_NODE_JNI_STYLE_PROP(jfloat, float, FlexShrink); +YG_NODE_JNI_STYLE_PROP(jfloat, float, FlexBasis); + +YG_NODE_JNI_STYLE_EDGE_PROP(jfloat, float, Position); +YG_NODE_JNI_STYLE_EDGE_PROP(jfloat, float, Margin); +YG_NODE_JNI_STYLE_EDGE_PROP(jfloat, float, Padding); +YG_NODE_JNI_STYLE_EDGE_PROP(jfloat, float, Border); + +YG_NODE_JNI_STYLE_PROP(jfloat, float, Width); +YG_NODE_JNI_STYLE_PROP(jfloat, float, MinWidth); +YG_NODE_JNI_STYLE_PROP(jfloat, float, MaxWidth); +YG_NODE_JNI_STYLE_PROP(jfloat, float, Height); +YG_NODE_JNI_STYLE_PROP(jfloat, float, MinHeight); +YG_NODE_JNI_STYLE_PROP(jfloat, float, MaxHeight); + +// Yoga specific properties, not compatible with flexbox specification +YG_NODE_JNI_STYLE_PROP(jfloat, float, AspectRatio); + +#define YGMakeNativeMethod(name) makeNativeMethod(#name, name) + +jint JNI_OnLoad(JavaVM *vm, void *) { + return initialize(vm, [] { + registerNatives("com/facebook/yoga/YogaNode", + { + YGMakeNativeMethod(jni_YGNodeNew), + YGMakeNativeMethod(jni_YGNodeFree), + YGMakeNativeMethod(jni_YGNodeReset), + YGMakeNativeMethod(jni_YGNodeInsertChild), + YGMakeNativeMethod(jni_YGNodeRemoveChild), + YGMakeNativeMethod(jni_YGNodeCalculateLayout), + YGMakeNativeMethod(jni_YGNodeHasNewLayout), + YGMakeNativeMethod(jni_YGNodeMarkDirty), + YGMakeNativeMethod(jni_YGNodeIsDirty), + YGMakeNativeMethod(jni_YGNodeMarkLayoutSeen), + YGMakeNativeMethod(jni_YGNodeSetHasMeasureFunc), + YGMakeNativeMethod(jni_YGNodeCopyStyle), + + YGMakeNativeMethod(jni_YGNodeStyleGetDirection), + YGMakeNativeMethod(jni_YGNodeStyleSetDirection), + YGMakeNativeMethod(jni_YGNodeStyleGetFlexDirection), + YGMakeNativeMethod(jni_YGNodeStyleSetFlexDirection), + YGMakeNativeMethod(jni_YGNodeStyleGetJustifyContent), + YGMakeNativeMethod(jni_YGNodeStyleSetJustifyContent), + YGMakeNativeMethod(jni_YGNodeStyleGetAlignItems), + YGMakeNativeMethod(jni_YGNodeStyleSetAlignItems), + YGMakeNativeMethod(jni_YGNodeStyleGetAlignSelf), + YGMakeNativeMethod(jni_YGNodeStyleSetAlignSelf), + YGMakeNativeMethod(jni_YGNodeStyleGetAlignContent), + YGMakeNativeMethod(jni_YGNodeStyleSetAlignContent), + YGMakeNativeMethod(jni_YGNodeStyleGetPositionType), + YGMakeNativeMethod(jni_YGNodeStyleSetPositionType), + YGMakeNativeMethod(jni_YGNodeStyleSetFlexWrap), + YGMakeNativeMethod(jni_YGNodeStyleGetOverflow), + YGMakeNativeMethod(jni_YGNodeStyleSetOverflow), + YGMakeNativeMethod(jni_YGNodeStyleSetFlex), + YGMakeNativeMethod(jni_YGNodeStyleGetFlexGrow), + YGMakeNativeMethod(jni_YGNodeStyleSetFlexGrow), + YGMakeNativeMethod(jni_YGNodeStyleGetFlexShrink), + YGMakeNativeMethod(jni_YGNodeStyleSetFlexShrink), + YGMakeNativeMethod(jni_YGNodeStyleGetFlexBasis), + YGMakeNativeMethod(jni_YGNodeStyleSetFlexBasis), + YGMakeNativeMethod(jni_YGNodeStyleGetMargin), + YGMakeNativeMethod(jni_YGNodeStyleSetMargin), + YGMakeNativeMethod(jni_YGNodeStyleGetPadding), + YGMakeNativeMethod(jni_YGNodeStyleSetPadding), + YGMakeNativeMethod(jni_YGNodeStyleGetBorder), + YGMakeNativeMethod(jni_YGNodeStyleSetBorder), + YGMakeNativeMethod(jni_YGNodeStyleGetPosition), + YGMakeNativeMethod(jni_YGNodeStyleSetPosition), + YGMakeNativeMethod(jni_YGNodeStyleGetWidth), + YGMakeNativeMethod(jni_YGNodeStyleSetWidth), + YGMakeNativeMethod(jni_YGNodeStyleGetHeight), + YGMakeNativeMethod(jni_YGNodeStyleSetHeight), + YGMakeNativeMethod(jni_YGNodeStyleGetMinWidth), + YGMakeNativeMethod(jni_YGNodeStyleSetMinWidth), + YGMakeNativeMethod(jni_YGNodeStyleGetMinHeight), + YGMakeNativeMethod(jni_YGNodeStyleSetMinHeight), + YGMakeNativeMethod(jni_YGNodeStyleGetMaxWidth), + YGMakeNativeMethod(jni_YGNodeStyleSetMaxWidth), + YGMakeNativeMethod(jni_YGNodeStyleGetMaxHeight), + YGMakeNativeMethod(jni_YGNodeStyleSetMaxHeight), + YGMakeNativeMethod(jni_YGNodeStyleGetAspectRatio), + YGMakeNativeMethod(jni_YGNodeStyleSetAspectRatio), + + YGMakeNativeMethod(jni_YGNodeGetInstanceCount), + YGMakeNativeMethod(jni_YGSetLogger), + YGMakeNativeMethod(jni_YGLog), + YGMakeNativeMethod(jni_YGSetExperimentalFeatureEnabled), + YGMakeNativeMethod(jni_YGIsExperimentalFeatureEnabled), + }); + }); +} diff --git a/java/tests/com/facebook/csslayout/CSSLayoutAbsolutePositionTest.java b/java/tests/com/facebook/csslayout/CSSLayoutAbsolutePositionTest.java deleted file mode 100644 index c64be24e..00000000 --- a/java/tests/com/facebook/csslayout/CSSLayoutAbsolutePositionTest.java +++ /dev/null @@ -1,259 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
-
-
- * - */ - -package com.facebook.csslayout; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class CSSLayoutAbsolutePositionTest { - @Test - public void test_absolute_layout_width_height_start_top() { - final CSSNode root = new CSSNode(); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setPositionType(CSSPositionType.ABSOLUTE); - root_child0.setPosition(Spacing.START, 10); - root_child0.setPosition(Spacing.TOP, 10); - root_child0.setStyleWidth(10); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(10, root_child0.getLayoutX(), 0.0f); - assertEquals(10, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(80, root_child0.getLayoutX(), 0.0f); - assertEquals(10, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - } - - @Test - public void test_absolute_layout_width_height_end_bottom() { - final CSSNode root = new CSSNode(); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setPositionType(CSSPositionType.ABSOLUTE); - root_child0.setPosition(Spacing.END, 10); - root_child0.setPosition(Spacing.BOTTOM, 10); - root_child0.setStyleWidth(10); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(80, root_child0.getLayoutX(), 0.0f); - assertEquals(80, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(10, root_child0.getLayoutX(), 0.0f); - assertEquals(80, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - } - - @Test - public void test_absolute_layout_start_top_end_bottom() { - final CSSNode root = new CSSNode(); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setPositionType(CSSPositionType.ABSOLUTE); - root_child0.setPosition(Spacing.START, 10); - root_child0.setPosition(Spacing.TOP, 10); - root_child0.setPosition(Spacing.END, 10); - root_child0.setPosition(Spacing.BOTTOM, 10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(10, root_child0.getLayoutX(), 0.0f); - assertEquals(10, root_child0.getLayoutY(), 0.0f); - assertEquals(80, root_child0.getLayoutWidth(), 0.0f); - assertEquals(80, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(10, root_child0.getLayoutX(), 0.0f); - assertEquals(10, root_child0.getLayoutY(), 0.0f); - assertEquals(80, root_child0.getLayoutWidth(), 0.0f); - assertEquals(80, root_child0.getLayoutHeight(), 0.0f); - } - - @Test - public void test_absolute_layout_width_height_start_top_end_bottom() { - final CSSNode root = new CSSNode(); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setPositionType(CSSPositionType.ABSOLUTE); - root_child0.setPosition(Spacing.START, 10); - root_child0.setPosition(Spacing.TOP, 10); - root_child0.setPosition(Spacing.END, 10); - root_child0.setPosition(Spacing.BOTTOM, 10); - root_child0.setStyleWidth(10); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(10, root_child0.getLayoutX(), 0.0f); - assertEquals(10, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(80, root_child0.getLayoutX(), 0.0f); - assertEquals(10, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - } - - @Test - public void test_do_not_clamp_height_of_absolute_node_to_height_of_its_overflow_hidden_parent() { - final CSSNode root = new CSSNode(); - root.setFlexDirection(CSSFlexDirection.ROW); - root.setOverflow(CSSOverflow.HIDDEN); - root.setStyleWidth(50); - root.setStyleHeight(50); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setPositionType(CSSPositionType.ABSOLUTE); - root.addChildAt(root_child0, 0); - - final CSSNode root_child0_child0 = new CSSNode(); - root_child0_child0.setStyleWidth(100); - root_child0_child0.setStyleHeight(100); - root_child0.addChildAt(root_child0_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(50, root.getLayoutWidth(), 0.0f); - assertEquals(50, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0_child0.getLayoutWidth(), 0.0f); - assertEquals(100, root_child0_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(50, root.getLayoutWidth(), 0.0f); - assertEquals(50, root.getLayoutHeight(), 0.0f); - - assertEquals(-50, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0_child0.getLayoutWidth(), 0.0f); - assertEquals(100, root_child0_child0.getLayoutHeight(), 0.0f); - } - -} diff --git a/java/tests/com/facebook/csslayout/CSSLayoutAlignContentTest.java b/java/tests/com/facebook/csslayout/CSSLayoutAlignContentTest.java deleted file mode 100644 index c8ae2f98..00000000 --- a/java/tests/com/facebook/csslayout/CSSLayoutAlignContentTest.java +++ /dev/null @@ -1,444 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
-
-
-
-
- -
-
-
-
-
-
-
- -
-
-
-
-
-
-
- -
-
-
-
-
-
-
- * - */ - -package com.facebook.csslayout; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class CSSLayoutAlignContentTest { - @Test - public void test_align_content_flex_start() { - final CSSNode root = new CSSNode(); - root.setWrap(CSSWrap.WRAP); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleWidth(50); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setStyleWidth(50); - root_child1.setStyleHeight(10); - root.addChildAt(root_child1, 1); - - final CSSNode root_child2 = new CSSNode(); - root_child2.setStyleWidth(50); - root_child2.setStyleHeight(10); - root.addChildAt(root_child2, 2); - - final CSSNode root_child3 = new CSSNode(); - root_child3.setStyleWidth(50); - root_child3.setStyleHeight(10); - root.addChildAt(root_child3, 3); - - final CSSNode root_child4 = new CSSNode(); - root_child4.setStyleWidth(50); - root_child4.setStyleHeight(10); - root.addChildAt(root_child4, 4); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(50, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(10, root_child1.getLayoutY(), 0.0f); - assertEquals(50, root_child1.getLayoutWidth(), 0.0f); - assertEquals(10, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(20, root_child2.getLayoutY(), 0.0f); - assertEquals(50, root_child2.getLayoutWidth(), 0.0f); - assertEquals(10, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child3.getLayoutX(), 0.0f); - assertEquals(30, root_child3.getLayoutY(), 0.0f); - assertEquals(50, root_child3.getLayoutWidth(), 0.0f); - assertEquals(10, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child4.getLayoutX(), 0.0f); - assertEquals(40, root_child4.getLayoutY(), 0.0f); - assertEquals(50, root_child4.getLayoutWidth(), 0.0f); - assertEquals(10, root_child4.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(50, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(50, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(50, root_child1.getLayoutX(), 0.0f); - assertEquals(10, root_child1.getLayoutY(), 0.0f); - assertEquals(50, root_child1.getLayoutWidth(), 0.0f); - assertEquals(10, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(50, root_child2.getLayoutX(), 0.0f); - assertEquals(20, root_child2.getLayoutY(), 0.0f); - assertEquals(50, root_child2.getLayoutWidth(), 0.0f); - assertEquals(10, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(50, root_child3.getLayoutX(), 0.0f); - assertEquals(30, root_child3.getLayoutY(), 0.0f); - assertEquals(50, root_child3.getLayoutWidth(), 0.0f); - assertEquals(10, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(50, root_child4.getLayoutX(), 0.0f); - assertEquals(40, root_child4.getLayoutY(), 0.0f); - assertEquals(50, root_child4.getLayoutWidth(), 0.0f); - assertEquals(10, root_child4.getLayoutHeight(), 0.0f); - } - - @Test - public void test_align_content_flex_end() { - final CSSNode root = new CSSNode(); - root.setAlignContent(CSSAlign.FLEX_END); - root.setWrap(CSSWrap.WRAP); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleWidth(50); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setStyleWidth(50); - root_child1.setStyleHeight(10); - root.addChildAt(root_child1, 1); - - final CSSNode root_child2 = new CSSNode(); - root_child2.setStyleWidth(50); - root_child2.setStyleHeight(10); - root.addChildAt(root_child2, 2); - - final CSSNode root_child3 = new CSSNode(); - root_child3.setStyleWidth(50); - root_child3.setStyleHeight(10); - root.addChildAt(root_child3, 3); - - final CSSNode root_child4 = new CSSNode(); - root_child4.setStyleWidth(50); - root_child4.setStyleHeight(10); - root.addChildAt(root_child4, 4); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(50, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(10, root_child1.getLayoutY(), 0.0f); - assertEquals(50, root_child1.getLayoutWidth(), 0.0f); - assertEquals(10, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(20, root_child2.getLayoutY(), 0.0f); - assertEquals(50, root_child2.getLayoutWidth(), 0.0f); - assertEquals(10, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child3.getLayoutX(), 0.0f); - assertEquals(30, root_child3.getLayoutY(), 0.0f); - assertEquals(50, root_child3.getLayoutWidth(), 0.0f); - assertEquals(10, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child4.getLayoutX(), 0.0f); - assertEquals(40, root_child4.getLayoutY(), 0.0f); - assertEquals(50, root_child4.getLayoutWidth(), 0.0f); - assertEquals(10, root_child4.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(50, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(50, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(50, root_child1.getLayoutX(), 0.0f); - assertEquals(10, root_child1.getLayoutY(), 0.0f); - assertEquals(50, root_child1.getLayoutWidth(), 0.0f); - assertEquals(10, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(50, root_child2.getLayoutX(), 0.0f); - assertEquals(20, root_child2.getLayoutY(), 0.0f); - assertEquals(50, root_child2.getLayoutWidth(), 0.0f); - assertEquals(10, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(50, root_child3.getLayoutX(), 0.0f); - assertEquals(30, root_child3.getLayoutY(), 0.0f); - assertEquals(50, root_child3.getLayoutWidth(), 0.0f); - assertEquals(10, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(50, root_child4.getLayoutX(), 0.0f); - assertEquals(40, root_child4.getLayoutY(), 0.0f); - assertEquals(50, root_child4.getLayoutWidth(), 0.0f); - assertEquals(10, root_child4.getLayoutHeight(), 0.0f); - } - - @Test - public void test_align_content_center() { - final CSSNode root = new CSSNode(); - root.setAlignContent(CSSAlign.CENTER); - root.setWrap(CSSWrap.WRAP); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleWidth(50); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setStyleWidth(50); - root_child1.setStyleHeight(10); - root.addChildAt(root_child1, 1); - - final CSSNode root_child2 = new CSSNode(); - root_child2.setStyleWidth(50); - root_child2.setStyleHeight(10); - root.addChildAt(root_child2, 2); - - final CSSNode root_child3 = new CSSNode(); - root_child3.setStyleWidth(50); - root_child3.setStyleHeight(10); - root.addChildAt(root_child3, 3); - - final CSSNode root_child4 = new CSSNode(); - root_child4.setStyleWidth(50); - root_child4.setStyleHeight(10); - root.addChildAt(root_child4, 4); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(50, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(10, root_child1.getLayoutY(), 0.0f); - assertEquals(50, root_child1.getLayoutWidth(), 0.0f); - assertEquals(10, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(20, root_child2.getLayoutY(), 0.0f); - assertEquals(50, root_child2.getLayoutWidth(), 0.0f); - assertEquals(10, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child3.getLayoutX(), 0.0f); - assertEquals(30, root_child3.getLayoutY(), 0.0f); - assertEquals(50, root_child3.getLayoutWidth(), 0.0f); - assertEquals(10, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child4.getLayoutX(), 0.0f); - assertEquals(40, root_child4.getLayoutY(), 0.0f); - assertEquals(50, root_child4.getLayoutWidth(), 0.0f); - assertEquals(10, root_child4.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(50, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(50, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(50, root_child1.getLayoutX(), 0.0f); - assertEquals(10, root_child1.getLayoutY(), 0.0f); - assertEquals(50, root_child1.getLayoutWidth(), 0.0f); - assertEquals(10, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(50, root_child2.getLayoutX(), 0.0f); - assertEquals(20, root_child2.getLayoutY(), 0.0f); - assertEquals(50, root_child2.getLayoutWidth(), 0.0f); - assertEquals(10, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(50, root_child3.getLayoutX(), 0.0f); - assertEquals(30, root_child3.getLayoutY(), 0.0f); - assertEquals(50, root_child3.getLayoutWidth(), 0.0f); - assertEquals(10, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(50, root_child4.getLayoutX(), 0.0f); - assertEquals(40, root_child4.getLayoutY(), 0.0f); - assertEquals(50, root_child4.getLayoutWidth(), 0.0f); - assertEquals(10, root_child4.getLayoutHeight(), 0.0f); - } - - @Test - public void test_align_content_stretch() { - final CSSNode root = new CSSNode(); - root.setAlignContent(CSSAlign.STRETCH); - root.setWrap(CSSWrap.WRAP); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleWidth(50); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setStyleWidth(50); - root.addChildAt(root_child1, 1); - - final CSSNode root_child2 = new CSSNode(); - root_child2.setStyleWidth(50); - root.addChildAt(root_child2, 2); - - final CSSNode root_child3 = new CSSNode(); - root_child3.setStyleWidth(50); - root.addChildAt(root_child3, 3); - - final CSSNode root_child4 = new CSSNode(); - root_child4.setStyleWidth(50); - root.addChildAt(root_child4, 4); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(50, root_child0.getLayoutWidth(), 0.0f); - assertEquals(0, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(0, root_child1.getLayoutY(), 0.0f); - assertEquals(50, root_child1.getLayoutWidth(), 0.0f); - assertEquals(0, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(0, root_child2.getLayoutY(), 0.0f); - assertEquals(50, root_child2.getLayoutWidth(), 0.0f); - assertEquals(0, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child3.getLayoutX(), 0.0f); - assertEquals(0, root_child3.getLayoutY(), 0.0f); - assertEquals(50, root_child3.getLayoutWidth(), 0.0f); - assertEquals(0, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child4.getLayoutX(), 0.0f); - assertEquals(0, root_child4.getLayoutY(), 0.0f); - assertEquals(50, root_child4.getLayoutWidth(), 0.0f); - assertEquals(0, root_child4.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(50, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(50, root_child0.getLayoutWidth(), 0.0f); - assertEquals(0, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(50, root_child1.getLayoutX(), 0.0f); - assertEquals(0, root_child1.getLayoutY(), 0.0f); - assertEquals(50, root_child1.getLayoutWidth(), 0.0f); - assertEquals(0, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(50, root_child2.getLayoutX(), 0.0f); - assertEquals(0, root_child2.getLayoutY(), 0.0f); - assertEquals(50, root_child2.getLayoutWidth(), 0.0f); - assertEquals(0, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(50, root_child3.getLayoutX(), 0.0f); - assertEquals(0, root_child3.getLayoutY(), 0.0f); - assertEquals(50, root_child3.getLayoutWidth(), 0.0f); - assertEquals(0, root_child3.getLayoutHeight(), 0.0f); - - assertEquals(50, root_child4.getLayoutX(), 0.0f); - assertEquals(0, root_child4.getLayoutY(), 0.0f); - assertEquals(50, root_child4.getLayoutWidth(), 0.0f); - assertEquals(0, root_child4.getLayoutHeight(), 0.0f); - } - -} diff --git a/java/tests/com/facebook/csslayout/CSSLayoutAlignItemsTest.java b/java/tests/com/facebook/csslayout/CSSLayoutAlignItemsTest.java deleted file mode 100644 index 49689901..00000000 --- a/java/tests/com/facebook/csslayout/CSSLayoutAlignItemsTest.java +++ /dev/null @@ -1,188 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
- -
-
-
- -
-
-
- -
-
-
- * - */ - -package com.facebook.csslayout; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class CSSLayoutAlignItemsTest { - @Test - public void test_align_items_stretch() { - final CSSNode root = new CSSNode(); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - } - - @Test - public void test_align_items_center() { - final CSSNode root = new CSSNode(); - root.setAlignItems(CSSAlign.CENTER); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleWidth(10); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(45, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(45, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - } - - @Test - public void test_align_items_flex_start() { - final CSSNode root = new CSSNode(); - root.setAlignItems(CSSAlign.FLEX_START); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleWidth(10); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(90, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - } - - @Test - public void test_align_items_flex_end() { - final CSSNode root = new CSSNode(); - root.setAlignItems(CSSAlign.FLEX_END); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleWidth(10); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(90, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - } - -} diff --git a/java/tests/com/facebook/csslayout/CSSLayoutAlignSelfTest.java b/java/tests/com/facebook/csslayout/CSSLayoutAlignSelfTest.java deleted file mode 100644 index 999972de..00000000 --- a/java/tests/com/facebook/csslayout/CSSLayoutAlignSelfTest.java +++ /dev/null @@ -1,191 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
- -
-
-
- -
-
-
- -
-
-
- * - */ - -package com.facebook.csslayout; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class CSSLayoutAlignSelfTest { - @Test - public void test_align_self_center() { - final CSSNode root = new CSSNode(); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setAlignSelf(CSSAlign.CENTER); - root_child0.setStyleWidth(10); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(45, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(45, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - } - - @Test - public void test_align_self_flex_end() { - final CSSNode root = new CSSNode(); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setAlignSelf(CSSAlign.FLEX_END); - root_child0.setStyleWidth(10); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(90, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - } - - @Test - public void test_align_self_flex_start() { - final CSSNode root = new CSSNode(); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setAlignSelf(CSSAlign.FLEX_START); - root_child0.setStyleWidth(10); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(90, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - } - - @Test - public void test_align_self_flex_end_override_flex_start() { - final CSSNode root = new CSSNode(); - root.setAlignItems(CSSAlign.FLEX_START); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setAlignSelf(CSSAlign.FLEX_END); - root_child0.setStyleWidth(10); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(90, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - } - -} diff --git a/java/tests/com/facebook/csslayout/CSSLayoutBorderTest.java b/java/tests/com/facebook/csslayout/CSSLayoutBorderTest.java deleted file mode 100644 index ee7505e4..00000000 --- a/java/tests/com/facebook/csslayout/CSSLayoutBorderTest.java +++ /dev/null @@ -1,227 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- * - */ - -package com.facebook.csslayout; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class CSSLayoutBorderTest { - @Test - public void test_border_no_size() { - final CSSNode root = new CSSNode(); - root.setBorder(Spacing.LEFT, 10); - root.setBorder(Spacing.TOP, 10); - root.setBorder(Spacing.RIGHT, 10); - root.setBorder(Spacing.BOTTOM, 10); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(20, root.getLayoutWidth(), 0.0f); - assertEquals(20, root.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(20, root.getLayoutWidth(), 0.0f); - assertEquals(20, root.getLayoutHeight(), 0.0f); - } - - @Test - public void test_border_container_match_child() { - final CSSNode root = new CSSNode(); - root.setBorder(Spacing.LEFT, 10); - root.setBorder(Spacing.TOP, 10); - root.setBorder(Spacing.RIGHT, 10); - root.setBorder(Spacing.BOTTOM, 10); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleWidth(10); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(30, root.getLayoutWidth(), 0.0f); - assertEquals(30, root.getLayoutHeight(), 0.0f); - - assertEquals(10, root_child0.getLayoutX(), 0.0f); - assertEquals(10, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(30, root.getLayoutWidth(), 0.0f); - assertEquals(30, root.getLayoutHeight(), 0.0f); - - assertEquals(10, root_child0.getLayoutX(), 0.0f); - assertEquals(10, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - } - - @Test - public void test_border_flex_child() { - final CSSNode root = new CSSNode(); - root.setBorder(Spacing.LEFT, 10); - root.setBorder(Spacing.TOP, 10); - root.setBorder(Spacing.RIGHT, 10); - root.setBorder(Spacing.BOTTOM, 10); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setFlexGrow(1); - root_child0.setStyleWidth(10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(10, root_child0.getLayoutX(), 0.0f); - assertEquals(10, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(80, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(80, root_child0.getLayoutX(), 0.0f); - assertEquals(10, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(80, root_child0.getLayoutHeight(), 0.0f); - } - - @Test - public void test_border_stretch_child() { - final CSSNode root = new CSSNode(); - root.setBorder(Spacing.LEFT, 10); - root.setBorder(Spacing.TOP, 10); - root.setBorder(Spacing.RIGHT, 10); - root.setBorder(Spacing.BOTTOM, 10); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(10, root_child0.getLayoutX(), 0.0f); - assertEquals(10, root_child0.getLayoutY(), 0.0f); - assertEquals(80, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(10, root_child0.getLayoutX(), 0.0f); - assertEquals(10, root_child0.getLayoutY(), 0.0f); - assertEquals(80, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - } - - @Test - public void test_border_center_child() { - final CSSNode root = new CSSNode(); - root.setJustifyContent(CSSJustify.CENTER); - root.setAlignItems(CSSAlign.CENTER); - root.setBorder(Spacing.START, 10); - root.setBorder(Spacing.END, 20); - root.setBorder(Spacing.BOTTOM, 20); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleWidth(10); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(40, root_child0.getLayoutX(), 0.0f); - assertEquals(35, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(50, root_child0.getLayoutX(), 0.0f); - assertEquals(35, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - } - -} diff --git a/java/tests/com/facebook/csslayout/CSSLayoutFlexDirectionTest.java b/java/tests/com/facebook/csslayout/CSSLayoutFlexDirectionTest.java deleted file mode 100644 index 7d741b7c..00000000 --- a/java/tests/com/facebook/csslayout/CSSLayoutFlexDirectionTest.java +++ /dev/null @@ -1,444 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- * - */ - -package com.facebook.csslayout; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class CSSLayoutFlexDirectionTest { - @Test - public void test_flex_direction_column_no_height() { - final CSSNode root = new CSSNode(); - root.setStyleWidth(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setStyleHeight(10); - root.addChildAt(root_child1, 1); - - final CSSNode root_child2 = new CSSNode(); - root_child2.setStyleHeight(10); - root.addChildAt(root_child2, 2); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(30, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(10, root_child1.getLayoutY(), 0.0f); - assertEquals(100, root_child1.getLayoutWidth(), 0.0f); - assertEquals(10, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(20, root_child2.getLayoutY(), 0.0f); - assertEquals(100, root_child2.getLayoutWidth(), 0.0f); - assertEquals(10, root_child2.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(30, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(10, root_child1.getLayoutY(), 0.0f); - assertEquals(100, root_child1.getLayoutWidth(), 0.0f); - assertEquals(10, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(20, root_child2.getLayoutY(), 0.0f); - assertEquals(100, root_child2.getLayoutWidth(), 0.0f); - assertEquals(10, root_child2.getLayoutHeight(), 0.0f); - } - - @Test - public void test_flex_direction_row_no_width() { - final CSSNode root = new CSSNode(); - root.setFlexDirection(CSSFlexDirection.ROW); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleWidth(10); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setStyleWidth(10); - root.addChildAt(root_child1, 1); - - final CSSNode root_child2 = new CSSNode(); - root_child2.setStyleWidth(10); - root.addChildAt(root_child2, 2); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(30, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(10, root_child1.getLayoutX(), 0.0f); - assertEquals(0, root_child1.getLayoutY(), 0.0f); - assertEquals(10, root_child1.getLayoutWidth(), 0.0f); - assertEquals(100, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(20, root_child2.getLayoutX(), 0.0f); - assertEquals(0, root_child2.getLayoutY(), 0.0f); - assertEquals(10, root_child2.getLayoutWidth(), 0.0f); - assertEquals(100, root_child2.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(30, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(20, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(10, root_child1.getLayoutX(), 0.0f); - assertEquals(0, root_child1.getLayoutY(), 0.0f); - assertEquals(10, root_child1.getLayoutWidth(), 0.0f); - assertEquals(100, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(0, root_child2.getLayoutY(), 0.0f); - assertEquals(10, root_child2.getLayoutWidth(), 0.0f); - assertEquals(100, root_child2.getLayoutHeight(), 0.0f); - } - - @Test - public void test_flex_direction_column() { - final CSSNode root = new CSSNode(); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setStyleHeight(10); - root.addChildAt(root_child1, 1); - - final CSSNode root_child2 = new CSSNode(); - root_child2.setStyleHeight(10); - root.addChildAt(root_child2, 2); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(10, root_child1.getLayoutY(), 0.0f); - assertEquals(100, root_child1.getLayoutWidth(), 0.0f); - assertEquals(10, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(20, root_child2.getLayoutY(), 0.0f); - assertEquals(100, root_child2.getLayoutWidth(), 0.0f); - assertEquals(10, root_child2.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(10, root_child1.getLayoutY(), 0.0f); - assertEquals(100, root_child1.getLayoutWidth(), 0.0f); - assertEquals(10, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(20, root_child2.getLayoutY(), 0.0f); - assertEquals(100, root_child2.getLayoutWidth(), 0.0f); - assertEquals(10, root_child2.getLayoutHeight(), 0.0f); - } - - @Test - public void test_flex_direction_row() { - final CSSNode root = new CSSNode(); - root.setFlexDirection(CSSFlexDirection.ROW); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleWidth(10); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setStyleWidth(10); - root.addChildAt(root_child1, 1); - - final CSSNode root_child2 = new CSSNode(); - root_child2.setStyleWidth(10); - root.addChildAt(root_child2, 2); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(10, root_child1.getLayoutX(), 0.0f); - assertEquals(0, root_child1.getLayoutY(), 0.0f); - assertEquals(10, root_child1.getLayoutWidth(), 0.0f); - assertEquals(100, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(20, root_child2.getLayoutX(), 0.0f); - assertEquals(0, root_child2.getLayoutY(), 0.0f); - assertEquals(10, root_child2.getLayoutWidth(), 0.0f); - assertEquals(100, root_child2.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(90, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(80, root_child1.getLayoutX(), 0.0f); - assertEquals(0, root_child1.getLayoutY(), 0.0f); - assertEquals(10, root_child1.getLayoutWidth(), 0.0f); - assertEquals(100, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(70, root_child2.getLayoutX(), 0.0f); - assertEquals(0, root_child2.getLayoutY(), 0.0f); - assertEquals(10, root_child2.getLayoutWidth(), 0.0f); - assertEquals(100, root_child2.getLayoutHeight(), 0.0f); - } - - @Test - public void test_flex_direction_column_reverse() { - final CSSNode root = new CSSNode(); - root.setFlexDirection(CSSFlexDirection.COLUMN_REVERSE); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setStyleHeight(10); - root.addChildAt(root_child1, 1); - - final CSSNode root_child2 = new CSSNode(); - root_child2.setStyleHeight(10); - root.addChildAt(root_child2, 2); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(90, root_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(80, root_child1.getLayoutY(), 0.0f); - assertEquals(100, root_child1.getLayoutWidth(), 0.0f); - assertEquals(10, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(70, root_child2.getLayoutY(), 0.0f); - assertEquals(100, root_child2.getLayoutWidth(), 0.0f); - assertEquals(10, root_child2.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(90, root_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(80, root_child1.getLayoutY(), 0.0f); - assertEquals(100, root_child1.getLayoutWidth(), 0.0f); - assertEquals(10, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(70, root_child2.getLayoutY(), 0.0f); - assertEquals(100, root_child2.getLayoutWidth(), 0.0f); - assertEquals(10, root_child2.getLayoutHeight(), 0.0f); - } - - @Test - public void test_flex_direction_row_reverse() { - final CSSNode root = new CSSNode(); - root.setFlexDirection(CSSFlexDirection.ROW_REVERSE); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleWidth(10); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setStyleWidth(10); - root.addChildAt(root_child1, 1); - - final CSSNode root_child2 = new CSSNode(); - root_child2.setStyleWidth(10); - root.addChildAt(root_child2, 2); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(90, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(80, root_child1.getLayoutX(), 0.0f); - assertEquals(0, root_child1.getLayoutY(), 0.0f); - assertEquals(10, root_child1.getLayoutWidth(), 0.0f); - assertEquals(100, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(70, root_child2.getLayoutX(), 0.0f); - assertEquals(0, root_child2.getLayoutY(), 0.0f); - assertEquals(10, root_child2.getLayoutWidth(), 0.0f); - assertEquals(100, root_child2.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(10, root_child1.getLayoutX(), 0.0f); - assertEquals(0, root_child1.getLayoutY(), 0.0f); - assertEquals(10, root_child1.getLayoutWidth(), 0.0f); - assertEquals(100, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(20, root_child2.getLayoutX(), 0.0f); - assertEquals(0, root_child2.getLayoutY(), 0.0f); - assertEquals(10, root_child2.getLayoutWidth(), 0.0f); - assertEquals(100, root_child2.getLayoutHeight(), 0.0f); - } - -} diff --git a/java/tests/com/facebook/csslayout/CSSLayoutFlexTest.java b/java/tests/com/facebook/csslayout/CSSLayoutFlexTest.java deleted file mode 100644 index 5056e307..00000000 --- a/java/tests/com/facebook/csslayout/CSSLayoutFlexTest.java +++ /dev/null @@ -1,395 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
-
- -
-
-
-
- -
-
-
-
- -
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- * - */ - -package com.facebook.csslayout; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class CSSLayoutFlexTest { - @Test - public void test_flex_basis_flex_grow_column() { - final CSSNode root = new CSSNode(); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setFlexGrow(1); - root_child0.setFlexBasis(50); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setFlexGrow(1); - root.addChildAt(root_child1, 1); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0.getLayoutWidth(), 0.0f); - assertEquals(75, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(75, root_child1.getLayoutY(), 0.0f); - assertEquals(100, root_child1.getLayoutWidth(), 0.0f); - assertEquals(25, root_child1.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0.getLayoutWidth(), 0.0f); - assertEquals(75, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(75, root_child1.getLayoutY(), 0.0f); - assertEquals(100, root_child1.getLayoutWidth(), 0.0f); - assertEquals(25, root_child1.getLayoutHeight(), 0.0f); - } - - @Test - public void test_flex_basis_flex_grow_row() { - final CSSNode root = new CSSNode(); - root.setFlexDirection(CSSFlexDirection.ROW); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setFlexGrow(1); - root_child0.setFlexBasis(50); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setFlexGrow(1); - root.addChildAt(root_child1, 1); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(75, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(75, root_child1.getLayoutX(), 0.0f); - assertEquals(0, root_child1.getLayoutY(), 0.0f); - assertEquals(25, root_child1.getLayoutWidth(), 0.0f); - assertEquals(100, root_child1.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(25, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(75, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(0, root_child1.getLayoutY(), 0.0f); - assertEquals(25, root_child1.getLayoutWidth(), 0.0f); - assertEquals(100, root_child1.getLayoutHeight(), 0.0f); - } - - @Test - public void test_flex_basis_flex_shrink_column() { - final CSSNode root = new CSSNode(); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setFlexShrink(1); - root_child0.setFlexBasis(100); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setFlexBasis(50); - root.addChildAt(root_child1, 1); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0.getLayoutWidth(), 0.0f); - assertEquals(50, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(50, root_child1.getLayoutY(), 0.0f); - assertEquals(100, root_child1.getLayoutWidth(), 0.0f); - assertEquals(50, root_child1.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0.getLayoutWidth(), 0.0f); - assertEquals(50, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(50, root_child1.getLayoutY(), 0.0f); - assertEquals(100, root_child1.getLayoutWidth(), 0.0f); - assertEquals(50, root_child1.getLayoutHeight(), 0.0f); - } - - @Test - public void test_flex_basis_flex_shrink_row() { - final CSSNode root = new CSSNode(); - root.setFlexDirection(CSSFlexDirection.ROW); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setFlexShrink(1); - root_child0.setFlexBasis(100); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setFlexBasis(50); - root.addChildAt(root_child1, 1); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(50, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(50, root_child1.getLayoutX(), 0.0f); - assertEquals(0, root_child1.getLayoutY(), 0.0f); - assertEquals(50, root_child1.getLayoutWidth(), 0.0f); - assertEquals(100, root_child1.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(50, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(50, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(0, root_child1.getLayoutY(), 0.0f); - assertEquals(50, root_child1.getLayoutWidth(), 0.0f); - assertEquals(100, root_child1.getLayoutHeight(), 0.0f); - } - - @Test - public void test_flex_shrink_to_zero() { - final CSSNode root = new CSSNode(); - root.setStyleHeight(75); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleWidth(50); - root_child0.setStyleHeight(50); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setFlexShrink(1); - root_child1.setStyleWidth(50); - root_child1.setStyleHeight(50); - root.addChildAt(root_child1, 1); - - final CSSNode root_child2 = new CSSNode(); - root_child2.setStyleWidth(50); - root_child2.setStyleHeight(50); - root.addChildAt(root_child2, 2); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(50, root.getLayoutWidth(), 0.0f); - assertEquals(75, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(50, root_child0.getLayoutWidth(), 0.0f); - assertEquals(50, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(50, root_child1.getLayoutY(), 0.0f); - assertEquals(50, root_child1.getLayoutWidth(), 0.0f); - assertEquals(0, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(50, root_child2.getLayoutY(), 0.0f); - assertEquals(50, root_child2.getLayoutWidth(), 0.0f); - assertEquals(50, root_child2.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(50, root.getLayoutWidth(), 0.0f); - assertEquals(75, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(50, root_child0.getLayoutWidth(), 0.0f); - assertEquals(50, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(50, root_child1.getLayoutY(), 0.0f); - assertEquals(50, root_child1.getLayoutWidth(), 0.0f); - assertEquals(0, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(50, root_child2.getLayoutY(), 0.0f); - assertEquals(50, root_child2.getLayoutWidth(), 0.0f); - assertEquals(50, root_child2.getLayoutHeight(), 0.0f); - } - - @Test - public void test_flex_basis_overrides_main_size() { - final CSSNode root = new CSSNode(); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setFlexGrow(1); - root_child0.setFlexBasis(50); - root_child0.setStyleHeight(20); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setFlexGrow(1); - root_child1.setStyleHeight(10); - root.addChildAt(root_child1, 1); - - final CSSNode root_child2 = new CSSNode(); - root_child2.setFlexGrow(1); - root_child2.setStyleHeight(10); - root.addChildAt(root_child2, 2); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0.getLayoutWidth(), 0.0f); - assertEquals(60, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(60, root_child1.getLayoutY(), 0.0f); - assertEquals(100, root_child1.getLayoutWidth(), 0.0f); - assertEquals(20, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(80, root_child2.getLayoutY(), 0.0f); - assertEquals(100, root_child2.getLayoutWidth(), 0.0f); - assertEquals(20, root_child2.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0.getLayoutWidth(), 0.0f); - assertEquals(60, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(60, root_child1.getLayoutY(), 0.0f); - assertEquals(100, root_child1.getLayoutWidth(), 0.0f); - assertEquals(20, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(80, root_child2.getLayoutY(), 0.0f); - assertEquals(100, root_child2.getLayoutWidth(), 0.0f); - assertEquals(20, root_child2.getLayoutHeight(), 0.0f); - } - -} diff --git a/java/tests/com/facebook/csslayout/CSSLayoutFlexWrapTest.java b/java/tests/com/facebook/csslayout/CSSLayoutFlexWrapTest.java deleted file mode 100644 index bd4b506d..00000000 --- a/java/tests/com/facebook/csslayout/CSSLayoutFlexWrapTest.java +++ /dev/null @@ -1,383 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- * - */ - -package com.facebook.csslayout; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class CSSLayoutFlexWrapTest { - @Test - public void test_wrap_column() { - final CSSNode root = new CSSNode(); - root.setWrap(CSSWrap.WRAP); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleWidth(30); - root_child0.setStyleHeight(30); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setStyleWidth(30); - root_child1.setStyleHeight(30); - root.addChildAt(root_child1, 1); - - final CSSNode root_child2 = new CSSNode(); - root_child2.setStyleWidth(30); - root_child2.setStyleHeight(30); - root.addChildAt(root_child2, 2); - - final CSSNode root_child3 = new CSSNode(); - root_child3.setStyleWidth(30); - root_child3.setStyleHeight(30); - root.addChildAt(root_child3, 3); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(60, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(30, root_child0.getLayoutWidth(), 0.0f); - assertEquals(30, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(30, root_child1.getLayoutY(), 0.0f); - assertEquals(30, root_child1.getLayoutWidth(), 0.0f); - assertEquals(30, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(60, root_child2.getLayoutY(), 0.0f); - assertEquals(30, root_child2.getLayoutWidth(), 0.0f); - assertEquals(30, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(30, root_child3.getLayoutX(), 0.0f); - assertEquals(0, root_child3.getLayoutY(), 0.0f); - assertEquals(30, root_child3.getLayoutWidth(), 0.0f); - assertEquals(30, root_child3.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(60, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(30, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(30, root_child0.getLayoutWidth(), 0.0f); - assertEquals(30, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(30, root_child1.getLayoutX(), 0.0f); - assertEquals(30, root_child1.getLayoutY(), 0.0f); - assertEquals(30, root_child1.getLayoutWidth(), 0.0f); - assertEquals(30, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(30, root_child2.getLayoutX(), 0.0f); - assertEquals(60, root_child2.getLayoutY(), 0.0f); - assertEquals(30, root_child2.getLayoutWidth(), 0.0f); - assertEquals(30, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child3.getLayoutX(), 0.0f); - assertEquals(0, root_child3.getLayoutY(), 0.0f); - assertEquals(30, root_child3.getLayoutWidth(), 0.0f); - assertEquals(30, root_child3.getLayoutHeight(), 0.0f); - } - - @Test - public void test_wrap_row() { - final CSSNode root = new CSSNode(); - root.setFlexDirection(CSSFlexDirection.ROW); - root.setWrap(CSSWrap.WRAP); - root.setStyleWidth(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleWidth(30); - root_child0.setStyleHeight(30); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setStyleWidth(30); - root_child1.setStyleHeight(30); - root.addChildAt(root_child1, 1); - - final CSSNode root_child2 = new CSSNode(); - root_child2.setStyleWidth(30); - root_child2.setStyleHeight(30); - root.addChildAt(root_child2, 2); - - final CSSNode root_child3 = new CSSNode(); - root_child3.setStyleWidth(30); - root_child3.setStyleHeight(30); - root.addChildAt(root_child3, 3); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(60, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(30, root_child0.getLayoutWidth(), 0.0f); - assertEquals(30, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(30, root_child1.getLayoutX(), 0.0f); - assertEquals(0, root_child1.getLayoutY(), 0.0f); - assertEquals(30, root_child1.getLayoutWidth(), 0.0f); - assertEquals(30, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(60, root_child2.getLayoutX(), 0.0f); - assertEquals(0, root_child2.getLayoutY(), 0.0f); - assertEquals(30, root_child2.getLayoutWidth(), 0.0f); - assertEquals(30, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child3.getLayoutX(), 0.0f); - assertEquals(30, root_child3.getLayoutY(), 0.0f); - assertEquals(30, root_child3.getLayoutWidth(), 0.0f); - assertEquals(30, root_child3.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(60, root.getLayoutHeight(), 0.0f); - - assertEquals(70, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(30, root_child0.getLayoutWidth(), 0.0f); - assertEquals(30, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(40, root_child1.getLayoutX(), 0.0f); - assertEquals(0, root_child1.getLayoutY(), 0.0f); - assertEquals(30, root_child1.getLayoutWidth(), 0.0f); - assertEquals(30, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(10, root_child2.getLayoutX(), 0.0f); - assertEquals(0, root_child2.getLayoutY(), 0.0f); - assertEquals(30, root_child2.getLayoutWidth(), 0.0f); - assertEquals(30, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(70, root_child3.getLayoutX(), 0.0f); - assertEquals(30, root_child3.getLayoutY(), 0.0f); - assertEquals(30, root_child3.getLayoutWidth(), 0.0f); - assertEquals(30, root_child3.getLayoutHeight(), 0.0f); - } - - @Test - public void test_wrap_row_align_items_flex_end() { - final CSSNode root = new CSSNode(); - root.setFlexDirection(CSSFlexDirection.ROW); - root.setAlignItems(CSSAlign.FLEX_END); - root.setWrap(CSSWrap.WRAP); - root.setStyleWidth(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleWidth(30); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setStyleWidth(30); - root_child1.setStyleHeight(20); - root.addChildAt(root_child1, 1); - - final CSSNode root_child2 = new CSSNode(); - root_child2.setStyleWidth(30); - root_child2.setStyleHeight(30); - root.addChildAt(root_child2, 2); - - final CSSNode root_child3 = new CSSNode(); - root_child3.setStyleWidth(30); - root_child3.setStyleHeight(30); - root.addChildAt(root_child3, 3); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(60, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(20, root_child0.getLayoutY(), 0.0f); - assertEquals(30, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(30, root_child1.getLayoutX(), 0.0f); - assertEquals(10, root_child1.getLayoutY(), 0.0f); - assertEquals(30, root_child1.getLayoutWidth(), 0.0f); - assertEquals(20, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(60, root_child2.getLayoutX(), 0.0f); - assertEquals(0, root_child2.getLayoutY(), 0.0f); - assertEquals(30, root_child2.getLayoutWidth(), 0.0f); - assertEquals(30, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child3.getLayoutX(), 0.0f); - assertEquals(30, root_child3.getLayoutY(), 0.0f); - assertEquals(30, root_child3.getLayoutWidth(), 0.0f); - assertEquals(30, root_child3.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(60, root.getLayoutHeight(), 0.0f); - - assertEquals(70, root_child0.getLayoutX(), 0.0f); - assertEquals(20, root_child0.getLayoutY(), 0.0f); - assertEquals(30, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(40, root_child1.getLayoutX(), 0.0f); - assertEquals(10, root_child1.getLayoutY(), 0.0f); - assertEquals(30, root_child1.getLayoutWidth(), 0.0f); - assertEquals(20, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(10, root_child2.getLayoutX(), 0.0f); - assertEquals(0, root_child2.getLayoutY(), 0.0f); - assertEquals(30, root_child2.getLayoutWidth(), 0.0f); - assertEquals(30, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(70, root_child3.getLayoutX(), 0.0f); - assertEquals(30, root_child3.getLayoutY(), 0.0f); - assertEquals(30, root_child3.getLayoutWidth(), 0.0f); - assertEquals(30, root_child3.getLayoutHeight(), 0.0f); - } - - @Test - public void test_wrap_row_align_items_center() { - final CSSNode root = new CSSNode(); - root.setFlexDirection(CSSFlexDirection.ROW); - root.setAlignItems(CSSAlign.CENTER); - root.setWrap(CSSWrap.WRAP); - root.setStyleWidth(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleWidth(30); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setStyleWidth(30); - root_child1.setStyleHeight(20); - root.addChildAt(root_child1, 1); - - final CSSNode root_child2 = new CSSNode(); - root_child2.setStyleWidth(30); - root_child2.setStyleHeight(30); - root.addChildAt(root_child2, 2); - - final CSSNode root_child3 = new CSSNode(); - root_child3.setStyleWidth(30); - root_child3.setStyleHeight(30); - root.addChildAt(root_child3, 3); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(60, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(10, root_child0.getLayoutY(), 0.0f); - assertEquals(30, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(30, root_child1.getLayoutX(), 0.0f); - assertEquals(5, root_child1.getLayoutY(), 0.0f); - assertEquals(30, root_child1.getLayoutWidth(), 0.0f); - assertEquals(20, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(60, root_child2.getLayoutX(), 0.0f); - assertEquals(0, root_child2.getLayoutY(), 0.0f); - assertEquals(30, root_child2.getLayoutWidth(), 0.0f); - assertEquals(30, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child3.getLayoutX(), 0.0f); - assertEquals(30, root_child3.getLayoutY(), 0.0f); - assertEquals(30, root_child3.getLayoutWidth(), 0.0f); - assertEquals(30, root_child3.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(60, root.getLayoutHeight(), 0.0f); - - assertEquals(70, root_child0.getLayoutX(), 0.0f); - assertEquals(10, root_child0.getLayoutY(), 0.0f); - assertEquals(30, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(40, root_child1.getLayoutX(), 0.0f); - assertEquals(5, root_child1.getLayoutY(), 0.0f); - assertEquals(30, root_child1.getLayoutWidth(), 0.0f); - assertEquals(20, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(10, root_child2.getLayoutX(), 0.0f); - assertEquals(0, root_child2.getLayoutY(), 0.0f); - assertEquals(30, root_child2.getLayoutWidth(), 0.0f); - assertEquals(30, root_child2.getLayoutHeight(), 0.0f); - - assertEquals(70, root_child3.getLayoutX(), 0.0f); - assertEquals(30, root_child3.getLayoutY(), 0.0f); - assertEquals(30, root_child3.getLayoutWidth(), 0.0f); - assertEquals(30, root_child3.getLayoutHeight(), 0.0f); - } - -} diff --git a/java/tests/com/facebook/csslayout/CSSLayoutJustifyContentTest.java b/java/tests/com/facebook/csslayout/CSSLayoutJustifyContentTest.java deleted file mode 100644 index cef3690a..00000000 --- a/java/tests/com/facebook/csslayout/CSSLayoutJustifyContentTest.java +++ /dev/null @@ -1,734 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- * - */ - -package com.facebook.csslayout; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class CSSLayoutJustifyContentTest { - @Test - public void test_justify_content_row_flex_start() { - final CSSNode root = new CSSNode(); - root.setFlexDirection(CSSFlexDirection.ROW); - root.setStyleWidth(102); - root.setStyleHeight(102); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleWidth(10); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setStyleWidth(10); - root.addChildAt(root_child1, 1); - - final CSSNode root_child2 = new CSSNode(); - root_child2.setStyleWidth(10); - root.addChildAt(root_child2, 2); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(102, root.getLayoutWidth(), 0.0f); - assertEquals(102, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(102, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(10, root_child1.getLayoutX(), 0.0f); - assertEquals(0, root_child1.getLayoutY(), 0.0f); - assertEquals(10, root_child1.getLayoutWidth(), 0.0f); - assertEquals(102, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(20, root_child2.getLayoutX(), 0.0f); - assertEquals(0, root_child2.getLayoutY(), 0.0f); - assertEquals(10, root_child2.getLayoutWidth(), 0.0f); - assertEquals(102, root_child2.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(102, root.getLayoutWidth(), 0.0f); - assertEquals(102, root.getLayoutHeight(), 0.0f); - - assertEquals(92, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(102, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(82, root_child1.getLayoutX(), 0.0f); - assertEquals(0, root_child1.getLayoutY(), 0.0f); - assertEquals(10, root_child1.getLayoutWidth(), 0.0f); - assertEquals(102, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(72, root_child2.getLayoutX(), 0.0f); - assertEquals(0, root_child2.getLayoutY(), 0.0f); - assertEquals(10, root_child2.getLayoutWidth(), 0.0f); - assertEquals(102, root_child2.getLayoutHeight(), 0.0f); - } - - @Test - public void test_justify_content_row_flex_end() { - final CSSNode root = new CSSNode(); - root.setFlexDirection(CSSFlexDirection.ROW); - root.setJustifyContent(CSSJustify.FLEX_END); - root.setStyleWidth(102); - root.setStyleHeight(102); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleWidth(10); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setStyleWidth(10); - root.addChildAt(root_child1, 1); - - final CSSNode root_child2 = new CSSNode(); - root_child2.setStyleWidth(10); - root.addChildAt(root_child2, 2); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(102, root.getLayoutWidth(), 0.0f); - assertEquals(102, root.getLayoutHeight(), 0.0f); - - assertEquals(72, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(102, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(82, root_child1.getLayoutX(), 0.0f); - assertEquals(0, root_child1.getLayoutY(), 0.0f); - assertEquals(10, root_child1.getLayoutWidth(), 0.0f); - assertEquals(102, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(92, root_child2.getLayoutX(), 0.0f); - assertEquals(0, root_child2.getLayoutY(), 0.0f); - assertEquals(10, root_child2.getLayoutWidth(), 0.0f); - assertEquals(102, root_child2.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(102, root.getLayoutWidth(), 0.0f); - assertEquals(102, root.getLayoutHeight(), 0.0f); - - assertEquals(20, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(102, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(10, root_child1.getLayoutX(), 0.0f); - assertEquals(0, root_child1.getLayoutY(), 0.0f); - assertEquals(10, root_child1.getLayoutWidth(), 0.0f); - assertEquals(102, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(0, root_child2.getLayoutY(), 0.0f); - assertEquals(10, root_child2.getLayoutWidth(), 0.0f); - assertEquals(102, root_child2.getLayoutHeight(), 0.0f); - } - - @Test - public void test_justify_content_row_center() { - final CSSNode root = new CSSNode(); - root.setFlexDirection(CSSFlexDirection.ROW); - root.setJustifyContent(CSSJustify.CENTER); - root.setStyleWidth(102); - root.setStyleHeight(102); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleWidth(10); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setStyleWidth(10); - root.addChildAt(root_child1, 1); - - final CSSNode root_child2 = new CSSNode(); - root_child2.setStyleWidth(10); - root.addChildAt(root_child2, 2); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(102, root.getLayoutWidth(), 0.0f); - assertEquals(102, root.getLayoutHeight(), 0.0f); - - assertEquals(36, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(102, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(46, root_child1.getLayoutX(), 0.0f); - assertEquals(0, root_child1.getLayoutY(), 0.0f); - assertEquals(10, root_child1.getLayoutWidth(), 0.0f); - assertEquals(102, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(56, root_child2.getLayoutX(), 0.0f); - assertEquals(0, root_child2.getLayoutY(), 0.0f); - assertEquals(10, root_child2.getLayoutWidth(), 0.0f); - assertEquals(102, root_child2.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(102, root.getLayoutWidth(), 0.0f); - assertEquals(102, root.getLayoutHeight(), 0.0f); - - assertEquals(56, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(102, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(46, root_child1.getLayoutX(), 0.0f); - assertEquals(0, root_child1.getLayoutY(), 0.0f); - assertEquals(10, root_child1.getLayoutWidth(), 0.0f); - assertEquals(102, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(36, root_child2.getLayoutX(), 0.0f); - assertEquals(0, root_child2.getLayoutY(), 0.0f); - assertEquals(10, root_child2.getLayoutWidth(), 0.0f); - assertEquals(102, root_child2.getLayoutHeight(), 0.0f); - } - - @Test - public void test_justify_content_row_space_between() { - final CSSNode root = new CSSNode(); - root.setFlexDirection(CSSFlexDirection.ROW); - root.setJustifyContent(CSSJustify.SPACE_BETWEEN); - root.setStyleWidth(102); - root.setStyleHeight(102); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleWidth(10); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setStyleWidth(10); - root.addChildAt(root_child1, 1); - - final CSSNode root_child2 = new CSSNode(); - root_child2.setStyleWidth(10); - root.addChildAt(root_child2, 2); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(102, root.getLayoutWidth(), 0.0f); - assertEquals(102, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(102, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(46, root_child1.getLayoutX(), 0.0f); - assertEquals(0, root_child1.getLayoutY(), 0.0f); - assertEquals(10, root_child1.getLayoutWidth(), 0.0f); - assertEquals(102, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(92, root_child2.getLayoutX(), 0.0f); - assertEquals(0, root_child2.getLayoutY(), 0.0f); - assertEquals(10, root_child2.getLayoutWidth(), 0.0f); - assertEquals(102, root_child2.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(102, root.getLayoutWidth(), 0.0f); - assertEquals(102, root.getLayoutHeight(), 0.0f); - - assertEquals(92, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(102, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(46, root_child1.getLayoutX(), 0.0f); - assertEquals(0, root_child1.getLayoutY(), 0.0f); - assertEquals(10, root_child1.getLayoutWidth(), 0.0f); - assertEquals(102, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(0, root_child2.getLayoutY(), 0.0f); - assertEquals(10, root_child2.getLayoutWidth(), 0.0f); - assertEquals(102, root_child2.getLayoutHeight(), 0.0f); - } - - @Test - public void test_justify_content_row_space_around() { - final CSSNode root = new CSSNode(); - root.setFlexDirection(CSSFlexDirection.ROW); - root.setJustifyContent(CSSJustify.SPACE_AROUND); - root.setStyleWidth(102); - root.setStyleHeight(102); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleWidth(10); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setStyleWidth(10); - root.addChildAt(root_child1, 1); - - final CSSNode root_child2 = new CSSNode(); - root_child2.setStyleWidth(10); - root.addChildAt(root_child2, 2); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(102, root.getLayoutWidth(), 0.0f); - assertEquals(102, root.getLayoutHeight(), 0.0f); - - assertEquals(12, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(102, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(46, root_child1.getLayoutX(), 0.0f); - assertEquals(0, root_child1.getLayoutY(), 0.0f); - assertEquals(10, root_child1.getLayoutWidth(), 0.0f); - assertEquals(102, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(80, root_child2.getLayoutX(), 0.0f); - assertEquals(0, root_child2.getLayoutY(), 0.0f); - assertEquals(10, root_child2.getLayoutWidth(), 0.0f); - assertEquals(102, root_child2.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(102, root.getLayoutWidth(), 0.0f); - assertEquals(102, root.getLayoutHeight(), 0.0f); - - assertEquals(80, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(102, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(46, root_child1.getLayoutX(), 0.0f); - assertEquals(0, root_child1.getLayoutY(), 0.0f); - assertEquals(10, root_child1.getLayoutWidth(), 0.0f); - assertEquals(102, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(12, root_child2.getLayoutX(), 0.0f); - assertEquals(0, root_child2.getLayoutY(), 0.0f); - assertEquals(10, root_child2.getLayoutWidth(), 0.0f); - assertEquals(102, root_child2.getLayoutHeight(), 0.0f); - } - - @Test - public void test_justify_content_column_flex_start() { - final CSSNode root = new CSSNode(); - root.setStyleWidth(102); - root.setStyleHeight(102); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root.addChildAt(root_child1, 1); - - final CSSNode root_child2 = new CSSNode(); - root_child2.setStyleHeight(10); - root.addChildAt(root_child2, 2); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(102, root.getLayoutWidth(), 0.0f); - assertEquals(102, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(102, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(10, root_child1.getLayoutY(), 0.0f); - assertEquals(102, root_child1.getLayoutWidth(), 0.0f); - assertEquals(0, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(10, root_child2.getLayoutY(), 0.0f); - assertEquals(102, root_child2.getLayoutWidth(), 0.0f); - assertEquals(10, root_child2.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(102, root.getLayoutWidth(), 0.0f); - assertEquals(102, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(102, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(10, root_child1.getLayoutY(), 0.0f); - assertEquals(102, root_child1.getLayoutWidth(), 0.0f); - assertEquals(0, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(10, root_child2.getLayoutY(), 0.0f); - assertEquals(102, root_child2.getLayoutWidth(), 0.0f); - assertEquals(10, root_child2.getLayoutHeight(), 0.0f); - } - - @Test - public void test_justify_content_column_flex_end() { - final CSSNode root = new CSSNode(); - root.setJustifyContent(CSSJustify.FLEX_END); - root.setStyleWidth(102); - root.setStyleHeight(102); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setStyleHeight(10); - root.addChildAt(root_child1, 1); - - final CSSNode root_child2 = new CSSNode(); - root_child2.setStyleHeight(10); - root.addChildAt(root_child2, 2); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(102, root.getLayoutWidth(), 0.0f); - assertEquals(102, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(72, root_child0.getLayoutY(), 0.0f); - assertEquals(102, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(82, root_child1.getLayoutY(), 0.0f); - assertEquals(102, root_child1.getLayoutWidth(), 0.0f); - assertEquals(10, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(92, root_child2.getLayoutY(), 0.0f); - assertEquals(102, root_child2.getLayoutWidth(), 0.0f); - assertEquals(10, root_child2.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(102, root.getLayoutWidth(), 0.0f); - assertEquals(102, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(72, root_child0.getLayoutY(), 0.0f); - assertEquals(102, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(82, root_child1.getLayoutY(), 0.0f); - assertEquals(102, root_child1.getLayoutWidth(), 0.0f); - assertEquals(10, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(92, root_child2.getLayoutY(), 0.0f); - assertEquals(102, root_child2.getLayoutWidth(), 0.0f); - assertEquals(10, root_child2.getLayoutHeight(), 0.0f); - } - - @Test - public void test_justify_content_column_center() { - final CSSNode root = new CSSNode(); - root.setJustifyContent(CSSJustify.CENTER); - root.setStyleWidth(102); - root.setStyleHeight(102); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setStyleHeight(10); - root.addChildAt(root_child1, 1); - - final CSSNode root_child2 = new CSSNode(); - root_child2.setStyleHeight(10); - root.addChildAt(root_child2, 2); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(102, root.getLayoutWidth(), 0.0f); - assertEquals(102, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(36, root_child0.getLayoutY(), 0.0f); - assertEquals(102, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(46, root_child1.getLayoutY(), 0.0f); - assertEquals(102, root_child1.getLayoutWidth(), 0.0f); - assertEquals(10, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(56, root_child2.getLayoutY(), 0.0f); - assertEquals(102, root_child2.getLayoutWidth(), 0.0f); - assertEquals(10, root_child2.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(102, root.getLayoutWidth(), 0.0f); - assertEquals(102, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(36, root_child0.getLayoutY(), 0.0f); - assertEquals(102, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(46, root_child1.getLayoutY(), 0.0f); - assertEquals(102, root_child1.getLayoutWidth(), 0.0f); - assertEquals(10, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(56, root_child2.getLayoutY(), 0.0f); - assertEquals(102, root_child2.getLayoutWidth(), 0.0f); - assertEquals(10, root_child2.getLayoutHeight(), 0.0f); - } - - @Test - public void test_justify_content_column_space_between() { - final CSSNode root = new CSSNode(); - root.setJustifyContent(CSSJustify.SPACE_BETWEEN); - root.setStyleWidth(102); - root.setStyleHeight(102); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setStyleHeight(10); - root.addChildAt(root_child1, 1); - - final CSSNode root_child2 = new CSSNode(); - root_child2.setStyleHeight(10); - root.addChildAt(root_child2, 2); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(102, root.getLayoutWidth(), 0.0f); - assertEquals(102, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(102, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(46, root_child1.getLayoutY(), 0.0f); - assertEquals(102, root_child1.getLayoutWidth(), 0.0f); - assertEquals(10, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(92, root_child2.getLayoutY(), 0.0f); - assertEquals(102, root_child2.getLayoutWidth(), 0.0f); - assertEquals(10, root_child2.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(102, root.getLayoutWidth(), 0.0f); - assertEquals(102, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(102, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(46, root_child1.getLayoutY(), 0.0f); - assertEquals(102, root_child1.getLayoutWidth(), 0.0f); - assertEquals(10, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(92, root_child2.getLayoutY(), 0.0f); - assertEquals(102, root_child2.getLayoutWidth(), 0.0f); - assertEquals(10, root_child2.getLayoutHeight(), 0.0f); - } - - @Test - public void test_justify_content_column_space_around() { - final CSSNode root = new CSSNode(); - root.setJustifyContent(CSSJustify.SPACE_AROUND); - root.setStyleWidth(102); - root.setStyleHeight(102); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setStyleHeight(10); - root.addChildAt(root_child1, 1); - - final CSSNode root_child2 = new CSSNode(); - root_child2.setStyleHeight(10); - root.addChildAt(root_child2, 2); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(102, root.getLayoutWidth(), 0.0f); - assertEquals(102, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(12, root_child0.getLayoutY(), 0.0f); - assertEquals(102, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(46, root_child1.getLayoutY(), 0.0f); - assertEquals(102, root_child1.getLayoutWidth(), 0.0f); - assertEquals(10, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(80, root_child2.getLayoutY(), 0.0f); - assertEquals(102, root_child2.getLayoutWidth(), 0.0f); - assertEquals(10, root_child2.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(102, root.getLayoutWidth(), 0.0f); - assertEquals(102, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(12, root_child0.getLayoutY(), 0.0f); - assertEquals(102, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(46, root_child1.getLayoutY(), 0.0f); - assertEquals(102, root_child1.getLayoutWidth(), 0.0f); - assertEquals(10, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(80, root_child2.getLayoutY(), 0.0f); - assertEquals(102, root_child2.getLayoutWidth(), 0.0f); - assertEquals(10, root_child2.getLayoutHeight(), 0.0f); - } - -} diff --git a/java/tests/com/facebook/csslayout/CSSLayoutMarginTest.java b/java/tests/com/facebook/csslayout/CSSLayoutMarginTest.java deleted file mode 100644 index f85ce54d..00000000 --- a/java/tests/com/facebook/csslayout/CSSLayoutMarginTest.java +++ /dev/null @@ -1,467 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
-
- -
-
-
-
- * - */ - -package com.facebook.csslayout; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class CSSLayoutMarginTest { - @Test - public void test_margin_start() { - final CSSNode root = new CSSNode(); - root.setFlexDirection(CSSFlexDirection.ROW); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setMargin(Spacing.START, 10); - root_child0.setStyleWidth(10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(10, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(80, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100, root_child0.getLayoutHeight(), 0.0f); - } - - @Test - public void test_margin_top() { - final CSSNode root = new CSSNode(); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setMargin(Spacing.TOP, 10); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(10, root_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(10, root_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - } - - @Test - public void test_margin_end() { - final CSSNode root = new CSSNode(); - root.setFlexDirection(CSSFlexDirection.ROW); - root.setJustifyContent(CSSJustify.FLEX_END); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setMargin(Spacing.END, 10); - root_child0.setStyleWidth(10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(80, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(10, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100, root_child0.getLayoutHeight(), 0.0f); - } - - @Test - public void test_margin_bottom() { - final CSSNode root = new CSSNode(); - root.setJustifyContent(CSSJustify.FLEX_END); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setMargin(Spacing.BOTTOM, 10); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(80, root_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(80, root_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - } - - @Test - public void test_margin_and_flex_row() { - final CSSNode root = new CSSNode(); - root.setFlexDirection(CSSFlexDirection.ROW); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setFlexGrow(1); - root_child0.setMargin(Spacing.START, 10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(10, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(90, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(90, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100, root_child0.getLayoutHeight(), 0.0f); - } - - @Test - public void test_margin_and_flex_column() { - final CSSNode root = new CSSNode(); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setFlexGrow(1); - root_child0.setMargin(Spacing.TOP, 10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(10, root_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0.getLayoutWidth(), 0.0f); - assertEquals(90, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(10, root_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0.getLayoutWidth(), 0.0f); - assertEquals(90, root_child0.getLayoutHeight(), 0.0f); - } - - @Test - public void test_margin_and_stretch_row() { - final CSSNode root = new CSSNode(); - root.setFlexDirection(CSSFlexDirection.ROW); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setFlexGrow(1); - root_child0.setMargin(Spacing.TOP, 10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(10, root_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0.getLayoutWidth(), 0.0f); - assertEquals(90, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(10, root_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0.getLayoutWidth(), 0.0f); - assertEquals(90, root_child0.getLayoutHeight(), 0.0f); - } - - @Test - public void test_margin_and_stretch_column() { - final CSSNode root = new CSSNode(); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setFlexGrow(1); - root_child0.setMargin(Spacing.START, 10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(10, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(90, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(90, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100, root_child0.getLayoutHeight(), 0.0f); - } - - @Test - public void test_margin_with_sibling_row() { - final CSSNode root = new CSSNode(); - root.setFlexDirection(CSSFlexDirection.ROW); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setFlexGrow(1); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setFlexGrow(1); - root.addChildAt(root_child1, 1); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(50, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(50, root_child1.getLayoutX(), 0.0f); - assertEquals(0, root_child1.getLayoutY(), 0.0f); - assertEquals(50, root_child1.getLayoutWidth(), 0.0f); - assertEquals(100, root_child1.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(50, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(50, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(0, root_child1.getLayoutY(), 0.0f); - assertEquals(50, root_child1.getLayoutWidth(), 0.0f); - assertEquals(100, root_child1.getLayoutHeight(), 0.0f); - } - - @Test - public void test_margin_with_sibling_column() { - final CSSNode root = new CSSNode(); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setFlexGrow(1); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setFlexGrow(1); - root.addChildAt(root_child1, 1); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0.getLayoutWidth(), 0.0f); - assertEquals(50, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(50, root_child1.getLayoutY(), 0.0f); - assertEquals(100, root_child1.getLayoutWidth(), 0.0f); - assertEquals(50, root_child1.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0.getLayoutWidth(), 0.0f); - assertEquals(50, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(50, root_child1.getLayoutY(), 0.0f); - assertEquals(100, root_child1.getLayoutWidth(), 0.0f); - assertEquals(50, root_child1.getLayoutHeight(), 0.0f); - } - -} diff --git a/java/tests/com/facebook/csslayout/CSSLayoutMinMaxDimensionTest.java b/java/tests/com/facebook/csslayout/CSSLayoutMinMaxDimensionTest.java deleted file mode 100644 index 2607d23e..00000000 --- a/java/tests/com/facebook/csslayout/CSSLayoutMinMaxDimensionTest.java +++ /dev/null @@ -1,378 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
- -
-
-
- -
-
-
-
- -
-
-
-
- -
-
-
- -
-
-
- -
-
-
-
-
- * - */ - -package com.facebook.csslayout; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class CSSLayoutMinMaxDimensionTest { - @Test - public void test_max_width() { - final CSSNode root = new CSSNode(); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleMaxWidth(50); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(50, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(50, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(50, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - } - - @Test - public void test_max_height() { - final CSSNode root = new CSSNode(); - root.setFlexDirection(CSSFlexDirection.ROW); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleWidth(10); - root_child0.setStyleMaxHeight(50); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(50, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(90, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(50, root_child0.getLayoutHeight(), 0.0f); - } - - @Test - public void test_min_height() { - final CSSNode root = new CSSNode(); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setFlexGrow(1); - root_child0.setStyleMinHeight(60); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setFlexGrow(1); - root.addChildAt(root_child1, 1); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0.getLayoutWidth(), 0.0f); - assertEquals(80, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(80, root_child1.getLayoutY(), 0.0f); - assertEquals(100, root_child1.getLayoutWidth(), 0.0f); - assertEquals(20, root_child1.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(100, root_child0.getLayoutWidth(), 0.0f); - assertEquals(80, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(80, root_child1.getLayoutY(), 0.0f); - assertEquals(100, root_child1.getLayoutWidth(), 0.0f); - assertEquals(20, root_child1.getLayoutHeight(), 0.0f); - } - - @Test - public void test_min_width() { - final CSSNode root = new CSSNode(); - root.setFlexDirection(CSSFlexDirection.ROW); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setFlexGrow(1); - root_child0.setStyleMinWidth(60); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setFlexGrow(1); - root.addChildAt(root_child1, 1); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(80, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(80, root_child1.getLayoutX(), 0.0f); - assertEquals(0, root_child1.getLayoutY(), 0.0f); - assertEquals(20, root_child1.getLayoutWidth(), 0.0f); - assertEquals(100, root_child1.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(20, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(80, root_child0.getLayoutWidth(), 0.0f); - assertEquals(100, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(0, root_child1.getLayoutY(), 0.0f); - assertEquals(20, root_child1.getLayoutWidth(), 0.0f); - assertEquals(100, root_child1.getLayoutHeight(), 0.0f); - } - - @Test - public void test_justify_content_min_max() { - final CSSNode root = new CSSNode(); - root.setJustifyContent(CSSJustify.CENTER); - root.setStyleWidth(100); - root.setStyleMinHeight(100); - root.setStyleMaxHeight(200); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleWidth(60); - root_child0.setStyleHeight(60); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(20, root_child0.getLayoutY(), 0.0f); - assertEquals(60, root_child0.getLayoutWidth(), 0.0f); - assertEquals(60, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(40, root_child0.getLayoutX(), 0.0f); - assertEquals(20, root_child0.getLayoutY(), 0.0f); - assertEquals(60, root_child0.getLayoutWidth(), 0.0f); - assertEquals(60, root_child0.getLayoutHeight(), 0.0f); - } - - @Test - public void test_align_items_min_max() { - final CSSNode root = new CSSNode(); - root.setAlignItems(CSSAlign.CENTER); - root.setStyleMinWidth(100); - root.setStyleMaxWidth(200); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleWidth(60); - root_child0.setStyleHeight(60); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(20, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(60, root_child0.getLayoutWidth(), 0.0f); - assertEquals(60, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(20, root_child0.getLayoutX(), 0.0f); - assertEquals(0, root_child0.getLayoutY(), 0.0f); - assertEquals(60, root_child0.getLayoutWidth(), 0.0f); - assertEquals(60, root_child0.getLayoutHeight(), 0.0f); - } - - @Test - public void test_justify_content_overflow_min_max() { - final CSSNode root = new CSSNode(); - root.setJustifyContent(CSSJustify.CENTER); - root.setStyleMinHeight(100); - root.setStyleMaxHeight(110); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleWidth(50); - root_child0.setStyleHeight(50); - root.addChildAt(root_child0, 0); - - final CSSNode root_child1 = new CSSNode(); - root_child1.setStyleWidth(50); - root_child1.setStyleHeight(50); - root.addChildAt(root_child1, 1); - - final CSSNode root_child2 = new CSSNode(); - root_child2.setStyleWidth(50); - root_child2.setStyleHeight(50); - root.addChildAt(root_child2, 2); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(50, root.getLayoutWidth(), 0.0f); - assertEquals(110, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(-20, root_child0.getLayoutY(), 0.0f); - assertEquals(50, root_child0.getLayoutWidth(), 0.0f); - assertEquals(50, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(30, root_child1.getLayoutY(), 0.0f); - assertEquals(50, root_child1.getLayoutWidth(), 0.0f); - assertEquals(50, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(80, root_child2.getLayoutY(), 0.0f); - assertEquals(50, root_child2.getLayoutWidth(), 0.0f); - assertEquals(50, root_child2.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(50, root.getLayoutWidth(), 0.0f); - assertEquals(110, root.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child0.getLayoutX(), 0.0f); - assertEquals(-20, root_child0.getLayoutY(), 0.0f); - assertEquals(50, root_child0.getLayoutWidth(), 0.0f); - assertEquals(50, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child1.getLayoutX(), 0.0f); - assertEquals(30, root_child1.getLayoutY(), 0.0f); - assertEquals(50, root_child1.getLayoutWidth(), 0.0f); - assertEquals(50, root_child1.getLayoutHeight(), 0.0f); - - assertEquals(0, root_child2.getLayoutX(), 0.0f); - assertEquals(80, root_child2.getLayoutY(), 0.0f); - assertEquals(50, root_child2.getLayoutWidth(), 0.0f); - assertEquals(50, root_child2.getLayoutHeight(), 0.0f); - } - -} diff --git a/java/tests/com/facebook/csslayout/CSSLayoutPaddingTest.java b/java/tests/com/facebook/csslayout/CSSLayoutPaddingTest.java deleted file mode 100644 index e8bd8671..00000000 --- a/java/tests/com/facebook/csslayout/CSSLayoutPaddingTest.java +++ /dev/null @@ -1,227 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- * - */ - -package com.facebook.csslayout; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class CSSLayoutPaddingTest { - @Test - public void test_padding_no_size() { - final CSSNode root = new CSSNode(); - root.setPadding(Spacing.LEFT, 10); - root.setPadding(Spacing.TOP, 10); - root.setPadding(Spacing.RIGHT, 10); - root.setPadding(Spacing.BOTTOM, 10); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(20, root.getLayoutWidth(), 0.0f); - assertEquals(20, root.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(20, root.getLayoutWidth(), 0.0f); - assertEquals(20, root.getLayoutHeight(), 0.0f); - } - - @Test - public void test_padding_container_match_child() { - final CSSNode root = new CSSNode(); - root.setPadding(Spacing.LEFT, 10); - root.setPadding(Spacing.TOP, 10); - root.setPadding(Spacing.RIGHT, 10); - root.setPadding(Spacing.BOTTOM, 10); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleWidth(10); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(30, root.getLayoutWidth(), 0.0f); - assertEquals(30, root.getLayoutHeight(), 0.0f); - - assertEquals(10, root_child0.getLayoutX(), 0.0f); - assertEquals(10, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(30, root.getLayoutWidth(), 0.0f); - assertEquals(30, root.getLayoutHeight(), 0.0f); - - assertEquals(10, root_child0.getLayoutX(), 0.0f); - assertEquals(10, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - } - - @Test - public void test_padding_flex_child() { - final CSSNode root = new CSSNode(); - root.setPadding(Spacing.LEFT, 10); - root.setPadding(Spacing.TOP, 10); - root.setPadding(Spacing.RIGHT, 10); - root.setPadding(Spacing.BOTTOM, 10); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setFlexGrow(1); - root_child0.setStyleWidth(10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(10, root_child0.getLayoutX(), 0.0f); - assertEquals(10, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(80, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(80, root_child0.getLayoutX(), 0.0f); - assertEquals(10, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(80, root_child0.getLayoutHeight(), 0.0f); - } - - @Test - public void test_padding_stretch_child() { - final CSSNode root = new CSSNode(); - root.setPadding(Spacing.LEFT, 10); - root.setPadding(Spacing.TOP, 10); - root.setPadding(Spacing.RIGHT, 10); - root.setPadding(Spacing.BOTTOM, 10); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(10, root_child0.getLayoutX(), 0.0f); - assertEquals(10, root_child0.getLayoutY(), 0.0f); - assertEquals(80, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(10, root_child0.getLayoutX(), 0.0f); - assertEquals(10, root_child0.getLayoutY(), 0.0f); - assertEquals(80, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - } - - @Test - public void test_padding_center_child() { - final CSSNode root = new CSSNode(); - root.setJustifyContent(CSSJustify.CENTER); - root.setAlignItems(CSSAlign.CENTER); - root.setPadding(Spacing.START, 10); - root.setPadding(Spacing.END, 20); - root.setPadding(Spacing.BOTTOM, 20); - root.setStyleWidth(100); - root.setStyleHeight(100); - - final CSSNode root_child0 = new CSSNode(); - root_child0.setStyleWidth(10); - root_child0.setStyleHeight(10); - root.addChildAt(root_child0, 0); - root.setDirection(CSSDirection.LTR); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(40, root_child0.getLayoutX(), 0.0f); - assertEquals(35, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - - root.setDirection(CSSDirection.RTL); - root.calculateLayout(null); - - assertEquals(0, root.getLayoutX(), 0.0f); - assertEquals(0, root.getLayoutY(), 0.0f); - assertEquals(100, root.getLayoutWidth(), 0.0f); - assertEquals(100, root.getLayoutHeight(), 0.0f); - - assertEquals(50, root_child0.getLayoutX(), 0.0f); - assertEquals(35, root_child0.getLayoutY(), 0.0f); - assertEquals(10, root_child0.getLayoutWidth(), 0.0f); - assertEquals(10, root_child0.getLayoutHeight(), 0.0f); - } - -} diff --git a/java/tests/com/facebook/csslayout/CSSNodeTest.java b/java/tests/com/facebook/csslayout/CSSNodeTest.java deleted file mode 100644 index c61b8988..00000000 --- a/java/tests/com/facebook/csslayout/CSSNodeTest.java +++ /dev/null @@ -1,42 +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. - */ - -package com.facebook.csslayout; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class CSSNodeTest { - - @Test - public void testInit() { - final int refCount = CSSNode.jni_CSSNodeGetInstanceCount(); - final CSSNode node = new CSSNode(); - assertEquals(refCount + 1, CSSNode.jni_CSSNodeGetInstanceCount()); - } - - @Test - public void testMeasure() { - final CSSNode node = new CSSNode(); - node.setMeasureFunction(new CSSNodeAPI.MeasureFunction() { - public long measure( - CSSNodeAPI node, - float width, - CSSMeasureMode widthMode, - float height, - CSSMeasureMode heightMode) { - return MeasureOutput.make(100, 100); - } - }); - node.calculateLayout(null); - assertEquals(100, (int) node.getLayoutWidth()); - assertEquals(100, (int) node.getLayoutHeight()); - } -} diff --git a/java/tests/com/facebook/yoga/YGAbsolutePositionTest.java b/java/tests/com/facebook/yoga/YGAbsolutePositionTest.java new file mode 100644 index 00000000..bdfaf0e1 --- /dev/null +++ b/java/tests/com/facebook/yoga/YGAbsolutePositionTest.java @@ -0,0 +1,306 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGAbsolutePositionTest.html + +package com.facebook.yoga; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class YGAbsolutePositionTest { + @Test + public void test_absolute_layout_width_height_start_top() { + final YogaNode root = new YogaNode(); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setPositionType(YogaPositionType.ABSOLUTE); + root_child0.setPosition(YogaEdge.START, 10f); + root_child0.setPosition(YogaEdge.TOP, 10f); + root_child0.setWidth(10f); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0.getLayoutX(), 0.0f); + assertEquals(10f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(80f, root_child0.getLayoutX(), 0.0f); + assertEquals(10f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_absolute_layout_width_height_end_bottom() { + final YogaNode root = new YogaNode(); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setPositionType(YogaPositionType.ABSOLUTE); + root_child0.setPosition(YogaEdge.END, 10f); + root_child0.setPosition(YogaEdge.BOTTOM, 10f); + root_child0.setWidth(10f); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(80f, root_child0.getLayoutX(), 0.0f); + assertEquals(80f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0.getLayoutX(), 0.0f); + assertEquals(80f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_absolute_layout_start_top_end_bottom() { + final YogaNode root = new YogaNode(); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setPositionType(YogaPositionType.ABSOLUTE); + root_child0.setPosition(YogaEdge.START, 10f); + root_child0.setPosition(YogaEdge.TOP, 10f); + root_child0.setPosition(YogaEdge.END, 10f); + root_child0.setPosition(YogaEdge.BOTTOM, 10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0.getLayoutX(), 0.0f); + assertEquals(10f, root_child0.getLayoutY(), 0.0f); + assertEquals(80f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(80f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0.getLayoutX(), 0.0f); + assertEquals(10f, root_child0.getLayoutY(), 0.0f); + assertEquals(80f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(80f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_absolute_layout_width_height_start_top_end_bottom() { + final YogaNode root = new YogaNode(); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setPositionType(YogaPositionType.ABSOLUTE); + root_child0.setPosition(YogaEdge.START, 10f); + root_child0.setPosition(YogaEdge.TOP, 10f); + root_child0.setPosition(YogaEdge.END, 10f); + root_child0.setPosition(YogaEdge.BOTTOM, 10f); + root_child0.setWidth(10f); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0.getLayoutX(), 0.0f); + assertEquals(10f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(80f, root_child0.getLayoutX(), 0.0f); + assertEquals(10f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_do_not_clamp_height_of_absolute_node_to_height_of_its_overflow_hidden_parent() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setOverflow(YogaOverflow.HIDDEN); + root.setWidth(50f); + root.setHeight(50f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setPositionType(YogaPositionType.ABSOLUTE); + root_child0.setPosition(YogaEdge.START, 0f); + root_child0.setPosition(YogaEdge.TOP, 0f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child0_child0 = new YogaNode(); + root_child0_child0.setWidth(100f); + root_child0_child0.setHeight(100f); + root_child0.addChildAt(root_child0_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(50f, root.getLayoutWidth(), 0.0f); + assertEquals(50f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(50f, root.getLayoutWidth(), 0.0f); + assertEquals(50f, root.getLayoutHeight(), 0.0f); + + assertEquals(-50f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_absolute_layout_within_border() { + final YogaNode root = new YogaNode(); + root.setMargin(YogaEdge.LEFT, 10f); + root.setMargin(YogaEdge.TOP, 10f); + root.setMargin(YogaEdge.RIGHT, 10f); + root.setMargin(YogaEdge.BOTTOM, 10f); + root.setPadding(YogaEdge.LEFT, 10); + root.setPadding(YogaEdge.TOP, 10); + root.setPadding(YogaEdge.RIGHT, 10); + root.setPadding(YogaEdge.BOTTOM, 10); + root.setBorder(YogaEdge.LEFT, 10f); + root.setBorder(YogaEdge.TOP, 10f); + root.setBorder(YogaEdge.RIGHT, 10f); + root.setBorder(YogaEdge.BOTTOM, 10f); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setPositionType(YogaPositionType.ABSOLUTE); + root_child0.setPosition(YogaEdge.LEFT, 0f); + root_child0.setPosition(YogaEdge.TOP, 0f); + root_child0.setWidth(50f); + root_child0.setHeight(50f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setPositionType(YogaPositionType.ABSOLUTE); + root_child1.setPosition(YogaEdge.RIGHT, 0f); + root_child1.setPosition(YogaEdge.BOTTOM, 0f); + root_child1.setWidth(50f); + root_child1.setHeight(50f); + root.addChildAt(root_child1, 1); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(10f, root.getLayoutX(), 0.0f); + assertEquals(10f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0.getLayoutX(), 0.0f); + assertEquals(10f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(40f, root_child1.getLayoutX(), 0.0f); + assertEquals(40f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child1.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(10f, root.getLayoutX(), 0.0f); + assertEquals(10f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0.getLayoutX(), 0.0f); + assertEquals(10f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(40f, root_child1.getLayoutX(), 0.0f); + assertEquals(40f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child1.getLayoutHeight(), 0.0f); + } + +} diff --git a/java/tests/com/facebook/yoga/YGAlignContentTest.java b/java/tests/com/facebook/yoga/YGAlignContentTest.java new file mode 100644 index 00000000..c0f6afa5 --- /dev/null +++ b/java/tests/com/facebook/yoga/YGAlignContentTest.java @@ -0,0 +1,409 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGAlignContentTest.html + +package com.facebook.yoga; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class YGAlignContentTest { + @Test + public void test_align_content_flex_start() { + final YogaNode root = new YogaNode(); + root.setWrap(YogaWrap.WRAP); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(50f); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setWidth(50f); + root_child1.setHeight(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(50f); + root_child2.setHeight(10f); + root.addChildAt(root_child2, 2); + + final YogaNode root_child3 = new YogaNode(); + root_child3.setWidth(50f); + root_child3.setHeight(10f); + root.addChildAt(root_child3, 3); + + final YogaNode root_child4 = new YogaNode(); + root_child4.setWidth(50f); + root_child4.setHeight(10f); + root.addChildAt(root_child4, 4); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(10f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(20f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child3.getLayoutX(), 0.0f); + assertEquals(30f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child4.getLayoutX(), 0.0f); + assertEquals(40f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child4.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(10f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child2.getLayoutX(), 0.0f); + assertEquals(20f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child3.getLayoutX(), 0.0f); + assertEquals(30f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child4.getLayoutX(), 0.0f); + assertEquals(40f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child4.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_content_flex_end() { + final YogaNode root = new YogaNode(); + root.setAlignContent(YogaAlign.FLEX_END); + root.setWrap(YogaWrap.WRAP); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(50f); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setWidth(50f); + root_child1.setHeight(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(50f); + root_child2.setHeight(10f); + root.addChildAt(root_child2, 2); + + final YogaNode root_child3 = new YogaNode(); + root_child3.setWidth(50f); + root_child3.setHeight(10f); + root.addChildAt(root_child3, 3); + + final YogaNode root_child4 = new YogaNode(); + root_child4.setWidth(50f); + root_child4.setHeight(10f); + root.addChildAt(root_child4, 4); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(10f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(20f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child3.getLayoutX(), 0.0f); + assertEquals(30f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child4.getLayoutX(), 0.0f); + assertEquals(40f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child4.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(10f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child2.getLayoutX(), 0.0f); + assertEquals(20f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child3.getLayoutX(), 0.0f); + assertEquals(30f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child4.getLayoutX(), 0.0f); + assertEquals(40f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child4.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_content_center() { + final YogaNode root = new YogaNode(); + root.setAlignContent(YogaAlign.CENTER); + root.setWrap(YogaWrap.WRAP); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(50f); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setWidth(50f); + root_child1.setHeight(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(50f); + root_child2.setHeight(10f); + root.addChildAt(root_child2, 2); + + final YogaNode root_child3 = new YogaNode(); + root_child3.setWidth(50f); + root_child3.setHeight(10f); + root.addChildAt(root_child3, 3); + + final YogaNode root_child4 = new YogaNode(); + root_child4.setWidth(50f); + root_child4.setHeight(10f); + root.addChildAt(root_child4, 4); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(10f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(20f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child3.getLayoutX(), 0.0f); + assertEquals(30f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child4.getLayoutX(), 0.0f); + assertEquals(40f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child4.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(10f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child2.getLayoutX(), 0.0f); + assertEquals(20f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child3.getLayoutX(), 0.0f); + assertEquals(30f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child4.getLayoutX(), 0.0f); + assertEquals(40f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child4.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_content_stretch() { + final YogaNode root = new YogaNode(); + root.setAlignContent(YogaAlign.STRETCH); + root.setWrap(YogaWrap.WRAP); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(50f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setWidth(50f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(50f); + root.addChildAt(root_child2, 2); + + final YogaNode root_child3 = new YogaNode(); + root_child3.setWidth(50f); + root.addChildAt(root_child3, 3); + + final YogaNode root_child4 = new YogaNode(); + root_child4.setWidth(50f); + root.addChildAt(root_child4, 4); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child3.getLayoutX(), 0.0f); + assertEquals(0f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child4.getLayoutX(), 0.0f); + assertEquals(0f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child4.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child3.getLayoutX(), 0.0f); + assertEquals(0f, root_child3.getLayoutY(), 0.0f); + assertEquals(50f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child4.getLayoutX(), 0.0f); + assertEquals(0f, root_child4.getLayoutY(), 0.0f); + assertEquals(50f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child4.getLayoutHeight(), 0.0f); + } + +} diff --git a/java/tests/com/facebook/yoga/YGAlignItemsTest.java b/java/tests/com/facebook/yoga/YGAlignItemsTest.java new file mode 100644 index 00000000..c7fd7a2a --- /dev/null +++ b/java/tests/com/facebook/yoga/YGAlignItemsTest.java @@ -0,0 +1,169 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGAlignItemsTest.html + +package com.facebook.yoga; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class YGAlignItemsTest { + @Test + public void test_align_items_stretch() { + final YogaNode root = new YogaNode(); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_items_center() { + final YogaNode root = new YogaNode(); + root.setAlignItems(YogaAlign.CENTER); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(10f); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(45f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(45f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_items_flex_start() { + final YogaNode root = new YogaNode(); + root.setAlignItems(YogaAlign.FLEX_START); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(10f); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(90f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_items_flex_end() { + final YogaNode root = new YogaNode(); + root.setAlignItems(YogaAlign.FLEX_END); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(10f); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(90f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + } + +} diff --git a/java/tests/com/facebook/yoga/YGAlignSelfTest.java b/java/tests/com/facebook/yoga/YGAlignSelfTest.java new file mode 100644 index 00000000..f8dc750b --- /dev/null +++ b/java/tests/com/facebook/yoga/YGAlignSelfTest.java @@ -0,0 +1,172 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGAlignSelfTest.html + +package com.facebook.yoga; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class YGAlignSelfTest { + @Test + public void test_align_self_center() { + final YogaNode root = new YogaNode(); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setAlignSelf(YogaAlign.CENTER); + root_child0.setWidth(10f); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(45f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(45f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_self_flex_end() { + final YogaNode root = new YogaNode(); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setAlignSelf(YogaAlign.FLEX_END); + root_child0.setWidth(10f); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(90f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_self_flex_start() { + final YogaNode root = new YogaNode(); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setAlignSelf(YogaAlign.FLEX_START); + root_child0.setWidth(10f); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(90f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_self_flex_end_override_flex_start() { + final YogaNode root = new YogaNode(); + root.setAlignItems(YogaAlign.FLEX_START); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setAlignSelf(YogaAlign.FLEX_END); + root_child0.setWidth(10f); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(90f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + } + +} diff --git a/java/tests/com/facebook/yoga/YGBorderTest.java b/java/tests/com/facebook/yoga/YGBorderTest.java new file mode 100644 index 00000000..f264a878 --- /dev/null +++ b/java/tests/com/facebook/yoga/YGBorderTest.java @@ -0,0 +1,205 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGBorderTest.html + +package com.facebook.yoga; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class YGBorderTest { + @Test + public void test_border_no_size() { + final YogaNode root = new YogaNode(); + root.setBorder(YogaEdge.LEFT, 10f); + root.setBorder(YogaEdge.TOP, 10f); + root.setBorder(YogaEdge.RIGHT, 10f); + root.setBorder(YogaEdge.BOTTOM, 10f); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(20f, root.getLayoutWidth(), 0.0f); + assertEquals(20f, root.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(20f, root.getLayoutWidth(), 0.0f); + assertEquals(20f, root.getLayoutHeight(), 0.0f); + } + + @Test + public void test_border_container_match_child() { + final YogaNode root = new YogaNode(); + root.setBorder(YogaEdge.LEFT, 10f); + root.setBorder(YogaEdge.TOP, 10f); + root.setBorder(YogaEdge.RIGHT, 10f); + root.setBorder(YogaEdge.BOTTOM, 10f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(10f); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(30f, root.getLayoutWidth(), 0.0f); + assertEquals(30f, root.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0.getLayoutX(), 0.0f); + assertEquals(10f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(30f, root.getLayoutWidth(), 0.0f); + assertEquals(30f, root.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0.getLayoutX(), 0.0f); + assertEquals(10f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_border_flex_child() { + final YogaNode root = new YogaNode(); + root.setBorder(YogaEdge.LEFT, 10f); + root.setBorder(YogaEdge.TOP, 10f); + root.setBorder(YogaEdge.RIGHT, 10f); + root.setBorder(YogaEdge.BOTTOM, 10f); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setFlexGrow(1f); + root_child0.setWidth(10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0.getLayoutX(), 0.0f); + assertEquals(10f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(80f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(80f, root_child0.getLayoutX(), 0.0f); + assertEquals(10f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(80f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_border_stretch_child() { + final YogaNode root = new YogaNode(); + root.setBorder(YogaEdge.LEFT, 10f); + root.setBorder(YogaEdge.TOP, 10f); + root.setBorder(YogaEdge.RIGHT, 10f); + root.setBorder(YogaEdge.BOTTOM, 10f); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0.getLayoutX(), 0.0f); + assertEquals(10f, root_child0.getLayoutY(), 0.0f); + assertEquals(80f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0.getLayoutX(), 0.0f); + assertEquals(10f, root_child0.getLayoutY(), 0.0f); + assertEquals(80f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_border_center_child() { + final YogaNode root = new YogaNode(); + root.setJustifyContent(YogaJustify.CENTER); + root.setAlignItems(YogaAlign.CENTER); + root.setBorder(YogaEdge.START, 10f); + root.setBorder(YogaEdge.END, 20f); + root.setBorder(YogaEdge.BOTTOM, 20f); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(10f); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(40f, root_child0.getLayoutX(), 0.0f); + assertEquals(35f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child0.getLayoutX(), 0.0f); + assertEquals(35f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + } + +} diff --git a/java/tests/com/facebook/yoga/YGFlexDirectionTest.java b/java/tests/com/facebook/yoga/YGFlexDirectionTest.java new file mode 100644 index 00000000..4a731e17 --- /dev/null +++ b/java/tests/com/facebook/yoga/YGFlexDirectionTest.java @@ -0,0 +1,405 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGFlexDirectionTest.html + +package com.facebook.yoga; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class YGFlexDirectionTest { + @Test + public void test_flex_direction_column_no_height() { + final YogaNode root = new YogaNode(); + root.setWidth(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setHeight(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setHeight(10f); + root.addChildAt(root_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(30f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(10f, root_child1.getLayoutY(), 0.0f); + assertEquals(100f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(20f, root_child2.getLayoutY(), 0.0f); + assertEquals(100f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(30f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(10f, root_child1.getLayoutY(), 0.0f); + assertEquals(100f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(20f, root_child2.getLayoutY(), 0.0f); + assertEquals(100f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + } + + @Test + public void test_flex_direction_row_no_width() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(10f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setWidth(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(10f); + root.addChildAt(root_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(30f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(10f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(20f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(10f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(30f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(20f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(10f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(10f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child2.getLayoutHeight(), 0.0f); + } + + @Test + public void test_flex_direction_column() { + final YogaNode root = new YogaNode(); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setHeight(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setHeight(10f); + root.addChildAt(root_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(10f, root_child1.getLayoutY(), 0.0f); + assertEquals(100f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(20f, root_child2.getLayoutY(), 0.0f); + assertEquals(100f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(10f, root_child1.getLayoutY(), 0.0f); + assertEquals(100f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(20f, root_child2.getLayoutY(), 0.0f); + assertEquals(100f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + } + + @Test + public void test_flex_direction_row() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(10f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setWidth(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(10f); + root.addChildAt(root_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(10f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(20f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(10f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(90f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(80f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(10f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(70f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(10f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child2.getLayoutHeight(), 0.0f); + } + + @Test + public void test_flex_direction_column_reverse() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.COLUMN_REVERSE); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setHeight(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setHeight(10f); + root.addChildAt(root_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(90f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(80f, root_child1.getLayoutY(), 0.0f); + assertEquals(100f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(70f, root_child2.getLayoutY(), 0.0f); + assertEquals(100f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(90f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(80f, root_child1.getLayoutY(), 0.0f); + assertEquals(100f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(70f, root_child2.getLayoutY(), 0.0f); + assertEquals(100f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + } + + @Test + public void test_flex_direction_row_reverse() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW_REVERSE); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(10f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setWidth(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(10f); + root.addChildAt(root_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(90f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(80f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(10f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(70f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(10f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(10f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(20f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(10f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child2.getLayoutHeight(), 0.0f); + } + +} diff --git a/java/tests/com/facebook/yoga/YGFlexTest.java b/java/tests/com/facebook/yoga/YGFlexTest.java new file mode 100644 index 00000000..ca7befd2 --- /dev/null +++ b/java/tests/com/facebook/yoga/YGFlexTest.java @@ -0,0 +1,410 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGFlexTest.html + +package com.facebook.yoga; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class YGFlexTest { + @Test + public void test_flex_basis_flex_grow_column() { + final YogaNode root = new YogaNode(); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setFlexGrow(1f); + root_child0.setFlexBasis(50f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setFlexGrow(1f); + root.addChildAt(root_child1, 1); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(75f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(75f, root_child1.getLayoutY(), 0.0f); + assertEquals(100f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(25f, root_child1.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(75f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(75f, root_child1.getLayoutY(), 0.0f); + assertEquals(100f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(25f, root_child1.getLayoutHeight(), 0.0f); + } + + @Test + public void test_flex_basis_flex_grow_row() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setFlexGrow(1f); + root_child0.setFlexBasis(50f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setFlexGrow(1f); + root.addChildAt(root_child1, 1); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(75f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(75f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(25f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(25f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(75f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(25f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); + } + + @Test + public void test_flex_basis_flex_shrink_column() { + final YogaNode root = new YogaNode(); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setFlexShrink(1f); + root_child0.setFlexBasis(100f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setFlexBasis(50f); + root.addChildAt(root_child1, 1); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(50f, root_child1.getLayoutY(), 0.0f); + assertEquals(100f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child1.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(50f, root_child1.getLayoutY(), 0.0f); + assertEquals(100f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child1.getLayoutHeight(), 0.0f); + } + + @Test + public void test_flex_basis_flex_shrink_row() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setFlexShrink(1f); + root_child0.setFlexBasis(100f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setFlexBasis(50f); + root.addChildAt(root_child1, 1); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); + } + + @Test + public void test_flex_shrink_to_zero() { + final YogaNode root = new YogaNode(); + root.setHeight(75f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(50f); + root_child0.setHeight(50f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setFlexShrink(1f); + root_child1.setWidth(50f); + root_child1.setHeight(50f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(50f); + root_child2.setHeight(50f); + root.addChildAt(root_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(50f, root.getLayoutWidth(), 0.0f); + assertEquals(75f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(50f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(50f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(50f, root.getLayoutWidth(), 0.0f); + assertEquals(75f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(50f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(50f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child2.getLayoutHeight(), 0.0f); + } + + @Test + public void test_flex_basis_overrides_main_size() { + final YogaNode root = new YogaNode(); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setFlexGrow(1f); + root_child0.setFlexBasis(50f); + root_child0.setHeight(20f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setFlexGrow(1f); + root_child1.setHeight(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setFlexGrow(1f); + root_child2.setHeight(10f); + root.addChildAt(root_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(60f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(60f, root_child1.getLayoutY(), 0.0f); + assertEquals(100f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(80f, root_child2.getLayoutY(), 0.0f); + assertEquals(100f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(60f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(60f, root_child1.getLayoutY(), 0.0f); + assertEquals(100f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(80f, root_child2.getLayoutY(), 0.0f); + assertEquals(100f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child2.getLayoutHeight(), 0.0f); + } + + @Test + public void test_flex_grow_shrink_at_most() { + final YogaNode root = new YogaNode(); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root.addChildAt(root_child0, 0); + + final YogaNode root_child0_child0 = new YogaNode(); + root_child0_child0.setFlexGrow(1f); + root_child0_child0.setFlexShrink(1f); + root_child0.addChildAt(root_child0_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutHeight(), 0.0f); + } + +} diff --git a/java/tests/com/facebook/yoga/YGFlexWrapTest.java b/java/tests/com/facebook/yoga/YGFlexWrapTest.java new file mode 100644 index 00000000..f4772efe --- /dev/null +++ b/java/tests/com/facebook/yoga/YGFlexWrapTest.java @@ -0,0 +1,352 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGFlexWrapTest.html + +package com.facebook.yoga; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class YGFlexWrapTest { + @Test + public void test_wrap_column() { + final YogaNode root = new YogaNode(); + root.setWrap(YogaWrap.WRAP); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(30f); + root_child0.setHeight(30f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setWidth(30f); + root_child1.setHeight(30f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(30f); + root_child2.setHeight(30f); + root.addChildAt(root_child2, 2); + + final YogaNode root_child3 = new YogaNode(); + root_child3.setWidth(30f); + root_child3.setHeight(30f); + root.addChildAt(root_child3, 3); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(60f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(30f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(30f, root_child1.getLayoutY(), 0.0f); + assertEquals(30f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(60f, root_child2.getLayoutY(), 0.0f); + assertEquals(30f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(30f, root_child3.getLayoutX(), 0.0f); + assertEquals(0f, root_child3.getLayoutY(), 0.0f); + assertEquals(30f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child3.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(60f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(30f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(30f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(30f, root_child1.getLayoutX(), 0.0f); + assertEquals(30f, root_child1.getLayoutY(), 0.0f); + assertEquals(30f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(30f, root_child2.getLayoutX(), 0.0f); + assertEquals(60f, root_child2.getLayoutY(), 0.0f); + assertEquals(30f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child3.getLayoutX(), 0.0f); + assertEquals(0f, root_child3.getLayoutY(), 0.0f); + assertEquals(30f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child3.getLayoutHeight(), 0.0f); + } + + @Test + public void test_wrap_row() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setWrap(YogaWrap.WRAP); + root.setWidth(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(30f); + root_child0.setHeight(30f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setWidth(30f); + root_child1.setHeight(30f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(30f); + root_child2.setHeight(30f); + root.addChildAt(root_child2, 2); + + final YogaNode root_child3 = new YogaNode(); + root_child3.setWidth(30f); + root_child3.setHeight(30f); + root.addChildAt(root_child3, 3); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(60f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(30f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(30f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(30f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(60f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(30f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child3.getLayoutX(), 0.0f); + assertEquals(30f, root_child3.getLayoutY(), 0.0f); + assertEquals(30f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child3.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(60f, root.getLayoutHeight(), 0.0f); + + assertEquals(70f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(30f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(40f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(30f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(30f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(70f, root_child3.getLayoutX(), 0.0f); + assertEquals(30f, root_child3.getLayoutY(), 0.0f); + assertEquals(30f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child3.getLayoutHeight(), 0.0f); + } + + @Test + public void test_wrap_row_align_items_flex_end() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setAlignItems(YogaAlign.FLEX_END); + root.setWrap(YogaWrap.WRAP); + root.setWidth(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(30f); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setWidth(30f); + root_child1.setHeight(20f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(30f); + root_child2.setHeight(30f); + root.addChildAt(root_child2, 2); + + final YogaNode root_child3 = new YogaNode(); + root_child3.setWidth(30f); + root_child3.setHeight(30f); + root.addChildAt(root_child3, 3); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(60f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(20f, root_child0.getLayoutY(), 0.0f); + assertEquals(30f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(30f, root_child1.getLayoutX(), 0.0f); + assertEquals(10f, root_child1.getLayoutY(), 0.0f); + assertEquals(30f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(60f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(30f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child3.getLayoutX(), 0.0f); + assertEquals(30f, root_child3.getLayoutY(), 0.0f); + assertEquals(30f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child3.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(60f, root.getLayoutHeight(), 0.0f); + + assertEquals(70f, root_child0.getLayoutX(), 0.0f); + assertEquals(20f, root_child0.getLayoutY(), 0.0f); + assertEquals(30f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(40f, root_child1.getLayoutX(), 0.0f); + assertEquals(10f, root_child1.getLayoutY(), 0.0f); + assertEquals(30f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(30f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(70f, root_child3.getLayoutX(), 0.0f); + assertEquals(30f, root_child3.getLayoutY(), 0.0f); + assertEquals(30f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child3.getLayoutHeight(), 0.0f); + } + + @Test + public void test_wrap_row_align_items_center() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setAlignItems(YogaAlign.CENTER); + root.setWrap(YogaWrap.WRAP); + root.setWidth(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(30f); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setWidth(30f); + root_child1.setHeight(20f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(30f); + root_child2.setHeight(30f); + root.addChildAt(root_child2, 2); + + final YogaNode root_child3 = new YogaNode(); + root_child3.setWidth(30f); + root_child3.setHeight(30f); + root.addChildAt(root_child3, 3); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(60f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(10f, root_child0.getLayoutY(), 0.0f); + assertEquals(30f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(30f, root_child1.getLayoutX(), 0.0f); + assertEquals(5f, root_child1.getLayoutY(), 0.0f); + assertEquals(30f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(60f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(30f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child3.getLayoutX(), 0.0f); + assertEquals(30f, root_child3.getLayoutY(), 0.0f); + assertEquals(30f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child3.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(60f, root.getLayoutHeight(), 0.0f); + + assertEquals(70f, root_child0.getLayoutX(), 0.0f); + assertEquals(10f, root_child0.getLayoutY(), 0.0f); + assertEquals(30f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(40f, root_child1.getLayoutX(), 0.0f); + assertEquals(5f, root_child1.getLayoutY(), 0.0f); + assertEquals(30f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(30f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(70f, root_child3.getLayoutX(), 0.0f); + assertEquals(30f, root_child3.getLayoutY(), 0.0f); + assertEquals(30f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child3.getLayoutHeight(), 0.0f); + } + +} diff --git a/java/tests/com/facebook/yoga/YGJustifyContentTest.java b/java/tests/com/facebook/yoga/YGJustifyContentTest.java new file mode 100644 index 00000000..19df3a5c --- /dev/null +++ b/java/tests/com/facebook/yoga/YGJustifyContentTest.java @@ -0,0 +1,671 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGJustifyContentTest.html + +package com.facebook.yoga; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class YGJustifyContentTest { + @Test + public void test_justify_content_row_flex_start() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setWidth(102f); + root.setHeight(102f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(10f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setWidth(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(10f); + root.addChildAt(root_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(102f, root.getLayoutWidth(), 0.0f); + assertEquals(102f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(10f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(20f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(10f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(102f, root.getLayoutWidth(), 0.0f); + assertEquals(102f, root.getLayoutHeight(), 0.0f); + + assertEquals(92f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(82f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(10f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(72f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(10f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child2.getLayoutHeight(), 0.0f); + } + + @Test + public void test_justify_content_row_flex_end() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setJustifyContent(YogaJustify.FLEX_END); + root.setWidth(102f); + root.setHeight(102f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(10f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setWidth(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(10f); + root.addChildAt(root_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(102f, root.getLayoutWidth(), 0.0f); + assertEquals(102f, root.getLayoutHeight(), 0.0f); + + assertEquals(72f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(82f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(10f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(92f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(10f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(102f, root.getLayoutWidth(), 0.0f); + assertEquals(102f, root.getLayoutHeight(), 0.0f); + + assertEquals(20f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(10f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(10f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child2.getLayoutHeight(), 0.0f); + } + + @Test + public void test_justify_content_row_center() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setJustifyContent(YogaJustify.CENTER); + root.setWidth(102f); + root.setHeight(102f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(10f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setWidth(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(10f); + root.addChildAt(root_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(102f, root.getLayoutWidth(), 0.0f); + assertEquals(102f, root.getLayoutHeight(), 0.0f); + + assertEquals(36f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(46f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(10f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(56f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(10f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(102f, root.getLayoutWidth(), 0.0f); + assertEquals(102f, root.getLayoutHeight(), 0.0f); + + assertEquals(56f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(46f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(10f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(36f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(10f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child2.getLayoutHeight(), 0.0f); + } + + @Test + public void test_justify_content_row_space_between() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setJustifyContent(YogaJustify.SPACE_BETWEEN); + root.setWidth(102f); + root.setHeight(102f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(10f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setWidth(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(10f); + root.addChildAt(root_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(102f, root.getLayoutWidth(), 0.0f); + assertEquals(102f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(46f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(10f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(92f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(10f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(102f, root.getLayoutWidth(), 0.0f); + assertEquals(102f, root.getLayoutHeight(), 0.0f); + + assertEquals(92f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(46f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(10f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(10f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child2.getLayoutHeight(), 0.0f); + } + + @Test + public void test_justify_content_row_space_around() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setJustifyContent(YogaJustify.SPACE_AROUND); + root.setWidth(102f); + root.setHeight(102f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(10f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setWidth(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(10f); + root.addChildAt(root_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(102f, root.getLayoutWidth(), 0.0f); + assertEquals(102f, root.getLayoutHeight(), 0.0f); + + assertEquals(12f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(46f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(10f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(80f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(10f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(102f, root.getLayoutWidth(), 0.0f); + assertEquals(102f, root.getLayoutHeight(), 0.0f); + + assertEquals(80f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(46f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(10f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(12f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(10f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(102f, root_child2.getLayoutHeight(), 0.0f); + } + + @Test + public void test_justify_content_column_flex_start() { + final YogaNode root = new YogaNode(); + root.setWidth(102f); + root.setHeight(102f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setHeight(10f); + root.addChildAt(root_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(102f, root.getLayoutWidth(), 0.0f); + assertEquals(102f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(102f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(10f, root_child1.getLayoutY(), 0.0f); + assertEquals(102f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(10f, root_child2.getLayoutY(), 0.0f); + assertEquals(102f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(102f, root.getLayoutWidth(), 0.0f); + assertEquals(102f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(102f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(10f, root_child1.getLayoutY(), 0.0f); + assertEquals(102f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(10f, root_child2.getLayoutY(), 0.0f); + assertEquals(102f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + } + + @Test + public void test_justify_content_column_flex_end() { + final YogaNode root = new YogaNode(); + root.setJustifyContent(YogaJustify.FLEX_END); + root.setWidth(102f); + root.setHeight(102f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setHeight(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setHeight(10f); + root.addChildAt(root_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(102f, root.getLayoutWidth(), 0.0f); + assertEquals(102f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(72f, root_child0.getLayoutY(), 0.0f); + assertEquals(102f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(82f, root_child1.getLayoutY(), 0.0f); + assertEquals(102f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(92f, root_child2.getLayoutY(), 0.0f); + assertEquals(102f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(102f, root.getLayoutWidth(), 0.0f); + assertEquals(102f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(72f, root_child0.getLayoutY(), 0.0f); + assertEquals(102f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(82f, root_child1.getLayoutY(), 0.0f); + assertEquals(102f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(92f, root_child2.getLayoutY(), 0.0f); + assertEquals(102f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + } + + @Test + public void test_justify_content_column_center() { + final YogaNode root = new YogaNode(); + root.setJustifyContent(YogaJustify.CENTER); + root.setWidth(102f); + root.setHeight(102f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setHeight(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setHeight(10f); + root.addChildAt(root_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(102f, root.getLayoutWidth(), 0.0f); + assertEquals(102f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(36f, root_child0.getLayoutY(), 0.0f); + assertEquals(102f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(46f, root_child1.getLayoutY(), 0.0f); + assertEquals(102f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(56f, root_child2.getLayoutY(), 0.0f); + assertEquals(102f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(102f, root.getLayoutWidth(), 0.0f); + assertEquals(102f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(36f, root_child0.getLayoutY(), 0.0f); + assertEquals(102f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(46f, root_child1.getLayoutY(), 0.0f); + assertEquals(102f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(56f, root_child2.getLayoutY(), 0.0f); + assertEquals(102f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + } + + @Test + public void test_justify_content_column_space_between() { + final YogaNode root = new YogaNode(); + root.setJustifyContent(YogaJustify.SPACE_BETWEEN); + root.setWidth(102f); + root.setHeight(102f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setHeight(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setHeight(10f); + root.addChildAt(root_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(102f, root.getLayoutWidth(), 0.0f); + assertEquals(102f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(102f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(46f, root_child1.getLayoutY(), 0.0f); + assertEquals(102f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(92f, root_child2.getLayoutY(), 0.0f); + assertEquals(102f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(102f, root.getLayoutWidth(), 0.0f); + assertEquals(102f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(102f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(46f, root_child1.getLayoutY(), 0.0f); + assertEquals(102f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(92f, root_child2.getLayoutY(), 0.0f); + assertEquals(102f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + } + + @Test + public void test_justify_content_column_space_around() { + final YogaNode root = new YogaNode(); + root.setJustifyContent(YogaJustify.SPACE_AROUND); + root.setWidth(102f); + root.setHeight(102f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setHeight(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setHeight(10f); + root.addChildAt(root_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(102f, root.getLayoutWidth(), 0.0f); + assertEquals(102f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(12f, root_child0.getLayoutY(), 0.0f); + assertEquals(102f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(46f, root_child1.getLayoutY(), 0.0f); + assertEquals(102f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(80f, root_child2.getLayoutY(), 0.0f); + assertEquals(102f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(102f, root.getLayoutWidth(), 0.0f); + assertEquals(102f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(12f, root_child0.getLayoutY(), 0.0f); + assertEquals(102f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(46f, root_child1.getLayoutY(), 0.0f); + assertEquals(102f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(80f, root_child2.getLayoutY(), 0.0f); + assertEquals(102f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child2.getLayoutHeight(), 0.0f); + } + +} diff --git a/java/tests/com/facebook/yoga/YGMarginTest.java b/java/tests/com/facebook/yoga/YGMarginTest.java new file mode 100644 index 00000000..35859473 --- /dev/null +++ b/java/tests/com/facebook/yoga/YGMarginTest.java @@ -0,0 +1,422 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGMarginTest.html + +package com.facebook.yoga; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class YGMarginTest { + @Test + public void test_margin_start() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setMargin(YogaEdge.START, 10f); + root_child0.setWidth(10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(80f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_margin_top() { + final YogaNode root = new YogaNode(); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setMargin(YogaEdge.TOP, 10f); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(10f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(10f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_margin_end() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setJustifyContent(YogaJustify.FLEX_END); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setMargin(YogaEdge.END, 10f); + root_child0.setWidth(10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(80f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_margin_bottom() { + final YogaNode root = new YogaNode(); + root.setJustifyContent(YogaJustify.FLEX_END); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setMargin(YogaEdge.BOTTOM, 10f); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(80f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(80f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_margin_and_flex_row() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setFlexGrow(1f); + root_child0.setMargin(YogaEdge.START, 10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(90f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(90f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_margin_and_flex_column() { + final YogaNode root = new YogaNode(); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setFlexGrow(1f); + root_child0.setMargin(YogaEdge.TOP, 10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(10f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(90f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(10f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(90f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_margin_and_stretch_row() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setFlexGrow(1f); + root_child0.setMargin(YogaEdge.TOP, 10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(10f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(90f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(10f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(90f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_margin_and_stretch_column() { + final YogaNode root = new YogaNode(); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setFlexGrow(1f); + root_child0.setMargin(YogaEdge.START, 10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(90f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(90f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_margin_with_sibling_row() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setFlexGrow(1f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setFlexGrow(1f); + root.addChildAt(root_child1, 1); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); + } + + @Test + public void test_margin_with_sibling_column() { + final YogaNode root = new YogaNode(); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setFlexGrow(1f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setFlexGrow(1f); + root.addChildAt(root_child1, 1); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(50f, root_child1.getLayoutY(), 0.0f); + assertEquals(100f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child1.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(50f, root_child1.getLayoutY(), 0.0f); + assertEquals(100f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child1.getLayoutHeight(), 0.0f); + } + +} diff --git a/java/tests/com/facebook/yoga/YGMinMaxDimensionTest.java b/java/tests/com/facebook/yoga/YGMinMaxDimensionTest.java new file mode 100644 index 00000000..f37a5c54 --- /dev/null +++ b/java/tests/com/facebook/yoga/YGMinMaxDimensionTest.java @@ -0,0 +1,447 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGMinMaxDimensionTest.html + +package com.facebook.yoga; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class YGMinMaxDimensionTest { + @Test + public void test_max_width() { + final YogaNode root = new YogaNode(); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setMaxWidth(50f); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_max_height() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(10f); + root_child0.setMaxHeight(50f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(90f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_min_height() { + final YogaNode root = new YogaNode(); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setFlexGrow(1f); + root_child0.setMinHeight(60f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setFlexGrow(1f); + root.addChildAt(root_child1, 1); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(80f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(80f, root_child1.getLayoutY(), 0.0f); + assertEquals(100f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child1.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(80f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(80f, root_child1.getLayoutY(), 0.0f); + assertEquals(100f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child1.getLayoutHeight(), 0.0f); + } + + @Test + public void test_min_width() { + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setFlexGrow(1f); + root_child0.setMinWidth(60f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setFlexGrow(1f); + root.addChildAt(root_child1, 1); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(80f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(80f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(20f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(20f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(80f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(20f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); + } + + @Test + public void test_justify_content_min_max() { + final YogaNode root = new YogaNode(); + root.setJustifyContent(YogaJustify.CENTER); + root.setWidth(100f); + root.setMinHeight(100f); + root.setMaxHeight(200f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(60f); + root_child0.setHeight(60f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(20f, root_child0.getLayoutY(), 0.0f); + assertEquals(60f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(60f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(40f, root_child0.getLayoutX(), 0.0f); + assertEquals(20f, root_child0.getLayoutY(), 0.0f); + assertEquals(60f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(60f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_align_items_min_max() { + final YogaNode root = new YogaNode(); + root.setAlignItems(YogaAlign.CENTER); + root.setMinWidth(100f); + root.setMaxWidth(200f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(60f); + root_child0.setHeight(60f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(20f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(60f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(60f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(20f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(60f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(60f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_justify_content_overflow_min_max() { + final YogaNode root = new YogaNode(); + root.setJustifyContent(YogaJustify.CENTER); + root.setMinHeight(100f); + root.setMaxHeight(110f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(50f); + root_child0.setHeight(50f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setWidth(50f); + root_child1.setHeight(50f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setWidth(50f); + root_child2.setHeight(50f); + root.addChildAt(root_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(50f, root.getLayoutWidth(), 0.0f); + assertEquals(110f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(-20f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(30f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(80f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(50f, root.getLayoutWidth(), 0.0f); + assertEquals(110f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(-20f, root_child0.getLayoutY(), 0.0f); + assertEquals(50f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(30f, root_child1.getLayoutY(), 0.0f); + assertEquals(50f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(80f, root_child2.getLayoutY(), 0.0f); + assertEquals(50f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child2.getLayoutHeight(), 0.0f); + } + + @Test + public void test_flex_grow_within_max_width() { + final YogaNode root = new YogaNode(); + root.setWidth(200f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setFlexDirection(YogaFlexDirection.ROW); + root_child0.setMaxWidth(100f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child0_child0 = new YogaNode(); + root_child0_child0.setFlexGrow(1f); + root_child0_child0.setHeight(20f); + root_child0.addChildAt(root_child0_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(200f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(200f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_flex_grow_within_constrained_max_width() { + final YogaNode root = new YogaNode(); + root.setWidth(200f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setFlexDirection(YogaFlexDirection.ROW); + root_child0.setMaxWidth(300f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child0_child0 = new YogaNode(); + root_child0_child0.setFlexGrow(1f); + root_child0_child0.setHeight(20f); + root_child0.addChildAt(root_child0_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(200f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(200f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(200f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(200f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(200f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(200f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(20f, root_child0_child0.getLayoutHeight(), 0.0f); + } + +} diff --git a/java/tests/com/facebook/yoga/YGPaddingTest.java b/java/tests/com/facebook/yoga/YGPaddingTest.java new file mode 100644 index 00000000..22349186 --- /dev/null +++ b/java/tests/com/facebook/yoga/YGPaddingTest.java @@ -0,0 +1,248 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGPaddingTest.html + +package com.facebook.yoga; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class YGPaddingTest { + @Test + public void test_padding_no_size() { + final YogaNode root = new YogaNode(); + root.setPadding(YogaEdge.LEFT, 10); + root.setPadding(YogaEdge.TOP, 10); + root.setPadding(YogaEdge.RIGHT, 10); + root.setPadding(YogaEdge.BOTTOM, 10); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(20f, root.getLayoutWidth(), 0.0f); + assertEquals(20f, root.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(20f, root.getLayoutWidth(), 0.0f); + assertEquals(20f, root.getLayoutHeight(), 0.0f); + } + + @Test + public void test_padding_container_match_child() { + final YogaNode root = new YogaNode(); + root.setPadding(YogaEdge.LEFT, 10); + root.setPadding(YogaEdge.TOP, 10); + root.setPadding(YogaEdge.RIGHT, 10); + root.setPadding(YogaEdge.BOTTOM, 10); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(10f); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(30f, root.getLayoutWidth(), 0.0f); + assertEquals(30f, root.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0.getLayoutX(), 0.0f); + assertEquals(10f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(30f, root.getLayoutWidth(), 0.0f); + assertEquals(30f, root.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0.getLayoutX(), 0.0f); + assertEquals(10f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_padding_flex_child() { + final YogaNode root = new YogaNode(); + root.setPadding(YogaEdge.LEFT, 10); + root.setPadding(YogaEdge.TOP, 10); + root.setPadding(YogaEdge.RIGHT, 10); + root.setPadding(YogaEdge.BOTTOM, 10); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setFlexGrow(1f); + root_child0.setWidth(10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0.getLayoutX(), 0.0f); + assertEquals(10f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(80f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(80f, root_child0.getLayoutX(), 0.0f); + assertEquals(10f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(80f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_padding_stretch_child() { + final YogaNode root = new YogaNode(); + root.setPadding(YogaEdge.LEFT, 10); + root.setPadding(YogaEdge.TOP, 10); + root.setPadding(YogaEdge.RIGHT, 10); + root.setPadding(YogaEdge.BOTTOM, 10); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0.getLayoutX(), 0.0f); + assertEquals(10f, root_child0.getLayoutY(), 0.0f); + assertEquals(80f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(10f, root_child0.getLayoutX(), 0.0f); + assertEquals(10f, root_child0.getLayoutY(), 0.0f); + assertEquals(80f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_padding_center_child() { + final YogaNode root = new YogaNode(); + root.setJustifyContent(YogaJustify.CENTER); + root.setAlignItems(YogaAlign.CENTER); + root.setPadding(YogaEdge.START, 10); + root.setPadding(YogaEdge.END, 20); + root.setPadding(YogaEdge.BOTTOM, 20); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setWidth(10f); + root_child0.setHeight(10f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(40f, root_child0.getLayoutX(), 0.0f); + assertEquals(35f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child0.getLayoutX(), 0.0f); + assertEquals(35f, root_child0.getLayoutY(), 0.0f); + assertEquals(10f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(10f, root_child0.getLayoutHeight(), 0.0f); + } + + @Test + public void test_child_with_padding_align_end() { + final YogaNode root = new YogaNode(); + root.setJustifyContent(YogaJustify.FLEX_END); + root.setAlignItems(YogaAlign.FLEX_END); + root.setWidth(200f); + root.setHeight(200f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setPadding(YogaEdge.LEFT, 20); + root_child0.setPadding(YogaEdge.TOP, 20); + root_child0.setPadding(YogaEdge.RIGHT, 20); + root_child0.setPadding(YogaEdge.BOTTOM, 20); + root_child0.setWidth(100f); + root_child0.setHeight(100f); + root.addChildAt(root_child0, 0); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(200f, root.getLayoutWidth(), 0.0f); + assertEquals(200f, root.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child0.getLayoutX(), 0.0f); + assertEquals(100f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(200f, root.getLayoutWidth(), 0.0f); + assertEquals(200f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(100f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + } + +} diff --git a/java/tests/com/facebook/yoga/YGRoundingTest.java b/java/tests/com/facebook/yoga/YGRoundingTest.java new file mode 100644 index 00000000..33624b15 --- /dev/null +++ b/java/tests/com/facebook/yoga/YGRoundingTest.java @@ -0,0 +1,795 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGRoundingTest.html + +package com.facebook.yoga; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class YGRoundingTest { + @Test + public void test_rounding_flex_basis_flex_grow_row_width_of_100() { + YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true); + + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setFlexGrow(1f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setFlexGrow(1f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setFlexGrow(1f); + root.addChildAt(root_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(33f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(33f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(34f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(67f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(33f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(67f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(33f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(33f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(34f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(33f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child2.getLayoutHeight(), 0.0f); + + YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false); + } + + @Test + public void test_rounding_flex_basis_flex_grow_row_prime_number_width() { + YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true); + + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setWidth(113f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setFlexGrow(1f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setFlexGrow(1f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setFlexGrow(1f); + root.addChildAt(root_child2, 2); + + final YogaNode root_child3 = new YogaNode(); + root_child3.setFlexGrow(1f); + root.addChildAt(root_child3, 3); + + final YogaNode root_child4 = new YogaNode(); + root_child4.setFlexGrow(1f); + root.addChildAt(root_child4, 4); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(113f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(23f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(23f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(22f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(45f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(23f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(68f, root_child3.getLayoutX(), 0.0f); + assertEquals(0f, root_child3.getLayoutY(), 0.0f); + assertEquals(22f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(90f, root_child4.getLayoutX(), 0.0f); + assertEquals(0f, root_child4.getLayoutY(), 0.0f); + assertEquals(23f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child4.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(113f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(90f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(23f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(68f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(22f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(45f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(23f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child2.getLayoutHeight(), 0.0f); + + assertEquals(23f, root_child3.getLayoutX(), 0.0f); + assertEquals(0f, root_child3.getLayoutY(), 0.0f); + assertEquals(22f, root_child3.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child3.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child4.getLayoutX(), 0.0f); + assertEquals(0f, root_child4.getLayoutY(), 0.0f); + assertEquals(23f, root_child4.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child4.getLayoutHeight(), 0.0f); + + YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false); + } + + @Test + public void test_rounding_flex_basis_flex_shrink_row() { + YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true); + + final YogaNode root = new YogaNode(); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setWidth(101f); + root.setHeight(100f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setFlexShrink(1f); + root_child0.setFlexBasis(100f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setFlexBasis(25f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setFlexBasis(25f); + root.addChildAt(root_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(101f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(51f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(51f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(25f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(76f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(25f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(101f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(50f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(51f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(25f, root_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child1.getLayoutY(), 0.0f); + assertEquals(25f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(0f, root_child2.getLayoutY(), 0.0f); + assertEquals(25f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child2.getLayoutHeight(), 0.0f); + + YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false); + } + + @Test + public void test_rounding_flex_basis_overrides_main_size() { + YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true); + + final YogaNode root = new YogaNode(); + root.setWidth(100f); + root.setHeight(113f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setFlexGrow(1f); + root_child0.setFlexBasis(50f); + root_child0.setHeight(20f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setFlexGrow(1f); + root_child1.setHeight(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setFlexGrow(1f); + root_child2.setHeight(10f); + root.addChildAt(root_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(113f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(64f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(64f, root_child1.getLayoutY(), 0.0f); + assertEquals(100f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(25f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(89f, root_child2.getLayoutY(), 0.0f); + assertEquals(100f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(24f, root_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(113f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(64f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(64f, root_child1.getLayoutY(), 0.0f); + assertEquals(100f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(25f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(89f, root_child2.getLayoutY(), 0.0f); + assertEquals(100f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(24f, root_child2.getLayoutHeight(), 0.0f); + + YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false); + } + + @Test + public void test_rounding_total_fractial() { + YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true); + + final YogaNode root = new YogaNode(); + root.setWidth(87.4f); + root.setHeight(113.4f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setFlexGrow(0.7f); + root_child0.setFlexBasis(50.3f); + root_child0.setHeight(20.3f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setFlexGrow(1.6f); + root_child1.setHeight(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setFlexGrow(1.1f); + root_child2.setHeight(10.7f); + root.addChildAt(root_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(87f, root.getLayoutWidth(), 0.0f); + assertEquals(113f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(87f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(59f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(59f, root_child1.getLayoutY(), 0.0f); + assertEquals(87f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(89f, root_child2.getLayoutY(), 0.0f); + assertEquals(87f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(24f, root_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(87f, root.getLayoutWidth(), 0.0f); + assertEquals(113f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(87f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(59f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(59f, root_child1.getLayoutY(), 0.0f); + assertEquals(87f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(89f, root_child2.getLayoutY(), 0.0f); + assertEquals(87f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(24f, root_child2.getLayoutHeight(), 0.0f); + + YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false); + } + + @Test + public void test_rounding_total_fractial_nested() { + YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true); + + final YogaNode root = new YogaNode(); + root.setWidth(87.4f); + root.setHeight(113.4f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setFlexGrow(0.7f); + root_child0.setFlexBasis(50.3f); + root_child0.setHeight(20.3f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child0_child0 = new YogaNode(); + root_child0_child0.setFlexGrow(1f); + root_child0_child0.setFlexBasis(0.3f); + root_child0_child0.setPosition(YogaEdge.BOTTOM, 13.3f); + root_child0_child0.setHeight(9.9f); + root_child0.addChildAt(root_child0_child0, 0); + + final YogaNode root_child0_child1 = new YogaNode(); + root_child0_child1.setFlexGrow(4f); + root_child0_child1.setFlexBasis(0.3f); + root_child0_child1.setPosition(YogaEdge.TOP, 13.3f); + root_child0_child1.setHeight(1.1f); + root_child0.addChildAt(root_child0_child1, 1); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setFlexGrow(1.6f); + root_child1.setHeight(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setFlexGrow(1.1f); + root_child2.setHeight(10.7f); + root.addChildAt(root_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(87f, root.getLayoutWidth(), 0.0f); + assertEquals(113f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(87f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(59f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(-13f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(87f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(12f, root_child0_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child1.getLayoutX(), 0.0f); + assertEquals(25f, root_child0_child1.getLayoutY(), 0.0f); + assertEquals(87f, root_child0_child1.getLayoutWidth(), 0.0f); + assertEquals(47f, root_child0_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(59f, root_child1.getLayoutY(), 0.0f); + assertEquals(87f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(89f, root_child2.getLayoutY(), 0.0f); + assertEquals(87f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(24f, root_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(87f, root.getLayoutWidth(), 0.0f); + assertEquals(113f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(87f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(59f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(-13f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(87f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(12f, root_child0_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child1.getLayoutX(), 0.0f); + assertEquals(25f, root_child0_child1.getLayoutY(), 0.0f); + assertEquals(87f, root_child0_child1.getLayoutWidth(), 0.0f); + assertEquals(47f, root_child0_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(59f, root_child1.getLayoutY(), 0.0f); + assertEquals(87f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(30f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(89f, root_child2.getLayoutY(), 0.0f); + assertEquals(87f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(24f, root_child2.getLayoutHeight(), 0.0f); + + YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false); + } + + @Test + public void test_rounding_fractial_input_1() { + YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true); + + final YogaNode root = new YogaNode(); + root.setWidth(100f); + root.setHeight(113.4f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setFlexGrow(1f); + root_child0.setFlexBasis(50f); + root_child0.setHeight(20f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setFlexGrow(1f); + root_child1.setHeight(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setFlexGrow(1f); + root_child2.setHeight(10f); + root.addChildAt(root_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(113f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(64f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(64f, root_child1.getLayoutY(), 0.0f); + assertEquals(100f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(25f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(89f, root_child2.getLayoutY(), 0.0f); + assertEquals(100f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(24f, root_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(113f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(64f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(64f, root_child1.getLayoutY(), 0.0f); + assertEquals(100f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(25f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(89f, root_child2.getLayoutY(), 0.0f); + assertEquals(100f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(24f, root_child2.getLayoutHeight(), 0.0f); + + YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false); + } + + @Test + public void test_rounding_fractial_input_2() { + YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true); + + final YogaNode root = new YogaNode(); + root.setWidth(100f); + root.setHeight(113.6f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setFlexGrow(1f); + root_child0.setFlexBasis(50f); + root_child0.setHeight(20f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setFlexGrow(1f); + root_child1.setHeight(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setFlexGrow(1f); + root_child2.setHeight(10f); + root.addChildAt(root_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(114f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(65f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(65f, root_child1.getLayoutY(), 0.0f); + assertEquals(100f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(24f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(89f, root_child2.getLayoutY(), 0.0f); + assertEquals(100f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(25f, root_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(114f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(65f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(65f, root_child1.getLayoutY(), 0.0f); + assertEquals(100f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(24f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(89f, root_child2.getLayoutY(), 0.0f); + assertEquals(100f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(25f, root_child2.getLayoutHeight(), 0.0f); + + YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false); + } + + @Test + public void test_rounding_fractial_input_3() { + YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true); + + final YogaNode root = new YogaNode(); + root.setPosition(YogaEdge.TOP, 0.3f); + root.setWidth(100f); + root.setHeight(113.4f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setFlexGrow(1f); + root_child0.setFlexBasis(50f); + root_child0.setHeight(20f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setFlexGrow(1f); + root_child1.setHeight(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setFlexGrow(1f); + root_child2.setHeight(10f); + root.addChildAt(root_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(114f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(64f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(64f, root_child1.getLayoutY(), 0.0f); + assertEquals(100f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(25f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(89f, root_child2.getLayoutY(), 0.0f); + assertEquals(100f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(24f, root_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(114f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(64f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(64f, root_child1.getLayoutY(), 0.0f); + assertEquals(100f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(25f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(89f, root_child2.getLayoutY(), 0.0f); + assertEquals(100f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(24f, root_child2.getLayoutHeight(), 0.0f); + + YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false); + } + + @Test + public void test_rounding_fractial_input_4() { + YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true); + + final YogaNode root = new YogaNode(); + root.setPosition(YogaEdge.TOP, 0.7f); + root.setWidth(100f); + root.setHeight(113.4f); + + final YogaNode root_child0 = new YogaNode(); + root_child0.setFlexGrow(1f); + root_child0.setFlexBasis(50f); + root_child0.setHeight(20f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child1 = new YogaNode(); + root_child1.setFlexGrow(1f); + root_child1.setHeight(10f); + root.addChildAt(root_child1, 1); + + final YogaNode root_child2 = new YogaNode(); + root_child2.setFlexGrow(1f); + root_child2.setHeight(10f); + root.addChildAt(root_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(1f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(113f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(64f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(64f, root_child1.getLayoutY(), 0.0f); + assertEquals(100f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(25f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(89f, root_child2.getLayoutY(), 0.0f); + assertEquals(100f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(24f, root_child2.getLayoutHeight(), 0.0f); + + root.setDirection(YogaDirection.RTL); + root.calculateLayout(); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(1f, root.getLayoutY(), 0.0f); + assertEquals(100f, root.getLayoutWidth(), 0.0f); + assertEquals(113f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(64f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child1.getLayoutX(), 0.0f); + assertEquals(64f, root_child1.getLayoutY(), 0.0f); + assertEquals(100f, root_child1.getLayoutWidth(), 0.0f); + assertEquals(25f, root_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child2.getLayoutX(), 0.0f); + assertEquals(89f, root_child2.getLayoutY(), 0.0f); + assertEquals(100f, root_child2.getLayoutWidth(), 0.0f); + assertEquals(24f, root_child2.getLayoutHeight(), 0.0f); + + YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false); + } + +} diff --git a/java/tests/com/facebook/yoga/YogaNodeTest.java b/java/tests/com/facebook/yoga/YogaNodeTest.java new file mode 100644 index 00000000..d7c759ea --- /dev/null +++ b/java/tests/com/facebook/yoga/YogaNodeTest.java @@ -0,0 +1,87 @@ +/** + * 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. + */ + +package com.facebook.yoga; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class YogaNodeTest { + + @Test + public void testInit() { + final int refCount = YogaNode.jni_YGNodeGetInstanceCount(); + final YogaNode node = new YogaNode(); + assertEquals(refCount + 1, YogaNode.jni_YGNodeGetInstanceCount()); + } + + @Test + public void testMeasure() { + final YogaNode node = new YogaNode(); + node.setMeasureFunction(new YogaMeasureFunction() { + public long measure( + YogaNodeAPI node, + float width, + YogaMeasureMode widthMode, + float height, + YogaMeasureMode heightMode) { + return YogaMeasureOutput.make(100, 100); + } + }); + node.calculateLayout(); + assertEquals(100, (int) node.getLayoutWidth()); + assertEquals(100, (int) node.getLayoutHeight()); + } + + private YogaLogLevel mLogLevel; + private String mLogMessage; + + @Test + public void testLogger() { + YogaNode.setLogger(new YogaLogger() { + public void log(YogaLogLevel level, String message) { + mLogLevel = level; + mLogMessage = message; + } + }); + YogaNode.jni_YGLog(YogaLogLevel.DEBUG.intValue(), "Hello"); + assertEquals(YogaLogLevel.DEBUG, mLogLevel); + assertEquals("Hello", mLogMessage); + } + + @Test + public void testUpdateLogger() { + YogaNode.setLogger(new YogaLogger() { + public void log(YogaLogLevel level, String message) {} + }); + YogaNode.setLogger(new YogaLogger() { + public void log(YogaLogLevel level, String message) { + mLogLevel = level; + mLogMessage = message; + } + }); + YogaNode.jni_YGLog(YogaLogLevel.VERBOSE.intValue(), "Flexbox"); + assertEquals(YogaLogLevel.VERBOSE, mLogLevel); + assertEquals("Flexbox", mLogMessage); + } + + @Test + public void testCopyStyle() { + final YogaNode node0 = new YogaNode(); + assertTrue(YogaConstants.isUndefined(node0.getMaxHeight())); + + final YogaNode node1 = new YogaNode(); + node1.setMaxHeight(100); + + node0.copyStyle(node1); + assertEquals(100, (int) node0.getMaxHeight()); + } +} diff --git a/lib/fb/BUCK b/lib/fb/BUCK index 11779067..da59ceaa 100644 --- a/lib/fb/BUCK +++ b/lib/fb/BUCK @@ -5,7 +5,7 @@ # 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_defs('//CSSLAYOUT_DEFS') +include_defs('//YOGA_DEFS') prebuilt_cxx_library( name = 'ndklog', @@ -13,7 +13,7 @@ prebuilt_cxx_library( exported_platform_linker_flags = [ ('android.*', ['-llog']), ], - visibility = [CSSLAYOUT_ROOT], + visibility = [YOGA_ROOT], ) cxx_library( @@ -34,8 +34,9 @@ cxx_library( '-Wno-unused-parameter', '-std=c++11', ], - deps = JNI_DEPS + [ + deps = [ ':ndklog', + JNI_TARGET, ], visibility = ['PUBLIC'], ) diff --git a/lib/gtest/BUCK b/lib/gtest/BUCK index d1a01d56..a4c8a00e 100644 --- a/lib/gtest/BUCK +++ b/lib/gtest/BUCK @@ -5,23 +5,7 @@ # 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_defs('//CSSLAYOUT_DEFS') - -with allow_unsafe_import(): - import os - import urllib2 - import zipfile - -# Download gtest dep if it does not exists in path -current_dir = os.path.dirname(os.path.realpath(__file__)) -gtest_folder = 'googletest-release-1.7.0' -if GTEST_DL_URL != None and not os.path.isdir(current_dir + gtest_folder): - gtest = urllib2.urlopen('https://github.com/google/googletest/archive/release-1.7.0.zip').read() - with open("gtest.zip", 'w') as f: - f.write(gtest) - with zipfile.ZipFile('gtest.zip',"r") as zip: - zip.extractall(os.path.dirname(os.path.realpath(__file__))) - os.remove('gtest.zip') +include_defs('//YOGA_DEFS') COMPILER_FLAGS = [ '-std=c++11', @@ -30,14 +14,14 @@ COMPILER_FLAGS = [ cxx_library( name = 'gtest', - srcs = glob([gtest_folder + '/src/*.cc']), + srcs = glob(['googletest/googletest/src/*.cc']), exported_headers = subdir_glob([ - (gtest_folder + '/include', '**/*.h'), - (gtest_folder, 'src/*.h'), - (gtest_folder, 'src/*.cc'), + ('googletest/googletest/include', '**/*.h'), + ('googletest/googletest', 'src/*.h'), + ('googletest/googletest', 'src/*.cc'), ]), header_namespace = '', compiler_flags = COMPILER_FLAGS, deps = [], - visibility = [CSSLAYOUT_ROOT], + visibility = [YOGA_ROOT], ) diff --git a/lib/gtest/googletest b/lib/gtest/googletest new file mode 160000 index 00000000..a2b8a8e0 --- /dev/null +++ b/lib/gtest/googletest @@ -0,0 +1 @@ +Subproject commit a2b8a8e07628e5fd60644b6dd99c1b5e7d7f1f47 diff --git a/lib/infer-annotations/BUCK b/lib/infer-annotations/BUCK index 313f9e5c..378a65d7 100644 --- a/lib/infer-annotations/BUCK +++ b/lib/infer-annotations/BUCK @@ -5,7 +5,7 @@ # 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_defs('//CSSLAYOUT_DEFS') +include_defs('//YOGA_DEFS') prebuilt_jar( name = 'infer-annotations-jar', @@ -17,5 +17,5 @@ java_library( exported_deps = [ ':infer-annotations-jar', ], - visibility = [CSSLAYOUT_ROOT], + visibility = [YOGA_ROOT], ) diff --git a/lib/jni/BUCK b/lib/jni/BUCK new file mode 100644 index 00000000..5a8808ff --- /dev/null +++ b/lib/jni/BUCK @@ -0,0 +1,17 @@ +# 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. + +cxx_library( + name = 'jni', + force_static = True, + header_namespace = '', + exported_headers = [ + 'jni.h', + 'real/jni.h', + ], + visibility = ['PUBLIC'], +) diff --git a/java/com/facebook/csslayout/CSSPositionType.java b/lib/jni/jni.h similarity index 77% rename from java/com/facebook/csslayout/CSSPositionType.java rename to lib/jni/jni.h index 19e27dd4..d768a112 100644 --- a/java/com/facebook/csslayout/CSSPositionType.java +++ b/lib/jni/jni.h @@ -7,9 +7,10 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -package com.facebook.csslayout; +#pragma once -public enum CSSPositionType { - RELATIVE, - ABSOLUTE, -} +#ifdef __ANDROID__ +#include_next +#else +#include "real/jni.h" +#endif diff --git a/lib/jni/real/jni.h b/lib/jni/real/jni.h new file mode 100644 index 00000000..1c2fb0cd --- /dev/null +++ b/lib/jni/real/jni.h @@ -0,0 +1,1141 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * JNI specification, as defined by Sun: + * http://java.sun.com/javase/6/docs/technotes/guides/jni/spec/jniTOC.html + * + * Everything here is expected to be VM-neutral. + */ + +#ifndef JNI_H_ +#define JNI_H_ + +#include +#include + +/* Primitive types that match up with Java equivalents. */ +typedef uint8_t jboolean; /* unsigned 8 bits */ +typedef int8_t jbyte; /* signed 8 bits */ +typedef uint16_t jchar; /* unsigned 16 bits */ +typedef int16_t jshort; /* signed 16 bits */ +typedef int32_t jint; /* signed 32 bits */ +typedef int64_t jlong; /* signed 64 bits */ +typedef float jfloat; /* 32-bit IEEE 754 */ +typedef double jdouble; /* 64-bit IEEE 754 */ + +/* "cardinal indices and sizes" */ +typedef jint jsize; + +#ifdef __cplusplus +/* + * Reference types, in C++ + */ +class _jobject {}; +class _jclass : public _jobject {}; +class _jstring : public _jobject {}; +class _jarray : public _jobject {}; +class _jobjectArray : public _jarray {}; +class _jbooleanArray : public _jarray {}; +class _jbyteArray : public _jarray {}; +class _jcharArray : public _jarray {}; +class _jshortArray : public _jarray {}; +class _jintArray : public _jarray {}; +class _jlongArray : public _jarray {}; +class _jfloatArray : public _jarray {}; +class _jdoubleArray : public _jarray {}; +class _jthrowable : public _jobject {}; + +typedef _jobject* jobject; +typedef _jclass* jclass; +typedef _jstring* jstring; +typedef _jarray* jarray; +typedef _jobjectArray* jobjectArray; +typedef _jbooleanArray* jbooleanArray; +typedef _jbyteArray* jbyteArray; +typedef _jcharArray* jcharArray; +typedef _jshortArray* jshortArray; +typedef _jintArray* jintArray; +typedef _jlongArray* jlongArray; +typedef _jfloatArray* jfloatArray; +typedef _jdoubleArray* jdoubleArray; +typedef _jthrowable* jthrowable; +typedef _jobject* jweak; + + +#else /* not __cplusplus */ + +/* + * Reference types, in C. + */ +typedef void* jobject; +typedef jobject jclass; +typedef jobject jstring; +typedef jobject jarray; +typedef jarray jobjectArray; +typedef jarray jbooleanArray; +typedef jarray jbyteArray; +typedef jarray jcharArray; +typedef jarray jshortArray; +typedef jarray jintArray; +typedef jarray jlongArray; +typedef jarray jfloatArray; +typedef jarray jdoubleArray; +typedef jobject jthrowable; +typedef jobject jweak; + +#endif /* not __cplusplus */ + +struct _jfieldID; /* opaque structure */ +typedef struct _jfieldID* jfieldID; /* field IDs */ + +struct _jmethodID; /* opaque structure */ +typedef struct _jmethodID* jmethodID; /* method IDs */ + +struct JNIInvokeInterface; + +typedef union jvalue { + jboolean z; + jbyte b; + jchar c; + jshort s; + jint i; + jlong j; + jfloat f; + jdouble d; + jobject l; +} jvalue; + +typedef enum jobjectRefType { + JNIInvalidRefType = 0, + JNILocalRefType = 1, + JNIGlobalRefType = 2, + JNIWeakGlobalRefType = 3 +} jobjectRefType; + +typedef struct { + const char* name; + const char* signature; + void* fnPtr; +} JNINativeMethod; + +struct _JNIEnv; +struct _JavaVM; +typedef const struct JNINativeInterface* C_JNIEnv; + +#if defined(__cplusplus) +typedef _JNIEnv JNIEnv; +typedef _JavaVM JavaVM; +#else +typedef const struct JNINativeInterface* JNIEnv; +typedef const struct JNIInvokeInterface* JavaVM; +#endif + +/* + * Table of interface function pointers. + */ +struct JNINativeInterface { + void* reserved0; + void* reserved1; + void* reserved2; + void* reserved3; + + jint (*GetVersion)(JNIEnv *); + + jclass (*DefineClass)(JNIEnv*, const char*, jobject, const jbyte*, + jsize); + jclass (*FindClass)(JNIEnv*, const char*); + + jmethodID (*FromReflectedMethod)(JNIEnv*, jobject); + jfieldID (*FromReflectedField)(JNIEnv*, jobject); + /* spec doesn't show jboolean parameter */ + jobject (*ToReflectedMethod)(JNIEnv*, jclass, jmethodID, jboolean); + + jclass (*GetSuperclass)(JNIEnv*, jclass); + jboolean (*IsAssignableFrom)(JNIEnv*, jclass, jclass); + + /* spec doesn't show jboolean parameter */ + jobject (*ToReflectedField)(JNIEnv*, jclass, jfieldID, jboolean); + + jint (*Throw)(JNIEnv*, jthrowable); + jint (*ThrowNew)(JNIEnv *, jclass, const char *); + jthrowable (*ExceptionOccurred)(JNIEnv*); + void (*ExceptionDescribe)(JNIEnv*); + void (*ExceptionClear)(JNIEnv*); + void (*FatalError)(JNIEnv*, const char*); + + jint (*PushLocalFrame)(JNIEnv*, jint); + jobject (*PopLocalFrame)(JNIEnv*, jobject); + + jobject (*NewGlobalRef)(JNIEnv*, jobject); + void (*DeleteGlobalRef)(JNIEnv*, jobject); + void (*DeleteLocalRef)(JNIEnv*, jobject); + jboolean (*IsSameObject)(JNIEnv*, jobject, jobject); + + jobject (*NewLocalRef)(JNIEnv*, jobject); + jint (*EnsureLocalCapacity)(JNIEnv*, jint); + + jobject (*AllocObject)(JNIEnv*, jclass); + jobject (*NewObject)(JNIEnv*, jclass, jmethodID, ...); + jobject (*NewObjectV)(JNIEnv*, jclass, jmethodID, va_list); + jobject (*NewObjectA)(JNIEnv*, jclass, jmethodID, jvalue*); + + jclass (*GetObjectClass)(JNIEnv*, jobject); + jboolean (*IsInstanceOf)(JNIEnv*, jobject, jclass); + jmethodID (*GetMethodID)(JNIEnv*, jclass, const char*, const char*); + + jobject (*CallObjectMethod)(JNIEnv*, jobject, jmethodID, ...); + jobject (*CallObjectMethodV)(JNIEnv*, jobject, jmethodID, va_list); + jobject (*CallObjectMethodA)(JNIEnv*, jobject, jmethodID, jvalue*); + jboolean (*CallBooleanMethod)(JNIEnv*, jobject, jmethodID, ...); + jboolean (*CallBooleanMethodV)(JNIEnv*, jobject, jmethodID, va_list); + jboolean (*CallBooleanMethodA)(JNIEnv*, jobject, jmethodID, jvalue*); + jbyte (*CallByteMethod)(JNIEnv*, jobject, jmethodID, ...); + jbyte (*CallByteMethodV)(JNIEnv*, jobject, jmethodID, va_list); + jbyte (*CallByteMethodA)(JNIEnv*, jobject, jmethodID, jvalue*); + jchar (*CallCharMethod)(JNIEnv*, jobject, jmethodID, ...); + jchar (*CallCharMethodV)(JNIEnv*, jobject, jmethodID, va_list); + jchar (*CallCharMethodA)(JNIEnv*, jobject, jmethodID, jvalue*); + jshort (*CallShortMethod)(JNIEnv*, jobject, jmethodID, ...); + jshort (*CallShortMethodV)(JNIEnv*, jobject, jmethodID, va_list); + jshort (*CallShortMethodA)(JNIEnv*, jobject, jmethodID, jvalue*); + jint (*CallIntMethod)(JNIEnv*, jobject, jmethodID, ...); + jint (*CallIntMethodV)(JNIEnv*, jobject, jmethodID, va_list); + jint (*CallIntMethodA)(JNIEnv*, jobject, jmethodID, jvalue*); + jlong (*CallLongMethod)(JNIEnv*, jobject, jmethodID, ...); + jlong (*CallLongMethodV)(JNIEnv*, jobject, jmethodID, va_list); + jlong (*CallLongMethodA)(JNIEnv*, jobject, jmethodID, jvalue*); + jfloat (*CallFloatMethod)(JNIEnv*, jobject, jmethodID, ...); + jfloat (*CallFloatMethodV)(JNIEnv*, jobject, jmethodID, va_list); + jfloat (*CallFloatMethodA)(JNIEnv*, jobject, jmethodID, jvalue*); + jdouble (*CallDoubleMethod)(JNIEnv*, jobject, jmethodID, ...); + jdouble (*CallDoubleMethodV)(JNIEnv*, jobject, jmethodID, va_list); + jdouble (*CallDoubleMethodA)(JNIEnv*, jobject, jmethodID, jvalue*); + void (*CallVoidMethod)(JNIEnv*, jobject, jmethodID, ...); + void (*CallVoidMethodV)(JNIEnv*, jobject, jmethodID, va_list); + void (*CallVoidMethodA)(JNIEnv*, jobject, jmethodID, jvalue*); + + jobject (*CallNonvirtualObjectMethod)(JNIEnv*, jobject, jclass, + jmethodID, ...); + jobject (*CallNonvirtualObjectMethodV)(JNIEnv*, jobject, jclass, + jmethodID, va_list); + jobject (*CallNonvirtualObjectMethodA)(JNIEnv*, jobject, jclass, + jmethodID, jvalue*); + jboolean (*CallNonvirtualBooleanMethod)(JNIEnv*, jobject, jclass, + jmethodID, ...); + jboolean (*CallNonvirtualBooleanMethodV)(JNIEnv*, jobject, jclass, + jmethodID, va_list); + jboolean (*CallNonvirtualBooleanMethodA)(JNIEnv*, jobject, jclass, + jmethodID, jvalue*); + jbyte (*CallNonvirtualByteMethod)(JNIEnv*, jobject, jclass, + jmethodID, ...); + jbyte (*CallNonvirtualByteMethodV)(JNIEnv*, jobject, jclass, + jmethodID, va_list); + jbyte (*CallNonvirtualByteMethodA)(JNIEnv*, jobject, jclass, + jmethodID, jvalue*); + jchar (*CallNonvirtualCharMethod)(JNIEnv*, jobject, jclass, + jmethodID, ...); + jchar (*CallNonvirtualCharMethodV)(JNIEnv*, jobject, jclass, + jmethodID, va_list); + jchar (*CallNonvirtualCharMethodA)(JNIEnv*, jobject, jclass, + jmethodID, jvalue*); + jshort (*CallNonvirtualShortMethod)(JNIEnv*, jobject, jclass, + jmethodID, ...); + jshort (*CallNonvirtualShortMethodV)(JNIEnv*, jobject, jclass, + jmethodID, va_list); + jshort (*CallNonvirtualShortMethodA)(JNIEnv*, jobject, jclass, + jmethodID, jvalue*); + jint (*CallNonvirtualIntMethod)(JNIEnv*, jobject, jclass, + jmethodID, ...); + jint (*CallNonvirtualIntMethodV)(JNIEnv*, jobject, jclass, + jmethodID, va_list); + jint (*CallNonvirtualIntMethodA)(JNIEnv*, jobject, jclass, + jmethodID, jvalue*); + jlong (*CallNonvirtualLongMethod)(JNIEnv*, jobject, jclass, + jmethodID, ...); + jlong (*CallNonvirtualLongMethodV)(JNIEnv*, jobject, jclass, + jmethodID, va_list); + jlong (*CallNonvirtualLongMethodA)(JNIEnv*, jobject, jclass, + jmethodID, jvalue*); + jfloat (*CallNonvirtualFloatMethod)(JNIEnv*, jobject, jclass, + jmethodID, ...); + jfloat (*CallNonvirtualFloatMethodV)(JNIEnv*, jobject, jclass, + jmethodID, va_list); + jfloat (*CallNonvirtualFloatMethodA)(JNIEnv*, jobject, jclass, + jmethodID, jvalue*); + jdouble (*CallNonvirtualDoubleMethod)(JNIEnv*, jobject, jclass, + jmethodID, ...); + jdouble (*CallNonvirtualDoubleMethodV)(JNIEnv*, jobject, jclass, + jmethodID, va_list); + jdouble (*CallNonvirtualDoubleMethodA)(JNIEnv*, jobject, jclass, + jmethodID, jvalue*); + void (*CallNonvirtualVoidMethod)(JNIEnv*, jobject, jclass, + jmethodID, ...); + void (*CallNonvirtualVoidMethodV)(JNIEnv*, jobject, jclass, + jmethodID, va_list); + void (*CallNonvirtualVoidMethodA)(JNIEnv*, jobject, jclass, + jmethodID, jvalue*); + + jfieldID (*GetFieldID)(JNIEnv*, jclass, const char*, const char*); + + jobject (*GetObjectField)(JNIEnv*, jobject, jfieldID); + jboolean (*GetBooleanField)(JNIEnv*, jobject, jfieldID); + jbyte (*GetByteField)(JNIEnv*, jobject, jfieldID); + jchar (*GetCharField)(JNIEnv*, jobject, jfieldID); + jshort (*GetShortField)(JNIEnv*, jobject, jfieldID); + jint (*GetIntField)(JNIEnv*, jobject, jfieldID); + jlong (*GetLongField)(JNIEnv*, jobject, jfieldID); + jfloat (*GetFloatField)(JNIEnv*, jobject, jfieldID); + jdouble (*GetDoubleField)(JNIEnv*, jobject, jfieldID); + + void (*SetObjectField)(JNIEnv*, jobject, jfieldID, jobject); + void (*SetBooleanField)(JNIEnv*, jobject, jfieldID, jboolean); + void (*SetByteField)(JNIEnv*, jobject, jfieldID, jbyte); + void (*SetCharField)(JNIEnv*, jobject, jfieldID, jchar); + void (*SetShortField)(JNIEnv*, jobject, jfieldID, jshort); + void (*SetIntField)(JNIEnv*, jobject, jfieldID, jint); + void (*SetLongField)(JNIEnv*, jobject, jfieldID, jlong); + void (*SetFloatField)(JNIEnv*, jobject, jfieldID, jfloat); + void (*SetDoubleField)(JNIEnv*, jobject, jfieldID, jdouble); + + jmethodID (*GetStaticMethodID)(JNIEnv*, jclass, const char*, const char*); + + jobject (*CallStaticObjectMethod)(JNIEnv*, jclass, jmethodID, ...); + jobject (*CallStaticObjectMethodV)(JNIEnv*, jclass, jmethodID, va_list); + jobject (*CallStaticObjectMethodA)(JNIEnv*, jclass, jmethodID, jvalue*); + jboolean (*CallStaticBooleanMethod)(JNIEnv*, jclass, jmethodID, ...); + jboolean (*CallStaticBooleanMethodV)(JNIEnv*, jclass, jmethodID, + va_list); + jboolean (*CallStaticBooleanMethodA)(JNIEnv*, jclass, jmethodID, + jvalue*); + jbyte (*CallStaticByteMethod)(JNIEnv*, jclass, jmethodID, ...); + jbyte (*CallStaticByteMethodV)(JNIEnv*, jclass, jmethodID, va_list); + jbyte (*CallStaticByteMethodA)(JNIEnv*, jclass, jmethodID, jvalue*); + jchar (*CallStaticCharMethod)(JNIEnv*, jclass, jmethodID, ...); + jchar (*CallStaticCharMethodV)(JNIEnv*, jclass, jmethodID, va_list); + jchar (*CallStaticCharMethodA)(JNIEnv*, jclass, jmethodID, jvalue*); + jshort (*CallStaticShortMethod)(JNIEnv*, jclass, jmethodID, ...); + jshort (*CallStaticShortMethodV)(JNIEnv*, jclass, jmethodID, va_list); + jshort (*CallStaticShortMethodA)(JNIEnv*, jclass, jmethodID, jvalue*); + jint (*CallStaticIntMethod)(JNIEnv*, jclass, jmethodID, ...); + jint (*CallStaticIntMethodV)(JNIEnv*, jclass, jmethodID, va_list); + jint (*CallStaticIntMethodA)(JNIEnv*, jclass, jmethodID, jvalue*); + jlong (*CallStaticLongMethod)(JNIEnv*, jclass, jmethodID, ...); + jlong (*CallStaticLongMethodV)(JNIEnv*, jclass, jmethodID, va_list); + jlong (*CallStaticLongMethodA)(JNIEnv*, jclass, jmethodID, jvalue*); + jfloat (*CallStaticFloatMethod)(JNIEnv*, jclass, jmethodID, ...); + jfloat (*CallStaticFloatMethodV)(JNIEnv*, jclass, jmethodID, va_list); + jfloat (*CallStaticFloatMethodA)(JNIEnv*, jclass, jmethodID, jvalue*); + jdouble (*CallStaticDoubleMethod)(JNIEnv*, jclass, jmethodID, ...); + jdouble (*CallStaticDoubleMethodV)(JNIEnv*, jclass, jmethodID, va_list); + jdouble (*CallStaticDoubleMethodA)(JNIEnv*, jclass, jmethodID, jvalue*); + void (*CallStaticVoidMethod)(JNIEnv*, jclass, jmethodID, ...); + void (*CallStaticVoidMethodV)(JNIEnv*, jclass, jmethodID, va_list); + void (*CallStaticVoidMethodA)(JNIEnv*, jclass, jmethodID, jvalue*); + + jfieldID (*GetStaticFieldID)(JNIEnv*, jclass, const char*, + const char*); + + jobject (*GetStaticObjectField)(JNIEnv*, jclass, jfieldID); + jboolean (*GetStaticBooleanField)(JNIEnv*, jclass, jfieldID); + jbyte (*GetStaticByteField)(JNIEnv*, jclass, jfieldID); + jchar (*GetStaticCharField)(JNIEnv*, jclass, jfieldID); + jshort (*GetStaticShortField)(JNIEnv*, jclass, jfieldID); + jint (*GetStaticIntField)(JNIEnv*, jclass, jfieldID); + jlong (*GetStaticLongField)(JNIEnv*, jclass, jfieldID); + jfloat (*GetStaticFloatField)(JNIEnv*, jclass, jfieldID); + jdouble (*GetStaticDoubleField)(JNIEnv*, jclass, jfieldID); + + void (*SetStaticObjectField)(JNIEnv*, jclass, jfieldID, jobject); + void (*SetStaticBooleanField)(JNIEnv*, jclass, jfieldID, jboolean); + void (*SetStaticByteField)(JNIEnv*, jclass, jfieldID, jbyte); + void (*SetStaticCharField)(JNIEnv*, jclass, jfieldID, jchar); + void (*SetStaticShortField)(JNIEnv*, jclass, jfieldID, jshort); + void (*SetStaticIntField)(JNIEnv*, jclass, jfieldID, jint); + void (*SetStaticLongField)(JNIEnv*, jclass, jfieldID, jlong); + void (*SetStaticFloatField)(JNIEnv*, jclass, jfieldID, jfloat); + void (*SetStaticDoubleField)(JNIEnv*, jclass, jfieldID, jdouble); + + jstring (*NewString)(JNIEnv*, const jchar*, jsize); + jsize (*GetStringLength)(JNIEnv*, jstring); + const jchar* (*GetStringChars)(JNIEnv*, jstring, jboolean*); + void (*ReleaseStringChars)(JNIEnv*, jstring, const jchar*); + jstring (*NewStringUTF)(JNIEnv*, const char*); + jsize (*GetStringUTFLength)(JNIEnv*, jstring); + /* JNI spec says this returns const jbyte*, but that's inconsistent */ + const char* (*GetStringUTFChars)(JNIEnv*, jstring, jboolean*); + void (*ReleaseStringUTFChars)(JNIEnv*, jstring, const char*); + jsize (*GetArrayLength)(JNIEnv*, jarray); + jobjectArray (*NewObjectArray)(JNIEnv*, jsize, jclass, jobject); + jobject (*GetObjectArrayElement)(JNIEnv*, jobjectArray, jsize); + void (*SetObjectArrayElement)(JNIEnv*, jobjectArray, jsize, jobject); + + jbooleanArray (*NewBooleanArray)(JNIEnv*, jsize); + jbyteArray (*NewByteArray)(JNIEnv*, jsize); + jcharArray (*NewCharArray)(JNIEnv*, jsize); + jshortArray (*NewShortArray)(JNIEnv*, jsize); + jintArray (*NewIntArray)(JNIEnv*, jsize); + jlongArray (*NewLongArray)(JNIEnv*, jsize); + jfloatArray (*NewFloatArray)(JNIEnv*, jsize); + jdoubleArray (*NewDoubleArray)(JNIEnv*, jsize); + + jboolean* (*GetBooleanArrayElements)(JNIEnv*, jbooleanArray, jboolean*); + jbyte* (*GetByteArrayElements)(JNIEnv*, jbyteArray, jboolean*); + jchar* (*GetCharArrayElements)(JNIEnv*, jcharArray, jboolean*); + jshort* (*GetShortArrayElements)(JNIEnv*, jshortArray, jboolean*); + jint* (*GetIntArrayElements)(JNIEnv*, jintArray, jboolean*); + jlong* (*GetLongArrayElements)(JNIEnv*, jlongArray, jboolean*); + jfloat* (*GetFloatArrayElements)(JNIEnv*, jfloatArray, jboolean*); + jdouble* (*GetDoubleArrayElements)(JNIEnv*, jdoubleArray, jboolean*); + + void (*ReleaseBooleanArrayElements)(JNIEnv*, jbooleanArray, + jboolean*, jint); + void (*ReleaseByteArrayElements)(JNIEnv*, jbyteArray, + jbyte*, jint); + void (*ReleaseCharArrayElements)(JNIEnv*, jcharArray, + jchar*, jint); + void (*ReleaseShortArrayElements)(JNIEnv*, jshortArray, + jshort*, jint); + void (*ReleaseIntArrayElements)(JNIEnv*, jintArray, + jint*, jint); + void (*ReleaseLongArrayElements)(JNIEnv*, jlongArray, + jlong*, jint); + void (*ReleaseFloatArrayElements)(JNIEnv*, jfloatArray, + jfloat*, jint); + void (*ReleaseDoubleArrayElements)(JNIEnv*, jdoubleArray, + jdouble*, jint); + + void (*GetBooleanArrayRegion)(JNIEnv*, jbooleanArray, + jsize, jsize, jboolean*); + void (*GetByteArrayRegion)(JNIEnv*, jbyteArray, + jsize, jsize, jbyte*); + void (*GetCharArrayRegion)(JNIEnv*, jcharArray, + jsize, jsize, jchar*); + void (*GetShortArrayRegion)(JNIEnv*, jshortArray, + jsize, jsize, jshort*); + void (*GetIntArrayRegion)(JNIEnv*, jintArray, + jsize, jsize, jint*); + void (*GetLongArrayRegion)(JNIEnv*, jlongArray, + jsize, jsize, jlong*); + void (*GetFloatArrayRegion)(JNIEnv*, jfloatArray, + jsize, jsize, jfloat*); + void (*GetDoubleArrayRegion)(JNIEnv*, jdoubleArray, + jsize, jsize, jdouble*); + + /* spec shows these without const; some jni.h do, some don't */ + void (*SetBooleanArrayRegion)(JNIEnv*, jbooleanArray, + jsize, jsize, const jboolean*); + void (*SetByteArrayRegion)(JNIEnv*, jbyteArray, + jsize, jsize, const jbyte*); + void (*SetCharArrayRegion)(JNIEnv*, jcharArray, + jsize, jsize, const jchar*); + void (*SetShortArrayRegion)(JNIEnv*, jshortArray, + jsize, jsize, const jshort*); + void (*SetIntArrayRegion)(JNIEnv*, jintArray, + jsize, jsize, const jint*); + void (*SetLongArrayRegion)(JNIEnv*, jlongArray, + jsize, jsize, const jlong*); + void (*SetFloatArrayRegion)(JNIEnv*, jfloatArray, + jsize, jsize, const jfloat*); + void (*SetDoubleArrayRegion)(JNIEnv*, jdoubleArray, + jsize, jsize, const jdouble*); + + jint (*RegisterNatives)(JNIEnv*, jclass, const JNINativeMethod*, + jint); + jint (*UnregisterNatives)(JNIEnv*, jclass); + jint (*MonitorEnter)(JNIEnv*, jobject); + jint (*MonitorExit)(JNIEnv*, jobject); + jint (*GetJavaVM)(JNIEnv*, JavaVM**); + + void (*GetStringRegion)(JNIEnv*, jstring, jsize, jsize, jchar*); + void (*GetStringUTFRegion)(JNIEnv*, jstring, jsize, jsize, char*); + + void* (*GetPrimitiveArrayCritical)(JNIEnv*, jarray, jboolean*); + void (*ReleasePrimitiveArrayCritical)(JNIEnv*, jarray, void*, jint); + + const jchar* (*GetStringCritical)(JNIEnv*, jstring, jboolean*); + void (*ReleaseStringCritical)(JNIEnv*, jstring, const jchar*); + + jweak (*NewWeakGlobalRef)(JNIEnv*, jobject); + void (*DeleteWeakGlobalRef)(JNIEnv*, jweak); + + jboolean (*ExceptionCheck)(JNIEnv*); + + jobject (*NewDirectByteBuffer)(JNIEnv*, void*, jlong); + void* (*GetDirectBufferAddress)(JNIEnv*, jobject); + jlong (*GetDirectBufferCapacity)(JNIEnv*, jobject); + + /* added in JNI 1.6 */ + jobjectRefType (*GetObjectRefType)(JNIEnv*, jobject); +}; + +/* + * C++ object wrapper. + * + * This is usually overlaid on a C struct whose first element is a + * JNINativeInterface*. We rely somewhat on compiler behavior. + */ +struct _JNIEnv { + /* do not rename this; it does not seem to be entirely opaque */ + const struct JNINativeInterface* functions; + +#if defined(__cplusplus) + + jint GetVersion() + { return functions->GetVersion(this); } + + jclass DefineClass(const char *name, jobject loader, const jbyte* buf, + jsize bufLen) + { return functions->DefineClass(this, name, loader, buf, bufLen); } + + jclass FindClass(const char* name) + { return functions->FindClass(this, name); } + + jmethodID FromReflectedMethod(jobject method) + { return functions->FromReflectedMethod(this, method); } + + jfieldID FromReflectedField(jobject field) + { return functions->FromReflectedField(this, field); } + + jobject ToReflectedMethod(jclass cls, jmethodID methodID, jboolean isStatic) + { return functions->ToReflectedMethod(this, cls, methodID, isStatic); } + + jclass GetSuperclass(jclass clazz) + { return functions->GetSuperclass(this, clazz); } + + jboolean IsAssignableFrom(jclass clazz1, jclass clazz2) + { return functions->IsAssignableFrom(this, clazz1, clazz2); } + + jobject ToReflectedField(jclass cls, jfieldID fieldID, jboolean isStatic) + { return functions->ToReflectedField(this, cls, fieldID, isStatic); } + + jint Throw(jthrowable obj) + { return functions->Throw(this, obj); } + + jint ThrowNew(jclass clazz, const char* message) + { return functions->ThrowNew(this, clazz, message); } + + jthrowable ExceptionOccurred() + { return functions->ExceptionOccurred(this); } + + void ExceptionDescribe() + { functions->ExceptionDescribe(this); } + + void ExceptionClear() + { functions->ExceptionClear(this); } + + void FatalError(const char* msg) + { functions->FatalError(this, msg); } + + jint PushLocalFrame(jint capacity) + { return functions->PushLocalFrame(this, capacity); } + + jobject PopLocalFrame(jobject result) + { return functions->PopLocalFrame(this, result); } + + jobject NewGlobalRef(jobject obj) + { return functions->NewGlobalRef(this, obj); } + + void DeleteGlobalRef(jobject globalRef) + { functions->DeleteGlobalRef(this, globalRef); } + + void DeleteLocalRef(jobject localRef) + { functions->DeleteLocalRef(this, localRef); } + + jboolean IsSameObject(jobject ref1, jobject ref2) + { return functions->IsSameObject(this, ref1, ref2); } + + jobject NewLocalRef(jobject ref) + { return functions->NewLocalRef(this, ref); } + + jint EnsureLocalCapacity(jint capacity) + { return functions->EnsureLocalCapacity(this, capacity); } + + jobject AllocObject(jclass clazz) + { return functions->AllocObject(this, clazz); } + + jobject NewObject(jclass clazz, jmethodID methodID, ...) + { + va_list args; + va_start(args, methodID); + jobject result = functions->NewObjectV(this, clazz, methodID, args); + va_end(args); + return result; + } + + jobject NewObjectV(jclass clazz, jmethodID methodID, va_list args) + { return functions->NewObjectV(this, clazz, methodID, args); } + + jobject NewObjectA(jclass clazz, jmethodID methodID, jvalue* args) + { return functions->NewObjectA(this, clazz, methodID, args); } + + jclass GetObjectClass(jobject obj) + { return functions->GetObjectClass(this, obj); } + + jboolean IsInstanceOf(jobject obj, jclass clazz) + { return functions->IsInstanceOf(this, obj, clazz); } + + jmethodID GetMethodID(jclass clazz, const char* name, const char* sig) + { return functions->GetMethodID(this, clazz, name, sig); } + +#define CALL_TYPE_METHOD(_jtype, _jname) \ + _jtype Call##_jname##Method(jobject obj, jmethodID methodID, ...) \ + { \ + _jtype result; \ + va_list args; \ + va_start(args, methodID); \ + result = functions->Call##_jname##MethodV(this, obj, methodID, \ + args); \ + va_end(args); \ + return result; \ + } +#define CALL_TYPE_METHODV(_jtype, _jname) \ + _jtype Call##_jname##MethodV(jobject obj, jmethodID methodID, \ + va_list args) \ + { return functions->Call##_jname##MethodV(this, obj, methodID, args); } +#define CALL_TYPE_METHODA(_jtype, _jname) \ + _jtype Call##_jname##MethodA(jobject obj, jmethodID methodID, \ + jvalue* args) \ + { return functions->Call##_jname##MethodA(this, obj, methodID, args); } + +#define CALL_TYPE(_jtype, _jname) \ + CALL_TYPE_METHOD(_jtype, _jname) \ + CALL_TYPE_METHODV(_jtype, _jname) \ + CALL_TYPE_METHODA(_jtype, _jname) + + CALL_TYPE(jobject, Object) + CALL_TYPE(jboolean, Boolean) + CALL_TYPE(jbyte, Byte) + CALL_TYPE(jchar, Char) + CALL_TYPE(jshort, Short) + CALL_TYPE(jint, Int) + CALL_TYPE(jlong, Long) + CALL_TYPE(jfloat, Float) + CALL_TYPE(jdouble, Double) + + void CallVoidMethod(jobject obj, jmethodID methodID, ...) + { + va_list args; + va_start(args, methodID); + functions->CallVoidMethodV(this, obj, methodID, args); + va_end(args); + } + void CallVoidMethodV(jobject obj, jmethodID methodID, va_list args) + { functions->CallVoidMethodV(this, obj, methodID, args); } + void CallVoidMethodA(jobject obj, jmethodID methodID, jvalue* args) + { functions->CallVoidMethodA(this, obj, methodID, args); } + +#define CALL_NONVIRT_TYPE_METHOD(_jtype, _jname) \ + _jtype CallNonvirtual##_jname##Method(jobject obj, jclass clazz, \ + jmethodID methodID, ...) \ + { \ + _jtype result; \ + va_list args; \ + va_start(args, methodID); \ + result = functions->CallNonvirtual##_jname##MethodV(this, obj, \ + clazz, methodID, args); \ + va_end(args); \ + return result; \ + } +#define CALL_NONVIRT_TYPE_METHODV(_jtype, _jname) \ + _jtype CallNonvirtual##_jname##MethodV(jobject obj, jclass clazz, \ + jmethodID methodID, va_list args) \ + { return functions->CallNonvirtual##_jname##MethodV(this, obj, clazz, \ + methodID, args); } +#define CALL_NONVIRT_TYPE_METHODA(_jtype, _jname) \ + _jtype CallNonvirtual##_jname##MethodA(jobject obj, jclass clazz, \ + jmethodID methodID, jvalue* args) \ + { return functions->CallNonvirtual##_jname##MethodA(this, obj, clazz, \ + methodID, args); } + +#define CALL_NONVIRT_TYPE(_jtype, _jname) \ + CALL_NONVIRT_TYPE_METHOD(_jtype, _jname) \ + CALL_NONVIRT_TYPE_METHODV(_jtype, _jname) \ + CALL_NONVIRT_TYPE_METHODA(_jtype, _jname) + + CALL_NONVIRT_TYPE(jobject, Object) + CALL_NONVIRT_TYPE(jboolean, Boolean) + CALL_NONVIRT_TYPE(jbyte, Byte) + CALL_NONVIRT_TYPE(jchar, Char) + CALL_NONVIRT_TYPE(jshort, Short) + CALL_NONVIRT_TYPE(jint, Int) + CALL_NONVIRT_TYPE(jlong, Long) + CALL_NONVIRT_TYPE(jfloat, Float) + CALL_NONVIRT_TYPE(jdouble, Double) + + void CallNonvirtualVoidMethod(jobject obj, jclass clazz, + jmethodID methodID, ...) + { + va_list args; + va_start(args, methodID); + functions->CallNonvirtualVoidMethodV(this, obj, clazz, methodID, args); + va_end(args); + } + void CallNonvirtualVoidMethodV(jobject obj, jclass clazz, + jmethodID methodID, va_list args) + { functions->CallNonvirtualVoidMethodV(this, obj, clazz, methodID, args); } + void CallNonvirtualVoidMethodA(jobject obj, jclass clazz, + jmethodID methodID, jvalue* args) + { functions->CallNonvirtualVoidMethodA(this, obj, clazz, methodID, args); } + + jfieldID GetFieldID(jclass clazz, const char* name, const char* sig) + { return functions->GetFieldID(this, clazz, name, sig); } + + jobject GetObjectField(jobject obj, jfieldID fieldID) + { return functions->GetObjectField(this, obj, fieldID); } + jboolean GetBooleanField(jobject obj, jfieldID fieldID) + { return functions->GetBooleanField(this, obj, fieldID); } + jbyte GetByteField(jobject obj, jfieldID fieldID) + { return functions->GetByteField(this, obj, fieldID); } + jchar GetCharField(jobject obj, jfieldID fieldID) + { return functions->GetCharField(this, obj, fieldID); } + jshort GetShortField(jobject obj, jfieldID fieldID) + { return functions->GetShortField(this, obj, fieldID); } + jint GetIntField(jobject obj, jfieldID fieldID) + { return functions->GetIntField(this, obj, fieldID); } + jlong GetLongField(jobject obj, jfieldID fieldID) + { return functions->GetLongField(this, obj, fieldID); } + jfloat GetFloatField(jobject obj, jfieldID fieldID) + { return functions->GetFloatField(this, obj, fieldID); } + jdouble GetDoubleField(jobject obj, jfieldID fieldID) + { return functions->GetDoubleField(this, obj, fieldID); } + + void SetObjectField(jobject obj, jfieldID fieldID, jobject value) + { functions->SetObjectField(this, obj, fieldID, value); } + void SetBooleanField(jobject obj, jfieldID fieldID, jboolean value) + { functions->SetBooleanField(this, obj, fieldID, value); } + void SetByteField(jobject obj, jfieldID fieldID, jbyte value) + { functions->SetByteField(this, obj, fieldID, value); } + void SetCharField(jobject obj, jfieldID fieldID, jchar value) + { functions->SetCharField(this, obj, fieldID, value); } + void SetShortField(jobject obj, jfieldID fieldID, jshort value) + { functions->SetShortField(this, obj, fieldID, value); } + void SetIntField(jobject obj, jfieldID fieldID, jint value) + { functions->SetIntField(this, obj, fieldID, value); } + void SetLongField(jobject obj, jfieldID fieldID, jlong value) + { functions->SetLongField(this, obj, fieldID, value); } + void SetFloatField(jobject obj, jfieldID fieldID, jfloat value) + { functions->SetFloatField(this, obj, fieldID, value); } + void SetDoubleField(jobject obj, jfieldID fieldID, jdouble value) + { functions->SetDoubleField(this, obj, fieldID, value); } + + jmethodID GetStaticMethodID(jclass clazz, const char* name, const char* sig) + { return functions->GetStaticMethodID(this, clazz, name, sig); } + +#define CALL_STATIC_TYPE_METHOD(_jtype, _jname) \ + _jtype CallStatic##_jname##Method(jclass clazz, jmethodID methodID, \ + ...) \ + { \ + _jtype result; \ + va_list args; \ + va_start(args, methodID); \ + result = functions->CallStatic##_jname##MethodV(this, clazz, \ + methodID, args); \ + va_end(args); \ + return result; \ + } +#define CALL_STATIC_TYPE_METHODV(_jtype, _jname) \ + _jtype CallStatic##_jname##MethodV(jclass clazz, jmethodID methodID, \ + va_list args) \ + { return functions->CallStatic##_jname##MethodV(this, clazz, methodID, \ + args); } +#define CALL_STATIC_TYPE_METHODA(_jtype, _jname) \ + _jtype CallStatic##_jname##MethodA(jclass clazz, jmethodID methodID, \ + jvalue* args) \ + { return functions->CallStatic##_jname##MethodA(this, clazz, methodID, \ + args); } + +#define CALL_STATIC_TYPE(_jtype, _jname) \ + CALL_STATIC_TYPE_METHOD(_jtype, _jname) \ + CALL_STATIC_TYPE_METHODV(_jtype, _jname) \ + CALL_STATIC_TYPE_METHODA(_jtype, _jname) + + CALL_STATIC_TYPE(jobject, Object) + CALL_STATIC_TYPE(jboolean, Boolean) + CALL_STATIC_TYPE(jbyte, Byte) + CALL_STATIC_TYPE(jchar, Char) + CALL_STATIC_TYPE(jshort, Short) + CALL_STATIC_TYPE(jint, Int) + CALL_STATIC_TYPE(jlong, Long) + CALL_STATIC_TYPE(jfloat, Float) + CALL_STATIC_TYPE(jdouble, Double) + + void CallStaticVoidMethod(jclass clazz, jmethodID methodID, ...) + { + va_list args; + va_start(args, methodID); + functions->CallStaticVoidMethodV(this, clazz, methodID, args); + va_end(args); + } + void CallStaticVoidMethodV(jclass clazz, jmethodID methodID, va_list args) + { functions->CallStaticVoidMethodV(this, clazz, methodID, args); } + void CallStaticVoidMethodA(jclass clazz, jmethodID methodID, jvalue* args) + { functions->CallStaticVoidMethodA(this, clazz, methodID, args); } + + jfieldID GetStaticFieldID(jclass clazz, const char* name, const char* sig) + { return functions->GetStaticFieldID(this, clazz, name, sig); } + + jobject GetStaticObjectField(jclass clazz, jfieldID fieldID) + { return functions->GetStaticObjectField(this, clazz, fieldID); } + jboolean GetStaticBooleanField(jclass clazz, jfieldID fieldID) + { return functions->GetStaticBooleanField(this, clazz, fieldID); } + jbyte GetStaticByteField(jclass clazz, jfieldID fieldID) + { return functions->GetStaticByteField(this, clazz, fieldID); } + jchar GetStaticCharField(jclass clazz, jfieldID fieldID) + { return functions->GetStaticCharField(this, clazz, fieldID); } + jshort GetStaticShortField(jclass clazz, jfieldID fieldID) + { return functions->GetStaticShortField(this, clazz, fieldID); } + jint GetStaticIntField(jclass clazz, jfieldID fieldID) + { return functions->GetStaticIntField(this, clazz, fieldID); } + jlong GetStaticLongField(jclass clazz, jfieldID fieldID) + { return functions->GetStaticLongField(this, clazz, fieldID); } + jfloat GetStaticFloatField(jclass clazz, jfieldID fieldID) + { return functions->GetStaticFloatField(this, clazz, fieldID); } + jdouble GetStaticDoubleField(jclass clazz, jfieldID fieldID) + { return functions->GetStaticDoubleField(this, clazz, fieldID); } + + void SetStaticObjectField(jclass clazz, jfieldID fieldID, jobject value) + { functions->SetStaticObjectField(this, clazz, fieldID, value); } + void SetStaticBooleanField(jclass clazz, jfieldID fieldID, jboolean value) + { functions->SetStaticBooleanField(this, clazz, fieldID, value); } + void SetStaticByteField(jclass clazz, jfieldID fieldID, jbyte value) + { functions->SetStaticByteField(this, clazz, fieldID, value); } + void SetStaticCharField(jclass clazz, jfieldID fieldID, jchar value) + { functions->SetStaticCharField(this, clazz, fieldID, value); } + void SetStaticShortField(jclass clazz, jfieldID fieldID, jshort value) + { functions->SetStaticShortField(this, clazz, fieldID, value); } + void SetStaticIntField(jclass clazz, jfieldID fieldID, jint value) + { functions->SetStaticIntField(this, clazz, fieldID, value); } + void SetStaticLongField(jclass clazz, jfieldID fieldID, jlong value) + { functions->SetStaticLongField(this, clazz, fieldID, value); } + void SetStaticFloatField(jclass clazz, jfieldID fieldID, jfloat value) + { functions->SetStaticFloatField(this, clazz, fieldID, value); } + void SetStaticDoubleField(jclass clazz, jfieldID fieldID, jdouble value) + { functions->SetStaticDoubleField(this, clazz, fieldID, value); } + + jstring NewString(const jchar* unicodeChars, jsize len) + { return functions->NewString(this, unicodeChars, len); } + + jsize GetStringLength(jstring string) + { return functions->GetStringLength(this, string); } + + const jchar* GetStringChars(jstring string, jboolean* isCopy) + { return functions->GetStringChars(this, string, isCopy); } + + void ReleaseStringChars(jstring string, const jchar* chars) + { functions->ReleaseStringChars(this, string, chars); } + + jstring NewStringUTF(const char* bytes) + { return functions->NewStringUTF(this, bytes); } + + jsize GetStringUTFLength(jstring string) + { return functions->GetStringUTFLength(this, string); } + + const char* GetStringUTFChars(jstring string, jboolean* isCopy) + { return functions->GetStringUTFChars(this, string, isCopy); } + + void ReleaseStringUTFChars(jstring string, const char* utf) + { functions->ReleaseStringUTFChars(this, string, utf); } + + jsize GetArrayLength(jarray array) + { return functions->GetArrayLength(this, array); } + + jobjectArray NewObjectArray(jsize length, jclass elementClass, + jobject initialElement) + { return functions->NewObjectArray(this, length, elementClass, + initialElement); } + + jobject GetObjectArrayElement(jobjectArray array, jsize index) + { return functions->GetObjectArrayElement(this, array, index); } + + void SetObjectArrayElement(jobjectArray array, jsize index, jobject value) + { functions->SetObjectArrayElement(this, array, index, value); } + + jbooleanArray NewBooleanArray(jsize length) + { return functions->NewBooleanArray(this, length); } + jbyteArray NewByteArray(jsize length) + { return functions->NewByteArray(this, length); } + jcharArray NewCharArray(jsize length) + { return functions->NewCharArray(this, length); } + jshortArray NewShortArray(jsize length) + { return functions->NewShortArray(this, length); } + jintArray NewIntArray(jsize length) + { return functions->NewIntArray(this, length); } + jlongArray NewLongArray(jsize length) + { return functions->NewLongArray(this, length); } + jfloatArray NewFloatArray(jsize length) + { return functions->NewFloatArray(this, length); } + jdoubleArray NewDoubleArray(jsize length) + { return functions->NewDoubleArray(this, length); } + + jboolean* GetBooleanArrayElements(jbooleanArray array, jboolean* isCopy) + { return functions->GetBooleanArrayElements(this, array, isCopy); } + jbyte* GetByteArrayElements(jbyteArray array, jboolean* isCopy) + { return functions->GetByteArrayElements(this, array, isCopy); } + jchar* GetCharArrayElements(jcharArray array, jboolean* isCopy) + { return functions->GetCharArrayElements(this, array, isCopy); } + jshort* GetShortArrayElements(jshortArray array, jboolean* isCopy) + { return functions->GetShortArrayElements(this, array, isCopy); } + jint* GetIntArrayElements(jintArray array, jboolean* isCopy) + { return functions->GetIntArrayElements(this, array, isCopy); } + jlong* GetLongArrayElements(jlongArray array, jboolean* isCopy) + { return functions->GetLongArrayElements(this, array, isCopy); } + jfloat* GetFloatArrayElements(jfloatArray array, jboolean* isCopy) + { return functions->GetFloatArrayElements(this, array, isCopy); } + jdouble* GetDoubleArrayElements(jdoubleArray array, jboolean* isCopy) + { return functions->GetDoubleArrayElements(this, array, isCopy); } + + void ReleaseBooleanArrayElements(jbooleanArray array, jboolean* elems, + jint mode) + { functions->ReleaseBooleanArrayElements(this, array, elems, mode); } + void ReleaseByteArrayElements(jbyteArray array, jbyte* elems, + jint mode) + { functions->ReleaseByteArrayElements(this, array, elems, mode); } + void ReleaseCharArrayElements(jcharArray array, jchar* elems, + jint mode) + { functions->ReleaseCharArrayElements(this, array, elems, mode); } + void ReleaseShortArrayElements(jshortArray array, jshort* elems, + jint mode) + { functions->ReleaseShortArrayElements(this, array, elems, mode); } + void ReleaseIntArrayElements(jintArray array, jint* elems, + jint mode) + { functions->ReleaseIntArrayElements(this, array, elems, mode); } + void ReleaseLongArrayElements(jlongArray array, jlong* elems, + jint mode) + { functions->ReleaseLongArrayElements(this, array, elems, mode); } + void ReleaseFloatArrayElements(jfloatArray array, jfloat* elems, + jint mode) + { functions->ReleaseFloatArrayElements(this, array, elems, mode); } + void ReleaseDoubleArrayElements(jdoubleArray array, jdouble* elems, + jint mode) + { functions->ReleaseDoubleArrayElements(this, array, elems, mode); } + + void GetBooleanArrayRegion(jbooleanArray array, jsize start, jsize len, + jboolean* buf) + { functions->GetBooleanArrayRegion(this, array, start, len, buf); } + void GetByteArrayRegion(jbyteArray array, jsize start, jsize len, + jbyte* buf) + { functions->GetByteArrayRegion(this, array, start, len, buf); } + void GetCharArrayRegion(jcharArray array, jsize start, jsize len, + jchar* buf) + { functions->GetCharArrayRegion(this, array, start, len, buf); } + void GetShortArrayRegion(jshortArray array, jsize start, jsize len, + jshort* buf) + { functions->GetShortArrayRegion(this, array, start, len, buf); } + void GetIntArrayRegion(jintArray array, jsize start, jsize len, + jint* buf) + { functions->GetIntArrayRegion(this, array, start, len, buf); } + void GetLongArrayRegion(jlongArray array, jsize start, jsize len, + jlong* buf) + { functions->GetLongArrayRegion(this, array, start, len, buf); } + void GetFloatArrayRegion(jfloatArray array, jsize start, jsize len, + jfloat* buf) + { functions->GetFloatArrayRegion(this, array, start, len, buf); } + void GetDoubleArrayRegion(jdoubleArray array, jsize start, jsize len, + jdouble* buf) + { functions->GetDoubleArrayRegion(this, array, start, len, buf); } + + void SetBooleanArrayRegion(jbooleanArray array, jsize start, jsize len, + const jboolean* buf) + { functions->SetBooleanArrayRegion(this, array, start, len, buf); } + void SetByteArrayRegion(jbyteArray array, jsize start, jsize len, + const jbyte* buf) + { functions->SetByteArrayRegion(this, array, start, len, buf); } + void SetCharArrayRegion(jcharArray array, jsize start, jsize len, + const jchar* buf) + { functions->SetCharArrayRegion(this, array, start, len, buf); } + void SetShortArrayRegion(jshortArray array, jsize start, jsize len, + const jshort* buf) + { functions->SetShortArrayRegion(this, array, start, len, buf); } + void SetIntArrayRegion(jintArray array, jsize start, jsize len, + const jint* buf) + { functions->SetIntArrayRegion(this, array, start, len, buf); } + void SetLongArrayRegion(jlongArray array, jsize start, jsize len, + const jlong* buf) + { functions->SetLongArrayRegion(this, array, start, len, buf); } + void SetFloatArrayRegion(jfloatArray array, jsize start, jsize len, + const jfloat* buf) + { functions->SetFloatArrayRegion(this, array, start, len, buf); } + void SetDoubleArrayRegion(jdoubleArray array, jsize start, jsize len, + const jdouble* buf) + { functions->SetDoubleArrayRegion(this, array, start, len, buf); } + + jint RegisterNatives(jclass clazz, const JNINativeMethod* methods, + jint nMethods) + { return functions->RegisterNatives(this, clazz, methods, nMethods); } + + jint UnregisterNatives(jclass clazz) + { return functions->UnregisterNatives(this, clazz); } + + jint MonitorEnter(jobject obj) + { return functions->MonitorEnter(this, obj); } + + jint MonitorExit(jobject obj) + { return functions->MonitorExit(this, obj); } + + jint GetJavaVM(JavaVM** vm) + { return functions->GetJavaVM(this, vm); } + + void GetStringRegion(jstring str, jsize start, jsize len, jchar* buf) + { functions->GetStringRegion(this, str, start, len, buf); } + + void GetStringUTFRegion(jstring str, jsize start, jsize len, char* buf) + { return functions->GetStringUTFRegion(this, str, start, len, buf); } + + void* GetPrimitiveArrayCritical(jarray array, jboolean* isCopy) + { return functions->GetPrimitiveArrayCritical(this, array, isCopy); } + + void ReleasePrimitiveArrayCritical(jarray array, void* carray, jint mode) + { functions->ReleasePrimitiveArrayCritical(this, array, carray, mode); } + + const jchar* GetStringCritical(jstring string, jboolean* isCopy) + { return functions->GetStringCritical(this, string, isCopy); } + + void ReleaseStringCritical(jstring string, const jchar* carray) + { functions->ReleaseStringCritical(this, string, carray); } + + jweak NewWeakGlobalRef(jobject obj) + { return functions->NewWeakGlobalRef(this, obj); } + + void DeleteWeakGlobalRef(jweak obj) + { functions->DeleteWeakGlobalRef(this, obj); } + + jboolean ExceptionCheck() + { return functions->ExceptionCheck(this); } + + jobject NewDirectByteBuffer(void* address, jlong capacity) + { return functions->NewDirectByteBuffer(this, address, capacity); } + + void* GetDirectBufferAddress(jobject buf) + { return functions->GetDirectBufferAddress(this, buf); } + + jlong GetDirectBufferCapacity(jobject buf) + { return functions->GetDirectBufferCapacity(this, buf); } + + /* added in JNI 1.6 */ + jobjectRefType GetObjectRefType(jobject obj) + { return functions->GetObjectRefType(this, obj); } +#endif /*__cplusplus*/ +}; + + +/* + * JNI invocation interface. + */ +struct JNIInvokeInterface { + void* reserved0; + void* reserved1; + void* reserved2; + + jint (*DestroyJavaVM)(JavaVM*); + jint (*AttachCurrentThread)(JavaVM*, JNIEnv**, void*); + jint (*DetachCurrentThread)(JavaVM*); + jint (*GetEnv)(JavaVM*, void**, jint); + jint (*AttachCurrentThreadAsDaemon)(JavaVM*, JNIEnv**, void*); +}; + +/* + * C++ version. + */ +struct _JavaVM { + const struct JNIInvokeInterface* functions; + +#if defined(__cplusplus) + jint DestroyJavaVM() + { return functions->DestroyJavaVM(this); } + jint AttachCurrentThread(JNIEnv** p_env, void* thr_args) + { return functions->AttachCurrentThread(this, p_env, thr_args); } + jint DetachCurrentThread() + { return functions->DetachCurrentThread(this); } + jint GetEnv(void** env, jint version) + { return functions->GetEnv(this, env, version); } + jint AttachCurrentThreadAsDaemon(JNIEnv** p_env, void* thr_args) + { return functions->AttachCurrentThreadAsDaemon(this, p_env, thr_args); } +#endif /*__cplusplus*/ +}; + +struct JavaVMAttachArgs { + jint version; /* must be >= JNI_VERSION_1_2 */ + const char* name; /* NULL or name of thread as modified UTF-8 str */ + jobject group; /* global ref of a ThreadGroup object, or NULL */ +}; +typedef struct JavaVMAttachArgs JavaVMAttachArgs; + +/* + * JNI 1.2+ initialization. (As of 1.6, the pre-1.2 structures are no + * longer supported.) + */ +typedef struct JavaVMOption { + const char* optionString; + void* extraInfo; +} JavaVMOption; + +typedef struct JavaVMInitArgs { + jint version; /* use JNI_VERSION_1_2 or later */ + + jint nOptions; + JavaVMOption* options; + jboolean ignoreUnrecognized; +} JavaVMInitArgs; + +#ifdef __cplusplus +extern "C" { +#endif +/* + * VM initialization functions. + * + * Note these are the only symbols exported for JNI by the VM. + */ +jint JNI_GetDefaultJavaVMInitArgs(void*); +jint JNI_CreateJavaVM(JavaVM**, JNIEnv**, void*); +jint JNI_GetCreatedJavaVMs(JavaVM**, jsize, jsize*); + +#define JNIIMPORT +#define JNIEXPORT __attribute__ ((visibility ("default"))) +#define JNICALL + +/* + * Prototypes for functions exported by loadable shared libs. These are + * called by JNI, not provided by JNI. + */ +JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved); +JNIEXPORT void JNI_OnUnload(JavaVM* vm, void* reserved); + +#ifdef __cplusplus +} +#endif + + +/* + * Manifest constants. + */ +#define JNI_FALSE 0 +#define JNI_TRUE 1 + +#define JNI_VERSION_1_1 0x00010001 +#define JNI_VERSION_1_2 0x00010002 +#define JNI_VERSION_1_4 0x00010004 +#define JNI_VERSION_1_6 0x00010006 + +#define JNI_OK (0) /* no error */ +#define JNI_ERR (-1) /* generic error */ +#define JNI_EDETACHED (-2) /* thread detached from the VM */ +#define JNI_EVERSION (-3) /* JNI version error */ + +#define JNI_COMMIT 1 /* copy content, do not free buffer */ +#define JNI_ABORT 2 /* free buffer w/o copying back */ + +#endif /* JNI_H_ */ diff --git a/lib/jsr-305/BUCK b/lib/jsr-305/BUCK index c3f74727..8ced012c 100644 --- a/lib/jsr-305/BUCK +++ b/lib/jsr-305/BUCK @@ -5,7 +5,7 @@ # 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_defs('//CSSLAYOUT_DEFS') +include_defs('//YOGA_DEFS') prebuilt_jar( name = 'jsr305-jar', @@ -17,5 +17,5 @@ java_library( exported_deps = [ ':jsr305-jar', ], - visibility = [CSSLAYOUT_ROOT], + visibility = [YOGA_ROOT], ) diff --git a/lib/junit/BUCK b/lib/junit/BUCK index e35b0533..e9bbe4b8 100644 --- a/lib/junit/BUCK +++ b/lib/junit/BUCK @@ -5,7 +5,7 @@ # 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_defs('//CSSLAYOUT_DEFS') +include_defs('//YOGA_DEFS') prebuilt_jar( name = 'junit-jar', @@ -17,5 +17,5 @@ java_library( exported_deps = [ ':junit-jar', ], - visibility = [CSSLAYOUT_ROOT], + visibility = [YOGA_ROOT], ) diff --git a/lib/soloader/BUCK b/lib/soloader/BUCK index 8a9ce0a8..977c6d58 100644 --- a/lib/soloader/BUCK +++ b/lib/soloader/BUCK @@ -5,10 +5,10 @@ # 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_defs('//CSSLAYOUT_DEFS') +include_defs('//YOGA_DEFS') android_prebuilt_aar( name = 'soloader', aar = 'soloader-0.1.0.aar', - visibility = [CSSLAYOUT_ROOT], + visibility = [YOGA_ROOT], ) diff --git a/tests/CSSLayoutAbsolutePositionTest.cpp b/tests/CSSLayoutAbsolutePositionTest.cpp deleted file mode 100644 index d817b6ff..00000000 --- a/tests/CSSLayoutAbsolutePositionTest.cpp +++ /dev/null @@ -1,248 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
-
-
- * - */ - -#include -#include - -TEST(CSSLayoutTest, absolute_layout_width_height_start_top) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetPositionType(root_child0, CSSPositionTypeAbsolute); - CSSNodeStyleSetPosition(root_child0, CSSEdgeStart, 10); - CSSNodeStyleSetPosition(root_child0, CSSEdgeTop, 10); - CSSNodeStyleSetWidth(root_child0, 10); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(80, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, absolute_layout_width_height_end_bottom) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetPositionType(root_child0, CSSPositionTypeAbsolute); - CSSNodeStyleSetPosition(root_child0, CSSEdgeEnd, 10); - CSSNodeStyleSetPosition(root_child0, CSSEdgeBottom, 10); - CSSNodeStyleSetWidth(root_child0, 10); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(80, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(80, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(80, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, absolute_layout_start_top_end_bottom) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetPositionType(root_child0, CSSPositionTypeAbsolute); - CSSNodeStyleSetPosition(root_child0, CSSEdgeStart, 10); - CSSNodeStyleSetPosition(root_child0, CSSEdgeTop, 10); - CSSNodeStyleSetPosition(root_child0, CSSEdgeEnd, 10); - CSSNodeStyleSetPosition(root_child0, CSSEdgeBottom, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(80, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(80, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(80, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(80, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, absolute_layout_width_height_start_top_end_bottom) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetPositionType(root_child0, CSSPositionTypeAbsolute); - CSSNodeStyleSetPosition(root_child0, CSSEdgeStart, 10); - CSSNodeStyleSetPosition(root_child0, CSSEdgeTop, 10); - CSSNodeStyleSetPosition(root_child0, CSSEdgeEnd, 10); - CSSNodeStyleSetPosition(root_child0, CSSEdgeBottom, 10); - CSSNodeStyleSetWidth(root_child0, 10); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(80, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, do_not_clamp_height_of_absolute_node_to_height_of_its_overflow_hidden_parent) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); - CSSNodeStyleSetOverflow(root, CSSOverflowHidden); - CSSNodeStyleSetWidth(root, 50); - CSSNodeStyleSetHeight(root, 50); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetPositionType(root_child0, CSSPositionTypeAbsolute); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child0_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0_child0, 100); - CSSNodeStyleSetHeight(root_child0_child0, 100); - CSSNodeInsertChild(root_child0, root_child0_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(50, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child0_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(50, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(-50, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child0_child0)); - - CSSNodeFreeRecursive(root); -} diff --git a/tests/CSSLayoutAlignContentTest.cpp b/tests/CSSLayoutAlignContentTest.cpp deleted file mode 100644 index 7176801b..00000000 --- a/tests/CSSLayoutAlignContentTest.cpp +++ /dev/null @@ -1,434 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
-
-
-
-
- -
-
-
-
-
-
-
- -
-
-
-
-
-
-
- -
-
-
-
-
-
-
- * - */ - -#include -#include - -TEST(CSSLayoutTest, align_content_flex_start) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexWrap(root, CSSWrapTypeWrap); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 50); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child1, 50); - CSSNodeStyleSetHeight(root_child1, 10); - CSSNodeInsertChild(root, root_child1, 1); - - const CSSNodeRef root_child2 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child2, 50); - CSSNodeStyleSetHeight(root_child2, 10); - CSSNodeInsertChild(root, root_child2, 2); - - const CSSNodeRef root_child3 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child3, 50); - CSSNodeStyleSetHeight(root_child3, 10); - CSSNodeInsertChild(root, root_child3, 3); - - const CSSNodeRef root_child4 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child4, 50); - CSSNodeStyleSetHeight(root_child4, 10); - CSSNodeInsertChild(root, root_child4, 4); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(20, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child2)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child3)); - ASSERT_EQ(30, CSSNodeLayoutGetTop(root_child3)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child3)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child3)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child4)); - ASSERT_EQ(40, CSSNodeLayoutGetTop(root_child4)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child4)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child4)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(50, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(50, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(50, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(20, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child2)); - - ASSERT_EQ(50, CSSNodeLayoutGetLeft(root_child3)); - ASSERT_EQ(30, CSSNodeLayoutGetTop(root_child3)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child3)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child3)); - - ASSERT_EQ(50, CSSNodeLayoutGetLeft(root_child4)); - ASSERT_EQ(40, CSSNodeLayoutGetTop(root_child4)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child4)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child4)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, align_content_flex_end) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetAlignContent(root, CSSAlignFlexEnd); - CSSNodeStyleSetFlexWrap(root, CSSWrapTypeWrap); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 50); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child1, 50); - CSSNodeStyleSetHeight(root_child1, 10); - CSSNodeInsertChild(root, root_child1, 1); - - const CSSNodeRef root_child2 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child2, 50); - CSSNodeStyleSetHeight(root_child2, 10); - CSSNodeInsertChild(root, root_child2, 2); - - const CSSNodeRef root_child3 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child3, 50); - CSSNodeStyleSetHeight(root_child3, 10); - CSSNodeInsertChild(root, root_child3, 3); - - const CSSNodeRef root_child4 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child4, 50); - CSSNodeStyleSetHeight(root_child4, 10); - CSSNodeInsertChild(root, root_child4, 4); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(20, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child2)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child3)); - ASSERT_EQ(30, CSSNodeLayoutGetTop(root_child3)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child3)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child3)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child4)); - ASSERT_EQ(40, CSSNodeLayoutGetTop(root_child4)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child4)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child4)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(50, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(50, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(50, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(20, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child2)); - - ASSERT_EQ(50, CSSNodeLayoutGetLeft(root_child3)); - ASSERT_EQ(30, CSSNodeLayoutGetTop(root_child3)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child3)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child3)); - - ASSERT_EQ(50, CSSNodeLayoutGetLeft(root_child4)); - ASSERT_EQ(40, CSSNodeLayoutGetTop(root_child4)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child4)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child4)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, align_content_center) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetAlignContent(root, CSSAlignCenter); - CSSNodeStyleSetFlexWrap(root, CSSWrapTypeWrap); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 50); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child1, 50); - CSSNodeStyleSetHeight(root_child1, 10); - CSSNodeInsertChild(root, root_child1, 1); - - const CSSNodeRef root_child2 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child2, 50); - CSSNodeStyleSetHeight(root_child2, 10); - CSSNodeInsertChild(root, root_child2, 2); - - const CSSNodeRef root_child3 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child3, 50); - CSSNodeStyleSetHeight(root_child3, 10); - CSSNodeInsertChild(root, root_child3, 3); - - const CSSNodeRef root_child4 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child4, 50); - CSSNodeStyleSetHeight(root_child4, 10); - CSSNodeInsertChild(root, root_child4, 4); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(20, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child2)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child3)); - ASSERT_EQ(30, CSSNodeLayoutGetTop(root_child3)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child3)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child3)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child4)); - ASSERT_EQ(40, CSSNodeLayoutGetTop(root_child4)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child4)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child4)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(50, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(50, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(50, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(20, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child2)); - - ASSERT_EQ(50, CSSNodeLayoutGetLeft(root_child3)); - ASSERT_EQ(30, CSSNodeLayoutGetTop(root_child3)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child3)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child3)); - - ASSERT_EQ(50, CSSNodeLayoutGetLeft(root_child4)); - ASSERT_EQ(40, CSSNodeLayoutGetTop(root_child4)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child4)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child4)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, align_content_stretch) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetAlignContent(root, CSSAlignStretch); - CSSNodeStyleSetFlexWrap(root, CSSWrapTypeWrap); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 50); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child1, 50); - CSSNodeInsertChild(root, root_child1, 1); - - const CSSNodeRef root_child2 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child2, 50); - CSSNodeInsertChild(root, root_child2, 2); - - const CSSNodeRef root_child3 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child3, 50); - CSSNodeInsertChild(root, root_child3, 3); - - const CSSNodeRef root_child4 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child4, 50); - CSSNodeInsertChild(root, root_child4, 4); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(0, CSSNodeLayoutGetHeight(root_child2)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child3)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child3)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child3)); - ASSERT_EQ(0, CSSNodeLayoutGetHeight(root_child3)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child4)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child4)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child4)); - ASSERT_EQ(0, CSSNodeLayoutGetHeight(root_child4)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(50, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(50, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(50, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(0, CSSNodeLayoutGetHeight(root_child2)); - - ASSERT_EQ(50, CSSNodeLayoutGetLeft(root_child3)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child3)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child3)); - ASSERT_EQ(0, CSSNodeLayoutGetHeight(root_child3)); - - ASSERT_EQ(50, CSSNodeLayoutGetLeft(root_child4)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child4)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child4)); - ASSERT_EQ(0, CSSNodeLayoutGetHeight(root_child4)); - - CSSNodeFreeRecursive(root); -} diff --git a/tests/CSSLayoutAlignItemsTest.cpp b/tests/CSSLayoutAlignItemsTest.cpp deleted file mode 100644 index 9a9ca6cc..00000000 --- a/tests/CSSLayoutAlignItemsTest.cpp +++ /dev/null @@ -1,178 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
- -
-
-
- -
-
-
- -
-
-
- * - */ - -#include -#include - -TEST(CSSLayoutTest, align_items_stretch) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, align_items_center) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetAlignItems(root, CSSAlignCenter); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 10); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(45, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(45, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, align_items_flex_start) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetAlignItems(root, CSSAlignFlexStart); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 10); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(90, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, align_items_flex_end) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetAlignItems(root, CSSAlignFlexEnd); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 10); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(90, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} diff --git a/tests/CSSLayoutAlignSelfTest.cpp b/tests/CSSLayoutAlignSelfTest.cpp deleted file mode 100644 index 7392fc8a..00000000 --- a/tests/CSSLayoutAlignSelfTest.cpp +++ /dev/null @@ -1,181 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
- -
-
-
- -
-
-
- -
-
-
- * - */ - -#include -#include - -TEST(CSSLayoutTest, align_self_center) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetAlignSelf(root_child0, CSSAlignCenter); - CSSNodeStyleSetWidth(root_child0, 10); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(45, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(45, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, align_self_flex_end) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetAlignSelf(root_child0, CSSAlignFlexEnd); - CSSNodeStyleSetWidth(root_child0, 10); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(90, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, align_self_flex_start) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetAlignSelf(root_child0, CSSAlignFlexStart); - CSSNodeStyleSetWidth(root_child0, 10); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(90, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, align_self_flex_end_override_flex_start) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetAlignItems(root, CSSAlignFlexStart); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetAlignSelf(root_child0, CSSAlignFlexEnd); - CSSNodeStyleSetWidth(root_child0, 10); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(90, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} diff --git a/tests/CSSLayoutBorderTest.cpp b/tests/CSSLayoutBorderTest.cpp deleted file mode 100644 index 08f67302..00000000 --- a/tests/CSSLayoutBorderTest.cpp +++ /dev/null @@ -1,216 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- * - */ - -#include -#include - -TEST(CSSLayoutTest, border_no_size) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetBorder(root, CSSEdgeLeft, 10); - CSSNodeStyleSetBorder(root, CSSEdgeTop, 10); - CSSNodeStyleSetBorder(root, CSSEdgeRight, 10); - CSSNodeStyleSetBorder(root, CSSEdgeBottom, 10); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(20, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(20, CSSNodeLayoutGetHeight(root)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(20, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(20, CSSNodeLayoutGetHeight(root)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, border_container_match_child) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetBorder(root, CSSEdgeLeft, 10); - CSSNodeStyleSetBorder(root, CSSEdgeTop, 10); - CSSNodeStyleSetBorder(root, CSSEdgeRight, 10); - CSSNodeStyleSetBorder(root, CSSEdgeBottom, 10); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 10); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, border_flex_child) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetBorder(root, CSSEdgeLeft, 10); - CSSNodeStyleSetBorder(root, CSSEdgeTop, 10); - CSSNodeStyleSetBorder(root, CSSEdgeRight, 10); - CSSNodeStyleSetBorder(root, CSSEdgeBottom, 10); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child0, 1); - CSSNodeStyleSetWidth(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(80, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(80, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(80, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, border_stretch_child) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetBorder(root, CSSEdgeLeft, 10); - CSSNodeStyleSetBorder(root, CSSEdgeTop, 10); - CSSNodeStyleSetBorder(root, CSSEdgeRight, 10); - CSSNodeStyleSetBorder(root, CSSEdgeBottom, 10); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(80, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(80, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, border_center_child) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetJustifyContent(root, CSSJustifyCenter); - CSSNodeStyleSetAlignItems(root, CSSAlignCenter); - CSSNodeStyleSetBorder(root, CSSEdgeStart, 10); - CSSNodeStyleSetBorder(root, CSSEdgeEnd, 20); - CSSNodeStyleSetBorder(root, CSSEdgeBottom, 20); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 10); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(40, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(35, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(50, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(35, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} diff --git a/tests/CSSLayoutDefaultValuesTest.cpp b/tests/CSSLayoutDefaultValuesTest.cpp deleted file mode 100644 index 7c647f61..00000000 --- a/tests/CSSLayoutDefaultValuesTest.cpp +++ /dev/null @@ -1,76 +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 -#include - -TEST(CSSLayoutTest, assert_default_values) { - const CSSNodeRef root = CSSNodeNew(); - - ASSERT_EQ(0, CSSNodeChildCount(root)); - ASSERT_EQ(NULL, CSSNodeGetChild(root, 1)); - - ASSERT_EQ(CSSDirectionInherit, CSSNodeStyleGetDirection(root)); - ASSERT_EQ(CSSFlexDirectionColumn, CSSNodeStyleGetFlexDirection(root)); - ASSERT_EQ(CSSJustifyFlexStart, CSSNodeStyleGetJustifyContent(root)); - ASSERT_EQ(CSSAlignFlexStart, CSSNodeStyleGetAlignContent(root)); - ASSERT_EQ(CSSAlignStretch, CSSNodeStyleGetAlignItems(root)); - ASSERT_EQ(CSSAlignAuto, CSSNodeStyleGetAlignSelf(root)); - ASSERT_EQ(CSSPositionTypeRelative, CSSNodeStyleGetPositionType(root)); - ASSERT_EQ(CSSWrapTypeNoWrap, CSSNodeStyleGetFlexWrap(root)); - ASSERT_EQ(CSSOverflowVisible, CSSNodeStyleGetOverflow(root)); - ASSERT_EQ(0, CSSNodeStyleGetFlexGrow(root)); - ASSERT_EQ(0, CSSNodeStyleGetFlexShrink(root)); - ASSERT_TRUE(CSSValueIsUndefined(CSSNodeStyleGetFlexBasis(root))); - - ASSERT_TRUE(CSSValueIsUndefined(CSSNodeStyleGetPosition(root, CSSEdgeLeft))); - ASSERT_TRUE(CSSValueIsUndefined(CSSNodeStyleGetPosition(root, CSSEdgeTop))); - ASSERT_TRUE(CSSValueIsUndefined(CSSNodeStyleGetPosition(root, CSSEdgeRight))); - ASSERT_TRUE(CSSValueIsUndefined(CSSNodeStyleGetPosition(root, CSSEdgeBottom))); - ASSERT_TRUE(CSSValueIsUndefined(CSSNodeStyleGetPosition(root, CSSEdgeStart))); - ASSERT_TRUE(CSSValueIsUndefined(CSSNodeStyleGetPosition(root, CSSEdgeEnd))); - - ASSERT_EQ(0, CSSNodeStyleGetMargin(root, CSSEdgeLeft)); - ASSERT_EQ(0, CSSNodeStyleGetMargin(root, CSSEdgeTop)); - ASSERT_EQ(0, CSSNodeStyleGetMargin(root, CSSEdgeRight)); - ASSERT_EQ(0, CSSNodeStyleGetMargin(root, CSSEdgeBottom)); - ASSERT_TRUE(CSSValueIsUndefined(CSSNodeStyleGetMargin(root, CSSEdgeStart))); - ASSERT_TRUE(CSSValueIsUndefined(CSSNodeStyleGetMargin(root, CSSEdgeEnd))); - - ASSERT_EQ(0, CSSNodeStyleGetPadding(root, CSSEdgeLeft)); - ASSERT_EQ(0, CSSNodeStyleGetPadding(root, CSSEdgeTop)); - ASSERT_EQ(0, CSSNodeStyleGetPadding(root, CSSEdgeRight)); - ASSERT_EQ(0, CSSNodeStyleGetPadding(root, CSSEdgeBottom)); - ASSERT_TRUE(CSSValueIsUndefined(CSSNodeStyleGetPadding(root, CSSEdgeStart))); - ASSERT_TRUE(CSSValueIsUndefined(CSSNodeStyleGetPadding(root, CSSEdgeEnd))); - - ASSERT_EQ(0, CSSNodeStyleGetBorder(root, CSSEdgeLeft)); - ASSERT_EQ(0, CSSNodeStyleGetBorder(root, CSSEdgeTop)); - ASSERT_EQ(0, CSSNodeStyleGetBorder(root, CSSEdgeRight)); - ASSERT_EQ(0, CSSNodeStyleGetBorder(root, CSSEdgeBottom)); - ASSERT_TRUE(CSSValueIsUndefined(CSSNodeStyleGetBorder(root, CSSEdgeStart))); - ASSERT_TRUE(CSSValueIsUndefined(CSSNodeStyleGetBorder(root, CSSEdgeEnd))); - - ASSERT_TRUE(CSSValueIsUndefined(CSSNodeStyleGetWidth(root))); - ASSERT_TRUE(CSSValueIsUndefined(CSSNodeStyleGetHeight(root))); - ASSERT_TRUE(CSSValueIsUndefined(CSSNodeStyleGetMinWidth(root))); - ASSERT_TRUE(CSSValueIsUndefined(CSSNodeStyleGetMinHeight(root))); - ASSERT_TRUE(CSSValueIsUndefined(CSSNodeStyleGetMaxWidth(root))); - ASSERT_TRUE(CSSValueIsUndefined(CSSNodeStyleGetMaxHeight(root))); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(0, CSSNodeLayoutGetRight(root)); - ASSERT_EQ(0, CSSNodeLayoutGetBottom(root)); - ASSERT_TRUE(CSSValueIsUndefined(CSSNodeLayoutGetWidth(root))); - ASSERT_TRUE(CSSValueIsUndefined(CSSNodeLayoutGetHeight(root))); - ASSERT_EQ(CSSDirectionInherit, CSSNodeLayoutGetDirection(root)); - - CSSNodeFreeRecursive(root); -} diff --git a/tests/CSSLayoutDirtyMarkingTest.cpp b/tests/CSSLayoutDirtyMarkingTest.cpp deleted file mode 100644 index 50d86c7c..00000000 --- a/tests/CSSLayoutDirtyMarkingTest.cpp +++ /dev/null @@ -1,71 +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 -#include - -TEST(CSSLayoutTest, dirty_propagation) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetAlignItems(root, CSSAlignFlexStart); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 50); - CSSNodeStyleSetHeight(root_child0, 20); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child1, 50); - CSSNodeStyleSetHeight(root_child1, 20); - CSSNodeInsertChild(root, root_child1, 1); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - CSSNodeStyleSetWidth(root_child0, 20); - - EXPECT_TRUE(CSSNodeIsDirty(root_child0)); - EXPECT_FALSE(CSSNodeIsDirty(root_child1)); - EXPECT_TRUE(CSSNodeIsDirty(root)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - EXPECT_FALSE(CSSNodeIsDirty(root_child0)); - EXPECT_FALSE(CSSNodeIsDirty(root_child1)); - EXPECT_FALSE(CSSNodeIsDirty(root)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, dirty_propagation_only_if_prop_changed) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetAlignItems(root, CSSAlignFlexStart); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 50); - CSSNodeStyleSetHeight(root_child0, 20); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child1, 50); - CSSNodeStyleSetHeight(root_child1, 20); - CSSNodeInsertChild(root, root_child1, 1); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - CSSNodeStyleSetWidth(root_child0, 50); - - EXPECT_FALSE(CSSNodeIsDirty(root_child0)); - EXPECT_FALSE(CSSNodeIsDirty(root_child1)); - EXPECT_FALSE(CSSNodeIsDirty(root)); - - CSSNodeFreeRecursive(root); -} diff --git a/tests/CSSLayoutEdgeTest.cpp b/tests/CSSLayoutEdgeTest.cpp deleted file mode 100644 index 09c718ed..00000000 --- a/tests/CSSLayoutEdgeTest.cpp +++ /dev/null @@ -1,163 +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 -#include - -TEST(CSSLayoutTest, start_overrides) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child0, 1); - CSSNodeStyleSetMargin(root_child0, CSSEdgeStart, 10); - CSSNodeStyleSetMargin(root_child0, CSSEdgeLeft, 20); - CSSNodeStyleSetMargin(root_child0, CSSEdgeRight, 20); - CSSNodeInsertChild(root, root_child0, 0); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(20, CSSNodeLayoutGetRight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - ASSERT_EQ(20, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetRight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, end_overrides) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child0, 1); - CSSNodeStyleSetMargin(root_child0, CSSEdgeEnd, 10); - CSSNodeStyleSetMargin(root_child0, CSSEdgeLeft, 20); - CSSNodeStyleSetMargin(root_child0, CSSEdgeRight, 20); - CSSNodeInsertChild(root, root_child0, 0); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - ASSERT_EQ(20, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetRight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(20, CSSNodeLayoutGetRight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, horizontal_overridden) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child0, 1); - CSSNodeStyleSetMargin(root_child0, CSSEdgeHorizontal, 10); - CSSNodeStyleSetMargin(root_child0, CSSEdgeLeft, 20); - CSSNodeInsertChild(root, root_child0, 0); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - ASSERT_EQ(20, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetRight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, vertical_overridden) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionColumn); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child0, 1); - CSSNodeStyleSetMargin(root_child0, CSSEdgeVertical, 10); - CSSNodeStyleSetMargin(root_child0, CSSEdgeTop, 20); - CSSNodeInsertChild(root, root_child0, 0); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - ASSERT_EQ(20, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetBottom(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, horizontal_overrides_all) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionColumn); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child0, 1); - CSSNodeStyleSetMargin(root_child0, CSSEdgeHorizontal, 10); - CSSNodeStyleSetMargin(root_child0, CSSEdgeAll, 20); - CSSNodeInsertChild(root, root_child0, 0); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(20, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetRight(root_child0)); - ASSERT_EQ(20, CSSNodeLayoutGetBottom(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, vertical_overrides_all) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionColumn); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child0, 1); - CSSNodeStyleSetMargin(root_child0, CSSEdgeVertical, 10); - CSSNodeStyleSetMargin(root_child0, CSSEdgeAll, 20); - CSSNodeInsertChild(root, root_child0, 0); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - ASSERT_EQ(20, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(20, CSSNodeLayoutGetRight(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetBottom(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, all_overridden) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionColumn); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child0, 1); - CSSNodeStyleSetMargin(root_child0, CSSEdgeLeft, 10); - CSSNodeStyleSetMargin(root_child0, CSSEdgeTop, 10); - CSSNodeStyleSetMargin(root_child0, CSSEdgeRight, 10); - CSSNodeStyleSetMargin(root_child0, CSSEdgeBottom, 10); - CSSNodeStyleSetMargin(root_child0, CSSEdgeAll, 20); - CSSNodeInsertChild(root, root_child0, 0); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetRight(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetBottom(root_child0)); - - CSSNodeFreeRecursive(root); -} diff --git a/tests/CSSLayoutFlexDirectionTest.cpp b/tests/CSSLayoutFlexDirectionTest.cpp deleted file mode 100644 index c1226c26..00000000 --- a/tests/CSSLayoutFlexDirectionTest.cpp +++ /dev/null @@ -1,432 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- * - */ - -#include -#include - -TEST(CSSLayoutTest, flex_direction_column_no_height) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetWidth(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetHeight(root_child1, 10); - CSSNodeInsertChild(root, root_child1, 1); - - const CSSNodeRef root_child2 = CSSNodeNew(); - CSSNodeStyleSetHeight(root_child2, 10); - CSSNodeInsertChild(root, root_child2, 2); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(20, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(20, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, flex_direction_row_no_width) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child1, 10); - CSSNodeInsertChild(root, root_child1, 1); - - const CSSNodeRef root_child2 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child2, 10); - CSSNodeInsertChild(root, root_child2, 2); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(20, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(20, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, flex_direction_column) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetHeight(root_child1, 10); - CSSNodeInsertChild(root, root_child1, 1); - - const CSSNodeRef root_child2 = CSSNodeNew(); - CSSNodeStyleSetHeight(root_child2, 10); - CSSNodeInsertChild(root, root_child2, 2); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(20, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(20, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, flex_direction_row) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child1, 10); - CSSNodeInsertChild(root, root_child1, 1); - - const CSSNodeRef root_child2 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child2, 10); - CSSNodeInsertChild(root, root_child2, 2); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(20, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(90, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(80, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(70, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, flex_direction_column_reverse) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionColumnReverse); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetHeight(root_child1, 10); - CSSNodeInsertChild(root, root_child1, 1); - - const CSSNodeRef root_child2 = CSSNodeNew(); - CSSNodeStyleSetHeight(root_child2, 10); - CSSNodeInsertChild(root, root_child2, 2); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(90, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(80, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(70, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(90, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(80, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(70, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, flex_direction_row_reverse) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRowReverse); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child1, 10); - CSSNodeInsertChild(root, root_child1, 1); - - const CSSNodeRef root_child2 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child2, 10); - CSSNodeInsertChild(root, root_child2, 2); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(90, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(80, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(70, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(20, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeFreeRecursive(root); -} diff --git a/tests/CSSLayoutFlexTest.cpp b/tests/CSSLayoutFlexTest.cpp deleted file mode 100644 index 7a5c76e7..00000000 --- a/tests/CSSLayoutFlexTest.cpp +++ /dev/null @@ -1,383 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
-
- -
-
-
-
- -
-
-
-
- -
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- * - */ - -#include -#include - -TEST(CSSLayoutTest, flex_basis_flex_grow_column) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child0, 1); - CSSNodeStyleSetFlexBasis(root_child0, 50); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child1, 1); - CSSNodeInsertChild(root, root_child1, 1); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(75, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(75, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(25, CSSNodeLayoutGetHeight(root_child1)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(75, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(75, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(25, CSSNodeLayoutGetHeight(root_child1)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, flex_basis_flex_grow_row) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child0, 1); - CSSNodeStyleSetFlexBasis(root_child0, 50); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child1, 1); - CSSNodeInsertChild(root, root_child1, 1); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(75, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(75, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(25, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child1)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(25, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(75, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(25, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child1)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, flex_basis_flex_shrink_column) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetFlexShrink(root_child0, 1); - CSSNodeStyleSetFlexBasis(root_child0, 100); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetFlexBasis(root_child1, 50); - CSSNodeInsertChild(root, root_child1, 1); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(50, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(50, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(50, CSSNodeLayoutGetHeight(root_child1)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(50, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(50, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(50, CSSNodeLayoutGetHeight(root_child1)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, flex_basis_flex_shrink_row) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetFlexShrink(root_child0, 1); - CSSNodeStyleSetFlexBasis(root_child0, 100); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetFlexBasis(root_child1, 50); - CSSNodeInsertChild(root, root_child1, 1); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(50, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child1)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(50, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child1)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, flex_shrink_to_zero) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetHeight(root, 75); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 50); - CSSNodeStyleSetHeight(root_child0, 50); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetFlexShrink(root_child1, 1); - CSSNodeStyleSetWidth(root_child1, 50); - CSSNodeStyleSetHeight(root_child1, 50); - CSSNodeInsertChild(root, root_child1, 1); - - const CSSNodeRef root_child2 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child2, 50); - CSSNodeStyleSetHeight(root_child2, 50); - CSSNodeInsertChild(root, root_child2, 2); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(75, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(50, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(50, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(50, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(50, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(75, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(50, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(50, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(50, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(50, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, flex_basis_overrides_main_size) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child0, 1); - CSSNodeStyleSetFlexBasis(root_child0, 50); - CSSNodeStyleSetHeight(root_child0, 20); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child1, 1); - CSSNodeStyleSetHeight(root_child1, 10); - CSSNodeInsertChild(root, root_child1, 1); - - const CSSNodeRef root_child2 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child2, 1); - CSSNodeStyleSetHeight(root_child2, 10); - CSSNodeInsertChild(root, root_child2, 2); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(60, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(60, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(20, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(80, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(20, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(60, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(60, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(20, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(80, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(20, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeFreeRecursive(root); -} diff --git a/tests/CSSLayoutFlexWrapTest.cpp b/tests/CSSLayoutFlexWrapTest.cpp deleted file mode 100644 index 49dcab93..00000000 --- a/tests/CSSLayoutFlexWrapTest.cpp +++ /dev/null @@ -1,373 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- * - */ - -#include -#include - -TEST(CSSLayoutTest, wrap_column) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexWrap(root, CSSWrapTypeWrap); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 30); - CSSNodeStyleSetHeight(root_child0, 30); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child1, 30); - CSSNodeStyleSetHeight(root_child1, 30); - CSSNodeInsertChild(root, root_child1, 1); - - const CSSNodeRef root_child2 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child2, 30); - CSSNodeStyleSetHeight(root_child2, 30); - CSSNodeInsertChild(root, root_child2, 2); - - const CSSNodeRef root_child3 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child3, 30); - CSSNodeStyleSetHeight(root_child3, 30); - CSSNodeInsertChild(root, root_child3, 3); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(60, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(30, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(60, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child2)); - - ASSERT_EQ(30, CSSNodeLayoutGetLeft(root_child3)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child3)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child3)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child3)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(60, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(30, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(30, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(30, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(30, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(60, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child2)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child3)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child3)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child3)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child3)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, wrap_row) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); - CSSNodeStyleSetFlexWrap(root, CSSWrapTypeWrap); - CSSNodeStyleSetWidth(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 30); - CSSNodeStyleSetHeight(root_child0, 30); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child1, 30); - CSSNodeStyleSetHeight(root_child1, 30); - CSSNodeInsertChild(root, root_child1, 1); - - const CSSNodeRef root_child2 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child2, 30); - CSSNodeStyleSetHeight(root_child2, 30); - CSSNodeInsertChild(root, root_child2, 2); - - const CSSNodeRef root_child3 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child3, 30); - CSSNodeStyleSetHeight(root_child3, 30); - CSSNodeInsertChild(root, root_child3, 3); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(60, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(30, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(60, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child2)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child3)); - ASSERT_EQ(30, CSSNodeLayoutGetTop(root_child3)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child3)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child3)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(60, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(70, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(40, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child2)); - - ASSERT_EQ(70, CSSNodeLayoutGetLeft(root_child3)); - ASSERT_EQ(30, CSSNodeLayoutGetTop(root_child3)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child3)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child3)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, wrap_row_align_items_flex_end) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); - CSSNodeStyleSetAlignItems(root, CSSAlignFlexEnd); - CSSNodeStyleSetFlexWrap(root, CSSWrapTypeWrap); - CSSNodeStyleSetWidth(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 30); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child1, 30); - CSSNodeStyleSetHeight(root_child1, 20); - CSSNodeInsertChild(root, root_child1, 1); - - const CSSNodeRef root_child2 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child2, 30); - CSSNodeStyleSetHeight(root_child2, 30); - CSSNodeInsertChild(root, root_child2, 2); - - const CSSNodeRef root_child3 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child3, 30); - CSSNodeStyleSetHeight(root_child3, 30); - CSSNodeInsertChild(root, root_child3, 3); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(60, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(20, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(30, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(20, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(60, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child2)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child3)); - ASSERT_EQ(30, CSSNodeLayoutGetTop(root_child3)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child3)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child3)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(60, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(70, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(20, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(40, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(20, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child2)); - - ASSERT_EQ(70, CSSNodeLayoutGetLeft(root_child3)); - ASSERT_EQ(30, CSSNodeLayoutGetTop(root_child3)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child3)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child3)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, wrap_row_align_items_center) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); - CSSNodeStyleSetAlignItems(root, CSSAlignCenter); - CSSNodeStyleSetFlexWrap(root, CSSWrapTypeWrap); - CSSNodeStyleSetWidth(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 30); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child1, 30); - CSSNodeStyleSetHeight(root_child1, 20); - CSSNodeInsertChild(root, root_child1, 1); - - const CSSNodeRef root_child2 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child2, 30); - CSSNodeStyleSetHeight(root_child2, 30); - CSSNodeInsertChild(root, root_child2, 2); - - const CSSNodeRef root_child3 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child3, 30); - CSSNodeStyleSetHeight(root_child3, 30); - CSSNodeInsertChild(root, root_child3, 3); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(60, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(30, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(5, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(20, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(60, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child2)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child3)); - ASSERT_EQ(30, CSSNodeLayoutGetTop(root_child3)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child3)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child3)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(60, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(70, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(40, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(5, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(20, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child2)); - - ASSERT_EQ(70, CSSNodeLayoutGetLeft(root_child3)); - ASSERT_EQ(30, CSSNodeLayoutGetTop(root_child3)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child3)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child3)); - - CSSNodeFreeRecursive(root); -} diff --git a/tests/CSSLayoutJustifyContentTest.cpp b/tests/CSSLayoutJustifyContentTest.cpp deleted file mode 100644 index dde60e7d..00000000 --- a/tests/CSSLayoutJustifyContentTest.cpp +++ /dev/null @@ -1,718 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- * - */ - -#include -#include - -TEST(CSSLayoutTest, justify_content_row_flex_start) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); - CSSNodeStyleSetWidth(root, 102); - CSSNodeStyleSetHeight(root, 102); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child1, 10); - CSSNodeInsertChild(root, root_child1, 1); - - const CSSNodeRef root_child2 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child2, 10); - CSSNodeInsertChild(root, root_child2, 2); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(20, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(92, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(82, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(72, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, justify_content_row_flex_end) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); - CSSNodeStyleSetJustifyContent(root, CSSJustifyFlexEnd); - CSSNodeStyleSetWidth(root, 102); - CSSNodeStyleSetHeight(root, 102); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child1, 10); - CSSNodeInsertChild(root, root_child1, 1); - - const CSSNodeRef root_child2 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child2, 10); - CSSNodeInsertChild(root, root_child2, 2); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(72, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(82, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(92, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(20, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, justify_content_row_center) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); - CSSNodeStyleSetJustifyContent(root, CSSJustifyCenter); - CSSNodeStyleSetWidth(root, 102); - CSSNodeStyleSetHeight(root, 102); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child1, 10); - CSSNodeInsertChild(root, root_child1, 1); - - const CSSNodeRef root_child2 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child2, 10); - CSSNodeInsertChild(root, root_child2, 2); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(36, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(46, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(56, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(56, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(46, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(36, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, justify_content_row_space_between) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); - CSSNodeStyleSetJustifyContent(root, CSSJustifySpaceBetween); - CSSNodeStyleSetWidth(root, 102); - CSSNodeStyleSetHeight(root, 102); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child1, 10); - CSSNodeInsertChild(root, root_child1, 1); - - const CSSNodeRef root_child2 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child2, 10); - CSSNodeInsertChild(root, root_child2, 2); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(46, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(92, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(92, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(46, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, justify_content_row_space_around) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); - CSSNodeStyleSetJustifyContent(root, CSSJustifySpaceAround); - CSSNodeStyleSetWidth(root, 102); - CSSNodeStyleSetHeight(root, 102); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child1, 10); - CSSNodeInsertChild(root, root_child1, 1); - - const CSSNodeRef root_child2 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child2, 10); - CSSNodeInsertChild(root, root_child2, 2); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(12, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(46, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(80, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(80, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(46, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(12, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, justify_content_column_flex_start) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetWidth(root, 102); - CSSNodeStyleSetHeight(root, 102); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeInsertChild(root, root_child1, 1); - - const CSSNodeRef root_child2 = CSSNodeNew(); - CSSNodeStyleSetHeight(root_child2, 10); - CSSNodeInsertChild(root, root_child2, 2); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, justify_content_column_flex_end) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetJustifyContent(root, CSSJustifyFlexEnd); - CSSNodeStyleSetWidth(root, 102); - CSSNodeStyleSetHeight(root, 102); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetHeight(root_child1, 10); - CSSNodeInsertChild(root, root_child1, 1); - - const CSSNodeRef root_child2 = CSSNodeNew(); - CSSNodeStyleSetHeight(root_child2, 10); - CSSNodeInsertChild(root, root_child2, 2); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(72, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(82, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(92, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(72, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(82, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(92, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, justify_content_column_center) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetJustifyContent(root, CSSJustifyCenter); - CSSNodeStyleSetWidth(root, 102); - CSSNodeStyleSetHeight(root, 102); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetHeight(root_child1, 10); - CSSNodeInsertChild(root, root_child1, 1); - - const CSSNodeRef root_child2 = CSSNodeNew(); - CSSNodeStyleSetHeight(root_child2, 10); - CSSNodeInsertChild(root, root_child2, 2); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(36, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(46, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(56, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(36, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(46, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(56, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, justify_content_column_space_between) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetJustifyContent(root, CSSJustifySpaceBetween); - CSSNodeStyleSetWidth(root, 102); - CSSNodeStyleSetHeight(root, 102); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetHeight(root_child1, 10); - CSSNodeInsertChild(root, root_child1, 1); - - const CSSNodeRef root_child2 = CSSNodeNew(); - CSSNodeStyleSetHeight(root_child2, 10); - CSSNodeInsertChild(root, root_child2, 2); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(46, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(92, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(46, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(92, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, justify_content_column_space_around) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetJustifyContent(root, CSSJustifySpaceAround); - CSSNodeStyleSetWidth(root, 102); - CSSNodeStyleSetHeight(root, 102); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetHeight(root_child1, 10); - CSSNodeInsertChild(root, root_child1, 1); - - const CSSNodeRef root_child2 = CSSNodeNew(); - CSSNodeStyleSetHeight(root_child2, 10); - CSSNodeInsertChild(root, root_child2, 2); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(12, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(46, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(80, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(102, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(12, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(46, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(80, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(102, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeFreeRecursive(root); -} diff --git a/tests/CSSLayoutMarginTest.cpp b/tests/CSSLayoutMarginTest.cpp deleted file mode 100644 index 1a504390..00000000 --- a/tests/CSSLayoutMarginTest.cpp +++ /dev/null @@ -1,451 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
-
- -
-
-
-
- * - */ - -#include -#include - -TEST(CSSLayoutTest, margin_start) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetMargin(root_child0, CSSEdgeStart, 10); - CSSNodeStyleSetWidth(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(80, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, margin_top) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetMargin(root_child0, CSSEdgeTop, 10); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, margin_end) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); - CSSNodeStyleSetJustifyContent(root, CSSJustifyFlexEnd); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetMargin(root_child0, CSSEdgeEnd, 10); - CSSNodeStyleSetWidth(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(80, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, margin_bottom) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetJustifyContent(root, CSSJustifyFlexEnd); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetMargin(root_child0, CSSEdgeBottom, 10); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(80, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(80, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, margin_and_flex_row) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child0, 1); - CSSNodeStyleSetMargin(root_child0, CSSEdgeStart, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(90, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(90, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, margin_and_flex_column) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child0, 1); - CSSNodeStyleSetMargin(root_child0, CSSEdgeTop, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(90, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(90, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, margin_and_stretch_row) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child0, 1); - CSSNodeStyleSetMargin(root_child0, CSSEdgeTop, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(90, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(90, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, margin_and_stretch_column) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child0, 1); - CSSNodeStyleSetMargin(root_child0, CSSEdgeStart, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(90, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(90, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, margin_with_sibling_row) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child0, 1); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child1, 1); - CSSNodeInsertChild(root, root_child1, 1); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(50, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child1)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(50, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child1)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, margin_with_sibling_column) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child0, 1); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child1, 1); - CSSNodeInsertChild(root, root_child1, 1); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(50, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(50, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(50, CSSNodeLayoutGetHeight(root_child1)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(50, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(50, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(50, CSSNodeLayoutGetHeight(root_child1)); - - CSSNodeFreeRecursive(root); -} diff --git a/tests/CSSLayoutMeasureCacheTest.cpp b/tests/CSSLayoutMeasureCacheTest.cpp deleted file mode 100644 index b2b90bbc..00000000 --- a/tests/CSSLayoutMeasureCacheTest.cpp +++ /dev/null @@ -1,152 +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 -#include - -static CSSSize _measureMax(CSSNodeRef node, - float width, - CSSMeasureMode widthMode, - float height, - CSSMeasureMode heightMode) { - - int *measureCount = (int *)CSSNodeGetContext(node); - *measureCount = *measureCount + 1; - return CSSSize { - .width = widthMode == CSSMeasureModeUndefined ? 10 : width, - .height = heightMode == CSSMeasureModeUndefined ? 10 : height, - }; -} - -static CSSSize _measureMin(CSSNodeRef node, - float width, - CSSMeasureMode widthMode, - float height, - CSSMeasureMode heightMode) { - - int *measureCount = (int *)CSSNodeGetContext(node); - *measureCount = *measureCount + 1; - return CSSSize { - .width = widthMode == CSSMeasureModeUndefined || (widthMode == CSSMeasureModeAtMost && width > 10) ? 10 : width, - .height = heightMode == CSSMeasureModeUndefined || (heightMode == CSSMeasureModeAtMost && height > 10) ? 10 : height, - }; -} - -TEST(CSSLayoutTest, measure_once_single_flexible_child) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); - CSSNodeStyleSetAlignItems(root, CSSAlignFlexStart); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - int measureCount = 0; - CSSNodeSetContext(root_child0, &measureCount); - CSSNodeSetMeasureFunc(root_child0, _measureMax); - CSSNodeStyleSetFlexGrow(root_child0, 1); - CSSNodeInsertChild(root, root_child0, 0); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(1, measureCount); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, remeasure_text_node_height_change) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetAlignItems(root, CSSAlignFlexStart); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeSetIsTextnode(root_child0, true); - CSSNodeStyleSetFlexGrow(root_child0, 1); - int measureCount = 0; - CSSNodeSetContext(root_child0, &measureCount); - CSSNodeSetMeasureFunc(root_child0, _measureMax); - CSSNodeInsertChild(root, root_child0, 0); - - CSSNodeCalculateLayout(root, 100, 10, CSSDirectionLTR); - CSSNodeCalculateLayout(root, 100, 20, CSSDirectionLTR); - - ASSERT_EQ(1, measureCount); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, remeasure_with_same_exact_width_larger_than_needed_height) { - const CSSNodeRef root = CSSNodeNew(); - - const CSSNodeRef root_child0 = CSSNodeNew(); - int measureCount = 0; - CSSNodeSetContext(root_child0, &measureCount); - CSSNodeSetMeasureFunc(root_child0, _measureMin); - CSSNodeInsertChild(root, root_child0, 0); - - CSSNodeCalculateLayout(root, 100, 100, CSSDirectionLTR); - CSSNodeCalculateLayout(root, 100, 50, CSSDirectionLTR); - - ASSERT_EQ(1, measureCount); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, remeasure_with_same_atmost_width_larger_than_needed_height) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetAlignItems(root, CSSAlignFlexStart); - - const CSSNodeRef root_child0 = CSSNodeNew(); - int measureCount = 0; - CSSNodeSetContext(root_child0, &measureCount); - CSSNodeSetMeasureFunc(root_child0, _measureMin); - CSSNodeInsertChild(root, root_child0, 0); - - CSSNodeCalculateLayout(root, 100, 100, CSSDirectionLTR); - CSSNodeCalculateLayout(root, 100, 50, CSSDirectionLTR); - - ASSERT_EQ(1, measureCount); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, remeasure_with_computed_width_larger_than_needed_height) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetAlignItems(root, CSSAlignFlexStart); - - const CSSNodeRef root_child0 = CSSNodeNew(); - int measureCount = 0; - CSSNodeSetContext(root_child0, &measureCount); - CSSNodeSetMeasureFunc(root_child0, _measureMin); - CSSNodeInsertChild(root, root_child0, 0); - - CSSNodeCalculateLayout(root, 100, 100, CSSDirectionLTR); - CSSNodeStyleSetAlignItems(root, CSSAlignStretch); - CSSNodeCalculateLayout(root, 10, 50, CSSDirectionLTR); - - ASSERT_EQ(1, measureCount); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, remeasure_with_atmost_computed_width_undefined_height) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetAlignItems(root, CSSAlignFlexStart); - - const CSSNodeRef root_child0 = CSSNodeNew(); - int measureCount = 0; - CSSNodeSetContext(root_child0, &measureCount); - CSSNodeSetMeasureFunc(root_child0, _measureMin); - CSSNodeInsertChild(root, root_child0, 0); - - CSSNodeCalculateLayout(root, 100, CSSUndefined, CSSDirectionLTR); - CSSNodeCalculateLayout(root, 10, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(1, measureCount); - - CSSNodeFreeRecursive(root); -} diff --git a/tests/CSSLayoutMeasureModeTest.cpp b/tests/CSSLayoutMeasureModeTest.cpp deleted file mode 100644 index 1f091068..00000000 --- a/tests/CSSLayoutMeasureModeTest.cpp +++ /dev/null @@ -1,323 +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 -#include - -struct _MeasureConstraint { - float width; - CSSMeasureMode widthMode; - float height; - CSSMeasureMode heightMode; -}; - -struct _MeasureConstraintList { - uint32_t length; - struct _MeasureConstraint *constraints; -}; - -static CSSSize _measure(CSSNodeRef node, - float width, - CSSMeasureMode widthMode, - float height, - CSSMeasureMode heightMode) { - struct _MeasureConstraintList *constraintList = (struct _MeasureConstraintList *)CSSNodeGetContext(node); - struct _MeasureConstraint *constraints = constraintList->constraints; - uint32_t currentIndex = constraintList->length; - (&constraints[currentIndex])->width = width; - (&constraints[currentIndex])->widthMode = widthMode; - (&constraints[currentIndex])->height = height; - (&constraints[currentIndex])->heightMode = heightMode; - constraintList->length = currentIndex + 1; - - return CSSSize { - .width = widthMode == CSSMeasureModeUndefined ? 10 : width, - .height = heightMode == CSSMeasureModeUndefined ? 10 : width, - }; -} - -TEST(CSSLayoutTest, exactly_measure_stretched_child_column) { - struct _MeasureConstraintList constraintList = _MeasureConstraintList { - .length = 0, - .constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)), - }; - - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeSetContext(root_child0, &constraintList); - CSSNodeSetMeasureFunc(root_child0, _measure); - CSSNodeInsertChild(root, root_child0, 0); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(1, constraintList.length); - - ASSERT_EQ(100, constraintList.constraints[0].width); - ASSERT_EQ(CSSMeasureModeExactly, constraintList.constraints[0].widthMode); - - free(constraintList.constraints); - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, exactly_measure_stretched_child_row) { - struct _MeasureConstraintList constraintList = _MeasureConstraintList { - .length = 0, - .constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)), - }; - - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeSetContext(root_child0, &constraintList); - CSSNodeSetMeasureFunc(root_child0, _measure); - CSSNodeInsertChild(root, root_child0, 0); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(1, constraintList.length); - - ASSERT_EQ(100, constraintList.constraints[0].height); - ASSERT_EQ(CSSMeasureModeExactly, constraintList.constraints[0].heightMode); - - free(constraintList.constraints); - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, at_most_main_axis_column) { - struct _MeasureConstraintList constraintList = _MeasureConstraintList { - .length = 0, - .constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)), - }; - - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeSetContext(root_child0, &constraintList); - CSSNodeSetMeasureFunc(root_child0, _measure); - CSSNodeInsertChild(root, root_child0, 0); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(1, constraintList.length); - - ASSERT_EQ(100, constraintList.constraints[0].height); - ASSERT_EQ(CSSMeasureModeAtMost, constraintList.constraints[0].heightMode); - - free(constraintList.constraints); - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, at_most_cross_axis_column) { - struct _MeasureConstraintList constraintList = _MeasureConstraintList { - .length = 0, - .constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)), - }; - - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetAlignItems(root, CSSAlignFlexStart); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeSetContext(root_child0, &constraintList); - CSSNodeSetMeasureFunc(root_child0, _measure); - CSSNodeInsertChild(root, root_child0, 0); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(1, constraintList.length); - - ASSERT_EQ(100, constraintList.constraints[0].width); - ASSERT_EQ(CSSMeasureModeAtMost, constraintList.constraints[0].widthMode); - - free(constraintList.constraints); - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, at_most_main_axis_row) { - struct _MeasureConstraintList constraintList = _MeasureConstraintList { - .length = 0, - .constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)), - }; - - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeSetContext(root_child0, &constraintList); - CSSNodeSetMeasureFunc(root_child0, _measure); - CSSNodeInsertChild(root, root_child0, 0); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(1, constraintList.length); - - ASSERT_EQ(100, constraintList.constraints[0].width); - ASSERT_EQ(CSSMeasureModeAtMost, constraintList.constraints[0].widthMode); - - free(constraintList.constraints); - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, at_most_cross_axis_row) { - struct _MeasureConstraintList constraintList = _MeasureConstraintList { - .length = 0, - .constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)), - }; - - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); - CSSNodeStyleSetAlignItems(root, CSSAlignFlexStart); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeSetContext(root_child0, &constraintList); - CSSNodeSetMeasureFunc(root_child0, _measure); - CSSNodeInsertChild(root, root_child0, 0); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(1, constraintList.length); - - ASSERT_EQ(100, constraintList.constraints[0].height); - ASSERT_EQ(CSSMeasureModeAtMost, constraintList.constraints[0].heightMode); - - free(constraintList.constraints); - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, flex_child) { - struct _MeasureConstraintList constraintList = _MeasureConstraintList { - .length = 0, - .constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)), - }; - - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child0, 1); - CSSNodeSetContext(root_child0, &constraintList); - CSSNodeSetMeasureFunc(root_child0, _measure); - CSSNodeInsertChild(root, root_child0, 0); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(2, constraintList.length); - - ASSERT_EQ(100, constraintList.constraints[0].height); - ASSERT_EQ(CSSMeasureModeAtMost, constraintList.constraints[0].heightMode); - - ASSERT_EQ(100, constraintList.constraints[1].height); - ASSERT_EQ(CSSMeasureModeExactly, constraintList.constraints[1].heightMode); - - free(constraintList.constraints); - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, flex_child_with_flex_basis) { - struct _MeasureConstraintList constraintList = _MeasureConstraintList { - .length = 0, - .constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)), - }; - - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child0, 1); - CSSNodeStyleSetFlexBasis(root_child0, 0); - CSSNodeSetContext(root_child0, &constraintList); - CSSNodeSetMeasureFunc(root_child0, _measure); - CSSNodeInsertChild(root, root_child0, 0); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(1, constraintList.length); - - ASSERT_EQ(100, constraintList.constraints[0].height); - ASSERT_EQ(CSSMeasureModeExactly, constraintList.constraints[0].heightMode); - - free(constraintList.constraints); - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, overflow_scroll_column) { - struct _MeasureConstraintList constraintList = _MeasureConstraintList { - .length = 0, - .constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)), - }; - - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetAlignItems(root, CSSAlignFlexStart); - CSSNodeStyleSetOverflow(root, CSSOverflowScroll); - CSSNodeStyleSetHeight(root, 100); - CSSNodeStyleSetWidth(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeSetContext(root_child0, &constraintList); - CSSNodeSetMeasureFunc(root_child0, _measure); - CSSNodeInsertChild(root, root_child0, 0); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(1, constraintList.length); - - ASSERT_EQ(100, constraintList.constraints[0].width); - ASSERT_EQ(CSSMeasureModeAtMost, constraintList.constraints[0].widthMode); - - ASSERT_TRUE(CSSValueIsUndefined(constraintList.constraints[0].height)); - ASSERT_EQ(CSSMeasureModeUndefined, constraintList.constraints[0].heightMode); - - free(constraintList.constraints); - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, overflow_scroll_row) { - struct _MeasureConstraintList constraintList = _MeasureConstraintList { - .length = 0, - .constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)), - }; - - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetAlignItems(root, CSSAlignFlexStart); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); - CSSNodeStyleSetOverflow(root, CSSOverflowScroll); - CSSNodeStyleSetHeight(root, 100); - CSSNodeStyleSetWidth(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeSetContext(root_child0, &constraintList); - CSSNodeSetMeasureFunc(root_child0, _measure); - CSSNodeInsertChild(root, root_child0, 0); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(1, constraintList.length); - - ASSERT_TRUE(CSSValueIsUndefined(constraintList.constraints[0].width)); - ASSERT_EQ(CSSMeasureModeUndefined, constraintList.constraints[0].widthMode); - - ASSERT_EQ(100, constraintList.constraints[0].height); - ASSERT_EQ(CSSMeasureModeAtMost, constraintList.constraints[0].heightMode); - - free(constraintList.constraints); - CSSNodeFreeRecursive(root); -} diff --git a/tests/CSSLayoutMeasureTest.cpp b/tests/CSSLayoutMeasureTest.cpp deleted file mode 100644 index e8362d0d..00000000 --- a/tests/CSSLayoutMeasureTest.cpp +++ /dev/null @@ -1,44 +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 -#include - -static CSSSize _measure(CSSNodeRef node, - float width, - CSSMeasureMode widthMode, - float height, - CSSMeasureMode heightMode) { - int *measureCount = (int *)CSSNodeGetContext(node); - *measureCount = *measureCount + 1; - return CSSSize { - .width = widthMode == CSSMeasureModeUndefined ? 10 : width, - .height = heightMode == CSSMeasureModeUndefined ? 10 : width, - }; -} - -TEST(CSSLayoutTest, ignore_measure_on_non_leaf_node) { - const CSSNodeRef root = CSSNodeNew(); - int measureCount = 0; - CSSNodeSetContext(root, &measureCount); - CSSNodeSetMeasureFunc(root, _measure); - - const CSSNodeRef root_child0 = CSSNodeNew(); - int childMeasureCount = 0; - CSSNodeSetContext(root_child0, &childMeasureCount); - CSSNodeSetMeasureFunc(root_child0, _measure); - CSSNodeInsertChild(root, root_child0, 0); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, measureCount); - ASSERT_EQ(1, childMeasureCount); - - CSSNodeFreeRecursive(root); -} diff --git a/tests/CSSLayoutMinMaxDimensionTest.cpp b/tests/CSSLayoutMinMaxDimensionTest.cpp deleted file mode 100644 index b58f22db..00000000 --- a/tests/CSSLayoutMinMaxDimensionTest.cpp +++ /dev/null @@ -1,365 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
-
- -
-
-
- -
-
-
-
- -
-
-
-
- -
-
-
- -
-
-
- -
-
-
-
-
- * - */ - -#include -#include - -TEST(CSSLayoutTest, max_width) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetMaxWidth(root_child0, 50); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(50, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, max_height) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 10); - CSSNodeStyleSetMaxHeight(root_child0, 50); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(50, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(90, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(50, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, min_height) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child0, 1); - CSSNodeStyleSetMinHeight(root_child0, 60); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child1, 1); - CSSNodeInsertChild(root, root_child1, 1); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(80, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(80, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(20, CSSNodeLayoutGetHeight(root_child1)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(80, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(80, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(20, CSSNodeLayoutGetHeight(root_child1)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, min_width) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child0, 1); - CSSNodeStyleSetMinWidth(root_child0, 60); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child1, 1); - CSSNodeInsertChild(root, root_child1, 1); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(80, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(80, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(20, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child1)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(20, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(80, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(20, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root_child1)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, justify_content_min_max) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetJustifyContent(root, CSSJustifyCenter); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetMinHeight(root, 100); - CSSNodeStyleSetMaxHeight(root, 200); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 60); - CSSNodeStyleSetHeight(root_child0, 60); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(20, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(60, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(60, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(40, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(20, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(60, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(60, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, align_items_min_max) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetAlignItems(root, CSSAlignCenter); - CSSNodeStyleSetMinWidth(root, 100); - CSSNodeStyleSetMaxWidth(root, 200); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 60); - CSSNodeStyleSetHeight(root_child0, 60); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(20, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(60, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(60, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(20, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(60, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(60, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, justify_content_overflow_min_max) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetJustifyContent(root, CSSJustifyCenter); - CSSNodeStyleSetMinHeight(root, 100); - CSSNodeStyleSetMaxHeight(root, 110); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 50); - CSSNodeStyleSetHeight(root_child0, 50); - CSSNodeInsertChild(root, root_child0, 0); - - const CSSNodeRef root_child1 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child1, 50); - CSSNodeStyleSetHeight(root_child1, 50); - CSSNodeInsertChild(root, root_child1, 1); - - const CSSNodeRef root_child2 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child2, 50); - CSSNodeStyleSetHeight(root_child2, 50); - CSSNodeInsertChild(root, root_child2, 2); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(110, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(-20, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(50, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(30, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(50, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(80, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(50, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(110, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(-20, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(50, CSSNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(30, CSSNodeLayoutGetTop(root_child1)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(50, CSSNodeLayoutGetHeight(root_child1)); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child2)); - ASSERT_EQ(80, CSSNodeLayoutGetTop(root_child2)); - ASSERT_EQ(50, CSSNodeLayoutGetWidth(root_child2)); - ASSERT_EQ(50, CSSNodeLayoutGetHeight(root_child2)); - - CSSNodeFreeRecursive(root); -} diff --git a/tests/CSSLayoutPaddingTest.cpp b/tests/CSSLayoutPaddingTest.cpp deleted file mode 100644 index 91ed3ddc..00000000 --- a/tests/CSSLayoutPaddingTest.cpp +++ /dev/null @@ -1,216 +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. - */ - -/** - * @Generated by gentest/gentest.sh with the following input - * -
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- * - */ - -#include -#include - -TEST(CSSLayoutTest, padding_no_size) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetPadding(root, CSSEdgeLeft, 10); - CSSNodeStyleSetPadding(root, CSSEdgeTop, 10); - CSSNodeStyleSetPadding(root, CSSEdgeRight, 10); - CSSNodeStyleSetPadding(root, CSSEdgeBottom, 10); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(20, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(20, CSSNodeLayoutGetHeight(root)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(20, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(20, CSSNodeLayoutGetHeight(root)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, padding_container_match_child) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetPadding(root, CSSEdgeLeft, 10); - CSSNodeStyleSetPadding(root, CSSEdgeTop, 10); - CSSNodeStyleSetPadding(root, CSSEdgeRight, 10); - CSSNodeStyleSetPadding(root, CSSEdgeBottom, 10); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 10); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(30, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(30, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, padding_flex_child) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetPadding(root, CSSEdgeLeft, 10); - CSSNodeStyleSetPadding(root, CSSEdgeTop, 10); - CSSNodeStyleSetPadding(root, CSSEdgeRight, 10); - CSSNodeStyleSetPadding(root, CSSEdgeBottom, 10); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetFlexGrow(root_child0, 1); - CSSNodeStyleSetWidth(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(80, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(80, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(80, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, padding_stretch_child) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetPadding(root, CSSEdgeLeft, 10); - CSSNodeStyleSetPadding(root, CSSEdgeTop, 10); - CSSNodeStyleSetPadding(root, CSSEdgeRight, 10); - CSSNodeStyleSetPadding(root, CSSEdgeBottom, 10); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(80, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(80, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} - -TEST(CSSLayoutTest, padding_center_child) { - const CSSNodeRef root = CSSNodeNew(); - CSSNodeStyleSetJustifyContent(root, CSSJustifyCenter); - CSSNodeStyleSetAlignItems(root, CSSAlignCenter); - CSSNodeStyleSetPadding(root, CSSEdgeStart, 10); - CSSNodeStyleSetPadding(root, CSSEdgeEnd, 20); - CSSNodeStyleSetPadding(root, CSSEdgeBottom, 20); - CSSNodeStyleSetWidth(root, 100); - CSSNodeStyleSetHeight(root, 100); - - const CSSNodeRef root_child0 = CSSNodeNew(); - CSSNodeStyleSetWidth(root_child0, 10); - CSSNodeStyleSetHeight(root_child0, 10); - CSSNodeInsertChild(root, root_child0, 0); - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(40, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(35, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); - - ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); - ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); - ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); - ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); - - ASSERT_EQ(50, CSSNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(35, CSSNodeLayoutGetTop(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); - - CSSNodeFreeRecursive(root); -} diff --git a/tests/YGAbsolutePositionTest.cpp b/tests/YGAbsolutePositionTest.cpp new file mode 100644 index 00000000..c5a3891b --- /dev/null +++ b/tests/YGAbsolutePositionTest.cpp @@ -0,0 +1,294 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGAbsolutePositionTest.html + +#include +#include + +TEST(YogaTest, absolute_layout_width_height_start_top) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); + YGNodeStyleSetPosition(root_child0, YGEdgeStart, 10); + YGNodeStyleSetPosition(root_child0, YGEdgeTop, 10); + YGNodeStyleSetWidth(root_child0, 10); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, absolute_layout_width_height_end_bottom) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); + YGNodeStyleSetPosition(root_child0, YGEdgeEnd, 10); + YGNodeStyleSetPosition(root_child0, YGEdgeBottom, 10); + YGNodeStyleSetWidth(root_child0, 10); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, absolute_layout_start_top_end_bottom) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); + YGNodeStyleSetPosition(root_child0, YGEdgeStart, 10); + YGNodeStyleSetPosition(root_child0, YGEdgeTop, 10); + YGNodeStyleSetPosition(root_child0, YGEdgeEnd, 10); + YGNodeStyleSetPosition(root_child0, YGEdgeBottom, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, absolute_layout_width_height_start_top_end_bottom) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); + YGNodeStyleSetPosition(root_child0, YGEdgeStart, 10); + YGNodeStyleSetPosition(root_child0, YGEdgeTop, 10); + YGNodeStyleSetPosition(root_child0, YGEdgeEnd, 10); + YGNodeStyleSetPosition(root_child0, YGEdgeBottom, 10); + YGNodeStyleSetWidth(root_child0, 10); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, do_not_clamp_height_of_absolute_node_to_height_of_its_overflow_hidden_parent) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetOverflow(root, YGOverflowHidden); + YGNodeStyleSetWidth(root, 50); + YGNodeStyleSetHeight(root, 50); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); + YGNodeStyleSetPosition(root_child0, YGEdgeStart, 0); + YGNodeStyleSetPosition(root_child0, YGEdgeTop, 0); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child0_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0_child0, 100); + YGNodeStyleSetHeight(root_child0_child0, 100); + YGNodeInsertChild(root_child0, root_child0_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(-50, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, absolute_layout_within_border) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetMargin(root, YGEdgeLeft, 10); + YGNodeStyleSetMargin(root, YGEdgeTop, 10); + YGNodeStyleSetMargin(root, YGEdgeRight, 10); + YGNodeStyleSetMargin(root, YGEdgeBottom, 10); + YGNodeStyleSetPadding(root, YGEdgeLeft, 10); + YGNodeStyleSetPadding(root, YGEdgeTop, 10); + YGNodeStyleSetPadding(root, YGEdgeRight, 10); + YGNodeStyleSetPadding(root, YGEdgeBottom, 10); + YGNodeStyleSetBorder(root, YGEdgeLeft, 10); + YGNodeStyleSetBorder(root, YGEdgeTop, 10); + YGNodeStyleSetBorder(root, YGEdgeRight, 10); + YGNodeStyleSetBorder(root, YGEdgeBottom, 10); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); + YGNodeStyleSetPosition(root_child0, YGEdgeLeft, 0); + YGNodeStyleSetPosition(root_child0, YGEdgeTop, 0); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeStyleSetHeight(root_child0, 50); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetPositionType(root_child1, YGPositionTypeAbsolute); + YGNodeStyleSetPosition(root_child1, YGEdgeRight, 0); + YGNodeStyleSetPosition(root_child1, YGEdgeBottom, 0); + YGNodeStyleSetWidth(root_child1, 50); + YGNodeStyleSetHeight(root_child1, 50); + YGNodeInsertChild(root, root_child1, 1); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); + + YGNodeFreeRecursive(root); +} diff --git a/tests/YGAlignContentTest.cpp b/tests/YGAlignContentTest.cpp new file mode 100644 index 00000000..6c2aaa40 --- /dev/null +++ b/tests/YGAlignContentTest.cpp @@ -0,0 +1,399 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGAlignContentTest.html + +#include +#include + +TEST(YogaTest, align_content_flex_start) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetWidth(root_child1, 50); + YGNodeStyleSetHeight(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 50); + YGNodeStyleSetHeight(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + + const YGNodeRef root_child3 = YGNodeNew(); + YGNodeStyleSetWidth(root_child3, 50); + YGNodeStyleSetHeight(root_child3, 10); + YGNodeInsertChild(root, root_child3, 3); + + const YGNodeRef root_child4 = YGNodeNew(); + YGNodeStyleSetWidth(root_child4, 50); + YGNodeStyleSetHeight(root_child4, 10); + YGNodeInsertChild(root, root_child4, 4); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, align_content_flex_end) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignContent(root, YGAlignFlexEnd); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetWidth(root_child1, 50); + YGNodeStyleSetHeight(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 50); + YGNodeStyleSetHeight(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + + const YGNodeRef root_child3 = YGNodeNew(); + YGNodeStyleSetWidth(root_child3, 50); + YGNodeStyleSetHeight(root_child3, 10); + YGNodeInsertChild(root, root_child3, 3); + + const YGNodeRef root_child4 = YGNodeNew(); + YGNodeStyleSetWidth(root_child4, 50); + YGNodeStyleSetHeight(root_child4, 10); + YGNodeInsertChild(root, root_child4, 4); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, align_content_center) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignContent(root, YGAlignCenter); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetWidth(root_child1, 50); + YGNodeStyleSetHeight(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 50); + YGNodeStyleSetHeight(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + + const YGNodeRef root_child3 = YGNodeNew(); + YGNodeStyleSetWidth(root_child3, 50); + YGNodeStyleSetHeight(root_child3, 10); + YGNodeInsertChild(root, root_child3, 3); + + const YGNodeRef root_child4 = YGNodeNew(); + YGNodeStyleSetWidth(root_child4, 50); + YGNodeStyleSetHeight(root_child4, 10); + YGNodeInsertChild(root, root_child4, 4); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, align_content_stretch) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignContent(root, YGAlignStretch); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetWidth(root_child1, 50); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 50); + YGNodeInsertChild(root, root_child2, 2); + + const YGNodeRef root_child3 = YGNodeNew(); + YGNodeStyleSetWidth(root_child3, 50); + YGNodeInsertChild(root, root_child3, 3); + + const YGNodeRef root_child4 = YGNodeNew(); + YGNodeStyleSetWidth(root_child4, 50); + YGNodeInsertChild(root, root_child4, 4); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child4)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child4)); + + YGNodeFreeRecursive(root); +} diff --git a/tests/YGAlignItemsTest.cpp b/tests/YGAlignItemsTest.cpp new file mode 100644 index 00000000..e80ae1d4 --- /dev/null +++ b/tests/YGAlignItemsTest.cpp @@ -0,0 +1,159 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGAlignItemsTest.html + +#include +#include + +TEST(YogaTest, align_items_stretch) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, align_items_center) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignCenter); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 10); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(45, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(45, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, align_items_flex_start) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 10); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, align_items_flex_end) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignFlexEnd); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 10); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} diff --git a/tests/YGAlignSelfTest.cpp b/tests/YGAlignSelfTest.cpp new file mode 100644 index 00000000..436d78b4 --- /dev/null +++ b/tests/YGAlignSelfTest.cpp @@ -0,0 +1,162 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGAlignSelfTest.html + +#include +#include + +TEST(YogaTest, align_self_center) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetAlignSelf(root_child0, YGAlignCenter); + YGNodeStyleSetWidth(root_child0, 10); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(45, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(45, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, align_self_flex_end) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetAlignSelf(root_child0, YGAlignFlexEnd); + YGNodeStyleSetWidth(root_child0, 10); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, align_self_flex_start) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetAlignSelf(root_child0, YGAlignFlexStart); + YGNodeStyleSetWidth(root_child0, 10); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, align_self_flex_end_override_flex_start) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetAlignSelf(root_child0, YGAlignFlexEnd); + YGNodeStyleSetWidth(root_child0, 10); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} diff --git a/tests/YGBorderTest.cpp b/tests/YGBorderTest.cpp new file mode 100644 index 00000000..41673414 --- /dev/null +++ b/tests/YGBorderTest.cpp @@ -0,0 +1,194 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGBorderTest.html + +#include +#include + +TEST(YogaTest, border_no_size) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetBorder(root, YGEdgeLeft, 10); + YGNodeStyleSetBorder(root, YGEdgeTop, 10); + YGNodeStyleSetBorder(root, YGEdgeRight, 10); + YGNodeStyleSetBorder(root, YGEdgeBottom, 10); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, border_container_match_child) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetBorder(root, YGEdgeLeft, 10); + YGNodeStyleSetBorder(root, YGEdgeTop, 10); + YGNodeStyleSetBorder(root, YGEdgeRight, 10); + YGNodeStyleSetBorder(root, YGEdgeBottom, 10); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 10); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, border_flex_child) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetBorder(root, YGEdgeLeft, 10); + YGNodeStyleSetBorder(root, YGEdgeTop, 10); + YGNodeStyleSetBorder(root, YGEdgeRight, 10); + YGNodeStyleSetBorder(root, YGEdgeBottom, 10); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeStyleSetWidth(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, border_stretch_child) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetBorder(root, YGEdgeLeft, 10); + YGNodeStyleSetBorder(root, YGEdgeTop, 10); + YGNodeStyleSetBorder(root, YGEdgeRight, 10); + YGNodeStyleSetBorder(root, YGEdgeBottom, 10); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, border_center_child) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetJustifyContent(root, YGJustifyCenter); + YGNodeStyleSetAlignItems(root, YGAlignCenter); + YGNodeStyleSetBorder(root, YGEdgeStart, 10); + YGNodeStyleSetBorder(root, YGEdgeEnd, 20); + YGNodeStyleSetBorder(root, YGEdgeBottom, 20); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 10); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(35, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(35, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} diff --git a/tests/YGDirtyMarkingTest.cpp b/tests/YGDirtyMarkingTest.cpp new file mode 100644 index 00000000..3888966e --- /dev/null +++ b/tests/YGDirtyMarkingTest.cpp @@ -0,0 +1,96 @@ +/** + * 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 +#include + +TEST(YogaTest, dirty_propagation) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeStyleSetHeight(root_child0, 20); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetWidth(root_child1, 50); + YGNodeStyleSetHeight(root_child1, 20); + YGNodeInsertChild(root, root_child1, 1); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + YGNodeStyleSetWidth(root_child0, 20); + + EXPECT_TRUE(YGNodeIsDirty(root_child0)); + EXPECT_FALSE(YGNodeIsDirty(root_child1)); + EXPECT_TRUE(YGNodeIsDirty(root)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + EXPECT_FALSE(YGNodeIsDirty(root_child0)); + EXPECT_FALSE(YGNodeIsDirty(root_child1)); + EXPECT_FALSE(YGNodeIsDirty(root)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, dirty_propagation_only_if_prop_changed) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeStyleSetHeight(root_child0, 20); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetWidth(root_child1, 50); + YGNodeStyleSetHeight(root_child1, 20); + YGNodeInsertChild(root, root_child1, 1); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + YGNodeStyleSetWidth(root_child0, 50); + + EXPECT_FALSE(YGNodeIsDirty(root_child0)); + EXPECT_FALSE(YGNodeIsDirty(root_child1)); + EXPECT_FALSE(YGNodeIsDirty(root)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, dirty_node_only_if_children_are_actually_removed) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetWidth(root, 50); + YGNodeStyleSetHeight(root, 50); + + const YGNodeRef child0 = YGNodeNew(); + YGNodeStyleSetWidth(child0, 50); + YGNodeStyleSetHeight(child0, 25); + YGNodeInsertChild(root, child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + const YGNodeRef child1 = YGNodeNew(); + YGNodeRemoveChild(root, child1); + EXPECT_FALSE(YGNodeIsDirty(root)); + YGNodeFree(child1); + + YGNodeRemoveChild(root, child0); + EXPECT_TRUE(YGNodeIsDirty(root)); + YGNodeFree(child0); + + YGNodeFreeRecursive(root); +} diff --git a/tests/YGEdgeTest.cpp b/tests/YGEdgeTest.cpp new file mode 100644 index 00000000..4122b11b --- /dev/null +++ b/tests/YGEdgeTest.cpp @@ -0,0 +1,163 @@ +/** + * 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 +#include + +TEST(YogaTest, start_overrides) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeStyleSetMargin(root_child0, YGEdgeStart, 10); + YGNodeStyleSetMargin(root_child0, YGEdgeLeft, 20); + YGNodeStyleSetMargin(root_child0, YGEdgeRight, 20); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetRight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetRight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, end_overrides) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeStyleSetMargin(root_child0, YGEdgeEnd, 10); + YGNodeStyleSetMargin(root_child0, YGEdgeLeft, 20); + YGNodeStyleSetMargin(root_child0, YGEdgeRight, 20); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetRight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetRight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, horizontal_overridden) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeStyleSetMargin(root_child0, YGEdgeHorizontal, 10); + YGNodeStyleSetMargin(root_child0, YGEdgeLeft, 20); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetRight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, vertical_overridden) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeStyleSetMargin(root_child0, YGEdgeVertical, 10); + YGNodeStyleSetMargin(root_child0, YGEdgeTop, 20); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetBottom(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, horizontal_overrides_all) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeStyleSetMargin(root_child0, YGEdgeHorizontal, 10); + YGNodeStyleSetMargin(root_child0, YGEdgeAll, 20); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetRight(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetBottom(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, vertical_overrides_all) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeStyleSetMargin(root_child0, YGEdgeVertical, 10); + YGNodeStyleSetMargin(root_child0, YGEdgeAll, 20); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetRight(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetBottom(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, all_overridden) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeStyleSetMargin(root_child0, YGEdgeLeft, 10); + YGNodeStyleSetMargin(root_child0, YGEdgeTop, 10); + YGNodeStyleSetMargin(root_child0, YGEdgeRight, 10); + YGNodeStyleSetMargin(root_child0, YGEdgeBottom, 10); + YGNodeStyleSetMargin(root_child0, YGEdgeAll, 20); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetRight(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetBottom(root_child0)); + + YGNodeFreeRecursive(root); +} diff --git a/tests/YGFlexDirectionTest.cpp b/tests/YGFlexDirectionTest.cpp new file mode 100644 index 00000000..b6016428 --- /dev/null +++ b/tests/YGFlexDirectionTest.cpp @@ -0,0 +1,393 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGFlexDirectionTest.html + +#include +#include + +TEST(YogaTest, flex_direction_column_no_height) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetHeight(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetHeight(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, flex_direction_row_no_width) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetWidth(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, flex_direction_column) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetHeight(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetHeight(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, flex_direction_row) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetWidth(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(70, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, flex_direction_column_reverse) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumnReverse); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetHeight(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetHeight(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(70, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(70, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, flex_direction_row_reverse) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRowReverse); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetWidth(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(70, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); +} diff --git a/tests/YGFlexTest.cpp b/tests/YGFlexTest.cpp new file mode 100644 index 00000000..559025f7 --- /dev/null +++ b/tests/YGFlexTest.cpp @@ -0,0 +1,397 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGFlexTest.html + +#include +#include + +TEST(YogaTest, flex_basis_flex_grow_column) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeStyleSetFlexBasis(root_child0, 50); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child1, 1); + YGNodeInsertChild(root, root_child1, 1); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(75, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(75, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child1)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(75, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(75, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child1)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, flex_basis_flex_grow_row) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeStyleSetFlexBasis(root_child0, 50); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child1, 1); + YGNodeInsertChild(root, root_child1, 1); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(75, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(75, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, flex_basis_flex_shrink_column) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexShrink(root_child0, 1); + YGNodeStyleSetFlexBasis(root_child0, 100); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetFlexBasis(root_child1, 50); + YGNodeInsertChild(root, root_child1, 1); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, flex_basis_flex_shrink_row) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexShrink(root_child0, 1); + YGNodeStyleSetFlexBasis(root_child0, 100); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetFlexBasis(root_child1, 50); + YGNodeInsertChild(root, root_child1, 1); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, flex_shrink_to_zero) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetHeight(root, 75); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeStyleSetHeight(root_child0, 50); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetFlexShrink(root_child1, 1); + YGNodeStyleSetWidth(root_child1, 50); + YGNodeStyleSetHeight(root_child1, 50); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 50); + YGNodeStyleSetHeight(root_child2, 50); + YGNodeInsertChild(root, root_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(75, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(75, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, flex_basis_overrides_main_size) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeStyleSetFlexBasis(root_child0, 50); + YGNodeStyleSetHeight(root_child0, 20); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child1, 1); + YGNodeStyleSetHeight(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child2, 1); + YGNodeStyleSetHeight(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, flex_grow_shrink_at_most) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child0_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0_child0, 1); + YGNodeStyleSetFlexShrink(root_child0_child0, 1); + YGNodeInsertChild(root_child0, root_child0_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0_child0)); + + YGNodeFreeRecursive(root); +} diff --git a/tests/YGFlexWrapTest.cpp b/tests/YGFlexWrapTest.cpp new file mode 100644 index 00000000..03d07a82 --- /dev/null +++ b/tests/YGFlexWrapTest.cpp @@ -0,0 +1,342 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGFlexWrapTest.html + +#include +#include + +TEST(YogaTest, wrap_column) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 30); + YGNodeStyleSetHeight(root_child0, 30); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetWidth(root_child1, 30); + YGNodeStyleSetHeight(root_child1, 30); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 30); + YGNodeStyleSetHeight(root_child2, 30); + YGNodeInsertChild(root, root_child2, 2); + + const YGNodeRef root_child3 = YGNodeNew(); + YGNodeStyleSetWidth(root_child3, 30); + YGNodeStyleSetHeight(root_child3, 30); + YGNodeInsertChild(root, root_child3, 3); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child3)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child3)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, wrap_row) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + YGNodeStyleSetWidth(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 30); + YGNodeStyleSetHeight(root_child0, 30); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetWidth(root_child1, 30); + YGNodeStyleSetHeight(root_child1, 30); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 30); + YGNodeStyleSetHeight(root_child2, 30); + YGNodeInsertChild(root, root_child2, 2); + + const YGNodeRef root_child3 = YGNodeNew(); + YGNodeStyleSetWidth(root_child3, 30); + YGNodeStyleSetHeight(root_child3, 30); + YGNodeInsertChild(root, root_child3, 3); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child3)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(70, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(70, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child3)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, wrap_row_align_items_flex_end) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetAlignItems(root, YGAlignFlexEnd); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + YGNodeStyleSetWidth(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 30); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetWidth(root_child1, 30); + YGNodeStyleSetHeight(root_child1, 20); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 30); + YGNodeStyleSetHeight(root_child2, 30); + YGNodeInsertChild(root, root_child2, 2); + + const YGNodeRef root_child3 = YGNodeNew(); + YGNodeStyleSetWidth(root_child3, 30); + YGNodeStyleSetHeight(root_child3, 30); + YGNodeInsertChild(root, root_child3, 3); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child3)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(70, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(70, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child3)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, wrap_row_align_items_center) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetAlignItems(root, YGAlignCenter); + YGNodeStyleSetFlexWrap(root, YGWrapWrap); + YGNodeStyleSetWidth(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 30); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetWidth(root_child1, 30); + YGNodeStyleSetHeight(root_child1, 20); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 30); + YGNodeStyleSetHeight(root_child2, 30); + YGNodeInsertChild(root, root_child2, 2); + + const YGNodeRef root_child3 = YGNodeNew(); + YGNodeStyleSetWidth(root_child3, 30); + YGNodeStyleSetHeight(root_child3, 30); + YGNodeInsertChild(root, root_child3, 3); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(5, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child3)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(70, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(5, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(70, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child3)); + + YGNodeFreeRecursive(root); +} diff --git a/tests/YGJustifyContentTest.cpp b/tests/YGJustifyContentTest.cpp new file mode 100644 index 00000000..b7afe1b6 --- /dev/null +++ b/tests/YGJustifyContentTest.cpp @@ -0,0 +1,655 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGJustifyContentTest.html + +#include +#include + +TEST(YogaTest, justify_content_row_flex_start) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetWidth(root, 102); + YGNodeStyleSetHeight(root, 102); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetWidth(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(92, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(82, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, justify_content_row_flex_end) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetJustifyContent(root, YGJustifyFlexEnd); + YGNodeStyleSetWidth(root, 102); + YGNodeStyleSetHeight(root, 102); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetWidth(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(82, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(92, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, justify_content_row_center) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetJustifyContent(root, YGJustifyCenter); + YGNodeStyleSetWidth(root, 102); + YGNodeStyleSetHeight(root, 102); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetWidth(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(36, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(46, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(56, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(56, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(46, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(36, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, justify_content_row_space_between) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetJustifyContent(root, YGJustifySpaceBetween); + YGNodeStyleSetWidth(root, 102); + YGNodeStyleSetHeight(root, 102); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetWidth(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(46, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(92, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(92, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(46, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, justify_content_row_space_around) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetJustifyContent(root, YGJustifySpaceAround); + YGNodeStyleSetWidth(root, 102); + YGNodeStyleSetHeight(root, 102); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetWidth(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(12, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(46, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(46, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(12, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, justify_content_column_flex_start) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 102); + YGNodeStyleSetHeight(root, 102); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetHeight(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, justify_content_column_flex_end) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetJustifyContent(root, YGJustifyFlexEnd); + YGNodeStyleSetWidth(root, 102); + YGNodeStyleSetHeight(root, 102); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetHeight(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetHeight(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(82, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(92, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(72, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(82, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(92, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, justify_content_column_center) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetJustifyContent(root, YGJustifyCenter); + YGNodeStyleSetWidth(root, 102); + YGNodeStyleSetHeight(root, 102); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetHeight(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetHeight(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(36, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(46, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(56, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(36, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(46, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(56, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, justify_content_column_space_between) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetJustifyContent(root, YGJustifySpaceBetween); + YGNodeStyleSetWidth(root, 102); + YGNodeStyleSetHeight(root, 102); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetHeight(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetHeight(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(46, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(92, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(46, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(92, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, justify_content_column_space_around) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetJustifyContent(root, YGJustifySpaceAround); + YGNodeStyleSetWidth(root, 102); + YGNodeStyleSetHeight(root, 102); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetHeight(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetHeight(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(12, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(46, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(12, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(46, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); +} diff --git a/tests/YGLayoutAspectRatioTest.cpp b/tests/YGLayoutAspectRatioTest.cpp new file mode 100644 index 00000000..22846c9b --- /dev/null +++ b/tests/YGLayoutAspectRatioTest.cpp @@ -0,0 +1,407 @@ +/** + * 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 +#include + +static YGSize _measure(YGNodeRef node, + float width, + YGMeasureMode widthMode, + float height, + YGMeasureMode heightMode) { + return YGSize { + .width = widthMode == YGMeasureModeExactly ? width : 50, + .height = heightMode == YGMeasureModeExactly ? height : 50, + }; +} + +TEST(YogaTest, aspect_ratio_cross_defined) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeStyleSetAspectRatio(root_child0, 1); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, aspect_ratio_main_defined) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetHeight(root_child0, 50); + YGNodeStyleSetAspectRatio(root_child0, 1); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, aspect_ratio_both_dimensions_defined) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetHeight(root_child0, 50); + YGNodeStyleSetAspectRatio(root_child0, 1); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, aspect_ratio_align_stretch) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetAspectRatio(root_child0, 1); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, aspect_ratio_flex_grow) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetHeight(root_child0, 50); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeStyleSetAspectRatio(root_child0, 1); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, aspect_ratio_flex_shrink) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetHeight(root_child0, 150); + YGNodeStyleSetFlexShrink(root_child0, 1); + YGNodeStyleSetAspectRatio(root_child0, 1); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, aspect_ratio_basis) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexBasis(root_child0, 50); + YGNodeStyleSetAspectRatio(root_child0, 1); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, aspect_ratio_absolute_layout_width_defined) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); + YGNodeStyleSetPosition(root_child0, YGEdgeLeft, 0); + YGNodeStyleSetPosition(root_child0, YGEdgeTop, 0); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeStyleSetAspectRatio(root_child0, 1); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, aspect_ratio_absolute_layout_height_defined) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); + YGNodeStyleSetPosition(root_child0, YGEdgeLeft, 0); + YGNodeStyleSetPosition(root_child0, YGEdgeTop, 0); + YGNodeStyleSetHeight(root_child0, 50); + YGNodeStyleSetAspectRatio(root_child0, 1); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, aspect_ratio_with_max_cross_defined) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetHeight(root_child0, 50); + YGNodeStyleSetMaxWidth(root_child0, 40); + YGNodeStyleSetAspectRatio(root_child0, 1); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_EQ(40, YGNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, aspect_ratio_with_max_main_defined) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeStyleSetMaxHeight(root_child0, 40); + YGNodeStyleSetAspectRatio(root_child0, 1); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(40, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, aspect_ratio_with_min_cross_defined) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetHeight(root_child0, 30); + YGNodeStyleSetMinWidth(root_child0, 40); + YGNodeStyleSetAspectRatio(root_child0, 1); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_EQ(40, YGNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(30, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, aspect_ratio_with_min_main_defined) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 30); + YGNodeStyleSetMinHeight(root_child0, 40); + YGNodeStyleSetAspectRatio(root_child0, 1); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_EQ(30, YGNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(40, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, aspect_ratio_double_cross) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetHeight(root_child0, 50); + YGNodeStyleSetAspectRatio(root_child0, 2); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, aspect_ratio_half_cross) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetHeight(root_child0, 100); + YGNodeStyleSetAspectRatio(root_child0, 0.5); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, aspect_ratio_double_main) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeStyleSetAspectRatio(root_child0, 2); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, aspect_ratio_half_main) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 100); + YGNodeStyleSetAspectRatio(root_child0, 0.5); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, aspect_ratio_with_measure_func) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeSetMeasureFunc(root_child0, _measure); + YGNodeStyleSetAspectRatio(root_child0, 1); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} diff --git a/tests/YGLayoutDefaultValuesTest.cpp b/tests/YGLayoutDefaultValuesTest.cpp new file mode 100644 index 00000000..fbc1e1b9 --- /dev/null +++ b/tests/YGLayoutDefaultValuesTest.cpp @@ -0,0 +1,76 @@ +/** + * 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 +#include + +TEST(YogaTest, assert_default_values) { + const YGNodeRef root = YGNodeNew(); + + ASSERT_EQ(0, YGNodeChildCount(root)); + ASSERT_EQ(NULL, YGNodeGetChild(root, 1)); + + ASSERT_EQ(YGDirectionInherit, YGNodeStyleGetDirection(root)); + ASSERT_EQ(YGFlexDirectionColumn, YGNodeStyleGetFlexDirection(root)); + ASSERT_EQ(YGJustifyFlexStart, YGNodeStyleGetJustifyContent(root)); + ASSERT_EQ(YGAlignFlexStart, YGNodeStyleGetAlignContent(root)); + ASSERT_EQ(YGAlignStretch, YGNodeStyleGetAlignItems(root)); + ASSERT_EQ(YGAlignAuto, YGNodeStyleGetAlignSelf(root)); + ASSERT_EQ(YGPositionTypeRelative, YGNodeStyleGetPositionType(root)); + ASSERT_EQ(YGWrapNoWrap, YGNodeStyleGetFlexWrap(root)); + ASSERT_EQ(YGOverflowVisible, YGNodeStyleGetOverflow(root)); + ASSERT_FLOAT_EQ(0, YGNodeStyleGetFlexGrow(root)); + ASSERT_FLOAT_EQ(0, YGNodeStyleGetFlexShrink(root)); + ASSERT_TRUE(YGValueIsUndefined(YGNodeStyleGetFlexBasis(root))); + + ASSERT_TRUE(YGValueIsUndefined(YGNodeStyleGetPosition(root, YGEdgeLeft))); + ASSERT_TRUE(YGValueIsUndefined(YGNodeStyleGetPosition(root, YGEdgeTop))); + ASSERT_TRUE(YGValueIsUndefined(YGNodeStyleGetPosition(root, YGEdgeRight))); + ASSERT_TRUE(YGValueIsUndefined(YGNodeStyleGetPosition(root, YGEdgeBottom))); + ASSERT_TRUE(YGValueIsUndefined(YGNodeStyleGetPosition(root, YGEdgeStart))); + ASSERT_TRUE(YGValueIsUndefined(YGNodeStyleGetPosition(root, YGEdgeEnd))); + + ASSERT_FLOAT_EQ(0, YGNodeStyleGetMargin(root, YGEdgeLeft)); + ASSERT_FLOAT_EQ(0, YGNodeStyleGetMargin(root, YGEdgeTop)); + ASSERT_FLOAT_EQ(0, YGNodeStyleGetMargin(root, YGEdgeRight)); + ASSERT_FLOAT_EQ(0, YGNodeStyleGetMargin(root, YGEdgeBottom)); + ASSERT_TRUE(YGValueIsUndefined(YGNodeStyleGetMargin(root, YGEdgeStart))); + ASSERT_TRUE(YGValueIsUndefined(YGNodeStyleGetMargin(root, YGEdgeEnd))); + + ASSERT_FLOAT_EQ(0, YGNodeStyleGetPadding(root, YGEdgeLeft)); + ASSERT_FLOAT_EQ(0, YGNodeStyleGetPadding(root, YGEdgeTop)); + ASSERT_FLOAT_EQ(0, YGNodeStyleGetPadding(root, YGEdgeRight)); + ASSERT_FLOAT_EQ(0, YGNodeStyleGetPadding(root, YGEdgeBottom)); + ASSERT_TRUE(YGValueIsUndefined(YGNodeStyleGetPadding(root, YGEdgeStart))); + ASSERT_TRUE(YGValueIsUndefined(YGNodeStyleGetPadding(root, YGEdgeEnd))); + + ASSERT_FLOAT_EQ(0, YGNodeStyleGetBorder(root, YGEdgeLeft)); + ASSERT_FLOAT_EQ(0, YGNodeStyleGetBorder(root, YGEdgeTop)); + ASSERT_FLOAT_EQ(0, YGNodeStyleGetBorder(root, YGEdgeRight)); + ASSERT_FLOAT_EQ(0, YGNodeStyleGetBorder(root, YGEdgeBottom)); + ASSERT_TRUE(YGValueIsUndefined(YGNodeStyleGetBorder(root, YGEdgeStart))); + ASSERT_TRUE(YGValueIsUndefined(YGNodeStyleGetBorder(root, YGEdgeEnd))); + + ASSERT_TRUE(YGValueIsUndefined(YGNodeStyleGetWidth(root))); + ASSERT_TRUE(YGValueIsUndefined(YGNodeStyleGetHeight(root))); + ASSERT_TRUE(YGValueIsUndefined(YGNodeStyleGetMinWidth(root))); + ASSERT_TRUE(YGValueIsUndefined(YGNodeStyleGetMinHeight(root))); + ASSERT_TRUE(YGValueIsUndefined(YGNodeStyleGetMaxWidth(root))); + ASSERT_TRUE(YGValueIsUndefined(YGNodeStyleGetMaxHeight(root))); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetRight(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetBottom(root)); + ASSERT_TRUE(YGValueIsUndefined(YGNodeLayoutGetWidth(root))); + ASSERT_TRUE(YGValueIsUndefined(YGNodeLayoutGetHeight(root))); + ASSERT_EQ(YGDirectionInherit, YGNodeLayoutGetDirection(root)); + + YGNodeFreeRecursive(root); +} diff --git a/tests/YGMarginTest.cpp b/tests/YGMarginTest.cpp new file mode 100644 index 00000000..724b2eef --- /dev/null +++ b/tests/YGMarginTest.cpp @@ -0,0 +1,406 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGMarginTest.html + +#include +#include + +TEST(YogaTest, margin_start) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetMargin(root_child0, YGEdgeStart, 10); + YGNodeStyleSetWidth(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, margin_top) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetMargin(root_child0, YGEdgeTop, 10); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, margin_end) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetJustifyContent(root, YGJustifyFlexEnd); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetMargin(root_child0, YGEdgeEnd, 10); + YGNodeStyleSetWidth(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, margin_bottom) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetJustifyContent(root, YGJustifyFlexEnd); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetMargin(root_child0, YGEdgeBottom, 10); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, margin_and_flex_row) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeStyleSetMargin(root_child0, YGEdgeStart, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, margin_and_flex_column) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeStyleSetMargin(root_child0, YGEdgeTop, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, margin_and_stretch_row) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeStyleSetMargin(root_child0, YGEdgeTop, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, margin_and_stretch_column) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeStyleSetMargin(root_child0, YGEdgeStart, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, margin_with_sibling_row) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child1, 1); + YGNodeInsertChild(root, root_child1, 1); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, margin_with_sibling_column) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child1, 1); + YGNodeInsertChild(root, root_child1, 1); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); + + YGNodeFreeRecursive(root); +} diff --git a/tests/YGMeasureCacheTest.cpp b/tests/YGMeasureCacheTest.cpp new file mode 100644 index 00000000..ca932b25 --- /dev/null +++ b/tests/YGMeasureCacheTest.cpp @@ -0,0 +1,133 @@ +/** + * 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 +#include + +static YGSize _measureMax(YGNodeRef node, + float width, + YGMeasureMode widthMode, + float height, + YGMeasureMode heightMode) { + + int *measureCount = (int *)YGNodeGetContext(node); + (*measureCount)++; + + return YGSize { + .width = widthMode == YGMeasureModeUndefined ? 10 : width, + .height = heightMode == YGMeasureModeUndefined ? 10 : height, + }; +} + +static YGSize _measureMin(YGNodeRef node, + float width, + YGMeasureMode widthMode, + float height, + YGMeasureMode heightMode) { + + int *measureCount = (int *)YGNodeGetContext(node); + *measureCount = *measureCount + 1; + return YGSize { + .width = widthMode == YGMeasureModeUndefined || (widthMode == YGMeasureModeAtMost && width > 10) ? 10 : width, + .height = heightMode == YGMeasureModeUndefined || (heightMode == YGMeasureModeAtMost && height > 10) ? 10 : height, + }; +} + +TEST(YogaTest, measure_once_single_flexible_child) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + int measureCount = 0; + YGNodeSetContext(root_child0, &measureCount); + YGNodeSetMeasureFunc(root_child0, _measureMax); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(1, measureCount); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, remeasure_with_same_exact_width_larger_than_needed_height) { + const YGNodeRef root = YGNodeNew(); + + const YGNodeRef root_child0 = YGNodeNew(); + int measureCount = 0; + YGNodeSetContext(root_child0, &measureCount); + YGNodeSetMeasureFunc(root_child0, _measureMin); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR); + YGNodeCalculateLayout(root, 100, 50, YGDirectionLTR); + + ASSERT_EQ(1, measureCount); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, remeasure_with_same_atmost_width_larger_than_needed_height) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + + const YGNodeRef root_child0 = YGNodeNew(); + int measureCount = 0; + YGNodeSetContext(root_child0, &measureCount); + YGNodeSetMeasureFunc(root_child0, _measureMin); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR); + YGNodeCalculateLayout(root, 100, 50, YGDirectionLTR); + + ASSERT_EQ(1, measureCount); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, remeasure_with_computed_width_larger_than_needed_height) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + + const YGNodeRef root_child0 = YGNodeNew(); + int measureCount = 0; + YGNodeSetContext(root_child0, &measureCount); + YGNodeSetMeasureFunc(root_child0, _measureMin); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR); + YGNodeStyleSetAlignItems(root, YGAlignStretch); + YGNodeCalculateLayout(root, 10, 50, YGDirectionLTR); + + ASSERT_EQ(1, measureCount); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, remeasure_with_atmost_computed_width_undefined_height) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + + const YGNodeRef root_child0 = YGNodeNew(); + int measureCount = 0; + YGNodeSetContext(root_child0, &measureCount); + YGNodeSetMeasureFunc(root_child0, _measureMin); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, 100, YGUndefined, YGDirectionLTR); + YGNodeCalculateLayout(root, 10, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(1, measureCount); + + YGNodeFreeRecursive(root); +} diff --git a/tests/YGMeasureModeTest.cpp b/tests/YGMeasureModeTest.cpp new file mode 100644 index 00000000..730247fa --- /dev/null +++ b/tests/YGMeasureModeTest.cpp @@ -0,0 +1,323 @@ +/** + * 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 +#include + +struct _MeasureConstraint { + float width; + YGMeasureMode widthMode; + float height; + YGMeasureMode heightMode; +}; + +struct _MeasureConstraintList { + uint32_t length; + struct _MeasureConstraint *constraints; +}; + +static YGSize _measure(YGNodeRef node, + float width, + YGMeasureMode widthMode, + float height, + YGMeasureMode heightMode) { + struct _MeasureConstraintList *constraintList = (struct _MeasureConstraintList *)YGNodeGetContext(node); + struct _MeasureConstraint *constraints = constraintList->constraints; + uint32_t currentIndex = constraintList->length; + (&constraints[currentIndex])->width = width; + (&constraints[currentIndex])->widthMode = widthMode; + (&constraints[currentIndex])->height = height; + (&constraints[currentIndex])->heightMode = heightMode; + constraintList->length = currentIndex + 1; + + return YGSize { + .width = widthMode == YGMeasureModeUndefined ? 10 : width, + .height = heightMode == YGMeasureModeUndefined ? 10 : width, + }; +} + +TEST(YogaTest, exactly_measure_stretched_child_column) { + struct _MeasureConstraintList constraintList = _MeasureConstraintList { + .length = 0, + .constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)), + }; + + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeSetContext(root_child0, &constraintList); + YGNodeSetMeasureFunc(root_child0, _measure); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(1, constraintList.length); + + ASSERT_FLOAT_EQ(100, constraintList.constraints[0].width); + ASSERT_EQ(YGMeasureModeExactly, constraintList.constraints[0].widthMode); + + free(constraintList.constraints); + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, exactly_measure_stretched_child_row) { + struct _MeasureConstraintList constraintList = _MeasureConstraintList { + .length = 0, + .constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)), + }; + + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeSetContext(root_child0, &constraintList); + YGNodeSetMeasureFunc(root_child0, _measure); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(1, constraintList.length); + + ASSERT_FLOAT_EQ(100, constraintList.constraints[0].height); + ASSERT_EQ(YGMeasureModeExactly, constraintList.constraints[0].heightMode); + + free(constraintList.constraints); + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, at_most_main_axis_column) { + struct _MeasureConstraintList constraintList = _MeasureConstraintList { + .length = 0, + .constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)), + }; + + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeSetContext(root_child0, &constraintList); + YGNodeSetMeasureFunc(root_child0, _measure); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(1, constraintList.length); + + ASSERT_FLOAT_EQ(100, constraintList.constraints[0].height); + ASSERT_EQ(YGMeasureModeAtMost, constraintList.constraints[0].heightMode); + + free(constraintList.constraints); + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, at_most_cross_axis_column) { + struct _MeasureConstraintList constraintList = _MeasureConstraintList { + .length = 0, + .constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)), + }; + + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeSetContext(root_child0, &constraintList); + YGNodeSetMeasureFunc(root_child0, _measure); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(1, constraintList.length); + + ASSERT_FLOAT_EQ(100, constraintList.constraints[0].width); + ASSERT_EQ(YGMeasureModeAtMost, constraintList.constraints[0].widthMode); + + free(constraintList.constraints); + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, at_most_main_axis_row) { + struct _MeasureConstraintList constraintList = _MeasureConstraintList { + .length = 0, + .constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)), + }; + + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeSetContext(root_child0, &constraintList); + YGNodeSetMeasureFunc(root_child0, _measure); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(1, constraintList.length); + + ASSERT_FLOAT_EQ(100, constraintList.constraints[0].width); + ASSERT_EQ(YGMeasureModeAtMost, constraintList.constraints[0].widthMode); + + free(constraintList.constraints); + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, at_most_cross_axis_row) { + struct _MeasureConstraintList constraintList = _MeasureConstraintList { + .length = 0, + .constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)), + }; + + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeSetContext(root_child0, &constraintList); + YGNodeSetMeasureFunc(root_child0, _measure); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(1, constraintList.length); + + ASSERT_FLOAT_EQ(100, constraintList.constraints[0].height); + ASSERT_EQ(YGMeasureModeAtMost, constraintList.constraints[0].heightMode); + + free(constraintList.constraints); + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, flex_child) { + struct _MeasureConstraintList constraintList = _MeasureConstraintList { + .length = 0, + .constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)), + }; + + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeSetContext(root_child0, &constraintList); + YGNodeSetMeasureFunc(root_child0, _measure); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(2, constraintList.length); + + ASSERT_FLOAT_EQ(100, constraintList.constraints[0].height); + ASSERT_EQ(YGMeasureModeAtMost, constraintList.constraints[0].heightMode); + + ASSERT_FLOAT_EQ(100, constraintList.constraints[1].height); + ASSERT_EQ(YGMeasureModeExactly, constraintList.constraints[1].heightMode); + + free(constraintList.constraints); + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, flex_child_with_flex_basis) { + struct _MeasureConstraintList constraintList = _MeasureConstraintList { + .length = 0, + .constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)), + }; + + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeStyleSetFlexBasis(root_child0, 0); + YGNodeSetContext(root_child0, &constraintList); + YGNodeSetMeasureFunc(root_child0, _measure); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(1, constraintList.length); + + ASSERT_FLOAT_EQ(100, constraintList.constraints[0].height); + ASSERT_EQ(YGMeasureModeExactly, constraintList.constraints[0].heightMode); + + free(constraintList.constraints); + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, overflow_scroll_column) { + struct _MeasureConstraintList constraintList = _MeasureConstraintList { + .length = 0, + .constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)), + }; + + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetOverflow(root, YGOverflowScroll); + YGNodeStyleSetHeight(root, 100); + YGNodeStyleSetWidth(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeSetContext(root_child0, &constraintList); + YGNodeSetMeasureFunc(root_child0, _measure); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(1, constraintList.length); + + ASSERT_FLOAT_EQ(100, constraintList.constraints[0].width); + ASSERT_EQ(YGMeasureModeAtMost, constraintList.constraints[0].widthMode); + + ASSERT_TRUE(YGValueIsUndefined(constraintList.constraints[0].height)); + ASSERT_EQ(YGMeasureModeUndefined, constraintList.constraints[0].heightMode); + + free(constraintList.constraints); + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, overflow_scroll_row) { + struct _MeasureConstraintList constraintList = _MeasureConstraintList { + .length = 0, + .constraints = (struct _MeasureConstraint *) malloc(10 * sizeof(struct _MeasureConstraint)), + }; + + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetOverflow(root, YGOverflowScroll); + YGNodeStyleSetHeight(root, 100); + YGNodeStyleSetWidth(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeSetContext(root_child0, &constraintList); + YGNodeSetMeasureFunc(root_child0, _measure); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(1, constraintList.length); + + ASSERT_TRUE(YGValueIsUndefined(constraintList.constraints[0].width)); + ASSERT_EQ(YGMeasureModeUndefined, constraintList.constraints[0].widthMode); + + ASSERT_FLOAT_EQ(100, constraintList.constraints[0].height); + ASSERT_EQ(YGMeasureModeAtMost, constraintList.constraints[0].heightMode); + + free(constraintList.constraints); + YGNodeFreeRecursive(root); +} diff --git a/tests/YGMeasureTest.cpp b/tests/YGMeasureTest.cpp new file mode 100644 index 00000000..911f0c51 --- /dev/null +++ b/tests/YGMeasureTest.cpp @@ -0,0 +1,79 @@ +/** + * 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 +#include + +static YGSize _measure(YGNodeRef node, + float width, + YGMeasureMode widthMode, + float height, + YGMeasureMode heightMode) { + int *measureCount = (int*) YGNodeGetContext(node); + if (measureCount) { + (*measureCount)++; + } + + return YGSize { + .width = 10, + .height = 10, + }; +} + +TEST(YogaTest, dont_measure_single_grow_shrink_child) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + int measureCount = 0; + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeSetContext(root_child0, &measureCount); + YGNodeSetMeasureFunc(root_child0, _measure); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeStyleSetFlexShrink(root_child0, 1); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(0, measureCount); + + YGNodeFreeRecursive(root); +} + +#if GTEST_HAS_DEATH_TEST +TEST(YogaTest, cannot_add_child_to_node_with_measure_func) { + const YGNodeRef root = YGNodeNew(); + YGNodeSetMeasureFunc(root, _measure); + + const YGNodeRef root_child0 = YGNodeNew(); + ASSERT_DEATH(YGNodeInsertChild(root, root_child0, 0), "Cannot add child.*"); + YGNodeFree(root_child0); + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, cannot_add_nonnull_measure_func_to_non_leaf_node) { + const YGNodeRef root = YGNodeNew(); + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeInsertChild(root, root_child0, 0); + + ASSERT_DEATH(YGNodeSetMeasureFunc(root, _measure), "Cannot set measure function.*"); + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, can_nullify_measure_func_on_any_node) { + const YGNodeRef root = YGNodeNew(); + YGNodeInsertChild(root, YGNodeNew(), 0); + + YGNodeSetMeasureFunc(root, NULL); + ASSERT_TRUE(YGNodeGetMeasureFunc(root) == NULL); + YGNodeFreeRecursive(root); +} + +#endif diff --git a/tests/YGMemoryFuncTest.cpp b/tests/YGMemoryFuncTest.cpp new file mode 100644 index 00000000..bef2985c --- /dev/null +++ b/tests/YGMemoryFuncTest.cpp @@ -0,0 +1,77 @@ +/** + * 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 +#include + +extern int32_t gNodeInstanceCount; + +static int testMallocCount; +static int testCallocCount; +static int testReallocCount; +static int testFreeCount; + +static void *testMalloc(size_t size) { + testMallocCount++; + return malloc(size); +} + +static void *testCalloc(size_t count, size_t size) { + testCallocCount++; + return calloc(count, size); +} + +static void *testRealloc(void *ptr, size_t size) { + testReallocCount++; + return realloc(ptr, size); +} + +static void testFree(void *ptr) { + testFreeCount++; + free(ptr); +} + +TEST(YogaTest, memory_func_default) { + gNodeInstanceCount = 0; // Reset YGNode instance count for memory func test + YGSetMemoryFuncs(NULL, NULL, NULL, NULL); + const YGNodeRef root = YGNodeNew(); + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeInsertChild(root, root_child0, 0); + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, memory_func_test_funcs) { + gNodeInstanceCount = 0; // Reset YGNode instance count for memory func test + YGSetMemoryFuncs(&testMalloc, &testCalloc, &testRealloc, &testFree); + const YGNodeRef root = YGNodeNew(); + for (int i = 0; i < 10; i++) { + const YGNodeRef child = YGNodeNew(); + YGNodeInsertChild(root, child, 0); + } + YGNodeFreeRecursive(root); + ASSERT_NE(testMallocCount, 0); + ASSERT_NE(testCallocCount, 0); + ASSERT_NE(testReallocCount, 0); + ASSERT_NE(testFreeCount, 0); + YGSetMemoryFuncs(NULL, NULL, NULL, NULL); +} + +#if GTEST_HAS_DEATH_TEST +TEST(YogaTest, memory_func_assert_zero_nodes) { + gNodeInstanceCount = 0; // Reset YGNode instance count for memory func test + const YGNodeRef root = YGNodeNew(); + ASSERT_DEATH(YGSetMemoryFuncs(&testMalloc, &testCalloc, &testRealloc, &testFree), "Cannot set memory functions: all node must be freed first"); + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, memory_func_assert_all_non_null) { + gNodeInstanceCount = 0; // Reset YGNode instance count for memory func test + ASSERT_DEATH(YGSetMemoryFuncs(NULL, &testCalloc, &testRealloc, &testFree), "Cannot set memory functions: functions must be all NULL or Non-NULL"); +} +#endif diff --git a/tests/YGMinMaxDimensionTest.cpp b/tests/YGMinMaxDimensionTest.cpp new file mode 100644 index 00000000..2c6d3120 --- /dev/null +++ b/tests/YGMinMaxDimensionTest.cpp @@ -0,0 +1,432 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGMinMaxDimensionTest.html + +#include +#include + +TEST(YogaTest, max_width) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetMaxWidth(root_child0, 50); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, max_height) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 10); + YGNodeStyleSetMaxHeight(root_child0, 50); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, min_height) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeStyleSetMinHeight(root_child0, 60); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child1, 1); + YGNodeInsertChild(root, root_child1, 1); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, min_width) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeStyleSetMinWidth(root_child0, 60); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child1, 1); + YGNodeInsertChild(root, root_child1, 1); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, justify_content_min_max) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetJustifyContent(root, YGJustifyCenter); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetMinHeight(root, 100); + YGNodeStyleSetMaxHeight(root, 200); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 60); + YGNodeStyleSetHeight(root_child0, 60); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, align_items_min_max) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetAlignItems(root, YGAlignCenter); + YGNodeStyleSetMinWidth(root, 100); + YGNodeStyleSetMaxWidth(root, 200); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 60); + YGNodeStyleSetHeight(root_child0, 60); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, justify_content_overflow_min_max) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetJustifyContent(root, YGJustifyCenter); + YGNodeStyleSetMinHeight(root, 100); + YGNodeStyleSetMaxHeight(root, 110); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 50); + YGNodeStyleSetHeight(root_child0, 50); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetWidth(root_child1, 50); + YGNodeStyleSetHeight(root_child1, 50); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetWidth(root_child2, 50); + YGNodeStyleSetHeight(root_child2, 50); + YGNodeInsertChild(root, root_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(110, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(-20, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(110, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(-20, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, flex_grow_within_max_width) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 200); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow); + YGNodeStyleSetMaxWidth(root_child0, 100); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child0_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0_child0, 1); + YGNodeStyleSetHeight(root_child0_child0, 20); + YGNodeInsertChild(root_child0, root_child0_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, flex_grow_within_constrained_max_width) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 200); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow); + YGNodeStyleSetMaxWidth(root_child0, 300); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child0_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0_child0, 1); + YGNodeStyleSetHeight(root_child0_child0, 20); + YGNodeInsertChild(root_child0, root_child0_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0_child0)); + + YGNodeFreeRecursive(root); +} diff --git a/tests/YGPaddingTest.cpp b/tests/YGPaddingTest.cpp new file mode 100644 index 00000000..aab6726b --- /dev/null +++ b/tests/YGPaddingTest.cpp @@ -0,0 +1,236 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGPaddingTest.html + +#include +#include + +TEST(YogaTest, padding_no_size) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetPadding(root, YGEdgeLeft, 10); + YGNodeStyleSetPadding(root, YGEdgeTop, 10); + YGNodeStyleSetPadding(root, YGEdgeRight, 10); + YGNodeStyleSetPadding(root, YGEdgeBottom, 10); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, padding_container_match_child) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetPadding(root, YGEdgeLeft, 10); + YGNodeStyleSetPadding(root, YGEdgeTop, 10); + YGNodeStyleSetPadding(root, YGEdgeRight, 10); + YGNodeStyleSetPadding(root, YGEdgeBottom, 10); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 10); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, padding_flex_child) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetPadding(root, YGEdgeLeft, 10); + YGNodeStyleSetPadding(root, YGEdgeTop, 10); + YGNodeStyleSetPadding(root, YGEdgeRight, 10); + YGNodeStyleSetPadding(root, YGEdgeBottom, 10); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeStyleSetWidth(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, padding_stretch_child) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetPadding(root, YGEdgeLeft, 10); + YGNodeStyleSetPadding(root, YGEdgeTop, 10); + YGNodeStyleSetPadding(root, YGEdgeRight, 10); + YGNodeStyleSetPadding(root, YGEdgeBottom, 10); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(80, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, padding_center_child) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetJustifyContent(root, YGJustifyCenter); + YGNodeStyleSetAlignItems(root, YGAlignCenter); + YGNodeStyleSetPadding(root, YGEdgeStart, 10); + YGNodeStyleSetPadding(root, YGEdgeEnd, 20); + YGNodeStyleSetPadding(root, YGEdgeBottom, 20); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetWidth(root_child0, 10); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(35, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(35, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} + +TEST(YogaTest, child_with_padding_align_end) { + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetJustifyContent(root, YGJustifyFlexEnd); + YGNodeStyleSetAlignItems(root, YGAlignFlexEnd); + YGNodeStyleSetWidth(root, 200); + YGNodeStyleSetHeight(root, 200); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetPadding(root_child0, YGEdgeLeft, 20); + YGNodeStyleSetPadding(root_child0, YGEdgeTop, 20); + YGNodeStyleSetPadding(root_child0, YGEdgeRight, 20); + YGNodeStyleSetPadding(root_child0, YGEdgeBottom, 20); + YGNodeStyleSetWidth(root_child0, 100); + YGNodeStyleSetHeight(root_child0, 100); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} diff --git a/tests/YGRelayoutTest.cpp b/tests/YGRelayoutTest.cpp new file mode 100644 index 00000000..de298325 --- /dev/null +++ b/tests/YGRelayoutTest.cpp @@ -0,0 +1,31 @@ +/** + * 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 +#include + +TEST(YogaTest, dont_cache_computed_flex_basis_between_layouts) { + YGSetExperimentalFeatureEnabled(YGExperimentalFeatureWebFlexBasis, true); + + const YGNodeRef root = YGNodeNew(); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetHeight(root_child0, 10); + YGNodeStyleSetFlexBasis(root_child0, 20); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, 100, YGUndefined, YGDirectionLTR); + YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR); + + ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); + + YGSetExperimentalFeatureEnabled(YGExperimentalFeatureWebFlexBasis, false); +} diff --git a/tests/YGRoundingMeasureFuncTest.cpp b/tests/YGRoundingMeasureFuncTest.cpp new file mode 100644 index 00000000..6bbee0e3 --- /dev/null +++ b/tests/YGRoundingMeasureFuncTest.cpp @@ -0,0 +1,73 @@ +/** + * 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 +#include + +static YGSize _measureFloor(YGNodeRef node, + float width, + YGMeasureMode widthMode, + float height, + YGMeasureMode heightMode) { + + return YGSize{ + width = 10.2, + height = 10.2, + }; +} + +static YGSize _measureCeil(YGNodeRef node, + float width, + YGMeasureMode widthMode, + float height, + YGMeasureMode heightMode) { + + return YGSize{ + width = 10.5, + height = 10.5, + }; +} + +TEST(YogaTest, rounding_feature_with_custom_measure_func_floor) { + YGSetExperimentalFeatureEnabled(YGExperimentalFeatureRounding, true); + + const YGNodeRef root = YGNodeNew(); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeSetMeasureFunc(root_child0, _measureFloor); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); + + YGSetExperimentalFeatureEnabled(YGExperimentalFeatureRounding, false); +} + +TEST(YogaTest, rounding_feature_with_custom_measure_func_ceil) { + YGSetExperimentalFeatureEnabled(YGExperimentalFeatureRounding, true); + + const YGNodeRef root = YGNodeNew(); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeSetMeasureFunc(root_child0, _measureCeil); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(11, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(11, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); + + YGSetExperimentalFeatureEnabled(YGExperimentalFeatureRounding, false); +} diff --git a/tests/YGRoundingTest.cpp b/tests/YGRoundingTest.cpp new file mode 100644 index 00000000..0ce9f5c0 --- /dev/null +++ b/tests/YGRoundingTest.cpp @@ -0,0 +1,779 @@ +/** + * 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. + */ + + // @Generated by gentest/gentest.rb from gentest/fixtures/YGRoundingTest.html + +#include +#include + +TEST(YogaTest, rounding_flex_basis_flex_grow_row_width_of_100) { + YGSetExperimentalFeatureEnabled(YGExperimentalFeatureRounding, true); + + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child1, 1); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child2, 1); + YGNodeInsertChild(root, root_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(33, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(33, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(34, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(67, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(33, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(67, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(33, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(33, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(34, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(33, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); + + YGSetExperimentalFeatureEnabled(YGExperimentalFeatureRounding, false); +} + +TEST(YogaTest, rounding_flex_basis_flex_grow_row_prime_number_width) { + YGSetExperimentalFeatureEnabled(YGExperimentalFeatureRounding, true); + + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetWidth(root, 113); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child1, 1); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child2, 1); + YGNodeInsertChild(root, root_child2, 2); + + const YGNodeRef root_child3 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child3, 1); + YGNodeInsertChild(root, root_child3, 3); + + const YGNodeRef root_child4 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child4, 1); + YGNodeInsertChild(root, root_child4, 4); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(113, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(23, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(23, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(22, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(45, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(23, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(68, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(22, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(23, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child4)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(113, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(23, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(68, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(22, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(45, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(23, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child2)); + + ASSERT_FLOAT_EQ(23, YGNodeLayoutGetLeft(root_child3)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child3)); + ASSERT_FLOAT_EQ(22, YGNodeLayoutGetWidth(root_child3)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child3)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child4)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); + ASSERT_FLOAT_EQ(23, YGNodeLayoutGetWidth(root_child4)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child4)); + + YGNodeFreeRecursive(root); + + YGSetExperimentalFeatureEnabled(YGExperimentalFeatureRounding, false); +} + +TEST(YogaTest, rounding_flex_basis_flex_shrink_row) { + YGSetExperimentalFeatureEnabled(YGExperimentalFeatureRounding, true); + + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetWidth(root, 101); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexShrink(root_child0, 1); + YGNodeStyleSetFlexBasis(root_child0, 100); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetFlexBasis(root_child1, 25); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetFlexBasis(root_child2, 25); + YGNodeInsertChild(root, root_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(101, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(51, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(51, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(76, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(101, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(51, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); + + YGSetExperimentalFeatureEnabled(YGExperimentalFeatureRounding, false); +} + +TEST(YogaTest, rounding_flex_basis_overrides_main_size) { + YGSetExperimentalFeatureEnabled(YGExperimentalFeatureRounding, true); + + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 113); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeStyleSetFlexBasis(root_child0, 50); + YGNodeStyleSetHeight(root_child0, 20); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child1, 1); + YGNodeStyleSetHeight(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child2, 1); + YGNodeStyleSetHeight(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(113, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(64, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(64, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(89, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(24, YGNodeLayoutGetHeight(root_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(113, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(64, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(64, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(89, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(24, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); + + YGSetExperimentalFeatureEnabled(YGExperimentalFeatureRounding, false); +} + +TEST(YogaTest, rounding_total_fractial) { + YGSetExperimentalFeatureEnabled(YGExperimentalFeatureRounding, true); + + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 87.4f); + YGNodeStyleSetHeight(root, 113.4f); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 0.7f); + YGNodeStyleSetFlexBasis(root_child0, 50.3f); + YGNodeStyleSetHeight(root_child0, 20.3f); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child1, 1.6f); + YGNodeStyleSetHeight(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child2, 1.1f); + YGNodeStyleSetHeight(root_child2, 10.7f); + YGNodeInsertChild(root, root_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(87, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(113, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(87, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(59, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(59, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(87, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(89, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(87, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(24, YGNodeLayoutGetHeight(root_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(87, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(113, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(87, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(59, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(59, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(87, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(89, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(87, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(24, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); + + YGSetExperimentalFeatureEnabled(YGExperimentalFeatureRounding, false); +} + +TEST(YogaTest, rounding_total_fractial_nested) { + YGSetExperimentalFeatureEnabled(YGExperimentalFeatureRounding, true); + + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 87.4f); + YGNodeStyleSetHeight(root, 113.4f); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 0.7f); + YGNodeStyleSetFlexBasis(root_child0, 50.3f); + YGNodeStyleSetHeight(root_child0, 20.3f); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child0_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0_child0, 1); + YGNodeStyleSetFlexBasis(root_child0_child0, 0.3f); + YGNodeStyleSetPosition(root_child0_child0, YGEdgeBottom, 13.3f); + YGNodeStyleSetHeight(root_child0_child0, 9.9f); + YGNodeInsertChild(root_child0, root_child0_child0, 0); + + const YGNodeRef root_child0_child1 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0_child1, 4); + YGNodeStyleSetFlexBasis(root_child0_child1, 0.3f); + YGNodeStyleSetPosition(root_child0_child1, YGEdgeTop, 13.3f); + YGNodeStyleSetHeight(root_child0_child1, 1.1f); + YGNodeInsertChild(root_child0, root_child0_child1, 1); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child1, 1.6f); + YGNodeStyleSetHeight(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child2, 1.1f); + YGNodeStyleSetHeight(root_child2, 10.7f); + YGNodeInsertChild(root, root_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(87, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(113, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(87, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(59, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(-13, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(87, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(12, YGNodeLayoutGetHeight(root_child0_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child1)); + ASSERT_FLOAT_EQ(25, YGNodeLayoutGetTop(root_child0_child1)); + ASSERT_FLOAT_EQ(87, YGNodeLayoutGetWidth(root_child0_child1)); + ASSERT_FLOAT_EQ(47, YGNodeLayoutGetHeight(root_child0_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(59, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(87, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(89, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(87, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(24, YGNodeLayoutGetHeight(root_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(87, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(113, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(87, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(59, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(-13, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(87, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(12, YGNodeLayoutGetHeight(root_child0_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child1)); + ASSERT_FLOAT_EQ(25, YGNodeLayoutGetTop(root_child0_child1)); + ASSERT_FLOAT_EQ(87, YGNodeLayoutGetWidth(root_child0_child1)); + ASSERT_FLOAT_EQ(47, YGNodeLayoutGetHeight(root_child0_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(59, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(87, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(89, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(87, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(24, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); + + YGSetExperimentalFeatureEnabled(YGExperimentalFeatureRounding, false); +} + +TEST(YogaTest, rounding_fractial_input_1) { + YGSetExperimentalFeatureEnabled(YGExperimentalFeatureRounding, true); + + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 113.4f); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeStyleSetFlexBasis(root_child0, 50); + YGNodeStyleSetHeight(root_child0, 20); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child1, 1); + YGNodeStyleSetHeight(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child2, 1); + YGNodeStyleSetHeight(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(113, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(64, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(64, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(89, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(24, YGNodeLayoutGetHeight(root_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(113, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(64, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(64, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(89, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(24, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); + + YGSetExperimentalFeatureEnabled(YGExperimentalFeatureRounding, false); +} + +TEST(YogaTest, rounding_fractial_input_2) { + YGSetExperimentalFeatureEnabled(YGExperimentalFeatureRounding, true); + + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 113.6f); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeStyleSetFlexBasis(root_child0, 50); + YGNodeStyleSetHeight(root_child0, 20); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child1, 1); + YGNodeStyleSetHeight(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child2, 1); + YGNodeStyleSetHeight(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(114, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(65, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(65, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(24, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(89, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(114, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(65, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(65, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(24, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(89, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); + + YGSetExperimentalFeatureEnabled(YGExperimentalFeatureRounding, false); +} + +TEST(YogaTest, rounding_fractial_input_3) { + YGSetExperimentalFeatureEnabled(YGExperimentalFeatureRounding, true); + + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetPosition(root, YGEdgeTop, 0.3f); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 113.4f); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeStyleSetFlexBasis(root_child0, 50); + YGNodeStyleSetHeight(root_child0, 20); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child1, 1); + YGNodeStyleSetHeight(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child2, 1); + YGNodeStyleSetHeight(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(114, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(64, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(64, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(89, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(24, YGNodeLayoutGetHeight(root_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(114, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(64, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(64, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(89, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(24, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); + + YGSetExperimentalFeatureEnabled(YGExperimentalFeatureRounding, false); +} + +TEST(YogaTest, rounding_fractial_input_4) { + YGSetExperimentalFeatureEnabled(YGExperimentalFeatureRounding, true); + + const YGNodeRef root = YGNodeNew(); + YGNodeStyleSetPosition(root, YGEdgeTop, 0.7f); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 113.4f); + + const YGNodeRef root_child0 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child0, 1); + YGNodeStyleSetFlexBasis(root_child0, 50); + YGNodeStyleSetHeight(root_child0, 20); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child1, 1); + YGNodeStyleSetHeight(root_child1, 10); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNew(); + YGNodeStyleSetFlexGrow(root_child2, 1); + YGNodeStyleSetHeight(root_child2, 10); + YGNodeInsertChild(root, root_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(1, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(113, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(64, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(64, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(89, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(24, YGNodeLayoutGetHeight(root_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(1, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(113, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(64, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(64, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(89, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(24, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); + + YGSetExperimentalFeatureEnabled(YGExperimentalFeatureRounding, false); +} diff --git a/tests/YGStyleTest.cpp b/tests/YGStyleTest.cpp new file mode 100644 index 00000000..4eb7fd60 --- /dev/null +++ b/tests/YGStyleTest.cpp @@ -0,0 +1,60 @@ +/** + * 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 +#include + +TEST(YogaTest, copy_style_same) { + const YGNodeRef node0 = YGNodeNew(); + const YGNodeRef node1 = YGNodeNew(); + ASSERT_FALSE(YGNodeIsDirty(node0)); + + YGNodeCopyStyle(node0, node1); + ASSERT_FALSE(YGNodeIsDirty(node0)); + + YGNodeFree(node0); + YGNodeFree(node1); +} + +TEST(YogaTest, copy_style_modified) { + const YGNodeRef node0 = YGNodeNew(); + ASSERT_FALSE(YGNodeIsDirty(node0)); + ASSERT_EQ(YGFlexDirectionColumn, YGNodeStyleGetFlexDirection(node0)); + ASSERT_TRUE(YGValueIsUndefined(YGNodeStyleGetMaxHeight(node0))); + + const YGNodeRef node1 = YGNodeNew(); + YGNodeStyleSetFlexDirection(node1, YGFlexDirectionRow); + YGNodeStyleSetMaxHeight(node1, 10); + + YGNodeCopyStyle(node0, node1); + ASSERT_TRUE(YGNodeIsDirty(node0)); + ASSERT_EQ(YGFlexDirectionRow, YGNodeStyleGetFlexDirection(node0)); + ASSERT_FLOAT_EQ(10, YGNodeStyleGetMaxHeight(node0)); + + YGNodeFree(node0); + YGNodeFree(node1); +} + +TEST(YogaTest, copy_style_modified_same) { + const YGNodeRef node0 = YGNodeNew(); + YGNodeStyleSetFlexDirection(node0, YGFlexDirectionRow); + YGNodeStyleSetMaxHeight(node0, 10); + YGNodeCalculateLayout(node0, YGUndefined, YGUndefined, YGDirectionLTR); + ASSERT_FALSE(YGNodeIsDirty(node0)); + + const YGNodeRef node1 = YGNodeNew(); + YGNodeStyleSetFlexDirection(node1, YGFlexDirectionRow); + YGNodeStyleSetMaxHeight(node1, 10); + + YGNodeCopyStyle(node0, node1); + ASSERT_FALSE(YGNodeIsDirty(node0)); + + YGNodeFree(node0); + YGNodeFree(node1); +} diff --git a/uikit/CSSLayout/Tests/CSSLayoutTests.m b/uikit/CSSLayout/Tests/CSSLayoutTests.m deleted file mode 100644 index cd1e775a..00000000 --- a/uikit/CSSLayout/Tests/CSSLayoutTests.m +++ /dev/null @@ -1,61 +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. - */ - -#import - -#import "UIView+CSSLayout.h" - -@interface CSSLayoutTests : XCTestCase -@end - -@implementation CSSLayoutTests - -- (void)testNodesAreDeallocedWithSingleView -{ - XCTAssertEqual(0, CSSNodeGetInstanceCount()); - - UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; - [view css_setFlex:1]; - XCTAssertEqual(1, CSSNodeGetInstanceCount()); - view = nil; - - XCTAssertEqual(0, CSSNodeGetInstanceCount()); -} - -- (void)testNodesAreDeallocedCascade -{ - XCTAssertEqual(0, CSSNodeGetInstanceCount()); - - UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; - [view css_setFlex:1]; - - for (int i=0; i<10; i++) { - UIView *subview = [[UIView alloc] initWithFrame:CGRectZero]; - [subview css_setFlex:1]; - [view addSubview:subview]; - } - XCTAssertEqual(11, CSSNodeGetInstanceCount()); - view = nil; - - XCTAssertEqual(0, CSSNodeGetInstanceCount()); -} - -- (void)testUsesFlexbox -{ - UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; - XCTAssertFalse([view css_usesFlexbox]); - - [view css_setUsesFlexbox:YES]; - XCTAssertTrue([view css_usesFlexbox]); - - [view css_setUsesFlexbox:NO]; - XCTAssertFalse([view css_usesFlexbox]); -} - -@end diff --git a/uikit/CSSLayout/UIView+CSSLayout.h b/uikit/CSSLayout/UIView+CSSLayout.h deleted file mode 100644 index e17948b5..00000000 --- a/uikit/CSSLayout/UIView+CSSLayout.h +++ /dev/null @@ -1,51 +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. - */ - -#import -#import - -@interface UIView (CSSLayout) - -- (void)css_setUsesFlexbox:(BOOL)enabled; -- (BOOL)css_usesFlexbox; - -- (void)css_setDirection:(CSSDirection)direction; -- (void)css_setFlexDirection:(CSSFlexDirection)flexDirection; -- (void)css_setJustifyContent:(CSSJustify)justifyContent; -- (void)css_setAlignContent:(CSSAlign)alignContent; -- (void)css_setAlignItems:(CSSAlign)alignItems; -- (void)css_setAlignSelf:(CSSAlign)alignSelf; -- (void)css_setPositionType:(CSSPositionType)positionType; -- (void)css_setFlexWrap:(CSSWrapType)flexWrap; -- (void)css_setOverflow:(CSSOverflow)overflow; - -- (void)css_setFlex:(CGFloat)flex; -- (void)css_setFlexGrow:(CGFloat)flexGrow; -- (void)css_setFlexShrink:(CGFloat)flexShrink; -- (void)css_setFlexBasis:(CGFloat)flexBasis; - -- (void)css_setPosition:(CGFloat)position forEdge:(CSSEdge)edge; -- (void)css_setMargin:(CGFloat)margin forEdge:(CSSEdge)edge; -- (void)css_setPadding:(CGFloat)padding forEdge:(CSSEdge)edge; -- (void)css_setBorder:(CGFloat)border forEdge:(CSSEdge)edge; - -- (void)css_setWidth:(CGFloat)width; -- (void)css_setHeight:(CGFloat)height; -- (void)css_setMinWidth:(CGFloat)minWidth; -- (void)css_setMinHeight:(CGFloat)minHeight; -- (void)css_setMaxWidth:(CGFloat)maxWidth; -- (void)css_setMaxHeight:(CGFloat)maxHeight; - -// Get the resolved direction of this node. This won't be CSSDirectionInherit -- (CSSDirection)css_resolvedDirection; - -// Perform a layout calculation and update the frames of the views in the hierarchy with th results -- (void)css_applyLayout; - -@end diff --git a/uikit/CSSLayout/UIView+CSSLayout.m b/uikit/CSSLayout/UIView+CSSLayout.m deleted file mode 100644 index 9a8eb645..00000000 --- a/uikit/CSSLayout/UIView+CSSLayout.m +++ /dev/null @@ -1,283 +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. - */ - -#import "UIView+CSSLayout.h" - -#import - -@interface CSSNodeBridge : NSObject -@property (nonatomic, assign, readonly) CSSNodeRef cnode; -@end - -@implementation CSSNodeBridge -- (instancetype)init -{ - if ([super init]) { - _cnode = CSSNodeNew(); - } - - return self; -} - -- (void)dealloc -{ - CSSNodeFree(_cnode); -} -@end - -@implementation UIView (CSSLayout) - -- (CSSNodeRef)cssNode -{ - CSSNodeBridge *node = objc_getAssociatedObject(self, @selector(cssNode)); - if (!node) { - node = [CSSNodeBridge new]; - CSSNodeSetContext(node.cnode, (__bridge void *) self); - objc_setAssociatedObject(self, @selector(cssNode), node, OBJC_ASSOCIATION_RETAIN_NONATOMIC); - } - - return node.cnode; -} - -- (void)css_setUsesFlexbox:(BOOL)enabled -{ - objc_setAssociatedObject( - self, - @selector(css_usesFlexbox), - @(enabled), - OBJC_ASSOCIATION_RETAIN_NONATOMIC); -} - -- (BOOL)css_usesFlexbox -{ - NSNumber *usesFlexbox = objc_getAssociatedObject(self, @selector(css_usesFlexbox)); - return [usesFlexbox boolValue]; -} - -- (void)css_setDirection:(CSSDirection)direction -{ - CSSNodeStyleSetDirection([self cssNode], direction); -} - -- (void)css_setFlexDirection:(CSSFlexDirection)flexDirection -{ - CSSNodeStyleSetFlexDirection([self cssNode], flexDirection); -} - -- (void)css_setJustifyContent:(CSSJustify)justifyContent -{ - CSSNodeStyleSetJustifyContent([self cssNode], justifyContent); -} - -- (void)css_setAlignContent:(CSSAlign)alignContent -{ - CSSNodeStyleSetAlignContent([self cssNode], alignContent); -} - -- (void)css_setAlignItems:(CSSAlign)alignItems -{ - CSSNodeStyleSetAlignItems([self cssNode], alignItems); -} - -- (void)css_setAlignSelf:(CSSAlign)alignSelf -{ - CSSNodeStyleSetAlignSelf([self cssNode], alignSelf); -} - -- (void)css_setPositionType:(CSSPositionType)positionType -{ - CSSNodeStyleSetPositionType([self cssNode], positionType); -} - -- (void)css_setFlexWrap:(CSSWrapType)flexWrap -{ - CSSNodeStyleSetFlexWrap([self cssNode], flexWrap); -} - -- (void)css_setOverflow:(CSSOverflow)overflow -{ - CSSNodeStyleSetOverflow([self cssNode], overflow); -} - -- (void)css_setFlex:(CGFloat)flex -{ - CSSNodeStyleSetFlex([self cssNode], flex); -} - -- (void)css_setFlexGrow:(CGFloat)flexGrow -{ - CSSNodeStyleSetFlexGrow([self cssNode], flexGrow); -} - -- (void)css_setFlexShrink:(CGFloat)flexShrink -{ - CSSNodeStyleSetFlexShrink([self cssNode], flexShrink); -} - -- (void)css_setFlexBasis:(CGFloat)flexBasis -{ - CSSNodeStyleSetFlexBasis([self cssNode], flexBasis); -} - -- (void)css_setPosition:(CGFloat)position forEdge:(CSSEdge)edge -{ - CSSNodeStyleSetPosition([self cssNode], edge, position); -} - -- (void)css_setMargin:(CGFloat)margin forEdge:(CSSEdge)edge -{ - CSSNodeStyleSetMargin([self cssNode], edge, margin); -} - -- (void)css_setPadding:(CGFloat)padding forEdge:(CSSEdge)edge -{ - CSSNodeStyleSetPadding([self cssNode], edge, padding); -} - -- (void)css_setBorder:(CGFloat)border forEdge:(CSSEdge)edge -{ - CSSNodeStyleSetBorder([self cssNode], edge, border); -} - -- (void)css_setWidth:(CGFloat)width -{ - CSSNodeStyleSetWidth([self cssNode], width); -} - -- (void)css_setHeight:(CGFloat)height -{ - CSSNodeStyleSetHeight([self cssNode], height); -} - -- (void)css_setMinWidth:(CGFloat)minWidth -{ - CSSNodeStyleSetMinWidth([self cssNode], minWidth); -} - -- (void)css_setMinHeight:(CGFloat)minHeight -{ - CSSNodeStyleSetMinHeight([self cssNode], minHeight); -} - -- (void)css_setMaxWidth:(CGFloat)maxWidth -{ - CSSNodeStyleSetMaxWidth([self cssNode], maxWidth); -} - -- (void)css_setMaxHeight:(CGFloat)maxHeight -{ - CSSNodeStyleSetMaxHeight([self cssNode], maxHeight); -} - -- (CSSDirection)css_resolvedDirection -{ - return CSSNodeLayoutGetDirection([self cssNode]); -} - -- (void)css_applyLayout -{ - NSAssert([NSThread isMainThread], @"Method called using a thread other than main!"); - NSAssert([self css_usesFlexbox], @"css_applyLayout must be called on a node using css styling!"); - - _attachNodesRecursive(self); - - CSSNodeRef node = [self cssNode]; - CSSNodeCalculateLayout( - [self cssNode], - CSSNodeStyleGetWidth(node), - CSSNodeStyleGetHeight(node), - CSSNodeStyleGetDirection(node)); - - _updateFrameRecursive(self); -} - -#pragma mark - Private - -static CSSSize _measure( - CSSNodeRef node, - float width, - CSSMeasureMode widthMode, - float height, - CSSMeasureMode heightMode) -{ - if ((widthMode == CSSMeasureModeExactly) && (heightMode == CSSMeasureModeExactly)) { - return (CSSSize) { - .width = width, - .height = height, - }; - } - - UIView *view = (__bridge UIView*) CSSNodeGetContext(node); - const CGSize sizeThatFits = [view sizeThatFits:(CGSize) { - .width = widthMode == CSSMeasureModeUndefined ? CGFLOAT_MAX : width, - .height = heightMode == CSSMeasureModeUndefined ? CGFLOAT_MAX : height, - }]; - - return (CSSSize) { - .width = sizeThatFits.width, - .height = sizeThatFits.height, - }; -} - -static void _attachNodesRecursive(UIView *view) { - CSSNodeRef node = [view cssNode]; - const BOOL usesFlexbox = [view css_usesFlexbox]; - const BOOL isLeaf = !usesFlexbox || view.subviews.count == 0; - - // Only leaf nodes should have a measure function - if (isLeaf) { - CSSNodeSetMeasureFunc(node, _measure); - - // Clear any children - while (CSSNodeChildCount(node) > 0) { - CSSNodeRemoveChild(node, CSSNodeGetChild(node, 0)); - } - } else { - CSSNodeSetMeasureFunc(node, NULL); - - // Add any children which were added since the last call to css_applyLayout - for (NSUInteger i = 0; i < view.subviews.count; i++) { - CSSNodeRef childNode = [view.subviews[i] cssNode]; - if (CSSNodeChildCount(node) < i + 1 || CSSNodeGetChild(node, i) != childNode) { - CSSNodeInsertChild(node, childNode, i); - } - _attachNodesRecursive(view.subviews[i]); - } - - // Remove any children which were removed since the last call to css_applyLayout - while (view.subviews.count < CSSNodeChildCount(node)) { - CSSNodeRemoveChild(node, CSSNodeGetChild(node, CSSNodeChildCount(node) - 1)); - } - } -} - -static void _updateFrameRecursive(UIView *view) { - CSSNodeRef node = [view cssNode]; - const BOOL usesFlexbox = [view css_usesFlexbox]; - const BOOL isLeaf = !usesFlexbox || view.subviews.count == 0; - - view.frame = (CGRect) { - .origin = { - .x = CSSNodeLayoutGetLeft(node), - .y = CSSNodeLayoutGetTop(node), - }, - .size = { - .width = CSSNodeLayoutGetWidth(node), - .height = CSSNodeLayoutGetHeight(node), - }, - }; - - if (!isLeaf) { - for (NSUInteger i = 0; i < view.subviews.count; i++) { - _updateFrameRecursive(view.subviews[i]); - } - } -} - -@end diff --git a/yoga/YGEnums.h b/yoga/YGEnums.h new file mode 100644 index 00000000..85d9d2f9 --- /dev/null +++ b/yoga/YGEnums.h @@ -0,0 +1,116 @@ +/** + * 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 "YGMacros.h" + +YG_EXTERN_C_BEGIN + +typedef enum YGFlexDirection { + YGFlexDirectionColumn, + YGFlexDirectionColumnReverse, + YGFlexDirectionRow, + YGFlexDirectionRowReverse, + YGFlexDirectionCount, +} YGFlexDirection; + +typedef enum YGMeasureMode { + YGMeasureModeUndefined, + YGMeasureModeExactly, + YGMeasureModeAtMost, + YGMeasureModeCount, +} YGMeasureMode; + +typedef enum YGPrintOptions { + YGPrintOptionsLayout = 1, + YGPrintOptionsStyle = 2, + YGPrintOptionsChildren = 4, + YGPrintOptionsCount, +} YGPrintOptions; + +typedef enum YGEdge { + YGEdgeLeft, + YGEdgeTop, + YGEdgeRight, + YGEdgeBottom, + YGEdgeStart, + YGEdgeEnd, + YGEdgeHorizontal, + YGEdgeVertical, + YGEdgeAll, + YGEdgeCount, +} YGEdge; + +typedef enum YGPositionType { + YGPositionTypeRelative, + YGPositionTypeAbsolute, + YGPositionTypeCount, +} YGPositionType; + +typedef enum YGDimension { + YGDimensionWidth, + YGDimensionHeight, + YGDimensionCount, +} YGDimension; + +typedef enum YGJustify { + YGJustifyFlexStart, + YGJustifyCenter, + YGJustifyFlexEnd, + YGJustifySpaceBetween, + YGJustifySpaceAround, + YGJustifyCount, +} YGJustify; + +typedef enum YGDirection { + YGDirectionInherit, + YGDirectionLTR, + YGDirectionRTL, + YGDirectionCount, +} YGDirection; + +typedef enum YGLogLevel { + YGLogLevelError, + YGLogLevelWarn, + YGLogLevelInfo, + YGLogLevelDebug, + YGLogLevelVerbose, + YGLogLevelCount, +} YGLogLevel; + +typedef enum YGWrap { + YGWrapNoWrap, + YGWrapWrap, + YGWrapCount, +} YGWrap; + +typedef enum YGOverflow { + YGOverflowVisible, + YGOverflowHidden, + YGOverflowScroll, + YGOverflowCount, +} YGOverflow; + +typedef enum YGExperimentalFeature { + YGExperimentalFeatureRounding, + YGExperimentalFeatureWebFlexBasis, + YGExperimentalFeatureCount, +} YGExperimentalFeature; + +typedef enum YGAlign { + YGAlignAuto, + YGAlignFlexStart, + YGAlignCenter, + YGAlignFlexEnd, + YGAlignStretch, + YGAlignCount, +} YGAlign; + +YG_EXTERN_C_END diff --git a/CSSLayout/CSSMacros.h b/yoga/YGMacros.h similarity index 54% rename from CSSLayout/CSSMacros.h rename to yoga/YGMacros.h index b9b1faad..def8371a 100644 --- a/CSSLayout/CSSMacros.h +++ b/yoga/YGMacros.h @@ -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,21 +28,15 @@ #endif #if FB_ASSERTIONS_ENABLED -#define CSS_ABORT() abort() +#define YG_ABORT() abort() #else -#define CSS_ABORT() +#define YG_ABORT() #endif -#if CSS_ASSERT_FAIL_ENABLED -#define CSS_ERROR_FUNC(message) CSSAssertFail(message) -#else -#define CSS_ERROR_FUNC(message) fprintf(stderr, "%s", message) -#endif - -#ifndef CSS_ASSERT -#define CSS_ASSERT(X, message) \ - if (!(X)) { \ - CSS_ERROR_FUNC(message); \ - CSS_ABORT(); \ +#ifndef YG_ASSERT +#define YG_ASSERT(X, message) \ + if (!(X)) { \ + YGLog(YGLogLevelError, "%s", message); \ + YG_ABORT(); \ } #endif diff --git a/yoga/YGNodeList.c b/yoga/YGNodeList.c new file mode 100644 index 00000000..d82753e2 --- /dev/null +++ b/yoga/YGNodeList.c @@ -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; +} diff --git a/yoga/YGNodeList.h b/yoga/YGNodeList.h new file mode 100644 index 00000000..41e272ab --- /dev/null +++ b/yoga/YGNodeList.h @@ -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 +#include +#include +#include + +#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 diff --git a/yoga/Yoga.c b/yoga/Yoga.c new file mode 100644 index 00000000..7245fc8c --- /dev/null +++ b/yoga/Yoga.c @@ -0,0 +1,2713 @@ +/** + * 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 + +#include "YGNodeList.h" +#include "Yoga.h" + +#ifdef _MSC_VER +#include +#ifndef isnan +#define isnan _isnan +#endif + +#ifndef __cplusplus +#define inline __inline +#endif + +/* 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 + +typedef struct YGCachedMeasurement { + float availableWidth; + float availableHeight; + YGMeasureMode widthMeasureMode; + YGMeasureMode heightMeasureMode; + + float computedWidth; + float computedHeight; +} YGCachedMeasurement; + +// This value was chosen based on empiracle data. Even the most complicated +// layouts should not require more than 16 entries to fit within the cache. +enum { YG_MAX_CACHED_RESULT_COUNT = 16 }; + +typedef struct YGLayout { + float position[4]; + float dimensions[2]; + YGDirection direction; + + uint32_t computedFlexBasisGeneration; + float computedFlexBasis; + + // Instead of recomputing the entire layout every single time, we + // cache some information to break early when nothing changed + uint32_t generationCount; + YGDirection lastParentDirection; + + uint32_t nextCachedMeasurementsIndex; + YGCachedMeasurement cachedMeasurements[YG_MAX_CACHED_RESULT_COUNT]; + float measuredDimensions[2]; + + YGCachedMeasurement cachedLayout; +} YGLayout; + +typedef struct YGStyle { + YGDirection direction; + YGFlexDirection flexDirection; + YGJustify justifyContent; + YGAlign alignContent; + YGAlign alignItems; + YGAlign alignSelf; + YGPositionType positionType; + YGWrap flexWrap; + YGOverflow overflow; + float flex; + float flexGrow; + float flexShrink; + float flexBasis; + float margin[YGEdgeCount]; + float position[YGEdgeCount]; + float padding[YGEdgeCount]; + float border[YGEdgeCount]; + float dimensions[2]; + float minDimensions[2]; + float maxDimensions[2]; + + // Yoga specific properties, not compatible with flexbox specification + float aspectRatio; +} YGStyle; + +typedef struct YGNode { + YGStyle style; + YGLayout layout; + uint32_t lineIndex; + bool hasNewLayout; + YGNodeRef parent; + YGNodeListRef children; + bool isDirty; + bool isVisible; + + struct YGNode *nextChild; + + YGMeasureFunc measure; + YGPrintFunc print; + void *context; +} YGNode; + +static void YGNodeMarkDirtyInternal(const YGNodeRef node); + +YGMalloc gYGMalloc = &malloc; +YGCalloc gYGCalloc = &calloc; +YGRealloc gYGRealloc = &realloc; +YGFree gYGFree = &free; + +#ifdef ANDROID +#include +static int YGAndroidLog(YGLogLevel level, const char *format, va_list args) { + int androidLevel = YGLogLevelDebug; + switch (level) { + case YGLogLevelError: + androidLevel = ANDROID_LOG_ERROR; + break; + case YGLogLevelWarn: + androidLevel = ANDROID_LOG_WARN; + break; + case YGLogLevelInfo: + androidLevel = ANDROID_LOG_INFO; + break; + case YGLogLevelDebug: + androidLevel = ANDROID_LOG_DEBUG; + break; + case YGLogLevelVerbose: + androidLevel = ANDROID_LOG_VERBOSE; + break; + case YGLogLevelCount: + break; + } + const int result = __android_log_vprint(androidLevel, "YG-layout", format, args); + return result; +} +static YGLogger gLogger = &YGAndroidLog; +#else +static int YGDefaultLog(YGLogLevel level, const char *format, va_list args) { + switch (level) { + case YGLogLevelError: + return vfprintf(stderr, format, args); + case YGLogLevelWarn: + case YGLogLevelInfo: + case YGLogLevelDebug: + case YGLogLevelVerbose: + default: + return vprintf(format, args); + } +} +static YGLogger gLogger = &YGDefaultLog; +#endif + +static inline float YGComputedEdgeValue(const float edges[YGEdgeCount], + const YGEdge edge, + const float defaultValue) { + YG_ASSERT(edge <= YGEdgeEnd, "Cannot get computed value of multi-edge shorthands"); + + if (!YGValueIsUndefined(edges[edge])) { + return edges[edge]; + } + + if ((edge == YGEdgeTop || edge == YGEdgeBottom) && !YGValueIsUndefined(edges[YGEdgeVertical])) { + return edges[YGEdgeVertical]; + } + + if ((edge == YGEdgeLeft || edge == YGEdgeRight || edge == YGEdgeStart || edge == YGEdgeEnd) && + !YGValueIsUndefined(edges[YGEdgeHorizontal])) { + return edges[YGEdgeHorizontal]; + } + + if (!YGValueIsUndefined(edges[YGEdgeAll])) { + return edges[YGEdgeAll]; + } + + if (edge == YGEdgeStart || edge == YGEdgeEnd) { + return YGUndefined; + } + + return defaultValue; +} + +static void YGNodeInit(const YGNodeRef node) { + node->parent = NULL; + node->children = NULL; + node->hasNewLayout = true; + node->isDirty = false; + node->isVisible = true; + + node->style.flex = YGUndefined; + node->style.flexGrow = YGUndefined; + node->style.flexShrink = YGUndefined; + node->style.flexBasis = YGUndefined; + + node->style.alignItems = YGAlignStretch; + node->style.alignContent = YGAlignFlexStart; + + node->style.direction = YGDirectionInherit; + node->style.flexDirection = YGFlexDirectionColumn; + + node->style.overflow = YGOverflowVisible; + + // Some of the fields default to undefined and not 0 + node->style.dimensions[YGDimensionWidth] = YGUndefined; + node->style.dimensions[YGDimensionHeight] = YGUndefined; + + node->style.minDimensions[YGDimensionWidth] = YGUndefined; + node->style.minDimensions[YGDimensionHeight] = YGUndefined; + + node->style.maxDimensions[YGDimensionWidth] = YGUndefined; + node->style.maxDimensions[YGDimensionHeight] = YGUndefined; + + for (YGEdge edge = YGEdgeLeft; edge < YGEdgeCount; edge++) { + node->style.position[edge] = YGUndefined; + node->style.margin[edge] = YGUndefined; + node->style.padding[edge] = YGUndefined; + node->style.border[edge] = YGUndefined; + } + + node->style.aspectRatio = YGUndefined; + + node->layout.dimensions[YGDimensionWidth] = YGUndefined; + node->layout.dimensions[YGDimensionHeight] = YGUndefined; + + // Such that the comparison is always going to be false + node->layout.lastParentDirection = (YGDirection) -1; + node->layout.nextCachedMeasurementsIndex = 0; + node->layout.computedFlexBasis = YGUndefined; + + node->layout.measuredDimensions[YGDimensionWidth] = YGUndefined; + node->layout.measuredDimensions[YGDimensionHeight] = YGUndefined; + node->layout.cachedLayout.widthMeasureMode = (YGMeasureMode) -1; + node->layout.cachedLayout.heightMeasureMode = (YGMeasureMode) -1; + node->layout.cachedLayout.computedWidth = -1; + node->layout.cachedLayout.computedHeight = -1; +} + +int32_t gNodeInstanceCount = 0; + +YGNodeRef YGNodeNew(void) { + const YGNodeRef node = gYGCalloc(1, sizeof(YGNode)); + YG_ASSERT(node, "Could not allocate memory for node"); + gNodeInstanceCount++; + + YGNodeInit(node); + return node; +} + +void YGNodeFree(const YGNodeRef node) { + if (node->parent) { + YGNodeListDelete(node->parent->children, node); + node->parent = NULL; + } + + const uint32_t childCount = YGNodeChildCount(node); + for (uint32_t i = 0; i < childCount; i++) { + const YGNodeRef child = YGNodeGetChild(node, i); + child->parent = NULL; + } + + YGNodeListFree(node->children); + gYGFree(node); + gNodeInstanceCount--; +} + +void YGNodeFreeRecursive(const YGNodeRef root) { + while (YGNodeChildCount(root) > 0) { + const YGNodeRef child = YGNodeGetChild(root, 0); + YGNodeRemoveChild(root, child); + YGNodeFreeRecursive(child); + } + YGNodeFree(root); +} + +void YGNodeReset(const YGNodeRef node) { + YG_ASSERT(YGNodeChildCount(node) == 0, "Cannot reset a node which still has children attached"); + YG_ASSERT(node->parent == NULL, "Cannot reset a node still attached to a parent"); + + YGNodeListFree(node->children); + memset(node, 0, sizeof(YGNode)); + YGNodeInit(node); +} + +int32_t YGNodeGetInstanceCount(void) { + return gNodeInstanceCount; +} + +static void YGNodeMarkDirtyInternal(const YGNodeRef node) { + if (!node->isDirty) { + node->isDirty = true; + node->layout.computedFlexBasis = YGUndefined; + if (node->parent) { + YGNodeMarkDirtyInternal(node->parent); + } + } +} + +void YGNodeSetMeasureFunc(const YGNodeRef node, YGMeasureFunc measureFunc) { + if (measureFunc == NULL) { + node->measure = NULL; + } else { + YG_ASSERT(YGNodeChildCount(node) == 0, + "Cannot set measure function: Nodes with measure functions cannot have children."); + node->measure = measureFunc; + } +} + +YGMeasureFunc YGNodeGetMeasureFunc(const YGNodeRef node) { + return node->measure; +} + +void YGNodeInsertChild(const YGNodeRef node, const YGNodeRef child, const uint32_t index) { + YG_ASSERT(child->parent == NULL, "Child already has a parent, it must be removed first."); + YG_ASSERT(node->measure == NULL, + "Cannot add child: Nodes with measure functions cannot have children."); + YGNodeListInsert(&node->children, child, index); + child->parent = node; + YGNodeMarkDirtyInternal(node); +} + +void YGNodeRemoveChild(const YGNodeRef node, const YGNodeRef child) { + if (YGNodeListDelete(node->children, child) != NULL) { + child->parent = NULL; + YGNodeMarkDirtyInternal(node); + } +} + +YGNodeRef YGNodeGetChild(const YGNodeRef node, const uint32_t index) { + return YGNodeListGet(node->children, index); +} + +inline uint32_t YGNodeChildCount(const YGNodeRef node) { + return YGNodeListCount(node->children); +} + +void YGNodeMarkDirty(const YGNodeRef node) { + YG_ASSERT(node->measure != NULL, + "Only leaf nodes with custom measure functions" + "should manually mark themselves as dirty"); + YGNodeMarkDirtyInternal(node); +} + +bool YGNodeIsDirty(const YGNodeRef node) { + return node->isDirty; +} + +void YGNodeHide(const YGNodeRef node) { + node->isVisible = false; + node->isDirty = false; /* See https://github.com/facebook/css-layout/issues/241 */ + _YGNodeMarkDirty(node); +} + +void YGNodeShow(const YGNodeRef node) { + node->isVisible = true; + node->isDirty = false; /* See https://github.com/facebook/css-layout/issues/241 */ + _YGNodeMarkDirty(node); +} + +bool YGNodeIsVisible(const YGNodeRef node) { + return node->isVisible; +} + +void YGNodeCopyStyle(const YGNodeRef dstNode, const YGNodeRef srcNode) { + if (memcmp(&dstNode->style, &srcNode->style, sizeof(YGStyle)) != 0) { + memcpy(&dstNode->style, &srcNode->style, sizeof(YGStyle)); + YGNodeMarkDirtyInternal(dstNode); + } +} + +inline float YGNodeStyleGetFlexGrow(const YGNodeRef node) { + if (!YGValueIsUndefined(node->style.flexGrow)) { + return node->style.flexGrow; + } + if (!YGValueIsUndefined(node->style.flex) && node->style.flex > 0) { + return node->style.flex; + } + return 0; +} + +inline float YGNodeStyleGetFlexShrink(const YGNodeRef node) { + if (!YGValueIsUndefined(node->style.flexShrink)) { + return node->style.flexShrink; + } + if (!YGValueIsUndefined(node->style.flex) && node->style.flex < 0) { + return -node->style.flex; + } + return 0; +} + +inline float YGNodeStyleGetFlexBasis(const YGNodeRef node) { + if (!YGValueIsUndefined(node->style.flexBasis)) { + return node->style.flexBasis; + } + if (!YGValueIsUndefined(node->style.flex)) { + return node->style.flex > 0 ? 0 : YGUndefined; + } + return YGUndefined; +} + +void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) { + if (node->style.flex != flex) { + node->style.flex = flex; + YGNodeMarkDirtyInternal(node); + } +} + +#define YG_NODE_PROPERTY_IMPL(type, name, paramName, instanceName) \ + void YGNodeSet##name(const YGNodeRef node, type paramName) { \ + node->instanceName = paramName; \ + } \ + \ + type YGNodeGet##name(const YGNodeRef node) { \ + return node->instanceName; \ + } + +#define YG_NODE_STYLE_PROPERTY_SETTER_IMPL(type, name, paramName, instanceName) \ + void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \ + if (node->style.instanceName != paramName) { \ + node->style.instanceName = paramName; \ + YGNodeMarkDirtyInternal(node); \ + } \ + } + +#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) { \ + return node->style.instanceName; \ + } + +#define YG_NODE_STYLE_EDGE_PROPERTY_IMPL(type, name, paramName, instanceName, defaultValue) \ + void YGNodeStyleSet##name(const YGNodeRef node, const YGEdge edge, const type paramName) { \ + if (node->style.instanceName[edge] != paramName) { \ + node->style.instanceName[edge] = paramName; \ + YGNodeMarkDirtyInternal(node); \ + } \ + } \ + \ + type YGNodeStyleGet##name(const YGNodeRef node, const YGEdge edge) { \ + return YGComputedEdgeValue(node->style.instanceName, edge, defaultValue); \ + } + +#define YG_NODE_LAYOUT_PROPERTY_IMPL(type, name, instanceName) \ + type YGNodeLayoutGet##name(const YGNodeRef node) { \ + return node->layout.instanceName; \ + } + +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_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); + +YG_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexGrow, flexGrow, flexGrow); +YG_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexShrink, flexShrink, flexShrink); +YG_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexBasis, flexBasis, flexBasis); + +YG_NODE_STYLE_EDGE_PROPERTY_IMPL(float, Position, position, position, YGUndefined); +YG_NODE_STYLE_EDGE_PROPERTY_IMPL(float, Margin, margin, margin, 0); +YG_NODE_STYLE_EDGE_PROPERTY_IMPL(float, Padding, padding, padding, 0); +YG_NODE_STYLE_EDGE_PROPERTY_IMPL(float, Border, border, border, 0); + +YG_NODE_STYLE_PROPERTY_IMPL(float, Width, width, dimensions[YGDimensionWidth]); +YG_NODE_STYLE_PROPERTY_IMPL(float, Height, height, dimensions[YGDimensionHeight]); +YG_NODE_STYLE_PROPERTY_IMPL(float, MinWidth, minWidth, minDimensions[YGDimensionWidth]); +YG_NODE_STYLE_PROPERTY_IMPL(float, MinHeight, minHeight, minDimensions[YGDimensionHeight]); +YG_NODE_STYLE_PROPERTY_IMPL(float, MaxWidth, maxWidth, maxDimensions[YGDimensionWidth]); +YG_NODE_STYLE_PROPERTY_IMPL(float, MaxHeight, maxHeight, maxDimensions[YGDimensionHeight]); + +// Yoga specific properties, not compatible with flexbox specification +YG_NODE_STYLE_PROPERTY_IMPL(float, AspectRatio, aspectRatio, aspectRatio); + +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); + +uint32_t gCurrentGenerationCount = 0; + +bool YGLayoutNodeInternal(const YGNodeRef node, + const float availableWidth, + const float availableHeight, + const YGDirection parentDirection, + const YGMeasureMode widthMeasureMode, + const YGMeasureMode heightMeasureMode, + const bool performLayout, + const char *reason); + +inline bool YGValueIsUndefined(const float value) { + return isnan(value); +} + +static inline bool YGFloatsEqual(const float a, const float b) { + if (YGValueIsUndefined(a)) { + return YGValueIsUndefined(b); + } + return fabs(a - b) < 0.0001; +} + +static void YGIndent(const uint32_t n) { + for (uint32_t i = 0; i < n; i++) { + YGLog(YGLogLevelDebug, " "); + } +} + +static void YGPrintNumberIfNotZero(const char *str, const float number) { + if (!YGFloatsEqual(number, 0)) { + YGLog(YGLogLevelDebug, "%s: %g, ", str, number); + } +} + +static void YGPrintNumberIfNotUndefined(const char *str, const float number) { + if (!YGValueIsUndefined(number)) { + YGLog(YGLogLevelDebug, "%s: %g, ", str, number); + } +} + +static bool YGFourFloatsEqual(const float four[4]) { + return YGFloatsEqual(four[0], four[1]) && YGFloatsEqual(four[0], four[2]) && + YGFloatsEqual(four[0], four[3]); +} + +static void YGNodePrintInternal(const YGNodeRef node, + const YGPrintOptions options, + const uint32_t level) { + YGIndent(level); + YGLog(YGLogLevelDebug, "{"); + + if (node->print) { + node->print(node); + } + + if (options & YGPrintOptionsLayout) { + YGLog(YGLogLevelDebug, "layout: {"); + YGLog(YGLogLevelDebug, "width: %g, ", node->layout.dimensions[YGDimensionWidth]); + YGLog(YGLogLevelDebug, "height: %g, ", node->layout.dimensions[YGDimensionHeight]); + YGLog(YGLogLevelDebug, "top: %g, ", node->layout.position[YGEdgeTop]); + YGLog(YGLogLevelDebug, "left: %g", node->layout.position[YGEdgeLeft]); + YGLog(YGLogLevelDebug, "}, "); + } + + if (options & YGPrintOptionsStyle) { + if (node->style.flexDirection == YGFlexDirectionColumn) { + YGLog(YGLogLevelDebug, "flexDirection: 'column', "); + } else if (node->style.flexDirection == YGFlexDirectionColumnReverse) { + YGLog(YGLogLevelDebug, "flexDirection: 'column-reverse', "); + } else if (node->style.flexDirection == YGFlexDirectionRow) { + YGLog(YGLogLevelDebug, "flexDirection: 'row', "); + } else if (node->style.flexDirection == YGFlexDirectionRowReverse) { + YGLog(YGLogLevelDebug, "flexDirection: 'row-reverse', "); + } + + if (node->style.justifyContent == YGJustifyCenter) { + YGLog(YGLogLevelDebug, "justifyContent: 'center', "); + } else if (node->style.justifyContent == YGJustifyFlexEnd) { + YGLog(YGLogLevelDebug, "justifyContent: 'flex-end', "); + } else if (node->style.justifyContent == YGJustifySpaceAround) { + YGLog(YGLogLevelDebug, "justifyContent: 'space-around', "); + } else if (node->style.justifyContent == YGJustifySpaceBetween) { + YGLog(YGLogLevelDebug, "justifyContent: 'space-between', "); + } + + if (node->style.alignItems == YGAlignCenter) { + YGLog(YGLogLevelDebug, "alignItems: 'center', "); + } else if (node->style.alignItems == YGAlignFlexEnd) { + YGLog(YGLogLevelDebug, "alignItems: 'flex-end', "); + } else if (node->style.alignItems == YGAlignStretch) { + YGLog(YGLogLevelDebug, "alignItems: 'stretch', "); + } + + if (node->style.alignContent == YGAlignCenter) { + YGLog(YGLogLevelDebug, "alignContent: 'center', "); + } else if (node->style.alignContent == YGAlignFlexEnd) { + YGLog(YGLogLevelDebug, "alignContent: 'flex-end', "); + } else if (node->style.alignContent == YGAlignStretch) { + YGLog(YGLogLevelDebug, "alignContent: 'stretch', "); + } + + if (node->style.alignSelf == YGAlignFlexStart) { + YGLog(YGLogLevelDebug, "alignSelf: 'flex-start', "); + } else if (node->style.alignSelf == YGAlignCenter) { + YGLog(YGLogLevelDebug, "alignSelf: 'center', "); + } else if (node->style.alignSelf == YGAlignFlexEnd) { + YGLog(YGLogLevelDebug, "alignSelf: 'flex-end', "); + } else if (node->style.alignSelf == YGAlignStretch) { + YGLog(YGLogLevelDebug, "alignSelf: 'stretch', "); + } + + YGPrintNumberIfNotUndefined("flexGrow", YGNodeStyleGetFlexGrow(node)); + YGPrintNumberIfNotUndefined("flexShrink", YGNodeStyleGetFlexShrink(node)); + YGPrintNumberIfNotUndefined("flexBasis", YGNodeStyleGetFlexBasis(node)); + + if (node->style.overflow == YGOverflowHidden) { + YGLog(YGLogLevelDebug, "overflow: 'hidden', "); + } else if (node->style.overflow == YGOverflowVisible) { + YGLog(YGLogLevelDebug, "overflow: 'visible', "); + } else if (node->style.overflow == YGOverflowScroll) { + YGLog(YGLogLevelDebug, "overflow: 'scroll', "); + } + + if (YGFourFloatsEqual(node->style.margin)) { + YGPrintNumberIfNotZero("margin", YGComputedEdgeValue(node->style.margin, YGEdgeLeft, 0)); + } else { + YGPrintNumberIfNotZero("marginLeft", YGComputedEdgeValue(node->style.margin, YGEdgeLeft, 0)); + YGPrintNumberIfNotZero("marginRight", + YGComputedEdgeValue(node->style.margin, YGEdgeRight, 0)); + YGPrintNumberIfNotZero("marginTop", YGComputedEdgeValue(node->style.margin, YGEdgeTop, 0)); + YGPrintNumberIfNotZero("marginBottom", + YGComputedEdgeValue(node->style.margin, YGEdgeBottom, 0)); + YGPrintNumberIfNotZero("marginStart", + YGComputedEdgeValue(node->style.margin, YGEdgeStart, 0)); + YGPrintNumberIfNotZero("marginEnd", YGComputedEdgeValue(node->style.margin, YGEdgeEnd, 0)); + } + + if (YGFourFloatsEqual(node->style.padding)) { + YGPrintNumberIfNotZero("padding", YGComputedEdgeValue(node->style.padding, YGEdgeLeft, 0)); + } else { + YGPrintNumberIfNotZero("paddingLeft", + YGComputedEdgeValue(node->style.padding, YGEdgeLeft, 0)); + YGPrintNumberIfNotZero("paddingRight", + YGComputedEdgeValue(node->style.padding, YGEdgeRight, 0)); + YGPrintNumberIfNotZero("paddingTop", YGComputedEdgeValue(node->style.padding, YGEdgeTop, 0)); + YGPrintNumberIfNotZero("paddingBottom", + YGComputedEdgeValue(node->style.padding, YGEdgeBottom, 0)); + YGPrintNumberIfNotZero("paddingStart", + YGComputedEdgeValue(node->style.padding, YGEdgeStart, 0)); + YGPrintNumberIfNotZero("paddingEnd", YGComputedEdgeValue(node->style.padding, YGEdgeEnd, 0)); + } + + if (YGFourFloatsEqual(node->style.border)) { + YGPrintNumberIfNotZero("borderWidth", YGComputedEdgeValue(node->style.border, YGEdgeLeft, 0)); + } else { + YGPrintNumberIfNotZero("borderLeftWidth", + YGComputedEdgeValue(node->style.border, YGEdgeLeft, 0)); + YGPrintNumberIfNotZero("borderRightWidth", + YGComputedEdgeValue(node->style.border, YGEdgeRight, 0)); + YGPrintNumberIfNotZero("borderTopWidth", + YGComputedEdgeValue(node->style.border, YGEdgeTop, 0)); + YGPrintNumberIfNotZero("borderBottomWidth", + YGComputedEdgeValue(node->style.border, YGEdgeBottom, 0)); + YGPrintNumberIfNotZero("borderStartWidth", + YGComputedEdgeValue(node->style.border, YGEdgeStart, 0)); + YGPrintNumberIfNotZero("borderEndWidth", + YGComputedEdgeValue(node->style.border, YGEdgeEnd, 0)); + } + + YGPrintNumberIfNotUndefined("width", node->style.dimensions[YGDimensionWidth]); + YGPrintNumberIfNotUndefined("height", node->style.dimensions[YGDimensionHeight]); + YGPrintNumberIfNotUndefined("maxWidth", node->style.maxDimensions[YGDimensionWidth]); + YGPrintNumberIfNotUndefined("maxHeight", node->style.maxDimensions[YGDimensionHeight]); + YGPrintNumberIfNotUndefined("minWidth", node->style.minDimensions[YGDimensionWidth]); + YGPrintNumberIfNotUndefined("minHeight", node->style.minDimensions[YGDimensionHeight]); + + if (node->style.positionType == YGPositionTypeAbsolute) { + YGLog(YGLogLevelDebug, "position: 'absolute', "); + } + + YGPrintNumberIfNotUndefined("left", + YGComputedEdgeValue(node->style.position, YGEdgeLeft, YGUndefined)); + YGPrintNumberIfNotUndefined( + "right", YGComputedEdgeValue(node->style.position, YGEdgeRight, YGUndefined)); + YGPrintNumberIfNotUndefined("top", + YGComputedEdgeValue(node->style.position, YGEdgeTop, YGUndefined)); + YGPrintNumberIfNotUndefined( + "bottom", YGComputedEdgeValue(node->style.position, YGEdgeBottom, YGUndefined)); + } + + const uint32_t childCount = YGNodeListCount(node->children); + if (options & YGPrintOptionsChildren && childCount > 0) { + YGLog(YGLogLevelDebug, "children: [\n"); + for (uint32_t i = 0; i < childCount; i++) { + YGNodePrintInternal(YGNodeGetChild(node, i), options, level + 1); + } + YGIndent(level); + YGLog(YGLogLevelDebug, "]},\n"); + } else { + YGLog(YGLogLevelDebug, "},\n"); + } +} + +void YGNodePrint(const YGNodeRef node, const YGPrintOptions options) { + YGNodePrintInternal(node, options, 0); +} + +static const YGEdge leading[4] = { + [YGFlexDirectionColumn] = YGEdgeTop, + [YGFlexDirectionColumnReverse] = YGEdgeBottom, + [YGFlexDirectionRow] = YGEdgeLeft, + [YGFlexDirectionRowReverse] = YGEdgeRight, +}; +static const YGEdge trailing[4] = { + [YGFlexDirectionColumn] = YGEdgeBottom, + [YGFlexDirectionColumnReverse] = YGEdgeTop, + [YGFlexDirectionRow] = YGEdgeRight, + [YGFlexDirectionRowReverse] = YGEdgeLeft, +}; +static const YGEdge pos[4] = { + [YGFlexDirectionColumn] = YGEdgeTop, + [YGFlexDirectionColumnReverse] = YGEdgeBottom, + [YGFlexDirectionRow] = YGEdgeLeft, + [YGFlexDirectionRowReverse] = YGEdgeRight, +}; +static const YGDimension dim[4] = { + [YGFlexDirectionColumn] = YGDimensionHeight, + [YGFlexDirectionColumnReverse] = YGDimensionHeight, + [YGFlexDirectionRow] = YGDimensionWidth, + [YGFlexDirectionRowReverse] = YGDimensionWidth, +}; + +static inline bool YGFlexDirectionIsRow(const YGFlexDirection flexDirection) { + return flexDirection == YGFlexDirectionRow || flexDirection == YGFlexDirectionRowReverse; +} + +static inline bool YGFlexDirectionIsColumn(const YGFlexDirection flexDirection) { + return flexDirection == YGFlexDirectionColumn || flexDirection == YGFlexDirectionColumnReverse; +} + +static inline float YGNodeLeadingMargin(const YGNodeRef node, const YGFlexDirection axis) { + if (YGFlexDirectionIsRow(axis) && !YGValueIsUndefined(node->style.margin[YGEdgeStart])) { + return node->style.margin[YGEdgeStart]; + } + + return YGComputedEdgeValue(node->style.margin, leading[axis], 0); +} + +static float YGNodeTrailingMargin(const YGNodeRef node, const YGFlexDirection axis) { + if (YGFlexDirectionIsRow(axis) && !YGValueIsUndefined(node->style.margin[YGEdgeEnd])) { + return node->style.margin[YGEdgeEnd]; + } + + return YGComputedEdgeValue(node->style.margin, trailing[axis], 0); +} + +static float YGNodeLeadingPadding(const YGNodeRef node, const YGFlexDirection axis) { + if (YGFlexDirectionIsRow(axis) && !YGValueIsUndefined(node->style.padding[YGEdgeStart]) && + node->style.padding[YGEdgeStart] >= 0) { + return node->style.padding[YGEdgeStart]; + } + + return fmaxf(YGComputedEdgeValue(node->style.padding, leading[axis], 0), 0); +} + +static float YGNodeTrailingPadding(const YGNodeRef node, const YGFlexDirection axis) { + if (YGFlexDirectionIsRow(axis) && !YGValueIsUndefined(node->style.padding[YGEdgeEnd]) && + node->style.padding[YGEdgeEnd] >= 0) { + return node->style.padding[YGEdgeEnd]; + } + + return fmaxf(YGComputedEdgeValue(node->style.padding, trailing[axis], 0), 0); +} + +static float YGNodeLeadingBorder(const YGNodeRef node, const YGFlexDirection axis) { + if (YGFlexDirectionIsRow(axis) && !YGValueIsUndefined(node->style.border[YGEdgeStart]) && + node->style.border[YGEdgeStart] >= 0) { + return node->style.border[YGEdgeStart]; + } + + return fmaxf(YGComputedEdgeValue(node->style.border, leading[axis], 0), 0); +} + +static float YGNodeTrailingBorder(const YGNodeRef node, const YGFlexDirection axis) { + if (YGFlexDirectionIsRow(axis) && !YGValueIsUndefined(node->style.border[YGEdgeEnd]) && + node->style.border[YGEdgeEnd] >= 0) { + return node->style.border[YGEdgeEnd]; + } + + return fmaxf(YGComputedEdgeValue(node->style.border, trailing[axis], 0), 0); +} + +static inline float YGNodeLeadingPaddingAndBorder(const YGNodeRef node, + const YGFlexDirection axis) { + return YGNodeLeadingPadding(node, axis) + YGNodeLeadingBorder(node, axis); +} + +static inline float YGNodeTrailingPaddingAndBorder(const YGNodeRef node, + const YGFlexDirection axis) { + return YGNodeTrailingPadding(node, axis) + YGNodeTrailingBorder(node, axis); +} + +static inline float YGNodeMarginForAxis(const YGNodeRef node, const YGFlexDirection axis) { + return YGNodeLeadingMargin(node, axis) + YGNodeTrailingMargin(node, axis); +} + +static inline float YGNodePaddingAndBorderForAxis(const YGNodeRef node, + const YGFlexDirection axis) { + return YGNodeLeadingPaddingAndBorder(node, axis) + YGNodeTrailingPaddingAndBorder(node, axis); +} + +static inline YGAlign YGNodeAlignItem(const YGNodeRef node, const YGNodeRef child) { + return child->style.alignSelf == YGAlignAuto ? node->style.alignItems : child->style.alignSelf; +} + +static inline YGDirection YGNodeResolveDirection(const YGNodeRef node, + const YGDirection parentDirection) { + if (node->style.direction == YGDirectionInherit) { + return parentDirection > YGDirectionInherit ? parentDirection : YGDirectionLTR; + } else { + return node->style.direction; + } +} + +static inline YGFlexDirection YGFlexDirectionResolve(const YGFlexDirection flexDirection, + const YGDirection direction) { + if (direction == YGDirectionRTL) { + if (flexDirection == YGFlexDirectionRow) { + return YGFlexDirectionRowReverse; + } else if (flexDirection == YGFlexDirectionRowReverse) { + return YGFlexDirectionRow; + } + } + + return flexDirection; +} + +static YGFlexDirection YGFlexDirectionCross(const YGFlexDirection flexDirection, + const YGDirection direction) { + return YGFlexDirectionIsColumn(flexDirection) + ? YGFlexDirectionResolve(YGFlexDirectionRow, direction) + : YGFlexDirectionColumn; +} + +static inline bool YGNodeIsFlex(const YGNodeRef node) { + return (node->style.positionType == YGPositionTypeRelative && + (node->style.flexGrow != 0 || node->style.flexShrink != 0 || node->style.flex != 0)); +} + +static inline float YGNodeDimWithMargin(const YGNodeRef node, const YGFlexDirection axis) { + return node->layout.measuredDimensions[dim[axis]] + YGNodeLeadingMargin(node, axis) + + YGNodeTrailingMargin(node, axis); +} + +static inline bool YGNodeIsStyleDimDefined(const YGNodeRef node, const YGFlexDirection axis) { + const float value = node->style.dimensions[dim[axis]]; + return !YGValueIsUndefined(value) && value >= 0.0; +} + +static inline bool YGNodeIsLayoutDimDefined(const YGNodeRef node, const YGFlexDirection axis) { + const float value = node->layout.measuredDimensions[dim[axis]]; + return !YGValueIsUndefined(value) && value >= 0.0; +} + +static inline bool YGNodeIsLeadingPosDefined(const YGNodeRef node, const YGFlexDirection axis) { + return (YGFlexDirectionIsRow(axis) && + !YGValueIsUndefined( + YGComputedEdgeValue(node->style.position, YGEdgeStart, YGUndefined))) || + !YGValueIsUndefined(YGComputedEdgeValue(node->style.position, leading[axis], YGUndefined)); +} + +static inline bool YGNodeIsTrailingPosDefined(const YGNodeRef node, const YGFlexDirection axis) { + return (YGFlexDirectionIsRow(axis) && + !YGValueIsUndefined(YGComputedEdgeValue(node->style.position, YGEdgeEnd, YGUndefined))) || + !YGValueIsUndefined( + YGComputedEdgeValue(node->style.position, trailing[axis], YGUndefined)); +} + +static float YGNodeLeadingPosition(const YGNodeRef node, const YGFlexDirection axis) { + if (YGFlexDirectionIsRow(axis)) { + const float leadingPosition = + YGComputedEdgeValue(node->style.position, YGEdgeStart, YGUndefined); + if (!YGValueIsUndefined(leadingPosition)) { + return leadingPosition; + } + } + + const float leadingPosition = + YGComputedEdgeValue(node->style.position, leading[axis], YGUndefined); + + return YGValueIsUndefined(leadingPosition) ? 0 : leadingPosition; +} + +static float YGNodeTrailingPosition(const YGNodeRef node, const YGFlexDirection axis) { + if (YGFlexDirectionIsRow(axis)) { + const float trailingPosition = + YGComputedEdgeValue(node->style.position, YGEdgeEnd, YGUndefined); + if (!YGValueIsUndefined(trailingPosition)) { + return trailingPosition; + } + } + + const float trailingPosition = + YGComputedEdgeValue(node->style.position, trailing[axis], YGUndefined); + + return YGValueIsUndefined(trailingPosition) ? 0 : trailingPosition; +} + +static float YGNodeBoundAxisWithinMinAndMax(const YGNodeRef node, + const YGFlexDirection axis, + const float value) { + float min = YGUndefined; + float max = YGUndefined; + + if (YGFlexDirectionIsColumn(axis)) { + min = node->style.minDimensions[YGDimensionHeight]; + max = node->style.maxDimensions[YGDimensionHeight]; + } else if (YGFlexDirectionIsRow(axis)) { + min = node->style.minDimensions[YGDimensionWidth]; + max = node->style.maxDimensions[YGDimensionWidth]; + } + + float boundValue = value; + + if (!YGValueIsUndefined(max) && max >= 0.0 && boundValue > max) { + boundValue = max; + } + + if (!YGValueIsUndefined(min) && min >= 0.0 && boundValue < min) { + boundValue = min; + } + + return boundValue; +} + +// Like YGNodeBoundAxisWithinMinAndMax but also ensures that the value doesn't go +// below the +// padding and border amount. +static inline float YGNodeBoundAxis(const YGNodeRef node, + const YGFlexDirection axis, + const float value) { + return fmaxf(YGNodeBoundAxisWithinMinAndMax(node, axis, value), + YGNodePaddingAndBorderForAxis(node, axis)); +} + +static void YGNodeSetChildTrailingPosition(const YGNodeRef node, + const YGNodeRef child, + const YGFlexDirection axis) { + const float size = child->layout.measuredDimensions[dim[axis]]; + child->layout.position[trailing[axis]] = + node->layout.measuredDimensions[dim[axis]] - size - child->layout.position[pos[axis]]; +} + +// If both left and right are defined, then use left. Otherwise return +// +left or -right depending on which is defined. +static float YGNodeRelativePosition(const YGNodeRef node, const YGFlexDirection axis) { + return YGNodeIsLeadingPosDefined(node, axis) ? YGNodeLeadingPosition(node, axis) + : -YGNodeTrailingPosition(node, axis); +} + +static void YGConstrainMaxSizeForMode(const float maxSize, YGMeasureMode *mode, float *size) { + switch (*mode) { + case YGMeasureModeExactly: + case YGMeasureModeAtMost: + *size = (YGValueIsUndefined(maxSize) || *size < maxSize) ? *size : maxSize; + break; + case YGMeasureModeUndefined: + if (!YGValueIsUndefined(maxSize)) { + *mode = YGMeasureModeAtMost; + *size = maxSize; + } + break; + case YGMeasureModeCount: + break; + } +} + +static void YGNodeSetPosition(const YGNodeRef node, const YGDirection direction) { + const YGFlexDirection mainAxis = YGFlexDirectionResolve(node->style.flexDirection, direction); + const YGFlexDirection crossAxis = YGFlexDirectionCross(mainAxis, direction); + const float relativePositionMain = YGNodeRelativePosition(node, mainAxis); + const float relativePositionCross = YGNodeRelativePosition(node, crossAxis); + + node->layout.position[leading[mainAxis]] = + YGNodeLeadingMargin(node, mainAxis) + relativePositionMain; + node->layout.position[trailing[mainAxis]] = + YGNodeTrailingMargin(node, mainAxis) + relativePositionMain; + node->layout.position[leading[crossAxis]] = + YGNodeLeadingMargin(node, crossAxis) + relativePositionCross; + node->layout.position[trailing[crossAxis]] = + YGNodeTrailingMargin(node, crossAxis) + relativePositionCross; +} + +static void YGNodeComputeFlexBasisForChild(const YGNodeRef node, + const YGNodeRef child, + const float width, + const YGMeasureMode widthMode, + const float height, + const YGMeasureMode heightMode, + const YGDirection direction) { + const YGFlexDirection mainAxis = YGFlexDirectionResolve(node->style.flexDirection, direction); + const bool isMainAxisRow = YGFlexDirectionIsRow(mainAxis); + + float childWidth; + float childHeight; + YGMeasureMode childWidthMeasureMode; + YGMeasureMode childHeightMeasureMode; + + const bool isRowStyleDimDefined = YGNodeIsStyleDimDefined(child, YGFlexDirectionRow); + const bool isColumnStyleDimDefined = YGNodeIsStyleDimDefined(child, YGFlexDirectionColumn); + + if (!YGValueIsUndefined(YGNodeStyleGetFlexBasis(child)) && + !YGValueIsUndefined(isMainAxisRow ? width : height)) { + if (YGValueIsUndefined(child->layout.computedFlexBasis) || + (YGIsExperimentalFeatureEnabled(YGExperimentalFeatureWebFlexBasis) && + child->layout.computedFlexBasisGeneration != gCurrentGenerationCount)) { + child->layout.computedFlexBasis = + fmaxf(YGNodeStyleGetFlexBasis(child), YGNodePaddingAndBorderForAxis(child, mainAxis)); + } + } else if (isMainAxisRow && isRowStyleDimDefined) { + // The width is definite, so use that as the flex basis. + child->layout.computedFlexBasis = + fmaxf(child->style.dimensions[YGDimensionWidth], + YGNodePaddingAndBorderForAxis(child, YGFlexDirectionRow)); + } else if (!isMainAxisRow && isColumnStyleDimDefined) { + // The height is definite, so use that as the flex basis. + child->layout.computedFlexBasis = + fmaxf(child->style.dimensions[YGDimensionHeight], + YGNodePaddingAndBorderForAxis(child, YGFlexDirectionColumn)); + } else { + // Compute the flex basis and hypothetical main size (i.e. the clamped + // flex basis). + childWidth = YGUndefined; + childHeight = YGUndefined; + childWidthMeasureMode = YGMeasureModeUndefined; + childHeightMeasureMode = YGMeasureModeUndefined; + + if (isRowStyleDimDefined) { + childWidth = child->style.dimensions[YGDimensionWidth] + + YGNodeMarginForAxis(child, YGFlexDirectionRow); + childWidthMeasureMode = YGMeasureModeExactly; + } + if (isColumnStyleDimDefined) { + childHeight = child->style.dimensions[YGDimensionHeight] + + YGNodeMarginForAxis(child, YGFlexDirectionColumn); + childHeightMeasureMode = YGMeasureModeExactly; + } + + // The W3C spec doesn't say anything about the 'overflow' property, + // but all major browsers appear to implement the following logic. + if ((!isMainAxisRow && node->style.overflow == YGOverflowScroll) || + node->style.overflow != YGOverflowScroll) { + if (YGValueIsUndefined(childWidth) && !YGValueIsUndefined(width)) { + childWidth = width; + childWidthMeasureMode = YGMeasureModeAtMost; + } + } + + if ((isMainAxisRow && node->style.overflow == YGOverflowScroll) || + node->style.overflow != YGOverflowScroll) { + if (YGValueIsUndefined(childHeight) && !YGValueIsUndefined(height)) { + childHeight = height; + childHeightMeasureMode = YGMeasureModeAtMost; + } + } + + // 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 + if (!isMainAxisRow && !YGValueIsUndefined(width) && !isRowStyleDimDefined && + widthMode == YGMeasureModeExactly && YGNodeAlignItem(node, child) == YGAlignStretch) { + childWidth = width; + childWidthMeasureMode = YGMeasureModeExactly; + } + if (isMainAxisRow && !YGValueIsUndefined(height) && !isColumnStyleDimDefined && + heightMode == YGMeasureModeExactly && YGNodeAlignItem(node, child) == YGAlignStretch) { + childHeight = height; + childHeightMeasureMode = YGMeasureModeExactly; + } + + if (!YGValueIsUndefined(child->style.aspectRatio)) { + if (!isMainAxisRow && childWidthMeasureMode == YGMeasureModeExactly) { + child->layout.computedFlexBasis = + fmaxf(childWidth * child->style.aspectRatio, + YGNodePaddingAndBorderForAxis(child, YGFlexDirectionColumn)); + return; + } else if (isMainAxisRow && childHeightMeasureMode == YGMeasureModeExactly) { + child->layout.computedFlexBasis = + fmaxf(childHeight * child->style.aspectRatio, + YGNodePaddingAndBorderForAxis(child, YGFlexDirectionRow)); + return; + } + } + + YGConstrainMaxSizeForMode(child->style.maxDimensions[YGDimensionWidth], + &childWidthMeasureMode, + &childWidth); + YGConstrainMaxSizeForMode(child->style.maxDimensions[YGDimensionHeight], + &childHeightMeasureMode, + &childHeight); + + // Measure the child + YGLayoutNodeInternal(child, + childWidth, + childHeight, + direction, + childWidthMeasureMode, + childHeightMeasureMode, + false, + "measure"); + + child->layout.computedFlexBasis = + fmaxf(isMainAxisRow ? child->layout.measuredDimensions[YGDimensionWidth] + : child->layout.measuredDimensions[YGDimensionHeight], + YGNodePaddingAndBorderForAxis(child, mainAxis)); + } + + child->layout.computedFlexBasisGeneration = gCurrentGenerationCount; +} + +static void YGNodeAbsoluteLayoutChild(const YGNodeRef node, + const YGNodeRef child, + const float width, + const YGMeasureMode widthMode, + const YGDirection direction) { + const YGFlexDirection mainAxis = YGFlexDirectionResolve(node->style.flexDirection, direction); + const YGFlexDirection crossAxis = YGFlexDirectionCross(mainAxis, direction); + const bool isMainAxisRow = YGFlexDirectionIsRow(mainAxis); + + float childWidth = YGUndefined; + float childHeight = YGUndefined; + YGMeasureMode childWidthMeasureMode = YGMeasureModeUndefined; + YGMeasureMode childHeightMeasureMode = YGMeasureModeUndefined; + + if (YGNodeIsStyleDimDefined(child, YGFlexDirectionRow)) { + childWidth = + child->style.dimensions[YGDimensionWidth] + YGNodeMarginForAxis(child, YGFlexDirectionRow); + } else { + // If the child doesn't have a specified width, compute the width based + // on the left/right + // offsets if they're defined. + if (YGNodeIsLeadingPosDefined(child, YGFlexDirectionRow) && + YGNodeIsTrailingPosDefined(child, YGFlexDirectionRow)) { + childWidth = node->layout.measuredDimensions[YGDimensionWidth] - + (YGNodeLeadingBorder(node, YGFlexDirectionRow) + + YGNodeTrailingBorder(node, YGFlexDirectionRow)) - + (YGNodeLeadingPosition(child, YGFlexDirectionRow) + + YGNodeTrailingPosition(child, YGFlexDirectionRow)); + childWidth = YGNodeBoundAxis(child, YGFlexDirectionRow, childWidth); + } + } + + if (YGNodeIsStyleDimDefined(child, YGFlexDirectionColumn)) { + childHeight = child->style.dimensions[YGDimensionHeight] + + YGNodeMarginForAxis(child, YGFlexDirectionColumn); + } else { + // If the child doesn't have a specified height, compute the height + // based on the top/bottom + // offsets if they're defined. + if (YGNodeIsLeadingPosDefined(child, YGFlexDirectionColumn) && + YGNodeIsTrailingPosDefined(child, YGFlexDirectionColumn)) { + childHeight = node->layout.measuredDimensions[YGDimensionHeight] - + (YGNodeLeadingBorder(node, YGFlexDirectionColumn) + + YGNodeTrailingBorder(node, YGFlexDirectionColumn)) - + (YGNodeLeadingPosition(child, YGFlexDirectionColumn) + + YGNodeTrailingPosition(child, YGFlexDirectionColumn)); + childHeight = YGNodeBoundAxis(child, YGFlexDirectionColumn, childHeight); + } + } + + // 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. + if (YGValueIsUndefined(childWidth) ^ YGValueIsUndefined(childHeight)) { + if (!YGValueIsUndefined(child->style.aspectRatio)) { + if (YGValueIsUndefined(childWidth)) { + childWidth = fmaxf(childHeight * child->style.aspectRatio, + YGNodePaddingAndBorderForAxis(child, YGFlexDirectionColumn)); + } else if (YGValueIsUndefined(childHeight)) { + childHeight = fmaxf(childWidth * child->style.aspectRatio, + YGNodePaddingAndBorderForAxis(child, YGFlexDirectionRow)); + } + } + } + + // If we're still missing one or the other dimension, measure the content. + if (YGValueIsUndefined(childWidth) || YGValueIsUndefined(childHeight)) { + childWidthMeasureMode = + YGValueIsUndefined(childWidth) ? YGMeasureModeUndefined : YGMeasureModeExactly; + childHeightMeasureMode = + YGValueIsUndefined(childHeight) ? YGMeasureModeUndefined : YGMeasureModeExactly; + + // According to the spec, if the main size is not definite and the + // child's inline axis is parallel to the main axis (i.e. it's + // horizontal), the child should be sized using "UNDEFINED" in + // the main size. Otherwise use "AT_MOST" in the cross axis. + if (!isMainAxisRow && YGValueIsUndefined(childWidth) && widthMode != YGMeasureModeUndefined) { + childWidth = width; + childWidthMeasureMode = YGMeasureModeAtMost; + } + + YGLayoutNodeInternal(child, + childWidth, + childHeight, + direction, + childWidthMeasureMode, + childHeightMeasureMode, + false, + "abs-measure"); + childWidth = child->layout.measuredDimensions[YGDimensionWidth] + + YGNodeMarginForAxis(child, YGFlexDirectionRow); + childHeight = child->layout.measuredDimensions[YGDimensionHeight] + + YGNodeMarginForAxis(child, YGFlexDirectionColumn); + } + + YGLayoutNodeInternal(child, + childWidth, + childHeight, + direction, + YGMeasureModeExactly, + YGMeasureModeExactly, + true, + "abs-layout"); + + if (YGNodeIsTrailingPosDefined(child, mainAxis) && !YGNodeIsLeadingPosDefined(child, mainAxis)) { + child->layout.position[leading[mainAxis]] = node->layout.measuredDimensions[dim[mainAxis]] - + child->layout.measuredDimensions[dim[mainAxis]] - + YGNodeTrailingBorder(node, mainAxis) - + YGNodeTrailingPosition(child, mainAxis); + } + + if (YGNodeIsTrailingPosDefined(child, crossAxis) && + !YGNodeIsLeadingPosDefined(child, crossAxis)) { + child->layout.position[leading[crossAxis]] = node->layout.measuredDimensions[dim[crossAxis]] - + child->layout.measuredDimensions[dim[crossAxis]] - + YGNodeTrailingBorder(node, crossAxis) - + YGNodeTrailingPosition(child, crossAxis); + } +} + +static void YGNodeWithMeasureFuncSetMeasuredDimensions(const YGNodeRef node, + const float availableWidth, + const float availableHeight, + const YGMeasureMode widthMeasureMode, + const YGMeasureMode heightMeasureMode) { + YG_ASSERT(node->measure, "Expected node to have custom measure function"); + + const float paddingAndBorderAxisRow = YGNodePaddingAndBorderForAxis(node, YGFlexDirectionRow); + const float paddingAndBorderAxisColumn = + YGNodePaddingAndBorderForAxis(node, YGFlexDirectionColumn); + const float marginAxisRow = YGNodeMarginForAxis(node, YGFlexDirectionRow); + const float marginAxisColumn = YGNodeMarginForAxis(node, YGFlexDirectionColumn); + + const float innerWidth = availableWidth - marginAxisRow - paddingAndBorderAxisRow; + const float innerHeight = availableHeight - marginAxisColumn - paddingAndBorderAxisColumn; + + if (widthMeasureMode == YGMeasureModeExactly && heightMeasureMode == YGMeasureModeExactly) { + // Don't bother sizing the text if both dimensions are already defined. + node->layout.measuredDimensions[YGDimensionWidth] = + YGNodeBoundAxis(node, YGFlexDirectionRow, availableWidth - marginAxisRow); + node->layout.measuredDimensions[YGDimensionHeight] = + YGNodeBoundAxis(node, YGFlexDirectionColumn, availableHeight - marginAxisColumn); + } else if (innerWidth <= 0 || innerHeight <= 0) { + // Don't bother sizing the text if there's no horizontal or vertical + // space. + node->layout.measuredDimensions[YGDimensionWidth] = + YGNodeBoundAxis(node, YGFlexDirectionRow, 0); + node->layout.measuredDimensions[YGDimensionHeight] = + YGNodeBoundAxis(node, YGFlexDirectionColumn, 0); + } else { + // Measure the text under the current constraints. + const YGSize measuredSize = + node->measure(node, innerWidth, widthMeasureMode, innerHeight, heightMeasureMode); + + node->layout.measuredDimensions[YGDimensionWidth] = + YGNodeBoundAxis(node, + YGFlexDirectionRow, + (widthMeasureMode == YGMeasureModeUndefined || + widthMeasureMode == YGMeasureModeAtMost) + ? measuredSize.width + paddingAndBorderAxisRow + : availableWidth - marginAxisRow); + node->layout.measuredDimensions[YGDimensionHeight] = + YGNodeBoundAxis(node, + YGFlexDirectionColumn, + (heightMeasureMode == YGMeasureModeUndefined || + heightMeasureMode == YGMeasureModeAtMost) + ? measuredSize.height + paddingAndBorderAxisColumn + : availableHeight - marginAxisColumn); + } +} + +// 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. +static void YGNodeEmptyContainerSetMeasuredDimensions(const YGNodeRef node, + const float availableWidth, + const float availableHeight, + const YGMeasureMode widthMeasureMode, + const YGMeasureMode heightMeasureMode) { + const float paddingAndBorderAxisRow = YGNodePaddingAndBorderForAxis(node, YGFlexDirectionRow); + const float paddingAndBorderAxisColumn = + YGNodePaddingAndBorderForAxis(node, YGFlexDirectionColumn); + const float marginAxisRow = YGNodeMarginForAxis(node, YGFlexDirectionRow); + const float marginAxisColumn = YGNodeMarginForAxis(node, YGFlexDirectionColumn); + + node->layout.measuredDimensions[YGDimensionWidth] = + YGNodeBoundAxis(node, + YGFlexDirectionRow, + (widthMeasureMode == YGMeasureModeUndefined || + widthMeasureMode == YGMeasureModeAtMost) + ? paddingAndBorderAxisRow + : availableWidth - marginAxisRow); + node->layout.measuredDimensions[YGDimensionHeight] = + YGNodeBoundAxis(node, + YGFlexDirectionColumn, + (heightMeasureMode == YGMeasureModeUndefined || + heightMeasureMode == YGMeasureModeAtMost) + ? paddingAndBorderAxisColumn + : availableHeight - marginAxisColumn); +} + +static bool YGNodeFixedSizeSetMeasuredDimensions(const YGNodeRef node, + const float availableWidth, + const float availableHeight, + const YGMeasureMode widthMeasureMode, + const YGMeasureMode heightMeasureMode) { + if ((widthMeasureMode == YGMeasureModeAtMost && availableWidth <= 0) || + (heightMeasureMode == YGMeasureModeAtMost && availableHeight <= 0) || + (widthMeasureMode == YGMeasureModeExactly && heightMeasureMode == YGMeasureModeExactly)) { + const float marginAxisColumn = YGNodeMarginForAxis(node, YGFlexDirectionColumn); + const float marginAxisRow = YGNodeMarginForAxis(node, YGFlexDirectionRow); + + node->layout.measuredDimensions[YGDimensionWidth] = + YGNodeBoundAxis(node, + YGFlexDirectionRow, + YGValueIsUndefined(availableWidth) || (widthMeasureMode == YGMeasureModeAtMost && availableWidth < 0) + ? 0 + : availableWidth - marginAxisRow); + + node->layout.measuredDimensions[YGDimensionHeight] = + YGNodeBoundAxis(node, + YGFlexDirectionColumn, + YGValueIsUndefined(availableHeight) || (heightMeasureMode == YGMeasureModeAtMost && availableHeight < 0) + ? 0 + : availableHeight - marginAxisColumn); + + return true; + } + + return false; +} + +// +// This is the main routine that implements a subset of the flexbox layout +// algorithm +// described in the W3C YG documentation: https://www.w3.org/TR/YG3-flexbox/. +// +// 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. +// * The 'wrap' property supports only 'nowrap' (which is the default) or +// 'wrap'. The +// rarely-used 'wrap-reverse' is not supported. +// * Rather than allowing arbitrary combinations of flexGrow, flexShrink and +// flexBasis, this algorithm supports only the three most common +// combinations: +// flex: 0 is equiavlent to flex: 0 0 auto +// flex: n (where n is a positive value) is equivalent to flex: n 1 auto +// If POSITIVE_FLEX_IS_AUTO is 0, then it is equivalent to flex: n 0 0 +// This is faster because the content doesn't need to be measured, but +// it's +// less flexible because the basis is always 0 and can't be overriden +// with +// the width/height attributes. +// flex: -1 (or any negative value) is equivalent to flex: 0 1 auto +// * Margins cannot be specified as 'auto'. They must be specified in terms of +// pixel +// values, and the default value is 0. +// * The 'baseline' value is not supported for alignItems and alignSelf +// properties. +// * Values of width, maxWidth, minWidth, height, maxHeight and minHeight must +// be +// specified as pixel values, not as percentages. +// * There is no support for calculation of dimensions based on intrinsic +// aspect ratios +// (e.g. images). +// * 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 +// or YGUndefined if the size is not available; interpretation depends on +// 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 +// from the spec (https://www.w3.org/TR/YG3-sizing/#terms): +// - YGMeasureModeUndefined: max content +// - YGMeasureModeExactly: fill available +// - YGMeasureModeAtMost: fit content +// +// When calling YGNodelayoutImpl and YGLayoutNodeInternal, if the caller passes +// an available size of +// undefined then it must also pass a measure mode of YGMeasureModeUndefined +// in that dimension. +// +static void YGNodelayoutImpl(const YGNodeRef node, + const float availableWidth, + const float availableHeight, + const YGDirection parentDirection, + const YGMeasureMode widthMeasureMode, + const YGMeasureMode heightMeasureMode, + const bool performLayout) { + YG_ASSERT(YGValueIsUndefined(availableWidth) ? widthMeasureMode == YGMeasureModeUndefined : true, + "availableWidth is indefinite so widthMeasureMode must be " + "YGMeasureModeUndefined"); + YG_ASSERT(YGValueIsUndefined(availableHeight) ? heightMeasureMode == YGMeasureModeUndefined + : true, + "availableHeight is indefinite so heightMeasureMode must be " + "YGMeasureModeUndefined"); + + // Set the resolved resolution in the node's layout. + const YGDirection direction = YGNodeResolveDirection(node, parentDirection); + node->layout.direction = direction; + + if (node->measure) { + YGNodeWithMeasureFuncSetMeasuredDimensions( + node, availableWidth, availableHeight, widthMeasureMode, heightMeasureMode); + return; + } + + const uint32_t childCount = YGNodeListCount(node->children); + if (childCount == 0) { + YGNodeEmptyContainerSetMeasuredDimensions( + node, availableWidth, availableHeight, widthMeasureMode, heightMeasureMode); + return; + } + + // If we're not being asked to perform a full layout we can skip the algorithm if we already know + // the size + if (!performLayout && + YGNodeFixedSizeSetMeasuredDimensions( + node, availableWidth, availableHeight, widthMeasureMode, heightMeasureMode)) { + return; + } + + // STEP 1: CALCULATE VALUES FOR REMAINDER OF ALGORITHM + const YGFlexDirection mainAxis = YGFlexDirectionResolve(node->style.flexDirection, direction); + const YGFlexDirection crossAxis = YGFlexDirectionCross(mainAxis, direction); + const bool isMainAxisRow = YGFlexDirectionIsRow(mainAxis); + const YGJustify justifyContent = node->style.justifyContent; + const bool isNodeFlexWrap = node->style.flexWrap == YGWrapWrap; + + YGNodeRef firstAbsoluteChild = NULL; + YGNodeRef currentAbsoluteChild = NULL; + + const float leadingPaddingAndBorderMain = YGNodeLeadingPaddingAndBorder(node, mainAxis); + const float trailingPaddingAndBorderMain = YGNodeTrailingPaddingAndBorder(node, mainAxis); + const float leadingPaddingAndBorderCross = YGNodeLeadingPaddingAndBorder(node, crossAxis); + const float paddingAndBorderAxisMain = YGNodePaddingAndBorderForAxis(node, mainAxis); + const float paddingAndBorderAxisCross = YGNodePaddingAndBorderForAxis(node, crossAxis); + + const YGMeasureMode measureModeMainDim = isMainAxisRow ? widthMeasureMode : heightMeasureMode; + const YGMeasureMode measureModeCrossDim = isMainAxisRow ? heightMeasureMode : widthMeasureMode; + + const float paddingAndBorderAxisRow = YGNodePaddingAndBorderForAxis(node, YGFlexDirectionRow); + const float paddingAndBorderAxisColumn = + YGNodePaddingAndBorderForAxis(node, YGFlexDirectionColumn); + const float marginAxisRow = YGNodeMarginForAxis(node, YGFlexDirectionRow); + const float marginAxisColumn = YGNodeMarginForAxis(node, YGFlexDirectionColumn); + + // STEP 2: DETERMINE AVAILABLE SIZE IN MAIN AND CROSS DIRECTIONS + const float availableInnerWidth = availableWidth - marginAxisRow - paddingAndBorderAxisRow; + const float availableInnerHeight = + availableHeight - marginAxisColumn - paddingAndBorderAxisColumn; + const float availableInnerMainDim = isMainAxisRow ? availableInnerWidth : availableInnerHeight; + 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 + YGNodeRef singleFlexChild = NULL; + if ((isMainAxisRow && widthMeasureMode == YGMeasureModeExactly) || + (!isMainAxisRow && heightMeasureMode == YGMeasureModeExactly)) { + for (uint32_t i = 0; i < childCount; i++) { + const YGNodeRef child = YGNodeGetChild(node, i); + if (singleFlexChild) { + if (YGNodeIsFlex(child)) { + // There is already a flexible child, abort. + singleFlexChild = NULL; + break; + } + } else if (YGNodeStyleGetFlexGrow(child) > 0 && YGNodeStyleGetFlexShrink(child) > 0) { + singleFlexChild = child; + } + } + } + + // STEP 3: DETERMINE FLEX BASIS FOR EACH ITEM + for (uint32_t i = 0; i < childCount; i++) { + const YGNodeRef child = YGNodeListGet(node->children, i); + if (NULL != child && false == YGNodeIsVisible(child)) { + continue; + } + + if (performLayout) { + // Set the initial position (relative to the parent). + const YGDirection childDirection = YGNodeResolveDirection(child, direction); + YGNodeSetPosition(child, childDirection); + } + + // Absolute-positioned children don't participate in flex layout. Add them + // to a list that we can process later. + if (child->style.positionType == YGPositionTypeAbsolute) { + // Store a private linked list of absolutely positioned children + // so that we can efficiently traverse them later. + if (firstAbsoluteChild == NULL) { + firstAbsoluteChild = child; + } + if (currentAbsoluteChild != NULL) { + currentAbsoluteChild->nextChild = child; + } + currentAbsoluteChild = child; + child->nextChild = NULL; + } else { + if (child == singleFlexChild) { + child->layout.computedFlexBasisGeneration = gCurrentGenerationCount; + child->layout.computedFlexBasis = 0; + } else { + YGNodeComputeFlexBasisForChild(node, + child, + availableInnerWidth, + widthMeasureMode, + availableInnerHeight, + heightMeasureMode, + direction); + } + } + } + + // 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; + + float totalFlexGrowFactors = 0; + float totalFlexShrinkScaledFactors = 0; + + // Maintain a linked list of the child nodes that can shrink and/or grow. + YGNodeRef firstRelativeChild = NULL; + YGNodeRef currentRelativeChild = NULL; + + // 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++) { + const YGNodeRef child = YGNodeListGet(node->children, i); + if (NULL != child && false == YGNodeIsVisible(child)) { + continue; + } + + child->lineIndex = lineCount; + + if (child->style.positionType != YGPositionTypeAbsolute) { + const float outerFlexBasis = + child->layout.computedFlexBasis + YGNodeMarginForAxis(child, mainAxis); + + // 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. + if (sizeConsumedOnCurrentLine + outerFlexBasis > availableInnerMainDim && isNodeFlexWrap && + itemsOnLine > 0) { + break; + } + + sizeConsumedOnCurrentLine += outerFlexBasis; + itemsOnLine++; + + if (YGNodeIsFlex(child)) { + totalFlexGrowFactors += YGNodeStyleGetFlexGrow(child); + + // Unlike the grow factor, the shrink factor is scaled relative to the + // child + // dimension. + totalFlexShrinkScaledFactors += + -YGNodeStyleGetFlexShrink(child) * child->layout.computedFlexBasis; + } + + // Store a private linked list of children that need to be layed out. + if (firstRelativeChild == NULL) { + firstRelativeChild = child; + } + if (currentRelativeChild != NULL) { + currentRelativeChild->nextChild = child; + } + currentRelativeChild = child; + child->nextChild = NULL; + } + } + + // If we don't need to measure the cross axis, we can skip the entire flex + // step. + const bool canSkipFlex = !performLayout && measureModeCrossDim == YGMeasureModeExactly; + + // 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. + float remainingFreeSpace = 0; + if (!YGValueIsUndefined(availableInnerMainDim)) { + remainingFreeSpace = availableInnerMainDim - sizeConsumedOnCurrentLine; + } else if (sizeConsumedOnCurrentLine < 0) { + // availableInnerMainDim is indefinite which means the node is being sized + // based on its + // content. + // sizeConsumedOnCurrentLine is negative which means the node will + // allocate 0 pixels for + // its content. Consequently, remainingFreeSpace is 0 - + // sizeConsumedOnCurrentLine. + 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 + // spec (https://www.w3.org/TR/YG-flexbox-1/#resolve-flexible-lengths) + // 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; + while (currentRelativeChild != NULL) { + childFlexBasis = currentRelativeChild->layout.computedFlexBasis; + + if (remainingFreeSpace < 0) { + flexShrinkScaledFactor = -YGNodeStyleGetFlexShrink(currentRelativeChild) * childFlexBasis; + + // Is this child able to shrink? + if (flexShrinkScaledFactor != 0) { + baseMainSize = + childFlexBasis + + remainingFreeSpace / totalFlexShrinkScaledFactors * flexShrinkScaledFactor; + boundMainSize = YGNodeBoundAxis(currentRelativeChild, mainAxis, baseMainSize); + 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) { + flexGrowFactor = YGNodeStyleGetFlexGrow(currentRelativeChild); + + // Is this child able to grow? + if (flexGrowFactor != 0) { + baseMainSize = + childFlexBasis + remainingFreeSpace / totalFlexGrowFactors * flexGrowFactor; + boundMainSize = YGNodeBoundAxis(currentRelativeChild, mainAxis, baseMainSize); + 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; + } + } + } + + currentRelativeChild = currentRelativeChild->nextChild; + } + + totalFlexShrinkScaledFactors += deltaFlexShrinkScaledFactors; + totalFlexGrowFactors += deltaFlexGrowFactors; + remainingFreeSpace += deltaFreeSpace; + + // Second pass: resolve the sizes of the flexible items + deltaFreeSpace = 0; + currentRelativeChild = firstRelativeChild; + while (currentRelativeChild != NULL) { + childFlexBasis = currentRelativeChild->layout.computedFlexBasis; + float updatedMainSize = childFlexBasis; + + if (remainingFreeSpace < 0) { + flexShrinkScaledFactor = -YGNodeStyleGetFlexShrink(currentRelativeChild) * childFlexBasis; + // Is this child able to shrink? + if (flexShrinkScaledFactor != 0) { + float childSize; + + if (totalFlexShrinkScaledFactors == 0) { + childSize = childFlexBasis + flexShrinkScaledFactor; + } else { + childSize = + childFlexBasis + + (remainingFreeSpace / totalFlexShrinkScaledFactors) * flexShrinkScaledFactor; + } + + updatedMainSize = YGNodeBoundAxis(currentRelativeChild, mainAxis, childSize); + } + } else if (remainingFreeSpace > 0) { + flexGrowFactor = YGNodeStyleGetFlexGrow(currentRelativeChild); + + // Is this child able to grow? + if (flexGrowFactor != 0) { + updatedMainSize = + YGNodeBoundAxis(currentRelativeChild, + mainAxis, + childFlexBasis + + remainingFreeSpace / totalFlexGrowFactors * flexGrowFactor); + } + } + + deltaFreeSpace -= updatedMainSize - childFlexBasis; + + float childWidth; + float childHeight; + YGMeasureMode childWidthMeasureMode; + YGMeasureMode childHeightMeasureMode; + + if (isMainAxisRow) { + childWidth = + updatedMainSize + YGNodeMarginForAxis(currentRelativeChild, YGFlexDirectionRow); + childWidthMeasureMode = YGMeasureModeExactly; + + if (!YGValueIsUndefined(availableInnerCrossDim) && + !YGNodeIsStyleDimDefined(currentRelativeChild, YGFlexDirectionColumn) && + heightMeasureMode == YGMeasureModeExactly && + YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch) { + childHeight = availableInnerCrossDim; + childHeightMeasureMode = YGMeasureModeExactly; + } else if (!YGNodeIsStyleDimDefined(currentRelativeChild, YGFlexDirectionColumn)) { + childHeight = availableInnerCrossDim; + childHeightMeasureMode = + YGValueIsUndefined(childHeight) ? YGMeasureModeUndefined : YGMeasureModeAtMost; + } else { + childHeight = currentRelativeChild->style.dimensions[YGDimensionHeight] + + YGNodeMarginForAxis(currentRelativeChild, YGFlexDirectionColumn); + childHeightMeasureMode = YGMeasureModeExactly; + } + } else { + childHeight = + updatedMainSize + YGNodeMarginForAxis(currentRelativeChild, YGFlexDirectionColumn); + childHeightMeasureMode = YGMeasureModeExactly; + + if (!YGValueIsUndefined(availableInnerCrossDim) && + !YGNodeIsStyleDimDefined(currentRelativeChild, YGFlexDirectionRow) && + widthMeasureMode == YGMeasureModeExactly && + YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch) { + childWidth = availableInnerCrossDim; + childWidthMeasureMode = YGMeasureModeExactly; + } else if (!YGNodeIsStyleDimDefined(currentRelativeChild, YGFlexDirectionRow)) { + childWidth = availableInnerCrossDim; + childWidthMeasureMode = + YGValueIsUndefined(childWidth) ? YGMeasureModeUndefined : YGMeasureModeAtMost; + } else { + childWidth = currentRelativeChild->style.dimensions[YGDimensionWidth] + + YGNodeMarginForAxis(currentRelativeChild, YGFlexDirectionRow); + childWidthMeasureMode = YGMeasureModeExactly; + } + } + + if (!YGValueIsUndefined(currentRelativeChild->style.aspectRatio)) { + if (isMainAxisRow && childHeightMeasureMode != YGMeasureModeExactly) { + childHeight = + fmaxf(childWidth * currentRelativeChild->style.aspectRatio, + YGNodePaddingAndBorderForAxis(currentRelativeChild, YGFlexDirectionColumn)); + childHeightMeasureMode = YGMeasureModeExactly; + } else if (!isMainAxisRow && childWidthMeasureMode != YGMeasureModeExactly) { + childWidth = + fmaxf(childHeight * currentRelativeChild->style.aspectRatio, + YGNodePaddingAndBorderForAxis(currentRelativeChild, YGFlexDirectionRow)); + childWidthMeasureMode = YGMeasureModeExactly; + } + } + + YGConstrainMaxSizeForMode(currentRelativeChild->style.maxDimensions[YGDimensionWidth], + &childWidthMeasureMode, + &childWidth); + YGConstrainMaxSizeForMode(currentRelativeChild->style.maxDimensions[YGDimensionHeight], + &childHeightMeasureMode, + &childHeight); + + const bool requiresStretchLayout = + !YGNodeIsStyleDimDefined(currentRelativeChild, crossAxis) && + YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch; + + // Recursively call the layout algorithm for this child with the updated + // main size. + YGLayoutNodeInternal(currentRelativeChild, + childWidth, + childHeight, + direction, + childWidthMeasureMode, + childHeightMeasureMode, + performLayout && !requiresStretchLayout, + "flex"); + + currentRelativeChild = currentRelativeChild->nextChild; + } + } + + remainingFreeSpace = originalRemainingFreeSpace + deltaFreeSpace; + + // 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. + + if (measureModeMainDim == YGMeasureModeAtMost && remainingFreeSpace > 0) { + if (!YGValueIsUndefined(node->style.minDimensions[dim[mainAxis]]) && + node->style.minDimensions[dim[mainAxis]] >= 0) { + remainingFreeSpace = fmaxf(0, + node->style.minDimensions[dim[mainAxis]] - + (availableInnerMainDim - remainingFreeSpace)); + } else { + remainingFreeSpace = 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; + case YGJustifySpaceAround: + // Space on the edges is half of the space between elements + betweenMainDim = remainingFreeSpace / itemsOnLine; + leadingMainDim = betweenMainDim / 2; + break; + case YGJustifyFlexStart: + case YGJustifyCount: + break; + } + + float mainDim = leadingPaddingAndBorderMain + leadingMainDim; + float crossDim = 0; + + for (uint32_t i = startOfLineIndex; i < endOfLineIndex; i++) { + const YGNodeRef child = YGNodeListGet(node->children, i); + if (NULL != child && false == YGNodeIsVisible(child)) { + continue; + } + + if (child->style.positionType == YGPositionTypeAbsolute && + YGNodeIsLeadingPosDefined(child, mainAxis)) { + 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). + child->layout.position[pos[mainAxis]] = YGNodeLeadingPosition(child, mainAxis) + + YGNodeLeadingBorder(node, mainAxis) + + YGNodeLeadingMargin(child, mainAxis); + } + } 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. + if (child->style.positionType == YGPositionTypeRelative) { + if (performLayout) { + child->layout.position[pos[mainAxis]] += mainDim; + } + + if (canSkipFlex) { + // If we skipped the flex step, then we can't rely on the + // measuredDims because + // they weren't computed. This means we can't call YGNodeDimWithMargin. + mainDim += betweenMainDim + YGNodeMarginForAxis(child, mainAxis) + + child->layout.computedFlexBasis; + crossDim = availableInnerCrossDim; + } else { + // The main dimension is the sum of all the elements dimension plus + // the spacing. + mainDim += betweenMainDim + YGNodeDimWithMargin(child, mainAxis); + + // The cross dimension is the max of the elements dimension since + // there + // can only be one element in that cross dimension. + crossDim = fmaxf(crossDim, YGNodeDimWithMargin(child, crossAxis)); + } + } else if (performLayout) { + child->layout.position[pos[mainAxis]] += + YGNodeLeadingBorder(node, mainAxis) + leadingMainDim; + } + } + } + + mainDim += trailingPaddingAndBorderMain; + + float containerCrossAxis = availableInnerCrossDim; + if (measureModeCrossDim == YGMeasureModeUndefined || + measureModeCrossDim == YGMeasureModeAtMost) { + // Compute the cross axis from the max cross dimension of the children. + containerCrossAxis = YGNodeBoundAxis(node, crossAxis, crossDim + paddingAndBorderAxisCross) - + paddingAndBorderAxisCross; + + if (measureModeCrossDim == YGMeasureModeAtMost) { + containerCrossAxis = fminf(containerCrossAxis, availableInnerCrossDim); + } + } + + // If there's no flex wrap, the cross dimension is defined by the container. + if (!isNodeFlexWrap && measureModeCrossDim == YGMeasureModeExactly) { + crossDim = availableInnerCrossDim; + } + + // Clamp to the min/max size specified on the container. + crossDim = YGNodeBoundAxis(node, crossAxis, crossDim + paddingAndBorderAxisCross) - + 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++) { + const YGNodeRef child = YGNodeListGet(node->children, i); + if (NULL != child && false == YGNodeIsVisible(child)) { + continue; + } + + if (child->style.positionType == YGPositionTypeAbsolute) { + // If the child is absolutely positioned and has a + // top/left/bottom/right + // set, override all the previously computed positions to set it + // correctly. + if (YGNodeIsLeadingPosDefined(child, crossAxis)) { + child->layout.position[pos[crossAxis]] = YGNodeLeadingPosition(child, crossAxis) + + YGNodeLeadingBorder(node, crossAxis) + + YGNodeLeadingMargin(child, crossAxis); + } else { + child->layout.position[pos[crossAxis]] = + YGNodeLeadingBorder(node, crossAxis) + YGNodeLeadingMargin(child, crossAxis); + } + } 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 + const YGAlign alignItem = YGNodeAlignItem(node, child); + + // 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. + if (alignItem == YGAlignStretch) { + const bool isCrossSizeDefinite = + (isMainAxisRow && YGNodeIsStyleDimDefined(child, YGFlexDirectionColumn)) || + (!isMainAxisRow && YGNodeIsStyleDimDefined(child, YGFlexDirectionRow)); + + float childWidth; + float childHeight; + YGMeasureMode childWidthMeasureMode = YGMeasureModeExactly; + YGMeasureMode childHeightMeasureMode = YGMeasureModeExactly; + + if (isMainAxisRow) { + childHeight = crossDim; + childWidth = child->layout.measuredDimensions[YGDimensionWidth] + + YGNodeMarginForAxis(child, YGFlexDirectionRow); + } else { + childWidth = crossDim; + childHeight = child->layout.measuredDimensions[YGDimensionHeight] + + YGNodeMarginForAxis(child, YGFlexDirectionColumn); + } + + YGConstrainMaxSizeForMode(child->style.maxDimensions[YGDimensionWidth], + &childWidthMeasureMode, + &childWidth); + YGConstrainMaxSizeForMode(child->style.maxDimensions[YGDimensionHeight], + &childHeightMeasureMode, + &childHeight); + + // If the child defines a definite size for its cross axis, there's + // no need to stretch. + if (!isCrossSizeDefinite) { + childWidthMeasureMode = + YGValueIsUndefined(childWidth) ? YGMeasureModeUndefined : YGMeasureModeExactly; + childHeightMeasureMode = + YGValueIsUndefined(childHeight) ? YGMeasureModeUndefined : YGMeasureModeExactly; + + YGLayoutNodeInternal(child, + childWidth, + childHeight, + direction, + childWidthMeasureMode, + childHeightMeasureMode, + true, + "stretch"); + } + } else if (alignItem != YGAlignFlexStart) { + const float remainingCrossDim = + containerCrossAxis - YGNodeDimWithMargin(child, crossAxis); + + if (alignItem == YGAlignCenter) { + leadingCrossDim += remainingCrossDim / 2; + } else { // YGAlignFlexEnd + leadingCrossDim += remainingCrossDim; + } + } + + // And we apply the position + child->layout.position[pos[crossAxis]] += totalLineCrossDim + leadingCrossDim; + } + } + } + + totalLineCrossDim += crossDim; + maxLineMainDim = fmaxf(maxLineMainDim, mainDim); + } + + // STEP 8: MULTI-LINE CONTENT ALIGNMENT + if (lineCount > 1 && performLayout && !YGValueIsUndefined(availableInnerCrossDim)) { + const float remainingAlignContentDim = availableInnerCrossDim - totalLineCrossDim; + + float crossDimLead = 0; + float currentLead = leadingPaddingAndBorderCross; + + switch (node->style.alignContent) { + case YGAlignFlexEnd: + currentLead += remainingAlignContentDim; + break; + case YGAlignCenter: + currentLead += remainingAlignContentDim / 2; + break; + case YGAlignStretch: + if (availableInnerCrossDim > totalLineCrossDim) { + crossDimLead = (remainingAlignContentDim / lineCount); + } + break; + case YGAlignAuto: + case YGAlignFlexStart: + case YGAlignCount: + break; + } + + uint32_t endIndex = 0; + for (uint32_t i = 0; i < lineCount; i++) { + uint32_t startIndex = endIndex; + uint32_t ii; + + // compute the line's height and find the endIndex + float lineHeight = 0; + for (ii = startIndex; ii < childCount; ii++) { + const YGNodeRef child = YGNodeListGet(node->children, ii); + if (NULL != child && false == YGNodeIsVisible(child)) { + continue; + } + + if (child->style.positionType == YGPositionTypeRelative) { + if (child->lineIndex != i) { + break; + } + + if (YGNodeIsLayoutDimDefined(child, crossAxis)) { + lineHeight = fmaxf(lineHeight, + child->layout.measuredDimensions[dim[crossAxis]] + + YGNodeMarginForAxis(child, crossAxis)); + } + } + } + endIndex = ii; + lineHeight += crossDimLead; + + if (performLayout) { + for (ii = startIndex; ii < endIndex; ii++) { + const YGNodeRef child = YGNodeListGet(node->children, ii); + if (NULL != child && false == YGNodeIsVisible(child)) { + continue; + } + + if (child->style.positionType == YGPositionTypeRelative) { + switch (YGNodeAlignItem(node, child)) { + case YGAlignFlexStart: { + child->layout.position[pos[crossAxis]] = + currentLead + YGNodeLeadingMargin(child, crossAxis); + break; + } + case YGAlignFlexEnd: { + child->layout.position[pos[crossAxis]] = + currentLead + lineHeight - YGNodeTrailingMargin(child, crossAxis) - + child->layout.measuredDimensions[dim[crossAxis]]; + break; + } + case YGAlignCenter: { + float childHeight = child->layout.measuredDimensions[dim[crossAxis]]; + child->layout.position[pos[crossAxis]] = + currentLead + (lineHeight - childHeight) / 2; + break; + } + case YGAlignStretch: { + child->layout.position[pos[crossAxis]] = + currentLead + YGNodeLeadingMargin(child, crossAxis); + // TODO(prenaux): Correctly set the height of items with indefinite + // (auto) crossAxis dimension. + break; + } + case YGAlignAuto: + case YGAlignCount: + break; + } + } + } + } + + currentLead += lineHeight; + } + } + + // STEP 9: COMPUTING FINAL DIMENSIONS + node->layout.measuredDimensions[YGDimensionWidth] = + YGNodeBoundAxis(node, YGFlexDirectionRow, availableWidth - marginAxisRow); + node->layout.measuredDimensions[YGDimensionHeight] = + YGNodeBoundAxis(node, YGFlexDirectionColumn, availableHeight - marginAxisColumn); + + // If the user didn't specify a width or height for the node, set the + // dimensions based on the children. + if (measureModeMainDim == YGMeasureModeUndefined) { + // Clamp the size to the min/max size, if specified, and make sure it + // doesn't go below the padding and border amount. + node->layout.measuredDimensions[dim[mainAxis]] = + YGNodeBoundAxis(node, mainAxis, maxLineMainDim); + } else if (measureModeMainDim == YGMeasureModeAtMost) { + node->layout.measuredDimensions[dim[mainAxis]] = + fmaxf(fminf(availableInnerMainDim + paddingAndBorderAxisMain, + YGNodeBoundAxisWithinMinAndMax(node, mainAxis, maxLineMainDim)), + paddingAndBorderAxisMain); + } + + if (measureModeCrossDim == YGMeasureModeUndefined) { + // Clamp the size to the min/max size, if specified, and make sure it + // doesn't go below the padding and border amount. + node->layout.measuredDimensions[dim[crossAxis]] = + YGNodeBoundAxis(node, crossAxis, totalLineCrossDim + paddingAndBorderAxisCross); + } else if (measureModeCrossDim == YGMeasureModeAtMost) { + node->layout.measuredDimensions[dim[crossAxis]] = + fmaxf(fminf(availableInnerCrossDim + paddingAndBorderAxisCross, + YGNodeBoundAxisWithinMinAndMax(node, + crossAxis, + totalLineCrossDim + paddingAndBorderAxisCross)), + paddingAndBorderAxisCross); + } + + if (performLayout) { + // STEP 10: SIZING AND POSITIONING ABSOLUTE CHILDREN + for (currentAbsoluteChild = firstAbsoluteChild; currentAbsoluteChild != NULL; + currentAbsoluteChild = currentAbsoluteChild->nextChild) { + YGNodeAbsoluteLayoutChild( + node, currentAbsoluteChild, availableInnerWidth, widthMeasureMode, direction); + } + + // STEP 11: SETTING TRAILING POSITIONS FOR CHILDREN + const bool needsMainTrailingPos = + mainAxis == YGFlexDirectionRowReverse || mainAxis == YGFlexDirectionColumnReverse; + const bool needsCrossTrailingPos = + crossAxis == YGFlexDirectionRowReverse || crossAxis == YGFlexDirectionColumnReverse; + + // Set trailing position if necessary. + if (needsMainTrailingPos || needsCrossTrailingPos) { + for (uint32_t i = 0; i < childCount; i++) { + const YGNodeRef child = YGNodeListGet(node->children, i); + if (NULL != child && false == YGNodeIsVisible(child)) { + continue; + } + + if (needsMainTrailingPos) { + YGNodeSetChildTrailingPosition(node, child, mainAxis); + } + + if (needsCrossTrailingPos) { + YGNodeSetChildTrailingPosition(node, child, crossAxis); + } + } + } + } +} + +uint32_t gDepth = 0; +bool gPrintTree = false; +bool gPrintChanges = false; +bool gPrintSkips = false; + +static const char *spacer = " "; + +static const char *YGSpacer(const unsigned long level) { + const size_t spacerLen = strlen(spacer); + if (level > spacerLen) { + return &spacer[0]; + } else { + return &spacer[spacerLen - level]; + } +} + +static const char *YGMeasureModeName(const YGMeasureMode mode, const bool performLayout) { + const char *kMeasureModeNames[YGMeasureModeCount] = {"UNDEFINED", "EXACTLY", "AT_MOST"}; + const char *kLayoutModeNames[YGMeasureModeCount] = {"LAY_UNDEFINED", + "LAY_EXACTLY", + "LAY_AT_" + "MOST"}; + + if (mode >= YGMeasureModeCount) { + return ""; + } + + return performLayout ? kLayoutModeNames[mode] : kMeasureModeNames[mode]; +} + +static inline bool YGMeasureModeSizeIsExactAndMatchesOldMeasuredSize(YGMeasureMode sizeMode, + float size, + float lastComputedSize) { + return sizeMode == YGMeasureModeExactly && YGFloatsEqual(size, lastComputedSize); +} + +static inline bool YGMeasureModeOldSizeIsUnspecifiedAndStillFits(YGMeasureMode sizeMode, + float size, + YGMeasureMode lastSizeMode, + float lastComputedSize) { + return sizeMode == YGMeasureModeAtMost && lastSizeMode == YGMeasureModeUndefined && + size >= lastComputedSize; +} + +static inline bool YGMeasureModeNewMeasureSizeIsStricterAndStillValid(YGMeasureMode sizeMode, + float size, + YGMeasureMode lastSizeMode, + float lastSize, + float lastComputedSize) { + return lastSizeMode == YGMeasureModeAtMost && sizeMode == YGMeasureModeAtMost && + lastSize > size && lastComputedSize <= size; +} + +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) { + if (lastComputedHeight < 0 || lastComputedWidth < 0) { + return false; + } + + const bool hasSameWidthSpec = lastWidthMode == widthMode && YGFloatsEqual(lastWidth, width); + const bool hasSameHeightSpec = lastHeightMode == heightMode && YGFloatsEqual(lastHeight, height); + + const bool widthIsCompatible = + hasSameWidthSpec || YGMeasureModeSizeIsExactAndMatchesOldMeasuredSize(widthMode, + width - marginRow, + lastComputedWidth) || + YGMeasureModeOldSizeIsUnspecifiedAndStillFits(widthMode, + width - marginRow, + lastWidthMode, + lastComputedWidth) || + YGMeasureModeNewMeasureSizeIsStricterAndStillValid( + widthMode, width - marginRow, lastWidthMode, lastWidth, lastComputedWidth); + + const bool heightIsCompatible = + hasSameHeightSpec || YGMeasureModeSizeIsExactAndMatchesOldMeasuredSize(heightMode, + height - marginColumn, + lastComputedHeight) || + YGMeasureModeOldSizeIsUnspecifiedAndStillFits(heightMode, + height - marginColumn, + lastHeightMode, + lastComputedHeight) || + YGMeasureModeNewMeasureSizeIsStricterAndStillValid( + heightMode, height - marginColumn, lastHeightMode, lastHeight, lastComputedHeight); + + return widthIsCompatible && heightIsCompatible; +} + +// +// This is a wrapper around the YGNodelayoutImpl function. It determines +// whether the layout request is redundant and can be skipped. +// +// Parameters: +// Input parameters are the same as YGNodelayoutImpl (see above) +// Return parameter is true if layout was performed, false if skipped +// +bool YGLayoutNodeInternal(const YGNodeRef node, + const float availableWidth, + const float availableHeight, + const YGDirection parentDirection, + const YGMeasureMode widthMeasureMode, + const YGMeasureMode heightMeasureMode, + const bool performLayout, + const char *reason) { + YGLayout *layout = &node->layout; + + gDepth++; + + const bool needToVisitNode = + (node->isDirty && layout->generationCount != gCurrentGenerationCount) || + layout->lastParentDirection != parentDirection; + + if (needToVisitNode) { + // Invalidate the cached results. + layout->nextCachedMeasurementsIndex = 0; + layout->cachedLayout.widthMeasureMode = (YGMeasureMode) -1; + layout->cachedLayout.heightMeasureMode = (YGMeasureMode) -1; + layout->cachedLayout.computedWidth = -1; + layout->cachedLayout.computedHeight = -1; + } + + YGCachedMeasurement *cachedResults = NULL; + + // Determine whether the results are already cached. We maintain a separate + // cache for layouts and measurements. A layout operation modifies the + // 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. + if (node->measure) { + const float marginAxisRow = YGNodeMarginForAxis(node, YGFlexDirectionRow); + const float marginAxisColumn = YGNodeMarginForAxis(node, YGFlexDirectionColumn); + + // 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, + marginAxisColumn)) { + 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, + marginAxisColumn)) { + 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 { + for (uint32_t i = 0; i < layout->nextCachedMeasurementsIndex; i++) { + if (YGFloatsEqual(layout->cachedMeasurements[i].availableWidth, availableWidth) && + YGFloatsEqual(layout->cachedMeasurements[i].availableHeight, availableHeight) && + layout->cachedMeasurements[i].widthMeasureMode == widthMeasureMode && + layout->cachedMeasurements[i].heightMeasureMode == heightMeasureMode) { + cachedResults = &layout->cachedMeasurements[i]; + break; + } + } + } + + if (!needToVisitNode && cachedResults != NULL) { + layout->measuredDimensions[YGDimensionWidth] = cachedResults->computedWidth; + layout->measuredDimensions[YGDimensionHeight] = cachedResults->computedHeight; + + if (gPrintChanges && gPrintSkips) { + printf("%s%d.{[skipped] ", YGSpacer(gDepth), gDepth); + if (node->print) { + node->print(node); + } + printf("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); + } + } else { + if (gPrintChanges) { + printf("%s%d.{%s", YGSpacer(gDepth), gDepth, needToVisitNode ? "*" : ""); + if (node->print) { + node->print(node); + } + printf("wm: %s, hm: %s, aw: %f ah: %f %s\n", + YGMeasureModeName(widthMeasureMode, performLayout), + YGMeasureModeName(heightMeasureMode, performLayout), + availableWidth, + availableHeight, + reason); + } + + YGNodelayoutImpl(node, + availableWidth, + availableHeight, + parentDirection, + widthMeasureMode, + heightMeasureMode, + performLayout); + + if (gPrintChanges) { + printf("%s%d.}%s", YGSpacer(gDepth), gDepth, needToVisitNode ? "*" : ""); + if (node->print) { + node->print(node); + } + printf("wm: %s, hm: %s, d: (%f, %f) %s\n", + YGMeasureModeName(widthMeasureMode, performLayout), + YGMeasureModeName(heightMeasureMode, performLayout), + layout->measuredDimensions[YGDimensionWidth], + layout->measuredDimensions[YGDimensionHeight], + reason); + } + + layout->lastParentDirection = parentDirection; + + if (cachedResults == NULL) { + if (layout->nextCachedMeasurementsIndex == YG_MAX_CACHED_RESULT_COUNT) { + if (gPrintChanges) { + printf("Out of cache entries!\n"); + } + layout->nextCachedMeasurementsIndex = 0; + } + + YGCachedMeasurement *newCacheEntry; + 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; + newCacheEntry->computedWidth = layout->measuredDimensions[YGDimensionWidth]; + newCacheEntry->computedHeight = layout->measuredDimensions[YGDimensionHeight]; + } + } + + if (performLayout) { + node->layout.dimensions[YGDimensionWidth] = node->layout.measuredDimensions[YGDimensionWidth]; + node->layout.dimensions[YGDimensionHeight] = node->layout.measuredDimensions[YGDimensionHeight]; + node->hasNewLayout = true; + node->isDirty = false; + } + + gDepth--; + layout->generationCount = gCurrentGenerationCount; + return (needToVisitNode || cachedResults == NULL); +} + +static void roundToPixelGrid(const YGNodeRef node) { + const float fractialLeft = + node->layout.position[YGEdgeLeft] - floorf(node->layout.position[YGEdgeLeft]); + const float fractialTop = + node->layout.position[YGEdgeTop] - floorf(node->layout.position[YGEdgeTop]); + node->layout.dimensions[YGDimensionWidth] = + roundf(fractialLeft + node->layout.dimensions[YGDimensionWidth]) - roundf(fractialLeft); + node->layout.dimensions[YGDimensionHeight] = + roundf(fractialTop + node->layout.dimensions[YGDimensionHeight]) - roundf(fractialTop); + + node->layout.position[YGEdgeLeft] = roundf(node->layout.position[YGEdgeLeft]); + node->layout.position[YGEdgeTop] = roundf(node->layout.position[YGEdgeTop]); + + const uint32_t childCount = YGNodeListCount(node->children); + for (uint32_t i = 0; i < childCount; i++) { + roundToPixelGrid(YGNodeGetChild(node, i)); + } +} + +void YGNodeCalculateLayout(const YGNodeRef node, + const float availableWidth, + const float availableHeight, + const YGDirection parentDirection) { + // 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++; + + float width = availableWidth; + float height = availableHeight; + YGMeasureMode widthMeasureMode = YGMeasureModeUndefined; + YGMeasureMode heightMeasureMode = YGMeasureModeUndefined; + + if (!YGValueIsUndefined(width)) { + widthMeasureMode = YGMeasureModeExactly; + } else if (YGNodeIsStyleDimDefined(node, YGFlexDirectionRow)) { + width = node->style.dimensions[dim[YGFlexDirectionRow]] + + YGNodeMarginForAxis(node, YGFlexDirectionRow); + widthMeasureMode = YGMeasureModeExactly; + } else if (node->style.maxDimensions[YGDimensionWidth] >= 0.0) { + width = node->style.maxDimensions[YGDimensionWidth]; + widthMeasureMode = YGMeasureModeAtMost; + } + + if (!YGValueIsUndefined(height)) { + heightMeasureMode = YGMeasureModeExactly; + } else if (YGNodeIsStyleDimDefined(node, YGFlexDirectionColumn)) { + height = node->style.dimensions[dim[YGFlexDirectionColumn]] + + YGNodeMarginForAxis(node, YGFlexDirectionColumn); + heightMeasureMode = YGMeasureModeExactly; + } else if (node->style.maxDimensions[YGDimensionHeight] >= 0.0) { + height = node->style.maxDimensions[YGDimensionHeight]; + heightMeasureMode = YGMeasureModeAtMost; + } + + if (YGLayoutNodeInternal(node, + width, + height, + parentDirection, + widthMeasureMode, + heightMeasureMode, + true, + "initia" + "l")) { + YGNodeSetPosition(node, node->layout.direction); + + if (YGIsExperimentalFeatureEnabled(YGExperimentalFeatureRounding)) { + roundToPixelGrid(node); + } + + if (gPrintTree) { + YGNodePrint(node, YGPrintOptionsLayout | YGPrintOptionsChildren | YGPrintOptionsStyle); + } + } +} + +void YGSetLogger(YGLogger logger) { + gLogger = logger; +} + +void YGLog(YGLogLevel level, const char *format, ...) { + va_list args; + va_start(args, format); + gLogger(level, format, args); + va_end(args); +} + +static bool experimentalFeatures[YGExperimentalFeatureCount + 1]; + +void YGSetExperimentalFeatureEnabled(YGExperimentalFeature feature, bool enabled) { + experimentalFeatures[feature] = enabled; +} + +inline bool YGIsExperimentalFeatureEnabled(YGExperimentalFeature feature) { + return experimentalFeatures[feature]; +} + +void YGSetMemoryFuncs(YGMalloc ygmalloc, YGCalloc yccalloc, YGRealloc ygrealloc, YGFree ygfree) { + YG_ASSERT(gNodeInstanceCount == 0, "Cannot set memory functions: all node must be freed first"); + YG_ASSERT((ygmalloc == NULL && yccalloc == NULL && ygrealloc == NULL && ygfree == NULL) || + (ygmalloc != NULL && yccalloc != NULL && ygrealloc != NULL && ygfree != NULL), + "Cannot set memory functions: functions must be all NULL or Non-NULL"); + + if (ygmalloc == NULL || yccalloc == NULL || ygrealloc == NULL || ygfree == NULL) { + gYGMalloc = &malloc; + gYGCalloc = &calloc; + gYGRealloc = &realloc; + gYGFree = &free; + } else { + gYGMalloc = ygmalloc; + gYGCalloc = yccalloc; + gYGRealloc = ygrealloc; + gYGFree = ygfree; + } +} diff --git a/yoga/Yoga.h b/yoga/Yoga.h new file mode 100644 index 00000000..afe609bf --- /dev/null +++ b/yoga/Yoga.h @@ -0,0 +1,185 @@ +n/** + * 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 +#include +#include +#include +#include +#include + +#ifndef __cplusplus +#include +#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 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 YGNodeHide(const CSSNodeRef node); +WIN_EXPORT void YGNodeShow(const CSSNodeRef node); +WIN_EXPORT bool YGNodeIsVisible(const CSSNodeRef 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 ygmalloc, YGCalloc yccalloc, YGRealloc ygrealloc, YGFree ygfree); + +YG_EXTERN_C_END