Fix justify content with min/max constraint parent

Summary:
The min/max inner width shouldn't take the margins into account.
Adds a test for both cases.

Fixes #664
Closes https://github.com/facebook/yoga/pull/665

Differential Revision: D6407982

Pulled By: emilsjolander

fbshipit-source-id: ffa549a06f802263e3b8488e90756aa3f722d52d
This commit is contained in:
Lukas Wöhrl
2017-11-24 07:06:16 -08:00
committed by Facebook Github Bot
parent 0b13a0c168
commit a69545a6ae
6 changed files with 700 additions and 4 deletions

View File

@@ -699,5 +699,173 @@ namespace Facebook.Yoga
Assert.AreEqual(10f, root_child2.LayoutHeight);
}
[Test]
public void Test_justify_content_row_min_width_and_margin()
{
YogaConfig config = new YogaConfig();
YogaNode root = new YogaNode(config);
root.FlexDirection = YogaFlexDirection.Row;
root.JustifyContent = YogaJustify.Center;
root.MarginLeft = 100;
root.MinWidth = 50;
YogaNode root_child0 = new YogaNode(config);
root_child0.Width = 20;
root_child0.Height = 20;
root.Insert(0, root_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(100f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(50f, root.LayoutWidth);
Assert.AreEqual(20f, root.LayoutHeight);
Assert.AreEqual(15f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(20f, root_child0.LayoutWidth);
Assert.AreEqual(20f, root_child0.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(100f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(50f, root.LayoutWidth);
Assert.AreEqual(20f, root.LayoutHeight);
Assert.AreEqual(15f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(20f, root_child0.LayoutWidth);
Assert.AreEqual(20f, root_child0.LayoutHeight);
}
[Test]
public void Test_justify_content_row_max_width_and_margin()
{
YogaConfig config = new YogaConfig();
YogaNode root = new YogaNode(config);
root.FlexDirection = YogaFlexDirection.Row;
root.JustifyContent = YogaJustify.Center;
root.MarginLeft = 100;
root.Width = 100;
root.MaxWidth = 80;
YogaNode root_child0 = new YogaNode(config);
root_child0.Width = 20;
root_child0.Height = 20;
root.Insert(0, root_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(100f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(80f, root.LayoutWidth);
Assert.AreEqual(20f, root.LayoutHeight);
Assert.AreEqual(30f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(20f, root_child0.LayoutWidth);
Assert.AreEqual(20f, root_child0.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(100f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(80f, root.LayoutWidth);
Assert.AreEqual(20f, root.LayoutHeight);
Assert.AreEqual(30f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(20f, root_child0.LayoutWidth);
Assert.AreEqual(20f, root_child0.LayoutHeight);
}
[Test]
public void Test_justify_content_column_min_height_and_margin()
{
YogaConfig config = new YogaConfig();
YogaNode root = new YogaNode(config);
root.JustifyContent = YogaJustify.Center;
root.MarginTop = 100;
root.MinHeight = 50;
YogaNode root_child0 = new YogaNode(config);
root_child0.Width = 20;
root_child0.Height = 20;
root.Insert(0, root_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(100f, root.LayoutY);
Assert.AreEqual(20f, root.LayoutWidth);
Assert.AreEqual(50f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(15f, root_child0.LayoutY);
Assert.AreEqual(20f, root_child0.LayoutWidth);
Assert.AreEqual(20f, root_child0.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(100f, root.LayoutY);
Assert.AreEqual(20f, root.LayoutWidth);
Assert.AreEqual(50f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(15f, root_child0.LayoutY);
Assert.AreEqual(20f, root_child0.LayoutWidth);
Assert.AreEqual(20f, root_child0.LayoutHeight);
}
[Test]
public void Test_justify_content_colunn_max_height_and_margin()
{
YogaConfig config = new YogaConfig();
YogaNode root = new YogaNode(config);
root.JustifyContent = YogaJustify.Center;
root.MarginTop = 100;
root.Height = 100;
root.MaxHeight = 80;
YogaNode root_child0 = new YogaNode(config);
root_child0.Width = 20;
root_child0.Height = 20;
root.Insert(0, root_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(100f, root.LayoutY);
Assert.AreEqual(20f, root.LayoutWidth);
Assert.AreEqual(80f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(30f, root_child0.LayoutY);
Assert.AreEqual(20f, root_child0.LayoutWidth);
Assert.AreEqual(20f, root_child0.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(100f, root.LayoutY);
Assert.AreEqual(20f, root.LayoutWidth);
Assert.AreEqual(80f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(30f, root_child0.LayoutY);
Assert.AreEqual(20f, root_child0.LayoutWidth);
Assert.AreEqual(20f, root_child0.LayoutHeight);
}
}
}