Compare commits

..

20 Commits

Author SHA1 Message Date
Emil Sjolander
4f37cde043 re-generate js build
Summary: npm run build:all

Reviewed By: dshahidehpour

Differential Revision: D4477027

fbshipit-source-id: 107e13134145df18a788e079be467b27d1893118
2017-01-27 14:24:40 -08:00
Guido Marucci Blas
7df60376ff CocoaPods support.
Summary:
This supersedes #309 and #305.

This is still a **work-in-progress.**

**TODO**

 - [x] Create Xcode project that builds an iOS framework
 - [x] Fix failing tests on Xcode
 - [ ] Make `pod lib lint` pass and make sure YogaKit can be included using CocoaPods
 - [ ] Add `pod lib lint` to .travis.yml
 - [x] Migrate to travis osx image with Xcode 8.2

**FOLLOW-UP**
  - [ ] Make YogaKitSample use framework built by new Xcode project.
  - [ ] Make Travis to upload prebuilt versions of the framework. More [here](https://github.com/Carthage/Carthage#use-travis-ci-to-upload-your-tagged-prebuild-frameworks)
  - [ ] Upgrade github/jekyll docs about installation using Cocoapods/Carthage
Closes https://github.com/facebook/yoga/pull/352

Reviewed By: emilsjolander

Differential Revision: D4471950

Pulled By: dshahidehpour

fbshipit-source-id: 8f30c69f9a487b26aa2e5f3b66841334b01b0ab1
2017-01-27 10:09:48 -08:00
Emil Sjolander
7fa4adb0d9 Fix aspectratio with margins
Summary: aspect ratio did not account for the widths and heights being including padding. This diff fixes that.

Reviewed By: astreet

Differential Revision: D4473024

fbshipit-source-id: 5a747e2f267b077203bb3b63e4c152847dc30774
2017-01-27 10:09:48 -08:00
Kazuki Sakamoto
abb91ae77b Remove deprecated code
Summary: - Remove classes and methods marked as `Obsolete`

Reviewed By: emilsjolander

Differential Revision: D4474945

fbshipit-source-id: 43552fa638c8b321603858a862a386c5296db2fa
2017-01-27 09:09:36 -08:00
Dustin Shahidehpour
a4b1ac83f4 Update README.md to include Pod Shield
Summary: Closes https://github.com/facebook/yoga/pull/356

Differential Revision: D4471126

Pulled By: dshahidehpour

fbshipit-source-id: 362a92225c8267cb89b12b45a98f69adf726c42d
2017-01-26 14:40:07 -08:00
Emil Sjolander
8775cdc13f Format and run codegen
Summary: run format & gentest scripts. Some of the javascript tests had not been generated recently by the looks of it.

Reviewed By: dshahidehpour

Differential Revision: D4459455

fbshipit-source-id: fc1eca58fe897c8f4a2571638b4f7035d023b479
2017-01-26 13:39:42 -08:00
Maël Nison
db732ce9fa Add YGLayoutGetBorder, counterpart of YGLayoutGetPadding
Summary:
Followup of #335, fix #326. This commit add the `YGLayoutGetBorder(node, edge)` function, which correctly takes RTL/LTR into account when resolving `EDGE_START` & `EDGE_END`.
Closes https://github.com/facebook/yoga/pull/344

Reviewed By: dshahidehpour

Differential Revision: D4459950

Pulled By: emilsjolander

fbshipit-source-id: b57eb7a5b1c181a364913c3200a3794a2b7b31a6
2017-01-26 13:39:42 -08:00
Lukas Wöhrl
7c09244c39 Fix absolute position if align-item or justify-content is center or flex-end
Summary:
Fix #310 (```center```)

additionally fixes if ```flex-end``` is set.
Closes https://github.com/facebook/yoga/pull/349

Reviewed By: dshahidehpour

Differential Revision: D4458528

Pulled By: emilsjolander

fbshipit-source-id: f073c80bfc3ea6675cb95b00283074d10e91a042
2017-01-26 13:39:41 -08:00
Dustin Shahidehpour
2cc2a5f2ff Add podspec for C-Library.
Summary: This is the first step to adding cocoapods support to YogaKit. We are going to publish a `Yoga` framework to the store that we can use as a dependency. This will also allow developers to build their own abstractions easily using the core API.

Reviewed By: nlutsenko, emilsjolander

Differential Revision: D4466788

fbshipit-source-id: 8f08bdbf524e57c88f7fc3400c4ba6ad58f98d7f
2017-01-26 10:39:36 -08:00
Lukas Wöhrl
e4b50f2a8d Fix unnecessary measure calls
Summary:
Fix #334
Closes https://github.com/facebook/yoga/pull/347

Reviewed By: dshahidehpour

Differential Revision: D4455438

Pulled By: emilsjolander

fbshipit-source-id: 013c89e71757d9048708ec85cbb6af9f33ac1ea6
2017-01-24 19:09:32 -08:00
Emil Sjolander
a2a84532ff Dont constrain absolute children to zero sized parents
Summary: Absolute children should not be constraint to the size of their parent if the parent does not have a size as this was causes the layout of the child to be skipped.

Reviewed By: gkassabli

Differential Revision: D4453612

fbshipit-source-id: e8269521560d2f42b2d6f0f0ff264a1605a57d79
2017-01-24 17:09:34 -08:00
Emil Sjolander
d391323129 Use findClassStatic instead of findClassLocal
Summary: We are saving the class reference in a static variable to should be using findClassStatic to ensure the reference is always valid.

Reviewed By: mhorowitz

Differential Revision: D4420352

fbshipit-source-id: 8c66c1b2213fe295334a9bdc4e1dd7e1a4285aae
2017-01-24 15:54:31 -08:00
David Hart
ab28ecf31b Improve test readability
Summary:
I did some stylistic changes to the Objective-C unit tests for the following reasons:

- When an equality assert fails, the error messages reads as if the value we are testing is the first argument and the value we expect is the second argument. To improve the readability of test messages, I made sure all `XCTAssertEqual` and `XCTAssertNotEqual` have the arguments in the correct order.

- Because failing equality asserts already comes with a detailed message including the value tested and the expected value, I rewrote several truth asserts on `CGSizeEqual` to two equality asserts on the width and height: when those fail, the error message are clearer.
Closes https://github.com/facebook/yoga/pull/351

Reviewed By: emilsjolander

Differential Revision: D4454484

Pulled By: dshahidehpour

fbshipit-source-id: 0c1295a4a7e8477eacfb3f4ef6648984fd102a51
2017-01-24 10:09:32 -08:00
Dustin Shahidehpour
a4bab68802 Make YogaKit tests pass whether they are run in Xcode or BUCK.
Summary: Currently, some YogaKit tests fail when they are run in Xcode, but pass in BUCK. This cleans up the tests so that they more definitively test what they say they are testing, and the results are not affected by the enviroment they are run in.

Reviewed By: emilsjolander

Differential Revision: D4453745

fbshipit-source-id: 238e41960afe63d31e9f6efdcd947cfac39f2dc4
2017-01-23 19:39:37 -08:00
Dustin Shahidehpour
e3cfacf0cb Upgrade Travis to Xcode 8.2
Summary:
Doing this externally to trigger a Travis build. This will put our Travis infra on the newest Xcode.
Closes https://github.com/facebook/yoga/pull/353

Reviewed By: emilsjolander

Differential Revision: D4453795

Pulled By: dshahidehpour

fbshipit-source-id: 23416405fdd43486c934bea0b720c217fafd7f30
2017-01-23 19:39:37 -08:00
Ahmed El-Helw
8d74e01f41 Fix typo in generated Yoga classes
Reviewed By: emilsjolander

Differential Revision: D4416273

fbshipit-source-id: fa3f87b86560121e1186cdc0ee295eb052fb3a97
2017-01-19 16:24:33 -08:00
David Hart
5404bb13d4 Fix bugs introduced with YogaKit improvements
Summary:
I'm trying to fix some bugs I introduced in my latest PR, but while writing the Unit Tests for them, I saw a really weird behaviour. The following exact piece of code WORKS inside a Yoga C++ unit test, but fails from a Objective-C unit test. I had me completely confused and blocked me in my progression. Any ideas?

```
TEST(YogaTest, stupid_test) {
  const YGNodeRef node = YGNodeNew();
  YGNodeStyleSetPosition(node, YGEdgeLeft, 1);

  ASSERT_FLOAT_EQ(1, YGNodeStyleGetPosition(node, YGEdgeLeft).value);
  ASSERT_EQ(YGUnitPixel, YGNodeStyleGetPosition(node, YGEdgeLeft).unit);

  YGNodeFree(node);
}

```

```
- (void)testPositionalPropertiesWork
{
  YGNodeRef node = YGNodeNew();
  YGNodeStyleSetPosition(node, YGEdgeLeft, 1);

  XCTAssertEqual(1, YGNodeStyleGetPosition(node, YGEdgeLeft).value);
  XCTAssertEqual(YGUnitPixel, YGNodeStyleGetPosition(node, YGEdgeLeft).unit);

  YGNodeFree(node);
}
```
Closes https://github.com/facebook/yoga/pull/328

Reviewed By: dshahidehpour

Differential Revision: D4421504

Pulled By: emilsjolander

fbshipit-source-id: f59379edf70aee87a77cd1ad2986313cdfe71b94
2017-01-18 09:24:35 -08:00
Lukas Woehrl
be8773fee0 Fix wraping calculation if min-size constraint exists
Summary:
Fixes #261
Closes https://github.com/facebook/css-layout/pull/262

Reviewed By: splhack

Differential Revision: D4245200

Pulled By: emilsjolander

fbshipit-source-id: 77d802d71010ed426511d6a01e6de1e7c9194179
2017-01-16 16:24:35 -08:00
Emil Sjolander
0bcec80dfe BREAKING - Fix sizing of container with child overflowing parent
Summary:
Fixes issue brought up in https://github.com/facebook/react-native/issues/10603

The gist of the problem is that in css it is fine for a child to overflow a parent if it feels the need to, we were not respecting this.

Reviewed By: mmmulani

Differential Revision: D4182141

fbshipit-source-id: c73fd15d2577ab846fc8a202d529d0e6e1207b75
2017-01-16 11:09:32 -08:00
Thanabodee Charoenpiriyakij
2c8c2bffda Edit README.md in Benchmarks section
Summary:
Benchmarks are not located in folder benchmark. So rename folder
and buck target from 'benchmarks' to 'benchmark'.
Closes https://github.com/facebook/yoga/pull/339

Reviewed By: gkassabli

Differential Revision: D4420355

Pulled By: emilsjolander

fbshipit-source-id: 7a1bc6ece7f4b64c7cac506357e265c1b4790a4f
2017-01-16 10:39:37 -08:00
65 changed files with 4876 additions and 722 deletions

1
.swift-version Normal file
View File

@@ -0,0 +1 @@
3.0

View File

@@ -6,7 +6,7 @@
# of patent rights can be found in the PATENTS file in the same directory.
os: osx
osx_image: xcode7.3
osx_image: xcode8.2
language: cpp
compiler: clang
@@ -29,7 +29,7 @@ install:
script:
- buck test //:yoga
- buck test //java:java
- buck test //YogaKit:YogaKitTests --config cxx.default_platform=iphonesimulator-x86_64 --config cxx.cflags=-DTRAVIS_CI
- buck test //YogaKit:YogaKitTests --config cxx.default_platform=iphonesimulator-x86_64
- sh csharp/tests/Facebook.Yoga/test_macos.sh
- cd javascript

View File

@@ -1,4 +1,4 @@
# Yoga [![Build Status](https://travis-ci.org/facebook/yoga.svg?branch=master)](https://travis-ci.org/facebook/yoga)
# Yoga [![Build Status](https://travis-ci.org/facebook/yoga.svg?branch=master)](https://travis-ci.org/facebook/yoga) [![Cocoapods](https://img.shields.io/cocoapods/v/Yoga.svg)](http://cocoapods.org/pods/Yoga)
## Building
Yoga builds with [buck](https://buckbuild.com). Make sure you install buck before contributing to Yoga. Yoga's main implementation is in C, with bindings to supported languages and frameworks. When making changes to Yoga please ensure the changes are also propagated to these bindings when applicable.
@@ -27,4 +27,4 @@ You may need to install the latest watir-webdriver gem (`gem install watir-webdr
For the main C implementation of Yoga clang-format is used to ensure a consistent code style. Please run `bash format.sh` before submitting a pull request. For other languages just try to follow the current code style.
## Benchmarks
Benchmarks are located in `benchmarks/YGBenchmark.c` and can be run with `buck run //benchmarks:benchmarks`. If you think your change has affected performance please run this before and after your change to validate that nothing has regressed. Benchmarks are run on every commit in CI.
Benchmarks are located in `benchmark/YGBenchmark.c` and can be run with `buck run //benchmark:benchmark`. If you think your change has affected performance please run this before and after your change to validate that nothing has regressed. Benchmarks are run on every commit in CI.

27
Yoga.podspec Normal file
View File

@@ -0,0 +1,27 @@
Pod::Spec.new do |s|
s.name = 'Yoga'
s.version = '1.0.0'
s.summary = 'A cross-platform layout engine.'
s.homepage = 'https://github.com/facebook/yoga'
s.documentation_url = 'https://facebook.github.io/yoga'
s.description = 'Yoga is a cross-platform layout engine enabling maximum collaboration within your team by implementing an API many designers are familiar with, and opening it up to developers across different platforms.'
s.license = { :type => 'BSD', :file => "LICENSE" }
s.authors = 'Facebook'
s.social_media_url = 'https://twitter.com/fbOpenSource'
s.source = {
:git => 'https://github.com/facebook/yoga.git',
:tag => 'v2017.01.23.00',
}
s.module_name = 'yoga'
s.requires_arc = false
s.compiler_flags = [
'-fno-omit-frame-pointer',
'-fexceptions',
'-Wall',
'-Werror',
'-std=c11',
'-fPIC'
]
s.source_files = 'yoga/**/*.{c,h}'
end

1
YogaKit/.swift-version Normal file
View File

@@ -0,0 +1 @@
3.0.2

View File

@@ -30,8 +30,8 @@ COMPILER_FLAGS = [
apple_library(
name = 'YogaKit',
compiler_flags = COMPILER_FLAGS,
srcs = glob(['*.m']),
exported_headers = glob(['*.h']),
srcs = glob(['Source/**/*.m']),
exported_headers = glob(['Source/**/*.h']),
frameworks = [
'$SDKROOT/System/Library/Frameworks/Foundation.framework',
'$SDKROOT/System/Library/Frameworks/UIKit.framework',

View File

@@ -8,8 +8,11 @@
*/
#import "YGLayout.h"
#import <yoga/Yoga.h>
@interface YGLayout (Private)
@interface YGLayout ()
@property (nonatomic, assign, readonly) YGNodeRef node;
- (instancetype)initWithView:(UIView *)view;

View File

@@ -9,75 +9,99 @@
#import "YGLayout+Private.h"
#import "UIView+Yoga.h"
#import <yoga/Yoga.h>
#define YG_STYLE_PROPERTY_IMPL(type, lowercased_name, capitalized_name) \
- (type)lowercased_name \
{ \
return YGNodeStyleGet##capitalized_name(self.node); \
} \
\
- (void)set##capitalized_name:(type)lowercased_name \
{ \
YGNodeStyleSet##capitalized_name(self.node, lowercased_name); \
#define YG_PROPERTY(type, lowercased_name, capitalized_name) \
- (type)lowercased_name \
{ \
return YGNodeStyleGet##capitalized_name(self.node); \
} \
\
- (void)set##capitalized_name:(type)lowercased_name \
{ \
YGNodeStyleSet##capitalized_name(self.node, lowercased_name); \
}
#define YG_STYLE_EDGE_PROPERTY_IMPL(lowercased_name, capitalized_name, property, edge) \
- (CGFloat)lowercased_name { \
return YGNodeStyleGet##property(self.node, edge); \
} \
\
- (void)set##capitalized_name:(CGFloat)lowercased_name { \
YGNodeStyleSet##property(self.node, edge, lowercased_name); \
#define YG_VALUE_PROPERTY(lowercased_name, capitalized_name) \
- (CGFloat)lowercased_name \
{ \
YGValue value = YGNodeStyleGet##capitalized_name(self.node); \
if (value.unit == YGUnitPixel) { \
return value.value; \
} else { \
return YGUndefined; \
} \
} \
\
- (void)set##capitalized_name:(CGFloat)lowercased_name \
{ \
YGNodeStyleSet##capitalized_name(self.node, lowercased_name); \
}
#define YG_STYLE_VALUE_PROPERTY_IMPL(lowercased_name, capitalized_name) \
- (CGFloat)lowercased_name \
{ \
YGValue value = YGNodeStyleGet##capitalized_name(self.node); \
if (value.unit == YGUnitPixel) { \
return value.value; \
} else { \
return YGUndefined; \
} \
} \
\
- (void)set##capitalized_name:(CGFloat)lowercased_name \
{ \
YGNodeStyleSet##capitalized_name(self.node, lowercased_name); \
#define YG_EDGE_PROPERTY_GETTER(lowercased_name, capitalized_name, property, edge) \
- (CGFloat)lowercased_name \
{ \
return YGNodeStyleGet##property(self.node, edge); \
}
#define YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(lowercased_name, capitalized_name, edge, edge_suffix) \
- (CGFloat)lowercased_name##edge_suffix \
{ \
YGValue value = YGNodeStyleGet##capitalized_name(self.node, edge); \
if (value.unit == YGUnitPixel) { \
return value.value; \
} else { \
return YGUndefined; \
} \
} \
\
- (void)set##capitalized_name##edge_suffix:(CGFloat)lowercased_name \
{ \
YGNodeStyleSet##capitalized_name(self.node, edge, lowercased_name); \
#define YG_SHORTHAND_EDGE_PROPERTY_GETTER(lowercased_name) \
- (CGFloat)lowercased_name \
{ \
return YGUndefined; \
}
#define YG_STYLE_ALL_EDGE_PROPERTY_UNIT_IMPL(lowercased_name, capitalized_name) \
YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(lowercased_name, capitalized_name, YGEdgeLeft, Left) \
YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(lowercased_name, capitalized_name, YGEdgeTop, Top) \
YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(lowercased_name, capitalized_name, YGEdgeRight, Right) \
YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(lowercased_name, capitalized_name, YGEdgeBottom, Bottom) \
YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(lowercased_name, capitalized_name, YGEdgeStart, Start) \
YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(lowercased_name, capitalized_name, YGEdgeEnd, End) \
YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(lowercased_name, capitalized_name, YGEdgeHorizontal, Horizontal) \
YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(lowercased_name, capitalized_name, YGEdgeVertical, Vertical) \
YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(lowercased_name, capitalized_name, YGEdgeAll, )
#define YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge) \
- (void)set##capitalized_name:(CGFloat)lowercased_name \
{ \
YGNodeStyleSet##property(self.node, edge, lowercased_name); \
}
#define YG_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \
YG_EDGE_PROPERTY_GETTER(lowercased_name, capitalized_name, property, edge) \
YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge)
#define YG_SHORTHAND_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \
YG_SHORTHAND_EDGE_PROPERTY_GETTER(lowercased_name) \
YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge)
#define YG_VALUE_EDGE_PROPERTY_GETTER(objc_lowercased_name, objc_capitalized_name, c_name, edge) \
- (CGFloat)objc_lowercased_name \
{ \
YGValue value = YGNodeStyleGet##c_name(self.node, edge); \
if (value.unit == YGUnitPixel) { \
return value.value; \
} else { \
return YGUndefined; \
} \
}
#define YG_VALUE_EDGE_PROPERTY_SETTER(objc_lowercased_name, objc_capitalized_name, c_name, edge) \
- (void)set##objc_capitalized_name:(CGFloat)objc_lowercased_name \
{ \
YGNodeStyleSet##c_name(self.node, edge, objc_lowercased_name); \
}
#define YG_VALUE_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \
YG_VALUE_EDGE_PROPERTY_GETTER(lowercased_name, capitalized_name, property, edge) \
YG_VALUE_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge)
#define YG_VALUE_SHORTHAND_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \
YG_SHORTHAND_EDGE_PROPERTY_GETTER(lowercased_name) \
YG_VALUE_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge)
#define YG_VALUE_EDGES_PROPERTIES(lowercased_name, capitalized_name) \
YG_VALUE_EDGE_PROPERTY(lowercased_name##Left, capitalized_name##Left, capitalized_name, YGEdgeLeft) \
YG_VALUE_EDGE_PROPERTY(lowercased_name##Top, capitalized_name##Top, capitalized_name, YGEdgeTop) \
YG_VALUE_EDGE_PROPERTY(lowercased_name##Right, capitalized_name##Right, capitalized_name, YGEdgeRight) \
YG_VALUE_EDGE_PROPERTY(lowercased_name##Bottom, capitalized_name##Bottom, capitalized_name, YGEdgeBottom) \
YG_VALUE_EDGE_PROPERTY(lowercased_name##Start, capitalized_name##Start, capitalized_name, YGEdgeStart) \
YG_VALUE_EDGE_PROPERTY(lowercased_name##End, capitalized_name##End, capitalized_name, YGEdgeEnd) \
YG_VALUE_SHORTHAND_EDGE_PROPERTY(lowercased_name##Horizontal, capitalized_name##Horizontal, capitalized_name, YGEdgeHorizontal) \
YG_VALUE_SHORTHAND_EDGE_PROPERTY(lowercased_name##Vertical, capitalized_name##Vertical, capitalized_name, YGEdgeVertical) \
YG_VALUE_SHORTHAND_EDGE_PROPERTY(lowercased_name, capitalized_name, capitalized_name, YGEdgeAll)
@interface YGLayout ()
@property (nonatomic, weak, readonly) UIView *view;
@property (nonatomic, assign, readonly) YGNodeRef node;
@end
@@ -85,6 +109,7 @@ YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(lowercased_name, capitalized_name, YGEdgeAll, )
@synthesize isEnabled=_isEnabled;
@synthesize isIncludedInLayout=_isIncludedInLayout;
@synthesize node=_node;
+ (void)initialize
{
@@ -148,43 +173,43 @@ YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(lowercased_name, capitalized_name, YGEdgeAll, )
YGNodeStyleSetPositionType(self.node, position);
}
YG_STYLE_PROPERTY_IMPL(YGDirection, direction, Direction)
YG_STYLE_PROPERTY_IMPL(YGFlexDirection, flexDirection, FlexDirection)
YG_STYLE_PROPERTY_IMPL(YGJustify, justifyContent, JustifyContent)
YG_STYLE_PROPERTY_IMPL(YGAlign, alignContent, AlignContent)
YG_STYLE_PROPERTY_IMPL(YGAlign, alignItems, AlignItems)
YG_STYLE_PROPERTY_IMPL(YGAlign, alignSelf, AlignSelf)
YG_STYLE_PROPERTY_IMPL(YGWrap, flexWrap, FlexWrap)
YG_STYLE_PROPERTY_IMPL(YGOverflow, overflow, Overflow)
YG_PROPERTY(YGDirection, direction, Direction)
YG_PROPERTY(YGFlexDirection, flexDirection, FlexDirection)
YG_PROPERTY(YGJustify, justifyContent, JustifyContent)
YG_PROPERTY(YGAlign, alignContent, AlignContent)
YG_PROPERTY(YGAlign, alignItems, AlignItems)
YG_PROPERTY(YGAlign, alignSelf, AlignSelf)
YG_PROPERTY(YGWrap, flexWrap, FlexWrap)
YG_PROPERTY(YGOverflow, overflow, Overflow)
YG_STYLE_PROPERTY_IMPL(CGFloat, flexGrow, FlexGrow)
YG_STYLE_PROPERTY_IMPL(CGFloat, flexShrink, FlexShrink)
YG_STYLE_VALUE_PROPERTY_IMPL(flexBasis, FlexBasis)
YG_PROPERTY(CGFloat, flexGrow, FlexGrow)
YG_PROPERTY(CGFloat, flexShrink, FlexShrink)
YG_VALUE_PROPERTY(flexBasis, FlexBasis)
YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(position, Position, YGEdgeLeft, Left)
YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(position, Position, YGEdgeTop, Top)
YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(position, Position, YGEdgeRight, Right)
YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(position, Position, YGEdgeBottom, Bottom)
YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(position, Position, YGEdgeStart, Start)
YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(position, Position, YGEdgeEnd, End)
YG_STYLE_ALL_EDGE_PROPERTY_UNIT_IMPL(margin, Margin)
YG_STYLE_ALL_EDGE_PROPERTY_UNIT_IMPL(padding, Padding)
YG_VALUE_EDGE_PROPERTY(left, Left, Position, YGEdgeLeft)
YG_VALUE_EDGE_PROPERTY(top, Top, Position, YGEdgeTop)
YG_VALUE_EDGE_PROPERTY(right, Right, Position, YGEdgeRight)
YG_VALUE_EDGE_PROPERTY(bottom, Bottom, Position, YGEdgeBottom)
YG_VALUE_EDGE_PROPERTY(start, Start, Position, YGEdgeStart)
YG_VALUE_EDGE_PROPERTY(end, End, Position, YGEdgeEnd)
YG_VALUE_EDGES_PROPERTIES(margin, Margin)
YG_VALUE_EDGES_PROPERTIES(padding, Padding)
YG_STYLE_EDGE_PROPERTY_IMPL(borderLeftWidth, BorderLeftWidth, Border, YGEdgeLeft)
YG_STYLE_EDGE_PROPERTY_IMPL(borderTopWidth, BorderTopWidth, Border, YGEdgeTop)
YG_STYLE_EDGE_PROPERTY_IMPL(borderRightWidth, BorderRightWidth, Border, YGEdgeRight)
YG_STYLE_EDGE_PROPERTY_IMPL(borderBottomWidth, BorderBottomWidth, Border, YGEdgeBottom)
YG_STYLE_EDGE_PROPERTY_IMPL(borderStartWidth, BorderStartWidth, Border, YGEdgeStart)
YG_STYLE_EDGE_PROPERTY_IMPL(borderEndWidth, BorderEndWidth, Border, YGEdgeEnd)
YG_STYLE_EDGE_PROPERTY_IMPL(borderWidth, BorderWidth, Border, YGEdgeAll)
YG_EDGE_PROPERTY(borderLeftWidth, BorderLeftWidth, Border, YGEdgeLeft)
YG_EDGE_PROPERTY(borderTopWidth, BorderTopWidth, Border, YGEdgeTop)
YG_EDGE_PROPERTY(borderRightWidth, BorderRightWidth, Border, YGEdgeRight)
YG_EDGE_PROPERTY(borderBottomWidth, BorderBottomWidth, Border, YGEdgeBottom)
YG_EDGE_PROPERTY(borderStartWidth, BorderStartWidth, Border, YGEdgeStart)
YG_EDGE_PROPERTY(borderEndWidth, BorderEndWidth, Border, YGEdgeEnd)
YG_SHORTHAND_EDGE_PROPERTY(borderWidth, BorderWidth, Border, YGEdgeAll)
YG_STYLE_VALUE_PROPERTY_IMPL(width, Width)
YG_STYLE_VALUE_PROPERTY_IMPL(height, Height)
YG_STYLE_VALUE_PROPERTY_IMPL(minWidth, MinWidth)
YG_STYLE_VALUE_PROPERTY_IMPL(minHeight, MinHeight)
YG_STYLE_VALUE_PROPERTY_IMPL(maxWidth, MaxWidth)
YG_STYLE_VALUE_PROPERTY_IMPL(maxHeight, MaxHeight)
YG_STYLE_PROPERTY_IMPL(CGFloat, aspectRatio, AspectRatio)
YG_VALUE_PROPERTY(width, Width)
YG_VALUE_PROPERTY(height, Height)
YG_VALUE_PROPERTY(minWidth, MinWidth)
YG_VALUE_PROPERTY(minHeight, MinHeight)
YG_VALUE_PROPERTY(maxWidth, MaxWidth)
YG_VALUE_PROPERTY(maxHeight, MaxHeight)
YG_PROPERTY(CGFloat, aspectRatio, AspectRatio)
#pragma mark - Layout and Sizing

View File

@@ -10,47 +10,53 @@
#import <XCTest/XCTest.h>
#import <YogaKit/UIView+Yoga.h>
#import <YogaKit/YGLayout+Private.h>
#import <yoga/Yoga.h>
@interface YogaKitTests : XCTestCase
@end
@implementation YogaKitTests
#ifndef TRAVIS_CI
- (void)testNodesAreDeallocedWithSingleView
{
XCTAssertEqual(0, YGNodeGetInstanceCount());
__weak YGLayout *layoutRef = nil;
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
view.yoga.flexBasis = 1;
XCTAssertEqual(1, YGNodeGetInstanceCount());
view = nil;
@autoreleasepool {
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
view.yoga.flexBasis = 1;
XCTAssertEqual(0, YGNodeGetInstanceCount());
layoutRef = view.yoga;
XCTAssertNotNil(layoutRef);
view = nil;
}
XCTAssertNil(layoutRef);
}
- (void)testNodesAreDeallocedCascade
{
XCTAssertEqual(0, YGNodeGetInstanceCount());
__weak YGLayout *topLayout = nil;
__weak YGLayout *subviewLayout = nil;
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
view.yoga.flexBasis = 1;
@autoreleasepool {
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
topLayout = view.yoga;
topLayout.flexBasis = 1;
for (int i=0; i<10; i++) {
UIView *subview = [[UIView alloc] initWithFrame:CGRectZero];
subview.yoga.flexBasis = 1;
[view addSubview:subview];
}
XCTAssertEqual(11, YGNodeGetInstanceCount());
view = nil;
subviewLayout = subview.yoga;
subviewLayout.flexBasis = 1;
XCTAssertEqual(0, YGNodeGetInstanceCount());
view = nil;
}
XCTAssertNil(topLayout);
XCTAssertNil(subviewLayout);
}
#endif
- (void)testUsesYoga
- (void)testIsEnabled
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
XCTAssertFalse(view.yoga.isEnabled);
@@ -87,13 +93,20 @@
UIView *textBadgeView = [[UIView alloc] initWithFrame:CGRectZero];
textBadgeView.yoga.isEnabled = YES;
textBadgeView.yoga.marginLeft = 3.0;
textBadgeView.yoga.margin = 0;
textBadgeView.yoga.width = 10;
textBadgeView.yoga.height = 10;
[container addSubview:textBadgeView];
const CGSize textBadgeViewSize = textBadgeView.yoga.intrinsicSize;
XCTAssertEqual(textBadgeViewSize.height, 10);
XCTAssertEqual(textBadgeViewSize.width, 10);
const CGSize containerSize = container.yoga.intrinsicSize;
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(514,21), containerSize), @"Size is actually %@", NSStringFromCGSize(containerSize));
const CGSize longTextLabelSize = longTextLabel.yoga.intrinsicSize;
XCTAssertEqual(longTextLabelSize.height, containerSize.height);
XCTAssertEqual(longTextLabelSize.width + textBadgeView.yoga.intrinsicSize.width, containerSize.width);
}
- (void)testThatMarkingLeafsAsDirtyWillTriggerASizeRecalculation
@@ -110,13 +123,15 @@
[container addSubview:label];
[container.yoga applyLayout];
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(146,21), label.bounds.size), @"Size is actually %@", NSStringFromCGSize(label.bounds.size));
CGSize const labelSizeAfterFirstPass = label.frame.size;
label.text = @"This is a slightly longer text.";
XCTAssertTrue(CGSizeEqualToSize(label.frame.size, labelSizeAfterFirstPass));
[label.yoga markDirty];
[container.yoga applyLayout];
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(213,21), label.bounds.size), @"Size is actually %@", NSStringFromCGSize(label.bounds.size));
XCTAssertFalse(CGSizeEqualToSize(label.frame.size, labelSizeAfterFirstPass));
}
- (void)testFrameAndOriginPlacement
@@ -127,18 +142,25 @@
container.yoga.isEnabled = YES;
container.yoga.flexDirection = YGFlexDirectionRow;
for (int i = 0; i < 3; i++) {
UIView *subview = [[UIView alloc] initWithFrame:CGRectZero];
subview.yoga.isEnabled = YES;
subview.yoga.flexGrow = 1;
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
subview1.yoga.isEnabled = YES;
subview1.yoga.flexGrow = 1;
[container addSubview:subview1];
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
subview2.yoga.isEnabled = YES;
subview2.yoga.flexGrow = 1;
[container addSubview:subview2];
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
subview3.yoga.isEnabled = YES;
subview3.yoga.flexGrow = 1;
[container addSubview:subview3];
[container addSubview:subview];
}
[container.yoga applyLayout];
XCTAssertFalse(CGRectIntersectsRect([container.subviews objectAtIndex:0].frame, [container.subviews objectAtIndex:1].frame));
XCTAssertFalse(CGRectIntersectsRect([container.subviews objectAtIndex:1].frame, [container.subviews objectAtIndex:2].frame));
XCTAssertFalse(CGRectIntersectsRect([container.subviews objectAtIndex:0].frame, [container.subviews objectAtIndex:2].frame));
XCTAssertEqualWithAccuracy(subview2.frame.origin.x, CGRectGetMaxX(subview1.frame), FLT_EPSILON);
XCTAssertEqualWithAccuracy(subview3.frame.origin.x, CGRectGetMaxX(subview2.frame), FLT_EPSILON);
CGFloat totalWidth = 0;
for (UIView *view in container.subviews) {
@@ -174,7 +196,7 @@
[container.yoga applyLayout];
XCTAssertTrue(CGRectEqualToRect(subview1.frame, CGRectMake(0, 0, 100, 50)));
XCTAssertTrue(CGRectEqualToRect(subview2.frame, CGRectMake(100, 0, 100, 50)), @"It's actually %@", NSStringFromCGRect(subview2.frame));
XCTAssertTrue(CGRectEqualToRect(subview2.frame, CGRectMake(100, 0, 100, 50)));
XCTAssertTrue(CGRectEqualToRect(subview3.frame, CGRectMake(200, 0, 100, 50)));
[container exchangeSubviewAtIndex:2 withSubviewAtIndex:0];
@@ -213,18 +235,18 @@
[container.yoga applyLayout];
for (UIView *view in container.subviews) {
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(100, 50), view.bounds.size), @"Actual size is %@", NSStringFromCGSize(view.bounds.size));
for (UIView *subview in container.subviews) {
XCTAssertEqual(subview.bounds.size.width, 100);
}
subview3.yoga.isIncludedInLayout = NO;
[container.yoga applyLayout];
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(150, 50), subview1.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview1.bounds.size));
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(150, 50), subview2.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview2.bounds.size));
XCTAssertEqual(subview1.bounds.size.width, 150);
XCTAssertEqual(subview2.bounds.size.width, 150);
// We don't set the frame to zero, so, it should be set to what it was previously at.
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(100, 50), subview3.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview3.bounds.size));
XCTAssertEqual(subview3.bounds.size.width, 100);
}
- (void)testThatNumberOfChildrenIsCorrectWhenWeIgnoreSubviews
@@ -249,11 +271,11 @@
[container addSubview:subview3];
[container.yoga applyLayout];
XCTAssertEqual(1, container.yoga.numberOfChildren);
XCTAssertEqual(container.yoga.numberOfChildren, 1);
subview2.yoga.isIncludedInLayout = YES;
[container.yoga applyLayout];
XCTAssertEqual(2, container.yoga.numberOfChildren);
XCTAssertEqual(container.yoga.numberOfChildren, 2);
}
- (void)testThatViewNotIncludedInFirstLayoutPassAreIncludedInSecond
@@ -280,18 +302,19 @@
[container.yoga applyLayout];
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(150, 50), subview1.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview1.bounds.size));
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(150, 50), subview2.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview2.bounds.size));
XCTAssertTrue(CGSizeEqualToSize(CGSizeZero, subview3.bounds.size), @"Actual size %@", NSStringFromCGSize(subview3.bounds.size));
XCTAssertEqual(subview1.bounds.size.width, 150);
XCTAssertEqual(subview2.bounds.size.width, 150);
XCTAssertEqual(subview3.bounds.size.width, 0);
subview3.yoga.isIncludedInLayout = YES;
[container.yoga applyLayout];
for (UIView *view in container.subviews) {
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(100, 50), view.bounds.size), @"Actual size is %@", NSStringFromCGSize(view.bounds.size));
}
XCTAssertEqual(subview1.bounds.size.width, 100);
XCTAssertEqual(subview2.bounds.size.width, 100);
XCTAssertEqual(subview3.bounds.size.width, 100);
}
- (void)testyg_isLeafFlag
- (void)testIsLeafFlag
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
XCTAssertTrue(view.yoga.isLeaf);
@@ -349,18 +372,22 @@
}
[container.yoga applyLayout];
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(100, 25), subview1.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview1.bounds.size));
XCTAssertEqual(subview1.bounds.size.width, 100);
XCTAssertEqual(subview1.bounds.size.height, 25);
for (UIView *subview in subview1.subviews) {
const CGSize subviewSize = subview.bounds.size;
XCTAssertFalse(CGSizeEqualToSize(CGSizeZero, subviewSize));
XCTAssertNotEqual(subviewSize.width, 0);
XCTAssertNotEqual(subviewSize.height, 0);
XCTAssertFalse(isnan(subviewSize.height));
XCTAssertFalse(isnan(subviewSize.width));
}
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(150, 25), subview2.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview2.bounds.size));
XCTAssertEqual(subview2.bounds.size.width, 150);
XCTAssertEqual(subview2.bounds.size.height, 25);
for (UIView *subview in subview2.subviews) {
const CGSize subviewSize = subview.bounds.size;
XCTAssertFalse(CGSizeEqualToSize(CGSizeZero, subview.bounds.size));
XCTAssertNotEqual(subviewSize.width, 0);
XCTAssertNotEqual(subviewSize.height, 0);
XCTAssertFalse(isnan(subviewSize.height));
XCTAssertFalse(isnan(subviewSize.width));
}
@@ -384,4 +411,211 @@
[container.yoga applyLayout];
}
- (void)testPositionalPropertiesWork
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
view.yoga.left = 1;
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeLeft).value, 1);
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.left, 1);
view.yoga.right = 2;
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeRight).value, 2);
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeRight).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.right, 2);
view.yoga.top = 3;
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeTop).value, 3);
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeTop).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.top, 3);
view.yoga.bottom = 4;
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeBottom).value, 4);
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.bottom, 4);
view.yoga.start = 5;
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeStart).value, 5);
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeStart).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.start, 5);
view.yoga.end = 6;
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeEnd).value, 6);
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.end, 6);
}
- (void)testMarginPropertiesWork
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
view.yoga.margin = 1;
XCTAssertEqual(view.yoga.marginLeft, 1);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginRight, 1);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeRight).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginStart, 1);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeStart).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginEnd, 1);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginTop, 1);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeTop).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginBottom, 1);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel);
XCTAssertTrue(isnan(view.yoga.marginHorizontal));
XCTAssertTrue(isnan(view.yoga.marginVertical));
XCTAssertTrue(isnan(view.yoga.margin));
view.yoga.marginHorizontal = 2;
XCTAssertEqual(view.yoga.marginLeft, 2);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginRight, 2);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeRight).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginStart, 2);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeStart).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginEnd, 2);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel);
XCTAssertTrue(isnan(view.yoga.marginHorizontal));
view.yoga.marginVertical = 3;
XCTAssertEqual(view.yoga.marginTop, 3);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeTop).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginBottom, 3);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel);
XCTAssertTrue(isnan(view.yoga.marginVertical));
view.yoga.marginLeft = 4;
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeLeft).value, 4);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginLeft, 4);
view.yoga.marginRight = 5;
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeRight).value, 5);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeRight).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginRight, 5);
view.yoga.marginTop = 6;
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeTop).value, 6);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeTop).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginTop, 6);
view.yoga.marginBottom = 7;
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeBottom).value, 7);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginBottom, 7);
view.yoga.marginStart = 8;
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeStart).value, 8);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeStart).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginStart, 8);
view.yoga.marginEnd = 9;
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeEnd).value, 9);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginEnd, 9);
}
- (void)testPaddingPropertiesWork
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
view.yoga.padding = 1;
XCTAssertEqual(view.yoga.paddingLeft, 1);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingRight, 1);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeRight).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingStart, 1);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeStart).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingEnd, 1);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingTop, 1);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeTop).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingBottom, 1);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel);
XCTAssertTrue(isnan(view.yoga.paddingHorizontal));
XCTAssertTrue(isnan(view.yoga.paddingVertical));
XCTAssertTrue(isnan(view.yoga.padding));
view.yoga.paddingHorizontal = 2;
XCTAssertEqual(view.yoga.paddingLeft, 2);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingRight, 2);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeRight).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingStart, 2);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeStart).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingEnd, 2);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel);
XCTAssertTrue(isnan(view.yoga.paddingHorizontal));
view.yoga.paddingVertical = 3;
XCTAssertEqual(view.yoga.paddingTop, 3);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeTop).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingBottom, 3);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel);
XCTAssertTrue(isnan(view.yoga.paddingVertical));
view.yoga.paddingLeft = 4;
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeLeft).value, 4);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingLeft, 4);
view.yoga.paddingRight = 5;
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeRight).value, 5);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeRight).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingRight, 5);
view.yoga.paddingTop = 6;
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeTop).value, 6);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeTop).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingTop, 6);
view.yoga.paddingBottom = 7;
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeBottom).value, 7);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingBottom, 7);
view.yoga.paddingStart = 8;
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeStart).value, 8);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeStart).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingStart, 8);
view.yoga.paddingEnd = 9;
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeEnd).value, 9);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingEnd, 9);
}
- (void)testBorderWidthPropertiesWork
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
view.yoga.borderWidth = 1;
XCTAssertEqual(view.yoga.borderLeftWidth, 1);
XCTAssertEqual(view.yoga.borderRightWidth, 1);
XCTAssertEqual(view.yoga.borderStartWidth, 1);
XCTAssertEqual(view.yoga.borderEndWidth, 1);
XCTAssertEqual(view.yoga.borderTopWidth, 1);
XCTAssertEqual(view.yoga.borderBottomWidth, 1);
XCTAssertTrue(isnan(view.yoga.borderWidth));
view.yoga.borderLeftWidth = 2;
XCTAssertEqual(view.yoga.borderLeftWidth, 2);
view.yoga.borderRightWidth = 3;
XCTAssertEqual(view.yoga.borderRightWidth, 3);
view.yoga.borderTopWidth = 4;
XCTAssertEqual(view.yoga.borderTopWidth, 4);
view.yoga.borderBottomWidth = 5;
XCTAssertEqual(view.yoga.borderBottomWidth, 5);
view.yoga.borderStartWidth = 6;
XCTAssertEqual(view.yoga.borderStartWidth, 6);
view.yoga.borderEndWidth = 7;
XCTAssertEqual(view.yoga.borderEndWidth, 7);
}
@end

