diff --git a/.buckconfig b/.buckconfig deleted file mode 100644 index 74a40a76..00000000 --- a/.buckconfig +++ /dev/null @@ -1,2 +0,0 @@ -[cxx] - gtest_dep = //lib/gtest:gtest diff --git a/.github/workflows/github-actions-ci.yml b/.github/workflows/github-actions-ci.yml index d7c83584..da8709ed 100644 --- a/.github/workflows/github-actions-ci.yml +++ b/.github/workflows/github-actions-ci.yml @@ -3,20 +3,21 @@ on: [push, pull_request] jobs: CI: - runs-on: macos-latest + # ℹ️ Available GitHub Actions Runner Images + # https://github.com/actions/runner-images + runs-on: macos-15 steps: - name: Checkout uses: actions/checkout@v2 - - run: bundle install - run: pod install --repo-update - - name: Set Xcode Version 13.2.1 - run: sudo xcode-select -s /Applications/Xcode_13.2.1.app + - name: Set Xcode Version 16.4.0 + run: sudo xcode-select -s /Applications/Xcode_16.4.0.app - name: fastlane - run: set -o pipefail && bundle exec fastlane travis + run: set -o pipefail && fastlane travis - run: bash <(curl -s https://codecov.io/bash) -J 'FlexLayout' -J 'FlexLayoutTests' diff --git a/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..919434a6 --- /dev/null +++ b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/BUCK b/BUCK deleted file mode 100644 index b87221ea..00000000 --- a/BUCK +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright (c) 2014-present, Facebook, Inc. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -load("//:yoga_defs.bzl", "LIBRARY_COMPILER_FLAGS", "BASE_COMPILER_FLAGS", "GTEST_TARGET", "yoga_dep", "cxx_library", "cxx_test") - -GMOCK_OVERRIDE_FLAGS = [ - # gmock does not mark mocked methods as override, ignore the warnings in tests - "-Wno-inconsistent-missing-override", -] - -COMPILER_FLAGS = LIBRARY_COMPILER_FLAGS + [ - "-std=c++1y", -] - -TEST_COMPILER_FLAGS = BASE_COMPILER_FLAGS + GMOCK_OVERRIDE_FLAGS + [ - "-std=c++1y", -] - -cxx_library( - name = "yoga", - srcs = glob(["Sources/yoga/*.cpp"]), - header_namespace = "yoga", - exported_headers = subdir_glob([("Sources/yoga", "*.h")]), - compiler_flags = COMPILER_FLAGS, - soname = "libyogacore.$(ext)", - tests = [":YogaTests"], - visibility = ["PUBLIC"], - deps = [ - yoga_dep("lib/fb:ndklog"), - ], -) - -cxx_test( - name = "YogaTests", - srcs = glob(["core-tests/*.cpp"]), - compiler_flags = TEST_COMPILER_FLAGS, - contacts = ["emilsj@fb.com"], - visibility = ["PUBLIC"], - deps = [ - ":yoga", - GTEST_TARGET, - ], -) diff --git a/Brewfile b/Brewfile deleted file mode 100644 index 8ff53451..00000000 --- a/Brewfile +++ /dev/null @@ -1,2 +0,0 @@ -tap 'facebook/fb' -brew 'buck' diff --git a/CHANGELOG.md b/CHANGELOG.md index eef61833..555c124f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,167 @@ # Change Log +## [2.2.3](https://github.com/layoutBox/FlexLayout/releases/tag/2.2.2) + +#### Add support for SPM dynamic linking + +This allows users to link FlexLayout as a dynamic framework when needed for their specific use cases. + +Added by [heoblitz](https://github.com/heoblitz) in Pull Request [#284](https://github.com/layoutBox/FlexLayout/pull/284) + + +#### Fix error when dynamically removing views + +Currently, FlexLayout does not guarantee that the UIView hierarchy state matches the Yoga node structure. This is because nodes are only updated during the layout process by following the UIView hierarchy. +When a child UIView is dynamically removed and markDirty() is called, it causes an error and terminates the program because it doesn't align with Yoga's logic. + +In React Native's case, views that become leaves are fixed and used consistently, but FlexLayout allows any UIView to become a leaf. Therefore, we add defensive code to prevent logical errors. + +Added by [heoblitz](https://github.com/heoblitz) in Pull Request [#281](https://github.com/layoutBox/FlexLayout/pull/281) + + +## [2.2.2](https://github.com/layoutBox/FlexLayout/releases/tag/2.2.2) + +#### Support Swift 6 + +Added by [heoblitz](https://github.com/heoblitz) in Pull Request [#277](https://github.com/layoutBox/FlexLayout/pull/277) + + +## [2.2.0](https://github.com/layoutBox/FlexLayout/releases/tag/2.2.0) + +#### Upgrade yoga to v3.2.1 + +Added by [OhKanghoon](https://github.com/OhKanghoon) in Pull Request [#271](https://github.com/layoutBox/FlexLayout/pull/266) + +#### Upgrade yoga to v3.1.0 + +Added by [OhKanghoon](https://github.com/OhKanghoon) in Pull Request [#266](https://github.com/layoutBox/FlexLayout/pull/266) + + +## [2.0.10](https://github.com/layoutBox/FlexLayout/releases/tag/2.0.10) + +#### Support `align-content`: `space-evenly` + +Added by [OhKanghoon](https://github.com/OhKanghoon) in Pull Request [#255](https://github.com/layoutBox/FlexLayout/pull/255) + + +## [2.0.9](https://github.com/layoutBox/FlexLayout/releases/tag/2.0.9) + +#### Add `static` position feature + +Add feature for the static position supported in Yoga version 3.0.0. +- Due to the default behavior of Yoga, insets like top, left, bottom, and right also affect relative position view. Accordingly, the README, docs and comments have been updated to match the Yoga specifications. +- Added static case to position and unit tests. + +https://www.yogalayout.dev/docs/styling/position +https://www.yogalayout.dev/docs/styling/insets + +Added by [heoblitz](https://github.com/heoblitz) in Pull Request [#245](https://github.com/layoutBox/FlexLayout/pull/254) + +## [2.0.7](https://github.com/layoutBox/FlexLayout/releases/tag/2.0.7) + +#### Update yoga to version 3.0.4 + +Added by [heoblitz](https://github.com/heoblitz) in Pull Request [#245](https://github.com/layoutBox/FlexLayout/pull/252) + + +## [2.0.06](https://github.com/layoutBox/FlexLayout/releases/tag/2.0.07) + +#### Remove FlexLayoutYoga duplicate dependency in Swift Package + +Added by [OhKanghoon](https://github.com/OhKanghoon) in Pull Request [#245](https://github.com/layoutBox/FlexLayout/pull/245) + + +## [2.0.06](https://github.com/layoutBox/FlexLayout/releases/tag/2.0.06) + +#### Fix error that occur when creating XCFramework + +Background + +- Public header issue occurs when using Objective-C package in [Tuist](https://github.com/tuist/tuist)'s Dependency. To resolve this issue, I want to provide xcframework. +- Resolve the issue that occurs when creating xcframework due to duplicate 'postfix operator %'. + +Contents + +- remove unnecessary files and headers + - Modified to manage yoga directly in FlexLayout. Buck dependency is now unnecessary. +- remove duplicated postfix operator +- update Podfile.lock +- remove Info.plist +- move `FlexLayout.h` to public header directory + +Added by [OhKanghoon](https://github.com/OhKanghoon) in Pull Request [#244](https://github.com/layoutBox/FlexLayout/pull/244) + + + +## [2.0.05](https://github.com/layoutBox/FlexLayout/releases/tag/2.0.05) +Released on 2024-01-11 + +#### 1) Add `Gap` support + +Add `Gap` methods: + +- `columnGap(_ value: CGFloat) -> Flex` +- `rowGap(_ value: CGFloat) -> Flex` +- `gap(_ value: CGFloat) -> Flex` + +##### background +After [Yoga layout updated to 2.0.0](https://github.com/layoutBox/FlexLayout/pull/230) the gap func added. and as needed by [this issue](https://github.com/layoutBox/FlexLayout/issues/235) and my company's product, me and my partner @TaekH made feature to use. 🙇‍♂️ + +Added by [Buseong Kim](https://github.com/Skyline-23) in Pull Request [#241](https://github.com/layoutBox/FlexLayout/pull/241) + + +#### 2) Fix "Child already has a owner" Assert + +Upgrading to the latest version of Yoga introduced an assert in YGNodeInsertChild() that was previously removed accidentally (see relevant commit). This assert will throw an error if the node we are trying to add already has an owner. Unfortunately, we can fall into this case quite easily if we move a view between different superviews (as demonstrated in the following contrived example). + +Restoring the changes from this old commit [c303faa](https://github.com/layoutBox/FlexLayout/commit/c303faae7b7b441872f8d49dbd1424db6ec7953f) should ensure that any lingering parent references are cleaned up before we call YGNodeInsertChild() + +Added by [kennethpu](https://github.com/kennethpu) in Pull Request [#242](https://github.com/layoutBox/FlexLayout/pull/242) + + + +## [2.0.04](https://github.com/layoutBox/FlexLayout/releases/tag/2.0.04) +Released on 2024-01-06 + +#### Enhance Swift Package experience + +- Change the Swift Package Manager to be available without `FLEXLAYOUT_SWIFT_PACKAGE` flag +- add public header path +- remove `FLEXLAYOUT_SWIFT_PACKAGE` +- remove library for internal (FlexLayoutYoga, FlexLayoutYogaKit) +- move the unit test to the swift package with XCTest + +Added by [OhKanghoon](https://github.com/OhKanghoon) in Pull Request [#232](https://github.com/layoutBox/FlexLayout/pull/232) + +#### Split the Example project in 2 projects (Cocoapods & SPM) + +Split the Example project in 2 projects: + +* `FlexLayoutSample`: Use cocoapods dependency manager +* `FlexLayoutSample-SPM`: Use SPM (Swift Packager Manager) dependency manager + +Added by [Luc Dion](https://github.com/lucdion) in Pull Request [#240](https://github.com/layoutBox/FlexLayout/pull/240) + + +## [2.0.03](https://github.com/layoutBox/FlexLayout/releases/tag/2.0.03) +Released on 2023-10-15 + +#### Fix crashes that occurs when the node's topLeft position is nan + +Added by [OhKanghoon](https://github.com/OhKanghoon) in Pull Request [#230](https://github.com/layoutBox/FlexLayout/pull/234) + + +## [2.0.01](https://github.com/layoutBox/FlexLayout/releases/tag/2.0.01) +Released on 2023-10-01 + +#### Update Yoga core to 2.0 + +FlexLayout version has been increased to reflect the new Yoga core version. + +Added by [OhKanghoon](https://github.com/OhKanghoon) in Pull Request [#230](https://github.com/layoutBox/FlexLayout/pull/230) + + ## [1.3.33](https://github.com/layoutBox/FlexLayout/releases/tag/1.3.33) Released on 2023-06-24 diff --git a/Carthage/Build/iOS/Nimble.framework/Headers/CwlCatchException.h b/Carthage/Build/iOS/Nimble.framework/Headers/CwlCatchException.h deleted file mode 100644 index 0c8dd878..00000000 --- a/Carthage/Build/iOS/Nimble.framework/Headers/CwlCatchException.h +++ /dev/null @@ -1,32 +0,0 @@ -// -// CwlCatchException.h -// CwlCatchException -// -// Created by Matt Gallagher on 2016/01/10. -// Copyright © 2016 Matt Gallagher ( http://cocoawithlove.com ). All rights reserved. -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY -// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR -// IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -// - -#import - -//! Project version number for CwlCatchException. -FOUNDATION_EXPORT double CwlCatchExceptionVersionNumber; - -//! Project version string for CwlCatchException. -FOUNDATION_EXPORT const unsigned char CwlCatchExceptionVersionString[]; - -#if !SWIFT_PACKAGE && NON_SWIFT_PACKAGE -__attribute__((visibility("hidden"))) -#endif -NSException* __nullable catchExceptionOfKind(Class __nonnull type, __attribute__((noescape)) void (^ __nonnull inBlock)(void)); diff --git a/Carthage/Build/iOS/Nimble.framework/Headers/CwlMachBadInstructionHandler.h b/Carthage/Build/iOS/Nimble.framework/Headers/CwlMachBadInstructionHandler.h deleted file mode 100644 index aef59c2c..00000000 --- a/Carthage/Build/iOS/Nimble.framework/Headers/CwlMachBadInstructionHandler.h +++ /dev/null @@ -1,70 +0,0 @@ -// -// CwlMachBadInstructionHandler.h -// CwlPreconditionTesting -// -// Created by Matt Gallagher on 2016/01/10. -// Copyright © 2016 Matt Gallagher ( http://cocoawithlove.com ). All rights reserved. -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY -// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR -// IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -// - -#import -#import - -NS_ASSUME_NONNULL_BEGIN - -extern boolean_t mach_exc_server(mach_msg_header_t *InHeadP, mach_msg_header_t *OutHeadP); - -// The request_mach_exception_raise_t struct is passed to mach_msg which assumes its exact layout. To avoid problems with different layouts, we keep the definition in C rather than Swift. -typedef struct -{ - mach_msg_header_t Head; - /* start of the kernel processed data */ - mach_msg_body_t msgh_body; - mach_msg_port_descriptor_t thread; - mach_msg_port_descriptor_t task; - /* end of the kernel processed data */ - NDR_record_t NDR; - exception_type_t exception; - mach_msg_type_number_t codeCnt; - int64_t code[2]; - int flavor; - mach_msg_type_number_t old_stateCnt; - natural_t old_state[224]; -} request_mach_exception_raise_t; - -// The reply_mach_exception_raise_state_t struct is passed to mach_msg which assumes its exact layout. To avoid problems with different layouts, we keep the definition in C rather than Swift. -typedef struct -{ - mach_msg_header_t Head; - NDR_record_t NDR; - kern_return_t RetCode; - int flavor; - mach_msg_type_number_t new_stateCnt; - natural_t new_state[224]; -} reply_mach_exception_raise_state_t; - -typedef struct -{ - mach_port_t exception_port; - exception_type_t exception; - mach_exception_data_type_t const * _Nullable code; - mach_msg_type_number_t codeCnt; - int32_t * _Nullable flavor; - natural_t const * _Nullable old_state; - mach_msg_type_number_t old_stateCnt; - thread_state_t _Nullable new_state; - mach_msg_type_number_t * _Nullable new_stateCnt; -} bad_instruction_exception_reply_t; - -NS_ASSUME_NONNULL_END diff --git a/Carthage/Build/iOS/Nimble.framework/Headers/CwlPreconditionTesting.h b/Carthage/Build/iOS/Nimble.framework/Headers/CwlPreconditionTesting.h deleted file mode 100644 index f9dbedda..00000000 --- a/Carthage/Build/iOS/Nimble.framework/Headers/CwlPreconditionTesting.h +++ /dev/null @@ -1,30 +0,0 @@ -// -// CwlPreconditionTesting.h -// CwlPreconditionTesting -// -// Created by Matt Gallagher on 2016/01/10. -// Copyright © 2016 Matt Gallagher ( http://cocoawithlove.com ). All rights reserved. -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY -// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR -// IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -// - -#import - -//! Project version number for CwlUtils. -FOUNDATION_EXPORT double CwlPreconditionTestingVersionNumber; - -//! Project version string for CwlUtils. -FOUNDATION_EXPORT const unsigned char CwlAssertingTestingVersionString[]; - -#include "CwlMachBadInstructionHandler.h" -#include "CwlCatchException.h" diff --git a/Carthage/Build/iOS/Nimble.framework/Headers/DSL.h b/Carthage/Build/iOS/Nimble.framework/Headers/DSL.h deleted file mode 100644 index caa3f7c7..00000000 --- a/Carthage/Build/iOS/Nimble.framework/Headers/DSL.h +++ /dev/null @@ -1,383 +0,0 @@ -#import - -@class NMBExpectation; -@class NMBObjCBeCloseToMatcher; -@class NMBObjCRaiseExceptionMatcher; -@protocol NMBMatcher; - - -NS_ASSUME_NONNULL_BEGIN - - -#define NIMBLE_OVERLOADABLE __attribute__((overloadable)) -#define NIMBLE_EXPORT FOUNDATION_EXPORT -#define NIMBLE_EXPORT_INLINE FOUNDATION_STATIC_INLINE - -#define NIMBLE_VALUE_OF(VAL) ({ \ - __typeof__((VAL)) val = (VAL); \ - [NSValue valueWithBytes:&val objCType:@encode(__typeof__((VAL)))]; \ -}) - -#ifdef NIMBLE_DISABLE_SHORT_SYNTAX -#define NIMBLE_SHORT(PROTO, ORIGINAL) -#define NIMBLE_SHORT_OVERLOADED(PROTO, ORIGINAL) -#else -#define NIMBLE_SHORT(PROTO, ORIGINAL) FOUNDATION_STATIC_INLINE PROTO { return (ORIGINAL); } -#define NIMBLE_SHORT_OVERLOADED(PROTO, ORIGINAL) FOUNDATION_STATIC_INLINE NIMBLE_OVERLOADABLE PROTO { return (ORIGINAL); } -#endif - - - -#define DEFINE_NMB_EXPECT_OVERLOAD(TYPE, EXPR) \ - NIMBLE_EXPORT_INLINE NIMBLE_OVERLOADABLE \ - NMBExpectation *NMB_expect(TYPE(^actualBlock)(void), NSString *file, NSUInteger line) { \ - return NMB_expect(^id { return EXPR; }, file, line); \ - } - - NIMBLE_EXPORT NIMBLE_OVERLOADABLE - NMBExpectation *NMB_expect(id(^actualBlock)(void), NSString *file, NSUInteger line); - - // overloaded dispatch for nils - expect(nil) - DEFINE_NMB_EXPECT_OVERLOAD(void*, nil) - DEFINE_NMB_EXPECT_OVERLOAD(NSRange, NIMBLE_VALUE_OF(actualBlock())) - DEFINE_NMB_EXPECT_OVERLOAD(long, @(actualBlock())) - DEFINE_NMB_EXPECT_OVERLOAD(unsigned long, @(actualBlock())) - DEFINE_NMB_EXPECT_OVERLOAD(int, @(actualBlock())) - DEFINE_NMB_EXPECT_OVERLOAD(unsigned int, @(actualBlock())) - DEFINE_NMB_EXPECT_OVERLOAD(float, @(actualBlock())) - DEFINE_NMB_EXPECT_OVERLOAD(double, @(actualBlock())) - DEFINE_NMB_EXPECT_OVERLOAD(long long, @(actualBlock())) - DEFINE_NMB_EXPECT_OVERLOAD(unsigned long long, @(actualBlock())) - DEFINE_NMB_EXPECT_OVERLOAD(char, @(actualBlock())) - DEFINE_NMB_EXPECT_OVERLOAD(unsigned char, @(actualBlock())) - // bool doesn't get the compiler to dispatch to BOOL types, but using BOOL here seems to allow - // the compiler to dispatch to bool. - DEFINE_NMB_EXPECT_OVERLOAD(BOOL, @(actualBlock())) - DEFINE_NMB_EXPECT_OVERLOAD(char *, @(actualBlock())) - - -#undef DEFINE_NMB_EXPECT_OVERLOAD - - - -NIMBLE_EXPORT NMBExpectation *NMB_expectAction(void(^actualBlock)(void), NSString *file, NSUInteger line); - - - -#define DEFINE_OVERLOAD(TYPE, EXPR) \ - NIMBLE_EXPORT_INLINE NIMBLE_OVERLOADABLE \ - id NMB_equal(TYPE expectedValue) { \ - return NMB_equal((EXPR)); \ - } \ - NIMBLE_SHORT_OVERLOADED(id equal(TYPE expectedValue), NMB_equal(expectedValue)); - - - NIMBLE_EXPORT NIMBLE_OVERLOADABLE - id NMB_equal(__nullable id expectedValue); - - NIMBLE_SHORT_OVERLOADED(id equal(__nullable id expectedValue), - NMB_equal(expectedValue)); - - // overloaded dispatch for nils - expect(nil) - DEFINE_OVERLOAD(void*__nullable, (id)nil) - DEFINE_OVERLOAD(NSRange, NIMBLE_VALUE_OF(expectedValue)) - DEFINE_OVERLOAD(long, @(expectedValue)) - DEFINE_OVERLOAD(unsigned long, @(expectedValue)) - DEFINE_OVERLOAD(int, @(expectedValue)) - DEFINE_OVERLOAD(unsigned int, @(expectedValue)) - DEFINE_OVERLOAD(float, @(expectedValue)) - DEFINE_OVERLOAD(double, @(expectedValue)) - DEFINE_OVERLOAD(long long, @(expectedValue)) - DEFINE_OVERLOAD(unsigned long long, @(expectedValue)) - DEFINE_OVERLOAD(char, @(expectedValue)) - DEFINE_OVERLOAD(unsigned char, @(expectedValue)) - // bool doesn't get the compiler to dispatch to BOOL types, but using BOOL here seems to allow - // the compiler to dispatch to bool. - DEFINE_OVERLOAD(BOOL, @(expectedValue)) - DEFINE_OVERLOAD(char *, @(expectedValue)) - -#undef DEFINE_OVERLOAD - - -#define DEFINE_OVERLOAD(TYPE, EXPR) \ - NIMBLE_EXPORT_INLINE NIMBLE_OVERLOADABLE \ - id NMB_haveCount(TYPE expectedValue) { \ - return NMB_haveCount((EXPR)); \ - } \ - NIMBLE_SHORT_OVERLOADED(id haveCount(TYPE expectedValue), \ - NMB_haveCount(expectedValue)); - - - NIMBLE_EXPORT NIMBLE_OVERLOADABLE - id NMB_haveCount(id expectedValue); - - NIMBLE_SHORT_OVERLOADED(id haveCount(id expectedValue), - NMB_haveCount(expectedValue)); - - DEFINE_OVERLOAD(long, @(expectedValue)) - DEFINE_OVERLOAD(unsigned long, @(expectedValue)) - DEFINE_OVERLOAD(int, @(expectedValue)) - DEFINE_OVERLOAD(unsigned int, @(expectedValue)) - DEFINE_OVERLOAD(long long, @(expectedValue)) - DEFINE_OVERLOAD(unsigned long long, @(expectedValue)) - DEFINE_OVERLOAD(char, @(expectedValue)) - DEFINE_OVERLOAD(unsigned char, @(expectedValue)) - -#undef DEFINE_OVERLOAD - -#define DEFINE_OVERLOAD(TYPE, EXPR) \ - NIMBLE_EXPORT_INLINE NIMBLE_OVERLOADABLE \ - NMBObjCBeCloseToMatcher *NMB_beCloseTo(TYPE expectedValue) { \ - return NMB_beCloseTo((NSNumber *)(EXPR)); \ - } \ - NIMBLE_SHORT_OVERLOADED(NMBObjCBeCloseToMatcher *beCloseTo(TYPE expectedValue), \ - NMB_beCloseTo(expectedValue)); - - NIMBLE_EXPORT NIMBLE_OVERLOADABLE NMBObjCBeCloseToMatcher *NMB_beCloseTo(NSNumber *expectedValue); - NIMBLE_SHORT_OVERLOADED(NMBObjCBeCloseToMatcher *beCloseTo(NSNumber *expectedValue), - NMB_beCloseTo(expectedValue)); - - // it would be better to only overload float & double, but zero becomes ambigious - - DEFINE_OVERLOAD(long, @(expectedValue)) - DEFINE_OVERLOAD(unsigned long, @(expectedValue)) - DEFINE_OVERLOAD(int, @(expectedValue)) - DEFINE_OVERLOAD(unsigned int, @(expectedValue)) - DEFINE_OVERLOAD(float, @(expectedValue)) - DEFINE_OVERLOAD(double, @(expectedValue)) - DEFINE_OVERLOAD(long long, @(expectedValue)) - DEFINE_OVERLOAD(unsigned long long, @(expectedValue)) - DEFINE_OVERLOAD(char, @(expectedValue)) - DEFINE_OVERLOAD(unsigned char, @(expectedValue)) - -#undef DEFINE_OVERLOAD - -NIMBLE_EXPORT id NMB_beAnInstanceOf(Class expectedClass); -NIMBLE_EXPORT_INLINE id beAnInstanceOf(Class expectedClass) { - return NMB_beAnInstanceOf(expectedClass); -} - -NIMBLE_EXPORT id NMB_beAKindOf(Class expectedClass); -NIMBLE_EXPORT_INLINE id beAKindOf(Class expectedClass) { - return NMB_beAKindOf(expectedClass); -} - -NIMBLE_EXPORT id NMB_beginWith(id itemElementOrSubstring); -NIMBLE_EXPORT_INLINE id beginWith(id itemElementOrSubstring) { - return NMB_beginWith(itemElementOrSubstring); -} - -#define DEFINE_OVERLOAD(TYPE, EXPR) \ - NIMBLE_EXPORT_INLINE NIMBLE_OVERLOADABLE \ - id NMB_beGreaterThan(TYPE expectedValue) { \ - return NMB_beGreaterThan((EXPR)); \ - } \ - NIMBLE_SHORT_OVERLOADED(id beGreaterThan(TYPE expectedValue), NMB_beGreaterThan(expectedValue)); - - NIMBLE_EXPORT NIMBLE_OVERLOADABLE - id NMB_beGreaterThan(NSNumber *expectedValue); - - NIMBLE_EXPORT_INLINE NIMBLE_OVERLOADABLE - id beGreaterThan(NSNumber *expectedValue) { - return NMB_beGreaterThan(expectedValue); - } - - DEFINE_OVERLOAD(long, @(expectedValue)) - DEFINE_OVERLOAD(unsigned long, @(expectedValue)) - DEFINE_OVERLOAD(int, @(expectedValue)) - DEFINE_OVERLOAD(unsigned int, @(expectedValue)) - DEFINE_OVERLOAD(float, @(expectedValue)) - DEFINE_OVERLOAD(double, @(expectedValue)) - DEFINE_OVERLOAD(long long, @(expectedValue)) - DEFINE_OVERLOAD(unsigned long long, @(expectedValue)) - DEFINE_OVERLOAD(char, @(expectedValue)) - DEFINE_OVERLOAD(unsigned char, @(expectedValue)) - -#undef DEFINE_OVERLOAD - -#define DEFINE_OVERLOAD(TYPE, EXPR) \ - NIMBLE_EXPORT_INLINE NIMBLE_OVERLOADABLE \ - id NMB_beGreaterThanOrEqualTo(TYPE expectedValue) { \ - return NMB_beGreaterThanOrEqualTo((EXPR)); \ - } \ - NIMBLE_SHORT_OVERLOADED(id beGreaterThanOrEqualTo(TYPE expectedValue), \ - NMB_beGreaterThanOrEqualTo(expectedValue)); - - NIMBLE_EXPORT NIMBLE_OVERLOADABLE - id NMB_beGreaterThanOrEqualTo(NSNumber *expectedValue); - - NIMBLE_EXPORT_INLINE NIMBLE_OVERLOADABLE - id beGreaterThanOrEqualTo(NSNumber *expectedValue) { - return NMB_beGreaterThanOrEqualTo(expectedValue); - } - - DEFINE_OVERLOAD(long, @(expectedValue)) - DEFINE_OVERLOAD(unsigned long, @(expectedValue)) - DEFINE_OVERLOAD(int, @(expectedValue)) - DEFINE_OVERLOAD(unsigned int, @(expectedValue)) - DEFINE_OVERLOAD(float, @(expectedValue)) - DEFINE_OVERLOAD(double, @(expectedValue)) - DEFINE_OVERLOAD(long long, @(expectedValue)) - DEFINE_OVERLOAD(unsigned long long, @(expectedValue)) - DEFINE_OVERLOAD(char, @(expectedValue)) - DEFINE_OVERLOAD(unsigned char, @(expectedValue)) - - -#undef DEFINE_OVERLOAD - -NIMBLE_EXPORT id NMB_beIdenticalTo(id expectedInstance); -NIMBLE_SHORT(id beIdenticalTo(id expectedInstance), - NMB_beIdenticalTo(expectedInstance)); - -NIMBLE_EXPORT id NMB_be(id expectedInstance); -NIMBLE_SHORT(id be(id expectedInstance), - NMB_be(expectedInstance)); - - -#define DEFINE_OVERLOAD(TYPE, EXPR) \ - NIMBLE_EXPORT_INLINE NIMBLE_OVERLOADABLE \ - id NMB_beLessThan(TYPE expectedValue) { \ - return NMB_beLessThan((EXPR)); \ - } \ - NIMBLE_SHORT_OVERLOADED(id beLessThan(TYPE expectedValue), \ - NMB_beLessThan(expectedValue)); - - NIMBLE_EXPORT NIMBLE_OVERLOADABLE - id NMB_beLessThan(NSNumber *expectedValue); - - NIMBLE_EXPORT_INLINE NIMBLE_OVERLOADABLE - id beLessThan(NSNumber *expectedValue) { - return NMB_beLessThan(expectedValue); - } - - DEFINE_OVERLOAD(long, @(expectedValue)) - DEFINE_OVERLOAD(unsigned long, @(expectedValue)) - DEFINE_OVERLOAD(int, @(expectedValue)) - DEFINE_OVERLOAD(unsigned int, @(expectedValue)) - DEFINE_OVERLOAD(float, @(expectedValue)) - DEFINE_OVERLOAD(double, @(expectedValue)) - DEFINE_OVERLOAD(long long, @(expectedValue)) - DEFINE_OVERLOAD(unsigned long long, @(expectedValue)) - DEFINE_OVERLOAD(char, @(expectedValue)) - DEFINE_OVERLOAD(unsigned char, @(expectedValue)) - -#undef DEFINE_OVERLOAD - - -#define DEFINE_OVERLOAD(TYPE, EXPR) \ - NIMBLE_EXPORT_INLINE NIMBLE_OVERLOADABLE \ - id NMB_beLessThanOrEqualTo(TYPE expectedValue) { \ - return NMB_beLessThanOrEqualTo((EXPR)); \ - } \ - NIMBLE_SHORT_OVERLOADED(id beLessThanOrEqualTo(TYPE expectedValue), \ - NMB_beLessThanOrEqualTo(expectedValue)); - - - NIMBLE_EXPORT NIMBLE_OVERLOADABLE - id NMB_beLessThanOrEqualTo(NSNumber *expectedValue); - - NIMBLE_EXPORT_INLINE NIMBLE_OVERLOADABLE - id beLessThanOrEqualTo(NSNumber *expectedValue) { - return NMB_beLessThanOrEqualTo(expectedValue); - } - - DEFINE_OVERLOAD(long, @(expectedValue)) - DEFINE_OVERLOAD(unsigned long, @(expectedValue)) - DEFINE_OVERLOAD(int, @(expectedValue)) - DEFINE_OVERLOAD(unsigned int, @(expectedValue)) - DEFINE_OVERLOAD(float, @(expectedValue)) - DEFINE_OVERLOAD(double, @(expectedValue)) - DEFINE_OVERLOAD(long long, @(expectedValue)) - DEFINE_OVERLOAD(unsigned long long, @(expectedValue)) - DEFINE_OVERLOAD(char, @(expectedValue)) - DEFINE_OVERLOAD(unsigned char, @(expectedValue)) - -#undef DEFINE_OVERLOAD - -NIMBLE_EXPORT id NMB_beTruthy(void); -NIMBLE_SHORT(id beTruthy(void), - NMB_beTruthy()); - -NIMBLE_EXPORT id NMB_beFalsy(void); -NIMBLE_SHORT(id beFalsy(void), - NMB_beFalsy()); - -NIMBLE_EXPORT id NMB_beTrue(void); -NIMBLE_SHORT(id beTrue(void), - NMB_beTrue()); - -NIMBLE_EXPORT id NMB_beFalse(void); -NIMBLE_SHORT(id beFalse(void), - NMB_beFalse()); - -NIMBLE_EXPORT id NMB_beNil(void); -NIMBLE_SHORT(id beNil(void), - NMB_beNil()); - -NIMBLE_EXPORT id NMB_beEmpty(void); -NIMBLE_SHORT(id beEmpty(void), - NMB_beEmpty()); - -NIMBLE_EXPORT id NMB_containWithNilTermination(id itemOrSubstring, ...) NS_REQUIRES_NIL_TERMINATION; -#define NMB_contain(...) NMB_containWithNilTermination(__VA_ARGS__, nil) -#ifndef NIMBLE_DISABLE_SHORT_SYNTAX -#define contain(...) NMB_contain(__VA_ARGS__) -#endif - -NIMBLE_EXPORT id NMB_containElementSatisfying(BOOL(^predicate)(id)); -NIMBLE_SHORT(id containElementSatisfying(BOOL(^predicate)(id)), - NMB_containElementSatisfying(predicate)); - -NIMBLE_EXPORT id NMB_endWith(id itemElementOrSubstring); -NIMBLE_SHORT(id endWith(id itemElementOrSubstring), - NMB_endWith(itemElementOrSubstring)); - -NIMBLE_EXPORT NMBObjCRaiseExceptionMatcher *NMB_raiseException(void); -NIMBLE_SHORT(NMBObjCRaiseExceptionMatcher *raiseException(void), - NMB_raiseException()); - -NIMBLE_EXPORT id NMB_match(id expectedValue); -NIMBLE_SHORT(id match(id expectedValue), - NMB_match(expectedValue)); - -NIMBLE_EXPORT id NMB_allPass(id matcher); -NIMBLE_SHORT(id allPass(id matcher), - NMB_allPass(matcher)); - -NIMBLE_EXPORT id NMB_satisfyAnyOfWithMatchers(id matchers); -#define NMB_satisfyAnyOf(...) NMB_satisfyAnyOfWithMatchers(@[__VA_ARGS__]) -#ifndef NIMBLE_DISABLE_SHORT_SYNTAX -#define satisfyAnyOf(...) NMB_satisfyAnyOf(__VA_ARGS__) -#endif - -// In order to preserve breakpoint behavior despite using macros to fill in __FILE__ and __LINE__, -// define a builder that populates __FILE__ and __LINE__, and returns a block that takes timeout -// and action arguments. See https://github.com/Quick/Quick/pull/185 for details. -typedef void (^NMBWaitUntilTimeoutBlock)(NSTimeInterval timeout, void (^action)(void (^)(void))); -typedef void (^NMBWaitUntilBlock)(void (^action)(void (^)(void))); - -NIMBLE_EXPORT void NMB_failWithMessage(NSString *msg, NSString *file, NSUInteger line); - -NIMBLE_EXPORT NMBWaitUntilTimeoutBlock NMB_waitUntilTimeoutBuilder(NSString *file, NSUInteger line); -NIMBLE_EXPORT NMBWaitUntilBlock NMB_waitUntilBuilder(NSString *file, NSUInteger line); - -NIMBLE_EXPORT void NMB_failWithMessage(NSString *msg, NSString *file, NSUInteger line); - -#define NMB_waitUntilTimeout NMB_waitUntilTimeoutBuilder(@(__FILE__), __LINE__) -#define NMB_waitUntil NMB_waitUntilBuilder(@(__FILE__), __LINE__) - -#ifndef NIMBLE_DISABLE_SHORT_SYNTAX -#define expect(...) NMB_expect(^{ return (__VA_ARGS__); }, @(__FILE__), __LINE__) -#define expectAction(BLOCK) NMB_expectAction((BLOCK), @(__FILE__), __LINE__) -#define failWithMessage(msg) NMB_failWithMessage(msg, @(__FILE__), __LINE__) -#define fail() failWithMessage(@"fail() always fails") - - -#define waitUntilTimeout NMB_waitUntilTimeout -#define waitUntil NMB_waitUntil - -#undef NIMBLE_VALUE_OF - -#endif - -NS_ASSUME_NONNULL_END diff --git a/Carthage/Build/iOS/Nimble.framework/Headers/NMBExceptionCapture.h b/Carthage/Build/iOS/Nimble.framework/Headers/NMBExceptionCapture.h deleted file mode 100644 index e6e0272a..00000000 --- a/Carthage/Build/iOS/Nimble.framework/Headers/NMBExceptionCapture.h +++ /dev/null @@ -1,11 +0,0 @@ -#import -#import - -@interface NMBExceptionCapture : NSObject - -- (nonnull instancetype)initWithHandler:(void(^ _Nullable)(NSException * _Nonnull))handler finally:(void(^ _Nullable)(void))finally; -- (void)tryBlock:(__attribute__((noescape)) void(^ _Nonnull)(void))unsafeBlock NS_SWIFT_NAME(tryBlock(_:)); - -@end - -typedef void(^NMBSourceCallbackBlock)(BOOL successful); diff --git a/Carthage/Build/iOS/Nimble.framework/Headers/NMBStringify.h b/Carthage/Build/iOS/Nimble.framework/Headers/NMBStringify.h deleted file mode 100644 index 7938bcac..00000000 --- a/Carthage/Build/iOS/Nimble.framework/Headers/NMBStringify.h +++ /dev/null @@ -1,18 +0,0 @@ -@class NSString; - -/** - * Returns a string appropriate for displaying in test output - * from the provided value. - * - * @param anyObject A value that will show up in a test's output. - * - * @return The string that is returned can be - * customized per type by conforming a type to the `TestOutputStringConvertible` - * protocol. When stringifying a non-`TestOutputStringConvertible` type, this - * function will return the value's debug description and then its - * normal description if available and in that order. Otherwise it - * will return the result of constructing a string from the value. - * - * @see `TestOutputStringConvertible` - */ -extern NSString *_Nonnull NMBStringify(id _Nullable anyObject) __attribute__((warn_unused_result)); diff --git a/Carthage/Build/iOS/Nimble.framework/Headers/Nimble-Swift.h b/Carthage/Build/iOS/Nimble.framework/Headers/Nimble-Swift.h deleted file mode 100644 index 2f4c1503..00000000 --- a/Carthage/Build/iOS/Nimble.framework/Headers/Nimble-Swift.h +++ /dev/null @@ -1,479 +0,0 @@ -// Generated by Apple Swift version 4.0.3 effective-3.2.3 (swiftlang-900.0.74.1 clang-900.0.39.2) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wgcc-compat" - -#if !defined(__has_include) -# define __has_include(x) 0 -#endif -#if !defined(__has_attribute) -# define __has_attribute(x) 0 -#endif -#if !defined(__has_feature) -# define __has_feature(x) 0 -#endif -#if !defined(__has_warning) -# define __has_warning(x) 0 -#endif - -#if __has_attribute(external_source_symbol) -# define SWIFT_STRINGIFY(str) #str -# define SWIFT_MODULE_NAMESPACE_PUSH(module_name) _Pragma(SWIFT_STRINGIFY(clang attribute push(__attribute__((external_source_symbol(language="Swift", defined_in=module_name, generated_declaration))), apply_to=any(function, enum, objc_interface, objc_category, objc_protocol)))) -# define SWIFT_MODULE_NAMESPACE_POP _Pragma("clang attribute pop") -#else -# define SWIFT_MODULE_NAMESPACE_PUSH(module_name) -# define SWIFT_MODULE_NAMESPACE_POP -#endif - -#if __has_include() -# include -#endif - -#pragma clang diagnostic ignored "-Wauto-import" -#include -#include -#include -#include - -#if !defined(SWIFT_TYPEDEFS) -# define SWIFT_TYPEDEFS 1 -# if __has_include() -# include -# elif !defined(__cplusplus) || __cplusplus < 201103L -typedef uint_least16_t char16_t; -typedef uint_least32_t char32_t; -# endif -typedef float swift_float2 __attribute__((__ext_vector_type__(2))); -typedef float swift_float3 __attribute__((__ext_vector_type__(3))); -typedef float swift_float4 __attribute__((__ext_vector_type__(4))); -typedef double swift_double2 __attribute__((__ext_vector_type__(2))); -typedef double swift_double3 __attribute__((__ext_vector_type__(3))); -typedef double swift_double4 __attribute__((__ext_vector_type__(4))); -typedef int swift_int2 __attribute__((__ext_vector_type__(2))); -typedef int swift_int3 __attribute__((__ext_vector_type__(3))); -typedef int swift_int4 __attribute__((__ext_vector_type__(4))); -typedef unsigned int swift_uint2 __attribute__((__ext_vector_type__(2))); -typedef unsigned int swift_uint3 __attribute__((__ext_vector_type__(3))); -typedef unsigned int swift_uint4 __attribute__((__ext_vector_type__(4))); -#endif - -#if !defined(SWIFT_PASTE) -# define SWIFT_PASTE_HELPER(x, y) x##y -# define SWIFT_PASTE(x, y) SWIFT_PASTE_HELPER(x, y) -#endif -#if !defined(SWIFT_METATYPE) -# define SWIFT_METATYPE(X) Class -#endif -#if !defined(SWIFT_CLASS_PROPERTY) -# if __has_feature(objc_class_property) -# define SWIFT_CLASS_PROPERTY(...) __VA_ARGS__ -# else -# define SWIFT_CLASS_PROPERTY(...) -# endif -#endif - -#if __has_attribute(objc_runtime_name) -# define SWIFT_RUNTIME_NAME(X) __attribute__((objc_runtime_name(X))) -#else -# define SWIFT_RUNTIME_NAME(X) -#endif -#if __has_attribute(swift_name) -# define SWIFT_COMPILE_NAME(X) __attribute__((swift_name(X))) -#else -# define SWIFT_COMPILE_NAME(X) -#endif -#if __has_attribute(objc_method_family) -# define SWIFT_METHOD_FAMILY(X) __attribute__((objc_method_family(X))) -#else -# define SWIFT_METHOD_FAMILY(X) -#endif -#if __has_attribute(noescape) -# define SWIFT_NOESCAPE __attribute__((noescape)) -#else -# define SWIFT_NOESCAPE -#endif -#if __has_attribute(warn_unused_result) -# define SWIFT_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) -#else -# define SWIFT_WARN_UNUSED_RESULT -#endif -#if __has_attribute(noreturn) -# define SWIFT_NORETURN __attribute__((noreturn)) -#else -# define SWIFT_NORETURN -#endif -#if !defined(SWIFT_CLASS_EXTRA) -# define SWIFT_CLASS_EXTRA -#endif -#if !defined(SWIFT_PROTOCOL_EXTRA) -# define SWIFT_PROTOCOL_EXTRA -#endif -#if !defined(SWIFT_ENUM_EXTRA) -# define SWIFT_ENUM_EXTRA -#endif -#if !defined(SWIFT_CLASS) -# if __has_attribute(objc_subclassing_restricted) -# define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) SWIFT_CLASS_EXTRA -# define SWIFT_CLASS_NAMED(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA -# else -# define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA -# define SWIFT_CLASS_NAMED(SWIFT_NAME) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA -# endif -#endif - -#if !defined(SWIFT_PROTOCOL) -# define SWIFT_PROTOCOL(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_PROTOCOL_EXTRA -# define SWIFT_PROTOCOL_NAMED(SWIFT_NAME) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_PROTOCOL_EXTRA -#endif - -#if !defined(SWIFT_EXTENSION) -# define SWIFT_EXTENSION(M) SWIFT_PASTE(M##_Swift_, __LINE__) -#endif - -#if !defined(OBJC_DESIGNATED_INITIALIZER) -# if __has_attribute(objc_designated_initializer) -# define OBJC_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer)) -# else -# define OBJC_DESIGNATED_INITIALIZER -# endif -#endif -#if !defined(SWIFT_ENUM_ATTR) -# if defined(__has_attribute) && __has_attribute(enum_extensibility) -# define SWIFT_ENUM_ATTR __attribute__((enum_extensibility(open))) -# else -# define SWIFT_ENUM_ATTR -# endif -#endif -#if !defined(SWIFT_ENUM) -# define SWIFT_ENUM(_type, _name) enum _name : _type _name; enum SWIFT_ENUM_ATTR SWIFT_ENUM_EXTRA _name : _type -# if __has_feature(generalized_swift_name) -# define SWIFT_ENUM_NAMED(_type, _name, SWIFT_NAME) enum _name : _type _name SWIFT_COMPILE_NAME(SWIFT_NAME); enum SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_ENUM_ATTR SWIFT_ENUM_EXTRA _name : _type -# else -# define SWIFT_ENUM_NAMED(_type, _name, SWIFT_NAME) SWIFT_ENUM(_type, _name) -# endif -#endif -#if !defined(SWIFT_UNAVAILABLE) -# define SWIFT_UNAVAILABLE __attribute__((unavailable)) -#endif -#if !defined(SWIFT_UNAVAILABLE_MSG) -# define SWIFT_UNAVAILABLE_MSG(msg) __attribute__((unavailable(msg))) -#endif -#if !defined(SWIFT_AVAILABILITY) -# define SWIFT_AVAILABILITY(plat, ...) __attribute__((availability(plat, __VA_ARGS__))) -#endif -#if !defined(SWIFT_DEPRECATED) -# define SWIFT_DEPRECATED __attribute__((deprecated)) -#endif -#if !defined(SWIFT_DEPRECATED_MSG) -# define SWIFT_DEPRECATED_MSG(...) __attribute__((deprecated(__VA_ARGS__))) -#endif -#if __has_feature(attribute_diagnose_if_objc) -# define SWIFT_DEPRECATED_OBJC(Msg) __attribute__((diagnose_if(1, Msg, "warning"))) -#else -# define SWIFT_DEPRECATED_OBJC(Msg) SWIFT_DEPRECATED_MSG(Msg) -#endif -#if __has_feature(modules) -@import Foundation; -@import ObjectiveC; -#endif - -#pragma clang diagnostic ignored "-Wproperty-attribute-mismatch" -#pragma clang diagnostic ignored "-Wduplicate-method-arg" -#if __has_warning("-Wpragma-clang-attribute") -# pragma clang diagnostic ignored "-Wpragma-clang-attribute" -#endif -#pragma clang diagnostic ignored "-Wunknown-pragmas" -#pragma clang diagnostic ignored "-Wnullability" - -SWIFT_MODULE_NAMESPACE_PUSH("Nimble") -@class NSCoder; -@class NSValue; -@class NSNumber; - -/// A simple NSException subclass. It’s not required to subclass NSException (since the exception type is represented in the name) but this helps for identifying the exception through runtime type. -SWIFT_CLASS_NAMED("BadInstructionException") -@interface BadInstructionException : NSException -- (nonnull instancetype)init SWIFT_UNAVAILABLE; -- (nullable instancetype)initWithCoder:(NSCoder * _Nonnull)aDecoder OBJC_DESIGNATED_INITIALIZER; -/// An Objective-C callable function, invoked from the mach_exc_server callback function catch_mach_exception_raise_state to push the raiseBadInstructionException function onto the stack. -+ (NSNumber * _Nonnull)receiveReply:(NSValue * _Nonnull)value SWIFT_WARN_UNUSED_RESULT; -- (nonnull instancetype)initWithName:(NSExceptionName _Nonnull)aName reason:(NSString * _Nullable)aReason userInfo:(NSDictionary * _Nullable)aUserInfo SWIFT_UNAVAILABLE; -@end - - -/// Encapsulates the failure message that matchers can report to the end user. -/// This is shared state between Nimble and matchers that mutate this value. -SWIFT_CLASS("_TtC6Nimble14FailureMessage") -@interface FailureMessage : NSObject -- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER; -@end - - - - -SWIFT_PROTOCOL("_TtP6Nimble13NMBComparable_") -@protocol NMBComparable -- (NSComparisonResult)NMB_compare:(id _Null_unspecified)otherObject SWIFT_WARN_UNUSED_RESULT; -@end - -@protocol NMBMatcher; - -SWIFT_CLASS("_TtC6Nimble14NMBExpectation") -@interface NMBExpectation : NSObject -- (nonnull instancetype)initWithActualBlock:(NSObject * _Null_unspecified (^ _Nonnull)(void))actualBlock negative:(BOOL)negative file:(NSString * _Nonnull)file line:(NSUInteger)line OBJC_DESIGNATED_INITIALIZER; -@property (nonatomic, readonly, copy) NMBExpectation * _Nonnull (^ _Nonnull withTimeout)(NSTimeInterval); -@property (nonatomic, readonly, copy) void (^ _Nonnull to)(id _Nonnull); -@property (nonatomic, readonly, copy) void (^ _Nonnull toWithDescription)(id _Nonnull, NSString * _Nonnull); -@property (nonatomic, readonly, copy) void (^ _Nonnull toNot)(id _Nonnull); -@property (nonatomic, readonly, copy) void (^ _Nonnull toNotWithDescription)(id _Nonnull, NSString * _Nonnull); -@property (nonatomic, readonly, copy) void (^ _Nonnull notTo)(id _Nonnull); -@property (nonatomic, readonly, copy) void (^ _Nonnull notToWithDescription)(id _Nonnull, NSString * _Nonnull); -@property (nonatomic, readonly, copy) void (^ _Nonnull toEventually)(id _Nonnull); -@property (nonatomic, readonly, copy) void (^ _Nonnull toEventuallyWithDescription)(id _Nonnull, NSString * _Nonnull); -@property (nonatomic, readonly, copy) void (^ _Nonnull toEventuallyNot)(id _Nonnull); -@property (nonatomic, readonly, copy) void (^ _Nonnull toEventuallyNotWithDescription)(id _Nonnull, NSString * _Nonnull); -@property (nonatomic, readonly, copy) void (^ _Nonnull toNotEventually)(id _Nonnull); -@property (nonatomic, readonly, copy) void (^ _Nonnull toNotEventuallyWithDescription)(id _Nonnull, NSString * _Nonnull); -+ (void)failWithMessage:(NSString * _Nonnull)message file:(NSString * _Nonnull)file line:(NSUInteger)line; -- (nonnull instancetype)init SWIFT_UNAVAILABLE; -@end - - -SWIFT_CLASS("_TtC6Nimble21NMBExpectationMessage") -@interface NMBExpectationMessage : NSObject -- (nonnull instancetype)init SWIFT_UNAVAILABLE; -@end - -@class SourceLocation; - -/// Objective-C interface to the Swift variant of Matcher. -SWIFT_PROTOCOL("_TtP6Nimble10NMBMatcher_") -@protocol NMBMatcher -- (BOOL)matches:(NSObject * _Null_unspecified (^ _Nonnull)(void))actualBlock failureMessage:(FailureMessage * _Nonnull)failureMessage location:(SourceLocation * _Nonnull)location SWIFT_WARN_UNUSED_RESULT; -- (BOOL)doesNotMatch:(NSObject * _Null_unspecified (^ _Nonnull)(void))actualBlock failureMessage:(FailureMessage * _Nonnull)failureMessage location:(SourceLocation * _Nonnull)location SWIFT_WARN_UNUSED_RESULT; -@end - - -SWIFT_CLASS("_TtC6Nimble23NMBObjCBeCloseToMatcher") -@interface NMBObjCBeCloseToMatcher : NSObject -- (BOOL)matches:(NSObject * _Null_unspecified (^ _Nonnull)(void))actualExpression failureMessage:(FailureMessage * _Nonnull)failureMessage location:(SourceLocation * _Nonnull)location SWIFT_WARN_UNUSED_RESULT; -- (BOOL)doesNotMatch:(NSObject * _Null_unspecified (^ _Nonnull)(void))actualExpression failureMessage:(FailureMessage * _Nonnull)failureMessage location:(SourceLocation * _Nonnull)location SWIFT_WARN_UNUSED_RESULT; -@property (nonatomic, readonly, copy) NMBObjCBeCloseToMatcher * _Nonnull (^ _Nonnull within)(double); -- (nonnull instancetype)init SWIFT_UNAVAILABLE; -@end - - -SWIFT_CLASS("_TtC6Nimble14NMBObjCMatcher") -@interface NMBObjCMatcher : NSObject -- (BOOL)matches:(NSObject * _Null_unspecified (^ _Nonnull)(void))actualBlock failureMessage:(FailureMessage * _Nonnull)failureMessage location:(SourceLocation * _Nonnull)location SWIFT_WARN_UNUSED_RESULT; -- (BOOL)doesNotMatch:(NSObject * _Null_unspecified (^ _Nonnull)(void))actualBlock failureMessage:(FailureMessage * _Nonnull)failureMessage location:(SourceLocation * _Nonnull)location SWIFT_WARN_UNUSED_RESULT; -- (nonnull instancetype)init SWIFT_UNAVAILABLE; -@end - - -@interface NMBObjCMatcher (SWIFT_EXTENSION(Nimble)) -+ (NMBObjCMatcher * _Nonnull)haveCountMatcher:(NSNumber * _Nonnull)expected SWIFT_WARN_UNUSED_RESULT; -@end - - -@interface NMBObjCMatcher (SWIFT_EXTENSION(Nimble)) -+ (NMBObjCMatcher * _Nonnull)endWithMatcher:(id _Nonnull)expected SWIFT_WARN_UNUSED_RESULT; -@end - - -@interface NMBObjCMatcher (SWIFT_EXTENSION(Nimble)) -+ (NMBObjCMatcher * _Nonnull)beNilMatcher SWIFT_WARN_UNUSED_RESULT; -@end - -@class NMBPredicate; - -@interface NMBObjCMatcher (SWIFT_EXTENSION(Nimble)) -+ (NMBPredicate * _Nonnull)beEmptyMatcher SWIFT_WARN_UNUSED_RESULT; -@end - - -@interface NMBObjCMatcher (SWIFT_EXTENSION(Nimble)) -+ (NMBObjCMatcher * _Nonnull)beIdenticalToMatcher:(NSObject * _Nullable)expected SWIFT_WARN_UNUSED_RESULT; -@end - - -@interface NMBObjCMatcher (SWIFT_EXTENSION(Nimble)) -+ (NMBObjCMatcher * _Nonnull)beginWithMatcher:(id _Nonnull)expected SWIFT_WARN_UNUSED_RESULT; -@end - - -@interface NMBObjCMatcher (SWIFT_EXTENSION(Nimble)) -+ (NMBObjCMatcher * _Nonnull)beGreaterThanOrEqualToMatcher:(id _Nullable)expected SWIFT_WARN_UNUSED_RESULT; -@end - - -@interface NMBObjCMatcher (SWIFT_EXTENSION(Nimble)) -+ (NMBObjCMatcher * _Nonnull)containMatcher:(NSArray * _Nonnull)expected SWIFT_WARN_UNUSED_RESULT; -@end - -@class NMBObjCRaiseExceptionMatcher; - -@interface NMBObjCMatcher (SWIFT_EXTENSION(Nimble)) -+ (NMBObjCRaiseExceptionMatcher * _Nonnull)raiseExceptionMatcher SWIFT_WARN_UNUSED_RESULT; -@end - - -@interface NMBObjCMatcher (SWIFT_EXTENSION(Nimble)) -+ (NMBObjCMatcher * _Nonnull)beGreaterThanMatcher:(id _Nullable)expected SWIFT_WARN_UNUSED_RESULT; -@end - - -@interface NMBObjCMatcher (SWIFT_EXTENSION(Nimble)) -+ (NMBObjCMatcher * _Nonnull)beLessThanMatcher:(id _Nullable)expected SWIFT_WARN_UNUSED_RESULT; -@end - - -@interface NMBObjCMatcher (SWIFT_EXTENSION(Nimble)) -+ (id _Nonnull)equalMatcher:(NSObject * _Nonnull)expected SWIFT_WARN_UNUSED_RESULT; -@end - - -@interface NMBObjCMatcher (SWIFT_EXTENSION(Nimble)) -+ (NMBObjCMatcher * _Nonnull)containElementSatisfyingMatcher:(BOOL (^ _Nonnull)(NSObject * _Nonnull))predicate SWIFT_WARN_UNUSED_RESULT; -@end - -@class NSString; - -@interface NMBObjCMatcher (SWIFT_EXTENSION(Nimble)) -+ (id _Nonnull)matchMatcher:(NSString * _Nonnull)expected SWIFT_WARN_UNUSED_RESULT; -@end - - -@interface NMBObjCMatcher (SWIFT_EXTENSION(Nimble)) -+ (id _Nonnull)beAKindOfMatcher:(Class _Nonnull)expected SWIFT_WARN_UNUSED_RESULT; -@end - - -@interface NMBObjCMatcher (SWIFT_EXTENSION(Nimble)) -+ (NMBPredicate * _Nonnull)allPassMatcher:(id _Nonnull)matcher SWIFT_WARN_UNUSED_RESULT; -@end - - -@interface NMBObjCMatcher (SWIFT_EXTENSION(Nimble)) -+ (id _Nonnull)beAnInstanceOfMatcher:(Class _Nonnull)expected SWIFT_WARN_UNUSED_RESULT; -@end - - -@interface NMBObjCMatcher (SWIFT_EXTENSION(Nimble)) -+ (NMBObjCMatcher * _Nonnull)beLessThanOrEqualToMatcher:(id _Nullable)expected SWIFT_WARN_UNUSED_RESULT; -@end - - -@interface NMBObjCMatcher (SWIFT_EXTENSION(Nimble)) -+ (NMBObjCBeCloseToMatcher * _Nonnull)beCloseToMatcher:(NSNumber * _Nonnull)expected within:(double)within SWIFT_WARN_UNUSED_RESULT; -@end - - -@interface NMBObjCMatcher (SWIFT_EXTENSION(Nimble)) -+ (NMBPredicate * _Nonnull)satisfyAnyOfMatcher:(NSArray> * _Nonnull)matchers SWIFT_WARN_UNUSED_RESULT; -@end - - -@interface NMBObjCMatcher (SWIFT_EXTENSION(Nimble)) -+ (NMBObjCMatcher * _Nonnull)beTruthyMatcher SWIFT_WARN_UNUSED_RESULT; -+ (NMBObjCMatcher * _Nonnull)beFalsyMatcher SWIFT_WARN_UNUSED_RESULT; -+ (NMBObjCMatcher * _Nonnull)beTrueMatcher SWIFT_WARN_UNUSED_RESULT; -+ (NMBObjCMatcher * _Nonnull)beFalseMatcher SWIFT_WARN_UNUSED_RESULT; -@end - -@class NSDictionary; - -SWIFT_CLASS("_TtC6Nimble28NMBObjCRaiseExceptionMatcher") -@interface NMBObjCRaiseExceptionMatcher : NSObject -- (BOOL)matches:(NSObject * _Null_unspecified (^ _Nonnull)(void))actualBlock failureMessage:(FailureMessage * _Nonnull)failureMessage location:(SourceLocation * _Nonnull)location SWIFT_WARN_UNUSED_RESULT; -- (BOOL)doesNotMatch:(NSObject * _Null_unspecified (^ _Nonnull)(void))actualBlock failureMessage:(FailureMessage * _Nonnull)failureMessage location:(SourceLocation * _Nonnull)location SWIFT_WARN_UNUSED_RESULT; -@property (nonatomic, readonly, copy) NMBObjCRaiseExceptionMatcher * _Nonnull (^ _Nonnull named)(NSString * _Nonnull); -@property (nonatomic, readonly, copy) NMBObjCRaiseExceptionMatcher * _Nonnull (^ _Nonnull reason)(NSString * _Nullable); -@property (nonatomic, readonly, copy) NMBObjCRaiseExceptionMatcher * _Nonnull (^ _Nonnull userInfo)(NSDictionary * _Nullable); -@property (nonatomic, readonly, copy) NMBObjCRaiseExceptionMatcher * _Nonnull (^ _Nonnull satisfyingBlock)(void (^ _Nullable)(NSException * _Nonnull)); -- (nonnull instancetype)init SWIFT_UNAVAILABLE; -@end - - -SWIFT_CLASS("_TtC6Nimble12NMBPredicate") -@interface NMBPredicate : NSObject -- (nonnull instancetype)init SWIFT_UNAVAILABLE; -@end - - -@interface NMBPredicate (SWIFT_EXTENSION(Nimble)) -- (BOOL)matches:(NSObject * _Null_unspecified (^ _Nonnull)(void))actualBlock failureMessage:(FailureMessage * _Nonnull)failureMessage location:(SourceLocation * _Nonnull)location SWIFT_WARN_UNUSED_RESULT; -- (BOOL)doesNotMatch:(NSObject * _Null_unspecified (^ _Nonnull)(void))actualBlock failureMessage:(FailureMessage * _Nonnull)failureMessage location:(SourceLocation * _Nonnull)location SWIFT_WARN_UNUSED_RESULT; -@end - - -SWIFT_CLASS("_TtC6Nimble18NMBPredicateResult") -@interface NMBPredicateResult : NSObject -- (nonnull instancetype)init SWIFT_UNAVAILABLE; -@end - - -SWIFT_CLASS("_TtC6Nimble18NMBPredicateStatus") -@interface NMBPredicateStatus : NSObject -@property (nonatomic, readonly) NSInteger hashValue; -- (BOOL)isEqual:(id _Nullable)object SWIFT_WARN_UNUSED_RESULT; -- (nonnull instancetype)init SWIFT_UNAVAILABLE; -@end - - -SWIFT_CLASS("_TtC6Nimble11NMBStringer") -@interface NMBStringer : NSObject -+ (NSString * _Nonnull)stringify:(id _Nullable)obj SWIFT_WARN_UNUSED_RESULT; -- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER; -@end - - - - - - - - - - - - - - - - - - - - - - - - - - -@interface NSNumber (SWIFT_EXTENSION(Nimble)) -- (NSComparisonResult)NMB_compare:(id _Null_unspecified)otherObject SWIFT_WARN_UNUSED_RESULT; -@end - - - - - - - - -@interface NSString (SWIFT_EXTENSION(Nimble)) -- (NSComparisonResult)NMB_compare:(id _Null_unspecified)otherObject SWIFT_WARN_UNUSED_RESULT; -@end - - - - -SWIFT_CLASS("_TtC6Nimble14SourceLocation") -@interface SourceLocation : NSObject -- (nonnull instancetype)init SWIFT_UNAVAILABLE; -@property (nonatomic, readonly, copy) NSString * _Nonnull description; -@end - -SWIFT_MODULE_NAMESPACE_POP -#pragma clang diagnostic pop diff --git a/Carthage/Build/iOS/Nimble.framework/Headers/Nimble.h b/Carthage/Build/iOS/Nimble.framework/Headers/Nimble.h deleted file mode 100644 index 2bbc6936..00000000 --- a/Carthage/Build/iOS/Nimble.framework/Headers/Nimble.h +++ /dev/null @@ -1,13 +0,0 @@ -#import -#import "NMBExceptionCapture.h" -#import "NMBStringify.h" -#import "DSL.h" - -#if TARGET_OS_TV - #import "CwlPreconditionTesting_POSIX.h" -#else - #import "CwlPreconditionTesting.h" -#endif - -FOUNDATION_EXPORT double NimbleVersionNumber; -FOUNDATION_EXPORT const unsigned char NimbleVersionString[]; diff --git a/Carthage/Build/iOS/Nimble.framework/Info.plist b/Carthage/Build/iOS/Nimble.framework/Info.plist deleted file mode 100644 index 3e43aeeb..00000000 Binary files a/Carthage/Build/iOS/Nimble.framework/Info.plist and /dev/null differ diff --git a/Carthage/Build/iOS/Nimble.framework/Modules/Nimble.swiftmodule/arm.swiftdoc b/Carthage/Build/iOS/Nimble.framework/Modules/Nimble.swiftmodule/arm.swiftdoc deleted file mode 100644 index cd02e902..00000000 Binary files a/Carthage/Build/iOS/Nimble.framework/Modules/Nimble.swiftmodule/arm.swiftdoc and /dev/null differ diff --git a/Carthage/Build/iOS/Nimble.framework/Modules/Nimble.swiftmodule/arm.swiftmodule b/Carthage/Build/iOS/Nimble.framework/Modules/Nimble.swiftmodule/arm.swiftmodule deleted file mode 100644 index 05b1e742..00000000 Binary files a/Carthage/Build/iOS/Nimble.framework/Modules/Nimble.swiftmodule/arm.swiftmodule and /dev/null differ diff --git a/Carthage/Build/iOS/Nimble.framework/Modules/Nimble.swiftmodule/arm64.swiftdoc b/Carthage/Build/iOS/Nimble.framework/Modules/Nimble.swiftmodule/arm64.swiftdoc deleted file mode 100644 index 508b42cc..00000000 Binary files a/Carthage/Build/iOS/Nimble.framework/Modules/Nimble.swiftmodule/arm64.swiftdoc and /dev/null differ diff --git a/Carthage/Build/iOS/Nimble.framework/Modules/Nimble.swiftmodule/arm64.swiftmodule b/Carthage/Build/iOS/Nimble.framework/Modules/Nimble.swiftmodule/arm64.swiftmodule deleted file mode 100644 index afb40f58..00000000 Binary files a/Carthage/Build/iOS/Nimble.framework/Modules/Nimble.swiftmodule/arm64.swiftmodule and /dev/null differ diff --git a/Carthage/Build/iOS/Nimble.framework/Modules/Nimble.swiftmodule/i386.swiftdoc b/Carthage/Build/iOS/Nimble.framework/Modules/Nimble.swiftmodule/i386.swiftdoc deleted file mode 100644 index 8c4f1f60..00000000 Binary files a/Carthage/Build/iOS/Nimble.framework/Modules/Nimble.swiftmodule/i386.swiftdoc and /dev/null differ diff --git a/Carthage/Build/iOS/Nimble.framework/Modules/Nimble.swiftmodule/i386.swiftmodule b/Carthage/Build/iOS/Nimble.framework/Modules/Nimble.swiftmodule/i386.swiftmodule deleted file mode 100644 index 99af706c..00000000 Binary files a/Carthage/Build/iOS/Nimble.framework/Modules/Nimble.swiftmodule/i386.swiftmodule and /dev/null differ diff --git a/Carthage/Build/iOS/Nimble.framework/Modules/Nimble.swiftmodule/x86_64.swiftdoc b/Carthage/Build/iOS/Nimble.framework/Modules/Nimble.swiftmodule/x86_64.swiftdoc deleted file mode 100644 index 70611d1f..00000000 Binary files a/Carthage/Build/iOS/Nimble.framework/Modules/Nimble.swiftmodule/x86_64.swiftdoc and /dev/null differ diff --git a/Carthage/Build/iOS/Nimble.framework/Modules/Nimble.swiftmodule/x86_64.swiftmodule b/Carthage/Build/iOS/Nimble.framework/Modules/Nimble.swiftmodule/x86_64.swiftmodule deleted file mode 100644 index 781880a7..00000000 Binary files a/Carthage/Build/iOS/Nimble.framework/Modules/Nimble.swiftmodule/x86_64.swiftmodule and /dev/null differ diff --git a/Carthage/Build/iOS/Nimble.framework/Modules/module.modulemap b/Carthage/Build/iOS/Nimble.framework/Modules/module.modulemap deleted file mode 100644 index b580b54c..00000000 --- a/Carthage/Build/iOS/Nimble.framework/Modules/module.modulemap +++ /dev/null @@ -1,11 +0,0 @@ -framework module Nimble { - umbrella header "Nimble.h" - - export * - module * { export * } -} - -module Nimble.Swift { - header "Nimble-Swift.h" - requires objc -} diff --git a/Carthage/Build/iOS/Nimble.framework/Nimble b/Carthage/Build/iOS/Nimble.framework/Nimble deleted file mode 100755 index 59d1a20f..00000000 Binary files a/Carthage/Build/iOS/Nimble.framework/Nimble and /dev/null differ diff --git a/Carthage/Build/iOS/Quick.framework/Headers/QCKDSL.h b/Carthage/Build/iOS/Quick.framework/Headers/QCKDSL.h deleted file mode 100644 index c5f3152a..00000000 --- a/Carthage/Build/iOS/Quick.framework/Headers/QCKDSL.h +++ /dev/null @@ -1,234 +0,0 @@ -#import - -@class ExampleMetadata; - -/** - Provides a hook for Quick to be configured before any examples are run. - Within this scope, override the +[QuickConfiguration configure:] method - to set properties on a configuration object to customize Quick behavior. - For details, see the documentation for Configuraiton.swift. - - @param name The name of the configuration class. Like any Objective-C - class name, this must be unique to the current runtime - environment. - */ -#define QuickConfigurationBegin(name) \ - @interface name : QuickConfiguration; @end \ - @implementation name \ - - -/** - Marks the end of a Quick configuration. - Make sure you put this after `QuickConfigurationBegin`. - */ -#define QuickConfigurationEnd \ - @end \ - - -/** - Defines a new QuickSpec. Define examples and example groups within the space - between this and `QuickSpecEnd`. - - @param name The name of the spec class. Like any Objective-C class name, this - must be unique to the current runtime environment. - */ -#define QuickSpecBegin(name) \ - @interface name : QuickSpec; @end \ - @implementation name \ - - (void)spec { \ - - -/** - Marks the end of a QuickSpec. Make sure you put this after `QuickSpecBegin`. - */ -#define QuickSpecEnd \ - } \ - @end \ - -typedef NSDictionary *(^QCKDSLSharedExampleContext)(void); -typedef void (^QCKDSLSharedExampleBlock)(QCKDSLSharedExampleContext); -typedef void (^QCKDSLEmptyBlock)(void); -typedef void (^QCKDSLExampleMetadataBlock)(ExampleMetadata *exampleMetadata); - -#define QUICK_EXPORT FOUNDATION_EXPORT - -QUICK_EXPORT void qck_beforeSuite(QCKDSLEmptyBlock closure); -QUICK_EXPORT void qck_afterSuite(QCKDSLEmptyBlock closure); -QUICK_EXPORT void qck_sharedExamples(NSString *name, QCKDSLSharedExampleBlock closure); -QUICK_EXPORT void qck_describe(NSString *description, QCKDSLEmptyBlock closure); -QUICK_EXPORT void qck_context(NSString *description, QCKDSLEmptyBlock closure); -QUICK_EXPORT void qck_beforeEach(QCKDSLEmptyBlock closure); -QUICK_EXPORT void qck_beforeEachWithMetadata(QCKDSLExampleMetadataBlock closure); -QUICK_EXPORT void qck_afterEach(QCKDSLEmptyBlock closure); -QUICK_EXPORT void qck_afterEachWithMetadata(QCKDSLExampleMetadataBlock closure); -QUICK_EXPORT void qck_pending(NSString *description, QCKDSLEmptyBlock closure); -QUICK_EXPORT void qck_xdescribe(NSString *description, QCKDSLEmptyBlock closure); -QUICK_EXPORT void qck_xcontext(NSString *description, QCKDSLEmptyBlock closure); -QUICK_EXPORT void qck_fdescribe(NSString *description, QCKDSLEmptyBlock closure); -QUICK_EXPORT void qck_fcontext(NSString *description, QCKDSLEmptyBlock closure); - -#ifndef QUICK_DISABLE_SHORT_SYNTAX -/** - Defines a closure to be run prior to any examples in the test suite. - You may define an unlimited number of these closures, but there is no - guarantee as to the order in which they're run. - - If the test suite crashes before the first example is run, this closure - will not be executed. - - @param closure The closure to be run prior to any examples in the test suite. - */ -static inline void beforeSuite(QCKDSLEmptyBlock closure) { - qck_beforeSuite(closure); -} - - -/** - Defines a closure to be run after all of the examples in the test suite. - You may define an unlimited number of these closures, but there is no - guarantee as to the order in which they're run. - - If the test suite crashes before all examples are run, this closure - will not be executed. - - @param closure The closure to be run after all of the examples in the test suite. - */ -static inline void afterSuite(QCKDSLEmptyBlock closure) { - qck_afterSuite(closure); -} - -/** - Defines a group of shared examples. These examples can be re-used in several locations - by using the `itBehavesLike` function. - - @param name The name of the shared example group. This must be unique across all shared example - groups defined in a test suite. - @param closure A closure containing the examples. This behaves just like an example group defined - using `describe` or `context`--the closure may contain any number of `beforeEach` - and `afterEach` closures, as well as any number of examples (defined using `it`). - */ -static inline void sharedExamples(NSString *name, QCKDSLSharedExampleBlock closure) { - qck_sharedExamples(name, closure); -} - -/** - Defines an example group. Example groups are logical groupings of examples. - Example groups can share setup and teardown code. - - @param description An arbitrary string describing the example group. - @param closure A closure that can contain other examples. - */ -static inline void describe(NSString *description, QCKDSLEmptyBlock closure) { - qck_describe(description, closure); -} - -/** - Defines an example group. Equivalent to `describe`. - */ -static inline void context(NSString *description, QCKDSLEmptyBlock closure) { - qck_context(description, closure); -} - -/** - Defines a closure to be run prior to each example in the current example - group. This closure is not run for pending or otherwise disabled examples. - An example group may contain an unlimited number of beforeEach. They'll be - run in the order they're defined, but you shouldn't rely on that behavior. - - @param closure The closure to be run prior to each example. - */ -static inline void beforeEach(QCKDSLEmptyBlock closure) { - qck_beforeEach(closure); -} - -/** - Identical to QCKDSL.beforeEach, except the closure is provided with - metadata on the example that the closure is being run prior to. - */ -static inline void beforeEachWithMetadata(QCKDSLExampleMetadataBlock closure) { - qck_beforeEachWithMetadata(closure); -} - -/** - Defines a closure to be run after each example in the current example - group. This closure is not run for pending or otherwise disabled examples. - An example group may contain an unlimited number of afterEach. They'll be - run in the order they're defined, but you shouldn't rely on that behavior. - - @param closure The closure to be run after each example. - */ -static inline void afterEach(QCKDSLEmptyBlock closure) { - qck_afterEach(closure); -} - -/** - Identical to QCKDSL.afterEach, except the closure is provided with - metadata on the example that the closure is being run after. - */ -static inline void afterEachWithMetadata(QCKDSLExampleMetadataBlock closure) { - qck_afterEachWithMetadata(closure); -} - -/** - Defines an example or example group that should not be executed. Use `pending` to temporarily disable - examples or groups that should not be run yet. - - @param description An arbitrary string describing the example or example group. - @param closure A closure that will not be evaluated. - */ -static inline void pending(NSString *description, QCKDSLEmptyBlock closure) { - qck_pending(description, closure); -} - -/** - Use this to quickly mark a `describe` block as pending. - This disables all examples within the block. - */ -static inline void xdescribe(NSString *description, QCKDSLEmptyBlock closure) { - qck_xdescribe(description, closure); -} - -/** - Use this to quickly mark a `context` block as pending. - This disables all examples within the block. - */ -static inline void xcontext(NSString *description, QCKDSLEmptyBlock closure) { - qck_xcontext(description, closure); -} - -/** - Use this to quickly focus a `describe` block, focusing the examples in the block. - If any examples in the test suite are focused, only those examples are executed. - This trumps any explicitly focused or unfocused examples within the block--they are all treated as focused. - */ -static inline void fdescribe(NSString *description, QCKDSLEmptyBlock closure) { - qck_fdescribe(description, closure); -} - -/** - Use this to quickly focus a `context` block. Equivalent to `fdescribe`. - */ -static inline void fcontext(NSString *description, QCKDSLEmptyBlock closure) { - qck_fcontext(description, closure); -} - -#define it qck_it -#define xit qck_xit -#define fit qck_fit -#define itBehavesLike qck_itBehavesLike -#define xitBehavesLike qck_xitBehavesLike -#define fitBehavesLike qck_fitBehavesLike -#endif - -#define qck_it qck_it_builder(@{}, @(__FILE__), __LINE__) -#define qck_xit qck_it_builder(@{Filter.pending: @YES}, @(__FILE__), __LINE__) -#define qck_fit qck_it_builder(@{Filter.focused: @YES}, @(__FILE__), __LINE__) -#define qck_itBehavesLike qck_itBehavesLike_builder(@{}, @(__FILE__), __LINE__) -#define qck_xitBehavesLike qck_itBehavesLike_builder(@{Filter.pending: @YES}, @(__FILE__), __LINE__) -#define qck_fitBehavesLike qck_itBehavesLike_builder(@{Filter.focused: @YES}, @(__FILE__), __LINE__) - -typedef void (^QCKItBlock)(NSString *description, QCKDSLEmptyBlock closure); -typedef void (^QCKItBehavesLikeBlock)(NSString *description, QCKDSLSharedExampleContext context); - -QUICK_EXPORT QCKItBlock qck_it_builder(NSDictionary *flags, NSString *file, NSUInteger line); -QUICK_EXPORT QCKItBehavesLikeBlock qck_itBehavesLike_builder(NSDictionary *flags, NSString *file, NSUInteger line); diff --git a/Carthage/Build/iOS/Quick.framework/Headers/Quick-Swift.h b/Carthage/Build/iOS/Quick.framework/Headers/Quick-Swift.h deleted file mode 100644 index 20f23a24..00000000 --- a/Carthage/Build/iOS/Quick.framework/Headers/Quick-Swift.h +++ /dev/null @@ -1,334 +0,0 @@ -// Generated by Apple Swift version 4.0.3 effective-3.2.3 (swiftlang-900.0.74.1 clang-900.0.39.2) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wgcc-compat" - -#if !defined(__has_include) -# define __has_include(x) 0 -#endif -#if !defined(__has_attribute) -# define __has_attribute(x) 0 -#endif -#if !defined(__has_feature) -# define __has_feature(x) 0 -#endif -#if !defined(__has_warning) -# define __has_warning(x) 0 -#endif - -#if __has_attribute(external_source_symbol) -# define SWIFT_STRINGIFY(str) #str -# define SWIFT_MODULE_NAMESPACE_PUSH(module_name) _Pragma(SWIFT_STRINGIFY(clang attribute push(__attribute__((external_source_symbol(language="Swift", defined_in=module_name, generated_declaration))), apply_to=any(function, enum, objc_interface, objc_category, objc_protocol)))) -# define SWIFT_MODULE_NAMESPACE_POP _Pragma("clang attribute pop") -#else -# define SWIFT_MODULE_NAMESPACE_PUSH(module_name) -# define SWIFT_MODULE_NAMESPACE_POP -#endif - -#if __has_include() -# include -#endif - -#pragma clang diagnostic ignored "-Wauto-import" -#include -#include -#include -#include - -#if !defined(SWIFT_TYPEDEFS) -# define SWIFT_TYPEDEFS 1 -# if __has_include() -# include -# elif !defined(__cplusplus) || __cplusplus < 201103L -typedef uint_least16_t char16_t; -typedef uint_least32_t char32_t; -# endif -typedef float swift_float2 __attribute__((__ext_vector_type__(2))); -typedef float swift_float3 __attribute__((__ext_vector_type__(3))); -typedef float swift_float4 __attribute__((__ext_vector_type__(4))); -typedef double swift_double2 __attribute__((__ext_vector_type__(2))); -typedef double swift_double3 __attribute__((__ext_vector_type__(3))); -typedef double swift_double4 __attribute__((__ext_vector_type__(4))); -typedef int swift_int2 __attribute__((__ext_vector_type__(2))); -typedef int swift_int3 __attribute__((__ext_vector_type__(3))); -typedef int swift_int4 __attribute__((__ext_vector_type__(4))); -typedef unsigned int swift_uint2 __attribute__((__ext_vector_type__(2))); -typedef unsigned int swift_uint3 __attribute__((__ext_vector_type__(3))); -typedef unsigned int swift_uint4 __attribute__((__ext_vector_type__(4))); -#endif - -#if !defined(SWIFT_PASTE) -# define SWIFT_PASTE_HELPER(x, y) x##y -# define SWIFT_PASTE(x, y) SWIFT_PASTE_HELPER(x, y) -#endif -#if !defined(SWIFT_METATYPE) -# define SWIFT_METATYPE(X) Class -#endif -#if !defined(SWIFT_CLASS_PROPERTY) -# if __has_feature(objc_class_property) -# define SWIFT_CLASS_PROPERTY(...) __VA_ARGS__ -# else -# define SWIFT_CLASS_PROPERTY(...) -# endif -#endif - -#if __has_attribute(objc_runtime_name) -# define SWIFT_RUNTIME_NAME(X) __attribute__((objc_runtime_name(X))) -#else -# define SWIFT_RUNTIME_NAME(X) -#endif -#if __has_attribute(swift_name) -# define SWIFT_COMPILE_NAME(X) __attribute__((swift_name(X))) -#else -# define SWIFT_COMPILE_NAME(X) -#endif -#if __has_attribute(objc_method_family) -# define SWIFT_METHOD_FAMILY(X) __attribute__((objc_method_family(X))) -#else -# define SWIFT_METHOD_FAMILY(X) -#endif -#if __has_attribute(noescape) -# define SWIFT_NOESCAPE __attribute__((noescape)) -#else -# define SWIFT_NOESCAPE -#endif -#if __has_attribute(warn_unused_result) -# define SWIFT_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) -#else -# define SWIFT_WARN_UNUSED_RESULT -#endif -#if __has_attribute(noreturn) -# define SWIFT_NORETURN __attribute__((noreturn)) -#else -# define SWIFT_NORETURN -#endif -#if !defined(SWIFT_CLASS_EXTRA) -# define SWIFT_CLASS_EXTRA -#endif -#if !defined(SWIFT_PROTOCOL_EXTRA) -# define SWIFT_PROTOCOL_EXTRA -#endif -#if !defined(SWIFT_ENUM_EXTRA) -# define SWIFT_ENUM_EXTRA -#endif -#if !defined(SWIFT_CLASS) -# if __has_attribute(objc_subclassing_restricted) -# define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) SWIFT_CLASS_EXTRA -# define SWIFT_CLASS_NAMED(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA -# else -# define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA -# define SWIFT_CLASS_NAMED(SWIFT_NAME) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA -# endif -#endif - -#if !defined(SWIFT_PROTOCOL) -# define SWIFT_PROTOCOL(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_PROTOCOL_EXTRA -# define SWIFT_PROTOCOL_NAMED(SWIFT_NAME) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_PROTOCOL_EXTRA -#endif - -#if !defined(SWIFT_EXTENSION) -# define SWIFT_EXTENSION(M) SWIFT_PASTE(M##_Swift_, __LINE__) -#endif - -#if !defined(OBJC_DESIGNATED_INITIALIZER) -# if __has_attribute(objc_designated_initializer) -# define OBJC_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer)) -# else -# define OBJC_DESIGNATED_INITIALIZER -# endif -#endif -#if !defined(SWIFT_ENUM_ATTR) -# if defined(__has_attribute) && __has_attribute(enum_extensibility) -# define SWIFT_ENUM_ATTR __attribute__((enum_extensibility(open))) -# else -# define SWIFT_ENUM_ATTR -# endif -#endif -#if !defined(SWIFT_ENUM) -# define SWIFT_ENUM(_type, _name) enum _name : _type _name; enum SWIFT_ENUM_ATTR SWIFT_ENUM_EXTRA _name : _type -# if __has_feature(generalized_swift_name) -# define SWIFT_ENUM_NAMED(_type, _name, SWIFT_NAME) enum _name : _type _name SWIFT_COMPILE_NAME(SWIFT_NAME); enum SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_ENUM_ATTR SWIFT_ENUM_EXTRA _name : _type -# else -# define SWIFT_ENUM_NAMED(_type, _name, SWIFT_NAME) SWIFT_ENUM(_type, _name) -# endif -#endif -#if !defined(SWIFT_UNAVAILABLE) -# define SWIFT_UNAVAILABLE __attribute__((unavailable)) -#endif -#if !defined(SWIFT_UNAVAILABLE_MSG) -# define SWIFT_UNAVAILABLE_MSG(msg) __attribute__((unavailable(msg))) -#endif -#if !defined(SWIFT_AVAILABILITY) -# define SWIFT_AVAILABILITY(plat, ...) __attribute__((availability(plat, __VA_ARGS__))) -#endif -#if !defined(SWIFT_DEPRECATED) -# define SWIFT_DEPRECATED __attribute__((deprecated)) -#endif -#if !defined(SWIFT_DEPRECATED_MSG) -# define SWIFT_DEPRECATED_MSG(...) __attribute__((deprecated(__VA_ARGS__))) -#endif -#if __has_feature(attribute_diagnose_if_objc) -# define SWIFT_DEPRECATED_OBJC(Msg) __attribute__((diagnose_if(1, Msg, "warning"))) -#else -# define SWIFT_DEPRECATED_OBJC(Msg) SWIFT_DEPRECATED_MSG(Msg) -#endif -#if __has_feature(modules) -@import Foundation; -@import ObjectiveC; -@import XCTest; -#endif - -#pragma clang diagnostic ignored "-Wproperty-attribute-mismatch" -#pragma clang diagnostic ignored "-Wduplicate-method-arg" -#if __has_warning("-Wpragma-clang-attribute") -# pragma clang diagnostic ignored "-Wpragma-clang-attribute" -#endif -#pragma clang diagnostic ignored "-Wunknown-pragmas" -#pragma clang diagnostic ignored "-Wnullability" - -SWIFT_MODULE_NAMESPACE_PUSH("Quick") - - - -SWIFT_CLASS("_TtC5Quick13_CallsiteBase") -@interface _CallsiteBase : NSObject -- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER; -@end - - -/// An object encapsulating the file and line number at which -/// a particular example is defined. -SWIFT_CLASS("_TtC5Quick8Callsite") -@interface Callsite : _CallsiteBase -/// The absolute path of the file in which an example is defined. -@property (nonatomic, readonly, copy) NSString * _Nonnull file; -/// The line number on which an example is defined. -@property (nonatomic, readonly) NSUInteger line; -- (nonnull instancetype)init SWIFT_UNAVAILABLE; -@end - - - -@class ExampleMetadata; - -/// A configuration encapsulates various options you can use -/// to configure Quick’s behavior. -SWIFT_CLASS("_TtC5Quick13Configuration") -@interface Configuration : NSObject -- (void)beforeEachWithMetadata:(void (^ _Nonnull)(ExampleMetadata * _Nonnull))closure; -- (void)afterEachWithMetadata:(void (^ _Nonnull)(ExampleMetadata * _Nonnull))closure; -- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER; -@end - - -SWIFT_CLASS("_TtC5Quick12_ExampleBase") -@interface _ExampleBase : NSObject -- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER; -@end - - -/// Examples, defined with the it function, use assertions to -/// demonstrate how code should behave. These are like “tests” in XCTest. -SWIFT_CLASS("_TtC5Quick7Example") -@interface Example : _ExampleBase -/// A boolean indicating whether the example is a shared example; -/// i.e.: whether it is an example defined with itBehavesLike. -@property (nonatomic) BOOL isSharedExample; -/// The site at which the example is defined. -/// This must be set correctly in order for Xcode to highlight -/// the correct line in red when reporting a failure. -@property (nonatomic, strong) Callsite * _Nonnull callsite; -@property (nonatomic, readonly, copy) NSString * _Nonnull description; -/// The example name. A name is a concatenation of the name of -/// the example group the example belongs to, followed by the -/// description of the example itself. -/// The example name is used to generate a test method selector -/// to be displayed in Xcode’s test navigator. -@property (nonatomic, readonly, copy) NSString * _Nonnull name; -/// Executes the example closure, as well as all before and after -/// closures defined in the its surrounding example groups. -- (void)run; -- (nonnull instancetype)init SWIFT_UNAVAILABLE; -@end - - - - -/// Example groups are logical groupings of examples, defined with -/// the describe and context functions. Example groups can share -/// setup and teardown code. -SWIFT_CLASS("_TtC5Quick12ExampleGroup") -@interface ExampleGroup : NSObject -@property (nonatomic, readonly, copy) NSString * _Nonnull description; -- (nonnull instancetype)init SWIFT_UNAVAILABLE; -@end - - -SWIFT_CLASS("_TtC5Quick20_ExampleMetadataBase") -@interface _ExampleMetadataBase : NSObject -- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER; -@end - - -/// A class that encapsulates information about an example, -/// including the index at which the example was executed, as -/// well as the example itself. -SWIFT_CLASS("_TtC5Quick15ExampleMetadata") -@interface ExampleMetadata : _ExampleMetadataBase -/// The example for which this metadata was collected. -@property (nonatomic, readonly, strong) Example * _Nonnull example; -/// The index at which this example was executed in the -/// test suite. -@property (nonatomic, readonly) NSInteger exampleIndex; -- (nonnull instancetype)init SWIFT_UNAVAILABLE; -@end - - -SWIFT_CLASS("_TtC5Quick11_FilterBase") -@interface _FilterBase : NSObject -- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER; -@end - - -/// A namespace for filter flag keys, defined primarily to make the -/// keys available in Objective-C. -SWIFT_CLASS("_TtC5Quick6Filter") -@interface Filter : _FilterBase -/// Example and example groups with [Focused: true] are included in test runs, -/// excluding all other examples without this flag. Use this to only run one or -/// two tests that you’re currently focusing on. -SWIFT_CLASS_PROPERTY(@property (nonatomic, class, readonly, copy) NSString * _Nonnull focused;) -+ (NSString * _Nonnull)focused SWIFT_WARN_UNUSED_RESULT; -/// Example and example groups with [Pending: true] are excluded from test runs. -/// Use this to temporarily suspend examples that you know do not pass yet. -SWIFT_CLASS_PROPERTY(@property (nonatomic, class, readonly, copy) NSString * _Nonnull pending;) -+ (NSString * _Nonnull)pending SWIFT_WARN_UNUSED_RESULT; -- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER; -@end - - -@interface NSString (SWIFT_EXTENSION(Quick)) -@property (nonatomic, readonly, copy) NSString * _Nonnull qck_c99ExtendedIdentifier; -@end - - -/// A base class for a class cluster of Quick test suites, that should correctly -/// build dynamic test suites for XCTest to execute. -SWIFT_CLASS("_TtC5Quick14QuickTestSuite") -@interface QuickTestSuite : XCTestSuite -/// Construct a test suite for a specific, selected subset of test cases (rather -/// than the default, which as all test cases). -/// If this method is called multiple times for the same test case class, e.g.. -/// FooSpec/testFoo -/// FooSpec/testBar -/// It is expected that the first call should return a valid test suite, and -/// all subsequent calls should return nil. -+ (QuickTestSuite * _Nullable)selectedTestSuiteForTestCaseWithName:(NSString * _Nonnull)name SWIFT_WARN_UNUSED_RESULT; -- (nonnull instancetype)initWithName:(NSString * _Nonnull)name OBJC_DESIGNATED_INITIALIZER; -@end - - - - - -SWIFT_MODULE_NAMESPACE_POP -#pragma clang diagnostic pop diff --git a/Carthage/Build/iOS/Quick.framework/Headers/Quick.h b/Carthage/Build/iOS/Quick.framework/Headers/Quick.h deleted file mode 100644 index 87dad100..00000000 --- a/Carthage/Build/iOS/Quick.framework/Headers/Quick.h +++ /dev/null @@ -1,11 +0,0 @@ -#import - -//! Project version number for Quick. -FOUNDATION_EXPORT double QuickVersionNumber; - -//! Project version string for Quick. -FOUNDATION_EXPORT const unsigned char QuickVersionString[]; - -#import "QuickSpec.h" -#import "QCKDSL.h" -#import "QuickConfiguration.h" diff --git a/Carthage/Build/iOS/Quick.framework/Headers/QuickConfiguration.h b/Carthage/Build/iOS/Quick.framework/Headers/QuickConfiguration.h deleted file mode 100644 index 56461993..00000000 --- a/Carthage/Build/iOS/Quick.framework/Headers/QuickConfiguration.h +++ /dev/null @@ -1,30 +0,0 @@ -#import - -@class Configuration; - -/** - Subclass QuickConfiguration and override the +[QuickConfiguration configure:] - method in order to configure how Quick behaves when running specs, or to define - shared examples that are used across spec files. - */ -@interface QuickConfiguration : NSObject - -/** - This method is executed on each subclass of this class before Quick runs - any examples. You may override this method on as many subclasses as you like, but - there is no guarantee as to the order in which these methods are executed. - - You can override this method in order to: - - 1. Configure how Quick behaves, by modifying properties on the Configuration object. - Setting the same properties in several methods has undefined behavior. - - 2. Define shared examples using `sharedExamples`. - - @param configuration A mutable object that is used to configure how Quick behaves on - a framework level. For details on all the options, see the - documentation in Configuration.swift. - */ -+ (void)configure:(Configuration *)configuration; - -@end diff --git a/Carthage/Build/iOS/Quick.framework/Headers/QuickSpec.h b/Carthage/Build/iOS/Quick.framework/Headers/QuickSpec.h deleted file mode 100644 index 105a97e2..00000000 --- a/Carthage/Build/iOS/Quick.framework/Headers/QuickSpec.h +++ /dev/null @@ -1,50 +0,0 @@ -#import - -/** - QuickSpec is a base class all specs written in Quick inherit from. - They need to inherit from QuickSpec, a subclass of XCTestCase, in - order to be discovered by the XCTest framework. - - XCTest automatically compiles a list of XCTestCase subclasses included - in the test target. It iterates over each class in that list, and creates - a new instance of that class for each test method. It then creates an - "invocation" to execute that test method. The invocation is an instance of - NSInvocation, which represents a single message send in Objective-C. - The invocation is set on the XCTestCase instance, and the test is run. - - Most of the code in QuickSpec is dedicated to hooking into XCTest events. - First, when the spec is first loaded and before it is sent any messages, - the +[NSObject initialize] method is called. QuickSpec overrides this method - to call +[QuickSpec spec]. This builds the example group stacks and - registers them with Quick.World, a global register of examples. - - Then, XCTest queries QuickSpec for a list of test methods. Normally, XCTest - automatically finds all methods whose selectors begin with the string "test". - However, QuickSpec overrides this default behavior by implementing the - +[XCTestCase testInvocations] method. This method iterates over each example - registered in Quick.World, defines a new method for that example, and - returns an invocation to call that method to XCTest. Those invocations are - the tests that are run by XCTest. Their selector names are displayed in - the Xcode test navigation bar. - */ -@interface QuickSpec : XCTestCase - -/** - Override this method in your spec to define a set of example groups - and examples. - - @code - override func spec() { - describe("winter") { - it("is coming") { - // ... - } - } - } - @endcode - - See DSL.swift for more information on what syntax is available. - */ -- (void)spec; - -@end diff --git a/Carthage/Build/iOS/Quick.framework/Info.plist b/Carthage/Build/iOS/Quick.framework/Info.plist deleted file mode 100644 index 3cffef9f..00000000 Binary files a/Carthage/Build/iOS/Quick.framework/Info.plist and /dev/null differ diff --git a/Carthage/Build/iOS/Quick.framework/Modules/Quick.swiftmodule/arm.swiftdoc b/Carthage/Build/iOS/Quick.framework/Modules/Quick.swiftmodule/arm.swiftdoc deleted file mode 100644 index e16b107e..00000000 Binary files a/Carthage/Build/iOS/Quick.framework/Modules/Quick.swiftmodule/arm.swiftdoc and /dev/null differ diff --git a/Carthage/Build/iOS/Quick.framework/Modules/Quick.swiftmodule/arm.swiftmodule b/Carthage/Build/iOS/Quick.framework/Modules/Quick.swiftmodule/arm.swiftmodule deleted file mode 100644 index 1cf9ff32..00000000 Binary files a/Carthage/Build/iOS/Quick.framework/Modules/Quick.swiftmodule/arm.swiftmodule and /dev/null differ diff --git a/Carthage/Build/iOS/Quick.framework/Modules/Quick.swiftmodule/arm64.swiftdoc b/Carthage/Build/iOS/Quick.framework/Modules/Quick.swiftmodule/arm64.swiftdoc deleted file mode 100644 index d38eb58d..00000000 Binary files a/Carthage/Build/iOS/Quick.framework/Modules/Quick.swiftmodule/arm64.swiftdoc and /dev/null differ diff --git a/Carthage/Build/iOS/Quick.framework/Modules/Quick.swiftmodule/arm64.swiftmodule b/Carthage/Build/iOS/Quick.framework/Modules/Quick.swiftmodule/arm64.swiftmodule deleted file mode 100644 index 1c2379a3..00000000 Binary files a/Carthage/Build/iOS/Quick.framework/Modules/Quick.swiftmodule/arm64.swiftmodule and /dev/null differ diff --git a/Carthage/Build/iOS/Quick.framework/Modules/Quick.swiftmodule/i386.swiftdoc b/Carthage/Build/iOS/Quick.framework/Modules/Quick.swiftmodule/i386.swiftdoc deleted file mode 100644 index fd8e6a1e..00000000 Binary files a/Carthage/Build/iOS/Quick.framework/Modules/Quick.swiftmodule/i386.swiftdoc and /dev/null differ diff --git a/Carthage/Build/iOS/Quick.framework/Modules/Quick.swiftmodule/i386.swiftmodule b/Carthage/Build/iOS/Quick.framework/Modules/Quick.swiftmodule/i386.swiftmodule deleted file mode 100644 index 58e01c46..00000000 Binary files a/Carthage/Build/iOS/Quick.framework/Modules/Quick.swiftmodule/i386.swiftmodule and /dev/null differ diff --git a/Carthage/Build/iOS/Quick.framework/Modules/Quick.swiftmodule/x86_64.swiftdoc b/Carthage/Build/iOS/Quick.framework/Modules/Quick.swiftmodule/x86_64.swiftdoc deleted file mode 100644 index c5b910f7..00000000 Binary files a/Carthage/Build/iOS/Quick.framework/Modules/Quick.swiftmodule/x86_64.swiftdoc and /dev/null differ diff --git a/Carthage/Build/iOS/Quick.framework/Modules/Quick.swiftmodule/x86_64.swiftmodule b/Carthage/Build/iOS/Quick.framework/Modules/Quick.swiftmodule/x86_64.swiftmodule deleted file mode 100644 index 258be058..00000000 Binary files a/Carthage/Build/iOS/Quick.framework/Modules/Quick.swiftmodule/x86_64.swiftmodule and /dev/null differ diff --git a/Carthage/Build/iOS/Quick.framework/Modules/module.modulemap b/Carthage/Build/iOS/Quick.framework/Modules/module.modulemap deleted file mode 100644 index 093a3923..00000000 --- a/Carthage/Build/iOS/Quick.framework/Modules/module.modulemap +++ /dev/null @@ -1,11 +0,0 @@ -framework module Quick { - umbrella header "Quick.h" - - export * - module * { export * } -} - -module Quick.Swift { - header "Quick-Swift.h" - requires objc -} diff --git a/Carthage/Build/iOS/Quick.framework/Quick b/Carthage/Build/iOS/Quick.framework/Quick deleted file mode 100755 index dd22d294..00000000 Binary files a/Carthage/Build/iOS/Quick.framework/Quick and /dev/null differ diff --git a/Example/FlexLayoutSample/Assets.xcassets/AppIcon.appiconset/Contents.json b/Example/FlexLayoutSample/Assets.xcassets/AppIcon.appiconset/Contents.json index 36d2c80d..99174b99 100644 --- a/Example/FlexLayoutSample/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/Example/FlexLayoutSample/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -2,67 +2,92 @@ "images" : [ { "idiom" : "iphone", - "size" : "29x29", - "scale" : "2x" + "scale" : "2x", + "size" : "20x20" }, { "idiom" : "iphone", - "size" : "29x29", - "scale" : "3x" + "scale" : "3x", + "size" : "20x20" }, { "idiom" : "iphone", - "size" : "40x40", - "scale" : "2x" + "scale" : "2x", + "size" : "29x29" }, { "idiom" : "iphone", - "size" : "40x40", - "scale" : "3x" + "scale" : "3x", + "size" : "29x29" }, { "idiom" : "iphone", - "size" : "60x60", - "scale" : "2x" + "scale" : "2x", + "size" : "40x40" }, { "idiom" : "iphone", - "size" : "60x60", - "scale" : "3x" + "scale" : "3x", + "size" : "40x40" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "60x60" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "60x60" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "20x20" }, { "idiom" : "ipad", - "size" : "29x29", - "scale" : "1x" + "scale" : "1x", + "size" : "29x29" }, { "idiom" : "ipad", - "size" : "29x29", - "scale" : "2x" + "scale" : "2x", + "size" : "29x29" }, { "idiom" : "ipad", - "size" : "40x40", - "scale" : "1x" + "scale" : "1x", + "size" : "40x40" }, { "idiom" : "ipad", - "size" : "40x40", - "scale" : "2x" + "scale" : "2x", + "size" : "40x40" }, { "idiom" : "ipad", - "size" : "76x76", - "scale" : "1x" + "scale" : "1x", + "size" : "76x76" }, { "idiom" : "ipad", - "size" : "76x76", - "scale" : "2x" + "scale" : "2x", + "size" : "76x76" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "83.5x83.5" + }, + { + "idiom" : "ios-marketing", + "scale" : "1x", + "size" : "1024x1024" } ], "info" : { - "version" : 1, - "author" : "xcode" + "author" : "xcode", + "version" : 1 } -} \ No newline at end of file +} diff --git a/Example/FlexLayoutSample/UI/Examples/CollectionViewExample/CollectionViewExampleView.swift b/Example/FlexLayoutSample/UI/Examples/CollectionViewExample/CollectionViewExampleView.swift index 6589811a..fc5c01c3 100644 --- a/Example/FlexLayoutSample/UI/Examples/CollectionViewExample/CollectionViewExampleView.swift +++ b/Example/FlexLayoutSample/UI/Examples/CollectionViewExample/CollectionViewExampleView.swift @@ -18,7 +18,6 @@ class CollectionViewExampleView: UIView { fileprivate let collectionView: UICollectionView fileprivate let flowLayout = UICollectionViewFlowLayout() - fileprivate let cellTemplate = HouseCell() fileprivate var houses: [House] = [] @@ -29,6 +28,7 @@ class CollectionViewExampleView: UIView { flowLayout.minimumLineSpacing = 8 flowLayout.minimumInteritemSpacing = 0 + flowLayout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize if #available(iOS 11.0, *) { flowLayout.sectionInsetReference = .fromSafeArea @@ -71,9 +71,9 @@ extension CollectionViewExampleView: UICollectionViewDelegateFlowLayout, UIColle cell.configure(house: houses[indexPath.row]) return cell } - + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { - cellTemplate.configure(house: houses[indexPath.row]) - return cellTemplate.sizeThatFits(CGSize(width: collectionView.bounds.width, height: .greatestFiniteMagnitude)) + // The height is only an estimate. HouseCell computes its actual height in preferredLayoutAttributesFitting(_:). + return CGSize(width: collectionView.bounds.width, height: 120) } } diff --git a/Example/FlexLayoutSample/UI/Examples/CollectionViewExample/HouseCell.swift b/Example/FlexLayoutSample/UI/Examples/CollectionViewExample/HouseCell.swift index 741e8c7e..8d7c7fec 100644 --- a/Example/FlexLayoutSample/UI/Examples/CollectionViewExample/HouseCell.swift +++ b/Example/FlexLayoutSample/UI/Examples/CollectionViewExample/HouseCell.swift @@ -78,11 +78,16 @@ class HouseCell: UICollectionViewCell { layout() } + override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes { + let size = sizeThatFits(layoutAttributes.size) + layoutAttributes.size = size + return layoutAttributes + } + override func sizeThatFits(_ size: CGSize) -> CGSize { - contentView.pin.width(size.width) - layout() - return contentView.frame.size + return contentView.flex.sizeThatFits(size: CGSize(width: size.width, height: .nan)) } + private func layout() { contentView.flex.layout(mode: .adjustHeight) } diff --git a/Example/FlexLayoutSample/UI/Examples/RaywenderlichTutorial/RaywenderlichTutorialViewController.swift b/Example/FlexLayoutSample/UI/Examples/RaywenderlichTutorial/RaywenderlichTutorialViewController.swift index f27d456a..01dab375 100644 --- a/Example/FlexLayoutSample/UI/Examples/RaywenderlichTutorial/RaywenderlichTutorialViewController.swift +++ b/Example/FlexLayoutSample/UI/Examples/RaywenderlichTutorial/RaywenderlichTutorialViewController.swift @@ -22,12 +22,6 @@ class RayWenderlichTutorialViewController: BaseViewController { init(pageType: PageType) { super.init() title = pageType.text - - // This property is used only on iOS 7/8/9/10. See https://developer.apple.com/documentation/uikit/uiviewcontroller/1621372-automaticallyadjustsscrollviewin - if #available(iOS 11.0, *) { - } else { - automaticallyAdjustsScrollViewInsets = false - } } required init?(coder aDecoder: NSCoder) { diff --git a/Example/FlexLayoutSample/UI/Examples/TableViewExample/TableViewExampleView.swift b/Example/FlexLayoutSample/UI/Examples/TableViewExample/TableViewExampleView.swift index 7beac501..560c9ec0 100644 --- a/Example/FlexLayoutSample/UI/Examples/TableViewExample/TableViewExampleView.swift +++ b/Example/FlexLayoutSample/UI/Examples/TableViewExample/TableViewExampleView.swift @@ -17,7 +17,6 @@ import UIKit class TableViewExampleView: UIView { fileprivate let tableView = UITableView() - fileprivate let methodCellTemplate = MethodCell() fileprivate var methods: [Method] = [] diff --git a/Example/FlexLayoutSample/UI/Examples/YogaExampleF/YogaExampleFView.swift b/Example/FlexLayoutSample/UI/Examples/YogaExampleF/YogaExampleFView.swift index c6c406af..efb1927a 100644 --- a/Example/FlexLayoutSample/UI/Examples/YogaExampleF/YogaExampleFView.swift +++ b/Example/FlexLayoutSample/UI/Examples/YogaExampleF/YogaExampleFView.swift @@ -172,7 +172,7 @@ class YogaExampleFView: UIView { // Layout the flexbox container using PinLayout // NOTE: Could be also layouted by setting directly rootFlexContainer.frame - rootFlexContainer.pin.top(pin.safeArea).horizontally(pin.safeArea).height(300) + rootFlexContainer.pin.all(pin.safeArea) // Then let the flexbox container layout itself rootFlexContainer.flex.layout() diff --git a/Example/FlexLayoutSample/UI/Menu/MenuViewController.swift b/Example/FlexLayoutSample/UI/Menu/MenuViewController.swift index 9141edae..e68e0ec6 100644 --- a/Example/FlexLayoutSample/UI/Menu/MenuViewController.swift +++ b/Example/FlexLayoutSample/UI/Menu/MenuViewController.swift @@ -84,10 +84,6 @@ class MenuViewController: BaseViewController { mainView.delegate = self } -// override func viewDidAppear(_ animated: Bool) { -// super.viewDidAppear(true) -// didSelect(pageType: .collectionView) -// } } // MARK: MenuViewDelegate diff --git a/Example/SPM/FlexLayoutSample-SPM.xcodeproj/project.pbxproj b/Example/SPM/FlexLayoutSample-SPM.xcodeproj/project.pbxproj new file mode 100644 index 00000000..2fb2c88f --- /dev/null +++ b/Example/SPM/FlexLayoutSample-SPM.xcodeproj/project.pbxproj @@ -0,0 +1,701 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 60; + objects = { + +/* Begin PBXBuildFile section */ + 7173B6822ACC6DD600EB0092 /* FlexLayout in Frameworks */ = {isa = PBXBuildFile; productRef = 7173B6812ACC6DD600EB0092 /* FlexLayout */; }; + B9EA7C662409B7B5000D8E35 /* BaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 242AECDF1FA011630024E7C2 /* BaseViewController.swift */; }; + B9EA7C672409B7B5000D8E35 /* BasicView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 242AECE01FA011630024E7C2 /* BasicView.swift */; }; + B9EA7C682409B7B5000D8E35 /* Stylesheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 242AECE11FA011630024E7C2 /* Stylesheet.swift */; }; + B9EA7C692409B7B5000D8E35 /* UIImageView+Download.swift in Sources */ = {isa = PBXBuildFile; fileRef = 242AECE61FA0119F0024E7C2 /* UIImageView+Download.swift */; }; + B9EA7C6A2409B7B5000D8E35 /* MenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2439CC331E665BF6003326FB /* MenuView.swift */; }; + B9EA7C6B2409B7B5000D8E35 /* MenuViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2439CC341E665BF6003326FB /* MenuViewController.swift */; }; + B9EA7C6C2409B7C2000D8E35 /* YogaExampleEView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24875E681F1F92C000BB1C09 /* YogaExampleEView.swift */; }; + B9EA7C6D2409B7C2000D8E35 /* YogaExampleEViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24875E691F1F92C000BB1C09 /* YogaExampleEViewController.swift */; }; + B9EA7C6E2409B7C5000D8E35 /* YogaExampleDView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24875E641F1F92B500BB1C09 /* YogaExampleDView.swift */; }; + B9EA7C6F2409B7C5000D8E35 /* YogaExampleDViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24875E651F1F92B500BB1C09 /* YogaExampleDViewController.swift */; }; + B9EA7C702409B7C8000D8E35 /* YogaExampleCView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24875E601F1F929600BB1C09 /* YogaExampleCView.swift */; }; + B9EA7C712409B7C8000D8E35 /* YogaExampleCViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24875E621F1F92A100BB1C09 /* YogaExampleCViewController.swift */; }; + B9EA7C722409B7CB000D8E35 /* YogaExampleBView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF0E85291F1F749C00AB1956 /* YogaExampleBView.swift */; }; + B9EA7C732409B7CB000D8E35 /* YogaExampleBViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF0E852A1F1F749C00AB1956 /* YogaExampleBViewController.swift */; }; + B9EA7C742409B7CE000D8E35 /* YogaExampleAView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF91747D1F1F6F9A0034632D /* YogaExampleAView.swift */; }; + B9EA7C752409B7CE000D8E35 /* YogaExampleAViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF91747E1F1F6F9A0034632D /* YogaExampleAViewController.swift */; }; + B9EA7C762409B7D0000D8E35 /* Example1View.swift in Sources */ = {isa = PBXBuildFile; fileRef = 247D73431F6757B00001AE2C /* Example1View.swift */; }; + B9EA7C772409B7D0000D8E35 /* Example1ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 247D73441F6757B00001AE2C /* Example1ViewController.swift */; }; + B9EA7C782409B7D3000D8E35 /* MethodCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FB883F1F59CA9A00615D33 /* MethodCell.swift */; }; + B9EA7C792409B7D3000D8E35 /* MethodGroupHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FB88401F59CA9A00615D33 /* MethodGroupHeader.swift */; }; + B9EA7C7A2409B7D3000D8E35 /* TableViewExampleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FB883B1F59CA8B00615D33 /* TableViewExampleView.swift */; }; + B9EA7C7B2409B7D3000D8E35 /* TableViewExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FB883C1F59CA8B00615D33 /* TableViewExampleViewController.swift */; }; + B9EA7C7C2409B7D7000D8E35 /* HouseCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2461068B1FA007B20038165C /* HouseCell.swift */; }; + B9EA7C7D2409B7D7000D8E35 /* CollectionViewExampleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24901F081F93D40F0025D11B /* CollectionViewExampleView.swift */; }; + B9EA7C7E2409B7D7000D8E35 /* CollectionViewExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24901F091F93D40F0025D11B /* CollectionViewExampleViewController.swift */; }; + B9EA7C7F2409B7DB000D8E35 /* ExpandedTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24AADD4A1F4E177700CB77E6 /* ExpandedTableView.swift */; }; + B9EA7C802409B7DB000D8E35 /* ShowTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24AADD491F4E177700CB77E6 /* ShowTableViewCell.swift */; }; + B9EA7C812409B7DB000D8E35 /* RaywenderlichTutorialView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24E835141F4CC336009F95CC /* RaywenderlichTutorialView.swift */; }; + B9EA7C822409B7DB000D8E35 /* RaywenderlichTutorialViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24E835151F4CC336009F95CC /* RaywenderlichTutorialViewController.swift */; }; + B9EA7C832409B7E0000D8E35 /* Shows.plist in Resources */ = {isa = PBXBuildFile; fileRef = 24AADD471F4E176A00CB77E6 /* Shows.plist */; }; + B9EA7C842409B7E2000D8E35 /* Show.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24C0F20F1F4EE9B20050BEE7 /* Show.swift */; }; + B9EA7C852409B7E7000D8E35 /* IntroView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24B14C591F278CCE00C90490 /* IntroView.swift */; }; + B9EA7C862409B7E7000D8E35 /* IntroViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24B14C5A1F278CCE00C90490 /* IntroViewController.swift */; }; + B9EA7C922409BAE1000D8E35 /* PinLayout in Frameworks */ = {isa = PBXBuildFile; productRef = B9EA7C912409BAE1000D8E35 /* PinLayout */; }; + B9EA7C932409BB0C000D8E35 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 249EFE491E64FAFE00165E39 /* Assets.xcassets */; }; + B9EA7C942409BB13000D8E35 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 249EFE4B1E64FAFE00165E39 /* LaunchScreen.storyboard */; }; + B9EA7C952409BB30000D8E35 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 249EFE421E64FAFE00165E39 /* AppDelegate.swift */; }; + DA9F7723277329C600FC4DF1 /* YogaExampleFViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60BAE157247DF4CE0020119C /* YogaExampleFViewController.swift */; }; + DA9F7724277329D000FC4DF1 /* YogaExampleFView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60BAE155247DF4120020119C /* YogaExampleFView.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 242AECDF1FA011630024E7C2 /* BaseViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseViewController.swift; sourceTree = ""; }; + 242AECE01FA011630024E7C2 /* BasicView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicView.swift; sourceTree = ""; }; + 242AECE11FA011630024E7C2 /* Stylesheet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Stylesheet.swift; sourceTree = ""; }; + 242AECE61FA0119F0024E7C2 /* UIImageView+Download.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImageView+Download.swift"; sourceTree = ""; }; + 2439CC331E665BF6003326FB /* MenuView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenuView.swift; sourceTree = ""; }; + 2439CC341E665BF6003326FB /* MenuViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenuViewController.swift; sourceTree = ""; }; + 2461068B1FA007B20038165C /* HouseCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HouseCell.swift; sourceTree = ""; }; + 247D73431F6757B00001AE2C /* Example1View.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Example1View.swift; path = Example1/Example1View.swift; sourceTree = ""; }; + 247D73441F6757B00001AE2C /* Example1ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Example1ViewController.swift; path = Example1/Example1ViewController.swift; sourceTree = ""; }; + 24875E601F1F929600BB1C09 /* YogaExampleCView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YogaExampleCView.swift; sourceTree = ""; }; + 24875E621F1F92A100BB1C09 /* YogaExampleCViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YogaExampleCViewController.swift; sourceTree = ""; }; + 24875E641F1F92B500BB1C09 /* YogaExampleDView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YogaExampleDView.swift; sourceTree = ""; }; + 24875E651F1F92B500BB1C09 /* YogaExampleDViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YogaExampleDViewController.swift; sourceTree = ""; }; + 24875E681F1F92C000BB1C09 /* YogaExampleEView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YogaExampleEView.swift; sourceTree = ""; }; + 24875E691F1F92C000BB1C09 /* YogaExampleEViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YogaExampleEViewController.swift; sourceTree = ""; }; + 24901F081F93D40F0025D11B /* CollectionViewExampleView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionViewExampleView.swift; sourceTree = ""; }; + 24901F091F93D40F0025D11B /* CollectionViewExampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionViewExampleViewController.swift; sourceTree = ""; }; + 249EFE421E64FAFE00165E39 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 249EFE491E64FAFE00165E39 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 249EFE4C1E64FAFE00165E39 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 249EFE4E1E64FAFE00165E39 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 24AADD471F4E176A00CB77E6 /* Shows.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Shows.plist; sourceTree = ""; }; + 24AADD491F4E177700CB77E6 /* ShowTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShowTableViewCell.swift; sourceTree = ""; }; + 24AADD4A1F4E177700CB77E6 /* ExpandedTableView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExpandedTableView.swift; sourceTree = ""; }; + 24B14C591F278CCE00C90490 /* IntroView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IntroView.swift; sourceTree = ""; }; + 24B14C5A1F278CCE00C90490 /* IntroViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IntroViewController.swift; sourceTree = ""; }; + 24C0F20F1F4EE9B20050BEE7 /* Show.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Show.swift; sourceTree = ""; }; + 24E835141F4CC336009F95CC /* RaywenderlichTutorialView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RaywenderlichTutorialView.swift; sourceTree = ""; }; + 24E835151F4CC336009F95CC /* RaywenderlichTutorialViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RaywenderlichTutorialViewController.swift; sourceTree = ""; }; + 24FB883B1F59CA8B00615D33 /* TableViewExampleView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewExampleView.swift; sourceTree = ""; }; + 24FB883C1F59CA8B00615D33 /* TableViewExampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewExampleViewController.swift; sourceTree = ""; }; + 24FB883F1F59CA9A00615D33 /* MethodCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MethodCell.swift; sourceTree = ""; }; + 24FB88401F59CA9A00615D33 /* MethodGroupHeader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MethodGroupHeader.swift; sourceTree = ""; }; + 60BAE155247DF4120020119C /* YogaExampleFView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YogaExampleFView.swift; sourceTree = ""; }; + 60BAE157247DF4CE0020119C /* YogaExampleFViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YogaExampleFViewController.swift; sourceTree = ""; }; + B9EA7C522409B79B000D8E35 /* FlexLayoutSample-SPM.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "FlexLayoutSample-SPM.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + DF0E85291F1F749C00AB1956 /* YogaExampleBView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YogaExampleBView.swift; sourceTree = ""; }; + DF0E852A1F1F749C00AB1956 /* YogaExampleBViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YogaExampleBViewController.swift; sourceTree = ""; }; + DF91747D1F1F6F9A0034632D /* YogaExampleAView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YogaExampleAView.swift; sourceTree = ""; }; + DF91747E1F1F6F9A0034632D /* YogaExampleAViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YogaExampleAViewController.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + B9EA7C4F2409B79B000D8E35 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + B9EA7C922409BAE1000D8E35 /* PinLayout in Frameworks */, + 7173B6822ACC6DD600EB0092 /* FlexLayout in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 242AECDD1FA011630024E7C2 /* Common */ = { + isa = PBXGroup; + children = ( + 242AECDF1FA011630024E7C2 /* BaseViewController.swift */, + 242AECE01FA011630024E7C2 /* BasicView.swift */, + 242AECE11FA011630024E7C2 /* Stylesheet.swift */, + 242AECE61FA0119F0024E7C2 /* UIImageView+Download.swift */, + ); + path = Common; + sourceTree = ""; + }; + 2439CC321E665BE3003326FB /* UI */ = { + isa = PBXGroup; + children = ( + 242AECDD1FA011630024E7C2 /* Common */, + 2439CC661E666128003326FB /* Menu */, + 2439CC371E665C5E003326FB /* Examples */, + ); + path = UI; + sourceTree = ""; + }; + 2439CC371E665C5E003326FB /* Examples */ = { + isa = PBXGroup; + children = ( + 24901F071F93D40F0025D11B /* CollectionViewExample */, + 247D73421F6757A00001AE2C /* Example1 */, + 24B14C581F278CB400C90490 /* Intro */, + 24E835131F4CC323009F95CC /* RaywenderlichTutorial */, + 24FB883A1F59CA7800615D33 /* TableViewExample */, + DF91747C1F1F6F8B0034632D /* YogaExampleA */, + DF0E85281F1F742C00AB1956 /* YogaExampleB */, + 24CD0D121F1F8D1100D56FC3 /* YogaExampleC */, + 24CD0D171F1F8E3D00D56FC3 /* YogaExampleD */, + 24CD0D1C1F1F90AF00D56FC3 /* YogaExampleE */, + 60BAE154247DF3F40020119C /* YogaExampleF */, + ); + path = Examples; + sourceTree = ""; + }; + 2439CC661E666128003326FB /* Menu */ = { + isa = PBXGroup; + children = ( + 2439CC331E665BF6003326FB /* MenuView.swift */, + 2439CC341E665BF6003326FB /* MenuViewController.swift */, + ); + path = Menu; + sourceTree = ""; + }; + 2439CC671E66614D003326FB /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 249EFE491E64FAFE00165E39 /* Assets.xcassets */, + 249EFE4E1E64FAFE00165E39 /* Info.plist */, + 249EFE4B1E64FAFE00165E39 /* LaunchScreen.storyboard */, + ); + path = "Supporting Files"; + sourceTree = ""; + }; + 247D73421F6757A00001AE2C /* Example1 */ = { + isa = PBXGroup; + children = ( + 247D73431F6757B00001AE2C /* Example1View.swift */, + 247D73441F6757B00001AE2C /* Example1ViewController.swift */, + ); + name = Example1; + sourceTree = ""; + }; + 24901F071F93D40F0025D11B /* CollectionViewExample */ = { + isa = PBXGroup; + children = ( + 2461068B1FA007B20038165C /* HouseCell.swift */, + 24901F081F93D40F0025D11B /* CollectionViewExampleView.swift */, + 24901F091F93D40F0025D11B /* CollectionViewExampleViewController.swift */, + ); + path = CollectionViewExample; + sourceTree = ""; + }; + 249EFE361E64FAFE00165E39 = { + isa = PBXGroup; + children = ( + 249EFE411E64FAFE00165E39 /* ../FlexLayoutSample */, + 249EFE401E64FAFE00165E39 /* Products */, + ); + sourceTree = ""; + }; + 249EFE401E64FAFE00165E39 /* Products */ = { + isa = PBXGroup; + children = ( + B9EA7C522409B79B000D8E35 /* FlexLayoutSample-SPM.app */, + ); + name = Products; + sourceTree = ""; + }; + 249EFE411E64FAFE00165E39 /* ../FlexLayoutSample */ = { + isa = PBXGroup; + children = ( + 2439CC321E665BE3003326FB /* UI */, + 2439CC671E66614D003326FB /* Supporting Files */, + 249EFE421E64FAFE00165E39 /* AppDelegate.swift */, + ); + path = ../FlexLayoutSample; + sourceTree = ""; + }; + 24AADD451F4E16ED00CB77E6 /* Subviews */ = { + isa = PBXGroup; + children = ( + 24AADD4A1F4E177700CB77E6 /* ExpandedTableView.swift */, + 24AADD491F4E177700CB77E6 /* ShowTableViewCell.swift */, + ); + path = Subviews; + sourceTree = ""; + }; + 24AADD461F4E173300CB77E6 /* Data */ = { + isa = PBXGroup; + children = ( + 24C0F20F1F4EE9B20050BEE7 /* Show.swift */, + 24AADD471F4E176A00CB77E6 /* Shows.plist */, + ); + path = Data; + sourceTree = ""; + }; + 24B14C581F278CB400C90490 /* Intro */ = { + isa = PBXGroup; + children = ( + 24B14C591F278CCE00C90490 /* IntroView.swift */, + 24B14C5A1F278CCE00C90490 /* IntroViewController.swift */, + ); + path = Intro; + sourceTree = ""; + }; + 24CD0D121F1F8D1100D56FC3 /* YogaExampleC */ = { + isa = PBXGroup; + children = ( + 24875E601F1F929600BB1C09 /* YogaExampleCView.swift */, + 24875E621F1F92A100BB1C09 /* YogaExampleCViewController.swift */, + ); + path = YogaExampleC; + sourceTree = ""; + }; + 24CD0D171F1F8E3D00D56FC3 /* YogaExampleD */ = { + isa = PBXGroup; + children = ( + 24875E641F1F92B500BB1C09 /* YogaExampleDView.swift */, + 24875E651F1F92B500BB1C09 /* YogaExampleDViewController.swift */, + ); + path = YogaExampleD; + sourceTree = ""; + }; + 24CD0D1C1F1F90AF00D56FC3 /* YogaExampleE */ = { + isa = PBXGroup; + children = ( + 24875E681F1F92C000BB1C09 /* YogaExampleEView.swift */, + 24875E691F1F92C000BB1C09 /* YogaExampleEViewController.swift */, + ); + path = YogaExampleE; + sourceTree = ""; + }; + 24E835131F4CC323009F95CC /* RaywenderlichTutorial */ = { + isa = PBXGroup; + children = ( + 24AADD461F4E173300CB77E6 /* Data */, + 24AADD451F4E16ED00CB77E6 /* Subviews */, + 24E835141F4CC336009F95CC /* RaywenderlichTutorialView.swift */, + 24E835151F4CC336009F95CC /* RaywenderlichTutorialViewController.swift */, + ); + path = RaywenderlichTutorial; + sourceTree = ""; + }; + 24FB883A1F59CA7800615D33 /* TableViewExample */ = { + isa = PBXGroup; + children = ( + 24FB88431F59CA9D00615D33 /* Subviews */, + 24FB883B1F59CA8B00615D33 /* TableViewExampleView.swift */, + 24FB883C1F59CA8B00615D33 /* TableViewExampleViewController.swift */, + ); + path = TableViewExample; + sourceTree = ""; + }; + 24FB88431F59CA9D00615D33 /* Subviews */ = { + isa = PBXGroup; + children = ( + 24FB883F1F59CA9A00615D33 /* MethodCell.swift */, + 24FB88401F59CA9A00615D33 /* MethodGroupHeader.swift */, + ); + path = Subviews; + sourceTree = ""; + }; + 60BAE154247DF3F40020119C /* YogaExampleF */ = { + isa = PBXGroup; + children = ( + 60BAE155247DF4120020119C /* YogaExampleFView.swift */, + 60BAE157247DF4CE0020119C /* YogaExampleFViewController.swift */, + ); + path = YogaExampleF; + sourceTree = ""; + }; + DF0E85281F1F742C00AB1956 /* YogaExampleB */ = { + isa = PBXGroup; + children = ( + DF0E85291F1F749C00AB1956 /* YogaExampleBView.swift */, + DF0E852A1F1F749C00AB1956 /* YogaExampleBViewController.swift */, + ); + path = YogaExampleB; + sourceTree = ""; + }; + DF91747C1F1F6F8B0034632D /* YogaExampleA */ = { + isa = PBXGroup; + children = ( + DF91747D1F1F6F9A0034632D /* YogaExampleAView.swift */, + DF91747E1F1F6F9A0034632D /* YogaExampleAViewController.swift */, + ); + path = YogaExampleA; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + B9EA7C512409B79B000D8E35 /* FlexLayoutSample-SPM */ = { + isa = PBXNativeTarget; + buildConfigurationList = B9EA7C652409B79C000D8E35 /* Build configuration list for PBXNativeTarget "FlexLayoutSample-SPM" */; + buildPhases = ( + B9EA7C4E2409B79B000D8E35 /* Sources */, + B9EA7C4F2409B79B000D8E35 /* Frameworks */, + B9EA7C502409B79B000D8E35 /* Resources */, + DF940B122B28A93B003CB6D5 /* Run Swiftlint */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "FlexLayoutSample-SPM"; + packageProductDependencies = ( + B9EA7C912409BAE1000D8E35 /* PinLayout */, + 7173B6812ACC6DD600EB0092 /* FlexLayout */, + ); + productName = FlexLayoutSampleSPM; + productReference = B9EA7C522409B79B000D8E35 /* FlexLayoutSample-SPM.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 249EFE371E64FAFE00165E39 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = YES; + LastSwiftUpdateCheck = 1130; + LastUpgradeCheck = 1510; + ORGANIZATIONNAME = Mirego; + TargetAttributes = { + B9EA7C512409B79B000D8E35 = { + CreatedOnToolsVersion = 11.3.1; + }; + }; + }; + buildConfigurationList = 249EFE3A1E64FAFE00165E39 /* Build configuration list for PBXProject "FlexLayoutSample-SPM" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 249EFE361E64FAFE00165E39; + packageReferences = ( + B9EA7C902409BAE1000D8E35 /* XCRemoteSwiftPackageReference "PinLayout" */, + DF940B112B28A875003CB6D5 /* XCLocalSwiftPackageReference "../.." */, + ); + productRefGroup = 249EFE401E64FAFE00165E39 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + B9EA7C512409B79B000D8E35 /* FlexLayoutSample-SPM */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + B9EA7C502409B79B000D8E35 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + B9EA7C942409BB13000D8E35 /* LaunchScreen.storyboard in Resources */, + B9EA7C932409BB0C000D8E35 /* Assets.xcassets in Resources */, + B9EA7C832409B7E0000D8E35 /* Shows.plist in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + DF940B122B28A93B003CB6D5 /* Run Swiftlint */ = { + isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = "Run Swiftlint"; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "../../Pods/SwiftLint/swiftlint ../FlexLayoutSample\n"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + B9EA7C4E2409B79B000D8E35 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + B9EA7C952409BB30000D8E35 /* AppDelegate.swift in Sources */, + B9EA7C702409B7C8000D8E35 /* YogaExampleCView.swift in Sources */, + B9EA7C6F2409B7C5000D8E35 /* YogaExampleDViewController.swift in Sources */, + B9EA7C7E2409B7D7000D8E35 /* CollectionViewExampleViewController.swift in Sources */, + DA9F7724277329D000FC4DF1 /* YogaExampleFView.swift in Sources */, + B9EA7C762409B7D0000D8E35 /* Example1View.swift in Sources */, + B9EA7C742409B7CE000D8E35 /* YogaExampleAView.swift in Sources */, + DA9F7723277329C600FC4DF1 /* YogaExampleFViewController.swift in Sources */, + B9EA7C712409B7C8000D8E35 /* YogaExampleCViewController.swift in Sources */, + B9EA7C7F2409B7DB000D8E35 /* ExpandedTableView.swift in Sources */, + B9EA7C6A2409B7B5000D8E35 /* MenuView.swift in Sources */, + B9EA7C6B2409B7B5000D8E35 /* MenuViewController.swift in Sources */, + B9EA7C782409B7D3000D8E35 /* MethodCell.swift in Sources */, + B9EA7C7D2409B7D7000D8E35 /* CollectionViewExampleView.swift in Sources */, + B9EA7C692409B7B5000D8E35 /* UIImageView+Download.swift in Sources */, + B9EA7C722409B7CB000D8E35 /* YogaExampleBView.swift in Sources */, + B9EA7C6E2409B7C5000D8E35 /* YogaExampleDView.swift in Sources */, + B9EA7C822409B7DB000D8E35 /* RaywenderlichTutorialViewController.swift in Sources */, + B9EA7C662409B7B5000D8E35 /* BaseViewController.swift in Sources */, + B9EA7C802409B7DB000D8E35 /* ShowTableViewCell.swift in Sources */, + B9EA7C7C2409B7D7000D8E35 /* HouseCell.swift in Sources */, + B9EA7C842409B7E2000D8E35 /* Show.swift in Sources */, + B9EA7C672409B7B5000D8E35 /* BasicView.swift in Sources */, + B9EA7C792409B7D3000D8E35 /* MethodGroupHeader.swift in Sources */, + B9EA7C732409B7CB000D8E35 /* YogaExampleBViewController.swift in Sources */, + B9EA7C6C2409B7C2000D8E35 /* YogaExampleEView.swift in Sources */, + B9EA7C6D2409B7C2000D8E35 /* YogaExampleEViewController.swift in Sources */, + B9EA7C852409B7E7000D8E35 /* IntroView.swift in Sources */, + B9EA7C7B2409B7D3000D8E35 /* TableViewExampleViewController.swift in Sources */, + B9EA7C752409B7CE000D8E35 /* YogaExampleAViewController.swift in Sources */, + B9EA7C7A2409B7D3000D8E35 /* TableViewExampleView.swift in Sources */, + B9EA7C682409B7B5000D8E35 /* Stylesheet.swift in Sources */, + B9EA7C812409B7DB000D8E35 /* RaywenderlichTutorialView.swift in Sources */, + B9EA7C772409B7D0000D8E35 /* Example1ViewController.swift in Sources */, + B9EA7C862409B7E7000D8E35 /* IntroViewController.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 249EFE4B1E64FAFE00165E39 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 249EFE4C1E64FAFE00165E39 /* Base */, + ); + name = LaunchScreen.storyboard; + path = .; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 249EFE651E64FAFE00165E39 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; + 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_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = 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_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = 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; + ENABLE_USER_SCRIPT_SANDBOXING = 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 = 12.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_SWIFT3_OBJC_INFERENCE = Off; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 249EFE661E64FAFE00165E39 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; + 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_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = 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_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = 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; + ENABLE_USER_SCRIPT_SANDBOXING = 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 = 12.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + SWIFT_SWIFT3_OBJC_INFERENCE = Off; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + B9EA7C632409B79C000D8E35 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CODE_SIGN_STYLE = Automatic; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + INFOPLIST_FILE = "../FlexLayoutSample/Supporting Files/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + PRODUCT_BUNDLE_IDENTIFIER = com.lucdion.FlexLayoutSampleSPM; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + B9EA7C642409B79C000D8E35 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = "../FlexLayoutSample/Supporting Files/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MTL_FAST_MATH = YES; + PRODUCT_BUNDLE_IDENTIFIER = com.lucdion.FlexLayoutSampleSPM; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 249EFE3A1E64FAFE00165E39 /* Build configuration list for PBXProject "FlexLayoutSample-SPM" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 249EFE651E64FAFE00165E39 /* Debug */, + 249EFE661E64FAFE00165E39 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + B9EA7C652409B79C000D8E35 /* Build configuration list for PBXNativeTarget "FlexLayoutSample-SPM" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + B9EA7C632409B79C000D8E35 /* Debug */, + B9EA7C642409B79C000D8E35 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + +/* Begin XCLocalSwiftPackageReference section */ + DF940B112B28A875003CB6D5 /* XCLocalSwiftPackageReference "../.." */ = { + isa = XCLocalSwiftPackageReference; + relativePath = ../..; + }; +/* End XCLocalSwiftPackageReference section */ + +/* Begin XCRemoteSwiftPackageReference section */ + B9EA7C902409BAE1000D8E35 /* XCRemoteSwiftPackageReference "PinLayout" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/layoutBox/PinLayout.git"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 1.8.13; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + 7173B6812ACC6DD600EB0092 /* FlexLayout */ = { + isa = XCSwiftPackageProductDependency; + productName = FlexLayout; + }; + B9EA7C912409BAE1000D8E35 /* PinLayout */ = { + isa = XCSwiftPackageProductDependency; + package = B9EA7C902409BAE1000D8E35 /* XCRemoteSwiftPackageReference "PinLayout" */; + productName = PinLayout; + }; +/* End XCSwiftPackageProductDependency section */ + }; + rootObject = 249EFE371E64FAFE00165E39 /* Project object */; +} diff --git a/Example/SPM/FlexLayoutSample-SPM.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Example/SPM/FlexLayoutSample-SPM.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..919434a6 --- /dev/null +++ b/Example/SPM/FlexLayoutSample-SPM.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Example/SPM/FlexLayoutSample-SPM.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Example/SPM/FlexLayoutSample-SPM.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/Example/SPM/FlexLayoutSample-SPM.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Example/SPM/FlexLayoutSample-SPM.xcodeproj/xcshareddata/xcschemes/FlexLayoutSample-SPM.xcscheme b/Example/SPM/FlexLayoutSample-SPM.xcodeproj/xcshareddata/xcschemes/FlexLayoutSample-SPM.xcscheme new file mode 100644 index 00000000..2cea8906 --- /dev/null +++ b/Example/SPM/FlexLayoutSample-SPM.xcodeproj/xcshareddata/xcschemes/FlexLayoutSample-SPM.xcscheme @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Example/FlexLayoutSample.xcodeproj/project.pbxproj b/Example/cocoapods/FlexLayoutSample.xcodeproj/project.pbxproj similarity index 67% rename from Example/FlexLayoutSample.xcodeproj/project.pbxproj rename to Example/cocoapods/FlexLayoutSample.xcodeproj/project.pbxproj index 70682916..d7bf484e 100644 --- a/Example/FlexLayoutSample.xcodeproj/project.pbxproj +++ b/Example/cocoapods/FlexLayoutSample.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 52; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -37,48 +37,6 @@ 24FB88421F59CA9A00615D33 /* MethodGroupHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FB88401F59CA9A00615D33 /* MethodGroupHeader.swift */; }; 60BAE156247DF4120020119C /* YogaExampleFView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60BAE155247DF4120020119C /* YogaExampleFView.swift */; }; 60BAE158247DF4CE0020119C /* YogaExampleFViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60BAE157247DF4CE0020119C /* YogaExampleFViewController.swift */; }; - B9BDD93E240A70C3005298B3 /* FlexLayout in Frameworks */ = {isa = PBXBuildFile; productRef = B9BDD93D240A70C3005298B3 /* FlexLayout */; }; - B9BDD940240A70C3005298B3 /* FlexLayoutYoga in Frameworks */ = {isa = PBXBuildFile; productRef = B9BDD93F240A70C3005298B3 /* FlexLayoutYoga */; }; - B9BDD942240A70C3005298B3 /* FlexLayoutYogaKit in Frameworks */ = {isa = PBXBuildFile; productRef = B9BDD941240A70C3005298B3 /* FlexLayoutYogaKit */; }; - B9EA7C662409B7B5000D8E35 /* BaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 242AECDF1FA011630024E7C2 /* BaseViewController.swift */; }; - B9EA7C672409B7B5000D8E35 /* BasicView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 242AECE01FA011630024E7C2 /* BasicView.swift */; }; - B9EA7C682409B7B5000D8E35 /* Stylesheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 242AECE11FA011630024E7C2 /* Stylesheet.swift */; }; - B9EA7C692409B7B5000D8E35 /* UIImageView+Download.swift in Sources */ = {isa = PBXBuildFile; fileRef = 242AECE61FA0119F0024E7C2 /* UIImageView+Download.swift */; }; - B9EA7C6A2409B7B5000D8E35 /* MenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2439CC331E665BF6003326FB /* MenuView.swift */; }; - B9EA7C6B2409B7B5000D8E35 /* MenuViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2439CC341E665BF6003326FB /* MenuViewController.swift */; }; - B9EA7C6C2409B7C2000D8E35 /* YogaExampleEView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24875E681F1F92C000BB1C09 /* YogaExampleEView.swift */; }; - B9EA7C6D2409B7C2000D8E35 /* YogaExampleEViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24875E691F1F92C000BB1C09 /* YogaExampleEViewController.swift */; }; - B9EA7C6E2409B7C5000D8E35 /* YogaExampleDView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24875E641F1F92B500BB1C09 /* YogaExampleDView.swift */; }; - B9EA7C6F2409B7C5000D8E35 /* YogaExampleDViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24875E651F1F92B500BB1C09 /* YogaExampleDViewController.swift */; }; - B9EA7C702409B7C8000D8E35 /* YogaExampleCView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24875E601F1F929600BB1C09 /* YogaExampleCView.swift */; }; - B9EA7C712409B7C8000D8E35 /* YogaExampleCViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24875E621F1F92A100BB1C09 /* YogaExampleCViewController.swift */; }; - B9EA7C722409B7CB000D8E35 /* YogaExampleBView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF0E85291F1F749C00AB1956 /* YogaExampleBView.swift */; }; - B9EA7C732409B7CB000D8E35 /* YogaExampleBViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF0E852A1F1F749C00AB1956 /* YogaExampleBViewController.swift */; }; - B9EA7C742409B7CE000D8E35 /* YogaExampleAView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF91747D1F1F6F9A0034632D /* YogaExampleAView.swift */; }; - B9EA7C752409B7CE000D8E35 /* YogaExampleAViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF91747E1F1F6F9A0034632D /* YogaExampleAViewController.swift */; }; - B9EA7C762409B7D0000D8E35 /* Example1View.swift in Sources */ = {isa = PBXBuildFile; fileRef = 247D73431F6757B00001AE2C /* Example1View.swift */; }; - B9EA7C772409B7D0000D8E35 /* Example1ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 247D73441F6757B00001AE2C /* Example1ViewController.swift */; }; - B9EA7C782409B7D3000D8E35 /* MethodCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FB883F1F59CA9A00615D33 /* MethodCell.swift */; }; - B9EA7C792409B7D3000D8E35 /* MethodGroupHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FB88401F59CA9A00615D33 /* MethodGroupHeader.swift */; }; - B9EA7C7A2409B7D3000D8E35 /* TableViewExampleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FB883B1F59CA8B00615D33 /* TableViewExampleView.swift */; }; - B9EA7C7B2409B7D3000D8E35 /* TableViewExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FB883C1F59CA8B00615D33 /* TableViewExampleViewController.swift */; }; - B9EA7C7C2409B7D7000D8E35 /* HouseCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2461068B1FA007B20038165C /* HouseCell.swift */; }; - B9EA7C7D2409B7D7000D8E35 /* CollectionViewExampleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24901F081F93D40F0025D11B /* CollectionViewExampleView.swift */; }; - B9EA7C7E2409B7D7000D8E35 /* CollectionViewExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24901F091F93D40F0025D11B /* CollectionViewExampleViewController.swift */; }; - B9EA7C7F2409B7DB000D8E35 /* ExpandedTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24AADD4A1F4E177700CB77E6 /* ExpandedTableView.swift */; }; - B9EA7C802409B7DB000D8E35 /* ShowTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24AADD491F4E177700CB77E6 /* ShowTableViewCell.swift */; }; - B9EA7C812409B7DB000D8E35 /* RaywenderlichTutorialView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24E835141F4CC336009F95CC /* RaywenderlichTutorialView.swift */; }; - B9EA7C822409B7DB000D8E35 /* RaywenderlichTutorialViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24E835151F4CC336009F95CC /* RaywenderlichTutorialViewController.swift */; }; - B9EA7C832409B7E0000D8E35 /* Shows.plist in Resources */ = {isa = PBXBuildFile; fileRef = 24AADD471F4E176A00CB77E6 /* Shows.plist */; }; - B9EA7C842409B7E2000D8E35 /* Show.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24C0F20F1F4EE9B20050BEE7 /* Show.swift */; }; - B9EA7C852409B7E7000D8E35 /* IntroView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24B14C591F278CCE00C90490 /* IntroView.swift */; }; - B9EA7C862409B7E7000D8E35 /* IntroViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24B14C5A1F278CCE00C90490 /* IntroViewController.swift */; }; - B9EA7C922409BAE1000D8E35 /* PinLayout in Frameworks */ = {isa = PBXBuildFile; productRef = B9EA7C912409BAE1000D8E35 /* PinLayout */; }; - B9EA7C932409BB0C000D8E35 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 249EFE491E64FAFE00165E39 /* Assets.xcassets */; }; - B9EA7C942409BB13000D8E35 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 249EFE4B1E64FAFE00165E39 /* LaunchScreen.storyboard */; }; - B9EA7C952409BB30000D8E35 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 249EFE421E64FAFE00165E39 /* AppDelegate.swift */; }; - DA9F7723277329C600FC4DF1 /* YogaExampleFViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60BAE157247DF4CE0020119C /* YogaExampleFViewController.swift */; }; - DA9F7724277329D000FC4DF1 /* YogaExampleFView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60BAE155247DF4120020119C /* YogaExampleFView.swift */; }; DF0E852B1F1F749C00AB1956 /* YogaExampleBView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF0E85291F1F749C00AB1956 /* YogaExampleBView.swift */; }; DF0E852C1F1F749C00AB1956 /* YogaExampleBViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF0E852A1F1F749C00AB1956 /* YogaExampleBViewController.swift */; }; DF1F2A091F17D11700BA1B97 /* MenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2439CC331E665BF6003326FB /* MenuView.swift */; }; @@ -104,7 +62,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 0D0595B5E0950936D037ECF2 /* Pods-FlexLayoutSample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FlexLayoutSample.release.xcconfig"; path = "../Pods/Target Support Files/Pods-FlexLayoutSample/Pods-FlexLayoutSample.release.xcconfig"; sourceTree = ""; }; + 0D0595B5E0950936D037ECF2 /* Pods-FlexLayoutSample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FlexLayoutSample.release.xcconfig"; path = "../../Pods/Target Support Files/Pods-FlexLayoutSample/Pods-FlexLayoutSample.release.xcconfig"; sourceTree = ""; }; 242AECDF1FA011630024E7C2 /* BaseViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseViewController.swift; sourceTree = ""; }; 242AECE01FA011630024E7C2 /* BasicView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicView.swift; sourceTree = ""; }; 242AECE11FA011630024E7C2 /* Stylesheet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Stylesheet.swift; sourceTree = ""; }; @@ -141,9 +99,7 @@ 60BAE155247DF4120020119C /* YogaExampleFView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YogaExampleFView.swift; sourceTree = ""; }; 60BAE157247DF4CE0020119C /* YogaExampleFViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YogaExampleFViewController.swift; sourceTree = ""; }; 82FCE524E22C2FF5BC4DFBAB /* Pods_FlexLayoutSample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_FlexLayoutSample.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 8561ACDBCFFA1B4B9ABEAB16 /* Pods-FlexLayoutSample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FlexLayoutSample.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-FlexLayoutSample/Pods-FlexLayoutSample.debug.xcconfig"; sourceTree = ""; }; - B9EA7C522409B79B000D8E35 /* FlexLayoutSampleSPM.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FlexLayoutSampleSPM.app; sourceTree = BUILT_PRODUCTS_DIR; }; - B9EA7C96240A6C24000D8E35 /* FlexLayout */ = {isa = PBXFileReference; lastKnownFileType = folder; name = FlexLayout; path = ..; sourceTree = ""; }; + 8561ACDBCFFA1B4B9ABEAB16 /* Pods-FlexLayoutSample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FlexLayoutSample.debug.xcconfig"; path = "../../Pods/Target Support Files/Pods-FlexLayoutSample/Pods-FlexLayoutSample.debug.xcconfig"; sourceTree = ""; }; DF0E85291F1F749C00AB1956 /* YogaExampleBView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YogaExampleBView.swift; sourceTree = ""; }; DF0E852A1F1F749C00AB1956 /* YogaExampleBViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YogaExampleBViewController.swift; sourceTree = ""; }; DF1F2A221F17D11700BA1B97 /* FlexLayoutSample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FlexLayoutSample.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -152,17 +108,6 @@ /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ - B9EA7C4F2409B79B000D8E35 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - B9EA7C922409BAE1000D8E35 /* PinLayout in Frameworks */, - B9BDD93E240A70C3005298B3 /* FlexLayout in Frameworks */, - B9BDD942240A70C3005298B3 /* FlexLayoutYogaKit in Frameworks */, - B9BDD940240A70C3005298B3 /* FlexLayoutYoga in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; DF1F2A141F17D11700BA1B97 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -254,7 +199,6 @@ 249EFE361E64FAFE00165E39 = { isa = PBXGroup; children = ( - B9EA7C96240A6C24000D8E35 /* FlexLayout */, 249EFE411E64FAFE00165E39 /* FlexLayoutSample */, 461884C59B72ACEAFC912B8A /* Frameworks */, 85CAAE97812075333AF3E88F /* Pods */, @@ -266,7 +210,6 @@ isa = PBXGroup; children = ( DF1F2A221F17D11700BA1B97 /* FlexLayoutSample.app */, - B9EA7C522409B79B000D8E35 /* FlexLayoutSampleSPM.app */, ); name = Products; sourceTree = ""; @@ -278,7 +221,7 @@ 2439CC321E665BE3003326FB /* UI */, 249EFE421E64FAFE00165E39 /* AppDelegate.swift */, ); - path = FlexLayoutSample; + path = ../FlexLayoutSample; sourceTree = ""; }; 24AADD451F4E16ED00CB77E6 /* Subviews */ = { @@ -412,29 +355,6 @@ /* End PBXGroup section */ /* Begin PBXNativeTarget section */ - B9EA7C512409B79B000D8E35 /* FlexLayoutSampleSPM */ = { - isa = PBXNativeTarget; - buildConfigurationList = B9EA7C652409B79C000D8E35 /* Build configuration list for PBXNativeTarget "FlexLayoutSampleSPM" */; - buildPhases = ( - B9EA7C4E2409B79B000D8E35 /* Sources */, - B9EA7C4F2409B79B000D8E35 /* Frameworks */, - B9EA7C502409B79B000D8E35 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = FlexLayoutSampleSPM; - packageProductDependencies = ( - B9EA7C912409BAE1000D8E35 /* PinLayout */, - B9BDD93D240A70C3005298B3 /* FlexLayout */, - B9BDD93F240A70C3005298B3 /* FlexLayoutYoga */, - B9BDD941240A70C3005298B3 /* FlexLayoutYogaKit */, - ); - productName = FlexLayoutSampleSPM; - productReference = B9EA7C522409B79B000D8E35 /* FlexLayoutSampleSPM.app */; - productType = "com.apple.product-type.application"; - }; DF1F2A051F17D11700BA1B97 /* FlexLayoutSample */ = { isa = PBXNativeTarget; buildConfigurationList = DF1F2A1F1F17D11700BA1B97 /* Build configuration list for PBXNativeTarget "FlexLayoutSample" */; @@ -444,7 +364,6 @@ DF1F2A141F17D11700BA1B97 /* Frameworks */, DF1F2A181F17D11700BA1B97 /* Resources */, DF1F2A1B1F17D11700BA1B97 /* Embed Frameworks */, - DF1F2A1C1F17D11700BA1B97 /* [CP] Embed Pods Frameworks */, DF1F2A1E1F17D11700BA1B97 /* Run Swiftlint */, ); buildRules = ( @@ -462,13 +381,11 @@ 249EFE371E64FAFE00165E39 /* Project object */ = { isa = PBXProject; attributes = { + BuildIndependentTargetsInParallel = YES; LastSwiftUpdateCheck = 1130; - LastUpgradeCheck = 1250; + LastUpgradeCheck = 1510; ORGANIZATIONNAME = Mirego; TargetAttributes = { - B9EA7C512409B79B000D8E35 = { - CreatedOnToolsVersion = 11.3.1; - }; DF1F2A051F17D11700BA1B97 = { LastSwiftMigration = 1030; }; @@ -483,31 +400,16 @@ Base, ); mainGroup = 249EFE361E64FAFE00165E39; - packageReferences = ( - B9EA7C892409B986000D8E35 /* XCRemoteSwiftPackageReference "FlexLayout" */, - B9EA7C902409BAE1000D8E35 /* XCRemoteSwiftPackageReference "PinLayout" */, - ); productRefGroup = 249EFE401E64FAFE00165E39 /* Products */; projectDirPath = ""; projectRoot = ""; targets = ( DF1F2A051F17D11700BA1B97 /* FlexLayoutSample */, - B9EA7C512409B79B000D8E35 /* FlexLayoutSampleSPM */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ - B9EA7C502409B79B000D8E35 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - B9EA7C942409BB13000D8E35 /* LaunchScreen.storyboard in Resources */, - B9EA7C932409BB0C000D8E35 /* Assets.xcassets in Resources */, - B9EA7C832409B7E0000D8E35 /* Shows.plist in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; DF1F2A181F17D11700BA1B97 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -539,28 +441,9 @@ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; - DF1F2A1C1F17D11700BA1B97 /* [CP] Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-FlexLayoutSample/Pods-FlexLayoutSample-frameworks.sh", - "${BUILT_PRODUCTS_DIR}/FlexLayout/FlexLayout.framework", - "${BUILT_PRODUCTS_DIR}/PinLayout/PinLayout.framework", - ); - name = "[CP] Embed Pods Frameworks"; - outputPaths = ( - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FlexLayout.framework", - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PinLayout.framework", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-FlexLayoutSample/Pods-FlexLayoutSample-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; DF1F2A1E1F17D11700BA1B97 /* Run Swiftlint */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); @@ -571,53 +454,11 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = ../Pods/SwiftLint/swiftlint; + shellScript = "\"${PODS_ROOT}/SwiftLint/swiftlint\" --path ../FlexLayoutSample\n"; }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ - B9EA7C4E2409B79B000D8E35 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - B9EA7C952409BB30000D8E35 /* AppDelegate.swift in Sources */, - B9EA7C702409B7C8000D8E35 /* YogaExampleCView.swift in Sources */, - B9EA7C6F2409B7C5000D8E35 /* YogaExampleDViewController.swift in Sources */, - B9EA7C7E2409B7D7000D8E35 /* CollectionViewExampleViewController.swift in Sources */, - DA9F7724277329D000FC4DF1 /* YogaExampleFView.swift in Sources */, - B9EA7C762409B7D0000D8E35 /* Example1View.swift in Sources */, - B9EA7C742409B7CE000D8E35 /* YogaExampleAView.swift in Sources */, - DA9F7723277329C600FC4DF1 /* YogaExampleFViewController.swift in Sources */, - B9EA7C712409B7C8000D8E35 /* YogaExampleCViewController.swift in Sources */, - B9EA7C7F2409B7DB000D8E35 /* ExpandedTableView.swift in Sources */, - B9EA7C6A2409B7B5000D8E35 /* MenuView.swift in Sources */, - B9EA7C6B2409B7B5000D8E35 /* MenuViewController.swift in Sources */, - B9EA7C782409B7D3000D8E35 /* MethodCell.swift in Sources */, - B9EA7C7D2409B7D7000D8E35 /* CollectionViewExampleView.swift in Sources */, - B9EA7C692409B7B5000D8E35 /* UIImageView+Download.swift in Sources */, - B9EA7C722409B7CB000D8E35 /* YogaExampleBView.swift in Sources */, - B9EA7C6E2409B7C5000D8E35 /* YogaExampleDView.swift in Sources */, - B9EA7C822409B7DB000D8E35 /* RaywenderlichTutorialViewController.swift in Sources */, - B9EA7C662409B7B5000D8E35 /* BaseViewController.swift in Sources */, - B9EA7C802409B7DB000D8E35 /* ShowTableViewCell.swift in Sources */, - B9EA7C7C2409B7D7000D8E35 /* HouseCell.swift in Sources */, - B9EA7C842409B7E2000D8E35 /* Show.swift in Sources */, - B9EA7C672409B7B5000D8E35 /* BasicView.swift in Sources */, - B9EA7C792409B7D3000D8E35 /* MethodGroupHeader.swift in Sources */, - B9EA7C732409B7CB000D8E35 /* YogaExampleBViewController.swift in Sources */, - B9EA7C6C2409B7C2000D8E35 /* YogaExampleEView.swift in Sources */, - B9EA7C6D2409B7C2000D8E35 /* YogaExampleEViewController.swift in Sources */, - B9EA7C852409B7E7000D8E35 /* IntroView.swift in Sources */, - B9EA7C7B2409B7D3000D8E35 /* TableViewExampleViewController.swift in Sources */, - B9EA7C752409B7CE000D8E35 /* YogaExampleAViewController.swift in Sources */, - B9EA7C7A2409B7D3000D8E35 /* TableViewExampleView.swift in Sources */, - B9EA7C682409B7B5000D8E35 /* Stylesheet.swift in Sources */, - B9EA7C812409B7DB000D8E35 /* RaywenderlichTutorialView.swift in Sources */, - B9EA7C772409B7D0000D8E35 /* Example1ViewController.swift in Sources */, - B9EA7C862409B7E7000D8E35 /* IntroViewController.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; DF1F2A071F17D11700BA1B97 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -682,7 +523,7 @@ CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; + CLANG_CXX_LIBRARY = ""; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; @@ -744,7 +585,7 @@ CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; + CLANG_CXX_LIBRARY = ""; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; @@ -793,64 +634,14 @@ }; name = Release; }; - B9EA7C632409B79C000D8E35 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; - CODE_SIGN_STYLE = Automatic; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - "FLEXLAYOUT_SWIFT_PACKAGE=1", - ); - INFOPLIST_FILE = "FlexLayoutSample/Supporting Files/Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); - MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; - MTL_FAST_MATH = YES; - PRODUCT_BUNDLE_IDENTIFIER = com.lucdion.FlexLayoutSampleSPM; - PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Debug; - }; - B9EA7C642409B79C000D8E35 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; - CODE_SIGN_STYLE = Automatic; - INFOPLIST_FILE = "FlexLayoutSample/Supporting Files/Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); - MTL_FAST_MATH = YES; - PRODUCT_BUNDLE_IDENTIFIER = com.lucdion.FlexLayoutSampleSPM; - PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Release; - }; DF1F2A201F17D11700BA1B97 /* Debug */ = { isa = XCBuildConfiguration; baseConfigurationReference = 8561ACDBCFFA1B4B9ABEAB16 /* Pods-FlexLayoutSample.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; GCC_INPUT_FILETYPE = automatic; - INFOPLIST_FILE = "FlexLayoutSample/Supporting Files/Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; + INFOPLIST_FILE = "../FlexLayoutSample/Supporting Files/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 13.4; PRODUCT_BUNDLE_IDENTIFIER = com.lucdion.FlexLayoutSample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; @@ -863,8 +654,8 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; GCC_INPUT_FILETYPE = automatic; - INFOPLIST_FILE = "FlexLayoutSample/Supporting Files/Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; + INFOPLIST_FILE = "../FlexLayoutSample/Supporting Files/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 13.4; PRODUCT_BUNDLE_IDENTIFIER = com.lucdion.FlexLayoutSample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; @@ -883,15 +674,6 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - B9EA7C652409B79C000D8E35 /* Build configuration list for PBXNativeTarget "FlexLayoutSampleSPM" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - B9EA7C632409B79C000D8E35 /* Debug */, - B9EA7C642409B79C000D8E35 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; DF1F2A1F1F17D11700BA1B97 /* Build configuration list for PBXNativeTarget "FlexLayoutSample" */ = { isa = XCConfigurationList; buildConfigurations = ( @@ -902,45 +684,6 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ - -/* Begin XCRemoteSwiftPackageReference section */ - B9EA7C892409B986000D8E35 /* XCRemoteSwiftPackageReference "FlexLayout" */ = { - isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/Tundaware/FlexLayout"; - requirement = { - branch = "spm-10"; - kind = branch; - }; - }; - B9EA7C902409BAE1000D8E35 /* XCRemoteSwiftPackageReference "PinLayout" */ = { - isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/layoutBox/PinLayout.git"; - requirement = { - kind = upToNextMajorVersion; - minimumVersion = 1.8.13; - }; - }; -/* End XCRemoteSwiftPackageReference section */ - -/* Begin XCSwiftPackageProductDependency section */ - B9BDD93D240A70C3005298B3 /* FlexLayout */ = { - isa = XCSwiftPackageProductDependency; - productName = FlexLayout; - }; - B9BDD93F240A70C3005298B3 /* FlexLayoutYoga */ = { - isa = XCSwiftPackageProductDependency; - productName = FlexLayoutYoga; - }; - B9BDD941240A70C3005298B3 /* FlexLayoutYogaKit */ = { - isa = XCSwiftPackageProductDependency; - productName = FlexLayoutYogaKit; - }; - B9EA7C912409BAE1000D8E35 /* PinLayout */ = { - isa = XCSwiftPackageProductDependency; - package = B9EA7C902409BAE1000D8E35 /* XCRemoteSwiftPackageReference "PinLayout" */; - productName = PinLayout; - }; -/* End XCSwiftPackageProductDependency section */ }; rootObject = 249EFE371E64FAFE00165E39 /* Project object */; } diff --git a/Example/FlexLayoutSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Example/cocoapods/FlexLayoutSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata similarity index 100% rename from Example/FlexLayoutSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata rename to Example/cocoapods/FlexLayoutSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/Example/cocoapods/FlexLayoutSample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Example/cocoapods/FlexLayoutSample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/Example/cocoapods/FlexLayoutSample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Example/FlexLayoutSample.xcodeproj/xcshareddata/xcschemes/FlexLayoutSample.xcscheme b/Example/cocoapods/FlexLayoutSample.xcodeproj/xcshareddata/xcschemes/FlexLayoutSample.xcscheme similarity index 99% rename from Example/FlexLayoutSample.xcodeproj/xcshareddata/xcschemes/FlexLayoutSample.xcscheme rename to Example/cocoapods/FlexLayoutSample.xcodeproj/xcshareddata/xcschemes/FlexLayoutSample.xcscheme index 982b4a84..0766ccac 100644 --- a/Example/FlexLayoutSample.xcodeproj/xcshareddata/xcschemes/FlexLayoutSample.xcscheme +++ b/Example/cocoapods/FlexLayoutSample.xcodeproj/xcshareddata/xcschemes/FlexLayoutSample.xcscheme @@ -1,6 +1,6 @@ "luc_dion@yahoo.com" } - spec.platform = :ios, "12.0" + spec.platform = :ios, "13.4" spec.source = { :git => "https://github.com/lucdion/FlexLayout.git", :tag => "#{spec.version}" } spec.source_files = "Sources/**/*.{swift,h,m,mm,cpp,c}" - spec.public_header_files = "Sources/yoga/include/yoga/*.h", "Sources/YogaKit/include/YogaKit/*.h" + spec.public_header_files = "Sources/YogaKit/include/YogaKit/*.h" spec.libraries = 'c++' + # Should match yoga_defs.bzl + BUCK configuration spec.compiler_flags = [ '-fno-omit-frame-pointer', '-fexceptions', '-Wall', '-Werror', - '-std=c++1y', + '-std=c++20', '-fPIC' ] + + spec.dependency 'Yoga', '3.2.1' end diff --git a/FlexLayout.xcodeproj/project.pbxproj b/FlexLayout.xcodeproj/project.pbxproj index ae361dae..043893ee 100644 --- a/FlexLayout.xcodeproj/project.pbxproj +++ b/FlexLayout.xcodeproj/project.pbxproj @@ -8,53 +8,25 @@ /* Begin PBXBuildFile section */ 1207ABCE834615F650234676 /* Pods_FlexLayoutTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1F69C581A2C68BBBD1B64F21 /* Pods_FlexLayoutTests.framework */; }; - 24170EDB1FC7178F005AF96F /* RectNimbleMatcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24170EDA1FC7178E005AF96F /* RectNimbleMatcher.swift */; }; - 24170EDD1FC72ABC005AF96F /* WidthSizeContentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24170EDC1FC72ABC005AF96F /* WidthSizeContentSpec.swift */; }; - 24170EDF1FC72EDA005AF96F /* AbsolutionPositionContentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24170EDE1FC72EDA005AF96F /* AbsolutionPositionContentSpec.swift */; }; - 2458137F1F4A21CF00CD676B /* PaddingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2458137E1F4A21CF00CD676B /* PaddingSpec.swift */; }; - 24A91B281F45E24B00AC8B3E /* MarginSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24A91B271F45E24B00AC8B3E /* MarginSpec.swift */; }; 24AE973E1FEAF30A00995987 /* FlexLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24AE972E1FEAF30A00995987 /* FlexLayout.swift */; }; - 24AE973F1FEAF30A00995987 /* FlexLayout+Enum.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24AE97301FEAF30A00995987 /* FlexLayout+Enum.swift */; }; 24AE97401FEAF30A00995987 /* FlexLayout+Private.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24AE97311FEAF30A00995987 /* FlexLayout+Private.swift */; }; 24AE97411FEAF30A00995987 /* UIView+FlexLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24AE97321FEAF30A00995987 /* UIView+FlexLayout.swift */; }; 24AE97421FEAF30A00995987 /* Percent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24AE97331FEAF30A00995987 /* Percent.swift */; }; - 24AE97431FEAF30A00995987 /* FlexLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 24AE97351FEAF30A00995987 /* FlexLayout.h */; settings = {ATTRIBUTES = (Public, ); }; }; 24AE974A1FEAF30A00995987 /* YGLayoutExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24AE973D1FEAF30A00995987 /* YGLayoutExtensions.swift */; }; - 24DA37691EF843C500D1AB2F /* FlexLayoutTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24DA37681EF843C500D1AB2F /* FlexLayoutTests.swift */; }; - 24FB88591F5ED2B800615D33 /* JustifyContentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FB88581F5ED2B800615D33 /* JustifyContentSpec.swift */; }; - 715C61502ABEDE1900D5A2E0 /* YGFloatOptional.h in Headers */ = {isa = PBXBuildFile; fileRef = 715C61312ABEDE1900D5A2E0 /* YGFloatOptional.h */; settings = {ATTRIBUTES = (Private, ); }; }; - 715C61512ABEDE1900D5A2E0 /* Utils.h in Headers */ = {isa = PBXBuildFile; fileRef = 715C61322ABEDE1900D5A2E0 /* Utils.h */; settings = {ATTRIBUTES = (Private, ); }; }; - 715C61522ABEDE1900D5A2E0 /* CompactValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 715C61332ABEDE1900D5A2E0 /* CompactValue.h */; settings = {ATTRIBUTES = (Private, ); }; }; - 715C61532ABEDE1900D5A2E0 /* Yoga-internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 715C61342ABEDE1900D5A2E0 /* Yoga-internal.h */; }; - 715C61542ABEDE1900D5A2E0 /* YGLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 715C61352ABEDE1900D5A2E0 /* YGLayout.h */; }; - 715C61552ABEDE1900D5A2E0 /* log.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 715C61362ABEDE1900D5A2E0 /* log.cpp */; }; - 715C61562ABEDE1900D5A2E0 /* Utils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 715C61372ABEDE1900D5A2E0 /* Utils.cpp */; }; - 715C61572ABEDE1900D5A2E0 /* CMakeLists.txt in Resources */ = {isa = PBXBuildFile; fileRef = 715C61382ABEDE1900D5A2E0 /* CMakeLists.txt */; }; - 715C61582ABEDE1900D5A2E0 /* YGNodePrint.h in Headers */ = {isa = PBXBuildFile; fileRef = 715C61392ABEDE1900D5A2E0 /* YGNodePrint.h */; settings = {ATTRIBUTES = (Private, ); }; }; - 715C61592ABEDE1900D5A2E0 /* YGLayout.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 715C613A2ABEDE1900D5A2E0 /* YGLayout.cpp */; }; - 715C615A2ABEDE1900D5A2E0 /* YGNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 715C613B2ABEDE1900D5A2E0 /* YGNode.h */; settings = {ATTRIBUTES = (Private, ); }; }; - 715C615B2ABEDE1900D5A2E0 /* Yoga.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 715C613C2ABEDE1900D5A2E0 /* Yoga.cpp */; }; - 715C615C2ABEDE1900D5A2E0 /* YGStyle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 715C613D2ABEDE1900D5A2E0 /* YGStyle.cpp */; }; - 715C615D2ABEDE1900D5A2E0 /* YGEnums.h in Headers */ = {isa = PBXBuildFile; fileRef = 715C61402ABEDE1900D5A2E0 /* YGEnums.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 715C615E2ABEDE1900D5A2E0 /* YGMacros.h in Headers */ = {isa = PBXBuildFile; fileRef = 715C61412ABEDE1900D5A2E0 /* YGMacros.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 715C615F2ABEDE1900D5A2E0 /* Yoga.h in Headers */ = {isa = PBXBuildFile; fileRef = 715C61422ABEDE1900D5A2E0 /* Yoga.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 715C61602ABEDE1900D5A2E0 /* YGValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 715C61432ABEDE1900D5A2E0 /* YGValue.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 715C61612ABEDE1900D5A2E0 /* YGNodePrint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 715C61442ABEDE1900D5A2E0 /* YGNodePrint.cpp */; }; - 715C61622ABEDE1900D5A2E0 /* YGStyle.h in Headers */ = {isa = PBXBuildFile; fileRef = 715C61452ABEDE1900D5A2E0 /* YGStyle.h */; settings = {ATTRIBUTES = (Private, ); }; }; - 715C61632ABEDE1900D5A2E0 /* YGEnums.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 715C61462ABEDE1900D5A2E0 /* YGEnums.cpp */; }; - 715C61642ABEDE1900D5A2E0 /* log.h in Headers */ = {isa = PBXBuildFile; fileRef = 715C61472ABEDE1900D5A2E0 /* log.h */; settings = {ATTRIBUTES = (Private, ); }; }; - 715C61652ABEDE1900D5A2E0 /* YGValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 715C61482ABEDE1900D5A2E0 /* YGValue.cpp */; }; - 715C61662ABEDE1900D5A2E0 /* BitUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 715C61492ABEDE1900D5A2E0 /* BitUtils.h */; settings = {ATTRIBUTES = (Private, ); }; }; - 715C61672ABEDE1900D5A2E0 /* YGConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = 715C614A2ABEDE1900D5A2E0 /* YGConfig.h */; settings = {ATTRIBUTES = (Private, ); }; }; - 715C61682ABEDE1900D5A2E0 /* YGConfig.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 715C614B2ABEDE1900D5A2E0 /* YGConfig.cpp */; }; - 715C61692ABEDE1900D5A2E0 /* YGNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 715C614C2ABEDE1900D5A2E0 /* YGNode.cpp */; }; - 715C616A2ABEDE1900D5A2E0 /* event.h in Headers */ = {isa = PBXBuildFile; fileRef = 715C614E2ABEDE1900D5A2E0 /* event.h */; settings = {ATTRIBUTES = (Private, ); }; }; - 715C616B2ABEDE1900D5A2E0 /* event.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 715C614F2ABEDE1900D5A2E0 /* event.cpp */; }; + 711F2EE72ACC727000DDDD67 /* WidthSizeContentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 711F2EE12ACC727000DDDD67 /* WidthSizeContentTests.swift */; }; + 711F2EE82ACC727000DDDD67 /* PaddingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 711F2EE22ACC727000DDDD67 /* PaddingTests.swift */; }; + 711F2EE92ACC727000DDDD67 /* FlexLayoutTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 711F2EE32ACC727000DDDD67 /* FlexLayoutTests.swift */; }; + 711F2EEA2ACC727000DDDD67 /* MarginTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 711F2EE42ACC727000DDDD67 /* MarginTests.swift */; }; + 711F2EEB2ACC727000DDDD67 /* JustifyContentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 711F2EE52ACC727000DDDD67 /* JustifyContentTests.swift */; }; 715C61812ABEE4B600D5A2E0 /* UIView+Yoga.mm in Sources */ = {isa = PBXBuildFile; fileRef = 715C617A2ABEE4B600D5A2E0 /* UIView+Yoga.mm */; }; - 715C61822ABEE4B600D5A2E0 /* YGLayout+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 715C617D2ABEE4B600D5A2E0 /* YGLayout+Private.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 715C61832ABEE4B600D5A2E0 /* YGLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 715C617E2ABEE4B600D5A2E0 /* YGLayout.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 715C61842ABEE4B600D5A2E0 /* UIView+Yoga.h in Headers */ = {isa = PBXBuildFile; fileRef = 715C617F2ABEE4B600D5A2E0 /* UIView+Yoga.h */; settings = {ATTRIBUTES = (Public, ); }; }; 715C61852ABEE4B600D5A2E0 /* YGLayout.mm in Sources */ = {isa = PBXBuildFile; fileRef = 715C61802ABEE4B600D5A2E0 /* YGLayout.mm */; }; + 71A5522D2CEAED24005D9FBF /* FlexLayout+Enum.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24AE97301FEAF30A00995987 /* FlexLayout+Enum.swift */; }; + 71A5522E2CEAED47005D9FBF /* UIView+Yoga.h in Headers */ = {isa = PBXBuildFile; fileRef = 715C617F2ABEE4B600D5A2E0 /* UIView+Yoga.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 71A5522F2CEAED47005D9FBF /* YGLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 715C617E2ABEE4B600D5A2E0 /* YGLayout.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 71A552302CEAED47005D9FBF /* YGLayout+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 715C617D2ABEE4B600D5A2E0 /* YGLayout+Private.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 71A552312CEAEDC1005D9FBF /* FlexLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 24AE97351FEAF30A00995987 /* FlexLayout.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 9421472A1695AFD38FAEBD72 /* Pods_FlexLayout.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3F893AE16F96F495E91B6D58 /* Pods_FlexLayout.framework */; }; + EF5445402C1D607100BF4A33 /* InsetTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF54453F2C1D607100BF4A33 /* InsetTests.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -81,60 +53,33 @@ /* Begin PBXFileReference section */ 1F69C581A2C68BBBD1B64F21 /* Pods_FlexLayoutTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_FlexLayoutTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 24170EDA1FC7178E005AF96F /* RectNimbleMatcher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RectNimbleMatcher.swift; sourceTree = ""; }; - 24170EDC1FC72ABC005AF96F /* WidthSizeContentSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WidthSizeContentSpec.swift; sourceTree = ""; }; - 24170EDE1FC72EDA005AF96F /* AbsolutionPositionContentSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AbsolutionPositionContentSpec.swift; sourceTree = ""; }; - 2458137E1F4A21CF00CD676B /* PaddingSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PaddingSpec.swift; sourceTree = ""; }; + 224171C69665A229D0A217EF /* Pods-FlexLayout.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FlexLayout.debug.xcconfig"; path = "Target Support Files/Pods-FlexLayout/Pods-FlexLayout.debug.xcconfig"; sourceTree = ""; }; 2491CC5C1FCB931F00F3A61C /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/iOS/Nimble.framework; sourceTree = ""; }; 2491CC5E1FCB932B00F3A61C /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/iOS/Quick.framework; sourceTree = ""; }; - 24A91B271F45E24B00AC8B3E /* MarginSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MarginSpec.swift; sourceTree = ""; }; 24AE972E1FEAF30A00995987 /* FlexLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FlexLayout.swift; sourceTree = ""; }; 24AE97301FEAF30A00995987 /* FlexLayout+Enum.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FlexLayout+Enum.swift"; sourceTree = ""; }; 24AE97311FEAF30A00995987 /* FlexLayout+Private.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FlexLayout+Private.swift"; sourceTree = ""; }; 24AE97321FEAF30A00995987 /* UIView+FlexLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+FlexLayout.swift"; sourceTree = ""; }; 24AE97331FEAF30A00995987 /* Percent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Percent.swift; sourceTree = ""; }; 24AE97351FEAF30A00995987 /* FlexLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FlexLayout.h; sourceTree = ""; }; - 24AE97361FEAF30A00995987 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 24AE973D1FEAF30A00995987 /* YGLayoutExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YGLayoutExtensions.swift; sourceTree = ""; }; 24DA375A1EF843C500D1AB2F /* FlexLayout.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = FlexLayout.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 24DA37631EF843C500D1AB2F /* FlexLayoutTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FlexLayoutTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 24DA37681EF843C500D1AB2F /* FlexLayoutTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlexLayoutTests.swift; sourceTree = ""; }; - 24FB88581F5ED2B800615D33 /* JustifyContentSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JustifyContentSpec.swift; sourceTree = ""; }; 2B210ECFE9D7665DACB8E8A7 /* Pods-FlexLayoutTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FlexLayoutTests.debug.xcconfig"; path = "Target Support Files/Pods-FlexLayoutTests/Pods-FlexLayoutTests.debug.xcconfig"; sourceTree = ""; }; 38E690AA4AF8EDFC95DB6626 /* Pods-FlexLayoutTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FlexLayoutTests.release.xcconfig"; path = "Target Support Files/Pods-FlexLayoutTests/Pods-FlexLayoutTests.release.xcconfig"; sourceTree = ""; }; - 715C61312ABEDE1900D5A2E0 /* YGFloatOptional.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGFloatOptional.h; sourceTree = ""; }; - 715C61322ABEDE1900D5A2E0 /* Utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Utils.h; sourceTree = ""; }; - 715C61332ABEDE1900D5A2E0 /* CompactValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompactValue.h; sourceTree = ""; }; - 715C61342ABEDE1900D5A2E0 /* Yoga-internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Yoga-internal.h"; sourceTree = ""; }; - 715C61352ABEDE1900D5A2E0 /* YGLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGLayout.h; sourceTree = ""; }; - 715C61362ABEDE1900D5A2E0 /* log.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = log.cpp; sourceTree = ""; }; - 715C61372ABEDE1900D5A2E0 /* Utils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Utils.cpp; sourceTree = ""; }; - 715C61382ABEDE1900D5A2E0 /* CMakeLists.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = ""; }; - 715C61392ABEDE1900D5A2E0 /* YGNodePrint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGNodePrint.h; sourceTree = ""; }; - 715C613A2ABEDE1900D5A2E0 /* YGLayout.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = YGLayout.cpp; sourceTree = ""; }; - 715C613B2ABEDE1900D5A2E0 /* YGNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGNode.h; sourceTree = ""; }; - 715C613C2ABEDE1900D5A2E0 /* Yoga.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Yoga.cpp; sourceTree = ""; }; - 715C613D2ABEDE1900D5A2E0 /* YGStyle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = YGStyle.cpp; sourceTree = ""; }; - 715C61402ABEDE1900D5A2E0 /* YGEnums.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGEnums.h; sourceTree = ""; }; - 715C61412ABEDE1900D5A2E0 /* YGMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGMacros.h; sourceTree = ""; }; - 715C61422ABEDE1900D5A2E0 /* Yoga.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Yoga.h; sourceTree = ""; }; - 715C61432ABEDE1900D5A2E0 /* YGValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGValue.h; sourceTree = ""; }; - 715C61442ABEDE1900D5A2E0 /* YGNodePrint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = YGNodePrint.cpp; sourceTree = ""; }; - 715C61452ABEDE1900D5A2E0 /* YGStyle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGStyle.h; sourceTree = ""; }; - 715C61462ABEDE1900D5A2E0 /* YGEnums.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = YGEnums.cpp; sourceTree = ""; }; - 715C61472ABEDE1900D5A2E0 /* log.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = log.h; sourceTree = ""; }; - 715C61482ABEDE1900D5A2E0 /* YGValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = YGValue.cpp; sourceTree = ""; }; - 715C61492ABEDE1900D5A2E0 /* BitUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BitUtils.h; sourceTree = ""; }; - 715C614A2ABEDE1900D5A2E0 /* YGConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGConfig.h; sourceTree = ""; }; - 715C614B2ABEDE1900D5A2E0 /* YGConfig.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = YGConfig.cpp; sourceTree = ""; }; - 715C614C2ABEDE1900D5A2E0 /* YGNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = YGNode.cpp; sourceTree = ""; }; - 715C614E2ABEDE1900D5A2E0 /* event.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = event.h; sourceTree = ""; }; - 715C614F2ABEDE1900D5A2E0 /* event.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = event.cpp; sourceTree = ""; }; + 3F893AE16F96F495E91B6D58 /* Pods_FlexLayout.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_FlexLayout.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 6B9A88E410DD5E3EA6C308DD /* Pods-FlexLayout.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FlexLayout.release.xcconfig"; path = "Target Support Files/Pods-FlexLayout/Pods-FlexLayout.release.xcconfig"; sourceTree = ""; }; + 711F2EE12ACC727000DDDD67 /* WidthSizeContentTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WidthSizeContentTests.swift; sourceTree = ""; }; + 711F2EE22ACC727000DDDD67 /* PaddingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PaddingTests.swift; sourceTree = ""; }; + 711F2EE32ACC727000DDDD67 /* FlexLayoutTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FlexLayoutTests.swift; sourceTree = ""; }; + 711F2EE42ACC727000DDDD67 /* MarginTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MarginTests.swift; sourceTree = ""; }; + 711F2EE52ACC727000DDDD67 /* JustifyContentTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JustifyContentTests.swift; sourceTree = ""; }; 715C617A2ABEE4B600D5A2E0 /* UIView+Yoga.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "UIView+Yoga.mm"; sourceTree = ""; }; 715C617D2ABEE4B600D5A2E0 /* YGLayout+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "YGLayout+Private.h"; sourceTree = ""; }; 715C617E2ABEE4B600D5A2E0 /* YGLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGLayout.h; sourceTree = ""; }; 715C617F2ABEE4B600D5A2E0 /* UIView+Yoga.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+Yoga.h"; sourceTree = ""; }; 715C61802ABEE4B600D5A2E0 /* YGLayout.mm */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.objcpp; path = YGLayout.mm; sourceTree = ""; tabWidth = 2; }; + EF54453F2C1D607100BF4A33 /* InsetTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InsetTests.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -142,6 +87,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 9421472A1695AFD38FAEBD72 /* Pods_FlexLayout.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -161,6 +107,8 @@ children = ( 2B210ECFE9D7665DACB8E8A7 /* Pods-FlexLayoutTests.debug.xcconfig */, 38E690AA4AF8EDFC95DB6626 /* Pods-FlexLayoutTests.release.xcconfig */, + 224171C69665A229D0A217EF /* Pods-FlexLayout.debug.xcconfig */, + 6B9A88E410DD5E3EA6C308DD /* Pods-FlexLayout.release.xcconfig */, ); path = Pods; sourceTree = ""; @@ -168,9 +116,7 @@ 24AE972D1FEAF30A00995987 /* Sources */ = { isa = PBXGroup; children = ( - 24AE97341FEAF30A00995987 /* SupportingFiles */, B9EAD87E238884C90058E0CB /* Swift */, - 715C61302ABEDE1900D5A2E0 /* yoga */, 715C61792ABEE4B600D5A2E0 /* YogaKit */, ); path = Sources; @@ -186,20 +132,11 @@ path = Impl; sourceTree = ""; }; - 24AE97341FEAF30A00995987 /* SupportingFiles */ = { - isa = PBXGroup; - children = ( - 24AE97351FEAF30A00995987 /* FlexLayout.h */, - 24AE97361FEAF30A00995987 /* Info.plist */, - ); - path = SupportingFiles; - sourceTree = ""; - }; 24DA37501EF843C500D1AB2F = { isa = PBXGroup; children = ( 24AE972D1FEAF30A00995987 /* Sources */, - 24DA37671EF843C500D1AB2F /* FlexLayoutTests */, + 711F2EDE2ACC727000DDDD67 /* Tests */, 24DA375B1EF843C500D1AB2F /* Products */, B5403C6F81C3814B69C05D0B /* Frameworks */, 11B7D0626353A881C6A3705D /* Pods */, @@ -215,77 +152,25 @@ name = Products; sourceTree = ""; }; - 24DA37671EF843C500D1AB2F /* FlexLayoutTests */ = { + 711F2EDE2ACC727000DDDD67 /* Tests */ = { isa = PBXGroup; children = ( - 24DA37681EF843C500D1AB2F /* FlexLayoutTests.swift */, - 24FB88581F5ED2B800615D33 /* JustifyContentSpec.swift */, - 24170EDC1FC72ABC005AF96F /* WidthSizeContentSpec.swift */, - 24170EDE1FC72EDA005AF96F /* AbsolutionPositionContentSpec.swift */, - 24A91B271F45E24B00AC8B3E /* MarginSpec.swift */, - 2458137E1F4A21CF00CD676B /* PaddingSpec.swift */, - 24170EDA1FC7178E005AF96F /* RectNimbleMatcher.swift */, + 711F2EDF2ACC727000DDDD67 /* FlexLayoutTests */, ); - path = FlexLayoutTests; - sourceTree = ""; - }; - 715C61302ABEDE1900D5A2E0 /* yoga */ = { - isa = PBXGroup; - children = ( - 715C61492ABEDE1900D5A2E0 /* BitUtils.h */, - 715C61382ABEDE1900D5A2E0 /* CMakeLists.txt */, - 715C61332ABEDE1900D5A2E0 /* CompactValue.h */, - 715C614D2ABEDE1900D5A2E0 /* event */, - 715C613E2ABEDE1900D5A2E0 /* include */, - 715C61362ABEDE1900D5A2E0 /* log.cpp */, - 715C61472ABEDE1900D5A2E0 /* log.h */, - 715C61372ABEDE1900D5A2E0 /* Utils.cpp */, - 715C61322ABEDE1900D5A2E0 /* Utils.h */, - 715C614B2ABEDE1900D5A2E0 /* YGConfig.cpp */, - 715C614A2ABEDE1900D5A2E0 /* YGConfig.h */, - 715C61462ABEDE1900D5A2E0 /* YGEnums.cpp */, - 715C61312ABEDE1900D5A2E0 /* YGFloatOptional.h */, - 715C613A2ABEDE1900D5A2E0 /* YGLayout.cpp */, - 715C61352ABEDE1900D5A2E0 /* YGLayout.h */, - 715C614C2ABEDE1900D5A2E0 /* YGNode.cpp */, - 715C613B2ABEDE1900D5A2E0 /* YGNode.h */, - 715C61442ABEDE1900D5A2E0 /* YGNodePrint.cpp */, - 715C61392ABEDE1900D5A2E0 /* YGNodePrint.h */, - 715C613D2ABEDE1900D5A2E0 /* YGStyle.cpp */, - 715C61452ABEDE1900D5A2E0 /* YGStyle.h */, - 715C61482ABEDE1900D5A2E0 /* YGValue.cpp */, - 715C61342ABEDE1900D5A2E0 /* Yoga-internal.h */, - 715C613C2ABEDE1900D5A2E0 /* Yoga.cpp */, - ); - path = yoga; + path = Tests; sourceTree = ""; }; - 715C613E2ABEDE1900D5A2E0 /* include */ = { + 711F2EDF2ACC727000DDDD67 /* FlexLayoutTests */ = { isa = PBXGroup; children = ( - 715C613F2ABEDE1900D5A2E0 /* yoga */, + 711F2EE12ACC727000DDDD67 /* WidthSizeContentTests.swift */, + 711F2EE22ACC727000DDDD67 /* PaddingTests.swift */, + 711F2EE32ACC727000DDDD67 /* FlexLayoutTests.swift */, + 711F2EE42ACC727000DDDD67 /* MarginTests.swift */, + 711F2EE52ACC727000DDDD67 /* JustifyContentTests.swift */, + EF54453F2C1D607100BF4A33 /* InsetTests.swift */, ); - path = include; - sourceTree = ""; - }; - 715C613F2ABEDE1900D5A2E0 /* yoga */ = { - isa = PBXGroup; - children = ( - 715C61402ABEDE1900D5A2E0 /* YGEnums.h */, - 715C61412ABEDE1900D5A2E0 /* YGMacros.h */, - 715C61432ABEDE1900D5A2E0 /* YGValue.h */, - 715C61422ABEDE1900D5A2E0 /* Yoga.h */, - ); - path = yoga; - sourceTree = ""; - }; - 715C614D2ABEDE1900D5A2E0 /* event */ = { - isa = PBXGroup; - children = ( - 715C614E2ABEDE1900D5A2E0 /* event.h */, - 715C614F2ABEDE1900D5A2E0 /* event.cpp */, - ); - path = event; + path = FlexLayoutTests; sourceTree = ""; }; 715C61792ABEE4B600D5A2E0 /* YogaKit */ = { @@ -316,12 +201,21 @@ path = YogaKit; sourceTree = ""; }; + 71CE1DE72B79E81500FD1037 /* Public */ = { + isa = PBXGroup; + children = ( + 24AE97351FEAF30A00995987 /* FlexLayout.h */, + ); + path = Public; + sourceTree = ""; + }; B5403C6F81C3814B69C05D0B /* Frameworks */ = { isa = PBXGroup; children = ( 2491CC5E1FCB932B00F3A61C /* Quick.framework */, 2491CC5C1FCB931F00F3A61C /* Nimble.framework */, 1F69C581A2C68BBBD1B64F21 /* Pods_FlexLayoutTests.framework */, + 3F893AE16F96F495E91B6D58 /* Pods_FlexLayout.framework */, ); name = Frameworks; sourceTree = ""; @@ -329,6 +223,7 @@ B9EAD87E238884C90058E0CB /* Swift */ = { isa = PBXGroup; children = ( + 71CE1DE72B79E81500FD1037 /* Public */, 24AE972E1FEAF30A00995987 /* FlexLayout.swift */, 24AE972F1FEAF30A00995987 /* Impl */, 24AE97331FEAF30A00995987 /* Percent.swift */, @@ -344,26 +239,10 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( - 715C615F2ABEDE1900D5A2E0 /* Yoga.h in Headers */, - 715C615E2ABEDE1900D5A2E0 /* YGMacros.h in Headers */, - 715C61832ABEE4B600D5A2E0 /* YGLayout.h in Headers */, - 715C61602ABEDE1900D5A2E0 /* YGValue.h in Headers */, - 715C61842ABEE4B600D5A2E0 /* UIView+Yoga.h in Headers */, - 715C615D2ABEDE1900D5A2E0 /* YGEnums.h in Headers */, - 715C61822ABEE4B600D5A2E0 /* YGLayout+Private.h in Headers */, - 715C61622ABEDE1900D5A2E0 /* YGStyle.h in Headers */, - 715C61672ABEDE1900D5A2E0 /* YGConfig.h in Headers */, - 715C61512ABEDE1900D5A2E0 /* Utils.h in Headers */, - 715C61582ABEDE1900D5A2E0 /* YGNodePrint.h in Headers */, - 715C61642ABEDE1900D5A2E0 /* log.h in Headers */, - 715C61662ABEDE1900D5A2E0 /* BitUtils.h in Headers */, - 715C61522ABEDE1900D5A2E0 /* CompactValue.h in Headers */, - 715C61502ABEDE1900D5A2E0 /* YGFloatOptional.h in Headers */, - 715C615A2ABEDE1900D5A2E0 /* YGNode.h in Headers */, - 715C616A2ABEDE1900D5A2E0 /* event.h in Headers */, - 24AE97431FEAF30A00995987 /* FlexLayout.h in Headers */, - 715C61542ABEDE1900D5A2E0 /* YGLayout.h in Headers */, - 715C61532ABEDE1900D5A2E0 /* Yoga-internal.h in Headers */, + 71A5522E2CEAED47005D9FBF /* UIView+Yoga.h in Headers */, + 71A5522F2CEAED47005D9FBF /* YGLayout.h in Headers */, + 71A552302CEAED47005D9FBF /* YGLayout+Private.h in Headers */, + 71A552312CEAEDC1005D9FBF /* FlexLayout.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -374,6 +253,7 @@ isa = PBXNativeTarget; buildConfigurationList = 24DA376E1EF843C500D1AB2F /* Build configuration list for PBXNativeTarget "FlexLayout" */; buildPhases = ( + 296ABF4DC2205E5C45A6CE32 /* [CP] Check Pods Manifest.lock */, 24DA37551EF843C500D1AB2F /* Sources */, 24DA37561EF843C500D1AB2F /* Frameworks */, 24DA37571EF843C500D1AB2F /* Headers */, @@ -396,7 +276,6 @@ 780CC5362B9779C60FF80C2D /* [CP] Check Pods Manifest.lock */, 24DA375F1EF843C500D1AB2F /* Sources */, 24DA37601EF843C500D1AB2F /* Frameworks */, - 1CCE19B4893250DCBCF5F00C /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -455,33 +334,32 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 715C61572ABEDE1900D5A2E0 /* CMakeLists.txt in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 1CCE19B4893250DCBCF5F00C /* [CP] Embed Pods Frameworks */ = { + 296ABF4DC2205E5C45A6CE32 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); + inputFileListPaths = ( + ); inputPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-FlexLayoutTests/Pods-FlexLayoutTests-frameworks.sh", - "${BUILT_PRODUCTS_DIR}/FlexLayout/FlexLayout.framework", - "${BUILT_PRODUCTS_DIR}/Nimble/Nimble.framework", - "${BUILT_PRODUCTS_DIR}/Quick/Quick.framework", + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( ); - name = "[CP] Embed Pods Frameworks"; outputPaths = ( - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FlexLayout.framework", - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Nimble.framework", - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Quick.framework", + "$(DERIVED_FILE_DIR)/Pods-FlexLayout-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-FlexLayoutTests/Pods-FlexLayoutTests-frameworks.sh\"\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; 780CC5362B9779C60FF80C2D /* [CP] Check Pods Manifest.lock */ = { @@ -513,24 +391,13 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 715C61552ABEDE1900D5A2E0 /* log.cpp in Sources */, 24AE974A1FEAF30A00995987 /* YGLayoutExtensions.swift in Sources */, 24AE97411FEAF30A00995987 /* UIView+FlexLayout.swift in Sources */, - 715C615C2ABEDE1900D5A2E0 /* YGStyle.cpp in Sources */, - 715C61562ABEDE1900D5A2E0 /* Utils.cpp in Sources */, 24AE97421FEAF30A00995987 /* Percent.swift in Sources */, 715C61852ABEE4B600D5A2E0 /* YGLayout.mm in Sources */, - 715C616B2ABEDE1900D5A2E0 /* event.cpp in Sources */, 24AE97401FEAF30A00995987 /* FlexLayout+Private.swift in Sources */, - 715C61692ABEDE1900D5A2E0 /* YGNode.cpp in Sources */, - 24AE973F1FEAF30A00995987 /* FlexLayout+Enum.swift in Sources */, 715C61812ABEE4B600D5A2E0 /* UIView+Yoga.mm in Sources */, - 715C61652ABEDE1900D5A2E0 /* YGValue.cpp in Sources */, - 715C61682ABEDE1900D5A2E0 /* YGConfig.cpp in Sources */, - 715C61632ABEDE1900D5A2E0 /* YGEnums.cpp in Sources */, - 715C615B2ABEDE1900D5A2E0 /* Yoga.cpp in Sources */, - 715C61612ABEDE1900D5A2E0 /* YGNodePrint.cpp in Sources */, - 715C61592ABEDE1900D5A2E0 /* YGLayout.cpp in Sources */, + 71A5522D2CEAED24005D9FBF /* FlexLayout+Enum.swift in Sources */, 24AE973E1FEAF30A00995987 /* FlexLayout.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -539,13 +406,12 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 24A91B281F45E24B00AC8B3E /* MarginSpec.swift in Sources */, - 24DA37691EF843C500D1AB2F /* FlexLayoutTests.swift in Sources */, - 24170EDD1FC72ABC005AF96F /* WidthSizeContentSpec.swift in Sources */, - 2458137F1F4A21CF00CD676B /* PaddingSpec.swift in Sources */, - 24170EDB1FC7178F005AF96F /* RectNimbleMatcher.swift in Sources */, - 24FB88591F5ED2B800615D33 /* JustifyContentSpec.swift in Sources */, - 24170EDF1FC72EDA005AF96F /* AbsolutionPositionContentSpec.swift in Sources */, + 711F2EEA2ACC727000DDDD67 /* MarginTests.swift in Sources */, + 711F2EE92ACC727000DDDD67 /* FlexLayoutTests.swift in Sources */, + 711F2EE82ACC727000DDDD67 /* PaddingTests.swift in Sources */, + 711F2EEB2ACC727000DDDD67 /* JustifyContentTests.swift in Sources */, + EF5445402C1D607100BF4A33 /* InsetTests.swift in Sources */, + 711F2EE72ACC727000DDDD67 /* WidthSizeContentTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -692,9 +558,12 @@ }; 24DA376F1EF843C500D1AB2F /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 224171C69665A229D0A217EF /* Pods-FlexLayout.debug.xcconfig */; buildSettings = { CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = YES; + CLANG_CXX_LANGUAGE_STANDARD = "c++20"; CLANG_ENABLE_MODULES = YES; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO; CODE_SIGN_IDENTITY = ""; CODE_SIGN_STYLE = Manual; DEFINES_MODULE = YES; @@ -702,18 +571,9 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/iOS", - ); - HEADER_SEARCH_PATHS = ( - "$(PROJECT_DIR)/Sources/yoga", - "$(PROJECT_DIR)/Sources/yoga/include/yoga", - "$(PROJECT_DIR)/Sources/YogaKit", - "$(PROJECT_DIR)/Sources/YogaKit/include/YogaKit", - ); - INFOPLIST_FILE = Sources/SupportingFiles/Info.plist; + GENERATE_INFOPLIST_FILE = YES; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 13.4; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.lucdion.FlexLayout; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -727,9 +587,12 @@ }; 24DA37701EF843C500D1AB2F /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 6B9A88E410DD5E3EA6C308DD /* Pods-FlexLayout.release.xcconfig */; buildSettings = { CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = YES; + CLANG_CXX_LANGUAGE_STANDARD = "c++20"; CLANG_ENABLE_MODULES = YES; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO; CODE_SIGN_IDENTITY = ""; CODE_SIGN_STYLE = Manual; DEFINES_MODULE = YES; @@ -737,18 +600,9 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/iOS", - ); - HEADER_SEARCH_PATHS = ( - "$(PROJECT_DIR)/Sources/yoga", - "$(PROJECT_DIR)/Sources/yoga/include/yoga", - "$(PROJECT_DIR)/Sources/YogaKit", - "$(PROJECT_DIR)/Sources/YogaKit/include/YogaKit", - ); - INFOPLIST_FILE = Sources/SupportingFiles/Info.plist; + GENERATE_INFOPLIST_FILE = YES; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 13.4; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.lucdion.FlexLayout; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -767,6 +621,7 @@ DEVELOPMENT_TEAM = F37Y9H9E46; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; GENERATE_INFOPLIST_FILE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 13.4; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; OTHER_LDFLAGS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = com.lucdion.FlexLayoutTests; @@ -783,6 +638,7 @@ DEVELOPMENT_TEAM = F37Y9H9E46; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; GENERATE_INFOPLIST_FILE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 13.4; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; OTHER_LDFLAGS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = com.lucdion.FlexLayoutTests; diff --git a/FlexLayout.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/FlexLayout.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/FlexLayout.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/FlexLayout.xcodeproj/xcshareddata/xcschemes/FlexLayout.xcscheme b/FlexLayout.xcodeproj/xcshareddata/xcschemes/FlexLayoutInner.xcscheme similarity index 100% rename from FlexLayout.xcodeproj/xcshareddata/xcschemes/FlexLayout.xcscheme rename to FlexLayout.xcodeproj/xcshareddata/xcschemes/FlexLayoutInner.xcscheme diff --git a/FlexLayout.xcworkspace/contents.xcworkspacedata b/FlexLayout.xcworkspace/contents.xcworkspacedata index 5172c2e1..8d6ba05b 100644 --- a/FlexLayout.xcworkspace/contents.xcworkspacedata +++ b/FlexLayout.xcworkspace/contents.xcworkspacedata @@ -2,7 +2,7 @@ + location = "group:Example/cocoapods/FlexLayoutSample.xcodeproj"> diff --git a/FlexLayoutTests/AbsolutionPositionContentSpec.swift b/FlexLayoutTests/AbsolutionPositionContentSpec.swift deleted file mode 100644 index c57551ec..00000000 --- a/FlexLayoutTests/AbsolutionPositionContentSpec.swift +++ /dev/null @@ -1,82 +0,0 @@ -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. - -import Quick -import Nimble - -class AbsolutionPositionContentSpec: QuickSpec { - override func spec() { - var viewController: UIViewController! - var rootFlexContainer: UIView! - var aView: UIView! -// var bView: UIView! -// var cView: UIView! -// var dView: UIView! - - beforeSuite { - } - - beforeEach { - viewController = UIViewController() - - rootFlexContainer = UIView() - rootFlexContainer.frame = CGRect(x: 0, y: 0, width: 400, height: 400) - viewController.view.addSubview(rootFlexContainer) - - aView = UIView() -// bView = UIView() -// cView = UIView() -// dView = UIView() - } - - describe("absolute position") { - it("position(.absolute)") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).position(.absolute).left(10).right(10).width(300).height(200) - } - - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 10.0, y: 0.0, width: 300.0, height: 200.0))) - } - - it("position(.absolute)") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).position(.absolute).left(10).right(10).width(300).height(200) - } - - // Later reset the aspectRatio - aView.flex.left(0) - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 300.0, height: 200.0))) - } - - it("position(.absolute)") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).position(.absolute).horizontally(15).vertically(20) - } - - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 15.0, y: 20.0, width: 370.0, height: 360.0))) - } - - it("position(.absolute)") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).position(.absolute).all(45) - } - - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 45.0, y: 45.0, width: 310.0, height: 310.0))) - } - - } - } -} diff --git a/FlexLayoutTests/JustifyContentSpec.swift b/FlexLayoutTests/JustifyContentSpec.swift deleted file mode 100644 index 06ab828b..00000000 --- a/FlexLayoutTests/JustifyContentSpec.swift +++ /dev/null @@ -1,140 +0,0 @@ -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. - -import Quick -import Nimble - -class JustifyContentSpec: QuickSpec { - override func spec() { - var viewController: UIViewController! - var rootFlexContainer: UIView! - var aView: UIView! - var bView: UIView! - var cView: UIView! - var dView: UIView! - - beforeSuite { - } - - beforeEach { - viewController = UIViewController() - - rootFlexContainer = UIView() - rootFlexContainer.frame = CGRect(x: 0, y: 0, width: 400, height: 400) - viewController.view.addSubview(rootFlexContainer) - - aView = UIView() - bView = UIView() - cView = UIView() - dView = UIView() - } - - describe("justifyContent") { - it("adjust view position") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).size(20) - flex.addItem(bView).size(20) - flex.addItem(cView).size(20) - flex.addItem(dView).size(20) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 20.0, height: 20.0))) - expect(bView.frame).to(equal(CGRect(x: 0.0, y: 20.0, width: 20.0, height: 20.0))) - expect(cView.frame).to(equal(CGRect(x: 0.0, y: 40.0, width: 20.0, height: 20.0))) - expect(dView.frame).to(equal(CGRect(x: 0.0, y: 60.0, width: 20.0, height: 20.0))) - } - - it("adjust view position") { - rootFlexContainer.flex.justifyContent(.start).define { (flex) in - flex.addItem(aView).size(20) - flex.addItem(bView).size(20) - flex.addItem(cView).size(20) - flex.addItem(dView).size(20) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 20.0, height: 20.0))) - expect(bView.frame).to(equal(CGRect(x: 0.0, y: 20.0, width: 20.0, height: 20.0))) - expect(cView.frame).to(equal(CGRect(x: 0.0, y: 40.0, width: 20.0, height: 20.0))) - expect(dView.frame).to(equal(CGRect(x: 0.0, y: 60.0, width: 20.0, height: 20.0))) - } - - it("adjust view position") { - rootFlexContainer.flex.justifyContent(.center).define { (flex) in - flex.addItem(aView).size(20) - flex.addItem(bView).size(20) - flex.addItem(cView).size(20) - flex.addItem(dView).size(20) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 160.0, width: 20.0, height: 20.0))) - expect(bView.frame).to(equal(CGRect(x: 0.0, y: 180.0, width: 20.0, height: 20.0))) - expect(cView.frame).to(equal(CGRect(x: 0.0, y: 200.0, width: 20.0, height: 20.0))) - expect(dView.frame).to(equal(CGRect(x: 0.0, y: 220.0, width: 20.0, height: 20.0))) - } - - it("adjust view position") { - rootFlexContainer.flex.justifyContent(.spaceAround).define { (flex) in - flex.addItem(aView).size(20) - flex.addItem(bView).size(20) - flex.addItem(cView).size(20) - flex.addItem(dView).size(20) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 40.0, width: 20.0, height: 20.0))) - expect(bView.frame).to(equal(CGRect(x: 0.0, y: 140.0, width: 20.0, height: 20.0))) - expect(cView.frame).to(equal(CGRect(x: 0.0, y: 240.0, width: 20.0, height: 20.0))) - expect(dView.frame).to(equal(CGRect(x: 0.0, y: 340.0, width: 20.0, height: 20.0))) - } - - it("adjust view position") { - rootFlexContainer.flex.justifyContent(.spaceBetween).define { (flex) in - flex.addItem(aView).size(20) - flex.addItem(bView).size(20) - flex.addItem(cView).size(20) - flex.addItem(dView).size(20) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(beCloseTo(CGRect(x: 0.0, y: 0.0, width: 20.0, height: 20.0), within: 0.5)) - expect(bView.frame).to(beCloseTo(CGRect(x: 0.0, y: 126.5, width: 20.0, height: 20.0), within: 0.5)) - expect(cView.frame).to(beCloseTo(CGRect(x: 0.0, y: 253.0, width: 20.0, height: 20.0), within: 0.5)) - expect(dView.frame).to(beCloseTo(CGRect(x: 0.0, y: 380.0, width: 20.0, height: 20.0), within: 0.5)) - } - - it("adjust view position") { - rootFlexContainer.flex.justifyContent(.spaceBetween).define { (flex) in - flex.addItem(aView).size(20).marginTop(10) - flex.addItem(bView).size(20) - flex.addItem(cView).size(20) - flex.addItem(dView).size(20).marginBottom(10) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 10.0, width: 20.0, height: 20.0))) - expect(bView.frame).to(equal(CGRect(x: 0.0, y: 130.0, width: 20.0, height: 20.0))) - expect(cView.frame).to(equal(CGRect(x: 0.0, y: 250.0, width: 20.0, height: 20.0))) - expect(dView.frame).to(equal(CGRect(x: 0.0, y: 370.0, width: 20.0, height: 20.0))) - } - } - - describe("basis") { - it("adjust view position") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).basis(1) - - // Disable until my PR on YogaKit is merged! - // https://github.com/facebook/yoga/pull/672 - //flex.addItem(bView).basis(nil) - } - rootFlexContainer.flex.layout() - } - } - } -} diff --git a/FlexLayoutTests/MarginSpec.swift b/FlexLayoutTests/MarginSpec.swift deleted file mode 100644 index a004d3e8..00000000 --- a/FlexLayoutTests/MarginSpec.swift +++ /dev/null @@ -1,132 +0,0 @@ -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. - -import Quick -import Nimble - -class MarginSpec: QuickSpec { - override func spec() { - var viewController: UIViewController! - var rootFlexContainer: UIView! - var aView: UIView! - - beforeSuite { - } - - beforeEach { - viewController = UIViewController() - - rootFlexContainer = UIView() - rootFlexContainer.frame = CGRect(x: 0, y: 0, width: 400, height: 400) - viewController.view.addSubview(rootFlexContainer) - - aView = UIView() - } - - describe("") { - it("adjust the aView size and position") { - rootFlexContainer.flex.define { (_) in - } - rootFlexContainer.flex.layout() - expect(rootFlexContainer.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 400.0, height: 400.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).grow(1) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 400.0, height: 400.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).grow(1).marginLeft(10) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 10.0, y: 0.0, width: 390.0, height: 400.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).grow(1).marginLeft(10) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 10.0, y: 0.0, width: 390.0, height: 400.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).grow(1).marginTop(10) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 10.0, width: 400.0, height: 390.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).grow(1).marginBottom(10) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 400.0, height: 390.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).grow(1).marginStart(10) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 10.0, y: 0.0, width: 390.0, height: 400.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).grow(1).marginEnd(10) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 390.0, height: 400.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).grow(1).margin(10, 20, 30, 40) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 20.0, y: 10.0, width: 340.0, height: 360.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).grow(1).margin(10) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 10.0, y: 10.0, width: 380.0, height: 380.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).grow(1).marginVertical(10) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 10.0, width: 400.0, height: 380.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).grow(1).marginHorizontal(10) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 10.0, y: 0.0, width: 380.0, height: 400.0))) - } - } - } -} diff --git a/FlexLayoutTests/PaddingSpec.swift b/FlexLayoutTests/PaddingSpec.swift deleted file mode 100644 index 5395d0a3..00000000 --- a/FlexLayoutTests/PaddingSpec.swift +++ /dev/null @@ -1,201 +0,0 @@ -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. - -import Quick -import Nimble -import FlexLayout - -class PaddingSpec: QuickSpec { - override func spec() { - var viewController: UIViewController! - var rootFlexContainer: UIView! - var aView: UIView! - - beforeSuite { - } - - beforeEach { - viewController = UIViewController() - - rootFlexContainer = UIView() - rootFlexContainer.frame = CGRect(x: 0, y: 0, width: 400, height: 400) - viewController.view.addSubview(rootFlexContainer) - - aView = UIView() - } - - describe("") { - it("adjust the aView size and position") { - rootFlexContainer.flex.paddingTop(10).define { (flex) in - flex.addItem(aView).grow(1) - } - - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 10.0, width: 400.0, height: 390.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.paddingTop(10%).define { (flex) in - flex.addItem(aView).grow(1) - } - - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 40.0, width: 400.0, height: 360.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.paddingLeft(10).define { (flex) in - flex.addItem(aView).grow(1) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 10.0, y: 0.0, width: 390.0, height: 400.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.paddingLeft(10%).define { (flex) in - flex.addItem(aView).grow(1) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 40.0, y: 0.0, width: 360.0, height: 400.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.paddingBottom(10).define { (flex) in - flex.addItem(aView).grow(1) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 400.0, height: 390.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.paddingBottom(10%).define { (flex) in - flex.addItem(aView).grow(1) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 400.0, height: 360.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.paddingRight(10).define { (flex) in - flex.addItem(aView).grow(1) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 390.0, height: 400.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.paddingRight(10%).define { (flex) in - flex.addItem(aView).grow(1) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 360.0, height: 400.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.padding(10).define { (flex) in - flex.addItem(aView).grow(1) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 10.0, y: 10.0, width: 380.0, height: 380.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.padding(10%).define { (flex) in - flex.addItem(aView).grow(1) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 40.0, y: 40.0, width: 320.0, height: 320.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.padding(10, 20, 30, 40).define { (flex) in - flex.addItem(aView).grow(1) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 20.0, y: 10.0, width: 340.0, height: 360.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.padding(10%, 20%, 30%, 40%).define { (flex) in - flex.addItem(aView).grow(1) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 80.0, y: 40.0, width: 160.0, height: 240.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.paddingStart(10).define { (flex) in - flex.addItem(aView).grow(1) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 10.0, y: 0.0, width: 390.0, height: 400.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.paddingStart(10%).define { (flex) in - flex.addItem(aView).grow(1) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 40.0, y: 0.0, width: 360.0, height: 400.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.paddingEnd(10).define { (flex) in - flex.addItem(aView).grow(1) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 390.0, height: 400.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.paddingEnd(10%).define { (flex) in - flex.addItem(aView).grow(1) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 360.0, height: 400.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.paddingVertical(10).define { (flex) in - flex.addItem(aView).grow(1) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 10.0, width: 400.0, height: 380.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.paddingVertical(10%).define { (flex) in - flex.addItem(aView).grow(1) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 40.0, width: 400.0, height: 320.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.paddingHorizontal(10).define { (flex) in - flex.addItem(aView).grow(1) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 10.0, y: 0.0, width: 380.0, height: 400.0))) - } - - it("adjust the aView size and position") { - rootFlexContainer.flex.paddingHorizontal(10%).define { (flex) in - flex.addItem(aView).grow(1) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 40.0, y: 0.0, width: 320.0, height: 400.0))) - } - - } - } -} diff --git a/FlexLayoutTests/RectNimbleMatcher.swift b/FlexLayoutTests/RectNimbleMatcher.swift deleted file mode 100644 index 0dbe09fe..00000000 --- a/FlexLayoutTests/RectNimbleMatcher.swift +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) 2017 Luc Dion -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// 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 THE -// AUTHORS OR COPYRIGHT HOLDERS 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. - -import Nimble -import UIKit - -public func beCloseTo(_ expectedValue: CGRect, within delta: CGFloat = 0.000_01) -> Nimble.Predicate { - let errorMessage = "be close to <\(stringify(expectedValue))> (each within \(stringify(delta)))" - return Predicate.simple(errorMessage) { actualExpression in - if let actual = try actualExpression.evaluate() { - if abs(actual.origin.x - expectedValue.origin.x) > delta { - return .doesNotMatch - } - - if abs(actual.origin.y - expectedValue.origin.y) > delta { - return .doesNotMatch - } - - if abs(actual.size.width - expectedValue.size.width) > delta { - return .doesNotMatch - } - - if abs(actual.size.height - expectedValue.size.height) > delta { - return .doesNotMatch - } - - return .matches - } - return .doesNotMatch - } -} diff --git a/FlexLayoutTests/WidthSizeContentSpec.swift b/FlexLayoutTests/WidthSizeContentSpec.swift deleted file mode 100644 index b4b99b28..00000000 --- a/FlexLayoutTests/WidthSizeContentSpec.swift +++ /dev/null @@ -1,166 +0,0 @@ -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. - -import Quick -import Nimble - -class WidthSizeContentSpec: QuickSpec { - override func spec() { - var viewController: UIViewController! - var rootFlexContainer: UIView! - var aView: UIView! - - beforeSuite { - } - - beforeEach { - viewController = UIViewController() - - rootFlexContainer = UIView() - rootFlexContainer.frame = CGRect(x: 0, y: 0, width: 400, height: 400) - viewController.view.addSubview(rootFlexContainer) - - aView = UIView() - } - - describe("basis") { - it("adjust view position") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).width(100).height(200) - } - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 100.0, height: 200.0))) - } - - it("aspectRatio") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).width(200).aspectRatio(2) - } - - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 200.0, height: 100.0))) - } - - it("aspectRatio reset") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).width(200).aspectRatio(2) - } - - // Later reset the aspectRatio - aView.flex.aspectRatio(nil) - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 200.0, height: 0.0))) - } - - it("width & height") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).width(200).minWidth(100).height(200).minHeight(100) - } - - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 200.0, height: 200.0))) - } - - it("width & height reset") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).width(200).minWidth(100).height(200).minHeight(100) - } - - // Later reset the width and the height - aView.flex.width(nil) - aView.flex.height(nil) - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 400.0, height: 100.0))) - } - - it("minWidth") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).width(200).minWidth(300).height(200) - } - - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 300.0, height: 200.0))) - } - - it("minWidth reset") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).width(200).maxWidth(300).height(200) - } - - // Later reset the minWidth - aView.flex.minWidth(nil) - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 200.0, height: 200.0))) - } - - it("maxWidth") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).maxWidth(300).height(200) - } - - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 300.0, height: 200.0))) - } - - it("maxWidth reset") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).maxWidth(300).height(200) - } - - // Later reset the width and the height - aView.flex.maxWidth(nil) - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 400.0, height: 200.0))) - } - - it("minHeight") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).height(200).minHeight(300) - } - - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 400.0, height: 300.0))) - } - - it("minHeight reset") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).height(200).minHeight(300) - } - - // Later reset the minHeight - aView.flex.minHeight(nil) - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 400.0, height: 200.0))) - } - - it("maxHeight") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).height(200).maxHeight(100) - } - - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 400.0, height: 100.0))) - } - - it("maxHeight reset") { - rootFlexContainer.flex.define { (flex) in - flex.addItem(aView).height(200).maxHeight(100) - } - - // Later reset the maxHeight - aView.flex.maxHeight(nil) - rootFlexContainer.flex.layout() - expect(aView.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 400.0, height: 200.0))) - } - } - } -} diff --git a/Gemfile b/Gemfile deleted file mode 100644 index fefa2fca..00000000 --- a/Gemfile +++ /dev/null @@ -1,3 +0,0 @@ -source 'https://rubygems.org' -gem 'cocoapods' -gem 'fastlane' diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 6678c50f..00000000 --- a/Gemfile.lock +++ /dev/null @@ -1,284 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - CFPropertyList (3.0.5) - rexml - activesupport (6.1.7.3) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 1.6, < 2) - minitest (>= 5.1) - tzinfo (~> 2.0) - zeitwerk (~> 2.3) - addressable (2.8.0) - public_suffix (>= 2.0.2, < 5.0) - algoliasearch (1.27.5) - httpclient (~> 2.8, >= 2.8.3) - json (>= 1.5.1) - artifactory (3.0.15) - atomos (0.1.3) - aws-eventstream (1.2.0) - aws-partitions (1.551.0) - aws-sdk-core (3.125.5) - aws-eventstream (~> 1, >= 1.0.2) - aws-partitions (~> 1, >= 1.525.0) - aws-sigv4 (~> 1.1) - jmespath (~> 1.0) - aws-sdk-kms (1.53.0) - aws-sdk-core (~> 3, >= 3.125.0) - aws-sigv4 (~> 1.1) - aws-sdk-s3 (1.111.3) - aws-sdk-core (~> 3, >= 3.125.0) - aws-sdk-kms (~> 1) - aws-sigv4 (~> 1.4) - aws-sigv4 (1.4.0) - aws-eventstream (~> 1, >= 1.0.2) - babosa (1.0.4) - claide (1.1.0) - cocoapods (1.11.2) - addressable (~> 2.8) - claide (>= 1.0.2, < 2.0) - cocoapods-core (= 1.11.2) - cocoapods-deintegrate (>= 1.0.3, < 2.0) - cocoapods-downloader (>= 1.4.0, < 2.0) - cocoapods-plugins (>= 1.0.0, < 2.0) - cocoapods-search (>= 1.0.0, < 2.0) - cocoapods-trunk (>= 1.4.0, < 2.0) - cocoapods-try (>= 1.1.0, < 2.0) - colored2 (~> 3.1) - escape (~> 0.0.4) - fourflusher (>= 2.3.0, < 3.0) - gh_inspector (~> 1.0) - molinillo (~> 0.8.0) - nap (~> 1.0) - ruby-macho (>= 1.0, < 3.0) - xcodeproj (>= 1.21.0, < 2.0) - cocoapods-core (1.11.2) - activesupport (>= 5.0, < 7) - addressable (~> 2.8) - algoliasearch (~> 1.0) - concurrent-ruby (~> 1.1) - fuzzy_match (~> 2.0.4) - nap (~> 1.0) - netrc (~> 0.11) - public_suffix (~> 4.0) - typhoeus (~> 1.0) - cocoapods-deintegrate (1.0.5) - cocoapods-downloader (1.6.3) - cocoapods-plugins (1.0.0) - nap - cocoapods-search (1.0.1) - cocoapods-trunk (1.6.0) - nap (>= 0.8, < 2.0) - netrc (~> 0.11) - cocoapods-try (1.2.0) - colored (1.2) - colored2 (3.1.2) - commander (4.6.0) - highline (~> 2.0.0) - concurrent-ruby (1.2.2) - declarative (0.0.20) - digest-crc (0.6.4) - rake (>= 12.0.0, < 14.0.0) - domain_name (0.5.20190701) - unf (>= 0.0.5, < 1.0.0) - dotenv (2.7.6) - emoji_regex (3.2.3) - escape (0.0.4) - ethon (0.15.0) - ffi (>= 1.15.0) - excon (0.90.0) - faraday (1.9.3) - faraday-em_http (~> 1.0) - faraday-em_synchrony (~> 1.0) - faraday-excon (~> 1.1) - faraday-httpclient (~> 1.0) - faraday-multipart (~> 1.0) - faraday-net_http (~> 1.0) - faraday-net_http_persistent (~> 1.0) - faraday-patron (~> 1.0) - faraday-rack (~> 1.0) - faraday-retry (~> 1.0) - ruby2_keywords (>= 0.0.4) - faraday-cookie_jar (0.0.7) - faraday (>= 0.8.0) - http-cookie (~> 1.0.0) - faraday-em_http (1.0.0) - faraday-em_synchrony (1.0.0) - faraday-excon (1.1.0) - faraday-httpclient (1.0.1) - faraday-multipart (1.0.3) - multipart-post (>= 1.2, < 3) - faraday-net_http (1.0.1) - faraday-net_http_persistent (1.2.0) - faraday-patron (1.0.0) - faraday-rack (1.0.0) - faraday-retry (1.0.3) - faraday_middleware (1.2.0) - faraday (~> 1.0) - fastimage (2.2.6) - fastlane (2.204.0) - CFPropertyList (>= 2.3, < 4.0.0) - addressable (>= 2.8, < 3.0.0) - artifactory (~> 3.0) - aws-sdk-s3 (~> 1.0) - babosa (>= 1.0.3, < 2.0.0) - bundler (>= 1.12.0, < 3.0.0) - colored - commander (~> 4.6) - dotenv (>= 2.1.1, < 3.0.0) - emoji_regex (>= 0.1, < 4.0) - excon (>= 0.71.0, < 1.0.0) - faraday (~> 1.0) - faraday-cookie_jar (~> 0.0.6) - faraday_middleware (~> 1.0) - fastimage (>= 2.1.0, < 3.0.0) - gh_inspector (>= 1.1.2, < 2.0.0) - google-apis-androidpublisher_v3 (~> 0.3) - google-apis-playcustomapp_v1 (~> 0.1) - google-cloud-storage (~> 1.31) - highline (~> 2.0) - json (< 3.0.0) - jwt (>= 2.1.0, < 3) - mini_magick (>= 4.9.4, < 5.0.0) - multipart-post (~> 2.0.0) - naturally (~> 2.2) - optparse (~> 0.1.1) - plist (>= 3.1.0, < 4.0.0) - rubyzip (>= 2.0.0, < 3.0.0) - security (= 0.1.3) - simctl (~> 1.6.3) - terminal-notifier (>= 2.0.0, < 3.0.0) - terminal-table (>= 1.4.5, < 2.0.0) - tty-screen (>= 0.6.3, < 1.0.0) - tty-spinner (>= 0.8.0, < 1.0.0) - word_wrap (~> 1.0.0) - xcodeproj (>= 1.13.0, < 2.0.0) - xcpretty (~> 0.3.0) - xcpretty-travis-formatter (>= 0.0.3) - ffi (1.15.5) - fourflusher (2.3.1) - fuzzy_match (2.0.4) - gh_inspector (1.1.3) - google-apis-androidpublisher_v3 (0.16.0) - google-apis-core (>= 0.4, < 2.a) - google-apis-core (0.4.2) - addressable (~> 2.5, >= 2.5.1) - googleauth (>= 0.16.2, < 2.a) - httpclient (>= 2.8.1, < 3.a) - mini_mime (~> 1.0) - representable (~> 3.0) - retriable (>= 2.0, < 4.a) - rexml - webrick - google-apis-iamcredentials_v1 (0.10.0) - google-apis-core (>= 0.4, < 2.a) - google-apis-playcustomapp_v1 (0.7.0) - google-apis-core (>= 0.4, < 2.a) - google-apis-storage_v1 (0.11.0) - google-apis-core (>= 0.4, < 2.a) - google-cloud-core (1.6.0) - google-cloud-env (~> 1.0) - google-cloud-errors (~> 1.0) - google-cloud-env (1.5.0) - faraday (>= 0.17.3, < 2.0) - google-cloud-errors (1.2.0) - google-cloud-storage (1.36.0) - addressable (~> 2.8) - digest-crc (~> 0.4) - google-apis-iamcredentials_v1 (~> 0.1) - google-apis-storage_v1 (~> 0.1) - google-cloud-core (~> 1.6) - googleauth (>= 0.16.2, < 2.a) - mini_mime (~> 1.0) - googleauth (1.1.0) - faraday (>= 0.17.3, < 2.0) - jwt (>= 1.4, < 3.0) - memoist (~> 0.16) - multi_json (~> 1.11) - os (>= 0.9, < 2.0) - signet (>= 0.16, < 2.a) - highline (2.0.3) - http-cookie (1.0.4) - domain_name (~> 0.5) - httpclient (2.8.3) - i18n (1.12.0) - concurrent-ruby (~> 1.0) - jmespath (1.6.1) - json (2.6.1) - jwt (2.3.0) - memoist (0.16.2) - mini_magick (4.11.0) - mini_mime (1.1.2) - minitest (5.18.0) - molinillo (0.8.0) - multi_json (1.15.0) - multipart-post (2.0.0) - nanaimo (0.3.0) - nap (1.1.0) - naturally (2.2.1) - netrc (0.11.0) - optparse (0.1.1) - os (1.1.4) - plist (3.6.0) - public_suffix (4.0.6) - rake (13.0.6) - representable (3.1.1) - declarative (< 0.1.0) - trailblazer-option (>= 0.1.1, < 0.2.0) - uber (< 0.2.0) - retriable (3.1.2) - rexml (3.2.5) - rouge (2.0.7) - ruby-macho (2.5.1) - ruby2_keywords (0.0.5) - rubyzip (2.3.2) - security (0.1.3) - signet (0.16.0) - addressable (~> 2.8) - faraday (>= 0.17.3, < 2.0) - jwt (>= 1.5, < 3.0) - multi_json (~> 1.10) - simctl (1.6.8) - CFPropertyList - naturally - terminal-notifier (2.0.0) - terminal-table (1.8.0) - unicode-display_width (~> 1.1, >= 1.1.1) - trailblazer-option (0.1.2) - tty-cursor (0.7.1) - tty-screen (0.8.1) - tty-spinner (0.9.3) - tty-cursor (~> 0.7) - typhoeus (1.4.0) - ethon (>= 0.9.0) - tzinfo (2.0.6) - concurrent-ruby (~> 1.0) - uber (0.1.0) - unf (0.1.4) - unf_ext - unf_ext (0.0.8) - unicode-display_width (1.8.0) - webrick (1.7.0) - word_wrap (1.0.0) - xcodeproj (1.21.0) - CFPropertyList (>= 2.3.3, < 4.0) - atomos (~> 0.1.3) - claide (>= 1.0.2, < 2.0) - colored2 (~> 3.1) - nanaimo (~> 0.3.0) - rexml (~> 3.2.4) - xcpretty (0.3.0) - rouge (~> 2.0.7) - xcpretty-travis-formatter (1.0.1) - xcpretty (~> 0.2, >= 0.0.7) - zeitwerk (2.6.7) - -PLATFORMS - ruby - -DEPENDENCIES - cocoapods - fastlane - -BUNDLED WITH - 2.2.33 diff --git a/Package.resolved b/Package.resolved new file mode 100644 index 00000000..4e09ffa7 --- /dev/null +++ b/Package.resolved @@ -0,0 +1,16 @@ +{ + "object": { + "pins": [ + { + "package": "yoga", + "repositoryURL": "https://github.com/facebook/yoga.git", + "state": { + "branch": null, + "revision": "042f5013152eb81c1552dec945b88f7b95ca350f", + "version": "3.2.1" + } + } + ] + }, + "version": 1 +} diff --git a/Package.swift b/Package.swift index 91ad59bf..195db8d4 100644 --- a/Package.swift +++ b/Package.swift @@ -1,61 +1,39 @@ -// swift-tools-version:5.3 +// swift-tools-version:5.5 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package( name: "FlexLayout", + platforms: [ + .iOS(.v13), + ], products: [ .library(name: "FlexLayout", targets: ["FlexLayout"]), - .library(name: "FlexLayoutYoga", targets: ["FlexLayoutYoga"]), - .library(name: "FlexLayoutYogaKit", targets: ["FlexLayoutYogaKit"]) + .library(name: "FlexLayout-Dynamic", type: .dynamic, targets: ["FlexLayout"]), ], dependencies: [ + .package(url: "https://github.com/facebook/yoga.git", .upToNextMinor(from: "3.2.1")), ], targets: [ .target( name: "FlexLayout", - dependencies: ["FlexLayoutYoga", "FlexLayoutYogaKit"], + dependencies: ["FlexLayoutYogaKit"], path: "Sources/Swift", - cSettings: [ - .define("FLEXLAYOUT_SWIFT_PACKAGE") - ], - cxxSettings: [ - .define("FLEXLAYOUT_SWIFT_PACKAGE"), - .headerSearchPath("include/yoga/"), - .headerSearchPath("./") - ], - swiftSettings: [ - .define("FLEXLAYOUT_SWIFT_PACKAGE") - ] - ), - .target( - name: "FlexLayoutYoga", - dependencies: [], - path: "Sources/yoga", - cSettings: [ - .define("FLEXLAYOUT_SWIFT_PACKAGE") - ], - cxxSettings: [ - .define("FLEXLAYOUT_SWIFT_PACKAGE"), - .headerSearchPath("include/yoga/"), - .headerSearchPath("./") - ] + publicHeadersPath: "Public" ), .target( name: "FlexLayoutYogaKit", - dependencies: ["FlexLayoutYoga"], + dependencies: ["yoga"], path: "Sources/YogaKit", - cSettings: [ - .define("FLEXLAYOUT_SWIFT_PACKAGE") - ], - cxxSettings: [ - .define("FLEXLAYOUT_SWIFT_PACKAGE"), - .headerSearchPath("include/YogaKit/"), - .headerSearchPath("./") + publicHeadersPath: "include/YogaKit" + ), + .testTarget( + name: "FlexLayoutTests", + dependencies: [ + "FlexLayout", ] - ) + ), ], - cLanguageStandard: .gnu99, - cxxLanguageStandard: .gnucxx11 + cxxLanguageStandard: CXXLanguageStandard(rawValue: "c++20") ) diff --git a/Podfile b/Podfile index d1d7c836..d8cd6d4d 100644 --- a/Podfile +++ b/Podfile @@ -1,24 +1,24 @@ source 'https://cdn.cocoapods.org/' -use_frameworks! -platform :ios, '12.0' +use_frameworks! :linkage => :static +platform :ios, '13.4' workspace 'FlexLayout.xcworkspace' +target 'FlexLayout' do + pod 'Yoga' +end + target 'FlexLayoutTests' do project 'FlexLayout.xcodeproj' - pod 'FlexLayout', :path => './' - - pod 'Quick' - pod 'Nimble', :inhibit_warnings => true + pod 'FlexLayout', path: './' end target 'FlexLayoutSample' do - project 'Example/FlexLayoutSample.xcodeproj' + project 'Example/cocoapods/FlexLayoutSample.xcodeproj' - pod 'FlexLayout', :path => './' + pod 'FlexLayout', path: './' pod 'PinLayout' # Debug only pod 'SwiftLint' end - diff --git a/Podfile.lock b/Podfile.lock index 153da16a..9899cd7a 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,35 +1,32 @@ PODS: - - FlexLayout (2.0.01) - - Nimble (10.0.0) - - PinLayout (1.10.4) - - Quick (5.0.1) - - SwiftLint (0.53.0) + - FlexLayout (2.2.1): + - Yoga (= 3.2.1) + - PinLayout (1.10.5) + - SwiftLint (0.55.1) + - Yoga (3.2.1) DEPENDENCIES: - FlexLayout (from `./`) - - Nimble - PinLayout - - Quick - SwiftLint + - Yoga SPEC REPOS: trunk: - - Nimble - PinLayout - - Quick - SwiftLint + - Yoga EXTERNAL SOURCES: FlexLayout: :path: "./" SPEC CHECKSUMS: - FlexLayout: c7a8d036bb9ca2fc79f4ced41fd93a55691c70a4 - Nimble: 5316ef81a170ce87baf72dd961f22f89a602ff84 - PinLayout: f8a677ce0cd1cfe96b58435d029b4ceb4ce9c04c - Quick: 749aa754fd1e7d984f2000fe051e18a3a9809179 - SwiftLint: 5ce4d6a8ff83f1b5fd5ad5dbf30965d35af65e44 + FlexLayout: fe365fe6e4a7bf1a53b7421a75acf4c7991e3575 + PinLayout: f6c2b63a5a5b24864064e1d15c67de41b4e74748 + SwiftLint: 3fe909719babe5537c552ee8181c0031392be933 + Yoga: 636ce73bd247407928a7df089f3bc3675916b3ff -PODFILE CHECKSUM: 0be37cb7e189fd6f408603b8354f9ef92b64a46c +PODFILE CHECKSUM: e95bd8fefde1bd2741249ea540133b9a4393b01f -COCOAPODS: 1.11.2 +COCOAPODS: 1.16.2 diff --git a/README.md b/README.md index e7d2da89..bb5d117e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ + +

FlexLayout

@@ -21,9 +23,9 @@ Flexbox is an incredible improvement over UIStackView. It is simpler to use, muc ### Requirements -* iOS 8.0+ -* Xcode 8.0+ / Xcode 9.0+ -* Swift 3.0+ / Swift 4.0 +* iOS 13.0+ +* Xcode 13.0+ +* Swift 5.5 ### Content @@ -34,7 +36,7 @@ Flexbox is an incredible improvement over UIStackView. It is simpler to use, muc * [Creation, modification and definition of flexbox containers](#create_modify_define_containers) * [Flexbox containers properties](#containers_properties) * [Flexbox items properties](#intems_properties) - * [Absolute positioning](#absolute_positioning) + * [Positioning](#positioning) * [Adjusting the size](#adjusting_size) * [Width, height and size](#width_height_size) * [minWidth, maxWidth, minHeight, maxHeight](#minmax_width_height_size) @@ -409,7 +411,7 @@ Another possible solution: ### layout() - Applies to: `flex containers` - Values: `fitContainer` / `adjustWidth` / `adjustHeight` -- Default value: `fitContainer ` +- Default value: `fitContainer` **Method:** @@ -419,8 +421,8 @@ The method will layout the flex container's children. Layout modes: * **`fitContainer`**: This is the default mode when no parameter is specified. Children are layouted **inside** the container's size (width and height). - * **`adjustHeight `**: In this mode, children are layouted **using only the container's width**. The container's height will be adjusted to fit the flexbox's children - * **`adjustWidth `**: In this mode, children are layouted **using only the container's height**. The container's width will be adjusted to fit the flexbox's children + * **`adjustHeight`**: In this mode, children are layouted **using only the container's width**. The container's height will be adjusted to fit the flexbox's children + * **`adjustWidth`**: In this mode, children are layouted **using only the container's height**. The container's width will be adjusted to fit the flexbox's children ###### Usage examples: ```swift @@ -513,7 +515,7 @@ The `justifyContent` property defines the alignment along the main-axis of the c ### alignItems() - Applies to: `flex containers` - Values: `stretch` / `start` / `end` / `center` / `baseline` -- Default value: `stretch ` +- Default value: `stretch` - CSS name: `align-items` **Method:** @@ -578,7 +580,7 @@ Reminder: the cross axis is the axis perpendicular to the main axis. Its directi ### alignContent() - Applies to: `flex containers` -- Values: `start` / `end` / `center` / `stretch` / `spaceBetween` / `spaceAround` +- Values: `start` / `end` / `center` / `stretch` / `spaceBetween` / `spaceAround` / `spaceEvenly` - Default value: `start` - CSS name: `align-content` @@ -598,6 +600,7 @@ Note, `alignContent` has no effect when the flexbox has only a single line. | **stretch** | | | | **spaceBetween** | | | | **spaceAround** | | | +| **spaceEvenly** | | |
@@ -662,7 +665,7 @@ It specifies the "flex shrink factor", which determines how much the flex item w
### basis -- Applies to: `flex items ` +- Applies to: `flex items` - Default value: 0 - CSS name: `flex-basis` @@ -679,6 +682,23 @@ This property takes the same values as the width and height properties, and spec
+### gap +- Applies to: `flex containers` +- CSS name: `gap` + +**Method:** + +* **`columnGap(_ value: CGFloat)`** +This property set distance between columns. + +* **`rowGap(_ value: CGFloat)`** +This property set distance between rows. + +* **`gap(_ value: CGFloat)`** +This property set distance between both of rows and columns. + +
+ ### isIncludedInLayout() - Applies to: `flex items` @@ -702,6 +722,26 @@ FlexLayout automatically includes the UIView when: Set the item display or not, with `none` value, the item will be hidden and not included in the layout. +Values: +* **`flex`**: Default value. The item is displayed normally and included in the layout. +* **`none`**: The item will be hidden and not included in the layout. +* **`contents`**: The node is removed from the layout flow, while its children are preserved and hoisted. This allows higher-level UI frameworks to compose wrapper components (e.g., to handle events) without influencing the layout of child nodes. + +
+ +### boxSizing +- Applies to: `flex items` + +**Method:** + +* **`boxSizing(_: BoxSizing)`** + +Set the box sizing mode for the item. This determines how the width and height of an element are calculated. + +Values: +* **`borderBox`**: Default value. With `borderBox`, the specified dimensions (width, height) include the content, padding, and border. This means the overall size of the element is as defined, with padding and border accounted for inside. +* **`contentBox`**: With `contentBox`, the specified dimensions refer only to the content area. Padding and borders are added outside these dimensions, potentially increasing the total size of the element. +
### markDirty() @@ -759,8 +799,8 @@ Item natural size, considering only properties of the view itself. Independent o
- -## 4. Absolute positioning + +## 4. Positioning - Applies to: `flex items` - Parameter: CGFloat @@ -768,16 +808,23 @@ Item natural size, considering only properties of the view itself. Independent o * **`position(_: Position)`** The position property tells Flexbox how you want your item to be positioned within its parent. Position values: - * **`relative (default)`** - * **`absolute`**: The view is positioned using properties: top(), bottom(), left(), right(), start(), end(). + * **`relative (default)`** The view is positioned using Insets properties (top, bottom, left, right, start, end) from its normal position within its flex container and will take up space within the flex container. This node will always form a containing block. + * **`absolute`**: The view is removed from the flex container's flow and is positioned using Insets properties (top, bottom, left, right, start, end). Insets will offset the node from its containing block. + * **`static`**: The view ignores insets and will not form a containing block. ###### Usage examples: ```swift + view.flex.position(.relative).top(10).left(10).size(50) + view.flex.position(.absolute).top(10).left(10).size(50) ``` ### top(), bottom(), left(), right(), start(), end(), vertically(), horizontally(), all() -A flex item which is `position` is set to `.absolute` is positioned absolutely in regards to its parent. This is done through the following methods: +A flex item with position set to .relative is positioned relative to its normal position within its flex container. Only one property can be applied in each direction, either vertical or horizontal. If both `top` and `bottom` properties are set, `top` takes precedence. If both `left` and `right` properties are set, `left` takes precedence. + +A flex item with position set to .absolute is positioned absolutely with respect to its containing block. Using these properties you can control the size and position of an absolute item within its parent. Because absolutely positioned children don’t affect their sibling's layout. Absolute position can be used to create overlays and stack children in the Z axis. + +This is done through the following methods: **Methods:** @@ -800,10 +847,10 @@ Controls the distance child’s left and right edges from the parent’s edges. * **`all(: CGFloat)`** / **`all(: FPercent)`**: Controls the distance child’s edges from the parent’s edges. Equal to `top().bottom().left().right()`. -Using these properties you can control the size and position of an absolute item within its parent. Because absolutely positioned children don’t affect their sibling's layout. Absolute position can be used to create overlays and stack children in the Z axis. - ###### Usage examples: ```swift + view.flex.position(.relative).top(10).right(10).width(100).height(50) + view.flex.position(.absolute).top(10).right(10).width(100).height(50) view.flex.position(.absolute).left(20%).right(20%) ``` @@ -1106,8 +1153,14 @@ To integrate FlexLayout into your Xcode project using Carthage: github "layoutBox/FlexLayout" ``` -2. Run `carthage update` to build frameworks. -3. Add built `FlexLayout.framework` in your Xcode project in the **Embedded Binaries** section. +2. Run the following commands to resolve dependencies and build: +```bash +carthage update --no-build +(cd ./Carthage/Checkouts/FlexLayout && pod install) +carthage build --use-xcframeworks +``` + +3. Add built `FlexLayout.xcframework` in your Xcode project in the **Embedded Binaries** section. ### Swift Package Manager @@ -1122,8 +1175,7 @@ To integrate FlexLayout into another Swift Package, add it as a dependency: #### In an Xcode target -1. To integrate FlexLayout into an Xcode target, use the `File -> Swift Packages -> Add Package Dependency` menu item. -2. Add "FLEXLAYOUT_SWIFT_PACKAGE=1" to the Xcode target's `GCC_PREPROCESSOR_DEFINITIONS` build setting. (TARGET -> Build Settings -> Apple Clang-Preprocessing -> Preprocessor Macros) +To integrate FlexLayout into an Xcode target, use the `File -> Swift Packages -> Add Package Dependency` menu item.
diff --git a/Sources/SupportingFiles/Info.plist b/Sources/SupportingFiles/Info.plist deleted file mode 100644 index fbe1e6b3..00000000 --- a/Sources/SupportingFiles/Info.plist +++ /dev/null @@ -1,24 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - FMWK - CFBundleShortVersionString - 1.0 - CFBundleVersion - $(CURRENT_PROJECT_VERSION) - NSPrincipalClass - - - diff --git a/Sources/Swift/FlexLayout.swift b/Sources/Swift/FlexLayout.swift index 374831b7..1d7782d3 100644 --- a/Sources/Swift/FlexLayout.swift +++ b/Sources/Swift/FlexLayout.swift @@ -13,7 +13,8 @@ // Created by Luc Dion on 2017-06-19. import UIKit -#if FLEXLAYOUT_SWIFT_PACKAGE + +#if SWIFT_PACKAGE import FlexLayoutYogaKit #endif @@ -25,6 +26,7 @@ import FlexLayoutYogaKit label.flex.margin(10) ``` */ +@MainActor public final class Flex { // @@ -57,9 +59,12 @@ public final class Flex { // /** - This method adds a flex item (UIView) to a flex container. Internally the methods adds the UIView has subviews and enables flexbox. + Adds a flex item (`UIView`) to the receiver and returns the item's flex interface. + + This method internally creates a new `UIView` instance corresponding to the flex item, + and is useful for adding a flex item/container when you don't need to refer to it later. - - Returns: The added view flex interface + - Returns: The flex interface corresponding to the added view. */ @discardableResult public func addItem() -> Flex { @@ -68,11 +73,12 @@ public final class Flex { } /** - This method is similar to `addItem(: UIView)` except that it also creates the flex item's UIView. Internally the method creates an - UIView, adds it has subviews and enables flexbox. This is useful to add a flex item/container easily when you don't need to refer to it later. + Adds a flex item (`UIView`) to the receiver and returns the item's flex interface. - - Parameter view: view to add to the flex container - - Returns: The added view flex interface + This method enables flexbox for `view` and adds it as a subview of the receiver's associated host view. + + - Parameter view: The view to be added. + - Returns: The flex interface corresponding to the added view. */ @discardableResult public func addItem(_ view: UIView) -> Flex { @@ -133,7 +139,7 @@ public final class Flex { flexbox's UIView is excluded, FlexLayout won't layout the view and its children views. - Parameter included: true to layout the view - - Returns: + - Returns: Flex interface */ @discardableResult public func isIncludedInLayout(_ included: Bool) -> Flex { @@ -230,7 +236,7 @@ public final class Flex { root of your layout tree. - Parameter value: new LayoutDirection - - Returns: + - Returns: Flex interface */ @discardableResult public func layoutDirection(_ value: LayoutDirection) -> Flex { @@ -515,7 +521,7 @@ public final class Flex { media types. AspectRatio accepts any floating point value > 0, the default is undefined. - Parameter value: - - Returns: + - Returns: Flex interface */ @discardableResult public func aspectRatio(_ value: CGFloat?) -> Flex { @@ -529,7 +535,7 @@ public final class Flex { media types. AspectRatio accepts any floating point value > 0, the default is undefined. - Parameter value: - - Returns: + - Returns: Flex interface */ @discardableResult public func aspectRatio(of imageView: UIImageView) -> Flex { @@ -540,7 +546,7 @@ public final class Flex { } // - // MARK: Absolute positionning + // MARK: Position / Inset // /** @@ -556,7 +562,7 @@ public final class Flex { /** Set the left edge distance from the container left edge in pixels. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. */ @discardableResult public func left(_ value: CGFloat) -> Flex { @@ -566,7 +572,7 @@ public final class Flex { /** Set the left edge distance from the container left edge in percentage of its container width. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. */ @discardableResult public func left(_ percent: FPercent) -> Flex { @@ -576,7 +582,7 @@ public final class Flex { /** Set the top edge distance from the container top edge in pixels. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. */ @discardableResult public func top(_ value: CGFloat) -> Flex { @@ -586,7 +592,7 @@ public final class Flex { /** Set the top edge distance from the container top edge in percentage of its container height. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. */ @discardableResult public func top(_ percent: FPercent) -> Flex { @@ -596,7 +602,7 @@ public final class Flex { /** Set the right edge distance from the container right edge in pixels. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. */ @discardableResult public func right(_ value: CGFloat) -> Flex { @@ -606,7 +612,7 @@ public final class Flex { /** Set the right edge distance from the container right edge in percentage of its container width. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. */ @discardableResult public func right(_ percent: FPercent) -> Flex { @@ -616,7 +622,7 @@ public final class Flex { /** Set the bottom edge distance from the container bottom edge in pixels. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. */ @discardableResult public func bottom(_ value: CGFloat) -> Flex { @@ -626,7 +632,7 @@ public final class Flex { /** Set the bottom edge distance from the container bottom edge in percentage of its container height. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. */ @discardableResult public func bottom(_ percent: FPercent) -> Flex { @@ -636,7 +642,7 @@ public final class Flex { /** Set the start edge (LTR=left, RTL=right) distance from the container start edge in pixels. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. */ @discardableResult public func start(_ value: CGFloat) -> Flex { @@ -647,7 +653,7 @@ public final class Flex { /** Set the start edge (LTR=left, RTL=right) distance from the container start edge in percentage of its container width. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. */ @discardableResult public func start(_ percent: FPercent) -> Flex { @@ -657,7 +663,7 @@ public final class Flex { /** Set the end edge (LTR=right, RTL=left) distance from the container end edge in pixels. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. */ @discardableResult public func end(_ value: CGFloat) -> Flex { @@ -668,7 +674,7 @@ public final class Flex { /** Set the end edge (LTR=right, RTL=left) distance from the container end edge in percentage of its container width. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. */ @discardableResult public func end(_ percent: FPercent) -> Flex { @@ -677,9 +683,10 @@ public final class Flex { } /** - Set the left and right edges distance from the container edges in pixels. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) - */ + Set the left and right edges distance from the container edges in pixels. + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. + For relative position, the right edge will be ignored. + */ @discardableResult public func horizontally(_ value: CGFloat) -> Flex { yoga.left = YGValue(value) @@ -687,10 +694,11 @@ public final class Flex { return self } - /** - Set the left and right edges distance from the container edges in percentage of its container width. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) - */ + /** + Set the left and right edges distance from the container edges in percentage of its container width. + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. + For relative position, the right edge will be ignored. + */ @discardableResult public func horizontally(_ percent: FPercent) -> Flex { yoga.left = YGValue(value: Float(percent.value), unit: .percent) @@ -700,7 +708,8 @@ public final class Flex { /** Set the top and bottom edges distance from the container edges in pixels. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. + For relative position, the bottom edge will be ignored. */ @discardableResult public func vertically(_ value: CGFloat) -> Flex { @@ -711,7 +720,8 @@ public final class Flex { /** Set the top and bottom edges distance from the container edges in percentage of its container height. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. + For relative position, the bottom edge will be ignored. */ @discardableResult public func vertically(_ percent: FPercent) -> Flex { @@ -722,7 +732,8 @@ public final class Flex { /** Set all edges distance from the container edges in pixels. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. + For relative position, the bottom and right edges will be ignored. */ @discardableResult public func all(_ value: CGFloat) -> Flex { @@ -735,7 +746,8 @@ public final class Flex { /** Set all edges distance from the container edges in percentage of its container size. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. + For relative position, the bottom and right edges will be ignored. */ @discardableResult public func all(_ percent: FPercent) -> Flex { @@ -880,7 +892,7 @@ public final class Flex { /** Set all margins using UIEdgeInsets. - This method is particularly useful to set all margins using iOS 11 `UIView.safeAreaInsets`. + This method is particularly useful to set all margins using `UIView.safeAreaInsets`. */ @discardableResult public func margin(_ insets: UIEdgeInsets) -> Flex { @@ -893,11 +905,8 @@ public final class Flex { /** Set margins using NSDirectionalEdgeInsets. - This method is particularly to set all margins using iOS 11 `UIView.directionalLayoutMargins`. - - Available only on iOS 11 and higher. + This method is particularly to set all margins using `UIView.directionalLayoutMargins`. */ - @available(tvOS 11.0, iOS 11.0, *) @discardableResult public func margin(_ directionalInsets: NSDirectionalEdgeInsets) -> Flex { yoga.marginTop = YGValue(directionalInsets.top) @@ -1113,7 +1122,7 @@ public final class Flex { /** Set paddings using UIEdgeInsets. - This method is particularly useful to set all paddings using iOS 11 `UIView.safeAreaInsets`. + This method is particularly useful to set all paddings using `UIView.safeAreaInsets`. */ @discardableResult public func padding(_ insets: UIEdgeInsets) -> Flex { @@ -1126,11 +1135,8 @@ public final class Flex { /** Set paddings using NSDirectionalEdgeInsets. - This method is particularly to set all paddings using iOS 11 `UIView.directionalLayoutMargins`. - - Available only on iOS 11 and higher. + This method is particularly to set all paddings using `UIView.directionalLayoutMargins`. */ - @available(tvOS 11.0, iOS 11.0, *) @discardableResult public func padding(_ directionalInsets: NSDirectionalEdgeInsets) -> Flex { yoga.paddingTop = YGValue(directionalInsets.top) @@ -1212,6 +1218,49 @@ public final class Flex { return self } + // + // MARK: Gap + // + + /** + Set distance between columns. + + - Parameters: + - value: distance + - Returns: flex interface + */ + @discardableResult + public func columnGap(_ value: CGFloat) -> Flex { + yoga.columnGap = value + return self + } + + /** + Set distance between rows. + + - Parameters: + - value: distance + - Returns: flex interface + */ + @discardableResult + public func rowGap(_ value: CGFloat) -> Flex { + yoga.rowGap = value + return self + } + + /** + Set distance between both of rows and columns. + + - Parameters: + - value: distance + - Returns: flex interface + */ + @discardableResult + public func gap(_ value: CGFloat) -> Flex { + yoga.gap = value + return self + } + // // MARK: UIView Visual properties // @@ -1280,7 +1329,20 @@ public final class Flex { yoga.display = value.yogaValue return self } - + + // + // MARK: Box Sizing + // + + /** + Set the box sizing + */ + @discardableResult + public func boxSizing(_ value: BoxSizing) -> Flex { + yoga.boxSizing = value.yogaValue + return self + } + // MARK: Enums /** @@ -1328,6 +1390,9 @@ public final class Flex { case spaceBetween /// Lines are evenly distributed in the flex container, with half-size spaces on either end Play it » case spaceAround + /// Lines are evenly distributed in the flex container + /// The size of gaps between children and between the parent's edges and the first/last child will all be equal + case spaceEvenly } /** @@ -1376,10 +1441,12 @@ public final class Flex { /** */ public enum Position { - /// Default value. + /// Default value. Positioned according to the flex container's flow. The item is positioned using Insets properties (top, bottom, left, right, start, end) from its normal position within its flex container and will take up space within the flex container. This node will always form a containing block. case relative - /// Positioned absolutely in regards to its container. The item is positionned using properties top, bottom, left, right, start, end. + /// Positioned absolutely, removed from the flex container's flow. The item is positioned using Insets properties (top, bottom, left, right, start, end). Insets will offset the node from its containing block. case absolute + /// Positioned like relative but ignores insets and will not form a containing block. + case `static` } /** @@ -1413,8 +1480,22 @@ public final class Flex { case flex /// With this value, the item will be hidden and not be calculated case none + /// With this value, the node is removed from the layout flow, while its children are preserved and hoisted. + /// This allows higher-level UI frameworks to compose wrapper components (e.g., to handle events) + /// without influencing the layout of child nodes. + case contents } - + + public enum BoxSizing { + /// Default value. + /// With `borderBox`, the specified dimensions (e.g., width, height) include the content, padding, and border. + /// This means the overall size of the element is as defined, with padding and border accounted for inside. + case borderBox + /// With `contentBox`, the specified dimensions refer only to the content area. + /// Padding and borders are added outside these dimensions, potentially increasing the total size of the element. + case contentBox + } + /*public enum Overflow { /// Items that overflow case visible diff --git a/Sources/Swift/Impl/FlexLayout+Enum.swift b/Sources/Swift/Impl/FlexLayout+Enum.swift index 6969fac9..b7da68de 100644 --- a/Sources/Swift/Impl/FlexLayout+Enum.swift +++ b/Sources/Swift/Impl/FlexLayout+Enum.swift @@ -14,63 +14,7 @@ import UIKit -#if FLEXLAYOUT_SWIFT_PACKAGE -import FlexLayoutYoga - -extension YGFlexDirection { - static let column = YGFlexDirectionColumn - static let columnReverse = YGFlexDirectionColumnReverse - static let row = YGFlexDirectionRow - static let rowReverse = YGFlexDirectionRowReverse -} - -extension YGJustify { - static let flexStart = YGJustifyFlexStart - static let center = YGJustifyCenter - static let flexEnd = YGJustifyFlexEnd - static let spaceBetween = YGJustifySpaceBetween - static let spaceAround = YGJustifySpaceAround - static let spaceEvenly = YGJustifySpaceEvenly -} - -extension YGAlign { - static let auto = YGAlignAuto - static let baseline = YGAlignBaseline - static let stretch = YGAlignStretch - static let flexStart = YGAlignFlexStart - static let center = YGAlignCenter - static let flexEnd = YGAlignFlexEnd - static let spaceBetween = YGAlignSpaceBetween - static let spaceAround = YGAlignSpaceAround -} - -extension YGWrap { - static let noWrap = YGWrapNoWrap - static let wrap = YGWrapWrap - static let wrapReverse = YGWrapWrapReverse -} - -extension YGPositionType { - static let relative = YGPositionTypeRelative - static let absolute = YGPositionTypeAbsolute -} - -extension YGDirection { - static let LTR = YGDirectionLTR - static let RTL = YGDirectionRTL - static let inherit = YGDirectionInherit -} - -extension YGDisplay { - static let flex = YGDisplayFlex - static let none = YGDisplayNone -} - -extension YGUnit { - static let percent = YGUnitPercent - static let point = YGUnitPoint -} -#endif +import yoga extension Flex.Direction { var yogaValue: YGFlexDirection { @@ -105,6 +49,7 @@ extension Flex.AlignContent { case .end: return YGAlign.flexEnd case .spaceBetween: return YGAlign.spaceBetween case .spaceAround: return YGAlign.spaceAround + case .spaceEvenly: return YGAlign.spaceEvenly } } } @@ -149,6 +94,7 @@ extension Flex.Position { switch self { case .relative: return YGPositionType.relative case .absolute: return YGPositionType.absolute + case .static: return YGPositionType.static } } } @@ -168,6 +114,16 @@ extension Flex.Display { switch self { case .flex: return YGDisplay.flex case .none: return YGDisplay.none + case .contents: return YGDisplay.contents + } + } +} + +extension Flex.BoxSizing { + var yogaValue: YGBoxSizing { + switch self { + case .borderBox: return YGBoxSizing.borderBox + case .contentBox: return YGBoxSizing.contentBox } } } diff --git a/Sources/Swift/Impl/FlexLayout+Private.swift b/Sources/Swift/Impl/FlexLayout+Private.swift index f2aabbae..9e57ae90 100644 --- a/Sources/Swift/Impl/FlexLayout+Private.swift +++ b/Sources/Swift/Impl/FlexLayout+Private.swift @@ -7,9 +7,8 @@ // import UIKit -#if FLEXLAYOUT_SWIFT_PACKAGE -import FlexLayoutYoga -#endif + +import yoga extension Flex { func valueOrUndefined(_ value: CGFloat?) -> YGValue { diff --git a/Sources/Swift/Impl/UIView+FlexLayout.swift b/Sources/Swift/Impl/UIView+FlexLayout.swift index cb8ec2c0..c617c177 100644 --- a/Sources/Swift/Impl/UIView+FlexLayout.swift +++ b/Sources/Swift/Impl/UIView+FlexLayout.swift @@ -14,6 +14,7 @@ import UIKit +@MainActor private var flexLayoutAssociatedObjectHandle = 72_399_923 extension UIView { diff --git a/Sources/Swift/Percent.swift b/Sources/Swift/Percent.swift index 3dd4b33e..e70b7b3d 100644 --- a/Sources/Swift/Percent.swift +++ b/Sources/Swift/Percent.swift @@ -24,6 +24,7 @@ public struct FPercent { } postfix operator % + public postfix func % (v: CGFloat) -> FPercent { return FPercent(value: v) } diff --git a/Sources/SupportingFiles/FlexLayout.h b/Sources/Swift/Public/FlexLayout.h similarity index 92% rename from Sources/SupportingFiles/FlexLayout.h rename to Sources/Swift/Public/FlexLayout.h index 20751c2a..efe2d199 100644 --- a/Sources/SupportingFiles/FlexLayout.h +++ b/Sources/Swift/Public/FlexLayout.h @@ -24,7 +24,7 @@ FOUNDATION_EXPORT double FlexLayoutVersionNumber; FOUNDATION_EXPORT const unsigned char FlexLayoutVersionString[]; // In this header, you should import all the public headers of your framework using -#import "Yoga.h" -#import "YGEnums.h" -#import "YGMacros.h" -#import "YGValue.h" +#import +#import +#import +#import diff --git a/Sources/Swift/YGLayoutExtensions.swift b/Sources/Swift/YGLayoutExtensions.swift index d34fd1cd..fea92daa 100644 --- a/Sources/Swift/YGLayoutExtensions.swift +++ b/Sources/Swift/YGLayoutExtensions.swift @@ -5,12 +5,9 @@ * LICENSE file in the root directory of this source tree. */ -#if FLEXLAYOUT_SWIFT_PACKAGE import CoreGraphics -import FlexLayoutYoga -#endif -postfix operator % +import yoga extension Int { public static postfix func %(value: Int) -> YGValue { diff --git a/Sources/YogaKit/YGLayout.mm b/Sources/YogaKit/YGLayout.mm index 7239bcb5..311b2d64 100644 --- a/Sources/YogaKit/YGLayout.mm +++ b/Sources/YogaKit/YGLayout.mm @@ -227,11 +227,13 @@ - (void)markDirty { // the measure function. Since we already know that this is a leaf, // this *should* be fine. Forgive me Hack Gods. const YGNodeRef node = self.node; - if (!YGNodeHasMeasureFunc(node)) { + if (!YGNodeHasMeasureFunc(node) && self.numberOfChildren == 0) { YGNodeSetMeasureFunc(node, YGMeasureView); } - YGNodeMarkDirty(node); + if (YGNodeHasMeasureFunc(node)) { + YGNodeMarkDirty(node); + } } - (NSUInteger)numberOfChildren { @@ -273,6 +275,7 @@ - (void)setPosition:(YGPositionType)position { YG_PROPERTY(YGWrap, flexWrap, FlexWrap) YG_PROPERTY(YGOverflow, overflow, Overflow) YG_PROPERTY(YGDisplay, display, Display) +YG_PROPERTY(YGBoxSizing, boxSizing, BoxSizing) YG_PROPERTY(CGFloat, flex, Flex) YG_PROPERTY(CGFloat, flexGrow, FlexGrow) @@ -365,7 +368,7 @@ - (CGSize)calculateLayoutWithSize:(CGSize)size { #pragma mark - Private static float YGMeasureBaselineLabel( - YGNodeRef node, + YGNodeConstRef node, const float width, const float height) { @@ -374,7 +377,7 @@ static float YGMeasureBaselineLabel( } static float YGMeasureBaselineTextView( - YGNodeRef node, + YGNodeConstRef node, const float width, const float height) { @@ -383,7 +386,7 @@ static float YGMeasureBaselineTextView( } static float YGMeasureBaselineTextField( - YGNodeRef node, + YGNodeConstRef node, const float width, const float height) { @@ -401,7 +404,7 @@ static float YGMeasureBaselineTextField( } static YGSize YGMeasureView( - YGNodeRef node, + YGNodeConstRef node, float width, YGMeasureMode widthMode, float height, @@ -489,7 +492,12 @@ static void YGAttachNodesFromViewHierachy(UIView* const view) { if (!YGNodeHasExactSameChildren(node, subviewsToInclude)) { YGRemoveAllChildren(node); for (int i = 0; i < subviewsToInclude.count; i++) { - YGNodeInsertChild(node, subviewsToInclude[i].yoga.node, i); + YGNodeRef child = subviewsToInclude[i].yoga.node; + YGNodeRef parent = YGNodeGetParent(child); + if (parent != NULL) { + YGNodeRemoveChild(parent, child); + } + YGNodeInsertChild(node, child, i); } } @@ -517,6 +525,18 @@ static CGFloat YGRoundPixelValue(CGFloat value) { return roundf(value * scale) / scale; } +static CGPoint YGPointReplacingNanWithZero(CGPoint const value) { + CGPoint result = value; + + if (isnan(result.x)) { + result.x = 0; + } + if (isnan(result.y)) { + result.y = 0; + } + return result; +} + static void YGApplyLayoutToViewHierarchy(UIView* view, BOOL preserveOrigin) { NSCAssert( [NSThread isMainThread], @@ -529,22 +549,15 @@ static void YGApplyLayoutToViewHierarchy(UIView* view, BOOL preserveOrigin) { } YGNodeRef node = yoga.node; - const CGPoint topLeft = { + const CGPoint topLeft = YGPointReplacingNanWithZero({ YGNodeLayoutGetLeft(node), YGNodeLayoutGetTop(node), - }; + }); - CGPoint bottomRight = { + const CGPoint bottomRight = YGPointReplacingNanWithZero({ topLeft.x + YGNodeLayoutGetWidth(node), topLeft.y + YGNodeLayoutGetHeight(node), - }; - - if (isnan(bottomRight.x)) { - bottomRight.x = 0; - } - if (isnan(bottomRight.y)) { - bottomRight.y = 0; - } + }); const CGPoint origin = preserveOrigin ? view.frame.origin : CGPointZero; view.frame = (CGRect){ diff --git a/Sources/YogaKit/include/YogaKit/YGLayout+Private.h b/Sources/YogaKit/include/YogaKit/YGLayout+Private.h index d0d99faf..63fd8c79 100644 --- a/Sources/YogaKit/include/YogaKit/YGLayout+Private.h +++ b/Sources/YogaKit/include/YogaKit/YGLayout+Private.h @@ -5,11 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -#if FLEXLAYOUT_SWIFT_PACKAGE #import -#else -#import "Yoga.h" -#endif #import "YGLayout.h" @interface YGLayout () diff --git a/Sources/YogaKit/include/YogaKit/YGLayout.h b/Sources/YogaKit/include/YogaKit/YGLayout.h index de622d3f..fef5ad41 100644 --- a/Sources/YogaKit/include/YogaKit/YGLayout.h +++ b/Sources/YogaKit/include/YogaKit/YGLayout.h @@ -7,15 +7,9 @@ #import -#if FLEXLAYOUT_SWIFT_PACKAGE #import #import #import -#else -#import "YGEnums.h" -#import "YGMacros.h" -#import "Yoga.h" -#endif YG_EXTERN_C_BEGIN @@ -70,6 +64,7 @@ typedef NS_OPTIONS(NSInteger, YGDimensionFlexibility) { @property(nonatomic, readwrite, assign) YGWrap flexWrap; @property(nonatomic, readwrite, assign) YGOverflow overflow; @property(nonatomic, readwrite, assign) YGDisplay display; +@property(nonatomic, readwrite, assign) YGBoxSizing boxSizing; @property(nonatomic, readwrite, assign) CGFloat flex; @property(nonatomic, readwrite, assign) CGFloat flexGrow; @@ -121,6 +116,10 @@ typedef NS_OPTIONS(NSInteger, YGDimensionFlexibility) { // Yoga specific properties, not compatible with flexbox specification @property(nonatomic, readwrite, assign) CGFloat aspectRatio; +@property(nonatomic, readwrite, assign) CGFloat columnGap; +@property(nonatomic, readwrite, assign) CGFloat rowGap; +@property(nonatomic, readwrite, assign) CGFloat gap; + /** Get the resolved direction of this node. This won't be YGDirectionInherit */ diff --git a/Sources/yoga/BitUtils.h b/Sources/yoga/BitUtils.h deleted file mode 100644 index be2a84e9..00000000 --- a/Sources/yoga/BitUtils.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include -#include - -#include "YGEnums.h" - -namespace facebook { -namespace yoga { - -namespace detail { - -// std::bitset with one bit for each option defined in YG_ENUM_SEQ_DECL -template -using EnumBitset = std::bitset()>; - -constexpr size_t log2ceilFn(size_t n) { - return n < 1 ? 0 : (1 + log2ceilFn(n / 2)); -} - -constexpr int mask(size_t bitWidth, size_t index) { - return ((1 << bitWidth) - 1) << index; -} - -// The number of bits necessary to represent enums defined with YG_ENUM_SEQ_DECL -template -constexpr size_t bitWidthFn() { - static_assert( - enums::count() > 0, "Enums must have at least one entries"); - return log2ceilFn(enums::count() - 1); -} - -template -constexpr Enum getEnumData(int flags, size_t index) { - return static_cast((flags & mask(bitWidthFn(), index)) >> index); -} - -template -void setEnumData(uint32_t& flags, size_t index, int newValue) { - flags = (flags & ~mask(bitWidthFn(), index)) | - ((newValue << index) & (mask(bitWidthFn(), index))); -} - -template -void setEnumData(uint8_t& flags, size_t index, int newValue) { - flags = (flags & ~static_cast(mask(bitWidthFn(), index))) | - ((newValue << index) & - (static_cast(mask(bitWidthFn(), index)))); -} - -constexpr bool getBooleanData(int flags, size_t index) { - return (flags >> index) & 1; -} - -inline void setBooleanData(uint8_t& flags, size_t index, bool value) { - if (value) { - flags |= 1 << index; - } else { - flags &= ~(1 << index); - } -} - -} // namespace detail -} // namespace yoga -} // namespace facebook diff --git a/Sources/yoga/CMakeLists.txt b/Sources/yoga/CMakeLists.txt deleted file mode 100644 index b6eca1ac..00000000 --- a/Sources/yoga/CMakeLists.txt +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright (c) Meta Platforms, Inc. and affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - - -cmake_minimum_required(VERSION 3.13...3.26) -project(yogacore) -set(CMAKE_VERBOSE_MAKEFILE on) - -if(TARGET yogacore) - return() -endif() - -include(CheckIPOSupported) - -set(YOGA_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..) -include(${YOGA_ROOT}/cmake/project-defaults.cmake) - - -file(GLOB SOURCES CONFIGURE_DEPENDS - ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/**/*.cpp) - -add_library(yogacore STATIC ${SOURCES}) - -# Yoga conditionally uses when building for Android -if (ANDROID) - target_link_libraries(yogacore log) -endif() - -check_ipo_supported(RESULT result) -if(result) - set_target_properties(yogacore PROPERTIES - CMAKE_INTERPROCEDURAL_OPTIMIZATION true) -endif() - -target_include_directories(yogacore - PUBLIC - $ - $) diff --git a/Sources/yoga/CompactValue.h b/Sources/yoga/CompactValue.h deleted file mode 100644 index 1a3b49c9..00000000 --- a/Sources/yoga/CompactValue.h +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include -#include - -#include "YGMacros.h" -#include "YGValue.h" - -#if defined(__has_include) && __has_include() -// needed to be able to evaluate defined(__cpp_lib_bit_cast) -#include -#else -// needed to be able to evaluate defined(__cpp_lib_bit_cast) -#include -#endif - -#ifdef __cpp_lib_bit_cast -#include -#else -#include -#endif - -static_assert( - std::numeric_limits::is_iec559, - "facebook::yoga::detail::CompactValue only works with IEEE754 floats"); - -#ifdef YOGA_COMPACT_VALUE_TEST -#define VISIBLE_FOR_TESTING public: -#else -#define VISIBLE_FOR_TESTING private: -#endif - -namespace facebook { -namespace yoga { -namespace detail { - -// This class stores YGValue in 32 bits. -// - The value does not matter for Undefined and Auto. NaNs are used for their -// representation. -// - To differentiate between Point and Percent, one exponent bit is used. -// Supported the range [0x40, 0xbf] (0xbf is inclusive for point, but -// exclusive for percent). -// - Value ranges: -// points: 1.08420217e-19f to 36893485948395847680 -// 0x00000000 0x3fffffff -// percent: 1.08420217e-19f to 18446742974197923840 -// 0x40000000 0x7f7fffff -// - Zero is supported, negative zero is not -// - values outside of the representable range are clamped -class YOGA_EXPORT CompactValue { - friend constexpr bool operator==(CompactValue, CompactValue) noexcept; - -public: - static constexpr auto LOWER_BOUND = 1.08420217e-19f; - static constexpr auto UPPER_BOUND_POINT = 36893485948395847680.0f; - static constexpr auto UPPER_BOUND_PERCENT = 18446742974197923840.0f; - - template - static CompactValue of(float value) noexcept { - if (value == 0.0f || (value < LOWER_BOUND && value > -LOWER_BOUND)) { - constexpr auto zero = - Unit == YGUnitPercent ? ZERO_BITS_PERCENT : ZERO_BITS_POINT; - return {zero}; - } - - constexpr auto upperBound = - Unit == YGUnitPercent ? UPPER_BOUND_PERCENT : UPPER_BOUND_POINT; - if (value > upperBound || value < -upperBound) { - value = copysignf(upperBound, value); - } - - uint32_t unitBit = Unit == YGUnitPercent ? PERCENT_BIT : 0; - auto data = asU32(value); - data -= BIAS; - data |= unitBit; - return {data}; - } - - template - static CompactValue ofMaybe(float value) noexcept { - return std::isnan(value) || std::isinf(value) ? ofUndefined() - : of(value); - } - - static constexpr CompactValue ofZero() noexcept { - return CompactValue{ZERO_BITS_POINT}; - } - - static constexpr CompactValue ofUndefined() noexcept { - return CompactValue{}; - } - - static constexpr CompactValue ofAuto() noexcept { - return CompactValue{AUTO_BITS}; - } - - constexpr CompactValue() noexcept : repr_(0x7FC00000) {} - - CompactValue(const YGValue& x) noexcept : repr_(uint32_t{0}) { - switch (x.unit) { - case YGUnitUndefined: - *this = ofUndefined(); - break; - case YGUnitAuto: - *this = ofAuto(); - break; - case YGUnitPoint: - *this = of(x.value); - break; - case YGUnitPercent: - *this = of(x.value); - break; - } - } - - operator YGValue() const noexcept { - switch (repr_) { - case AUTO_BITS: - return YGValueAuto; - case ZERO_BITS_POINT: - return YGValue{0.0f, YGUnitPoint}; - case ZERO_BITS_PERCENT: - return YGValue{0.0f, YGUnitPercent}; - } - - if (std::isnan(asFloat(repr_))) { - return YGValueUndefined; - } - - auto data = repr_; - data &= ~PERCENT_BIT; - data += BIAS; - - return YGValue{ - asFloat(data), repr_ & 0x40000000 ? YGUnitPercent : YGUnitPoint}; - } - - bool isUndefined() const noexcept { - return ( - repr_ != AUTO_BITS && repr_ != ZERO_BITS_POINT && - repr_ != ZERO_BITS_PERCENT && std::isnan(asFloat(repr_))); - } - - bool isAuto() const noexcept { return repr_ == AUTO_BITS; } - -private: - uint32_t repr_; - - static constexpr uint32_t BIAS = 0x20000000; - static constexpr uint32_t PERCENT_BIT = 0x40000000; - - // these are signaling NaNs with specific bit pattern as payload they will be - // silenced whenever going through an FPU operation on ARM + x86 - static constexpr uint32_t AUTO_BITS = 0x7faaaaaa; - static constexpr uint32_t ZERO_BITS_POINT = 0x7f8f0f0f; - static constexpr uint32_t ZERO_BITS_PERCENT = 0x7f80f0f0; - - constexpr CompactValue(uint32_t data) noexcept : repr_(data) {} - - VISIBLE_FOR_TESTING uint32_t repr() { return repr_; } - - static uint32_t asU32(float f) { -#ifdef __cpp_lib_bit_cast - return std::bit_cast(f); -#else - uint32_t u; - static_assert( - sizeof(u) == sizeof(f), "uint32_t and float must have the same size"); - std::memcpy(&u, &f, sizeof(f)); - return u; -#endif - } - - static float asFloat(uint32_t u) { -#ifdef __cpp_lib_bit_cast - return std::bit_cast(u); -#else - float f; - static_assert( - sizeof(f) == sizeof(u), "uint32_t and float must have the same size"); - std::memcpy(&f, &u, sizeof(u)); - return f; -#endif - } -}; - -template <> -CompactValue CompactValue::of(float) noexcept = delete; -template <> -CompactValue CompactValue::of(float) noexcept = delete; -template <> -CompactValue CompactValue::ofMaybe(float) noexcept = delete; -template <> -CompactValue CompactValue::ofMaybe(float) noexcept = delete; - -constexpr bool operator==(CompactValue a, CompactValue b) noexcept { - return a.repr_ == b.repr_; -} - -constexpr bool operator!=(CompactValue a, CompactValue b) noexcept { - return !(a == b); -} - -} // namespace detail -} // namespace yoga -} // namespace facebook diff --git a/Sources/yoga/Utils.cpp b/Sources/yoga/Utils.cpp deleted file mode 100644 index 7cc94022..00000000 --- a/Sources/yoga/Utils.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "Utils.h" -#include - -using namespace facebook; - -YGFlexDirection YGFlexDirectionCross( - const YGFlexDirection flexDirection, - const YGDirection direction) { - return YGFlexDirectionIsColumn(flexDirection) - ? YGResolveFlexDirection(YGFlexDirectionRow, direction) - : YGFlexDirectionColumn; -} - -float YGFloatMax(const float a, const float b) { - if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) { - return fmaxf(a, b); - } - return yoga::isUndefined(a) ? b : a; -} - -float YGFloatMin(const float a, const float b) { - if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) { - return fminf(a, b); - } - - return yoga::isUndefined(a) ? b : a; -} - -bool YGValueEqual(const YGValue& a, const YGValue& b) { - if (a.unit != b.unit) { - return false; - } - - if (a.unit == YGUnitUndefined || - (yoga::isUndefined(a.value) && yoga::isUndefined(b.value))) { - return true; - } - - return fabs(a.value - b.value) < 0.0001f; -} - -bool YGFloatsEqual(const float a, const float b) { - if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) { - return fabs(a - b) < 0.0001f; - } - return yoga::isUndefined(a) && yoga::isUndefined(b); -} - -bool YGDoubleEqual(const double a, const double b) { - if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) { - return fabs(a - b) < 0.0001; - } - return yoga::isUndefined(a) && yoga::isUndefined(b); -} - -float YGFloatSanitize(const float val) { - return yoga::isUndefined(val) ? 0 : val; -} - -YGFloatOptional YGFloatOptionalMax(YGFloatOptional op1, YGFloatOptional op2) { - if (op1 >= op2) { - return op1; - } - if (op2 > op1) { - return op2; - } - return op1.isUndefined() ? op2 : op1; -} - -void yoga::throwLogicalErrorWithMessage(const char* message) { -#if defined(__cpp_exceptions) - throw std::logic_error(message); -#else // !defined(__cpp_exceptions) - std::terminate(); -#endif // defined(__cpp_exceptions) -} diff --git a/Sources/yoga/Utils.h b/Sources/yoga/Utils.h deleted file mode 100644 index 376c4fb5..00000000 --- a/Sources/yoga/Utils.h +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "YGNode.h" -#include "Yoga-internal.h" -#include "CompactValue.h" - -// This struct is an helper model to hold the data for step 4 of flexbox algo, -// which is collecting the flex items in a line. -// -// - itemsOnLine: Number of items which can fit in a line considering the -// available Inner dimension, the flex items computed flexbasis and their -// margin. It may be different than the difference between start and end -// indicates because we skip over absolute-positioned items. -// -// - sizeConsumedOnCurrentLine: It 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. -// -// - totalFlexGrowFactors: total flex grow factors of flex items which are to be -// laid in the current line -// -// - totalFlexShrinkFactors: total flex shrink factors of flex items which are -// to be laid in the current line -// -// - endOfLineIndex: Its the end index of the last flex item which was examined -// and it may or may not be part of the current line(as it may be absolutely -// positioned or including it may have caused to overshoot availableInnerDim) -// -// - relativeChildren: Maintain a vector of the child nodes that can shrink -// and/or grow. - -struct YGCollectFlexItemsRowValues { - uint32_t itemsOnLine; - float sizeConsumedOnCurrentLine; - float totalFlexGrowFactors; - float totalFlexShrinkScaledFactors; - uint32_t endOfLineIndex; - std::vector relativeChildren; - float remainingFreeSpace; - // The size of the mainDim for the row after considering size, padding, margin - // and border of flex items. This is used to calculate maxLineDim after going - // through all the rows to decide on the main axis size of owner. - float mainDim; - // The size of the crossDim for the row after considering size, padding, - // margin and border of flex items. Used for calculating containers crossSize. - float crossDim; -}; - -bool YGValueEqual(const YGValue& a, const YGValue& b); -inline bool YGValueEqual( - facebook::yoga::detail::CompactValue a, - facebook::yoga::detail::CompactValue b) { - return YGValueEqual((YGValue) a, (YGValue) b); -} - -// This custom float equality function returns true if either absolute -// difference between two floats is less than 0.0001f or both are undefined. -bool YGFloatsEqual(const float a, const float b); - -bool YGDoubleEqual(const double a, const double b); - -float YGFloatMax(const float a, const float b); - -YGFloatOptional YGFloatOptionalMax( - const YGFloatOptional op1, - const YGFloatOptional op2); - -float YGFloatMin(const float a, const float b); - -// This custom float comparison function compares the array of float with -// YGFloatsEqual, as the default float comparison operator will not work(Look -// at the comments of YGFloatsEqual function). -template -bool YGFloatArrayEqual( - const std::array& val1, - const std::array& val2) { - bool areEqual = true; - for (std::size_t i = 0; i < size && areEqual; ++i) { - areEqual = YGFloatsEqual(val1[i], val2[i]); - } - return areEqual; -} - -// This function returns 0 if YGFloatIsUndefined(val) is true and val otherwise -float YGFloatSanitize(const float val); - -YGFlexDirection YGFlexDirectionCross( - const YGFlexDirection flexDirection, - const YGDirection direction); - -inline bool YGFlexDirectionIsRow(const YGFlexDirection flexDirection) { - return flexDirection == YGFlexDirectionRow || - flexDirection == YGFlexDirectionRowReverse; -} - -inline YGFloatOptional YGResolveValue( - const YGValue value, - const float ownerSize) { - switch (value.unit) { - case YGUnitPoint: - return YGFloatOptional{value.value}; - case YGUnitPercent: - return YGFloatOptional{value.value * ownerSize * 0.01f}; - default: - return YGFloatOptional{}; - } -} - -inline YGFloatOptional YGResolveValue( - facebook::yoga::detail::CompactValue value, - float ownerSize) { - return YGResolveValue((YGValue) value, ownerSize); -} - -inline bool YGFlexDirectionIsColumn(const YGFlexDirection flexDirection) { - return flexDirection == YGFlexDirectionColumn || - flexDirection == YGFlexDirectionColumnReverse; -} - -inline YGFlexDirection YGResolveFlexDirection( - const YGFlexDirection flexDirection, - const YGDirection direction) { - if (direction == YGDirectionRTL) { - if (flexDirection == YGFlexDirectionRow) { - return YGFlexDirectionRowReverse; - } else if (flexDirection == YGFlexDirectionRowReverse) { - return YGFlexDirectionRow; - } - } - - return flexDirection; -} - -inline YGFloatOptional YGResolveValueMargin( - facebook::yoga::detail::CompactValue value, - const float ownerSize) { - return value.isAuto() ? YGFloatOptional{0} : YGResolveValue(value, ownerSize); -} diff --git a/Sources/yoga/YGConfig.cpp b/Sources/yoga/YGConfig.cpp deleted file mode 100644 index 5bf85f4a..00000000 --- a/Sources/yoga/YGConfig.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "YGConfig.h" - -using namespace facebook::yoga; - -namespace facebook { -namespace yoga { -bool configUpdateInvalidatesLayout(YGConfigRef a, YGConfigRef b) { - return a->getErrata() != b->getErrata() || - a->getEnabledExperiments() != b->getEnabledExperiments() || - a->getPointScaleFactor() != b->getPointScaleFactor() || - a->useWebDefaults() != b->useWebDefaults(); -} -} // namespace yoga -} // namespace facebook - -YGConfig::YGConfig(YGLogger logger) : cloneNodeCallback_{nullptr} { - setLogger(logger); -} - -void YGConfig::setUseWebDefaults(bool useWebDefaults) { - flags_.useWebDefaults = useWebDefaults; -} - -bool YGConfig::useWebDefaults() const { - return flags_.useWebDefaults; -} - -void YGConfig::setShouldPrintTree(bool printTree) { - flags_.printTree = printTree; -} - -bool YGConfig::shouldPrintTree() const { - return flags_.printTree; -} - -void YGConfig::setExperimentalFeatureEnabled( - YGExperimentalFeature feature, - bool enabled) { - experimentalFeatures_.set(feature, enabled); -} - -bool YGConfig::isExperimentalFeatureEnabled( - YGExperimentalFeature feature) const { - return experimentalFeatures_.test(feature); -} - -ExperimentalFeatureSet YGConfig::getEnabledExperiments() const { - return experimentalFeatures_; -} - -void YGConfig::setErrata(YGErrata errata) { - errata_ = errata; -} - -void YGConfig::addErrata(YGErrata errata) { - errata_ |= errata; -} - -void YGConfig::removeErrata(YGErrata errata) { - errata_ &= (~errata); -} - -YGErrata YGConfig::getErrata() const { - return errata_; -} - -bool YGConfig::hasErrata(YGErrata errata) const { - return (errata_ & errata) != YGErrataNone; -} - -void YGConfig::setPointScaleFactor(float pointScaleFactor) { - pointScaleFactor_ = pointScaleFactor; -} - -float YGConfig::getPointScaleFactor() const { - return pointScaleFactor_; -} - -void YGConfig::setContext(void* context) { - context_ = context; -} - -void* YGConfig::getContext() const { - return context_; -} - -void YGConfig::setLogger(YGLogger logger) { - logger_.noContext = logger; - flags_.loggerUsesContext = false; -} - -void YGConfig::setLogger(LogWithContextFn logger) { - logger_.withContext = logger; - flags_.loggerUsesContext = true; -} - -void YGConfig::setLogger(std::nullptr_t) { - setLogger(YGLogger{nullptr}); -} - -void YGConfig::log( - YGConfig* config, - YGNode* node, - YGLogLevel logLevel, - void* logContext, - const char* format, - va_list args) const { - if (flags_.loggerUsesContext) { - logger_.withContext(config, node, logLevel, logContext, format, args); - } else { - logger_.noContext(config, node, logLevel, format, args); - } -} - -void YGConfig::setCloneNodeCallback(YGCloneNodeFunc cloneNode) { - cloneNodeCallback_.noContext = cloneNode; - flags_.cloneNodeUsesContext = false; -} - -void YGConfig::setCloneNodeCallback(CloneWithContextFn cloneNode) { - cloneNodeCallback_.withContext = cloneNode; - flags_.cloneNodeUsesContext = true; -} - -void YGConfig::setCloneNodeCallback(std::nullptr_t) { - setCloneNodeCallback(YGCloneNodeFunc{nullptr}); -} - -YGNodeRef YGConfig::cloneNode( - YGNodeRef node, - YGNodeRef owner, - int childIndex, - void* cloneContext) const { - YGNodeRef clone = nullptr; - if (cloneNodeCallback_.noContext != nullptr) { - clone = flags_.cloneNodeUsesContext - ? cloneNodeCallback_.withContext(node, owner, childIndex, cloneContext) - : cloneNodeCallback_.noContext(node, owner, childIndex); - } - if (clone == nullptr) { - clone = YGNodeClone(node); - } - return clone; -} diff --git a/Sources/yoga/YGConfig.h b/Sources/yoga/YGConfig.h deleted file mode 100644 index eae7508a..00000000 --- a/Sources/yoga/YGConfig.h +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "BitUtils.h" -#include "Yoga.h" -#include "Yoga-internal.h" - -namespace facebook { -namespace yoga { - -// Whether moving a node from config "a" to config "b" should dirty previously -// calculated layout results. -bool configUpdateInvalidatesLayout(YGConfigRef a, YGConfigRef b); - -// Internal variants of log functions, currently used only by JNI bindings. -// TODO: Reconcile this with the public API -using LogWithContextFn = int (*)( - YGConfigRef config, - YGNodeRef node, - YGLogLevel level, - void* context, - const char* format, - va_list args); -using CloneWithContextFn = YGNodeRef (*)( - YGNodeRef node, - YGNodeRef owner, - int childIndex, - void* cloneContext); - -using ExperimentalFeatureSet = - facebook::yoga::detail::EnumBitset; - -#pragma pack(push) -#pragma pack(1) -// Packed structure of <32-bit options to miminize size per node. -struct YGConfigFlags { - bool useWebDefaults : 1; - bool printTree : 1; - bool cloneNodeUsesContext : 1; - bool loggerUsesContext : 1; -}; -#pragma pack(pop) - -} // namespace yoga -} // namespace facebook - -struct YOGA_EXPORT YGConfig { - YGConfig(YGLogger logger); - - void setUseWebDefaults(bool useWebDefaults); - bool useWebDefaults() const; - - void setShouldPrintTree(bool printTree); - bool shouldPrintTree() const; - - void setExperimentalFeatureEnabled( - YGExperimentalFeature feature, - bool enabled); - bool isExperimentalFeatureEnabled(YGExperimentalFeature feature) const; - facebook::yoga::ExperimentalFeatureSet getEnabledExperiments() const; - - void setErrata(YGErrata errata); - void addErrata(YGErrata errata); - void removeErrata(YGErrata errata); - YGErrata getErrata() const; - bool hasErrata(YGErrata errata) const; - - void setPointScaleFactor(float pointScaleFactor); - float getPointScaleFactor() const; - - void setContext(void* context); - void* getContext() const; - - void setLogger(YGLogger logger); - void setLogger(facebook::yoga::LogWithContextFn logger); - void setLogger(std::nullptr_t); - void log(YGConfig*, YGNode*, YGLogLevel, void*, const char*, va_list) const; - - void setCloneNodeCallback(YGCloneNodeFunc cloneNode); - void setCloneNodeCallback(facebook::yoga::CloneWithContextFn cloneNode); - void setCloneNodeCallback(std::nullptr_t); - YGNodeRef cloneNode( - YGNodeRef node, - YGNodeRef owner, - int childIndex, - void* cloneContext) const; - -private: - union { - facebook::yoga::CloneWithContextFn withContext; - YGCloneNodeFunc noContext; - } cloneNodeCallback_; - union { - facebook::yoga::LogWithContextFn withContext; - YGLogger noContext; - } logger_; - - facebook::yoga::YGConfigFlags flags_{}; - facebook::yoga::ExperimentalFeatureSet experimentalFeatures_{}; - YGErrata errata_ = YGErrataNone; - float pointScaleFactor_ = 1.0f; - void* context_ = nullptr; -}; diff --git a/Sources/yoga/YGEnums.cpp b/Sources/yoga/YGEnums.cpp deleted file mode 100644 index 53629699..00000000 --- a/Sources/yoga/YGEnums.cpp +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @generated by enums.py - -#include "YGEnums.h" - -const char* YGAlignToString(const YGAlign value) { - switch (value) { - case YGAlignAuto: - return "auto"; - case YGAlignFlexStart: - return "flex-start"; - case YGAlignCenter: - return "center"; - case YGAlignFlexEnd: - return "flex-end"; - case YGAlignStretch: - return "stretch"; - case YGAlignBaseline: - return "baseline"; - case YGAlignSpaceBetween: - return "space-between"; - case YGAlignSpaceAround: - return "space-around"; - } - return "unknown"; -} - -const char* YGDimensionToString(const YGDimension value) { - switch (value) { - case YGDimensionWidth: - return "width"; - case YGDimensionHeight: - return "height"; - } - return "unknown"; -} - -const char* YGDirectionToString(const YGDirection value) { - switch (value) { - case YGDirectionInherit: - return "inherit"; - case YGDirectionLTR: - return "ltr"; - case YGDirectionRTL: - return "rtl"; - } - return "unknown"; -} - -const char* YGDisplayToString(const YGDisplay value) { - switch (value) { - case YGDisplayFlex: - return "flex"; - case YGDisplayNone: - return "none"; - } - return "unknown"; -} - -const char* YGEdgeToString(const YGEdge value) { - switch (value) { - case YGEdgeLeft: - return "left"; - case YGEdgeTop: - return "top"; - case YGEdgeRight: - return "right"; - case YGEdgeBottom: - return "bottom"; - case YGEdgeStart: - return "start"; - case YGEdgeEnd: - return "end"; - case YGEdgeHorizontal: - return "horizontal"; - case YGEdgeVertical: - return "vertical"; - case YGEdgeAll: - return "all"; - } - return "unknown"; -} - -const char* YGErrataToString(const YGErrata value) { - switch (value) { - case YGErrataNone: - return "none"; - case YGErrataStretchFlexBasis: - return "stretch-flex-basis"; - case YGErrataAll: - return "all"; - case YGErrataClassic: - return "classic"; - } - return "unknown"; -} - -const char* YGExperimentalFeatureToString(const YGExperimentalFeature value) { - switch (value) { - case YGExperimentalFeatureWebFlexBasis: - return "web-flex-basis"; - case YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge: - return "absolute-percentage-against-padding-edge"; - case YGExperimentalFeatureFixJNILocalRefOverflows: - return "fix-jnilocal-ref-overflows"; - } - return "unknown"; -} - -const char* YGFlexDirectionToString(const YGFlexDirection value) { - switch (value) { - case YGFlexDirectionColumn: - return "column"; - case YGFlexDirectionColumnReverse: - return "column-reverse"; - case YGFlexDirectionRow: - return "row"; - case YGFlexDirectionRowReverse: - return "row-reverse"; - } - return "unknown"; -} - -const char* YGGutterToString(const YGGutter value) { - switch (value) { - case YGGutterColumn: - return "column"; - case YGGutterRow: - return "row"; - case YGGutterAll: - return "all"; - } - return "unknown"; -} - -const char* YGJustifyToString(const YGJustify value) { - switch (value) { - case YGJustifyFlexStart: - return "flex-start"; - case YGJustifyCenter: - return "center"; - case YGJustifyFlexEnd: - return "flex-end"; - case YGJustifySpaceBetween: - return "space-between"; - case YGJustifySpaceAround: - return "space-around"; - case YGJustifySpaceEvenly: - return "space-evenly"; - } - return "unknown"; -} - -const char* YGLogLevelToString(const YGLogLevel value) { - switch (value) { - case YGLogLevelError: - return "error"; - case YGLogLevelWarn: - return "warn"; - case YGLogLevelInfo: - return "info"; - case YGLogLevelDebug: - return "debug"; - case YGLogLevelVerbose: - return "verbose"; - case YGLogLevelFatal: - return "fatal"; - } - return "unknown"; -} - -const char* YGMeasureModeToString(const YGMeasureMode value) { - switch (value) { - case YGMeasureModeUndefined: - return "undefined"; - case YGMeasureModeExactly: - return "exactly"; - case YGMeasureModeAtMost: - return "at-most"; - } - return "unknown"; -} - -const char* YGNodeTypeToString(const YGNodeType value) { - switch (value) { - case YGNodeTypeDefault: - return "default"; - case YGNodeTypeText: - return "text"; - } - return "unknown"; -} - -const char* YGOverflowToString(const YGOverflow value) { - switch (value) { - case YGOverflowVisible: - return "visible"; - case YGOverflowHidden: - return "hidden"; - case YGOverflowScroll: - return "scroll"; - } - return "unknown"; -} - -const char* YGPositionTypeToString(const YGPositionType value) { - switch (value) { - case YGPositionTypeStatic: - return "static"; - case YGPositionTypeRelative: - return "relative"; - case YGPositionTypeAbsolute: - return "absolute"; - } - return "unknown"; -} - -const char* YGPrintOptionsToString(const YGPrintOptions value) { - switch (value) { - case YGPrintOptionsLayout: - return "layout"; - case YGPrintOptionsStyle: - return "style"; - case YGPrintOptionsChildren: - return "children"; - } - return "unknown"; -} - -const char* YGUnitToString(const YGUnit value) { - switch (value) { - case YGUnitUndefined: - return "undefined"; - case YGUnitPoint: - return "point"; - case YGUnitPercent: - return "percent"; - case YGUnitAuto: - return "auto"; - } - return "unknown"; -} - -const char* YGWrapToString(const YGWrap value) { - switch (value) { - case YGWrapNoWrap: - return "no-wrap"; - case YGWrapWrap: - return "wrap"; - case YGWrapWrapReverse: - return "wrap-reverse"; - } - return "unknown"; -} diff --git a/Sources/yoga/YGFloatOptional.h b/Sources/yoga/YGFloatOptional.h deleted file mode 100644 index 4aa9e76e..00000000 --- a/Sources/yoga/YGFloatOptional.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include -#include "Yoga-internal.h" - -struct YGFloatOptional { -private: - float value_ = std::numeric_limits::quiet_NaN(); - -public: - explicit constexpr YGFloatOptional(float value) : value_(value) {} - constexpr YGFloatOptional() = default; - - // returns the wrapped value, or a value x with YGIsUndefined(x) == true - constexpr float unwrap() const { return value_; } - - bool isUndefined() const { return std::isnan(value_); } -}; - -// operators take YGFloatOptional by value, as it is a 32bit value - -inline bool operator==(YGFloatOptional lhs, YGFloatOptional rhs) { - return lhs.unwrap() == rhs.unwrap() || - (lhs.isUndefined() && rhs.isUndefined()); -} -inline bool operator!=(YGFloatOptional lhs, YGFloatOptional rhs) { - return !(lhs == rhs); -} - -inline bool operator==(YGFloatOptional lhs, float rhs) { - return lhs == YGFloatOptional{rhs}; -} -inline bool operator!=(YGFloatOptional lhs, float rhs) { - return !(lhs == rhs); -} - -inline bool operator==(float lhs, YGFloatOptional rhs) { - return rhs == lhs; -} -inline bool operator!=(float lhs, YGFloatOptional rhs) { - return !(lhs == rhs); -} - -inline YGFloatOptional operator+(YGFloatOptional lhs, YGFloatOptional rhs) { - return YGFloatOptional{lhs.unwrap() + rhs.unwrap()}; -} - -inline bool operator>(YGFloatOptional lhs, YGFloatOptional rhs) { - return lhs.unwrap() > rhs.unwrap(); -} - -inline bool operator<(YGFloatOptional lhs, YGFloatOptional rhs) { - return lhs.unwrap() < rhs.unwrap(); -} - -inline bool operator>=(YGFloatOptional lhs, YGFloatOptional rhs) { - return lhs > rhs || lhs == rhs; -} - -inline bool operator<=(YGFloatOptional lhs, YGFloatOptional rhs) { - return lhs < rhs || lhs == rhs; -} diff --git a/Sources/yoga/YGLayout.cpp b/Sources/yoga/YGLayout.cpp deleted file mode 100644 index 9aadcd4a..00000000 --- a/Sources/yoga/YGLayout.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "YGLayout.h" -#include "Utils.h" - -using namespace facebook; - -bool YGLayout::operator==(YGLayout layout) const { - bool isEqual = YGFloatArrayEqual(position, layout.position) && - YGFloatArrayEqual(dimensions, layout.dimensions) && - YGFloatArrayEqual(margin, layout.margin) && - YGFloatArrayEqual(border, layout.border) && - YGFloatArrayEqual(padding, layout.padding) && - direction() == layout.direction() && - hadOverflow() == layout.hadOverflow() && - lastOwnerDirection == layout.lastOwnerDirection && - nextCachedMeasurementsIndex == layout.nextCachedMeasurementsIndex && - cachedLayout == layout.cachedLayout && - computedFlexBasis == layout.computedFlexBasis; - - for (uint32_t i = 0; i < YG_MAX_CACHED_RESULT_COUNT && isEqual; ++i) { - isEqual = isEqual && cachedMeasurements[i] == layout.cachedMeasurements[i]; - } - - if (!yoga::isUndefined(measuredDimensions[0]) || - !yoga::isUndefined(layout.measuredDimensions[0])) { - isEqual = - isEqual && (measuredDimensions[0] == layout.measuredDimensions[0]); - } - if (!yoga::isUndefined(measuredDimensions[1]) || - !yoga::isUndefined(layout.measuredDimensions[1])) { - isEqual = - isEqual && (measuredDimensions[1] == layout.measuredDimensions[1]); - } - - return isEqual; -} diff --git a/Sources/yoga/YGLayout.h b/Sources/yoga/YGLayout.h deleted file mode 100644 index 166eabb6..00000000 --- a/Sources/yoga/YGLayout.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "BitUtils.h" -#include "YGFloatOptional.h" -#include "Yoga-internal.h" - -struct YGLayout { - std::array position = {}; - std::array dimensions = {{YGUndefined, YGUndefined}}; - std::array margin = {}; - std::array border = {}; - std::array padding = {}; - -private: - static constexpr size_t directionOffset = 0; - static constexpr size_t hadOverflowOffset = - directionOffset + facebook::yoga::detail::bitWidthFn(); - uint8_t flags = 0; - -public: - uint32_t computedFlexBasisGeneration = 0; - YGFloatOptional computedFlexBasis = {}; - - // Instead of recomputing the entire layout every single time, we cache some - // information to break early when nothing changed - uint32_t generationCount = 0; - YGDirection lastOwnerDirection = YGDirectionInherit; - - uint32_t nextCachedMeasurementsIndex = 0; - std::array - cachedMeasurements = {}; - std::array measuredDimensions = {{YGUndefined, YGUndefined}}; - - YGCachedMeasurement cachedLayout = YGCachedMeasurement(); - - YGDirection direction() const { - return facebook::yoga::detail::getEnumData( - flags, directionOffset); - } - - void setDirection(YGDirection direction) { - facebook::yoga::detail::setEnumData( - flags, directionOffset, direction); - } - - bool hadOverflow() const { - return facebook::yoga::detail::getBooleanData(flags, hadOverflowOffset); - } - void setHadOverflow(bool hadOverflow) { - facebook::yoga::detail::setBooleanData( - flags, hadOverflowOffset, hadOverflow); - } - - bool operator==(YGLayout layout) const; - bool operator!=(YGLayout layout) const { return !(*this == layout); } -}; diff --git a/Sources/yoga/YGNode.cpp b/Sources/yoga/YGNode.cpp deleted file mode 100644 index cd323b54..00000000 --- a/Sources/yoga/YGNode.cpp +++ /dev/null @@ -1,584 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "YGNode.h" -#include -#include -#include "Utils.h" - -using namespace facebook; -using facebook::yoga::detail::CompactValue; - -YGNode::YGNode(const YGConfigRef config) : config_{config} { - YGAssert( - config != nullptr, "Attempting to construct YGNode with null config"); - - flags_.hasNewLayout = true; - if (config->useWebDefaults()) { - useWebDefaults(); - } -} - -YGNode::YGNode(YGNode&& node) { - context_ = node.context_; - flags_ = node.flags_; - measure_ = node.measure_; - baseline_ = node.baseline_; - print_ = node.print_; - dirtied_ = node.dirtied_; - style_ = node.style_; - layout_ = node.layout_; - lineIndex_ = node.lineIndex_; - owner_ = node.owner_; - children_ = std::move(node.children_); - config_ = node.config_; - resolvedDimensions_ = node.resolvedDimensions_; - for (auto c : children_) { - c->setOwner(this); - } -} - -void YGNode::print(void* printContext) { - if (print_.noContext != nullptr) { - if (flags_.printUsesContext) { - print_.withContext(this, printContext); - } else { - print_.noContext(this); - } - } -} - -CompactValue YGNode::computeEdgeValueForRow( - const YGStyle::Edges& edges, - YGEdge rowEdge, - YGEdge edge, - CompactValue defaultValue) { - if (!edges[rowEdge].isUndefined()) { - return edges[rowEdge]; - } else if (!edges[edge].isUndefined()) { - return edges[edge]; - } else if (!edges[YGEdgeHorizontal].isUndefined()) { - return edges[YGEdgeHorizontal]; - } else if (!edges[YGEdgeAll].isUndefined()) { - return edges[YGEdgeAll]; - } else { - return defaultValue; - } -} - -CompactValue YGNode::computeEdgeValueForColumn( - const YGStyle::Edges& edges, - YGEdge edge, - CompactValue defaultValue) { - if (!edges[edge].isUndefined()) { - return edges[edge]; - } else if (!edges[YGEdgeVertical].isUndefined()) { - return edges[YGEdgeVertical]; - } else if (!edges[YGEdgeAll].isUndefined()) { - return edges[YGEdgeAll]; - } else { - return defaultValue; - } -} - -CompactValue YGNode::computeRowGap( - const YGStyle::Gutters& gutters, - CompactValue defaultValue) { - if (!gutters[YGGutterRow].isUndefined()) { - return gutters[YGGutterRow]; - } else if (!gutters[YGGutterAll].isUndefined()) { - return gutters[YGGutterAll]; - } else { - return defaultValue; - } -} - -CompactValue YGNode::computeColumnGap( - const YGStyle::Gutters& gutters, - CompactValue defaultValue) { - if (!gutters[YGGutterColumn].isUndefined()) { - return gutters[YGGutterColumn]; - } else if (!gutters[YGGutterAll].isUndefined()) { - return gutters[YGGutterAll]; - } else { - return defaultValue; - } -} - -YGFloatOptional YGNode::getLeadingPosition( - const YGFlexDirection axis, - const float axisSize) const { - auto leadingPosition = YGFlexDirectionIsRow(axis) - ? computeEdgeValueForRow( - style_.position(), - YGEdgeStart, - leading[axis], - CompactValue::ofZero()) - : computeEdgeValueForColumn( - style_.position(), leading[axis], CompactValue::ofZero()); - return YGResolveValue(leadingPosition, axisSize); -} - -YGFloatOptional YGNode::getTrailingPosition( - const YGFlexDirection axis, - const float axisSize) const { - auto trailingPosition = YGFlexDirectionIsRow(axis) - ? computeEdgeValueForRow( - style_.position(), - YGEdgeEnd, - trailing[axis], - CompactValue::ofZero()) - : computeEdgeValueForColumn( - style_.position(), trailing[axis], CompactValue::ofZero()); - return YGResolveValue(trailingPosition, axisSize); -} - -bool YGNode::isLeadingPositionDefined(const YGFlexDirection axis) const { - auto leadingPosition = YGFlexDirectionIsRow(axis) - ? computeEdgeValueForRow( - style_.position(), - YGEdgeStart, - leading[axis], - CompactValue::ofUndefined()) - : computeEdgeValueForColumn( - style_.position(), leading[axis], CompactValue::ofUndefined()); - return !leadingPosition.isUndefined(); -} - -bool YGNode::isTrailingPosDefined(const YGFlexDirection axis) const { - auto trailingPosition = YGFlexDirectionIsRow(axis) - ? computeEdgeValueForRow( - style_.position(), - YGEdgeEnd, - trailing[axis], - CompactValue::ofUndefined()) - : computeEdgeValueForColumn( - style_.position(), trailing[axis], CompactValue::ofUndefined()); - return !trailingPosition.isUndefined(); -} - -YGFloatOptional YGNode::getLeadingMargin( - const YGFlexDirection axis, - const float widthSize) const { - auto leadingMargin = YGFlexDirectionIsRow(axis) - ? computeEdgeValueForRow( - style_.margin(), YGEdgeStart, leading[axis], CompactValue::ofZero()) - : computeEdgeValueForColumn( - style_.margin(), leading[axis], CompactValue::ofZero()); - return YGResolveValueMargin(leadingMargin, widthSize); -} - -YGFloatOptional YGNode::getTrailingMargin( - const YGFlexDirection axis, - const float widthSize) const { - auto trailingMargin = YGFlexDirectionIsRow(axis) - ? computeEdgeValueForRow( - style_.margin(), YGEdgeEnd, trailing[axis], CompactValue::ofZero()) - : computeEdgeValueForColumn( - style_.margin(), trailing[axis], CompactValue::ofZero()); - return YGResolveValueMargin(trailingMargin, widthSize); -} - -YGFloatOptional YGNode::getMarginForAxis( - const YGFlexDirection axis, - const float widthSize) const { - return getLeadingMargin(axis, widthSize) + getTrailingMargin(axis, widthSize); -} - -YGFloatOptional YGNode::getGapForAxis( - const YGFlexDirection axis, - const float widthSize) const { - auto gap = YGFlexDirectionIsRow(axis) - ? computeColumnGap(style_.gap(), CompactValue::ofZero()) - : computeRowGap(style_.gap(), CompactValue::ofZero()); - return YGResolveValue(gap, widthSize); -} - -YGSize YGNode::measure( - float width, - YGMeasureMode widthMode, - float height, - YGMeasureMode heightMode, - void* layoutContext) { - return flags_.measureUsesContext - ? measure_.withContext( - this, width, widthMode, height, heightMode, layoutContext) - : measure_.noContext(this, width, widthMode, height, heightMode); -} - -float YGNode::baseline(float width, float height, void* layoutContext) { - return flags_.baselineUsesContext - ? baseline_.withContext(this, width, height, layoutContext) - : baseline_.noContext(this, width, height); -} - -// Setters - -void YGNode::setMeasureFunc(decltype(YGNode::measure_) measureFunc) { - if (measureFunc.noContext == nullptr) { - // TODO: t18095186 Move nodeType to opt-in function and mark appropriate - // places in Litho - setNodeType(YGNodeTypeDefault); - } else { - YGAssertWithNode( - this, - children_.size() == 0, - "Cannot set measure function: Nodes with measure functions cannot have " - "children."); - // TODO: t18095186 Move nodeType to opt-in function and mark appropriate - // places in Litho - setNodeType(YGNodeTypeText); - } - - measure_ = measureFunc; -} - -void YGNode::setMeasureFunc(YGMeasureFunc measureFunc) { - flags_.measureUsesContext = false; - decltype(YGNode::measure_) m; - m.noContext = measureFunc; - setMeasureFunc(m); -} - -YOGA_EXPORT void YGNode::setMeasureFunc(MeasureWithContextFn measureFunc) { - flags_.measureUsesContext = true; - decltype(YGNode::measure_) m; - m.withContext = measureFunc; - setMeasureFunc(m); -} - -void YGNode::replaceChild(YGNodeRef child, uint32_t index) { - children_[index] = child; -} - -void YGNode::replaceChild(YGNodeRef oldChild, YGNodeRef newChild) { - std::replace(children_.begin(), children_.end(), oldChild, newChild); -} - -void YGNode::insertChild(YGNodeRef child, uint32_t index) { - children_.insert(children_.begin() + index, child); -} - -void YGNode::setConfig(YGConfigRef config) { - YGAssert(config != nullptr, "Attempting to set a null config on a YGNode"); - YGAssertWithConfig( - config, - config->useWebDefaults() == config_->useWebDefaults(), - "UseWebDefaults may not be changed after constructing a YGNode"); - - if (yoga::configUpdateInvalidatesLayout(config_, config)) { - markDirtyAndPropagate(); - } - - config_ = config; -} - -void YGNode::setDirty(bool isDirty) { - if (isDirty == flags_.isDirty) { - return; - } - flags_.isDirty = isDirty; - if (isDirty && dirtied_) { - dirtied_(this); - } -} - -bool YGNode::removeChild(YGNodeRef child) { - std::vector::iterator p = - std::find(children_.begin(), children_.end(), child); - if (p != children_.end()) { - children_.erase(p); - return true; - } - return false; -} - -void YGNode::removeChild(uint32_t index) { - children_.erase(children_.begin() + index); -} - -void YGNode::setLayoutDirection(YGDirection direction) { - layout_.setDirection(direction); -} - -void YGNode::setLayoutMargin(float margin, int index) { - layout_.margin[index] = margin; -} - -void YGNode::setLayoutBorder(float border, int index) { - layout_.border[index] = border; -} - -void YGNode::setLayoutPadding(float padding, int index) { - layout_.padding[index] = padding; -} - -void YGNode::setLayoutLastOwnerDirection(YGDirection direction) { - layout_.lastOwnerDirection = direction; -} - -void YGNode::setLayoutComputedFlexBasis( - const YGFloatOptional computedFlexBasis) { - layout_.computedFlexBasis = computedFlexBasis; -} - -void YGNode::setLayoutPosition(float position, int index) { - layout_.position[index] = position; -} - -void YGNode::setLayoutComputedFlexBasisGeneration( - uint32_t computedFlexBasisGeneration) { - layout_.computedFlexBasisGeneration = computedFlexBasisGeneration; -} - -void YGNode::setLayoutMeasuredDimension(float measuredDimension, int index) { - layout_.measuredDimensions[index] = measuredDimension; -} - -void YGNode::setLayoutHadOverflow(bool hadOverflow) { - layout_.setHadOverflow(hadOverflow); -} - -void YGNode::setLayoutDimension(float dimension, int index) { - layout_.dimensions[index] = dimension; -} - -// If both left and right are defined, then use left. Otherwise return +left or -// -right depending on which is defined. -YGFloatOptional YGNode::relativePosition( - const YGFlexDirection axis, - const float axisSize) const { - if (isLeadingPositionDefined(axis)) { - return getLeadingPosition(axis, axisSize); - } - - YGFloatOptional trailingPosition = getTrailingPosition(axis, axisSize); - if (!trailingPosition.isUndefined()) { - trailingPosition = YGFloatOptional{-1 * trailingPosition.unwrap()}; - } - return trailingPosition; -} - -void YGNode::setPosition( - const YGDirection direction, - const float mainSize, - const float crossSize, - const float ownerWidth) { - /* Root nodes should be always layouted as LTR, so we don't return negative - * values. */ - const YGDirection directionRespectingRoot = - owner_ != nullptr ? direction : YGDirectionLTR; - const YGFlexDirection mainAxis = - YGResolveFlexDirection(style_.flexDirection(), directionRespectingRoot); - const YGFlexDirection crossAxis = - YGFlexDirectionCross(mainAxis, directionRespectingRoot); - - // Here we should check for `YGPositionTypeStatic` and in this case zero inset - // properties (left, right, top, bottom, begin, end). - // https://www.w3.org/TR/css-position-3/#valdef-position-static - const YGFloatOptional relativePositionMain = - relativePosition(mainAxis, mainSize); - const YGFloatOptional relativePositionCross = - relativePosition(crossAxis, crossSize); - - setLayoutPosition( - (getLeadingMargin(mainAxis, ownerWidth) + relativePositionMain).unwrap(), - leading[mainAxis]); - setLayoutPosition( - (getTrailingMargin(mainAxis, ownerWidth) + relativePositionMain).unwrap(), - trailing[mainAxis]); - setLayoutPosition( - (getLeadingMargin(crossAxis, ownerWidth) + relativePositionCross) - .unwrap(), - leading[crossAxis]); - setLayoutPosition( - (getTrailingMargin(crossAxis, ownerWidth) + relativePositionCross) - .unwrap(), - trailing[crossAxis]); -} - -YGValue YGNode::marginLeadingValue(const YGFlexDirection axis) const { - if (YGFlexDirectionIsRow(axis) && - !style_.margin()[YGEdgeStart].isUndefined()) { - return style_.margin()[YGEdgeStart]; - } else { - return style_.margin()[leading[axis]]; - } -} - -YGValue YGNode::marginTrailingValue(const YGFlexDirection axis) const { - if (YGFlexDirectionIsRow(axis) && !style_.margin()[YGEdgeEnd].isUndefined()) { - return style_.margin()[YGEdgeEnd]; - } else { - return style_.margin()[trailing[axis]]; - } -} - -YGValue YGNode::resolveFlexBasisPtr() const { - YGValue flexBasis = style_.flexBasis(); - if (flexBasis.unit != YGUnitAuto && flexBasis.unit != YGUnitUndefined) { - return flexBasis; - } - if (!style_.flex().isUndefined() && style_.flex().unwrap() > 0.0f) { - return config_->useWebDefaults() ? YGValueAuto : YGValueZero; - } - return YGValueAuto; -} - -void YGNode::resolveDimension() { - using namespace yoga; - const YGStyle& style = getStyle(); - for (auto dim : {YGDimensionWidth, YGDimensionHeight}) { - if (!style.maxDimensions()[dim].isUndefined() && - YGValueEqual(style.maxDimensions()[dim], style.minDimensions()[dim])) { - resolvedDimensions_[dim] = style.maxDimensions()[dim]; - } else { - resolvedDimensions_[dim] = style.dimensions()[dim]; - } - } -} - -YGDirection YGNode::resolveDirection(const YGDirection ownerDirection) { - if (style_.direction() == YGDirectionInherit) { - return ownerDirection > YGDirectionInherit ? ownerDirection - : YGDirectionLTR; - } else { - return style_.direction(); - } -} - -YOGA_EXPORT void YGNode::clearChildren() { - children_.clear(); - children_.shrink_to_fit(); -} - -// Other Methods - -void YGNode::cloneChildrenIfNeeded(void* cloneContext) { - iterChildrenAfterCloningIfNeeded([](YGNodeRef, void*) {}, cloneContext); -} - -void YGNode::markDirtyAndPropagate() { - if (!flags_.isDirty) { - setDirty(true); - setLayoutComputedFlexBasis(YGFloatOptional()); - if (owner_) { - owner_->markDirtyAndPropagate(); - } - } -} - -void YGNode::markDirtyAndPropagateDownwards() { - flags_.isDirty = true; - for_each(children_.begin(), children_.end(), [](YGNodeRef childNode) { - childNode->markDirtyAndPropagateDownwards(); - }); -} - -float YGNode::resolveFlexGrow() const { - // Root nodes flexGrow should always be 0 - if (owner_ == nullptr) { - return 0.0; - } - if (!style_.flexGrow().isUndefined()) { - return style_.flexGrow().unwrap(); - } - if (!style_.flex().isUndefined() && style_.flex().unwrap() > 0.0f) { - return style_.flex().unwrap(); - } - return kDefaultFlexGrow; -} - -float YGNode::resolveFlexShrink() const { - if (owner_ == nullptr) { - return 0.0; - } - if (!style_.flexShrink().isUndefined()) { - return style_.flexShrink().unwrap(); - } - if (!config_->useWebDefaults() && !style_.flex().isUndefined() && - style_.flex().unwrap() < 0.0f) { - return -style_.flex().unwrap(); - } - return config_->useWebDefaults() ? kWebDefaultFlexShrink : kDefaultFlexShrink; -} - -bool YGNode::isNodeFlexible() { - return ( - (style_.positionType() != YGPositionTypeAbsolute) && - (resolveFlexGrow() != 0 || resolveFlexShrink() != 0)); -} - -float YGNode::getLeadingBorder(const YGFlexDirection axis) const { - YGValue leadingBorder = YGFlexDirectionIsRow(axis) - ? computeEdgeValueForRow( - style_.border(), YGEdgeStart, leading[axis], CompactValue::ofZero()) - : computeEdgeValueForColumn( - style_.border(), leading[axis], CompactValue::ofZero()); - return fmaxf(leadingBorder.value, 0.0f); -} - -float YGNode::getTrailingBorder(const YGFlexDirection axis) const { - YGValue trailingBorder = YGFlexDirectionIsRow(axis) - ? computeEdgeValueForRow( - style_.border(), YGEdgeEnd, trailing[axis], CompactValue::ofZero()) - : computeEdgeValueForColumn( - style_.border(), trailing[axis], CompactValue::ofZero()); - return fmaxf(trailingBorder.value, 0.0f); -} - -YGFloatOptional YGNode::getLeadingPadding( - const YGFlexDirection axis, - const float widthSize) const { - auto leadingPadding = YGFlexDirectionIsRow(axis) - ? computeEdgeValueForRow( - style_.padding(), - YGEdgeStart, - leading[axis], - CompactValue::ofZero()) - : computeEdgeValueForColumn( - style_.padding(), leading[axis], CompactValue::ofZero()); - return YGFloatOptionalMax( - YGResolveValue(leadingPadding, widthSize), YGFloatOptional(0.0f)); -} - -YGFloatOptional YGNode::getTrailingPadding( - const YGFlexDirection axis, - const float widthSize) const { - auto trailingPadding = YGFlexDirectionIsRow(axis) - ? computeEdgeValueForRow( - style_.padding(), YGEdgeEnd, trailing[axis], CompactValue::ofZero()) - : computeEdgeValueForColumn( - style_.padding(), trailing[axis], CompactValue::ofZero()); - return YGFloatOptionalMax( - YGResolveValue(trailingPadding, widthSize), YGFloatOptional(0.0f)); -} - -YGFloatOptional YGNode::getLeadingPaddingAndBorder( - const YGFlexDirection axis, - const float widthSize) const { - return getLeadingPadding(axis, widthSize) + - YGFloatOptional(getLeadingBorder(axis)); -} - -YGFloatOptional YGNode::getTrailingPaddingAndBorder( - const YGFlexDirection axis, - const float widthSize) const { - return getTrailingPadding(axis, widthSize) + - YGFloatOptional(getTrailingBorder(axis)); -} - -void YGNode::reset() { - YGAssertWithNode( - this, - children_.size() == 0, - "Cannot reset a node which still has children attached"); - YGAssertWithNode( - this, owner_ == nullptr, "Cannot reset a node still attached to a owner"); - - *this = YGNode{getConfig()}; -} diff --git a/Sources/yoga/YGNode.h b/Sources/yoga/YGNode.h deleted file mode 100644 index e3c202f2..00000000 --- a/Sources/yoga/YGNode.h +++ /dev/null @@ -1,335 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include -#include "CompactValue.h" -#include "YGConfig.h" -#include "YGLayout.h" -#include "YGStyle.h" -#include "Yoga-internal.h" - -YGConfigRef YGConfigGetDefault(); - -#pragma pack(push) -#pragma pack(1) -struct YGNodeFlags { - bool hasNewLayout : 1; - bool isReferenceBaseline : 1; - bool isDirty : 1; - uint8_t nodeType : 1; - bool measureUsesContext : 1; - bool baselineUsesContext : 1; - bool printUsesContext : 1; -}; -#pragma pack(pop) - -struct YOGA_EXPORT YGNode { - using MeasureWithContextFn = - YGSize (*)(YGNode*, float, YGMeasureMode, float, YGMeasureMode, void*); - using BaselineWithContextFn = float (*)(YGNode*, float, float, void*); - using PrintWithContextFn = void (*)(YGNode*, void*); - -private: - void* context_ = nullptr; - YGNodeFlags flags_ = {}; - union { - YGMeasureFunc noContext; - MeasureWithContextFn withContext; - } measure_ = {nullptr}; - union { - YGBaselineFunc noContext; - BaselineWithContextFn withContext; - } baseline_ = {nullptr}; - union { - YGPrintFunc noContext; - PrintWithContextFn withContext; - } print_ = {nullptr}; - YGDirtiedFunc dirtied_ = nullptr; - YGStyle style_ = {}; - YGLayout layout_ = {}; - uint32_t lineIndex_ = 0; - YGNodeRef owner_ = nullptr; - YGVector children_ = {}; - YGConfigRef config_; - std::array resolvedDimensions_ = { - {YGValueUndefined, YGValueUndefined}}; - - YGFloatOptional relativePosition( - const YGFlexDirection axis, - const float axisSize) const; - - void setMeasureFunc(decltype(measure_)); - void setBaselineFunc(decltype(baseline_)); - - void useWebDefaults() { - style_.flexDirection() = YGFlexDirectionRow; - style_.alignContent() = YGAlignStretch; - } - - // DANGER DANGER DANGER! - // If the node assigned to has children, we'd either have to deallocate - // them (potentially incorrect) or ignore them (danger of leaks). Only ever - // use this after checking that there are no children. - // DO NOT CHANGE THE VISIBILITY OF THIS METHOD! - YGNode& operator=(YGNode&&) = default; - - using CompactValue = facebook::yoga::detail::CompactValue; - -public: - YGNode() : YGNode{YGConfigGetDefault()} { flags_.hasNewLayout = true; } - explicit YGNode(const YGConfigRef config); - ~YGNode() = default; // cleanup of owner/children relationships in YGNodeFree - - YGNode(YGNode&&); - - // Does not expose true value semantics, as children are not cloned eagerly. - // Should we remove this? - YGNode(const YGNode& node) = default; - - // assignment means potential leaks of existing children, or alternatively - // freeing unowned memory, double free, or freeing stack memory. - YGNode& operator=(const YGNode&) = delete; - - // Getters - void* getContext() const { return context_; } - - void print(void*); - - bool getHasNewLayout() const { return flags_.hasNewLayout; } - - YGNodeType getNodeType() const { - return static_cast(flags_.nodeType); - } - - bool hasMeasureFunc() const noexcept { return measure_.noContext != nullptr; } - - YGSize measure(float, YGMeasureMode, float, YGMeasureMode, void*); - - bool hasBaselineFunc() const noexcept { - return baseline_.noContext != nullptr; - } - - float baseline(float width, float height, void* layoutContext); - - bool hasErrata(YGErrata errata) const { return config_->hasErrata(errata); } - - YGDirtiedFunc getDirtied() const { return dirtied_; } - - // For Performance reasons passing as reference. - YGStyle& getStyle() { return style_; } - - const YGStyle& getStyle() const { return style_; } - - // For Performance reasons passing as reference. - YGLayout& getLayout() { return layout_; } - - const YGLayout& getLayout() const { return layout_; } - - uint32_t getLineIndex() const { return lineIndex_; } - - bool isReferenceBaseline() { return flags_.isReferenceBaseline; } - - // returns the YGNodeRef that owns this YGNode. An owner is used to identify - // the YogaTree that a YGNode belongs to. This method will return the parent - // of the YGNode when a YGNode only belongs to one YogaTree or nullptr when - // the YGNode is shared between two or more YogaTrees. - YGNodeRef getOwner() const { return owner_; } - - // Deprecated, use getOwner() instead. - YGNodeRef getParent() const { return getOwner(); } - - const YGVector& getChildren() const { return children_; } - - // Applies a callback to all children, after cloning them if they are not - // owned. - template - void iterChildrenAfterCloningIfNeeded(T callback, void* cloneContext) { - int i = 0; - for (YGNodeRef& child : children_) { - if (child->getOwner() != this) { - child = config_->cloneNode(child, this, i, cloneContext); - child->setOwner(this); - } - i += 1; - - callback(child, cloneContext); - } - } - - YGNodeRef getChild(uint32_t index) const { return children_.at(index); } - - YGConfigRef getConfig() const { return config_; } - - bool isDirty() const { return flags_.isDirty; } - - std::array getResolvedDimensions() const { - return resolvedDimensions_; - } - - YGValue getResolvedDimension(int index) const { - return resolvedDimensions_[index]; - } - - static CompactValue computeEdgeValueForColumn( - const YGStyle::Edges& edges, - YGEdge edge, - CompactValue defaultValue); - - static CompactValue computeEdgeValueForRow( - const YGStyle::Edges& edges, - YGEdge rowEdge, - YGEdge edge, - CompactValue defaultValue); - - static CompactValue computeRowGap( - const YGStyle::Gutters& gutters, - CompactValue defaultValue); - - static CompactValue computeColumnGap( - const YGStyle::Gutters& gutters, - CompactValue defaultValue); - - // Methods related to positions, margin, padding and border - YGFloatOptional getLeadingPosition( - const YGFlexDirection axis, - const float axisSize) const; - bool isLeadingPositionDefined(const YGFlexDirection axis) const; - bool isTrailingPosDefined(const YGFlexDirection axis) const; - YGFloatOptional getTrailingPosition( - const YGFlexDirection axis, - const float axisSize) const; - YGFloatOptional getLeadingMargin( - const YGFlexDirection axis, - const float widthSize) const; - YGFloatOptional getTrailingMargin( - const YGFlexDirection axis, - const float widthSize) const; - float getLeadingBorder(const YGFlexDirection flexDirection) const; - float getTrailingBorder(const YGFlexDirection flexDirection) const; - YGFloatOptional getLeadingPadding( - const YGFlexDirection axis, - const float widthSize) const; - YGFloatOptional getTrailingPadding( - const YGFlexDirection axis, - const float widthSize) const; - YGFloatOptional getLeadingPaddingAndBorder( - const YGFlexDirection axis, - const float widthSize) const; - YGFloatOptional getTrailingPaddingAndBorder( - const YGFlexDirection axis, - const float widthSize) const; - YGFloatOptional getMarginForAxis( - const YGFlexDirection axis, - const float widthSize) const; - YGFloatOptional getGapForAxis( - const YGFlexDirection axis, - const float widthSize) const; - // Setters - - void setContext(void* context) { context_ = context; } - - void setPrintFunc(YGPrintFunc printFunc) { - print_.noContext = printFunc; - flags_.printUsesContext = false; - } - void setPrintFunc(PrintWithContextFn printFunc) { - print_.withContext = printFunc; - flags_.printUsesContext = true; - } - void setPrintFunc(std::nullptr_t) { setPrintFunc(YGPrintFunc{nullptr}); } - - void setHasNewLayout(bool hasNewLayout) { - flags_.hasNewLayout = hasNewLayout; - } - - void setNodeType(YGNodeType nodeType) { - flags_.nodeType = static_cast(nodeType); - } - - void setMeasureFunc(YGMeasureFunc measureFunc); - void setMeasureFunc(MeasureWithContextFn); - void setMeasureFunc(std::nullptr_t) { - return setMeasureFunc(YGMeasureFunc{nullptr}); - } - - void setBaselineFunc(YGBaselineFunc baseLineFunc) { - flags_.baselineUsesContext = false; - baseline_.noContext = baseLineFunc; - } - void setBaselineFunc(BaselineWithContextFn baseLineFunc) { - flags_.baselineUsesContext = true; - baseline_.withContext = baseLineFunc; - } - void setBaselineFunc(std::nullptr_t) { - return setBaselineFunc(YGBaselineFunc{nullptr}); - } - - void setDirtiedFunc(YGDirtiedFunc dirtiedFunc) { dirtied_ = dirtiedFunc; } - - void setStyle(const YGStyle& style) { style_ = style; } - - void setLayout(const YGLayout& layout) { layout_ = layout; } - - void setLineIndex(uint32_t lineIndex) { lineIndex_ = lineIndex; } - - void setIsReferenceBaseline(bool isReferenceBaseline) { - flags_.isReferenceBaseline = isReferenceBaseline; - } - - void setOwner(YGNodeRef owner) { owner_ = owner; } - - void setChildren(const YGVector& children) { children_ = children; } - - // TODO: rvalue override for setChildren - - void setConfig(YGConfigRef config); - - void setDirty(bool isDirty); - void setLayoutLastOwnerDirection(YGDirection direction); - void setLayoutComputedFlexBasis(const YGFloatOptional computedFlexBasis); - void setLayoutComputedFlexBasisGeneration( - uint32_t computedFlexBasisGeneration); - void setLayoutMeasuredDimension(float measuredDimension, int index); - void setLayoutHadOverflow(bool hadOverflow); - void setLayoutDimension(float dimension, int index); - void setLayoutDirection(YGDirection direction); - void setLayoutMargin(float margin, int index); - void setLayoutBorder(float border, int index); - void setLayoutPadding(float padding, int index); - void setLayoutPosition(float position, int index); - void setPosition( - const YGDirection direction, - const float mainSize, - const float crossSize, - const float ownerWidth); - void markDirtyAndPropagateDownwards(); - - // Other methods - YGValue marginLeadingValue(const YGFlexDirection axis) const; - YGValue marginTrailingValue(const YGFlexDirection axis) const; - YGValue resolveFlexBasisPtr() const; - void resolveDimension(); - YGDirection resolveDirection(const YGDirection ownerDirection); - void clearChildren(); - /// Replaces the occurrences of oldChild with newChild - void replaceChild(YGNodeRef oldChild, YGNodeRef newChild); - void replaceChild(YGNodeRef child, uint32_t index); - void insertChild(YGNodeRef child, uint32_t index); - /// Removes the first occurrence of child - bool removeChild(YGNodeRef child); - void removeChild(uint32_t index); - - void cloneChildrenIfNeeded(void*); - void markDirtyAndPropagate(); - float resolveFlexGrow() const; - float resolveFlexShrink() const; - bool isNodeFlexible(); - void reset(); -}; diff --git a/Sources/yoga/YGNodePrint.cpp b/Sources/yoga/YGNodePrint.cpp deleted file mode 100644 index 08c4a9f7..00000000 --- a/Sources/yoga/YGNodePrint.cpp +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#ifdef DEBUG - -#include - -#include "YGEnums.h" -#include "YGNodePrint.h" -#include "YGNode.h" -#include "Yoga-internal.h" -#include "Utils.h" - -namespace facebook { -namespace yoga { -typedef std::string string; - -static void indent(string& base, uint32_t level) { - for (uint32_t i = 0; i < level; ++i) { - base.append(" "); - } -} - -static bool areFourValuesEqual(const YGStyle::Edges& four) { - return YGValueEqual(four[0], four[1]) && YGValueEqual(four[0], four[2]) && - YGValueEqual(four[0], four[3]); -} - -static void appendFormattedString(string& str, const char* fmt, ...) { - va_list args; - va_start(args, fmt); - va_list argsCopy; - va_copy(argsCopy, args); - std::vector buf(1 + vsnprintf(NULL, 0, fmt, args)); - va_end(args); - vsnprintf(buf.data(), buf.size(), fmt, argsCopy); - va_end(argsCopy); - string result = string(buf.begin(), buf.end() - 1); - str.append(result); -} - -static void appendFloatOptionalIfDefined( - string& base, - const string key, - const YGFloatOptional num) { - if (!num.isUndefined()) { - appendFormattedString(base, "%s: %g; ", key.c_str(), num.unwrap()); - } -} - -static void appendNumberIfNotUndefined( - string& base, - const string key, - const YGValue number) { - if (number.unit != YGUnitUndefined) { - if (number.unit == YGUnitAuto) { - base.append(key + ": auto; "); - } else { - string unit = number.unit == YGUnitPoint ? "px" : "%%"; - appendFormattedString( - base, "%s: %g%s; ", key.c_str(), number.value, unit.c_str()); - } - } -} - -static void appendNumberIfNotAuto( - string& base, - const string& key, - const YGValue number) { - if (number.unit != YGUnitAuto) { - appendNumberIfNotUndefined(base, key, number); - } -} - -static void appendNumberIfNotZero( - string& base, - const string& str, - const YGValue number) { - if (number.unit == YGUnitAuto) { - base.append(str + ": auto; "); - } else if (!YGFloatsEqual(number.value, 0)) { - appendNumberIfNotUndefined(base, str, number); - } -} - -static void appendEdges( - string& base, - const string& key, - const YGStyle::Edges& edges) { - if (areFourValuesEqual(edges)) { - auto edgeValue = YGNode::computeEdgeValueForColumn( - edges, YGEdgeLeft, detail::CompactValue::ofZero()); - appendNumberIfNotZero(base, key, edgeValue); - } else { - for (int edge = YGEdgeLeft; edge != YGEdgeAll; ++edge) { - string str = key + "-" + YGEdgeToString(static_cast(edge)); - appendNumberIfNotZero(base, str, edges[edge]); - } - } -} - -static void appendEdgeIfNotUndefined( - string& base, - const string& str, - const YGStyle::Edges& edges, - const YGEdge edge) { - // TODO: this doesn't take RTL / YGEdgeStart / YGEdgeEnd into account - auto value = (edge == YGEdgeLeft || edge == YGEdgeRight) - ? YGNode::computeEdgeValueForRow( - edges, edge, edge, detail::CompactValue::ofUndefined()) - : YGNode::computeEdgeValueForColumn( - edges, edge, detail::CompactValue::ofUndefined()); - appendNumberIfNotUndefined(base, str, value); -} - -void YGNodeToString( - std::string& str, - YGNodeRef node, - YGPrintOptions options, - uint32_t level) { - indent(str, level); - appendFormattedString(str, "
getLayout().dimensions[YGDimensionWidth]); - appendFormattedString( - str, "height: %g; ", node->getLayout().dimensions[YGDimensionHeight]); - appendFormattedString( - str, "top: %g; ", node->getLayout().position[YGEdgeTop]); - appendFormattedString( - str, "left: %g;", node->getLayout().position[YGEdgeLeft]); - appendFormattedString(str, "\" "); - } - - if (options & YGPrintOptionsStyle) { - appendFormattedString(str, "style=\""); - const auto& style = node->getStyle(); - if (style.flexDirection() != YGNode().getStyle().flexDirection()) { - appendFormattedString( - str, - "flex-direction: %s; ", - YGFlexDirectionToString(style.flexDirection())); - } - if (style.justifyContent() != YGNode().getStyle().justifyContent()) { - appendFormattedString( - str, - "justify-content: %s; ", - YGJustifyToString(style.justifyContent())); - } - if (style.alignItems() != YGNode().getStyle().alignItems()) { - appendFormattedString( - str, "align-items: %s; ", YGAlignToString(style.alignItems())); - } - if (style.alignContent() != YGNode().getStyle().alignContent()) { - appendFormattedString( - str, "align-content: %s; ", YGAlignToString(style.alignContent())); - } - if (style.alignSelf() != YGNode().getStyle().alignSelf()) { - appendFormattedString( - str, "align-self: %s; ", YGAlignToString(style.alignSelf())); - } - appendFloatOptionalIfDefined(str, "flex-grow", style.flexGrow()); - appendFloatOptionalIfDefined(str, "flex-shrink", style.flexShrink()); - appendNumberIfNotAuto(str, "flex-basis", style.flexBasis()); - appendFloatOptionalIfDefined(str, "flex", style.flex()); - - if (style.flexWrap() != YGNode().getStyle().flexWrap()) { - appendFormattedString( - str, "flex-wrap: %s; ", YGWrapToString(style.flexWrap())); - } - - if (style.overflow() != YGNode().getStyle().overflow()) { - appendFormattedString( - str, "overflow: %s; ", YGOverflowToString(style.overflow())); - } - - if (style.display() != YGNode().getStyle().display()) { - appendFormattedString( - str, "display: %s; ", YGDisplayToString(style.display())); - } - appendEdges(str, "margin", style.margin()); - appendEdges(str, "padding", style.padding()); - appendEdges(str, "border", style.border()); - - if (YGNode::computeColumnGap( - style.gap(), detail::CompactValue::ofUndefined()) != - YGNode::computeColumnGap( - YGNode().getStyle().gap(), detail::CompactValue::ofUndefined())) { - appendNumberIfNotUndefined( - str, "column-gap", style.gap()[YGGutterColumn]); - } - if (YGNode::computeRowGap( - style.gap(), detail::CompactValue::ofUndefined()) != - YGNode::computeRowGap( - YGNode().getStyle().gap(), detail::CompactValue::ofUndefined())) { - appendNumberIfNotUndefined(str, "row-gap", style.gap()[YGGutterRow]); - } - - appendNumberIfNotAuto(str, "width", style.dimensions()[YGDimensionWidth]); - appendNumberIfNotAuto(str, "height", style.dimensions()[YGDimensionHeight]); - appendNumberIfNotAuto( - str, "max-width", style.maxDimensions()[YGDimensionWidth]); - appendNumberIfNotAuto( - str, "max-height", style.maxDimensions()[YGDimensionHeight]); - appendNumberIfNotAuto( - str, "min-width", style.minDimensions()[YGDimensionWidth]); - appendNumberIfNotAuto( - str, "min-height", style.minDimensions()[YGDimensionHeight]); - - if (style.positionType() != YGNode().getStyle().positionType()) { - appendFormattedString( - str, "position: %s; ", YGPositionTypeToString(style.positionType())); - } - - appendEdgeIfNotUndefined(str, "left", style.position(), YGEdgeLeft); - appendEdgeIfNotUndefined(str, "right", style.position(), YGEdgeRight); - appendEdgeIfNotUndefined(str, "top", style.position(), YGEdgeTop); - appendEdgeIfNotUndefined(str, "bottom", style.position(), YGEdgeBottom); - appendFormattedString(str, "\" "); - - if (node->hasMeasureFunc()) { - appendFormattedString(str, "has-custom-measure=\"true\""); - } - } - appendFormattedString(str, ">"); - - const uint32_t childCount = static_cast(node->getChildren().size()); - if (options & YGPrintOptionsChildren && childCount > 0) { - for (uint32_t i = 0; i < childCount; i++) { - appendFormattedString(str, "\n"); - YGNodeToString(str, YGNodeGetChild(node, i), options, level + 1); - } - appendFormattedString(str, "\n"); - indent(str, level); - } - appendFormattedString(str, "
"); -} -} // namespace yoga -} // namespace facebook -#endif diff --git a/Sources/yoga/YGNodePrint.h b/Sources/yoga/YGNodePrint.h deleted file mode 100644 index f06d457c..00000000 --- a/Sources/yoga/YGNodePrint.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#ifdef DEBUG - -#pragma once - -#include - -#include "Yoga.h" - -namespace facebook { -namespace yoga { - -void YGNodeToString( - std::string& str, - YGNodeRef node, - YGPrintOptions options, - uint32_t level); - -} // namespace yoga -} // namespace facebook - -#endif diff --git a/Sources/yoga/YGStyle.cpp b/Sources/yoga/YGStyle.cpp deleted file mode 100644 index 37153f2e..00000000 --- a/Sources/yoga/YGStyle.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "YGStyle.h" -#include "Utils.h" - -// Yoga specific properties, not compatible with flexbox specification -bool operator==(const YGStyle& lhs, const YGStyle& rhs) { - bool areNonFloatValuesEqual = lhs.direction() == rhs.direction() && - lhs.flexDirection() == rhs.flexDirection() && - lhs.justifyContent() == rhs.justifyContent() && - lhs.alignContent() == rhs.alignContent() && - lhs.alignItems() == rhs.alignItems() && - lhs.alignSelf() == rhs.alignSelf() && - lhs.positionType() == rhs.positionType() && - lhs.flexWrap() == rhs.flexWrap() && lhs.overflow() == rhs.overflow() && - lhs.display() == rhs.display() && - YGValueEqual(lhs.flexBasis(), rhs.flexBasis()) && - lhs.margin() == rhs.margin() && lhs.position() == rhs.position() && - lhs.padding() == rhs.padding() && lhs.border() == rhs.border() && - lhs.gap() == rhs.gap() && lhs.dimensions() == rhs.dimensions() && - lhs.minDimensions() == rhs.minDimensions() && - lhs.maxDimensions() == rhs.maxDimensions(); - - areNonFloatValuesEqual = areNonFloatValuesEqual && - lhs.flex().isUndefined() == rhs.flex().isUndefined(); - if (areNonFloatValuesEqual && !lhs.flex().isUndefined() && - !rhs.flex().isUndefined()) { - areNonFloatValuesEqual = areNonFloatValuesEqual && lhs.flex() == rhs.flex(); - } - - areNonFloatValuesEqual = areNonFloatValuesEqual && - lhs.flexGrow().isUndefined() == rhs.flexGrow().isUndefined(); - if (areNonFloatValuesEqual && !lhs.flexGrow().isUndefined()) { - areNonFloatValuesEqual = - areNonFloatValuesEqual && lhs.flexGrow() == rhs.flexGrow(); - } - - areNonFloatValuesEqual = areNonFloatValuesEqual && - lhs.flexShrink().isUndefined() == rhs.flexShrink().isUndefined(); - if (areNonFloatValuesEqual && !rhs.flexShrink().isUndefined()) { - areNonFloatValuesEqual = - areNonFloatValuesEqual && lhs.flexShrink() == rhs.flexShrink(); - } - - if (!(lhs.aspectRatio().isUndefined() && rhs.aspectRatio().isUndefined())) { - areNonFloatValuesEqual = - areNonFloatValuesEqual && lhs.aspectRatio() == rhs.aspectRatio(); - } - - return areNonFloatValuesEqual; -} diff --git a/Sources/yoga/YGStyle.h b/Sources/yoga/YGStyle.h deleted file mode 100644 index 3a65573c..00000000 --- a/Sources/yoga/YGStyle.h +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include -#include -#include - -#include "CompactValue.h" -#include "YGFloatOptional.h" -#include "Yoga.h" -#include "Yoga-internal.h" -#include "BitUtils.h" - -class YOGA_EXPORT YGStyle { - template - using Values = - facebook::yoga::detail::Values()>; - using CompactValue = facebook::yoga::detail::CompactValue; - -public: - using Dimensions = Values; - using Edges = Values; - using Gutters = Values; - - template - struct BitfieldRef { - YGStyle& style; - size_t offset; - operator T() const { - return facebook::yoga::detail::getEnumData(style.flags, offset); - } - BitfieldRef& operator=(T x) { - facebook::yoga::detail::setEnumData(style.flags, offset, x); - return *this; - } - }; - - template - struct Ref { - YGStyle& style; - operator T() const { return style.*Prop; } - Ref& operator=(T value) { - style.*Prop = value; - return *this; - } - }; - - template YGStyle::*Prop> - struct IdxRef { - struct Ref { - YGStyle& style; - Idx idx; - operator CompactValue() const { return (style.*Prop)[idx]; } - operator YGValue() const { return (style.*Prop)[idx]; } - Ref& operator=(CompactValue value) { - (style.*Prop)[idx] = value; - return *this; - } - }; - - YGStyle& style; - IdxRef& operator=(const Values& values) { - style.*Prop = values; - return *this; - } - operator const Values&() const { return style.*Prop; } - Ref operator[](Idx idx) { return {style, idx}; } - CompactValue operator[](Idx idx) const { return (style.*Prop)[idx]; } - }; - - YGStyle() { - alignContent() = YGAlignFlexStart; - alignItems() = YGAlignStretch; - } - ~YGStyle() = default; - -private: - static constexpr size_t directionOffset = 0; - static constexpr size_t flexdirectionOffset = - directionOffset + facebook::yoga::detail::bitWidthFn(); - static constexpr size_t justifyContentOffset = flexdirectionOffset + - facebook::yoga::detail::bitWidthFn(); - static constexpr size_t alignContentOffset = - justifyContentOffset + facebook::yoga::detail::bitWidthFn(); - static constexpr size_t alignItemsOffset = - alignContentOffset + facebook::yoga::detail::bitWidthFn(); - static constexpr size_t alignSelfOffset = - alignItemsOffset + facebook::yoga::detail::bitWidthFn(); - static constexpr size_t positionTypeOffset = - alignSelfOffset + facebook::yoga::detail::bitWidthFn(); - static constexpr size_t flexWrapOffset = - positionTypeOffset + facebook::yoga::detail::bitWidthFn(); - static constexpr size_t overflowOffset = - flexWrapOffset + facebook::yoga::detail::bitWidthFn(); - static constexpr size_t displayOffset = - overflowOffset + facebook::yoga::detail::bitWidthFn(); - - uint32_t flags = 0; - - YGFloatOptional flex_ = {}; - YGFloatOptional flexGrow_ = {}; - YGFloatOptional flexShrink_ = {}; - CompactValue flexBasis_ = CompactValue::ofAuto(); - Edges margin_ = {}; - Edges position_ = {}; - Edges padding_ = {}; - Edges border_ = {}; - Gutters gap_ = {}; - Dimensions dimensions_{CompactValue::ofAuto()}; - Dimensions minDimensions_ = {}; - Dimensions maxDimensions_ = {}; - // Yoga specific properties, not compatible with flexbox specification - YGFloatOptional aspectRatio_ = {}; - -public: - // for library users needing a type - using ValueRepr = std::remove_reference::type; - - YGDirection direction() const { - return facebook::yoga::detail::getEnumData( - flags, directionOffset); - } - BitfieldRef direction() { return {*this, directionOffset}; } - - YGFlexDirection flexDirection() const { - return facebook::yoga::detail::getEnumData( - flags, flexdirectionOffset); - } - BitfieldRef flexDirection() { - return {*this, flexdirectionOffset}; - } - - YGJustify justifyContent() const { - return facebook::yoga::detail::getEnumData( - flags, justifyContentOffset); - } - BitfieldRef justifyContent() { - return {*this, justifyContentOffset}; - } - - YGAlign alignContent() const { - return facebook::yoga::detail::getEnumData( - flags, alignContentOffset); - } - BitfieldRef alignContent() { return {*this, alignContentOffset}; } - - YGAlign alignItems() const { - return facebook::yoga::detail::getEnumData( - flags, alignItemsOffset); - } - BitfieldRef alignItems() { return {*this, alignItemsOffset}; } - - YGAlign alignSelf() const { - return facebook::yoga::detail::getEnumData(flags, alignSelfOffset); - } - BitfieldRef alignSelf() { return {*this, alignSelfOffset}; } - - YGPositionType positionType() const { - return facebook::yoga::detail::getEnumData( - flags, positionTypeOffset); - } - BitfieldRef positionType() { - return {*this, positionTypeOffset}; - } - - YGWrap flexWrap() const { - return facebook::yoga::detail::getEnumData(flags, flexWrapOffset); - } - BitfieldRef flexWrap() { return {*this, flexWrapOffset}; } - - YGOverflow overflow() const { - return facebook::yoga::detail::getEnumData( - flags, overflowOffset); - } - BitfieldRef overflow() { return {*this, overflowOffset}; } - - YGDisplay display() const { - return facebook::yoga::detail::getEnumData(flags, displayOffset); - } - BitfieldRef display() { return {*this, displayOffset}; } - - YGFloatOptional flex() const { return flex_; } - Ref flex() { return {*this}; } - - YGFloatOptional flexGrow() const { return flexGrow_; } - Ref flexGrow() { return {*this}; } - - YGFloatOptional flexShrink() const { return flexShrink_; } - Ref flexShrink() { return {*this}; } - - CompactValue flexBasis() const { return flexBasis_; } - Ref flexBasis() { return {*this}; } - - const Edges& margin() const { return margin_; } - IdxRef margin() { return {*this}; } - - const Edges& position() const { return position_; } - IdxRef position() { return {*this}; } - - const Edges& padding() const { return padding_; } - IdxRef padding() { return {*this}; } - - const Edges& border() const { return border_; } - IdxRef border() { return {*this}; } - - const Gutters& gap() const { return gap_; } - IdxRef gap() { return {*this}; } - - const Dimensions& dimensions() const { return dimensions_; } - IdxRef dimensions() { return {*this}; } - - const Dimensions& minDimensions() const { return minDimensions_; } - IdxRef minDimensions() { - return {*this}; - } - - const Dimensions& maxDimensions() const { return maxDimensions_; } - IdxRef maxDimensions() { - return {*this}; - } - - // Yoga specific properties, not compatible with flexbox specification - YGFloatOptional aspectRatio() const { return aspectRatio_; } - Ref aspectRatio() { return {*this}; } -}; - -YOGA_EXPORT bool operator==(const YGStyle& lhs, const YGStyle& rhs); -YOGA_EXPORT inline bool operator!=(const YGStyle& lhs, const YGStyle& rhs) { - return !(lhs == rhs); -} diff --git a/Sources/yoga/YGValue.cpp b/Sources/yoga/YGValue.cpp deleted file mode 100644 index 89ff41ba..00000000 --- a/Sources/yoga/YGValue.cpp +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "YGValue.h" - -const YGValue YGValueZero = {0, YGUnitPoint}; -const YGValue YGValueUndefined = {YGUndefined, YGUnitUndefined}; -const YGValue YGValueAuto = {YGUndefined, YGUnitAuto}; diff --git a/Sources/yoga/Yoga-internal.h b/Sources/yoga/Yoga-internal.h deleted file mode 100644 index 903975d5..00000000 --- a/Sources/yoga/Yoga-internal.h +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include -#include -#include - -#include "CompactValue.h" -#include "Yoga.h" - -using YGVector = std::vector; - -YG_EXTERN_C_BEGIN - -void YGNodeCalculateLayoutWithContext( - YGNodeRef node, - float availableWidth, - float availableHeight, - YGDirection ownerDirection, - void* layoutContext); - -// Deallocates a Yoga Node. Unlike YGNodeFree, does not remove the node from -// its parent or children. -void YGNodeDeallocate(YGNodeRef node); - -YG_EXTERN_C_END - -namespace facebook { -namespace yoga { - -inline bool isUndefined(float value) { - return std::isnan(value); -} - -inline bool isUndefined(double value) { - return std::isnan(value); -} - -void throwLogicalErrorWithMessage(const char* message); - -} // namespace yoga -} // namespace facebook - -extern const std::array trailing; -extern const std::array leading; -extern const YGValue YGValueUndefined; -extern const YGValue YGValueAuto; -extern const YGValue YGValueZero; - -struct YGCachedMeasurement { - float availableWidth; - float availableHeight; - YGMeasureMode widthMeasureMode; - YGMeasureMode heightMeasureMode; - - float computedWidth; - float computedHeight; - - YGCachedMeasurement() - : availableWidth(-1), - availableHeight(-1), - widthMeasureMode(YGMeasureModeUndefined), - heightMeasureMode(YGMeasureModeUndefined), - computedWidth(-1), - computedHeight(-1) {} - - bool operator==(YGCachedMeasurement measurement) const { - using namespace facebook; - - bool isEqual = widthMeasureMode == measurement.widthMeasureMode && - heightMeasureMode == measurement.heightMeasureMode; - - if (!yoga::isUndefined(availableWidth) || - !yoga::isUndefined(measurement.availableWidth)) { - isEqual = isEqual && availableWidth == measurement.availableWidth; - } - if (!yoga::isUndefined(availableHeight) || - !yoga::isUndefined(measurement.availableHeight)) { - isEqual = isEqual && availableHeight == measurement.availableHeight; - } - if (!yoga::isUndefined(computedWidth) || - !yoga::isUndefined(measurement.computedWidth)) { - isEqual = isEqual && computedWidth == measurement.computedWidth; - } - if (!yoga::isUndefined(computedHeight) || - !yoga::isUndefined(measurement.computedHeight)) { - isEqual = isEqual && computedHeight == measurement.computedHeight; - } - - return isEqual; - } -}; - -// This value was chosen based on empirical data: -// 98% of analyzed layouts require less than 8 entries. -#define YG_MAX_CACHED_RESULT_COUNT 8 - -namespace facebook { -namespace yoga { -namespace detail { - -template -class Values { -private: - std::array values_; - -public: - Values() = default; - Values(const Values& other) = default; - - explicit Values(const YGValue& defaultValue) noexcept { - values_.fill(defaultValue); - } - - const CompactValue& operator[](size_t i) const noexcept { return values_[i]; } - CompactValue& operator[](size_t i) noexcept { return values_[i]; } - - template - YGValue get() const noexcept { - return std::get(values_); - } - - template - void set(YGValue& value) noexcept { - std::get(values_) = value; - } - - template - void set(YGValue&& value) noexcept { - set(value); - } - - bool operator==(const Values& other) const noexcept { - for (size_t i = 0; i < Size; ++i) { - if (values_[i] != other.values_[i]) { - return false; - } - } - return true; - } - - Values& operator=(const Values& other) = default; -}; -} // namespace detail -} // namespace yoga -} // namespace facebook - -static const float kDefaultFlexGrow = 0.0f; -static const float kDefaultFlexShrink = 0.0f; -static const float kWebDefaultFlexShrink = 1.0f; - -extern bool YGFloatsEqual(const float a, const float b); diff --git a/Sources/yoga/Yoga.cpp b/Sources/yoga/Yoga.cpp deleted file mode 100644 index 3588fd0a..00000000 --- a/Sources/yoga/Yoga.cpp +++ /dev/null @@ -1,4346 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include -#include -#include -#include -#include - -#include "log.h" -#include "Utils.h" -#include "YGNode.h" -#include "YGNodePrint.h" -#include "Yoga.h" -#include "Yoga-internal.h" -#include "event/event.h" - -using namespace facebook::yoga; -using detail::Log; - -#ifdef ANDROID -static int YGAndroidLog( - const YGConfigRef config, - const YGNodeRef node, - YGLogLevel level, - const char* format, - va_list args); -#else -static int YGDefaultLog( - const YGConfigRef config, - const YGNodeRef node, - YGLogLevel level, - const char* format, - va_list args); -#endif - -#ifdef ANDROID -#include -static int YGAndroidLog( - const YGConfigRef /*config*/, - const YGNodeRef /*node*/, - YGLogLevel level, - const char* format, - va_list args) { - int androidLevel = YGLogLevelDebug; - switch (level) { - case YGLogLevelFatal: - androidLevel = ANDROID_LOG_FATAL; - break; - 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; - } - const int result = __android_log_vprint(androidLevel, "yoga", format, args); - return result; -} -#else -#define YG_UNUSED(x) (void) (x); - -static int YGDefaultLog( - const YGConfigRef config, - const YGNodeRef node, - YGLogLevel level, - const char* format, - va_list args) { - YG_UNUSED(config); - YG_UNUSED(node); - switch (level) { - case YGLogLevelError: - case YGLogLevelFatal: - return vfprintf(stderr, format, args); - case YGLogLevelWarn: - case YGLogLevelInfo: - case YGLogLevelDebug: - case YGLogLevelVerbose: - default: - return vprintf(format, args); - } -} - -#undef YG_UNUSED -#endif - -static inline bool YGDoubleIsUndefined(const double value) { - return facebook::yoga::isUndefined(value); -} - -YOGA_EXPORT bool YGFloatIsUndefined(const float value) { - return facebook::yoga::isUndefined(value); -} - -YOGA_EXPORT void* YGNodeGetContext(YGNodeRef node) { - return node->getContext(); -} - -YOGA_EXPORT void YGNodeSetContext(YGNodeRef node, void* context) { - return node->setContext(context); -} - -YOGA_EXPORT YGConfigRef YGNodeGetConfig(YGNodeRef node) { - return node->getConfig(); -} - -YOGA_EXPORT void YGNodeSetConfig(YGNodeRef node, YGConfigRef config) { - node->setConfig(config); -} - -YOGA_EXPORT bool YGNodeHasMeasureFunc(YGNodeRef node) { - return node->hasMeasureFunc(); -} - -YOGA_EXPORT void YGNodeSetMeasureFunc( - YGNodeRef node, - YGMeasureFunc measureFunc) { - node->setMeasureFunc(measureFunc); -} - -YOGA_EXPORT bool YGNodeHasBaselineFunc(YGNodeRef node) { - return node->hasBaselineFunc(); -} - -YOGA_EXPORT void YGNodeSetBaselineFunc( - YGNodeRef node, - YGBaselineFunc baselineFunc) { - node->setBaselineFunc(baselineFunc); -} - -YOGA_EXPORT YGDirtiedFunc YGNodeGetDirtiedFunc(YGNodeRef node) { - return node->getDirtied(); -} - -YOGA_EXPORT void YGNodeSetDirtiedFunc( - YGNodeRef node, - YGDirtiedFunc dirtiedFunc) { - node->setDirtiedFunc(dirtiedFunc); -} - -YOGA_EXPORT void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc) { - node->setPrintFunc(printFunc); -} - -YOGA_EXPORT bool YGNodeGetHasNewLayout(YGNodeRef node) { - return node->getHasNewLayout(); -} - -YOGA_EXPORT void YGConfigSetPrintTreeFlag(YGConfigRef config, bool enabled) { - config->setShouldPrintTree(enabled); -} - -YOGA_EXPORT void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout) { - node->setHasNewLayout(hasNewLayout); -} - -YOGA_EXPORT YGNodeType YGNodeGetNodeType(YGNodeRef node) { - return node->getNodeType(); -} - -YOGA_EXPORT void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType) { - return node->setNodeType(nodeType); -} - -YOGA_EXPORT bool YGNodeIsDirty(YGNodeRef node) { - return node->isDirty(); -} - -YOGA_EXPORT void YGNodeMarkDirtyAndPropagateToDescendants( - const YGNodeRef node) { - return node->markDirtyAndPropagateDownwards(); -} - -int32_t gConfigInstanceCount = 0; - -YOGA_EXPORT WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config) { - const YGNodeRef node = new YGNode{config}; - YGAssert(config != nullptr, "Tried to construct YGNode with null config"); - YGAssertWithConfig( - config, node != nullptr, "Could not allocate memory for node"); - Event::publish(node, {config}); - - return node; -} - -YOGA_EXPORT YGConfigRef YGConfigGetDefault() { - static YGConfigRef defaultConfig = YGConfigNew(); - return defaultConfig; -} - -YOGA_EXPORT YGNodeRef YGNodeNew(void) { - return YGNodeNewWithConfig(YGConfigGetDefault()); -} - -YOGA_EXPORT YGNodeRef YGNodeClone(YGNodeRef oldNode) { - YGNodeRef node = new YGNode(*oldNode); - YGAssertWithConfig( - oldNode->getConfig(), - node != nullptr, - "Could not allocate memory for node"); - Event::publish(node, {node->getConfig()}); - node->setOwner(nullptr); - return node; -} - -YOGA_EXPORT void YGNodeFree(const YGNodeRef node) { - if (YGNodeRef owner = node->getOwner()) { - owner->removeChild(node); - node->setOwner(nullptr); - } - - const uint32_t childCount = YGNodeGetChildCount(node); - for (uint32_t i = 0; i < childCount; i++) { - const YGNodeRef child = YGNodeGetChild(node, i); - child->setOwner(nullptr); - } - - node->clearChildren(); - YGNodeDeallocate(node); -} - -YOGA_EXPORT void YGNodeDeallocate(const YGNodeRef node) { - Event::publish(node, {node->getConfig()}); - delete node; -} - -YOGA_EXPORT void YGNodeFreeRecursiveWithCleanupFunc( - const YGNodeRef root, - YGNodeCleanupFunc cleanup) { - uint32_t skipped = 0; - while (YGNodeGetChildCount(root) > skipped) { - const YGNodeRef child = YGNodeGetChild(root, skipped); - if (child->getOwner() != root) { - // Don't free shared nodes that we don't own. - skipped += 1; - } else { - YGNodeRemoveChild(root, child); - YGNodeFreeRecursive(child); - } - } - if (cleanup != nullptr) { - cleanup(root); - } - YGNodeFree(root); -} - -YOGA_EXPORT void YGNodeFreeRecursive(const YGNodeRef root) { - return YGNodeFreeRecursiveWithCleanupFunc(root, nullptr); -} - -YOGA_EXPORT void YGNodeReset(YGNodeRef node) { - node->reset(); -} - -YOGA_EXPORT int32_t YGConfigGetInstanceCount(void) { - return gConfigInstanceCount; -} - -YOGA_EXPORT YGConfigRef YGConfigNew(void) { -#ifdef ANDROID - const YGConfigRef config = new YGConfig(YGAndroidLog); -#else - const YGConfigRef config = new YGConfig(YGDefaultLog); -#endif - gConfigInstanceCount++; - return config; -} - -YOGA_EXPORT void YGConfigFree(const YGConfigRef config) { - delete config; - gConfigInstanceCount--; -} - -void YGConfigCopy(const YGConfigRef dest, const YGConfigRef src) { - memcpy(dest, src, sizeof(YGConfig)); -} - -YOGA_EXPORT void YGNodeSetIsReferenceBaseline( - YGNodeRef node, - bool isReferenceBaseline) { - if (node->isReferenceBaseline() != isReferenceBaseline) { - node->setIsReferenceBaseline(isReferenceBaseline); - node->markDirtyAndPropagate(); - } -} - -YOGA_EXPORT bool YGNodeIsReferenceBaseline(YGNodeRef node) { - return node->isReferenceBaseline(); -} - -YOGA_EXPORT void YGNodeInsertChild( - const YGNodeRef owner, - const YGNodeRef child, - const uint32_t index) { - YGAssertWithNode( - owner, - child->getOwner() == nullptr, - "Child already has a owner, it must be removed first."); - - YGAssertWithNode( - owner, - !owner->hasMeasureFunc(), - "Cannot add child: Nodes with measure functions cannot have children."); - - owner->insertChild(child, index); - child->setOwner(owner); - owner->markDirtyAndPropagate(); -} - -YOGA_EXPORT void YGNodeSwapChild( - const YGNodeRef owner, - const YGNodeRef child, - const uint32_t index) { - owner->replaceChild(child, index); - child->setOwner(owner); -} - -YOGA_EXPORT void YGNodeRemoveChild( - const YGNodeRef owner, - const YGNodeRef excludedChild) { - if (YGNodeGetChildCount(owner) == 0) { - // This is an empty set. Nothing to remove. - return; - } - - // Children may be shared between parents, which is indicated by not having an - // owner. We only want to reset the child completely if it is owned - // exclusively by one node. - auto childOwner = excludedChild->getOwner(); - if (owner->removeChild(excludedChild)) { - if (owner == childOwner) { - excludedChild->setLayout({}); // layout is no longer valid - excludedChild->setOwner(nullptr); - } - owner->markDirtyAndPropagate(); - } -} - -YOGA_EXPORT void YGNodeRemoveAllChildren(const YGNodeRef owner) { - const uint32_t childCount = YGNodeGetChildCount(owner); - if (childCount == 0) { - // This is an empty set already. Nothing to do. - return; - } - const YGNodeRef firstChild = YGNodeGetChild(owner, 0); - if (firstChild->getOwner() == owner) { - // If the first child has this node as its owner, we assume that this child - // set is unique. - for (uint32_t i = 0; i < childCount; i++) { - const YGNodeRef oldChild = YGNodeGetChild(owner, i); - oldChild->setLayout(YGNode().getLayout()); // layout is no longer valid - oldChild->setOwner(nullptr); - } - owner->clearChildren(); - owner->markDirtyAndPropagate(); - return; - } - // Otherwise, we are not the owner of the child set. We don't have to do - // anything to clear it. - owner->setChildren(YGVector()); - owner->markDirtyAndPropagate(); -} - -YOGA_EXPORT void YGNodeSetChildren( - const YGNodeRef owner, - const YGNodeRef* children, - const uint32_t count) { - if (!owner) { - return; - } - - const YGVector childrenVector = {children, children + count}; - if (childrenVector.size() == 0) { - if (YGNodeGetChildCount(owner) > 0) { - for (YGNodeRef const child : owner->getChildren()) { - child->setLayout(YGLayout()); - child->setOwner(nullptr); - } - owner->setChildren(YGVector()); - owner->markDirtyAndPropagate(); - } - } else { - if (YGNodeGetChildCount(owner) > 0) { - for (YGNodeRef const oldChild : owner->getChildren()) { - // Our new children may have nodes in common with the old children. We - // don't reset these common nodes. - if (std::find(childrenVector.begin(), childrenVector.end(), oldChild) == - childrenVector.end()) { - oldChild->setLayout(YGLayout()); - oldChild->setOwner(nullptr); - } - } - } - owner->setChildren(childrenVector); - for (YGNodeRef child : childrenVector) { - child->setOwner(owner); - } - owner->markDirtyAndPropagate(); - } -} - -YOGA_EXPORT YGNodeRef -YGNodeGetChild(const YGNodeRef node, const uint32_t index) { - if (index < node->getChildren().size()) { - return node->getChild(index); - } - return nullptr; -} - -YOGA_EXPORT uint32_t YGNodeGetChildCount(const YGNodeRef node) { - return static_cast(node->getChildren().size()); -} - -YOGA_EXPORT YGNodeRef YGNodeGetOwner(const YGNodeRef node) { - return node->getOwner(); -} - -YOGA_EXPORT YGNodeRef YGNodeGetParent(const YGNodeRef node) { - return node->getOwner(); -} - -YOGA_EXPORT void YGNodeMarkDirty(const YGNodeRef node) { - YGAssertWithNode( - node, - node->hasMeasureFunc(), - "Only leaf nodes with custom measure functions " - "should manually mark themselves as dirty"); - - node->markDirtyAndPropagate(); -} - -YOGA_EXPORT void YGNodeCopyStyle( - const YGNodeRef dstNode, - const YGNodeRef srcNode) { - if (!(dstNode->getStyle() == srcNode->getStyle())) { - dstNode->setStyle(srcNode->getStyle()); - dstNode->markDirtyAndPropagate(); - } -} - -YOGA_EXPORT float YGNodeStyleGetFlexGrow(const YGNodeConstRef node) { - return node->getStyle().flexGrow().isUndefined() - ? kDefaultFlexGrow - : node->getStyle().flexGrow().unwrap(); -} - -YOGA_EXPORT float YGNodeStyleGetFlexShrink(const YGNodeConstRef node) { - return node->getStyle().flexShrink().isUndefined() - ? (node->getConfig()->useWebDefaults() ? kWebDefaultFlexShrink - : kDefaultFlexShrink) - : node->getStyle().flexShrink().unwrap(); -} - -namespace { - -template -void updateStyle( - YGNode* node, - T value, - NeedsUpdate&& needsUpdate, - Update&& update) { - if (needsUpdate(node->getStyle(), value)) { - update(node->getStyle(), value); - node->markDirtyAndPropagate(); - } -} - -template -void updateStyle(YGNode* node, Ref (YGStyle::*prop)(), T value) { - updateStyle( - node, - value, - [prop](YGStyle& s, T x) { return (s.*prop)() != x; }, - [prop](YGStyle& s, T x) { (s.*prop)() = x; }); -} - -template -void updateIndexedStyleProp( - YGNode* node, - Ref (YGStyle::*prop)(), - Idx idx, - detail::CompactValue value) { - using detail::CompactValue; - updateStyle( - node, - value, - [idx, prop](YGStyle& s, CompactValue x) { return (s.*prop)()[idx] != x; }, - [idx, prop](YGStyle& s, CompactValue x) { (s.*prop)()[idx] = x; }); -} - -} // namespace - -// MSVC has trouble inferring the return type of pointer to member functions -// with const and non-const overloads, instead of preferring the non-const -// overload like clang and GCC. For the purposes of updateStyle(), we can help -// MSVC by specifying that return type explicitly. In combination with -// decltype, MSVC will prefer the non-const version. -#define MSVC_HINT(PROP) decltype(YGStyle{}.PROP()) - -YOGA_EXPORT void YGNodeStyleSetDirection( - const YGNodeRef node, - const YGDirection value) { - updateStyle(node, &YGStyle::direction, value); -} -YOGA_EXPORT YGDirection YGNodeStyleGetDirection(const YGNodeConstRef node) { - return node->getStyle().direction(); -} - -YOGA_EXPORT void YGNodeStyleSetFlexDirection( - const YGNodeRef node, - const YGFlexDirection flexDirection) { - updateStyle( - node, &YGStyle::flexDirection, flexDirection); -} -YOGA_EXPORT YGFlexDirection -YGNodeStyleGetFlexDirection(const YGNodeConstRef node) { - return node->getStyle().flexDirection(); -} - -YOGA_EXPORT void YGNodeStyleSetJustifyContent( - const YGNodeRef node, - const YGJustify justifyContent) { - updateStyle( - node, &YGStyle::justifyContent, justifyContent); -} -YOGA_EXPORT YGJustify YGNodeStyleGetJustifyContent(const YGNodeConstRef node) { - return node->getStyle().justifyContent(); -} - -YOGA_EXPORT void YGNodeStyleSetAlignContent( - const YGNodeRef node, - const YGAlign alignContent) { - updateStyle( - node, &YGStyle::alignContent, alignContent); -} -YOGA_EXPORT YGAlign YGNodeStyleGetAlignContent(const YGNodeConstRef node) { - return node->getStyle().alignContent(); -} - -YOGA_EXPORT void YGNodeStyleSetAlignItems( - const YGNodeRef node, - const YGAlign alignItems) { - updateStyle(node, &YGStyle::alignItems, alignItems); -} -YOGA_EXPORT YGAlign YGNodeStyleGetAlignItems(const YGNodeConstRef node) { - return node->getStyle().alignItems(); -} - -YOGA_EXPORT void YGNodeStyleSetAlignSelf( - const YGNodeRef node, - const YGAlign alignSelf) { - updateStyle(node, &YGStyle::alignSelf, alignSelf); -} -YOGA_EXPORT YGAlign YGNodeStyleGetAlignSelf(const YGNodeConstRef node) { - return node->getStyle().alignSelf(); -} - -YOGA_EXPORT void YGNodeStyleSetPositionType( - const YGNodeRef node, - const YGPositionType positionType) { - updateStyle( - node, &YGStyle::positionType, positionType); -} -YOGA_EXPORT YGPositionType -YGNodeStyleGetPositionType(const YGNodeConstRef node) { - return node->getStyle().positionType(); -} - -YOGA_EXPORT void YGNodeStyleSetFlexWrap( - const YGNodeRef node, - const YGWrap flexWrap) { - updateStyle(node, &YGStyle::flexWrap, flexWrap); -} -YOGA_EXPORT YGWrap YGNodeStyleGetFlexWrap(const YGNodeConstRef node) { - return node->getStyle().flexWrap(); -} - -YOGA_EXPORT void YGNodeStyleSetOverflow( - const YGNodeRef node, - const YGOverflow overflow) { - updateStyle(node, &YGStyle::overflow, overflow); -} -YOGA_EXPORT YGOverflow YGNodeStyleGetOverflow(const YGNodeConstRef node) { - return node->getStyle().overflow(); -} - -YOGA_EXPORT void YGNodeStyleSetDisplay( - const YGNodeRef node, - const YGDisplay display) { - updateStyle(node, &YGStyle::display, display); -} -YOGA_EXPORT YGDisplay YGNodeStyleGetDisplay(const YGNodeConstRef node) { - return node->getStyle().display(); -} - -// TODO(T26792433): Change the API to accept YGFloatOptional. -YOGA_EXPORT void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) { - updateStyle(node, &YGStyle::flex, YGFloatOptional{flex}); -} - -// TODO(T26792433): Change the API to accept YGFloatOptional. -YOGA_EXPORT float YGNodeStyleGetFlex(const YGNodeConstRef node) { - return node->getStyle().flex().isUndefined() - ? YGUndefined - : node->getStyle().flex().unwrap(); -} - -// TODO(T26792433): Change the API to accept YGFloatOptional. -YOGA_EXPORT void YGNodeStyleSetFlexGrow( - const YGNodeRef node, - const float flexGrow) { - updateStyle( - node, &YGStyle::flexGrow, YGFloatOptional{flexGrow}); -} - -// TODO(T26792433): Change the API to accept YGFloatOptional. -YOGA_EXPORT void YGNodeStyleSetFlexShrink( - const YGNodeRef node, - const float flexShrink) { - updateStyle( - node, &YGStyle::flexShrink, YGFloatOptional{flexShrink}); -} - -YOGA_EXPORT YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) { - YGValue flexBasis = node->getStyle().flexBasis(); - if (flexBasis.unit == YGUnitUndefined || flexBasis.unit == YGUnitAuto) { - // TODO(T26792433): Get rid off the use of YGUndefined at client side - flexBasis.value = YGUndefined; - } - return flexBasis; -} - -YOGA_EXPORT void YGNodeStyleSetFlexBasis( - const YGNodeRef node, - const float flexBasis) { - auto value = detail::CompactValue::ofMaybe(flexBasis); - updateStyle(node, &YGStyle::flexBasis, value); -} - -YOGA_EXPORT void YGNodeStyleSetFlexBasisPercent( - const YGNodeRef node, - const float flexBasisPercent) { - auto value = detail::CompactValue::ofMaybe(flexBasisPercent); - updateStyle(node, &YGStyle::flexBasis, value); -} - -YOGA_EXPORT void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node) { - updateStyle( - node, &YGStyle::flexBasis, detail::CompactValue::ofAuto()); -} - -YOGA_EXPORT void YGNodeStyleSetPosition( - YGNodeRef node, - YGEdge edge, - float points) { - auto value = detail::CompactValue::ofMaybe(points); - updateIndexedStyleProp( - node, &YGStyle::position, edge, value); -} -YOGA_EXPORT void YGNodeStyleSetPositionPercent( - YGNodeRef node, - YGEdge edge, - float percent) { - auto value = detail::CompactValue::ofMaybe(percent); - updateIndexedStyleProp( - node, &YGStyle::position, edge, value); -} -YOGA_EXPORT YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) { - return node->getStyle().position()[edge]; -} - -YOGA_EXPORT void YGNodeStyleSetMargin( - YGNodeRef node, - YGEdge edge, - float points) { - auto value = detail::CompactValue::ofMaybe(points); - updateIndexedStyleProp( - node, &YGStyle::margin, edge, value); -} -YOGA_EXPORT void YGNodeStyleSetMarginPercent( - YGNodeRef node, - YGEdge edge, - float percent) { - auto value = detail::CompactValue::ofMaybe(percent); - updateIndexedStyleProp( - node, &YGStyle::margin, edge, value); -} -YOGA_EXPORT void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge) { - updateIndexedStyleProp( - node, &YGStyle::margin, edge, detail::CompactValue::ofAuto()); -} -YOGA_EXPORT YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) { - return node->getStyle().margin()[edge]; -} - -YOGA_EXPORT void YGNodeStyleSetPadding( - YGNodeRef node, - YGEdge edge, - float points) { - auto value = detail::CompactValue::ofMaybe(points); - updateIndexedStyleProp( - node, &YGStyle::padding, edge, value); -} -YOGA_EXPORT void YGNodeStyleSetPaddingPercent( - YGNodeRef node, - YGEdge edge, - float percent) { - auto value = detail::CompactValue::ofMaybe(percent); - updateIndexedStyleProp( - node, &YGStyle::padding, edge, value); -} -YOGA_EXPORT YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge) { - return node->getStyle().padding()[edge]; -} - -// TODO(T26792433): Change the API to accept YGFloatOptional. -YOGA_EXPORT void YGNodeStyleSetBorder( - const YGNodeRef node, - const YGEdge edge, - const float border) { - auto value = detail::CompactValue::ofMaybe(border); - updateIndexedStyleProp( - node, &YGStyle::border, edge, value); -} - -YOGA_EXPORT float YGNodeStyleGetBorder( - const YGNodeConstRef node, - const YGEdge edge) { - auto border = node->getStyle().border()[edge]; - if (border.isUndefined() || border.isAuto()) { - // TODO(T26792433): Rather than returning YGUndefined, change the api to - // return YGFloatOptional. - return YGUndefined; - } - - return static_cast(border).value; -} - -YOGA_EXPORT void YGNodeStyleSetGap( - const YGNodeRef node, - const YGGutter gutter, - const float gapLength) { - auto length = detail::CompactValue::ofMaybe(gapLength); - updateIndexedStyleProp(node, &YGStyle::gap, gutter, length); -} - -YOGA_EXPORT float YGNodeStyleGetGap( - const YGNodeConstRef node, - const YGGutter gutter) { - auto gapLength = node->getStyle().gap()[gutter]; - if (gapLength.isUndefined() || gapLength.isAuto()) { - // TODO(T26792433): Rather than returning YGUndefined, change the api to - // return YGFloatOptional. - return YGUndefined; - } - - return static_cast(gapLength).value; -} - -// Yoga specific properties, not compatible with flexbox specification - -// TODO(T26792433): Change the API to accept YGFloatOptional. -YOGA_EXPORT float YGNodeStyleGetAspectRatio(const YGNodeConstRef node) { - const YGFloatOptional op = node->getStyle().aspectRatio(); - return op.isUndefined() ? YGUndefined : op.unwrap(); -} - -// TODO(T26792433): Change the API to accept YGFloatOptional. -YOGA_EXPORT void YGNodeStyleSetAspectRatio( - const YGNodeRef node, - const float aspectRatio) { - updateStyle( - node, &YGStyle::aspectRatio, YGFloatOptional{aspectRatio}); -} - -YOGA_EXPORT void YGNodeStyleSetWidth(YGNodeRef node, float points) { - auto value = detail::CompactValue::ofMaybe(points); - updateIndexedStyleProp( - node, &YGStyle::dimensions, YGDimensionWidth, value); -} -YOGA_EXPORT void YGNodeStyleSetWidthPercent(YGNodeRef node, float percent) { - auto value = detail::CompactValue::ofMaybe(percent); - updateIndexedStyleProp( - node, &YGStyle::dimensions, YGDimensionWidth, value); -} -YOGA_EXPORT void YGNodeStyleSetWidthAuto(YGNodeRef node) { - updateIndexedStyleProp( - node, - &YGStyle::dimensions, - YGDimensionWidth, - detail::CompactValue::ofAuto()); -} -YOGA_EXPORT YGValue YGNodeStyleGetWidth(YGNodeConstRef node) { - return node->getStyle().dimensions()[YGDimensionWidth]; -} - -YOGA_EXPORT void YGNodeStyleSetHeight(YGNodeRef node, float points) { - auto value = detail::CompactValue::ofMaybe(points); - updateIndexedStyleProp( - node, &YGStyle::dimensions, YGDimensionHeight, value); -} -YOGA_EXPORT void YGNodeStyleSetHeightPercent(YGNodeRef node, float percent) { - auto value = detail::CompactValue::ofMaybe(percent); - updateIndexedStyleProp( - node, &YGStyle::dimensions, YGDimensionHeight, value); -} -YOGA_EXPORT void YGNodeStyleSetHeightAuto(YGNodeRef node) { - updateIndexedStyleProp( - node, - &YGStyle::dimensions, - YGDimensionHeight, - detail::CompactValue::ofAuto()); -} -YOGA_EXPORT YGValue YGNodeStyleGetHeight(YGNodeConstRef node) { - return node->getStyle().dimensions()[YGDimensionHeight]; -} - -YOGA_EXPORT void YGNodeStyleSetMinWidth( - const YGNodeRef node, - const float minWidth) { - auto value = detail::CompactValue::ofMaybe(minWidth); - updateIndexedStyleProp( - node, &YGStyle::minDimensions, YGDimensionWidth, value); -} -YOGA_EXPORT void YGNodeStyleSetMinWidthPercent( - const YGNodeRef node, - const float minWidth) { - auto value = detail::CompactValue::ofMaybe(minWidth); - updateIndexedStyleProp( - node, &YGStyle::minDimensions, YGDimensionWidth, value); -} -YOGA_EXPORT YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) { - return node->getStyle().minDimensions()[YGDimensionWidth]; -} - -YOGA_EXPORT void YGNodeStyleSetMinHeight( - const YGNodeRef node, - const float minHeight) { - auto value = detail::CompactValue::ofMaybe(minHeight); - updateIndexedStyleProp( - node, &YGStyle::minDimensions, YGDimensionHeight, value); -} -YOGA_EXPORT void YGNodeStyleSetMinHeightPercent( - const YGNodeRef node, - const float minHeight) { - auto value = detail::CompactValue::ofMaybe(minHeight); - updateIndexedStyleProp( - node, &YGStyle::minDimensions, YGDimensionHeight, value); -} -YOGA_EXPORT YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) { - return node->getStyle().minDimensions()[YGDimensionHeight]; -} - -YOGA_EXPORT void YGNodeStyleSetMaxWidth( - const YGNodeRef node, - const float maxWidth) { - auto value = detail::CompactValue::ofMaybe(maxWidth); - updateIndexedStyleProp( - node, &YGStyle::maxDimensions, YGDimensionWidth, value); -} -YOGA_EXPORT void YGNodeStyleSetMaxWidthPercent( - const YGNodeRef node, - const float maxWidth) { - auto value = detail::CompactValue::ofMaybe(maxWidth); - updateIndexedStyleProp( - node, &YGStyle::maxDimensions, YGDimensionWidth, value); -} -YOGA_EXPORT YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) { - return node->getStyle().maxDimensions()[YGDimensionWidth]; -} - -YOGA_EXPORT void YGNodeStyleSetMaxHeight( - const YGNodeRef node, - const float maxHeight) { - auto value = detail::CompactValue::ofMaybe(maxHeight); - updateIndexedStyleProp( - node, &YGStyle::maxDimensions, YGDimensionHeight, value); -} -YOGA_EXPORT void YGNodeStyleSetMaxHeightPercent( - const YGNodeRef node, - const float maxHeight) { - auto value = detail::CompactValue::ofMaybe(maxHeight); - updateIndexedStyleProp( - node, &YGStyle::maxDimensions, YGDimensionHeight, value); -} -YOGA_EXPORT YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) { - return node->getStyle().maxDimensions()[YGDimensionHeight]; -} - -#define YG_NODE_LAYOUT_PROPERTY_IMPL(type, name, instanceName) \ - YOGA_EXPORT type YGNodeLayoutGet##name(const YGNodeRef node) { \ - return node->getLayout().instanceName; \ - } - -#define YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(type, name, instanceName) \ - YOGA_EXPORT type YGNodeLayoutGet##name( \ - const YGNodeRef node, const YGEdge edge) { \ - YGAssertWithNode( \ - node, \ - edge <= YGEdgeEnd, \ - "Cannot get layout properties of multi-edge shorthands"); \ - \ - if (edge == YGEdgeStart) { \ - if (node->getLayout().direction() == YGDirectionRTL) { \ - return node->getLayout().instanceName[YGEdgeRight]; \ - } else { \ - return node->getLayout().instanceName[YGEdgeLeft]; \ - } \ - } \ - \ - if (edge == YGEdgeEnd) { \ - if (node->getLayout().direction() == YGDirectionRTL) { \ - return node->getLayout().instanceName[YGEdgeLeft]; \ - } else { \ - return node->getLayout().instanceName[YGEdgeRight]; \ - } \ - } \ - \ - return node->getLayout().instanceName[edge]; \ - } - -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()) -YG_NODE_LAYOUT_PROPERTY_IMPL(bool, HadOverflow, hadOverflow()) - -YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Margin, margin) -YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Border, border) -YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Padding, padding) - -std::atomic gCurrentGenerationCount(0); - -bool YGLayoutNodeInternal( - const YGNodeRef node, - const float availableWidth, - const float availableHeight, - const YGDirection ownerDirection, - const YGMeasureMode widthMeasureMode, - const YGMeasureMode heightMeasureMode, - const float ownerWidth, - const float ownerHeight, - const bool performLayout, - const LayoutPassReason reason, - const YGConfigRef config, - LayoutData& layoutMarkerData, - void* const layoutContext, - const uint32_t depth, - const uint32_t generationCount); - -#ifdef DEBUG -static void YGNodePrintInternal( - const YGNodeRef node, - const YGPrintOptions options) { - std::string str; - facebook::yoga::YGNodeToString(str, node, options, 0); - Log::log(node, YGLogLevelDebug, nullptr, str.c_str()); -} - -YOGA_EXPORT void YGNodePrint( - const YGNodeRef node, - const YGPrintOptions options) { - YGNodePrintInternal(node, options); -} -#endif - -const std::array leading = { - {YGEdgeTop, YGEdgeBottom, YGEdgeLeft, YGEdgeRight}}; - -const std::array trailing = { - {YGEdgeBottom, YGEdgeTop, YGEdgeRight, YGEdgeLeft}}; -static const std::array pos = {{ - YGEdgeTop, - YGEdgeBottom, - YGEdgeLeft, - YGEdgeRight, -}}; - -static const std::array dim = { - {YGDimensionHeight, YGDimensionHeight, YGDimensionWidth, YGDimensionWidth}}; - -static inline float YGNodePaddingAndBorderForAxis( - const YGNodeConstRef node, - const YGFlexDirection axis, - const float widthSize) { - return (node->getLeadingPaddingAndBorder(axis, widthSize) + - node->getTrailingPaddingAndBorder(axis, widthSize)) - .unwrap(); -} - -static inline YGAlign YGNodeAlignItem(const YGNode* node, const YGNode* child) { - const YGAlign align = child->getStyle().alignSelf() == YGAlignAuto - ? node->getStyle().alignItems() - : child->getStyle().alignSelf(); - if (align == YGAlignBaseline && - YGFlexDirectionIsColumn(node->getStyle().flexDirection())) { - return YGAlignFlexStart; - } - return align; -} - -static float YGBaseline(const YGNodeRef node, void* layoutContext) { - if (node->hasBaselineFunc()) { - - Event::publish(node); - - const float baseline = node->baseline( - node->getLayout().measuredDimensions[YGDimensionWidth], - node->getLayout().measuredDimensions[YGDimensionHeight], - layoutContext); - - Event::publish(node); - - YGAssertWithNode( - node, - !YGFloatIsUndefined(baseline), - "Expect custom baseline function to not return NaN"); - return baseline; - } - - YGNodeRef baselineChild = nullptr; - const uint32_t childCount = YGNodeGetChildCount(node); - for (uint32_t i = 0; i < childCount; i++) { - const YGNodeRef child = YGNodeGetChild(node, i); - if (child->getLineIndex() > 0) { - break; - } - if (child->getStyle().positionType() == YGPositionTypeAbsolute) { - continue; - } - if (YGNodeAlignItem(node, child) == YGAlignBaseline || - child->isReferenceBaseline()) { - baselineChild = child; - break; - } - - if (baselineChild == nullptr) { - baselineChild = child; - } - } - - if (baselineChild == nullptr) { - return node->getLayout().measuredDimensions[YGDimensionHeight]; - } - - const float baseline = YGBaseline(baselineChild, layoutContext); - return baseline + baselineChild->getLayout().position[YGEdgeTop]; -} - -static bool YGIsBaselineLayout(const YGNodeRef node) { - if (YGFlexDirectionIsColumn(node->getStyle().flexDirection())) { - return false; - } - if (node->getStyle().alignItems() == YGAlignBaseline) { - return true; - } - const uint32_t childCount = YGNodeGetChildCount(node); - for (uint32_t i = 0; i < childCount; i++) { - const YGNodeRef child = YGNodeGetChild(node, i); - if (child->getStyle().positionType() != YGPositionTypeAbsolute && - child->getStyle().alignSelf() == YGAlignBaseline) { - return true; - } - } - - return false; -} - -static inline float YGNodeDimWithMargin( - const YGNodeRef node, - const YGFlexDirection axis, - const float widthSize) { - return node->getLayout().measuredDimensions[dim[axis]] + - (node->getLeadingMargin(axis, widthSize) + - node->getTrailingMargin(axis, widthSize)) - .unwrap(); -} - -static inline bool YGNodeIsStyleDimDefined( - const YGNodeRef node, - const YGFlexDirection axis, - const float ownerSize) { - bool isUndefined = - YGFloatIsUndefined(node->getResolvedDimension(dim[axis]).value); - return !( - node->getResolvedDimension(dim[axis]).unit == YGUnitAuto || - node->getResolvedDimension(dim[axis]).unit == YGUnitUndefined || - (node->getResolvedDimension(dim[axis]).unit == YGUnitPoint && - !isUndefined && node->getResolvedDimension(dim[axis]).value < 0.0f) || - (node->getResolvedDimension(dim[axis]).unit == YGUnitPercent && - !isUndefined && - (node->getResolvedDimension(dim[axis]).value < 0.0f || - YGFloatIsUndefined(ownerSize)))); -} - -static inline bool YGNodeIsLayoutDimDefined( - const YGNodeRef node, - const YGFlexDirection axis) { - const float value = node->getLayout().measuredDimensions[dim[axis]]; - return !YGFloatIsUndefined(value) && value >= 0.0f; -} - -static YGFloatOptional YGNodeBoundAxisWithinMinAndMax( - const YGNodeConstRef node, - const YGFlexDirection axis, - const YGFloatOptional value, - const float axisSize) { - YGFloatOptional min; - YGFloatOptional max; - - if (YGFlexDirectionIsColumn(axis)) { - min = YGResolveValue( - node->getStyle().minDimensions()[YGDimensionHeight], axisSize); - max = YGResolveValue( - node->getStyle().maxDimensions()[YGDimensionHeight], axisSize); - } else if (YGFlexDirectionIsRow(axis)) { - min = YGResolveValue( - node->getStyle().minDimensions()[YGDimensionWidth], axisSize); - max = YGResolveValue( - node->getStyle().maxDimensions()[YGDimensionWidth], axisSize); - } - - if (max >= YGFloatOptional{0} && value > max) { - return max; - } - - if (min >= YGFloatOptional{0} && value < min) { - return min; - } - - return value; -} - -// 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, - const float axisSize, - const float widthSize) { - return YGFloatMax( - YGNodeBoundAxisWithinMinAndMax( - node, axis, YGFloatOptional{value}, axisSize) - .unwrap(), - YGNodePaddingAndBorderForAxis(node, axis, widthSize)); -} - -static void YGNodeSetChildTrailingPosition( - const YGNodeRef node, - const YGNodeRef child, - const YGFlexDirection axis) { - const float size = child->getLayout().measuredDimensions[dim[axis]]; - child->setLayoutPosition( - node->getLayout().measuredDimensions[dim[axis]] - size - - child->getLayout().position[pos[axis]], - trailing[axis]); -} - -static void YGConstrainMaxSizeForMode( - const YGNodeConstRef node, - const enum YGFlexDirection axis, - const float ownerAxisSize, - const float ownerWidth, - YGMeasureMode* mode, - float* size) { - const YGFloatOptional maxSize = - YGResolveValue( - node->getStyle().maxDimensions()[dim[axis]], ownerAxisSize) + - YGFloatOptional(node->getMarginForAxis(axis, ownerWidth)); - switch (*mode) { - case YGMeasureModeExactly: - case YGMeasureModeAtMost: - *size = (maxSize.isUndefined() || *size < maxSize.unwrap()) - ? *size - : maxSize.unwrap(); - break; - case YGMeasureModeUndefined: - if (!maxSize.isUndefined()) { - *mode = YGMeasureModeAtMost; - *size = maxSize.unwrap(); - } - break; - } -} - -static void YGNodeComputeFlexBasisForChild( - const YGNodeRef node, - const YGNodeRef child, - const float width, - const YGMeasureMode widthMode, - const float height, - const float ownerWidth, - const float ownerHeight, - const YGMeasureMode heightMode, - const YGDirection direction, - const YGConfigRef config, - LayoutData& layoutMarkerData, - void* const layoutContext, - const uint32_t depth, - const uint32_t generationCount) { - const YGFlexDirection mainAxis = - YGResolveFlexDirection(node->getStyle().flexDirection(), direction); - const bool isMainAxisRow = YGFlexDirectionIsRow(mainAxis); - const float mainAxisSize = isMainAxisRow ? width : height; - const float mainAxisownerSize = isMainAxisRow ? ownerWidth : ownerHeight; - - float childWidth; - float childHeight; - YGMeasureMode childWidthMeasureMode; - YGMeasureMode childHeightMeasureMode; - - const YGFloatOptional resolvedFlexBasis = - YGResolveValue(child->resolveFlexBasisPtr(), mainAxisownerSize); - const bool isRowStyleDimDefined = - YGNodeIsStyleDimDefined(child, YGFlexDirectionRow, ownerWidth); - const bool isColumnStyleDimDefined = - YGNodeIsStyleDimDefined(child, YGFlexDirectionColumn, ownerHeight); - - if (!resolvedFlexBasis.isUndefined() && !YGFloatIsUndefined(mainAxisSize)) { - if (child->getLayout().computedFlexBasis.isUndefined() || - (child->getConfig()->isExperimentalFeatureEnabled( - YGExperimentalFeatureWebFlexBasis) && - child->getLayout().computedFlexBasisGeneration != generationCount)) { - const YGFloatOptional paddingAndBorder = YGFloatOptional( - YGNodePaddingAndBorderForAxis(child, mainAxis, ownerWidth)); - child->setLayoutComputedFlexBasis( - YGFloatOptionalMax(resolvedFlexBasis, paddingAndBorder)); - } - } else if (isMainAxisRow && isRowStyleDimDefined) { - // The width is definite, so use that as the flex basis. - const YGFloatOptional paddingAndBorder = YGFloatOptional( - YGNodePaddingAndBorderForAxis(child, YGFlexDirectionRow, ownerWidth)); - - child->setLayoutComputedFlexBasis(YGFloatOptionalMax( - YGResolveValue( - child->getResolvedDimensions()[YGDimensionWidth], ownerWidth), - paddingAndBorder)); - } else if (!isMainAxisRow && isColumnStyleDimDefined) { - // The height is definite, so use that as the flex basis. - const YGFloatOptional paddingAndBorder = - YGFloatOptional(YGNodePaddingAndBorderForAxis( - child, YGFlexDirectionColumn, ownerWidth)); - child->setLayoutComputedFlexBasis(YGFloatOptionalMax( - YGResolveValue( - child->getResolvedDimensions()[YGDimensionHeight], ownerHeight), - paddingAndBorder)); - } else { - // Compute the flex basis and hypothetical main size (i.e. the clamped flex - // basis). - childWidth = YGUndefined; - childHeight = YGUndefined; - childWidthMeasureMode = YGMeasureModeUndefined; - childHeightMeasureMode = YGMeasureModeUndefined; - - auto marginRow = - child->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap(); - auto marginColumn = - child->getMarginForAxis(YGFlexDirectionColumn, ownerWidth).unwrap(); - - if (isRowStyleDimDefined) { - childWidth = - YGResolveValue( - child->getResolvedDimensions()[YGDimensionWidth], ownerWidth) - .unwrap() + - marginRow; - childWidthMeasureMode = YGMeasureModeExactly; - } - if (isColumnStyleDimDefined) { - childHeight = - YGResolveValue( - child->getResolvedDimensions()[YGDimensionHeight], ownerHeight) - .unwrap() + - marginColumn; - 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->getStyle().overflow() == YGOverflowScroll) || - node->getStyle().overflow() != YGOverflowScroll) { - if (YGFloatIsUndefined(childWidth) && !YGFloatIsUndefined(width)) { - childWidth = width; - childWidthMeasureMode = YGMeasureModeAtMost; - } - } - - if ((isMainAxisRow && node->getStyle().overflow() == YGOverflowScroll) || - node->getStyle().overflow() != YGOverflowScroll) { - if (YGFloatIsUndefined(childHeight) && !YGFloatIsUndefined(height)) { - childHeight = height; - childHeightMeasureMode = YGMeasureModeAtMost; - } - } - - const auto& childStyle = child->getStyle(); - if (!childStyle.aspectRatio().isUndefined()) { - if (!isMainAxisRow && childWidthMeasureMode == YGMeasureModeExactly) { - childHeight = marginColumn + - (childWidth - marginRow) / childStyle.aspectRatio().unwrap(); - childHeightMeasureMode = YGMeasureModeExactly; - } else if ( - isMainAxisRow && childHeightMeasureMode == YGMeasureModeExactly) { - childWidth = marginRow + - (childHeight - marginColumn) * childStyle.aspectRatio().unwrap(); - childWidthMeasureMode = YGMeasureModeExactly; - } - } - - // 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 - - const bool hasExactWidth = - !YGFloatIsUndefined(width) && widthMode == YGMeasureModeExactly; - const bool childWidthStretch = - YGNodeAlignItem(node, child) == YGAlignStretch && - childWidthMeasureMode != YGMeasureModeExactly; - if (!isMainAxisRow && !isRowStyleDimDefined && hasExactWidth && - childWidthStretch) { - childWidth = width; - childWidthMeasureMode = YGMeasureModeExactly; - if (!childStyle.aspectRatio().isUndefined()) { - childHeight = - (childWidth - marginRow) / childStyle.aspectRatio().unwrap(); - childHeightMeasureMode = YGMeasureModeExactly; - } - } - - const bool hasExactHeight = - !YGFloatIsUndefined(height) && heightMode == YGMeasureModeExactly; - const bool childHeightStretch = - YGNodeAlignItem(node, child) == YGAlignStretch && - childHeightMeasureMode != YGMeasureModeExactly; - if (isMainAxisRow && !isColumnStyleDimDefined && hasExactHeight && - childHeightStretch) { - childHeight = height; - childHeightMeasureMode = YGMeasureModeExactly; - - if (!childStyle.aspectRatio().isUndefined()) { - childWidth = - (childHeight - marginColumn) * childStyle.aspectRatio().unwrap(); - childWidthMeasureMode = YGMeasureModeExactly; - } - } - - YGConstrainMaxSizeForMode( - child, - YGFlexDirectionRow, - ownerWidth, - ownerWidth, - &childWidthMeasureMode, - &childWidth); - YGConstrainMaxSizeForMode( - child, - YGFlexDirectionColumn, - ownerHeight, - ownerWidth, - &childHeightMeasureMode, - &childHeight); - - // Measure the child - YGLayoutNodeInternal( - child, - childWidth, - childHeight, - direction, - childWidthMeasureMode, - childHeightMeasureMode, - ownerWidth, - ownerHeight, - false, - LayoutPassReason::kMeasureChild, - config, - layoutMarkerData, - layoutContext, - depth, - generationCount); - - child->setLayoutComputedFlexBasis(YGFloatOptional(YGFloatMax( - child->getLayout().measuredDimensions[dim[mainAxis]], - YGNodePaddingAndBorderForAxis(child, mainAxis, ownerWidth)))); - } - child->setLayoutComputedFlexBasisGeneration(generationCount); -} - -static void YGNodeAbsoluteLayoutChild( - const YGNodeRef node, - const YGNodeRef child, - const float width, - const YGMeasureMode widthMode, - const float height, - const YGDirection direction, - const YGConfigRef config, - LayoutData& layoutMarkerData, - void* const layoutContext, - const uint32_t depth, - const uint32_t generationCount) { - const YGFlexDirection mainAxis = - YGResolveFlexDirection(node->getStyle().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; - - auto marginRow = child->getMarginForAxis(YGFlexDirectionRow, width).unwrap(); - auto marginColumn = - child->getMarginForAxis(YGFlexDirectionColumn, width).unwrap(); - - if (YGNodeIsStyleDimDefined(child, YGFlexDirectionRow, width)) { - childWidth = - YGResolveValue(child->getResolvedDimensions()[YGDimensionWidth], width) - .unwrap() + - marginRow; - } else { - // If the child doesn't have a specified width, compute the width based on - // the left/right offsets if they're defined. - if (child->isLeadingPositionDefined(YGFlexDirectionRow) && - child->isTrailingPosDefined(YGFlexDirectionRow)) { - childWidth = node->getLayout().measuredDimensions[YGDimensionWidth] - - (node->getLeadingBorder(YGFlexDirectionRow) + - node->getTrailingBorder(YGFlexDirectionRow)) - - (child->getLeadingPosition(YGFlexDirectionRow, width) + - child->getTrailingPosition(YGFlexDirectionRow, width)) - .unwrap(); - childWidth = - YGNodeBoundAxis(child, YGFlexDirectionRow, childWidth, width, width); - } - } - - if (YGNodeIsStyleDimDefined(child, YGFlexDirectionColumn, height)) { - childHeight = YGResolveValue( - child->getResolvedDimensions()[YGDimensionHeight], height) - .unwrap() + - marginColumn; - } else { - // If the child doesn't have a specified height, compute the height based on - // the top/bottom offsets if they're defined. - if (child->isLeadingPositionDefined(YGFlexDirectionColumn) && - child->isTrailingPosDefined(YGFlexDirectionColumn)) { - childHeight = node->getLayout().measuredDimensions[YGDimensionHeight] - - (node->getLeadingBorder(YGFlexDirectionColumn) + - node->getTrailingBorder(YGFlexDirectionColumn)) - - (child->getLeadingPosition(YGFlexDirectionColumn, height) + - child->getTrailingPosition(YGFlexDirectionColumn, height)) - .unwrap(); - childHeight = YGNodeBoundAxis( - child, YGFlexDirectionColumn, childHeight, height, width); - } - } - - // 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. - const auto& childStyle = child->getStyle(); - if (YGFloatIsUndefined(childWidth) ^ YGFloatIsUndefined(childHeight)) { - if (!childStyle.aspectRatio().isUndefined()) { - if (YGFloatIsUndefined(childWidth)) { - childWidth = marginRow + - (childHeight - marginColumn) * childStyle.aspectRatio().unwrap(); - } else if (YGFloatIsUndefined(childHeight)) { - childHeight = marginColumn + - (childWidth - marginRow) / childStyle.aspectRatio().unwrap(); - } - } - } - - // If we're still missing one or the other dimension, measure the content. - if (YGFloatIsUndefined(childWidth) || YGFloatIsUndefined(childHeight)) { - childWidthMeasureMode = YGFloatIsUndefined(childWidth) - ? YGMeasureModeUndefined - : YGMeasureModeExactly; - childHeightMeasureMode = YGFloatIsUndefined(childHeight) - ? YGMeasureModeUndefined - : YGMeasureModeExactly; - - // If the size of the owner is defined then try to constrain the absolute - // child to that size as well. This allows text within the absolute child to - // wrap to the size of its owner. This is the same behavior as many browsers - // implement. - if (!isMainAxisRow && YGFloatIsUndefined(childWidth) && - widthMode != YGMeasureModeUndefined && !YGFloatIsUndefined(width) && - width > 0) { - childWidth = width; - childWidthMeasureMode = YGMeasureModeAtMost; - } - - YGLayoutNodeInternal( - child, - childWidth, - childHeight, - direction, - childWidthMeasureMode, - childHeightMeasureMode, - childWidth, - childHeight, - false, - LayoutPassReason::kAbsMeasureChild, - config, - layoutMarkerData, - layoutContext, - depth, - generationCount); - childWidth = child->getLayout().measuredDimensions[YGDimensionWidth] + - child->getMarginForAxis(YGFlexDirectionRow, width).unwrap(); - childHeight = child->getLayout().measuredDimensions[YGDimensionHeight] + - child->getMarginForAxis(YGFlexDirectionColumn, width).unwrap(); - } - - YGLayoutNodeInternal( - child, - childWidth, - childHeight, - direction, - YGMeasureModeExactly, - YGMeasureModeExactly, - childWidth, - childHeight, - true, - LayoutPassReason::kAbsLayout, - config, - layoutMarkerData, - layoutContext, - depth, - generationCount); - - if (child->isTrailingPosDefined(mainAxis) && - !child->isLeadingPositionDefined(mainAxis)) { - child->setLayoutPosition( - node->getLayout().measuredDimensions[dim[mainAxis]] - - child->getLayout().measuredDimensions[dim[mainAxis]] - - node->getTrailingBorder(mainAxis) - - child->getTrailingMargin(mainAxis, isMainAxisRow ? width : height) - .unwrap() - - child->getTrailingPosition(mainAxis, isMainAxisRow ? width : height) - .unwrap(), - leading[mainAxis]); - } else if ( - !child->isLeadingPositionDefined(mainAxis) && - node->getStyle().justifyContent() == YGJustifyCenter) { - child->setLayoutPosition( - (node->getLayout().measuredDimensions[dim[mainAxis]] - - child->getLayout().measuredDimensions[dim[mainAxis]]) / - 2.0f, - leading[mainAxis]); - } else if ( - !child->isLeadingPositionDefined(mainAxis) && - node->getStyle().justifyContent() == YGJustifyFlexEnd) { - child->setLayoutPosition( - (node->getLayout().measuredDimensions[dim[mainAxis]] - - child->getLayout().measuredDimensions[dim[mainAxis]]), - leading[mainAxis]); - } else if ( - node->getConfig()->isExperimentalFeatureEnabled( - YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge) && - child->isLeadingPositionDefined(mainAxis)) { - child->setLayoutPosition( - child->getLeadingPosition( - mainAxis, node->getLayout().measuredDimensions[dim[mainAxis]]) - .unwrap() + - node->getLeadingBorder(mainAxis) + - child - ->getLeadingMargin( - mainAxis, - node->getLayout().measuredDimensions[dim[mainAxis]]) - .unwrap(), - leading[mainAxis]); - } - - if (child->isTrailingPosDefined(crossAxis) && - !child->isLeadingPositionDefined(crossAxis)) { - child->setLayoutPosition( - node->getLayout().measuredDimensions[dim[crossAxis]] - - child->getLayout().measuredDimensions[dim[crossAxis]] - - node->getTrailingBorder(crossAxis) - - child->getTrailingMargin(crossAxis, isMainAxisRow ? height : width) - .unwrap() - - child - ->getTrailingPosition(crossAxis, isMainAxisRow ? height : width) - .unwrap(), - leading[crossAxis]); - - } else if ( - !child->isLeadingPositionDefined(crossAxis) && - YGNodeAlignItem(node, child) == YGAlignCenter) { - child->setLayoutPosition( - (node->getLayout().measuredDimensions[dim[crossAxis]] - - child->getLayout().measuredDimensions[dim[crossAxis]]) / - 2.0f, - leading[crossAxis]); - } else if ( - !child->isLeadingPositionDefined(crossAxis) && - ((YGNodeAlignItem(node, child) == YGAlignFlexEnd) ^ - (node->getStyle().flexWrap() == YGWrapWrapReverse))) { - child->setLayoutPosition( - (node->getLayout().measuredDimensions[dim[crossAxis]] - - child->getLayout().measuredDimensions[dim[crossAxis]]), - leading[crossAxis]); - } else if ( - node->getConfig()->isExperimentalFeatureEnabled( - YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge) && - child->isLeadingPositionDefined(crossAxis)) { - child->setLayoutPosition( - child->getLeadingPosition( - crossAxis, - node->getLayout().measuredDimensions[dim[crossAxis]]) - .unwrap() + - node->getLeadingBorder(crossAxis) + - child - ->getLeadingMargin( - crossAxis, - node->getLayout().measuredDimensions[dim[crossAxis]]) - .unwrap(), - leading[crossAxis]); - } -} - -static void YGNodeWithMeasureFuncSetMeasuredDimensions( - const YGNodeRef node, - float availableWidth, - float availableHeight, - const YGMeasureMode widthMeasureMode, - const YGMeasureMode heightMeasureMode, - const float ownerWidth, - const float ownerHeight, - LayoutData& layoutMarkerData, - void* const layoutContext, - const LayoutPassReason reason) { - YGAssertWithNode( - node, - node->hasMeasureFunc(), - "Expected node to have custom measure function"); - - if (widthMeasureMode == YGMeasureModeUndefined) { - availableWidth = YGUndefined; - } - if (heightMeasureMode == YGMeasureModeUndefined) { - availableHeight = YGUndefined; - } - - const auto& padding = node->getLayout().padding; - const auto& border = node->getLayout().border; - const float paddingAndBorderAxisRow = padding[YGEdgeLeft] + - padding[YGEdgeRight] + border[YGEdgeLeft] + border[YGEdgeRight]; - const float paddingAndBorderAxisColumn = padding[YGEdgeTop] + - padding[YGEdgeBottom] + border[YGEdgeTop] + border[YGEdgeBottom]; - - // We want to make sure we don't call measure with negative size - const float innerWidth = YGFloatIsUndefined(availableWidth) - ? availableWidth - : YGFloatMax(0, availableWidth - paddingAndBorderAxisRow); - const float innerHeight = YGFloatIsUndefined(availableHeight) - ? availableHeight - : YGFloatMax(0, availableHeight - paddingAndBorderAxisColumn); - - if (widthMeasureMode == YGMeasureModeExactly && - heightMeasureMode == YGMeasureModeExactly) { - // Don't bother sizing the text if both dimensions are already defined. - node->setLayoutMeasuredDimension( - YGNodeBoundAxis( - node, YGFlexDirectionRow, availableWidth, ownerWidth, ownerWidth), - YGDimensionWidth); - node->setLayoutMeasuredDimension( - YGNodeBoundAxis( - node, - YGFlexDirectionColumn, - availableHeight, - ownerHeight, - ownerWidth), - YGDimensionHeight); - } else { - Event::publish(node); - - // Measure the text under the current constraints. - const YGSize measuredSize = node->measure( - innerWidth, - widthMeasureMode, - innerHeight, - heightMeasureMode, - layoutContext); - - layoutMarkerData.measureCallbacks += 1; - layoutMarkerData.measureCallbackReasonsCount[static_cast(reason)] += - 1; - - Event::publish( - node, - {layoutContext, - innerWidth, - widthMeasureMode, - innerHeight, - heightMeasureMode, - measuredSize.width, - measuredSize.height, - reason}); - - node->setLayoutMeasuredDimension( - YGNodeBoundAxis( - node, - YGFlexDirectionRow, - (widthMeasureMode == YGMeasureModeUndefined || - widthMeasureMode == YGMeasureModeAtMost) - ? measuredSize.width + paddingAndBorderAxisRow - : availableWidth, - ownerWidth, - ownerWidth), - YGDimensionWidth); - - node->setLayoutMeasuredDimension( - YGNodeBoundAxis( - node, - YGFlexDirectionColumn, - (heightMeasureMode == YGMeasureModeUndefined || - heightMeasureMode == YGMeasureModeAtMost) - ? measuredSize.height + paddingAndBorderAxisColumn - : availableHeight, - ownerHeight, - ownerWidth), - YGDimensionHeight); - } -} - -// 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 ownerWidth, - const float ownerHeight) { - const auto& padding = node->getLayout().padding; - const auto& border = node->getLayout().border; - - float width = availableWidth; - if (widthMeasureMode == YGMeasureModeUndefined || - widthMeasureMode == YGMeasureModeAtMost) { - width = padding[YGEdgeLeft] + padding[YGEdgeRight] + border[YGEdgeLeft] + - border[YGEdgeRight]; - } - node->setLayoutMeasuredDimension( - YGNodeBoundAxis(node, YGFlexDirectionRow, width, ownerWidth, ownerWidth), - YGDimensionWidth); - - float height = availableHeight; - if (heightMeasureMode == YGMeasureModeUndefined || - heightMeasureMode == YGMeasureModeAtMost) { - height = padding[YGEdgeTop] + padding[YGEdgeBottom] + border[YGEdgeTop] + - border[YGEdgeBottom]; - } - node->setLayoutMeasuredDimension( - YGNodeBoundAxis( - node, YGFlexDirectionColumn, height, ownerHeight, ownerWidth), - YGDimensionHeight); -} - -static bool YGNodeFixedSizeSetMeasuredDimensions( - const YGNodeRef node, - const float availableWidth, - const float availableHeight, - const YGMeasureMode widthMeasureMode, - const YGMeasureMode heightMeasureMode, - const float ownerWidth, - const float ownerHeight) { - if ((!YGFloatIsUndefined(availableWidth) && - widthMeasureMode == YGMeasureModeAtMost && availableWidth <= 0.0f) || - (!YGFloatIsUndefined(availableHeight) && - heightMeasureMode == YGMeasureModeAtMost && availableHeight <= 0.0f) || - (widthMeasureMode == YGMeasureModeExactly && - heightMeasureMode == YGMeasureModeExactly)) { - node->setLayoutMeasuredDimension( - YGNodeBoundAxis( - node, - YGFlexDirectionRow, - YGFloatIsUndefined(availableWidth) || - (widthMeasureMode == YGMeasureModeAtMost && - availableWidth < 0.0f) - ? 0.0f - : availableWidth, - ownerWidth, - ownerWidth), - YGDimensionWidth); - - node->setLayoutMeasuredDimension( - YGNodeBoundAxis( - node, - YGFlexDirectionColumn, - YGFloatIsUndefined(availableHeight) || - (heightMeasureMode == YGMeasureModeAtMost && - availableHeight < 0.0f) - ? 0.0f - : availableHeight, - ownerHeight, - ownerWidth), - YGDimensionHeight); - return true; - } - - return false; -} - -static void YGZeroOutLayoutRecursively( - const YGNodeRef node, - void* layoutContext) { - node->getLayout() = {}; - node->setLayoutDimension(0, 0); - node->setLayoutDimension(0, 1); - node->setHasNewLayout(true); - - node->iterChildrenAfterCloningIfNeeded( - YGZeroOutLayoutRecursively, layoutContext); -} - -static float YGNodeCalculateAvailableInnerDim( - const YGNodeConstRef node, - const YGDimension dimension, - const float availableDim, - const float paddingAndBorder, - const float ownerDim) { - float availableInnerDim = availableDim - paddingAndBorder; - // Max dimension overrides predefined dimension value; Min dimension in turn - // overrides both of the above - if (!YGFloatIsUndefined(availableInnerDim)) { - // We want to make sure our available height does not violate min and max - // constraints - const YGFloatOptional minDimensionOptional = - YGResolveValue(node->getStyle().minDimensions()[dimension], ownerDim); - const float minInnerDim = minDimensionOptional.isUndefined() - ? 0.0f - : minDimensionOptional.unwrap() - paddingAndBorder; - - const YGFloatOptional maxDimensionOptional = - YGResolveValue(node->getStyle().maxDimensions()[dimension], ownerDim); - - const float maxInnerDim = maxDimensionOptional.isUndefined() - ? FLT_MAX - : maxDimensionOptional.unwrap() - paddingAndBorder; - availableInnerDim = - YGFloatMax(YGFloatMin(availableInnerDim, maxInnerDim), minInnerDim); - } - - return availableInnerDim; -} - -static float YGNodeComputeFlexBasisForChildren( - const YGNodeRef node, - const float availableInnerWidth, - const float availableInnerHeight, - YGMeasureMode widthMeasureMode, - YGMeasureMode heightMeasureMode, - YGDirection direction, - YGFlexDirection mainAxis, - const YGConfigRef config, - bool performLayout, - LayoutData& layoutMarkerData, - void* const layoutContext, - const uint32_t depth, - const uint32_t generationCount) { - float totalOuterFlexBasis = 0.0f; - YGNodeRef singleFlexChild = nullptr; - const YGVector& children = node->getChildren(); - YGMeasureMode measureModeMainDim = - YGFlexDirectionIsRow(mainAxis) ? widthMeasureMode : heightMeasureMode; - // 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 - if (measureModeMainDim == YGMeasureModeExactly) { - for (auto child : children) { - if (child->isNodeFlexible()) { - if (singleFlexChild != nullptr || - YGFloatsEqual(child->resolveFlexGrow(), 0.0f) || - YGFloatsEqual(child->resolveFlexShrink(), 0.0f)) { - // There is already a flexible child, or this flexible child doesn't - // have flexGrow and flexShrink, abort - singleFlexChild = nullptr; - break; - } else { - singleFlexChild = child; - } - } - } - } - - for (auto child : children) { - child->resolveDimension(); - if (child->getStyle().display() == YGDisplayNone) { - YGZeroOutLayoutRecursively(child, layoutContext); - child->setHasNewLayout(true); - child->setDirty(false); - continue; - } - if (performLayout) { - // Set the initial position (relative to the owner). - const YGDirection childDirection = child->resolveDirection(direction); - const float mainDim = YGFlexDirectionIsRow(mainAxis) - ? availableInnerWidth - : availableInnerHeight; - const float crossDim = YGFlexDirectionIsRow(mainAxis) - ? availableInnerHeight - : availableInnerWidth; - child->setPosition( - childDirection, mainDim, crossDim, availableInnerWidth); - } - - if (child->getStyle().positionType() == YGPositionTypeAbsolute) { - continue; - } - if (child == singleFlexChild) { - child->setLayoutComputedFlexBasisGeneration(generationCount); - child->setLayoutComputedFlexBasis(YGFloatOptional(0)); - } else { - YGNodeComputeFlexBasisForChild( - node, - child, - availableInnerWidth, - widthMeasureMode, - availableInnerHeight, - availableInnerWidth, - availableInnerHeight, - heightMeasureMode, - direction, - config, - layoutMarkerData, - layoutContext, - depth, - generationCount); - } - - totalOuterFlexBasis += - (child->getLayout().computedFlexBasis + - child->getMarginForAxis(mainAxis, availableInnerWidth)) - .unwrap(); - } - - return totalOuterFlexBasis; -} - -// This function assumes that all the children of node have their -// computedFlexBasis properly computed(To do this use -// YGNodeComputeFlexBasisForChildren function). This function calculates -// YGCollectFlexItemsRowMeasurement -static YGCollectFlexItemsRowValues YGCalculateCollectFlexItemsRowValues( - const YGNodeRef& node, - const YGDirection ownerDirection, - const float mainAxisownerSize, - const float availableInnerWidth, - const float availableInnerMainDim, - const uint32_t startOfLineIndex, - const uint32_t lineCount) { - YGCollectFlexItemsRowValues flexAlgoRowMeasurement = {}; - flexAlgoRowMeasurement.relativeChildren.reserve(node->getChildren().size()); - - float sizeConsumedOnCurrentLineIncludingMinConstraint = 0; - const YGFlexDirection mainAxis = YGResolveFlexDirection( - node->getStyle().flexDirection(), node->resolveDirection(ownerDirection)); - const bool isNodeFlexWrap = node->getStyle().flexWrap() != YGWrapNoWrap; - const float gap = node->getGapForAxis(mainAxis, availableInnerWidth).unwrap(); - - // Add items to the current line until it's full or we run out of items. - uint32_t endOfLineIndex = startOfLineIndex; - for (; endOfLineIndex < node->getChildren().size(); endOfLineIndex++) { - const YGNodeRef child = node->getChild(endOfLineIndex); - if (child->getStyle().display() == YGDisplayNone || - child->getStyle().positionType() == YGPositionTypeAbsolute) { - continue; - } - - const bool isFirstElementInLine = (endOfLineIndex - startOfLineIndex) == 0; - - child->setLineIndex(lineCount); - const float childMarginMainAxis = - child->getMarginForAxis(mainAxis, availableInnerWidth).unwrap(); - const float childLeadingGapMainAxis = isFirstElementInLine ? 0.0f : gap; - const float flexBasisWithMinAndMaxConstraints = - YGNodeBoundAxisWithinMinAndMax( - child, - mainAxis, - child->getLayout().computedFlexBasis, - mainAxisownerSize) - .unwrap(); - - // 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 (sizeConsumedOnCurrentLineIncludingMinConstraint + - flexBasisWithMinAndMaxConstraints + childMarginMainAxis + - childLeadingGapMainAxis > - availableInnerMainDim && - isNodeFlexWrap && flexAlgoRowMeasurement.itemsOnLine > 0) { - break; - } - - sizeConsumedOnCurrentLineIncludingMinConstraint += - flexBasisWithMinAndMaxConstraints + childMarginMainAxis + - childLeadingGapMainAxis; - flexAlgoRowMeasurement.sizeConsumedOnCurrentLine += - flexBasisWithMinAndMaxConstraints + childMarginMainAxis + - childLeadingGapMainAxis; - flexAlgoRowMeasurement.itemsOnLine++; - - if (child->isNodeFlexible()) { - flexAlgoRowMeasurement.totalFlexGrowFactors += child->resolveFlexGrow(); - - // Unlike the grow factor, the shrink factor is scaled relative to the - // child dimension. - flexAlgoRowMeasurement.totalFlexShrinkScaledFactors += - -child->resolveFlexShrink() * - child->getLayout().computedFlexBasis.unwrap(); - } - - flexAlgoRowMeasurement.relativeChildren.push_back(child); - } - - // The total flex factor needs to be floored to 1. - if (flexAlgoRowMeasurement.totalFlexGrowFactors > 0 && - flexAlgoRowMeasurement.totalFlexGrowFactors < 1) { - flexAlgoRowMeasurement.totalFlexGrowFactors = 1; - } - - // The total flex shrink factor needs to be floored to 1. - if (flexAlgoRowMeasurement.totalFlexShrinkScaledFactors > 0 && - flexAlgoRowMeasurement.totalFlexShrinkScaledFactors < 1) { - flexAlgoRowMeasurement.totalFlexShrinkScaledFactors = 1; - } - flexAlgoRowMeasurement.endOfLineIndex = endOfLineIndex; - return flexAlgoRowMeasurement; -} - -// It distributes the free space to the flexible items and ensures that the size -// of the flex items abide the min and max constraints. At the end of this -// function the child nodes would have proper size. Prior using this function -// please ensure that YGDistributeFreeSpaceFirstPass is called. -static float YGDistributeFreeSpaceSecondPass( - YGCollectFlexItemsRowValues& collectedFlexItemsValues, - const YGNodeRef node, - const YGFlexDirection mainAxis, - const YGFlexDirection crossAxis, - const float mainAxisownerSize, - const float availableInnerMainDim, - const float availableInnerCrossDim, - const float availableInnerWidth, - const float availableInnerHeight, - const bool mainAxisOverflows, - const YGMeasureMode measureModeCrossDim, - const bool performLayout, - const YGConfigRef config, - LayoutData& layoutMarkerData, - void* const layoutContext, - const uint32_t depth, - const uint32_t generationCount) { - float childFlexBasis = 0; - float flexShrinkScaledFactor = 0; - float flexGrowFactor = 0; - float deltaFreeSpace = 0; - const bool isMainAxisRow = YGFlexDirectionIsRow(mainAxis); - const bool isNodeFlexWrap = node->getStyle().flexWrap() != YGWrapNoWrap; - - for (auto currentRelativeChild : collectedFlexItemsValues.relativeChildren) { - childFlexBasis = YGNodeBoundAxisWithinMinAndMax( - currentRelativeChild, - mainAxis, - currentRelativeChild->getLayout().computedFlexBasis, - mainAxisownerSize) - .unwrap(); - float updatedMainSize = childFlexBasis; - - if (!YGFloatIsUndefined(collectedFlexItemsValues.remainingFreeSpace) && - collectedFlexItemsValues.remainingFreeSpace < 0) { - flexShrinkScaledFactor = - -currentRelativeChild->resolveFlexShrink() * childFlexBasis; - // Is this child able to shrink? - if (flexShrinkScaledFactor != 0) { - float childSize; - - if (!YGFloatIsUndefined( - collectedFlexItemsValues.totalFlexShrinkScaledFactors) && - collectedFlexItemsValues.totalFlexShrinkScaledFactors == 0) { - childSize = childFlexBasis + flexShrinkScaledFactor; - } else { - childSize = childFlexBasis + - (collectedFlexItemsValues.remainingFreeSpace / - collectedFlexItemsValues.totalFlexShrinkScaledFactors) * - flexShrinkScaledFactor; - } - - updatedMainSize = YGNodeBoundAxis( - currentRelativeChild, - mainAxis, - childSize, - availableInnerMainDim, - availableInnerWidth); - } - } else if ( - !YGFloatIsUndefined(collectedFlexItemsValues.remainingFreeSpace) && - collectedFlexItemsValues.remainingFreeSpace > 0) { - flexGrowFactor = currentRelativeChild->resolveFlexGrow(); - - // Is this child able to grow? - if (!YGFloatIsUndefined(flexGrowFactor) && flexGrowFactor != 0) { - updatedMainSize = YGNodeBoundAxis( - currentRelativeChild, - mainAxis, - childFlexBasis + - collectedFlexItemsValues.remainingFreeSpace / - collectedFlexItemsValues.totalFlexGrowFactors * - flexGrowFactor, - availableInnerMainDim, - availableInnerWidth); - } - } - - deltaFreeSpace += updatedMainSize - childFlexBasis; - - const float marginMain = - currentRelativeChild->getMarginForAxis(mainAxis, availableInnerWidth) - .unwrap(); - const float marginCross = - currentRelativeChild->getMarginForAxis(crossAxis, availableInnerWidth) - .unwrap(); - - float childCrossSize; - float childMainSize = updatedMainSize + marginMain; - YGMeasureMode childCrossMeasureMode; - YGMeasureMode childMainMeasureMode = YGMeasureModeExactly; - - const auto& childStyle = currentRelativeChild->getStyle(); - if (!childStyle.aspectRatio().isUndefined()) { - childCrossSize = isMainAxisRow - ? (childMainSize - marginMain) / childStyle.aspectRatio().unwrap() - : (childMainSize - marginMain) * childStyle.aspectRatio().unwrap(); - childCrossMeasureMode = YGMeasureModeExactly; - - childCrossSize += marginCross; - } else if ( - !YGFloatIsUndefined(availableInnerCrossDim) && - !YGNodeIsStyleDimDefined( - currentRelativeChild, crossAxis, availableInnerCrossDim) && - measureModeCrossDim == YGMeasureModeExactly && - !(isNodeFlexWrap && mainAxisOverflows) && - YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch && - currentRelativeChild->marginLeadingValue(crossAxis).unit != - YGUnitAuto && - currentRelativeChild->marginTrailingValue(crossAxis).unit != - YGUnitAuto) { - childCrossSize = availableInnerCrossDim; - childCrossMeasureMode = YGMeasureModeExactly; - } else if (!YGNodeIsStyleDimDefined( - currentRelativeChild, crossAxis, availableInnerCrossDim)) { - childCrossSize = availableInnerCrossDim; - childCrossMeasureMode = YGFloatIsUndefined(childCrossSize) - ? YGMeasureModeUndefined - : YGMeasureModeAtMost; - } else { - childCrossSize = - YGResolveValue( - currentRelativeChild->getResolvedDimension(dim[crossAxis]), - availableInnerCrossDim) - .unwrap() + - marginCross; - const bool isLoosePercentageMeasurement = - currentRelativeChild->getResolvedDimension(dim[crossAxis]).unit == - YGUnitPercent && - measureModeCrossDim != YGMeasureModeExactly; - childCrossMeasureMode = - YGFloatIsUndefined(childCrossSize) || isLoosePercentageMeasurement - ? YGMeasureModeUndefined - : YGMeasureModeExactly; - } - - YGConstrainMaxSizeForMode( - currentRelativeChild, - mainAxis, - availableInnerMainDim, - availableInnerWidth, - &childMainMeasureMode, - &childMainSize); - YGConstrainMaxSizeForMode( - currentRelativeChild, - crossAxis, - availableInnerCrossDim, - availableInnerWidth, - &childCrossMeasureMode, - &childCrossSize); - - const bool requiresStretchLayout = - !YGNodeIsStyleDimDefined( - currentRelativeChild, crossAxis, availableInnerCrossDim) && - YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch && - currentRelativeChild->marginLeadingValue(crossAxis).unit != - YGUnitAuto && - currentRelativeChild->marginTrailingValue(crossAxis).unit != YGUnitAuto; - - const float childWidth = isMainAxisRow ? childMainSize : childCrossSize; - const float childHeight = !isMainAxisRow ? childMainSize : childCrossSize; - - const YGMeasureMode childWidthMeasureMode = - isMainAxisRow ? childMainMeasureMode : childCrossMeasureMode; - const YGMeasureMode childHeightMeasureMode = - !isMainAxisRow ? childMainMeasureMode : childCrossMeasureMode; - - const bool isLayoutPass = performLayout && !requiresStretchLayout; - // Recursively call the layout algorithm for this child with the updated - // main size. - YGLayoutNodeInternal( - currentRelativeChild, - childWidth, - childHeight, - node->getLayout().direction(), - childWidthMeasureMode, - childHeightMeasureMode, - availableInnerWidth, - availableInnerHeight, - isLayoutPass, - isLayoutPass ? LayoutPassReason::kFlexLayout - : LayoutPassReason::kFlexMeasure, - config, - layoutMarkerData, - layoutContext, - depth, - generationCount); - node->setLayoutHadOverflow( - node->getLayout().hadOverflow() || - currentRelativeChild->getLayout().hadOverflow()); - } - return deltaFreeSpace; -} - -// It distributes the free space to the flexible items.For those flexible items -// whose min and max constraints are triggered, those flex item's clamped size -// is removed from the remaingfreespace. -static void YGDistributeFreeSpaceFirstPass( - YGCollectFlexItemsRowValues& collectedFlexItemsValues, - const YGFlexDirection mainAxis, - const float mainAxisownerSize, - const float availableInnerMainDim, - const float availableInnerWidth) { - float flexShrinkScaledFactor = 0; - float flexGrowFactor = 0; - float baseMainSize = 0; - float boundMainSize = 0; - float deltaFreeSpace = 0; - - for (auto currentRelativeChild : collectedFlexItemsValues.relativeChildren) { - float childFlexBasis = - YGNodeBoundAxisWithinMinAndMax( - currentRelativeChild, - mainAxis, - currentRelativeChild->getLayout().computedFlexBasis, - mainAxisownerSize) - .unwrap(); - - if (collectedFlexItemsValues.remainingFreeSpace < 0) { - flexShrinkScaledFactor = - -currentRelativeChild->resolveFlexShrink() * childFlexBasis; - - // Is this child able to shrink? - if (!YGFloatIsUndefined(flexShrinkScaledFactor) && - flexShrinkScaledFactor != 0) { - baseMainSize = childFlexBasis + - collectedFlexItemsValues.remainingFreeSpace / - collectedFlexItemsValues.totalFlexShrinkScaledFactors * - flexShrinkScaledFactor; - boundMainSize = YGNodeBoundAxis( - currentRelativeChild, - mainAxis, - baseMainSize, - availableInnerMainDim, - availableInnerWidth); - if (!YGFloatIsUndefined(baseMainSize) && - !YGFloatIsUndefined(boundMainSize) && - 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; - collectedFlexItemsValues.totalFlexShrinkScaledFactors -= - (-currentRelativeChild->resolveFlexShrink() * - currentRelativeChild->getLayout().computedFlexBasis.unwrap()); - } - } - } else if ( - !YGFloatIsUndefined(collectedFlexItemsValues.remainingFreeSpace) && - collectedFlexItemsValues.remainingFreeSpace > 0) { - flexGrowFactor = currentRelativeChild->resolveFlexGrow(); - - // Is this child able to grow? - if (!YGFloatIsUndefined(flexGrowFactor) && flexGrowFactor != 0) { - baseMainSize = childFlexBasis + - collectedFlexItemsValues.remainingFreeSpace / - collectedFlexItemsValues.totalFlexGrowFactors * flexGrowFactor; - boundMainSize = YGNodeBoundAxis( - currentRelativeChild, - mainAxis, - baseMainSize, - availableInnerMainDim, - availableInnerWidth); - - if (!YGFloatIsUndefined(baseMainSize) && - !YGFloatIsUndefined(boundMainSize) && - 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; - collectedFlexItemsValues.totalFlexGrowFactors -= flexGrowFactor; - } - } - } - } - collectedFlexItemsValues.remainingFreeSpace -= deltaFreeSpace; -} - -// 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 -// the first pass. 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. -// -// At the end of this function the child nodes would have the proper size -// assigned to them. -// -static void YGResolveFlexibleLength( - const YGNodeRef node, - YGCollectFlexItemsRowValues& collectedFlexItemsValues, - const YGFlexDirection mainAxis, - const YGFlexDirection crossAxis, - const float mainAxisownerSize, - const float availableInnerMainDim, - const float availableInnerCrossDim, - const float availableInnerWidth, - const float availableInnerHeight, - const bool mainAxisOverflows, - const YGMeasureMode measureModeCrossDim, - const bool performLayout, - const YGConfigRef config, - LayoutData& layoutMarkerData, - void* const layoutContext, - const uint32_t depth, - const uint32_t generationCount) { - const float originalFreeSpace = collectedFlexItemsValues.remainingFreeSpace; - // First pass: detect the flex items whose min/max constraints trigger - YGDistributeFreeSpaceFirstPass( - collectedFlexItemsValues, - mainAxis, - mainAxisownerSize, - availableInnerMainDim, - availableInnerWidth); - - // Second pass: resolve the sizes of the flexible items - const float distributedFreeSpace = YGDistributeFreeSpaceSecondPass( - collectedFlexItemsValues, - node, - mainAxis, - crossAxis, - mainAxisownerSize, - availableInnerMainDim, - availableInnerCrossDim, - availableInnerWidth, - availableInnerHeight, - mainAxisOverflows, - measureModeCrossDim, - performLayout, - config, - layoutMarkerData, - layoutContext, - depth, - generationCount); - - collectedFlexItemsValues.remainingFreeSpace = - originalFreeSpace - distributedFreeSpace; -} - -static void YGJustifyMainAxis( - const YGNodeRef node, - YGCollectFlexItemsRowValues& collectedFlexItemsValues, - const uint32_t startOfLineIndex, - const YGFlexDirection mainAxis, - const YGFlexDirection crossAxis, - const YGMeasureMode measureModeMainDim, - const YGMeasureMode measureModeCrossDim, - const float mainAxisownerSize, - const float ownerWidth, - const float availableInnerMainDim, - const float availableInnerCrossDim, - const float availableInnerWidth, - const bool performLayout, - void* const layoutContext) { - const auto& style = node->getStyle(); - const float leadingPaddingAndBorderMain = - node->getLeadingPaddingAndBorder(mainAxis, ownerWidth).unwrap(); - const float trailingPaddingAndBorderMain = - node->getTrailingPaddingAndBorder(mainAxis, ownerWidth).unwrap(); - const float gap = node->getGapForAxis(mainAxis, ownerWidth).unwrap(); - // If we are using "at most" rules in the main axis, make sure that - // remainingFreeSpace is 0 when min main dimension is not given - if (measureModeMainDim == YGMeasureModeAtMost && - collectedFlexItemsValues.remainingFreeSpace > 0) { - if (!style.minDimensions()[dim[mainAxis]].isUndefined() && - !YGResolveValue(style.minDimensions()[dim[mainAxis]], mainAxisownerSize) - .isUndefined()) { - // This condition makes sure that if the size of main dimension(after - // considering child nodes main dim, leading and trailing padding etc) - // falls below min dimension, then the remainingFreeSpace is reassigned - // considering the min dimension - - // `minAvailableMainDim` denotes minimum available space in which child - // can be laid out, it will exclude space consumed by padding and border. - const float minAvailableMainDim = - YGResolveValue( - style.minDimensions()[dim[mainAxis]], mainAxisownerSize) - .unwrap() - - leadingPaddingAndBorderMain - trailingPaddingAndBorderMain; - const float occupiedSpaceByChildNodes = - availableInnerMainDim - collectedFlexItemsValues.remainingFreeSpace; - collectedFlexItemsValues.remainingFreeSpace = - YGFloatMax(0, minAvailableMainDim - occupiedSpaceByChildNodes); - } else { - collectedFlexItemsValues.remainingFreeSpace = 0; - } - } - - int numberOfAutoMarginsOnCurrentLine = 0; - for (uint32_t i = startOfLineIndex; - i < collectedFlexItemsValues.endOfLineIndex; - i++) { - const YGNodeRef child = node->getChild(i); - if (child->getStyle().positionType() != YGPositionTypeAbsolute) { - if (child->marginLeadingValue(mainAxis).unit == YGUnitAuto) { - numberOfAutoMarginsOnCurrentLine++; - } - if (child->marginTrailingValue(mainAxis).unit == YGUnitAuto) { - numberOfAutoMarginsOnCurrentLine++; - } - } - } - - // 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 = gap; - const YGJustify justifyContent = node->getStyle().justifyContent(); - - if (numberOfAutoMarginsOnCurrentLine == 0) { - switch (justifyContent) { - case YGJustifyCenter: - leadingMainDim = collectedFlexItemsValues.remainingFreeSpace / 2; - break; - case YGJustifyFlexEnd: - leadingMainDim = collectedFlexItemsValues.remainingFreeSpace; - break; - case YGJustifySpaceBetween: - if (collectedFlexItemsValues.itemsOnLine > 1) { - betweenMainDim += - YGFloatMax(collectedFlexItemsValues.remainingFreeSpace, 0) / - (collectedFlexItemsValues.itemsOnLine - 1); - } - break; - case YGJustifySpaceEvenly: - // Space is distributed evenly across all elements - leadingMainDim = collectedFlexItemsValues.remainingFreeSpace / - (collectedFlexItemsValues.itemsOnLine + 1); - betweenMainDim += leadingMainDim; - break; - case YGJustifySpaceAround: - // Space on the edges is half of the space between elements - leadingMainDim = 0.5f * collectedFlexItemsValues.remainingFreeSpace / - collectedFlexItemsValues.itemsOnLine; - betweenMainDim += leadingMainDim * 2; - break; - case YGJustifyFlexStart: - break; - } - } - - collectedFlexItemsValues.mainDim = - leadingPaddingAndBorderMain + leadingMainDim; - collectedFlexItemsValues.crossDim = 0; - - float maxAscentForCurrentLine = 0; - float maxDescentForCurrentLine = 0; - bool isNodeBaselineLayout = YGIsBaselineLayout(node); - for (uint32_t i = startOfLineIndex; - i < collectedFlexItemsValues.endOfLineIndex; - i++) { - const YGNodeRef child = node->getChild(i); - const YGStyle& childStyle = child->getStyle(); - const YGLayout childLayout = child->getLayout(); - const bool isLastChild = i == collectedFlexItemsValues.endOfLineIndex - 1; - // remove the gap if it is the last element of the line - if (isLastChild) { - betweenMainDim -= gap; - } - if (childStyle.display() == YGDisplayNone) { - continue; - } - if (childStyle.positionType() == YGPositionTypeAbsolute && - child->isLeadingPositionDefined(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->setLayoutPosition( - child->getLeadingPosition(mainAxis, availableInnerMainDim) - .unwrap() + - node->getLeadingBorder(mainAxis) + - child->getLeadingMargin(mainAxis, availableInnerWidth).unwrap(), - pos[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 (childStyle.positionType() != YGPositionTypeAbsolute) { - if (child->marginLeadingValue(mainAxis).unit == YGUnitAuto) { - collectedFlexItemsValues.mainDim += - collectedFlexItemsValues.remainingFreeSpace / - numberOfAutoMarginsOnCurrentLine; - } - - if (performLayout) { - child->setLayoutPosition( - childLayout.position[pos[mainAxis]] + - collectedFlexItemsValues.mainDim, - pos[mainAxis]); - } - - if (child->marginTrailingValue(mainAxis).unit == YGUnitAuto) { - collectedFlexItemsValues.mainDim += - collectedFlexItemsValues.remainingFreeSpace / - numberOfAutoMarginsOnCurrentLine; - } - bool canSkipFlex = - !performLayout && measureModeCrossDim == YGMeasureModeExactly; - 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. - collectedFlexItemsValues.mainDim += betweenMainDim + - child->getMarginForAxis(mainAxis, availableInnerWidth).unwrap() + - childLayout.computedFlexBasis.unwrap(); - collectedFlexItemsValues.crossDim = availableInnerCrossDim; - } else { - // The main dimension is the sum of all the elements dimension plus - // the spacing. - collectedFlexItemsValues.mainDim += betweenMainDim + - YGNodeDimWithMargin(child, mainAxis, availableInnerWidth); - - if (isNodeBaselineLayout) { - // If the child is baseline aligned then the cross dimension is - // calculated by adding maxAscent and maxDescent from the baseline. - const float ascent = YGBaseline(child, layoutContext) + - child - ->getLeadingMargin( - YGFlexDirectionColumn, availableInnerWidth) - .unwrap(); - const float descent = - child->getLayout().measuredDimensions[YGDimensionHeight] + - child - ->getMarginForAxis( - YGFlexDirectionColumn, availableInnerWidth) - .unwrap() - - ascent; - - maxAscentForCurrentLine = - YGFloatMax(maxAscentForCurrentLine, ascent); - maxDescentForCurrentLine = - YGFloatMax(maxDescentForCurrentLine, descent); - } else { - // The cross dimension is the max of the elements dimension since - // there can only be one element in that cross dimension in the case - // when the items are not baseline aligned - collectedFlexItemsValues.crossDim = YGFloatMax( - collectedFlexItemsValues.crossDim, - YGNodeDimWithMargin(child, crossAxis, availableInnerWidth)); - } - } - } else if (performLayout) { - child->setLayoutPosition( - childLayout.position[pos[mainAxis]] + - node->getLeadingBorder(mainAxis) + leadingMainDim, - pos[mainAxis]); - } - } - } - collectedFlexItemsValues.mainDim += trailingPaddingAndBorderMain; - - if (isNodeBaselineLayout) { - collectedFlexItemsValues.crossDim = - maxAscentForCurrentLine + maxDescentForCurrentLine; - } -} - -// -// 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. -// * 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 laid 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 -// - ownerDirection: the inline (text) direction within the owner -// (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 laid 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): -// - 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 ownerDirection, - const YGMeasureMode widthMeasureMode, - const YGMeasureMode heightMeasureMode, - const float ownerWidth, - const float ownerHeight, - const bool performLayout, - const YGConfigRef config, - LayoutData& layoutMarkerData, - void* const layoutContext, - const uint32_t depth, - const uint32_t generationCount, - const LayoutPassReason reason) { - YGAssertWithNode( - node, - YGFloatIsUndefined(availableWidth) - ? widthMeasureMode == YGMeasureModeUndefined - : true, - "availableWidth is indefinite so widthMeasureMode must be " - "YGMeasureModeUndefined"); - YGAssertWithNode( - node, - YGFloatIsUndefined(availableHeight) - ? heightMeasureMode == YGMeasureModeUndefined - : true, - "availableHeight is indefinite so heightMeasureMode must be " - "YGMeasureModeUndefined"); - - (performLayout ? layoutMarkerData.layouts : layoutMarkerData.measures) += 1; - - // Set the resolved resolution in the node's layout. - const YGDirection direction = node->resolveDirection(ownerDirection); - node->setLayoutDirection(direction); - - const YGFlexDirection flexRowDirection = - YGResolveFlexDirection(YGFlexDirectionRow, direction); - const YGFlexDirection flexColumnDirection = - YGResolveFlexDirection(YGFlexDirectionColumn, direction); - - const YGEdge startEdge = - direction == YGDirectionLTR ? YGEdgeLeft : YGEdgeRight; - const YGEdge endEdge = direction == YGDirectionLTR ? YGEdgeRight : YGEdgeLeft; - - const float marginRowLeading = - node->getLeadingMargin(flexRowDirection, ownerWidth).unwrap(); - node->setLayoutMargin(marginRowLeading, startEdge); - const float marginRowTrailing = - node->getTrailingMargin(flexRowDirection, ownerWidth).unwrap(); - node->setLayoutMargin(marginRowTrailing, endEdge); - const float marginColumnLeading = - node->getLeadingMargin(flexColumnDirection, ownerWidth).unwrap(); - node->setLayoutMargin(marginColumnLeading, YGEdgeTop); - const float marginColumnTrailing = - node->getTrailingMargin(flexColumnDirection, ownerWidth).unwrap(); - node->setLayoutMargin(marginColumnTrailing, YGEdgeBottom); - - const float marginAxisRow = marginRowLeading + marginRowTrailing; - const float marginAxisColumn = marginColumnLeading + marginColumnTrailing; - - node->setLayoutBorder(node->getLeadingBorder(flexRowDirection), startEdge); - node->setLayoutBorder(node->getTrailingBorder(flexRowDirection), endEdge); - node->setLayoutBorder(node->getLeadingBorder(flexColumnDirection), YGEdgeTop); - node->setLayoutBorder( - node->getTrailingBorder(flexColumnDirection), YGEdgeBottom); - - node->setLayoutPadding( - node->getLeadingPadding(flexRowDirection, ownerWidth).unwrap(), - startEdge); - node->setLayoutPadding( - node->getTrailingPadding(flexRowDirection, ownerWidth).unwrap(), endEdge); - node->setLayoutPadding( - node->getLeadingPadding(flexColumnDirection, ownerWidth).unwrap(), - YGEdgeTop); - node->setLayoutPadding( - node->getTrailingPadding(flexColumnDirection, ownerWidth).unwrap(), - YGEdgeBottom); - - if (node->hasMeasureFunc()) { - YGNodeWithMeasureFuncSetMeasuredDimensions( - node, - availableWidth - marginAxisRow, - availableHeight - marginAxisColumn, - widthMeasureMode, - heightMeasureMode, - ownerWidth, - ownerHeight, - layoutMarkerData, - layoutContext, - reason); - return; - } - - const uint32_t childCount = YGNodeGetChildCount(node); - if (childCount == 0) { - YGNodeEmptyContainerSetMeasuredDimensions( - node, - availableWidth - marginAxisRow, - availableHeight - marginAxisColumn, - widthMeasureMode, - heightMeasureMode, - ownerWidth, - ownerHeight); - 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 - marginAxisRow, - availableHeight - marginAxisColumn, - widthMeasureMode, - heightMeasureMode, - ownerWidth, - ownerHeight)) { - return; - } - - // At this point we know we're going to perform work. Ensure that each child - // has a mutable copy. - node->cloneChildrenIfNeeded(layoutContext); - // Reset layout flags, as they could have changed. - node->setLayoutHadOverflow(false); - - // STEP 1: CALCULATE VALUES FOR REMAINDER OF ALGORITHM - const YGFlexDirection mainAxis = - YGResolveFlexDirection(node->getStyle().flexDirection(), direction); - const YGFlexDirection crossAxis = YGFlexDirectionCross(mainAxis, direction); - const bool isMainAxisRow = YGFlexDirectionIsRow(mainAxis); - const bool isNodeFlexWrap = node->getStyle().flexWrap() != YGWrapNoWrap; - - const float mainAxisownerSize = isMainAxisRow ? ownerWidth : ownerHeight; - const float crossAxisownerSize = isMainAxisRow ? ownerHeight : ownerWidth; - - const float paddingAndBorderAxisMain = - YGNodePaddingAndBorderForAxis(node, mainAxis, ownerWidth); - const float leadingPaddingAndBorderCross = - node->getLeadingPaddingAndBorder(crossAxis, ownerWidth).unwrap(); - const float trailingPaddingAndBorderCross = - node->getTrailingPaddingAndBorder(crossAxis, ownerWidth).unwrap(); - const float paddingAndBorderAxisCross = - leadingPaddingAndBorderCross + trailingPaddingAndBorderCross; - - YGMeasureMode measureModeMainDim = - isMainAxisRow ? widthMeasureMode : heightMeasureMode; - YGMeasureMode measureModeCrossDim = - isMainAxisRow ? heightMeasureMode : widthMeasureMode; - - const float paddingAndBorderAxisRow = - isMainAxisRow ? paddingAndBorderAxisMain : paddingAndBorderAxisCross; - const float paddingAndBorderAxisColumn = - isMainAxisRow ? paddingAndBorderAxisCross : paddingAndBorderAxisMain; - - // STEP 2: DETERMINE AVAILABLE SIZE IN MAIN AND CROSS DIRECTIONS - - float availableInnerWidth = YGNodeCalculateAvailableInnerDim( - node, - YGDimensionWidth, - availableWidth - marginAxisRow, - paddingAndBorderAxisRow, - ownerWidth); - float availableInnerHeight = YGNodeCalculateAvailableInnerDim( - node, - YGDimensionHeight, - availableHeight - marginAxisColumn, - paddingAndBorderAxisColumn, - ownerHeight); - - float availableInnerMainDim = - isMainAxisRow ? availableInnerWidth : availableInnerHeight; - const float availableInnerCrossDim = - isMainAxisRow ? availableInnerHeight : availableInnerWidth; - - // STEP 3: DETERMINE FLEX BASIS FOR EACH ITEM - - // Computed basis + margins + gap - float totalMainDim = 0; - totalMainDim += YGNodeComputeFlexBasisForChildren( - node, - availableInnerWidth, - availableInnerHeight, - widthMeasureMode, - heightMeasureMode, - direction, - mainAxis, - config, - performLayout, - layoutMarkerData, - layoutContext, - depth, - generationCount); - - if (childCount > 1) { - totalMainDim += - node->getGapForAxis(mainAxis, availableInnerCrossDim).unwrap() * - (childCount - 1); - } - - const bool mainAxisOverflows = - (measureModeMainDim != YGMeasureModeUndefined) && - totalMainDim > availableInnerMainDim; - - if (isNodeFlexWrap && mainAxisOverflows && - measureModeMainDim == YGMeasureModeAtMost) { - measureModeMainDim = YGMeasureModeExactly; - } - // 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; - - const float crossAxisGap = - node->getGapForAxis(crossAxis, availableInnerCrossDim).unwrap(); - - // Max main dimension of all the lines. - float maxLineMainDim = 0; - YGCollectFlexItemsRowValues collectedFlexItemsValues; - for (; endOfLineIndex < childCount; - lineCount++, startOfLineIndex = endOfLineIndex) { - collectedFlexItemsValues = YGCalculateCollectFlexItemsRowValues( - node, - ownerDirection, - mainAxisownerSize, - availableInnerWidth, - availableInnerMainDim, - startOfLineIndex, - lineCount); - endOfLineIndex = collectedFlexItemsValues.endOfLineIndex; - - // If we don't need to measure the cross axis, we can skip the entire flex - // step. - const bool canSkipFlex = - !performLayout && measureModeCrossDim == YGMeasureModeExactly; - - // 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. - - bool sizeBasedOnContent = false; - // If we don't measure with exact main dimension we want to ensure we don't - // violate min and max - if (measureModeMainDim != YGMeasureModeExactly) { - const auto& minDimensions = node->getStyle().minDimensions(); - const auto& maxDimensions = node->getStyle().maxDimensions(); - const float minInnerWidth = - YGResolveValue(minDimensions[YGDimensionWidth], ownerWidth).unwrap() - - paddingAndBorderAxisRow; - const float maxInnerWidth = - YGResolveValue(maxDimensions[YGDimensionWidth], ownerWidth).unwrap() - - paddingAndBorderAxisRow; - const float minInnerHeight = - YGResolveValue(minDimensions[YGDimensionHeight], ownerHeight) - .unwrap() - - paddingAndBorderAxisColumn; - const float maxInnerHeight = - YGResolveValue(maxDimensions[YGDimensionHeight], ownerHeight) - .unwrap() - - paddingAndBorderAxisColumn; - - const float minInnerMainDim = - isMainAxisRow ? minInnerWidth : minInnerHeight; - const float maxInnerMainDim = - isMainAxisRow ? maxInnerWidth : maxInnerHeight; - - if (!YGFloatIsUndefined(minInnerMainDim) && - collectedFlexItemsValues.sizeConsumedOnCurrentLine < - minInnerMainDim) { - availableInnerMainDim = minInnerMainDim; - } else if ( - !YGFloatIsUndefined(maxInnerMainDim) && - collectedFlexItemsValues.sizeConsumedOnCurrentLine > - maxInnerMainDim) { - availableInnerMainDim = maxInnerMainDim; - } else { - bool useLegacyStretchBehaviour = - node->hasErrata(YGErrataStretchFlexBasis); - - if (!useLegacyStretchBehaviour && - ((!YGFloatIsUndefined( - collectedFlexItemsValues.totalFlexGrowFactors) && - collectedFlexItemsValues.totalFlexGrowFactors == 0) || - (!YGFloatIsUndefined(node->resolveFlexGrow()) && - node->resolveFlexGrow() == 0))) { - // If we don't have any children to flex or we can't flex the node - // itself, space we've used is all space we need. Root node also - // should be shrunk to minimum - availableInnerMainDim = - collectedFlexItemsValues.sizeConsumedOnCurrentLine; - } - - sizeBasedOnContent = !useLegacyStretchBehaviour; - } - } - - if (!sizeBasedOnContent && !YGFloatIsUndefined(availableInnerMainDim)) { - collectedFlexItemsValues.remainingFreeSpace = availableInnerMainDim - - collectedFlexItemsValues.sizeConsumedOnCurrentLine; - } else if (collectedFlexItemsValues.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 points for its content. Consequently, - // remainingFreeSpace is 0 - sizeConsumedOnCurrentLine. - collectedFlexItemsValues.remainingFreeSpace = - -collectedFlexItemsValues.sizeConsumedOnCurrentLine; - } - - if (!canSkipFlex) { - YGResolveFlexibleLength( - node, - collectedFlexItemsValues, - mainAxis, - crossAxis, - mainAxisownerSize, - availableInnerMainDim, - availableInnerCrossDim, - availableInnerWidth, - availableInnerHeight, - mainAxisOverflows, - measureModeCrossDim, - performLayout, - config, - layoutMarkerData, - layoutContext, - depth, - generationCount); - } - - node->setLayoutHadOverflow( - node->getLayout().hadOverflow() | - (collectedFlexItemsValues.remainingFreeSpace < 0)); - - // 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. - - YGJustifyMainAxis( - node, - collectedFlexItemsValues, - startOfLineIndex, - mainAxis, - crossAxis, - measureModeMainDim, - measureModeCrossDim, - mainAxisownerSize, - ownerWidth, - availableInnerMainDim, - availableInnerCrossDim, - availableInnerWidth, - performLayout, - layoutContext); - - float containerCrossAxis = availableInnerCrossDim; - if (measureModeCrossDim == YGMeasureModeUndefined || - measureModeCrossDim == YGMeasureModeAtMost) { - // Compute the cross axis from the max cross dimension of the children. - containerCrossAxis = - YGNodeBoundAxis( - node, - crossAxis, - collectedFlexItemsValues.crossDim + paddingAndBorderAxisCross, - crossAxisownerSize, - ownerWidth) - - paddingAndBorderAxisCross; - } - - // If there's no flex wrap, the cross dimension is defined by the container. - if (!isNodeFlexWrap && measureModeCrossDim == YGMeasureModeExactly) { - collectedFlexItemsValues.crossDim = availableInnerCrossDim; - } - - // Clamp to the min/max size specified on the container. - collectedFlexItemsValues.crossDim = - YGNodeBoundAxis( - node, - crossAxis, - collectedFlexItemsValues.crossDim + paddingAndBorderAxisCross, - crossAxisownerSize, - ownerWidth) - - 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 = node->getChild(i); - if (child->getStyle().display() == YGDisplayNone) { - continue; - } - if (child->getStyle().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. - const bool isChildLeadingPosDefined = - child->isLeadingPositionDefined(crossAxis); - if (isChildLeadingPosDefined) { - child->setLayoutPosition( - child->getLeadingPosition(crossAxis, availableInnerCrossDim) - .unwrap() + - node->getLeadingBorder(crossAxis) + - child->getLeadingMargin(crossAxis, availableInnerWidth) - .unwrap(), - pos[crossAxis]); - } - // If leading position is not defined or calculations result in Nan, - // default to border + margin - if (!isChildLeadingPosDefined || - YGFloatIsUndefined(child->getLayout().position[pos[crossAxis]])) { - child->setLayoutPosition( - node->getLeadingBorder(crossAxis) + - child->getLeadingMargin(crossAxis, availableInnerWidth) - .unwrap(), - pos[crossAxis]); - } - } else { - float leadingCrossDim = leadingPaddingAndBorderCross; - - // For a relative children, we're either using alignItems (owner) 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 && - child->marginLeadingValue(crossAxis).unit != YGUnitAuto && - child->marginTrailingValue(crossAxis).unit != YGUnitAuto) { - // If the child defines a definite size for its cross axis, there's - // no need to stretch. - if (!YGNodeIsStyleDimDefined( - child, crossAxis, availableInnerCrossDim)) { - float childMainSize = - child->getLayout().measuredDimensions[dim[mainAxis]]; - const auto& childStyle = child->getStyle(); - float childCrossSize = !childStyle.aspectRatio().isUndefined() - ? child->getMarginForAxis(crossAxis, availableInnerWidth) - .unwrap() + - (isMainAxisRow - ? childMainSize / childStyle.aspectRatio().unwrap() - : childMainSize * childStyle.aspectRatio().unwrap()) - : collectedFlexItemsValues.crossDim; - - childMainSize += - child->getMarginForAxis(mainAxis, availableInnerWidth) - .unwrap(); - - YGMeasureMode childMainMeasureMode = YGMeasureModeExactly; - YGMeasureMode childCrossMeasureMode = YGMeasureModeExactly; - YGConstrainMaxSizeForMode( - child, - mainAxis, - availableInnerMainDim, - availableInnerWidth, - &childMainMeasureMode, - &childMainSize); - YGConstrainMaxSizeForMode( - child, - crossAxis, - availableInnerCrossDim, - availableInnerWidth, - &childCrossMeasureMode, - &childCrossSize); - - const float childWidth = - isMainAxisRow ? childMainSize : childCrossSize; - const float childHeight = - !isMainAxisRow ? childMainSize : childCrossSize; - - auto alignContent = node->getStyle().alignContent(); - auto crossAxisDoesNotGrow = - alignContent != YGAlignStretch && isNodeFlexWrap; - const YGMeasureMode childWidthMeasureMode = - YGFloatIsUndefined(childWidth) || - (!isMainAxisRow && crossAxisDoesNotGrow) - ? YGMeasureModeUndefined - : YGMeasureModeExactly; - const YGMeasureMode childHeightMeasureMode = - YGFloatIsUndefined(childHeight) || - (isMainAxisRow && crossAxisDoesNotGrow) - ? YGMeasureModeUndefined - : YGMeasureModeExactly; - - YGLayoutNodeInternal( - child, - childWidth, - childHeight, - direction, - childWidthMeasureMode, - childHeightMeasureMode, - availableInnerWidth, - availableInnerHeight, - true, - LayoutPassReason::kStretch, - config, - layoutMarkerData, - layoutContext, - depth, - generationCount); - } - } else { - const float remainingCrossDim = containerCrossAxis - - YGNodeDimWithMargin(child, crossAxis, availableInnerWidth); - - if (child->marginLeadingValue(crossAxis).unit == YGUnitAuto && - child->marginTrailingValue(crossAxis).unit == YGUnitAuto) { - leadingCrossDim += YGFloatMax(0.0f, remainingCrossDim / 2); - } else if ( - child->marginTrailingValue(crossAxis).unit == YGUnitAuto) { - // No-Op - } else if ( - child->marginLeadingValue(crossAxis).unit == YGUnitAuto) { - leadingCrossDim += YGFloatMax(0.0f, remainingCrossDim); - } else if (alignItem == YGAlignFlexStart) { - // No-Op - } else if (alignItem == YGAlignCenter) { - leadingCrossDim += remainingCrossDim / 2; - } else { - leadingCrossDim += remainingCrossDim; - } - } - // And we apply the position - child->setLayoutPosition( - child->getLayout().position[pos[crossAxis]] + totalLineCrossDim + - leadingCrossDim, - pos[crossAxis]); - } - } - } - - const float appliedCrossGap = lineCount != 0 ? crossAxisGap : 0.0f; - totalLineCrossDim += collectedFlexItemsValues.crossDim + appliedCrossGap; - maxLineMainDim = - YGFloatMax(maxLineMainDim, collectedFlexItemsValues.mainDim); - } - - // STEP 8: MULTI-LINE CONTENT ALIGNMENT - // currentLead stores the size of the cross dim - if (performLayout && (isNodeFlexWrap || YGIsBaselineLayout(node))) { - float crossDimLead = 0; - float currentLead = leadingPaddingAndBorderCross; - if (!YGFloatIsUndefined(availableInnerCrossDim)) { - const float remainingAlignContentDim = - availableInnerCrossDim - totalLineCrossDim; - switch (node->getStyle().alignContent()) { - case YGAlignFlexEnd: - currentLead += remainingAlignContentDim; - break; - case YGAlignCenter: - currentLead += remainingAlignContentDim / 2; - break; - case YGAlignStretch: - if (availableInnerCrossDim > totalLineCrossDim) { - crossDimLead = remainingAlignContentDim / lineCount; - } - break; - case YGAlignSpaceAround: - if (availableInnerCrossDim > totalLineCrossDim) { - currentLead += remainingAlignContentDim / (2 * lineCount); - if (lineCount > 1) { - crossDimLead = remainingAlignContentDim / lineCount; - } - } else { - currentLead += remainingAlignContentDim / 2; - } - break; - case YGAlignSpaceBetween: - if (availableInnerCrossDim > totalLineCrossDim && lineCount > 1) { - crossDimLead = remainingAlignContentDim / (lineCount - 1); - } - break; - case YGAlignAuto: - case YGAlignFlexStart: - case YGAlignBaseline: - break; - } - } - uint32_t endIndex = 0; - for (uint32_t i = 0; i < lineCount; i++) { - const uint32_t startIndex = endIndex; - uint32_t ii; - - // compute the line's height and find the endIndex - float lineHeight = 0; - float maxAscentForCurrentLine = 0; - float maxDescentForCurrentLine = 0; - for (ii = startIndex; ii < childCount; ii++) { - const YGNodeRef child = node->getChild(ii); - if (child->getStyle().display() == YGDisplayNone) { - continue; - } - if (child->getStyle().positionType() != YGPositionTypeAbsolute) { - if (child->getLineIndex() != i) { - break; - } - if (YGNodeIsLayoutDimDefined(child, crossAxis)) { - lineHeight = YGFloatMax( - lineHeight, - child->getLayout().measuredDimensions[dim[crossAxis]] + - child->getMarginForAxis(crossAxis, availableInnerWidth) - .unwrap()); - } - if (YGNodeAlignItem(node, child) == YGAlignBaseline) { - const float ascent = YGBaseline(child, layoutContext) + - child - ->getLeadingMargin( - YGFlexDirectionColumn, availableInnerWidth) - .unwrap(); - const float descent = - child->getLayout().measuredDimensions[YGDimensionHeight] + - child - ->getMarginForAxis( - YGFlexDirectionColumn, availableInnerWidth) - .unwrap() - - ascent; - maxAscentForCurrentLine = - YGFloatMax(maxAscentForCurrentLine, ascent); - maxDescentForCurrentLine = - YGFloatMax(maxDescentForCurrentLine, descent); - lineHeight = YGFloatMax( - lineHeight, maxAscentForCurrentLine + maxDescentForCurrentLine); - } - } - } - endIndex = ii; - lineHeight += crossDimLead; - currentLead += i != 0 ? crossAxisGap : 0; - - if (performLayout) { - for (ii = startIndex; ii < endIndex; ii++) { - const YGNodeRef child = node->getChild(ii); - if (child->getStyle().display() == YGDisplayNone) { - continue; - } - if (child->getStyle().positionType() != YGPositionTypeAbsolute) { - switch (YGNodeAlignItem(node, child)) { - case YGAlignFlexStart: { - child->setLayoutPosition( - currentLead + - child->getLeadingMargin(crossAxis, availableInnerWidth) - .unwrap(), - pos[crossAxis]); - break; - } - case YGAlignFlexEnd: { - child->setLayoutPosition( - currentLead + lineHeight - - child->getTrailingMargin(crossAxis, availableInnerWidth) - .unwrap() - - child->getLayout().measuredDimensions[dim[crossAxis]], - pos[crossAxis]); - break; - } - case YGAlignCenter: { - float childHeight = - child->getLayout().measuredDimensions[dim[crossAxis]]; - - child->setLayoutPosition( - currentLead + (lineHeight - childHeight) / 2, - pos[crossAxis]); - break; - } - case YGAlignStretch: { - child->setLayoutPosition( - currentLead + - child->getLeadingMargin(crossAxis, availableInnerWidth) - .unwrap(), - pos[crossAxis]); - - // Remeasure child with the line height as it as been only - // measured with the owners height yet. - if (!YGNodeIsStyleDimDefined( - child, crossAxis, availableInnerCrossDim)) { - const float childWidth = isMainAxisRow - ? (child->getLayout() - .measuredDimensions[YGDimensionWidth] + - child->getMarginForAxis(mainAxis, availableInnerWidth) - .unwrap()) - : lineHeight; - - const float childHeight = !isMainAxisRow - ? (child->getLayout() - .measuredDimensions[YGDimensionHeight] + - child->getMarginForAxis(crossAxis, availableInnerWidth) - .unwrap()) - : lineHeight; - - if (!(YGFloatsEqual( - childWidth, - child->getLayout() - .measuredDimensions[YGDimensionWidth]) && - YGFloatsEqual( - childHeight, - child->getLayout() - .measuredDimensions[YGDimensionHeight]))) { - YGLayoutNodeInternal( - child, - childWidth, - childHeight, - direction, - YGMeasureModeExactly, - YGMeasureModeExactly, - availableInnerWidth, - availableInnerHeight, - true, - LayoutPassReason::kMultilineStretch, - config, - layoutMarkerData, - layoutContext, - depth, - generationCount); - } - } - break; - } - case YGAlignBaseline: { - child->setLayoutPosition( - currentLead + maxAscentForCurrentLine - - YGBaseline(child, layoutContext) + - child - ->getLeadingPosition( - YGFlexDirectionColumn, availableInnerCrossDim) - .unwrap(), - YGEdgeTop); - - break; - } - case YGAlignAuto: - case YGAlignSpaceBetween: - case YGAlignSpaceAround: - break; - } - } - } - } - currentLead += lineHeight; - } - } - - // STEP 9: COMPUTING FINAL DIMENSIONS - - node->setLayoutMeasuredDimension( - YGNodeBoundAxis( - node, - YGFlexDirectionRow, - availableWidth - marginAxisRow, - ownerWidth, - ownerWidth), - YGDimensionWidth); - - node->setLayoutMeasuredDimension( - YGNodeBoundAxis( - node, - YGFlexDirectionColumn, - availableHeight - marginAxisColumn, - ownerHeight, - ownerWidth), - YGDimensionHeight); - - // If the user didn't specify a width or height for the node, set the - // dimensions based on the children. - if (measureModeMainDim == YGMeasureModeUndefined || - (node->getStyle().overflow() != YGOverflowScroll && - measureModeMainDim == YGMeasureModeAtMost)) { - // Clamp the size to the min/max size, if specified, and make sure it - // doesn't go below the padding and border amount. - node->setLayoutMeasuredDimension( - YGNodeBoundAxis( - node, mainAxis, maxLineMainDim, mainAxisownerSize, ownerWidth), - dim[mainAxis]); - - } else if ( - measureModeMainDim == YGMeasureModeAtMost && - node->getStyle().overflow() == YGOverflowScroll) { - node->setLayoutMeasuredDimension( - YGFloatMax( - YGFloatMin( - availableInnerMainDim + paddingAndBorderAxisMain, - YGNodeBoundAxisWithinMinAndMax( - node, - mainAxis, - YGFloatOptional{maxLineMainDim}, - mainAxisownerSize) - .unwrap()), - paddingAndBorderAxisMain), - dim[mainAxis]); - } - - if (measureModeCrossDim == YGMeasureModeUndefined || - (node->getStyle().overflow() != YGOverflowScroll && - measureModeCrossDim == YGMeasureModeAtMost)) { - // Clamp the size to the min/max size, if specified, and make sure it - // doesn't go below the padding and border amount. - node->setLayoutMeasuredDimension( - YGNodeBoundAxis( - node, - crossAxis, - totalLineCrossDim + paddingAndBorderAxisCross, - crossAxisownerSize, - ownerWidth), - dim[crossAxis]); - - } else if ( - measureModeCrossDim == YGMeasureModeAtMost && - node->getStyle().overflow() == YGOverflowScroll) { - node->setLayoutMeasuredDimension( - YGFloatMax( - YGFloatMin( - availableInnerCrossDim + paddingAndBorderAxisCross, - YGNodeBoundAxisWithinMinAndMax( - node, - crossAxis, - YGFloatOptional{ - totalLineCrossDim + paddingAndBorderAxisCross}, - crossAxisownerSize) - .unwrap()), - paddingAndBorderAxisCross), - dim[crossAxis]); - } - - // As we only wrapped in normal direction yet, we need to reverse the - // positions on wrap-reverse. - if (performLayout && node->getStyle().flexWrap() == YGWrapWrapReverse) { - for (uint32_t i = 0; i < childCount; i++) { - const YGNodeRef child = YGNodeGetChild(node, i); - if (child->getStyle().positionType() != YGPositionTypeAbsolute) { - child->setLayoutPosition( - node->getLayout().measuredDimensions[dim[crossAxis]] - - child->getLayout().position[pos[crossAxis]] - - child->getLayout().measuredDimensions[dim[crossAxis]], - pos[crossAxis]); - } - } - } - - if (performLayout) { - // STEP 10: SIZING AND POSITIONING ABSOLUTE CHILDREN - for (auto child : node->getChildren()) { - if (child->getStyle().display() == YGDisplayNone || - child->getStyle().positionType() != YGPositionTypeAbsolute) { - continue; - } - const bool absolutePercentageAgainstPaddingEdge = - node->getConfig()->isExperimentalFeatureEnabled( - YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge); - - YGNodeAbsoluteLayoutChild( - node, - child, - absolutePercentageAgainstPaddingEdge - ? node->getLayout().measuredDimensions[YGDimensionWidth] - : availableInnerWidth, - isMainAxisRow ? measureModeMainDim : measureModeCrossDim, - absolutePercentageAgainstPaddingEdge - ? node->getLayout().measuredDimensions[YGDimensionHeight] - : availableInnerHeight, - direction, - config, - layoutMarkerData, - layoutContext, - depth, - generationCount); - } - - // 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 = node->getChild(i); - if (child->getStyle().display() == YGDisplayNone) { - continue; - } - if (needsMainTrailingPos) { - YGNodeSetChildTrailingPosition(node, child, mainAxis); - } - - if (needsCrossTrailingPos) { - YGNodeSetChildTrailingPosition(node, child, crossAxis); - } - } - } - } -} - -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) { - constexpr auto N = enums::count(); - const char* kMeasureModeNames[N] = {"UNDEFINED", "EXACTLY", "AT_MOST"}; - const char* kLayoutModeNames[N] = { - "LAY_UNDEFINED", "LAY_EXACTLY", "LAY_AT_MOST"}; - - if (mode >= N) { - 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 || YGFloatsEqual(size, lastComputedSize)); -} - -static inline bool YGMeasureModeNewMeasureSizeIsStricterAndStillValid( - YGMeasureMode sizeMode, - float size, - YGMeasureMode lastSizeMode, - float lastSize, - float lastComputedSize) { - return lastSizeMode == YGMeasureModeAtMost && - sizeMode == YGMeasureModeAtMost && !YGFloatIsUndefined(lastSize) && - !YGFloatIsUndefined(size) && !YGFloatIsUndefined(lastComputedSize) && - lastSize > size && - (lastComputedSize <= size || YGFloatsEqual(size, lastComputedSize)); -} - -YOGA_EXPORT float YGRoundValueToPixelGrid( - const double value, - const double pointScaleFactor, - const bool forceCeil, - const bool forceFloor) { - double scaledValue = value * pointScaleFactor; - // We want to calculate `fractial` such that `floor(scaledValue) = scaledValue - // - fractial`. - double fractial = fmod(scaledValue, 1.0); - if (fractial < 0) { - // This branch is for handling negative numbers for `value`. - // - // Regarding `floor` and `ceil`. Note that for a number x, `floor(x) <= x <= - // ceil(x)` even for negative numbers. Here are a couple of examples: - // - x = 2.2: floor( 2.2) = 2, ceil( 2.2) = 3 - // - x = -2.2: floor(-2.2) = -3, ceil(-2.2) = -2 - // - // Regarding `fmodf`. For fractional negative numbers, `fmodf` returns a - // negative number. For example, `fmodf(-2.2) = -0.2`. However, we want - // `fractial` to be the number such that subtracting it from `value` will - // give us `floor(value)`. In the case of negative numbers, adding 1 to - // `fmodf(value)` gives us this. Let's continue the example from above: - // - fractial = fmodf(-2.2) = -0.2 - // - Add 1 to the fraction: fractial2 = fractial + 1 = -0.2 + 1 = 0.8 - // - Finding the `floor`: -2.2 - fractial2 = -2.2 - 0.8 = -3 - ++fractial; - } - if (YGDoubleEqual(fractial, 0)) { - // First we check if the value is already rounded - scaledValue = scaledValue - fractial; - } else if (YGDoubleEqual(fractial, 1.0)) { - scaledValue = scaledValue - fractial + 1.0; - } else if (forceCeil) { - // Next we check if we need to use forced rounding - scaledValue = scaledValue - fractial + 1.0; - } else if (forceFloor) { - scaledValue = scaledValue - fractial; - } else { - // Finally we just round the value - scaledValue = scaledValue - fractial + - (!YGDoubleIsUndefined(fractial) && - (fractial > 0.5 || YGDoubleEqual(fractial, 0.5)) - ? 1.0 - : 0.0); - } - return (YGDoubleIsUndefined(scaledValue) || - YGDoubleIsUndefined(pointScaleFactor)) - ? YGUndefined - : (float) (scaledValue / pointScaleFactor); -} - -YOGA_EXPORT bool YGNodeCanUseCachedMeasurement( - const YGMeasureMode widthMode, - const float width, - const YGMeasureMode heightMode, - const float height, - const YGMeasureMode lastWidthMode, - const float lastWidth, - const YGMeasureMode lastHeightMode, - const float lastHeight, - const float lastComputedWidth, - const float lastComputedHeight, - const float marginRow, - const float marginColumn, - const YGConfigRef config) { - if ((!YGFloatIsUndefined(lastComputedHeight) && lastComputedHeight < 0) || - (!YGFloatIsUndefined(lastComputedWidth) && lastComputedWidth < 0)) { - return false; - } - bool useRoundedComparison = - config != nullptr && config->getPointScaleFactor() != 0; - const float effectiveWidth = useRoundedComparison - ? YGRoundValueToPixelGrid( - width, config->getPointScaleFactor(), false, false) - : width; - const float effectiveHeight = useRoundedComparison - ? YGRoundValueToPixelGrid( - height, config->getPointScaleFactor(), false, false) - : height; - const float effectiveLastWidth = useRoundedComparison - ? YGRoundValueToPixelGrid( - lastWidth, config->getPointScaleFactor(), false, false) - : lastWidth; - const float effectiveLastHeight = useRoundedComparison - ? YGRoundValueToPixelGrid( - lastHeight, config->getPointScaleFactor(), false, false) - : lastHeight; - - const bool hasSameWidthSpec = lastWidthMode == widthMode && - YGFloatsEqual(effectiveLastWidth, effectiveWidth); - const bool hasSameHeightSpec = lastHeightMode == heightMode && - YGFloatsEqual(effectiveLastHeight, effectiveHeight); - - 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 ownerDirection, - const YGMeasureMode widthMeasureMode, - const YGMeasureMode heightMeasureMode, - const float ownerWidth, - const float ownerHeight, - const bool performLayout, - const LayoutPassReason reason, - const YGConfigRef config, - LayoutData& layoutMarkerData, - void* const layoutContext, - uint32_t depth, - const uint32_t generationCount) { - YGLayout* layout = &node->getLayout(); - - depth++; - - const bool needToVisitNode = - (node->isDirty() && layout->generationCount != generationCount) || - layout->lastOwnerDirection != ownerDirection; - - if (needToVisitNode) { - // Invalidate the cached results. - layout->nextCachedMeasurementsIndex = 0; - layout->cachedLayout.availableWidth = -1; - layout->cachedLayout.availableHeight = -1; - layout->cachedLayout.widthMeasureMode = YGMeasureModeUndefined; - layout->cachedLayout.heightMeasureMode = YGMeasureModeUndefined; - layout->cachedLayout.computedWidth = -1; - layout->cachedLayout.computedHeight = -1; - } - - YGCachedMeasurement* cachedResults = nullptr; - - // 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 laid 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->hasMeasureFunc()) { - const float marginAxisRow = - node->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap(); - const float marginAxisColumn = - node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth).unwrap(); - - // 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, - config)) { - 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, - config)) { - 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 != nullptr) { - layout->measuredDimensions[YGDimensionWidth] = cachedResults->computedWidth; - layout->measuredDimensions[YGDimensionHeight] = - cachedResults->computedHeight; - - (performLayout ? layoutMarkerData.cachedLayouts - : layoutMarkerData.cachedMeasures) += 1; - - if (gPrintChanges && gPrintSkips) { - Log::log( - node, - YGLogLevelVerbose, - nullptr, - "%s%d.{[skipped] ", - YGSpacer(depth), - depth); - node->print(layoutContext); - Log::log( - node, - YGLogLevelVerbose, - nullptr, - "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, - LayoutPassReasonToString(reason)); - } - } else { - if (gPrintChanges) { - Log::log( - node, - YGLogLevelVerbose, - nullptr, - "%s%d.{%s", - YGSpacer(depth), - depth, - needToVisitNode ? "*" : ""); - node->print(layoutContext); - Log::log( - node, - YGLogLevelVerbose, - nullptr, - "wm: %s, hm: %s, aw: %f ah: %f %s\n", - YGMeasureModeName(widthMeasureMode, performLayout), - YGMeasureModeName(heightMeasureMode, performLayout), - availableWidth, - availableHeight, - LayoutPassReasonToString(reason)); - } - - YGNodelayoutImpl( - node, - availableWidth, - availableHeight, - ownerDirection, - widthMeasureMode, - heightMeasureMode, - ownerWidth, - ownerHeight, - performLayout, - config, - layoutMarkerData, - layoutContext, - depth, - generationCount, - reason); - - if (gPrintChanges) { - Log::log( - node, - YGLogLevelVerbose, - nullptr, - "%s%d.}%s", - YGSpacer(depth), - depth, - needToVisitNode ? "*" : ""); - node->print(layoutContext); - Log::log( - node, - YGLogLevelVerbose, - nullptr, - "wm: %s, hm: %s, d: (%f, %f) %s\n", - YGMeasureModeName(widthMeasureMode, performLayout), - YGMeasureModeName(heightMeasureMode, performLayout), - layout->measuredDimensions[YGDimensionWidth], - layout->measuredDimensions[YGDimensionHeight], - LayoutPassReasonToString(reason)); - } - - layout->lastOwnerDirection = ownerDirection; - - if (cachedResults == nullptr) { - if (layout->nextCachedMeasurementsIndex + 1 > - (uint32_t) layoutMarkerData.maxMeasureCache) { - layoutMarkerData.maxMeasureCache = - layout->nextCachedMeasurementsIndex + 1; - } - if (layout->nextCachedMeasurementsIndex == YG_MAX_CACHED_RESULT_COUNT) { - if (gPrintChanges) { - Log::log(node, YGLogLevelVerbose, nullptr, "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->setLayoutDimension( - node->getLayout().measuredDimensions[YGDimensionWidth], - YGDimensionWidth); - node->setLayoutDimension( - node->getLayout().measuredDimensions[YGDimensionHeight], - YGDimensionHeight); - - node->setHasNewLayout(true); - node->setDirty(false); - } - - layout->generationCount = generationCount; - - LayoutType layoutType; - if (performLayout) { - layoutType = !needToVisitNode && cachedResults == &layout->cachedLayout - ? LayoutType::kCachedLayout - : LayoutType::kLayout; - } else { - layoutType = cachedResults != nullptr ? LayoutType::kCachedMeasure - : LayoutType::kMeasure; - } - Event::publish(node, {layoutType, layoutContext}); - - return (needToVisitNode || cachedResults == nullptr); -} - -YOGA_EXPORT void YGConfigSetPointScaleFactor( - const YGConfigRef config, - const float pixelsInPoint) { - YGAssertWithConfig( - config, - pixelsInPoint >= 0.0f, - "Scale factor should not be less than zero"); - - // We store points for Pixel as we will use it for rounding - if (pixelsInPoint == 0.0f) { - // Zero is used to skip rounding - config->setPointScaleFactor(0.0f); - } else { - config->setPointScaleFactor(pixelsInPoint); - } -} - -YOGA_EXPORT float YGConfigGetPointScaleFactor(const YGConfigRef config) { - return config->getPointScaleFactor(); -} - -static void YGRoundToPixelGrid( - const YGNodeRef node, - const double pointScaleFactor, - const double absoluteLeft, - const double absoluteTop) { - if (pointScaleFactor == 0.0f) { - return; - } - - const double nodeLeft = node->getLayout().position[YGEdgeLeft]; - const double nodeTop = node->getLayout().position[YGEdgeTop]; - - const double nodeWidth = node->getLayout().dimensions[YGDimensionWidth]; - const double nodeHeight = node->getLayout().dimensions[YGDimensionHeight]; - - const double absoluteNodeLeft = absoluteLeft + nodeLeft; - const double absoluteNodeTop = absoluteTop + nodeTop; - - const double absoluteNodeRight = absoluteNodeLeft + nodeWidth; - const double absoluteNodeBottom = absoluteNodeTop + nodeHeight; - - // If a node has a custom measure function we never want to round down its - // size as this could lead to unwanted text truncation. - const bool textRounding = node->getNodeType() == YGNodeTypeText; - - node->setLayoutPosition( - YGRoundValueToPixelGrid(nodeLeft, pointScaleFactor, false, textRounding), - YGEdgeLeft); - - node->setLayoutPosition( - YGRoundValueToPixelGrid(nodeTop, pointScaleFactor, false, textRounding), - YGEdgeTop); - - // We multiply dimension by scale factor and if the result is close to the - // whole number, we don't have any fraction To verify if the result is close - // to whole number we want to check both floor and ceil numbers - const bool hasFractionalWidth = - !YGDoubleEqual(fmod(nodeWidth * pointScaleFactor, 1.0), 0) && - !YGDoubleEqual(fmod(nodeWidth * pointScaleFactor, 1.0), 1.0); - const bool hasFractionalHeight = - !YGDoubleEqual(fmod(nodeHeight * pointScaleFactor, 1.0), 0) && - !YGDoubleEqual(fmod(nodeHeight * pointScaleFactor, 1.0), 1.0); - - node->setLayoutDimension( - YGRoundValueToPixelGrid( - absoluteNodeRight, - pointScaleFactor, - (textRounding && hasFractionalWidth), - (textRounding && !hasFractionalWidth)) - - YGRoundValueToPixelGrid( - absoluteNodeLeft, pointScaleFactor, false, textRounding), - YGDimensionWidth); - - node->setLayoutDimension( - YGRoundValueToPixelGrid( - absoluteNodeBottom, - pointScaleFactor, - (textRounding && hasFractionalHeight), - (textRounding && !hasFractionalHeight)) - - YGRoundValueToPixelGrid( - absoluteNodeTop, pointScaleFactor, false, textRounding), - YGDimensionHeight); - - const uint32_t childCount = YGNodeGetChildCount(node); - for (uint32_t i = 0; i < childCount; i++) { - YGRoundToPixelGrid( - YGNodeGetChild(node, i), - pointScaleFactor, - absoluteNodeLeft, - absoluteNodeTop); - } -} - -YOGA_EXPORT void YGNodeCalculateLayoutWithContext( - const YGNodeRef node, - const float ownerWidth, - const float ownerHeight, - const YGDirection ownerDirection, - void* layoutContext) { - - Event::publish(node, {layoutContext}); - LayoutData markerData = {}; - - // 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.fetch_add(1, std::memory_order_relaxed); - node->resolveDimension(); - float width = YGUndefined; - YGMeasureMode widthMeasureMode = YGMeasureModeUndefined; - const auto& maxDimensions = node->getStyle().maxDimensions(); - if (YGNodeIsStyleDimDefined(node, YGFlexDirectionRow, ownerWidth)) { - width = - (YGResolveValue( - node->getResolvedDimension(dim[YGFlexDirectionRow]), ownerWidth) + - node->getMarginForAxis(YGFlexDirectionRow, ownerWidth)) - .unwrap(); - widthMeasureMode = YGMeasureModeExactly; - } else if (!YGResolveValue(maxDimensions[YGDimensionWidth], ownerWidth) - .isUndefined()) { - width = - YGResolveValue(maxDimensions[YGDimensionWidth], ownerWidth).unwrap(); - widthMeasureMode = YGMeasureModeAtMost; - } else { - width = ownerWidth; - widthMeasureMode = YGFloatIsUndefined(width) ? YGMeasureModeUndefined - : YGMeasureModeExactly; - } - - float height = YGUndefined; - YGMeasureMode heightMeasureMode = YGMeasureModeUndefined; - if (YGNodeIsStyleDimDefined(node, YGFlexDirectionColumn, ownerHeight)) { - height = (YGResolveValue( - node->getResolvedDimension(dim[YGFlexDirectionColumn]), - ownerHeight) + - node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth)) - .unwrap(); - heightMeasureMode = YGMeasureModeExactly; - } else if (!YGResolveValue(maxDimensions[YGDimensionHeight], ownerHeight) - .isUndefined()) { - height = - YGResolveValue(maxDimensions[YGDimensionHeight], ownerHeight).unwrap(); - heightMeasureMode = YGMeasureModeAtMost; - } else { - height = ownerHeight; - heightMeasureMode = YGFloatIsUndefined(height) ? YGMeasureModeUndefined - : YGMeasureModeExactly; - } - if (YGLayoutNodeInternal( - node, - width, - height, - ownerDirection, - widthMeasureMode, - heightMeasureMode, - ownerWidth, - ownerHeight, - true, - LayoutPassReason::kInitial, - node->getConfig(), - markerData, - layoutContext, - 0, // tree root - gCurrentGenerationCount.load(std::memory_order_relaxed))) { - node->setPosition( - node->getLayout().direction(), ownerWidth, ownerHeight, ownerWidth); - YGRoundToPixelGrid( - node, node->getConfig()->getPointScaleFactor(), 0.0f, 0.0f); - -#ifdef DEBUG - if (node->getConfig()->shouldPrintTree()) { - YGNodePrint( - node, - (YGPrintOptions) (YGPrintOptionsLayout | YGPrintOptionsChildren | YGPrintOptionsStyle)); - } -#endif - } - - Event::publish(node, {layoutContext, &markerData}); -} - -YOGA_EXPORT void YGNodeCalculateLayout( - const YGNodeRef node, - const float ownerWidth, - const float ownerHeight, - const YGDirection ownerDirection) { - YGNodeCalculateLayoutWithContext( - node, ownerWidth, ownerHeight, ownerDirection, nullptr); -} - -YOGA_EXPORT void YGConfigSetLogger(const YGConfigRef config, YGLogger logger) { - if (logger != nullptr) { - config->setLogger(logger); - } else { -#ifdef ANDROID - config->setLogger(&YGAndroidLog); -#else - config->setLogger(&YGDefaultLog); -#endif - } -} - -void YGAssert(const bool condition, const char* message) { - if (!condition) { - Log::log(YGNodeRef{nullptr}, YGLogLevelFatal, nullptr, "%s\n", message); - throwLogicalErrorWithMessage(message); - } -} - -void YGAssertWithNode( - const YGNodeRef node, - const bool condition, - const char* message) { - if (!condition) { - Log::log(node, YGLogLevelFatal, nullptr, "%s\n", message); - throwLogicalErrorWithMessage(message); - } -} - -void YGAssertWithConfig( - const YGConfigRef config, - const bool condition, - const char* message) { - if (!condition) { - Log::log(config, YGLogLevelFatal, nullptr, "%s\n", message); - throwLogicalErrorWithMessage(message); - } -} - -YOGA_EXPORT void YGConfigSetExperimentalFeatureEnabled( - const YGConfigRef config, - const YGExperimentalFeature feature, - const bool enabled) { - config->setExperimentalFeatureEnabled(feature, enabled); -} - -YOGA_EXPORT bool YGConfigIsExperimentalFeatureEnabled( - const YGConfigRef config, - const YGExperimentalFeature feature) { - return config->isExperimentalFeatureEnabled(feature); -} - -YOGA_EXPORT void YGConfigSetUseWebDefaults( - const YGConfigRef config, - const bool enabled) { - config->setUseWebDefaults(enabled); -} - -YOGA_EXPORT bool YGConfigGetUseLegacyStretchBehaviour( - const YGConfigRef config) { - return config->hasErrata(YGErrataStretchFlexBasis); -} - -YOGA_EXPORT void YGConfigSetUseLegacyStretchBehaviour( - const YGConfigRef config, - const bool useLegacyStretchBehaviour) { - if (useLegacyStretchBehaviour) { - config->addErrata(YGErrataStretchFlexBasis); - } else { - config->removeErrata(YGErrataStretchFlexBasis); - } -} - -bool YGConfigGetUseWebDefaults(const YGConfigRef config) { - return config->useWebDefaults(); -} - -YOGA_EXPORT void YGConfigSetContext(const YGConfigRef config, void* context) { - config->setContext(context); -} - -YOGA_EXPORT void* YGConfigGetContext(const YGConfigRef config) { - return config->getContext(); -} - -YOGA_EXPORT void YGConfigSetErrata(YGConfigRef config, YGErrata errata) { - config->setErrata(errata); -} - -YOGA_EXPORT YGErrata YGConfigGetErrata(YGConfigRef config) { - return config->getErrata(); -} - -YOGA_EXPORT void YGConfigSetCloneNodeFunc( - const YGConfigRef config, - const YGCloneNodeFunc callback) { - config->setCloneNodeCallback(callback); -} diff --git a/Sources/yoga/event/event.cpp b/Sources/yoga/event/event.cpp deleted file mode 100644 index 152c4e16..00000000 --- a/Sources/yoga/event/event.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "event.h" -#include -#include - -namespace facebook { -namespace yoga { - -const char* LayoutPassReasonToString(const LayoutPassReason value) { - switch (value) { - case LayoutPassReason::kInitial: - return "initial"; - case LayoutPassReason::kAbsLayout: - return "abs_layout"; - case LayoutPassReason::kStretch: - return "stretch"; - case LayoutPassReason::kMultilineStretch: - return "multiline_stretch"; - case LayoutPassReason::kFlexLayout: - return "flex_layout"; - case LayoutPassReason::kMeasureChild: - return "measure"; - case LayoutPassReason::kAbsMeasureChild: - return "abs_measure"; - case LayoutPassReason::kFlexMeasure: - return "flex_measure"; - default: - return "unknown"; - } -} - -namespace { - -struct Node { - std::function subscriber = nullptr; - Node* next = nullptr; - - Node(std::function&& subscriber) - : subscriber{std::move(subscriber)} {} -}; - -std::atomic subscribers{nullptr}; - -Node* push(Node* newHead) { - Node* oldHead; - do { - oldHead = subscribers.load(std::memory_order_relaxed); - if (newHead != nullptr) { - newHead->next = oldHead; - } - } while (!subscribers.compare_exchange_weak( - oldHead, newHead, std::memory_order_release, std::memory_order_relaxed)); - return oldHead; -} - -} // namespace - -void Event::reset() { - auto head = push(nullptr); - while (head != nullptr) { - auto current = head; - head = head->next; - delete current; - } -} - -void Event::subscribe(std::function&& subscriber) { - push(new Node{std::move(subscriber)}); -} - -void Event::publish(const YGNode& node, Type eventType, const Data& eventData) { - for (auto subscriber = subscribers.load(std::memory_order_relaxed); - subscriber != nullptr; - subscriber = subscriber->next) { - subscriber->subscriber(node, eventType, eventData); - } -} - -} // namespace yoga -} // namespace facebook diff --git a/Sources/yoga/event/event.h b/Sources/yoga/event/event.h deleted file mode 100644 index de15648f..00000000 --- a/Sources/yoga/event/event.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include -#include -#include -#include "YGEnums.h" - -struct YGConfig; -struct YGNode; - -namespace facebook { -namespace yoga { - -enum struct LayoutType : int { - kLayout = 0, - kMeasure = 1, - kCachedLayout = 2, - kCachedMeasure = 3 -}; - -enum struct LayoutPassReason : int { - kInitial = 0, - kAbsLayout = 1, - kStretch = 2, - kMultilineStretch = 3, - kFlexLayout = 4, - kMeasureChild = 5, - kAbsMeasureChild = 6, - kFlexMeasure = 7, - COUNT -}; - -struct LayoutData { - int layouts; - int measures; - int maxMeasureCache; - int cachedLayouts; - int cachedMeasures; - int measureCallbacks; - std::array(LayoutPassReason::COUNT)> - measureCallbackReasonsCount; -}; - -const char* LayoutPassReasonToString(const LayoutPassReason value); - -struct YOGA_EXPORT Event { - enum Type { - NodeAllocation, - NodeDeallocation, - NodeLayout, - LayoutPassStart, - LayoutPassEnd, - MeasureCallbackStart, - MeasureCallbackEnd, - NodeBaselineStart, - NodeBaselineEnd, - }; - class Data; - using Subscriber = void(const YGNode&, Type, Data); - using Subscribers = std::vector>; - - template - struct TypedData {}; - - class Data { - const void* data_; - - public: - template - Data(const TypedData& data) : data_{&data} {} - - template - const TypedData& get() const { - return *static_cast*>(data_); - } - }; - - static void reset(); - - static void subscribe(std::function&& subscriber); - - template - static void publish(const YGNode& node, const TypedData& eventData = {}) { - publish(node, E, Data{eventData}); - } - - template - static void publish(const YGNode* node, const TypedData& eventData = {}) { - publish(*node, eventData); - } - -private: - static void publish(const YGNode&, Type, const Data&); -}; - -template <> -struct Event::TypedData { - YGConfig* config; -}; - -template <> -struct Event::TypedData { - YGConfig* config; -}; - -template <> -struct Event::TypedData { - void* layoutContext; -}; - -template <> -struct Event::TypedData { - void* layoutContext; - LayoutData* layoutData; -}; - -template <> -struct Event::TypedData { - void* layoutContext; - float width; - YGMeasureMode widthMeasureMode; - float height; - YGMeasureMode heightMeasureMode; - float measuredWidth; - float measuredHeight; - const LayoutPassReason reason; -}; - -template <> -struct Event::TypedData { - LayoutType layoutType; - void* layoutContext; -}; - -} // namespace yoga -} // namespace facebook diff --git a/Sources/yoga/include/yoga/YGEnums.h b/Sources/yoga/include/yoga/YGEnums.h deleted file mode 100644 index d34f7aa2..00000000 --- a/Sources/yoga/include/yoga/YGEnums.h +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @generated by enums.py - -#pragma once -#include "YGMacros.h" - -// clang-format off - - -YG_EXTERN_C_BEGIN - -YG_ENUM_SEQ_DECL( - YGAlign, - YGAlignAuto, - YGAlignFlexStart, - YGAlignCenter, - YGAlignFlexEnd, - YGAlignStretch, - YGAlignBaseline, - YGAlignSpaceBetween, - YGAlignSpaceAround) - -YG_ENUM_SEQ_DECL( - YGDimension, - YGDimensionWidth, - YGDimensionHeight) - -YG_ENUM_SEQ_DECL( - YGDirection, - YGDirectionInherit, - YGDirectionLTR, - YGDirectionRTL) - -YG_ENUM_SEQ_DECL( - YGDisplay, - YGDisplayFlex, - YGDisplayNone) - -YG_ENUM_SEQ_DECL( - YGEdge, - YGEdgeLeft, - YGEdgeTop, - YGEdgeRight, - YGEdgeBottom, - YGEdgeStart, - YGEdgeEnd, - YGEdgeHorizontal, - YGEdgeVertical, - YGEdgeAll) - -YG_ENUM_DECL( - YGErrata, - YGErrataNone = 0, - YGErrataStretchFlexBasis = 1, - YGErrataAll = 2147483647, - YGErrataClassic = 2147483646) -YG_DEFINE_ENUM_FLAG_OPERATORS(YGErrata) - -YG_ENUM_SEQ_DECL( - YGExperimentalFeature, - YGExperimentalFeatureWebFlexBasis, - YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge, - YGExperimentalFeatureFixJNILocalRefOverflows) - -YG_ENUM_SEQ_DECL( - YGFlexDirection, - YGFlexDirectionColumn, - YGFlexDirectionColumnReverse, - YGFlexDirectionRow, - YGFlexDirectionRowReverse) - -YG_ENUM_SEQ_DECL( - YGGutter, - YGGutterColumn, - YGGutterRow, - YGGutterAll) - -YG_ENUM_SEQ_DECL( - YGJustify, - YGJustifyFlexStart, - YGJustifyCenter, - YGJustifyFlexEnd, - YGJustifySpaceBetween, - YGJustifySpaceAround, - YGJustifySpaceEvenly) - -YG_ENUM_SEQ_DECL( - YGLogLevel, - YGLogLevelError, - YGLogLevelWarn, - YGLogLevelInfo, - YGLogLevelDebug, - YGLogLevelVerbose, - YGLogLevelFatal) - -YG_ENUM_SEQ_DECL( - YGMeasureMode, - YGMeasureModeUndefined, - YGMeasureModeExactly, - YGMeasureModeAtMost) - -YG_ENUM_SEQ_DECL( - YGNodeType, - YGNodeTypeDefault, - YGNodeTypeText) - -YG_ENUM_SEQ_DECL( - YGOverflow, - YGOverflowVisible, - YGOverflowHidden, - YGOverflowScroll) - -YG_ENUM_SEQ_DECL( - YGPositionType, - YGPositionTypeStatic, - YGPositionTypeRelative, - YGPositionTypeAbsolute) - -YG_ENUM_DECL( - YGPrintOptions, - YGPrintOptionsLayout = 1, - YGPrintOptionsStyle = 2, - YGPrintOptionsChildren = 4) -YG_DEFINE_ENUM_FLAG_OPERATORS(YGPrintOptions) - -YG_ENUM_SEQ_DECL( - YGUnit, - YGUnitUndefined, - YGUnitPoint, - YGUnitPercent, - YGUnitAuto) - -YG_ENUM_SEQ_DECL( - YGWrap, - YGWrapNoWrap, - YGWrapWrap, - YGWrapWrapReverse) - -YG_EXTERN_C_END diff --git a/Sources/yoga/include/yoga/YGMacros.h b/Sources/yoga/include/yoga/YGMacros.h deleted file mode 100644 index cd137117..00000000 --- a/Sources/yoga/include/yoga/YGMacros.h +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#ifdef __cplusplus -#include -#endif - -#ifdef __cplusplus -#define YG_EXTERN_C_BEGIN extern "C" { -#define YG_EXTERN_C_END } -#else -#define YG_EXTERN_C_BEGIN -#define YG_EXTERN_C_END -#endif - -#if defined(__cplusplus) -#define YG_DEPRECATED(message) [[deprecated(message)]] -#elif defined(_MSC_VER) -#define YG_DEPRECATED(message) __declspec(deprecated(message)) -#else -#define YG_DEPRECATED(message) __attribute__((deprecated(message))) -#endif - -#ifdef _WINDLL -#define WIN_EXPORT __declspec(dllexport) -#else -#define WIN_EXPORT -#endif - -#ifndef YOGA_EXPORT -#ifdef _MSC_VER -#define YOGA_EXPORT -#else -#define YOGA_EXPORT __attribute__((visibility("default"))) -#endif -#endif - -#ifdef NS_ENUM -// Cannot use NSInteger as NSInteger has a different size than int (which is the -// default type of a enum). Therefor when linking the Yoga C library into obj-c -// the header is a mismatch for the Yoga ABI. -#define YG_ENUM_BEGIN(name) NS_ENUM(int, name) -#define YG_ENUM_END(name) -#else -#define YG_ENUM_BEGIN(name) enum name -#define YG_ENUM_END(name) name -#endif - -#ifdef __cplusplus -#define YG_DEFINE_ENUM_FLAG_OPERATORS(name) \ - extern "C++" { \ - constexpr inline name operator~(name a) { \ - return static_cast( \ - ~static_cast::type>(a)); \ - } \ - constexpr inline name operator|(name a, name b) { \ - return static_cast( \ - static_cast::type>(a) | \ - static_cast::type>(b)); \ - } \ - constexpr inline name operator&(name a, name b) { \ - return static_cast( \ - static_cast::type>(a) & \ - static_cast::type>(b)); \ - } \ - constexpr inline name operator^(name a, name b) { \ - return static_cast( \ - static_cast::type>(a) ^ \ - static_cast::type>(b)); \ - } \ - inline name& operator|=(name& a, name b) { \ - return reinterpret_cast( \ - reinterpret_cast::type&>(a) |= \ - static_cast::type>(b)); \ - } \ - inline name& operator&=(name& a, name b) { \ - return reinterpret_cast( \ - reinterpret_cast::type&>(a) &= \ - static_cast::type>(b)); \ - } \ - inline name& operator^=(name& a, name b) { \ - return reinterpret_cast( \ - reinterpret_cast::type&>(a) ^= \ - static_cast::type>(b)); \ - } \ - } -#else -#define YG_DEFINE_ENUM_FLAG_OPERATORS(name) -#endif - -#ifdef __cplusplus -namespace facebook { -namespace yoga { -namespace enums { - -template -constexpr int count(); // can't use `= delete` due to a defect in clang < 3.9 - -namespace detail { -template -constexpr int n() { - return sizeof...(xs); -} -} // namespace detail - -} // namespace enums -} // namespace yoga -} // namespace facebook -#endif - -#define YG_ENUM_DECL(NAME, ...) \ - typedef YG_ENUM_BEGIN(NAME){__VA_ARGS__} YG_ENUM_END(NAME); \ - WIN_EXPORT const char* NAME##ToString(NAME); - -#ifdef __cplusplus -#define YG_ENUM_SEQ_DECL(NAME, ...) \ - YG_ENUM_DECL(NAME, __VA_ARGS__) \ - YG_EXTERN_C_END \ - namespace facebook { \ - namespace yoga { \ - namespace enums { \ - template <> \ - constexpr int count() { \ - return detail::n<__VA_ARGS__>(); \ - } \ - } \ - } \ - } \ - YG_EXTERN_C_BEGIN -#else -#define YG_ENUM_SEQ_DECL YG_ENUM_DECL -#endif diff --git a/Sources/yoga/include/yoga/YGValue.h b/Sources/yoga/include/yoga/YGValue.h deleted file mode 100644 index a4f89f3b..00000000 --- a/Sources/yoga/include/yoga/YGValue.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "YGEnums.h" -#include "YGMacros.h" - -YG_EXTERN_C_BEGIN - -typedef struct YGValue { - float value; - YGUnit unit; -} YGValue; - -YOGA_EXPORT extern const YGValue YGValueAuto; -YOGA_EXPORT extern const YGValue YGValueUndefined; -YOGA_EXPORT extern const YGValue YGValueZero; - -YG_EXTERN_C_END - -#ifdef __cplusplus -#include -constexpr float YGUndefined = std::numeric_limits::quiet_NaN(); -#else -#include -#define YGUndefined NAN -#endif - -#ifdef __cplusplus -inline bool operator==(const YGValue& lhs, const YGValue& rhs) { - if (lhs.unit != rhs.unit) { - return false; - } - - switch (lhs.unit) { - case YGUnitUndefined: - case YGUnitAuto: - return true; - case YGUnitPoint: - case YGUnitPercent: - return lhs.value == rhs.value; - } - - return false; -} - -inline bool operator!=(const YGValue& lhs, const YGValue& rhs) { - return !(lhs == rhs); -} - -inline YGValue operator-(const YGValue& value) { - return {-value.value, value.unit}; -} -#endif diff --git a/Sources/yoga/include/yoga/Yoga.h b/Sources/yoga/include/yoga/Yoga.h deleted file mode 100644 index 81a01a67..00000000 --- a/Sources/yoga/include/yoga/Yoga.h +++ /dev/null @@ -1,381 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - -#ifndef __cplusplus -#include -#endif - -#include "YGEnums.h" -#include "YGMacros.h" -#include "YGValue.h" - -YG_EXTERN_C_BEGIN - -typedef struct YGSize { - float width; - float height; -} YGSize; - -typedef struct YGConfig* YGConfigRef; - -typedef struct YGNode* YGNodeRef; -typedef const struct YGNode* YGNodeConstRef; - -typedef YGSize (*YGMeasureFunc)( - YGNodeRef node, - float width, - YGMeasureMode widthMode, - float height, - YGMeasureMode heightMode); -typedef float (*YGBaselineFunc)(YGNodeRef node, float width, float height); -typedef void (*YGDirtiedFunc)(YGNodeRef node); -typedef void (*YGPrintFunc)(YGNodeRef node); -typedef void (*YGNodeCleanupFunc)(YGNodeRef node); -typedef int (*YGLogger)( - YGConfigRef config, - YGNodeRef node, - YGLogLevel level, - const char* format, - va_list args); -typedef YGNodeRef ( - *YGCloneNodeFunc)(YGNodeRef oldNode, YGNodeRef owner, int childIndex); - -// YGNode -WIN_EXPORT YGNodeRef YGNodeNew(void); -WIN_EXPORT YGNodeRef YGNodeNewWithConfig(YGConfigRef config); -WIN_EXPORT YGNodeRef YGNodeClone(YGNodeRef node); -WIN_EXPORT void YGNodeFree(YGNodeRef node); -WIN_EXPORT void YGNodeFreeRecursiveWithCleanupFunc( - YGNodeRef node, - YGNodeCleanupFunc cleanup); -WIN_EXPORT void YGNodeFreeRecursive(YGNodeRef node); -WIN_EXPORT void YGNodeReset(YGNodeRef node); - -WIN_EXPORT void YGNodeInsertChild( - YGNodeRef node, - YGNodeRef child, - uint32_t index); - -WIN_EXPORT void YGNodeSwapChild( - YGNodeRef node, - YGNodeRef child, - uint32_t index); - -WIN_EXPORT void YGNodeRemoveChild(YGNodeRef node, YGNodeRef child); -WIN_EXPORT void YGNodeRemoveAllChildren(YGNodeRef node); -WIN_EXPORT YGNodeRef YGNodeGetChild(YGNodeRef node, uint32_t index); -WIN_EXPORT YGNodeRef YGNodeGetOwner(YGNodeRef node); -WIN_EXPORT YGNodeRef YGNodeGetParent(YGNodeRef node); -WIN_EXPORT uint32_t YGNodeGetChildCount(YGNodeRef node); -WIN_EXPORT void YGNodeSetChildren( - YGNodeRef owner, - const YGNodeRef* children, - uint32_t count); - -WIN_EXPORT void YGNodeSetIsReferenceBaseline( - YGNodeRef node, - bool isReferenceBaseline); - -WIN_EXPORT bool YGNodeIsReferenceBaseline(YGNodeRef node); - -WIN_EXPORT void YGNodeCalculateLayout( - YGNodeRef node, - float availableWidth, - float availableHeight, - YGDirection ownerDirection); - -// Mark a node as dirty. Only valid for nodes with a custom measure function -// set. -// -// Yoga knows when to mark all other nodes as dirty but because nodes with -// measure functions depend on information not known to Yoga they must perform -// this dirty marking manually. -WIN_EXPORT void YGNodeMarkDirty(YGNodeRef node); - -// Marks the current node and all its descendants as dirty. -// -// Intended to be used for Yoga benchmarks. Don't use in production, as calling -// `YGCalculateLayout` will cause the recalculation of each and every node. -WIN_EXPORT void YGNodeMarkDirtyAndPropagateToDescendants(YGNodeRef node); - -WIN_EXPORT void YGNodePrint(YGNodeRef node, YGPrintOptions options); - -WIN_EXPORT bool YGFloatIsUndefined(float value); - -WIN_EXPORT bool YGNodeCanUseCachedMeasurement( - YGMeasureMode widthMode, - float width, - YGMeasureMode heightMode, - float height, - YGMeasureMode lastWidthMode, - float lastWidth, - YGMeasureMode lastHeightMode, - float lastHeight, - float lastComputedWidth, - float lastComputedHeight, - float marginRow, - float marginColumn, - YGConfigRef config); - -WIN_EXPORT void YGNodeCopyStyle(YGNodeRef dstNode, YGNodeRef srcNode); - -WIN_EXPORT void* YGNodeGetContext(YGNodeRef node); -WIN_EXPORT void YGNodeSetContext(YGNodeRef node, void* context); - -WIN_EXPORT YGConfigRef YGNodeGetConfig(YGNodeRef node); -WIN_EXPORT void YGNodeSetConfig(YGNodeRef node, YGConfigRef config); - -void YGConfigSetPrintTreeFlag(YGConfigRef config, bool enabled); -bool YGNodeHasMeasureFunc(YGNodeRef node); -WIN_EXPORT void YGNodeSetMeasureFunc(YGNodeRef node, YGMeasureFunc measureFunc); -bool YGNodeHasBaselineFunc(YGNodeRef node); -void YGNodeSetBaselineFunc(YGNodeRef node, YGBaselineFunc baselineFunc); -YGDirtiedFunc YGNodeGetDirtiedFunc(YGNodeRef node); -void YGNodeSetDirtiedFunc(YGNodeRef node, YGDirtiedFunc dirtiedFunc); -void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc); -WIN_EXPORT bool YGNodeGetHasNewLayout(YGNodeRef node); -WIN_EXPORT void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout); -YGNodeType YGNodeGetNodeType(YGNodeRef node); -void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType); -WIN_EXPORT bool YGNodeIsDirty(YGNodeRef node); - -WIN_EXPORT void YGNodeStyleSetDirection(YGNodeRef node, YGDirection direction); -WIN_EXPORT YGDirection YGNodeStyleGetDirection(YGNodeConstRef node); - -WIN_EXPORT void YGNodeStyleSetFlexDirection( - YGNodeRef node, - YGFlexDirection flexDirection); -WIN_EXPORT YGFlexDirection YGNodeStyleGetFlexDirection(YGNodeConstRef node); - -WIN_EXPORT void YGNodeStyleSetJustifyContent( - YGNodeRef node, - YGJustify justifyContent); -WIN_EXPORT YGJustify YGNodeStyleGetJustifyContent(YGNodeConstRef node); - -WIN_EXPORT void YGNodeStyleSetAlignContent( - YGNodeRef node, - YGAlign alignContent); -WIN_EXPORT YGAlign YGNodeStyleGetAlignContent(YGNodeConstRef node); - -WIN_EXPORT void YGNodeStyleSetAlignItems(YGNodeRef node, YGAlign alignItems); -WIN_EXPORT YGAlign YGNodeStyleGetAlignItems(YGNodeConstRef node); - -WIN_EXPORT void YGNodeStyleSetAlignSelf(YGNodeRef node, YGAlign alignSelf); -WIN_EXPORT YGAlign YGNodeStyleGetAlignSelf(YGNodeConstRef node); - -WIN_EXPORT void YGNodeStyleSetPositionType( - YGNodeRef node, - YGPositionType positionType); -WIN_EXPORT YGPositionType YGNodeStyleGetPositionType(YGNodeConstRef node); - -WIN_EXPORT void YGNodeStyleSetFlexWrap(YGNodeRef node, YGWrap flexWrap); -WIN_EXPORT YGWrap YGNodeStyleGetFlexWrap(YGNodeConstRef node); - -WIN_EXPORT void YGNodeStyleSetOverflow(YGNodeRef node, YGOverflow overflow); -WIN_EXPORT YGOverflow YGNodeStyleGetOverflow(YGNodeConstRef node); - -WIN_EXPORT void YGNodeStyleSetDisplay(YGNodeRef node, YGDisplay display); -WIN_EXPORT YGDisplay YGNodeStyleGetDisplay(YGNodeConstRef node); - -WIN_EXPORT void YGNodeStyleSetFlex(YGNodeRef node, float flex); -WIN_EXPORT float YGNodeStyleGetFlex(YGNodeConstRef node); - -WIN_EXPORT void YGNodeStyleSetFlexGrow(YGNodeRef node, float flexGrow); -WIN_EXPORT float YGNodeStyleGetFlexGrow(YGNodeConstRef node); - -WIN_EXPORT void YGNodeStyleSetFlexShrink(YGNodeRef node, float flexShrink); -WIN_EXPORT float YGNodeStyleGetFlexShrink(YGNodeConstRef node); - -WIN_EXPORT void YGNodeStyleSetFlexBasis(YGNodeRef node, float flexBasis); -WIN_EXPORT void YGNodeStyleSetFlexBasisPercent(YGNodeRef node, float flexBasis); -WIN_EXPORT void YGNodeStyleSetFlexBasisAuto(YGNodeRef node); -WIN_EXPORT YGValue YGNodeStyleGetFlexBasis(YGNodeConstRef node); - -WIN_EXPORT void YGNodeStyleSetPosition( - YGNodeRef node, - YGEdge edge, - float position); -WIN_EXPORT void YGNodeStyleSetPositionPercent( - YGNodeRef node, - YGEdge edge, - float position); -WIN_EXPORT YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge); - -WIN_EXPORT void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, float margin); -WIN_EXPORT void YGNodeStyleSetMarginPercent( - YGNodeRef node, - YGEdge edge, - float margin); -WIN_EXPORT void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge); -WIN_EXPORT YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge); - -WIN_EXPORT void YGNodeStyleSetPadding( - YGNodeRef node, - YGEdge edge, - float padding); -WIN_EXPORT void YGNodeStyleSetPaddingPercent( - YGNodeRef node, - YGEdge edge, - float padding); -WIN_EXPORT YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge); - -WIN_EXPORT void YGNodeStyleSetBorder(YGNodeRef node, YGEdge edge, float border); -WIN_EXPORT float YGNodeStyleGetBorder(YGNodeConstRef node, YGEdge edge); - -WIN_EXPORT void YGNodeStyleSetGap( - YGNodeRef node, - YGGutter gutter, - float gapLength); -WIN_EXPORT float YGNodeStyleGetGap(YGNodeConstRef node, YGGutter gutter); - -WIN_EXPORT void YGNodeStyleSetWidth(YGNodeRef node, float width); -WIN_EXPORT void YGNodeStyleSetWidthPercent(YGNodeRef node, float width); -WIN_EXPORT void YGNodeStyleSetWidthAuto(YGNodeRef node); -WIN_EXPORT YGValue YGNodeStyleGetWidth(YGNodeConstRef node); - -WIN_EXPORT void YGNodeStyleSetHeight(YGNodeRef node, float height); -WIN_EXPORT void YGNodeStyleSetHeightPercent(YGNodeRef node, float height); -WIN_EXPORT void YGNodeStyleSetHeightAuto(YGNodeRef node); -WIN_EXPORT YGValue YGNodeStyleGetHeight(YGNodeConstRef node); - -WIN_EXPORT void YGNodeStyleSetMinWidth(YGNodeRef node, float minWidth); -WIN_EXPORT void YGNodeStyleSetMinWidthPercent(YGNodeRef node, float minWidth); -WIN_EXPORT YGValue YGNodeStyleGetMinWidth(YGNodeConstRef node); - -WIN_EXPORT void YGNodeStyleSetMinHeight(YGNodeRef node, float minHeight); -WIN_EXPORT void YGNodeStyleSetMinHeightPercent(YGNodeRef node, float minHeight); -WIN_EXPORT YGValue YGNodeStyleGetMinHeight(YGNodeConstRef node); - -WIN_EXPORT void YGNodeStyleSetMaxWidth(YGNodeRef node, float maxWidth); -WIN_EXPORT void YGNodeStyleSetMaxWidthPercent(YGNodeRef node, float maxWidth); -WIN_EXPORT YGValue YGNodeStyleGetMaxWidth(YGNodeConstRef node); - -WIN_EXPORT void YGNodeStyleSetMaxHeight(YGNodeRef node, float maxHeight); -WIN_EXPORT void YGNodeStyleSetMaxHeightPercent(YGNodeRef node, float maxHeight); -WIN_EXPORT YGValue YGNodeStyleGetMaxHeight(YGNodeConstRef node); - -// Yoga specific properties, not compatible with flexbox specification Aspect -// ratio control the size of the undefined dimension of a node. Aspect ratio is -// encoded as a floating point value width/height. e.g. A value of 2 leads to a -// node with a width twice the size of its height while a value of 0.5 gives the -// opposite effect. -// -// - 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 -WIN_EXPORT void YGNodeStyleSetAspectRatio(YGNodeRef node, float aspectRatio); -WIN_EXPORT float YGNodeStyleGetAspectRatio(YGNodeConstRef node); - -WIN_EXPORT float YGNodeLayoutGetLeft(YGNodeRef node); -WIN_EXPORT float YGNodeLayoutGetTop(YGNodeRef node); -WIN_EXPORT float YGNodeLayoutGetRight(YGNodeRef node); -WIN_EXPORT float YGNodeLayoutGetBottom(YGNodeRef node); -WIN_EXPORT float YGNodeLayoutGetWidth(YGNodeRef node); -WIN_EXPORT float YGNodeLayoutGetHeight(YGNodeRef node); -WIN_EXPORT YGDirection YGNodeLayoutGetDirection(YGNodeRef node); -WIN_EXPORT bool YGNodeLayoutGetHadOverflow(YGNodeRef node); - -// Get the computed values for these nodes after performing layout. If they were -// set using point values then the returned value will be the same as -// YGNodeStyleGetXXX. However if they were set using a percentage value then the -// returned value is the computed value used during layout. -WIN_EXPORT float YGNodeLayoutGetMargin(YGNodeRef node, YGEdge edge); -WIN_EXPORT float YGNodeLayoutGetBorder(YGNodeRef node, YGEdge edge); -WIN_EXPORT float YGNodeLayoutGetPadding(YGNodeRef node, YGEdge edge); - -WIN_EXPORT void YGConfigSetLogger(YGConfigRef config, YGLogger logger); -WIN_EXPORT void YGAssert(bool condition, const char* message); -WIN_EXPORT void YGAssertWithNode( - YGNodeRef node, - bool condition, - const char* message); -WIN_EXPORT void YGAssertWithConfig( - YGConfigRef config, - bool condition, - const char* message); -// Set this to number of pixels in 1 point to round calculation results If you -// want to avoid rounding - set PointScaleFactor to 0 -WIN_EXPORT void YGConfigSetPointScaleFactor( - YGConfigRef config, - float pixelsInPoint); -WIN_EXPORT float YGConfigGetPointScaleFactor(YGConfigRef config); - -// Yoga previously had an error where containers would take the maximum space -// possible instead of the minimum like they are supposed to. In practice this -// resulted in implicit behaviour similar to align-self: stretch; Because this -// was such a long-standing bug we must allow legacy users to switch back to -// this behaviour. -WIN_EXPORT YG_DEPRECATED( - "Please use " - "\"YGConfigGetErrata()\"") bool YGConfigGetUseLegacyStretchBehaviour(YGConfigRef - config); -WIN_EXPORT -YG_DEPRECATED( - "\"YGConfigSetUseLegacyStretchBehaviour\" will be removed in the next " - "release. Usage should be replaced with \"YGConfigSetErrata(YGErrataAll)\" " - "to opt out of all future breaking conformance fixes, or " - "\"YGConfigSetErrata(YGErrataStretchFlexBasis)\" to opt out of the " - "specific conformance fix previously disabled by " - "\"UseLegacyStretchBehaviour\".") -void YGConfigSetUseLegacyStretchBehaviour( - YGConfigRef config, - bool useLegacyStretchBehaviour); - -// YGConfig -WIN_EXPORT YGConfigRef YGConfigNew(void); -WIN_EXPORT void YGConfigFree(YGConfigRef config); -WIN_EXPORT void YGConfigCopy(YGConfigRef dest, YGConfigRef src); -WIN_EXPORT int32_t YGConfigGetInstanceCount(void); - -WIN_EXPORT void YGConfigSetExperimentalFeatureEnabled( - YGConfigRef config, - YGExperimentalFeature feature, - bool enabled); -WIN_EXPORT bool YGConfigIsExperimentalFeatureEnabled( - YGConfigRef config, - YGExperimentalFeature feature); - -// Using the web defaults is the preferred configuration for new projects. Usage -// of non web defaults should be considered as legacy. -WIN_EXPORT void YGConfigSetUseWebDefaults(YGConfigRef config, bool enabled); -WIN_EXPORT bool YGConfigGetUseWebDefaults(YGConfigRef config); - -WIN_EXPORT void YGConfigSetCloneNodeFunc( - YGConfigRef config, - YGCloneNodeFunc callback); - -// Export only for C# -WIN_EXPORT YGConfigRef YGConfigGetDefault(void); - -WIN_EXPORT void YGConfigSetContext(YGConfigRef config, void* context); -WIN_EXPORT void* YGConfigGetContext(YGConfigRef config); - -WIN_EXPORT void YGConfigSetErrata(YGConfigRef config, YGErrata errata); -WIN_EXPORT YGErrata YGConfigGetErrata(YGConfigRef config); - -WIN_EXPORT float YGRoundValueToPixelGrid( - double value, - double pointScaleFactor, - bool forceCeil, - bool forceFloor); - -YG_EXTERN_C_END diff --git a/Sources/yoga/log.cpp b/Sources/yoga/log.cpp deleted file mode 100644 index b947aeaf..00000000 --- a/Sources/yoga/log.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "log.h" -#include "YGConfig.h" -#include "YGNode.h" -#include "Yoga.h" - -namespace facebook { -namespace yoga { -namespace detail { - -namespace { - -void vlog( - YGConfig* config, - YGNode* node, - YGLogLevel level, - void* context, - const char* format, - va_list args) { - YGConfig* logConfig = config != nullptr ? config : YGConfigGetDefault(); - logConfig->log(logConfig, node, level, context, format, args); -} -} // namespace - -YOGA_EXPORT void Log::log( - YGNode* node, - YGLogLevel level, - void* context, - const char* format, - ...) noexcept { - va_list args; - va_start(args, format); - vlog( - node == nullptr ? nullptr : node->getConfig(), - node, - level, - context, - format, - args); - va_end(args); -} - -void Log::log( - YGConfig* config, - YGLogLevel level, - void* context, - const char* format, - ...) noexcept { - va_list args; - va_start(args, format); - vlog(config, nullptr, level, context, format, args); - va_end(args); -} - -} // namespace detail -} // namespace yoga -} // namespace facebook diff --git a/Sources/yoga/log.h b/Sources/yoga/log.h deleted file mode 100644 index 1d270e82..00000000 --- a/Sources/yoga/log.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "YGEnums.h" - -struct YGNode; -struct YGConfig; - -namespace facebook { -namespace yoga { - -namespace detail { - -struct Log { - static void log( - YGNode* node, - YGLogLevel level, - void*, - const char* message, - ...) noexcept; - - static void log( - YGConfig* config, - YGLogLevel level, - void*, - const char* format, - ...) noexcept; -}; - -} // namespace detail -} // namespace yoga -} // namespace facebook diff --git a/FlexLayoutTests/FlexLayoutTests.swift b/Tests/FlexLayoutTests/FlexLayoutTests.swift similarity index 70% rename from FlexLayoutTests/FlexLayoutTests.swift rename to Tests/FlexLayoutTests/FlexLayoutTests.swift index 30553756..555ec27b 100644 --- a/FlexLayoutTests/FlexLayoutTests.swift +++ b/Tests/FlexLayoutTests/FlexLayoutTests.swift @@ -13,8 +13,9 @@ import XCTest @testable import FlexLayout -class FlexLayoutTests: XCTestCase { - +@MainActor +final class FlexLayoutTests: XCTestCase { + func testRetainCycle() { weak var weakView: UIView? = nil _ = { _ in @@ -22,8 +23,21 @@ class FlexLayoutTests: XCTestCase { strongView.flex.direction(.column) weakView = strongView }(()) - + XCTAssertNil(weakView, "Creation of flex should not lead to retain cycle") } + + func testRemoveViewDynamically() { + let rootFlexContainer = UIView() + rootFlexContainer.flex.addItem(UIView()) + rootFlexContainer.flex.define { _ in } + rootFlexContainer.flex.layout() + + rootFlexContainer.subviews.forEach { $0.removeFromSuperview() } + rootFlexContainer.flex.markDirty() + rootFlexContainer.flex.layout() + + XCTAssertTrue(rootFlexContainer.subviews.isEmpty) + } } diff --git a/Tests/FlexLayoutTests/InsetTests.swift b/Tests/FlexLayoutTests/InsetTests.swift new file mode 100644 index 00000000..a7bfb547 --- /dev/null +++ b/Tests/FlexLayoutTests/InsetTests.swift @@ -0,0 +1,168 @@ +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +import FlexLayout +import XCTest + +@MainActor +final class InsetTests: XCTestCase, Sendable { + + var viewController: UIViewController! + var rootFlexContainer: UIView! + var aView: UIView! + + override func setUp() async throws { + try await super.setUp() + + viewController = UIViewController() + + rootFlexContainer = UIView() + rootFlexContainer.frame = CGRect(x: 0, y: 0, width: 400, height: 400) + viewController.view.addSubview(rootFlexContainer) + + aView = UIView() + } + + func test_adjust_the_aView_size_and_relative_position_with_left() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.relative).grow(1).left(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 10.0, y: 0.0, width: 400.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_relative_position_with_top() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.relative).grow(1).top(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 10.0, width: 400.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_relative_position_with_right() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.relative).grow(1).right(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: -10.0, y: 0.0, width: 400.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_relative_position_with_bottom() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.relative).grow(1).bottom(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: -10.0, width: 400.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_relative_position_with_horizontally() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.relative).grow(1).horizontally(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 10.0, y: 0.0, width: 400.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_relative_position_with_vertically() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.relative).grow(1).vertically(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 10.0, width: 400.0, height: 400.0)) + } + + func test_adjust_the_aView_size_absolute_position_with_left_right() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.absolute).left(10).right(10).width(300).height(200) + } + + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 10.0, y: 0.0, width: 300.0, height: 200.0)) + } + + func test_adjust_the_aView_size_absolute_position_with_right_and_reset_left_later() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.absolute).left(10).right(10).width(300).height(200) + } + + // Later reset the aspectRatio + aView.flex.left(0) + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 300.0, height: 200.0)) + } + + func test_adjust_the_aView_size_absolute_position_with_horizontally_vertically() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.absolute).horizontally(15).vertically(20) + } + + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 15.0, y: 20.0, width: 370.0, height: 360.0)) + } + + func test_adjust_the_aView_size_absolute_position_with_all() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.absolute).all(45) + } + + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 45.0, y: 45.0, width: 310.0, height: 310.0)) + } + + func test_adjust_the_aView_size_and_relative_static_with_left() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.static).grow(1).left(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_static_position_with_top() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.static).grow(1).top(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_static_position_with_right() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.static).grow(1).right(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_static_position_with_bottom() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.static).grow(1).bottom(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_static_position_with_horizontally() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.static).grow(1).horizontally(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_static_position_with_vertically() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.static).grow(1).vertically(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 400.0)) + } +} diff --git a/Tests/FlexLayoutTests/JustifyContentTests.swift b/Tests/FlexLayoutTests/JustifyContentTests.swift new file mode 100644 index 00000000..b98e1195 --- /dev/null +++ b/Tests/FlexLayoutTests/JustifyContentTests.swift @@ -0,0 +1,154 @@ +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +import FlexLayout +import XCTest + +@MainActor +final class JustifyContentTests: XCTestCase, Sendable { + + var viewController: UIViewController! + var rootFlexContainer: UIView! + var aView: UIView! + var bView: UIView! + var cView: UIView! + var dView: UIView! + + override func setUp() async throws { + try await super.setUp() + + viewController = UIViewController() + + rootFlexContainer = UIView() + rootFlexContainer.frame = CGRect(x: 0, y: 0, width: 400, height: 400) + viewController.view.addSubview(rootFlexContainer) + + aView = UIView() + bView = UIView() + cView = UIView() + dView = UIView() + } + + + func test_justifyContent_adjust_view_position_default() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).size(20) + flex.addItem(bView).size(20) + flex.addItem(cView).size(20) + flex.addItem(dView).size(20) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 20.0, height: 20.0)) + XCTAssertEqual(bView.frame, CGRect(x: 0.0, y: 20.0, width: 20.0, height: 20.0)) + XCTAssertEqual(cView.frame, CGRect(x: 0.0, y: 40.0, width: 20.0, height: 20.0)) + XCTAssertEqual(dView.frame, CGRect(x: 0.0, y: 60.0, width: 20.0, height: 20.0)) + } + + func test_justifyContent_adjust_view_position_start() { + rootFlexContainer.flex.justifyContent(.start).define { flex in + flex.addItem(aView).size(20) + flex.addItem(bView).size(20) + flex.addItem(cView).size(20) + flex.addItem(dView).size(20) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 20.0, height: 20.0)) + XCTAssertEqual(bView.frame, CGRect(x: 0.0, y: 20.0, width: 20.0, height: 20.0)) + XCTAssertEqual(cView.frame, CGRect(x: 0.0, y: 40.0, width: 20.0, height: 20.0)) + XCTAssertEqual(dView.frame, CGRect(x: 0.0, y: 60.0, width: 20.0, height: 20.0)) + } + + func test_justifyContent_adjust_view_position_center() { + rootFlexContainer.flex.justifyContent(.center).define { flex in + flex.addItem(aView).size(20) + flex.addItem(bView).size(20) + flex.addItem(cView).size(20) + flex.addItem(dView).size(20) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 160.0, width: 20.0, height: 20.0)) + XCTAssertEqual(bView.frame, CGRect(x: 0.0, y: 180.0, width: 20.0, height: 20.0)) + XCTAssertEqual(cView.frame, CGRect(x: 0.0, y: 200.0, width: 20.0, height: 20.0)) + XCTAssertEqual(dView.frame, CGRect(x: 0.0, y: 220.0, width: 20.0, height: 20.0)) + } + + func test_justifyContent_adjust_view_position_spaceAround() { + rootFlexContainer.flex.justifyContent(.spaceAround).define { flex in + flex.addItem(aView).size(20) + flex.addItem(bView).size(20) + flex.addItem(cView).size(20) + flex.addItem(dView).size(20) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 40.0, width: 20.0, height: 20.0)) + XCTAssertEqual(bView.frame, CGRect(x: 0.0, y: 140.0, width: 20.0, height: 20.0)) + XCTAssertEqual(cView.frame, CGRect(x: 0.0, y: 240.0, width: 20.0, height: 20.0)) + XCTAssertEqual(dView.frame, CGRect(x: 0.0, y: 340.0, width: 20.0, height: 20.0)) + } + + func test_justifyContent_adjust_view_position_spaceBetween() { + rootFlexContainer.flex.justifyContent(.spaceBetween).define { flex in + flex.addItem(aView).size(20) + flex.addItem(bView).size(20) + flex.addItem(cView).size(20) + flex.addItem(dView).size(20) + } + rootFlexContainer.flex.layout() + + XCTAssertTrue(aView.frame.beCloseTo(CGRect(x: 0.0, y: 0.0, width: 20.0, height: 20.0), within: 0.5)) + XCTAssertTrue(bView.frame.beCloseTo(CGRect(x: 0.0, y: 126.5, width: 20.0, height: 20.0), within: 0.5)) + XCTAssertTrue(cView.frame.beCloseTo(CGRect(x: 0.0, y: 253.0, width: 20.0, height: 20.0), within: 0.5)) + XCTAssertTrue(dView.frame.beCloseTo(CGRect(x: 0.0, y: 380.0, width: 20.0, height: 20.0), within: 0.5)) + } + + func test_justifyContent_adjust_view_position_spaceBetween_with_margin() { + rootFlexContainer.flex.justifyContent(.spaceBetween).define { flex in + flex.addItem(aView).size(20).marginTop(10) + flex.addItem(bView).size(20) + flex.addItem(cView).size(20) + flex.addItem(dView).size(20).marginBottom(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 10.0, width: 20.0, height: 20.0)) + XCTAssertEqual(bView.frame, CGRect(x: 0.0, y: 130.0, width: 20.0, height: 20.0)) + XCTAssertEqual(cView.frame, CGRect(x: 0.0, y: 250.0, width: 20.0, height: 20.0)) + XCTAssertEqual(dView.frame, CGRect(x: 0.0, y: 370.0, width: 20.0, height: 20.0)) + } +} + + +// MARK: - Private + +extension CGRect { + + fileprivate func beCloseTo(_ expectedValue: CGRect, within delta: CGFloat = 0.000_01) -> Bool { + let actual = self + + if abs(actual.origin.x - expectedValue.origin.x) > delta { + return false + } + + if abs(actual.origin.y - expectedValue.origin.y) > delta { + return false + } + + if abs(actual.size.width - expectedValue.size.width) > delta { + return false + } + + if abs(actual.size.height - expectedValue.size.height) > delta { + return false + } + + return true + } +} diff --git a/Tests/FlexLayoutTests/MarginTests.swift b/Tests/FlexLayoutTests/MarginTests.swift new file mode 100644 index 00000000..3f0fc72a --- /dev/null +++ b/Tests/FlexLayoutTests/MarginTests.swift @@ -0,0 +1,121 @@ +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +import FlexLayout +import XCTest + +@MainActor +final class MarginTests: XCTestCase, Sendable { + + var viewController: UIViewController! + var rootFlexContainer: UIView! + var aView: UIView! + + override func setUp() async throws { + try await super.setUp() + + viewController = UIViewController() + + rootFlexContainer = UIView() + rootFlexContainer.frame = CGRect(x: 0, y: 0, width: 400, height: 400) + viewController.view.addSubview(rootFlexContainer) + + aView = UIView() + } + + func test_adjust_the_rootFlexContainer_size_and_position() { + rootFlexContainer.flex.define { _ in + } + rootFlexContainer.flex.layout() + XCTAssertEqual(rootFlexContainer.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_position() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).grow(1) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_position_with_marginLeft() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).grow(1).marginLeft(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 10.0, y: 0.0, width: 390.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_position_with_marginTop() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).grow(1).marginTop(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 10.0, width: 400.0, height: 390.0)) + } + + func test_adjust_the_aView_size_and_position_with_marginBottom() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).grow(1).marginBottom(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 390.0)) + } + + func test_adjust_the_aView_size_and_position_with_marginStart() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).grow(1).marginStart(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 10.0, y: 0.0, width: 390.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_position_with_marginEnd() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).grow(1).marginEnd(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 390.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_position_with_margin() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).grow(1).margin(10, 20, 30, 40) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 20.0, y: 10.0, width: 340.0, height: 360.0)) + } + + func test_adjust_the_aView_size_and_position_with_margin_all() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).grow(1).margin(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 10.0, y: 10.0, width: 380.0, height: 380.0)) + } + + func test_adjust_the_aView_size_and_position_with_marginVertical() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).grow(1).marginVertical(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 10.0, width: 400.0, height: 380.0)) + } + + func test_adjust_the_aView_size_and_position_with_marginHorizontal() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).grow(1).marginHorizontal(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 10.0, y: 0.0, width: 380.0, height: 400.0)) + } +} diff --git a/Tests/FlexLayoutTests/PaddingTests.swift b/Tests/FlexLayoutTests/PaddingTests.swift new file mode 100644 index 00000000..e43f7758 --- /dev/null +++ b/Tests/FlexLayoutTests/PaddingTests.swift @@ -0,0 +1,196 @@ +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +import FlexLayout +import XCTest + +@MainActor +final class PaddingTests: XCTestCase, Sendable { + + var viewController: UIViewController! + var rootFlexContainer: UIView! + var aView: UIView! + + override func setUp() async throws { + try await super.setUp() + + viewController = UIViewController() + + rootFlexContainer = UIView() + rootFlexContainer.frame = CGRect(x: 0, y: 0, width: 400, height: 400) + viewController.view.addSubview(rootFlexContainer) + + aView = UIView() + } + + func test_adjust_the_aView_size_and_position_with_paddingTop() { + rootFlexContainer.flex.paddingTop(10).define { flex in + flex.addItem(aView).grow(1) + } + + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 10.0, width: 400.0, height: 390.0)) + } + + func test_adjust_the_aView_size_and_position_with_paddingTop_percent() { + rootFlexContainer.flex.paddingTop(10%).define { flex in + flex.addItem(aView).grow(1) + } + + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 40.0, width: 400.0, height: 360.0)) + } + + func test_adjust_the_aView_size_and_position_with_paddingLeft() { + rootFlexContainer.flex.paddingLeft(10).define { flex in + flex.addItem(aView).grow(1) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 10.0, y: 0.0, width: 390.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_position_with_paddingLeft_percent() { + rootFlexContainer.flex.paddingLeft(10%).define { flex in + flex.addItem(aView).grow(1) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 40.0, y: 0.0, width: 360.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_position_with_paddingBottom() { + rootFlexContainer.flex.paddingBottom(10).define { flex in + flex.addItem(aView).grow(1) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 390.0)) + } + + func test_adjust_the_aView_size_and_position_with_paddingBottom_percent() { + rootFlexContainer.flex.paddingBottom(10%).define { flex in + flex.addItem(aView).grow(1) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 360.0)) + } + + func test_adjust_the_aView_size_and_position_with_paddingRight() { + rootFlexContainer.flex.paddingRight(10).define { flex in + flex.addItem(aView).grow(1) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 390.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_position_with_paddingRight_percent() { + rootFlexContainer.flex.paddingRight(10%).define { flex in + flex.addItem(aView).grow(1) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 360.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_position_with_padding_all() { + rootFlexContainer.flex.padding(10).define { flex in + flex.addItem(aView).grow(1) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 10.0, y: 10.0, width: 380.0, height: 380.0)) + } + + func test_adjust_the_aView_size_and_position_with_padding_all_percent() { + rootFlexContainer.flex.padding(10%).define { flex in + flex.addItem(aView).grow(1) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 40.0, y: 40.0, width: 320.0, height: 320.0)) + } + + func test_adjust_the_aView_size_and_position_with_padding() { + rootFlexContainer.flex.padding(10, 20, 30, 40).define { flex in + flex.addItem(aView).grow(1) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 20.0, y: 10.0, width: 340.0, height: 360.0)) + } + + func test_adjust_the_aView_size_and_position_with_padding_percent() { + rootFlexContainer.flex.padding(10%, 20%, 30%, 40%).define { flex in + flex.addItem(aView).grow(1) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 80.0, y: 40.0, width: 160.0, height: 240.0)) + } + + func test_adjust_the_aView_size_and_position_with_paddingStart() { + rootFlexContainer.flex.paddingStart(10).define { flex in + flex.addItem(aView).grow(1) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 10.0, y: 0.0, width: 390.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_position_with_paddingStart_percent() { + rootFlexContainer.flex.paddingStart(10%).define { flex in + flex.addItem(aView).grow(1) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 40.0, y: 0.0, width: 360.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_position_with_paddingEnd() { + rootFlexContainer.flex.paddingEnd(10).define { flex in + flex.addItem(aView).grow(1) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 390.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_position_with_paddingEnd_percent() { + rootFlexContainer.flex.paddingEnd(10%).define { flex in + flex.addItem(aView).grow(1) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 360.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_position_with_paddingVertical() { + rootFlexContainer.flex.paddingVertical(10).define { flex in + flex.addItem(aView).grow(1) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 10.0, width: 400.0, height: 380.0)) + } + + func test_adjust_the_aView_size_and_position_with_paddingVertical_percent() { + rootFlexContainer.flex.paddingVertical(10%).define { flex in + flex.addItem(aView).grow(1) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 40.0, width: 400.0, height: 320.0)) + } + + func test_adjust_the_aView_size_and_position_with_paddingHorizontal() { + rootFlexContainer.flex.paddingHorizontal(10).define { flex in + flex.addItem(aView).grow(1) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 10.0, y: 0.0, width: 380.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_position_with_paddingHorizontal_percent() { + rootFlexContainer.flex.paddingHorizontal(10%).define { flex in + flex.addItem(aView).grow(1) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 40.0, y: 0.0, width: 320.0, height: 400.0)) + } +} diff --git a/Tests/FlexLayoutTests/WidthSizeContentTests.swift b/Tests/FlexLayoutTests/WidthSizeContentTests.swift new file mode 100644 index 00000000..d247e872 --- /dev/null +++ b/Tests/FlexLayoutTests/WidthSizeContentTests.swift @@ -0,0 +1,212 @@ +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +import FlexLayout +import XCTest + +@MainActor +final class WidthSizeContentTests: XCTestCase, Sendable { + + var viewController: UIViewController! + var rootFlexContainer: UIView! + var aView: UIView! + var bView: UIView! + var cView: UIView! + + override func setUp() async throws { + try await super.setUp() + + viewController = UIViewController() + + rootFlexContainer = UIView() + rootFlexContainer.frame = CGRect(x: 0, y: 0, width: 400, height: 400) + viewController.view.addSubview(rootFlexContainer) + + aView = UIView() + bView = UIView() + cView = UIView() + } + + func test_basis_adjust_aView_size_and_position() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).width(100).height(200) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 100.0, height: 200.0)) + } + + func test_basis_adjust_aView_size_and_position_with_aspectRatio() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).width(200).aspectRatio(2) + } + + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 200.0, height: 100.0)) + } + + func test_basis_adjust_aView_size_and_position_with_aspectRatio_reset() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).width(200).aspectRatio(2) + } + + // Later reset the aspectRatio + aView.flex.aspectRatio(nil) + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 200.0, height: 0.0)) + } + + func test_basis_adjust_aView_size_and_position_with_width_height() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).width(200).minWidth(100).height(200).minHeight(100) + } + + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 200.0, height: 200.0)) + } + + func test_basis_adjust_aView_size_and_position_with_width_height_reset() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).width(200).minWidth(100).height(200).minHeight(100) + } + + // Later reset the width and the height + aView.flex.width(nil) + aView.flex.height(nil) + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 100.0)) + } + + func test_basis_adjust_aView_size_and_position_with_minWidth() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).width(200).minWidth(300).height(200) + } + + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 300.0, height: 200.0)) + } + + func test_basis_adjust_aView_size_and_position_with_minWidth_reset() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).width(200).maxWidth(300).height(200) + } + + // Later reset the minWidth + aView.flex.minWidth(nil) + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 200.0, height: 200.0)) + } + + func test_basis_adjust_aView_size_and_position_with_maxWidth() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).maxWidth(300).height(200) + } + + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 300.0, height: 200.0)) + } + + func test_basis_adjust_aView_size_and_position_with_maxWidth_reset() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).maxWidth(300).height(200) + } + + // Later reset the width and the height + aView.flex.maxWidth(nil) + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 200.0)) + } + + func test_basis_adjust_aView_size_and_position_with_minHeight() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).height(200).minHeight(300) + } + + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 300.0)) + } + + func test_basis_adjust_aView_size_and_position_with_minHeight_reset() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).height(200).minHeight(300) + } + + // Later reset the minHeight + aView.flex.minHeight(nil) + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 200.0)) + } + + func test_basis_adjust_aView_size_and_position_with_maxHeight() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).height(200).maxHeight(100) + } + + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 100.0)) + } + + func test_basis_adjust_aView_size_and_position_with_maxHeight_reset() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).height(200).maxHeight(100) + } + + // Later reset the maxHeight + aView.flex.maxHeight(nil) + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 200.0)) + } + + func test_row_gap() { + rootFlexContainer.flex.direction(.row).define { flex in + flex.addItem(aView).height(100).width(100) + flex.addItem(bView).height(100).width(100) + flex.alignItems(.start) + + flex.columnGap(50) + } + + rootFlexContainer.flex.layout() + XCTAssertEqual(bView.frame, CGRect(x: 150.0, y: 0.0, width: 100.0, height: 100.0)) + } + + func test_column_gap() { + rootFlexContainer.flex.direction(.column).define { flex in + flex.addItem(aView).height(100).width(100) + flex.addItem(bView).height(100).width(100) + flex.alignItems(.start) + + flex.rowGap(50) + } + + rootFlexContainer.flex.layout() + XCTAssertEqual(bView.frame, CGRect(x: 0.0, y: 150.0, width: 100.0, height: 100.0)) + } + + func test_gap() { + rootFlexContainer.flex.direction(.column).define { flex in + flex.addItem().direction(.row).define { flex in + flex.addItem(aView).height(100).width(100) + flex.addItem(bView).height(100).width(100) + flex.gap(50) + } + flex.addItem(cView).height(100).width(100) + + flex.alignItems(.start) + flex.gap(50) + } + + rootFlexContainer.flex.layout() + + XCTAssertEqual(bView.frame, CGRect(x: 150.0, y: 0.0, width: 100.0, height: 100.0)) + XCTAssertEqual(cView.frame, CGRect(x: 0.0, y: 150.0, width: 100.0, height: 100.0)) + } +} diff --git a/core-tests/YGAbsolutePositionTest.cpp b/core-tests/YGAbsolutePositionTest.cpp deleted file mode 100644 index a319cf1d..00000000 --- a/core-tests/YGAbsolutePositionTest.cpp +++ /dev/null @@ -1,1031 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @Generated by gentest/gentest.rb from gentest/fixtures/YGAbsolutePositionTest.html - -#include -#include - -TEST(YogaTest, absolute_layout_width_height_start_top) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, absolute_layout_width_height_end_bottom) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, absolute_layout_start_top_end_bottom) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, absolute_layout_width_height_start_top_end_bottom) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, do_not_clamp_height_of_absolute_node_to_height_of_its_overflow_hidden_parent) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetOverflow(root, YGOverflowHidden); - YGNodeStyleSetWidth(root, 50); - YGNodeStyleSetHeight(root, 50); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); - YGNodeStyleSetPosition(root_child0, YGEdgeStart, 0); - YGNodeStyleSetPosition(root_child0, YGEdgeTop, 0); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, absolute_layout_within_border) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - 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 = YGNodeNewWithConfig(config); - 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 = YGNodeNewWithConfig(config); - 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); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetPositionType(root_child2, YGPositionTypeAbsolute); - YGNodeStyleSetPosition(root_child2, YGEdgeLeft, 0); - YGNodeStyleSetPosition(root_child2, YGEdgeTop, 0); - YGNodeStyleSetMargin(root_child2, YGEdgeLeft, 10); - YGNodeStyleSetMargin(root_child2, YGEdgeTop, 10); - YGNodeStyleSetMargin(root_child2, YGEdgeRight, 10); - YGNodeStyleSetMargin(root_child2, YGEdgeBottom, 10); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeStyleSetHeight(root_child2, 50); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetPositionType(root_child3, YGPositionTypeAbsolute); - YGNodeStyleSetPosition(root_child3, YGEdgeRight, 0); - YGNodeStyleSetPosition(root_child3, YGEdgeBottom, 0); - YGNodeStyleSetMargin(root_child3, YGEdgeLeft, 10); - YGNodeStyleSetMargin(root_child3, YGEdgeTop, 10); - YGNodeStyleSetMargin(root_child3, YGEdgeRight, 10); - YGNodeStyleSetMargin(root_child3, YGEdgeBottom, 10); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeStyleSetHeight(root_child3, 50); - YGNodeInsertChild(root, root_child3, 3); - 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)); - - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); - - 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)); - - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, absolute_layout_align_items_and_justify_content_center) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetFlexGrow(root, 1); - YGNodeStyleSetWidth(root, 110); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); - YGNodeStyleSetWidth(root_child0, 60); - YGNodeStyleSetHeight(root_child0, 40); - 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(110, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(110, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, absolute_layout_align_items_and_justify_content_flex_end) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifyFlexEnd); - YGNodeStyleSetAlignItems(root, YGAlignFlexEnd); - YGNodeStyleSetFlexGrow(root, 1); - YGNodeStyleSetWidth(root, 110); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); - YGNodeStyleSetWidth(root_child0, 60); - YGNodeStyleSetHeight(root_child0, 40); - 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(110, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(110, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, absolute_layout_justify_content_center) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetFlexGrow(root, 1); - YGNodeStyleSetWidth(root, 110); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); - YGNodeStyleSetWidth(root_child0, 60); - YGNodeStyleSetHeight(root_child0, 40); - 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(110, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(110, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, absolute_layout_align_items_center) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetFlexGrow(root, 1); - YGNodeStyleSetWidth(root, 110); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); - YGNodeStyleSetWidth(root_child0, 60); - YGNodeStyleSetHeight(root_child0, 40); - 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(110, 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(60, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(110, 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(60, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, absolute_layout_align_items_center_on_child_only) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root, 1); - YGNodeStyleSetWidth(root, 110); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignSelf(root_child0, YGAlignCenter); - YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); - YGNodeStyleSetWidth(root_child0, 60); - YGNodeStyleSetHeight(root_child0, 40); - 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(110, 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(60, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(110, 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(60, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, absolute_layout_align_items_and_justify_content_center_and_top_position) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetFlexGrow(root, 1); - YGNodeStyleSetWidth(root, 110); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); - YGNodeStyleSetPosition(root_child0, YGEdgeTop, 10); - YGNodeStyleSetWidth(root_child0, 60); - YGNodeStyleSetHeight(root_child0, 40); - 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(110, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(110, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, absolute_layout_align_items_and_justify_content_center_and_bottom_position) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetFlexGrow(root, 1); - YGNodeStyleSetWidth(root, 110); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); - YGNodeStyleSetPosition(root_child0, YGEdgeBottom, 10); - YGNodeStyleSetWidth(root_child0, 60); - YGNodeStyleSetHeight(root_child0, 40); - 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(110, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(110, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, absolute_layout_align_items_and_justify_content_center_and_left_position) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetFlexGrow(root, 1); - YGNodeStyleSetWidth(root, 110); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); - YGNodeStyleSetPosition(root_child0, YGEdgeLeft, 5); - YGNodeStyleSetWidth(root_child0, 60); - YGNodeStyleSetHeight(root_child0, 40); - 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(110, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(5, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(110, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(5, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, absolute_layout_align_items_and_justify_content_center_and_right_position) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetFlexGrow(root, 1); - YGNodeStyleSetWidth(root, 110); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); - YGNodeStyleSetPosition(root_child0, YGEdgeRight, 5); - YGNodeStyleSetWidth(root_child0, 60); - YGNodeStyleSetHeight(root_child0, 40); - 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(110, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(45, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(110, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(45, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, position_root_with_rtl_should_position_withoutdirection) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetPosition(root, YGEdgeLeft, 72); - YGNodeStyleSetWidth(root, 52); - YGNodeStyleSetHeight(root, 52); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, absolute_layout_percentage_bottom_based_on_parent_height) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); - YGNodeStyleSetPositionPercent(root_child0, YGEdgeTop, 50); - YGNodeStyleSetWidth(root_child0, 10); - YGNodeStyleSetHeight(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetPositionType(root_child1, YGPositionTypeAbsolute); - YGNodeStyleSetPositionPercent(root_child1, YGEdgeBottom, 50); - YGNodeStyleSetWidth(root_child1, 10); - YGNodeStyleSetHeight(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetPositionType(root_child2, YGPositionTypeAbsolute); - YGNodeStyleSetPositionPercent(root_child2, YGEdgeTop, 10); - YGNodeStyleSetPositionPercent(root_child2, YGEdgeBottom, 10); - 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(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(10, 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(10, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(160, 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(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(160, YGNodeLayoutGetHeight(root_child2)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, absolute_layout_in_wrap_reverse_column_container) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexWrap(root, YGWrapWrapReverse); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); - YGNodeStyleSetWidth(root_child0, 20); - YGNodeStyleSetHeight(root_child0, 20); - 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(20, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(20, 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(20, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, absolute_layout_in_wrap_reverse_row_container) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetFlexWrap(root, YGWrapWrapReverse); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); - YGNodeStyleSetWidth(root_child0, 20); - YGNodeStyleSetHeight(root_child0, 20); - 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(20, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(20, 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(80, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, absolute_layout_in_wrap_reverse_column_container_flex_end) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexWrap(root, YGWrapWrapReverse); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignSelf(root_child0, YGAlignFlexEnd); - YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); - YGNodeStyleSetWidth(root_child0, 20); - YGNodeStyleSetHeight(root_child0, 20); - 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(20, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(20, 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(20, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, absolute_layout_in_wrap_reverse_row_container_flex_end) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetFlexWrap(root, YGWrapWrapReverse); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignSelf(root_child0, YGAlignFlexEnd); - YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); - YGNodeStyleSetWidth(root_child0, 20); - YGNodeStyleSetHeight(root_child0, 20); - 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(20, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(20, 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(20, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} diff --git a/core-tests/YGAlignContentTest.cpp b/core-tests/YGAlignContentTest.cpp deleted file mode 100644 index 7cd5c095..00000000 --- a/core-tests/YGAlignContentTest.cpp +++ /dev/null @@ -1,1878 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @Generated by gentest/gentest.rb from gentest/fixtures/YGAlignContentTest.html - -#include -#include - -TEST(YogaTest, align_content_flex_start) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 130); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeStyleSetHeight(root_child2, 10); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeStyleSetHeight(root_child3, 10); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNewWithConfig(config); - 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(130, 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(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, 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(10, 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(10, 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(20, 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(130, 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(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_content_flex_start_without_height_on_children) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeStyleSetHeight(root_child3, 10); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNewWithConfig(config); - 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(10, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(10, 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(10, 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(20, 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(10, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(10, 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(10, 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(20, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_content_flex_start_with_flex) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 120); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexBasisPercent(root_child0, 0); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeStyleSetFlexBasisPercent(root_child1, 0); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child3, 1); - YGNodeStyleSetFlexShrink(root_child3, 1); - YGNodeStyleSetFlexBasisPercent(root_child3, 0); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNewWithConfig(config); - 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(120, 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(40, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(40, 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(0, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(120, 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(120, 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(40, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(80, 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(80, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(120, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_content_flex_end) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignContent(root, YGAlignFlexEnd); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeStyleSetHeight(root_child2, 10); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeStyleSetHeight(root_child3, 10); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, align_content_stretch) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignContent(root, YGAlignStretch); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 150); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNewWithConfig(config); - 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(150, 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(150, 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(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(100, 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(100, 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(100, 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(100, 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); - - YGConfigFree(config); -} - -TEST(YogaTest, align_content_spacebetween) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root, YGAlignSpaceBetween); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 130); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeStyleSetHeight(root_child2, 10); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeStyleSetHeight(root_child3, 10); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNewWithConfig(config); - 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(130, 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(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, 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(45, 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(45, 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(90, 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(130, 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(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(45, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(45, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_content_spacearound) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root, YGAlignSpaceAround); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 140); - YGNodeStyleSetHeight(root, 120); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeStyleSetHeight(root_child2, 10); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeStyleSetHeight(root_child3, 10); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNewWithConfig(config); - 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(140, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(120, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(15, 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(15, 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(55, 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(55, 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(95, 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(140, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(120, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(15, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(15, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(55, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(55, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(95, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_content_stretch_row) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root, YGAlignStretch); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 150); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNewWithConfig(config); - 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(150, 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(50, 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(50, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(150, 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(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, 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(50, 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(50, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_content_stretch_row_with_children) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root, YGAlignStretch); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 150); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0_child0, 1); - YGNodeStyleSetFlexShrink(root_child0_child0, 1); - YGNodeStyleSetFlexBasisPercent(root_child0_child0, 0); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNewWithConfig(config); - 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(150, 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(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_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(50, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(150, 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(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_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(50, 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(50, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_content_stretch_row_with_flex) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root, YGAlignStretch); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 150); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeStyleSetFlexShrink(root_child1, 1); - YGNodeStyleSetFlexBasisPercent(root_child1, 0); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child3, 1); - YGNodeStyleSetFlexShrink(root_child3, 1); - YGNodeStyleSetFlexBasisPercent(root_child3, 0); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNewWithConfig(config); - 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(150, 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(0, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(100, 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(100, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, 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(150, 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(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(100, 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(100, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(0, 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(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_content_stretch_row_with_flex_no_shrink) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root, YGAlignStretch); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 150); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeStyleSetFlexShrink(root_child1, 1); - YGNodeStyleSetFlexBasisPercent(root_child1, 0); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child3, 1); - YGNodeStyleSetFlexBasisPercent(root_child3, 0); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNewWithConfig(config); - 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(150, 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(0, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(100, 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(100, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, 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(150, 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(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(100, 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(100, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(0, 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(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_content_stretch_row_with_margin) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root, YGAlignStretch); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 150); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetMargin(root_child1, YGEdgeLeft, 10); - YGNodeStyleSetMargin(root_child1, YGEdgeTop, 10); - YGNodeStyleSetMargin(root_child1, YGEdgeRight, 10); - YGNodeStyleSetMargin(root_child1, YGEdgeBottom, 10); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetMargin(root_child3, YGEdgeLeft, 10); - YGNodeStyleSetMargin(root_child3, YGEdgeTop, 10); - YGNodeStyleSetMargin(root_child3, YGEdgeRight, 10); - YGNodeStyleSetMargin(root_child3, YGEdgeBottom, 10); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNewWithConfig(config); - 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(150, 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(40, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child4)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(150, 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(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_content_stretch_row_with_padding) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root, YGAlignStretch); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 150); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetPadding(root_child1, YGEdgeLeft, 10); - YGNodeStyleSetPadding(root_child1, YGEdgeTop, 10); - YGNodeStyleSetPadding(root_child1, YGEdgeRight, 10); - YGNodeStyleSetPadding(root_child1, YGEdgeBottom, 10); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetPadding(root_child3, YGEdgeLeft, 10); - YGNodeStyleSetPadding(root_child3, YGEdgeTop, 10); - YGNodeStyleSetPadding(root_child3, YGEdgeRight, 10); - YGNodeStyleSetPadding(root_child3, YGEdgeBottom, 10); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNewWithConfig(config); - 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(150, 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(50, 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(50, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(150, 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(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, 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(50, 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(50, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_content_stretch_row_with_single_row) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root, YGAlignStretch); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 150); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(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(150, 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(150, 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(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)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_content_stretch_row_with_fixed_height) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root, YGAlignStretch); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 150); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(root_child1, 60); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNewWithConfig(config); - 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(150, 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(80, 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(60, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child4)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(150, 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(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(80, 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(60, 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(80, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_content_stretch_row_with_max_height) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root, YGAlignStretch); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 150); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetMaxHeight(root_child1, 20); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNewWithConfig(config); - 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(150, 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(50, 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(20, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(150, 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(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, 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(20, 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(50, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_content_stretch_row_with_min_height) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root, YGAlignStretch); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 150); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetMinHeight(root_child1, 80); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNewWithConfig(config); - 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(150, 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(90, 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(90, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(90, 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(90, 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(150, 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(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(90, 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(90, 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(90, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(90, 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(90, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_content_stretch_column) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignContent(root, YGAlignStretch); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 150); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0_child0, 1); - YGNodeStyleSetFlexShrink(root_child0_child0, 1); - YGNodeStyleSetFlexBasisPercent(root_child0_child0, 0); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeStyleSetFlexShrink(root_child1, 1); - YGNodeStyleSetFlexBasisPercent(root_child1, 0); - YGNodeStyleSetHeight(root_child1, 50); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root_child2, 50); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root_child3, 50); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(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(150, 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_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_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)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(50, 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(50, 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(150, 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(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(50, 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(50, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(50, 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(50, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_content_stretch_is_not_overriding_align_items) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignContent(root, YGAlignStretch); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root_child0, YGAlignStretch); - YGNodeStyleSetAlignItems(root_child0, YGAlignCenter); - YGNodeStyleSetWidth(root_child0, 100); - YGNodeStyleSetHeight(root_child0, 100); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignContent(root_child0_child0, YGAlignStretch); - YGNodeStyleSetWidth(root_child0_child0, 10); - YGNodeStyleSetHeight(root_child0_child0, 10); - 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(100, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(45, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(10, 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(100, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(45, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} diff --git a/core-tests/YGAlignItemsTest.cpp b/core-tests/YGAlignItemsTest.cpp deleted file mode 100644 index fd5e424f..00000000 --- a/core-tests/YGAlignItemsTest.cpp +++ /dev/null @@ -1,2158 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @Generated by gentest/gentest.rb from gentest/fixtures/YGAlignItemsTest.html - -#include -#include - -TEST(YogaTest, align_items_stretch) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, align_items_center) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, align_items_flex_start) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, align_items_flex_end) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root, YGAlignFlexEnd); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, align_baseline) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignItems(root, YGAlignBaseline); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(root_child1, 20); - 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(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, 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(50, 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(30, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_baseline_child) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignItems(root, YGAlignBaseline); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(root_child1, 20); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child1_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1_child0, 50); - YGNodeStyleSetHeight(root_child1_child0, 10); - YGNodeInsertChild(root_child1, root_child1_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(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_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(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_baseline_child_multiline) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignItems(root, YGAlignBaseline); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 60); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root_child1, YGFlexDirectionRow); - YGNodeStyleSetFlexWrap(root_child1, YGWrapWrap); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(root_child1, 25); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child1_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1_child0, 25); - YGNodeStyleSetHeight(root_child1_child0, 20); - YGNodeInsertChild(root_child1, root_child1_child0, 0); - - const YGNodeRef root_child1_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1_child1, 25); - YGNodeStyleSetHeight(root_child1_child1, 10); - YGNodeInsertChild(root_child1, root_child1_child1, 1); - - const YGNodeRef root_child1_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1_child2, 25); - YGNodeStyleSetHeight(root_child1_child2, 20); - YGNodeInsertChild(root_child1, root_child1_child2, 2); - - const YGNodeRef root_child1_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1_child3, 25); - YGNodeStyleSetHeight(root_child1_child3, 10); - YGNodeInsertChild(root_child1, root_child1_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(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(60, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1_child0)); - - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child1_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child1)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child1_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child1_child2)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child1_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1_child2)); - - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child1_child3)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child1_child3)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child1_child3)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_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(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(60, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child1)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child1_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_child1)); - - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child1_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child1_child2)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child1_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1_child2)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child3)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child1_child3)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child1_child3)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_child3)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_baseline_child_multiline_override) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignItems(root, YGAlignBaseline); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 60); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root_child1, YGFlexDirectionRow); - YGNodeStyleSetFlexWrap(root_child1, YGWrapWrap); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(root_child1, 25); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child1_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1_child0, 25); - YGNodeStyleSetHeight(root_child1_child0, 20); - YGNodeInsertChild(root_child1, root_child1_child0, 0); - - const YGNodeRef root_child1_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignSelf(root_child1_child1, YGAlignBaseline); - YGNodeStyleSetWidth(root_child1_child1, 25); - YGNodeStyleSetHeight(root_child1_child1, 10); - YGNodeInsertChild(root_child1, root_child1_child1, 1); - - const YGNodeRef root_child1_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1_child2, 25); - YGNodeStyleSetHeight(root_child1_child2, 20); - YGNodeInsertChild(root_child1, root_child1_child2, 2); - - const YGNodeRef root_child1_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignSelf(root_child1_child3, YGAlignBaseline); - YGNodeStyleSetWidth(root_child1_child3, 25); - YGNodeStyleSetHeight(root_child1_child3, 10); - YGNodeInsertChild(root_child1, root_child1_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(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(60, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1_child0)); - - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child1_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child1)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child1_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child1_child2)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child1_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1_child2)); - - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child1_child3)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child1_child3)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child1_child3)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_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(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(60, 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(25, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child1)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child1_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_child1)); - - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child1_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child1_child2)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child1_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1_child2)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child3)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child1_child3)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child1_child3)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_child3)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_baseline_child_multiline_no_override_on_secondline) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignItems(root, YGAlignBaseline); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 60); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root_child1, YGFlexDirectionRow); - YGNodeStyleSetFlexWrap(root_child1, YGWrapWrap); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(root_child1, 25); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child1_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1_child0, 25); - YGNodeStyleSetHeight(root_child1_child0, 20); - YGNodeInsertChild(root_child1, root_child1_child0, 0); - - const YGNodeRef root_child1_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1_child1, 25); - YGNodeStyleSetHeight(root_child1_child1, 10); - YGNodeInsertChild(root_child1, root_child1_child1, 1); - - const YGNodeRef root_child1_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1_child2, 25); - YGNodeStyleSetHeight(root_child1_child2, 20); - YGNodeInsertChild(root_child1, root_child1_child2, 2); - - const YGNodeRef root_child1_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignSelf(root_child1_child3, YGAlignBaseline); - YGNodeStyleSetWidth(root_child1_child3, 25); - YGNodeStyleSetHeight(root_child1_child3, 10); - YGNodeInsertChild(root_child1, root_child1_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(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(60, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1_child0)); - - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child1_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child1)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child1_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child1_child2)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child1_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1_child2)); - - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child1_child3)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child1_child3)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child1_child3)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_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(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(60, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child1)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child1_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_child1)); - - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child1_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child1_child2)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child1_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1_child2)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child3)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child1_child3)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child1_child3)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_child3)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_baseline_child_top) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignItems(root, YGAlignBaseline); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetPosition(root_child0, YGEdgeTop, 10); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(root_child1, 20); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child1_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1_child0, 50); - YGNodeStyleSetHeight(root_child1_child0, 10); - YGNodeInsertChild(root_child1, root_child1_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(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_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(10, 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(40, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_baseline_child_top2) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignItems(root, YGAlignBaseline); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetPosition(root_child1, YGEdgeTop, 5); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(root_child1, 20); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child1_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1_child0, 50); - YGNodeStyleSetHeight(root_child1_child0, 10); - YGNodeInsertChild(root_child1, root_child1_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(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(45, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_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(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(45, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_baseline_double_nested_child) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignItems(root, YGAlignBaseline); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0_child0, 50); - YGNodeStyleSetHeight(root_child0_child0, 20); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(root_child1, 20); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child1_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1_child0, 50); - YGNodeStyleSetHeight(root_child1_child0, 15); - YGNodeInsertChild(root_child1, root_child1_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(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(5, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(15, YGNodeLayoutGetHeight(root_child1_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(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(5, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(15, YGNodeLayoutGetHeight(root_child1_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_baseline_column) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root, YGAlignBaseline); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(root_child1, 20); - 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(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(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(50, 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(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_baseline_child_margin) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignItems(root, YGAlignBaseline); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMargin(root_child0, YGEdgeLeft, 5); - YGNodeStyleSetMargin(root_child0, YGEdgeTop, 5); - YGNodeStyleSetMargin(root_child0, YGEdgeRight, 5); - YGNodeStyleSetMargin(root_child0, YGEdgeBottom, 5); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(root_child1, 20); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child1_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMargin(root_child1_child0, YGEdgeLeft, 1); - YGNodeStyleSetMargin(root_child1_child0, YGEdgeTop, 1); - YGNodeStyleSetMargin(root_child1_child0, YGEdgeRight, 1); - YGNodeStyleSetMargin(root_child1_child0, YGEdgeBottom, 1); - YGNodeStyleSetWidth(root_child1_child0, 50); - YGNodeStyleSetHeight(root_child1_child0, 10); - YGNodeInsertChild(root_child1, root_child1_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(5, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(5, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(44, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(1, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(1, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_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(5, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(44, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(-1, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(1, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_baseline_child_padding) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignItems(root, YGAlignBaseline); - YGNodeStyleSetPadding(root, YGEdgeLeft, 5); - YGNodeStyleSetPadding(root, YGEdgeTop, 5); - YGNodeStyleSetPadding(root, YGEdgeRight, 5); - YGNodeStyleSetPadding(root, YGEdgeBottom, 5); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetPadding(root_child1, YGEdgeLeft, 5); - YGNodeStyleSetPadding(root_child1, YGEdgeTop, 5); - YGNodeStyleSetPadding(root_child1, YGEdgeRight, 5); - YGNodeStyleSetPadding(root_child1, YGEdgeBottom, 5); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(root_child1, 20); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child1_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1_child0, 50); - YGNodeStyleSetHeight(root_child1_child0, 10); - YGNodeInsertChild(root_child1, root_child1_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(5, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(5, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(55, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(5, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(5, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_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(5, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(-5, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(-5, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(5, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_baseline_multiline) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignItems(root, YGAlignBaseline); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(root_child1, 20); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child1_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1_child0, 50); - YGNodeStyleSetHeight(root_child1_child0, 10); - YGNodeInsertChild(root_child1, root_child1_child0, 0); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeStyleSetHeight(root_child2, 20); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child2_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2_child0, 50); - YGNodeStyleSetHeight(root_child2_child0, 10); - YGNodeInsertChild(root_child2, root_child2_child0, 0); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeStyleSetHeight(root_child3, 50); - 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(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(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(50, 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(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(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child3)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_baseline_multiline_column) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root, YGAlignBaseline); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 30); - YGNodeStyleSetHeight(root_child1, 50); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child1_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1_child0, 20); - YGNodeStyleSetHeight(root_child1_child0, 20); - YGNodeInsertChild(root_child1, root_child1_child0, 0); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 40); - YGNodeStyleSetHeight(root_child2, 70); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child2_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2_child0, 10); - YGNodeStyleSetHeight(root_child2_child0, 10); - YGNodeInsertChild(root_child2, root_child2_child0, 0); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeStyleSetHeight(root_child3, 20); - 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(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(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(70, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child2_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(70, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(20, 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(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(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(70, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1_child0)); - - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(70, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child2_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child2_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(70, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child3)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_baseline_multiline_column2) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root, YGAlignBaseline); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 30); - YGNodeStyleSetHeight(root_child1, 50); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child1_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1_child0, 20); - YGNodeStyleSetHeight(root_child1_child0, 20); - YGNodeInsertChild(root_child1, root_child1_child0, 0); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 40); - YGNodeStyleSetHeight(root_child2, 70); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child2_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2_child0, 10); - YGNodeStyleSetHeight(root_child2_child0, 10); - YGNodeInsertChild(root_child2, root_child2_child0, 0); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeStyleSetHeight(root_child3, 20); - 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(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(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(70, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child2_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(70, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(20, 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(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(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(70, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1_child0)); - - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(70, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child2_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child2_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(70, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child3)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_baseline_multiline_row_and_column) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignItems(root, YGAlignBaseline); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(root_child1, 50); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child1_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1_child0, 50); - YGNodeStyleSetHeight(root_child1_child0, 10); - YGNodeInsertChild(root_child1, root_child1_child0, 0); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 50); - YGNodeStyleSetHeight(root_child2, 20); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child2_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2_child0, 50); - YGNodeStyleSetHeight(root_child2_child0, 10); - YGNodeInsertChild(root_child2, root_child2_child0, 0); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child3, 50); - YGNodeStyleSetHeight(root_child3, 20); - 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(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(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(20, 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(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(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child3)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_items_center_child_with_margin_bigger_than_parent) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetWidth(root, 52); - YGNodeStyleSetHeight(root, 52); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root_child0, YGAlignCenter); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMargin(root_child0_child0, YGEdgeLeft, 10); - YGNodeStyleSetMargin(root_child0_child0, YGEdgeRight, 10); - YGNodeStyleSetWidth(root_child0_child0, 52); - YGNodeStyleSetHeight(root_child0_child0, 52); - 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(52, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root_child0_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root_child0_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_items_flex_end_child_with_margin_bigger_than_parent) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetWidth(root, 52); - YGNodeStyleSetHeight(root, 52); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root_child0, YGAlignFlexEnd); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMargin(root_child0_child0, YGEdgeLeft, 10); - YGNodeStyleSetMargin(root_child0_child0, YGEdgeRight, 10); - YGNodeStyleSetWidth(root_child0_child0, 52); - YGNodeStyleSetHeight(root_child0_child0, 52); - 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(52, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root_child0_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root_child0_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_items_center_child_without_margin_bigger_than_parent) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetWidth(root, 52); - YGNodeStyleSetHeight(root, 52); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root_child0, YGAlignCenter); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0_child0, 72); - YGNodeStyleSetHeight(root_child0_child0, 72); - 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(52, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_items_flex_end_child_without_margin_bigger_than_parent) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetWidth(root, 52); - YGNodeStyleSetHeight(root, 52); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root_child0, YGAlignFlexEnd); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0_child0, 72); - YGNodeStyleSetHeight(root_child0_child0, 72); - 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(52, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_center_should_size_based_on_content) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetMargin(root, YGEdgeTop, 20); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root_child0, YGJustifyCenter); - YGNodeStyleSetFlexShrink(root_child0, 1); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0_child0, 1); - YGNodeStyleSetFlexShrink(root_child0_child0, 1); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - const YGNodeRef root_child0_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0_child0_child0, 20); - YGNodeStyleSetHeight(root_child0_child0_child0, 20); - YGNodeInsertChild(root_child0_child0, root_child0_child0_child0, 0); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(20, 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(20, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0_child0_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(20, 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(20, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0_child0_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_strech_should_size_based_on_parent) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetMargin(root, YGEdgeTop, 20); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root_child0, YGJustifyCenter); - YGNodeStyleSetFlexShrink(root_child0, 1); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0_child0, 1); - YGNodeStyleSetFlexShrink(root_child0_child0, 1); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - const YGNodeRef root_child0_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0_child0_child0, 20); - YGNodeStyleSetHeight(root_child0_child0_child0, 20); - YGNodeInsertChild(root_child0_child0, root_child0_child0_child0, 0); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(20, 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(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)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0_child0_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(20, 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(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)); - - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0_child0_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_flex_start_with_shrinking_children) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 500); - YGNodeStyleSetHeight(root, 500); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root_child0, YGAlignFlexStart); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0_child0, 1); - YGNodeStyleSetFlexShrink(root_child0_child0, 1); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - const YGNodeRef root_child0_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0_child0_child0, 1); - YGNodeStyleSetFlexShrink(root_child0_child0_child0, 1); - YGNodeInsertChild(root_child0_child0, root_child0_child0_child0, 0); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(500, 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(0, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0_child0_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0_child0_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_flex_start_with_stretching_children) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 500); - YGNodeStyleSetHeight(root, 500); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0_child0, 1); - YGNodeStyleSetFlexShrink(root_child0_child0, 1); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - const YGNodeRef root_child0_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0_child0_child0, 1); - YGNodeStyleSetFlexShrink(root_child0_child0_child0, 1); - YGNodeInsertChild(root_child0_child0, root_child0_child0_child0, 0); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(500, 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(500, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0_child0_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(500, 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(500, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0_child0_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, align_flex_start_with_shrinking_children_with_stretch) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 500); - YGNodeStyleSetHeight(root, 500); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root_child0, YGAlignFlexStart); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0_child0, 1); - YGNodeStyleSetFlexShrink(root_child0_child0, 1); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - const YGNodeRef root_child0_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0_child0_child0, 1); - YGNodeStyleSetFlexShrink(root_child0_child0_child0, 1); - YGNodeInsertChild(root_child0_child0, root_child0_child0_child0, 0); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(500, 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(0, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0_child0_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0_child0_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} diff --git a/core-tests/YGAlignSelfTest.cpp b/core-tests/YGAlignSelfTest.cpp deleted file mode 100644 index 00bb7b9a..00000000 --- a/core-tests/YGAlignSelfTest.cpp +++ /dev/null @@ -1,249 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @Generated by gentest/gentest.rb from gentest/fixtures/YGAlignSelfTest.html - -#include -#include - -TEST(YogaTest, align_self_center) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, align_self_flex_end) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, align_self_flex_start) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, align_self_flex_end_override_flex_start) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, align_self_baseline) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignSelf(root_child0, YGAlignBaseline); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignSelf(root_child1, YGAlignBaseline); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(root_child1, 20); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child1_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1_child0, 50); - YGNodeStyleSetHeight(root_child1_child0, 10); - YGNodeInsertChild(root_child1, root_child1_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(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_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(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} diff --git a/core-tests/YGAndroidNewsFeed.cpp b/core-tests/YGAndroidNewsFeed.cpp deleted file mode 100644 index fb3f0730..00000000 --- a/core-tests/YGAndroidNewsFeed.cpp +++ /dev/null @@ -1,445 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @Generated by gentest/gentest.rb from gentest/fixtures/YGAndroidNewsFeed.html - -#include -#include - -TEST(YogaTest, android_news_feed) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignContent(root, YGAlignStretch); - YGNodeStyleSetWidth(root, 1080); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignContent(root_child0_child0, YGAlignStretch); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - const YGNodeRef root_child0_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignContent(root_child0_child0_child0, YGAlignStretch); - YGNodeInsertChild(root_child0_child0, root_child0_child0_child0, 0); - - const YGNodeRef root_child0_child0_child0_child0 = - YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection( - root_child0_child0_child0_child0, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root_child0_child0_child0_child0, YGAlignStretch); - YGNodeStyleSetAlignItems(root_child0_child0_child0_child0, YGAlignFlexStart); - YGNodeStyleSetMargin(root_child0_child0_child0_child0, YGEdgeStart, 36); - YGNodeStyleSetMargin(root_child0_child0_child0_child0, YGEdgeTop, 24); - YGNodeInsertChild( - root_child0_child0_child0, root_child0_child0_child0_child0, 0); - - const YGNodeRef root_child0_child0_child0_child0_child0 = - YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection( - root_child0_child0_child0_child0_child0, YGFlexDirectionRow); - YGNodeStyleSetAlignContent( - root_child0_child0_child0_child0_child0, YGAlignStretch); - YGNodeInsertChild( - root_child0_child0_child0_child0, - root_child0_child0_child0_child0_child0, - 0); - - const YGNodeRef root_child0_child0_child0_child0_child0_child0 = - YGNodeNewWithConfig(config); - YGNodeStyleSetAlignContent( - root_child0_child0_child0_child0_child0_child0, YGAlignStretch); - YGNodeStyleSetWidth(root_child0_child0_child0_child0_child0_child0, 120); - YGNodeStyleSetHeight(root_child0_child0_child0_child0_child0_child0, 120); - YGNodeInsertChild( - root_child0_child0_child0_child0_child0, - root_child0_child0_child0_child0_child0_child0, - 0); - - const YGNodeRef root_child0_child0_child0_child0_child1 = - YGNodeNewWithConfig(config); - YGNodeStyleSetAlignContent( - root_child0_child0_child0_child0_child1, YGAlignStretch); - YGNodeStyleSetFlexShrink(root_child0_child0_child0_child0_child1, 1); - YGNodeStyleSetMargin( - root_child0_child0_child0_child0_child1, YGEdgeRight, 36); - YGNodeStyleSetPadding( - root_child0_child0_child0_child0_child1, YGEdgeLeft, 36); - YGNodeStyleSetPadding(root_child0_child0_child0_child0_child1, YGEdgeTop, 21); - YGNodeStyleSetPadding( - root_child0_child0_child0_child0_child1, YGEdgeRight, 36); - YGNodeStyleSetPadding( - root_child0_child0_child0_child0_child1, YGEdgeBottom, 18); - YGNodeInsertChild( - root_child0_child0_child0_child0, - root_child0_child0_child0_child0_child1, - 1); - - const YGNodeRef root_child0_child0_child0_child0_child1_child0 = - YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection( - root_child0_child0_child0_child0_child1_child0, YGFlexDirectionRow); - YGNodeStyleSetAlignContent( - root_child0_child0_child0_child0_child1_child0, YGAlignStretch); - YGNodeStyleSetFlexShrink(root_child0_child0_child0_child0_child1_child0, 1); - YGNodeInsertChild( - root_child0_child0_child0_child0_child1, - root_child0_child0_child0_child0_child1_child0, - 0); - - const YGNodeRef root_child0_child0_child0_child0_child1_child1 = - YGNodeNewWithConfig(config); - YGNodeStyleSetAlignContent( - root_child0_child0_child0_child0_child1_child1, YGAlignStretch); - YGNodeStyleSetFlexShrink(root_child0_child0_child0_child0_child1_child1, 1); - YGNodeInsertChild( - root_child0_child0_child0_child0_child1, - root_child0_child0_child0_child0_child1_child1, - 1); - - const YGNodeRef root_child0_child0_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignContent(root_child0_child0_child1, YGAlignStretch); - YGNodeInsertChild(root_child0_child0, root_child0_child0_child1, 1); - - const YGNodeRef root_child0_child0_child1_child0 = - YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection( - root_child0_child0_child1_child0, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root_child0_child0_child1_child0, YGAlignStretch); - YGNodeStyleSetAlignItems(root_child0_child0_child1_child0, YGAlignFlexStart); - YGNodeStyleSetMargin(root_child0_child0_child1_child0, YGEdgeStart, 174); - YGNodeStyleSetMargin(root_child0_child0_child1_child0, YGEdgeTop, 24); - YGNodeInsertChild( - root_child0_child0_child1, root_child0_child0_child1_child0, 0); - - const YGNodeRef root_child0_child0_child1_child0_child0 = - YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection( - root_child0_child0_child1_child0_child0, YGFlexDirectionRow); - YGNodeStyleSetAlignContent( - root_child0_child0_child1_child0_child0, YGAlignStretch); - YGNodeInsertChild( - root_child0_child0_child1_child0, - root_child0_child0_child1_child0_child0, - 0); - - const YGNodeRef root_child0_child0_child1_child0_child0_child0 = - YGNodeNewWithConfig(config); - YGNodeStyleSetAlignContent( - root_child0_child0_child1_child0_child0_child0, YGAlignStretch); - YGNodeStyleSetWidth(root_child0_child0_child1_child0_child0_child0, 72); - YGNodeStyleSetHeight(root_child0_child0_child1_child0_child0_child0, 72); - YGNodeInsertChild( - root_child0_child0_child1_child0_child0, - root_child0_child0_child1_child0_child0_child0, - 0); - - const YGNodeRef root_child0_child0_child1_child0_child1 = - YGNodeNewWithConfig(config); - YGNodeStyleSetAlignContent( - root_child0_child0_child1_child0_child1, YGAlignStretch); - YGNodeStyleSetFlexShrink(root_child0_child0_child1_child0_child1, 1); - YGNodeStyleSetMargin( - root_child0_child0_child1_child0_child1, YGEdgeRight, 36); - YGNodeStyleSetPadding( - root_child0_child0_child1_child0_child1, YGEdgeLeft, 36); - YGNodeStyleSetPadding(root_child0_child0_child1_child0_child1, YGEdgeTop, 21); - YGNodeStyleSetPadding( - root_child0_child0_child1_child0_child1, YGEdgeRight, 36); - YGNodeStyleSetPadding( - root_child0_child0_child1_child0_child1, YGEdgeBottom, 18); - YGNodeInsertChild( - root_child0_child0_child1_child0, - root_child0_child0_child1_child0_child1, - 1); - - const YGNodeRef root_child0_child0_child1_child0_child1_child0 = - YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection( - root_child0_child0_child1_child0_child1_child0, YGFlexDirectionRow); - YGNodeStyleSetAlignContent( - root_child0_child0_child1_child0_child1_child0, YGAlignStretch); - YGNodeStyleSetFlexShrink(root_child0_child0_child1_child0_child1_child0, 1); - YGNodeInsertChild( - root_child0_child0_child1_child0_child1, - root_child0_child0_child1_child0_child1_child0, - 0); - - const YGNodeRef root_child0_child0_child1_child0_child1_child1 = - YGNodeNewWithConfig(config); - YGNodeStyleSetAlignContent( - root_child0_child0_child1_child0_child1_child1, YGAlignStretch); - YGNodeStyleSetFlexShrink(root_child0_child0_child1_child0_child1_child1, 1); - YGNodeInsertChild( - root_child0_child0_child1_child0_child1, - root_child0_child0_child1_child0_child1_child1, - 1); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(1080, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(240, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(1080, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(240, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(1080, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(240, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(1080, YGNodeLayoutGetWidth(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(144, YGNodeLayoutGetHeight(root_child0_child0_child0)); - - ASSERT_FLOAT_EQ(36, YGNodeLayoutGetLeft(root_child0_child0_child0_child0)); - ASSERT_FLOAT_EQ(24, YGNodeLayoutGetTop(root_child0_child0_child0_child0)); - ASSERT_FLOAT_EQ(1044, YGNodeLayoutGetWidth(root_child0_child0_child0_child0)); - ASSERT_FLOAT_EQ(120, YGNodeLayoutGetHeight(root_child0_child0_child0_child0)); - - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetLeft(root_child0_child0_child0_child0_child0)); - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetTop(root_child0_child0_child0_child0_child0)); - ASSERT_FLOAT_EQ( - 120, YGNodeLayoutGetWidth(root_child0_child0_child0_child0_child0)); - ASSERT_FLOAT_EQ( - 120, YGNodeLayoutGetHeight(root_child0_child0_child0_child0_child0)); - - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetLeft(root_child0_child0_child0_child0_child0_child0)); - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetTop(root_child0_child0_child0_child0_child0_child0)); - ASSERT_FLOAT_EQ( - 120, - YGNodeLayoutGetWidth(root_child0_child0_child0_child0_child0_child0)); - ASSERT_FLOAT_EQ( - 120, - YGNodeLayoutGetHeight(root_child0_child0_child0_child0_child0_child0)); - - ASSERT_FLOAT_EQ( - 120, YGNodeLayoutGetLeft(root_child0_child0_child0_child0_child1)); - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetTop(root_child0_child0_child0_child0_child1)); - ASSERT_FLOAT_EQ( - 72, YGNodeLayoutGetWidth(root_child0_child0_child0_child0_child1)); - ASSERT_FLOAT_EQ( - 39, YGNodeLayoutGetHeight(root_child0_child0_child0_child0_child1)); - - ASSERT_FLOAT_EQ( - 36, YGNodeLayoutGetLeft(root_child0_child0_child0_child0_child1_child0)); - ASSERT_FLOAT_EQ( - 21, YGNodeLayoutGetTop(root_child0_child0_child0_child0_child1_child0)); - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetWidth(root_child0_child0_child0_child0_child1_child0)); - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetHeight(root_child0_child0_child0_child0_child1_child0)); - - ASSERT_FLOAT_EQ( - 36, YGNodeLayoutGetLeft(root_child0_child0_child0_child0_child1_child1)); - ASSERT_FLOAT_EQ( - 21, YGNodeLayoutGetTop(root_child0_child0_child0_child0_child1_child1)); - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetWidth(root_child0_child0_child0_child0_child1_child1)); - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetHeight(root_child0_child0_child0_child0_child1_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child1)); - ASSERT_FLOAT_EQ(144, YGNodeLayoutGetTop(root_child0_child0_child1)); - ASSERT_FLOAT_EQ(1080, YGNodeLayoutGetWidth(root_child0_child0_child1)); - ASSERT_FLOAT_EQ(96, YGNodeLayoutGetHeight(root_child0_child0_child1)); - - ASSERT_FLOAT_EQ(174, YGNodeLayoutGetLeft(root_child0_child0_child1_child0)); - ASSERT_FLOAT_EQ(24, YGNodeLayoutGetTop(root_child0_child0_child1_child0)); - ASSERT_FLOAT_EQ(906, YGNodeLayoutGetWidth(root_child0_child0_child1_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0_child0_child1_child0)); - - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetLeft(root_child0_child0_child1_child0_child0)); - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetTop(root_child0_child0_child1_child0_child0)); - ASSERT_FLOAT_EQ( - 72, YGNodeLayoutGetWidth(root_child0_child0_child1_child0_child0)); - ASSERT_FLOAT_EQ( - 72, YGNodeLayoutGetHeight(root_child0_child0_child1_child0_child0)); - - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetLeft(root_child0_child0_child1_child0_child0_child0)); - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetTop(root_child0_child0_child1_child0_child0_child0)); - ASSERT_FLOAT_EQ( - 72, YGNodeLayoutGetWidth(root_child0_child0_child1_child0_child0_child0)); - ASSERT_FLOAT_EQ( - 72, - YGNodeLayoutGetHeight(root_child0_child0_child1_child0_child0_child0)); - - ASSERT_FLOAT_EQ( - 72, YGNodeLayoutGetLeft(root_child0_child0_child1_child0_child1)); - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetTop(root_child0_child0_child1_child0_child1)); - ASSERT_FLOAT_EQ( - 72, YGNodeLayoutGetWidth(root_child0_child0_child1_child0_child1)); - ASSERT_FLOAT_EQ( - 39, YGNodeLayoutGetHeight(root_child0_child0_child1_child0_child1)); - - ASSERT_FLOAT_EQ( - 36, YGNodeLayoutGetLeft(root_child0_child0_child1_child0_child1_child0)); - ASSERT_FLOAT_EQ( - 21, YGNodeLayoutGetTop(root_child0_child0_child1_child0_child1_child0)); - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetWidth(root_child0_child0_child1_child0_child1_child0)); - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetHeight(root_child0_child0_child1_child0_child1_child0)); - - ASSERT_FLOAT_EQ( - 36, YGNodeLayoutGetLeft(root_child0_child0_child1_child0_child1_child1)); - ASSERT_FLOAT_EQ( - 21, YGNodeLayoutGetTop(root_child0_child0_child1_child0_child1_child1)); - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetWidth(root_child0_child0_child1_child0_child1_child1)); - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetHeight(root_child0_child0_child1_child0_child1_child1)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(1080, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(240, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(1080, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(240, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(1080, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(240, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(1080, YGNodeLayoutGetWidth(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(144, YGNodeLayoutGetHeight(root_child0_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0_child0)); - ASSERT_FLOAT_EQ(24, YGNodeLayoutGetTop(root_child0_child0_child0_child0)); - ASSERT_FLOAT_EQ(1044, YGNodeLayoutGetWidth(root_child0_child0_child0_child0)); - ASSERT_FLOAT_EQ(120, YGNodeLayoutGetHeight(root_child0_child0_child0_child0)); - - ASSERT_FLOAT_EQ( - 924, YGNodeLayoutGetLeft(root_child0_child0_child0_child0_child0)); - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetTop(root_child0_child0_child0_child0_child0)); - ASSERT_FLOAT_EQ( - 120, YGNodeLayoutGetWidth(root_child0_child0_child0_child0_child0)); - ASSERT_FLOAT_EQ( - 120, YGNodeLayoutGetHeight(root_child0_child0_child0_child0_child0)); - - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetLeft(root_child0_child0_child0_child0_child0_child0)); - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetTop(root_child0_child0_child0_child0_child0_child0)); - ASSERT_FLOAT_EQ( - 120, - YGNodeLayoutGetWidth(root_child0_child0_child0_child0_child0_child0)); - ASSERT_FLOAT_EQ( - 120, - YGNodeLayoutGetHeight(root_child0_child0_child0_child0_child0_child0)); - - ASSERT_FLOAT_EQ( - 816, YGNodeLayoutGetLeft(root_child0_child0_child0_child0_child1)); - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetTop(root_child0_child0_child0_child0_child1)); - ASSERT_FLOAT_EQ( - 72, YGNodeLayoutGetWidth(root_child0_child0_child0_child0_child1)); - ASSERT_FLOAT_EQ( - 39, YGNodeLayoutGetHeight(root_child0_child0_child0_child0_child1)); - - ASSERT_FLOAT_EQ( - 36, YGNodeLayoutGetLeft(root_child0_child0_child0_child0_child1_child0)); - ASSERT_FLOAT_EQ( - 21, YGNodeLayoutGetTop(root_child0_child0_child0_child0_child1_child0)); - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetWidth(root_child0_child0_child0_child0_child1_child0)); - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetHeight(root_child0_child0_child0_child0_child1_child0)); - - ASSERT_FLOAT_EQ( - 36, YGNodeLayoutGetLeft(root_child0_child0_child0_child0_child1_child1)); - ASSERT_FLOAT_EQ( - 21, YGNodeLayoutGetTop(root_child0_child0_child0_child0_child1_child1)); - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetWidth(root_child0_child0_child0_child0_child1_child1)); - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetHeight(root_child0_child0_child0_child0_child1_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child1)); - ASSERT_FLOAT_EQ(144, YGNodeLayoutGetTop(root_child0_child0_child1)); - ASSERT_FLOAT_EQ(1080, YGNodeLayoutGetWidth(root_child0_child0_child1)); - ASSERT_FLOAT_EQ(96, YGNodeLayoutGetHeight(root_child0_child0_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child1_child0)); - ASSERT_FLOAT_EQ(24, YGNodeLayoutGetTop(root_child0_child0_child1_child0)); - ASSERT_FLOAT_EQ(906, YGNodeLayoutGetWidth(root_child0_child0_child1_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0_child0_child1_child0)); - - ASSERT_FLOAT_EQ( - 834, YGNodeLayoutGetLeft(root_child0_child0_child1_child0_child0)); - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetTop(root_child0_child0_child1_child0_child0)); - ASSERT_FLOAT_EQ( - 72, YGNodeLayoutGetWidth(root_child0_child0_child1_child0_child0)); - ASSERT_FLOAT_EQ( - 72, YGNodeLayoutGetHeight(root_child0_child0_child1_child0_child0)); - - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetLeft(root_child0_child0_child1_child0_child0_child0)); - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetTop(root_child0_child0_child1_child0_child0_child0)); - ASSERT_FLOAT_EQ( - 72, YGNodeLayoutGetWidth(root_child0_child0_child1_child0_child0_child0)); - ASSERT_FLOAT_EQ( - 72, - YGNodeLayoutGetHeight(root_child0_child0_child1_child0_child0_child0)); - - ASSERT_FLOAT_EQ( - 726, YGNodeLayoutGetLeft(root_child0_child0_child1_child0_child1)); - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetTop(root_child0_child0_child1_child0_child1)); - ASSERT_FLOAT_EQ( - 72, YGNodeLayoutGetWidth(root_child0_child0_child1_child0_child1)); - ASSERT_FLOAT_EQ( - 39, YGNodeLayoutGetHeight(root_child0_child0_child1_child0_child1)); - - ASSERT_FLOAT_EQ( - 36, YGNodeLayoutGetLeft(root_child0_child0_child1_child0_child1_child0)); - ASSERT_FLOAT_EQ( - 21, YGNodeLayoutGetTop(root_child0_child0_child1_child0_child1_child0)); - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetWidth(root_child0_child0_child1_child0_child1_child0)); - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetHeight(root_child0_child0_child1_child0_child1_child0)); - - ASSERT_FLOAT_EQ( - 36, YGNodeLayoutGetLeft(root_child0_child0_child1_child0_child1_child1)); - ASSERT_FLOAT_EQ( - 21, YGNodeLayoutGetTop(root_child0_child0_child1_child0_child1_child1)); - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetWidth(root_child0_child0_child1_child0_child1_child1)); - ASSERT_FLOAT_EQ( - 0, YGNodeLayoutGetHeight(root_child0_child0_child1_child0_child1_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} diff --git a/core-tests/YGAspectRatioTest.cpp b/core-tests/YGAspectRatioTest.cpp deleted file mode 100644 index ec84aa92..00000000 --- a/core-tests/YGAspectRatioTest.cpp +++ /dev/null @@ -1,898 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include -#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_row) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetWidth(root_child0, 100); - 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(100, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, aspect_ratio_both_dimensions_defined_column) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetWidth(root_child0, 100); - 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_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_flex_shrink_2) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetHeightPercent(root_child0, 100); - YGNodeStyleSetFlexShrink(root_child0, 1); - YGNodeStyleSetAspectRatio(root_child0, 1); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNew(); - YGNodeStyleSetHeightPercent(root_child1, 100); - YGNodeStyleSetFlexShrink(root_child1, 1); - YGNodeStyleSetAspectRatio(root_child1, 1); - YGNodeInsertChild(root, root_child1, 1); - - 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)); - - ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(50, YGNodeLayoutGetTop(root_child1)); - ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - 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(40, 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(40, 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, 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_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, 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_with_measure_func) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNew(); - root_child0->setMeasureFunc(_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); -} - -TEST(YogaTest, aspect_ratio_width_height_flex_grow_row) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetWidth(root_child0, 50); - 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_width_height_flex_grow_column) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetWidth(root_child0, 50); - 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_height_as_flex_basis) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetAspectRatio(root_child0, 1); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNew(); - YGNodeStyleSetHeight(root_child1, 100); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeStyleSetAspectRatio(root_child1, 1); - YGNodeInsertChild(root, root_child1, 1); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_EQ(75, YGNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(75, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(75, YGNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_EQ(125, YGNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(125, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, aspect_ratio_width_as_flex_basis) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetAspectRatio(root_child0, 1); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNew(); - YGNodeStyleSetWidth(root_child1, 100); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeStyleSetAspectRatio(root_child1, 1); - YGNodeInsertChild(root, root_child1, 1); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_EQ(75, YGNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(75, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_EQ(75, YGNodeLayoutGetTop(root_child1)); - ASSERT_EQ(125, YGNodeLayoutGetWidth(root_child1)); - ASSERT_EQ(125, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, aspect_ratio_overrides_flex_grow_row) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetFlexGrow(root_child0, 1); - 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(200, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, aspect_ratio_overrides_flex_grow_column) { - 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, 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(200, YGNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(100, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, aspect_ratio_left_right_absolute) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); - YGNodeStyleSetPosition(root_child0, YGEdgeLeft, 10); - YGNodeStyleSetPosition(root_child0, YGEdgeTop, 10); - YGNodeStyleSetPosition(root_child0, YGEdgeRight, 10); - YGNodeStyleSetAspectRatio(root_child0, 1); - YGNodeInsertChild(root, root_child0, 0); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_EQ(10, YGNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, YGNodeLayoutGetTop(root_child0)); - ASSERT_EQ(80, YGNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(80, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, aspect_ratio_top_bottom_absolute) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); - YGNodeStyleSetPosition(root_child0, YGEdgeLeft, 10); - YGNodeStyleSetPosition(root_child0, YGEdgeTop, 10); - YGNodeStyleSetPosition(root_child0, YGEdgeBottom, 10); - YGNodeStyleSetAspectRatio(root_child0, 1); - YGNodeInsertChild(root, root_child0, 0); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_EQ(10, YGNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(10, YGNodeLayoutGetTop(root_child0)); - ASSERT_EQ(80, YGNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(80, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, aspect_ratio_width_overrides_align_stretch_row) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - 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_height_overrides_align_stretch_column) { - 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(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, aspect_ratio_allow_child_overflow_parent_size) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 100); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeStyleSetAspectRatio(root_child0, 4); - YGNodeInsertChild(root, root_child0, 0); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_EQ(100, YGNodeLayoutGetWidth(root)); - ASSERT_EQ(50, YGNodeLayoutGetHeight(root)); - - ASSERT_EQ(200, YGNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, aspect_ratio_defined_main_with_margin) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeStyleSetAspectRatio(root_child0, 1); - YGNodeStyleSetMargin(root_child0, YGEdgeLeft, 10); - YGNodeStyleSetMargin(root_child0, YGEdgeRight, 10); - YGNodeInsertChild(root, root_child0, 0); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_EQ(100, YGNodeLayoutGetWidth(root)); - ASSERT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, aspect_ratio_defined_cross_with_margin) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetAspectRatio(root_child0, 1); - YGNodeStyleSetMargin(root_child0, YGEdgeLeft, 10); - YGNodeStyleSetMargin(root_child0, YGEdgeRight, 10); - YGNodeInsertChild(root, root_child0, 0); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_EQ(100, YGNodeLayoutGetWidth(root)); - ASSERT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, aspect_ratio_defined_cross_with_main_margin) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetAspectRatio(root_child0, 1); - YGNodeStyleSetMargin(root_child0, YGEdgeTop, 10); - YGNodeStyleSetMargin(root_child0, YGEdgeBottom, 10); - YGNodeInsertChild(root, root_child0, 0); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_EQ(100, YGNodeLayoutGetWidth(root)); - ASSERT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, aspect_ratio_should_prefer_explicit_height) { - const YGConfigRef config = YGConfigNew(); - YGConfigSetUseWebDefaults(config, true); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionColumn); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root_child0_child0, YGFlexDirectionColumn); - YGNodeStyleSetHeight(root_child0_child0, 100); - YGNodeStyleSetAspectRatio(root_child0_child0, 2); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - YGNodeCalculateLayout(root, 100, 200, YGDirectionLTR); - - ASSERT_EQ(100, YGNodeLayoutGetWidth(root)); - ASSERT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_EQ(100, YGNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(100, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(200, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_EQ(100, YGNodeLayoutGetHeight(root_child0_child0)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, aspect_ratio_should_prefer_explicit_width) { - const YGConfigRef config = YGConfigNew(); - YGConfigSetUseWebDefaults(config, true); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root_child0_child0, YGFlexDirectionRow); - YGNodeStyleSetWidth(root_child0_child0, 100); - YGNodeStyleSetAspectRatio(root_child0_child0, 0.5); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - YGNodeCalculateLayout(root, 200, 100, YGDirectionLTR); - - ASSERT_EQ(200, YGNodeLayoutGetWidth(root)); - ASSERT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_EQ(100, YGNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(100, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(100, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_EQ(200, YGNodeLayoutGetHeight(root_child0_child0)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, aspect_ratio_should_prefer_flexed_dimension) { - const YGConfigRef config = YGConfigNew(); - YGConfigSetUseWebDefaults(config, true); - - const YGNodeRef root = YGNodeNewWithConfig(config); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionColumn); - YGNodeStyleSetAspectRatio(root_child0, 2); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetAspectRatio(root_child0_child0, 4); - YGNodeStyleSetFlexGrow(root_child0_child0, 1); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR); - - ASSERT_EQ(100, YGNodeLayoutGetWidth(root)); - ASSERT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_EQ(100, YGNodeLayoutGetWidth(root_child0)); - ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_EQ(200, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0_child0)); - - YGNodeFreeRecursive(root); -} diff --git a/core-tests/YGBaselineFuncTest.cpp b/core-tests/YGBaselineFuncTest.cpp deleted file mode 100644 index c8d1ff1a..00000000 --- a/core-tests/YGBaselineFuncTest.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include -#include -#include - -static float _baseline(YGNodeRef node, const float width, const float height) { - float* baseline = (float*)node->getContext(); - return *baseline; -} - -TEST(YogaTest, align_baseline_customer_func) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignItems(root, YGAlignBaseline); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - 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, 20); - YGNodeInsertChild(root, root_child1, 1); - - float baselineValue = 10; - const YGNodeRef root_child1_child0 = YGNodeNew(); - root_child1_child0->setContext(&baselineValue); - YGNodeStyleSetWidth(root_child1_child0, 50); - root_child1_child0->setBaseLineFunc(_baseline); - YGNodeStyleSetHeight(root_child1_child0, 20); - YGNodeInsertChild(root_child1, root_child1_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(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1_child0)); -} diff --git a/core-tests/YGBorderTest.cpp b/core-tests/YGBorderTest.cpp deleted file mode 100644 index d4e63764..00000000 --- a/core-tests/YGBorderTest.cpp +++ /dev/null @@ -1,212 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @Generated by gentest/gentest.rb from gentest/fixtures/YGBorderTest.html - -#include -#include - -TEST(YogaTest, border_no_size) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, border_container_match_child) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetBorder(root, YGEdgeLeft, 10); - YGNodeStyleSetBorder(root, YGEdgeTop, 10); - YGNodeStyleSetBorder(root, YGEdgeRight, 10); - YGNodeStyleSetBorder(root, YGEdgeBottom, 10); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, border_flex_child) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - 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 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, border_stretch_child) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - 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 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, border_center_child) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - 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 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} diff --git a/core-tests/YGComputedMarginTest.cpp b/core-tests/YGComputedMarginTest.cpp deleted file mode 100644 index 9cbbe4e0..00000000 --- a/core-tests/YGComputedMarginTest.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include -#include - -TEST(YogaTest, computed_layout_margin) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - YGNodeStyleSetMarginPercent(root, YGEdgeStart, 10); - - YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR); - - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetMargin(root, YGEdgeLeft)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetMargin(root, YGEdgeRight)); - - YGNodeCalculateLayout(root, 100, 100, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetMargin(root, YGEdgeLeft)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetMargin(root, YGEdgeRight)); - - YGNodeFreeRecursive(root); -} diff --git a/core-tests/YGComputedPaddingTest.cpp b/core-tests/YGComputedPaddingTest.cpp deleted file mode 100644 index bf31fe7b..00000000 --- a/core-tests/YGComputedPaddingTest.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include -#include - -TEST(YogaTest, computed_layout_padding) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - YGNodeStyleSetPaddingPercent(root, YGEdgeStart, 10); - - YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR); - - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetPadding(root, YGEdgeLeft)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetPadding(root, YGEdgeRight)); - - YGNodeCalculateLayout(root, 100, 100, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetPadding(root, YGEdgeLeft)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetPadding(root, YGEdgeRight)); - - YGNodeFreeRecursive(root); -} diff --git a/core-tests/YGDefaultValuesTest.cpp b/core-tests/YGDefaultValuesTest.cpp deleted file mode 100644 index ca143866..00000000 --- a/core-tests/YGDefaultValuesTest.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include -#include - -TEST(YogaTest, assert_default_values) { - const YGNodeRef root = YGNodeNew(); - - ASSERT_EQ(0, YGNodeGetChildCount(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_EQ(YGNodeStyleGetFlexBasis(root).unit, YGUnitAuto); - - ASSERT_EQ(YGNodeStyleGetPosition(root, YGEdgeLeft).unit, YGUnitUndefined); - ASSERT_EQ(YGNodeStyleGetPosition(root, YGEdgeTop).unit, YGUnitUndefined); - ASSERT_EQ(YGNodeStyleGetPosition(root, YGEdgeRight).unit, YGUnitUndefined); - ASSERT_EQ(YGNodeStyleGetPosition(root, YGEdgeBottom).unit, YGUnitUndefined); - ASSERT_EQ(YGNodeStyleGetPosition(root, YGEdgeStart).unit, YGUnitUndefined); - ASSERT_EQ(YGNodeStyleGetPosition(root, YGEdgeEnd).unit, YGUnitUndefined); - - ASSERT_EQ(YGNodeStyleGetMargin(root, YGEdgeLeft).unit, YGUnitUndefined); - ASSERT_EQ(YGNodeStyleGetMargin(root, YGEdgeTop).unit, YGUnitUndefined); - ASSERT_EQ(YGNodeStyleGetMargin(root, YGEdgeRight).unit, YGUnitUndefined); - ASSERT_EQ(YGNodeStyleGetMargin(root, YGEdgeBottom).unit, YGUnitUndefined); - ASSERT_EQ(YGNodeStyleGetMargin(root, YGEdgeStart).unit, YGUnitUndefined); - ASSERT_EQ(YGNodeStyleGetMargin(root, YGEdgeEnd).unit, YGUnitUndefined); - - ASSERT_EQ(YGNodeStyleGetPadding(root, YGEdgeLeft).unit, YGUnitUndefined); - ASSERT_EQ(YGNodeStyleGetPadding(root, YGEdgeTop).unit, YGUnitUndefined); - ASSERT_EQ(YGNodeStyleGetPadding(root, YGEdgeRight).unit, YGUnitUndefined); - ASSERT_EQ(YGNodeStyleGetPadding(root, YGEdgeBottom).unit, YGUnitUndefined); - ASSERT_EQ(YGNodeStyleGetPadding(root, YGEdgeStart).unit, YGUnitUndefined); - ASSERT_EQ(YGNodeStyleGetPadding(root, YGEdgeEnd).unit, YGUnitUndefined); - - ASSERT_TRUE(YGFloatIsUndefined(YGNodeStyleGetBorder(root, YGEdgeLeft))); - ASSERT_TRUE(YGFloatIsUndefined(YGNodeStyleGetBorder(root, YGEdgeTop))); - ASSERT_TRUE(YGFloatIsUndefined(YGNodeStyleGetBorder(root, YGEdgeRight))); - ASSERT_TRUE(YGFloatIsUndefined(YGNodeStyleGetBorder(root, YGEdgeBottom))); - ASSERT_TRUE(YGFloatIsUndefined(YGNodeStyleGetBorder(root, YGEdgeStart))); - ASSERT_TRUE(YGFloatIsUndefined(YGNodeStyleGetBorder(root, YGEdgeEnd))); - - ASSERT_EQ(YGNodeStyleGetWidth(root).unit, YGUnitAuto); - ASSERT_EQ(YGNodeStyleGetHeight(root).unit, YGUnitAuto); - ASSERT_EQ(YGNodeStyleGetMinWidth(root).unit, YGUnitUndefined); - ASSERT_EQ(YGNodeStyleGetMinHeight(root).unit, YGUnitUndefined); - ASSERT_EQ(YGNodeStyleGetMaxWidth(root).unit, YGUnitUndefined); - ASSERT_EQ(YGNodeStyleGetMaxHeight(root).unit, YGUnitUndefined); - - 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_FLOAT_EQ(0, YGNodeLayoutGetMargin(root, YGEdgeLeft)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetMargin(root, YGEdgeTop)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetMargin(root, YGEdgeRight)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetMargin(root, YGEdgeBottom)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetPadding(root, YGEdgeLeft)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetPadding(root, YGEdgeTop)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetPadding(root, YGEdgeRight)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetPadding(root, YGEdgeBottom)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetBorder(root, YGEdgeLeft)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetBorder(root, YGEdgeTop)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetBorder(root, YGEdgeRight)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetBorder(root, YGEdgeBottom)); - - ASSERT_TRUE(YGFloatIsUndefined(YGNodeLayoutGetWidth(root))); - ASSERT_TRUE(YGFloatIsUndefined(YGNodeLayoutGetHeight(root))); - ASSERT_EQ(YGDirectionInherit, YGNodeLayoutGetDirection(root)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, assert_webdefault_values) { - YGConfig *config = YGConfigNew(); - YGConfigSetUseWebDefaults(config, true); - const YGNodeRef root = YGNodeNewWithConfig(config); - - ASSERT_EQ(YGFlexDirectionRow, YGNodeStyleGetFlexDirection(root)); - ASSERT_EQ(YGAlignStretch, YGNodeStyleGetAlignContent(root)); - ASSERT_FLOAT_EQ(1.0f, YGNodeStyleGetFlexShrink(root)); - - YGNodeFreeRecursive(root); - YGConfigFree(config); -} - -TEST(YogaTest, assert_webdefault_values_reset) { - YGConfig *config = YGConfigNew(); - YGConfigSetUseWebDefaults(config, true); - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeReset(root); - - ASSERT_EQ(YGFlexDirectionRow, YGNodeStyleGetFlexDirection(root)); - ASSERT_EQ(YGAlignStretch, YGNodeStyleGetAlignContent(root)); - ASSERT_FLOAT_EQ(1.0f, YGNodeStyleGetFlexShrink(root)); - - YGNodeFreeRecursive(root); - YGConfigFree(config); -} - -TEST(YogaTest, assert_legacy_stretch_behaviour) { - YGConfig *config = YGConfigNew(); - YGConfigSetUseLegacyStretchBehaviour(config, true); - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 500); - YGNodeStyleSetHeight(root, 500); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root_child0, YGAlignFlexStart); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0_child0, 1); - YGNodeStyleSetFlexShrink(root_child0_child0, 1); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - const YGNodeRef root_child0_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0_child0_child0, 1); - YGNodeStyleSetFlexShrink(root_child0_child0_child0, 1); - YGNodeInsertChild(root_child0_child0, root_child0_child0_child0, 0); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root_child0_child0_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} diff --git a/core-tests/YGDimensionTest.cpp b/core-tests/YGDimensionTest.cpp deleted file mode 100644 index 42fc123a..00000000 --- a/core-tests/YGDimensionTest.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @Generated by gentest/gentest.rb from gentest/fixtures/YGDimensionTest.html - -#include -#include - -TEST(YogaTest, wrap_child) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - 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(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(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(100, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, wrap_grandchild) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - 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(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(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(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(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); - - YGConfigFree(config); -} diff --git a/core-tests/YGDirtiedTest.cpp b/core-tests/YGDirtiedTest.cpp deleted file mode 100644 index bb0c05d0..00000000 --- a/core-tests/YGDirtiedTest.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include -#include - -static void _dirtied(YGNodeRef node) { - int* dirtiedCount = (int*)node->getContext(); - (*dirtiedCount)++; -} - -TEST(YogaTest, dirtied) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - int dirtiedCount = 0; - root->setContext(&dirtiedCount); - root->setDirtiedFunc(_dirtied); - - ASSERT_EQ(0, dirtiedCount); - - // `_dirtied` MUST be called in case of explicit dirtying. - root->setDirty(true); - ASSERT_EQ(1, dirtiedCount); - - // `_dirtied` MUST be called ONCE. - root->setDirty(true); - ASSERT_EQ(1, dirtiedCount); -} - -TEST(YogaTest, dirtied_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); - - int dirtiedCount = 0; - root->setContext(&dirtiedCount); - root->setDirtiedFunc(_dirtied); - - ASSERT_EQ(0, dirtiedCount); - - // `_dirtied` MUST be called for the first time. - root_child0->markDirtyAndPropogate(); - ASSERT_EQ(1, dirtiedCount); - - // `_dirtied` must NOT be called for the second time. - root_child0->markDirtyAndPropogate(); - ASSERT_EQ(1, dirtiedCount); -} - -TEST(YogaTest, dirtied_hierarchy) { - 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); - - int dirtiedCount = 0; - root_child0->setContext(&dirtiedCount); - root_child0->setDirtiedFunc(_dirtied); - - ASSERT_EQ(0, dirtiedCount); - - // `_dirtied` must NOT be called for descendants. - root->markDirtyAndPropogate(); - ASSERT_EQ(0, dirtiedCount); - - // `_dirtied` must NOT be called for the sibling node. - root_child1->markDirtyAndPropogate(); - ASSERT_EQ(0, dirtiedCount); - - // `_dirtied` MUST be called in case of explicit dirtying. - root_child0->markDirtyAndPropogate(); - ASSERT_EQ(1, dirtiedCount); -} diff --git a/core-tests/YGDirtyMarkingTest.cpp b/core-tests/YGDirtyMarkingTest.cpp deleted file mode 100644 index d951f53e..00000000 --- a/core-tests/YGDirtyMarkingTest.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#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(root_child0->isDirty()); - EXPECT_FALSE(root_child1->isDirty()); - EXPECT_TRUE(root->isDirty()); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - EXPECT_FALSE(root_child0->isDirty()); - EXPECT_FALSE(root_child1->isDirty()); - EXPECT_FALSE(root->isDirty()); - - 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(root_child0->isDirty()); - EXPECT_FALSE(root_child1->isDirty()); - EXPECT_FALSE(root->isDirty()); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, dirty_mark_all_children_as_dirty_when_display_changes) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef child0 = YGNodeNew(); - YGNodeStyleSetFlexGrow(child0, 1); - const YGNodeRef child1 = YGNodeNew(); - YGNodeStyleSetFlexGrow(child1, 1); - - const YGNodeRef child1_child0 = YGNodeNew(); - const YGNodeRef child1_child0_child0 = YGNodeNew(); - YGNodeStyleSetWidth(child1_child0_child0, 8); - YGNodeStyleSetHeight(child1_child0_child0, 16); - - YGNodeInsertChild(child1_child0, child1_child0_child0, 0); - - YGNodeInsertChild(child1, child1_child0, 0); - YGNodeInsertChild(root, child0, 0); - YGNodeInsertChild(root, child1, 0); - - YGNodeStyleSetDisplay(child0, YGDisplayFlex); - YGNodeStyleSetDisplay(child1, YGDisplayNone); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(child1_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(child1_child0_child0)); - - YGNodeStyleSetDisplay(child0, YGDisplayNone); - YGNodeStyleSetDisplay(child1, YGDisplayFlex); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - ASSERT_FLOAT_EQ(8, YGNodeLayoutGetWidth(child1_child0_child0)); - ASSERT_FLOAT_EQ(16, YGNodeLayoutGetHeight(child1_child0_child0)); - - YGNodeStyleSetDisplay(child0, YGDisplayFlex); - YGNodeStyleSetDisplay(child1, YGDisplayNone); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(child1_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(child1_child0_child0)); - - YGNodeStyleSetDisplay(child0, YGDisplayNone); - YGNodeStyleSetDisplay(child1, YGDisplayFlex); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - ASSERT_FLOAT_EQ(8, YGNodeLayoutGetWidth(child1_child0_child0)); - ASSERT_FLOAT_EQ(16, YGNodeLayoutGetHeight(child1_child0_child0)); - - 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(root->isDirty()); - YGNodeFree(child1); - - YGNodeRemoveChild(root, child0); - EXPECT_TRUE(root->isDirty()); - YGNodeFree(child0); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, dirty_node_only_if_undefined_values_gets_set_to_undefined) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetWidth(root, 50); - YGNodeStyleSetHeight(root, 50); - YGNodeStyleSetMinWidth(root, YGUndefined); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - EXPECT_FALSE(root->isDirty()); - - YGNodeStyleSetMinWidth(root, YGUndefined); - - EXPECT_FALSE(root->isDirty()); - - YGNodeFreeRecursive(root); -} diff --git a/core-tests/YGDisplayTest.cpp b/core-tests/YGDisplayTest.cpp deleted file mode 100644 index 45256ac9..00000000 --- a/core-tests/YGDisplayTest.cpp +++ /dev/null @@ -1,332 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @Generated by gentest/gentest.rb from gentest/fixtures/YGDisplayTest.html - -#include -#include - -TEST(YogaTest, display_none) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeStyleSetDisplay(root_child1, YGDisplayNone); - 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(100, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(0, 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(100, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, display_none_fixed_size) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 20); - YGNodeStyleSetHeight(root_child1, 20); - YGNodeStyleSetDisplay(root_child1, YGDisplayNone); - 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(100, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(0, 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(100, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, display_none_with_margin) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMargin(root_child0, YGEdgeLeft, 10); - YGNodeStyleSetMargin(root_child0, YGEdgeTop, 10); - YGNodeStyleSetMargin(root_child0, YGEdgeRight, 10); - YGNodeStyleSetMargin(root_child0, YGEdgeBottom, 10); - YGNodeStyleSetWidth(root_child0, 20); - YGNodeStyleSetHeight(root_child0, 20); - YGNodeStyleSetDisplay(root_child0, YGDisplayNone); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - 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(0, 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(100, 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(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(0, 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(100, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, display_none_with_child) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexShrink(root_child0, 1); - YGNodeStyleSetFlexBasisPercent(root_child0, 0); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeStyleSetFlexShrink(root_child1, 1); - YGNodeStyleSetFlexBasisPercent(root_child1, 0); - YGNodeStyleSetDisplay(root_child1, YGDisplayNone); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child1_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1_child0, 1); - YGNodeStyleSetFlexShrink(root_child1_child0, 1); - YGNodeStyleSetFlexBasisPercent(root_child1_child0, 0); - YGNodeStyleSetWidth(root_child1_child0, 20); - YGNodeStyleSetMinWidth(root_child1_child0, 0); - YGNodeStyleSetMinHeight(root_child1_child0, 0); - YGNodeInsertChild(root_child1, root_child1_child0, 0); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child2, 1); - YGNodeStyleSetFlexShrink(root_child2, 1); - YGNodeStyleSetFlexBasisPercent(root_child2, 0); - 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(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(0, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child1_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, 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(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(0, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child1_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child2)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, display_none_with_position) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeStyleSetPosition(root_child1, YGEdgeTop, 10); - YGNodeStyleSetDisplay(root_child1, YGDisplayNone); - 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(100, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(0, 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(100, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} diff --git a/core-tests/YGEdgeTest.cpp b/core-tests/YGEdgeTest.cpp deleted file mode 100644 index 02de1463..00000000 --- a/core-tests/YGEdgeTest.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#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/core-tests/YGFlexDirectionTest.cpp b/core-tests/YGFlexDirectionTest.cpp deleted file mode 100644 index 93e09425..00000000 --- a/core-tests/YGFlexDirectionTest.cpp +++ /dev/null @@ -1,415 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @Generated by gentest/gentest.rb from gentest/fixtures/YGFlexDirectionTest.html - -#include -#include - -TEST(YogaTest, flex_direction_column_no_height) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, flex_direction_row_no_width) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, flex_direction_column) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, flex_direction_row) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, flex_direction_column_reverse) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumnReverse); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, flex_direction_row_reverse) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRowReverse); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} diff --git a/core-tests/YGFlexTest.cpp b/core-tests/YGFlexTest.cpp deleted file mode 100644 index e1a8ba89..00000000 --- a/core-tests/YGFlexTest.cpp +++ /dev/null @@ -1,491 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @Generated by gentest/gentest.rb from gentest/fixtures/YGFlexTest.html - -#include -#include - -TEST(YogaTest, flex_basis_flex_grow_column) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexBasis(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, flex_basis_flex_grow_row) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexBasis(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, flex_basis_flex_shrink_column) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexShrink(root_child0, 1); - YGNodeStyleSetFlexBasis(root_child0, 100); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, flex_basis_flex_shrink_row) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexShrink(root_child0, 1); - YGNodeStyleSetFlexBasis(root_child0, 100); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, flex_shrink_to_zero) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root, 75); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexShrink(root_child1, 1); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(root_child1, 50); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, flex_basis_overrides_main_size) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexBasis(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 20); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeStyleSetHeight(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, flex_grow_shrink_at_most) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, flex_grow_less_than_factor_one) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 500); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 0.2f); - YGNodeStyleSetFlexBasis(root_child0, 40); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 0.2f); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child2, 0.4f); - 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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(500, 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(132, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(132, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(92, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(224, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(184, YGNodeLayoutGetHeight(root_child2)); - - 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(500, 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(132, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(132, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(92, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(224, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(184, YGNodeLayoutGetHeight(root_child2)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} diff --git a/core-tests/YGFlexWrapTest.cpp b/core-tests/YGFlexWrapTest.cpp deleted file mode 100644 index e8e5458c..00000000 --- a/core-tests/YGFlexWrapTest.cpp +++ /dev/null @@ -1,1735 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @Generated by gentest/gentest.rb from gentest/fixtures/YGFlexWrapTest.html - -#include -#include - -TEST(YogaTest, wrap_column) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 30); - YGNodeStyleSetHeight(root_child0, 30); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 30); - YGNodeStyleSetHeight(root_child1, 30); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 30); - YGNodeStyleSetHeight(root_child2, 30); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, wrap_row) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 30); - YGNodeStyleSetHeight(root_child0, 30); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 30); - YGNodeStyleSetHeight(root_child1, 30); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 30); - YGNodeStyleSetHeight(root_child2, 30); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, wrap_row_align_items_flex_end) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignItems(root, YGAlignFlexEnd); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 30); - YGNodeStyleSetHeight(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 30); - YGNodeStyleSetHeight(root_child1, 20); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 30); - YGNodeStyleSetHeight(root_child2, 30); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, wrap_row_align_items_center) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 30); - YGNodeStyleSetHeight(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 30); - YGNodeStyleSetHeight(root_child1, 20); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 30); - YGNodeStyleSetHeight(root_child2, 30); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, flex_wrap_children_with_min_main_overriding_flex_basis) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexBasis(root_child0, 50); - YGNodeStyleSetMinWidth(root_child0, 55); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexBasis(root_child1, 50); - YGNodeStyleSetMinWidth(root_child1, 55); - YGNodeStyleSetHeight(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(55, 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(55, 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(45, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(55, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(45, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(55, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, flex_wrap_wrap_to_child_height) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow); - YGNodeStyleSetAlignItems(root_child0, YGAlignFlexStart); - YGNodeStyleSetFlexWrap(root_child0, YGWrapWrap); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0_child0, 100); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - const YGNodeRef root_child0_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0_child0_child0, 100); - YGNodeStyleSetHeight(root_child0_child0_child0, 100); - YGNodeInsertChild(root_child0_child0, root_child0_child0_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 100); - YGNodeStyleSetHeight(root_child1, 100); - 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(200, 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)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(100, 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(200, 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)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, flex_wrap_align_stretch_fits_one_row) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 150); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(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(150, 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(150, 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(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)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, wrap_reverse_row_align_content_flex_start) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetFlexWrap(root, YGWrapWrapReverse); - YGNodeStyleSetWidth(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 30); - YGNodeStyleSetHeight(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 30); - YGNodeStyleSetHeight(root_child1, 20); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 30); - YGNodeStyleSetHeight(root_child2, 30); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child3, 30); - YGNodeStyleSetHeight(root_child3, 40); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child4, 30); - YGNodeStyleSetHeight(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(80, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(70, 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(60, 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(50, 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(10, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, 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(80, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(70, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(70, 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(60, 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(50, 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(10, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, wrap_reverse_row_align_content_center) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root, YGAlignCenter); - YGNodeStyleSetFlexWrap(root, YGWrapWrapReverse); - YGNodeStyleSetWidth(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 30); - YGNodeStyleSetHeight(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 30); - YGNodeStyleSetHeight(root_child1, 20); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 30); - YGNodeStyleSetHeight(root_child2, 30); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child3, 30); - YGNodeStyleSetHeight(root_child3, 40); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child4, 30); - YGNodeStyleSetHeight(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(80, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(70, 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(60, 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(50, 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(10, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, 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(80, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(70, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(70, 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(60, 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(50, 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(10, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, wrap_reverse_row_single_line_different_size) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetFlexWrap(root, YGWrapWrapReverse); - YGNodeStyleSetWidth(root, 300); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 30); - YGNodeStyleSetHeight(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 30); - YGNodeStyleSetHeight(root_child1, 20); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 30); - YGNodeStyleSetHeight(root_child2, 30); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child3, 30); - YGNodeStyleSetHeight(root_child3, 40); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child4, 30); - YGNodeStyleSetHeight(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(300, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(40, 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(30, 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(20, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(120, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(300, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(270, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(240, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(210, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(180, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, wrap_reverse_row_align_content_stretch) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root, YGAlignStretch); - YGNodeStyleSetFlexWrap(root, YGWrapWrapReverse); - YGNodeStyleSetWidth(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 30); - YGNodeStyleSetHeight(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 30); - YGNodeStyleSetHeight(root_child1, 20); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 30); - YGNodeStyleSetHeight(root_child2, 30); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child3, 30); - YGNodeStyleSetHeight(root_child3, 40); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child4, 30); - YGNodeStyleSetHeight(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(80, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(70, 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(60, 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(50, 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(10, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, 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(80, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(70, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(70, 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(60, 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(50, 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(10, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, wrap_reverse_row_align_content_space_around) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignContent(root, YGAlignSpaceAround); - YGNodeStyleSetFlexWrap(root, YGWrapWrapReverse); - YGNodeStyleSetWidth(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 30); - YGNodeStyleSetHeight(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 30); - YGNodeStyleSetHeight(root_child1, 20); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 30); - YGNodeStyleSetHeight(root_child2, 30); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child3, 30); - YGNodeStyleSetHeight(root_child3, 40); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child4, 30); - YGNodeStyleSetHeight(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(80, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(70, 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(60, 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(50, 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(10, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, 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(80, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(70, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(70, 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(60, 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(50, 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(10, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, wrap_reverse_column_fixed_size) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetFlexWrap(root, YGWrapWrapReverse); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 30); - YGNodeStyleSetHeight(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 30); - YGNodeStyleSetHeight(root_child1, 20); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 30); - YGNodeStyleSetHeight(root_child2, 30); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child3, 30); - YGNodeStyleSetHeight(root_child3, 40); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child4, 30); - YGNodeStyleSetHeight(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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(170, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(170, 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(170, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root_child2)); - - ASSERT_FLOAT_EQ(170, YGNodeLayoutGetLeft(root_child3)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(140, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); - - 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(30, 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(30, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(30, 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(60, YGNodeLayoutGetTop(root_child3)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child3)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child3)); - - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child4)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child4)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root_child4)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child4)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, wrapped_row_within_align_items_center) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow); - YGNodeStyleSetFlexWrap(root_child0, YGWrapWrap); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0_child0, 150); - YGNodeStyleSetHeight(root_child0_child0, 80); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - const YGNodeRef root_child0_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0_child1, 80); - YGNodeStyleSetHeight(root_child0_child1, 80); - YGNodeInsertChild(root_child0, root_child0_child1, 1); - 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(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(160, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child1)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child0_child1)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetWidth(root_child0_child1)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0_child1)); - - 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(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(160, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(120, YGNodeLayoutGetLeft(root_child0_child1)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child0_child1)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetWidth(root_child0_child1)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, wrapped_row_within_align_items_flex_start) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow); - YGNodeStyleSetFlexWrap(root_child0, YGWrapWrap); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0_child0, 150); - YGNodeStyleSetHeight(root_child0_child0, 80); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - const YGNodeRef root_child0_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0_child1, 80); - YGNodeStyleSetHeight(root_child0_child1, 80); - YGNodeInsertChild(root_child0, root_child0_child1, 1); - 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(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(160, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child1)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child0_child1)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetWidth(root_child0_child1)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0_child1)); - - 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(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(160, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(120, YGNodeLayoutGetLeft(root_child0_child1)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child0_child1)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetWidth(root_child0_child1)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, wrapped_row_within_align_items_flex_end) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root, YGAlignFlexEnd); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow); - YGNodeStyleSetFlexWrap(root_child0, YGWrapWrap); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0_child0, 150); - YGNodeStyleSetHeight(root_child0_child0, 80); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - const YGNodeRef root_child0_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0_child1, 80); - YGNodeStyleSetHeight(root_child0_child1, 80); - YGNodeInsertChild(root_child0, root_child0_child1, 1); - 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(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(160, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child1)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child0_child1)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetWidth(root_child0_child1)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0_child1)); - - 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(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(160, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(120, YGNodeLayoutGetLeft(root_child0_child1)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child0_child1)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetWidth(root_child0_child1)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, wrapped_column_max_height) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetAlignContent(root, YGAlignCenter); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 700); - YGNodeStyleSetHeight(root, 500); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 100); - YGNodeStyleSetHeight(root_child0, 500); - YGNodeStyleSetMaxHeight(root_child0, 200); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetMargin(root_child1, YGEdgeLeft, 20); - YGNodeStyleSetMargin(root_child1, YGEdgeTop, 20); - YGNodeStyleSetMargin(root_child1, YGEdgeRight, 20); - YGNodeStyleSetMargin(root_child1, YGEdgeBottom, 20); - YGNodeStyleSetWidth(root_child1, 200); - YGNodeStyleSetHeight(root_child1, 200); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 100); - YGNodeStyleSetHeight(root_child2, 100); - 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(700, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(250, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(250, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(420, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(100, 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(700, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(350, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(300, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(250, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(180, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child2)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, wrapped_column_max_height_flex) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetAlignContent(root, YGAlignCenter); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetFlexWrap(root, YGWrapWrap); - YGNodeStyleSetWidth(root, 700); - YGNodeStyleSetHeight(root, 500); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexShrink(root_child0, 1); - YGNodeStyleSetFlexBasisPercent(root_child0, 0); - YGNodeStyleSetWidth(root_child0, 100); - YGNodeStyleSetHeight(root_child0, 500); - YGNodeStyleSetMaxHeight(root_child0, 200); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeStyleSetFlexShrink(root_child1, 1); - YGNodeStyleSetFlexBasisPercent(root_child1, 0); - YGNodeStyleSetMargin(root_child1, YGEdgeLeft, 20); - YGNodeStyleSetMargin(root_child1, YGEdgeTop, 20); - YGNodeStyleSetMargin(root_child1, YGEdgeRight, 20); - YGNodeStyleSetMargin(root_child1, YGEdgeBottom, 20); - YGNodeStyleSetWidth(root_child1, 200); - YGNodeStyleSetHeight(root_child1, 200); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 100); - YGNodeStyleSetHeight(root_child2, 100); - 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(700, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(300, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(180, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(250, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(180, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(300, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(400, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(100, 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(700, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(300, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(180, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(250, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(180, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(300, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(400, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child2)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, wrap_nodes_with_content_sizing_overflowing_margin) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 500); - YGNodeStyleSetHeight(root, 500); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow); - YGNodeStyleSetFlexWrap(root_child0, YGWrapWrap); - YGNodeStyleSetWidth(root_child0, 85); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - const YGNodeRef root_child0_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0_child0_child0, 40); - YGNodeStyleSetHeight(root_child0_child0_child0, 40); - YGNodeInsertChild(root_child0_child0, root_child0_child0_child0, 0); - - const YGNodeRef root_child0_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetMargin(root_child0_child1, YGEdgeRight, 10); - YGNodeInsertChild(root_child0, root_child0_child1, 1); - - const YGNodeRef root_child0_child1_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0_child1_child0, 40); - YGNodeStyleSetHeight(root_child0_child1_child0, 40); - YGNodeInsertChild(root_child0_child1, root_child0_child1_child0, 0); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(85, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child0_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child0_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child1_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child0_child1_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0_child1_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(415, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(85, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(45, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0_child0_child0)); - - ASSERT_FLOAT_EQ(35, YGNodeLayoutGetLeft(root_child0_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child0_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child0_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child1_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child0_child1_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0_child1_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, wrap_nodes_with_content_sizing_margin_cross) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 500); - YGNodeStyleSetHeight(root, 500); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow); - YGNodeStyleSetFlexWrap(root_child0, YGWrapWrap); - YGNodeStyleSetWidth(root_child0, 70); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - const YGNodeRef root_child0_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0_child0_child0, 40); - YGNodeStyleSetHeight(root_child0_child0_child0, 40); - YGNodeInsertChild(root_child0_child0, root_child0_child0_child0, 0); - - const YGNodeRef root_child0_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetMargin(root_child0_child1, YGEdgeTop, 10); - YGNodeInsertChild(root_child0, root_child0_child1, 1); - - const YGNodeRef root_child0_child1_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0_child1_child0, 40); - YGNodeStyleSetHeight(root_child0_child1_child0, 40); - YGNodeInsertChild(root_child0_child1, root_child0_child1_child0, 0); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(70, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child0_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child0_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child1_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child0_child1_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0_child1_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(430, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(70, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0_child0_child0)); - - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child0_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child0_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child0_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child1_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child0_child1_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0_child1_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} diff --git a/core-tests/YGHadOverflowTest.cpp b/core-tests/YGHadOverflowTest.cpp deleted file mode 100644 index 47dc2809..00000000 --- a/core-tests/YGHadOverflowTest.cpp +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#include -#include - -using namespace ::testing; - -class YogaTest_HadOverflowTests : public Test { -protected: - YogaTest_HadOverflowTests() { - config = YGConfigNew(); - root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 100); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn); - YGNodeStyleSetFlexWrap(root, YGWrapNoWrap); - } - - ~YogaTest_HadOverflowTests() { - YGNodeFreeRecursive(root); - YGConfigFree(config); - } - - YGNodeRef root; - YGConfigRef config; -}; - -TEST_F(YogaTest_HadOverflowTests, children_overflow_no_wrap_and_no_flex_children) { - const YGNodeRef child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(child0, 80); - YGNodeStyleSetHeight(child0, 40); - YGNodeStyleSetMargin(child0, YGEdgeTop, 10); - YGNodeStyleSetMargin(child0, YGEdgeBottom, 15); - YGNodeInsertChild(root, child0, 0); - const YGNodeRef child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(child1, 80); - YGNodeStyleSetHeight(child1, 40); - YGNodeStyleSetMargin(child1, YGEdgeBottom, 5); - YGNodeInsertChild(root, child1, 1); - - YGNodeCalculateLayout(root, 200, 100, YGDirectionLTR); - - ASSERT_TRUE(YGNodeLayoutGetHadOverflow(root)); -} - -TEST_F(YogaTest_HadOverflowTests, spacing_overflow_no_wrap_and_no_flex_children) { - const YGNodeRef child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(child0, 80); - YGNodeStyleSetHeight(child0, 40); - YGNodeStyleSetMargin(child0, YGEdgeTop, 10); - YGNodeStyleSetMargin(child0, YGEdgeBottom, 10); - YGNodeInsertChild(root, child0, 0); - const YGNodeRef child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(child1, 80); - YGNodeStyleSetHeight(child1, 40); - YGNodeStyleSetMargin(child1, YGEdgeBottom, 5); - YGNodeInsertChild(root, child1, 1); - - YGNodeCalculateLayout(root, 200, 100, YGDirectionLTR); - - ASSERT_TRUE(YGNodeLayoutGetHadOverflow(root)); -} - -TEST_F(YogaTest_HadOverflowTests, no_overflow_no_wrap_and_flex_children) { - const YGNodeRef child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(child0, 80); - YGNodeStyleSetHeight(child0, 40); - YGNodeStyleSetMargin(child0, YGEdgeTop, 10); - YGNodeStyleSetMargin(child0, YGEdgeBottom, 10); - YGNodeInsertChild(root, child0, 0); - const YGNodeRef child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(child1, 80); - YGNodeStyleSetHeight(child1, 40); - YGNodeStyleSetMargin(child1, YGEdgeBottom, 5); - YGNodeStyleSetFlexShrink(child1, 1); - YGNodeInsertChild(root, child1, 1); - - YGNodeCalculateLayout(root, 200, 100, YGDirectionLTR); - - ASSERT_FALSE(YGNodeLayoutGetHadOverflow(root)); -} - -TEST_F(YogaTest_HadOverflowTests, hadOverflow_gets_reset_if_not_logger_valid) { - const YGNodeRef child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(child0, 80); - YGNodeStyleSetHeight(child0, 40); - YGNodeStyleSetMargin(child0, YGEdgeTop, 10); - YGNodeStyleSetMargin(child0, YGEdgeBottom, 10); - YGNodeInsertChild(root, child0, 0); - const YGNodeRef child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(child1, 80); - YGNodeStyleSetHeight(child1, 40); - YGNodeStyleSetMargin(child1, YGEdgeBottom, 5); - YGNodeInsertChild(root, child1, 1); - - YGNodeCalculateLayout(root, 200, 100, YGDirectionLTR); - - ASSERT_TRUE(YGNodeLayoutGetHadOverflow(root)); - - YGNodeStyleSetFlexShrink(child1, 1); - - YGNodeCalculateLayout(root, 200, 100, YGDirectionLTR); - - ASSERT_FALSE(YGNodeLayoutGetHadOverflow(root)); -} - -TEST_F(YogaTest_HadOverflowTests, spacing_overflow_in_nested_nodes) { - const YGNodeRef child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(child0, 80); - YGNodeStyleSetHeight(child0, 40); - YGNodeStyleSetMargin(child0, YGEdgeTop, 10); - YGNodeStyleSetMargin(child0, YGEdgeBottom, 10); - YGNodeInsertChild(root, child0, 0); - const YGNodeRef child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(child1, 80); - YGNodeStyleSetHeight(child1, 40); - YGNodeInsertChild(root, child1, 1); - const YGNodeRef child1_1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(child1_1, 80); - YGNodeStyleSetHeight(child1_1, 40); - YGNodeStyleSetMargin(child1_1, YGEdgeBottom, 5); - YGNodeInsertChild(child1, child1_1, 0); - - YGNodeCalculateLayout(root, 200, 100, YGDirectionLTR); - - ASSERT_TRUE(YGNodeLayoutGetHadOverflow(root)); -} diff --git a/core-tests/YGInfiniteHeightTest.cpp b/core-tests/YGInfiniteHeightTest.cpp deleted file mode 100644 index a557b3d9..00000000 --- a/core-tests/YGInfiniteHeightTest.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include -#include - -// This test isn't correct from the Flexbox standard standpoint, -// because percentages are calculated with parent constraints. -// However, we need to make sure we fail gracefully in this case, not returning NaN -TEST(YogaTest, percent_absolute_position_infinite_height) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 300); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 300); - YGNodeStyleSetHeight(root_child0, 300); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetPositionType(root_child1, YGPositionTypeAbsolute); - YGNodeStyleSetPositionPercent(root_child1, YGEdgeLeft, 20); - YGNodeStyleSetPositionPercent(root_child1, YGEdgeTop, 20); - YGNodeStyleSetWidthPercent(root_child1, 20); - YGNodeStyleSetHeightPercent(root_child1, 20); - 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(300, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(300, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(300, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(300, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} diff --git a/core-tests/YGJustifyContentTest.cpp b/core-tests/YGJustifyContentTest.cpp deleted file mode 100644 index e5d42168..00000000 --- a/core-tests/YGJustifyContentTest.cpp +++ /dev/null @@ -1,999 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @Generated by gentest/gentest.rb from gentest/fixtures/YGJustifyContentTest.html - -#include -#include - -TEST(YogaTest, justify_content_row_flex_start) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 102); - YGNodeStyleSetHeight(root, 102); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, justify_content_row_flex_end) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetJustifyContent(root, YGJustifyFlexEnd); - YGNodeStyleSetWidth(root, 102); - YGNodeStyleSetHeight(root, 102); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, justify_content_row_center) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetWidth(root, 102); - YGNodeStyleSetHeight(root, 102); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, justify_content_row_space_between) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetJustifyContent(root, YGJustifySpaceBetween); - YGNodeStyleSetWidth(root, 102); - YGNodeStyleSetHeight(root, 102); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, justify_content_row_space_around) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetJustifyContent(root, YGJustifySpaceAround); - YGNodeStyleSetWidth(root, 102); - YGNodeStyleSetHeight(root, 102); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, justify_content_column_flex_start) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 102); - YGNodeStyleSetHeight(root, 102); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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(10, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(20, 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(10, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, justify_content_column_flex_end) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifyFlexEnd); - YGNodeStyleSetWidth(root, 102); - YGNodeStyleSetHeight(root, 102); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, justify_content_column_center) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetWidth(root, 102); - YGNodeStyleSetHeight(root, 102); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, justify_content_column_space_between) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifySpaceBetween); - YGNodeStyleSetWidth(root, 102); - YGNodeStyleSetHeight(root, 102); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, justify_content_column_space_around) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifySpaceAround); - YGNodeStyleSetWidth(root, 102); - YGNodeStyleSetHeight(root, 102); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, justify_content_row_min_width_and_margin) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetMargin(root, YGEdgeLeft, 100); - YGNodeStyleSetMinWidth(root, 50); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 20); - YGNodeStyleSetHeight(root_child0, 20); - YGNodeInsertChild(root, root_child0, 0); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(15, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(15, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, justify_content_row_max_width_and_margin) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetMargin(root, YGEdgeLeft, 100); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetMaxWidth(root, 80); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 20); - YGNodeStyleSetHeight(root_child0, 20); - YGNodeInsertChild(root, root_child0, 0); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, justify_content_column_min_height_and_margin) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetMargin(root, YGEdgeTop, 100); - YGNodeStyleSetMinHeight(root, 50); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 20); - YGNodeStyleSetHeight(root_child0, 20); - YGNodeInsertChild(root, root_child0, 0); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(15, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(15, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, justify_content_colunn_max_height_and_margin) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetMargin(root, YGEdgeTop, 100); - YGNodeStyleSetHeight(root, 100); - YGNodeStyleSetMaxHeight(root, 80); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 20); - YGNodeStyleSetHeight(root_child0, 20); - YGNodeInsertChild(root, root_child0, 0); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, justify_content_column_space_evenly) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifySpaceEvenly); - YGNodeStyleSetWidth(root, 102); - YGNodeStyleSetHeight(root, 102); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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(18, 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(74, 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(18, 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(74, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(102, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, justify_content_row_space_evenly) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetJustifyContent(root, YGJustifySpaceEvenly); - YGNodeStyleSetWidth(root, 102); - YGNodeStyleSetHeight(root, 102); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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(26, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(51, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(77, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(0, 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(77, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(51, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(26, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} diff --git a/core-tests/YGLayoutDiffingTest.cpp b/core-tests/YGLayoutDiffingTest.cpp deleted file mode 100644 index a04e87df..00000000 --- a/core-tests/YGLayoutDiffingTest.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include -#include -#include - -TEST(YogaTest, assert_layout_trees_are_same) { - YGConfig* config = YGConfigNew(); - YGConfigSetUseLegacyStretchBehaviour(config, true); - const YGNodeRef root1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root1, 500); - YGNodeStyleSetHeight(root1, 500); - - const YGNodeRef root1_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root1_child0, YGAlignFlexStart); - YGNodeInsertChild(root1, root1_child0, 0); - - const YGNodeRef root1_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root1_child0_child0, 1); - YGNodeStyleSetFlexShrink(root1_child0_child0, 1); - YGNodeInsertChild(root1_child0, root1_child0_child0, 0); - - const YGNodeRef root1_child0_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root1_child0_child0_child0, 1); - YGNodeStyleSetFlexShrink(root1_child0_child0_child0, 1); - YGNodeInsertChild(root1_child0_child0, root1_child0_child0_child0, 0); - - const int32_t cal1_configInstanceCount = YGConfigGetInstanceCount(); - const int32_t cal1_nodeInstanceCount = YGNodeGetInstanceCount(); - - YGNodeCalculateLayout(root1, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_EQ(YGConfigGetInstanceCount(), cal1_configInstanceCount); - ASSERT_EQ(YGNodeGetInstanceCount(), cal1_nodeInstanceCount); - - const YGNodeRef root2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root2, 500); - YGNodeStyleSetHeight(root2, 500); - - const YGNodeRef root2_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root2_child0, YGAlignFlexStart); - YGNodeInsertChild(root2, root2_child0, 0); - - const YGNodeRef root2_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root2_child0_child0, 1); - YGNodeStyleSetFlexShrink(root2_child0_child0, 1); - YGNodeInsertChild(root2_child0, root2_child0_child0, 0); - - const YGNodeRef root2_child0_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root2_child0_child0_child0, 1); - YGNodeStyleSetFlexShrink(root2_child0_child0_child0, 1); - YGNodeInsertChild(root2_child0_child0, root2_child0_child0_child0, 0); - - const int32_t cal2_configInstanceCount = YGConfigGetInstanceCount(); - const int32_t cal2_nodeInstanceCount = YGNodeGetInstanceCount(); - - YGNodeCalculateLayout(root2, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_EQ(YGConfigGetInstanceCount(), cal2_configInstanceCount); - ASSERT_EQ(YGNodeGetInstanceCount(), cal2_nodeInstanceCount); - - ASSERT_TRUE(YGNodeLayoutGetDidUseLegacyFlag(root1)); - ASSERT_TRUE(YGNodeLayoutGetDidUseLegacyFlag(root2)); - ASSERT_TRUE(root1->isLayoutTreeEqualToNode(*root2)); - - YGNodeStyleSetAlignItems(root2, YGAlignFlexEnd); - - const int32_t cal3_configInstanceCount = YGConfigGetInstanceCount(); - const int32_t cal3_nodeInstanceCount = YGNodeGetInstanceCount(); - - YGNodeCalculateLayout(root2, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_EQ(YGConfigGetInstanceCount(), cal3_configInstanceCount); - ASSERT_EQ(YGNodeGetInstanceCount(), cal3_nodeInstanceCount); - - ASSERT_FALSE(root1->isLayoutTreeEqualToNode(*root2)); - - YGNodeFreeRecursive(root1); - YGNodeFreeRecursive(root2); - - YGConfigFree(config); -} diff --git a/core-tests/YGLoggerTest.cpp b/core-tests/YGLoggerTest.cpp deleted file mode 100644 index 1b84ee6b..00000000 --- a/core-tests/YGLoggerTest.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include -#include -#include - -namespace { -char writeBuffer[4096]; -int _unmanagedLogger(const YGConfigRef config, - const YGNodeRef node, - YGLogLevel level, - const char *format, - va_list args) { - return vsnprintf(writeBuffer + strlen(writeBuffer), - sizeof(writeBuffer) - strlen(writeBuffer), - format, - args); -} -} - -TEST(YogaTest, logger_default_node_should_print_no_style_info) { - writeBuffer[0] = '\0'; - const YGConfigRef config = YGConfigNew(); - YGConfigSetLogger(config, _unmanagedLogger); - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeCalculateLayout(root, YGUnitUndefined, YGUnitUndefined, YGDirectionLTR); - YGNodePrint(root, - (YGPrintOptions)(YGPrintOptionsLayout | YGPrintOptionsChildren | - YGPrintOptionsStyle)); - YGConfigSetLogger(config, NULL); - YGNodeFree(root); - - const char *expected = "
"; - ASSERT_STREQ(expected, writeBuffer); -} - -TEST(YogaTest, logger_node_with_percentage_absolute_position_and_margin) { - writeBuffer[0] = '\0'; - const YGConfigRef config = YGConfigNew(); - YGConfigSetLogger(config, _unmanagedLogger); - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); - YGNodeStyleSetWidthPercent(root, 50); - YGNodeStyleSetHeightPercent(root, 75); - YGNodeStyleSetFlex(root, 1); - YGNodeStyleSetMargin(root, YGEdgeRight, 10); - YGNodeStyleSetMarginAuto(root, YGEdgeLeft); - YGNodeCalculateLayout(root, YGUnitUndefined, YGUnitUndefined, YGDirectionLTR); - YGNodePrint(root, - (YGPrintOptions)(YGPrintOptionsLayout | YGPrintOptionsChildren | - YGPrintOptionsStyle)); - YGConfigSetLogger(config, NULL); - YGNodeFree(root); - - const char *expected = "
"; - ASSERT_STREQ(expected, writeBuffer); -} - -TEST(YogaTest, logger_node_with_children_should_print_indented) { - writeBuffer[0] = '\0'; - const YGConfigRef config = YGConfigNew(); - YGConfigSetLogger(config, _unmanagedLogger); - const YGNodeRef root = YGNodeNewWithConfig(config); - const YGNodeRef child0 = YGNodeNewWithConfig(config); - const YGNodeRef child1 = YGNodeNewWithConfig(config); - YGNodeInsertChild(root, child0, 0); - YGNodeInsertChild(root, child1, 1); - YGNodeCalculateLayout(root, YGUnitUndefined, YGUnitUndefined, YGDirectionLTR); - YGNodePrint(root, - (YGPrintOptions)(YGPrintOptionsLayout | YGPrintOptionsChildren | - YGPrintOptionsStyle)); - YGConfigSetLogger(config, NULL); - YGNodeFreeRecursive(root); - - const char *expected = "
\n " - "
\n
\n
"; - ASSERT_STREQ(expected, writeBuffer); -} diff --git a/core-tests/YGMarginTest.cpp b/core-tests/YGMarginTest.cpp deleted file mode 100644 index 593cd2f2..00000000 --- a/core-tests/YGMarginTest.cpp +++ /dev/null @@ -1,1717 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @Generated by gentest/gentest.rb from gentest/fixtures/YGMarginTest.html - -#include -#include - -TEST(YogaTest, margin_start) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_top) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_end) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetJustifyContent(root, YGJustifyFlexEnd); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_bottom) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifyFlexEnd); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_and_flex_row) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetMargin(root_child0, YGEdgeStart, 10); - YGNodeStyleSetMargin(root_child0, YGEdgeEnd, 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(80, 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(80, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_and_flex_column) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetMargin(root_child0, YGEdgeTop, 10); - YGNodeStyleSetMargin(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(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(100, 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(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_and_stretch_row) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetMargin(root_child0, YGEdgeTop, 10); - YGNodeStyleSetMargin(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(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(100, 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(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_and_stretch_column) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetMargin(root_child0, YGEdgeStart, 10); - YGNodeStyleSetMargin(root_child0, YGEdgeEnd, 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(80, 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(80, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_with_sibling_row) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetMargin(root_child0, YGEdgeEnd, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - 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(45, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(55, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(45, 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(55, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(45, 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(45, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_with_sibling_column) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetMargin(root_child0, YGEdgeBottom, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - 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(45, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(55, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(45, 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(45, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(55, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(45, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_auto_bottom) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeBottom); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(75, 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(75, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(150, 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(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(75, 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(75, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_auto_top) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeTop); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(150, 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(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_auto_bottom_and_top) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeTop); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeBottom); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(150, 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(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_auto_bottom_and_top_justify_center) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeTop); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeBottom); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(50, 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(150, 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(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_auto_mutiple_children_column) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeTop); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetMarginAuto(root_child1, YGEdgeTop); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(root_child1, 50); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(150, 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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_auto_mutiple_children_row) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeRight); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetMarginAuto(root_child1, YGEdgeRight); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(root_child1, 50); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(75, 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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(125, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(75, 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(75, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_auto_left_and_right_column) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeLeft); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeRight); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(75, 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(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(75, 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(75, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_auto_left_and_right) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeLeft); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeRight); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(75, 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(50, YGNodeLayoutGetHeight(root_child1)); - - 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(75, 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(150, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_auto_start_and_end_column) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeStart); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeEnd); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(75, 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(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(75, 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(75, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_auto_start_and_end) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeStart); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeEnd); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(75, 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(50, YGNodeLayoutGetHeight(root_child1)); - - 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(75, 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(150, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_auto_left_and_right_column_and_center) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeLeft); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeRight); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(75, 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(75, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(50, 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(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(75, 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(75, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_auto_left) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeLeft); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(150, 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(75, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(50, 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(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(150, 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(75, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_auto_right) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeRight); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, 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(75, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(50, 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(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(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_auto_left_and_right_strech) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeLeft); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeRight); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, 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(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, 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(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(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(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_auto_top_and_bottom_strech) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeTop); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeBottom); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(50, 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(150, 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(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_should_not_be_part_of_max_height) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 250); - YGNodeStyleSetHeight(root, 250); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMargin(root_child0, YGEdgeTop, 20); - YGNodeStyleSetWidth(root_child0, 100); - YGNodeStyleSetHeight(root_child0, 100); - YGNodeStyleSetMaxHeight(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(250, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(250, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(20, 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(250, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(250, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_should_not_be_part_of_max_width) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 250); - YGNodeStyleSetHeight(root, 250); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMargin(root_child0, YGEdgeLeft, 20); - YGNodeStyleSetWidth(root_child0, 100); - YGNodeStyleSetMaxWidth(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(250, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(250, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, 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(250, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(250, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_auto_left_right_child_bigger_than_parent) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetWidth(root, 52); - YGNodeStyleSetHeight(root, 52); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeLeft); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeRight); - YGNodeStyleSetWidth(root_child0, 72); - YGNodeStyleSetHeight(root_child0, 72); - 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(52, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(-20, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_auto_left_child_bigger_than_parent) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetWidth(root, 52); - YGNodeStyleSetHeight(root, 52); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeLeft); - YGNodeStyleSetWidth(root_child0, 72); - YGNodeStyleSetHeight(root_child0, 72); - 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(52, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(-20, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_fix_left_auto_right_child_bigger_than_parent) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetWidth(root, 52); - YGNodeStyleSetHeight(root, 52); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMargin(root_child0, YGEdgeLeft, 10); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeRight); - YGNodeStyleSetWidth(root_child0, 72); - YGNodeStyleSetHeight(root_child0, 72); - 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(52, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(-20, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_auto_left_fix_right_child_bigger_than_parent) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetWidth(root, 52); - YGNodeStyleSetHeight(root, 52); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeLeft); - YGNodeStyleSetMargin(root_child0, YGEdgeRight, 10); - YGNodeStyleSetWidth(root_child0, 72); - YGNodeStyleSetHeight(root_child0, 72); - 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(52, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(-30, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(-10, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(72, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_auto_top_stretching_child) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexShrink(root_child0, 1); - YGNodeStyleSetFlexBasisPercent(root_child0, 0); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeTop); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(150, 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(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(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, margin_auto_left_stretching_child) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexShrink(root_child0, 1); - YGNodeStyleSetFlexBasisPercent(root_child0, 0); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeLeft); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(150, 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(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} diff --git a/core-tests/YGMeasureCacheTest.cpp b/core-tests/YGMeasureCacheTest.cpp deleted file mode 100644 index 91f18911..00000000 --- a/core-tests/YGMeasureCacheTest.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include -#include -#include - -static YGSize _measureMax(YGNodeRef node, - float width, - YGMeasureMode widthMode, - float height, - YGMeasureMode heightMode) { - int* measureCount = (int*)node->getContext(); - (*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*)node->getContext(); - *measureCount = *measureCount + 1; - return YGSize{ - .width = - widthMode == YGMeasureModeUndefined || (widthMode == YGMeasureModeAtMost && width > 10) - ? 10 - : width, - .height = - heightMode == YGMeasureModeUndefined || (heightMode == YGMeasureModeAtMost && height > 10) - ? 10 - : height, - }; -} - -static YGSize _measure_84_49(YGNodeRef node, - float width, - YGMeasureMode widthMode, - float height, - YGMeasureMode heightMode) { - int* measureCount = (int*)node->getContext(); - if (measureCount) { - (*measureCount)++; - } - - return YGSize{ - .width = 84.f, .height = 49.f, - }; -} - -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; - root_child0->setContext(&measureCount); - root_child0->setMeasureFunc(_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; - root_child0->setContext(&measureCount); - root_child0->setMeasureFunc(_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; - root_child0->setContext(&measureCount); - root_child0->setMeasureFunc(_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; - root_child0->setContext(&measureCount); - root_child0->setMeasureFunc(_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; - root_child0->setContext(&measureCount); - root_child0->setMeasureFunc(_measureMin); - YGNodeInsertChild(root, root_child0, 0); - - YGNodeCalculateLayout(root, 100, YGUndefined, YGDirectionLTR); - YGNodeCalculateLayout(root, 10, YGUndefined, YGDirectionLTR); - - ASSERT_EQ(1, measureCount); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, remeasure_with_already_measured_value_smaller_but_still_float_equal) { - int measureCount = 0; - - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetWidth(root, 288.f); - YGNodeStyleSetHeight(root, 288.f); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetPadding(root_child0, YGEdgeAll, 2.88f); - YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNew(); - root_child0_child0->setContext(&measureCount); - root_child0_child0->setMeasureFunc(_measure_84_49); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - YGNodeFreeRecursive(root); - - ASSERT_EQ(1, measureCount); -} diff --git a/core-tests/YGMeasureModeTest.cpp b/core-tests/YGMeasureModeTest.cpp deleted file mode 100644 index cbe1985a..00000000 --- a/core-tests/YGMeasureModeTest.cpp +++ /dev/null @@ -1,326 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include -#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*)node->getContext(); - 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(); - // root_child0->setContext(&constraintList); - root_child0->setContext(&constraintList); - root_child0->setMeasureFunc(_measure); - // root_child0->setMeasureFunc(_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(); - // root_child0->setContext(&constraintList); - root_child0->setContext(&constraintList); - root_child0->setMeasureFunc(_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(); - root_child0->setContext(&constraintList); - root_child0->setMeasureFunc(_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(); - root_child0->setContext(&constraintList); - root_child0->setMeasureFunc(_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(); - root_child0->setContext(&constraintList); - root_child0->setMeasureFunc(_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(); - root_child0->setContext(&constraintList); - root_child0->setMeasureFunc(_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); - root_child0->setContext(&constraintList); - root_child0->setMeasureFunc(_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); - root_child0->setContext(&constraintList); - root_child0->setMeasureFunc(_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(); - root_child0->setContext(&constraintList); - root_child0->setMeasureFunc(_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(YGFloatIsUndefined(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(); - root_child0->setContext(&constraintList); - root_child0->setMeasureFunc(_measure); - YGNodeInsertChild(root, root_child0, 0); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_EQ(1, constraintList.length); - - ASSERT_TRUE(YGFloatIsUndefined(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/core-tests/YGMeasureTest.cpp b/core-tests/YGMeasureTest.cpp deleted file mode 100644 index aea2cd59..00000000 --- a/core-tests/YGMeasureTest.cpp +++ /dev/null @@ -1,689 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include -#include -#include - -static YGSize _measure(YGNodeRef node, - float width, - YGMeasureMode widthMode, - float height, - YGMeasureMode heightMode) { - int* measureCount = (int*)node->getContext(); - if (measureCount) { - (*measureCount)++; - } - - return YGSize{ - .width = 10, .height = 10, - }; -} - -static YGSize _simulate_wrapping_text(YGNodeRef node, - float width, - YGMeasureMode widthMode, - float height, - YGMeasureMode heightMode) { - if (widthMode == YGMeasureModeUndefined || width >= 68) { - return YGSize{.width = 68, .height = 16}; - } - - return YGSize{ - .width = 50, .height = 32, - }; -} - -static YGSize _measure_assert_negative(YGNodeRef node, - float width, - YGMeasureMode widthMode, - float height, - YGMeasureMode heightMode) { - EXPECT_GE(width, 0); - EXPECT_GE(height, 0); - - return YGSize{ - .width = 0, .height = 0, - }; -} - -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(); - root_child0->setContext(&measureCount); - root_child0->setMeasureFunc(_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); -} - -TEST(YogaTest, measure_absolute_child_with_no_constraints) { - const YGNodeRef root = YGNodeNew(); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeInsertChild(root, root_child0, 0); - - int measureCount = 0; - - const YGNodeRef root_child0_child0 = YGNodeNew(); - YGNodeStyleSetPositionType(root_child0_child0, YGPositionTypeAbsolute); - root_child0_child0->setContext(&measureCount); - root_child0_child0->setMeasureFunc(_measure); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_EQ(1, measureCount); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, dont_measure_when_min_equals_max) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - int measureCount = 0; - - const YGNodeRef root_child0 = YGNodeNew(); - root_child0->setContext(&measureCount); - root_child0->setMeasureFunc(_measure); - YGNodeStyleSetMinWidth(root_child0, 10); - YGNodeStyleSetMaxWidth(root_child0, 10); - YGNodeStyleSetMinHeight(root_child0, 10); - YGNodeStyleSetMaxHeight(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_EQ(0, measureCount); - 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, dont_measure_when_min_equals_max_percentages) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - int measureCount = 0; - - const YGNodeRef root_child0 = YGNodeNew(); - root_child0->setContext(&measureCount); - root_child0->setMeasureFunc(_measure); - YGNodeStyleSetMinWidthPercent(root_child0, 10); - YGNodeStyleSetMaxWidthPercent(root_child0, 10); - YGNodeStyleSetMinHeightPercent(root_child0, 10); - YGNodeStyleSetMaxHeightPercent(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_EQ(0, measureCount); - 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, measure_nodes_with_margin_auto_and_stretch) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetWidth(root, 500); - YGNodeStyleSetHeight(root, 500); - - const YGNodeRef root_child0 = YGNodeNew(); - root_child0->setMeasureFunc(_measure); - YGNodeStyleSetMarginAuto(root_child0, YGEdgeLeft); - YGNodeInsertChild(root, root_child0, 0); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - EXPECT_EQ(490, YGNodeLayoutGetLeft(root_child0)); - EXPECT_EQ(0, YGNodeLayoutGetTop(root_child0)); - EXPECT_EQ(10, YGNodeLayoutGetWidth(root_child0)); - EXPECT_EQ(10, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, dont_measure_when_min_equals_max_mixed_width_percent) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - int measureCount = 0; - - const YGNodeRef root_child0 = YGNodeNew(); - root_child0->setContext(&measureCount); - root_child0->setMeasureFunc(_measure); - YGNodeStyleSetMinWidthPercent(root_child0, 10); - YGNodeStyleSetMaxWidthPercent(root_child0, 10); - YGNodeStyleSetMinHeight(root_child0, 10); - YGNodeStyleSetMaxHeight(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_EQ(0, measureCount); - 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, dont_measure_when_min_equals_max_mixed_height_percent) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - int measureCount = 0; - - const YGNodeRef root_child0 = YGNodeNew(); - root_child0->setContext(&measureCount); - root_child0->setMeasureFunc(_measure); - YGNodeStyleSetMinWidth(root_child0, 10); - YGNodeStyleSetMaxWidth(root_child0, 10); - YGNodeStyleSetMinHeightPercent(root_child0, 10); - YGNodeStyleSetMaxHeightPercent(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_EQ(0, measureCount); - 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, measure_enough_size_should_be_in_single_line) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetWidth(root, 100); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetAlignSelf(root_child0, YGAlignFlexStart); - root_child0->setMeasureFunc(_simulate_wrapping_text); - - YGNodeInsertChild(root, root_child0, 0); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(68, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(16, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, measure_not_enough_size_should_wrap) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetWidth(root, 55); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetAlignSelf(root_child0, YGAlignFlexStart); - // YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text); - root_child0->setMeasureFunc(_simulate_wrapping_text); - YGNodeInsertChild(root, root_child0, 0); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(32, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, measure_zero_space_should_grow) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetHeight(root, 200); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn); - YGNodeStyleSetFlexGrow(root, 0); - - int measureCount = 0; - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionColumn); - YGNodeStyleSetPadding(root_child0, YGEdgeAll, 100); - root_child0->setContext(&measureCount); - root_child0->setMeasureFunc(_measure); - - YGNodeInsertChild(root, root_child0, 0); - - YGNodeCalculateLayout(root, 282, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(282, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, measure_flex_direction_row_and_padding) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetPadding(root, YGEdgeLeft, 25); - YGNodeStyleSetPadding(root, YGEdgeTop, 25); - YGNodeStyleSetPadding(root, YGEdgeRight, 25); - YGNodeStyleSetPadding(root, YGEdgeBottom, 25); - YGNodeStyleSetWidth(root, 50); - YGNodeStyleSetHeight(root, 50); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - root_child0->setMeasureFunc(_simulate_wrapping_text); - // YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 5); - YGNodeStyleSetHeight(root_child1, 5); - 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(50, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(5, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(5, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, measure_flex_direction_column_and_padding) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetMargin(root, YGEdgeTop, 20); - YGNodeStyleSetPadding(root, YGEdgeAll, 25); - YGNodeStyleSetWidth(root, 50); - YGNodeStyleSetHeight(root, 50); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - root_child0->setMeasureFunc(_simulate_wrapping_text); - // YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 5); - YGNodeStyleSetHeight(root_child1, 5); - YGNodeInsertChild(root, root_child1, 1); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(32, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(57, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(5, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(5, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, measure_flex_direction_row_no_padding) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetMargin(root, YGEdgeTop, 20); - YGNodeStyleSetWidth(root, 50); - YGNodeStyleSetHeight(root, 50); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - // YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text); - root_child0->setMeasureFunc(_simulate_wrapping_text); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 5); - YGNodeStyleSetHeight(root_child1, 5); - YGNodeInsertChild(root, root_child1, 1); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(20, 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(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(5, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(5, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, measure_flex_direction_row_no_padding_align_items_flexstart) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetMargin(root, YGEdgeTop, 20); - YGNodeStyleSetWidth(root, 50); - YGNodeStyleSetHeight(root, 50); - YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - root_child0->setMeasureFunc(_simulate_wrapping_text); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 5); - YGNodeStyleSetHeight(root_child1, 5); - YGNodeInsertChild(root, root_child1, 1); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(20, 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(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(32, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(5, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(5, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, measure_with_fixed_size) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetMargin(root, YGEdgeTop, 20); - YGNodeStyleSetPadding(root, YGEdgeAll, 25); - YGNodeStyleSetWidth(root, 50); - YGNodeStyleSetHeight(root, 50); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - root_child0->setMeasureFunc(_simulate_wrapping_text); - YGNodeStyleSetWidth(root_child0, 10); - YGNodeStyleSetHeight(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 5); - YGNodeStyleSetHeight(root_child1, 5); - YGNodeInsertChild(root, root_child1, 1); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(35, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(5, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(5, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, measure_with_flex_shrink) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetMargin(root, YGEdgeTop, 20); - YGNodeStyleSetPadding(root, YGEdgeAll, 25); - YGNodeStyleSetWidth(root, 50); - YGNodeStyleSetHeight(root, 50); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - root_child0->setMeasureFunc(_simulate_wrapping_text); - YGNodeStyleSetFlexShrink(root_child0, 1); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 5); - YGNodeStyleSetHeight(root_child1, 5); - YGNodeInsertChild(root, root_child1, 1); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(5, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(5, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, measure_no_padding) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetMargin(root, YGEdgeTop, 20); - YGNodeStyleSetWidth(root, 50); - YGNodeStyleSetHeight(root, 50); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - root_child0->setMeasureFunc(_simulate_wrapping_text); - YGNodeStyleSetFlexShrink(root_child0, 1); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 5); - YGNodeStyleSetHeight(root_child1, 5); - YGNodeInsertChild(root, root_child1, 1); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(20, 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(50, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(32, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(32, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(5, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(5, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -#if GTEST_HAS_DEATH_TEST -TEST(YogaDeathTest, cannot_add_child_to_node_with_measure_func) { - const YGNodeRef root = YGNodeNew(); - root->setMeasureFunc(_measure); - - const YGNodeRef root_child0 = YGNodeNew(); - ASSERT_DEATH(YGNodeInsertChild(root, root_child0, 0), "Cannot add child.*"); - YGNodeFree(root_child0); - YGNodeFreeRecursive(root); -} - -TEST(YogaDeathTest, 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(root->setMeasureFunc(_measure), "Cannot set measure function.*"); - YGNodeFreeRecursive(root); -} - -#endif - -TEST(YogaTest, can_nullify_measure_func_on_any_node) { - const YGNodeRef root = YGNodeNew(); - YGNodeInsertChild(root, YGNodeNew(), 0); - root->setMeasureFunc(nullptr); - ASSERT_TRUE(root->getMeasure() == NULL); - YGNodeFreeRecursive(root); -} - -TEST(YogaTest, cant_call_negative_measure) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn); - YGNodeStyleSetWidth(root, 50); - YGNodeStyleSetHeight(root, 10); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - root_child0->setMeasureFunc(_measure_assert_negative); - YGNodeStyleSetMargin(root_child0, YGEdgeTop, 20); - YGNodeInsertChild(root, root_child0, 0); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - YGNodeFreeRecursive(root); - YGConfigFree(config); -} - -TEST(YogaTest, cant_call_negative_measure_horizontal) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 10); - YGNodeStyleSetHeight(root, 20); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - root_child0->setMeasureFunc(_measure_assert_negative); - YGNodeStyleSetMargin(root_child0, YGEdgeStart, 20); - YGNodeInsertChild(root, root_child0, 0); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - YGNodeFreeRecursive(root); - YGConfigFree(config); -} - -static YGSize _measure_90_10(YGNodeRef node, - float width, - YGMeasureMode widthMode, - float height, - YGMeasureMode heightMode) { - - return YGSize{ - .width = 90, .height = 10, - }; -} - -TEST(YogaTest, percent_with_text_node) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetJustifyContent(root, YGJustifySpaceBetween); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 80); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - root_child1->setMeasureFunc(_measure_90_10); - YGNodeStyleSetMaxWidthPercent(root_child1, 50); - YGNodeStyleSetPaddingPercent(root_child1, YGEdgeTop, 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(80, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(15, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} diff --git a/core-tests/YGMinMaxDimensionTest.cpp b/core-tests/YGMinMaxDimensionTest.cpp deleted file mode 100644 index 515bdfdc..00000000 --- a/core-tests/YGMinMaxDimensionTest.cpp +++ /dev/null @@ -1,1297 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @Generated by gentest/gentest.rb from gentest/fixtures/YGMinMaxDimensionTest.html - -#include -#include - -TEST(YogaTest, max_width) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, max_height) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, min_height) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetMinHeight(root_child0, 60); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, min_width) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetMinWidth(root_child0, 60); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, justify_content_min_max) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetMinHeight(root, 100); - YGNodeStyleSetMaxHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, align_items_min_max) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetMinWidth(root, 100); - YGNodeStyleSetMaxWidth(root, 200); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, justify_content_overflow_min_max) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetMinHeight(root, 100); - YGNodeStyleSetMaxHeight(root, 110); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child1, 50); - YGNodeStyleSetHeight(root_child1, 50); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, flex_grow_to_min) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetMinHeight(root, 100); - YGNodeStyleSetMaxHeight(root, 500); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexShrink(root_child0, 1); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(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); - - YGConfigFree(config); -} - -TEST(YogaTest, flex_grow_in_at_most_container) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0_child0, 1); - YGNodeStyleSetFlexBasis(root_child0_child0, 0); - 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(0, 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(0, 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(100, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(0, 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(0, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, flex_grow_child) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexBasis(root_child0, 0); - 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(0, 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(0, 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(0, 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(0, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, flex_grow_within_constrained_min_max_column) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetMinHeight(root, 100); - YGNodeStyleSetMaxHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(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(0, 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(0, 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(0, 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(0, 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(0, 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(0, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, flex_grow_within_max_width) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow); - YGNodeStyleSetMaxWidth(root_child0, 100); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, flex_grow_within_constrained_max_width) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow); - YGNodeStyleSetMaxWidth(root_child0, 300); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, flex_root_ignored) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root, 1); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetMinHeight(root, 100); - YGNodeStyleSetMaxHeight(root, 500); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexBasis(root_child0, 200); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root_child1, 100); - 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(300, 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(200, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(100, 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(300, 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(200, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, flex_grow_root_minimized) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetMinHeight(root, 100); - YGNodeStyleSetMaxHeight(root, 500); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetMinHeight(root_child0, 100); - YGNodeStyleSetMaxHeight(root_child0, 500); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0_child0, 1); - YGNodeStyleSetFlexBasis(root_child0_child0, 200); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - const YGNodeRef root_child0_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root_child0_child1, 100); - YGNodeInsertChild(root_child0, root_child0_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(300, 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(300, 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(200, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetTop(root_child0_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_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(300, 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(300, 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(200, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetTop(root_child0_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, flex_grow_height_maximized) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 500); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetMinHeight(root_child0, 100); - YGNodeStyleSetMaxHeight(root_child0, 500); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0_child0, 1); - YGNodeStyleSetFlexBasis(root_child0_child0, 200); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - const YGNodeRef root_child0_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root_child0_child1, 100); - YGNodeInsertChild(root_child0, root_child0_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(500, 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(500, 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(400, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child1)); - ASSERT_FLOAT_EQ(400, YGNodeLayoutGetTop(root_child0_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_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(500, 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(500, 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(400, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child1)); - ASSERT_FLOAT_EQ(400, YGNodeLayoutGetTop(root_child0_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, flex_grow_within_constrained_min_row) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetMinWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(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); - - YGConfigFree(config); -} - -TEST(YogaTest, flex_grow_within_constrained_min_column) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetMinHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(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(0, 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(0, 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(0, 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(0, 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(0, 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(0, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, flex_grow_within_constrained_max_row) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow); - YGNodeStyleSetMaxWidth(root_child0, 100); - YGNodeStyleSetHeight(root_child0, 100); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexShrink(root_child0_child0, 1); - YGNodeStyleSetFlexBasis(root_child0_child0, 100); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - const YGNodeRef root_child0_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0_child1, 50); - YGNodeInsertChild(root_child0, root_child0_child1, 1); - 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(100, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_child1)); - - 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(100, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, flex_grow_within_constrained_max_column) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetMaxHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexShrink(root_child0, 1); - YGNodeStyleSetFlexBasis(root_child0, 100); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(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); - - YGConfigFree(config); -} - -TEST(YogaTest, child_min_max_width_flexing) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 120); - YGNodeStyleSetHeight(root, 50); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexBasis(root_child0, 0); - YGNodeStyleSetMinWidth(root_child0, 60); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeStyleSetFlexBasisPercent(root_child1, 50); - YGNodeStyleSetMaxWidth(root_child1, 20); - 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(120, 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(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(20, 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(120, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(20, 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(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, min_width_overrides_width) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 50); - YGNodeStyleSetMinWidth(root, 100); - 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(0, YGNodeLayoutGetHeight(root)); - - 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(0, YGNodeLayoutGetHeight(root)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, max_width_overrides_width) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetMaxWidth(root, 100); - 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(0, YGNodeLayoutGetHeight(root)); - - 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(0, YGNodeLayoutGetHeight(root)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, min_height_overrides_height) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root, 50); - YGNodeStyleSetMinHeight(root, 100); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, max_height_overrides_height) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root, 200); - YGNodeStyleSetMaxHeight(root, 100); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, min_max_percent_no_width_height) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMinWidthPercent(root_child0, 10); - YGNodeStyleSetMaxWidthPercent(root_child0, 10); - YGNodeStyleSetMinHeightPercent(root_child0, 10); - YGNodeStyleSetMaxHeightPercent(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); - - YGConfigFree(config); -} diff --git a/core-tests/YGNodeChildTest.cpp b/core-tests/YGNodeChildTest.cpp deleted file mode 100644 index 9d6bb486..00000000 --- a/core-tests/YGNodeChildTest.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include -#include - -TEST(YogaTest, reset_layout_when_child_removed) { - const YGNodeRef root = YGNodeNew(); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetWidth(root_child0, 100); - YGNodeStyleSetHeight(root_child0, 100); - 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)); - - YGNodeRemoveChild(root, root_child0); - - ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_TRUE(YGFloatIsUndefined(YGNodeLayoutGetWidth(root_child0))); - ASSERT_TRUE(YGFloatIsUndefined(YGNodeLayoutGetHeight(root_child0))); - - YGNodeFreeRecursive(root); -} diff --git a/core-tests/YGPaddingTest.cpp b/core-tests/YGPaddingTest.cpp deleted file mode 100644 index f0d37527..00000000 --- a/core-tests/YGPaddingTest.cpp +++ /dev/null @@ -1,258 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @Generated by gentest/gentest.rb from gentest/fixtures/YGPaddingTest.html - -#include -#include - -TEST(YogaTest, padding_no_size) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, padding_container_match_child) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetPadding(root, YGEdgeLeft, 10); - YGNodeStyleSetPadding(root, YGEdgeTop, 10); - YGNodeStyleSetPadding(root, YGEdgeRight, 10); - YGNodeStyleSetPadding(root, YGEdgeBottom, 10); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, padding_flex_child) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - 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 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, padding_stretch_child) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - 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 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, padding_center_child) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - 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 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, child_with_padding_align_end) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifyFlexEnd); - YGNodeStyleSetAlignItems(root, YGAlignFlexEnd); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} diff --git a/core-tests/YGPercentageTest.cpp b/core-tests/YGPercentageTest.cpp deleted file mode 100644 index 2be04595..00000000 --- a/core-tests/YGPercentageTest.cpp +++ /dev/null @@ -1,1194 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @Generated by gentest/gentest.rb from gentest/fixtures/YGPercentageTest.html - -#include -#include - -TEST(YogaTest, percentage_width_height) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidthPercent(root_child0, 30); - YGNodeStyleSetHeightPercent(root_child0, 30); - 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(0, 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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(140, 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); - - YGConfigFree(config); -} - -TEST(YogaTest, percentage_position_left_top) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 400); - YGNodeStyleSetHeight(root, 400); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetPositionPercent(root_child0, YGEdgeLeft, 10); - YGNodeStyleSetPositionPercent(root_child0, YGEdgeTop, 20); - YGNodeStyleSetWidthPercent(root_child0, 45); - YGNodeStyleSetHeightPercent(root_child0, 55); - 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(400, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(400, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(180, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(220, YGNodeLayoutGetHeight(root_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(400, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(400, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(260, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(180, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(220, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, percentage_position_bottom_right) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 500); - YGNodeStyleSetHeight(root, 500); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetPositionPercent(root_child0, YGEdgeRight, 20); - YGNodeStyleSetPositionPercent(root_child0, YGEdgeBottom, 10); - YGNodeStyleSetWidthPercent(root_child0, 55); - YGNodeStyleSetHeightPercent(root_child0, 15); - 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(500, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(-100, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(-50, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(275, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetHeight(root_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(125, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(-50, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(275, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, percentage_flex_basis) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexBasisPercent(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeStyleSetFlexBasisPercent(root_child1, 25); - 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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(125, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(125, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root_child1)); - - 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(75, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(125, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, percentage_flex_basis_cross) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexBasisPercent(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeStyleSetFlexBasisPercent(root_child1, 25); - 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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, 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(125, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(125, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetHeight(root_child1)); - - 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(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(125, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(125, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, percentage_flex_basis_cross_min_height) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetMinHeightPercent(root_child0, 60); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 2); - YGNodeStyleSetMinHeightPercent(root_child1, 10); - 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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, 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(140, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(140, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetHeight(root_child1)); - - 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(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(140, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(140, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, percentage_flex_basis_main_max_height) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexBasisPercent(root_child0, 10); - YGNodeStyleSetMaxHeightPercent(root_child0, 60); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 4); - YGNodeStyleSetFlexBasisPercent(root_child1, 10); - YGNodeStyleSetMaxHeightPercent(root_child1, 20); - 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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(120, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(148, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child1)); - - 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(148, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(52, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(120, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(148, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, percentage_flex_basis_cross_max_height) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexBasisPercent(root_child0, 10); - YGNodeStyleSetMaxHeightPercent(root_child0, 60); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 4); - YGNodeStyleSetFlexBasisPercent(root_child1, 10); - YGNodeStyleSetMaxHeightPercent(root_child1, 20); - 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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, 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(120, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(120, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child1)); - - 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(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(120, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(120, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, percentage_flex_basis_main_max_width) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexBasisPercent(root_child0, 15); - YGNodeStyleSetMaxWidthPercent(root_child0, 60); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 4); - YGNodeStyleSetFlexBasisPercent(root_child1, 10); - YGNodeStyleSetMaxWidthPercent(root_child1, 20); - 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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(120, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(120, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root_child1)); - - 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(80, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(120, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, percentage_flex_basis_cross_max_width) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexBasisPercent(root_child0, 10); - YGNodeStyleSetMaxWidthPercent(root_child0, 60); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 4); - YGNodeStyleSetFlexBasisPercent(root_child1, 15); - YGNodeStyleSetMaxWidthPercent(root_child1, 20); - 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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(120, 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(40, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetHeight(root_child1)); - - 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(80, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(120, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(160, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, percentage_flex_basis_main_min_width) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexBasisPercent(root_child0, 15); - YGNodeStyleSetMinWidthPercent(root_child0, 60); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 4); - YGNodeStyleSetFlexBasisPercent(root_child1, 10); - YGNodeStyleSetMinWidthPercent(root_child1, 20); - 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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(120, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(120, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root_child1)); - - 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(80, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(120, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(80, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, percentage_flex_basis_cross_min_width) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexBasisPercent(root_child0, 10); - YGNodeStyleSetMinWidthPercent(root_child0, 60); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 4); - YGNodeStyleSetFlexBasisPercent(root_child1, 15); - YGNodeStyleSetMinWidthPercent(root_child1, 20); - 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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, 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(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetHeight(root_child1)); - - 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(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(200, 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(200, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, percentage_multiple_nested_with_padding_margin_and_percentage_values) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexBasisPercent(root_child0, 10); - YGNodeStyleSetMargin(root_child0, YGEdgeLeft, 5); - YGNodeStyleSetMargin(root_child0, YGEdgeTop, 5); - YGNodeStyleSetMargin(root_child0, YGEdgeRight, 5); - YGNodeStyleSetMargin(root_child0, YGEdgeBottom, 5); - YGNodeStyleSetPadding(root_child0, YGEdgeLeft, 3); - YGNodeStyleSetPadding(root_child0, YGEdgeTop, 3); - YGNodeStyleSetPadding(root_child0, YGEdgeRight, 3); - YGNodeStyleSetPadding(root_child0, YGEdgeBottom, 3); - YGNodeStyleSetMinWidthPercent(root_child0, 60); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMargin(root_child0_child0, YGEdgeLeft, 5); - YGNodeStyleSetMargin(root_child0_child0, YGEdgeTop, 5); - YGNodeStyleSetMargin(root_child0_child0, YGEdgeRight, 5); - YGNodeStyleSetMargin(root_child0_child0, YGEdgeBottom, 5); - YGNodeStyleSetPaddingPercent(root_child0_child0, YGEdgeLeft, 3); - YGNodeStyleSetPaddingPercent(root_child0_child0, YGEdgeTop, 3); - YGNodeStyleSetPaddingPercent(root_child0_child0, YGEdgeRight, 3); - YGNodeStyleSetPaddingPercent(root_child0_child0, YGEdgeBottom, 3); - YGNodeStyleSetWidthPercent(root_child0_child0, 50); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - const YGNodeRef root_child0_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetMarginPercent(root_child0_child0_child0, YGEdgeLeft, 5); - YGNodeStyleSetMarginPercent(root_child0_child0_child0, YGEdgeTop, 5); - YGNodeStyleSetMarginPercent(root_child0_child0_child0, YGEdgeRight, 5); - YGNodeStyleSetMarginPercent(root_child0_child0_child0, YGEdgeBottom, 5); - YGNodeStyleSetPadding(root_child0_child0_child0, YGEdgeLeft, 3); - YGNodeStyleSetPadding(root_child0_child0_child0, YGEdgeTop, 3); - YGNodeStyleSetPadding(root_child0_child0_child0, YGEdgeRight, 3); - YGNodeStyleSetPadding(root_child0_child0_child0, YGEdgeBottom, 3); - YGNodeStyleSetWidthPercent(root_child0_child0_child0, 45); - YGNodeInsertChild(root_child0_child0, root_child0_child0_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 4); - YGNodeStyleSetFlexBasisPercent(root_child1, 15); - YGNodeStyleSetMinWidthPercent(root_child1, 20); - 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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(5, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(5, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(190, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(48, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(8, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(8, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(92, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(36, YGNodeLayoutGetWidth(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(6, YGNodeLayoutGetHeight(root_child0_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(58, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(142, YGNodeLayoutGetHeight(root_child1)); - - 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(5, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(5, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(190, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(48, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(8, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(92, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(46, YGNodeLayoutGetLeft(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(36, YGNodeLayoutGetWidth(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(6, YGNodeLayoutGetHeight(root_child0_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(58, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(142, YGNodeLayoutGetHeight(root_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, percentage_margin_should_calculate_based_only_on_width) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetMarginPercent(root_child0, YGEdgeLeft, 10); - YGNodeStyleSetMarginPercent(root_child0, YGEdgeTop, 10); - YGNodeStyleSetMarginPercent(root_child0, YGEdgeRight, 10); - YGNodeStyleSetMarginPercent(root_child0, YGEdgeBottom, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0_child0, 10); - YGNodeStyleSetHeight(root_child0_child0, 10); - 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(20, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(160, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(10, 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(20, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(160, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, percentage_padding_should_calculate_based_only_on_width) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetPaddingPercent(root_child0, YGEdgeLeft, 10); - YGNodeStyleSetPaddingPercent(root_child0, YGEdgeTop, 10); - YGNodeStyleSetPaddingPercent(root_child0, YGEdgeRight, 10); - YGNodeStyleSetPaddingPercent(root_child0, YGEdgeBottom, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0_child0, 10); - YGNodeStyleSetHeight(root_child0_child0, 10); - 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(100, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(10, 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(100, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(170, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(20, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, percentage_absolute_position) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); - YGNodeStyleSetPositionPercent(root_child0, YGEdgeLeft, 30); - YGNodeStyleSetPositionPercent(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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(60, 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(200, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(60, 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); - - YGConfigFree(config); -} - -TEST(YogaTest, percentage_width_height_undefined_parent_size) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidthPercent(root_child0, 50); - YGNodeStyleSetHeightPercent(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(0, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, percent_within_flex_grow) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 350); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 100); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child1_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidthPercent(root_child1_child0, 100); - YGNodeInsertChild(root_child1, root_child1_child0, 0); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child2, 100); - 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(350, 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(100, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child1_child0)); - - ASSERT_FLOAT_EQ(250, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(100, 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(350, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(250, 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(100, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child1_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child2)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, percentage_container_in_wrapping_container) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetJustifyContent(root, YGJustifyCenter); - YGNodeStyleSetAlignItems(root, YGAlignCenter); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root_child0_child0, YGFlexDirectionRow); - YGNodeStyleSetJustifyContent(root_child0_child0, YGJustifyCenter); - YGNodeStyleSetWidthPercent(root_child0_child0, 100); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - const YGNodeRef root_child0_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0_child0_child0, 50); - YGNodeStyleSetHeight(root_child0_child0_child0, 50); - YGNodeInsertChild(root_child0_child0, root_child0_child0_child0, 0); - - const YGNodeRef root_child0_child0_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0_child0_child1, 50); - YGNodeStyleSetHeight(root_child0_child0_child1, 50); - YGNodeInsertChild(root_child0_child0, root_child0_child0_child1, 1); - 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(50, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, 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(50, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_child0_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0_child0_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_child0_child1)); - - 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(50, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, 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(50, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_child0_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, percent_absolute_position) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 60); - YGNodeStyleSetHeight(root, 50); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow); - YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); - YGNodeStyleSetPositionPercent(root_child0, YGEdgeLeft, 50); - YGNodeStyleSetWidthPercent(root_child0, 100); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidthPercent(root_child0_child0, 100); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - const YGNodeRef root_child0_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidthPercent(root_child0_child1, 100); - YGNodeInsertChild(root_child0, root_child0_child1, 1); - 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(50, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetLeft(root_child0_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child1)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root_child0_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_child1)); - - 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(50, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(30, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(-60, YGNodeLayoutGetLeft(root_child0_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child1)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetWidth(root_child0_child1)); - ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_child1)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} diff --git a/core-tests/YGPersistenceTest.cpp b/core-tests/YGPersistenceTest.cpp deleted file mode 100644 index 9df861a8..00000000 --- a/core-tests/YGPersistenceTest.cpp +++ /dev/null @@ -1,250 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @Generated by gentest/gentest.rb from gentest/fixtures/YGPercentageTest.html - -#include -#include - -TEST(YogaTest, cloning_shared_root) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexBasis(root_child0, 50); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - 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)); - - const YGNodeRef root2 = YGNodeClone(root); - YGNodeStyleSetWidth(root2, 100); - - ASSERT_EQ(2, YGNodeGetChildCount(root2)); - // The children should have referential equality at this point. - ASSERT_EQ(root_child0, YGNodeGetChild(root2, 0)); - ASSERT_EQ(root_child1, YGNodeGetChild(root2, 1)); - - YGNodeCalculateLayout(root2, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_EQ(2, YGNodeGetChildCount(root2)); - // Relayout with no changed input should result in referential equality. - ASSERT_EQ(root_child0, YGNodeGetChild(root2, 0)); - ASSERT_EQ(root_child1, YGNodeGetChild(root2, 1)); - - YGNodeStyleSetWidth(root2, 150); - YGNodeStyleSetHeight(root2, 200); - YGNodeCalculateLayout(root2, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_EQ(2, YGNodeGetChildCount(root2)); - // Relayout with changed input should result in cloned children. - const YGNodeRef root2_child0 = YGNodeGetChild(root2, 0); - const YGNodeRef root2_child1 = YGNodeGetChild(root2, 1); - ASSERT_NE(root_child0, root2_child0); - ASSERT_NE(root_child1, root2_child1); - - // Everything in the root should remain unchanged. - 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)); - - // The new root now has new layout. - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root2)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root2)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root2)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root2_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root2_child0)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root2_child0)); - ASSERT_FLOAT_EQ(125, YGNodeLayoutGetHeight(root2_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root2_child1)); - ASSERT_FLOAT_EQ(125, YGNodeLayoutGetTop(root2_child1)); - ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root2_child1)); - ASSERT_FLOAT_EQ(75, YGNodeLayoutGetHeight(root2_child1)); - - YGNodeFreeRecursive(root2); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, mutating_children_of_a_clone_clones) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - ASSERT_EQ(0, YGNodeGetChildCount(root)); - - const YGNodeRef root2 = YGNodeClone(root); - ASSERT_EQ(0, YGNodeGetChildCount(root2)); - - const YGNodeRef root2_child0 = YGNodeNewWithConfig(config); - YGNodeInsertChild(root2, root2_child0, 0); - - ASSERT_EQ(0, YGNodeGetChildCount(root)); - ASSERT_EQ(1, YGNodeGetChildCount(root2)); - - const YGNodeRef root3 = YGNodeClone(root2); - ASSERT_EQ(1, YGNodeGetChildCount(root2)); - ASSERT_EQ(1, YGNodeGetChildCount(root3)); - ASSERT_EQ(YGNodeGetChild(root2, 0), YGNodeGetChild(root3, 0)); - - const YGNodeRef root3_child1 = YGNodeNewWithConfig(config); - YGNodeInsertChild(root3, root3_child1, 1); - ASSERT_EQ(1, YGNodeGetChildCount(root2)); - ASSERT_EQ(2, YGNodeGetChildCount(root3)); - ASSERT_EQ(root3_child1, YGNodeGetChild(root3, 1)); - ASSERT_NE(YGNodeGetChild(root2, 0), YGNodeGetChild(root3, 0)); - - const YGNodeRef root4 = YGNodeClone(root3); - ASSERT_EQ(root3_child1, YGNodeGetChild(root4, 1)); - - YGNodeRemoveChild(root4, root3_child1); - ASSERT_EQ(2, YGNodeGetChildCount(root3)); - ASSERT_EQ(1, YGNodeGetChildCount(root4)); - ASSERT_NE(YGNodeGetChild(root3, 0), YGNodeGetChild(root4, 0)); - - YGNodeFreeRecursive(root4); - YGNodeFreeRecursive(root3); - YGNodeFreeRecursive(root2); - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, cloning_two_levels) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexBasis(root_child0, 15); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child1_0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexBasis(root_child1_0, 10); - YGNodeStyleSetFlexGrow(root_child1_0, 1); - YGNodeInsertChild(root_child1, root_child1_0, 0); - - const YGNodeRef root_child1_1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexBasis(root_child1_1, 25); - YGNodeInsertChild(root_child1, root_child1_1, 1); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetHeight(root_child1)); - ASSERT_FLOAT_EQ(35, YGNodeLayoutGetHeight(root_child1_0)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child1_1)); - - const YGNodeRef root2_child0 = YGNodeClone(root_child0); - const YGNodeRef root2_child1 = YGNodeClone(root_child1); - const YGNodeRef root2 = YGNodeClone(root); - - YGNodeStyleSetFlexGrow(root2_child0, 0); - YGNodeStyleSetFlexBasis(root2_child0, 40); - - YGNodeRemoveAllChildren(root2); - YGNodeInsertChild(root2, root2_child0, 0); - YGNodeInsertChild(root2, root2_child1, 1); - ASSERT_EQ(2, YGNodeGetChildCount(root2)); - - YGNodeCalculateLayout(root2, YGUndefined, YGUndefined, YGDirectionLTR); - - // Original root is unchanged - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root_child0)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetHeight(root_child1)); - ASSERT_FLOAT_EQ(35, YGNodeLayoutGetHeight(root_child1_0)); - ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child1_1)); - - // New root has new layout at the top - ASSERT_FLOAT_EQ(40, YGNodeLayoutGetHeight(root2_child0)); - ASSERT_FLOAT_EQ(60, YGNodeLayoutGetHeight(root2_child1)); - - // The deeper children are untouched. - ASSERT_EQ(YGNodeGetChild(root2_child1, 0), root_child1_0); - ASSERT_EQ(YGNodeGetChild(root2_child1, 1), root_child1_1); - - YGNodeFreeRecursive(root2); - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, cloning_and_freeing) { - const int32_t initialInstanceCount = YGNodeGetInstanceCount(); - - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeInsertChild(root, root_child0, 0); - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeInsertChild(root, root_child1, 1); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - const YGNodeRef root2 = YGNodeClone(root); - - // Freeing the original root should be safe as long as we don't free its - // children. - YGNodeFree(root); - - YGNodeCalculateLayout(root2, YGUndefined, YGUndefined, YGDirectionLTR); - - YGNodeFreeRecursive(root2); - - YGNodeFree(root_child0); - YGNodeFree(root_child1); - - YGConfigFree(config); - - ASSERT_EQ(initialInstanceCount, YGNodeGetInstanceCount()); -} diff --git a/core-tests/YGPixelGridRounding.cpp b/core-tests/YGPixelGridRounding.cpp deleted file mode 100644 index b38dc64b..00000000 --- a/core-tests/YGPixelGridRounding.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include - -// This test scrutinize next behaviours: -// - pixel grid snapping in 1e4..0 coordinate range -// - ability to layout nodes with smallest possible dimensions (one pixel separators) -// - providing text node layout with bounds strictly larger than sized - -TEST(YogaTest, pixel_grid_rounding_table) { - const float kPointScale = 3; - - const YGConfigRef config = YGConfigNew(); - YGConfigSetPointScaleFactor(config, kPointScale); - - const float kSeparatorHeight = 1 / kPointScale; - const float kCellContentHeight = 44.5; - const int kCellsCount = 100; - - const YGNodeRef root = YGNodeNewWithConfig(config); - - int subnodesCount = 0; - - for (int i = 0; i < kCellsCount; i++) { - const YGNodeRef separator = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(separator, kSeparatorHeight); - YGNodeInsertChild(root, separator, subnodesCount++); - - const YGNodeRef cell = YGNodeNewWithConfig(config); - YGNodeSetNodeType(cell, YGNodeTypeText); - YGNodeStyleSetHeight(cell, kCellContentHeight); - YGNodeInsertChild(root, cell, subnodesCount++); - } - - const YGNodeRef separator = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(separator, kSeparatorHeight); - YGNodeInsertChild(root, separator, subnodesCount++); - - YGNodeCalculateLayout(root, 375, YGUndefined, YGDirectionLTR); - - EXPECT_LE(kCellsCount * (kSeparatorHeight + kCellContentHeight) + kSeparatorHeight, YGNodeLayoutGetHeight(root)); - EXPECT_FLOAT_EQ(375, YGNodeLayoutGetWidth(root)); - - for (int i = 0; i < YGNodeGetChildCount(root); i++) { - const YGNodeRef child = YGNodeGetChild(root, i); - const float childHeight = YGNodeLayoutGetHeight(child); - - if (YGNodeGetNodeType(child) == YGNodeTypeText) { - EXPECT_GT(childHeight, kCellContentHeight); - } else { - EXPECT_GT(childHeight, 0); - } - } - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} diff --git a/core-tests/YGRelayoutTest.cpp b/core-tests/YGRelayoutTest.cpp deleted file mode 100644 index cbda5248..00000000 --- a/core-tests/YGRelayoutTest.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include -#include - -TEST(YogaTest, dont_cache_computed_flex_basis_between_layouts) { - const YGConfigRef config = YGConfigNew(); - YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureWebFlexBasis, true); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetHeightPercent(root, 100); - YGNodeStyleSetWidthPercent(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexBasisPercent(root_child0, 100); - YGNodeInsertChild(root, root_child0, 0); - - YGNodeCalculateLayout(root, 100, YGUndefined, YGDirectionLTR); - YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR); - - ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, recalculate_resolvedDimonsion_onchange) { - const YGNodeRef root = YGNodeNew(); - - const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetMinHeight(root_child0, 10); - YGNodeStyleSetMaxHeight(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); - - YGNodeStyleSetMinHeight(root_child0, YGUndefined); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); -} diff --git a/core-tests/YGRoundingFunctionTest.cpp b/core-tests/YGRoundingFunctionTest.cpp deleted file mode 100644 index 0b8a3f4f..00000000 --- a/core-tests/YGRoundingFunctionTest.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include -#include -#include - -TEST(YogaTest, rounding_value) { - // Test that whole numbers are rounded to whole despite ceil/floor flags - ASSERT_FLOAT_EQ(6.0, YGRoundValueToPixelGrid(6.000001, 2.0, false, false)); - ASSERT_FLOAT_EQ(6.0, YGRoundValueToPixelGrid(6.000001, 2.0, true, false)); - ASSERT_FLOAT_EQ(6.0, YGRoundValueToPixelGrid(6.000001, 2.0, false, true)); - ASSERT_FLOAT_EQ(6.0, YGRoundValueToPixelGrid(5.999999, 2.0, false, false)); - ASSERT_FLOAT_EQ(6.0, YGRoundValueToPixelGrid(5.999999, 2.0, true, false)); - ASSERT_FLOAT_EQ(6.0, YGRoundValueToPixelGrid(5.999999, 2.0, false, true)); - - // Test that numbers with fraction are rounded correctly accounting for ceil/floor flags - ASSERT_FLOAT_EQ(6.0, YGRoundValueToPixelGrid(6.1, 2.0, false, false)); - ASSERT_FLOAT_EQ(6.5, YGRoundValueToPixelGrid(6.1, 2.0, true, false)); - ASSERT_FLOAT_EQ(6.0, YGRoundValueToPixelGrid(6.1, 2.0, false, true)); - ASSERT_FLOAT_EQ(6.0, YGRoundValueToPixelGrid(5.9, 2.0, false, false)); - ASSERT_FLOAT_EQ(6.0, YGRoundValueToPixelGrid(5.9, 2.0, true, false)); - ASSERT_FLOAT_EQ(5.5, YGRoundValueToPixelGrid(5.9, 2.0, false, true)); - - // Are we able to treat value as rounded for reasonably large number? - ASSERT_FLOAT_EQ(527.6666666, YGRoundValueToPixelGrid(527.666, 3.0, false, true)); - ASSERT_FLOAT_EQ(527.6666666, YGRoundValueToPixelGrid(527.666, 3.0, true, false)); - ASSERT_FLOAT_EQ(527.6666666, YGRoundValueToPixelGrid(527.666, 3.0, true, true)); -} diff --git a/core-tests/YGRoundingMeasureFuncTest.cpp b/core-tests/YGRoundingMeasureFuncTest.cpp deleted file mode 100644 index 33820c44..00000000 --- a/core-tests/YGRoundingMeasureFuncTest.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include -#include -#include - -static YGSize _measureFloor(YGNodeRef node, - float width, - YGMeasureMode widthMode, - float height, - YGMeasureMode heightMode) { - return YGSize{ - width = 10.2f, height = 10.2f, - }; -} - -static YGSize _measureCeil(YGNodeRef node, - float width, - YGMeasureMode widthMode, - float height, - YGMeasureMode heightMode) { - return YGSize{ - width = 10.5f, height = 10.5f, - }; -} - -static YGSize _measureFractial(YGNodeRef node, - float width, - YGMeasureMode widthMode, - float height, - YGMeasureMode heightMode) { - return YGSize{ - width = 0.5f, height = 0.5f, - }; -} - -TEST(YogaTest, rounding_feature_with_custom_measure_func_floor) { - const YGConfigRef config = YGConfigNew(); - const YGNodeRef root = YGNodeNewWithConfig(config); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - root_child0->setMeasureFunc(_measureFloor); - YGNodeInsertChild(root, root_child0, 0); - - YGConfigSetPointScaleFactor(config, 0.0f); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(10.2, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(10.2, YGNodeLayoutGetHeight(root_child0)); - - YGConfigSetPointScaleFactor(config, 1.0f); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(11, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(11, YGNodeLayoutGetHeight(root_child0)); - - YGConfigSetPointScaleFactor(config, 2.0f); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(10.5, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(10.5, YGNodeLayoutGetHeight(root_child0)); - - YGConfigSetPointScaleFactor(config, 4.0f); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(10.25, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(10.25, YGNodeLayoutGetHeight(root_child0)); - - YGConfigSetPointScaleFactor(config, 1.0f / 3.0f); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(12.0, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(12.0, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, rounding_feature_with_custom_measure_func_ceil) { - const YGConfigRef config = YGConfigNew(); - const YGNodeRef root = YGNodeNewWithConfig(config); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - root_child0->setMeasureFunc(_measureCeil); - YGNodeInsertChild(root, root_child0, 0); - - YGConfigSetPointScaleFactor(config, 1.0f); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(11, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(11, YGNodeLayoutGetHeight(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, rounding_feature_with_custom_measure_and_fractial_matching_scale) { - const YGConfigRef config = YGConfigNew(); - const YGNodeRef root = YGNodeNewWithConfig(config); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetPosition(root_child0, YGEdgeLeft, 73.625); - root_child0->setMeasureFunc(_measureFractial); - YGNodeInsertChild(root, root_child0, 0); - - YGConfigSetPointScaleFactor(config, 2.0f); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0.5, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(0.5, YGNodeLayoutGetHeight(root_child0)); - ASSERT_FLOAT_EQ(73.5, YGNodeLayoutGetLeft(root_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} diff --git a/core-tests/YGRoundingTest.cpp b/core-tests/YGRoundingTest.cpp deleted file mode 100644 index 303e9f0b..00000000 --- a/core-tests/YGRoundingTest.cpp +++ /dev/null @@ -1,1077 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @Generated by gentest/gentest.rb from gentest/fixtures/YGRoundingTest.html - -#include -#include - -TEST(YogaTest, rounding_flex_basis_flex_grow_row_width_of_100) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, rounding_flex_basis_flex_grow_row_prime_number_width) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 113); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child2, 1); - YGNodeInsertChild(root, root_child2, 2); - - const YGNodeRef root_child3 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child3, 1); - YGNodeInsertChild(root, root_child3, 3); - - const YGNodeRef root_child4 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, rounding_flex_basis_flex_shrink_row) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 101); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexShrink(root_child0, 1); - YGNodeStyleSetFlexBasis(root_child0, 100); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexBasis(root_child1, 25); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, rounding_flex_basis_overrides_main_size) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 113); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexBasis(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 20); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeStyleSetHeight(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, rounding_total_fractial) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 87.4f); - YGNodeStyleSetHeight(root, 113.4f); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 0.7f); - YGNodeStyleSetFlexBasis(root_child0, 50.3f); - YGNodeStyleSetHeight(root_child0, 20.3f); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 1.6f); - YGNodeStyleSetHeight(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, rounding_total_fractial_nested) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 87.4f); - YGNodeStyleSetHeight(root, 113.4f); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - 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 = YGNodeNewWithConfig(config); - 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 = YGNodeNewWithConfig(config); - 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 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 1.6f); - YGNodeStyleSetHeight(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, rounding_fractial_input_1) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 113.4f); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexBasis(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 20); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeStyleSetHeight(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, rounding_fractial_input_2) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 113.6f); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexBasis(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 20); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeStyleSetHeight(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, rounding_fractial_input_3) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetPosition(root, YGEdgeTop, 0.3f); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 113.4f); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexBasis(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 20); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeStyleSetHeight(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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(64, 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(64, 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); - - YGConfigFree(config); -} - -TEST(YogaTest, rounding_fractial_input_4) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetPosition(root, YGEdgeTop, 0.7f); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 113.4f); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexBasis(root_child0, 50); - YGNodeStyleSetHeight(root_child0, 20); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeStyleSetHeight(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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); - - YGConfigFree(config); -} - -TEST(YogaTest, rounding_inner_node_controversy_horizontal) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 320); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetHeight(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeStyleSetHeight(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child1_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1_child0, 1); - YGNodeStyleSetHeight(root_child1_child0, 10); - YGNodeInsertChild(root_child1, root_child1_child0, 0); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - 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(320, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(107, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(107, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(106, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(106, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_child0)); - - ASSERT_FLOAT_EQ(213, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(107, 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(320, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(213, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(107, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(107, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(106, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(106, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(107, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, rounding_inner_node_controversy_vertical) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(root, 320); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetWidth(root_child0, 10); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeStyleSetWidth(root_child1, 10); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child1_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1_child0, 1); - YGNodeStyleSetWidth(root_child1_child0, 10); - YGNodeInsertChild(root_child1, root_child1_child0, 0); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child2, 1); - 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(10, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(320, 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(107, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(107, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(106, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(106, YGNodeLayoutGetHeight(root_child1_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(213, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(107, YGNodeLayoutGetHeight(root_child2)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(320, 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(107, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(107, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(106, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(106, YGNodeLayoutGetHeight(root_child1_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(213, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(107, YGNodeLayoutGetHeight(root_child2)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, rounding_inner_node_controversy_combined) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 640); - YGNodeStyleSetHeight(root, 320); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetHeightPercent(root_child0, 100); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1, 1); - YGNodeStyleSetHeightPercent(root_child1, 100); - YGNodeInsertChild(root, root_child1, 1); - - const YGNodeRef root_child1_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1_child0, 1); - YGNodeStyleSetWidthPercent(root_child1_child0, 100); - YGNodeInsertChild(root_child1, root_child1_child0, 0); - - const YGNodeRef root_child1_child1 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1_child1, 1); - YGNodeStyleSetWidthPercent(root_child1_child1, 100); - YGNodeInsertChild(root_child1, root_child1_child1, 1); - - const YGNodeRef root_child1_child1_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1_child1_child0, 1); - YGNodeStyleSetWidthPercent(root_child1_child1_child0, 100); - YGNodeInsertChild(root_child1_child1, root_child1_child1_child0, 0); - - const YGNodeRef root_child1_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child1_child2, 1); - YGNodeStyleSetWidthPercent(root_child1_child2, 100); - YGNodeInsertChild(root_child1, root_child1_child2, 2); - - const YGNodeRef root_child2 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child2, 1); - YGNodeStyleSetHeightPercent(root_child2, 100); - 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(640, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(320, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(213, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(320, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(213, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(214, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(320, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(214, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(107, YGNodeLayoutGetHeight(root_child1_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child1)); - ASSERT_FLOAT_EQ(107, YGNodeLayoutGetTop(root_child1_child1)); - ASSERT_FLOAT_EQ(214, YGNodeLayoutGetWidth(root_child1_child1)); - ASSERT_FLOAT_EQ(106, YGNodeLayoutGetHeight(root_child1_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child1_child0)); - ASSERT_FLOAT_EQ(214, YGNodeLayoutGetWidth(root_child1_child1_child0)); - ASSERT_FLOAT_EQ(106, YGNodeLayoutGetHeight(root_child1_child1_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child2)); - ASSERT_FLOAT_EQ(213, YGNodeLayoutGetTop(root_child1_child2)); - ASSERT_FLOAT_EQ(214, YGNodeLayoutGetWidth(root_child1_child2)); - ASSERT_FLOAT_EQ(107, YGNodeLayoutGetHeight(root_child1_child2)); - - ASSERT_FLOAT_EQ(427, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(213, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(320, YGNodeLayoutGetHeight(root_child2)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(640, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(320, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(427, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(213, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(320, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(213, YGNodeLayoutGetLeft(root_child1)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); - ASSERT_FLOAT_EQ(214, YGNodeLayoutGetWidth(root_child1)); - ASSERT_FLOAT_EQ(320, YGNodeLayoutGetHeight(root_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0)); - ASSERT_FLOAT_EQ(214, YGNodeLayoutGetWidth(root_child1_child0)); - ASSERT_FLOAT_EQ(107, YGNodeLayoutGetHeight(root_child1_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child1)); - ASSERT_FLOAT_EQ(107, YGNodeLayoutGetTop(root_child1_child1)); - ASSERT_FLOAT_EQ(214, YGNodeLayoutGetWidth(root_child1_child1)); - ASSERT_FLOAT_EQ(106, YGNodeLayoutGetHeight(root_child1_child1)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child1_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child1_child0)); - ASSERT_FLOAT_EQ(214, YGNodeLayoutGetWidth(root_child1_child1_child0)); - ASSERT_FLOAT_EQ(106, YGNodeLayoutGetHeight(root_child1_child1_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child2)); - ASSERT_FLOAT_EQ(213, YGNodeLayoutGetTop(root_child1_child2)); - ASSERT_FLOAT_EQ(214, YGNodeLayoutGetWidth(root_child1_child2)); - ASSERT_FLOAT_EQ(107, YGNodeLayoutGetHeight(root_child1_child2)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); - ASSERT_FLOAT_EQ(213, YGNodeLayoutGetWidth(root_child2)); - ASSERT_FLOAT_EQ(320, YGNodeLayoutGetHeight(root_child2)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} diff --git a/core-tests/YGSizeOverflowTest.cpp b/core-tests/YGSizeOverflowTest.cpp deleted file mode 100644 index 3fbcb300..00000000 --- a/core-tests/YGSizeOverflowTest.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @Generated by gentest/gentest.rb from gentest/fixtures/YGSizeOverflowTest.html - -#include -#include - -TEST(YogaTest, nested_overflowing_child) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0_child0, 200); - YGNodeStyleSetHeight(root_child0_child0, 200); - 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(200, 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(200, 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(200, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(-100, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root_child0_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, nested_overflowing_child_in_constraint_parent) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 100); - YGNodeStyleSetHeight(root_child0, 100); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0_child0, 200); - YGNodeStyleSetHeight(root_child0_child0, 200); - 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(100, 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(200, 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(100, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(-100, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root_child0_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} - -TEST(YogaTest, parent_wrap_child_size_overflowing_parent) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0, 100); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root_child0_child0, 100); - YGNodeStyleSetHeight(root_child0_child0, 200); - 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(200, 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(200, 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(200, 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(200, YGNodeLayoutGetHeight(root_child0_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} diff --git a/core-tests/YGStyleTest.cpp b/core-tests/YGStyleTest.cpp deleted file mode 100644 index 5de45e45..00000000 --- a/core-tests/YGStyleTest.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include -#include -#include - -TEST(YogaTest, copy_style_same) { - const YGNodeRef node0 = YGNodeNew(); - const YGNodeRef node1 = YGNodeNew(); - ASSERT_FALSE(node0->isDirty()); - - YGNodeCopyStyle(node0, node1); - ASSERT_FALSE(node0->isDirty()); - - YGNodeFree(node0); - YGNodeFree(node1); -} - -TEST(YogaTest, copy_style_modified) { - const YGNodeRef node0 = YGNodeNew(); - ASSERT_FALSE(node0->isDirty()); - ASSERT_EQ(YGFlexDirectionColumn, YGNodeStyleGetFlexDirection(node0)); - ASSERT_FALSE(YGNodeStyleGetMaxHeight(node0).unit != YGUnitUndefined); - - const YGNodeRef node1 = YGNodeNew(); - YGNodeStyleSetFlexDirection(node1, YGFlexDirectionRow); - YGNodeStyleSetMaxHeight(node1, 10); - - YGNodeCopyStyle(node0, node1); - ASSERT_TRUE(node0->isDirty()); - ASSERT_EQ(YGFlexDirectionRow, YGNodeStyleGetFlexDirection(node0)); - ASSERT_FLOAT_EQ(10, YGNodeStyleGetMaxHeight(node0).value); - - 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(node0->isDirty()); - - const YGNodeRef node1 = YGNodeNew(); - YGNodeStyleSetFlexDirection(node1, YGFlexDirectionRow); - YGNodeStyleSetMaxHeight(node1, 10); - - YGNodeCopyStyle(node0, node1); - ASSERT_FALSE(node0->isDirty()); - - YGNodeFree(node0); - YGNodeFree(node1); -} diff --git a/core-tests/YGZeroOutLayoutRecursivlyTest.cpp b/core-tests/YGZeroOutLayoutRecursivlyTest.cpp deleted file mode 100644 index 92e7c8a0..00000000 --- a/core-tests/YGZeroOutLayoutRecursivlyTest.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include -#include - -TEST(YogaTest, zero_out_layout) { - const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); - YGNodeStyleSetWidth(root, 200); - YGNodeStyleSetHeight(root, 200); - - const YGNodeRef child = YGNodeNew(); - YGNodeInsertChild(root, child, 0); - YGNodeStyleSetWidth(child, 100); - YGNodeStyleSetHeight(child, 100); - YGNodeStyleSetMargin(child, YGEdgeTop, 10); - YGNodeStyleSetPadding(child, YGEdgeTop, 10); - - YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR); - - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetMargin(child, YGEdgeTop)); - ASSERT_FLOAT_EQ(10, YGNodeLayoutGetPadding(child, YGEdgeTop)); - - YGNodeStyleSetDisplay(child, YGDisplayNone); - - YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetMargin(child, YGEdgeTop)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetPadding(child, YGEdgeTop)); - - YGNodeFreeRecursive(root); -} diff --git a/docs/1.1/Classes/Flex.html b/docs/1.1/Classes/Flex.html index 69715090..733b15ec 100644 --- a/docs/1.1/Classes/Flex.html +++ b/docs/1.1/Classes/Flex.html @@ -117,7 +117,7 @@

Declaration

@@ -147,7 +147,7 @@

Declaration

@@ -192,7 +192,7 @@

Return Value

The added view flex interface

@@ -246,7 +246,7 @@

Return Value

The added view flex interface

@@ -301,7 +301,7 @@

Return Value

Flex interface

@@ -361,7 +361,7 @@

Parameters

@@ -392,7 +392,7 @@

Declaration

@@ -446,7 +446,7 @@

Return Value

@@ -484,7 +484,7 @@

Return Value

Flex interface

@@ -537,7 +537,7 @@

Return Value

item size

@@ -604,7 +604,7 @@

Parameters

@@ -653,7 +653,7 @@

Parameters

@@ -708,7 +708,7 @@

Return Value

@@ -770,7 +770,7 @@

Parameters

@@ -821,7 +821,7 @@

Parameters

@@ -872,7 +872,7 @@

Parameters

@@ -922,7 +922,7 @@

Parameters

@@ -984,7 +984,7 @@

Parameters

@@ -1040,7 +1040,7 @@

Parameters

@@ -1093,7 +1093,7 @@

Parameters

@@ -1134,7 +1134,7 @@

Declaration

@@ -1165,7 +1165,7 @@

Declaration

@@ -1195,7 +1195,7 @@

Declaration

@@ -1226,7 +1226,7 @@

Declaration

@@ -1256,7 +1256,7 @@

Declaration

@@ -1286,7 +1286,7 @@

Declaration

@@ -1316,7 +1316,7 @@

Declaration

@@ -1346,7 +1346,7 @@

Declaration

@@ -1376,7 +1376,7 @@

Declaration

@@ -1406,7 +1406,7 @@

Declaration

@@ -1436,7 +1436,7 @@

Declaration

@@ -1466,7 +1466,7 @@

Declaration

@@ -1496,7 +1496,7 @@

Declaration

@@ -1526,7 +1526,7 @@

Declaration

@@ -1581,7 +1581,7 @@

Return Value

@@ -1636,7 +1636,7 @@

Return Value

@@ -1696,7 +1696,7 @@

Parameters

@@ -1726,7 +1726,7 @@

Declaration

@@ -1756,7 +1756,7 @@

Declaration

@@ -1786,7 +1786,7 @@

Declaration

@@ -1816,7 +1816,7 @@

Declaration

@@ -1846,7 +1846,7 @@

Declaration

@@ -1876,7 +1876,7 @@

Declaration

@@ -1917,7 +1917,7 @@

Declaration

@@ -1947,7 +1947,7 @@

Declaration

@@ -1977,7 +1977,7 @@

Declaration

@@ -2007,7 +2007,7 @@

Declaration

@@ -2037,7 +2037,7 @@

Declaration

@@ -2067,7 +2067,7 @@

Declaration

@@ -2097,7 +2097,7 @@

Declaration

@@ -2127,7 +2127,7 @@

Declaration

@@ -2164,7 +2164,7 @@

Declaration

@@ -2194,7 +2194,7 @@

Declaration

@@ -2231,7 +2231,7 @@

Declaration

@@ -2261,7 +2261,7 @@

Declaration

@@ -2291,7 +2291,7 @@

Declaration

@@ -2321,7 +2321,7 @@

Declaration

@@ -2351,7 +2351,7 @@

Declaration

@@ -2381,7 +2381,7 @@

Declaration

@@ -2412,7 +2412,7 @@

Declaration

@@ -2442,7 +2442,7 @@

Declaration

@@ -2472,7 +2472,7 @@

Declaration

@@ -2502,7 +2502,7 @@

Declaration

@@ -2532,7 +2532,7 @@

Declaration

@@ -2573,7 +2573,7 @@

Declaration

@@ -2603,7 +2603,7 @@

Declaration

@@ -2633,7 +2633,7 @@

Declaration

@@ -2663,7 +2663,7 @@

Declaration

@@ -2700,7 +2700,7 @@

Declaration

@@ -2737,7 +2737,7 @@

Declaration

@@ -2767,7 +2767,7 @@

Declaration

@@ -2797,7 +2797,7 @@

Declaration

@@ -2828,7 +2828,7 @@

Declaration

@@ -2858,7 +2858,7 @@

Declaration

@@ -2888,7 +2888,7 @@

Declaration

@@ -2952,7 +2952,7 @@

Return Value

flex interface

@@ -2993,7 +2993,7 @@

Declaration

@@ -3023,7 +3023,7 @@

Declaration

@@ -3053,7 +3053,7 @@

Declaration

@@ -3083,7 +3083,7 @@

Declaration

@@ -3113,7 +3113,7 @@

Declaration

@@ -3143,7 +3143,7 @@

Declaration

@@ -3173,7 +3173,7 @@

Declaration

@@ -3203,7 +3203,7 @@

Declaration

@@ -3234,7 +3234,7 @@

Declaration

diff --git a/docs/1.1/Classes/Flex/AlignContent.html b/docs/1.1/Classes/Flex/AlignContent.html index 456f4e8b..a91cd4a7 100644 --- a/docs/1.1/Classes/Flex/AlignContent.html +++ b/docs/1.1/Classes/Flex/AlignContent.html @@ -105,7 +105,7 @@

Declaration

@@ -139,7 +139,7 @@

Declaration

@@ -173,7 +173,7 @@

Declaration

@@ -207,7 +207,7 @@

Declaration

@@ -241,7 +241,7 @@

Declaration

@@ -275,7 +275,7 @@

Declaration

diff --git a/docs/1.1/Classes/Flex/AlignItems.html b/docs/1.1/Classes/Flex/AlignItems.html index 40d9ed76..6799f0f9 100644 --- a/docs/1.1/Classes/Flex/AlignItems.html +++ b/docs/1.1/Classes/Flex/AlignItems.html @@ -105,7 +105,7 @@

Declaration

@@ -139,7 +139,7 @@

Declaration

@@ -173,7 +173,7 @@

Declaration

@@ -207,7 +207,7 @@

Declaration

@@ -241,7 +241,7 @@

Declaration

diff --git a/docs/1.1/Classes/Flex/AlignSelf.html b/docs/1.1/Classes/Flex/AlignSelf.html index a080153d..3e2d313f 100644 --- a/docs/1.1/Classes/Flex/AlignSelf.html +++ b/docs/1.1/Classes/Flex/AlignSelf.html @@ -105,7 +105,7 @@

Declaration

@@ -139,7 +139,7 @@

Declaration

@@ -173,7 +173,7 @@

Declaration

@@ -207,7 +207,7 @@

Declaration

@@ -241,7 +241,7 @@

Declaration

@@ -275,7 +275,7 @@

Declaration

diff --git a/docs/1.1/Classes/Flex/Direction.html b/docs/1.1/Classes/Flex/Direction.html index 7e0c09b8..1a8323cf 100644 --- a/docs/1.1/Classes/Flex/Direction.html +++ b/docs/1.1/Classes/Flex/Direction.html @@ -105,7 +105,7 @@

Declaration

@@ -139,7 +139,7 @@

Declaration

@@ -173,7 +173,7 @@

Declaration

@@ -207,7 +207,7 @@

Declaration

diff --git a/docs/1.1/Classes/Flex/JustifyContent.html b/docs/1.1/Classes/Flex/JustifyContent.html index 65148394..97e73731 100644 --- a/docs/1.1/Classes/Flex/JustifyContent.html +++ b/docs/1.1/Classes/Flex/JustifyContent.html @@ -105,7 +105,7 @@

Declaration

@@ -139,7 +139,7 @@

Declaration

@@ -173,7 +173,7 @@

Declaration

@@ -207,7 +207,7 @@

Declaration

@@ -241,7 +241,7 @@

Declaration

diff --git a/docs/1.1/Classes/Flex/LayoutDirection.html b/docs/1.1/Classes/Flex/LayoutDirection.html index bd7d188a..a42bc113 100644 --- a/docs/1.1/Classes/Flex/LayoutDirection.html +++ b/docs/1.1/Classes/Flex/LayoutDirection.html @@ -105,7 +105,7 @@

Declaration

@@ -139,7 +139,7 @@

Declaration

@@ -173,7 +173,7 @@

Declaration

diff --git a/docs/1.1/Classes/Flex/LayoutMode.html b/docs/1.1/Classes/Flex/LayoutMode.html index a32648ff..16c7bc94 100644 --- a/docs/1.1/Classes/Flex/LayoutMode.html +++ b/docs/1.1/Classes/Flex/LayoutMode.html @@ -106,7 +106,7 @@

Declaration

@@ -140,7 +140,7 @@

Declaration

@@ -174,7 +174,7 @@

Declaration

diff --git a/docs/1.1/Classes/Flex/Position.html b/docs/1.1/Classes/Flex/Position.html index 0d7fbc86..d51f6d03 100644 --- a/docs/1.1/Classes/Flex/Position.html +++ b/docs/1.1/Classes/Flex/Position.html @@ -93,7 +93,7 @@

Position

-

Default value.

+

Default value. Positioned according to the flex container's flow. The item is positioned using Insets properties (top, bottom, left, right, start, end) from its normal position within its flex container and will take up space within the flex container. This node will always form a containing block.

@@ -105,7 +105,7 @@

Declaration

@@ -127,7 +127,7 @@

Declaration

-

Positioned absolutely in regards to its container. The item is positionned using properties top, bottom, left, right, start, end.

+

Positioned absolutely, removed from the flex container's flow. The item is positioned using Insets properties (top, bottom, left, right, start, end). Insets will offset the node from its containing block.

@@ -139,7 +139,41 @@

Declaration

+
+ + + + +
+
    +
  • +
    + + + + static + +
    +
    +
    +
    +
    +
    +

    Positioned like relative but ignores insets and will not form a containing block.

    + +
    +
    +

    Declaration

    +
    +

    Swift

    +
    case static
    + +
    +
    +
    diff --git a/docs/1.1/Classes/Flex/Wrap.html b/docs/1.1/Classes/Flex/Wrap.html index 0be1ad12..cab08472 100644 --- a/docs/1.1/Classes/Flex/Wrap.html +++ b/docs/1.1/Classes/Flex/Wrap.html @@ -105,7 +105,7 @@

    Declaration

@@ -139,7 +139,7 @@

Declaration

@@ -173,7 +173,7 @@

Declaration

diff --git a/docs_markdown/examples.md b/docs_markdown/examples.md index ef21e413..bdb6c85d 100644 --- a/docs_markdown/examples.md +++ b/docs_markdown/examples.md @@ -7,10 +7,20 @@ The FlexLayout's Example exposes some usage example of FlexLayout. -The Example App is available in the [`Example`](https://github.com/layoutBox/FlexLayout/tree/master/Example) folder. +The Example App is available in 2 versions: -### Running the Example app -1. Do a `pod install` from the FlexLayout root directory. +* [SPM (using Swift Package Manager)](https://github.com/layoutBox/FlexLayout/tree/master/Example/SPM) +* [Cocoapods](https://github.com/layoutBox/FlexLayout/tree/master/Example/cocoapods) + +### Running the SPM (Swift Package Manager) Example app +1. Open the Xcode project `Example/SPM/FlexLayoutSample-SPM.xcodeproj`. +3. Select the `FlexLayoutSample-SPM` target. +4. Run the app on your device or simulator. + +
+ +### Running the Cocoapods Example app +1. Do a `pod install` from the `Example/cocoapods` directory. 2. Open the newly generated `FlexLayout.xcworkspace` Xcode workspace. 3. Select the `FlexLayoutSample` target. 4. Run the app on your device or simulator. diff --git a/fastlane/Fastfile b/fastlane/Fastfile index a93c34d3..5a2f0122 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -6,7 +6,7 @@ # This is the minimum version number required. # Update this, if you use features of a newer version -fastlane_version "2.29.0" +fastlane_version '2.29.0' default_platform :ios skip_docs @@ -15,92 +15,87 @@ platform :ios do before_all do end + DEVICE_NAME = 'iPhone 17' + DESTINATION = "platform=iOS Simulator,name=#{DEVICE_NAME}" + lane :install do bundle_install + cocoapods( use_bundle_exec: true, try_repo_update_on_error: true ) - - #carthage( - # command: "bootstrap", - # use_ssh: true, - # platform: "iOS", - #) end lane :build do - install - - #Dir.chdir("..") do - swiftlint( - mode: :lint, - config_file: ".swiftlint.yml", - executable: "Pods/SwiftLint/swiftlint", - ignore_exit_status: true - ) - #end + swiftlint( + mode: :lint, + config_file: '.swiftlint.yml', + executable: 'Pods/SwiftLint/swiftlint', + ignore_exit_status: true + ) + # FlexLayout xcodebuild( - project: "FlexLayout.xcodeproj", - scheme: "FlexLayout", - configuration: "Release", + workspace: 'FlexLayout.xcworkspace', + scheme: 'FlexLayoutInner', + configuration: 'Release', build: true, clean: true, - destination: "platform=iOS Simulator,name=iPhone 8,OS=15.2" + destination: DESTINATION ) - #xcodebuild( - # workspace: "FlexLayout.xcworkspace", - # scheme: "FlexLayoutTVOS", - # configuration: "Release", - # build: true, - # clean: true - # destination: "platform=iOS Simulator,name=iPhone X,OS=15.2" - #) + # FlexLayoutSample from FlexLayout.xcworkspace + xcodebuild( + workspace: 'FlexLayout.xcworkspace', + scheme: 'FlexLayoutSample', + configuration: 'Release', + build: true, + # clean: true, + destination: DESTINATION + ) + # Example SPM (Swift Package Manager) xcodebuild( - workspace: "FlexLayout.xcworkspace", - scheme: "FlexLayoutSample", - configuration: "Release", + project: 'Example/SPM/FlexLayoutSample-SPM.xcodeproj', + scheme: 'FlexLayoutSample-SPM', + configuration: 'Release', build: true, clean: true, - destination: "platform=iOS Simulator,name=iPhone 8,OS=15.2" + destination: DESTINATION ) end lane :tests do - # sh "buck test :yoga " - scan(scheme: "FlexLayoutSample", - workspace: "FlexLayout.xcworkspace") + scan(scheme: 'FlexLayoutInner', workspace: 'FlexLayout.xcworkspace', device: DEVICE_NAME) end - lane :doc do + lane :doc do jazzy end lane :travis do - build + install tests - #pod_lib_lint(allow_warnings: true, verbose: false) + build + # pod_lib_lint(allow_warnings: true, verbose: false) end lane :deploy do ensure_git_branch - version = version_bump_podspec(path: "FlexLayout.podspec") - git_commit(path: ["./FlexLayout.podspec"], message: "Bumped to version #{version}") + version = version_bump_podspec(path: 'FlexLayout.podspec') + git_commit(path: ['./FlexLayout.podspec'], message: "Bumped to version #{version}") push_to_git_remote(remote_branch: 'master', force: false, tags: true) changelog = changelog_from_git_commits github_release = set_github_release( - repository_name: "layoutBox/FlexLayout", + repository_name: 'layoutBox/FlexLayout', api_token: ENV['GITHUB_TOKEN'], name: version, tag_name: version, description: changelog, - commitish: "master" + commitish: 'master' ) - sh("git fetch --tags") + sh('git fetch --tags') pod_push(allow_warnings: true, verbose: true) end - end diff --git a/lib/fb/BUCK b/lib/fb/BUCK deleted file mode 100644 index 50077d2e..00000000 --- a/lib/fb/BUCK +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright (c) 2014-present, Facebook, Inc. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -include_defs("//yoga_defs.bzl") - -prebuilt_cxx_library( - name = "ndklog", - exported_platform_linker_flags = [ - ( - "^android.*", - ["-llog"], - ), - ], - header_only = True, - visibility = YOGA_ROOTS, -) - -cxx_library( - name = "fbjni", - srcs = glob(["src/main/cpp/**/*.cpp"]), - header_namespace = "", - exported_headers = subdir_glob([("src/main/cpp/include", "**/*.h")]), - compiler_flags = [ - "-DLOG_TAG=\"libfb\"", - "-DDISABLE_CPUCAP", - "-DDISABLE_XPLAT", - "-DHAVE_POSIX_CLOCKS", - "-fno-omit-frame-pointer", - "-fexceptions", - "-frtti", - "-Wall", - "-Werror", - "-Wno-unused-parameter", - "-std=c++11", - ], - visibility = ["PUBLIC"], - deps = [ - ":ndklog", - FBJNI_JAVA_TARGET, - JNI_TARGET, - ], -) diff --git a/lib/fb/build.gradle b/lib/fb/build.gradle deleted file mode 100644 index 7a419b0b..00000000 --- a/lib/fb/build.gradle +++ /dev/null @@ -1,33 +0,0 @@ -apply plugin: 'com.android.library' - -android { - compileSdkVersion rootProject.compileSdkVersion - buildToolsVersion rootProject.buildToolsVersion - - defaultConfig { - minSdkVersion rootProject.minSdkVersion - targetSdkVersion rootProject.targetSdkVersion - - ndk { - abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a' - } - - externalNativeBuild { - cmake { - arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=c++_static' - } - } - } - - externalNativeBuild { - cmake { - path 'src/main/cpp/CMakeLists.txt' - } - } - - dependencies { - implementation 'com.facebook.soloader:soloader:0.2.0' - compileOnly 'com.google.code.findbugs:jsr305:3.0.1' - compileOnly project(':yoga:proguard-annotations') - } -} diff --git a/lib/fb/src/main/AndroidManifest.xml b/lib/fb/src/main/AndroidManifest.xml deleted file mode 100644 index fb03ab18..00000000 --- a/lib/fb/src/main/AndroidManifest.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - diff --git a/lib/fb/src/main/cpp/CMakeLists.txt b/lib/fb/src/main/cpp/CMakeLists.txt deleted file mode 100644 index 59cc2b72..00000000 --- a/lib/fb/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -# -# Copyright (c) 2014-present, Facebook, Inc. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. -# - -cmake_minimum_required(VERSION 3.4.1) - -set(CMAKE_VERBOSE_MAKEFILE on) - -add_compile_options( - -fno-omit-frame-pointer - -fexceptions - -Wall - -std=c++11 - -DDISABLE_CPUCAP - -DDISABLE_XPLAT) - -file(GLOB fb_SRC - *.cpp - jni/*.cpp - lyra/*.cpp) - -add_library(fb SHARED - ${fb_SRC}) - -target_include_directories(fb PRIVATE - include) - -target_link_libraries(fb android log) diff --git a/lib/fb/src/main/cpp/Doxyfile b/lib/fb/src/main/cpp/Doxyfile deleted file mode 100644 index b44118dd..00000000 --- a/lib/fb/src/main/cpp/Doxyfile +++ /dev/null @@ -1,15 +0,0 @@ -PROJECT_NAME = "Facebook Android Support" -JAVADOC_AUTOBRIEF = YES -EXTRACT_ALL = YES -RECURSIVE = YES -EXCLUDE = tests -EXCLUDE_PATTERNS = *.cpp -GENERATE_HTML = YES -GENERATE_LATEX = NO -ENABLE_PREPROCESSING = YES -HIDE_UNDOC_MEMBERS = YES -HIDE_SCOPE_NAMES = YES -HIDE_FRIEND_COMPOUNDS = YES -HIDE_UNDOC_CLASSES = YES -SHOW_INCLUDE_FILES = NO -#ENABLED_SECTIONS = INTERNAL diff --git a/lib/fb/src/main/cpp/assert.cpp b/lib/fb/src/main/cpp/assert.cpp deleted file mode 100644 index d39c29e4..00000000 --- a/lib/fb/src/main/cpp/assert.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include -#include - -#include -#include - -namespace facebook { - -#define ASSERT_BUF_SIZE 4096 -static char sAssertBuf[ASSERT_BUF_SIZE]; -static AssertHandler gAssertHandler; - -void assertInternal(const char* formatstr ...) { - va_list va_args; - va_start(va_args, formatstr); - vsnprintf(sAssertBuf, sizeof(sAssertBuf), formatstr, va_args); - va_end(va_args); - if (gAssertHandler != NULL) { - gAssertHandler(sAssertBuf); - } - FBLOG(LOG_FATAL, "fbassert", "%s", sAssertBuf); - // crash at this specific address so that we can find our crashes easier - *(int*)0xdeadb00c = 0; - // let the compiler know we won't reach the end of the function - __builtin_unreachable(); -} - -void setAssertHandler(AssertHandler assertHandler) { - gAssertHandler = assertHandler; -} - -} // namespace facebook diff --git a/lib/fb/src/main/cpp/include/fb/ALog.h b/lib/fb/src/main/cpp/include/fb/ALog.h deleted file mode 100644 index 5f231cb7..00000000 --- a/lib/fb/src/main/cpp/include/fb/ALog.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -/** @file ALog.h - * - * Very simple android only logging. Define LOG_TAG to enable the macros. - */ - -#pragma once - -#ifdef __ANDROID__ - -#include - -namespace facebook { -namespace alog { - -template -inline void log(int level, const char* tag, const char* msg, ARGS... args) noexcept { - __android_log_print(level, tag, msg, args...); -} - -template -inline void log(int level, const char* tag, const char* msg) noexcept { - __android_log_write(level, tag, msg); -} - -template -inline void logv(const char* tag, const char* msg, ARGS... args) noexcept { - log(ANDROID_LOG_VERBOSE, tag, msg, args...); -} - -template -inline void logd(const char* tag, const char* msg, ARGS... args) noexcept { - log(ANDROID_LOG_DEBUG, tag, msg, args...); -} - -template -inline void logi(const char* tag, const char* msg, ARGS... args) noexcept { - log(ANDROID_LOG_INFO, tag, msg, args...); -} - -template -inline void logw(const char* tag, const char* msg, ARGS... args) noexcept { - log(ANDROID_LOG_WARN, tag, msg, args...); -} - -template -inline void loge(const char* tag, const char* msg, ARGS... args) noexcept { - log(ANDROID_LOG_ERROR, tag, msg, args...); -} - -template -inline void logf(const char* tag, const char* msg, ARGS... args) noexcept { - log(ANDROID_LOG_FATAL, tag, msg, args...); -} - - -#ifdef LOG_TAG -# define ALOGV(...) ::facebook::alog::logv(LOG_TAG, __VA_ARGS__) -# define ALOGD(...) ::facebook::alog::logd(LOG_TAG, __VA_ARGS__) -# define ALOGI(...) ::facebook::alog::logi(LOG_TAG, __VA_ARGS__) -# define ALOGW(...) ::facebook::alog::logw(LOG_TAG, __VA_ARGS__) -# define ALOGE(...) ::facebook::alog::loge(LOG_TAG, __VA_ARGS__) -# define ALOGF(...) ::facebook::alog::logf(LOG_TAG, __VA_ARGS__) -#endif - -}} - -#else -# define ALOGV(...) ((void)0) -# define ALOGD(...) ((void)0) -# define ALOGI(...) ((void)0) -# define ALOGW(...) ((void)0) -# define ALOGE(...) ((void)0) -# define ALOGF(...) ((void)0) -#endif diff --git a/lib/fb/src/main/cpp/include/fb/Countable.h b/lib/fb/src/main/cpp/include/fb/Countable.h deleted file mode 100644 index 1fafba36..00000000 --- a/lib/fb/src/main/cpp/include/fb/Countable.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once -#include -#include -#include -#include -#include - -namespace facebook { - -class Countable : public noncopyable, public nonmovable { -public: - // RefPtr expects refcount to start at 0 - Countable() : m_refcount(0) {} - virtual ~Countable() - { - FBASSERT(m_refcount == 0); - } - -private: - void ref() { - ++m_refcount; - } - - void unref() { - if (0 == --m_refcount) { - delete this; - } - } - - bool hasOnlyOneRef() const { - return m_refcount == 1; - } - - template friend class RefPtr; - std::atomic m_refcount; -}; - -} diff --git a/lib/fb/src/main/cpp/include/fb/Doxyfile b/lib/fb/src/main/cpp/include/fb/Doxyfile deleted file mode 100644 index 8b4df6a7..00000000 --- a/lib/fb/src/main/cpp/include/fb/Doxyfile +++ /dev/null @@ -1,18 +0,0 @@ -PROJECT_NAME = "Facebook JNI" -PROJECT_BRIEF = "Helper library to provide safe and convenient access to JNI with very low overhead" -JAVADOC_AUTOBRIEF = YES -EXTRACT_ALL = YES -RECURSIVE = YES -EXCLUDE = tests Asserts.h Countable.h GlobalReference.h LocalReference.h LocalString.h Registration.h WeakReference.h jni_helpers.h Environment.h -EXCLUDE_PATTERNS = *-inl.h *.cpp -GENERATE_HTML = YES -GENERATE_LATEX = NO -ENABLE_PREPROCESSING = YES -HIDE_UNDOC_MEMBERS = YES -HIDE_SCOPE_NAMES = YES -HIDE_FRIEND_COMPOUNDS = YES -HIDE_UNDOC_CLASSES = YES -SHOW_INCLUDE_FILES = NO -PREDEFINED = LOG_TAG=fbjni -EXAMPLE_PATH = samples -#ENABLED_SECTIONS = INTERNAL diff --git a/lib/fb/src/main/cpp/include/fb/Environment.h b/lib/fb/src/main/cpp/include/fb/Environment.h deleted file mode 100644 index e63db9cb..00000000 --- a/lib/fb/src/main/cpp/include/fb/Environment.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once -#include -#include -#include - -#include - -namespace facebook { -namespace jni { - -// Keeps a thread-local reference to the current thread's JNIEnv. -struct Environment { - // May be null if this thread isn't attached to the JVM - FBEXPORT static JNIEnv* current(); - static void initialize(JavaVM* vm); - - // There are subtle issues with calling the next functions directly. It is - // much better to always use a ThreadScope to manage attaching/detaching for - // you. - FBEXPORT static JNIEnv* ensureCurrentThreadIsAttached(); - FBEXPORT static void detachCurrentThread(); -}; - -/** - * RAII Object that attaches a thread to the JVM. Failing to detach from a thread before it - * exits will cause a crash, as will calling Detach an extra time, and this guard class helps - * keep that straight. In addition, it remembers whether it performed the attach or not, so it - * is safe to nest it with itself or with non-fbjni code that manages the attachment correctly. - * - * Potential concerns: - * - Attaching to the JVM is fast (~100us on MotoG), but ideally you would attach while the - * app is not busy. - * - Having a thread detach at arbitrary points is not safe in Dalvik; you need to be sure that - * there is no Java code on the current stack or you run the risk of a crash like: - * ERROR: detaching thread with interp frames (count=18) - * (More detail at https://groups.google.com/forum/#!topic/android-ndk/2H8z5grNqjo) - * ThreadScope won't do a detach if the thread was already attached before the guard is - * instantiated, but there's probably some usage that could trip this up. - * - Newly attached C++ threads only get the bootstrap class loader -- i.e. java language - * classes, not any of our application's classes. This will be different behavior than threads - * that were initiated on the Java side. A workaround is to pass a global reference for a - * class or instance to the new thread; this bypasses the need for the class loader. - * (See http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/invocation.html#attach_current_thread) - * If you need access to the application's classes, you can use ThreadScope::WithClassLoader. - */ -class FBEXPORT ThreadScope { - public: - ThreadScope(); - ThreadScope(ThreadScope&) = delete; - ThreadScope(ThreadScope&&) = default; - ThreadScope& operator=(ThreadScope&) = delete; - ThreadScope& operator=(ThreadScope&&) = delete; - ~ThreadScope(); - - /** - * This runs the closure in a scope with fbjni's classloader. This should be - * the same classloader as the rest of the application and thus anything - * running in the closure will have access to the same classes as in a normal - * java-create thread. - */ - static void WithClassLoader(std::function&& runnable); - - static void OnLoad(); - private: - bool attachedWithThisScope_; -}; -} -} diff --git a/lib/fb/src/main/cpp/include/fb/ProgramLocation.h b/lib/fb/src/main/cpp/include/fb/ProgramLocation.h deleted file mode 100644 index 92b45406..00000000 --- a/lib/fb/src/main/cpp/include/fb/ProgramLocation.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once -#include -#include -#include - -namespace facebook { - -#define FROM_HERE facebook::ProgramLocation(__FUNCTION__, __FILE__, __LINE__) - -class ProgramLocation { -public: - ProgramLocation() : m_functionName("Unspecified"), m_fileName("Unspecified"), m_lineNumber(0) {} - - ProgramLocation(const char* functionName, const char* fileName, int line) : - m_functionName(functionName), - m_fileName(fileName), - m_lineNumber(line) - {} - - const char* functionName() const { return m_functionName; } - const char* fileName() const { return m_fileName; } - int lineNumber() const { return m_lineNumber; } - - std::string asFormattedString() const { - std::stringstream str; - str << "Function " << m_functionName << " in file " << m_fileName << ":" << m_lineNumber; - return str.str(); - } - - bool operator==(const ProgramLocation& other) const { - // Assumes that the strings are static - return (m_functionName == other.m_functionName) && (m_fileName == other.m_fileName) && m_lineNumber == other.m_lineNumber; - } - -private: - const char* m_functionName; - const char* m_fileName; - int m_lineNumber; -}; - -} diff --git a/lib/fb/src/main/cpp/include/fb/RefPtr.h b/lib/fb/src/main/cpp/include/fb/RefPtr.h deleted file mode 100644 index ee19960f..00000000 --- a/lib/fb/src/main/cpp/include/fb/RefPtr.h +++ /dev/null @@ -1,272 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once -#include -#include - -namespace facebook { - -// Reference counting smart pointer. This is designed to work with the -// Countable class or other implementations in the future. It is designed in a -// way to be both efficient and difficult to misuse. Typical usage is very -// simple once you learn the patterns (and the compiler will help!): -// -// By default, the internal pointer is null. -// RefPtr ref; -// -// Object creation requires explicit construction: -// RefPtr ref = createNew(...); -// -// Or if the constructor is not public: -// RefPtr ref = adoptRef(new Foo(...)); -// -// But you can implicitly create from nullptr: -// RefPtr maybeRef = cond ? ref : nullptr; -// -// Move/Copy Construction/Assignment are straightforward: -// RefPtr ref2 = ref; -// ref = std::move(ref2); -// -// Destruction automatically drops the RefPtr's reference as expected. -// -// Upcasting is implicit but downcasting requires an explicit cast: -// struct Bar : public Foo {}; -// RefPtr barRef = static_cast>(ref); -// ref = barRef; -// -template -class RefPtr { -public: - constexpr RefPtr() : - m_ptr(nullptr) - {} - - // Allow implicit construction from a pointer only from nullptr - constexpr RefPtr(std::nullptr_t ptr) : - m_ptr(nullptr) - {} - - RefPtr(const RefPtr& ref) : - m_ptr(ref.m_ptr) - { - refIfNecessary(m_ptr); - } - - // Only allow implicit upcasts. A downcast will result in a compile error - // unless you use static_cast (which will end up invoking the explicit - // operator below). - template - RefPtr(const RefPtr& ref, typename std::enable_if::value, U>::type* = nullptr) : - m_ptr(ref.get()) - { - refIfNecessary(m_ptr); - } - - RefPtr(RefPtr&& ref) : - m_ptr(nullptr) - { - *this = std::move(ref); - } - - // Only allow implicit upcasts. A downcast will result in a compile error - // unless you use static_cast (which will end up invoking the explicit - // operator below). - template - RefPtr(RefPtr&& ref, typename std::enable_if::value, U>::type* = nullptr) : - m_ptr(nullptr) - { - *this = std::move(ref); - } - - ~RefPtr() { - unrefIfNecessary(m_ptr); - m_ptr = nullptr; - } - - RefPtr& operator=(const RefPtr& ref) { - if (m_ptr != ref.m_ptr) { - unrefIfNecessary(m_ptr); - m_ptr = ref.m_ptr; - refIfNecessary(m_ptr); - } - return *this; - } - - // The STL assumes rvalue references are unique and for simplicity's sake, we - // make the same assumption here, that &ref != this. - RefPtr& operator=(RefPtr&& ref) { - unrefIfNecessary(m_ptr); - m_ptr = ref.m_ptr; - ref.m_ptr = nullptr; - return *this; - } - - template - RefPtr& operator=(RefPtr&& ref) { - unrefIfNecessary(m_ptr); - m_ptr = ref.m_ptr; - ref.m_ptr = nullptr; - return *this; - } - - void reset() { - unrefIfNecessary(m_ptr); - m_ptr = nullptr; - } - - T* get() const { - return m_ptr; - } - - T* operator->() const { - return m_ptr; - } - - T& operator*() const { - return *m_ptr; - } - - template - explicit operator RefPtr () const; - - explicit operator bool() const { - return m_ptr ? true : false; - } - - bool isTheLastRef() const { - FBASSERT(m_ptr); - return m_ptr->hasOnlyOneRef(); - } - - // Creates a strong reference from a raw pointer, assuming that is already - // referenced from some other RefPtr. This should be used sparingly. - static inline RefPtr assumeAlreadyReffed(T* ptr) { - return RefPtr(ptr, ConstructionMode::External); - } - - // Creates a strong reference from a raw pointer, assuming that it points to a - // freshly-created object. See the documentation for RefPtr for usage. - static inline RefPtr adoptRef(T* ptr) { - return RefPtr(ptr, ConstructionMode::Adopted); - } - -private: - enum class ConstructionMode { - Adopted, - External - }; - - RefPtr(T* ptr, ConstructionMode mode) : - m_ptr(ptr) - { - FBASSERTMSGF(ptr, "Got null pointer in %s construction mode", mode == ConstructionMode::Adopted ? "adopted" : "external"); - ptr->ref(); - if (mode == ConstructionMode::Adopted) { - FBASSERT(ptr->hasOnlyOneRef()); - } - } - - static inline void refIfNecessary(T* ptr) { - if (ptr) { - ptr->ref(); - } - } - static inline void unrefIfNecessary(T* ptr) { - if (ptr) { - ptr->unref(); - } - } - - template friend class RefPtr; - - T* m_ptr; -}; - -// Creates a strong reference from a raw pointer, assuming that is already -// referenced from some other RefPtr and that it is non-null. This should be -// used sparingly. -template -static inline RefPtr assumeAlreadyReffed(T* ptr) { - return RefPtr::assumeAlreadyReffed(ptr); -} - -// As above, but tolerant of nullptr. -template -static inline RefPtr assumeAlreadyReffedOrNull(T* ptr) { - return ptr ? RefPtr::assumeAlreadyReffed(ptr) : nullptr; -} - -// Creates a strong reference from a raw pointer, assuming that it points to a -// freshly-created object. See the documentation for RefPtr for usage. -template -static inline RefPtr adoptRef(T* ptr) { - return RefPtr::adoptRef(ptr); -} - -template -static inline RefPtr createNew(Args&&... arguments) { - return RefPtr::adoptRef(new T(std::forward(arguments)...)); -} - -template template -RefPtr::operator RefPtr() const { - static_assert(std::is_base_of::value, "Invalid static cast"); - return assumeAlreadyReffedOrNull(static_cast(m_ptr)); -} - -template -inline bool operator==(const RefPtr& a, const RefPtr& b) { - return a.get() == b.get(); -} - -template -inline bool operator!=(const RefPtr& a, const RefPtr& b) { - return a.get() != b.get(); -} - -template -inline bool operator==(const RefPtr& ref, U* ptr) { - return ref.get() == ptr; -} - -template -inline bool operator!=(const RefPtr& ref, U* ptr) { - return ref.get() != ptr; -} - -template -inline bool operator==(U* ptr, const RefPtr& ref) { - return ref.get() == ptr; -} - -template -inline bool operator!=(U* ptr, const RefPtr& ref) { - return ref.get() != ptr; -} - -template -inline bool operator==(const RefPtr& ref, std::nullptr_t ptr) { - return ref.get() == ptr; -} - -template -inline bool operator!=(const RefPtr& ref, std::nullptr_t ptr) { - return ref.get() != ptr; -} - -template -inline bool operator==(std::nullptr_t ptr, const RefPtr& ref) { - return ref.get() == ptr; -} - -template -inline bool operator!=(std::nullptr_t ptr, const RefPtr& ref) { - return ref.get() != ptr; -} - -} diff --git a/lib/fb/src/main/cpp/include/fb/StaticInitialized.h b/lib/fb/src/main/cpp/include/fb/StaticInitialized.h deleted file mode 100644 index c5ecc2fe..00000000 --- a/lib/fb/src/main/cpp/include/fb/StaticInitialized.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once -#include -#include - -namespace facebook { - -// Class that lets you declare a global but does not add a static constructor -// to the binary. Eventually I'd like to have this auto-initialize in a -// multithreaded environment but for now it's easiest just to use manual -// initialization. -template -class StaticInitialized { -public: - constexpr StaticInitialized() : - m_instance(nullptr) - {} - - template - void initialize(Args&&... arguments) { - FBASSERT(!m_instance); - m_instance = new T(std::forward(arguments)...); - } - - T* operator->() const { - return m_instance; - } -private: - T* m_instance; -}; - -} diff --git a/lib/fb/src/main/cpp/include/fb/ThreadLocal.h b/lib/fb/src/main/cpp/include/fb/ThreadLocal.h deleted file mode 100644 index 1b868c44..00000000 --- a/lib/fb/src/main/cpp/include/fb/ThreadLocal.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include - -#include - -namespace facebook { - -/////////////////////////////////////////////////////////////////////////////// - -/** - * A thread-local object is a "global" object within a thread. This is useful - * for writing apartment-threaded code, where nothing is actullay shared - * between different threads (hence no locking) but those variables are not - * on stack in local scope. To use it, just do something like this, - * - * ThreadLocal static_object; - * static_object->data_ = ...; - * static_object->doSomething(); - * - * ThreadLocal static_number; - * int value = *static_number; - * - * So, syntax-wise it's similar to pointers. T can be primitive types, and if - * it's a class, there has to be a default constructor. - */ -template -class ThreadLocal { -public: - /** - * Constructor that has to be called from a thread-neutral place. - */ - ThreadLocal() : - m_key(0), - m_cleanup(OnThreadExit) { - initialize(); - } - - /** - * As above but with a custom cleanup function - */ - typedef void (*CleanupFunction)(void* obj); - explicit ThreadLocal(CleanupFunction cleanup) : - m_key(0), - m_cleanup(cleanup) { - FBASSERT(cleanup); - initialize(); - } - - /** - * Access object's member or method through this operator overload. - */ - T *operator->() const { - return get(); - } - - T &operator*() const { - return *get(); - } - - T *get() const { - return (T*)pthread_getspecific(m_key); - } - - T* release() { - T* obj = get(); - pthread_setspecific(m_key, NULL); - return obj; - } - - void reset(T* other = NULL) { - T* old = (T*)pthread_getspecific(m_key); - if (old != other) { - FBASSERT(m_cleanup); - m_cleanup(old); - pthread_setspecific(m_key, other); - } - } - -private: - void initialize() { - int ret = pthread_key_create(&m_key, m_cleanup); - if (ret != 0) { - const char *msg = "(unknown error)"; - switch (ret) { - case EAGAIN: - msg = "PTHREAD_KEYS_MAX (1024) is exceeded"; - break; - case ENOMEM: - msg = "Out-of-memory"; - break; - } - (void) msg; - FBASSERTMSGF(0, "pthread_key_create failed: %d %s", ret, msg); - } - } - - static void OnThreadExit(void *obj) { - if (NULL != obj) { - delete (T*)obj; - } - } - - pthread_key_t m_key; - CleanupFunction m_cleanup; -}; - -} diff --git a/lib/fb/src/main/cpp/include/fb/assert.h b/lib/fb/src/main/cpp/include/fb/assert.h deleted file mode 100644 index ea0c3f65..00000000 --- a/lib/fb/src/main/cpp/include/fb/assert.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#ifndef FBASSERT_H -#define FBASSERT_H - -#include - -namespace facebook { -#define ENABLE_FBASSERT 1 - -#if ENABLE_FBASSERT -#define FBASSERTMSGF(expr, msg, ...) !(expr) ? facebook::assertInternal("Assert (%s:%d): " msg, __FILE__, __LINE__, ##__VA_ARGS__) : (void) 0 -#else -#define FBASSERTMSGF(expr, msg, ...) -#endif // ENABLE_FBASSERT - -#define FBASSERT(expr) FBASSERTMSGF(expr, "%s", #expr) - -#define FBCRASH(msg, ...) facebook::assertInternal("Fatal error (%s:%d): " msg, __FILE__, __LINE__, ##__VA_ARGS__) -#define FBUNREACHABLE() facebook::assertInternal("This code should be unreachable (%s:%d)", __FILE__, __LINE__) - -FBEXPORT void assertInternal(const char* formatstr, ...) __attribute__((noreturn)); - -// This allows storing the assert message before the current process terminates due to a crash -typedef void (*AssertHandler)(const char* message); -void setAssertHandler(AssertHandler assertHandler); - -} // namespace facebook -#endif // FBASSERT_H diff --git a/lib/fb/src/main/cpp/include/fb/fbjni.h b/lib/fb/src/main/cpp/include/fb/fbjni.h deleted file mode 100644 index e67aa164..00000000 --- a/lib/fb/src/main/cpp/include/fb/fbjni.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include diff --git a/lib/fb/src/main/cpp/include/fb/fbjni/Boxed.h b/lib/fb/src/main/cpp/include/fb/fbjni/Boxed.h deleted file mode 100644 index b4799616..00000000 --- a/lib/fb/src/main/cpp/include/fb/fbjni/Boxed.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "CoreClasses.h" - -namespace facebook { -namespace jni { - -namespace detail { -template -struct JPrimitive : JavaClass { - using typename JavaClass::javaobject; - using JavaClass::javaClassStatic; - static local_ref valueOf(jprim val) { - static auto cls = javaClassStatic(); - static auto method = - cls->template getStaticMethod("valueOf"); - return method(cls, val); - } - jprim value() const { - static auto method = - javaClassStatic()->template getMethod(T::kValueMethod); - return method(this->self()); - } -}; - -} // namespace detail - - -#define DEFINE_BOXED_PRIMITIVE(LITTLE, BIG) \ - struct J ## BIG : detail::JPrimitive { \ - static auto constexpr kJavaDescriptor = "Ljava/lang/" #BIG ";"; \ - static auto constexpr kValueMethod = #LITTLE "Value"; \ - j ## LITTLE LITTLE ## Value() const { \ - return value(); \ - } \ - }; \ - inline local_ref autobox(j ## LITTLE val) { \ - return J ## BIG::valueOf(val); \ - } - -DEFINE_BOXED_PRIMITIVE(boolean, Boolean) -DEFINE_BOXED_PRIMITIVE(byte, Byte) -DEFINE_BOXED_PRIMITIVE(char, Character) -DEFINE_BOXED_PRIMITIVE(short, Short) -DEFINE_BOXED_PRIMITIVE(int, Integer) -DEFINE_BOXED_PRIMITIVE(long, Long) -DEFINE_BOXED_PRIMITIVE(float, Float) -DEFINE_BOXED_PRIMITIVE(double, Double) - -#undef DEFINE_BOXED_PRIMITIVE - -inline local_ref autobox(alias_ref val) { - return make_local(val); -} - -}} - diff --git a/lib/fb/src/main/cpp/include/fb/fbjni/ByteBuffer.h b/lib/fb/src/main/cpp/include/fb/fbjni/ByteBuffer.h deleted file mode 100644 index 21d17a27..00000000 --- a/lib/fb/src/main/cpp/include/fb/fbjni/ByteBuffer.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2016-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include - -#include "CoreClasses.h" -#include "References-forward.h" - -namespace facebook { -namespace jni { - -// JNI's NIO support has some awkward preconditions and error reporting. This -// class provides much more user-friendly access. -class FBEXPORT JByteBuffer : public JavaClass { - public: - static constexpr const char* kJavaDescriptor = "Ljava/nio/ByteBuffer;"; - - static local_ref wrapBytes(uint8_t* data, size_t size); - - bool isDirect() const; - - uint8_t* getDirectBytes() const; - size_t getDirectSize() const; -}; - -}} diff --git a/lib/fb/src/main/cpp/include/fb/fbjni/Common.h b/lib/fb/src/main/cpp/include/fb/fbjni/Common.h deleted file mode 100644 index a7775db6..00000000 --- a/lib/fb/src/main/cpp/include/fb/fbjni/Common.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -/** @file Common.h - * - * Defining the stuff that don't deserve headers of their own... - */ - -#pragma once - -#include - -#include - -#include -#include - -#ifdef FBJNI_DEBUG_REFS -# ifdef __ANDROID__ -# include -# else -# include -# endif -#endif - -// If a pending JNI Java exception is found, wraps it in a JniException object and throws it as -// a C++ exception. -#define FACEBOOK_JNI_THROW_PENDING_EXCEPTION() \ - ::facebook::jni::throwPendingJniExceptionAsCppException() - -// If the condition is true, throws a JniException object, which wraps the pending JNI Java -// exception if any. If no pending exception is found, throws a JniException object that wraps a -// RuntimeException throwable.  -#define FACEBOOK_JNI_THROW_EXCEPTION_IF(CONDITION) \ - ::facebook::jni::throwCppExceptionIf(CONDITION) - -/// @cond INTERNAL - -namespace facebook { -namespace jni { - -FBEXPORT void throwPendingJniExceptionAsCppException(); -FBEXPORT void throwCppExceptionIf(bool condition); - -[[noreturn]] FBEXPORT void throwNewJavaException(jthrowable); -[[noreturn]] FBEXPORT void throwNewJavaException(const char* throwableName, const char* msg); -template -[[noreturn]] void throwNewJavaException(const char* throwableName, const char* fmt, Args... args); - - -/** - * This needs to be called at library load time, typically in your JNI_OnLoad method. - * - * The intended use is to return the result of initialize() directly - * from JNI_OnLoad and to do nothing else there. Library specific - * initialization code should go in the function passed to initialize - * (which can be, and probably should be, a C++ lambda). This approach - * provides correct error handling and translation errors during - * initialization into Java exceptions when appropriate. - * - * Failure to call this will cause your code to crash in a remarkably - * unhelpful way (typically a segfault) while trying to handle an exception - * which occurs later. - */ -FBEXPORT jint initialize(JavaVM*, std::function&&) noexcept; - -namespace internal { - -/** - * Retrieve a pointer the JNI environment of the current thread. - * - * @pre The current thread must be attached to the VM - */ -inline JNIEnv* getEnv() noexcept { - // TODO(T6594868) Benchmark against raw JNI access - return Environment::current(); -} - -// Define to get extremely verbose logging of references and to enable reference stats -#ifdef FBJNI_DEBUG_REFS -template -inline void dbglog(const char* msg, Args... args) { -# ifdef __ANDROID__ - __android_log_print(ANDROID_LOG_VERBOSE, "fbjni_dbg", msg, args...); -# else - std::fprintf(stderr, msg, args...); -# endif -} - -#else - -template -inline void dbglog(const char*, Args...) { -} - -#endif - -}}} - -/// @endcond diff --git a/lib/fb/src/main/cpp/include/fb/fbjni/Context.h b/lib/fb/src/main/cpp/include/fb/fbjni/Context.h deleted file mode 100644 index 726a2533..00000000 --- a/lib/fb/src/main/cpp/include/fb/fbjni/Context.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2016-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "CoreClasses.h" -#include "File.h" - -namespace facebook { -namespace jni { - -class AContext : public JavaClass { - public: - static constexpr const char* kJavaDescriptor = "Landroid/content/Context;"; - - // Define a method that calls into the represented Java class - local_ref getCacheDir() { - static auto method = getClass()->getMethod("getCacheDir"); - return method(self()); - } - - local_ref getFilesDir() { - static auto method = getClass()->getMethod("getFilesDir"); - return method(self()); - } -}; - -} -} diff --git a/lib/fb/src/main/cpp/include/fb/fbjni/CoreClasses-inl.h b/lib/fb/src/main/cpp/include/fb/fbjni/CoreClasses-inl.h deleted file mode 100644 index 1e00441a..00000000 --- a/lib/fb/src/main/cpp/include/fb/fbjni/CoreClasses-inl.h +++ /dev/null @@ -1,661 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include -#include - -#include "Common.h" -#include "Exceptions.h" -#include "Meta.h" -#include "MetaConvert.h" - -namespace facebook { -namespace jni { - -// jobject ///////////////////////////////////////////////////////////////////////////////////////// - -inline bool isSameObject(alias_ref lhs, alias_ref rhs) noexcept { - return internal::getEnv()->IsSameObject(lhs.get(), rhs.get()) != JNI_FALSE; -} - -inline local_ref JObject::getClass() const noexcept { - return adopt_local(internal::getEnv()->GetObjectClass(self())); -} - -inline bool JObject::isInstanceOf(alias_ref cls) const noexcept { - return internal::getEnv()->IsInstanceOf(self(), cls.get()) != JNI_FALSE; -} - -template -inline T JObject::getFieldValue(JField field) const noexcept { - return field.get(self()); -} - -template -inline local_ref JObject::getFieldValue(JField field) const noexcept { - return adopt_local(field.get(self())); -} - -template -inline void JObject::setFieldValue(JField field, T value) noexcept { - field.set(self(), value); -} - -inline std::string JObject::toString() const { - static auto method = findClassLocal("java/lang/Object")->getMethod("toString"); - - return method(self())->toStdString(); -} - - -// Class is here instead of CoreClasses.h because we need -// alias_ref to be complete. -class MonitorLock { - public: - inline MonitorLock() noexcept; - inline MonitorLock(alias_ref object) noexcept; - inline ~MonitorLock() noexcept; - - inline MonitorLock(MonitorLock&& other) noexcept; - inline MonitorLock& operator=(MonitorLock&& other) noexcept; - - inline MonitorLock(const MonitorLock&) = delete; - inline MonitorLock& operator=(const MonitorLock&) = delete; - - private: - inline void reset() noexcept; - alias_ref owned_; -}; - -MonitorLock::MonitorLock() noexcept : owned_(nullptr) {} - -MonitorLock::MonitorLock(alias_ref object) noexcept - : owned_(object) { - internal::getEnv()->MonitorEnter(object.get()); -} - -void MonitorLock::reset() noexcept { - if (owned_) { - internal::getEnv()->MonitorExit(owned_.get()); - if (internal::getEnv()->ExceptionCheck()) { - abort(); // Lock mismatch - } - owned_ = nullptr; - } -} - -MonitorLock::~MonitorLock() noexcept { - reset(); -} - -MonitorLock::MonitorLock(MonitorLock&& other) noexcept - : owned_(other.owned_) -{ - other.owned_ = nullptr; -} - -MonitorLock& MonitorLock::operator=(MonitorLock&& other) noexcept { - reset(); - owned_ = other.owned_; - other.owned_ = nullptr; - return *this; -} - -inline MonitorLock JObject::lock() const noexcept { - return MonitorLock(this_); -} - -inline jobject JObject::self() const noexcept { - return this_; -} - -inline void swap(JObject& a, JObject& b) noexcept { - using std::swap; - swap(a.this_, b.this_); -} - -// JavaClass /////////////////////////////////////////////////////////////////////////////////////// - -namespace detail { -template -static local_ref newInstance(Args... args) { - static auto cls = JC::javaClassStatic(); - static auto constructor = cls->template getConstructor(); - return cls->newObject(constructor, args...); -} -} - - -template -auto JavaClass::self() const noexcept -> javaobject { - return static_cast(JObject::self()); -} - -// jclass ////////////////////////////////////////////////////////////////////////////////////////// - -namespace detail { - -// This is not a real type. It is used so people won't accidentally -// use a void* to initialize a NativeMethod. -struct NativeMethodWrapper; - -} - -struct NativeMethod { - const char* name; - std::string descriptor; - detail::NativeMethodWrapper* wrapper; -}; - -inline local_ref JClass::getSuperclass() const noexcept { - return adopt_local(internal::getEnv()->GetSuperclass(self())); -} - -inline void JClass::registerNatives(std::initializer_list methods) { - const auto env = internal::getEnv(); - - JNINativeMethod jnimethods[methods.size()]; - size_t i = 0; - for (auto it = methods.begin(); it < methods.end(); ++it, ++i) { - jnimethods[i].name = it->name; - jnimethods[i].signature = it->descriptor.c_str(); - jnimethods[i].fnPtr = reinterpret_cast(it->wrapper); - } - - auto result = env->RegisterNatives(self(), jnimethods, methods.size()); - FACEBOOK_JNI_THROW_EXCEPTION_IF(result != JNI_OK); -} - -inline bool JClass::isAssignableFrom(alias_ref other) const noexcept { - const auto env = internal::getEnv(); - const auto result = env->IsAssignableFrom(self(), other.get()); - return result; -} - -template -inline JConstructor JClass::getConstructor() const { - return getConstructor(jmethod_traits_from_cxx::constructor_descriptor().c_str()); -} - -template -inline JConstructor JClass::getConstructor(const char* descriptor) const { - constexpr auto constructor_method_name = ""; - return getMethod(constructor_method_name, descriptor); -} - -template -inline JMethod JClass::getMethod(const char* name) const { - return getMethod(name, jmethod_traits_from_cxx::descriptor().c_str()); -} - -template -inline JMethod JClass::getMethod( - const char* name, - const char* descriptor) const { - const auto env = internal::getEnv(); - const auto method = env->GetMethodID(self(), name, descriptor); - FACEBOOK_JNI_THROW_EXCEPTION_IF(!method); - return JMethod{method}; -} - -template -inline JStaticMethod JClass::getStaticMethod(const char* name) const { - return getStaticMethod(name, jmethod_traits_from_cxx::descriptor().c_str()); -} - -template -inline JStaticMethod JClass::getStaticMethod( - const char* name, - const char* descriptor) const { - const auto env = internal::getEnv(); - const auto method = env->GetStaticMethodID(self(), name, descriptor); - FACEBOOK_JNI_THROW_EXCEPTION_IF(!method); - return JStaticMethod{method}; -} - -template -inline JNonvirtualMethod JClass::getNonvirtualMethod(const char* name) const { - return getNonvirtualMethod(name, jmethod_traits_from_cxx::descriptor().c_str()); -} - -template -inline JNonvirtualMethod JClass::getNonvirtualMethod( - const char* name, - const char* descriptor) const { - const auto env = internal::getEnv(); - const auto method = env->GetMethodID(self(), name, descriptor); - FACEBOOK_JNI_THROW_EXCEPTION_IF(!method); - return JNonvirtualMethod{method}; -} - -template -inline JField(), T>> -JClass::getField(const char* name) const { - return getField(name, jtype_traits::descriptor().c_str()); -} - -template -inline JField(), T>> JClass::getField( - const char* name, - const char* descriptor) const { - const auto env = internal::getEnv(); - auto field = env->GetFieldID(self(), name, descriptor); - FACEBOOK_JNI_THROW_EXCEPTION_IF(!field); - return JField{field}; -} - -template -inline JStaticField(), T>> JClass::getStaticField( - const char* name) const { - return getStaticField(name, jtype_traits::descriptor().c_str()); -} - -template -inline JStaticField(), T>> JClass::getStaticField( - const char* name, - const char* descriptor) const { - const auto env = internal::getEnv(); - auto field = env->GetStaticFieldID(self(), name, descriptor); - FACEBOOK_JNI_THROW_EXCEPTION_IF(!field); - return JStaticField{field}; -} - -template -inline T JClass::getStaticFieldValue(JStaticField field) const noexcept { - return field.get(self()); -} - -template -inline local_ref JClass::getStaticFieldValue(JStaticField field) noexcept { - return adopt_local(field.get(self())); -} - -template -inline void JClass::setStaticFieldValue(JStaticField field, T value) noexcept { - field.set(self(), value); -} - -template -inline local_ref JClass::newObject( - JConstructor constructor, - Args... args) const { - const auto env = internal::getEnv(); - auto object = env->NewObject(self(), constructor.getId(), - detail::callToJni( - detail::Convert::type>::toCall(args))...); - FACEBOOK_JNI_THROW_EXCEPTION_IF(!object); - return adopt_local(static_cast(object)); -} - -inline jclass JClass::self() const noexcept { - return static_cast(JObject::self()); -} - -inline void registerNatives(const char* name, std::initializer_list methods) { - findClassLocal(name)->registerNatives(methods); -} - - -// jstring ///////////////////////////////////////////////////////////////////////////////////////// - -inline local_ref make_jstring(const std::string& modifiedUtf8) { - return make_jstring(modifiedUtf8.c_str()); -} - -namespace detail { -// convert to std::string from jstring -template <> -struct Convert { - typedef jstring jniType; - static std::string fromJni(jniType t) { - return wrap_alias(t)->toStdString(); - } - static jniType toJniRet(const std::string& t) { - return make_jstring(t).release(); - } - static local_ref toCall(const std::string& t) { - return make_jstring(t); - } -}; - -// convert return from const char* -template <> -struct Convert { - typedef jstring jniType; - // no automatic synthesis of const char*. (It can't be freed.) - static jniType toJniRet(const char* t) { - return make_jstring(t).release(); - } - static local_ref toCall(const char* t) { - return make_jstring(t); - } -}; -} - -// jthrowable ////////////////////////////////////////////////////////////////////////////////////// - -inline local_ref JThrowable::initCause(alias_ref cause) { - static auto meth = javaClassStatic()->getMethod("initCause"); - return meth(self(), cause.get()); -} - -// jtypeArray ////////////////////////////////////////////////////////////////////////////////////// - -namespace detail { -inline size_t JArray::size() const noexcept { - const auto env = internal::getEnv(); - return env->GetArrayLength(self()); -} -} - -namespace detail { -template -inline ElementProxy::ElementProxy( - Target* target, - size_t idx) - : target_{target}, idx_{idx} {} - -template -inline ElementProxy& ElementProxy::operator=(const T& o) { - target_->setElement(idx_, o); - return *this; -} - -template -inline ElementProxy& ElementProxy::operator=(alias_ref& o) { - target_->setElement(idx_, o.get()); - return *this; -} - -template -inline ElementProxy& ElementProxy::operator=(alias_ref&& o) { - target_->setElement(idx_, o.get()); - return *this; -} - -template -inline ElementProxy& ElementProxy::operator=(const ElementProxy& o) { - auto src = o.target_->getElement(o.idx_); - target_->setElement(idx_, src.get()); - return *this; -} - -template -inline ElementProxy::ElementProxy::operator const local_ref () const { - return target_->getElement(idx_); -} - -template -inline ElementProxy::ElementProxy::operator local_ref () { - return target_->getElement(idx_); -} -} - -template -std::string JArrayClass::get_instantiated_java_descriptor() { - return "[" + jtype_traits::descriptor(); -}; - -template -std::string JArrayClass::get_instantiated_base_name() { - return get_instantiated_java_descriptor(); -}; - -template -auto JArrayClass::newArray(size_t size) -> local_ref { - static auto elementClass = findClassStatic(jtype_traits::base_name().c_str()); - const auto env = internal::getEnv(); - auto rawArray = env->NewObjectArray(size, elementClass.get(), nullptr); - FACEBOOK_JNI_THROW_EXCEPTION_IF(!rawArray); - return adopt_local(static_cast(rawArray)); -} - -template -inline void JArrayClass::setElement(size_t idx, const T& value) { - const auto env = internal::getEnv(); - env->SetObjectArrayElement(this->self(), idx, value); -} - -template -inline local_ref JArrayClass::getElement(size_t idx) { - const auto env = internal::getEnv(); - auto rawElement = env->GetObjectArrayElement(this->self(), idx); - return adopt_local(static_cast(rawElement)); -} - -template -inline detail::ElementProxy> JArrayClass::operator[](size_t index) { - return detail::ElementProxy>(this, index); -} - -// jarray ///////////////////////////////////////////////////////////////////////////////////////// - -template -auto JPrimitiveArray::getRegion(jsize start, jsize length) - -> std::unique_ptr { - using T = typename jtype_traits::entry_type; - auto buf = std::unique_ptr{new T[length]}; - getRegion(start, length, buf.get()); - return buf; -} - -template -std::string JPrimitiveArray::get_instantiated_java_descriptor() { - return jtype_traits::descriptor(); -} -template -std::string JPrimitiveArray::get_instantiated_base_name() { - return JPrimitiveArray::get_instantiated_java_descriptor(); -} - -template -auto JPrimitiveArray::pin() -> PinnedPrimitiveArray> { - return PinnedPrimitiveArray>{this->self(), 0, 0}; -} - -template -auto JPrimitiveArray::pinRegion(jsize start, jsize length) - -> PinnedPrimitiveArray> { - return PinnedPrimitiveArray>{this->self(), start, length}; -} - -template -auto JPrimitiveArray::pinCritical() - -> PinnedPrimitiveArray> { - return PinnedPrimitiveArray>{this->self(), 0, 0}; -} - -template -class PinnedArrayAlloc { - public: - static void allocate( - alias_ref::array_type> array, - jsize start, - jsize length, - T** elements, - size_t* size, - jboolean* isCopy) { - (void) start; - (void) length; - *elements = array->getElements(isCopy); - *size = array->size(); - } - static void release( - alias_ref::array_type> array, - T* elements, - jint start, - jint size, - jint mode) { - (void) start; - (void) size; - array->releaseElements(elements, mode); - } -}; - -template -class PinnedCriticalAlloc { - public: - static void allocate( - alias_ref::array_type> array, - jsize start, - jsize length, - T** elements, - size_t* size, - jboolean* isCopy) { - const auto env = internal::getEnv(); - *elements = static_cast(env->GetPrimitiveArrayCritical(array.get(), isCopy)); - FACEBOOK_JNI_THROW_EXCEPTION_IF(!elements); - *size = array->size(); - } - static void release( - alias_ref::array_type> array, - T* elements, - jint start, - jint size, - jint mode) { - const auto env = internal::getEnv(); - env->ReleasePrimitiveArrayCritical(array.get(), elements, mode); - } -}; - -template -class PinnedRegionAlloc { - public: - static void allocate( - alias_ref::array_type> array, - jsize start, - jsize length, - T** elements, - size_t* size, - jboolean* isCopy) { - auto buf = array->getRegion(start, length); - FACEBOOK_JNI_THROW_EXCEPTION_IF(!buf); - *elements = buf.release(); - *size = length; - *isCopy = true; - } - static void release( - alias_ref::array_type> array, - T* elements, - jint start, - jint size, - jint mode) { - std::unique_ptr holder; - if (mode == 0 || mode == JNI_ABORT) { - holder.reset(elements); - } - if (mode == 0 || mode == JNI_COMMIT) { - array->setRegion(start, size, elements); - } - } -}; - -// PinnedPrimitiveArray /////////////////////////////////////////////////////////////////////////// - -template -PinnedPrimitiveArray::PinnedPrimitiveArray(PinnedPrimitiveArray&& o) { - *this = std::move(o); -} - -template -PinnedPrimitiveArray& -PinnedPrimitiveArray::operator=(PinnedPrimitiveArray&& o) { - if (array_) { - release(); - } - array_ = std::move(o.array_); - elements_ = o.elements_; - isCopy_ = o.isCopy_; - size_ = o.size_; - start_ = o.start_; - o.clear(); - return *this; -} - -template -T* PinnedPrimitiveArray::get() { - return elements_; -} - -template -inline void PinnedPrimitiveArray::release() { - releaseImpl(0); - clear(); -} - -template -inline void PinnedPrimitiveArray::commit() { - releaseImpl(JNI_COMMIT); -} - -template -inline void PinnedPrimitiveArray::abort() { - releaseImpl(JNI_ABORT); - clear(); -} - -template -inline void PinnedPrimitiveArray::releaseImpl(jint mode) { - FACEBOOK_JNI_THROW_EXCEPTION_IF(array_.get() == nullptr); - Alloc::release(array_, elements_, start_, size_, mode); -} - -template -inline void PinnedPrimitiveArray::clear() noexcept { - array_ = nullptr; - elements_ = nullptr; - isCopy_ = false; - start_ = 0; - size_ = 0; -} - -template -inline T& PinnedPrimitiveArray::operator[](size_t index) { - FACEBOOK_JNI_THROW_EXCEPTION_IF(elements_ == nullptr); - return elements_[index]; -} - -template -inline bool PinnedPrimitiveArray::isCopy() const noexcept { - return isCopy_ == JNI_TRUE; -} - -template -inline size_t PinnedPrimitiveArray::size() const noexcept { - return size_; -} - -template -inline PinnedPrimitiveArray::~PinnedPrimitiveArray() noexcept { - if (elements_) { - release(); - } -} - -template -inline PinnedPrimitiveArray::PinnedPrimitiveArray(alias_ref::array_type> array, jint start, jint length) { - array_ = array; - start_ = start; - Alloc::allocate(array, start, length, &elements_, &size_, &isCopy_); -} - -template -inline alias_ref JavaClass::javaClassStatic() { - static auto cls = findClassStatic(jtype_traits::base_name().c_str()); - return cls; -} - -template -inline local_ref JavaClass::javaClassLocal() { - std::string className(jtype_traits::base_name().c_str()); - return findClassLocal(className.c_str()); -} - -}} diff --git a/lib/fb/src/main/cpp/include/fb/fbjni/CoreClasses.h b/lib/fb/src/main/cpp/include/fb/fbjni/CoreClasses.h deleted file mode 100644 index b4d76a07..00000000 --- a/lib/fb/src/main/cpp/include/fb/fbjni/CoreClasses.h +++ /dev/null @@ -1,593 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -/** @file CoreClasses.h - * - * In CoreClasses.h wrappers for the core classes (jobject, jclass, and jstring) is defined - * to provide access to corresponding JNI functions + some conveniance. - */ - -#include "References-forward.h" -#include "Meta-forward.h" -#include "TypeTraits.h" - -#include - -#include - -#include - -namespace facebook { -namespace jni { - -class JClass; -class JObject; - -/// Lookup a class by name. Note this functions returns an alias_ref that -/// points to a leaked global reference. This is appropriate for classes -/// that are never unloaded (which is any class in an Android app and most -/// Java programs). -/// -/// The most common use case for this is storing the result -/// in a "static auto" variable, or a static global. -/// -/// @return Returns a leaked global reference to the class -FBEXPORT alias_ref findClassStatic(const char* name); - -/// Lookup a class by name. Note this functions returns a local reference, -/// which means that it must not be stored in a static variable. -/// -/// The most common use case for this is one-time initialization -/// (like caching method ids). -/// -/// @return Returns a global reference to the class -FBEXPORT local_ref findClassLocal(const char* name); - -/// Check to see if two references refer to the same object. Comparison with nullptr -/// returns true if and only if compared to another nullptr. A weak reference that -/// refers to a reclaimed object count as nullptr. -FBEXPORT bool isSameObject(alias_ref lhs, alias_ref rhs) noexcept; - -// Together, these classes allow convenient use of any class with the fbjni -// helpers. To use: -// -// struct MyClass : public JavaClass { -// constexpr static auto kJavaDescriptor = "Lcom/example/package/MyClass;"; -// }; -// -// Then, an alias_ref will be backed by an instance of -// MyClass. JavaClass provides a convenient way to add functionality to these -// smart references. -// -// For example: -// -// struct MyClass : public JavaClass { -// constexpr static auto kJavaDescriptor = "Lcom/example/package/MyClass;"; -// -// void foo() { -// static auto method = javaClassStatic()->getMethod("foo"); -// method(self()); -// } -// -// static local_ref create(int i) { -// return newInstance(i); -// } -// }; -// -// auto obj = MyClass::create(10); -// obj->foo(); -// -// While users of a JavaClass-type can lookup methods and fields through the -// underlying JClass, those calls can only be checked at runtime. It is recommended -// that the JavaClass-type instead explicitly expose it's methods as in the example -// above. - -namespace detail { -template -static local_ref newInstance(Args... args); -} - -class MonitorLock; - -class FBEXPORT JObject : detail::JObjectBase { -public: - static constexpr auto kJavaDescriptor = "Ljava/lang/Object;"; - - static constexpr const char* get_instantiated_java_descriptor() { return nullptr; } - static constexpr const char* get_instantiated_base_name() { return nullptr; } - - /// Get a @ref local_ref of the object's class - local_ref getClass() const noexcept; - - /// Checks if the object is an instance of a class - bool isInstanceOf(alias_ref cls) const noexcept; - - /// Get the primitive value of a field - template - T getFieldValue(JField field) const noexcept; - - /// Get and wrap the value of a field in a @ref local_ref - template - local_ref getFieldValue(JField field) const noexcept; - - /// Set the value of field. Any Java type is accepted, including the primitive types - /// and raw reference types. - template - void setFieldValue(JField field, T value) noexcept; - - /// Convenience method to create a std::string representing the object - std::string toString() const; - - // Take this object's monitor lock - MonitorLock lock() const noexcept; - - typedef _jobject _javaobject; - typedef _javaobject* javaobject; - -protected: - jobject self() const noexcept; -private: - friend void swap(JObject& a, JObject& b) noexcept; - template - friend struct detail::ReprAccess; - template - friend class JavaClass; - - template - friend class JObjectWrapper; -}; - -// This is only to maintain backwards compatibility with things that are -// already providing a specialization of JObjectWrapper. Any such instances -// should be updated to use a JavaClass. -template<> -class JObjectWrapper : public JObject { -}; - - -namespace detail { -template -struct JTypeFor { - static_assert( - std::is_base_of< - std::remove_pointer::type, - typename std::remove_pointer::type - >::value, ""); - using _javaobject = typename std::remove_pointer::type; - using javaobject = JType; -}; - -template -struct JTypeFor { - // JNI pattern for jobject assignable pointer - struct _javaobject : Base::_javaobject { - // This allows us to map back to the defining type (in ReprType, for - // example). - typedef T JniRefRepr; - }; - using javaobject = _javaobject*; -}; -} - -// JavaClass provides a method to inform fbjni about user-defined Java types. -// Given a class: -// struct Foo : JavaClass { -// static constexpr auto kJavaDescriptor = "Lcom/example/package/Foo;"; -// }; -// fbjni can determine the java type/method signatures for Foo::javaobject and -// smart refs (like alias_ref) will hold an instance of Foo -// and provide access to it through the -> and * operators. -// -// The "Base" template argument can be used to specify the JavaClass superclass -// of this type (for instance, JString's Base is JObject). -// -// The "JType" template argument is used to provide a jni type (like jstring, -// jthrowable) to be used as javaobject. This should only be necessary for -// built-in jni types and not user-defined ones. -template -class FBEXPORT JavaClass : public Base { - using JObjType = typename detail::JTypeFor; -public: - using _javaobject = typename JObjType::_javaobject; - using javaobject = typename JObjType::javaobject; - - using JavaBase = JavaClass; - - static alias_ref javaClassStatic(); - static local_ref javaClassLocal(); -protected: - /// Allocates a new object and invokes the specified constructor - /// Like JClass's getConstructor, this function can only check at runtime if - /// the class actually has a constructor that accepts the corresponding types. - /// While a JavaClass-type can expose this function directly, it is recommended - /// to instead to use this to explicitly only expose those constructors that - /// the Java class actually has (i.e. with static create() functions). - template - static local_ref newInstance(Args... args) { - return detail::newInstance(args...); - } - - javaobject self() const noexcept; -}; - -/// Wrapper to provide functionality to jclass references -struct NativeMethod; - -class FBEXPORT JClass : public JavaClass { - public: - /// Java type descriptor - static constexpr const char* kJavaDescriptor = "Ljava/lang/Class;"; - - /// Get a @local_ref to the super class of this class - local_ref getSuperclass() const noexcept; - - /// Register native methods for the class. Usage looks like this: - /// - /// classRef->registerNatives({ - /// makeNativeMethod("nativeMethodWithAutomaticDescriptor", - /// methodWithAutomaticDescriptor), - /// makeNativeMethod("nativeMethodWithExplicitDescriptor", - /// "(Lcom/facebook/example/MyClass;)V", - /// methodWithExplicitDescriptor), - /// }); - /// - /// By default, C++ exceptions raised will be converted to Java exceptions. - /// To avoid this and get the "standard" JNI behavior of a crash when a C++ - /// exception is crashing out of the JNI method, declare the method noexcept. - void registerNatives(std::initializer_list methods); - - /// Check to see if the class is assignable from another class - /// @pre cls != nullptr - bool isAssignableFrom(alias_ref cls) const noexcept; - - /// Convenience method to lookup the constructor with descriptor as specified by the - /// type arguments - template - JConstructor getConstructor() const; - - /// Convenience method to lookup the constructor with specified descriptor - template - JConstructor getConstructor(const char* descriptor) const; - - /// Look up the method with given name and descriptor as specified with the type arguments - template - JMethod getMethod(const char* name) const; - - /// Look up the method with given name and descriptor - template - JMethod getMethod(const char* name, const char* descriptor) const; - - /// Lookup the field with the given name and deduced descriptor - template - JField(), T>> getField(const char* name) const; - - /// Lookup the field with the given name and descriptor - template - JField(), T>> getField(const char* name, const char* descriptor) const; - - /// Lookup the static field with the given name and deduced descriptor - template - JStaticField(), T>> getStaticField(const char* name) const; - - /// Lookup the static field with the given name and descriptor - template - JStaticField(), T>> getStaticField( - const char* name, - const char* descriptor) const; - - /// Get the primitive value of a static field - template - T getStaticFieldValue(JStaticField field) const noexcept; - - /// Get and wrap the value of a field in a @ref local_ref - template - local_ref getStaticFieldValue(JStaticField field) noexcept; - - /// Set the value of field. Any Java type is accepted, including the primitive types - /// and raw reference types. - template - void setStaticFieldValue(JStaticField field, T value) noexcept; - - /// Allocates a new object and invokes the specified constructor - template - local_ref newObject(JConstructor constructor, Args... args) const; - - /// Look up the static method with given name and descriptor as specified with the type arguments - template - JStaticMethod getStaticMethod(const char* name) const; - - /// Look up the static method with given name and descriptor - template - JStaticMethod getStaticMethod(const char* name, const char* descriptor) const; - - /// Look up the non virtual method with given name and descriptor as specified with the - /// type arguments - template - JNonvirtualMethod getNonvirtualMethod(const char* name) const; - - /// Look up the non virtual method with given name and descriptor - template - JNonvirtualMethod getNonvirtualMethod(const char* name, const char* descriptor) const; - -private: - jclass self() const noexcept; -}; - -// Convenience method to register methods on a class without holding -// onto the class object. -void registerNatives(const char* name, std::initializer_list methods); - -/// Wrapper to provide functionality to jstring references -class FBEXPORT JString : public JavaClass { - public: - /// Java type descriptor - static constexpr const char* kJavaDescriptor = "Ljava/lang/String;"; - - /// Convenience method to convert a jstring object to a std::string - std::string toStdString() const; -}; - -/// Convenience functions to convert a std::string or const char* into a @ref local_ref to a -/// jstring -FBEXPORT local_ref make_jstring(const char* modifiedUtf8); -FBEXPORT local_ref make_jstring(const std::string& modifiedUtf8); - -/// Wrapper to provide functionality to jthrowable references -class FBEXPORT JThrowable : public JavaClass { - public: - static constexpr const char* kJavaDescriptor = "Ljava/lang/Throwable;"; - - local_ref initCause(alias_ref cause); -}; - -namespace detail { -template -class ElementProxy { - private: - Target* target_; - size_t idx_; - - public: - using T = typename Target::javaentry; - ElementProxy(Target* target, size_t idx); - - ElementProxy& operator=(const T& o); - - ElementProxy& operator=(alias_ref& o); - - ElementProxy& operator=(alias_ref&& o); - - ElementProxy& operator=(const ElementProxy& o); - - operator const local_ref () const; - - operator local_ref (); -}; -} - -namespace detail { -class FBEXPORT JArray : public JavaClass { - public: - // This cannot be used in a scope that derives a descriptor (like in a method - // signature). Use a more derived type instead (like JArrayInt or - // JArrayClass). - static constexpr const char* kJavaDescriptor = nullptr; - size_t size() const noexcept; -}; - -// This is used so that the JArrayClass javaobject extends jni's -// jobjectArray. This class should not be used directly. A general Object[] -// should use JArrayClass. -class FBEXPORT JTypeArray : public JavaClass { - // This cannot be used in a scope that derives a descriptor (like in a method - // signature). - static constexpr const char* kJavaDescriptor = nullptr; -}; -} - -template -class JArrayClass : public JavaClass, detail::JTypeArray> { - public: - static_assert(is_plain_jni_reference(), ""); - // javaentry is the jni type of an entry in the array (i.e. jint). - using javaentry = T; - // javaobject is the jni type of the array. - using javaobject = typename JavaClass, detail::JTypeArray>::javaobject; - static constexpr const char* kJavaDescriptor = nullptr; - static std::string get_instantiated_java_descriptor(); - static std::string get_instantiated_base_name(); - - /// Allocate a new array from Java heap, for passing as a JNI parameter or return value. - /// NOTE: if using as a return value, you want to call release() instead of get() on the - /// smart pointer. - static local_ref newArray(size_t count); - - /// Assign an object to the array. - /// Typically you will use the shorthand (*ref)[idx]=value; - void setElement(size_t idx, const T& value); - - /// Read an object from the array. - /// Typically you will use the shorthand - /// T value = (*ref)[idx]; - /// If you use auto, you'll get an ElementProxy, which may need to be cast. - local_ref getElement(size_t idx); - - /// EXPERIMENTAL SUBSCRIPT SUPPORT - /// This implementation of [] returns a proxy object which then has a bunch of specializations - /// (adopt_local free function, operator= and casting overloads on the ElementProxy) that can - /// make code look like it is dealing with a T rather than an obvious proxy. In particular, the - /// proxy in this iteration does not read a value and therefore does not create a LocalRef - /// until one of these other operators is used. There are certainly holes that you may find - /// by using idioms that haven't been tried yet. Consider yourself warned. On the other hand, - /// it does make for some idiomatic assignment code; see TestBuildStringArray in fbjni_tests - /// for some examples. - detail::ElementProxy operator[](size_t idx); -}; - -template -using jtypeArray = typename JArrayClass::javaobject; - -template -local_ref::javaobject> adopt_local_array(jobjectArray ref) { - return adopt_local(static_cast::javaobject>(ref)); -} - -template -local_ref adopt_local(detail::ElementProxy elementProxy) { - return static_cast>(elementProxy); -} - -template -class PinnedPrimitiveArray; - -template class PinnedArrayAlloc; -template class PinnedRegionAlloc; -template class PinnedCriticalAlloc; - -/// Wrapper to provide functionality to jarray references. -/// This is an empty holder by itself. Construct a PinnedPrimitiveArray to actually interact with -/// the elements of the array. -template -class FBEXPORT JPrimitiveArray : - public JavaClass, detail::JArray, JArrayType> { - static_assert(is_jni_primitive_array(), ""); - public: - static constexpr const char* kJavaDescriptor = nullptr; - static std::string get_instantiated_java_descriptor(); - static std::string get_instantiated_base_name(); - - using T = typename jtype_traits::entry_type; - - static local_ref newArray(size_t count); - - void getRegion(jsize start, jsize length, T* buf); - std::unique_ptr getRegion(jsize start, jsize length); - void setRegion(jsize start, jsize length, const T* buf); - - /// Returns a view of the underlying array. This will either be a "pinned" - /// version of the array (in which case changes to one immediately affect the - /// other) or a copy of the array (in which cases changes to the view will take - /// affect when destroyed or on calls to release()/commit()). - PinnedPrimitiveArray> pin(); - - /// Returns a view of part of the underlying array. A pinned region is always - /// backed by a copy of the region. - PinnedPrimitiveArray> pinRegion(jsize start, jsize length); - - /// Returns a view of the underlying array like pin(). However, while the pin - /// is held, the code is considered within a "critical region". In a critical - /// region, native code must not call JNI functions or make any calls that may - /// block on other Java threads. These restrictions make it more likely that - /// the view will be "pinned" rather than copied (for example, the VM may - /// suspend garbage collection within a critical region). - PinnedPrimitiveArray> pinCritical(); - -private: - friend class PinnedArrayAlloc; - T* getElements(jboolean* isCopy); - void releaseElements(T* elements, jint mode); -}; - -FBEXPORT local_ref make_boolean_array(jsize size); -FBEXPORT local_ref make_byte_array(jsize size); -FBEXPORT local_ref make_char_array(jsize size); -FBEXPORT local_ref make_short_array(jsize size); -FBEXPORT local_ref make_int_array(jsize size); -FBEXPORT local_ref make_long_array(jsize size); -FBEXPORT local_ref make_float_array(jsize size); -FBEXPORT local_ref make_double_array(jsize size); - -using JArrayBoolean = JPrimitiveArray; -using JArrayByte = JPrimitiveArray; -using JArrayChar = JPrimitiveArray; -using JArrayShort = JPrimitiveArray; -using JArrayInt = JPrimitiveArray; -using JArrayLong = JPrimitiveArray; -using JArrayFloat = JPrimitiveArray; -using JArrayDouble = JPrimitiveArray; - -/// RAII class for pinned primitive arrays -/// This currently only supports read/write access to existing java arrays. You can't create a -/// primitive array this way yet. This class also pins the entire array into memory during the -/// lifetime of the PinnedPrimitiveArray. If you need to unpin the array manually, call the -/// release() or abort() functions. During a long-running block of code, you -/// should unpin the array as soon as you're done with it, to avoid holding up -/// the Java garbage collector. -template -class PinnedPrimitiveArray { - public: - static_assert(is_jni_primitive::value, - "PinnedPrimitiveArray requires primitive jni type."); - - using ArrayType = typename jtype_traits::array_type; - - PinnedPrimitiveArray(PinnedPrimitiveArray&&); - PinnedPrimitiveArray(const PinnedPrimitiveArray&) = delete; - ~PinnedPrimitiveArray() noexcept; - - PinnedPrimitiveArray& operator=(PinnedPrimitiveArray&&); - PinnedPrimitiveArray& operator=(const PinnedPrimitiveArray&) = delete; - - T* get(); - void release(); - /// Unpins the array. If the array is a copy, pending changes are discarded. - void abort(); - /// If the array is a copy, copies pending changes to the underlying java array. - void commit(); - - bool isCopy() const noexcept; - - const T& operator[](size_t index) const; - T& operator[](size_t index); - size_t size() const noexcept; - - private: - alias_ref array_; - size_t start_; - T* elements_; - jboolean isCopy_; - size_t size_; - - void allocate(alias_ref, jint start, jint length); - void releaseImpl(jint mode); - void clear() noexcept; - - PinnedPrimitiveArray(alias_ref, jint start, jint length); - - friend class JPrimitiveArray::array_type>; -}; - -#pragma push_macro("PlainJniRefMap") -#undef PlainJniRefMap -#define PlainJniRefMap(rtype, jtype) \ -namespace detail { \ -template<> \ -struct RefReprType { \ - using type = rtype; \ -}; \ -} - -PlainJniRefMap(JArrayBoolean, jbooleanArray); -PlainJniRefMap(JArrayByte, jbyteArray); -PlainJniRefMap(JArrayChar, jcharArray); -PlainJniRefMap(JArrayShort, jshortArray); -PlainJniRefMap(JArrayInt, jintArray); -PlainJniRefMap(JArrayLong, jlongArray); -PlainJniRefMap(JArrayFloat, jfloatArray); -PlainJniRefMap(JArrayDouble, jdoubleArray); -PlainJniRefMap(JObject, jobject); -PlainJniRefMap(JClass, jclass); -PlainJniRefMap(JString, jstring); -PlainJniRefMap(JThrowable, jthrowable); - -#pragma pop_macro("PlainJniRefMap") - -}} - -#include "CoreClasses-inl.h" diff --git a/lib/fb/src/main/cpp/include/fb/fbjni/Exceptions.h b/lib/fb/src/main/cpp/include/fb/fbjni/Exceptions.h deleted file mode 100644 index 08deb42e..00000000 --- a/lib/fb/src/main/cpp/include/fb/fbjni/Exceptions.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -/** - * @file Exceptions.h - * - * After invoking a JNI function that can throw a Java exception, the macro - * @ref FACEBOOK_JNI_THROW_PENDING_EXCEPTION() or @ref FACEBOOK_JNI_THROW_EXCEPTION_IF() - * should be invoked. - * - * IMPORTANT! IMPORTANT! IMPORTANT! IMPORTANT! IMPORTANT! IMPORTANT! IMPORTANT! IMPORTANT! - * To use these methods you MUST call initExceptionHelpers() when your library is loaded. - */ - -#pragma once - -#include -#include -#include - -#include - -#include - -#include "Common.h" -#include "References.h" -#include "CoreClasses.h" - -namespace facebook { -namespace jni { - -class JThrowable; - -class JCppException : public JavaClass { - public: - static auto constexpr kJavaDescriptor = "Lcom/facebook/jni/CppException;"; - - static local_ref create(const char* str) { - return newInstance(make_jstring(str)); - } - - static local_ref create(const std::exception& ex) { - return newInstance(make_jstring(ex.what())); - } -}; - -// JniException //////////////////////////////////////////////////////////////////////////////////// - -/** - * This class wraps a Java exception into a C++ exception; if the exception is routed back - * to the Java side, it can be unwrapped and just look like a pure Java interaction. The class - * is resilient to errors while creating the exception, falling back to some pre-allocated - * exceptions if a new one cannot be allocated or populated. - * - * Note: the what() method of this class is not thread-safe (t6900503). - */ -class FBEXPORT JniException : public std::exception { - public: - JniException(); - ~JniException(); - - explicit JniException(alias_ref throwable); - - JniException(JniException &&rhs); - - JniException(const JniException &other); - - local_ref getThrowable() const noexcept; - - virtual const char* what() const noexcept; - - void setJavaException() const noexcept; - - private: - global_ref throwable_; - mutable std::string what_; - mutable bool isMessageExtracted_; - const static std::string kExceptionMessageFailure_; - - void populateWhat() const noexcept; -}; - -// Exception throwing & translating functions ////////////////////////////////////////////////////// - -// Functions that throw C++ exceptions - -static const int kMaxExceptionMessageBufferSize = 512; - -// These methods are the preferred way to throw a Java exception from -// a C++ function. They create and throw a C++ exception which wraps -// a Java exception, so the C++ flow is interrupted. Then, when -// translatePendingCppExceptionToJavaException is called at the -// topmost level of the native stack, the wrapped Java exception is -// thrown to the java caller. -template -[[noreturn]] void throwNewJavaException(const char* throwableName, const char* fmt, Args... args) { - int msgSize = snprintf(nullptr, 0, fmt, args...); - - char *msg = (char*) alloca(msgSize + 1); - snprintf(msg, kMaxExceptionMessageBufferSize, fmt, args...); - throwNewJavaException(throwableName, msg); -} - -// Identifies any pending C++ exception and throws it as a Java exception. If the exception can't -// be thrown, it aborts the program. This is a noexcept function at C++ level. -FBEXPORT void translatePendingCppExceptionToJavaException() noexcept; - -// For convenience, some exception names in java.lang are available here. - -const char* const gJavaLangIllegalArgumentException = "java/lang/IllegalArgumentException"; - -}} diff --git a/lib/fb/src/main/cpp/include/fb/fbjni/File.h b/lib/fb/src/main/cpp/include/fb/fbjni/File.h deleted file mode 100644 index 74c752a0..00000000 --- a/lib/fb/src/main/cpp/include/fb/fbjni/File.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2016-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "CoreClasses.h" - -namespace facebook { -namespace jni { - -class JFile : public JavaClass { - public: - static constexpr const char* kJavaDescriptor = "Ljava/io/File;"; - - // Define a method that calls into the represented Java class - std::string getAbsolutePath() { - static auto method = getClass()->getMethod("getAbsolutePath"); - return method(self())->toStdString(); - } - -}; - -} -} diff --git a/lib/fb/src/main/cpp/include/fb/fbjni/Hybrid.h b/lib/fb/src/main/cpp/include/fb/fbjni/Hybrid.h deleted file mode 100644 index f020826c..00000000 --- a/lib/fb/src/main/cpp/include/fb/fbjni/Hybrid.h +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include - -#include -#include - -#include "CoreClasses.h" - -namespace facebook { -namespace jni { - -namespace detail { - -class BaseHybridClass { -public: - virtual ~BaseHybridClass() {} -}; - -struct FBEXPORT HybridData : public JavaClass { - constexpr static auto kJavaDescriptor = "Lcom/facebook/jni/HybridData;"; - void setNativePointer(std::unique_ptr new_value); - BaseHybridClass* getNativePointer(); - static local_ref create(); -}; - -template -struct HybridTraits { - // This static assert should actually always fail if we don't use one of the - // specializations below. - static_assert( - std::is_base_of::value || - std::is_base_of::value, - "The base of a HybridClass must be either another HybridClass or derived from JObject."); -}; - -template <> -struct HybridTraits { - using CxxBase = BaseHybridClass; - using JavaBase = JObject; -}; - -template -struct HybridTraits< - Base, - typename std::enable_if::value>::type> { - using CxxBase = Base; - using JavaBase = typename Base::JavaPart; -}; - -template -struct HybridTraits< - Base, - typename std::enable_if::value>::type> { - using CxxBase = BaseHybridClass; - using JavaBase = Base; -}; - -// convert to HybridClass* from jhybridobject -template -struct FBEXPORT Convert< - T, typename std::enable_if< - std::is_base_of::type>::value>::type> { - typedef typename std::remove_pointer::type::jhybridobject jniType; - static T fromJni(jniType t) { - if (t == nullptr) { - return nullptr; - } - return wrap_alias(t)->cthis(); - } - // There is no automatic return conversion for objects. -}; - -template -struct RefReprType::value, void>::type> { - static_assert(std::is_same::value, - "HybridFoo (where HybridFoo derives from HybridClass) is not supported in this context. " - "For an xxx_ref, you may want: xxx_ref or HybridFoo*."); - using Repr = T; -}; - - -} - -template -class FBEXPORT HybridClass : public detail::HybridTraits::CxxBase { -public: - struct JavaPart : JavaClass::JavaBase> { - // At this point, T is incomplete, and so we cannot access - // T::kJavaDescriptor directly. jtype_traits support this escape hatch for - // such a case. - static constexpr const char* kJavaDescriptor = nullptr; - static std::string get_instantiated_java_descriptor(); - static std::string get_instantiated_base_name(); - - using HybridType = T; - - // This will reach into the java object and extract the C++ instance from - // the mHybridData and return it. - T* cthis(); - - friend class HybridClass; - }; - - using jhybridobject = typename JavaPart::javaobject; - using javaobject = typename JavaPart::javaobject; - typedef detail::HybridData::javaobject jhybriddata; - - static alias_ref javaClassStatic() { - return JavaPart::javaClassStatic(); - } - - static local_ref javaClassLocal() { - std::string className(T::kJavaDescriptor + 1, strlen(T::kJavaDescriptor) - 2); - return findClassLocal(className.c_str()); - } - -protected: - typedef HybridClass HybridBase; - - // This ensures that a C++ hybrid part cannot be created on its own - // by default. If a hybrid wants to enable this, it can provide its - // own public ctor, or change the accessibility of this to public. - using detail::HybridTraits::CxxBase::CxxBase; - - static void registerHybrid(std::initializer_list methods) { - javaClassStatic()->registerNatives(methods); - } - - static local_ref makeHybridData(std::unique_ptr cxxPart) { - auto hybridData = detail::HybridData::create(); - hybridData->setNativePointer(std::move(cxxPart)); - return hybridData; - } - - template - static local_ref makeCxxInstance(Args&&... args) { - return makeHybridData(std::unique_ptr(new T(std::forward(args)...))); - } - -public: - // Factory method for creating a hybrid object where the arguments - // are used to initialize the C++ part directly without passing them - // through java. This method requires the Java part to have a ctor - // which takes a HybridData, and for the C++ part to have a ctor - // compatible with the arguments passed here. For safety, the ctor - // can be private, and the hybrid declared a friend of its base, so - // the hybrid can only be created from here. - // - // Exception behavior: This can throw an exception if creating the - // C++ object fails, or any JNI methods throw. - template - static local_ref newObjectCxxArgs(Args&&... args) { - auto hybridData = makeCxxInstance(std::forward(args)...); - return JavaPart::newInstance(hybridData); - } - - // TODO? Create reusable interface for Allocatable classes and use it to - // strengthen type-checking (and possibly provide a default - // implementation of allocate().) - template - static local_ref allocateWithCxxArgs(Args&&... args) { - auto hybridData = makeCxxInstance(std::forward(args)...); - static auto allocateMethod = - javaClassStatic()->template getStaticMethod("allocate"); - return allocateMethod(javaClassStatic(), hybridData.get()); - } - - // Factory method for creating a hybrid object where the arguments - // are passed to the java ctor. - template - static local_ref newObjectJavaArgs(Args&&... args) { - return JavaPart::newInstance(std::move(args)...); - } - - // If a hybrid class throws an exception which derives from - // std::exception, it will be passed to mapException on the hybrid - // class, or nearest ancestor. This allows boilerplate exception - // translation code (for example, calling throwNewJavaException on a - // particular java class) to be hoisted to a common function. If - // mapException returns, then the std::exception will be translated - // to Java. - static void mapException(const std::exception& ex) {} -}; - -template -inline T* HybridClass::JavaPart::cthis() { - static auto field = - HybridClass::JavaPart::javaClassStatic()->template getField("mHybridData"); - auto hybridData = this->getFieldValue(field); - if (!hybridData) { - throwNewJavaException("java/lang/NullPointerException", "java.lang.NullPointerException"); - } - // I'd like to use dynamic_cast here, but -fno-rtti is the default. - T* value = static_cast(hybridData->getNativePointer()); - // This would require some serious programmer error. - FBASSERTMSGF(value != 0, "Incorrect C++ type in hybrid field"); - return value; -}; - -template -/* static */ inline std::string HybridClass::JavaPart::get_instantiated_java_descriptor() { - return T::kJavaDescriptor; -} - -template -/* static */ inline std::string HybridClass::JavaPart::get_instantiated_base_name() { - auto name = get_instantiated_java_descriptor(); - return name.substr(1, name.size() - 2); -} - -// Given a *_ref object which refers to a hybrid class, this will reach inside -// of it, find the mHybridData, extract the C++ instance pointer, cast it to -// the appropriate type, and return it. -template -inline auto cthis(T jthis) -> decltype(jthis->cthis()) { - return jthis->cthis(); -} - -void HybridDataOnLoad(); - -} -} diff --git a/lib/fb/src/main/cpp/include/fb/fbjni/Iterator-inl.h b/lib/fb/src/main/cpp/include/fb/fbjni/Iterator-inl.h deleted file mode 100644 index c056e16a..00000000 --- a/lib/fb/src/main/cpp/include/fb/fbjni/Iterator-inl.h +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -namespace facebook { -namespace jni { - -namespace detail { - -template -struct IteratorHelper : public JavaClass> { - constexpr static auto kJavaDescriptor = "Lcom/facebook/jni/IteratorHelper;"; - - typedef local_ref value_type; - typedef ptrdiff_t difference_type; - typedef value_type* pointer; - typedef value_type& reference; - typedef std::forward_iterator_tag iterator_category; - - typedef JavaClass> JavaBase_; - - bool hasNext() const { - static auto hasNextMethod = - JavaBase_::javaClassStatic()->template getMethod("hasNext"); - return hasNextMethod(JavaBase_::self()); - } - - value_type next() { - static auto elementField = - JavaBase_::javaClassStatic()->template getField("mElement"); - return dynamic_ref_cast(JavaBase_::getFieldValue(elementField)); - } - - static void reset(value_type& v) { - v.reset(); - } -}; - -template -struct MapIteratorHelper : public JavaClass> { - constexpr static auto kJavaDescriptor = "Lcom/facebook/jni/MapIteratorHelper;"; - - typedef std::pair, local_ref> value_type; - - typedef JavaClass> JavaBase_; - - bool hasNext() const { - static auto hasNextMethod = - JavaBase_::javaClassStatic()->template getMethod("hasNext"); - return hasNextMethod(JavaBase_::self()); - } - - value_type next() { - static auto keyField = JavaBase_::javaClassStatic()->template getField("mKey"); - static auto valueField = JavaBase_::javaClassStatic()->template getField("mValue"); - return std::make_pair(dynamic_ref_cast(JavaBase_::getFieldValue(keyField)), - dynamic_ref_cast(JavaBase_::getFieldValue(valueField))); - } - - static void reset(value_type& v) { - v.first.reset(); - v.second.reset(); - } -}; - -template -class Iterator { - public: - typedef typename T::value_type value_type; - typedef ptrdiff_t difference_type; - typedef value_type* pointer; - typedef value_type& reference; - typedef std::input_iterator_tag iterator_category; - - // begin ctor - Iterator(global_ref&& helper) - : helper_(std::move(helper)) - , i_(-1) { - ++(*this); - } - - // end ctor - Iterator() - : i_(-1) {} - - bool operator==(const Iterator& it) const { return i_ == it.i_; } - bool operator!=(const Iterator& it) const { return !(*this == it); } - const value_type& operator*() const { assert(i_ != -1); return entry_; } - const value_type* operator->() const { assert(i_ != -1); return &entry_; } - Iterator& operator++() { // preincrement - bool hasNext = helper_->hasNext(); - if (hasNext) { - ++i_; - entry_ = helper_->next(); - } else { - i_ = -1; - helper_->reset(entry_); - } - return *this; - } - Iterator operator++(int) { // postincrement - Iterator ret; - ret.i_ = i_; - ret.entry_ = std::move(entry_); - ++(*this); - return ret; - } - - global_ref helper_; - // set to -1 at end - std::ptrdiff_t i_; - value_type entry_; -}; - -} - -template -struct JIterator::Iterator : public detail::Iterator> { - using detail::Iterator>::Iterator; -}; - -template -typename JIterator::Iterator JIterator::begin() const { - static auto ctor = detail::IteratorHelper::javaClassStatic()-> - template getConstructor::javaobject( - typename JIterator::javaobject)>(); - return Iterator( - make_global( - detail::IteratorHelper::javaClassStatic()->newObject(ctor, this->self()))); -} - -template -typename JIterator::Iterator JIterator::end() const { - return Iterator(); -} - -template -struct JIterable::Iterator : public detail::Iterator> { - using detail::Iterator>::Iterator; -}; - -template -typename JIterable::Iterator JIterable::begin() const { - static auto ctor = detail::IteratorHelper::javaClassStatic()-> - template getConstructor::javaobject( - typename JIterable::javaobject)>(); - return Iterator( - make_global( - detail::IteratorHelper::javaClassStatic()->newObject(ctor, this->self()))); -} - -template -typename JIterable::Iterator JIterable::end() const { - return Iterator(); -} - -template -size_t JCollection::size() const { - static auto sizeMethod = - JCollection::javaClassStatic()->template getMethod("size"); - return sizeMethod(this->self()); -} - -template -struct JMap::Iterator : public detail::Iterator> { - using detail::Iterator>::Iterator; -}; - -template -size_t JMap::size() const { - static auto sizeMethod = - JMap::javaClassStatic()->template getMethod("size"); - return sizeMethod(this->self()); -} - -template -typename JMap::Iterator JMap::begin() const { - static auto ctor = detail::MapIteratorHelper::javaClassStatic()-> - template getConstructor::javaobject( - typename JMap::javaobject)>(); - return Iterator( - make_global( - detail::MapIteratorHelper::javaClassStatic()->newObject(ctor, this->self()))); -} - -template -typename JMap::Iterator JMap::end() const { - return Iterator(); -} - -} -} diff --git a/lib/fb/src/main/cpp/include/fb/fbjni/Iterator.h b/lib/fb/src/main/cpp/include/fb/fbjni/Iterator.h deleted file mode 100644 index 0da2c362..00000000 --- a/lib/fb/src/main/cpp/include/fb/fbjni/Iterator.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "CoreClasses.h" - -namespace facebook { -namespace jni { - -/** - * JavaClass which represents a reference to a java.util.Iterator instance. It - * provides begin()/end() methods to provide C++-style iteration over the - * underlying collection. The class has a template parameter for the element - * type, which defaults to jobject. For example: - * - * alias_ref::javaobject> my_iter = ...; - * - * In the simplest case, it can be used just as alias_ref::javaobject>, - * for example in a method declaration. - */ -template -struct JIterator : JavaClass> { - constexpr static auto kJavaDescriptor = "Ljava/util/Iterator;"; - - struct Iterator; - - /** - * To iterate: - * - * for (const auto& element : *jiter) { ... } - * - * The JIterator iterator value_type is local_ref, containing a reference - * to an element instance. - * - * If the Iterator returns objects whch are not convertible to the given - * element type, iteration will throw a java ClassCastException. - * - * For example, to convert an iterator over a collection of java strings to - * an std::vector of std::strings: - * - * std::vector vs; - * for (const auto& elem : *jiter) { - * vs.push_back(elem->toStdString()); - * } - * - * Or if you prefer using std algorithms: - * - * std::vector vs; - * std::transform(jiter->begin(), jiter->end(), std::back_inserter(vs), - * [](const local_ref& elem) { return elem->toStdString(); }); - * - * The iterator is a InputIterator. - */ - Iterator begin() const; - Iterator end() const; -}; - -/** - * Similar to JIterator, except this represents any object which implements the - * java.lang.Iterable interface. It will create the Java Iterator as a part of - * begin(). - */ -template -struct JIterable : JavaClass> { - constexpr static auto kJavaDescriptor = "Ljava/lang/Iterable;"; - - struct Iterator; - - Iterator begin() const; - Iterator end() const; -}; - -/** - * JavaClass types which represent Collection, List, and Set are also provided. - * These preserve the Java class heirarchy. - */ -template -struct JCollection : JavaClass, JIterable> { - constexpr static auto kJavaDescriptor = "Ljava/util/Collection;"; - - /** - * Returns the number of elements in the collection. - */ - size_t size() const; -}; - -template -struct JList : JavaClass, JCollection> { - constexpr static auto kJavaDescriptor = "Ljava/util/List;"; -}; - -template -struct JSet : JavaClass, JCollection> { - constexpr static auto kJavaDescriptor = "Ljava/util/Set;"; -}; - -/** - * JavaClass which represents a reference to a java.util.Map instance. It adds - * wrappers around Java methods, including begin()/end() methods to provide - * C++-style iteration over the Java Map. The class has template parameters - * for the key and value types, which default to jobject. For example: - * - * alias_ref::javaobject> my_map = ...; - * - * In the simplest case, it can be used just as alias_ref::javaobject>, - * for example in a method declaration. - */ -template -struct JMap : JavaClass> { - constexpr static auto kJavaDescriptor = "Ljava/util/Map;"; - - struct Iterator; - - /** - * Returns the number of pairs in the map. - */ - size_t size() const; - - /** - * To iterate over the Map: - * - * for (const auto& entry : *jmap) { ... } - * - * The JMap iterator value_type is std::pair, local_ref> - * containing references to key and value instances. - * - * If the Map contains objects whch are not convertible to the given key and - * value types, iteration will throw a java ClassCastException. - * - * The iterator is a InputIterator. - */ - Iterator begin() const; - Iterator end() const; -}; - -} -} - -#include "Iterator-inl.h" diff --git a/lib/fb/src/main/cpp/include/fb/fbjni/JThread.h b/lib/fb/src/main/cpp/include/fb/fbjni/JThread.h deleted file mode 100644 index 1bb61199..00000000 --- a/lib/fb/src/main/cpp/include/fb/fbjni/JThread.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2016-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "CoreClasses.h" -#include "NativeRunnable.h" - -namespace facebook { -namespace jni { - -class JThread : public JavaClass { - public: - static constexpr const char* kJavaDescriptor = "Ljava/lang/Thread;"; - - void start() { - static auto method = javaClassStatic()->getMethod("start"); - method(self()); - } - - void join() { - static auto method = javaClassStatic()->getMethod("join"); - method(self()); - } - - static local_ref create(std::function&& runnable) { - auto jrunnable = JNativeRunnable::newObjectCxxArgs(std::move(runnable)); - return newInstance(static_ref_cast(jrunnable)); - } -}; - -} -} diff --git a/lib/fb/src/main/cpp/include/fb/fbjni/Meta-forward.h b/lib/fb/src/main/cpp/include/fb/fbjni/Meta-forward.h deleted file mode 100644 index 60dfee44..00000000 --- a/lib/fb/src/main/cpp/include/fb/fbjni/Meta-forward.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -namespace facebook { -namespace jni { - -template -class JMethod; -template -class JStaticMethod; -template -class JNonvirtualMethod; -template -struct JConstructor; -template -class JField; -template -class JStaticField; - -/// Type traits for Java types (currently providing Java type descriptors) -template -struct jtype_traits; - -/// Type traits for Java methods (currently providing Java type descriptors) -template -struct jmethod_traits; - -}} diff --git a/lib/fb/src/main/cpp/include/fb/fbjni/Meta-inl.h b/lib/fb/src/main/cpp/include/fb/fbjni/Meta-inl.h deleted file mode 100644 index ff4c016b..00000000 --- a/lib/fb/src/main/cpp/include/fb/fbjni/Meta-inl.h +++ /dev/null @@ -1,430 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include - -#include "Common.h" -#include "Exceptions.h" -#include "MetaConvert.h" -#include "References.h" -#include "Boxed.h" - -#if defined(__ANDROID__) -#include -#endif - -namespace facebook { -namespace jni { - -// JMethod ///////////////////////////////////////////////////////////////////////////////////////// - -inline JMethodBase::JMethodBase(jmethodID method_id) noexcept - : method_id_{method_id} -{} - -inline JMethodBase::operator bool() const noexcept { - return method_id_ != nullptr; -} - -inline jmethodID JMethodBase::getId() const noexcept { - return method_id_; -} - -namespace { - -template -struct ArgsArraySetter; - -template -struct ArgsArraySetter { - static void set(alias_ref::javaobject> array, Arg arg0, Args... args) { - // TODO(xxxxxxxx): Use Convert... to do conversions like the fast path. - (*array)[idx] = autobox(arg0); - ArgsArraySetter::set(array, args...); - } -}; - -template -struct ArgsArraySetter { - static void set(alias_ref::javaobject> array) { - } -}; - -template -local_ref::javaobject> makeArgsArray(Args... args) { - auto arr = JArrayClass::newArray(sizeof...(args)); - ArgsArraySetter<0, Args...>::set(arr, args...); - return arr; -} - - -inline bool needsSlowPath(alias_ref obj) { -#if defined(__ANDROID__) - // On Android 6.0, art crashes when attempting to call a function on a Proxy. - // So, when we detect that case we must use the safe, slow workaround. That is, - // we resolve the method id to the corresponding java.lang.reflect.Method object - // and make the call via it's invoke() method. - static auto android_sdk = ([] { - char sdk_version_str[PROP_VALUE_MAX]; - __system_property_get("ro.build.version.sdk", sdk_version_str); - return atoi(sdk_version_str); - })(); - static auto is_bad_android = android_sdk == 23; - if (!is_bad_android) return false; - static auto proxy_class = findClassStatic("java/lang/reflect/Proxy"); - return obj->isInstanceOf(proxy_class); -#else - return false; -#endif -} - -} - -template -inline void JMethod::operator()(alias_ref self, Args... args) { - const auto env = Environment::current(); - env->CallVoidMethod( - self.get(), - getId(), - detail::callToJni(detail::Convert::type>::toCall(args))...); - FACEBOOK_JNI_THROW_PENDING_EXCEPTION(); -} - -#pragma push_macro("DEFINE_PRIMITIVE_CALL") -#undef DEFINE_PRIMITIVE_CALL -#define DEFINE_PRIMITIVE_CALL(TYPE, METHOD, CLASS) \ -template \ -inline TYPE JMethod::operator()(alias_ref self, Args... args) { \ - const auto env = internal::getEnv(); \ - auto result = env->Call ## METHOD ## Method( \ - self.get(), \ - getId(), \ - detail::callToJni(detail::Convert::type>::toCall(args))...); \ - FACEBOOK_JNI_THROW_PENDING_EXCEPTION(); \ - return result; \ -} - -DEFINE_PRIMITIVE_CALL(jboolean, Boolean, JBoolean) -DEFINE_PRIMITIVE_CALL(jbyte, Byte, JByte) -DEFINE_PRIMITIVE_CALL(jchar, Char, JCharacter) -DEFINE_PRIMITIVE_CALL(jshort, Short, JShort) -DEFINE_PRIMITIVE_CALL(jint, Int, JInteger) -DEFINE_PRIMITIVE_CALL(jlong, Long, JLong) -DEFINE_PRIMITIVE_CALL(jfloat, Float, JFloat) -DEFINE_PRIMITIVE_CALL(jdouble, Double, JDouble) -#pragma pop_macro("DEFINE_PRIMITIVE_CALL") - -/// JMethod specialization for references that wraps the return value in a @ref local_ref -template -class JMethod : public JMethodBase { - public: - // TODO: static_assert is jobject-derived or local_ref jobject - using JniRet = typename detail::Convert::type>::jniType; - static_assert(IsPlainJniReference(), "JniRet must be a JNI reference"); - using JMethodBase::JMethodBase; - JMethod() noexcept {}; - JMethod(const JMethod& other) noexcept = default; - - /// Invoke a method and return a local reference wrapping the result - local_ref operator()(alias_ref self, Args... args); - - friend class JClass; -}; - -template -inline auto JMethod::operator()(alias_ref self, Args... args) -> local_ref { - const auto env = Environment::current(); - auto result = env->CallObjectMethod( - self.get(), - getId(), - detail::callToJni(detail::Convert::type>::toCall(args))...); - FACEBOOK_JNI_THROW_PENDING_EXCEPTION(); - return adopt_local(static_cast(result)); -} - -template -inline void JStaticMethod::operator()(alias_ref cls, Args... args) { - const auto env = internal::getEnv(); - env->CallStaticVoidMethod( - cls.get(), - getId(), - detail::callToJni(detail::Convert::type>::toCall(args))...); - FACEBOOK_JNI_THROW_PENDING_EXCEPTION(); -} - -#pragma push_macro("DEFINE_PRIMITIVE_STATIC_CALL") -#undef DEFINE_PRIMITIVE_STATIC_CALL -#define DEFINE_PRIMITIVE_STATIC_CALL(TYPE, METHOD) \ -template \ -inline TYPE JStaticMethod::operator()(alias_ref cls, Args... args) { \ - const auto env = internal::getEnv(); \ - auto result = env->CallStatic ## METHOD ## Method( \ - cls.get(), \ - getId(), \ - detail::callToJni(detail::Convert::type>::toCall(args))...); \ - FACEBOOK_JNI_THROW_PENDING_EXCEPTION(); \ - return result; \ -} - -DEFINE_PRIMITIVE_STATIC_CALL(jboolean, Boolean) -DEFINE_PRIMITIVE_STATIC_CALL(jbyte, Byte) -DEFINE_PRIMITIVE_STATIC_CALL(jchar, Char) -DEFINE_PRIMITIVE_STATIC_CALL(jshort, Short) -DEFINE_PRIMITIVE_STATIC_CALL(jint, Int) -DEFINE_PRIMITIVE_STATIC_CALL(jlong, Long) -DEFINE_PRIMITIVE_STATIC_CALL(jfloat, Float) -DEFINE_PRIMITIVE_STATIC_CALL(jdouble, Double) -#pragma pop_macro("DEFINE_PRIMITIVE_STATIC_CALL") - -/// JStaticMethod specialization for references that wraps the return value in a @ref local_ref -template -class JStaticMethod : public JMethodBase { - - public: - using JniRet = typename detail::Convert::type>::jniType; - static_assert(IsPlainJniReference(), "T* must be a JNI reference"); - using JMethodBase::JMethodBase; - JStaticMethod() noexcept {}; - JStaticMethod(const JStaticMethod& other) noexcept = default; - - /// Invoke a method and return a local reference wrapping the result - local_ref operator()(alias_ref cls, Args... args) { - const auto env = internal::getEnv(); - auto result = env->CallStaticObjectMethod( - cls.get(), - getId(), - detail::callToJni(detail::Convert::type>::toCall(args))...); - FACEBOOK_JNI_THROW_PENDING_EXCEPTION(); - return adopt_local(static_cast(result)); - } - - friend class JClass; -}; - -template -inline void -JNonvirtualMethod::operator()(alias_ref self, alias_ref cls, Args... args) { - const auto env = internal::getEnv(); - env->CallNonvirtualVoidMethod( - self.get(), - cls.get(), - getId(), - detail::callToJni(detail::Convert::type>::toCall(args))...); - FACEBOOK_JNI_THROW_PENDING_EXCEPTION(); -} - -#pragma push_macro("DEFINE_PRIMITIVE_NON_VIRTUAL_CALL") -#undef DEFINE_PRIMITIVE_NON_VIRTUAL_CALL -#define DEFINE_PRIMITIVE_NON_VIRTUAL_CALL(TYPE, METHOD) \ -template \ -inline TYPE \ -JNonvirtualMethod::operator()(alias_ref self, alias_ref cls, Args... args) { \ - const auto env = internal::getEnv(); \ - auto result = env->CallNonvirtual ## METHOD ## Method( \ - self.get(), \ - cls.get(), \ - getId(), \ - detail::callToJni(detail::Convert::type>::toCall(args))...); \ - FACEBOOK_JNI_THROW_PENDING_EXCEPTION(); \ - return result; \ -} - -DEFINE_PRIMITIVE_NON_VIRTUAL_CALL(jboolean, Boolean) -DEFINE_PRIMITIVE_NON_VIRTUAL_CALL(jbyte, Byte) -DEFINE_PRIMITIVE_NON_VIRTUAL_CALL(jchar, Char) -DEFINE_PRIMITIVE_NON_VIRTUAL_CALL(jshort, Short) -DEFINE_PRIMITIVE_NON_VIRTUAL_CALL(jint, Int) -DEFINE_PRIMITIVE_NON_VIRTUAL_CALL(jlong, Long) -DEFINE_PRIMITIVE_NON_VIRTUAL_CALL(jfloat, Float) -DEFINE_PRIMITIVE_NON_VIRTUAL_CALL(jdouble, Double) -#pragma pop_macro("DEFINE_PRIMITIVE_NON_VIRTUAL_CALL") - -/// JNonvirtualMethod specialization for references that wraps the return value in a @ref local_ref -template -class JNonvirtualMethod : public JMethodBase { - public: - using JniRet = typename detail::Convert::type>::jniType; - static_assert(IsPlainJniReference(), "T* must be a JNI reference"); - using JMethodBase::JMethodBase; - JNonvirtualMethod() noexcept {}; - JNonvirtualMethod(const JNonvirtualMethod& other) noexcept = default; - - /// Invoke a method and return a local reference wrapping the result - local_ref operator()(alias_ref self, alias_ref cls, Args... args){ - const auto env = internal::getEnv(); - auto result = env->CallNonvirtualObjectMethod( - self.get(), - cls.get(), - getId(), - detail::callToJni(detail::Convert::type>::toCall(args))...); - FACEBOOK_JNI_THROW_PENDING_EXCEPTION(); - return adopt_local(static_cast(result)); - } - - friend class JClass; -}; - -template -local_ref slowCall(jmethodID method_id, alias_ref self, Args... args) { - static auto invoke = findClassStatic("java/lang/reflect/Method") - ->getMethod::javaobject)>("invoke"); - // TODO(xxxxxxx): Provide fbjni interface to ToReflectedMethod. - auto reflected = adopt_local(Environment::current()->ToReflectedMethod(self->getClass().get(), method_id, JNI_FALSE)); - FACEBOOK_JNI_THROW_PENDING_EXCEPTION(); - if (!reflected) throw std::runtime_error("Unable to get reflected java.lang.reflect.Method"); - auto argsArray = makeArgsArray(args...); - // No need to check for exceptions since invoke is itself a JMethod that will do that for us. - return invoke(reflected, self.get(), argsArray.get()); -} - - -// JField /////////////////////////////////////////////////////////////////////////////////////// - -template -inline JField::JField(jfieldID field) noexcept - : field_id_{field} -{} - -template -inline JField::operator bool() const noexcept { - return field_id_ != nullptr; -} - -template -inline jfieldID JField::getId() const noexcept { - return field_id_; -} - -#pragma push_macro("DEFINE_FIELD_PRIMITIVE_GET_SET") -#undef DEFINE_FIELD_PRIMITIVE_GET_SET -#define DEFINE_FIELD_PRIMITIVE_GET_SET(TYPE, METHOD) \ -template<> \ -inline TYPE JField::get(jobject object) const noexcept { \ - const auto env = internal::getEnv(); \ - return env->Get ## METHOD ## Field(object, field_id_); \ -} \ - \ -template<> \ -inline void JField::set(jobject object, TYPE value) noexcept { \ - const auto env = internal::getEnv(); \ - env->Set ## METHOD ## Field(object, field_id_, value); \ -} - -DEFINE_FIELD_PRIMITIVE_GET_SET(jboolean, Boolean) -DEFINE_FIELD_PRIMITIVE_GET_SET(jbyte, Byte) -DEFINE_FIELD_PRIMITIVE_GET_SET(jchar, Char) -DEFINE_FIELD_PRIMITIVE_GET_SET(jshort, Short) -DEFINE_FIELD_PRIMITIVE_GET_SET(jint, Int) -DEFINE_FIELD_PRIMITIVE_GET_SET(jlong, Long) -DEFINE_FIELD_PRIMITIVE_GET_SET(jfloat, Float) -DEFINE_FIELD_PRIMITIVE_GET_SET(jdouble, Double) -#pragma pop_macro("DEFINE_FIELD_PRIMITIVE_GET_SET") - -template -inline T JField::get(jobject object) const noexcept { - return static_cast(internal::getEnv()->GetObjectField(object, field_id_)); -} - -template -inline void JField::set(jobject object, T value) noexcept { - internal::getEnv()->SetObjectField(object, field_id_, static_cast(value)); -} - -// JStaticField ///////////////////////////////////////////////////////////////////////////////// - -template -inline JStaticField::JStaticField(jfieldID field) noexcept - : field_id_{field} -{} - -template -inline JStaticField::operator bool() const noexcept { - return field_id_ != nullptr; -} - -template -inline jfieldID JStaticField::getId() const noexcept { - return field_id_; -} - -#pragma push_macro("DEFINE_STATIC_FIELD_PRIMITIVE_GET_SET") -#undef DEFINE_STATIC_FIELD_PRIMITIVE_GET_SET -#define DEFINE_STATIC_FIELD_PRIMITIVE_GET_SET(TYPE, METHOD) \ -template<> \ -inline TYPE JStaticField::get(jclass jcls) const noexcept { \ - const auto env = internal::getEnv(); \ - return env->GetStatic ## METHOD ## Field(jcls, field_id_); \ -} \ - \ -template<> \ -inline void JStaticField::set(jclass jcls, TYPE value) noexcept { \ - const auto env = internal::getEnv(); \ - env->SetStatic ## METHOD ## Field(jcls, field_id_, value); \ -} - -DEFINE_STATIC_FIELD_PRIMITIVE_GET_SET(jboolean, Boolean) -DEFINE_STATIC_FIELD_PRIMITIVE_GET_SET(jbyte, Byte) -DEFINE_STATIC_FIELD_PRIMITIVE_GET_SET(jchar, Char) -DEFINE_STATIC_FIELD_PRIMITIVE_GET_SET(jshort, Short) -DEFINE_STATIC_FIELD_PRIMITIVE_GET_SET(jint, Int) -DEFINE_STATIC_FIELD_PRIMITIVE_GET_SET(jlong, Long) -DEFINE_STATIC_FIELD_PRIMITIVE_GET_SET(jfloat, Float) -DEFINE_STATIC_FIELD_PRIMITIVE_GET_SET(jdouble, Double) -#pragma pop_macro("DEFINE_STATIC_FIELD_PRIMITIVE_GET_SET") - -template -inline T JStaticField::get(jclass jcls) const noexcept { - const auto env = internal::getEnv(); - return static_cast(env->GetStaticObjectField(jcls, field_id_)); -} - -template -inline void JStaticField::set(jclass jcls, T value) noexcept { - internal::getEnv()->SetStaticObjectField(jcls, field_id_, value); -} - - -// jmethod_traits ////////////////////////////////////////////////////////////////////////////////// - -// TODO(T6608405) Adapt this to implement a register natives method that requires no descriptor -namespace internal { - -template -inline std::string JavaDescriptor() { - return jtype_traits::descriptor(); -} - -template -inline std::string JavaDescriptor() { - return JavaDescriptor() + JavaDescriptor(); -} - -template -inline std::string JMethodDescriptor() { - return "(" + JavaDescriptor() + ")" + JavaDescriptor(); -} - -template -inline std::string JMethodDescriptor() { - return "()" + JavaDescriptor(); -} - -} // internal - -template -inline std::string jmethod_traits::descriptor() { - return internal::JMethodDescriptor(); -} - -template -inline std::string jmethod_traits::constructor_descriptor() { - return internal::JMethodDescriptor(); -} - -}} diff --git a/lib/fb/src/main/cpp/include/fb/fbjni/Meta.h b/lib/fb/src/main/cpp/include/fb/fbjni/Meta.h deleted file mode 100644 index e9717bf7..00000000 --- a/lib/fb/src/main/cpp/include/fb/fbjni/Meta.h +++ /dev/null @@ -1,338 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -/** @file meta.h - * - * Provides wrappers for meta data such as methods and fields. - */ - -#pragma once - -#include -#include - -#include - -#include "References-forward.h" - -#ifdef __ANDROID__ -# include -# define XLOG_TAG "fb-jni" -# define XLOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, XLOG_TAG, __VA_ARGS__) -# define XLOGD(...) __android_log_print(ANDROID_LOG_DEBUG, XLOG_TAG, __VA_ARGS__) -# define XLOGI(...) __android_log_print(ANDROID_LOG_INFO, XLOG_TAG, __VA_ARGS__) -# define XLOGW(...) __android_log_print(ANDROID_LOG_WARN, XLOG_TAG, __VA_ARGS__) -# define XLOGE(...) __android_log_print(ANDROID_LOG_ERROR, XLOG_TAG, __VA_ARGS__) -# define XLOGWTF(...) __android_log_print(ANDROID_LOG_FATAL, XLOG_TAG, __VA_ARGS__) -#endif - -namespace facebook { -namespace jni { - -// This will get the reflected Java Method from the method_id, get it's invoke -// method, and call the method via that. This shouldn't ever be needed, but -// Android 6.0 crashes when calling a method on a java.lang.Proxy via jni. -template -local_ref slowCall(jmethodID method_id, alias_ref self, Args... args); - -class JObject; - - -/// Wrapper of a jmethodID. Provides a common base for JMethod specializations -class JMethodBase { - public: - /// Verify that the method is valid - explicit operator bool() const noexcept; - - /// Access the wrapped id - jmethodID getId() const noexcept; - - protected: - /// Create a wrapper of a method id - explicit JMethodBase(jmethodID method_id = nullptr) noexcept; - - private: - jmethodID method_id_; -}; - - -/// Representation of a jmethodID -template -class JMethod; - -/// @cond INTERNAL -#pragma push_macro("DEFINE_PRIMITIVE_METHOD_CLASS") - -#undef DEFINE_PRIMITIVE_METHOD_CLASS - -// Defining JMethod specializations based on return value -#define DEFINE_PRIMITIVE_METHOD_CLASS(TYPE) \ -template \ -class JMethod : public JMethodBase { \ - public: \ - static_assert(std::is_void::value || IsJniPrimitive(), \ - "TYPE must be primitive or void"); \ - \ - using JMethodBase::JMethodBase; \ - JMethod() noexcept {}; \ - JMethod(const JMethod& other) noexcept = default; \ - \ - TYPE operator()(alias_ref self, Args... args); \ - \ - friend class JClass; \ -} - -DEFINE_PRIMITIVE_METHOD_CLASS(void); -DEFINE_PRIMITIVE_METHOD_CLASS(jboolean); -DEFINE_PRIMITIVE_METHOD_CLASS(jbyte); -DEFINE_PRIMITIVE_METHOD_CLASS(jchar); -DEFINE_PRIMITIVE_METHOD_CLASS(jshort); -DEFINE_PRIMITIVE_METHOD_CLASS(jint); -DEFINE_PRIMITIVE_METHOD_CLASS(jlong); -DEFINE_PRIMITIVE_METHOD_CLASS(jfloat); -DEFINE_PRIMITIVE_METHOD_CLASS(jdouble); - -#pragma pop_macro("DEFINE_PRIMITIVE_METHOD_CLASS") -/// @endcond - - -/// Convenience type representing constructors -/// These should only be used with JClass::getConstructor and JClass::newObject. -template -struct JConstructor : private JMethod { - using JMethod::JMethod; - private: - JConstructor(const JMethod& other) : JMethod(other.getId()) {} - friend class JClass; -}; - -/// Representation of a jStaticMethodID -template -class JStaticMethod; - -/// @cond INTERNAL -#pragma push_macro("DEFINE_PRIMITIVE_STATIC_METHOD_CLASS") - -#undef DEFINE_PRIMITIVE_STATIC_METHOD_CLASS - -// Defining JStaticMethod specializations based on return value -#define DEFINE_PRIMITIVE_STATIC_METHOD_CLASS(TYPE) \ -template \ -class JStaticMethod : public JMethodBase { \ - static_assert(std::is_void::value || IsJniPrimitive(), \ - "T must be a JNI primitive or void"); \ - \ - public: \ - using JMethodBase::JMethodBase; \ - JStaticMethod() noexcept {}; \ - JStaticMethod(const JStaticMethod& other) noexcept = default; \ - \ - TYPE operator()(alias_ref cls, Args... args); \ - \ - friend class JClass; \ -} - -DEFINE_PRIMITIVE_STATIC_METHOD_CLASS(void); -DEFINE_PRIMITIVE_STATIC_METHOD_CLASS(jboolean); -DEFINE_PRIMITIVE_STATIC_METHOD_CLASS(jbyte); -DEFINE_PRIMITIVE_STATIC_METHOD_CLASS(jchar); -DEFINE_PRIMITIVE_STATIC_METHOD_CLASS(jshort); -DEFINE_PRIMITIVE_STATIC_METHOD_CLASS(jint); -DEFINE_PRIMITIVE_STATIC_METHOD_CLASS(jlong); -DEFINE_PRIMITIVE_STATIC_METHOD_CLASS(jfloat); -DEFINE_PRIMITIVE_STATIC_METHOD_CLASS(jdouble); - -#pragma pop_macro("DEFINE_PRIMITIVE_STATIC_METHOD_CLASS") -/// @endcond - - -/// Representation of a jNonvirtualMethodID -template -class JNonvirtualMethod; - -/// @cond INTERNAL -#pragma push_macro("DEFINE_PRIMITIVE_NON_VIRTUAL_METHOD_CLASS") - -#undef DEFINE_PRIMITIVE_NON_VIRTUAL_METHOD_CLASS - -// Defining JNonvirtualMethod specializations based on return value -#define DEFINE_PRIMITIVE_NON_VIRTUAL_METHOD_CLASS(TYPE) \ -template \ -class JNonvirtualMethod : public JMethodBase { \ - static_assert(std::is_void::value || IsJniPrimitive(), \ - "T must be a JNI primitive or void"); \ - \ - public: \ - using JMethodBase::JMethodBase; \ - JNonvirtualMethod() noexcept {}; \ - JNonvirtualMethod(const JNonvirtualMethod& other) noexcept = default; \ - \ - TYPE operator()(alias_ref self, alias_ref cls, Args... args); \ - \ - friend class JClass; \ -} - -DEFINE_PRIMITIVE_NON_VIRTUAL_METHOD_CLASS(void); -DEFINE_PRIMITIVE_NON_VIRTUAL_METHOD_CLASS(jboolean); -DEFINE_PRIMITIVE_NON_VIRTUAL_METHOD_CLASS(jbyte); -DEFINE_PRIMITIVE_NON_VIRTUAL_METHOD_CLASS(jchar); -DEFINE_PRIMITIVE_NON_VIRTUAL_METHOD_CLASS(jshort); -DEFINE_PRIMITIVE_NON_VIRTUAL_METHOD_CLASS(jint); -DEFINE_PRIMITIVE_NON_VIRTUAL_METHOD_CLASS(jlong); -DEFINE_PRIMITIVE_NON_VIRTUAL_METHOD_CLASS(jfloat); -DEFINE_PRIMITIVE_NON_VIRTUAL_METHOD_CLASS(jdouble); - -#pragma pop_macro("DEFINE_PRIMITIVE_NON_VIRTUAL_METHOD_CLASS") -/// @endcond - - -/** - * JField represents typed fields and simplifies their access. Note that object types return - * raw pointers which generally should promptly get a wrap_local treatment. - */ -template -class JField { - static_assert(IsJniScalar(), "T must be a JNI scalar"); - - public: - /// Wraps an existing field id - explicit JField(jfieldID field = nullptr) noexcept; - - /// Verify that the id is valid - explicit operator bool() const noexcept; - - /// Access the wrapped id - jfieldID getId() const noexcept; - - private: - jfieldID field_id_; - - /// Get field value - /// @pre object != nullptr - T get(jobject object) const noexcept; - - /// Set field value - /// @pre object != nullptr - void set(jobject object, T value) noexcept; - - friend class JObject; -}; - - -/** - * JStaticField represents typed fields and simplifies their access. Note that object types - * return raw pointers which generally should promptly get a wrap_local treatment. - */ -template -class JStaticField { - static_assert(IsJniScalar(), "T must be a JNI scalar"); - - public: - /// Wraps an existing field id - explicit JStaticField(jfieldID field = nullptr) noexcept; - - /// Verify that the id is valid - explicit operator bool() const noexcept; - - /// Access the wrapped id - jfieldID getId() const noexcept; - - private: - jfieldID field_id_; - - /// Get field value - /// @pre object != nullptr - T get(jclass jcls) const noexcept; - - /// Set field value - /// @pre object != nullptr - void set(jclass jcls, T value) noexcept; - - friend class JClass; - friend class JObject; -}; - - -/// Template magic to provide @ref jmethod_traits -template -struct jmethod_traits { - static std::string descriptor(); - static std::string constructor_descriptor(); -}; - - -// jtype_traits //////////////////////////////////////////////////////////////////////////////////// - -template -struct jtype_traits { -private: - using Repr = ReprType; -public: - // The jni type signature (described at - // http://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/types.html). - static std::string descriptor() { - std::string descriptor; - if (Repr::kJavaDescriptor == nullptr) { - descriptor = Repr::get_instantiated_java_descriptor(); - } else { - descriptor = Repr::kJavaDescriptor; - } - return descriptor; - } - - // The signature used for class lookups. See - // http://docs.oracle.com/javase/6/docs/api/java/lang/Class.html#getName(). - static std::string base_name() { - if (Repr::kJavaDescriptor != nullptr) { - std::string base_name = Repr::kJavaDescriptor; - return base_name.substr(1, base_name.size() - 2); - } - return Repr::get_instantiated_base_name(); - } -}; - -#pragma push_macro("DEFINE_FIELD_AND_ARRAY_TRAIT") -#undef DEFINE_FIELD_AND_ARRAY_TRAIT - -#define DEFINE_FIELD_AND_ARRAY_TRAIT(TYPE, DSC) \ -template<> \ -struct jtype_traits { \ - static std::string descriptor() { return std::string{#DSC}; } \ - static std::string base_name() { return descriptor(); } \ - using array_type = TYPE ## Array; \ -}; \ -template<> \ -struct jtype_traits { \ - static std::string descriptor() { return std::string{"[" #DSC}; } \ - static std::string base_name() { return descriptor(); } \ - using entry_type = TYPE; \ -}; - -// There is no voidArray, handle that without the macro. -template<> -struct jtype_traits { - static std::string descriptor() { return std::string{"V"}; }; -}; - -DEFINE_FIELD_AND_ARRAY_TRAIT(jboolean, Z) -DEFINE_FIELD_AND_ARRAY_TRAIT(jbyte, B) -DEFINE_FIELD_AND_ARRAY_TRAIT(jchar, C) -DEFINE_FIELD_AND_ARRAY_TRAIT(jshort, S) -DEFINE_FIELD_AND_ARRAY_TRAIT(jint, I) -DEFINE_FIELD_AND_ARRAY_TRAIT(jlong, J) -DEFINE_FIELD_AND_ARRAY_TRAIT(jfloat, F) -DEFINE_FIELD_AND_ARRAY_TRAIT(jdouble, D) - -#pragma pop_macro("DEFINE_FIELD_AND_ARRAY_TRAIT") - - -template -struct jmethod_traits_from_cxx; - -}} - -#include "Meta-inl.h" diff --git a/lib/fb/src/main/cpp/include/fb/fbjni/MetaConvert.h b/lib/fb/src/main/cpp/include/fb/fbjni/MetaConvert.h deleted file mode 100644 index 33027c7e..00000000 --- a/lib/fb/src/main/cpp/include/fb/fbjni/MetaConvert.h +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once - -#include - -#include "Common.h" -#include "References.h" - -namespace facebook { -namespace jni { - -namespace detail { - -// In order to avoid potentially filling the jni locals table, -// temporary objects (right now, this is just jstrings) need to be -// released. This is done by returning a holder which autoconverts to -// jstring. -template -inline T callToJni(T&& t) { - return t; -} - -template -inline JniType callToJni(local_ref&& sref) { - return sref.get(); -} - -// Normally, pass through types unmolested. -template -struct Convert { - typedef T jniType; - static jniType fromJni(jniType t) { - return t; - } - static jniType toJniRet(jniType t) { - return t; - } - static jniType toCall(jniType t) { - return t; - } -}; - -// This is needed for return conversion -template <> -struct Convert { - typedef void jniType; -}; - -// jboolean is an unsigned char, not a bool. Allow it to work either way. -template<> -struct Convert { - typedef jboolean jniType; - static bool fromJni(jniType t) { - return t; - } - static jniType toJniRet(bool t) { - return t; - } - static jniType toCall(bool t) { - return t; - } -}; - -// convert to alias_ref from T -template -struct Convert> { - typedef JniType jniType; - static alias_ref fromJni(jniType t) { - return wrap_alias(t); - } - static jniType toJniRet(alias_ref t) { - return t.get(); - } - static jniType toCall(alias_ref t) { - return t.get(); - } -}; - -// convert return from local_ref -template -struct Convert> { - typedef JniType jniType; - // No automatic synthesis of local_ref - static jniType toJniRet(local_ref t) { - return t.release(); - } - static jniType toCall(local_ref t) { - return t.get(); - } -}; - -// convert return from global_ref -template -struct Convert> { - typedef JniType jniType; - // No automatic synthesis of global_ref - static jniType toJniRet(global_ref t) { - return t.get(); - } - static jniType toCall(global_ref t) { - return t.get(); - } -}; - -template struct jni_sig_from_cxx_t; -template -struct jni_sig_from_cxx_t { - using JniRet = typename Convert::type>::jniType; - using JniSig = JniRet(typename Convert::type>::jniType...); -}; - -template -using jni_sig_from_cxx = typename jni_sig_from_cxx_t::JniSig; - -} // namespace detail - -template -struct jmethod_traits_from_cxx : jmethod_traits> { -}; - -}} diff --git a/lib/fb/src/main/cpp/include/fb/fbjni/NativeRunnable.h b/lib/fb/src/main/cpp/include/fb/fbjni/NativeRunnable.h deleted file mode 100644 index 0502e36b..00000000 --- a/lib/fb/src/main/cpp/include/fb/fbjni/NativeRunnable.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "CoreClasses.h" -#include "Hybrid.h" -#include "Registration.h" - -#include - -namespace facebook { -namespace jni { - -struct JRunnable : public JavaClass { - static auto constexpr kJavaDescriptor = "Ljava/lang/Runnable;"; -}; - -struct JNativeRunnable : public HybridClass { - public: - static auto constexpr kJavaDescriptor = "Lcom/facebook/jni/NativeRunnable;"; - - JNativeRunnable(std::function&& runnable) : runnable_(std::move(runnable)) {} - - static void OnLoad() { - registerHybrid({ - makeNativeMethod("run", JNativeRunnable::run), - }); - } - - void run() { - runnable_(); - } - - private: - std::function runnable_; -}; - - -} // namespace jni -} // namespace facebook diff --git a/lib/fb/src/main/cpp/include/fb/fbjni/ReferenceAllocators-inl.h b/lib/fb/src/main/cpp/include/fb/fbjni/ReferenceAllocators-inl.h deleted file mode 100644 index 65b9828c..00000000 --- a/lib/fb/src/main/cpp/include/fb/fbjni/ReferenceAllocators-inl.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include -#include - -namespace facebook { -namespace jni { - -/// @cond INTERNAL -namespace internal { - -// Statistics mostly provided for test (only updated if FBJNI_DEBUG_REFS is defined) -struct ReferenceStats { - std::atomic_uint locals_deleted, globals_deleted, weaks_deleted; - - void reset() noexcept; -}; - -extern ReferenceStats g_reference_stats; -} -/// @endcond - - -// LocalReferenceAllocator ///////////////////////////////////////////////////////////////////////// - -inline jobject LocalReferenceAllocator::newReference(jobject original) const { - internal::dbglog("Local new: %p", original); - auto ref = internal::getEnv()->NewLocalRef(original); - FACEBOOK_JNI_THROW_PENDING_EXCEPTION(); - return ref; -} - -inline void LocalReferenceAllocator::deleteReference(jobject reference) const noexcept { - internal::dbglog("Local release: %p", reference); - - if (reference) { - #ifdef FBJNI_DEBUG_REFS - ++internal::g_reference_stats.locals_deleted; - #endif - assert(verifyReference(reference)); - internal::getEnv()->DeleteLocalRef(reference); - } -} - -inline bool LocalReferenceAllocator::verifyReference(jobject reference) const noexcept { - if (!reference || !internal::doesGetObjectRefTypeWork()) { - return true; - } - return internal::getEnv()->GetObjectRefType(reference) == JNILocalRefType; -} - - -// GlobalReferenceAllocator //////////////////////////////////////////////////////////////////////// - -inline jobject GlobalReferenceAllocator::newReference(jobject original) const { - internal::dbglog("Global new: %p", original); - auto ref = internal::getEnv()->NewGlobalRef(original); - FACEBOOK_JNI_THROW_PENDING_EXCEPTION(); - return ref; -} - -inline void GlobalReferenceAllocator::deleteReference(jobject reference) const noexcept { - internal::dbglog("Global release: %p", reference); - - if (reference) { - #ifdef FBJNI_DEBUG_REFS - ++internal::g_reference_stats.globals_deleted; - #endif - assert(verifyReference(reference)); - internal::getEnv()->DeleteGlobalRef(reference); - } -} - -inline bool GlobalReferenceAllocator::verifyReference(jobject reference) const noexcept { - if (!reference || !internal::doesGetObjectRefTypeWork()) { - return true; - } - return internal::getEnv()->GetObjectRefType(reference) == JNIGlobalRefType; -} - - -// WeakGlobalReferenceAllocator //////////////////////////////////////////////////////////////////// - -inline jobject WeakGlobalReferenceAllocator::newReference(jobject original) const { - internal::dbglog("Weak global new: %p", original); - auto ref = internal::getEnv()->NewWeakGlobalRef(original); - FACEBOOK_JNI_THROW_PENDING_EXCEPTION(); - return ref; -} - -inline void WeakGlobalReferenceAllocator::deleteReference(jobject reference) const noexcept { - internal::dbglog("Weak Global release: %p", reference); - - if (reference) { - #ifdef FBJNI_DEBUG_REFS - ++internal::g_reference_stats.weaks_deleted; - #endif - assert(verifyReference(reference)); - internal::getEnv()->DeleteWeakGlobalRef(reference); - } -} - -inline bool WeakGlobalReferenceAllocator::verifyReference(jobject reference) const noexcept { - if (!reference || !internal::doesGetObjectRefTypeWork()) { - return true; - } - return internal::getEnv()->GetObjectRefType(reference) == JNIWeakGlobalRefType; -} - -}} diff --git a/lib/fb/src/main/cpp/include/fb/fbjni/ReferenceAllocators.h b/lib/fb/src/main/cpp/include/fb/fbjni/ReferenceAllocators.h deleted file mode 100644 index a971263a..00000000 --- a/lib/fb/src/main/cpp/include/fb/fbjni/ReferenceAllocators.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -/** - * @file ReferenceAllocators.h - * - * Reference allocators are used to create and delete various classes of JNI references (local, - * global, and weak global). - */ - -#pragma once - -#include - -#include "Common.h" - -namespace facebook { namespace jni { - -/// Allocator that handles local references -class FBEXPORT LocalReferenceAllocator { - public: - jobject newReference(jobject original) const; - void deleteReference(jobject reference) const noexcept; - bool verifyReference(jobject reference) const noexcept; -}; - -/// Allocator that handles global references -class FBEXPORT GlobalReferenceAllocator { - public: - jobject newReference(jobject original) const; - void deleteReference(jobject reference) const noexcept; - bool verifyReference(jobject reference) const noexcept; -}; - -/// Allocator that handles weak global references -class FBEXPORT WeakGlobalReferenceAllocator { - public: - jobject newReference(jobject original) const; - void deleteReference(jobject reference) const noexcept; - bool verifyReference(jobject reference) const noexcept; -}; - -/// @cond INTERNAL -namespace internal { - -/** - * @return true iff env->GetObjectRefType is expected to work properly. - */ -FBEXPORT bool doesGetObjectRefTypeWork(); - -} -/// @endcond - -}} - -#include "ReferenceAllocators-inl.h" diff --git a/lib/fb/src/main/cpp/include/fb/fbjni/References-forward.h b/lib/fb/src/main/cpp/include/fb/fbjni/References-forward.h deleted file mode 100644 index 58ce511d..00000000 --- a/lib/fb/src/main/cpp/include/fb/fbjni/References-forward.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "ReferenceAllocators.h" - -namespace facebook { -namespace jni { - -template -class JObjectWrapper; - -namespace detail { -struct JObjectBase { - jobject get() const noexcept; - void set(jobject reference) noexcept; - jobject this_; -}; - -// RefReprType maps a type to the representation used by fbjni smart references. -template -struct RefReprType; - -template -struct JavaObjectType; - -template -struct ReprAccess; -} - -// Given T, either a jobject-like type or a JavaClass-derived type, ReprType -// is the corresponding JavaClass-derived type and JniType is the -// jobject-like type. -template -using ReprType = typename detail::RefReprType::type; - -template -using JniType = typename detail::JavaObjectType::type; - -template -class base_owned_ref; - -template -class basic_strong_ref; - -template -class weak_ref; - -template -class alias_ref; - -/// A smart unique reference owning a local JNI reference -template -using local_ref = basic_strong_ref; - -/// A smart unique reference owning a global JNI reference -template -using global_ref = basic_strong_ref; - -}} // namespace facebook::jni diff --git a/lib/fb/src/main/cpp/include/fb/fbjni/References-inl.h b/lib/fb/src/main/cpp/include/fb/fbjni/References-inl.h deleted file mode 100644 index 6bdc1815..00000000 --- a/lib/fb/src/main/cpp/include/fb/fbjni/References-inl.h +++ /dev/null @@ -1,508 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include "CoreClasses.h" - -namespace facebook { -namespace jni { - -template -inline enable_if_t(), T> getPlainJniReference(T ref) { - return ref; -} - -template -inline JniType getPlainJniReference(alias_ref ref) { - return ref.get(); -} - -template -inline JniType getPlainJniReference(const base_owned_ref& ref) { - return ref.get(); -} - - -namespace detail { -template -struct ReprAccess { - using javaobject = JniType; - static void set(Repr& repr, javaobject obj) noexcept { - repr.JObjectBase::set(obj); - } - static javaobject get(const Repr& repr) { - return static_cast(repr.JObject::get()); - } -}; - -namespace { -template -void StaticAssertValidRepr() noexcept { - static_assert(std::is_base_of::value, - "A smart ref representation must be derived from JObject."); - static_assert(IsPlainJniReference>(), "T must be a JNI reference"); - static_assert(sizeof(Repr) == sizeof(JObjectBase), ""); - static_assert(alignof(Repr) == alignof(JObjectBase), ""); -} -} - -template -ReprStorage::ReprStorage(JniType obj) noexcept { - StaticAssertValidRepr(); - set(obj); -} - -template -void ReprStorage::set(JniType obj) noexcept { - new (&storage_) Repr; - ReprAccess::set(get(), obj); -} - -template -Repr& ReprStorage::get() noexcept { - return *reinterpret_cast(&storage_); -} - -template -const Repr& ReprStorage::get() const noexcept { - return *reinterpret_cast(&storage_); -} - -template -JniType ReprStorage::jobj() const noexcept { - ReprAccess::get(get()); - return ReprAccess::get(get()); -} - -template -void ReprStorage::swap(ReprStorage& other) noexcept { - StaticAssertValidRepr(); - using std::swap; - swap(get(), other.get()); -} - -inline void JObjectBase::set(jobject reference) noexcept { - this_ = reference; -} - -inline jobject JObjectBase::get() const noexcept { - return this_; -} - -template -enable_if_t(), plain_jni_reference_t> make_ref(const T& reference) { - auto old_reference = getPlainJniReference(reference); - if (!old_reference) { - return nullptr; - } - - auto ref = Alloc{}.newReference(old_reference); - if (!ref) { - // Note that we end up here if we pass a weak ref that refers to a collected object. - // Thus, it's hard to come up with a reason why this function should be used with - // weak references. - throw std::bad_alloc{}; - } - - return static_cast>(ref); -} - -} // namespace detail - -template -inline local_ref adopt_local(T ref) noexcept { - static_assert(IsPlainJniReference(), "T must be a plain jni reference"); - return local_ref{ref}; -} - -template -inline global_ref adopt_global(T ref) noexcept { - static_assert(IsPlainJniReference(), "T must be a plain jni reference"); - return global_ref{ref}; -} - -template -inline weak_ref adopt_weak_global(T ref) noexcept { - static_assert(IsPlainJniReference(), "T must be a plain jni reference"); - return weak_ref{ref}; -} - - -template -inline enable_if_t(), alias_ref> wrap_alias(T ref) noexcept { - return alias_ref(ref); -} - - -template -enable_if_t(), alias_ref> wrap_alias(T ref) noexcept; - - -template -enable_if_t(), local_ref>> -make_local(const T& ref) { - return adopt_local(detail::make_ref(ref)); -} - -template -enable_if_t(), global_ref>> -make_global(const T& ref) { - return adopt_global(detail::make_ref(ref)); -} - -template -enable_if_t(), weak_ref>> -make_weak(const T& ref) { - return adopt_weak_global(detail::make_ref(ref)); -} - -template -inline enable_if_t() && IsNonWeakReference(), bool> -operator==(const T1& a, const T2& b) { - return isSameObject(getPlainJniReference(a), getPlainJniReference(b)); -} - -template -inline enable_if_t() && IsNonWeakReference(), bool> -operator!=(const T1& a, const T2& b) { - return !(a == b); -} - - -// base_owned_ref /////////////////////////////////////////////////////////////////////// - -template -inline base_owned_ref::base_owned_ref() noexcept - : base_owned_ref(nullptr) -{} - -template -inline base_owned_ref::base_owned_ref(std::nullptr_t t) noexcept - : base_owned_ref(static_cast(nullptr)) -{} - -template -inline base_owned_ref::base_owned_ref(const base_owned_ref& other) - : storage_{static_cast(Alloc{}.newReference(other.get()))} -{} - -template -template -inline base_owned_ref::base_owned_ref(const base_owned_ref& other) - : storage_{static_cast(Alloc{}.newReference(other.get()))} -{ - static_assert(std::is_convertible, javaobject>::value, ""); -} - -template -inline facebook::jni::base_owned_ref::base_owned_ref( - javaobject reference) noexcept - : storage_(reference) { - assert(Alloc{}.verifyReference(reference)); - internal::dbglog("New wrapped ref=%p this=%p", get(), this); -} - -template -inline base_owned_ref::base_owned_ref( - base_owned_ref&& other) noexcept - : storage_(other.get()) { - internal::dbglog("New move from ref=%p other=%p", other.get(), &other); - internal::dbglog("New move to ref=%p this=%p", get(), this); - // JObject is a simple type and does not support move semantics so we explicitly - // clear other - other.set(nullptr); -} - -template -template -base_owned_ref::base_owned_ref(base_owned_ref&& other) noexcept - : storage_(other.get()) { - internal::dbglog("New move from ref=%p other=%p", other.get(), &other); - internal::dbglog("New move to ref=%p this=%p", get(), this); - // JObject is a simple type and does not support move semantics so we explicitly - // clear other - other.set(nullptr); -} - -template -inline base_owned_ref::~base_owned_ref() noexcept { - reset(); - internal::dbglog("Ref destruct ref=%p this=%p", get(), this); -} - -template -inline auto base_owned_ref::release() noexcept -> javaobject { - auto value = get(); - internal::dbglog("Ref release ref=%p this=%p", value, this); - set(nullptr); - return value; -} - -template -inline void base_owned_ref::reset() noexcept { - reset(nullptr); -} - -template -inline void base_owned_ref::reset(javaobject reference) noexcept { - if (get()) { - assert(Alloc{}.verifyReference(reference)); - Alloc{}.deleteReference(get()); - } - set(reference); -} - -template -inline auto base_owned_ref::get() const noexcept -> javaobject { - return storage_.jobj(); -} - -template -inline void base_owned_ref::set(javaobject ref) noexcept { - storage_.set(ref); -} - - -// weak_ref /////////////////////////////////////////////////////////////////////// - -template -inline weak_ref& weak_ref::operator=( - const weak_ref& other) { - auto otherCopy = other; - swap(*this, otherCopy); - return *this; -} - -template -inline weak_ref& weak_ref::operator=( - weak_ref&& other) noexcept { - internal::dbglog("Op= move ref=%p this=%p oref=%p other=%p", - get(), this, other.get(), &other); - reset(other.release()); - return *this; -} - -template -local_ref weak_ref::lockLocal() const { - return adopt_local( - static_cast(LocalReferenceAllocator{}.newReference(get()))); -} - -template -global_ref weak_ref::lockGlobal() const { - return adopt_global( - static_cast(GlobalReferenceAllocator{}.newReference(get()))); -} - -template -inline void swap( - weak_ref& a, - weak_ref& b) noexcept { - internal::dbglog("Ref swap a.ref=%p a=%p b.ref=%p b=%p", - a.get(), &a, b.get(), &b); - a.storage_.swap(b.storage_); -} - - -// basic_strong_ref //////////////////////////////////////////////////////////////////////////// - -template -inline basic_strong_ref& basic_strong_ref::operator=( - const basic_strong_ref& other) { - auto otherCopy = other; - swap(*this, otherCopy); - return *this; -} - -template -inline basic_strong_ref& basic_strong_ref::operator=( - basic_strong_ref&& other) noexcept { - internal::dbglog("Op= move ref=%p this=%p oref=%p other=%p", - get(), this, other.get(), &other); - reset(other.release()); - return *this; -} - -template -inline alias_ref basic_strong_ref::releaseAlias() noexcept { - return wrap_alias(release()); -} - -template -inline basic_strong_ref::operator bool() const noexcept { - return get() != nullptr; -} - -template -inline auto basic_strong_ref::operator->() noexcept -> Repr* { - return &storage_.get(); -} - -template -inline auto basic_strong_ref::operator->() const noexcept -> const Repr* { - return &storage_.get(); -} - -template -inline auto basic_strong_ref::operator*() noexcept -> Repr& { - return storage_.get(); -} - -template -inline auto basic_strong_ref::operator*() const noexcept -> const Repr& { - return storage_.get(); -} - -template -inline void swap( - basic_strong_ref& a, - basic_strong_ref& b) noexcept { - internal::dbglog("Ref swap a.ref=%p a=%p b.ref=%p b=%p", - a.get(), &a, b.get(), &b); - using std::swap; - a.storage_.swap(b.storage_); -} - - -// alias_ref ////////////////////////////////////////////////////////////////////////////// - -template -inline alias_ref::alias_ref() noexcept - : storage_{nullptr} -{} - -template -inline alias_ref::alias_ref(std::nullptr_t) noexcept - : storage_{nullptr} -{} - -template -inline alias_ref::alias_ref(const alias_ref& other) noexcept - : storage_{other.get()} -{} - -template -inline alias_ref::alias_ref(javaobject ref) noexcept - : storage_(ref) { - assert( - LocalReferenceAllocator{}.verifyReference(ref) || - GlobalReferenceAllocator{}.verifyReference(ref)); -} - -template -template -inline alias_ref::alias_ref(alias_ref other) noexcept - : storage_{other.get()} -{} - -template -template -inline alias_ref::alias_ref(const basic_strong_ref& other) noexcept - : storage_{other.get()} -{} - -template -inline alias_ref& alias_ref::operator=(alias_ref other) noexcept { - swap(*this, other); - return *this; -} - -template -inline alias_ref::operator bool() const noexcept { - return get() != nullptr; -} - -template -inline auto facebook::jni::alias_ref::get() const noexcept -> javaobject { - return storage_.jobj(); -} - -template -inline auto alias_ref::operator->() noexcept -> Repr* { - return &(**this); -} - -template -inline auto alias_ref::operator->() const noexcept -> const Repr* { - return &(**this); -} - -template -inline auto alias_ref::operator*() noexcept -> Repr& { - return storage_.get(); -} - -template -inline auto alias_ref::operator*() const noexcept -> const Repr& { - return storage_.get(); -} - -template -inline void alias_ref::set(javaobject ref) noexcept { - storage_.set(ref); -} - -template -inline void swap(alias_ref& a, alias_ref& b) noexcept { - a.storage_.swap(b.storage_); -} - -// Could reduce code duplication by using a pointer-to-function -// template argument. I'm not sure whether that would make the code -// more maintainable (DRY), or less (too clever/confusing.). -template -enable_if_t(), local_ref> -static_ref_cast(const local_ref& ref) noexcept -{ - T p = static_cast(ref.get()); - return make_local(p); -} - -template -enable_if_t(), global_ref> -static_ref_cast(const global_ref& ref) noexcept -{ - T p = static_cast(ref.get()); - return make_global(p); -} - -template -enable_if_t(), alias_ref> -static_ref_cast(const alias_ref& ref) noexcept -{ - T p = static_cast(ref.get()); - return wrap_alias(p); -} - -template -auto dynamic_ref_cast(const RefType& ref) -> -enable_if_t(), decltype(static_ref_cast(ref))> -{ - if (! ref) { - return decltype(static_ref_cast(ref))(); - } - - std::string target_class_name{jtype_traits::base_name()}; - - // If not found, will throw an exception. - alias_ref target_class = findClassStatic(target_class_name.c_str()); - - local_ref source_class = ref->getClass(); - - if ( ! source_class->isAssignableFrom(target_class)) { - throwNewJavaException("java/lang/ClassCastException", - "Tried to cast from %s to %s.", - source_class->toString().c_str(), - target_class_name.c_str()); - } - - return static_ref_cast(ref); -} - -}} diff --git a/lib/fb/src/main/cpp/include/fb/fbjni/References.h b/lib/fb/src/main/cpp/include/fb/fbjni/References.h deleted file mode 100644 index b3484e5e..00000000 --- a/lib/fb/src/main/cpp/include/fb/fbjni/References.h +++ /dev/null @@ -1,586 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - - -/** @file References.h - * - * Functionality similar to smart pointers, but for references into the VM. Four main reference - * types are provided: local_ref, global_ref, weak_ref, and alias_ref. All are generic - * templates that and refer to objects in the jobject hierarchy. The type of the referred objects - * are specified using the template parameter. All reference types except alias_ref own their - * underlying reference, just as a std smart pointer owns the underlying raw pointer. In the context - * of std smart pointers, these references behave like unique_ptr, and have basically the same - * interface. Thus, when the reference is destructed, the plain JNI reference, i.e. the underlying - * JNI reference (like the parameters passed directly to JNI functions), is released. The alias - * references provides no ownership and is a simple wrapper for plain JNI references. - * - * All but the weak references provides access to the underlying object using dereferencing, and a - * get() method. It is also possible to convert these references to booleans to test for nullity. - * To access the underlying object of a weak reference, the reference must either be released, or - * the weak reference can be used to create a local or global reference. - * - * An owning reference is created either by moving the reference from an existing owned reference, - * by copying an existing owned reference (which creates a new underlying reference), by using the - * default constructor which initialize the reference to nullptr, or by using a helper function. The - * helper function exist in two flavors: make_XXX or adopt_XXX. - * - * Adopting takes a plain JNI reference and wrap it in an owned reference. It takes ownership of the - * plain JNI reference so be sure that no one else owns the reference when you adopt it, and make - * sure that you know what kind of reference it is. - * - * New owned references can be created from existing plain JNI references, alias references, local - * references, and global references (i.e. non-weak references) using the make_local, make_global, - * and make_weak functions. - * - * Alias references can be implicitly initialized using global, local and plain JNI references using - * the wrap_alias function. Here, we don't assume ownership of the passed-in reference, but rather - * create a separate reference that we do own, leaving the passed-in reference to its fate. - * - * Similar rules apply for assignment. An owned reference can be copy or move assigned using a smart - * reference of the same type. In the case of copy assignment a new reference is created. Alias - * reference can also be assigned new values, but since they are simple wrappers of plain JNI - * references there is no move semantics involved. - * - * Alias references are special in that they do not own the object and can therefore safely be - * converted to and from its corresponding plain JNI reference. They are useful as parameters of - * functions that do not affect the lifetime of a reference. Usage can be compared with using plain - * JNI pointers as parameters where a function does not take ownership of the underlying object. - * - * The local, global, and alias references makes it possible to access methods in the underlying - * objects. A core set of classes are implemented in CoreClasses.h, and user defined wrappers are - * supported (see example below). The wrappers also supports inheritance so a wrapper can inherit - * from another wrapper to gain access to its functionality. As an example the jstring wrapper - * inherits from the jobject wrapper, so does the jclass wrapper. That means that you can for - * example call the toString() method using the jclass wrapper, or any other class that inherits - * from the jobject wrapper. - * - * Note that the wrappers are parameterized on the static type of your (jobject) pointer, thus if - * you have a jobject that refers to a Java String you will need to cast it to jstring to get the - * jstring wrapper. This also mean that if you make a down cast that is invalid there will be no one - * stopping you and the wrappers currently does not detect this which can cause crashes. Thus, cast - * wisely. - * - * @include WrapperSample.cpp - */ - -#pragma once - -#include -#include -#include - -#include - -#include - -#include "ReferenceAllocators.h" -#include "TypeTraits.h" -#include "References-forward.h" - -namespace facebook { -namespace jni { - -/// Convenience function to wrap an existing local reference -template -local_ref adopt_local(T ref) noexcept; - -/// Convenience function to wrap an existing global reference -template -global_ref adopt_global(T ref) noexcept; - -/// Convenience function to wrap an existing weak reference -template -weak_ref adopt_weak_global(T ref) noexcept; - - -/// Swaps two owning references of the same type -template -void swap(weak_ref& a, weak_ref& b) noexcept; - -/// Swaps two owning references of the same type -template -void swap(basic_strong_ref& a, basic_strong_ref& b) noexcept; - -/** - * Retrieve the plain reference from a plain reference. - */ -template -enable_if_t(), T> getPlainJniReference(T ref); - -/** - * Retrieve the plain reference from an alias reference. - */ -template -JniType getPlainJniReference(alias_ref ref); - -/** - * Retrieve the plain JNI reference from any reference owned reference. - */ -template -JniType getPlainJniReference(const base_owned_ref& ref); - -class JObject; -class JClass; - -namespace detail { - -template -struct HasJniRefRepr : std::false_type {}; - -template -struct HasJniRefRepr::value, void>::type> : std::true_type { - using type = typename T::JniRefRepr; -}; - -template -struct RefReprType { - using type = typename std::conditional::value, typename HasJniRefRepr::type, JObjectWrapper>::type; - static_assert(std::is_base_of::value, - "Repr type missing JObject base."); - static_assert(std::is_same::type>::value, - "RefReprType not idempotent"); -}; - -template -struct RefReprType::value, void>::type> { - using type = T; - static_assert(std::is_base_of::value, - "Repr type missing JObject base."); - static_assert(std::is_same::type>::value, - "RefReprType not idempotent"); -}; - -template -struct JavaObjectType { - using type = typename RefReprType::type::javaobject; - static_assert(IsPlainJniReference(), - "JavaObjectType not a plain jni reference"); - static_assert(std::is_same::type>::value, - "JavaObjectType not idempotent"); -}; - -template -struct JavaObjectType> { - using type = T; - static_assert(IsPlainJniReference(), - "JavaObjectType not a plain jni reference"); - static_assert(std::is_same::type>::value, - "JavaObjectType not idempotent"); -}; - -template -struct JavaObjectType { - using type = T*; - static_assert(IsPlainJniReference(), - "JavaObjectType not a plain jni reference"); - static_assert(std::is_same::type>::value, - "JavaObjectType not idempotent"); -}; - -template -struct ReprStorage { - explicit ReprStorage(JniType obj) noexcept; - - void set(JniType obj) noexcept; - - Repr& get() noexcept; - const Repr& get() const noexcept; - JniType jobj() const noexcept; - - void swap(ReprStorage& other) noexcept; - private: - ReprStorage() = delete; - ReprStorage(const ReprStorage&) = delete; - ReprStorage(ReprStorage&&) = delete; - ReprStorage& operator=(const ReprStorage&) = delete; - ReprStorage& operator=(ReprStorage&&) = delete; - - using Storage = typename std::aligned_storage::type; - Storage storage_; -}; - -} // namespace detail - -/** - * Create a new local reference from an existing reference - * - * @param ref a plain JNI, alias, or strong reference - * @return an owned local reference (referring to null if the input does) - * @throws std::bad_alloc if the JNI reference could not be created - */ -template -enable_if_t(), local_ref>> -make_local(const T& r); - -/** - * Create a new global reference from an existing reference - * - * @param ref a plain JNI, alias, or strong reference - * @return an owned global reference (referring to null if the input does) - * @throws std::bad_alloc if the JNI reference could not be created - */ -template -enable_if_t(), global_ref>> -make_global(const T& r); - -/** - * Create a new weak global reference from an existing reference - * - * @param ref a plain JNI, alias, or strong reference - * @return an owned weak global reference (referring to null if the input does) - * @throws std::bad_alloc if the returned reference is null - */ -template -enable_if_t(), weak_ref>> -make_weak(const T& r); - -/** - * Compare two references to see if they refer to the same object - */ -template -enable_if_t() && IsNonWeakReference(), bool> -operator==(const T1& a, const T2& b); - -/** - * Compare two references to see if they don't refer to the same object - */ -template -enable_if_t() && IsNonWeakReference(), bool> -operator!=(const T1& a, const T2& b); - -template -class base_owned_ref { - public: - using javaobject = JniType; - - /** - * Release the ownership and set the reference to null. Thus no deleter is invoked. - * @return Returns the reference - */ - javaobject release() noexcept; - - /** - * Reset the reference to refer to nullptr. - */ - void reset() noexcept; - - protected: - using Repr = ReprType; - detail::ReprStorage storage_; - - javaobject get() const noexcept; - void set(javaobject ref) noexcept; - - /* - * Wrap an existing reference and transfers its ownership to the newly created unique reference. - * NB! Does not create a new reference - */ - explicit base_owned_ref(javaobject reference) noexcept; - - /// Create a null reference - base_owned_ref() noexcept; - - /// Create a null reference - explicit base_owned_ref(std::nullptr_t) noexcept; - - /// Copy constructor (note creates a new reference) - base_owned_ref(const base_owned_ref& other); - template - base_owned_ref(const base_owned_ref& other); - - /// Transfers ownership of an underlying reference from one unique reference to another - base_owned_ref(base_owned_ref&& other) noexcept; - template - base_owned_ref(base_owned_ref&& other) noexcept; - - /// The delete the underlying reference if applicable - ~base_owned_ref() noexcept; - - - /// Assignment operator (note creates a new reference) - base_owned_ref& operator=(const base_owned_ref& other); - - /// Assignment by moving a reference thus not creating a new reference - base_owned_ref& operator=(base_owned_ref&& rhs) noexcept; - - void reset(javaobject reference) noexcept; - - friend javaobject jni::getPlainJniReference<>(const base_owned_ref& ref); - - template - friend class base_owned_ref; -}; - - -/** - * A smart reference that owns its underlying JNI reference. The class provides basic - * functionality to handle a reference but gives no access to it unless the reference is - * released, thus no longer owned. The API is stolen with pride from unique_ptr and the - * semantics should be basically the same. This class should not be used directly, instead use - * @ref weak_ref - */ -template -class weak_ref : public base_owned_ref { - public: - using javaobject = JniType; - - using Allocator = WeakGlobalReferenceAllocator; - - // This inherits non-default, non-copy, non-move ctors. - using base_owned_ref::base_owned_ref; - - /// Create a null reference - weak_ref() noexcept - : base_owned_ref{} {} - - /// Create a null reference - explicit weak_ref(std::nullptr_t) noexcept - : base_owned_ref{nullptr} {} - - /// Copy constructor (note creates a new reference) - weak_ref(const weak_ref& other) - : base_owned_ref{other} {} - - // This needs to be explicit to change its visibility. - template - weak_ref(const weak_ref& other) - : base_owned_ref{other} {} - - /// Transfers ownership of an underlying reference from one unique reference to another - weak_ref(weak_ref&& other) noexcept - : base_owned_ref{std::move(other)} {} - - - /// Assignment operator (note creates a new reference) - weak_ref& operator=(const weak_ref& other); - - /// Assignment by moving a reference thus not creating a new reference - weak_ref& operator=(weak_ref&& rhs) noexcept; - - // Creates an owned local reference to the referred object or to null if the object is reclaimed - local_ref lockLocal() const; - - // Creates an owned global reference to the referred object or to null if the object is reclaimed - global_ref lockGlobal() const; - - private: - // get/release/reset on weak_ref are not exposed to users. - using base_owned_ref::get; - using base_owned_ref::release; - using base_owned_ref::reset; - /* - * Wrap an existing reference and transfers its ownership to the newly created unique reference. - * NB! Does not create a new reference - */ - explicit weak_ref(javaobject reference) noexcept - : base_owned_ref{reference} {} - - template friend class weak_ref; - friend weak_ref adopt_weak_global(javaobject ref) noexcept; - friend void swap(weak_ref& a, weak_ref& b) noexcept; -}; - - -/** - * A class representing owned strong references to Java objects. This class - * should not be used directly, instead use @ref local_ref, or @ref global_ref. - */ -template -class basic_strong_ref : public base_owned_ref { - using typename base_owned_ref::Repr; - public: - using javaobject = JniType; - - using Allocator = Alloc; - - // This inherits non-default, non-copy, non-move ctors. - using base_owned_ref::base_owned_ref; - using base_owned_ref::release; - using base_owned_ref::reset; - - /// Create a null reference - basic_strong_ref() noexcept - : base_owned_ref{} {} - - /// Create a null reference - explicit basic_strong_ref(std::nullptr_t) noexcept - : base_owned_ref{nullptr} {} - - /// Copy constructor (note creates a new reference) - basic_strong_ref(const basic_strong_ref& other) - : base_owned_ref{other} {} - - // This needs to be explicit to change its visibility. - template - basic_strong_ref(const basic_strong_ref& other) - : base_owned_ref{other} {} - - /// Transfers ownership of an underlying reference from one unique reference to another - basic_strong_ref(basic_strong_ref&& other) noexcept - : base_owned_ref{std::move(other)} {} - - /// Assignment operator (note creates a new reference) - basic_strong_ref& operator=(const basic_strong_ref& other); - - /// Assignment by moving a reference thus not creating a new reference - basic_strong_ref& operator=(basic_strong_ref&& rhs) noexcept; - - /// Get the plain JNI reference - using base_owned_ref::get; - - /// Release the ownership of the reference and return the wrapped reference in an alias - alias_ref releaseAlias() noexcept; - - /// Checks if the reference points to a non-null object - explicit operator bool() const noexcept; - - /// Access the functionality provided by the object wrappers - Repr* operator->() noexcept; - - /// Access the functionality provided by the object wrappers - const Repr* operator->() const noexcept; - - /// Provide a reference to the underlying wrapper (be sure that it is non-null before invoking) - Repr& operator*() noexcept; - - /// Provide a const reference to the underlying wrapper (be sure that it is non-null - /// before invoking) - const Repr& operator*() const noexcept; - - private: - - using base_owned_ref::storage_; - - /* - * Wrap an existing reference and transfers its ownership to the newly created unique reference. - * NB! Does not create a new reference - */ - explicit basic_strong_ref(javaobject reference) noexcept - : base_owned_ref{reference} {} - - - friend local_ref adopt_local(T ref) noexcept; - friend global_ref adopt_global(T ref) noexcept; - friend void swap(basic_strong_ref& a, basic_strong_ref& b) noexcept; -}; - - -template -enable_if_t(), alias_ref> wrap_alias(T ref) noexcept; - -/// Swaps to alias reference of the same type -template -void swap(alias_ref& a, alias_ref& b) noexcept; - -/** - * A non-owning variant of the smart references (a dumb reference). These references still provide - * access to the functionality of the @ref JObjectWrapper specializations including exception - * handling and ease of use. Use this representation when you don't want to claim ownership of the - * underlying reference (compare to using raw pointers instead of smart pointers.) For symmetry use - * @ref alias_ref instead of this class. - */ -template -class alias_ref { - using Repr = ReprType; - - public: - using javaobject = JniType; - - /// Create a null reference - alias_ref() noexcept; - - /// Create a null reference - alias_ref(std::nullptr_t) noexcept; - - /// Copy constructor - alias_ref(const alias_ref& other) noexcept; - - /// Wrap an existing plain JNI reference - /* implicit */ alias_ref(javaobject ref) noexcept; - - /// Wrap an existing smart reference of any type convertible to T - template< - typename TOther, - typename = enable_if_t< - IsConvertible, javaobject>(), T> - > - alias_ref(alias_ref other) noexcept; - - /// Wrap an existing alias reference of a type convertible to T - template< - typename TOther, - typename AOther, - typename = enable_if_t< - IsConvertible, javaobject>(), T> - > - alias_ref(const basic_strong_ref& other) noexcept; - - /// Assignment operator - alias_ref& operator=(alias_ref other) noexcept; - - /// Checks if the reference points to a non-null object - explicit operator bool() const noexcept; - - /// Converts back to a plain JNI reference - javaobject get() const noexcept; - - /// Access the functionality provided by the object wrappers - Repr* operator->() noexcept; - - /// Access the functionality provided by the object wrappers - const Repr* operator->() const noexcept; - - /// Provide a guaranteed non-null reference (be sure that it is non-null before invoking) - Repr& operator*() noexcept; - - /// Provide a guaranteed non-null reference (be sure that it is non-null before invoking) - const Repr& operator*() const noexcept; - - private: - void set(javaobject ref) noexcept; - - detail::ReprStorage storage_; - - friend void swap(alias_ref& a, alias_ref& b) noexcept; -}; - - -/** - * RAII object to create a local JNI frame, using PushLocalFrame/PopLocalFrame. - * - * This is useful when you have a call which is initiated from C++-land, and therefore - * doesn't automatically get a local JNI frame managed for you by the JNI framework. - */ -class FBEXPORT JniLocalScope { -public: - JniLocalScope(JNIEnv* p_env, jint capacity); - ~JniLocalScope(); - -private: - JNIEnv* env_; - bool hasFrame_; -}; - -template -enable_if_t(), local_ref> -static_ref_cast(const local_ref& ref) noexcept; - -template -enable_if_t(), global_ref> -static_ref_cast(const global_ref& ref) noexcept; - -template -enable_if_t(), alias_ref> -static_ref_cast(const alias_ref& ref) noexcept; - -template -auto dynamic_ref_cast(const RefType& ref) -> -enable_if_t(), decltype(static_ref_cast(ref))> ; - -}} - -#include "References-inl.h" diff --git a/lib/fb/src/main/cpp/include/fb/fbjni/Registration-inl.h b/lib/fb/src/main/cpp/include/fb/fbjni/Registration-inl.h deleted file mode 100644 index e2817473..00000000 --- a/lib/fb/src/main/cpp/include/fb/fbjni/Registration-inl.h +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "Exceptions.h" -#include "Hybrid.h" - -namespace facebook { -namespace jni { - -namespace detail { - -#ifdef __i386__ -// X86 ABI forces 16 byte stack allignment on calls. Unfortunately -// sometimes Dalvik chooses not to obey the ABI: -// - https://code.google.com/p/android/issues/detail?id=61012 -// - https://android.googlesource.com/platform/ndk/+/81696d2%5E!/ -// Therefore, we tell the compiler to re-align the stack on entry -// to our JNI functions. -#define JNI_ENTRY_POINT __attribute__((force_align_arg_pointer)) -#else -#define JNI_ENTRY_POINT -#endif - -// registration wrapper for legacy JNI-style functions - -template -inline NativeMethodWrapper* exceptionWrapJNIMethod(void (*)(JNIEnv*, C, Args... args)) { - struct funcWrapper { - JNI_ENTRY_POINT static void call(JNIEnv* env, jobject obj, Args... args) { - // Note that if func was declared noexcept, then both gcc and clang are smart - // enough to elide the try/catch. - try { - (*func)(env, static_cast(obj), args...); - } catch (...) { - translatePendingCppExceptionToJavaException(); - } - } - }; - - // This intentionally erases the real type; JNI will do it anyway - return reinterpret_cast(&(funcWrapper::call)); -} - -template -inline NativeMethodWrapper* exceptionWrapJNIMethod(R (*)(JNIEnv*, C, Args... args)) { - struct funcWrapper { - JNI_ENTRY_POINT static R call(JNIEnv* env, jobject obj, Args... args) { - try { - return (*func)(env, static_cast>(obj), args...); - } catch (...) { - translatePendingCppExceptionToJavaException(); - return R{}; - } - } - }; - - // This intentionally erases the real type; JNI will do it anyway - return reinterpret_cast(&(funcWrapper::call)); -} - -// registration wrappers for functions, with autoconversion of arguments. - -template -inline NativeMethodWrapper* exceptionWrapJNIMethod(void (*)(alias_ref, Args... args)) { - struct funcWrapper { - JNI_ENTRY_POINT static void call(JNIEnv*, jobject obj, - typename Convert::type>::jniType... args) { - try { - (*func)(static_cast>(obj), Convert::type>::fromJni(args)...); - } catch (...) { - translatePendingCppExceptionToJavaException(); - } - } - }; - - // This intentionally erases the real type; JNI will do it anyway - return reinterpret_cast(&(funcWrapper::call)); -} - -template -inline NativeMethodWrapper* exceptionWrapJNIMethod(R (*)(alias_ref, Args... args)) { - struct funcWrapper { - - JNI_ENTRY_POINT static typename Convert::type>::jniType call(JNIEnv*, jobject obj, - typename Convert::type>::jniType... args) { - try { - return Convert::type>::toJniRet( - (*func)(static_cast>(obj), Convert::type>::fromJni(args)...)); - } catch (...) { - using jniRet = typename Convert::type>::jniType; - translatePendingCppExceptionToJavaException(); - return jniRet{}; - } - } - }; - - // This intentionally erases the real type; JNI will do it anyway - return reinterpret_cast(&(funcWrapper::call)); -} - -// registration wrappers for non-static methods, with autoconvertion of arguments. - -template -inline NativeMethodWrapper* exceptionWrapJNIMethod(void (C::*method0)(Args... args)) { - struct funcWrapper { - JNI_ENTRY_POINT static void call(JNIEnv* env, jobject obj, - typename Convert::type>::jniType... args) { - try { - try { - auto aref = wrap_alias(static_cast(obj)); - // This is usually a noop, but if the hybrid object is a - // base class of other classes which register JNI methods, - // this will get the right type for the registered method. - auto cobj = static_cast(facebook::jni::cthis(aref)); - (cobj->*method)(Convert::type>::fromJni(args)...); - } catch (const std::exception& ex) { - C::mapException(ex); - throw; - } - } catch (...) { - translatePendingCppExceptionToJavaException(); - } - } - }; - - // This intentionally erases the real type; JNI will do it anyway - return reinterpret_cast(&(funcWrapper::call)); -} - -template -inline NativeMethodWrapper* exceptionWrapJNIMethod(R (C::*method0)(Args... args)) { - struct funcWrapper { - - JNI_ENTRY_POINT static typename Convert::type>::jniType call(JNIEnv* env, jobject obj, - typename Convert::type>::jniType... args) { - try { - try { - auto aref = wrap_alias(static_cast(obj)); - // This is usually a noop, but if the hybrid object is a - // base class of other classes which register JNI methods, - // this will get the right type for the registered method. - auto cobj = static_cast(facebook::jni::cthis(aref)); - return Convert::type>::toJniRet( - (cobj->*method)(Convert::type>::fromJni(args)...)); - } catch (const std::exception& ex) { - C::mapException(ex); - throw; - } - } catch (...) { - using jniRet = typename Convert::type>::jniType; - translatePendingCppExceptionToJavaException(); - return jniRet{}; - } - } - }; - - // This intentionally erases the real type; JNI will do it anyway - return reinterpret_cast(&(funcWrapper::call)); -} - -template -inline std::string makeDescriptor(R (*)(JNIEnv*, C, Args... args)) { - return jmethod_traits::descriptor(); -} - -template -inline std::string makeDescriptor(R (*)(alias_ref, Args... args)) { - return jmethod_traits_from_cxx::descriptor(); -} - -template -inline std::string makeDescriptor(R (C::*)(Args... args)) { - return jmethod_traits_from_cxx::descriptor(); -} - -} - -}} diff --git a/lib/fb/src/main/cpp/include/fb/fbjni/Registration.h b/lib/fb/src/main/cpp/include/fb/fbjni/Registration.h deleted file mode 100644 index 654fdab2..00000000 --- a/lib/fb/src/main/cpp/include/fb/fbjni/Registration.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include "References.h" - -namespace facebook { -namespace jni { - -namespace detail { - -// This uses the real JNI function as a non-type template parameter to -// cause a (static member) function to exist with the same signature, -// but with try/catch exception translation. -template -NativeMethodWrapper* exceptionWrapJNIMethod(void (*func0)(JNIEnv*, jobject, Args... args)); - -// Same as above, but for non-void return types. -template -NativeMethodWrapper* exceptionWrapJNIMethod(R (*func0)(JNIEnv*, jobject, Args... args)); - -// Automatically wrap object argument, and don't take env explicitly. -template -NativeMethodWrapper* exceptionWrapJNIMethod(void (*func0)(alias_ref, Args... args)); - -// Automatically wrap object argument, and don't take env explicitly, -// non-void return type. -template -NativeMethodWrapper* exceptionWrapJNIMethod(R (*func0)(alias_ref, Args... args)); - -// Extract C++ instance from object, and invoke given method on it. -template -NativeMethodWrapper* exceptionWrapJNIMethod(void (C::*method0)(Args... args)); - -// Extract C++ instance from object, and invoke given method on it, -// non-void return type -template -NativeMethodWrapper* exceptionWrapJNIMethod(R (C::*method0)(Args... args)); - -// This uses deduction to figure out the descriptor name if the types -// are primitive or have JObjectWrapper specializations. -template -std::string makeDescriptor(R (*func)(JNIEnv*, C, Args... args)); - -// This uses deduction to figure out the descriptor name if the types -// are primitive or have JObjectWrapper specializations. -template -std::string makeDescriptor(R (*func)(alias_ref, Args... args)); - -// This uses deduction to figure out the descriptor name if the types -// are primitive or have JObjectWrapper specializations. -template -std::string makeDescriptor(R (C::*method0)(Args... args)); - -} - -// We have to use macros here, because the func needs to be used -// as both a decltype expression argument and as a non-type template -// parameter, since C++ provides no way for translateException -// to deduce the type of its non-type template parameter. -// The empty string in the macros below ensures that name -// is always a string literal (because that syntax is only -// valid when name is a string literal). -#define makeNativeMethod2(name, func) \ - { name "", ::facebook::jni::detail::makeDescriptor(&func), \ - ::facebook::jni::detail::exceptionWrapJNIMethod(&func) } - -#define makeNativeMethod3(name, desc, func) \ - { name "", desc, \ - ::facebook::jni::detail::exceptionWrapJNIMethod(&func) } - -// Variadic template hacks to get macros with different numbers of -// arguments. Usage instructions are in CoreClasses.h. -#define makeNativeMethodN(a, b, c, count, ...) makeNativeMethod ## count -#define makeNativeMethod(...) makeNativeMethodN(__VA_ARGS__, 3, 2)(__VA_ARGS__) - -}} - -#include "Registration-inl.h" diff --git a/lib/fb/src/main/cpp/include/fb/fbjni/TypeTraits.h b/lib/fb/src/main/cpp/include/fb/fbjni/TypeTraits.h deleted file mode 100644 index 36c8bec1..00000000 --- a/lib/fb/src/main/cpp/include/fb/fbjni/TypeTraits.h +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include - -#include "References-forward.h" - -namespace facebook { -namespace jni { - -/// Generic std::enable_if helper -template -using enable_if_t = typename std::enable_if::type; - -/// Generic std::is_convertible helper -template -constexpr bool IsConvertible() { - return std::is_convertible::value; -} - -template class TT, typename T> -struct is_instantiation_of : std::false_type {}; - -template class TT, typename... Ts> -struct is_instantiation_of> : std::true_type {}; - -template class TT, typename... Ts> -constexpr bool IsInstantiationOf() { - return is_instantiation_of::value; -} - -/// Metafunction to determine whether a type is a JNI reference or not -template -struct is_plain_jni_reference : - std::integral_constant::value && - std::is_base_of< - typename std::remove_pointer::type, - typename std::remove_pointer::type>::value> {}; - -/// Helper to simplify use of is_plain_jni_reference -template -constexpr bool IsPlainJniReference() { - return is_plain_jni_reference::value; -} - -/// Metafunction to determine whether a type is a primitive JNI type or not -template -struct is_jni_primitive : - std::integral_constant::value || - std::is_same::value || - std::is_same::value || - std::is_same::value || - std::is_same::value || - std::is_same::value || - std::is_same::value || - std::is_same::value> {}; - -/// Helper to simplify use of is_jni_primitive -template -constexpr bool IsJniPrimitive() { - return is_jni_primitive::value; -} - -/// Metafunction to determine whether a type is a JNI array of primitives or not -template -struct is_jni_primitive_array : - std::integral_constant::value || - std::is_same::value || - std::is_same::value || - std::is_same::value || - std::is_same::value || - std::is_same::value || - std::is_same::value || - std::is_same::value> {}; - -/// Helper to simplify use of is_jni_primitive_array -template -constexpr bool IsJniPrimitiveArray() { - return is_jni_primitive_array::value; -} - -/// Metafunction to determine if a type is a scalar (primitive or reference) JNI type -template -struct is_jni_scalar : - std::integral_constant::value || - is_jni_primitive::value> {}; - -/// Helper to simplify use of is_jni_scalar -template -constexpr bool IsJniScalar() { - return is_jni_scalar::value; -} - -// Metafunction to determine if a type is a JNI type -template -struct is_jni_type : - std::integral_constant::value || - std::is_void::value> {}; - -/// Helper to simplify use of is_jni_type -template -constexpr bool IsJniType() { - return is_jni_type::value; -} - -template -struct is_non_weak_reference : - std::integral_constant() || - IsInstantiationOf() || - IsInstantiationOf()> {}; - -template -constexpr bool IsNonWeakReference() { - return is_non_weak_reference::value; -} - -template -struct is_any_reference : - std::integral_constant() || - IsInstantiationOf() || - IsInstantiationOf() || - IsInstantiationOf()> {}; - -template -constexpr bool IsAnyReference() { - return is_any_reference::value; -} - -template -struct reference_traits { - using plain_jni_reference_t = JniType; - static_assert(IsPlainJniReference(), "Need a plain JNI reference"); -}; - -template