Merge branch 'facebook/master' into percentage-feature
This commit is contained in:
@@ -289,4 +289,58 @@
|
|||||||
XCTAssertFalse(view.yg_isLeaf);
|
XCTAssertFalse(view.yg_isLeaf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)testThatWeCorrectlyAttachNestedViews
|
||||||
|
{
|
||||||
|
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)];
|
||||||
|
[container yg_setUsesYoga:YES];
|
||||||
|
[container yg_setFlexDirection:YGFlexDirectionColumn];
|
||||||
|
|
||||||
|
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
|
[subview1 yg_setUsesYoga:YES];
|
||||||
|
[subview1 yg_setWidth:100];
|
||||||
|
[subview1 yg_setFlexGrow:1];
|
||||||
|
[subview1 yg_setFlexDirection:YGFlexDirectionColumn];
|
||||||
|
[container addSubview:subview1];
|
||||||
|
|
||||||
|
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
|
[subview2 yg_setUsesYoga:YES];
|
||||||
|
[subview2 yg_setWidth:150];
|
||||||
|
[subview2 yg_setFlexGrow:1];
|
||||||
|
[subview2 yg_setFlexDirection:YGFlexDirectionColumn];
|
||||||
|
[container addSubview:subview2];
|
||||||
|
|
||||||
|
for (UIView *view in @[subview1, subview2]) {
|
||||||
|
UIView *someView = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
|
[someView yg_setUsesYoga:YES];
|
||||||
|
[someView yg_setFlexGrow:1];
|
||||||
|
[view addSubview:someView];
|
||||||
|
}
|
||||||
|
[container yg_applyLayout];
|
||||||
|
|
||||||
|
// Add the same amount of new views, reapply layout.
|
||||||
|
for (UIView *view in @[subview1, subview2]) {
|
||||||
|
UIView *someView = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
|
[someView yg_setUsesYoga:YES];
|
||||||
|
[someView yg_setFlexGrow:1];
|
||||||
|
[view addSubview:someView];
|
||||||
|
}
|
||||||
|
[container yg_applyLayout];
|
||||||
|
|
||||||
|
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(100, 25), subview1.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview1.bounds.size));
|
||||||
|
for (UIView *subview in subview1.subviews) {
|
||||||
|
const CGSize subviewSize = subview.bounds.size;
|
||||||
|
XCTAssertFalse(CGSizeEqualToSize(CGSizeZero, subviewSize));
|
||||||
|
XCTAssertFalse(isnan(subviewSize.height));
|
||||||
|
XCTAssertFalse(isnan(subviewSize.width));
|
||||||
|
}
|
||||||
|
|
||||||
|
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(150, 25), subview2.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview2.bounds.size));
|
||||||
|
for (UIView *subview in subview2.subviews) {
|
||||||
|
const CGSize subviewSize = subview.bounds.size;
|
||||||
|
XCTAssertFalse(CGSizeEqualToSize(CGSizeZero, subview.bounds.size));
|
||||||
|
XCTAssertFalse(isnan(subviewSize.height));
|
||||||
|
XCTAssertFalse(isnan(subviewSize.width));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@@ -290,9 +290,24 @@ static CGFloat YGSanitizeMeasurement(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void YGAttachNodesFromViewHierachy(UIView *view)
|
static BOOL YGNodeHasExactSameChildren(const YGNodeRef node, NSArray<UIView *> *subviews)
|
||||||
{
|
{
|
||||||
YGNodeRef node = [view ygNode];
|
if (YGNodeGetChildCount(node) != subviews.count) {
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i=0; i<subviews.count; i++) {
|
||||||
|
if (YGNodeGetChild(node, i) != subviews[i].ygNode) {
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void YGAttachNodesFromViewHierachy(UIView *const view)
|
||||||
|
{
|
||||||
|
const YGNodeRef node = [view ygNode];
|
||||||
|
|
||||||
// Only leaf nodes should have a measure function
|
// Only leaf nodes should have a measure function
|
||||||
if (view.yg_isLeaf) {
|
if (view.yg_isLeaf) {
|
||||||
@@ -301,7 +316,6 @@ static void YGAttachNodesFromViewHierachy(UIView *view)
|
|||||||
} else {
|
} else {
|
||||||
YGNodeSetMeasureFunc(node, NULL);
|
YGNodeSetMeasureFunc(node, NULL);
|
||||||
|
|
||||||
// Create a list of all the subviews that we are going to use for layout.
|
|
||||||
NSMutableArray<UIView *> *subviewsToInclude = [[NSMutableArray alloc] initWithCapacity:view.subviews.count];
|
NSMutableArray<UIView *> *subviewsToInclude = [[NSMutableArray alloc] initWithCapacity:view.subviews.count];
|
||||||
for (UIView *subview in view.subviews) {
|
for (UIView *subview in view.subviews) {
|
||||||
if ([subview yg_includeInLayout]) {
|
if ([subview yg_includeInLayout]) {
|
||||||
@@ -309,26 +323,15 @@ static void YGAttachNodesFromViewHierachy(UIView *view)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL shouldReconstructChildList = NO;
|
if (!YGNodeHasExactSameChildren(node, subviewsToInclude)) {
|
||||||
if (YGNodeGetChildCount(node) != subviewsToInclude.count) {
|
YGRemoveAllChildren(node);
|
||||||
shouldReconstructChildList = YES;
|
for (int i=0; i<subviewsToInclude.count; i++) {
|
||||||
} else {
|
YGNodeInsertChild(node, [subviewsToInclude[i] ygNode], i);
|
||||||
for (int i = 0; i < subviewsToInclude.count; i++) {
|
|
||||||
if (YGNodeGetChild(node, i) != [subviewsToInclude[i] ygNode]) {
|
|
||||||
shouldReconstructChildList = YES;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldReconstructChildList) {
|
for (UIView *const subview in subviewsToInclude) {
|
||||||
YGRemoveAllChildren(node);
|
|
||||||
|
|
||||||
for (int i = 0 ; i < subviewsToInclude.count; i++) {
|
|
||||||
UIView *const subview = subviewsToInclude[i];
|
|
||||||
YGNodeInsertChild(node, [subview ygNode], i);
|
|
||||||
YGAttachNodesFromViewHierachy(subview);
|
YGAttachNodesFromViewHierachy(subview);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -385,7 +388,7 @@ static void YGApplyLayoutToViewHierarchy(UIView *view)
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (!view.yg_isLeaf) {
|
if (!view.yg_isLeaf) {
|
||||||
for (NSUInteger i = 0; i < view.subviews.count; i++) {
|
for (NSUInteger i=0; i<view.subviews.count; i++) {
|
||||||
YGApplyLayoutToViewHierarchy(view.subviews[i]);
|
YGApplyLayoutToViewHierarchy(view.subviews[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -454,5 +454,226 @@ namespace Facebook.Yoga
|
|||||||
Assert.AreEqual(20f, root_child0_child0.LayoutHeight);
|
Assert.AreEqual(20f, root_child0_child0.LayoutHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Test_flex_grow_within_constrained_min_row()
|
||||||
|
{
|
||||||
|
YogaNode root = new YogaNode();
|
||||||
|
root.FlexDirection = YogaFlexDirection.Row;
|
||||||
|
root.MinWidth = 100f;
|
||||||
|
root.Height = 100f;
|
||||||
|
|
||||||
|
YogaNode root_child0 = new YogaNode();
|
||||||
|
root_child0.FlexGrow = 1f;
|
||||||
|
root.Insert(0, root_child0);
|
||||||
|
|
||||||
|
YogaNode root_child1 = new YogaNode();
|
||||||
|
root_child1.Width = 50f;
|
||||||
|
root.Insert(1, root_child1);
|
||||||
|
root.StyleDirection = YogaDirection.LTR;
|
||||||
|
root.CalculateLayout();
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root.LayoutY);
|
||||||
|
Assert.AreEqual(100f, root.LayoutWidth);
|
||||||
|
Assert.AreEqual(100f, root.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||||
|
Assert.AreEqual(100f, root_child0.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(50f, root_child1.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root_child1.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||||
|
Assert.AreEqual(100f, root_child1.LayoutHeight);
|
||||||
|
|
||||||
|
root.StyleDirection = YogaDirection.RTL;
|
||||||
|
root.CalculateLayout();
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root.LayoutY);
|
||||||
|
Assert.AreEqual(100f, root.LayoutWidth);
|
||||||
|
Assert.AreEqual(100f, root.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(50f, root_child0.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||||
|
Assert.AreEqual(100f, root_child0.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root_child1.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root_child1.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||||
|
Assert.AreEqual(100f, root_child1.LayoutHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Test_flex_grow_within_constrained_min_column()
|
||||||
|
{
|
||||||
|
YogaNode root = new YogaNode();
|
||||||
|
root.MinHeight = 100f;
|
||||||
|
|
||||||
|
YogaNode root_child0 = new YogaNode();
|
||||||
|
root_child0.FlexGrow = 1f;
|
||||||
|
root.Insert(0, root_child0);
|
||||||
|
|
||||||
|
YogaNode root_child1 = new YogaNode();
|
||||||
|
root_child1.Height = 50f;
|
||||||
|
root.Insert(1, root_child1);
|
||||||
|
root.StyleDirection = YogaDirection.LTR;
|
||||||
|
root.CalculateLayout();
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root.LayoutY);
|
||||||
|
Assert.AreEqual(0f, root.LayoutWidth);
|
||||||
|
Assert.AreEqual(100f, root.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||||
|
Assert.AreEqual(0f, root_child0.LayoutWidth);
|
||||||
|
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root_child1.LayoutX);
|
||||||
|
Assert.AreEqual(50f, root_child1.LayoutY);
|
||||||
|
Assert.AreEqual(0f, 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(0f, root.LayoutWidth);
|
||||||
|
Assert.AreEqual(100f, root.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||||
|
Assert.AreEqual(0f, root_child0.LayoutWidth);
|
||||||
|
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root_child1.LayoutX);
|
||||||
|
Assert.AreEqual(50f, root_child1.LayoutY);
|
||||||
|
Assert.AreEqual(0f, root_child1.LayoutWidth);
|
||||||
|
Assert.AreEqual(50f, root_child1.LayoutHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Test_flex_grow_within_constrained_max_row()
|
||||||
|
{
|
||||||
|
YogaNode root = new YogaNode();
|
||||||
|
root.Width = 200f;
|
||||||
|
|
||||||
|
YogaNode root_child0 = new YogaNode();
|
||||||
|
root_child0.FlexDirection = YogaFlexDirection.Row;
|
||||||
|
root_child0.MaxWidth = 100f;
|
||||||
|
root_child0.Height = 100f;
|
||||||
|
root.Insert(0, root_child0);
|
||||||
|
|
||||||
|
YogaNode root_child0_child0 = new YogaNode();
|
||||||
|
root_child0_child0.FlexShrink = 1f;
|
||||||
|
root_child0_child0.FlexBasis = 100f;
|
||||||
|
root_child0.Insert(0, root_child0_child0);
|
||||||
|
|
||||||
|
YogaNode root_child0_child1 = new YogaNode();
|
||||||
|
root_child0_child1.Width = 50f;
|
||||||
|
root_child0.Insert(1, root_child0_child1);
|
||||||
|
root.StyleDirection = YogaDirection.LTR;
|
||||||
|
root.CalculateLayout();
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root.LayoutY);
|
||||||
|
Assert.AreEqual(200f, root.LayoutWidth);
|
||||||
|
Assert.AreEqual(100f, root.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||||
|
Assert.AreEqual(100f, root_child0.LayoutWidth);
|
||||||
|
Assert.AreEqual(100f, root_child0.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root_child0_child0.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root_child0_child0.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child0_child0.LayoutWidth);
|
||||||
|
Assert.AreEqual(100f, root_child0_child0.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(50f, root_child0_child1.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root_child0_child1.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child0_child1.LayoutWidth);
|
||||||
|
Assert.AreEqual(100f, root_child0_child1.LayoutHeight);
|
||||||
|
|
||||||
|
root.StyleDirection = YogaDirection.RTL;
|
||||||
|
root.CalculateLayout();
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root.LayoutY);
|
||||||
|
Assert.AreEqual(200f, root.LayoutWidth);
|
||||||
|
Assert.AreEqual(100f, root.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(100f, root_child0.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||||
|
Assert.AreEqual(100f, root_child0.LayoutWidth);
|
||||||
|
Assert.AreEqual(100f, root_child0.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(50f, root_child0_child0.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root_child0_child0.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child0_child0.LayoutWidth);
|
||||||
|
Assert.AreEqual(100f, root_child0_child0.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root_child0_child1.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root_child0_child1.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child0_child1.LayoutWidth);
|
||||||
|
Assert.AreEqual(100f, root_child0_child1.LayoutHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Test_flex_grow_within_constrained_max_column()
|
||||||
|
{
|
||||||
|
YogaNode root = new YogaNode();
|
||||||
|
root.Width = 100f;
|
||||||
|
root.MaxHeight = 100f;
|
||||||
|
|
||||||
|
YogaNode root_child0 = new YogaNode();
|
||||||
|
root_child0.FlexShrink = 1f;
|
||||||
|
root_child0.FlexBasis = 100f;
|
||||||
|
root.Insert(0, root_child0);
|
||||||
|
|
||||||
|
YogaNode root_child1 = new YogaNode();
|
||||||
|
root_child1.Height = 50f;
|
||||||
|
root.Insert(1, root_child1);
|
||||||
|
root.StyleDirection = YogaDirection.LTR;
|
||||||
|
root.CalculateLayout();
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root.LayoutY);
|
||||||
|
Assert.AreEqual(100f, root.LayoutWidth);
|
||||||
|
Assert.AreEqual(100f, root.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||||
|
Assert.AreEqual(100f, root_child0.LayoutWidth);
|
||||||
|
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root_child1.LayoutX);
|
||||||
|
Assert.AreEqual(50f, root_child1.LayoutY);
|
||||||
|
Assert.AreEqual(100f, root_child1.LayoutWidth);
|
||||||
|
Assert.AreEqual(50f, root_child1.LayoutHeight);
|
||||||
|
|
||||||
|
root.StyleDirection = YogaDirection.RTL;
|
||||||
|
root.CalculateLayout();
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root.LayoutY);
|
||||||
|
Assert.AreEqual(100f, root.LayoutWidth);
|
||||||
|
Assert.AreEqual(100f, root.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||||
|
Assert.AreEqual(100f, root_child0.LayoutWidth);
|
||||||
|
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root_child1.LayoutX);
|
||||||
|
Assert.AreEqual(50f, root_child1.LayoutY);
|
||||||
|
Assert.AreEqual(100f, root_child1.LayoutWidth);
|
||||||
|
Assert.AreEqual(50f, root_child1.LayoutHeight);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -41,3 +41,25 @@
|
|||||||
<div style="height: 20px; flex-grow: 1;"></div>
|
<div style="height: 20px; flex-grow: 1;"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="flex_grow_within_constrained_min_row" style="min-width: 100px; height:100px; flex-direction: row;">
|
||||||
|
<div style="flex-grow:1;"></div>
|
||||||
|
<div style="width: 50px;"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="flex_grow_within_constrained_min_column" style="min-height: 100px;">
|
||||||
|
<div style="flex-grow:1;"></div>
|
||||||
|
<div style="height: 50px;"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="flex_grow_within_constrained_max_row" style="width: 200px;">
|
||||||
|
<div style="height: 100px; max-width: 100px; flex-direction: row;">
|
||||||
|
<div style="flex-shrink:1; flex-basis:100px"></div>
|
||||||
|
<div style="width: 50px;"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="flex_grow_within_constrained_max_column" style="max-height: 100px; width: 100px;">
|
||||||
|
<div style="flex-shrink:1; flex-basis:100px"></div>
|
||||||
|
<div style="height: 50px;"></div>
|
||||||
|
</div>
|
||||||
|
@@ -444,4 +444,221 @@ public class YGMinMaxDimensionTest {
|
|||||||
assertEquals(20f, root_child0_child0.getLayoutHeight(), 0.0f);
|
assertEquals(20f, root_child0_child0.getLayoutHeight(), 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_flex_grow_within_constrained_min_row() {
|
||||||
|
final YogaNode root = new YogaNode();
|
||||||
|
root.setFlexDirection(YogaFlexDirection.ROW);
|
||||||
|
root.setMinWidth(100f);
|
||||||
|
root.setHeight(100f);
|
||||||
|
|
||||||
|
final YogaNode root_child0 = new YogaNode();
|
||||||
|
root_child0.setFlexGrow(1f);
|
||||||
|
root.addChildAt(root_child0, 0);
|
||||||
|
|
||||||
|
final YogaNode root_child1 = new YogaNode();
|
||||||
|
root_child1.setWidth(50f);
|
||||||
|
root.addChildAt(root_child1, 1);
|
||||||
|
root.setDirection(YogaDirection.LTR);
|
||||||
|
root.calculateLayout();
|
||||||
|
|
||||||
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(100f, root.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(100f, root_child0.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(50f, root_child1.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(100f, root_child1.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
root.setDirection(YogaDirection.RTL);
|
||||||
|
root.calculateLayout();
|
||||||
|
|
||||||
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(100f, root.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(50f, root_child0.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(100f, root_child0.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(100f, root_child1.getLayoutHeight(), 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_flex_grow_within_constrained_min_column() {
|
||||||
|
final YogaNode root = new YogaNode();
|
||||||
|
root.setMinHeight(100f);
|
||||||
|
|
||||||
|
final YogaNode root_child0 = new YogaNode();
|
||||||
|
root_child0.setFlexGrow(1f);
|
||||||
|
root.addChildAt(root_child0, 0);
|
||||||
|
|
||||||
|
final YogaNode root_child1 = new YogaNode();
|
||||||
|
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(0f, 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(0f, 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(0f, 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(0f, 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(0f, 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(0f, root_child1.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_flex_grow_within_constrained_max_row() {
|
||||||
|
final YogaNode root = new YogaNode();
|
||||||
|
root.setWidth(200f);
|
||||||
|
|
||||||
|
final YogaNode root_child0 = new YogaNode();
|
||||||
|
root_child0.setFlexDirection(YogaFlexDirection.ROW);
|
||||||
|
root_child0.setMaxWidth(100f);
|
||||||
|
root_child0.setHeight(100f);
|
||||||
|
root.addChildAt(root_child0, 0);
|
||||||
|
|
||||||
|
final YogaNode root_child0_child0 = new YogaNode();
|
||||||
|
root_child0_child0.setFlexShrink(1f);
|
||||||
|
root_child0_child0.setFlexBasis(100f);
|
||||||
|
root_child0.addChildAt(root_child0_child0, 0);
|
||||||
|
|
||||||
|
final YogaNode root_child0_child1 = new YogaNode();
|
||||||
|
root_child0_child1.setWidth(50f);
|
||||||
|
root_child0.addChildAt(root_child0_child1, 1);
|
||||||
|
root.setDirection(YogaDirection.LTR);
|
||||||
|
root.calculateLayout();
|
||||||
|
|
||||||
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(100f, root_child0.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(100f, root_child0_child0.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(50f, root_child0_child1.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child0_child1.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child0_child1.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(100f, root_child0_child1.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
root.setDirection(YogaDirection.RTL);
|
||||||
|
root.calculateLayout();
|
||||||
|
|
||||||
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(100f, root_child0.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(100f, root_child0.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(50f, root_child0_child0.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(100f, root_child0_child0.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(0f, root_child0_child1.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child0_child1.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child0_child1.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(100f, root_child0_child1.getLayoutHeight(), 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_flex_grow_within_constrained_max_column() {
|
||||||
|
final YogaNode root = new YogaNode();
|
||||||
|
root.setWidth(100f);
|
||||||
|
root.setMaxHeight(100f);
|
||||||
|
|
||||||
|
final YogaNode root_child0 = new YogaNode();
|
||||||
|
root_child0.setFlexShrink(1f);
|
||||||
|
root_child0.setFlexBasis(100f);
|
||||||
|
root.addChildAt(root_child0, 0);
|
||||||
|
|
||||||
|
final YogaNode root_child1 = new YogaNode();
|
||||||
|
root_child1.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(100f, root_child0.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(100f, root_child1.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
root.setDirection(YogaDirection.RTL);
|
||||||
|
root.calculateLayout();
|
||||||
|
|
||||||
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(100f, root.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(100f, root_child1.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -430,3 +430,216 @@ TEST(YogaTest, flex_grow_within_constrained_max_width) {
|
|||||||
|
|
||||||
YGNodeFreeRecursive(root);
|
YGNodeFreeRecursive(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(YogaTest, flex_grow_within_constrained_min_row) {
|
||||||
|
const YGNodeRef root = YGNodeNew();
|
||||||
|
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
||||||
|
YGNodeStyleSetMinWidth(root, 100);
|
||||||
|
YGNodeStyleSetHeight(root, 100);
|
||||||
|
|
||||||
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
|
YGNodeStyleSetFlexGrow(root_child0, 1);
|
||||||
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
|
const YGNodeRef root_child1 = YGNodeNew();
|
||||||
|
YGNodeStyleSetWidth(root_child1, 50);
|
||||||
|
YGNodeInsertChild(root, root_child1, 1);
|
||||||
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1));
|
||||||
|
|
||||||
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1));
|
||||||
|
|
||||||
|
YGNodeFreeRecursive(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(YogaTest, flex_grow_within_constrained_min_column) {
|
||||||
|
const YGNodeRef root = YGNodeNew();
|
||||||
|
YGNodeStyleSetMinHeight(root, 100);
|
||||||
|
|
||||||
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
|
YGNodeStyleSetFlexGrow(root_child0, 1);
|
||||||
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
|
const YGNodeRef root_child1 = YGNodeNew();
|
||||||
|
YGNodeStyleSetHeight(root_child1, 50);
|
||||||
|
YGNodeInsertChild(root, root_child1, 1);
|
||||||
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||||
|
|
||||||
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||||
|
|
||||||
|
YGNodeFreeRecursive(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(YogaTest, flex_grow_within_constrained_max_row) {
|
||||||
|
const YGNodeRef root = YGNodeNew();
|
||||||
|
YGNodeStyleSetWidth(root, 200);
|
||||||
|
|
||||||
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
|
YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow);
|
||||||
|
YGNodeStyleSetMaxWidth(root_child0, 100);
|
||||||
|
YGNodeStyleSetHeight(root_child0, 100);
|
||||||
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
|
const YGNodeRef root_child0_child0 = YGNodeNew();
|
||||||
|
YGNodeStyleSetFlexShrink(root_child0_child0, 1);
|
||||||
|
YGNodeStyleSetFlexBasis(root_child0_child0, 100);
|
||||||
|
YGNodeInsertChild(root_child0, root_child0_child0, 0);
|
||||||
|
|
||||||
|
const YGNodeRef root_child0_child1 = YGNodeNew();
|
||||||
|
YGNodeStyleSetWidth(root_child0_child1, 50);
|
||||||
|
YGNodeInsertChild(root_child0, root_child0_child1, 1);
|
||||||
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||||
|
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_child0));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0_child1));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child1));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_child1));
|
||||||
|
|
||||||
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||||
|
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_child0));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child1));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child1));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_child1));
|
||||||
|
|
||||||
|
YGNodeFreeRecursive(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(YogaTest, flex_grow_within_constrained_max_column) {
|
||||||
|
const YGNodeRef root = YGNodeNew();
|
||||||
|
YGNodeStyleSetWidth(root, 100);
|
||||||
|
YGNodeStyleSetMaxHeight(root, 100);
|
||||||
|
|
||||||
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
|
YGNodeStyleSetFlexShrink(root_child0, 1);
|
||||||
|
YGNodeStyleSetFlexBasis(root_child0, 100);
|
||||||
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
|
const YGNodeRef root_child1 = YGNodeNew();
|
||||||
|
YGNodeStyleSetHeight(root_child1, 50);
|
||||||
|
YGNodeInsertChild(root, root_child1, 1);
|
||||||
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||||
|
|
||||||
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||||
|
|
||||||
|
YGNodeFreeRecursive(root);
|
||||||
|
}
|
||||||
|
33
yoga/Yoga.c
33
yoga/Yoga.c
@@ -1597,9 +1597,24 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
const float marginAxisColumn = YGNodeMarginForAxis(node, YGFlexDirectionColumn, parentWidth);
|
const float marginAxisColumn = YGNodeMarginForAxis(node, YGFlexDirectionColumn, parentWidth);
|
||||||
|
|
||||||
// STEP 2: DETERMINE AVAILABLE SIZE IN MAIN AND CROSS DIRECTIONS
|
// STEP 2: DETERMINE AVAILABLE SIZE IN MAIN AND CROSS DIRECTIONS
|
||||||
const float availableInnerWidth = availableWidth - marginAxisRow - paddingAndBorderAxisRow;
|
float availableInnerWidth = availableWidth - marginAxisRow - paddingAndBorderAxisRow;
|
||||||
const float availableInnerHeight = availableHeight - marginAxisColumn - paddingAndBorderAxisColumn;
|
float availableInnerHeight = availableHeight - marginAxisColumn - paddingAndBorderAxisColumn;
|
||||||
const float availableInnerMainDim = isMainAxisRow ? availableInnerWidth : availableInnerHeight;
|
const float minInnerWidth = YGValueResolve(&node->style.minDimensions[YGDimensionWidth], parentWidth) - marginAxisRow - paddingAndBorderAxisRow;
|
||||||
|
const float maxInnerWidth = YGValueResolve(&node->style.maxDimensions[YGDimensionWidth], parentWidth) - marginAxisRow - paddingAndBorderAxisRow;
|
||||||
|
const float minInnerHeight = YGValueResolve(&node->style.minDimensions[YGDimensionHeight], parentHeight) - marginAxisColumn - paddingAndBorderAxisColumn;
|
||||||
|
const float maxInnerHeight = YGValueResolve(&node->style.maxDimensions[YGDimensionHeight], parentHeight) - marginAxisColumn - paddingAndBorderAxisColumn;
|
||||||
|
const float minInnerMainDim = isMainAxisRow ? minInnerWidth : minInnerHeight;
|
||||||
|
const float maxInnerMainDim = isMainAxisRow ? maxInnerWidth : maxInnerHeight;
|
||||||
|
|
||||||
|
// Max dimension overrides predefined dimension value; Min dimension in turn overrides both of the above
|
||||||
|
if (!YGFloatIsUndefined(availableInnerWidth)) {
|
||||||
|
availableInnerWidth = fmaxf(fminf(availableInnerWidth, maxInnerWidth), minInnerWidth);
|
||||||
|
}
|
||||||
|
if (!YGFloatIsUndefined(availableInnerHeight)) {
|
||||||
|
availableInnerHeight = fmaxf(fminf(availableInnerHeight, maxInnerHeight), minInnerHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
float availableInnerMainDim = isMainAxisRow ? availableInnerWidth : availableInnerHeight;
|
||||||
const float availableInnerCrossDim = isMainAxisRow ? availableInnerHeight : availableInnerWidth;
|
const float availableInnerCrossDim = isMainAxisRow ? availableInnerHeight : availableInnerWidth;
|
||||||
|
|
||||||
// If there is only one child with flexGrow + flexShrink it means we can set the
|
// If there is only one child with flexGrow + flexShrink it means we can set the
|
||||||
@@ -1755,6 +1770,18 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
// Calculate the remaining available space that needs to be allocated.
|
// Calculate the remaining available space that needs to be allocated.
|
||||||
// If the main dimension size isn't known, it is computed based on
|
// If the main dimension size isn't known, it is computed based on
|
||||||
// the line length, so there's no more space left to distribute.
|
// the line length, so there's no more space left to distribute.
|
||||||
|
|
||||||
|
// We resolve main dimension to fit minimum and maximum values
|
||||||
|
if (YGValueIsUndefined(availableInnerMainDim)) {
|
||||||
|
if (!YGValueIsUndefined(minInnerMainDim) &&
|
||||||
|
sizeConsumedOnCurrentLine < minInnerMainDim) {
|
||||||
|
availableInnerMainDim = minInnerMainDim;
|
||||||
|
} else if (!YGValueIsUndefined(maxInnerMainDim) &&
|
||||||
|
sizeConsumedOnCurrentLine > maxInnerMainDim) {
|
||||||
|
availableInnerMainDim = maxInnerMainDim;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
float remainingFreeSpace = 0;
|
float remainingFreeSpace = 0;
|
||||||
if (!YGFloatIsUndefined(availableInnerMainDim)) {
|
if (!YGFloatIsUndefined(availableInnerMainDim)) {
|
||||||
remainingFreeSpace = availableInnerMainDim - sizeConsumedOnCurrentLine;
|
remainingFreeSpace = availableInnerMainDim - sizeConsumedOnCurrentLine;
|
||||||
|
Reference in New Issue
Block a user