30
YogaKit/YogaKit.podspec Normal file
View File

@@ -0,0 +1,30 @@
Pod::Spec.new do |spec|
spec.name = 'YogaKit'
spec.version = '1.0.0'
spec.license = { :type => 'BSD-3-Clause', :file => '../LICENSE' }
spec.homepage = 'https://facebook.github.io/yoga'
spec.authors = {
'Emil Sjölander' => 'sjolander.emil@gmail.com',
'Dustin Shahidehpour' => 'dshahidehpour@gmail.com'
}
spec.summary = 'Yoga is a cross-platform layout engine which implements Flexbox.'
spec.description = <<-DESC
Yoga is a cross-platform layout engine which implements Flexbox.
It enables maximum collaboration within your team by implementing an API familiar to
many designers and opening it up to developers across different platforms.
DESC
spec.documentation_url = 'https://facebook.github.io/yoga/docs/getting-started/'
spec.source = {
:git => 'https://github.com/facebook/yoga.git',
:tag => 'v2017.01.23.00'
}
spec.platform = :ios
spec.dependency 'Yoga', '~> 1.0'
spec.source_files = 'Source/*.{h,m}',
spec.public_header_files = 'Source/{YGLayout,UIView+Yoga}.h'
spec.private_header_files = 'Source/YGLayout+Private.h'
end

