added test for auto margin and fixed those layouts
This commit is contained in:
@@ -1408,4 +1408,175 @@ public class YGMarginTest {
|
||||
assertEquals(100f, root_child0.getLayoutHeight(), 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_margin_auto_left_right_child_bigger_than_parent() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
final YogaNode root = new YogaNode(config);
|
||||
root.setJustifyContent(YogaJustify.CENTER);
|
||||
root.setPositionType(YogaPositionType.ABSOLUTE);
|
||||
root.setWidth(52f);
|
||||
root.setHeight(52f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.setMarginAuto(YogaEdge.LEFT);
|
||||
root_child0.setMarginAuto(YogaEdge.RIGHT);
|
||||
root_child0.setWidth(72f);
|
||||
root_child0.setHeight(72f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(52f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(52f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(-10f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(72f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(72f, root_child0.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(52f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(52f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(-20f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(-10f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(72f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(72f, root_child0.getLayoutHeight(), 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_margin_auto_left_child_bigger_than_parent() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
final YogaNode root = new YogaNode(config);
|
||||
root.setJustifyContent(YogaJustify.CENTER);
|
||||
root.setPositionType(YogaPositionType.ABSOLUTE);
|
||||
root.setWidth(52f);
|
||||
root.setHeight(52f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.setMarginAuto(YogaEdge.LEFT);
|
||||
root_child0.setWidth(72f);
|
||||
root_child0.setHeight(72f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(52f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(52f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(-10f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(72f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(72f, root_child0.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(52f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(52f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(-20f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(-10f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(72f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(72f, root_child0.getLayoutHeight(), 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_margin_fix_left_auto_right_child_bigger_than_parent() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
final YogaNode root = new YogaNode(config);
|
||||
root.setJustifyContent(YogaJustify.CENTER);
|
||||
root.setPositionType(YogaPositionType.ABSOLUTE);
|
||||
root.setWidth(52f);
|
||||
root.setHeight(52f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.setMargin(YogaEdge.LEFT, 10f);
|
||||
root_child0.setMarginAuto(YogaEdge.RIGHT);
|
||||
root_child0.setWidth(72f);
|
||||
root_child0.setHeight(72f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(52f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(52f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(10f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(-10f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(72f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(72f, root_child0.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(52f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(52f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(-20f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(-10f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(72f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(72f, root_child0.getLayoutHeight(), 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_margin_auto_left_fix_right_child_bigger_than_parent() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
final YogaNode root = new YogaNode(config);
|
||||
root.setJustifyContent(YogaJustify.CENTER);
|
||||
root.setPositionType(YogaPositionType.ABSOLUTE);
|
||||
root.setWidth(52f);
|
||||
root.setHeight(52f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.setMarginAuto(YogaEdge.LEFT);
|
||||
root_child0.setMargin(YogaEdge.RIGHT, 10f);
|
||||
root_child0.setWidth(72f);
|
||||
root_child0.setHeight(72f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(52f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(52f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(-10f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(72f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(72f, root_child0.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(52f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(52f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(-30f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(-10f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(72f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(72f, root_child0.getLayoutHeight(), 0.0f);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user