Feature auto margin
Summary: Even so I know there are some opinions against ```margin: 0 auto``` it's still part of the spec: https://www.w3.org/TR/css-flexbox-1/#auto-margins and pretty usefull if you have to position via ```justify-content```. This PR adds an implementation for that. It adds an additonal ```YGUnitAuto``` and margins got ```YGNodeStyleSetMarginAuto``` functions as well. Closes https://github.com/facebook/yoga/pull/357 Reviewed By: astreet Differential Revision: D4501142 Pulled By: emilsjolander fbshipit-source-id: 86519f8632496f46e78a7c9dbc5b21e212e3e0c7
This commit is contained in:
committed by
Facebook Github Bot
parent
8a91c0a0e5
commit
1146013e9e
@@ -196,6 +196,9 @@ namespace Facebook.Yoga
|
||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void YGNodeStyleSetFlexBasisPercent(YGNodeHandle node, float flexBasis);
|
||||
|
||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void YGNodeStyleSetFlexBasisAuto(YGNodeHandle node);
|
||||
|
||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern YogaValue YGNodeStyleGetFlexBasis(YGNodeHandle node);
|
||||
|
||||
@@ -205,6 +208,9 @@ namespace Facebook.Yoga
|
||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void YGNodeStyleSetWidthPercent(YGNodeHandle node, float width);
|
||||
|
||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void YGNodeStyleSetWidthAuto(YGNodeHandle node);
|
||||
|
||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern YogaValue YGNodeStyleGetWidth(YGNodeHandle node);
|
||||
|
||||
@@ -213,6 +219,9 @@ namespace Facebook.Yoga
|
||||
|
||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void YGNodeStyleSetHeightPercent(YGNodeHandle node, float height);
|
||||
|
||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void YGNodeStyleSetHeightAuto(YGNodeHandle node);
|
||||
|
||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern YogaValue YGNodeStyleGetHeight(YGNodeHandle node);
|
||||
@@ -278,6 +287,9 @@ namespace Facebook.Yoga
|
||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void YGNodeStyleSetMarginPercent(YGNodeHandle node, YogaEdge edge, float margin);
|
||||
|
||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void YGNodeStyleSetMarginAuto(YGNodeHandle node, YogaEdge edge);
|
||||
|
||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern YogaValue YGNodeStyleGetMargin(YGNodeHandle node, YogaEdge edge);
|
||||
|
||||
|
@@ -226,6 +226,10 @@ namespace Facebook.Yoga
|
||||
{
|
||||
Native.YGNodeStyleSetMarginPercent(_ygNode, edge, value.Value);
|
||||
}
|
||||
else if (value.Unit == YogaUnit.Auto)
|
||||
{
|
||||
Native.YGNodeStyleSetMarginAuto(_ygNode, edge);
|
||||
}
|
||||
else
|
||||
{
|
||||
Native.YGNodeStyleSetMargin(_ygNode, edge, value.Value);
|
||||
|
@@ -270,6 +270,10 @@ namespace Facebook.Yoga
|
||||
{
|
||||
Native.YGNodeStyleSetFlexBasisPercent(_ygNode, value.Value);
|
||||
}
|
||||
else if (value.Unit == YogaUnit.Auto)
|
||||
{
|
||||
Native.YGNodeStyleSetFlexBasisAuto(_ygNode);
|
||||
}
|
||||
else
|
||||
{
|
||||
Native.YGNodeStyleSetFlexBasis(_ygNode, value.Value);
|
||||
@@ -290,6 +294,10 @@ namespace Facebook.Yoga
|
||||
{
|
||||
Native.YGNodeStyleSetWidthPercent(_ygNode, value.Value);
|
||||
}
|
||||
else if (value.Unit == YogaUnit.Auto)
|
||||
{
|
||||
Native.YGNodeStyleSetWidthAuto(_ygNode);
|
||||
}
|
||||
else
|
||||
{
|
||||
Native.YGNodeStyleSetWidth(_ygNode, value.Value);
|
||||
@@ -310,6 +318,10 @@ namespace Facebook.Yoga
|
||||
{
|
||||
Native.YGNodeStyleSetHeightPercent(_ygNode, value.Value);
|
||||
}
|
||||
else if (value.Unit == YogaUnit.Auto)
|
||||
{
|
||||
Native.YGNodeStyleSetHeightAuto(_ygNode);
|
||||
}
|
||||
else
|
||||
{
|
||||
Native.YGNodeStyleSetHeight(_ygNode, value.Value);
|
||||
|
@@ -14,5 +14,6 @@ namespace Facebook.Yoga
|
||||
Undefined,
|
||||
Pixel,
|
||||
Percent,
|
||||
Auto,
|
||||
}
|
||||
}
|
||||
|
@@ -70,6 +70,15 @@ namespace Facebook.Yoga
|
||||
};
|
||||
}
|
||||
|
||||
public static YogaValue Auto()
|
||||
{
|
||||
return new YogaValue
|
||||
{
|
||||
value = 0f,
|
||||
unit = YogaUnit.Auto
|
||||
};
|
||||
}
|
||||
|
||||
public static YogaValue Percent(float value)
|
||||
{
|
||||
return new YogaValue
|
||||
|
@@ -436,5 +436,759 @@ namespace Facebook.Yoga
|
||||
Assert.AreEqual(45f, root_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_margin_auto_bottom()
|
||||
{
|
||||
YogaNode root = new YogaNode();
|
||||
root.AlignItems = YogaAlign.Center;
|
||||
root.Width = 200;
|
||||
root.Height = 200;
|
||||
|
||||
YogaNode root_child0 = new YogaNode();
|
||||
root_child0.MarginBottom = YogaValue.Auto();
|
||||
root_child0.Width = 50;
|
||||
root_child0.Height = 50;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child1 = new YogaNode();
|
||||
root_child1.Width = 50;
|
||||
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(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child1.LayoutX);
|
||||
Assert.AreEqual(150f, root_child1.LayoutY);
|
||||
Assert.AreEqual(50f, 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(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child1.LayoutX);
|
||||
Assert.AreEqual(150f, root_child1.LayoutY);
|
||||
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_margin_auto_top()
|
||||
{
|
||||
YogaNode root = new YogaNode();
|
||||
root.AlignItems = YogaAlign.Center;
|
||||
root.Width = 200;
|
||||
root.Height = 200;
|
||||
|
||||
YogaNode root_child0 = new YogaNode();
|
||||
root_child0.MarginTop = YogaValue.Auto();
|
||||
root_child0.Width = 50;
|
||||
root_child0.Height = 50;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child1 = new YogaNode();
|
||||
root_child1.Width = 50;
|
||||
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(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child0.LayoutX);
|
||||
Assert.AreEqual(100f, root_child0.LayoutY);
|
||||
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child1.LayoutX);
|
||||
Assert.AreEqual(150f, root_child1.LayoutY);
|
||||
Assert.AreEqual(50f, 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(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child0.LayoutX);
|
||||
Assert.AreEqual(100f, root_child0.LayoutY);
|
||||
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child1.LayoutX);
|
||||
Assert.AreEqual(150f, root_child1.LayoutY);
|
||||
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_margin_auto_bottom_and_top()
|
||||
{
|
||||
YogaNode root = new YogaNode();
|
||||
root.AlignItems = YogaAlign.Center;
|
||||
root.Width = 200;
|
||||
root.Height = 200;
|
||||
|
||||
YogaNode root_child0 = new YogaNode();
|
||||
root_child0.MarginTop = YogaValue.Auto();
|
||||
root_child0.MarginBottom = YogaValue.Auto();
|
||||
root_child0.Width = 50;
|
||||
root_child0.Height = 50;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child1 = new YogaNode();
|
||||
root_child1.Width = 50;
|
||||
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(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child0.LayoutX);
|
||||
Assert.AreEqual(50f, root_child0.LayoutY);
|
||||
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child1.LayoutX);
|
||||
Assert.AreEqual(150f, root_child1.LayoutY);
|
||||
Assert.AreEqual(50f, 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(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child0.LayoutX);
|
||||
Assert.AreEqual(50f, root_child0.LayoutY);
|
||||
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child1.LayoutX);
|
||||
Assert.AreEqual(150f, root_child1.LayoutY);
|
||||
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_margin_auto_bottom_and_top_justify_center()
|
||||
{
|
||||
YogaNode root = new YogaNode();
|
||||
root.JustifyContent = YogaJustify.Center;
|
||||
root.Width = 200;
|
||||
root.Height = 200;
|
||||
|
||||
YogaNode root_child0 = new YogaNode();
|
||||
root_child0.MarginTop = YogaValue.Auto();
|
||||
root_child0.MarginBottom = YogaValue.Auto();
|
||||
root_child0.Width = 50;
|
||||
root_child0.Height = 50;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child1 = new YogaNode();
|
||||
root_child1.Width = 50;
|
||||
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(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||
Assert.AreEqual(50f, root_child0.LayoutY);
|
||||
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child1.LayoutX);
|
||||
Assert.AreEqual(150f, root_child1.LayoutY);
|
||||
Assert.AreEqual(50f, 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(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(150f, root_child0.LayoutX);
|
||||
Assert.AreEqual(50f, root_child0.LayoutY);
|
||||
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(150f, root_child1.LayoutX);
|
||||
Assert.AreEqual(150f, root_child1.LayoutY);
|
||||
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_margin_auto_mutiple_children_column()
|
||||
{
|
||||
YogaNode root = new YogaNode();
|
||||
root.AlignItems = YogaAlign.Center;
|
||||
root.Width = 200;
|
||||
root.Height = 200;
|
||||
|
||||
YogaNode root_child0 = new YogaNode();
|
||||
root_child0.MarginTop = YogaValue.Auto();
|
||||
root_child0.Width = 50;
|
||||
root_child0.Height = 50;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child1 = new YogaNode();
|
||||
root_child1.MarginTop = YogaValue.Auto();
|
||||
root_child1.Width = 50;
|
||||
root_child1.Height = 50;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
YogaNode root_child2 = new YogaNode();
|
||||
root_child2.Width = 50;
|
||||
root_child2.Height = 50;
|
||||
root.Insert(2, root_child2);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child0.LayoutX);
|
||||
Assert.AreEqual(25f, root_child0.LayoutY);
|
||||
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child1.LayoutX);
|
||||
Assert.AreEqual(100f, root_child1.LayoutY);
|
||||
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child2.LayoutX);
|
||||
Assert.AreEqual(150f, root_child2.LayoutY);
|
||||
Assert.AreEqual(50f, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child2.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child0.LayoutX);
|
||||
Assert.AreEqual(25f, root_child0.LayoutY);
|
||||
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child1.LayoutX);
|
||||
Assert.AreEqual(100f, root_child1.LayoutY);
|
||||
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child2.LayoutX);
|
||||
Assert.AreEqual(150f, root_child2.LayoutY);
|
||||
Assert.AreEqual(50f, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child2.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_margin_auto_mutiple_children_row()
|
||||
{
|
||||
YogaNode root = new YogaNode();
|
||||
root.FlexDirection = YogaFlexDirection.Row;
|
||||
root.AlignItems = YogaAlign.Center;
|
||||
root.Width = 200;
|
||||
root.Height = 200;
|
||||
|
||||
YogaNode root_child0 = new YogaNode();
|
||||
root_child0.MarginRight = YogaValue.Auto();
|
||||
root_child0.Width = 50;
|
||||
root_child0.Height = 50;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child1 = new YogaNode();
|
||||
root_child1.MarginRight = YogaValue.Auto();
|
||||
root_child1.Width = 50;
|
||||
root_child1.Height = 50;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
YogaNode root_child2 = new YogaNode();
|
||||
root_child2.Width = 50;
|
||||
root_child2.Height = 50;
|
||||
root.Insert(2, root_child2);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||
Assert.AreEqual(75f, root_child0.LayoutY);
|
||||
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child1.LayoutX);
|
||||
Assert.AreEqual(75f, root_child1.LayoutY);
|
||||
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(150f, root_child2.LayoutX);
|
||||
Assert.AreEqual(75f, root_child2.LayoutY);
|
||||
Assert.AreEqual(50f, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child2.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(125f, root_child0.LayoutX);
|
||||
Assert.AreEqual(75f, root_child0.LayoutY);
|
||||
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50f, root_child1.LayoutX);
|
||||
Assert.AreEqual(75f, root_child1.LayoutY);
|
||||
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child2.LayoutX);
|
||||
Assert.AreEqual(75f, root_child2.LayoutY);
|
||||
Assert.AreEqual(50f, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child2.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_margin_auto_left_and_right_column()
|
||||
{
|
||||
YogaNode root = new YogaNode();
|
||||
root.FlexDirection = YogaFlexDirection.Row;
|
||||
root.AlignItems = YogaAlign.Center;
|
||||
root.Width = 200;
|
||||
root.Height = 200;
|
||||
|
||||
YogaNode root_child0 = new YogaNode();
|
||||
root_child0.MarginLeft = YogaValue.Auto();
|
||||
root_child0.MarginRight = YogaValue.Auto();
|
||||
root_child0.Width = 50;
|
||||
root_child0.Height = 50;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child1 = new YogaNode();
|
||||
root_child1.Width = 50;
|
||||
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(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50f, root_child0.LayoutX);
|
||||
Assert.AreEqual(75f, root_child0.LayoutY);
|
||||
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(150f, root_child1.LayoutX);
|
||||
Assert.AreEqual(75f, root_child1.LayoutY);
|
||||
Assert.AreEqual(50f, 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(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(100f, root_child0.LayoutX);
|
||||
Assert.AreEqual(75f, root_child0.LayoutY);
|
||||
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child1.LayoutX);
|
||||
Assert.AreEqual(75f, root_child1.LayoutY);
|
||||
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_margin_auto_left_and_right()
|
||||
{
|
||||
YogaNode root = new YogaNode();
|
||||
root.Width = 200;
|
||||
root.Height = 200;
|
||||
|
||||
YogaNode root_child0 = new YogaNode();
|
||||
root_child0.MarginLeft = YogaValue.Auto();
|
||||
root_child0.MarginRight = YogaValue.Auto();
|
||||
root_child0.Width = 50;
|
||||
root_child0.Height = 50;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child1 = new YogaNode();
|
||||
root_child1.Width = 50;
|
||||
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(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child1.LayoutX);
|
||||
Assert.AreEqual(50f, root_child1.LayoutY);
|
||||
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_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(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(150f, root_child1.LayoutX);
|
||||
Assert.AreEqual(50f, root_child1.LayoutY);
|
||||
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_margin_auto_left_and_right_column_and_center()
|
||||
{
|
||||
YogaNode root = new YogaNode();
|
||||
root.AlignItems = YogaAlign.Center;
|
||||
root.Width = 200;
|
||||
root.Height = 200;
|
||||
|
||||
YogaNode root_child0 = new YogaNode();
|
||||
root_child0.MarginLeft = YogaValue.Auto();
|
||||
root_child0.MarginRight = YogaValue.Auto();
|
||||
root_child0.Width = 50;
|
||||
root_child0.Height = 50;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child1 = new YogaNode();
|
||||
root_child1.Width = 50;
|
||||
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(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child1.LayoutX);
|
||||
Assert.AreEqual(50f, root_child1.LayoutY);
|
||||
Assert.AreEqual(50f, 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(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child1.LayoutX);
|
||||
Assert.AreEqual(50f, root_child1.LayoutY);
|
||||
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_margin_auto_left()
|
||||
{
|
||||
YogaNode root = new YogaNode();
|
||||
root.AlignItems = YogaAlign.Center;
|
||||
root.Width = 200;
|
||||
root.Height = 200;
|
||||
|
||||
YogaNode root_child0 = new YogaNode();
|
||||
root_child0.MarginLeft = YogaValue.Auto();
|
||||
root_child0.Width = 50;
|
||||
root_child0.Height = 50;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child1 = new YogaNode();
|
||||
root_child1.Width = 50;
|
||||
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(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(150f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child1.LayoutX);
|
||||
Assert.AreEqual(50f, root_child1.LayoutY);
|
||||
Assert.AreEqual(50f, 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(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(150f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child1.LayoutX);
|
||||
Assert.AreEqual(50f, root_child1.LayoutY);
|
||||
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_margin_auto_right()
|
||||
{
|
||||
YogaNode root = new YogaNode();
|
||||
root.AlignItems = YogaAlign.Center;
|
||||
root.Width = 200;
|
||||
root.Height = 200;
|
||||
|
||||
YogaNode root_child0 = new YogaNode();
|
||||
root_child0.MarginRight = YogaValue.Auto();
|
||||
root_child0.Width = 50;
|
||||
root_child0.Height = 50;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child1 = new YogaNode();
|
||||
root_child1.Width = 50;
|
||||
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(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child1.LayoutX);
|
||||
Assert.AreEqual(50f, root_child1.LayoutY);
|
||||
Assert.AreEqual(50f, 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(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75f, root_child1.LayoutX);
|
||||
Assert.AreEqual(50f, root_child1.LayoutY);
|
||||
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_margin_auto_left_and_right_strech()
|
||||
{
|
||||
YogaNode root = new YogaNode();
|
||||
root.FlexDirection = YogaFlexDirection.Row;
|
||||
root.Width = 200;
|
||||
root.Height = 200;
|
||||
|
||||
YogaNode root_child0 = new YogaNode();
|
||||
root_child0.MarginLeft = YogaValue.Auto();
|
||||
root_child0.MarginRight = YogaValue.Auto();
|
||||
root_child0.Width = 50;
|
||||
root_child0.Height = 50;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child1 = new YogaNode();
|
||||
root_child1.Width = 50;
|
||||
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(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(150f, root_child1.LayoutX);
|
||||
Assert.AreEqual(0f, root_child1.LayoutY);
|
||||
Assert.AreEqual(50f, 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(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(100f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child1.LayoutX);
|
||||
Assert.AreEqual(0f, root_child1.LayoutY);
|
||||
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_margin_auto_top_and_bottom_strech()
|
||||
{
|
||||
YogaNode root = new YogaNode();
|
||||
root.Width = 200;
|
||||
root.Height = 200;
|
||||
|
||||
YogaNode root_child0 = new YogaNode();
|
||||
root_child0.MarginTop = YogaValue.Auto();
|
||||
root_child0.MarginBottom = YogaValue.Auto();
|
||||
root_child0.Width = 50;
|
||||
root_child0.Height = 50;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child1 = new YogaNode();
|
||||
root_child1.Width = 50;
|
||||
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(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||
Assert.AreEqual(50f, root_child0.LayoutY);
|
||||
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child1.LayoutX);
|
||||
Assert.AreEqual(150f, root_child1.LayoutY);
|
||||
Assert.AreEqual(50f, 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(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(150f, root_child0.LayoutX);
|
||||
Assert.AreEqual(50f, root_child0.LayoutY);
|
||||
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(150f, root_child1.LayoutX);
|
||||
Assert.AreEqual(150f, root_child1.LayoutY);
|
||||
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
1
enums.py
1
enums.py
@@ -21,6 +21,7 @@ ENUMS = {
|
||||
'Undefined',
|
||||
'Pixel',
|
||||
'Percent',
|
||||
'Auto',
|
||||
],
|
||||
'FlexDirection': [
|
||||
'Column',
|
||||
|
@@ -39,3 +39,70 @@
|
||||
<div style="margin-bottom: 10px; flex-grow: 1;"></div>
|
||||
<div style="flex-grow: 1;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_auto_bottom" style="width: 200px; height: 200px; align-items: center;">
|
||||
<div style="width: 50px; height: 50px; margin-bottom:auto;"></div>
|
||||
<div style="width: 50px; height: 50px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_auto_top" style="width: 200px; height: 200px; align-items: center;">
|
||||
<div style="width: 50px; height: 50px; margin-top:auto;"></div>
|
||||
<div style="width: 50px; height: 50px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_auto_bottom_and_top" style="width: 200px; height: 200px; align-items: center;">
|
||||
<div style="width: 50px; height: 50px; margin-top:auto; margin-bottom:auto;"></div>
|
||||
<div style="width: 50px; height: 50px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_auto_bottom_and_top_justify_center" style="width: 200px; height: 200px; justify-content: center;">
|
||||
<div style="width: 50px; height: 50px; margin-top:auto; margin-bottom:auto;"></div>
|
||||
<div style="width: 50px; height: 50px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_auto_mutiple_children_column" style="width: 200px; height: 200px; flex-direction: column; align-items: center;">
|
||||
<div style="width: 50px; height: 50px; margin-top:auto;"></div>
|
||||
<div style="width: 50px; height: 50px; margin-top:auto;"></div>
|
||||
<div style="width: 50px; height: 50px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_auto_mutiple_children_row" style="width: 200px; height: 200px; flex-direction:row; align-items: center;">
|
||||
<div style="width: 50px; height: 50px; margin-right:auto;"></div>
|
||||
<div style="width: 50px; height: 50px; margin-right:auto;"></div>
|
||||
<div style="width: 50px; height: 50px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_auto_left_and_right_column" style="width: 200px; height: 200px; align-items: center; flex-direction: row;">
|
||||
<div style="width: 50px; height: 50px; margin-left:auto; margin-right:auto;"></div>
|
||||
<div style="width: 50px; height: 50px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_auto_left_and_right" style="width: 200px; height: 200px; ">
|
||||
<div style="width: 50px; height: 50px; margin-left:auto; margin-right:auto;"></div>
|
||||
<div style="width: 50px; height: 50px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_auto_left_and_right_column_and_center" style="width: 200px; height: 200px; align-items: center;">
|
||||
<div style="width: 50px; height: 50px; margin-left:auto; margin-right:auto;"></div>
|
||||
<div style="width: 50px; height: 50px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_auto_left" style="width: 200px; height: 200px; align-items: center;">
|
||||
<div style="width: 50px; height: 50px; margin-left:auto;"></div>
|
||||
<div style="width: 50px; height: 50px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_auto_right" style="width: 200px; height: 200px; align-items: center;">
|
||||
<div style="width: 50px; height: 50px; margin-right:auto;"></div>
|
||||
<div style="width: 50px; height: 50px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_auto_left_and_right_strech" style="width: 200px; height: 200px; flex-direction:row; align-items: stretch;">
|
||||
<div style="width: 50px; height: 50px; margin-left:auto; margin-right:auto;"></div>
|
||||
<div style="width: 50px; height: 50px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_auto_top_and_bottom_strech" style="width: 200px; height: 200px; flex-direction: column; align-items: stretch;">
|
||||
<div style="width: 50px; height: 50px; margin-top:auto; margin-bottom:auto;"></div>
|
||||
<div style="width: 50px; height: 50px;"></div>
|
||||
</div>
|
||||
|
@@ -13,8 +13,10 @@ function toValueCpp(value) {
|
||||
}
|
||||
|
||||
function toFunctionName(value) {
|
||||
if (value.indexOf('%') >= 0){
|
||||
if (value.indexOf('%') >= 0) {
|
||||
return 'Percent';
|
||||
} else if(value.indexOf('Auto') >= 0) {
|
||||
return 'Auto';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
@@ -121,6 +123,8 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
|
||||
|
||||
YGDisplayFlex:{value:'YGDisplayFlex'},
|
||||
YGDisplayNone:{value:'YGDisplayNone'},
|
||||
YGAuto:{value:'YGAuto'},
|
||||
|
||||
|
||||
YGNodeCalculateLayout:{value:function(node, dir) {
|
||||
this.push('YGNodeCalculateLayout(' + node + ', YGUndefined, YGUndefined, ' + dir + ');');
|
||||
@@ -199,7 +203,13 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
|
||||
}},
|
||||
|
||||
YGNodeStyleSetMargin:{value:function(nodeName, edge, value) {
|
||||
this.push('YGNodeStyleSetMargin' + toFunctionName(value) + '(' + nodeName + ', ' + edge + ', ' + toValueCpp(value) + ');');
|
||||
var valueStr = toValueCpp(value);
|
||||
if (valueStr != 'YGAuto') {
|
||||
valueStr = ', ' + valueStr;
|
||||
} else {
|
||||
valueStr = '';
|
||||
}
|
||||
this.push('YGNodeStyleSetMargin' + toFunctionName(value) + '(' + nodeName + ', ' + edge + valueStr + ');');
|
||||
}},
|
||||
|
||||
YGNodeStyleSetMaxHeight:{value:function(nodeName, value) {
|
||||
|
@@ -17,6 +17,9 @@ function toCsUnitValue(value) {
|
||||
if (value.indexOf('%') >= 0){
|
||||
methodName = '.Percent()';
|
||||
}
|
||||
if(value.indexOf('Auto') >= 0){
|
||||
return 'YogaValue.Auto()';
|
||||
}
|
||||
return toValueCs(value) + methodName;
|
||||
}
|
||||
|
||||
@@ -130,6 +133,8 @@ CSEmitter.prototype = Object.create(Emitter.prototype, {
|
||||
|
||||
YGUndefined:{value:'YogaConstants.Undefined'},
|
||||
|
||||
YGAuto:{value:'YogaConstants.Auto'},
|
||||
|
||||
YGDisplayFlex:{value:'YogaDisplay.Flex'},
|
||||
YGDisplayNone:{value:'YogaDisplay.None'},
|
||||
|
||||
|
@@ -15,6 +15,8 @@ function toValueJava(value) {
|
||||
function toMethodName(value) {
|
||||
if (value.indexOf('%') >= 0){
|
||||
return 'Percent';
|
||||
} else if(value.indexOf('AUTO') >= 0) {
|
||||
return 'Auto';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
@@ -136,6 +138,8 @@ JavaEmitter.prototype = Object.create(Emitter.prototype, {
|
||||
|
||||
YGDisplayFlex:{value:'YogaDisplay.FLEX'},
|
||||
YGDisplayNone:{value:'YogaDisplay.NONE'},
|
||||
YGAuto:{value:'YogaConstants.AUTO'},
|
||||
|
||||
|
||||
YGWrapNoWrap:{value:'YogaWrap.NO_WRAP'},
|
||||
YGWrapWrap:{value:'YogaWrap.WRAP'},
|
||||
@@ -218,7 +222,14 @@ JavaEmitter.prototype = Object.create(Emitter.prototype, {
|
||||
}},
|
||||
|
||||
YGNodeStyleSetMargin:{value:function(nodeName, edge, value) {
|
||||
this.push(nodeName + '.setMargin' + toMethodName(value) + '(' + edge + ', ' + toValueJava(value) + 'f);');
|
||||
var valueStr = toValueJava(value);
|
||||
if (valueStr != 'YogaConstants.AUTO') {
|
||||
valueStr = ', ' + valueStr + 'f';
|
||||
} else {
|
||||
valueStr = '';
|
||||
}
|
||||
|
||||
this.push(nodeName + '.setMargin' + toMethodName(value) + '(' + edge + valueStr + ');');
|
||||
}},
|
||||
|
||||
YGNodeStyleSetMaxHeight:{value:function(nodeName, value) {
|
||||
|
@@ -14,6 +14,7 @@ var JavascriptEmitter = function() {
|
||||
function toValueJavascript(value) {
|
||||
if (value.match(/^[0-9.e+-]+px$/i)) return parseFloat(value);
|
||||
if (value.match(/^[0-9.e+-]+%/i)) return JSON.stringify(value);
|
||||
if (value == 'Yoga.AUTO') return '"auto"';
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -122,6 +123,8 @@ JavascriptEmitter.prototype = Object.create(Emitter.prototype, {
|
||||
YGPositionTypeAbsolute:{value:'Yoga.POSITION_TYPE_ABSOLUTE'},
|
||||
YGPositionTypeRelative:{value:'Yoga.POSITION_TYPE_RELATIVE'},
|
||||
|
||||
YGAuto:{value:'Yoga.AUTO'},
|
||||
|
||||
YGWrapNoWrap:{value:'Yoga.WRAP_NO_WRAP'},
|
||||
YGWrapWrap:{value:'Yoga.WRAP_WRAP'},
|
||||
|
||||
|
@@ -389,7 +389,7 @@ function alignValue(e, value) {
|
||||
|
||||
function pixelValue(e, value) {
|
||||
switch (value) {
|
||||
case 'auto': return e.YGUndefined;
|
||||
case 'auto': return e.YGAuto;
|
||||
case 'undefined': return e.YGUndefined;
|
||||
default: return value;
|
||||
}
|
||||
|
@@ -378,6 +378,12 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
|
||||
jni_YGNodeStyleSetFlexBasisPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
private native void jni_YGNodeStyleSetFlexBasisAuto(long nativePointer);
|
||||
@Override
|
||||
public void setFlexBasisAuto() {
|
||||
jni_YGNodeStyleSetFlexBasisAuto(mNativePointer);
|
||||
}
|
||||
|
||||
private native Object jni_YGNodeStyleGetMargin(long nativePointer, int edge);
|
||||
@Override
|
||||
public YogaValue getMargin(YogaEdge edge) {
|
||||
@@ -401,6 +407,13 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
|
||||
jni_YGNodeStyleSetMarginPercent(mNativePointer, edge.intValue(), percent);
|
||||
}
|
||||
|
||||
private native void jni_YGNodeStyleSetMarginAuto(long nativePointer, int edge);
|
||||
@Override
|
||||
public void setMarginAuto(YogaEdge edge) {
|
||||
mHasSetMargin = true;
|
||||
jni_YGNodeStyleSetMarginAuto(mNativePointer, edge.intValue());
|
||||
}
|
||||
|
||||
private native Object jni_YGNodeStyleGetPadding(long nativePointer, int edge);
|
||||
@Override
|
||||
public YogaValue getPadding(YogaEdge edge) {
|
||||
@@ -481,6 +494,12 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
|
||||
jni_YGNodeStyleSetWidthPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
private native void jni_YGNodeStyleSetWidthAuto(long nativePointer);
|
||||
@Override
|
||||
public void setWidthAuto() {
|
||||
jni_YGNodeStyleSetWidthAuto(mNativePointer);
|
||||
}
|
||||
|
||||
private native Object jni_YGNodeStyleGetHeight(long nativePointer);
|
||||
@Override
|
||||
public YogaValue getHeight() {
|
||||
@@ -499,6 +518,12 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
|
||||
jni_YGNodeStyleSetHeightPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
private native void jni_YGNodeStyleSetHeightAuto(long nativePointer);
|
||||
@Override
|
||||
public void setHeightAuto() {
|
||||
jni_YGNodeStyleSetHeightAuto(mNativePointer);
|
||||
}
|
||||
|
||||
private native Object jni_YGNodeStyleGetMinWidth(long nativePointer);
|
||||
@Override
|
||||
public YogaValue getMinWidth() {
|
||||
|
@@ -49,9 +49,11 @@ public interface YogaNodeAPI<YogaNodeType extends YogaNodeAPI> {
|
||||
YogaValue getFlexBasis();
|
||||
void setFlexBasis(float flexBasis);
|
||||
void setFlexBasisPercent(float percent);
|
||||
void setFlexBasisAuto();
|
||||
YogaValue getMargin(YogaEdge edge);
|
||||
void setMargin(YogaEdge edge, float margin);
|
||||
void setMarginPercent(YogaEdge edge, float percent);
|
||||
void setMarginAuto(YogaEdge edge);
|
||||
YogaValue getPadding(YogaEdge edge);
|
||||
void setPadding(YogaEdge edge, float padding);
|
||||
void setPaddingPercent(YogaEdge edge, float percent);
|
||||
@@ -63,9 +65,11 @@ public interface YogaNodeAPI<YogaNodeType extends YogaNodeAPI> {
|
||||
YogaValue getWidth();
|
||||
void setWidth(float width);
|
||||
void setWidthPercent(float percent);
|
||||
void setWidthAuto();
|
||||
YogaValue getHeight();
|
||||
void setHeight(float height);
|
||||
void setHeightPercent(float percent);
|
||||
void setHeightAuto();
|
||||
YogaValue getMaxWidth();
|
||||
void setMaxWidth(float maxWidth);
|
||||
void setMaxWidthPercent(float percent);
|
||||
|
@@ -15,7 +15,8 @@ import com.facebook.proguard.annotations.DoNotStrip;
|
||||
public enum YogaUnit {
|
||||
UNDEFINED(0),
|
||||
PIXEL(1),
|
||||
PERCENT(2);
|
||||
PERCENT(2),
|
||||
AUTO(3);
|
||||
|
||||
private int mIntValue;
|
||||
|
||||
@@ -32,6 +33,7 @@ public enum YogaUnit {
|
||||
case 0: return UNDEFINED;
|
||||
case 1: return PIXEL;
|
||||
case 2: return PERCENT;
|
||||
case 3: return AUTO;
|
||||
default: throw new IllegalArgumentException("Unknown enum value: " + value);
|
||||
}
|
||||
}
|
||||
|
@@ -285,6 +285,12 @@ struct JYogaValue : public JavaClass<JYogaValue> {
|
||||
YGNodeStyleSet##name##Percent(_jlong2YGNodeRef(nativePointer), static_cast<float>(value)); \
|
||||
}
|
||||
|
||||
#define YG_NODE_JNI_STYLE_UNIT_PROP_AUTO(name) \
|
||||
YG_NODE_JNI_STYLE_UNIT_PROP(name) \
|
||||
void jni_YGNodeStyleSet##name##Auto(alias_ref<jobject>, jlong nativePointer) { \
|
||||
YGNodeStyleSet##name##Auto(_jlong2YGNodeRef(nativePointer)); \
|
||||
}
|
||||
|
||||
#define YG_NODE_JNI_STYLE_EDGE_PROP(javatype, type, name) \
|
||||
javatype jni_YGNodeStyleGet##name(alias_ref<jobject>, jlong nativePointer, jint edge) { \
|
||||
return (javatype) YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer), \
|
||||
@@ -323,6 +329,12 @@ struct JYogaValue : public JavaClass<JYogaValue> {
|
||||
static_cast<float>(value)); \
|
||||
}
|
||||
|
||||
#define YG_NODE_JNI_STYLE_EDGE_UNIT_PROP_AUTO(name) \
|
||||
YG_NODE_JNI_STYLE_EDGE_UNIT_PROP(name) \
|
||||
void jni_YGNodeStyleSet##name##Auto(alias_ref<jobject>, jlong nativePointer, jint edge) { \
|
||||
YGNodeStyleSet##name##Auto(_jlong2YGNodeRef(nativePointer), static_cast<YGEdge>(edge)); \
|
||||
}
|
||||
|
||||
YG_NODE_JNI_STYLE_PROP(jint, YGDirection, Direction);
|
||||
YG_NODE_JNI_STYLE_PROP(jint, YGFlexDirection, FlexDirection);
|
||||
YG_NODE_JNI_STYLE_PROP(jint, YGJustify, JustifyContent);
|
||||
@@ -339,17 +351,17 @@ void jni_YGNodeStyleSetFlex(alias_ref<jobject>, jlong nativePointer, jfloat valu
|
||||
}
|
||||
YG_NODE_JNI_STYLE_PROP(jfloat, float, FlexGrow);
|
||||
YG_NODE_JNI_STYLE_PROP(jfloat, float, FlexShrink);
|
||||
YG_NODE_JNI_STYLE_UNIT_PROP(FlexBasis);
|
||||
YG_NODE_JNI_STYLE_UNIT_PROP_AUTO(FlexBasis);
|
||||
|
||||
YG_NODE_JNI_STYLE_EDGE_UNIT_PROP(Position);
|
||||
YG_NODE_JNI_STYLE_EDGE_UNIT_PROP(Margin);
|
||||
YG_NODE_JNI_STYLE_EDGE_UNIT_PROP_AUTO(Margin);
|
||||
YG_NODE_JNI_STYLE_EDGE_UNIT_PROP(Padding);
|
||||
YG_NODE_JNI_STYLE_EDGE_PROP(jfloat, float, Border);
|
||||
|
||||
YG_NODE_JNI_STYLE_UNIT_PROP(Width);
|
||||
YG_NODE_JNI_STYLE_UNIT_PROP_AUTO(Width);
|
||||
YG_NODE_JNI_STYLE_UNIT_PROP(MinWidth);
|
||||
YG_NODE_JNI_STYLE_UNIT_PROP(MaxWidth);
|
||||
YG_NODE_JNI_STYLE_UNIT_PROP(Height);
|
||||
YG_NODE_JNI_STYLE_UNIT_PROP_AUTO(Height);
|
||||
YG_NODE_JNI_STYLE_UNIT_PROP(MinHeight);
|
||||
YG_NODE_JNI_STYLE_UNIT_PROP(MaxHeight);
|
||||
|
||||
@@ -402,9 +414,11 @@ jint JNI_OnLoad(JavaVM *vm, void *) {
|
||||
YGMakeNativeMethod(jni_YGNodeStyleGetFlexBasis),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetFlexBasis),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetFlexBasisPercent),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetFlexBasisAuto),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleGetMargin),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetMargin),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetMarginPercent),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetMarginAuto),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleGetPadding),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetPadding),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetPaddingPercent),
|
||||
@@ -416,9 +430,11 @@ jint JNI_OnLoad(JavaVM *vm, void *) {
|
||||
YGMakeNativeMethod(jni_YGNodeStyleGetWidth),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetWidth),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetWidthPercent),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetWidthAuto),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleGetHeight),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetHeight),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetHeightPercent),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetHeightAuto),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleGetMinWidth),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetMinWidth),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetMinWidthPercent),
|
||||
|
@@ -425,4 +425,745 @@ public class YGMarginTest {
|
||||
assertEquals(45f, root_child1.getLayoutHeight(), 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_margin_auto_bottom() {
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setAlignItems(YogaAlign.CENTER);
|
||||
root.setWidth(200f);
|
||||
root.setHeight(200f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setMarginAuto(YogaEdge.BOTTOM);
|
||||
root_child0.setWidth(50f);
|
||||
root_child0.setHeight(50f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
root_child1.setWidth(50f);
|
||||
root_child1.setHeight(50f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(150f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(150f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_margin_auto_top() {
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setAlignItems(YogaAlign.CENTER);
|
||||
root.setWidth(200f);
|
||||
root.setHeight(200f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setMarginAuto(YogaEdge.TOP);
|
||||
root_child0.setWidth(50f);
|
||||
root_child0.setHeight(50f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
root_child1.setWidth(50f);
|
||||
root_child1.setHeight(50f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(100f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(150f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(100f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(150f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_margin_auto_bottom_and_top() {
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setAlignItems(YogaAlign.CENTER);
|
||||
root.setWidth(200f);
|
||||
root.setHeight(200f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setMarginAuto(YogaEdge.TOP);
|
||||
root_child0.setMarginAuto(YogaEdge.BOTTOM);
|
||||
root_child0.setWidth(50f);
|
||||
root_child0.setHeight(50f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
root_child1.setWidth(50f);
|
||||
root_child1.setHeight(50f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(150f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(150f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_margin_auto_bottom_and_top_justify_center() {
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setJustifyContent(YogaJustify.CENTER);
|
||||
root.setWidth(200f);
|
||||
root.setHeight(200f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setMarginAuto(YogaEdge.TOP);
|
||||
root_child0.setMarginAuto(YogaEdge.BOTTOM);
|
||||
root_child0.setWidth(50f);
|
||||
root_child0.setHeight(50f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
root_child1.setWidth(50f);
|
||||
root_child1.setHeight(50f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(150f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(150f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(150f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(150f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_margin_auto_mutiple_children_column() {
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setAlignItems(YogaAlign.CENTER);
|
||||
root.setWidth(200f);
|
||||
root.setHeight(200f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setMarginAuto(YogaEdge.TOP);
|
||||
root_child0.setWidth(50f);
|
||||
root_child0.setHeight(50f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
root_child1.setMarginAuto(YogaEdge.TOP);
|
||||
root_child1.setWidth(50f);
|
||||
root_child1.setHeight(50f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
|
||||
final YogaNode root_child2 = new YogaNode();
|
||||
root_child2.setWidth(50f);
|
||||
root_child2.setHeight(50f);
|
||||
root.addChildAt(root_child2, 2);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(25f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(100f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child2.getLayoutX(), 0.0f);
|
||||
assertEquals(150f, root_child2.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child2.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child2.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(25f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(100f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child2.getLayoutX(), 0.0f);
|
||||
assertEquals(150f, root_child2.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child2.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child2.getLayoutHeight(), 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_margin_auto_mutiple_children_row() {
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setFlexDirection(YogaFlexDirection.ROW);
|
||||
root.setAlignItems(YogaAlign.CENTER);
|
||||
root.setWidth(200f);
|
||||
root.setHeight(200f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setMarginAuto(YogaEdge.RIGHT);
|
||||
root_child0.setWidth(50f);
|
||||
root_child0.setHeight(50f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
root_child1.setMarginAuto(YogaEdge.RIGHT);
|
||||
root_child1.setWidth(50f);
|
||||
root_child1.setHeight(50f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
|
||||
final YogaNode root_child2 = new YogaNode();
|
||||
root_child2.setWidth(50f);
|
||||
root_child2.setHeight(50f);
|
||||
root.addChildAt(root_child2, 2);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(75f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(75f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(150f, root_child2.getLayoutX(), 0.0f);
|
||||
assertEquals(75f, root_child2.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child2.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child2.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(125f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(75f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(50f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(75f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child2.getLayoutX(), 0.0f);
|
||||
assertEquals(75f, root_child2.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child2.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child2.getLayoutHeight(), 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_margin_auto_left_and_right_column() {
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setFlexDirection(YogaFlexDirection.ROW);
|
||||
root.setAlignItems(YogaAlign.CENTER);
|
||||
root.setWidth(200f);
|
||||
root.setHeight(200f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setMarginAuto(YogaEdge.LEFT);
|
||||
root_child0.setMarginAuto(YogaEdge.RIGHT);
|
||||
root_child0.setWidth(50f);
|
||||
root_child0.setHeight(50f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
root_child1.setWidth(50f);
|
||||
root_child1.setHeight(50f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(50f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(75f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(150f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(75f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(100f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(75f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(75f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_margin_auto_left_and_right() {
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setWidth(200f);
|
||||
root.setHeight(200f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setMarginAuto(YogaEdge.LEFT);
|
||||
root_child0.setMarginAuto(YogaEdge.RIGHT);
|
||||
root_child0.setWidth(50f);
|
||||
root_child0.setHeight(50f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
root_child1.setWidth(50f);
|
||||
root_child1.setHeight(50f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(150f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_margin_auto_left_and_right_column_and_center() {
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setAlignItems(YogaAlign.CENTER);
|
||||
root.setWidth(200f);
|
||||
root.setHeight(200f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setMarginAuto(YogaEdge.LEFT);
|
||||
root_child0.setMarginAuto(YogaEdge.RIGHT);
|
||||
root_child0.setWidth(50f);
|
||||
root_child0.setHeight(50f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
root_child1.setWidth(50f);
|
||||
root_child1.setHeight(50f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_margin_auto_left() {
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setAlignItems(YogaAlign.CENTER);
|
||||
root.setWidth(200f);
|
||||
root.setHeight(200f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setMarginAuto(YogaEdge.LEFT);
|
||||
root_child0.setWidth(50f);
|
||||
root_child0.setHeight(50f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
root_child1.setWidth(50f);
|
||||
root_child1.setHeight(50f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(150f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(150f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_margin_auto_right() {
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setAlignItems(YogaAlign.CENTER);
|
||||
root.setWidth(200f);
|
||||
root.setHeight(200f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setMarginAuto(YogaEdge.RIGHT);
|
||||
root_child0.setWidth(50f);
|
||||
root_child0.setHeight(50f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
root_child1.setWidth(50f);
|
||||
root_child1.setHeight(50f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_margin_auto_left_and_right_strech() {
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setFlexDirection(YogaFlexDirection.ROW);
|
||||
root.setWidth(200f);
|
||||
root.setHeight(200f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setMarginAuto(YogaEdge.LEFT);
|
||||
root_child0.setMarginAuto(YogaEdge.RIGHT);
|
||||
root_child0.setWidth(50f);
|
||||
root_child0.setHeight(50f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
root_child1.setWidth(50f);
|
||||
root_child1.setHeight(50f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(50f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(150f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(100f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_margin_auto_top_and_bottom_strech() {
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setWidth(200f);
|
||||
root.setHeight(200f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setMarginAuto(YogaEdge.TOP);
|
||||
root_child0.setMarginAuto(YogaEdge.BOTTOM);
|
||||
root_child0.setWidth(50f);
|
||||
root_child0.setHeight(50f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
root_child1.setWidth(50f);
|
||||
root_child1.setHeight(50f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(150f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(150f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(150f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(150f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -119,6 +119,11 @@ void Node::setMarginPercent(int edge, double margin)
|
||||
YGNodeStyleSetMarginPercent(m_node, static_cast<YGEdge>(edge), margin);
|
||||
}
|
||||
|
||||
void Node::setMarginAuto(int edge)
|
||||
{
|
||||
YGNodeStyleSetMarginAuto(m_node, static_cast<YGEdge>(edge));
|
||||
}
|
||||
|
||||
void Node::setOverflow(int overflow)
|
||||
{
|
||||
YGNodeStyleSetOverflow(m_node, static_cast<YGOverflow>(overflow));
|
||||
@@ -164,6 +169,11 @@ void Node::setWidthPercent(double width)
|
||||
YGNodeStyleSetWidthPercent(m_node, width);
|
||||
}
|
||||
|
||||
void Node::setWidthAuto()
|
||||
{
|
||||
YGNodeStyleSetWidthAuto(m_node);
|
||||
}
|
||||
|
||||
void Node::setHeight(double height)
|
||||
{
|
||||
YGNodeStyleSetHeight(m_node, height);
|
||||
@@ -174,6 +184,11 @@ void Node::setHeightPercent(double height)
|
||||
YGNodeStyleSetHeightPercent(m_node, height);
|
||||
}
|
||||
|
||||
void Node::setHeightAuto()
|
||||
{
|
||||
YGNodeStyleSetHeightAuto(m_node);
|
||||
}
|
||||
|
||||
void Node::setMinWidth(double minWidth)
|
||||
{
|
||||
YGNodeStyleSetMinWidth(m_node, minWidth);
|
||||
|
@@ -65,6 +65,7 @@ class Node {
|
||||
|
||||
void setMargin(int edge, double margin);
|
||||
void setMarginPercent(int edge, double margin);
|
||||
void setMarginAuto(int edge);
|
||||
|
||||
void setOverflow(int overflow);
|
||||
void setDisplay(int display);
|
||||
@@ -72,13 +73,16 @@ class Node {
|
||||
void setFlex(double flex);
|
||||
void setFlexBasis(double flexBasis);
|
||||
void setFlexBasisPercent(double flexBasis);
|
||||
void setFlexBasisAuto();
|
||||
void setFlexGrow(double flexGrow);
|
||||
void setFlexShrink(double flexShrink);
|
||||
|
||||
void setWidth(double width);
|
||||
void setWidthPercent(double width);
|
||||
void setWidthAuto();
|
||||
void setHeight(double height);
|
||||
void setHeightPercent(double height);
|
||||
void setHeightAuto();
|
||||
|
||||
void setMinWidth(double minWidth);
|
||||
void setMinWidthPercent(double minWidth);
|
||||
|
@@ -86,10 +86,11 @@ module.exports = {
|
||||
PRINT_OPTIONS_STYLE: 2,
|
||||
PRINT_OPTIONS_CHILDREN: 4,
|
||||
|
||||
UNIT_COUNT: 3,
|
||||
UNIT_COUNT: 4,
|
||||
UNIT_UNDEFINED: 0,
|
||||
UNIT_PIXEL: 1,
|
||||
UNIT_PERCENT: 2,
|
||||
UNIT_AUTO: 3,
|
||||
|
||||
WRAP_COUNT: 2,
|
||||
WRAP_NO_WRAP: 0,
|
||||
|
@@ -107,6 +107,9 @@ module.exports = function (bind, lib) {
|
||||
|
||||
case constants.UNIT_PERCENT:
|
||||
return `${this.value}%`;
|
||||
|
||||
case constants.UNIT_AUTO:
|
||||
return `auto`;
|
||||
|
||||
default: {
|
||||
return `${this.value}?`;
|
||||
|
@@ -65,6 +65,7 @@ NBIND_CLASS(Node)
|
||||
|
||||
method(setMargin);
|
||||
method(setMarginPercent);
|
||||
method(setMarginAuto);
|
||||
|
||||
method(setOverflow);
|
||||
method(setDisplay);
|
||||
@@ -77,8 +78,10 @@ NBIND_CLASS(Node)
|
||||
|
||||
method(setWidth);
|
||||
method(setWidthPercent);
|
||||
method(setWidthAuto);
|
||||
method(setHeight);
|
||||
method(setHeightPercent);
|
||||
method(setHeightAuto);
|
||||
|
||||
method(setMinWidth);
|
||||
method(setMinWidthPercent);
|
||||
|
@@ -440,3 +440,770 @@ it("margin_with_sibling_column", function () {
|
||||
(typeof gc !== "undefined") && gc();
|
||||
console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")");
|
||||
});
|
||||
it("margin_auto_bottom", function () {
|
||||
var root = Yoga.Node.create();
|
||||
root.setAlignItems(Yoga.ALIGN_CENTER);
|
||||
root.setWidth(200);
|
||||
root.setHeight(200);
|
||||
|
||||
var root_child0 = Yoga.Node.create();
|
||||
root_child0.setMargin(Yoga.EDGE_BOTTOM, "auto");
|
||||
root_child0.setWidth(50);
|
||||
root_child0.setHeight(50);
|
||||
root.insertChild(root_child0, 0);
|
||||
|
||||
var root_child1 = Yoga.Node.create();
|
||||
root_child1.setWidth(50);
|
||||
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(200 === root.getComputedWidth(), "200 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
|
||||
console.assert(200 === root.getComputedHeight(), "200 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
|
||||
|
||||
console.assert(75 === root_child0.getComputedLeft(), "75 === 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(75 === root_child1.getComputedLeft(), "75 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
|
||||
console.assert(150 === root_child1.getComputedTop(), "150 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
|
||||
console.assert(50 === root_child1.getComputedWidth(), "50 === 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(200 === root.getComputedWidth(), "200 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
|
||||
console.assert(200 === root.getComputedHeight(), "200 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
|
||||
|
||||
console.assert(75 === root_child0.getComputedLeft(), "75 === 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(75 === root_child1.getComputedLeft(), "75 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
|
||||
console.assert(150 === root_child1.getComputedTop(), "150 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
|
||||
console.assert(50 === root_child1.getComputedWidth(), "50 === 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() + ")");
|
||||
});
|
||||
it("margin_auto_top", function () {
|
||||
var root = Yoga.Node.create();
|
||||
root.setAlignItems(Yoga.ALIGN_CENTER);
|
||||
root.setWidth(200);
|
||||
root.setHeight(200);
|
||||
|
||||
var root_child0 = Yoga.Node.create();
|
||||
root_child0.setMargin(Yoga.EDGE_TOP, "auto");
|
||||
root_child0.setWidth(50);
|
||||
root_child0.setHeight(50);
|
||||
root.insertChild(root_child0, 0);
|
||||
|
||||
var root_child1 = Yoga.Node.create();
|
||||
root_child1.setWidth(50);
|
||||
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(200 === root.getComputedWidth(), "200 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
|
||||
console.assert(200 === root.getComputedHeight(), "200 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
|
||||
|
||||
console.assert(75 === root_child0.getComputedLeft(), "75 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
|
||||
console.assert(100 === root_child0.getComputedTop(), "100 === 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(75 === root_child1.getComputedLeft(), "75 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
|
||||
console.assert(150 === root_child1.getComputedTop(), "150 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
|
||||
console.assert(50 === root_child1.getComputedWidth(), "50 === 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(200 === root.getComputedWidth(), "200 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
|
||||
console.assert(200 === root.getComputedHeight(), "200 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
|
||||
|
||||
console.assert(75 === root_child0.getComputedLeft(), "75 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
|
||||
console.assert(100 === root_child0.getComputedTop(), "100 === 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(75 === root_child1.getComputedLeft(), "75 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
|
||||
console.assert(150 === root_child1.getComputedTop(), "150 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
|
||||
console.assert(50 === root_child1.getComputedWidth(), "50 === 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() + ")");
|
||||
});
|
||||
it("margin_auto_bottom_and_top", function () {
|
||||
var root = Yoga.Node.create();
|
||||
root.setAlignItems(Yoga.ALIGN_CENTER);
|
||||
root.setWidth(200);
|
||||
root.setHeight(200);
|
||||
|
||||
var root_child0 = Yoga.Node.create();
|
||||
root_child0.setMargin(Yoga.EDGE_TOP, "auto");
|
||||
root_child0.setMargin(Yoga.EDGE_BOTTOM, "auto");
|
||||
root_child0.setWidth(50);
|
||||
root_child0.setHeight(50);
|
||||
root.insertChild(root_child0, 0);
|
||||
|
||||
var root_child1 = Yoga.Node.create();
|
||||
root_child1.setWidth(50);
|
||||
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(200 === root.getComputedWidth(), "200 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
|
||||
console.assert(200 === root.getComputedHeight(), "200 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
|
||||
|
||||
console.assert(75 === root_child0.getComputedLeft(), "75 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
|
||||
console.assert(50 === root_child0.getComputedTop(), "50 === 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(75 === root_child1.getComputedLeft(), "75 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
|
||||
console.assert(150 === root_child1.getComputedTop(), "150 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
|
||||
console.assert(50 === root_child1.getComputedWidth(), "50 === 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(200 === root.getComputedWidth(), "200 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
|
||||
console.assert(200 === root.getComputedHeight(), "200 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
|
||||
|
||||
console.assert(75 === root_child0.getComputedLeft(), "75 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
|
||||
console.assert(50 === root_child0.getComputedTop(), "50 === 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(75 === root_child1.getComputedLeft(), "75 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
|
||||
console.assert(150 === root_child1.getComputedTop(), "150 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
|
||||
console.assert(50 === root_child1.getComputedWidth(), "50 === 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() + ")");
|
||||
});
|
||||
it("margin_auto_bottom_and_top_justify_center", function () {
|
||||
var root = Yoga.Node.create();
|
||||
root.setJustifyContent(Yoga.JUSTIFY_CENTER);
|
||||
root.setWidth(200);
|
||||
root.setHeight(200);
|
||||
|
||||
var root_child0 = Yoga.Node.create();
|
||||
root_child0.setMargin(Yoga.EDGE_TOP, "auto");
|
||||
root_child0.setMargin(Yoga.EDGE_BOTTOM, "auto");
|
||||
root_child0.setWidth(50);
|
||||
root_child0.setHeight(50);
|
||||
root.insertChild(root_child0, 0);
|
||||
|
||||
var root_child1 = Yoga.Node.create();
|
||||
root_child1.setWidth(50);
|
||||
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(200 === root.getComputedWidth(), "200 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
|
||||
console.assert(200 === root.getComputedHeight(), "200 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
|
||||
|
||||
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
|
||||
console.assert(50 === root_child0.getComputedTop(), "50 === 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(150 === root_child1.getComputedTop(), "150 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
|
||||
console.assert(50 === root_child1.getComputedWidth(), "50 === 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(200 === root.getComputedWidth(), "200 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
|
||||
console.assert(200 === root.getComputedHeight(), "200 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
|
||||
|
||||
console.assert(150 === root_child0.getComputedLeft(), "150 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
|
||||
console.assert(50 === root_child0.getComputedTop(), "50 === 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(150 === root_child1.getComputedLeft(), "150 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
|
||||
console.assert(150 === root_child1.getComputedTop(), "150 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
|
||||
console.assert(50 === root_child1.getComputedWidth(), "50 === 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() + ")");
|
||||
});
|
||||
it("margin_auto_mutiple_children_column", function () {
|
||||
var root = Yoga.Node.create();
|
||||
root.setAlignItems(Yoga.ALIGN_CENTER);
|
||||
root.setWidth(200);
|
||||
root.setHeight(200);
|
||||
|
||||
var root_child0 = Yoga.Node.create();
|
||||
root_child0.setMargin(Yoga.EDGE_TOP, "auto");
|
||||
root_child0.setWidth(50);
|
||||
root_child0.setHeight(50);
|
||||
root.insertChild(root_child0, 0);
|
||||
|
||||
var root_child1 = Yoga.Node.create();
|
||||
root_child1.setMargin(Yoga.EDGE_TOP, "auto");
|
||||
root_child1.setWidth(50);
|
||||
root_child1.setHeight(50);
|
||||
root.insertChild(root_child1, 1);
|
||||
|
||||
var root_child2 = Yoga.Node.create();
|
||||
root_child2.setWidth(50);
|
||||
root_child2.setHeight(50);
|
||||
root.insertChild(root_child2, 2);
|
||||
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(200 === root.getComputedWidth(), "200 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
|
||||
console.assert(200 === root.getComputedHeight(), "200 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
|
||||
|
||||
console.assert(75 === root_child0.getComputedLeft(), "75 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
|
||||
console.assert(25 === root_child0.getComputedTop(), "25 === 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(75 === root_child1.getComputedLeft(), "75 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
|
||||
console.assert(100 === root_child1.getComputedTop(), "100 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
|
||||
console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")");
|
||||
console.assert(50 === root_child1.getComputedHeight(), "50 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
|
||||
|
||||
console.assert(75 === root_child2.getComputedLeft(), "75 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")");
|
||||
console.assert(150 === root_child2.getComputedTop(), "150 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")");
|
||||
console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")");
|
||||
console.assert(50 === root_child2.getComputedHeight(), "50 === root_child2.getComputedHeight() (" + root_child2.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(200 === root.getComputedWidth(), "200 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
|
||||
console.assert(200 === root.getComputedHeight(), "200 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
|
||||
|
||||
console.assert(75 === root_child0.getComputedLeft(), "75 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
|
||||
console.assert(25 === root_child0.getComputedTop(), "25 === 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(75 === root_child1.getComputedLeft(), "75 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
|
||||
console.assert(100 === root_child1.getComputedTop(), "100 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
|
||||
console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")");
|
||||
console.assert(50 === root_child1.getComputedHeight(), "50 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
|
||||
|
||||
console.assert(75 === root_child2.getComputedLeft(), "75 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")");
|
||||
console.assert(150 === root_child2.getComputedTop(), "150 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")");
|
||||
console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")");
|
||||
console.assert(50 === root_child2.getComputedHeight(), "50 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")");
|
||||
|
||||
if (typeof root !== "undefined")
|
||||
root.freeRecursive();
|
||||
|
||||
(typeof gc !== "undefined") && gc();
|
||||
console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")");
|
||||
});
|
||||
it("margin_auto_mutiple_children_row", function () {
|
||||
var root = Yoga.Node.create();
|
||||
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
|
||||
root.setAlignItems(Yoga.ALIGN_CENTER);
|
||||
root.setWidth(200);
|
||||
root.setHeight(200);
|
||||
|
||||
var root_child0 = Yoga.Node.create();
|
||||
root_child0.setMargin(Yoga.EDGE_RIGHT, "auto");
|
||||
root_child0.setWidth(50);
|
||||
root_child0.setHeight(50);
|
||||
root.insertChild(root_child0, 0);
|
||||
|
||||
var root_child1 = Yoga.Node.create();
|
||||
root_child1.setMargin(Yoga.EDGE_RIGHT, "auto");
|
||||
root_child1.setWidth(50);
|
||||
root_child1.setHeight(50);
|
||||
root.insertChild(root_child1, 1);
|
||||
|
||||
var root_child2 = Yoga.Node.create();
|
||||
root_child2.setWidth(50);
|
||||
root_child2.setHeight(50);
|
||||
root.insertChild(root_child2, 2);
|
||||
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(200 === root.getComputedWidth(), "200 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
|
||||
console.assert(200 === root.getComputedHeight(), "200 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
|
||||
|
||||
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
|
||||
console.assert(75 === root_child0.getComputedTop(), "75 === 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(75 === root_child1.getComputedLeft(), "75 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
|
||||
console.assert(75 === root_child1.getComputedTop(), "75 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
|
||||
console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")");
|
||||
console.assert(50 === root_child1.getComputedHeight(), "50 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
|
||||
|
||||
console.assert(150 === root_child2.getComputedLeft(), "150 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")");
|
||||
console.assert(75 === root_child2.getComputedTop(), "75 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")");
|
||||
console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")");
|
||||
console.assert(50 === root_child2.getComputedHeight(), "50 === root_child2.getComputedHeight() (" + root_child2.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(200 === root.getComputedWidth(), "200 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
|
||||
console.assert(200 === root.getComputedHeight(), "200 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
|
||||
|
||||
console.assert(125 === root_child0.getComputedLeft(), "125 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
|
||||
console.assert(75 === root_child0.getComputedTop(), "75 === 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(75 === root_child1.getComputedTop(), "75 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
|
||||
console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")");
|
||||
console.assert(50 === root_child1.getComputedHeight(), "50 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
|
||||
|
||||
console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")");
|
||||
console.assert(75 === root_child2.getComputedTop(), "75 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")");
|
||||
console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")");
|
||||
console.assert(50 === root_child2.getComputedHeight(), "50 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")");
|
||||
|
||||
if (typeof root !== "undefined")
|
||||
root.freeRecursive();
|
||||
|
||||
(typeof gc !== "undefined") && gc();
|
||||
console.assert(0 === Yoga.getInstanceCount(), "0 === Yoga.getInstanceCount() (" + Yoga.getInstanceCount() + ")");
|
||||
});
|
||||
it("margin_auto_left_and_right_column", function () {
|
||||
var root = Yoga.Node.create();
|
||||
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
|
||||
root.setAlignItems(Yoga.ALIGN_CENTER);
|
||||
root.setWidth(200);
|
||||
root.setHeight(200);
|
||||
|
||||
var root_child0 = Yoga.Node.create();
|
||||
root_child0.setMargin(Yoga.EDGE_LEFT, "auto");
|
||||
root_child0.setMargin(Yoga.EDGE_RIGHT, "auto");
|
||||
root_child0.setWidth(50);
|
||||
root_child0.setHeight(50);
|
||||
root.insertChild(root_child0, 0);
|
||||
|
||||
var root_child1 = Yoga.Node.create();
|
||||
root_child1.setWidth(50);
|
||||
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(200 === root.getComputedWidth(), "200 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
|
||||
console.assert(200 === root.getComputedHeight(), "200 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
|
||||
|
||||
console.assert(50 === root_child0.getComputedLeft(), "50 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
|
||||
console.assert(75 === root_child0.getComputedTop(), "75 === 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(150 === root_child1.getComputedLeft(), "150 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
|
||||
console.assert(75 === root_child1.getComputedTop(), "75 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
|
||||
console.assert(50 === root_child1.getComputedWidth(), "50 === 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(200 === root.getComputedWidth(), "200 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
|
||||
console.assert(200 === root.getComputedHeight(), "200 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
|
||||
|
||||
console.assert(100 === root_child0.getComputedLeft(), "100 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
|
||||
console.assert(75 === root_child0.getComputedTop(), "75 === 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(75 === root_child1.getComputedTop(), "75 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
|
||||
console.assert(50 === root_child1.getComputedWidth(), "50 === 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() + ")");
|
||||
});
|
||||
it("margin_auto_left_and_right", function () {
|
||||
var root = Yoga.Node.create();
|
||||
root.setWidth(200);
|
||||
root.setHeight(200);
|
||||
|
||||
var root_child0 = Yoga.Node.create();
|
||||
root_child0.setMargin(Yoga.EDGE_LEFT, "auto");
|
||||
root_child0.setMargin(Yoga.EDGE_RIGHT, "auto");
|
||||
root_child0.setWidth(50);
|
||||
root_child0.setHeight(50);
|
||||
root.insertChild(root_child0, 0);
|
||||
|
||||
var root_child1 = Yoga.Node.create();
|
||||
root_child1.setWidth(50);
|
||||
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(200 === root.getComputedWidth(), "200 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
|
||||
console.assert(200 === root.getComputedHeight(), "200 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
|
||||
|
||||
console.assert(75 === root_child0.getComputedLeft(), "75 === 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(50 === root_child1.getComputedTop(), "50 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
|
||||
console.assert(50 === root_child1.getComputedWidth(), "50 === 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(200 === root.getComputedWidth(), "200 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
|
||||
console.assert(200 === root.getComputedHeight(), "200 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
|
||||
|
||||
console.assert(75 === root_child0.getComputedLeft(), "75 === 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(150 === root_child1.getComputedLeft(), "150 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
|
||||
console.assert(50 === root_child1.getComputedTop(), "50 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
|
||||
console.assert(50 === root_child1.getComputedWidth(), "50 === 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() + ")");
|
||||
});
|
||||
it("margin_auto_left_and_right_column_and_center", function () {
|
||||
var root = Yoga.Node.create();
|
||||
root.setAlignItems(Yoga.ALIGN_CENTER);
|
||||
root.setWidth(200);
|
||||
root.setHeight(200);
|
||||
|
||||
var root_child0 = Yoga.Node.create();
|
||||
root_child0.setMargin(Yoga.EDGE_LEFT, "auto");
|
||||
root_child0.setMargin(Yoga.EDGE_RIGHT, "auto");
|
||||
root_child0.setWidth(50);
|
||||
root_child0.setHeight(50);
|
||||
root.insertChild(root_child0, 0);
|
||||
|
||||
var root_child1 = Yoga.Node.create();
|
||||
root_child1.setWidth(50);
|
||||
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(200 === root.getComputedWidth(), "200 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
|
||||
console.assert(200 === root.getComputedHeight(), "200 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
|
||||
|
||||
console.assert(75 === root_child0.getComputedLeft(), "75 === 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(75 === root_child1.getComputedLeft(), "75 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
|
||||
console.assert(50 === root_child1.getComputedTop(), "50 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
|
||||
console.assert(50 === root_child1.getComputedWidth(), "50 === 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(200 === root.getComputedWidth(), "200 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
|
||||
console.assert(200 === root.getComputedHeight(), "200 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
|
||||
|
||||
console.assert(75 === root_child0.getComputedLeft(), "75 === 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(75 === root_child1.getComputedLeft(), "75 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
|
||||
console.assert(50 === root_child1.getComputedTop(), "50 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
|
||||
console.assert(50 === root_child1.getComputedWidth(), "50 === 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() + ")");
|
||||
});
|
||||
it("margin_auto_left", function () {
|
||||
var root = Yoga.Node.create();
|
||||
root.setAlignItems(Yoga.ALIGN_CENTER);
|
||||
root.setWidth(200);
|
||||
root.setHeight(200);
|
||||
|
||||
var root_child0 = Yoga.Node.create();
|
||||
root_child0.setMargin(Yoga.EDGE_LEFT, "auto");
|
||||
root_child0.setWidth(50);
|
||||
root_child0.setHeight(50);
|
||||
root.insertChild(root_child0, 0);
|
||||
|
||||
var root_child1 = Yoga.Node.create();
|
||||
root_child1.setWidth(50);
|
||||
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(200 === root.getComputedWidth(), "200 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
|
||||
console.assert(200 === root.getComputedHeight(), "200 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
|
||||
|
||||
console.assert(150 === root_child0.getComputedLeft(), "150 === 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(75 === root_child1.getComputedLeft(), "75 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
|
||||
console.assert(50 === root_child1.getComputedTop(), "50 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
|
||||
console.assert(50 === root_child1.getComputedWidth(), "50 === 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(200 === root.getComputedWidth(), "200 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
|
||||
console.assert(200 === root.getComputedHeight(), "200 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
|
||||
|
||||
console.assert(150 === root_child0.getComputedLeft(), "150 === 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(75 === root_child1.getComputedLeft(), "75 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
|
||||
console.assert(50 === root_child1.getComputedTop(), "50 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
|
||||
console.assert(50 === root_child1.getComputedWidth(), "50 === 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() + ")");
|
||||
});
|
||||
it("margin_auto_right", function () {
|
||||
var root = Yoga.Node.create();
|
||||
root.setAlignItems(Yoga.ALIGN_CENTER);
|
||||
root.setWidth(200);
|
||||
root.setHeight(200);
|
||||
|
||||
var root_child0 = Yoga.Node.create();
|
||||
root_child0.setMargin(Yoga.EDGE_RIGHT, "auto");
|
||||
root_child0.setWidth(50);
|
||||
root_child0.setHeight(50);
|
||||
root.insertChild(root_child0, 0);
|
||||
|
||||
var root_child1 = Yoga.Node.create();
|
||||
root_child1.setWidth(50);
|
||||
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(200 === root.getComputedWidth(), "200 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
|
||||
console.assert(200 === root.getComputedHeight(), "200 === 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(75 === root_child1.getComputedLeft(), "75 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
|
||||
console.assert(50 === root_child1.getComputedTop(), "50 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
|
||||
console.assert(50 === root_child1.getComputedWidth(), "50 === 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(200 === root.getComputedWidth(), "200 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
|
||||
console.assert(200 === root.getComputedHeight(), "200 === 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(75 === root_child1.getComputedLeft(), "75 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
|
||||
console.assert(50 === root_child1.getComputedTop(), "50 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
|
||||
console.assert(50 === root_child1.getComputedWidth(), "50 === 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() + ")");
|
||||
});
|
||||
it("margin_auto_left_and_right_strech", function () {
|
||||
var root = Yoga.Node.create();
|
||||
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
|
||||
root.setWidth(200);
|
||||
root.setHeight(200);
|
||||
|
||||
var root_child0 = Yoga.Node.create();
|
||||
root_child0.setMargin(Yoga.EDGE_LEFT, "auto");
|
||||
root_child0.setMargin(Yoga.EDGE_RIGHT, "auto");
|
||||
root_child0.setWidth(50);
|
||||
root_child0.setHeight(50);
|
||||
root.insertChild(root_child0, 0);
|
||||
|
||||
var root_child1 = Yoga.Node.create();
|
||||
root_child1.setWidth(50);
|
||||
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(200 === root.getComputedWidth(), "200 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
|
||||
console.assert(200 === root.getComputedHeight(), "200 === 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(150 === root_child1.getComputedLeft(), "150 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
|
||||
console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
|
||||
console.assert(50 === root_child1.getComputedWidth(), "50 === 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(200 === root.getComputedWidth(), "200 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
|
||||
console.assert(200 === root.getComputedHeight(), "200 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
|
||||
|
||||
console.assert(100 === root_child0.getComputedLeft(), "100 === 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(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
|
||||
console.assert(50 === root_child1.getComputedWidth(), "50 === 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() + ")");
|
||||
});
|
||||
it("margin_auto_top_and_bottom_strech", function () {
|
||||
var root = Yoga.Node.create();
|
||||
root.setWidth(200);
|
||||
root.setHeight(200);
|
||||
|
||||
var root_child0 = Yoga.Node.create();
|
||||
root_child0.setMargin(Yoga.EDGE_TOP, "auto");
|
||||
root_child0.setMargin(Yoga.EDGE_BOTTOM, "auto");
|
||||
root_child0.setWidth(50);
|
||||
root_child0.setHeight(50);
|
||||
root.insertChild(root_child0, 0);
|
||||
|
||||
var root_child1 = Yoga.Node.create();
|
||||
root_child1.setWidth(50);
|
||||
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(200 === root.getComputedWidth(), "200 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
|
||||
console.assert(200 === root.getComputedHeight(), "200 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
|
||||
|
||||
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
|
||||
console.assert(50 === root_child0.getComputedTop(), "50 === 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(150 === root_child1.getComputedTop(), "150 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
|
||||
console.assert(50 === root_child1.getComputedWidth(), "50 === 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(200 === root.getComputedWidth(), "200 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
|
||||
console.assert(200 === root.getComputedHeight(), "200 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
|
||||
|
||||
console.assert(150 === root_child0.getComputedLeft(), "150 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
|
||||
console.assert(50 === root_child0.getComputedTop(), "50 === 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(150 === root_child1.getComputedLeft(), "150 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
|
||||
console.assert(150 === root_child1.getComputedTop(), "150 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
|
||||
console.assert(50 === root_child1.getComputedWidth(), "50 === 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() + ")");
|
||||
});
|
||||
|
@@ -27,7 +27,7 @@ TEST(YogaTest, assert_default_values) {
|
||||
ASSERT_EQ(YGOverflowVisible, YGNodeStyleGetOverflow(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeStyleGetFlexGrow(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeStyleGetFlexShrink(root));
|
||||
ASSERT_FALSE(YGNodeStyleGetFlexBasis(root).unit != YGUnitUndefined);
|
||||
ASSERT_FALSE(YGNodeStyleGetFlexBasis(root).unit != YGUnitAuto);
|
||||
|
||||
ASSERT_EQ(YGNodeStyleGetPosition(root, YGEdgeLeft).unit, YGUnitUndefined);
|
||||
ASSERT_EQ(YGNodeStyleGetPosition(root, YGEdgeTop).unit, YGUnitUndefined);
|
||||
@@ -57,8 +57,8 @@ TEST(YogaTest, assert_default_values) {
|
||||
ASSERT_TRUE(YGFloatIsUndefined(YGNodeStyleGetBorder(root, YGEdgeStart)));
|
||||
ASSERT_TRUE(YGFloatIsUndefined(YGNodeStyleGetBorder(root, YGEdgeEnd)));
|
||||
|
||||
ASSERT_EQ(YGNodeStyleGetWidth(root).unit, YGUnitUndefined);
|
||||
ASSERT_EQ(YGNodeStyleGetHeight(root).unit, YGUnitUndefined);
|
||||
ASSERT_EQ(YGNodeStyleGetWidth(root).unit, YGUnitAuto);
|
||||
ASSERT_EQ(YGNodeStyleGetHeight(root).unit, YGUnitAuto);
|
||||
ASSERT_EQ(YGNodeStyleGetMinWidth(root).unit, YGUnitUndefined);
|
||||
ASSERT_EQ(YGNodeStyleGetMinHeight(root).unit, YGUnitUndefined);
|
||||
ASSERT_EQ(YGNodeStyleGetMaxWidth(root).unit, YGUnitUndefined);
|
||||
|
@@ -410,3 +410,731 @@ TEST(YogaTest, margin_with_sibling_column) {
|
||||
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
TEST(YogaTest, margin_auto_bottom) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
YGNodeStyleSetAlignItems(root, YGAlignCenter);
|
||||
YGNodeStyleSetWidth(root, 200);
|
||||
YGNodeStyleSetHeight(root, 200);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeStyleSetMarginAuto(root_child0, YGEdgeBottom);
|
||||
YGNodeStyleSetWidth(root_child0, 50);
|
||||
YGNodeStyleSetHeight(root_child0, 50);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
const YGNodeRef root_child1 = YGNodeNew();
|
||||
YGNodeStyleSetWidth(root_child1, 50);
|
||||
YGNodeStyleSetHeight(root_child1, 50);
|
||||
YGNodeInsertChild(root, root_child1, 1);
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1));
|
||||
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetTop(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1));
|
||||
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetTop(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
TEST(YogaTest, margin_auto_top) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
YGNodeStyleSetAlignItems(root, YGAlignCenter);
|
||||
YGNodeStyleSetWidth(root, 200);
|
||||
YGNodeStyleSetHeight(root, 200);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeStyleSetMarginAuto(root_child0, YGEdgeTop);
|
||||
YGNodeStyleSetWidth(root_child0, 50);
|
||||
YGNodeStyleSetHeight(root_child0, 50);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
const YGNodeRef root_child1 = YGNodeNew();
|
||||
YGNodeStyleSetWidth(root_child1, 50);
|
||||
YGNodeStyleSetHeight(root_child1, 50);
|
||||
YGNodeInsertChild(root, root_child1, 1);
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1));
|
||||
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetTop(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1));
|
||||
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetTop(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
TEST(YogaTest, margin_auto_bottom_and_top) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
YGNodeStyleSetAlignItems(root, YGAlignCenter);
|
||||
YGNodeStyleSetWidth(root, 200);
|
||||
YGNodeStyleSetHeight(root, 200);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeStyleSetMarginAuto(root_child0, YGEdgeTop);
|
||||
YGNodeStyleSetMarginAuto(root_child0, YGEdgeBottom);
|
||||
YGNodeStyleSetWidth(root_child0, 50);
|
||||
YGNodeStyleSetHeight(root_child0, 50);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
const YGNodeRef root_child1 = YGNodeNew();
|
||||
YGNodeStyleSetWidth(root_child1, 50);
|
||||
YGNodeStyleSetHeight(root_child1, 50);
|
||||
YGNodeInsertChild(root, root_child1, 1);
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1));
|
||||
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetTop(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1));
|
||||
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetTop(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
TEST(YogaTest, margin_auto_bottom_and_top_justify_center) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
YGNodeStyleSetJustifyContent(root, YGJustifyCenter);
|
||||
YGNodeStyleSetWidth(root, 200);
|
||||
YGNodeStyleSetHeight(root, 200);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeStyleSetMarginAuto(root_child0, YGEdgeTop);
|
||||
YGNodeStyleSetMarginAuto(root_child0, YGEdgeBottom);
|
||||
YGNodeStyleSetWidth(root_child0, 50);
|
||||
YGNodeStyleSetHeight(root_child0, 50);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
const YGNodeRef root_child1 = YGNodeNew();
|
||||
YGNodeStyleSetWidth(root_child1, 50);
|
||||
YGNodeStyleSetHeight(root_child1, 50);
|
||||
YGNodeInsertChild(root, root_child1, 1);
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
|
||||
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetTop(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetLeft(root_child1));
|
||||
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetTop(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
TEST(YogaTest, margin_auto_mutiple_children_column) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
YGNodeStyleSetAlignItems(root, YGAlignCenter);
|
||||
YGNodeStyleSetWidth(root, 200);
|
||||
YGNodeStyleSetHeight(root, 200);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeStyleSetMarginAuto(root_child0, YGEdgeTop);
|
||||
YGNodeStyleSetWidth(root_child0, 50);
|
||||
YGNodeStyleSetHeight(root_child0, 50);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
const YGNodeRef root_child1 = YGNodeNew();
|
||||
YGNodeStyleSetMarginAuto(root_child1, YGEdgeTop);
|
||||
YGNodeStyleSetWidth(root_child1, 50);
|
||||
YGNodeStyleSetHeight(root_child1, 50);
|
||||
YGNodeInsertChild(root, root_child1, 1);
|
||||
|
||||
const YGNodeRef root_child2 = YGNodeNew();
|
||||
YGNodeStyleSetWidth(root_child2, 50);
|
||||
YGNodeStyleSetHeight(root_child2, 50);
|
||||
YGNodeInsertChild(root, root_child2, 2);
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(25, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1));
|
||||
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child2));
|
||||
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetTop(root_child2));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2));
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(25, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1));
|
||||
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child2));
|
||||
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetTop(root_child2));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2));
|
||||
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
TEST(YogaTest, margin_auto_mutiple_children_row) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
||||
YGNodeStyleSetAlignItems(root, YGAlignCenter);
|
||||
YGNodeStyleSetWidth(root, 200);
|
||||
YGNodeStyleSetHeight(root, 200);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeStyleSetMarginAuto(root_child0, YGEdgeRight);
|
||||
YGNodeStyleSetWidth(root_child0, 50);
|
||||
YGNodeStyleSetHeight(root_child0, 50);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
const YGNodeRef root_child1 = YGNodeNew();
|
||||
YGNodeStyleSetMarginAuto(root_child1, YGEdgeRight);
|
||||
YGNodeStyleSetWidth(root_child1, 50);
|
||||
YGNodeStyleSetHeight(root_child1, 50);
|
||||
YGNodeInsertChild(root, root_child1, 1);
|
||||
|
||||
const YGNodeRef root_child2 = YGNodeNew();
|
||||
YGNodeStyleSetWidth(root_child2, 50);
|
||||
YGNodeStyleSetHeight(root_child2, 50);
|
||||
YGNodeInsertChild(root, root_child2, 2);
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1));
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetTop(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||
|
||||
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetLeft(root_child2));
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetTop(root_child2));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2));
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(125, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1));
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetTop(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2));
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetTop(root_child2));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2));
|
||||
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
TEST(YogaTest, margin_auto_left_and_right_column) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
||||
YGNodeStyleSetAlignItems(root, YGAlignCenter);
|
||||
YGNodeStyleSetWidth(root, 200);
|
||||
YGNodeStyleSetHeight(root, 200);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeStyleSetMarginAuto(root_child0, YGEdgeLeft);
|
||||
YGNodeStyleSetMarginAuto(root_child0, YGEdgeRight);
|
||||
YGNodeStyleSetWidth(root_child0, 50);
|
||||
YGNodeStyleSetHeight(root_child0, 50);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
const YGNodeRef root_child1 = YGNodeNew();
|
||||
YGNodeStyleSetWidth(root_child1, 50);
|
||||
YGNodeStyleSetHeight(root_child1, 50);
|
||||
YGNodeInsertChild(root, root_child1, 1);
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetLeft(root_child1));
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetTop(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetTop(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
TEST(YogaTest, margin_auto_left_and_right) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
YGNodeStyleSetWidth(root, 200);
|
||||
YGNodeStyleSetHeight(root, 200);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeStyleSetMarginAuto(root_child0, YGEdgeLeft);
|
||||
YGNodeStyleSetMarginAuto(root_child0, YGEdgeRight);
|
||||
YGNodeStyleSetWidth(root_child0, 50);
|
||||
YGNodeStyleSetHeight(root_child0, 50);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
const YGNodeRef root_child1 = YGNodeNew();
|
||||
YGNodeStyleSetWidth(root_child1, 50);
|
||||
YGNodeStyleSetHeight(root_child1, 50);
|
||||
YGNodeInsertChild(root, root_child1, 1);
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetLeft(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
TEST(YogaTest, margin_auto_left_and_right_column_and_center) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
YGNodeStyleSetAlignItems(root, YGAlignCenter);
|
||||
YGNodeStyleSetWidth(root, 200);
|
||||
YGNodeStyleSetHeight(root, 200);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeStyleSetMarginAuto(root_child0, YGEdgeLeft);
|
||||
YGNodeStyleSetMarginAuto(root_child0, YGEdgeRight);
|
||||
YGNodeStyleSetWidth(root_child0, 50);
|
||||
YGNodeStyleSetHeight(root_child0, 50);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
const YGNodeRef root_child1 = YGNodeNew();
|
||||
YGNodeStyleSetWidth(root_child1, 50);
|
||||
YGNodeStyleSetHeight(root_child1, 50);
|
||||
YGNodeInsertChild(root, root_child1, 1);
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
TEST(YogaTest, margin_auto_left) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
YGNodeStyleSetAlignItems(root, YGAlignCenter);
|
||||
YGNodeStyleSetWidth(root, 200);
|
||||
YGNodeStyleSetHeight(root, 200);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeStyleSetMarginAuto(root_child0, YGEdgeLeft);
|
||||
YGNodeStyleSetWidth(root_child0, 50);
|
||||
YGNodeStyleSetHeight(root_child0, 50);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
const YGNodeRef root_child1 = YGNodeNew();
|
||||
YGNodeStyleSetWidth(root_child1, 50);
|
||||
YGNodeStyleSetHeight(root_child1, 50);
|
||||
YGNodeInsertChild(root, root_child1, 1);
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
TEST(YogaTest, margin_auto_right) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
YGNodeStyleSetAlignItems(root, YGAlignCenter);
|
||||
YGNodeStyleSetWidth(root, 200);
|
||||
YGNodeStyleSetHeight(root, 200);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeStyleSetMarginAuto(root_child0, YGEdgeRight);
|
||||
YGNodeStyleSetWidth(root_child0, 50);
|
||||
YGNodeStyleSetHeight(root_child0, 50);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
const YGNodeRef root_child1 = YGNodeNew();
|
||||
YGNodeStyleSetWidth(root_child1, 50);
|
||||
YGNodeStyleSetHeight(root_child1, 50);
|
||||
YGNodeInsertChild(root, root_child1, 1);
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
ASSERT_FLOAT_EQ(75, YGNodeLayoutGetLeft(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
TEST(YogaTest, margin_auto_left_and_right_strech) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
||||
YGNodeStyleSetWidth(root, 200);
|
||||
YGNodeStyleSetHeight(root, 200);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeStyleSetMarginAuto(root_child0, YGEdgeLeft);
|
||||
YGNodeStyleSetMarginAuto(root_child0, YGEdgeRight);
|
||||
YGNodeStyleSetWidth(root_child0, 50);
|
||||
YGNodeStyleSetHeight(root_child0, 50);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
const YGNodeRef root_child1 = YGNodeNew();
|
||||
YGNodeStyleSetWidth(root_child1, 50);
|
||||
YGNodeStyleSetHeight(root_child1, 50);
|
||||
YGNodeInsertChild(root, root_child1, 1);
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetLeft(root_child1));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
TEST(YogaTest, margin_auto_top_and_bottom_strech) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
YGNodeStyleSetWidth(root, 200);
|
||||
YGNodeStyleSetHeight(root, 200);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeStyleSetMarginAuto(root_child0, YGEdgeTop);
|
||||
YGNodeStyleSetMarginAuto(root_child0, YGEdgeBottom);
|
||||
YGNodeStyleSetWidth(root_child0, 50);
|
||||
YGNodeStyleSetHeight(root_child0, 50);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
const YGNodeRef root_child1 = YGNodeNew();
|
||||
YGNodeStyleSetWidth(root_child1, 50);
|
||||
YGNodeStyleSetHeight(root_child1, 50);
|
||||
YGNodeInsertChild(root, root_child1, 1);
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
|
||||
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetTop(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetLeft(root_child1));
|
||||
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetTop(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
@@ -116,11 +116,12 @@ typedef YG_ENUM_BEGIN(YGPrintOptions) {
|
||||
YGPrintOptionsChildren = 4,
|
||||
} YG_ENUM_END(YGPrintOptions);
|
||||
|
||||
#define YGUnitCount 3
|
||||
#define YGUnitCount 4
|
||||
typedef YG_ENUM_BEGIN(YGUnit) {
|
||||
YGUnitUndefined,
|
||||
YGUnitPixel,
|
||||
YGUnitPercent,
|
||||
YGUnitAuto,
|
||||
} YG_ENUM_END(YGUnit);
|
||||
|
||||
#define YGWrapCount 2
|
||||
|
167
yoga/Yoga.c
167
yoga/Yoga.c
@@ -118,6 +118,9 @@ typedef struct YGNode {
|
||||
#define YG_UNDEFINED_VALUES \
|
||||
{ .value = YGUndefined, .unit = YGUnitUndefined }
|
||||
|
||||
#define YG_AUTO_VALUES \
|
||||
{ .value = YGUndefined, .unit = YGUnitAuto }
|
||||
|
||||
#define YG_DEFAULT_EDGE_VALUES_UNIT \
|
||||
{ \
|
||||
[YGEdgeLeft] = YG_UNDEFINED_VALUES, [YGEdgeTop] = YG_UNDEFINED_VALUES, \
|
||||
@@ -133,6 +136,9 @@ typedef struct YGNode {
|
||||
#define YG_DEFAULT_DIMENSION_VALUES_UNIT \
|
||||
{ [YGDimensionWidth] = YG_UNDEFINED_VALUES, [YGDimensionHeight] = YG_UNDEFINED_VALUES, }
|
||||
|
||||
#define YG_DEFAULT_DIMENSION_VALUES_AUTO_UNIT \
|
||||
{ [YGDimensionWidth] = YG_AUTO_VALUES, [YGDimensionHeight] = YG_AUTO_VALUES, }
|
||||
|
||||
static YGNode gYGNodeDefaults = {
|
||||
.parent = NULL,
|
||||
.children = NULL,
|
||||
@@ -146,7 +152,7 @@ static YGNode gYGNodeDefaults = {
|
||||
.flex = YGUndefined,
|
||||
.flexGrow = YGUndefined,
|
||||
.flexShrink = YGUndefined,
|
||||
.flexBasis = YG_UNDEFINED_VALUES,
|
||||
.flexBasis = YG_AUTO_VALUES,
|
||||
.justifyContent = YGJustifyFlexStart,
|
||||
.alignItems = YGAlignStretch,
|
||||
.alignContent = YGAlignFlexStart,
|
||||
@@ -154,7 +160,7 @@ static YGNode gYGNodeDefaults = {
|
||||
.flexDirection = YGFlexDirectionColumn,
|
||||
.overflow = YGOverflowVisible,
|
||||
.display = YGDisplayFlex,
|
||||
.dimensions = YG_DEFAULT_DIMENSION_VALUES_UNIT,
|
||||
.dimensions = YG_DEFAULT_DIMENSION_VALUES_AUTO_UNIT,
|
||||
.minDimensions = YG_DEFAULT_DIMENSION_VALUES_UNIT,
|
||||
.maxDimensions = YG_DEFAULT_DIMENSION_VALUES_UNIT,
|
||||
.position = YG_DEFAULT_EDGE_VALUES_UNIT,
|
||||
@@ -265,6 +271,7 @@ static inline const YGValue *YGComputedEdgeValue(const YGValue edges[YGEdgeCount
|
||||
static inline float YGValueResolve(const YGValue *const value, const float parentSize) {
|
||||
switch (value->unit) {
|
||||
case YGUnitUndefined:
|
||||
case YGUnitAuto:
|
||||
return YGUndefined;
|
||||
case YGUnitPixel:
|
||||
return value->value;
|
||||
@@ -274,6 +281,10 @@ static inline float YGValueResolve(const YGValue *const value, const float paren
|
||||
return YGUndefined;
|
||||
}
|
||||
|
||||
static inline float YGValueResolveMargin(const YGValue *const value, const float parentSize) {
|
||||
return value->unit == YGUnitAuto ? 0 : YGValueResolve(value, parentSize);
|
||||
}
|
||||
|
||||
int32_t gNodeInstanceCount = 0;
|
||||
|
||||
YGNodeRef YGNodeNew(void) {
|
||||
@@ -423,13 +434,13 @@ inline float YGNodeStyleGetFlexShrink(const YGNodeRef node) {
|
||||
}
|
||||
|
||||
static inline const YGValue *YGNodeStyleGetFlexBasisPtr(const YGNodeRef node) {
|
||||
if (node->style.flexBasis.unit != YGUnitUndefined) {
|
||||
if (node->style.flexBasis.unit != YGUnitAuto) {
|
||||
return &node->style.flexBasis;
|
||||
}
|
||||
if (!YGFloatIsUndefined(node->style.flex) && node->style.flex > 0.0f) {
|
||||
return &YGValueZero;
|
||||
}
|
||||
return &YGValueUndefined;
|
||||
return &YGValueAuto;
|
||||
}
|
||||
|
||||
inline YGValue YGNodeStyleGetFlexBasis(const YGNodeRef node) {
|
||||
@@ -481,6 +492,33 @@ void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {
|
||||
} \
|
||||
}
|
||||
|
||||
#define YG_NODE_STYLE_PROPERTY_SETTER_UNIT_AUTO_IMPL(type, name, paramName, instanceName) \
|
||||
void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \
|
||||
if (node->style.instanceName.value != paramName || \
|
||||
node->style.instanceName.unit != YGUnitPixel) { \
|
||||
node->style.instanceName.value = YGFloatIsUndefined(paramName) ? YGUndefined : paramName; \
|
||||
node->style.instanceName.unit = YGFloatIsUndefined(paramName) ? YGUnitAuto : YGUnitPixel; \
|
||||
YGNodeMarkDirtyInternal(node); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
void YGNodeStyleSet##name##Percent(const YGNodeRef node, const type paramName) { \
|
||||
if (node->style.instanceName.value != paramName || \
|
||||
node->style.instanceName.unit != YGUnitPercent) { \
|
||||
node->style.instanceName.value = YGFloatIsUndefined(paramName) ? YGUndefined : paramName; \
|
||||
node->style.instanceName.unit = YGFloatIsUndefined(paramName) ? YGUnitAuto : YGUnitPercent; \
|
||||
YGNodeMarkDirtyInternal(node); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
void YGNodeStyleSet##name##Auto(const YGNodeRef node) { \
|
||||
if (node->style.instanceName.unit != YGUnitAuto) { \
|
||||
node->style.instanceName.value = YGUndefined; \
|
||||
node->style.instanceName.unit = YGUnitAuto; \
|
||||
YGNodeMarkDirtyInternal(node); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define YG_NODE_STYLE_PROPERTY_IMPL(type, name, paramName, instanceName) \
|
||||
YG_NODE_STYLE_PROPERTY_SETTER_IMPL(type, name, paramName, instanceName) \
|
||||
\
|
||||
@@ -495,6 +533,22 @@ void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {
|
||||
return node->style.instanceName; \
|
||||
}
|
||||
|
||||
#define YG_NODE_STYLE_PROPERTY_UNIT_AUTO_IMPL(type, name, paramName, instanceName) \
|
||||
YG_NODE_STYLE_PROPERTY_SETTER_UNIT_AUTO_IMPL(float, name, paramName, instanceName) \
|
||||
\
|
||||
type YGNodeStyleGet##name(const YGNodeRef node) { \
|
||||
return node->style.instanceName; \
|
||||
}
|
||||
|
||||
#define YG_NODE_STYLE_EDGE_PROPERTY_UNIT_AUTO_IMPL(type, name, instanceName) \
|
||||
void YGNodeStyleSet##name##Auto(const YGNodeRef node, const YGEdge edge) { \
|
||||
if (node->style.instanceName[edge].unit != YGUnitAuto) { \
|
||||
node->style.instanceName[edge].value = YGUndefined; \
|
||||
node->style.instanceName[edge].unit = YGUnitAuto; \
|
||||
YGNodeMarkDirtyInternal(node); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(type, name, paramName, instanceName) \
|
||||
void YGNodeStyleSet##name(const YGNodeRef node, const YGEdge edge, const float paramName) { \
|
||||
if (node->style.instanceName[edge].value != paramName || \
|
||||
@@ -582,15 +636,16 @@ YG_NODE_STYLE_PROPERTY_IMPL(YGDisplay, Display, display, display);
|
||||
|
||||
YG_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexGrow, flexGrow, flexGrow);
|
||||
YG_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexShrink, flexShrink, flexShrink);
|
||||
YG_NODE_STYLE_PROPERTY_SETTER_UNIT_IMPL(float, FlexBasis, flexBasis, flexBasis);
|
||||
YG_NODE_STYLE_PROPERTY_SETTER_UNIT_AUTO_IMPL(float, FlexBasis, flexBasis, flexBasis);
|
||||
|
||||
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(YGValue, Position, position, position);
|
||||
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(YGValue, Margin, margin, margin);
|
||||
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_AUTO_IMPL(YGValue, Margin, margin);
|
||||
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(YGValue, Padding, padding, padding);
|
||||
YG_NODE_STYLE_EDGE_PROPERTY_IMPL(float, Border, border, border);
|
||||
|
||||
YG_NODE_STYLE_PROPERTY_UNIT_IMPL(YGValue, Width, width, dimensions[YGDimensionWidth]);
|
||||
YG_NODE_STYLE_PROPERTY_UNIT_IMPL(YGValue, Height, height, dimensions[YGDimensionHeight]);
|
||||
YG_NODE_STYLE_PROPERTY_UNIT_AUTO_IMPL(YGValue, Width, width, dimensions[YGDimensionWidth]);
|
||||
YG_NODE_STYLE_PROPERTY_UNIT_AUTO_IMPL(YGValue, Height, height, dimensions[YGDimensionHeight]);
|
||||
YG_NODE_STYLE_PROPERTY_UNIT_IMPL(YGValue, MinWidth, minWidth, minDimensions[YGDimensionWidth]);
|
||||
YG_NODE_STYLE_PROPERTY_UNIT_IMPL(YGValue, MinHeight, minHeight, minDimensions[YGDimensionHeight]);
|
||||
YG_NODE_STYLE_PROPERTY_UNIT_IMPL(YGValue, MaxWidth, maxWidth, maxDimensions[YGDimensionWidth]);
|
||||
@@ -902,22 +957,22 @@ static inline float YGNodeLeadingMargin(const YGNodeRef node,
|
||||
const YGFlexDirection axis,
|
||||
const float widthSize) {
|
||||
if (YGFlexDirectionIsRow(axis) && node->style.margin[YGEdgeStart].unit != YGUnitUndefined) {
|
||||
return YGValueResolve(&node->style.margin[YGEdgeStart], widthSize);
|
||||
return YGValueResolveMargin(&node->style.margin[YGEdgeStart], widthSize);
|
||||
}
|
||||
|
||||
return YGValueResolve(YGComputedEdgeValue(node->style.margin, leading[axis], &YGValueZero),
|
||||
widthSize);
|
||||
return YGValueResolveMargin(YGComputedEdgeValue(node->style.margin, leading[axis], &YGValueZero),
|
||||
widthSize);
|
||||
}
|
||||
|
||||
static float YGNodeTrailingMargin(const YGNodeRef node,
|
||||
const YGFlexDirection axis,
|
||||
const float widthSize) {
|
||||
if (YGFlexDirectionIsRow(axis) && node->style.margin[YGEdgeEnd].unit != YGUnitUndefined) {
|
||||
return YGValueResolve(&node->style.margin[YGEdgeEnd], widthSize);
|
||||
return YGValueResolveMargin(&node->style.margin[YGEdgeEnd], widthSize);
|
||||
}
|
||||
|
||||
return YGValueResolve(YGComputedEdgeValue(node->style.margin, trailing[axis], &YGValueZero),
|
||||
widthSize);
|
||||
return YGValueResolveMargin(YGComputedEdgeValue(node->style.margin, trailing[axis], &YGValueZero),
|
||||
widthSize);
|
||||
}
|
||||
|
||||
static float YGNodeLeadingPadding(const YGNodeRef node,
|
||||
@@ -1096,7 +1151,8 @@ static inline float YGNodeDimWithMargin(const YGNodeRef node,
|
||||
static inline bool YGNodeIsStyleDimDefined(const YGNodeRef node,
|
||||
const YGFlexDirection axis,
|
||||
const float parentSize) {
|
||||
return !(node->resolvedDimensions[dim[axis]]->unit == YGUnitUndefined ||
|
||||
return !(node->resolvedDimensions[dim[axis]]->unit == YGUnitAuto ||
|
||||
node->resolvedDimensions[dim[axis]]->unit == YGUnitUndefined ||
|
||||
(node->resolvedDimensions[dim[axis]]->unit == YGUnitPixel &&
|
||||
node->resolvedDimensions[dim[axis]]->value < 0.0f) ||
|
||||
(node->resolvedDimensions[dim[axis]]->unit == YGUnitPercent &&
|
||||
@@ -2430,27 +2486,42 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
||||
}
|
||||
}
|
||||
|
||||
switch (justifyContent) {
|
||||
case YGJustifyCenter:
|
||||
leadingMainDim = remainingFreeSpace / 2;
|
||||
break;
|
||||
case YGJustifyFlexEnd:
|
||||
leadingMainDim = remainingFreeSpace;
|
||||
break;
|
||||
case YGJustifySpaceBetween:
|
||||
if (itemsOnLine > 1) {
|
||||
betweenMainDim = fmaxf(remainingFreeSpace, 0) / (itemsOnLine - 1);
|
||||
} else {
|
||||
betweenMainDim = 0;
|
||||
int numberOfAutoMarginsOnCurrentLine = 0;
|
||||
for (uint32_t i = startOfLineIndex; i < endOfLineIndex; i++) {
|
||||
const YGNodeRef child = YGNodeListGet(node->children, i);
|
||||
if (child->style.positionType == YGPositionTypeRelative) {
|
||||
if (child->style.margin[leading[mainAxis]].unit == YGUnitAuto) {
|
||||
numberOfAutoMarginsOnCurrentLine++;
|
||||
}
|
||||
break;
|
||||
case YGJustifySpaceAround:
|
||||
// Space on the edges is half of the space between elements
|
||||
betweenMainDim = remainingFreeSpace / itemsOnLine;
|
||||
leadingMainDim = betweenMainDim / 2;
|
||||
break;
|
||||
case YGJustifyFlexStart:
|
||||
break;
|
||||
if (child->style.margin[trailing[mainAxis]].unit == YGUnitAuto) {
|
||||
numberOfAutoMarginsOnCurrentLine++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (numberOfAutoMarginsOnCurrentLine == 0) {
|
||||
switch (justifyContent) {
|
||||
case YGJustifyCenter:
|
||||
leadingMainDim = remainingFreeSpace / 2;
|
||||
break;
|
||||
case YGJustifyFlexEnd:
|
||||
leadingMainDim = remainingFreeSpace;
|
||||
break;
|
||||
case YGJustifySpaceBetween:
|
||||
if (itemsOnLine > 1) {
|
||||
betweenMainDim = fmaxf(remainingFreeSpace, 0) / (itemsOnLine - 1);
|
||||
} else {
|
||||
betweenMainDim = 0;
|
||||
}
|
||||
break;
|
||||
case YGJustifySpaceAround:
|
||||
// Space on the edges is half of the space between elements
|
||||
betweenMainDim = remainingFreeSpace / itemsOnLine;
|
||||
leadingMainDim = betweenMainDim / 2;
|
||||
break;
|
||||
case YGJustifyFlexStart:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
float mainDim = leadingPaddingAndBorderMain + leadingMainDim;
|
||||
@@ -2477,10 +2548,18 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
||||
// We need to do that only for relative elements. Absolute elements
|
||||
// do not take part in that phase.
|
||||
if (child->style.positionType == YGPositionTypeRelative) {
|
||||
if (child->style.margin[leading[mainAxis]].unit == YGUnitAuto) {
|
||||
mainDim += remainingFreeSpace / numberOfAutoMarginsOnCurrentLine;
|
||||
}
|
||||
|
||||
if (performLayout) {
|
||||
child->layout.position[pos[mainAxis]] += mainDim;
|
||||
}
|
||||
|
||||
if (child->style.margin[trailing[mainAxis]].unit == YGUnitAuto) {
|
||||
mainDim += remainingFreeSpace / numberOfAutoMarginsOnCurrentLine;
|
||||
}
|
||||
|
||||
if (canSkipFlex) {
|
||||
// If we skipped the flex step, then we can't rely on the
|
||||
// measuredDims because
|
||||
@@ -2569,7 +2648,9 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
||||
// time, this time
|
||||
// forcing the cross-axis size to be the computed cross size for the
|
||||
// current line.
|
||||
if (alignItem == YGAlignStretch) {
|
||||
if (alignItem == YGAlignStretch &&
|
||||
child->style.margin[leading[crossAxis]].unit != YGUnitAuto &&
|
||||
child->style.margin[trailing[crossAxis]].unit != YGUnitAuto) {
|
||||
const bool isCrossSizeDefinite =
|
||||
(isMainAxisRow &&
|
||||
YGNodeIsStyleDimDefined(child, YGFlexDirectionColumn, availableInnerHeight)) ||
|
||||
@@ -2636,17 +2717,25 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
||||
true,
|
||||
"stretch");
|
||||
}
|
||||
} else if (alignItem != YGAlignFlexStart) {
|
||||
} else {
|
||||
const float remainingCrossDim =
|
||||
containerCrossAxis - YGNodeDimWithMargin(child, crossAxis, availableInnerWidth);
|
||||
|
||||
if (alignItem == YGAlignCenter) {
|
||||
if (child->style.margin[leading[crossAxis]].unit == YGUnitAuto &&
|
||||
child->style.margin[trailing[crossAxis]].unit == YGUnitAuto) {
|
||||
leadingCrossDim += remainingCrossDim / 2;
|
||||
} else { // YGAlignFlexEnd
|
||||
} else if (child->style.margin[trailing[crossAxis]].unit == YGUnitAuto) {
|
||||
// No-Op
|
||||
} else if (child->style.margin[leading[crossAxis]].unit == YGUnitAuto) {
|
||||
leadingCrossDim += remainingCrossDim;
|
||||
} else if (alignItem == YGAlignFlexStart) {
|
||||
// No-Op
|
||||
} else if (alignItem == YGAlignCenter) {
|
||||
leadingCrossDim += remainingCrossDim / 2;
|
||||
} else {
|
||||
leadingCrossDim += remainingCrossDim;
|
||||
}
|
||||
}
|
||||
|
||||
// And we apply the position
|
||||
child->layout.position[pos[crossAxis]] += totalLineCrossDim + leadingCrossDim;
|
||||
}
|
||||
|
15
yoga/Yoga.h
15
yoga/Yoga.h
@@ -44,6 +44,7 @@ typedef struct YGValue {
|
||||
} YGValue;
|
||||
|
||||
static const YGValue YGValueUndefined = {YGUndefined, YGUnitUndefined};
|
||||
static const YGValue YGValueAuto = {0, YGUnitAuto};
|
||||
|
||||
typedef struct YGNode *YGNodeRef;
|
||||
typedef YGSize (*YGMeasureFunc)(YGNodeRef node,
|
||||
@@ -121,6 +122,10 @@ WIN_EXPORT void YGNodeCopyStyle(const YGNodeRef dstNode, const YGNodeRef srcNode
|
||||
WIN_EXPORT void YGNodeStyleSet##name##Percent(const YGNodeRef node, const float paramName); \
|
||||
WIN_EXPORT type YGNodeStyleGet##name(const YGNodeRef node);
|
||||
|
||||
#define YG_NODE_STYLE_PROPERTY_UNIT_AUTO(type, name, paramName) \
|
||||
YG_NODE_STYLE_PROPERTY_UNIT(type, name, paramName) \
|
||||
WIN_EXPORT void YGNodeStyleSet##name##Auto(const YGNodeRef node);
|
||||
|
||||
#define YG_NODE_STYLE_EDGE_PROPERTY(type, name, paramName) \
|
||||
WIN_EXPORT void YGNodeStyleSet##name(const YGNodeRef node, \
|
||||
const YGEdge edge, \
|
||||
@@ -136,6 +141,9 @@ WIN_EXPORT void YGNodeCopyStyle(const YGNodeRef dstNode, const YGNodeRef srcNode
|
||||
const float paramName); \
|
||||
WIN_EXPORT type YGNodeStyleGet##name(const YGNodeRef node, const YGEdge edge);
|
||||
|
||||
#define YG_NODE_STYLE_EDGE_PROPERTY_UNIT_AUTO(type, name) \
|
||||
WIN_EXPORT void YGNodeStyleSet##name##Auto(const YGNodeRef node, const YGEdge edge);
|
||||
|
||||
#define YG_NODE_LAYOUT_PROPERTY(type, name) \
|
||||
WIN_EXPORT type YGNodeLayoutGet##name(const YGNodeRef node);
|
||||
|
||||
@@ -162,15 +170,16 @@ YG_NODE_STYLE_PROPERTY(YGDisplay, Display, display);
|
||||
WIN_EXPORT void YGNodeStyleSetFlex(const YGNodeRef node, const float flex);
|
||||
YG_NODE_STYLE_PROPERTY(float, FlexGrow, flexGrow);
|
||||
YG_NODE_STYLE_PROPERTY(float, FlexShrink, flexShrink);
|
||||
YG_NODE_STYLE_PROPERTY_UNIT(YGValue, FlexBasis, flexBasis);
|
||||
YG_NODE_STYLE_PROPERTY_UNIT_AUTO(YGValue, FlexBasis, flexBasis);
|
||||
|
||||
YG_NODE_STYLE_EDGE_PROPERTY_UNIT(YGValue, Position, position);
|
||||
YG_NODE_STYLE_EDGE_PROPERTY_UNIT(YGValue, Margin, margin);
|
||||
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_AUTO(YGValue, Margin);
|
||||
YG_NODE_STYLE_EDGE_PROPERTY_UNIT(YGValue, Padding, padding);
|
||||
YG_NODE_STYLE_EDGE_PROPERTY(float, Border, border);
|
||||
|
||||
YG_NODE_STYLE_PROPERTY_UNIT(YGValue, Width, width);
|
||||
YG_NODE_STYLE_PROPERTY_UNIT(YGValue, Height, height);
|
||||
YG_NODE_STYLE_PROPERTY_UNIT_AUTO(YGValue, Width, width);
|
||||
YG_NODE_STYLE_PROPERTY_UNIT_AUTO(YGValue, Height, height);
|
||||
YG_NODE_STYLE_PROPERTY_UNIT(YGValue, MinWidth, minWidth);
|
||||
YG_NODE_STYLE_PROPERTY_UNIT(YGValue, MinHeight, minHeight);
|
||||
YG_NODE_STYLE_PROPERTY_UNIT(YGValue, MaxWidth, maxWidth);
|
||||
|
Reference in New Issue
Block a user