View File

@@ -21,10 +21,20 @@
13687D851DF87D1E00E7C260 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 13687D841DF87D1E00E7C260 /* UIKit.framework */; };
13687D871DF87D2400E7C260 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 13687D861DF87D2400E7C260 /* Foundation.framework */; };
638A94431E1EF5D000A726AD /* YGLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 638A94411E1EF5D000A726AD /* YGLayout.m */; };
638A94451E1EF8A900A726AD /* YGValue.h in yoga */ = {isa = PBXBuildFile; fileRef = 638A94441E1EF89C00A726AD /* YGValue.h */; };
638A94481E1F06D100A726AD /* SwiftViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 638A94471E1F06D100A726AD /* SwiftViewController.swift */; };
638A945A1E215CD400A726AD /* YogaKitTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 638A94591E215CD400A726AD /* YogaKitTests.m */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
638A94541E215CC800A726AD /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 13687D3B1DF8748300E7C260 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 13687D421DF8748300E7C260;
remoteInfo = YogaKitSample;
};
/* End PBXContainerItemProxy section */
/* Begin PBXCopyFilesBuildPhase section */
13687D771DF878A000E7C260 /* yoga */ = {
isa = PBXCopyFilesBuildPhase;
@@ -32,7 +42,6 @@
dstPath = include/yoga;
dstSubfolderSpec = 16;
files = (
638A94451E1EF8A900A726AD /* YGValue.h in yoga */,
13687D781DF878C600E7C260 /* YGEnums.h in yoga */,
13687D791DF878C600E7C260 /* YGMacros.h in yoga */,
13687D7A1DF878C600E7C260 /* Yoga.h in yoga */,
@@ -75,9 +84,11 @@
638A94401E1EF5D000A726AD /* YGLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGLayout.h; sourceTree = "<group>"; };
638A94411E1EF5D000A726AD /* YGLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YGLayout.m; sourceTree = "<group>"; };
638A94421E1EF5D000A726AD /* YGLayout+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "YGLayout+Private.h"; sourceTree = "<group>"; };
638A94441E1EF89C00A726AD /* YGValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGValue.h; sourceTree = "<group>"; };
638A94461E1F06D100A726AD /* YogaKitSample-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "YogaKitSample-Bridging-Header.h"; sourceTree = "<group>"; };
638A94471E1F06D100A726AD /* SwiftViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftViewController.swift; sourceTree = "<group>"; };
638A944F1E215CC800A726AD /* YogaKitSampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = YogaKitSampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
638A94531E215CC800A726AD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
638A94591E215CD400A726AD /* YogaKitTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = YogaKitTests.m; path = ../../Tests/YogaKitTests.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -90,6 +101,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
638A944C1E215CC800A726AD /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
@@ -99,6 +117,7 @@
13687D5D1DF8778F00E7C260 /* yoga */,
13687D641DF8778F00E7C260 /* YogaKit */,
13687D451DF8748400E7C260 /* YogaKitSample */,
638A94501E215CC800A726AD /* YogaKitSampleTests */,
13687D441DF8748400E7C260 /* Products */,
13687D831DF87D1E00E7C260 /* Frameworks */,
);
@@ -108,6 +127,7 @@
isa = PBXGroup;
children = (
13687D431DF8748400E7C260 /* YogaKitSample.app */,
638A944F1E215CC800A726AD /* YogaKitSampleTests.xctest */,
);
name = Products;
sourceTree = "<group>";
@@ -139,7 +159,6 @@
13687D5D1DF8778F00E7C260 /* yoga */ = {
isa = PBXGroup;
children = (
638A94441E1EF89C00A726AD /* YGValue.h */,
13687D5E1DF8778F00E7C260 /* YGEnums.h */,
13687D5F1DF8778F00E7C260 /* YGMacros.h */,
13687D601DF8778F00E7C260 /* YGNodeList.c */,
@@ -173,6 +192,15 @@
name = Frameworks;
sourceTree = "<group>";
};
638A94501E215CC800A726AD /* YogaKitSampleTests */ = {
isa = PBXGroup;
children = (
638A94591E215CD400A726AD /* YogaKitTests.m */,
638A94531E215CC800A726AD /* Info.plist */,
);
path = YogaKitSampleTests;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@@ -195,6 +223,24 @@
productReference = 13687D431DF8748400E7C260 /* YogaKitSample.app */;
productType = "com.apple.product-type.application";
};
638A944E1E215CC800A726AD /* YogaKitSampleTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = 638A94561E215CC800A726AD /* Build configuration list for PBXNativeTarget "YogaKitSampleTests" */;
buildPhases = (
638A944B1E215CC800A726AD /* Sources */,
638A944C1E215CC800A726AD /* Frameworks */,
638A944D1E215CC800A726AD /* Resources */,
);
buildRules = (
);
dependencies = (
638A94551E215CC800A726AD /* PBXTargetDependency */,
);
name = YogaKitSampleTests;
productName = YogaKitSampleTests;
productReference = 638A944F1E215CC800A726AD /* YogaKitSampleTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
@@ -209,6 +255,11 @@
LastSwiftMigration = 0820;
ProvisioningStyle = Automatic;
};
638A944E1E215CC800A726AD = {
CreatedOnToolsVersion = 8.2.1;
ProvisioningStyle = Automatic;
TestTargetID = 13687D421DF8748300E7C260;
};
};
};
buildConfigurationList = 13687D3E1DF8748300E7C260 /* Build configuration list for PBXProject "YogaKitSample" */;
@@ -225,6 +276,7 @@
projectRoot = "";
targets = (
13687D421DF8748300E7C260 /* YogaKitSample */,
638A944E1E215CC800A726AD /* YogaKitSampleTests */,
);
};
/* End PBXProject section */
@@ -238,6 +290,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
638A944D1E215CC800A726AD /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
@@ -256,8 +315,24 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
638A944B1E215CC800A726AD /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
638A945A1E215CD400A726AD /* YogaKitTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
638A94551E215CC800A726AD /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 13687D421DF8748300E7C260 /* YogaKitSample */;
targetProxy = 638A94541E215CC800A726AD /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
/* Begin XCBuildConfiguration section */
13687D581DF8748400E7C260 /* Debug */ = {
isa = XCBuildConfiguration;
@@ -378,6 +453,34 @@
};
name = Release;
};
638A94571E215CC800A726AD /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
BUNDLE_LOADER = "$(TEST_HOST)";
INFOPLIST_FILE = YogaKitSampleTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.facebook.YogaKitSampleTests;
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/YogaKitSample.app/YogaKitSample";
};
name = Debug;
};
638A94581E215CC800A726AD /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
BUNDLE_LOADER = "$(TEST_HOST)";
INFOPLIST_FILE = YogaKitSampleTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.facebook.YogaKitSampleTests;
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/YogaKitSample.app/YogaKitSample";
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
@@ -399,6 +502,14 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
638A94561E215CC800A726AD /* Build configuration list for PBXNativeTarget "YogaKitSampleTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
638A94571E215CC800A726AD /* Debug */,
638A94581E215CC800A726AD /* Release */,
);
defaultConfigurationIsVisible = 0;
};
/* End XCConfigurationList section */
};
rootObject = 13687D3B1DF8748300E7C260 /* Project object */;

View File

@@ -1,32 +0,0 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
namespace Facebook.Yoga
{
[System.Obsolete]
public class Border
{
public float? Top;
public float? Bottom;
public float? Left;
public float? Right;
public Border(
float? top = null,
float? bottom = null,
float? left = null,
float? right = null)
{
Top = top;
Bottom = bottom;
Left = left;
Right = right;
}
}
}

View File

@@ -10,11 +10,9 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)BaselineFunction.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Border.cs" />
<Compile Include="$(MSBuildThisFileDirectory)MeasureFunction.cs" />
<Compile Include="$(MSBuildThisFileDirectory)MeasureOutput.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Native.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Spacing.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaAlign.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaBaselineFunc.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaConstants.cs" />
@@ -28,7 +26,6 @@
<Compile Include="$(MSBuildThisFileDirectory)YogaLogLevel.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaMeasureFunc.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaMeasureMode.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaNode.Create.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaNode.Spacing.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaNode.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaOverflow.cs" />
@@ -40,4 +37,4 @@
<Compile Include="$(MSBuildThisFileDirectory)YogaValueExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaWrap.cs" />
</ItemGroup>
</Project>
</Project>

View File

@@ -1,32 +0,0 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
namespace Facebook.Yoga
{
[System.Obsolete]
public class Spacing
{
public YogaValue? Top;
public YogaValue? Bottom;
public YogaValue? Left;
public YogaValue? Right;
public Spacing(
YogaValue? top = null,
YogaValue? bottom = null,
YogaValue? left = null,
YogaValue? right = null)
{
Top = top;
Bottom = bottom;
Left = left;
Right = right;
}
}
}

View File

@@ -1,234 +0,0 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
using System;
namespace Facebook.Yoga
{
public partial class YogaNode
{
[Obsolete("use Object Initializer")]
public static YogaNode Create(
YogaDirection? styleDirection = null,
YogaFlexDirection? flexDirection = null,
YogaJustify? justifyContent = null,
YogaAlign? alignContent = null,
YogaAlign? alignItems = null,
YogaAlign? alignSelf = null,
YogaPositionType? positionType = null,
YogaWrap? wrap = null,
YogaOverflow? overflow = null,
float? flex = null,
float? flexGrow = null,
float? flexShrink = null,
YogaValue? flexBasis = null,
Spacing position = null,
Spacing margin = null,
Spacing padding = null,
Border border = null,
YogaValue? width = null,
YogaValue? height = null,
YogaValue? maxWidth = null,
YogaValue? maxHeight = null,
YogaValue? minWidth = null,
YogaValue? minHeight = null)
{
YogaNode node = new YogaNode();
if (styleDirection.HasValue)
{
node.StyleDirection = styleDirection.Value;
}
if (flexDirection.HasValue)
{
node.FlexDirection = flexDirection.Value;
}
if (justifyContent.HasValue)
{
node.JustifyContent = justifyContent.Value;
}
if (alignContent.HasValue)
{
node.AlignContent = alignContent.Value;
}
if (alignItems.HasValue)
{
node.AlignItems = alignItems.Value;
}
if (alignSelf.HasValue)
{
node.AlignSelf = alignSelf.Value;
}
if (positionType.HasValue)
{
node.PositionType = positionType.Value;
}
if (wrap.HasValue)
{
node.Wrap = wrap.Value;
}
if (overflow.HasValue)
{
node.Overflow = overflow.Value;
}
if (flex.HasValue)
{
node.Flex = flex.Value;
}
if (flexGrow.HasValue)
{
node.FlexGrow = flexGrow.Value;
}
if (flexShrink.HasValue)
{
node.FlexShrink = flexShrink.Value;
}
if (flexBasis.HasValue)
{
node.FlexBasis = flexBasis.Value;
}
if (position != null)
{
if (position.Top.HasValue)
{
node.Top = position.Top.Value;
}
if (position.Bottom.HasValue)
{
node.Bottom = position.Bottom.Value;
}
if (position.Left.HasValue)
{
node.Left = position.Left.Value;
}
if (position.Right.HasValue)
{
node.Right = position.Right.Value;
}
}
if (margin != null)
{
if (margin.Top.HasValue)
{
node.MarginTop = margin.Top.Value;
}
if (margin.Bottom.HasValue)
{
node.MarginBottom = margin.Bottom.Value;
}
if (margin.Left.HasValue)
{
node.MarginLeft = margin.Left.Value;
}
if (margin.Right.HasValue)
{
node.MarginRight = margin.Right.Value;
}
}
if (padding != null)
{
if (padding.Top.HasValue)
{
node.PaddingTop = padding.Top.Value;
}
if (padding.Bottom.HasValue)
{
node.PaddingBottom = padding.Bottom.Value;
}
if (padding.Left.HasValue)
{
node.PaddingLeft = padding.Left.Value;
}
if (padding.Right.HasValue)
{
node.PaddingRight = padding.Right.Value;
}
}
if (border != null)
{
if (border.Top.HasValue)
{
node.BorderTopWidth = border.Top.Value;
}
if (border.Bottom.HasValue)
{
node.BorderBottomWidth = border.Bottom.Value;
}
if (border.Left.HasValue)
{
node.BorderLeftWidth = border.Left.Value;
}
if (border.Right.HasValue)
{
node.BorderRightWidth = border.Right.Value;
}
}
if (width.HasValue)
{
node.Width = width.Value;
}
if (height.HasValue)
{
node.Height = height.Value;
}
if (minWidth.HasValue)
{
node.MinWidth = minWidth.Value;
}
if (minHeight.HasValue)
{
node.MinHeight = minHeight.Value;
}
if (maxWidth.HasValue)
{
node.MaxWidth = maxWidth.Value;
}
if (maxHeight.HasValue)
{
node.MaxHeight = maxHeight.Value;
}
return node;
}
}
}

View File

@@ -264,81 +264,6 @@ namespace Facebook.Yoga
}
}
[Obsolete("use Margin properties")]
public YogaValue GetMargin(YogaEdge edge)
{
return Native.YGNodeStyleGetMargin(_ygNode, edge);
}
[Obsolete("use Margin properties")]
public void SetMargin(YogaEdge edge, YogaValue value)
{
if (value.Unit == YogaUnit.Percent)
{
Native.YGNodeStyleSetMarginPercent(_ygNode, edge, value.Value);
}
else
{
Native.YGNodeStyleSetMargin(_ygNode, edge, value.Value);
}
}
[Obsolete("use Padding properties")]
public YogaValue GetPadding(YogaEdge edge)
{
return Native.YGNodeStyleGetPadding(_ygNode, edge);
}
[Obsolete("use Padding properties")]
public void SetPadding(YogaEdge edge, YogaValue value)
{
if (value.Unit == YogaUnit.Percent)
{
Native.YGNodeStyleSetPaddingPercent(_ygNode, edge, value.Value);
}
else
{
Native.YGNodeStyleSetPadding(_ygNode, edge, value.Value);
}
}
[Obsolete("use BorderWidth properties")]
public float GetBorder(YogaEdge edge)
{
return Native.YGNodeStyleGetBorder(_ygNode, edge);
}
[Obsolete("use BorderWidth properties")]
public void SetBorder(YogaEdge edge, float border)
{
Native.YGNodeStyleSetBorder(_ygNode, edge, border);
}
[Obsolete("use Position properties")]
public YogaValue GetPosition(YogaEdge edge)
{
return Native.YGNodeStyleGetPosition(_ygNode, edge);
}
[Obsolete("use Position properties")]
public void SetPosition(YogaEdge edge, YogaValue value)
{
if (value.Unit == YogaUnit.Percent)
{
Native.YGNodeStyleSetPositionPercent(_ygNode, edge, value.Value);
}
else
{
Native.YGNodeStyleSetPosition(_ygNode, edge, value.Value);
}
}
[Obsolete("use LayoutPadding properties")]
public float GetLayoutPadding(YogaEdge edge)
{
return Native.YGNodeLayoutGetPadding(_ygNode, edge);
}
public YogaValue Width
{
get

View File

@@ -310,5 +310,384 @@ namespace Facebook.Yoga
Assert.AreEqual(50f, root_child1.LayoutHeight);
}
[Test]
public void Test_absolute_layout_align_items_and_justify_content_center()
{
YogaNode root = new YogaNode();
root.JustifyContent = YogaJustify.Center;
root.AlignItems = YogaAlign.Center;
root.FlexGrow = 1;
root.Width = 110;
root.Height = 100;
YogaNode root_child0 = new YogaNode();
root_child0.PositionType = YogaPositionType.Absolute;
root_child0.Width = 60;
root_child0.Height = 40;
root.Insert(0, root_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(110f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(25f, root_child0.LayoutX);
Assert.AreEqual(30f, root_child0.LayoutY);
Assert.AreEqual(60f, root_child0.LayoutWidth);
Assert.AreEqual(40f, root_child0.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(110f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(25f, root_child0.LayoutX);
Assert.AreEqual(30f, root_child0.LayoutY);
Assert.AreEqual(60f, root_child0.LayoutWidth);
Assert.AreEqual(40f, root_child0.LayoutHeight);
}
[Test]
public void Test_absolute_layout_align_items_and_justify_content_flex_end()
{
YogaNode root = new YogaNode();
root.JustifyContent = YogaJustify.FlexEnd;
root.AlignItems = YogaAlign.FlexEnd;
root.FlexGrow = 1;
root.Width = 110;
root.Height = 100;
YogaNode root_child0 = new YogaNode();
root_child0.PositionType = YogaPositionType.Absolute;
root_child0.Width = 60;
root_child0.Height = 40;
root.Insert(0, root_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(110f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(50f, root_child0.LayoutX);
Assert.AreEqual(60f, root_child0.LayoutY);
Assert.AreEqual(60f, root_child0.LayoutWidth);
Assert.AreEqual(40f, root_child0.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(110f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(60f, root_child0.LayoutY);
Assert.AreEqual(60f, root_child0.LayoutWidth);
Assert.AreEqual(40f, root_child0.LayoutHeight);
}
[Test]
public void Test_absolute_layout_justify_content_center()
{
YogaNode root = new YogaNode();
root.JustifyContent = YogaJustify.Center;
root.FlexGrow = 1;
root.Width = 110;
root.Height = 100;
YogaNode root_child0 = new YogaNode();
root_child0.PositionType = YogaPositionType.Absolute;
root_child0.Width = 60;
root_child0.Height = 40;
root.Insert(0, root_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(110f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(30f, root_child0.LayoutY);
Assert.AreEqual(60f, root_child0.LayoutWidth);
Assert.AreEqual(40f, root_child0.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(110f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(50f, root_child0.LayoutX);
Assert.AreEqual(30f, root_child0.LayoutY);
Assert.AreEqual(60f, root_child0.LayoutWidth);
Assert.AreEqual(40f, root_child0.LayoutHeight);
}
[Test]
public void Test_absolute_layout_align_items_center()
{
YogaNode root = new YogaNode();
root.AlignItems = YogaAlign.Center;
root.FlexGrow = 1;
root.Width = 110;
root.Height = 100;
YogaNode root_child0 = new YogaNode();
root_child0.PositionType = YogaPositionType.Absolute;
root_child0.Width = 60;
root_child0.Height = 40;
root.Insert(0, root_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(110f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(25f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(60f, root_child0.LayoutWidth);
Assert.AreEqual(40f, root_child0.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(110f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(25f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(60f, root_child0.LayoutWidth);
Assert.AreEqual(40f, root_child0.LayoutHeight);
}
[Test]
public void Test_absolute_layout_align_items_center_on_child_only()
{
YogaNode root = new YogaNode();
root.FlexGrow = 1;
root.Width = 110;
root.Height = 100;
YogaNode root_child0 = new YogaNode();
root_child0.AlignSelf = YogaAlign.Center;
root_child0.PositionType = YogaPositionType.Absolute;
root_child0.Width = 60;
root_child0.Height = 40;
root.Insert(0, root_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(110f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(25f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(60f, root_child0.LayoutWidth);
Assert.AreEqual(40f, root_child0.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(110f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(25f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(60f, root_child0.LayoutWidth);
Assert.AreEqual(40f, root_child0.LayoutHeight);
}
[Test]
public void Test_absolute_layout_align_items_and_justify_content_center_and_top_position()
{
YogaNode root = new YogaNode();
root.JustifyContent = YogaJustify.Center;
root.AlignItems = YogaAlign.Center;
root.FlexGrow = 1;
root.Width = 110;
root.Height = 100;
YogaNode root_child0 = new YogaNode();
root_child0.PositionType = YogaPositionType.Absolute;
root_child0.Top = 10;
root_child0.Width = 60;
root_child0.Height = 40;
root.Insert(0, root_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(110f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(25f, root_child0.LayoutX);
Assert.AreEqual(10f, root_child0.LayoutY);
Assert.AreEqual(60f, root_child0.LayoutWidth);
Assert.AreEqual(40f, root_child0.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(110f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(25f, root_child0.LayoutX);
Assert.AreEqual(10f, root_child0.LayoutY);
Assert.AreEqual(60f, root_child0.LayoutWidth);
Assert.AreEqual(40f, root_child0.LayoutHeight);
}
[Test]
public void Test_absolute_layout_align_items_and_justify_content_center_and_bottom_position()
{
YogaNode root = new YogaNode();
root.JustifyContent = YogaJustify.Center;
root.AlignItems = YogaAlign.Center;
root.FlexGrow = 1;
root.Width = 110;
root.Height = 100;
YogaNode root_child0 = new YogaNode();
root_child0.PositionType = YogaPositionType.Absolute;
root_child0.Bottom = 10;
root_child0.Width = 60;
root_child0.Height = 40;
root.Insert(0, root_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(110f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(25f, root_child0.LayoutX);
Assert.AreEqual(50f, root_child0.LayoutY);
Assert.AreEqual(60f, root_child0.LayoutWidth);
Assert.AreEqual(40f, root_child0.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(110f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(25f, root_child0.LayoutX);
Assert.AreEqual(50f, root_child0.LayoutY);
Assert.AreEqual(60f, root_child0.LayoutWidth);
Assert.AreEqual(40f, root_child0.LayoutHeight);
}
[Test]
public void Test_absolute_layout_align_items_and_justify_content_center_and_left_position()
{
YogaNode root = new YogaNode();
root.JustifyContent = YogaJustify.Center;
root.AlignItems = YogaAlign.Center;
root.FlexGrow = 1;
root.Width = 110;
root.Height = 100;
YogaNode root_child0 = new YogaNode();
root_child0.PositionType = YogaPositionType.Absolute;
root_child0.Left = 5;
root_child0.Width = 60;
root_child0.Height = 40;
root.Insert(0, root_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(110f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(5f, root_child0.LayoutX);
Assert.AreEqual(30f, root_child0.LayoutY);
Assert.AreEqual(60f, root_child0.LayoutWidth);
Assert.AreEqual(40f, root_child0.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(110f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(5f, root_child0.LayoutX);
Assert.AreEqual(30f, root_child0.LayoutY);
Assert.AreEqual(60f, root_child0.LayoutWidth);
Assert.AreEqual(40f, root_child0.LayoutHeight);
}
[Test]
public void Test_absolute_layout_align_items_and_justify_content_center_and_right_position()
{
YogaNode root = new YogaNode();
root.JustifyContent = YogaJustify.Center;
root.AlignItems = YogaAlign.Center;
root.FlexGrow = 1;
root.Width = 110;
root.Height = 100;
YogaNode root_child0 = new YogaNode();
root_child0.PositionType = YogaPositionType.Absolute;
root_child0.Right = 5;
root_child0.Width = 60;
root_child0.Height = 40;
root.Insert(0, root_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(110f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(45f, root_child0.LayoutX);
Assert.AreEqual(30f, root_child0.LayoutY);
Assert.AreEqual(60f, root_child0.LayoutWidth);
Assert.AreEqual(40f, root_child0.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(110f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(45f, root_child0.LayoutX);
Assert.AreEqual(30f, root_child0.LayoutY);
Assert.AreEqual(60f, root_child0.LayoutWidth);
Assert.AreEqual(40f, root_child0.LayoutHeight);
}
}
}

View File

@@ -354,5 +354,61 @@ namespace Facebook.Yoga
Assert.AreEqual(30f, root_child3.LayoutHeight);
}
[Test]
public void Test_flex_wrap_children_with_min_main_overriding_flex_basis()
{
YogaNode root = new YogaNode();
root.FlexDirection = YogaFlexDirection.Row;
root.Wrap = YogaWrap.Wrap;
root.Width = 100;
YogaNode root_child0 = new YogaNode();
root_child0.FlexBasis = 50;
root_child0.MinWidth = 55;
root_child0.Height = 50;
root.Insert(0, root_child0);
YogaNode root_child1 = new YogaNode();
root_child1.FlexBasis = 50;
root_child1.MinWidth = 55;
root_child1.Height = 50;
root.Insert(1, root_child1);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(100f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(55f, root_child0.LayoutWidth);
Assert.AreEqual(50f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(50f, root_child1.LayoutY);
Assert.AreEqual(55f, root_child1.LayoutWidth);
Assert.AreEqual(50f, root_child1.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(100f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(45f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(55f, root_child0.LayoutWidth);
Assert.AreEqual(50f, root_child0.LayoutHeight);
Assert.AreEqual(45f, root_child1.LayoutX);
Assert.AreEqual(50f, root_child1.LayoutY);
Assert.AreEqual(55f, root_child1.LayoutWidth);
Assert.AreEqual(50f, root_child1.LayoutHeight);
}
}
}

View File

@@ -0,0 +1,177 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// @Generated by gentest/gentest.rb from gentest/fixtures/YGSizeOverflowTest.html
using System;
using NUnit.Framework;
namespace Facebook.Yoga
{
[TestFixture]
public class YGSizeOverflowTest
{
[Test]
public void Test_nested_overflowing_child()
{
YogaNode root = new YogaNode();
root.Width = 100;
root.Height = 100;
YogaNode root_child0 = new YogaNode();
root.Insert(0, root_child0);
YogaNode root_child0_child0 = new YogaNode();
root_child0_child0.Width = 200;
root_child0_child0.Height = 200;
root_child0.Insert(0, root_child0_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(100f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(200f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0.LayoutY);
Assert.AreEqual(200f, root_child0_child0.LayoutWidth);
Assert.AreEqual(200f, root_child0_child0.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(100f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(200f, root_child0.LayoutHeight);
Assert.AreEqual(-100f, root_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0.LayoutY);
Assert.AreEqual(200f, root_child0_child0.LayoutWidth);
Assert.AreEqual(200f, root_child0_child0.LayoutHeight);
}
[Test]
public void Test_nested_overflowing_child_in_constraint_parent()
{
YogaNode root = new YogaNode();
root.Width = 100;
root.Height = 100;
YogaNode root_child0 = new YogaNode();
root_child0.Width = 100;
root_child0.Height = 100;
root.Insert(0, root_child0);
YogaNode root_child0_child0 = new YogaNode();
root_child0_child0.Width = 200;
root_child0_child0.Height = 200;
root_child0.Insert(0, root_child0_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(100f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(100f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0.LayoutY);
Assert.AreEqual(200f, root_child0_child0.LayoutWidth);
Assert.AreEqual(200f, root_child0_child0.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(100f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(100f, root_child0.LayoutHeight);
Assert.AreEqual(-100f, root_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0.LayoutY);
Assert.AreEqual(200f, root_child0_child0.LayoutWidth);
Assert.AreEqual(200f, root_child0_child0.LayoutHeight);
}
[Test]
public void Test_parent_wrap_child_size_overflowing_parent()
{
YogaNode root = new YogaNode();
root.Width = 100;
root.Height = 100;
YogaNode root_child0 = new YogaNode();
root_child0.Width = 100;
root.Insert(0, root_child0);
YogaNode root_child0_child0 = new YogaNode();
root_child0_child0.Width = 100;
root_child0_child0.Height = 200;
root_child0.Insert(0, root_child0_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(100f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(200f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0.LayoutY);
Assert.AreEqual(100f, root_child0_child0.LayoutWidth);
Assert.AreEqual(200f, root_child0_child0.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(100f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(200f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0.LayoutY);
Assert.AreEqual(100f, root_child0_child0.LayoutWidth);
Assert.AreEqual(200f, root_child0_child0.LayoutHeight);
}
}
}

View File

@@ -175,7 +175,7 @@ for name, values in ENUMS.items():
f.write(' case %d: return %s;\n' % (value[1], to_java_upper(value[0])))
else:
f.write(' case %d: return %s;\n' % (values.index(value), to_java_upper(value)))
f.write(' default: throw new IllegalArgumentException("Unkown enum value: " + value);\n')
f.write(' default: throw new IllegalArgumentException("Unknown enum value: " + value);\n')
f.write(' }\n')
f.write(' }\n')
f.write('}\n')
@@ -208,5 +208,5 @@ with open(root + '/javascript/sources/YGEnums.js', 'w') as f:
else:
f.write(' %s_%s: %d,\n' % (to_java_upper(name), to_java_upper(value), base))
base += 1
f.write('\n');
f.write('\n')
f.write('};\n')

View File

@@ -24,3 +24,39 @@
<div style="position: absolute; width: 50px; height: 50px; left: 0px; top: 0px;"></div>
<div style="position: absolute; width: 50px; height: 50px; right: 0px; bottom: 0px;"></div>
</div>
<div id="absolute_layout_align_items_and_justify_content_center" style="height: 100px; width: 110px; flex-grow: 1; align-items: center; justify-content: center;">
<div style="position: absolute; width: 60px; height: 40px;"></div>
</div>
<div id="absolute_layout_align_items_and_justify_content_flex_end" style="height: 100px; width: 110px; flex-grow: 1; align-items: flex-end; justify-content: flex-end;">
<div style="position: absolute; width: 60px; height: 40px;"></div>
</div>
<div id="absolute_layout_justify_content_center" style="height: 100px; width: 110px; flex-grow: 1; justify-content: center;">
<div style="position: absolute; width: 60px; height: 40px;"></div>
</div>
<div id="absolute_layout_align_items_center" style="height: 100px; width: 110px; flex-grow: 1; align-items: center;">
<div style="position: absolute; width: 60px; height: 40px;"></div>
</div>
<div id="absolute_layout_align_items_center_on_child_only" style="height: 100px; width: 110px; flex-grow: 1;">
<div style="position: absolute; width: 60px; height: 40px;align-self: center;"></div>
</div>
<div id="absolute_layout_align_items_and_justify_content_center_and_top_position" style="height: 100px; width: 110px; flex-grow: 1; align-items: center; justify-content: center;">
<div style="position: absolute; width: 60px; height: 40px;top:10px;"></div>
</div>
<div id="absolute_layout_align_items_and_justify_content_center_and_bottom_position" style="height: 100px; width: 110px; flex-grow: 1; align-items: center; justify-content: center;">
<div style="position: absolute; width: 60px; height: 40px;bottom:10px;"></div>
</div>
<div id="absolute_layout_align_items_and_justify_content_center_and_left_position" style="height: 100px; width: 110px; flex-grow: 1; align-items: center; justify-content: center;">
<div style="position: absolute; width: 60px; height: 40px;left:5px;"></div>
</div>
<div id="absolute_layout_align_items_and_justify_content_center_and_right_position" style="height: 100px; width: 110px; flex-grow: 1; align-items: center; justify-content: center;">
<div style="position: absolute; width: 60px; height: 40px;right:5px;"></div>
</div>

View File

@@ -25,3 +25,8 @@
<div style="height: 30px; width: 30px;"></div>
<div style="height: 30px; width: 30px;"></div>
</div>
<div id="flex_wrap_children_with_min_main_overriding_flex_basis" style="width: 100px; flex-wrap: wrap; flex-direction: row;">
<div style="flex-basis: 50px; height: 50px; min-width: 55px;"></div>
<div style="flex-basis: 50px; height: 50px; min-width: 55px;"></div>
</div>

View File

@@ -45,7 +45,6 @@
<div style="flex-grow: 4; flex-basis: 15%; max-width: 20%;"></div>
</div>
<div id="percentage_flex_basis_main_min_width" experiments="Rounding" style="width: 200px; height: 200px; flex-direction: row;">
<div style="flex-grow: 1; flex-basis: 15%; min-width: 60%;"></div>
<div style="flex-grow: 4; flex-basis: 10%; min-width: 20%;"></div>
@@ -79,4 +78,4 @@
<div id="percentage_absolute_position" experiments="Rounding" style="width: 200px; height: 100px;">
<div style="position: absolute; top: 10%; left: 30%; width: 10px; height: 10px;"></div>
</div>
</div>

View File

@@ -0,0 +1,17 @@
<div id="nested_overflowing_child" style="height: 100px; width: 100px;">
<div>
<div style="height: 200px; width: 200px;"></div>
</div>
</div>
<div id="nested_overflowing_child_in_constraint_parent" style="height: 100px; width: 100px;">
<div style="height: 100px; width: 100px;">
<div style="height: 200px; width: 200px;"></div>
</div>
</div>
<div id="parent_wrap_child_size_overflowing_parent" style="width: 100px; height: 100px;">
<div style="width: 100px;">
<div style="width: 100px; height: 200px;"></div>
</div>
</div>

View File

@@ -38,7 +38,7 @@ public enum YogaAlign {
case 3: return FLEX_END;
case 4: return STRETCH;
case 5: return BASELINE;
default: throw new IllegalArgumentException("Unkown enum value: " + value);
default: throw new IllegalArgumentException("Unknown enum value: " + value);
}
}
}

View File

@@ -30,7 +30,7 @@ public enum YogaDimension {
switch (value) {
case 0: return WIDTH;
case 1: return HEIGHT;
default: throw new IllegalArgumentException("Unkown enum value: " + value);
default: throw new IllegalArgumentException("Unknown enum value: " + value);
}
}
}

View File

@@ -32,7 +32,7 @@ public enum YogaDirection {
case 0: return INHERIT;
case 1: return LTR;
case 2: return RTL;
default: throw new IllegalArgumentException("Unkown enum value: " + value);
default: throw new IllegalArgumentException("Unknown enum value: " + value);
}
}
}

View File

@@ -44,7 +44,7 @@ public enum YogaEdge {
case 6: return HORIZONTAL;
case 7: return VERTICAL;
case 8: return ALL;
default: throw new IllegalArgumentException("Unkown enum value: " + value);
default: throw new IllegalArgumentException("Unknown enum value: " + value);
}
}
}

View File

@@ -30,7 +30,7 @@ public enum YogaExperimentalFeature {
switch (value) {
case 0: return ROUNDING;
case 1: return WEB_FLEX_BASIS;
default: throw new IllegalArgumentException("Unkown enum value: " + value);
default: throw new IllegalArgumentException("Unknown enum value: " + value);
}
}
}

View File

@@ -34,7 +34,7 @@ public enum YogaFlexDirection {
case 1: return COLUMN_REVERSE;
case 2: return ROW;
case 3: return ROW_REVERSE;
default: throw new IllegalArgumentException("Unkown enum value: " + value);
default: throw new IllegalArgumentException("Unknown enum value: " + value);
}
}
}

View File

@@ -36,7 +36,7 @@ public enum YogaJustify {
case 2: return FLEX_END;
case 3: return SPACE_BETWEEN;
case 4: return SPACE_AROUND;
default: throw new IllegalArgumentException("Unkown enum value: " + value);
default: throw new IllegalArgumentException("Unknown enum value: " + value);
}
}
}

View File

@@ -36,7 +36,7 @@ public enum YogaLogLevel {
case 2: return INFO;
case 3: return DEBUG;
case 4: return VERBOSE;
default: throw new IllegalArgumentException("Unkown enum value: " + value);
default: throw new IllegalArgumentException("Unknown enum value: " + value);
}
}
}

View File

@@ -32,7 +32,7 @@ public enum YogaMeasureMode {
case 0: return UNDEFINED;
case 1: return EXACTLY;
case 2: return AT_MOST;
default: throw new IllegalArgumentException("Unkown enum value: " + value);
default: throw new IllegalArgumentException("Unknown enum value: " + value);
}
}
}

View File

@@ -32,7 +32,7 @@ public enum YogaOverflow {
case 0: return VISIBLE;
case 1: return HIDDEN;
case 2: return SCROLL;
default: throw new IllegalArgumentException("Unkown enum value: " + value);
default: throw new IllegalArgumentException("Unknown enum value: " + value);
}
}
}

View File

@@ -30,7 +30,7 @@ public enum YogaPositionType {
switch (value) {
case 0: return RELATIVE;
case 1: return ABSOLUTE;
default: throw new IllegalArgumentException("Unkown enum value: " + value);
default: throw new IllegalArgumentException("Unknown enum value: " + value);
}
}
}

View File

@@ -32,7 +32,7 @@ public enum YogaPrintOptions {
case 1: return LAYOUT;
case 2: return STYLE;
case 4: return CHILDREN;
default: throw new IllegalArgumentException("Unkown enum value: " + value);
default: throw new IllegalArgumentException("Unknown enum value: " + value);
}
}
}

View File

@@ -32,7 +32,7 @@ public enum YogaUnit {
case 0: return UNDEFINED;
case 1: return PIXEL;
case 2: return PERCENT;
default: throw new IllegalArgumentException("Unkown enum value: " + value);
default: throw new IllegalArgumentException("Unknown enum value: " + value);
}
}
}

View File

@@ -30,7 +30,7 @@ public enum YogaWrap {
switch (value) {
case 0: return NO_WRAP;
case 1: return WRAP;
default: throw new IllegalArgumentException("Unkown enum value: " + value);
default: throw new IllegalArgumentException("Unknown enum value: " + value);
}
}
}

View File

@@ -75,7 +75,9 @@ static void YGPrint(YGNodeRef node) {
static float YGJNIBaselineFunc(YGNodeRef node, float width, float height) {
if (auto obj = YGNodeJobject(node)->lockLocal()) {
return findClassLocal("com/facebook/yoga/YogaNode")->getMethod<jfloat(jfloat, jfloat)>("baseline")(obj, width, height);
static auto baselineFunc = findClassStatic("com/facebook/yoga/YogaNode")
->getMethod<jfloat(jfloat, jfloat)>("baseline");
return baselineFunc(obj, width, height);
} else {
return height;
}
@@ -87,7 +89,7 @@ static YGSize YGJNIMeasureFunc(YGNodeRef node,
float height,
YGMeasureMode heightMode) {
if (auto obj = YGNodeJobject(node)->lockLocal()) {
static auto measureFunc = findClassLocal("com/facebook/yoga/YogaNode")
static auto measureFunc = findClassStatic("com/facebook/yoga/YogaNode")
->getMethod<jlong(jfloat, jint, jfloat, jint)>("measure");
YGTransferLayoutDirection(node, obj);
@@ -121,7 +123,7 @@ static int YGLog(YGLogLevel level, const char *format, va_list args) {
char buffer[256];
int result = vsnprintf(buffer, sizeof(buffer), format, args);
static auto logFunc = findClassLocal("com/facebook/yoga/YogaLogger")
static auto logFunc = findClassStatic("com/facebook/yoga/YogaLogger")
->getMethod<void(local_ref<JYogaLogLevel>, jstring)>("log");
static auto logLevelFromInt =
@@ -221,8 +223,11 @@ void jni_YGNodeSetHasMeasureFunc(alias_ref<jobject>, jlong nativePointer, jboole
YGNodeSetMeasureFunc(_jlong2YGNodeRef(nativePointer), hasMeasureFunc ? YGJNIMeasureFunc : NULL);
}
void jni_YGNodeSetHasBaselineFunc(alias_ref<jobject>, jlong nativePointer, jboolean hasBaselineFunc) {
YGNodeSetBaselineFunc(_jlong2YGNodeRef(nativePointer), hasBaselineFunc ? YGJNIBaselineFunc : NULL);
void jni_YGNodeSetHasBaselineFunc(alias_ref<jobject>,
jlong nativePointer,
jboolean hasBaselineFunc) {
YGNodeSetBaselineFunc(_jlong2YGNodeRef(nativePointer),
hasBaselineFunc ? YGJNIBaselineFunc : NULL);
}
jboolean jni_YGNodeHasNewLayout(alias_ref<jobject>, jlong nativePointer) {

View File

@@ -303,4 +303,374 @@ public class YGAbsolutePositionTest {
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
}
@Test
public void test_absolute_layout_align_items_and_justify_content_center() {
final YogaNode root = new YogaNode();
root.setJustifyContent(YogaJustify.CENTER);
root.setAlignItems(YogaAlign.CENTER);
root.setFlexGrow(1f);
root.setWidth(110f);
root.setHeight(100f);
final YogaNode root_child0 = new YogaNode();
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
root_child0.setWidth(60f);
root_child0.setHeight(40f);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout();
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(110f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(25f, root_child0.getLayoutX(), 0.0f);
assertEquals(30f, root_child0.getLayoutY(), 0.0f);
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout();
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(110f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(25f, root_child0.getLayoutX(), 0.0f);
assertEquals(30f, root_child0.getLayoutY(), 0.0f);
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_absolute_layout_align_items_and_justify_content_flex_end() {
final YogaNode root = new YogaNode();
root.setJustifyContent(YogaJustify.FLEX_END);
root.setAlignItems(YogaAlign.FLEX_END);
root.setFlexGrow(1f);
root.setWidth(110f);
root.setHeight(100f);
final YogaNode root_child0 = new YogaNode();
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
root_child0.setWidth(60f);
root_child0.setHeight(40f);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout();
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(110f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(50f, root_child0.getLayoutX(), 0.0f);
assertEquals(60f, root_child0.getLayoutY(), 0.0f);
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout();
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(110f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(60f, root_child0.getLayoutY(), 0.0f);
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_absolute_layout_justify_content_center() {
final YogaNode root = new YogaNode();
root.setJustifyContent(YogaJustify.CENTER);
root.setFlexGrow(1f);
root.setWidth(110f);
root.setHeight(100f);
final YogaNode root_child0 = new YogaNode();
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
root_child0.setWidth(60f);
root_child0.setHeight(40f);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout();
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(110f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(30f, root_child0.getLayoutY(), 0.0f);
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout();
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(110f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(50f, root_child0.getLayoutX(), 0.0f);
assertEquals(30f, root_child0.getLayoutY(), 0.0f);
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_absolute_layout_align_items_center() {
final YogaNode root = new YogaNode();
root.setAlignItems(YogaAlign.CENTER);
root.setFlexGrow(1f);
root.setWidth(110f);
root.setHeight(100f);
final YogaNode root_child0 = new YogaNode();
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
root_child0.setWidth(60f);
root_child0.setHeight(40f);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout();
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(110f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(25f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout();
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(110f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(25f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_absolute_layout_align_items_center_on_child_only() {
final YogaNode root = new YogaNode();
root.setFlexGrow(1f);
root.setWidth(110f);
root.setHeight(100f);
final YogaNode root_child0 = new YogaNode();
root_child0.setAlignSelf(YogaAlign.CENTER);
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
root_child0.setWidth(60f);
root_child0.setHeight(40f);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout();
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(110f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(25f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout();
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(110f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(25f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_absolute_layout_align_items_and_justify_content_center_and_top_position() {
final YogaNode root = new YogaNode();
root.setJustifyContent(YogaJustify.CENTER);
root.setAlignItems(YogaAlign.CENTER);
root.setFlexGrow(1f);
root.setWidth(110f);
root.setHeight(100f);
final YogaNode root_child0 = new YogaNode();
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
root_child0.setPosition(YogaEdge.TOP, 10f);
root_child0.setWidth(60f);
root_child0.setHeight(40f);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout();
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(110f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(25f, root_child0.getLayoutX(), 0.0f);
assertEquals(10f, root_child0.getLayoutY(), 0.0f);
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout();
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(110f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(25f, root_child0.getLayoutX(), 0.0f);
assertEquals(10f, root_child0.getLayoutY(), 0.0f);
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_absolute_layout_align_items_and_justify_content_center_and_bottom_position() {
final YogaNode root = new YogaNode();
root.setJustifyContent(YogaJustify.CENTER);
root.setAlignItems(YogaAlign.CENTER);
root.setFlexGrow(1f);
root.setWidth(110f);
root.setHeight(100f);
final YogaNode root_child0 = new YogaNode();
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
root_child0.setPosition(YogaEdge.BOTTOM, 10f);
root_child0.setWidth(60f);
root_child0.setHeight(40f);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout();
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(110f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(25f, root_child0.getLayoutX(), 0.0f);
assertEquals(50f, root_child0.getLayoutY(), 0.0f);
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout();
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(110f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(25f, root_child0.getLayoutX(), 0.0f);
assertEquals(50f, root_child0.getLayoutY(), 0.0f);
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_absolute_layout_align_items_and_justify_content_center_and_left_position() {
final YogaNode root = new YogaNode();
root.setJustifyContent(YogaJustify.CENTER);
root.setAlignItems(YogaAlign.CENTER);
root.setFlexGrow(1f);
root.setWidth(110f);
root.setHeight(100f);
final YogaNode root_child0 = new YogaNode();
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
root_child0.setPosition(YogaEdge.LEFT, 5f);
root_child0.setWidth(60f);
root_child0.setHeight(40f);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout();
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(110f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(5f, root_child0.getLayoutX(), 0.0f);
assertEquals(30f, root_child0.getLayoutY(), 0.0f);
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout();
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(110f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(5f, root_child0.getLayoutX(), 0.0f);
assertEquals(30f, root_child0.getLayoutY(), 0.0f);
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_absolute_layout_align_items_and_justify_content_center_and_right_position() {
final YogaNode root = new YogaNode();
root.setJustifyContent(YogaJustify.CENTER);
root.setAlignItems(YogaAlign.CENTER);
root.setFlexGrow(1f);
root.setWidth(110f);
root.setHeight(100f);
final YogaNode root_child0 = new YogaNode();
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
root_child0.setPosition(YogaEdge.RIGHT, 5f);
root_child0.setWidth(60f);
root_child0.setHeight(40f);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout();
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(110f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(45f, root_child0.getLayoutX(), 0.0f);
assertEquals(30f, root_child0.getLayoutY(), 0.0f);
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout();
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(110f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(45f, root_child0.getLayoutX(), 0.0f);
assertEquals(30f, root_child0.getLayoutY(), 0.0f);
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
}
}

View File

@@ -349,4 +349,59 @@ public class YGFlexWrapTest {
assertEquals(30f, root_child3.getLayoutHeight(), 0.0f);
}
@Test
public void test_flex_wrap_children_with_min_main_overriding_flex_basis() {
final YogaNode root = new YogaNode();
root.setFlexDirection(YogaFlexDirection.ROW);
root.setWrap(YogaWrap.WRAP);
root.setWidth(100f);
final YogaNode root_child0 = new YogaNode();
root_child0.setFlexBasis(50f);
root_child0.setMinWidth(55f);
root_child0.setHeight(50f);
root.addChildAt(root_child0, 0);
final YogaNode root_child1 = new YogaNode();
root_child1.setFlexBasis(50f);
root_child1.setMinWidth(55f);
root_child1.setHeight(50f);
root.addChildAt(root_child1, 1);
root.setDirection(YogaDirection.LTR);
root.calculateLayout();
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(55f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
assertEquals(50f, root_child1.getLayoutY(), 0.0f);
assertEquals(55f, root_child1.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout();
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(45f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(55f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(45f, root_child1.getLayoutX(), 0.0f);
assertEquals(50f, root_child1.getLayoutY(), 0.0f);
assertEquals(55f, root_child1.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
}
}

View File

@@ -0,0 +1,172 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// @Generated by gentest/gentest.rb from gentest/fixtures/YGSizeOverflowTest.html
package com.facebook.yoga;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class YGSizeOverflowTest {
@Test
public void test_nested_overflowing_child() {
final YogaNode root = new YogaNode();
root.setWidth(100f);
root.setHeight(100f);
final YogaNode root_child0 = new YogaNode();
root.addChildAt(root_child0, 0);
final YogaNode root_child0_child0 = new YogaNode();
root_child0_child0.setWidth(200f);
root_child0_child0.setHeight(200f);
root_child0.addChildAt(root_child0_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout();
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(200f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(200f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(200f, root_child0_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout();
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(200f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(-100f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(200f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(200f, root_child0_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_nested_overflowing_child_in_constraint_parent() {
final YogaNode root = new YogaNode();
root.setWidth(100f);
root.setHeight(100f);
final YogaNode root_child0 = new YogaNode();
root_child0.setWidth(100f);
root_child0.setHeight(100f);
root.addChildAt(root_child0, 0);
final YogaNode root_child0_child0 = new YogaNode();
root_child0_child0.setWidth(200f);
root_child0_child0.setHeight(200f);
root_child0.addChildAt(root_child0_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout();
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(100f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(200f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(200f, root_child0_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout();
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(100f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(-100f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(200f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(200f, root_child0_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_parent_wrap_child_size_overflowing_parent() {
final YogaNode root = new YogaNode();
root.setWidth(100f);
root.setHeight(100f);
final YogaNode root_child0 = new YogaNode();
root_child0.setWidth(100f);
root.addChildAt(root_child0, 0);
final YogaNode root_child0_child0 = new YogaNode();
root_child0_child0.setWidth(100f);
root_child0_child0.setHeight(200f);
root_child0.addChildAt(root_child0_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout();
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(200f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(100f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(200f, root_child0_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout();
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(200f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(100f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(200f, root_child0_child0.getLayoutHeight(), 0.0f);
}
}

File diff suppressed because one or more lines are too long

View File

@@ -459,6 +459,11 @@ double Node::getComputedMargin(int edge) const
return YGNodeLayoutGetMargin(m_node, static_cast<YGEdge>(edge));
}
double Node::getComputedBorder(int edge) const
{
return YGNodeLayoutGetBorder(m_node, static_cast<YGEdge>(edge));
}
double Node::getComputedPadding(int edge) const
{
return YGNodeLayoutGetPadding(m_node, static_cast<YGEdge>(edge));

View File

@@ -177,6 +177,7 @@ class Node {
Layout getComputedLayout(void) const;
double getComputedMargin(int edge) const;
double getComputedBorder(int edge) const;
double getComputedPadding(int edge) const;
private:

View File

@@ -155,5 +155,6 @@ NBIND_CLASS(Node)
method(getComputedLayout);
method(getComputedMargin);
method(getComputedBorder);
method(getComputedPadding);
}

View File

@@ -310,3 +310,391 @@ it("absolute_layout_within_border", function () {
(typeof gc !== "undefined") && gc();
console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")");
});
it("absolute_layout_align_items_and_justify_content_center", function () {
var root = Yoga.Node.create();
root.setJustifyContent(Yoga.JUSTIFY_CENTER);
root.setAlignItems(Yoga.ALIGN_CENTER);
root.setFlexGrow(1);
root.setWidth(110);
root.setHeight(100);
var root_child0 = Yoga.Node.create();
root_child0.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE);
root_child0.setWidth(60);
root_child0.setHeight(40);
root.insertChild(root_child0, 0);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(110 === root.getComputedWidth(), "110 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(25 === root_child0.getComputedLeft(), "25 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(30 === root_child0.getComputedTop(), "30 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(60 === root_child0.getComputedWidth(), "60 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(40 === root_child0.getComputedHeight(), "40 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(110 === root.getComputedWidth(), "110 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(25 === root_child0.getComputedLeft(), "25 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(30 === root_child0.getComputedTop(), "30 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(60 === root_child0.getComputedWidth(), "60 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(40 === root_child0.getComputedHeight(), "40 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
if (typeof root !== "undefined")
root.freeRecursive();
(typeof gc !== "undefined") && gc();
console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")");
});
it("absolute_layout_align_items_and_justify_content_flex_end", function () {
var root = Yoga.Node.create();
root.setJustifyContent(Yoga.JUSTIFY_FLEX_END);
root.setAlignItems(Yoga.ALIGN_FLEX_END);
root.setFlexGrow(1);
root.setWidth(110);
root.setHeight(100);
var root_child0 = Yoga.Node.create();
root_child0.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE);
root_child0.setWidth(60);
root_child0.setHeight(40);
root.insertChild(root_child0, 0);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(110 === root.getComputedWidth(), "110 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(50 === root_child0.getComputedLeft(), "50 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(60 === root_child0.getComputedTop(), "60 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(60 === root_child0.getComputedWidth(), "60 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(40 === root_child0.getComputedHeight(), "40 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(110 === root.getComputedWidth(), "110 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(60 === root_child0.getComputedTop(), "60 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(60 === root_child0.getComputedWidth(), "60 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(40 === root_child0.getComputedHeight(), "40 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
if (typeof root !== "undefined")
root.freeRecursive();
(typeof gc !== "undefined") && gc();
console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")");
});
it("absolute_layout_justify_content_center", function () {
var root = Yoga.Node.create();
root.setJustifyContent(Yoga.JUSTIFY_CENTER);
root.setFlexGrow(1);
root.setWidth(110);
root.setHeight(100);
var root_child0 = Yoga.Node.create();
root_child0.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE);
root_child0.setWidth(60);
root_child0.setHeight(40);
root.insertChild(root_child0, 0);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(110 === root.getComputedWidth(), "110 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(30 === root_child0.getComputedTop(), "30 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(60 === root_child0.getComputedWidth(), "60 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(40 === root_child0.getComputedHeight(), "40 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(110 === root.getComputedWidth(), "110 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(50 === root_child0.getComputedLeft(), "50 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(30 === root_child0.getComputedTop(), "30 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(60 === root_child0.getComputedWidth(), "60 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(40 === root_child0.getComputedHeight(), "40 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
if (typeof root !== "undefined")
root.freeRecursive();
(typeof gc !== "undefined") && gc();
console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")");
});
it("absolute_layout_align_items_center", function () {
var root = Yoga.Node.create();
root.setAlignItems(Yoga.ALIGN_CENTER);
root.setFlexGrow(1);
root.setWidth(110);
root.setHeight(100);
var root_child0 = Yoga.Node.create();
root_child0.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE);
root_child0.setWidth(60);
root_child0.setHeight(40);
root.insertChild(root_child0, 0);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(110 === root.getComputedWidth(), "110 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(25 === root_child0.getComputedLeft(), "25 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(60 === root_child0.getComputedWidth(), "60 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(40 === root_child0.getComputedHeight(), "40 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(110 === root.getComputedWidth(), "110 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(25 === root_child0.getComputedLeft(), "25 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(60 === root_child0.getComputedWidth(), "60 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(40 === root_child0.getComputedHeight(), "40 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
if (typeof root !== "undefined")
root.freeRecursive();
(typeof gc !== "undefined") && gc();
console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")");
});
it("absolute_layout_align_items_center_on_child_only", function () {
var root = Yoga.Node.create();
root.setFlexGrow(1);
root.setWidth(110);
root.setHeight(100);
var root_child0 = Yoga.Node.create();
root_child0.setAlignSelf(Yoga.ALIGN_CENTER);
root_child0.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE);
root_child0.setWidth(60);
root_child0.setHeight(40);
root.insertChild(root_child0, 0);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(110 === root.getComputedWidth(), "110 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(25 === root_child0.getComputedLeft(), "25 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(60 === root_child0.getComputedWidth(), "60 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(40 === root_child0.getComputedHeight(), "40 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(110 === root.getComputedWidth(), "110 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(25 === root_child0.getComputedLeft(), "25 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(60 === root_child0.getComputedWidth(), "60 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(40 === root_child0.getComputedHeight(), "40 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
if (typeof root !== "undefined")
root.freeRecursive();
(typeof gc !== "undefined") && gc();
console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")");
});
it("absolute_layout_align_items_and_justify_content_center_and_top_position", function () {
var root = Yoga.Node.create();
root.setJustifyContent(Yoga.JUSTIFY_CENTER);
root.setAlignItems(Yoga.ALIGN_CENTER);
root.setFlexGrow(1);
root.setWidth(110);
root.setHeight(100);
var root_child0 = Yoga.Node.create();
root_child0.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE);
root_child0.setPosition(Yoga.EDGE_TOP, 10);
root_child0.setWidth(60);
root_child0.setHeight(40);
root.insertChild(root_child0, 0);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(110 === root.getComputedWidth(), "110 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(25 === root_child0.getComputedLeft(), "25 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(10 === root_child0.getComputedTop(), "10 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(60 === root_child0.getComputedWidth(), "60 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(40 === root_child0.getComputedHeight(), "40 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(110 === root.getComputedWidth(), "110 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(25 === root_child0.getComputedLeft(), "25 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(10 === root_child0.getComputedTop(), "10 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(60 === root_child0.getComputedWidth(), "60 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(40 === root_child0.getComputedHeight(), "40 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
if (typeof root !== "undefined")
root.freeRecursive();
(typeof gc !== "undefined") && gc();
console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")");
});
it("absolute_layout_align_items_and_justify_content_center_and_bottom_position", function () {
var root = Yoga.Node.create();
root.setJustifyContent(Yoga.JUSTIFY_CENTER);
root.setAlignItems(Yoga.ALIGN_CENTER);
root.setFlexGrow(1);
root.setWidth(110);
root.setHeight(100);
var root_child0 = Yoga.Node.create();
root_child0.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE);
root_child0.setPosition(Yoga.EDGE_BOTTOM, 10);
root_child0.setWidth(60);
root_child0.setHeight(40);
root.insertChild(root_child0, 0);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(110 === root.getComputedWidth(), "110 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(25 === root_child0.getComputedLeft(), "25 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(50 === root_child0.getComputedTop(), "50 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(60 === root_child0.getComputedWidth(), "60 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(40 === root_child0.getComputedHeight(), "40 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(110 === root.getComputedWidth(), "110 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(25 === root_child0.getComputedLeft(), "25 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(50 === root_child0.getComputedTop(), "50 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(60 === root_child0.getComputedWidth(), "60 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(40 === root_child0.getComputedHeight(), "40 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
if (typeof root !== "undefined")
root.freeRecursive();
(typeof gc !== "undefined") && gc();
console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")");
});
it("absolute_layout_align_items_and_justify_content_center_and_left_position", function () {
var root = Yoga.Node.create();
root.setJustifyContent(Yoga.JUSTIFY_CENTER);
root.setAlignItems(Yoga.ALIGN_CENTER);
root.setFlexGrow(1);
root.setWidth(110);
root.setHeight(100);
var root_child0 = Yoga.Node.create();
root_child0.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE);
root_child0.setPosition(Yoga.EDGE_LEFT, 5);
root_child0.setWidth(60);
root_child0.setHeight(40);
root.insertChild(root_child0, 0);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(110 === root.getComputedWidth(), "110 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(5 === root_child0.getComputedLeft(), "5 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(30 === root_child0.getComputedTop(), "30 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(60 === root_child0.getComputedWidth(), "60 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(40 === root_child0.getComputedHeight(), "40 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(110 === root.getComputedWidth(), "110 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(5 === root_child0.getComputedLeft(), "5 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(30 === root_child0.getComputedTop(), "30 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(60 === root_child0.getComputedWidth(), "60 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(40 === root_child0.getComputedHeight(), "40 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
if (typeof root !== "undefined")
root.freeRecursive();
(typeof gc !== "undefined") && gc();
console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")");
});
it("absolute_layout_align_items_and_justify_content_center_and_right_position", function () {
var root = Yoga.Node.create();
root.setJustifyContent(Yoga.JUSTIFY_CENTER);
root.setAlignItems(Yoga.ALIGN_CENTER);
root.setFlexGrow(1);
root.setWidth(110);
root.setHeight(100);
var root_child0 = Yoga.Node.create();
root_child0.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE);
root_child0.setPosition(Yoga.EDGE_RIGHT, 5);
root_child0.setWidth(60);
root_child0.setHeight(40);
root.insertChild(root_child0, 0);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(110 === root.getComputedWidth(), "110 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(45 === root_child0.getComputedLeft(), "45 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(30 === root_child0.getComputedTop(), "30 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(60 === root_child0.getComputedWidth(), "60 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(40 === root_child0.getComputedHeight(), "40 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(110 === root.getComputedWidth(), "110 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(45 === root_child0.getComputedLeft(), "45 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(30 === root_child0.getComputedTop(), "30 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(60 === root_child0.getComputedWidth(), "60 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(40 === root_child0.getComputedHeight(), "40 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
if (typeof root !== "undefined")
root.freeRecursive();
(typeof gc !== "undefined") && gc();
console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")");
});

File diff suppressed because it is too large Load Diff

View File

@@ -172,3 +172,75 @@ it("align_self_flex_end_override_flex_start", function () {
(typeof gc !== "undefined") && gc();
console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")");
});
it("align_self_baseline", function () {
var root = Yoga.Node.create();
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
root.setWidth(100);
root.setHeight(100);
var root_child0 = Yoga.Node.create();
root_child0.setAlignSelf(Yoga.ALIGN_BASELINE);
root_child0.setWidth(50);
root_child0.setHeight(50);
root.insertChild(root_child0, 0);
var root_child1 = Yoga.Node.create();
root_child1.setAlignSelf(Yoga.ALIGN_BASELINE);
root_child1.setWidth(50);
root_child1.setHeight(20);
root.insertChild(root_child1, 1);
var root_child1_child0 = Yoga.Node.create();
root_child1_child0.setWidth(50);
root_child1_child0.setHeight(10);
root_child1.insertChild(root_child1_child0, 0);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(50 === root_child0.getComputedHeight(), "50 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(50 === root_child1.getComputedLeft(), "50 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
console.assert(40 === root_child1.getComputedTop(), "40 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")");
console.assert(20 === root_child1.getComputedHeight(), "20 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
console.assert(0 === root_child1_child0.getComputedLeft(), "0 === root_child1_child0.getComputedLeft() (" + root_child1_child0.getComputedLeft() + ")");
console.assert(0 === root_child1_child0.getComputedTop(), "0 === root_child1_child0.getComputedTop() (" + root_child1_child0.getComputedTop() + ")");
console.assert(50 === root_child1_child0.getComputedWidth(), "50 === root_child1_child0.getComputedWidth() (" + root_child1_child0.getComputedWidth() + ")");
console.assert(10 === root_child1_child0.getComputedHeight(), "10 === root_child1_child0.getComputedHeight() (" + root_child1_child0.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(50 === root_child0.getComputedLeft(), "50 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(50 === root_child0.getComputedWidth(), "50 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(50 === root_child0.getComputedHeight(), "50 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(0 === root_child1.getComputedLeft(), "0 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
console.assert(40 === root_child1.getComputedTop(), "40 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")");
console.assert(20 === root_child1.getComputedHeight(), "20 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
console.assert(0 === root_child1_child0.getComputedLeft(), "0 === root_child1_child0.getComputedLeft() (" + root_child1_child0.getComputedLeft() + ")");
console.assert(0 === root_child1_child0.getComputedTop(), "0 === root_child1_child0.getComputedTop() (" + root_child1_child0.getComputedTop() + ")");
console.assert(50 === root_child1_child0.getComputedWidth(), "50 === root_child1_child0.getComputedWidth() (" + root_child1_child0.getComputedWidth() + ")");
console.assert(10 === root_child1_child0.getComputedHeight(), "10 === root_child1_child0.getComputedHeight() (" + root_child1_child0.getComputedHeight() + ")");
if (typeof root !== "undefined")
root.freeRecursive();
(typeof gc !== "undefined") && gc();
console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")");
});

View File

@@ -0,0 +1,33 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
var Yoga = Yoga || require("../../sources/entry-" + process.env.TEST_ENTRY);
it("border_start", function () {
var root = Yoga.Node.create();
root.setWidth(100);
root.setHeight(100);
root.setBorder(Yoga.EDGE_START, 10);
root.calculateLayout(100, 100, Yoga.DIRECTION_LTR);
console.assert(10 === root.getComputedBorder(Yoga.EDGE_LEFT), "10 === root.getComputedBorder(Yoga.EDGE_LEFT)");
console.assert(0 === root.getComputedBorder(Yoga.EDGE_RIGHT), "0 === root.getComputedBorder(Yoga.EDGE_RIGHT)");
root.calculateLayout(100, 100, Yoga.DIRECTION_RTL);
console.assert(0 === root.getComputedBorder(Yoga.EDGE_LEFT), "0 === root.getComputedBorder(Yoga.EDGE_LEFT)");
console.assert(10 === root.getComputedBorder(Yoga.EDGE_RIGHT), "10 === root.getComputedBorder(Yoga.EDGE_RIGHT)");
if (typeof root !== "undefined")
root.freeRecursive();
(typeof gc !== "undefined") && gc();
console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")");
});

View File

@@ -352,3 +352,60 @@ it("wrap_row_align_items_center", function () {
(typeof gc !== "undefined") && gc();
console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")");
});
it("flex_wrap_children_with_min_main_overriding_flex_basis", function () {
var root = Yoga.Node.create();
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
root.setFlexWrap(Yoga.WRAP_WRAP);
root.setWidth(100);
var root_child0 = Yoga.Node.create();
root_child0.setFlexBasis(50);
root_child0.setMinWidth(55);
root_child0.setHeight(50);
root.insertChild(root_child0, 0);
var root_child1 = Yoga.Node.create();
root_child1.setFlexBasis(50);
root_child1.setMinWidth(55);
root_child1.setHeight(50);
root.insertChild(root_child1, 1);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(55 === root_child0.getComputedWidth(), "55 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(50 === root_child0.getComputedHeight(), "50 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(0 === root_child1.getComputedLeft(), "0 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
console.assert(50 === root_child1.getComputedTop(), "50 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
console.assert(55 === root_child1.getComputedWidth(), "55 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")");
console.assert(50 === root_child1.getComputedHeight(), "50 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(45 === root_child0.getComputedLeft(), "45 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(55 === root_child0.getComputedWidth(), "55 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(50 === root_child0.getComputedHeight(), "50 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(45 === root_child1.getComputedLeft(), "45 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
console.assert(50 === root_child1.getComputedTop(), "50 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
console.assert(55 === root_child1.getComputedWidth(), "55 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")");
console.assert(50 === root_child1.getComputedHeight(), "50 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
if (typeof root !== "undefined")
root.freeRecursive();
(typeof gc !== "undefined") && gc();
console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")");
});

View File

@@ -0,0 +1,172 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// @Generated by gentest/gentest.rb from gentest/fixtures/YGSizeOverflowTest.html
var Yoga = Yoga || require("../../sources/entry-" + process.env.TEST_ENTRY);
it("nested_overflowing_child", function () {
var root = Yoga.Node.create();
root.setWidth(100);
root.setHeight(100);
var root_child0 = Yoga.Node.create();
root.insertChild(root_child0, 0);
var root_child0_child0 = Yoga.Node.create();
root_child0_child0.setWidth(200);
root_child0_child0.setHeight(200);
root_child0.insertChild(root_child0_child0, 0);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(100 === root_child0.getComputedWidth(), "100 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(200 === root_child0.getComputedHeight(), "200 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(0 === root_child0_child0.getComputedLeft(), "0 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")");
console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")");
console.assert(200 === root_child0_child0.getComputedWidth(), "200 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")");
console.assert(200 === root_child0_child0.getComputedHeight(), "200 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(100 === root_child0.getComputedWidth(), "100 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(200 === root_child0.getComputedHeight(), "200 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(-100 === root_child0_child0.getComputedLeft(), "-100 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")");
console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")");
console.assert(200 === root_child0_child0.getComputedWidth(), "200 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")");
console.assert(200 === root_child0_child0.getComputedHeight(), "200 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")");
if (typeof root !== "undefined")
root.freeRecursive();
(typeof gc !== "undefined") && gc();
console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")");
});
it("nested_overflowing_child_in_constraint_parent", function () {
var root = Yoga.Node.create();
root.setWidth(100);
root.setHeight(100);
var root_child0 = Yoga.Node.create();
root_child0.setWidth(100);
root_child0.setHeight(100);
root.insertChild(root_child0, 0);
var root_child0_child0 = Yoga.Node.create();
root_child0_child0.setWidth(200);
root_child0_child0.setHeight(200);
root_child0.insertChild(root_child0_child0, 0);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(100 === root_child0.getComputedWidth(), "100 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(100 === root_child0.getComputedHeight(), "100 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(0 === root_child0_child0.getComputedLeft(), "0 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")");
console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")");
console.assert(200 === root_child0_child0.getComputedWidth(), "200 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")");
console.assert(200 === root_child0_child0.getComputedHeight(), "200 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(100 === root_child0.getComputedWidth(), "100 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(100 === root_child0.getComputedHeight(), "100 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(-100 === root_child0_child0.getComputedLeft(), "-100 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")");
console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")");
console.assert(200 === root_child0_child0.getComputedWidth(), "200 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")");
console.assert(200 === root_child0_child0.getComputedHeight(), "200 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")");
if (typeof root !== "undefined")
root.freeRecursive();
(typeof gc !== "undefined") && gc();
console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")");
});
it("parent_wrap_child_size_overflowing_parent", function () {
var root = Yoga.Node.create();
root.setWidth(100);
root.setHeight(100);
var root_child0 = Yoga.Node.create();
root_child0.setWidth(100);
root.insertChild(root_child0, 0);
var root_child0_child0 = Yoga.Node.create();
root_child0_child0.setWidth(100);
root_child0_child0.setHeight(200);
root_child0.insertChild(root_child0_child0, 0);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(100 === root_child0.getComputedWidth(), "100 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(200 === root_child0.getComputedHeight(), "200 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(0 === root_child0_child0.getComputedLeft(), "0 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")");
console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")");
console.assert(100 === root_child0_child0.getComputedWidth(), "100 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")");
console.assert(200 === root_child0_child0.getComputedHeight(), "200 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(100 === root_child0.getComputedWidth(), "100 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(200 === root_child0.getComputedHeight(), "200 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(0 === root_child0_child0.getComputedLeft(), "0 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")");
console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")");
console.assert(100 === root_child0_child0.getComputedWidth(), "100 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")");
console.assert(200 === root_child0_child0.getComputedHeight(), "200 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")");
if (typeof root !== "undefined")
root.freeRecursive();
(typeof gc !== "undefined") && gc();
console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")");
});

View File

@@ -292,3 +292,364 @@ TEST(YogaTest, absolute_layout_within_border) {
YGNodeFreeRecursive(root);
}
TEST(YogaTest, absolute_layout_align_items_and_justify_content_center) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetJustifyContent(root, YGJustifyCenter);
YGNodeStyleSetAlignItems(root, YGAlignCenter);
YGNodeStyleSetFlexGrow(root, 1);
YGNodeStyleSetWidth(root, 110);
YGNodeStyleSetHeight(root, 100);
const YGNodeRef root_child0 = YGNodeNew();
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);
}
TEST(YogaTest, absolute_layout_align_items_and_justify_content_flex_end) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetJustifyContent(root, YGJustifyFlexEnd);
YGNodeStyleSetAlignItems(root, YGAlignFlexEnd);
YGNodeStyleSetFlexGrow(root, 1);
YGNodeStyleSetWidth(root, 110);
YGNodeStyleSetHeight(root, 100);
const YGNodeRef root_child0 = YGNodeNew();
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);
}
TEST(YogaTest, absolute_layout_justify_content_center) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetJustifyContent(root, YGJustifyCenter);
YGNodeStyleSetFlexGrow(root, 1);
YGNodeStyleSetWidth(root, 110);
YGNodeStyleSetHeight(root, 100);
const YGNodeRef root_child0 = YGNodeNew();
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);
}
TEST(YogaTest, absolute_layout_align_items_center) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetAlignItems(root, YGAlignCenter);
YGNodeStyleSetFlexGrow(root, 1);
YGNodeStyleSetWidth(root, 110);
YGNodeStyleSetHeight(root, 100);
const YGNodeRef root_child0 = YGNodeNew();
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);
}
TEST(YogaTest, absolute_layout_align_items_center_on_child_only) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetFlexGrow(root, 1);
YGNodeStyleSetWidth(root, 110);
YGNodeStyleSetHeight(root, 100);
const YGNodeRef root_child0 = YGNodeNew();
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);
}
TEST(YogaTest, absolute_layout_align_items_and_justify_content_center_and_top_position) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetJustifyContent(root, YGJustifyCenter);
YGNodeStyleSetAlignItems(root, YGAlignCenter);
YGNodeStyleSetFlexGrow(root, 1);
YGNodeStyleSetWidth(root, 110);
YGNodeStyleSetHeight(root, 100);
const YGNodeRef root_child0 = YGNodeNew();
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);
}
TEST(YogaTest, absolute_layout_align_items_and_justify_content_center_and_bottom_position) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetJustifyContent(root, YGJustifyCenter);
YGNodeStyleSetAlignItems(root, YGAlignCenter);
YGNodeStyleSetFlexGrow(root, 1);
YGNodeStyleSetWidth(root, 110);
YGNodeStyleSetHeight(root, 100);
const YGNodeRef root_child0 = YGNodeNew();
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);
}
TEST(YogaTest, absolute_layout_align_items_and_justify_content_center_and_left_position) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetJustifyContent(root, YGJustifyCenter);
YGNodeStyleSetAlignItems(root, YGAlignCenter);
YGNodeStyleSetFlexGrow(root, 1);
YGNodeStyleSetWidth(root, 110);
YGNodeStyleSetHeight(root, 100);
const YGNodeRef root_child0 = YGNodeNew();
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);
}
TEST(YogaTest, absolute_layout_align_items_and_justify_content_center_and_right_position) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetJustifyContent(root, YGJustifyCenter);
YGNodeStyleSetAlignItems(root, YGAlignCenter);
YGNodeStyleSetFlexGrow(root, 1);
YGNodeStyleSetWidth(root, 110);
YGNodeStyleSetHeight(root, 100);
const YGNodeRef root_child0 = YGNodeNew();
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);
}

View File

@@ -697,3 +697,53 @@ TEST(YogaTest, aspect_ratio_allow_child_overflow_parent_size) {
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);
}

View File

@@ -340,3 +340,57 @@ TEST(YogaTest, wrap_row_align_items_center) {
YGNodeFreeRecursive(root);
}
TEST(YogaTest, flex_wrap_children_with_min_main_overriding_flex_basis) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
YGNodeStyleSetFlexWrap(root, YGWrapWrap);
YGNodeStyleSetWidth(root, 100);
const YGNodeRef root_child0 = YGNodeNew();
YGNodeStyleSetFlexBasis(root_child0, 50);
YGNodeStyleSetMinWidth(root_child0, 55);
YGNodeStyleSetHeight(root_child0, 50);
YGNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child1 = YGNodeNew();
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);
}

View File

@@ -39,6 +39,22 @@ static YGSize _measureMin(YGNodeRef node,
};
}
static YGSize _measure_84_49(YGNodeRef node,
float width,
YGMeasureMode widthMode,
float height,
YGMeasureMode heightMode) {
int *measureCount = (int*) YGNodeGetContext(node);
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);
@@ -131,3 +147,28 @@ TEST(YogaTest, remeasure_with_atmost_computed_width_undefined_height) {
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();
YGNodeSetContext(root_child0_child0, &measureCount);
YGNodeSetMeasureFunc(root_child0_child0, _measure_84_49);
YGNodeInsertChild(root_child0, root_child0_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
YGNodeFreeRecursive(root);
ASSERT_EQ(1, measureCount);
}

View File

@@ -47,6 +47,27 @@ TEST(YogaTest, dont_measure_single_grow_shrink_child) {
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);
YGNodeSetContext(root_child0_child0, &measureCount);
YGNodeSetMeasureFunc(root_child0_child0, _measure);
YGNodeInsertChild(root_child0, root_child0_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_EQ(1, measureCount);
YGNodeFreeRecursive(root);
}
#if GTEST_HAS_DEATH_TEST
TEST(YogaTest, cannot_add_child_to_node_with_measure_func) {
const YGNodeRef root = YGNodeNew();

View File

@@ -0,0 +1,163 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// @Generated by gentest/gentest.rb from gentest/fixtures/YGSizeOverflowTest.html
#include <yoga/Yoga.h>
#include <gtest/gtest.h>
TEST(YogaTest, nested_overflowing_child) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 100);
const YGNodeRef root_child0 = YGNodeNew();
YGNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child0_child0 = YGNodeNew();
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);
}
TEST(YogaTest, nested_overflowing_child_in_constraint_parent) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 100);
const YGNodeRef root_child0 = YGNodeNew();
YGNodeStyleSetWidth(root_child0, 100);
YGNodeStyleSetHeight(root_child0, 100);
YGNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child0_child0 = YGNodeNew();
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);
}
TEST(YogaTest, parent_wrap_child_size_overflowing_parent) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 100);
const YGNodeRef root_child0 = YGNodeNew();
YGNodeStyleSetWidth(root_child0, 100);
YGNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child0_child0 = YGNodeNew();
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);
}

View File

@@ -15,110 +15,89 @@ YG_EXTERN_C_BEGIN
#define YGFlexDirectionCount 4
typedef YG_ENUM_BEGIN(YGFlexDirection) {
YGFlexDirectionColumn,
YGFlexDirectionColumnReverse,
YGFlexDirectionRow,
YGFlexDirectionRowReverse,
} YG_ENUM_END(YGFlexDirection);
YGFlexDirectionColumn, YGFlexDirectionColumnReverse, YGFlexDirectionRow,
YGFlexDirectionRowReverse,
}
YG_ENUM_END(YGFlexDirection);
#define YGMeasureModeCount 3
typedef YG_ENUM_BEGIN(YGMeasureMode) {
YGMeasureModeUndefined,
YGMeasureModeExactly,
YGMeasureModeAtMost,
} YG_ENUM_END(YGMeasureMode);
YGMeasureModeUndefined, YGMeasureModeExactly, YGMeasureModeAtMost,
}
YG_ENUM_END(YGMeasureMode);
#define YGPrintOptionsCount 3
typedef YG_ENUM_BEGIN(YGPrintOptions) {
YGPrintOptionsLayout = 1,
YGPrintOptionsStyle = 2,
YGPrintOptionsChildren = 4,
} YG_ENUM_END(YGPrintOptions);
YGPrintOptionsLayout = 1, YGPrintOptionsStyle = 2, YGPrintOptionsChildren = 4,
}
YG_ENUM_END(YGPrintOptions);
#define YGEdgeCount 9
typedef YG_ENUM_BEGIN(YGEdge) {
YGEdgeLeft,
YGEdgeTop,
YGEdgeRight,
YGEdgeBottom,
YGEdgeStart,
YGEdgeEnd,
YGEdgeHorizontal,
YGEdgeVertical,
YGEdgeAll,
} YG_ENUM_END(YGEdge);
YGEdgeLeft, YGEdgeTop, YGEdgeRight, YGEdgeBottom, YGEdgeStart, YGEdgeEnd, YGEdgeHorizontal,
YGEdgeVertical, YGEdgeAll,
}
YG_ENUM_END(YGEdge);
#define YGPositionTypeCount 2
typedef YG_ENUM_BEGIN(YGPositionType) {
YGPositionTypeRelative,
YGPositionTypeAbsolute,
} YG_ENUM_END(YGPositionType);
YGPositionTypeRelative, YGPositionTypeAbsolute,
}
YG_ENUM_END(YGPositionType);
#define YGDimensionCount 2
typedef YG_ENUM_BEGIN(YGDimension) {
YGDimensionWidth,
YGDimensionHeight,
} YG_ENUM_END(YGDimension);
YGDimensionWidth, YGDimensionHeight,
}
YG_ENUM_END(YGDimension);
#define YGJustifyCount 5
typedef YG_ENUM_BEGIN(YGJustify) {
YGJustifyFlexStart,
YGJustifyCenter,
YGJustifyFlexEnd,
YGJustifySpaceBetween,
YGJustifySpaceAround,
} YG_ENUM_END(YGJustify);
YGJustifyFlexStart, YGJustifyCenter, YGJustifyFlexEnd, YGJustifySpaceBetween,
YGJustifySpaceAround,
}
YG_ENUM_END(YGJustify);
#define YGDirectionCount 3
typedef YG_ENUM_BEGIN(YGDirection) {
YGDirectionInherit,
YGDirectionLTR,
YGDirectionRTL,
} YG_ENUM_END(YGDirection);
YGDirectionInherit, YGDirectionLTR, YGDirectionRTL,
}
YG_ENUM_END(YGDirection);
#define YGLogLevelCount 5
typedef YG_ENUM_BEGIN(YGLogLevel) {
YGLogLevelError,
YGLogLevelWarn,
YGLogLevelInfo,
YGLogLevelDebug,
YGLogLevelVerbose,
} YG_ENUM_END(YGLogLevel);
YGLogLevelError, YGLogLevelWarn, YGLogLevelInfo, YGLogLevelDebug, YGLogLevelVerbose,
}
YG_ENUM_END(YGLogLevel);
#define YGWrapCount 2
typedef YG_ENUM_BEGIN(YGWrap) {
YGWrapNoWrap,
YGWrapWrap,
} YG_ENUM_END(YGWrap);
YGWrapNoWrap, YGWrapWrap,
}
YG_ENUM_END(YGWrap);
#define YGOverflowCount 3
typedef YG_ENUM_BEGIN(YGOverflow) {
YGOverflowVisible,
YGOverflowHidden,
YGOverflowScroll,
} YG_ENUM_END(YGOverflow);
YGOverflowVisible, YGOverflowHidden, YGOverflowScroll,
}
YG_ENUM_END(YGOverflow);
#define YGExperimentalFeatureCount 2
typedef YG_ENUM_BEGIN(YGExperimentalFeature) {
YGExperimentalFeatureRounding,
YGExperimentalFeatureWebFlexBasis,
} YG_ENUM_END(YGExperimentalFeature);
YGExperimentalFeatureRounding, YGExperimentalFeatureWebFlexBasis,
}
YG_ENUM_END(YGExperimentalFeature);
#define YGAlignCount 6
typedef YG_ENUM_BEGIN(YGAlign) {
YGAlignAuto,
YGAlignFlexStart,
YGAlignCenter,
YGAlignFlexEnd,
YGAlignStretch,
YGAlignBaseline,
} YG_ENUM_END(YGAlign);
YGAlignAuto, YGAlignFlexStart, YGAlignCenter, YGAlignFlexEnd, YGAlignStretch, YGAlignBaseline,
}
YG_ENUM_END(YGAlign);
#define YGUnitCount 3
typedef YG_ENUM_BEGIN(YGUnit) {
YGUnitUndefined,
YGUnitPixel,
YGUnitPercent,
} YG_ENUM_END(YGUnit);
YGUnitUndefined, YGUnitPixel, YGUnitPercent,
}
YG_ENUM_END(YGUnit);
YG_EXTERN_C_END

View File

@@ -42,7 +42,8 @@
#endif
#ifdef NS_ENUM
// Cannot use NSInteger as NSInteger has a different size than int (which is the default type of a 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 missmatch for the Yoga ABI.
#define YG_ENUM_BEGIN(name) NS_ENUM(int, name)
#define YG_ENUM_END(name)

View File

@@ -48,6 +48,7 @@ typedef struct YGLayout {
float position[4];
float dimensions[2];
float margin[6];
float border[6];
float padding[6];
YGDirection direction;
@@ -531,7 +532,7 @@ void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {
return node->layout.instanceName; \
}
#define YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(type, name, instanceName) \
#define YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(type, name, instanceName) \
type YGNodeLayoutGet##name(const YGNodeRef node, const YGEdge edge) { \
YG_ASSERT(edge <= YGEdgeEnd, "Cannot get layout properties of multi-edge shorthands"); \
\
@@ -596,6 +597,7 @@ YG_NODE_LAYOUT_PROPERTY_IMPL(float, Height, dimensions[YGDimensionHeight]);
YG_NODE_LAYOUT_PROPERTY_IMPL(YGDirection, Direction, direction);
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);
uint32_t gCurrentGenerationCount = 0;
@@ -985,7 +987,9 @@ static inline YGDirection YGNodeResolveDirection(const YGNodeRef node,
static float YGBaseline(const YGNodeRef node) {
if (node->baseline != NULL) {
const float baseline = node->baseline(node, node->layout.measuredDimensions[YGDimensionWidth], node->layout.measuredDimensions[YGDimensionHeight]);
const float baseline = node->baseline(node,
node->layout.measuredDimensions[YGDimensionWidth],
node->layout.measuredDimensions[YGDimensionHeight]);
YG_ASSERT(!YGFloatIsUndefined(baseline), "Expect custom baseline function to not return NaN")
return baseline;
}
@@ -1270,14 +1274,17 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node,
childWidthMeasureMode = YGMeasureModeUndefined;
childHeightMeasureMode = YGMeasureModeUndefined;
const float marginRow = YGNodeMarginForAxis(child, YGFlexDirectionRow, parentWidth);
const float marginColumn = YGNodeMarginForAxis(child, YGFlexDirectionColumn, parentWidth);
if (isRowStyleDimDefined) {
childWidth = YGValueResolve(&child->style.dimensions[YGDimensionWidth], parentWidth) +
YGNodeMarginForAxis(child, YGFlexDirectionRow, parentWidth);
childWidth =
YGValueResolve(&child->style.dimensions[YGDimensionWidth], parentWidth) + marginRow;
childWidthMeasureMode = YGMeasureModeExactly;
}
if (isColumnStyleDimDefined) {
childHeight = YGValueResolve(&child->style.dimensions[YGDimensionHeight], parentHeight) +
YGNodeMarginForAxis(child, YGFlexDirectionColumn, parentWidth);
childHeight =
YGValueResolve(&child->style.dimensions[YGDimensionHeight], parentHeight) + marginColumn;
childHeightMeasureMode = YGMeasureModeExactly;
}
@@ -1316,12 +1323,12 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node,
if (!YGFloatIsUndefined(child->style.aspectRatio)) {
if (!isMainAxisRow && childWidthMeasureMode == YGMeasureModeExactly) {
child->layout.computedFlexBasis =
fmaxf(childWidth / child->style.aspectRatio,
fmaxf((childWidth - marginRow) / child->style.aspectRatio,
YGNodePaddingAndBorderForAxis(child, YGFlexDirectionColumn, parentWidth));
return;
} else if (isMainAxisRow && childHeightMeasureMode == YGMeasureModeExactly) {
child->layout.computedFlexBasis =
fmaxf(childHeight * child->style.aspectRatio,
fmaxf((childHeight - marginColumn) * child->style.aspectRatio,
YGNodePaddingAndBorderForAxis(child, YGFlexDirectionRow, parentWidth));
return;
}
@@ -1372,9 +1379,11 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node,
YGMeasureMode childWidthMeasureMode = YGMeasureModeUndefined;
YGMeasureMode childHeightMeasureMode = YGMeasureModeUndefined;
const float marginRow = YGNodeMarginForAxis(child, YGFlexDirectionRow, width);
const float marginColumn = YGNodeMarginForAxis(child, YGFlexDirectionColumn, width);
if (YGNodeIsStyleDimDefined(child, YGFlexDirectionRow)) {
childWidth = YGValueResolve(&child->style.dimensions[YGDimensionWidth], width) +
YGNodeMarginForAxis(child, YGFlexDirectionRow, width);
childWidth = YGValueResolve(&child->style.dimensions[YGDimensionWidth], width) + marginRow;
} else {
// If the child doesn't have a specified width, compute the width based
// on the left/right
@@ -1391,8 +1400,8 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node,
}
if (YGNodeIsStyleDimDefined(child, YGFlexDirectionColumn)) {
childHeight = YGValueResolve(&child->style.dimensions[YGDimensionHeight], height) +
YGNodeMarginForAxis(child, YGFlexDirectionColumn, width);
childHeight =
YGValueResolve(&child->style.dimensions[YGDimensionHeight], height) + marginColumn;
} else {
// If the child doesn't have a specified height, compute the height
// based on the top/bottom
@@ -1413,11 +1422,13 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node,
if (YGFloatIsUndefined(childWidth) ^ YGFloatIsUndefined(childHeight)) {
if (!YGFloatIsUndefined(child->style.aspectRatio)) {
if (YGFloatIsUndefined(childWidth)) {
childWidth = fmaxf(childHeight * child->style.aspectRatio,
YGNodePaddingAndBorderForAxis(child, YGFlexDirectionColumn, width));
childWidth =
marginRow + fmaxf((childHeight - marginColumn) * child->style.aspectRatio,
YGNodePaddingAndBorderForAxis(child, YGFlexDirectionColumn, width));
} else if (YGFloatIsUndefined(childHeight)) {
childHeight = fmaxf(childWidth / child->style.aspectRatio,
YGNodePaddingAndBorderForAxis(child, YGFlexDirectionRow, width));
childHeight =
marginColumn + fmaxf((childWidth - marginRow) / child->style.aspectRatio,
YGNodePaddingAndBorderForAxis(child, YGFlexDirectionRow, width));
}
}
}
@@ -1429,11 +1440,11 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node,
childHeightMeasureMode =
YGFloatIsUndefined(childHeight) ? YGMeasureModeUndefined : YGMeasureModeExactly;
// According to the spec, if the main size is not definite and the
// child's inline axis is parallel to the main axis (i.e. it's
// horizontal), the child should be sized using "UNDEFINED" in
// the main size. Otherwise use "AT_MOST" in the cross axis.
if (!isMainAxisRow && YGFloatIsUndefined(childWidth) && widthMode != YGMeasureModeUndefined) {
// If the size of the parent 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 parent.
// This is the same behavior as many browsers implement.
if (!isMainAxisRow && YGFloatIsUndefined(childWidth) && widthMode != YGMeasureModeUndefined &&
width > 0) {
childWidth = width;
childWidthMeasureMode = YGMeasureModeAtMost;
}
@@ -1470,6 +1481,15 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node,
child->layout.measuredDimensions[dim[mainAxis]] -
YGNodeTrailingBorder(node, mainAxis) -
YGNodeTrailingPosition(child, mainAxis, width);
} else if (!YGNodeIsLeadingPosDefined(child, mainAxis) &&
node->style.justifyContent == YGJustifyCenter) {
child->layout.position[leading[mainAxis]] = (node->layout.measuredDimensions[dim[mainAxis]] -
child->layout.measuredDimensions[dim[mainAxis]]) /
2.0f;
} else if (!YGNodeIsLeadingPosDefined(child, mainAxis) &&
node->style.justifyContent == YGJustifyFlexEnd) {
child->layout.position[leading[mainAxis]] = (node->layout.measuredDimensions[dim[mainAxis]] -
child->layout.measuredDimensions[dim[mainAxis]]);
}
if (YGNodeIsTrailingPosDefined(child, crossAxis) &&
@@ -1478,6 +1498,16 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node,
child->layout.measuredDimensions[dim[crossAxis]] -
YGNodeTrailingBorder(node, crossAxis) -
YGNodeTrailingPosition(child, crossAxis, width);
} else if (!YGNodeIsLeadingPosDefined(child, crossAxis) &&
YGNodeAlignItem(node, child) == YGAlignCenter) {
child->layout.position[leading[crossAxis]] =
(node->layout.measuredDimensions[dim[crossAxis]] -
child->layout.measuredDimensions[dim[crossAxis]]) /
2.0f;
} else if (!YGNodeIsLeadingPosDefined(child, crossAxis) &&
YGNodeAlignItem(node, child) == YGAlignFlexEnd) {
child->layout.position[leading[crossAxis]] = (node->layout.measuredDimensions[dim[crossAxis]] -
child->layout.measuredDimensions[dim[crossAxis]]);
}
}
@@ -1747,39 +1777,25 @@ static void YGNodelayoutImpl(const YGNodeRef node,
const YGDirection direction = YGNodeResolveDirection(node, parentDirection);
node->layout.direction = direction;
node->layout.margin[YGEdgeStart] =
YGNodeLeadingMargin(node,
YGFlexDirectionResolve(YGFlexDirectionRow, direction),
parentWidth);
node->layout.margin[YGEdgeEnd] =
YGNodeTrailingMargin(node,
YGFlexDirectionResolve(YGFlexDirectionRow, direction),
parentWidth);
node->layout.margin[YGEdgeTop] =
YGNodeLeadingMargin(node,
YGFlexDirectionResolve(YGFlexDirectionColumn, direction),
parentWidth);
node->layout.margin[YGEdgeBottom] =
YGNodeTrailingMargin(node,
YGFlexDirectionResolve(YGFlexDirectionColumn, direction),
parentWidth);
const YGFlexDirection flexRowDirection = YGFlexDirectionResolve(YGFlexDirectionRow, direction);
const YGFlexDirection flexColumnDirection =
YGFlexDirectionResolve(YGFlexDirectionColumn, direction);
node->layout.padding[YGEdgeStart] =
YGNodeLeadingPadding(node,
YGFlexDirectionResolve(YGFlexDirectionRow, direction),
parentWidth);
node->layout.padding[YGEdgeEnd] =
YGNodeTrailingPadding(node,
YGFlexDirectionResolve(YGFlexDirectionRow, direction),
parentWidth);
node->layout.padding[YGEdgeTop] =
YGNodeLeadingPadding(node,
YGFlexDirectionResolve(YGFlexDirectionColumn, direction),
parentWidth);
node->layout.margin[YGEdgeStart] = YGNodeLeadingMargin(node, flexRowDirection, parentWidth);
node->layout.margin[YGEdgeEnd] = YGNodeTrailingMargin(node, flexRowDirection, parentWidth);
node->layout.margin[YGEdgeTop] = YGNodeLeadingMargin(node, flexColumnDirection, parentWidth);
node->layout.margin[YGEdgeBottom] = YGNodeTrailingMargin(node, flexColumnDirection, parentWidth);
node->layout.border[YGEdgeStart] = YGNodeLeadingBorder(node, flexRowDirection);
node->layout.border[YGEdgeEnd] = YGNodeTrailingBorder(node, flexRowDirection);
node->layout.border[YGEdgeTop] = YGNodeLeadingBorder(node, flexColumnDirection);
node->layout.border[YGEdgeBottom] = YGNodeTrailingBorder(node, flexColumnDirection);
node->layout.padding[YGEdgeStart] = YGNodeLeadingPadding(node, flexRowDirection, parentWidth);
node->layout.padding[YGEdgeEnd] = YGNodeTrailingPadding(node, flexRowDirection, parentWidth);
node->layout.padding[YGEdgeTop] = YGNodeLeadingPadding(node, flexColumnDirection, parentWidth);
node->layout.padding[YGEdgeBottom] =
YGNodeTrailingPadding(node,
YGFlexDirectionResolve(YGFlexDirectionColumn, direction),
parentWidth);
YGNodeTrailingPadding(node, flexColumnDirection, parentWidth);
if (node->measure) {
YGNodeWithMeasureFuncSetMeasuredDimensions(
@@ -1982,8 +1998,10 @@ static void YGNodelayoutImpl(const YGNodeRef node,
child->lineIndex = lineCount;
if (child->style.positionType != YGPositionTypeAbsolute) {
const float outerFlexBasis = child->layout.computedFlexBasis +
YGNodeMarginForAxis(child, mainAxis, availableInnerWidth);
const float outerFlexBasis =
fmaxf(YGValueResolve(&child->style.minDimensions[dim[mainAxis]], mainAxisParentSize),
child->layout.computedFlexBasis) +
YGNodeMarginForAxis(child, mainAxis, availableInnerWidth);
// If this is a multi-line flow and this item pushes us over the
// available size, we've
@@ -2202,10 +2220,13 @@ static void YGNodelayoutImpl(const YGNodeRef node,
YGMeasureMode childWidthMeasureMode;
YGMeasureMode childHeightMeasureMode;
const float marginRow =
YGNodeMarginForAxis(currentRelativeChild, YGFlexDirectionRow, availableInnerWidth);
const float marginColumn =
YGNodeMarginForAxis(currentRelativeChild, YGFlexDirectionColumn, availableInnerWidth);
if (isMainAxisRow) {
childWidth =
updatedMainSize +
YGNodeMarginForAxis(currentRelativeChild, YGFlexDirectionRow, availableInnerWidth);
childWidth = updatedMainSize + marginRow;
childWidthMeasureMode = YGMeasureModeExactly;
if (!YGFloatIsUndefined(availableInnerCrossDim) &&
@@ -2221,15 +2242,11 @@ static void YGNodelayoutImpl(const YGNodeRef node,
} else {
childHeight = YGValueResolve(&currentRelativeChild->style.dimensions[YGDimensionHeight],
availableInnerHeight) +
YGNodeMarginForAxis(currentRelativeChild,
YGFlexDirectionColumn,
availableInnerWidth);
marginColumn;
childHeightMeasureMode = YGMeasureModeExactly;
}
} else {
childHeight =
updatedMainSize +
YGNodeMarginForAxis(currentRelativeChild, YGFlexDirectionColumn, availableInnerWidth);
childHeight = updatedMainSize + marginColumn;
childHeightMeasureMode = YGMeasureModeExactly;
if (!YGFloatIsUndefined(availableInnerCrossDim) &&
@@ -2243,17 +2260,16 @@ static void YGNodelayoutImpl(const YGNodeRef node,
childWidthMeasureMode =
YGFloatIsUndefined(childWidth) ? YGMeasureModeUndefined : YGMeasureModeAtMost;
} else {
childWidth =
YGValueResolve(&currentRelativeChild->style.dimensions[YGDimensionWidth],
availableInnerWidth) +
YGNodeMarginForAxis(currentRelativeChild, YGFlexDirectionRow, availableInnerWidth);
childWidth = YGValueResolve(&currentRelativeChild->style.dimensions[YGDimensionWidth],
availableInnerWidth) +
marginRow;
childWidthMeasureMode = YGMeasureModeExactly;
}
}
if (!YGFloatIsUndefined(currentRelativeChild->style.aspectRatio)) {
if (isMainAxisRow) {
childHeight = fmaxf(childWidth / currentRelativeChild->style.aspectRatio,
childHeight = fmaxf((childWidth - marginRow) / currentRelativeChild->style.aspectRatio,
YGNodePaddingAndBorderForAxis(currentRelativeChild,
YGFlexDirectionColumn,
availableInnerWidth));
@@ -2261,21 +2277,26 @@ static void YGNodelayoutImpl(const YGNodeRef node,
// Parent size constraint should have higher priority than flex
if (YGNodeIsFlex(currentRelativeChild)) {
childHeight = fminf(childHeight, availableInnerHeight);
childWidth = childHeight * currentRelativeChild->style.aspectRatio;
childHeight = fminf((childHeight - marginColumn), availableInnerHeight);
childWidth = marginRow + childHeight * currentRelativeChild->style.aspectRatio;
}
childHeight += marginColumn;
} else {
childWidth = fmaxf(childHeight * currentRelativeChild->style.aspectRatio,
YGNodePaddingAndBorderForAxis(currentRelativeChild,
YGFlexDirectionRow,
availableInnerWidth));
childWidth =
fmaxf((childHeight - marginColumn) * currentRelativeChild->style.aspectRatio,
YGNodePaddingAndBorderForAxis(currentRelativeChild,
YGFlexDirectionRow,
availableInnerWidth));
childWidthMeasureMode = YGMeasureModeExactly;
// Parent size constraint should have higher priority than flex
if (YGNodeIsFlex(currentRelativeChild)) {
childWidth = fminf(childWidth, availableInnerWidth);
childHeight = childWidth / currentRelativeChild->style.aspectRatio;
childWidth = fminf((childWidth - marginRow), availableInnerWidth);
childHeight = marginColumn + childWidth / currentRelativeChild->style.aspectRatio;
}
childWidth += marginRow;
}
}
@@ -2484,24 +2505,31 @@ static void YGNodelayoutImpl(const YGNodeRef node,
YGMeasureMode childWidthMeasureMode = YGMeasureModeExactly;
YGMeasureMode childHeightMeasureMode = YGMeasureModeExactly;
const float marginRow =
YGNodeMarginForAxis(child, YGFlexDirectionRow, availableInnerWidth);
const float marginColumn =
YGNodeMarginForAxis(child, YGFlexDirectionColumn, availableInnerWidth);
if (isMainAxisRow) {
childWidth = child->layout.measuredDimensions[YGDimensionWidth] +
YGNodeMarginForAxis(child, YGFlexDirectionRow, availableInnerWidth);
childWidth = child->layout.measuredDimensions[YGDimensionWidth];
if (!YGFloatIsUndefined(child->style.aspectRatio)) {
childHeight = childWidth / child->style.aspectRatio;
childHeight = marginColumn + childWidth / child->style.aspectRatio;
} else {
childHeight = crossDim;
}
childWidth += marginRow;
} else {
childHeight = child->layout.measuredDimensions[YGDimensionHeight] +
YGNodeMarginForAxis(child, YGFlexDirectionColumn, availableInnerWidth);
childHeight = child->layout.measuredDimensions[YGDimensionHeight];
if (!YGFloatIsUndefined(child->style.aspectRatio)) {
childWidth = childHeight * child->style.aspectRatio;
childWidth = marginRow + childHeight * child->style.aspectRatio;
} else {
childWidth = crossDim;
}
childHeight += marginColumn;
}
YGConstrainMaxSizeForMode(YGValueResolve(&child->style.maxDimensions[YGDimensionWidth],
@@ -2672,19 +2700,22 @@ static void YGNodelayoutImpl(const YGNodeRef node,
// If the user didn't specify a width or height for the node, set the
// dimensions based on the children.
if (measureModeMainDim == YGMeasureModeUndefined) {
if (measureModeMainDim == YGMeasureModeUndefined ||
(node->style.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->layout.measuredDimensions[dim[mainAxis]] =
YGNodeBoundAxis(node, mainAxis, maxLineMainDim, mainAxisParentSize, parentWidth);
} else if (measureModeMainDim == YGMeasureModeAtMost) {
} else if (measureModeMainDim == YGMeasureModeAtMost &&
node->style.overflow == YGOverflowScroll) {
node->layout.measuredDimensions[dim[mainAxis]] = fmaxf(
fminf(availableInnerMainDim + paddingAndBorderAxisMain,
YGNodeBoundAxisWithinMinAndMax(node, mainAxis, maxLineMainDim, mainAxisParentSize)),
paddingAndBorderAxisMain);
}
if (measureModeCrossDim == YGMeasureModeUndefined) {
if (measureModeCrossDim == YGMeasureModeUndefined ||
(node->style.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->layout.measuredDimensions[dim[crossAxis]] =
@@ -2693,7 +2724,8 @@ static void YGNodelayoutImpl(const YGNodeRef node,
totalLineCrossDim + paddingAndBorderAxisCross,
crossAxisParentSize,
parentWidth);
} else if (measureModeCrossDim == YGMeasureModeAtMost) {
} else if (measureModeCrossDim == YGMeasureModeAtMost &&
node->style.overflow == YGOverflowScroll) {
node->layout.measuredDimensions[dim[crossAxis]] =
fmaxf(fminf(availableInnerCrossDim + paddingAndBorderAxisCross,
YGNodeBoundAxisWithinMinAndMax(node,
@@ -2779,7 +2811,7 @@ static inline bool YGMeasureModeOldSizeIsUnspecifiedAndStillFits(YGMeasureMode s
YGMeasureMode lastSizeMode,
float lastComputedSize) {
return sizeMode == YGMeasureModeAtMost && lastSizeMode == YGMeasureModeUndefined &&
size >= lastComputedSize;
(size >= lastComputedSize || YGFloatsEqual(size, lastComputedSize));
}
static inline bool YGMeasureModeNewMeasureSizeIsStricterAndStillValid(YGMeasureMode sizeMode,
@@ -2788,7 +2820,7 @@ static inline bool YGMeasureModeNewMeasureSizeIsStricterAndStillValid(YGMeasureM
float lastSize,
float lastComputedSize) {
return lastSizeMode == YGMeasureModeAtMost && sizeMode == YGMeasureModeAtMost &&
lastSize > size && lastComputedSize <= size;
lastSize > size && (lastComputedSize <= size || YGFloatsEqual(size, lastComputedSize));
}
bool YGNodeCanUseCachedMeasurement(const YGMeasureMode widthMode,

View File

@@ -43,7 +43,7 @@ typedef struct YGValue {
YGUnit unit;
} YGValue;
static const YGValue YGValueUndefined = { YGUndefined, YGUnitUndefined };
static const YGValue YGValueUndefined = {YGUndefined, YGUnitUndefined};
typedef struct YGNode *YGNodeRef;
typedef YGSize (*YGMeasureFunc)(YGNodeRef node,
@@ -139,6 +139,9 @@ WIN_EXPORT void YGNodeCopyStyle(const YGNodeRef dstNode, const YGNodeRef srcNode
#define YG_NODE_LAYOUT_PROPERTY(type, name) \
WIN_EXPORT type YGNodeLayoutGet##name(const YGNodeRef node);
#define YG_NODE_LAYOUT_EDGE_PROPERTY(type, name) \
WIN_EXPORT type YGNodeLayoutGet##name(const YGNodeRef node, const YGEdge edge);
YG_NODE_PROPERTY(void *, Context, context);
YG_NODE_PROPERTY(YGMeasureFunc, MeasureFunc, measureFunc);
YG_NODE_PROPERTY(YGBaselineFunc, BaselineFunc, baselineFunc)
@@ -195,12 +198,13 @@ YG_NODE_LAYOUT_PROPERTY(float, Width);
YG_NODE_LAYOUT_PROPERTY(float, Height);
YG_NODE_LAYOUT_PROPERTY(YGDirection, Direction);
// Get the computed padding for this node after performing layout. If padding was set using
// pixel values then the returned value will be the same as YGNodeStyleGetPadding. However if
// padding was set using a percentage value then the returned value is the computed value used
// Get the computed values for these nodes after performing layout. If they were set using
// pixel 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(const YGNodeRef node, const YGEdge edge);
WIN_EXPORT float YGNodeLayoutGetPadding(const YGNodeRef node, const YGEdge edge);
YG_NODE_LAYOUT_EDGE_PROPERTY(float, Margin);
YG_NODE_LAYOUT_EDGE_PROPERTY(float, Border);
YG_NODE_LAYOUT_EDGE_PROPERTY(float, Padding);
WIN_EXPORT void YGSetLogger(YGLogger logger);
WIN_EXPORT void YGLog(YGLogLevel level, const char *message, ...);