Summary: X-link: https://github.com/facebook/react-native/pull/46216 Regarding [issue](https://github.com/facebook/react-native/issues/45817) with incorrect layout when `left` is set to `auto`. This PR introduces handling `auto` whenever inline or flex position is checked to be defined and it fixes above issue. Changelog: [General][Fixed] - Fix handling 'auto' checks in absolute layout ## Tests: I have run the provided unit tests and everything passes. Pull Request resolved: https://github.com/facebook/yoga/pull/1689 Reviewed By: cipolleschi Differential Revision: D61737876 Pulled By: NickGerleman fbshipit-source-id: 531199a91c5e122b930b49725ea567cbb1d592ce
1698 lines
66 KiB
Java
1698 lines
66 KiB
Java
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @generated SignedSource<<c4a613bef526a87ca88e3b28e1abc215>>
|
|
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGAbsolutePositionTest.html
|
|
*/
|
|
|
|
package com.facebook.yoga;
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import org.junit.Ignore;
|
|
import org.junit.Test;
|
|
import org.junit.runner.RunWith;
|
|
import org.junit.runners.Parameterized;
|
|
import com.facebook.yoga.utils.TestUtils;
|
|
|
|
@RunWith(Parameterized.class)
|
|
public class YGAbsolutePositionTest {
|
|
@Parameterized.Parameters(name = "{0}")
|
|
public static Iterable<TestParametrization.NodeFactory> nodeFactories() {
|
|
return TestParametrization.nodeFactories();
|
|
}
|
|
|
|
@Parameterized.Parameter public TestParametrization.NodeFactory mNodeFactory;
|
|
|
|
@Test
|
|
public void test_absolute_layout_width_height_start_top() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setWidth(100f);
|
|
root.setHeight(100f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setPosition(YogaEdge.START, 10f);
|
|
root_child0.setPosition(YogaEdge.TOP, 10f);
|
|
root_child0.setWidth(10f);
|
|
root_child0.setHeight(10f);
|
|
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(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(10f, 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(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(80f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_width_height_left_auto_right() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setWidth(100f);
|
|
root.setHeight(100f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setPositionAuto(YogaEdge.LEFT);
|
|
root_child0.setPosition(YogaEdge.RIGHT, 10f);
|
|
root_child0.setWidth(10f);
|
|
root_child0.setHeight(10f);
|
|
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(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(80f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(10f, 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(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(80f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_width_height_left_right_auto() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setWidth(100f);
|
|
root.setHeight(100f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setPosition(YogaEdge.LEFT, 10f);
|
|
root_child0.setPositionAuto(YogaEdge.RIGHT);
|
|
root_child0.setWidth(10f);
|
|
root_child0.setHeight(10f);
|
|
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(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(10f, 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(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_width_height_left_auto_right_auto() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setWidth(100f);
|
|
root.setHeight(100f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setPositionAuto(YogaEdge.LEFT);
|
|
root_child0.setPositionAuto(YogaEdge.RIGHT);
|
|
root_child0.setWidth(10f);
|
|
root_child0.setHeight(10f);
|
|
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(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(10f, 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(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(90f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_width_height_end_bottom() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setWidth(100f);
|
|
root.setHeight(100f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setPosition(YogaEdge.END, 10f);
|
|
root_child0.setPosition(YogaEdge.BOTTOM, 10f);
|
|
root_child0.setWidth(10f);
|
|
root_child0.setHeight(10f);
|
|
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(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(80f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(80f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(10f, 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(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(80f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_start_top_end_bottom() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setWidth(100f);
|
|
root.setHeight(100f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setPosition(YogaEdge.START, 10f);
|
|
root_child0.setPosition(YogaEdge.TOP, 10f);
|
|
root_child0.setPosition(YogaEdge.END, 10f);
|
|
root_child0.setPosition(YogaEdge.BOTTOM, 10f);
|
|
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(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(80f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(80f, 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(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(80f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(80f, root_child0.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_width_height_start_top_end_bottom() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setWidth(100f);
|
|
root.setHeight(100f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setPosition(YogaEdge.START, 10f);
|
|
root_child0.setPosition(YogaEdge.TOP, 10f);
|
|
root_child0.setPosition(YogaEdge.END, 10f);
|
|
root_child0.setPosition(YogaEdge.BOTTOM, 10f);
|
|
root_child0.setWidth(10f);
|
|
root_child0.setHeight(10f);
|
|
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(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(10f, 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(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(80f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_do_not_clamp_height_of_absolute_node_to_height_of_its_overflow_hidden_parent() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setFlexDirection(YogaFlexDirection.ROW);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setOverflow(YogaOverflow.HIDDEN);
|
|
root.setWidth(50f);
|
|
root.setHeight(50f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setPosition(YogaEdge.START, 0f);
|
|
root_child0.setPosition(YogaEdge.TOP, 0f);
|
|
root.addChildAt(root_child0, 0);
|
|
|
|
final YogaNode root_child0_child0 = createNode(config);
|
|
root_child0_child0.setWidth(100f);
|
|
root_child0_child0.setHeight(100f);
|
|
root_child0.addChildAt(root_child0_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(50f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(50f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root_child0.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
|
|
assertEquals(100f, root_child0_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root_child0_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(50f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(50f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(-50f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root_child0.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
|
|
assertEquals(100f, root_child0_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root_child0_child0.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_within_border() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setMargin(YogaEdge.LEFT, 10f);
|
|
root.setMargin(YogaEdge.TOP, 10f);
|
|
root.setMargin(YogaEdge.RIGHT, 10f);
|
|
root.setMargin(YogaEdge.BOTTOM, 10f);
|
|
root.setPadding(YogaEdge.LEFT, 10);
|
|
root.setPadding(YogaEdge.TOP, 10);
|
|
root.setPadding(YogaEdge.RIGHT, 10);
|
|
root.setPadding(YogaEdge.BOTTOM, 10);
|
|
root.setBorder(YogaEdge.LEFT, 10f);
|
|
root.setBorder(YogaEdge.TOP, 10f);
|
|
root.setBorder(YogaEdge.RIGHT, 10f);
|
|
root.setBorder(YogaEdge.BOTTOM, 10f);
|
|
root.setWidth(100f);
|
|
root.setHeight(100f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setPosition(YogaEdge.LEFT, 0f);
|
|
root_child0.setPosition(YogaEdge.TOP, 0f);
|
|
root_child0.setWidth(50f);
|
|
root_child0.setHeight(50f);
|
|
root.addChildAt(root_child0, 0);
|
|
|
|
final YogaNode root_child1 = createNode(config);
|
|
root_child1.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child1.setPosition(YogaEdge.RIGHT, 0f);
|
|
root_child1.setPosition(YogaEdge.BOTTOM, 0f);
|
|
root_child1.setWidth(50f);
|
|
root_child1.setHeight(50f);
|
|
root.addChildAt(root_child1, 1);
|
|
|
|
final YogaNode root_child2 = createNode(config);
|
|
root_child2.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child2.setPosition(YogaEdge.LEFT, 0f);
|
|
root_child2.setPosition(YogaEdge.TOP, 0f);
|
|
root_child2.setMargin(YogaEdge.LEFT, 10f);
|
|
root_child2.setMargin(YogaEdge.TOP, 10f);
|
|
root_child2.setMargin(YogaEdge.RIGHT, 10f);
|
|
root_child2.setMargin(YogaEdge.BOTTOM, 10f);
|
|
root_child2.setWidth(50f);
|
|
root_child2.setHeight(50f);
|
|
root.addChildAt(root_child2, 2);
|
|
|
|
final YogaNode root_child3 = createNode(config);
|
|
root_child3.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child3.setPosition(YogaEdge.RIGHT, 0f);
|
|
root_child3.setPosition(YogaEdge.BOTTOM, 0f);
|
|
root_child3.setMargin(YogaEdge.LEFT, 10f);
|
|
root_child3.setMargin(YogaEdge.TOP, 10f);
|
|
root_child3.setMargin(YogaEdge.RIGHT, 10f);
|
|
root_child3.setMargin(YogaEdge.BOTTOM, 10f);
|
|
root_child3.setWidth(50f);
|
|
root_child3.setHeight(50f);
|
|
root.addChildAt(root_child3, 3);
|
|
root.setDirection(YogaDirection.LTR);
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
|
|
|
assertEquals(10f, root.getLayoutX(), 0.0f);
|
|
assertEquals(10f, root.getLayoutY(), 0.0f);
|
|
assertEquals(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(40f, root_child1.getLayoutX(), 0.0f);
|
|
assertEquals(40f, root_child1.getLayoutY(), 0.0f);
|
|
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
|
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(20f, root_child2.getLayoutX(), 0.0f);
|
|
assertEquals(20f, root_child2.getLayoutY(), 0.0f);
|
|
assertEquals(50f, root_child2.getLayoutWidth(), 0.0f);
|
|
assertEquals(50f, root_child2.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(30f, root_child3.getLayoutX(), 0.0f);
|
|
assertEquals(30f, root_child3.getLayoutY(), 0.0f);
|
|
assertEquals(50f, root_child3.getLayoutWidth(), 0.0f);
|
|
assertEquals(50f, root_child3.getLayoutHeight(), 0.0f);
|
|
|
|
root.setDirection(YogaDirection.RTL);
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
|
|
|
assertEquals(10f, root.getLayoutX(), 0.0f);
|
|
assertEquals(10f, root.getLayoutY(), 0.0f);
|
|
assertEquals(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(40f, root_child1.getLayoutX(), 0.0f);
|
|
assertEquals(40f, root_child1.getLayoutY(), 0.0f);
|
|
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
|
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(20f, root_child2.getLayoutX(), 0.0f);
|
|
assertEquals(20f, root_child2.getLayoutY(), 0.0f);
|
|
assertEquals(50f, root_child2.getLayoutWidth(), 0.0f);
|
|
assertEquals(50f, root_child2.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(30f, root_child3.getLayoutX(), 0.0f);
|
|
assertEquals(30f, root_child3.getLayoutY(), 0.0f);
|
|
assertEquals(50f, root_child3.getLayoutWidth(), 0.0f);
|
|
assertEquals(50f, root_child3.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_align_items_and_justify_content_center() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setJustifyContent(YogaJustify.CENTER);
|
|
root.setAlignItems(YogaAlign.CENTER);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setFlexGrow(1f);
|
|
root.setWidth(110f);
|
|
root.setHeight(100f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setWidth(60f);
|
|
root_child0.setHeight(40f);
|
|
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(110f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(25f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(30f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
|
|
|
|
root.setDirection(YogaDirection.RTL);
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
|
|
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
|
assertEquals(110f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(25f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(30f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_align_items_and_justify_content_flex_end() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setJustifyContent(YogaJustify.FLEX_END);
|
|
root.setAlignItems(YogaAlign.FLEX_END);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setFlexGrow(1f);
|
|
root.setWidth(110f);
|
|
root.setHeight(100f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setWidth(60f);
|
|
root_child0.setHeight(40f);
|
|
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(110f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(50f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(60f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
|
|
|
|
root.setDirection(YogaDirection.RTL);
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
|
|
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
|
assertEquals(110f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(60f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_justify_content_center() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setJustifyContent(YogaJustify.CENTER);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setFlexGrow(1f);
|
|
root.setWidth(110f);
|
|
root.setHeight(100f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setWidth(60f);
|
|
root_child0.setHeight(40f);
|
|
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(110f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(30f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
|
|
|
|
root.setDirection(YogaDirection.RTL);
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
|
|
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
|
assertEquals(110f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(50f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(30f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_align_items_center() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setAlignItems(YogaAlign.CENTER);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setFlexGrow(1f);
|
|
root.setWidth(110f);
|
|
root.setHeight(100f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setWidth(60f);
|
|
root_child0.setHeight(40f);
|
|
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(110f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(25f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
|
|
|
|
root.setDirection(YogaDirection.RTL);
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
|
|
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
|
assertEquals(110f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(25f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_align_items_center_on_child_only() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setFlexGrow(1f);
|
|
root.setWidth(110f);
|
|
root.setHeight(100f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setAlignSelf(YogaAlign.CENTER);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setWidth(60f);
|
|
root_child0.setHeight(40f);
|
|
root.addChildAt(root_child0, 0);
|
|
root.setDirection(YogaDirection.LTR);
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
|
|
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
|
assertEquals(110f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(25f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
|
|
|
|
root.setDirection(YogaDirection.RTL);
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
|
|
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
|
assertEquals(110f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(25f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_align_items_and_justify_content_center_and_top_position() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setJustifyContent(YogaJustify.CENTER);
|
|
root.setAlignItems(YogaAlign.CENTER);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setFlexGrow(1f);
|
|
root.setWidth(110f);
|
|
root.setHeight(100f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setPosition(YogaEdge.TOP, 10f);
|
|
root_child0.setWidth(60f);
|
|
root_child0.setHeight(40f);
|
|
root.addChildAt(root_child0, 0);
|
|
root.setDirection(YogaDirection.LTR);
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
|
|
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
|
assertEquals(110f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(25f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
|
|
|
|
root.setDirection(YogaDirection.RTL);
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
|
|
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
|
assertEquals(110f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(25f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_align_items_and_justify_content_center_and_bottom_position() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setJustifyContent(YogaJustify.CENTER);
|
|
root.setAlignItems(YogaAlign.CENTER);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setFlexGrow(1f);
|
|
root.setWidth(110f);
|
|
root.setHeight(100f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setPosition(YogaEdge.BOTTOM, 10f);
|
|
root_child0.setWidth(60f);
|
|
root_child0.setHeight(40f);
|
|
root.addChildAt(root_child0, 0);
|
|
root.setDirection(YogaDirection.LTR);
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
|
|
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
|
assertEquals(110f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(25f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(50f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
|
|
|
|
root.setDirection(YogaDirection.RTL);
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
|
|
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
|
assertEquals(110f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(25f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(50f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_align_items_and_justify_content_center_and_left_position() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setJustifyContent(YogaJustify.CENTER);
|
|
root.setAlignItems(YogaAlign.CENTER);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setFlexGrow(1f);
|
|
root.setWidth(110f);
|
|
root.setHeight(100f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setPosition(YogaEdge.LEFT, 5f);
|
|
root_child0.setWidth(60f);
|
|
root_child0.setHeight(40f);
|
|
root.addChildAt(root_child0, 0);
|
|
root.setDirection(YogaDirection.LTR);
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
|
|
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
|
assertEquals(110f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(5f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(30f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
|
|
|
|
root.setDirection(YogaDirection.RTL);
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
|
|
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
|
assertEquals(110f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(5f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(30f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_align_items_and_justify_content_center_and_right_position() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setJustifyContent(YogaJustify.CENTER);
|
|
root.setAlignItems(YogaAlign.CENTER);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setFlexGrow(1f);
|
|
root.setWidth(110f);
|
|
root.setHeight(100f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setPosition(YogaEdge.RIGHT, 5f);
|
|
root_child0.setWidth(60f);
|
|
root_child0.setHeight(40f);
|
|
root.addChildAt(root_child0, 0);
|
|
root.setDirection(YogaDirection.LTR);
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
|
|
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
|
assertEquals(110f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(45f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(30f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
|
|
|
|
root.setDirection(YogaDirection.RTL);
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
|
|
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
|
assertEquals(110f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(45f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(30f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_position_root_with_rtl_should_position_withoutdirection() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setPosition(YogaEdge.LEFT, 72f);
|
|
root.setWidth(52f);
|
|
root.setHeight(52f);
|
|
root.setDirection(YogaDirection.LTR);
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
|
|
|
assertEquals(72f, root.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
|
assertEquals(52f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(52f, root.getLayoutHeight(), 0.0f);
|
|
|
|
root.setDirection(YogaDirection.RTL);
|
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
|
|
|
assertEquals(72f, root.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
|
assertEquals(52f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(52f, root.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_percentage_bottom_based_on_parent_height() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setWidth(100f);
|
|
root.setHeight(200f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setPositionPercent(YogaEdge.TOP, 50f);
|
|
root_child0.setWidth(10f);
|
|
root_child0.setHeight(10f);
|
|
root.addChildAt(root_child0, 0);
|
|
|
|
final YogaNode root_child1 = createNode(config);
|
|
root_child1.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child1.setPositionPercent(YogaEdge.BOTTOM, 50f);
|
|
root_child1.setWidth(10f);
|
|
root_child1.setHeight(10f);
|
|
root.addChildAt(root_child1, 1);
|
|
|
|
final YogaNode root_child2 = createNode(config);
|
|
root_child2.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child2.setPositionPercent(YogaEdge.TOP, 10f);
|
|
root_child2.setPositionPercent(YogaEdge.BOTTOM, 10f);
|
|
root_child2.setWidth(10f);
|
|
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(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(100f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
|
|
assertEquals(90f, root_child1.getLayoutY(), 0.0f);
|
|
assertEquals(10f, root_child1.getLayoutWidth(), 0.0f);
|
|
assertEquals(10f, root_child1.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(0f, root_child2.getLayoutX(), 0.0f);
|
|
assertEquals(20f, root_child2.getLayoutY(), 0.0f);
|
|
assertEquals(10f, root_child2.getLayoutWidth(), 0.0f);
|
|
assertEquals(160f, 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(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(90f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(100f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(90f, root_child1.getLayoutX(), 0.0f);
|
|
assertEquals(90f, root_child1.getLayoutY(), 0.0f);
|
|
assertEquals(10f, root_child1.getLayoutWidth(), 0.0f);
|
|
assertEquals(10f, root_child1.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(90f, root_child2.getLayoutX(), 0.0f);
|
|
assertEquals(20f, root_child2.getLayoutY(), 0.0f);
|
|
assertEquals(10f, root_child2.getLayoutWidth(), 0.0f);
|
|
assertEquals(160f, root_child2.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_in_wrap_reverse_column_container() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setWrap(YogaWrap.WRAP_REVERSE);
|
|
root.setWidth(100f);
|
|
root.setHeight(100f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setWidth(20f);
|
|
root_child0.setHeight(20f);
|
|
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(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(80f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(20f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(20f, 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(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(20f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(20f, root_child0.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_in_wrap_reverse_row_container() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setFlexDirection(YogaFlexDirection.ROW);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setWrap(YogaWrap.WRAP_REVERSE);
|
|
root.setWidth(100f);
|
|
root.setHeight(100f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setWidth(20f);
|
|
root_child0.setHeight(20f);
|
|
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(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(80f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(20f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(20f, 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(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(80f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(80f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(20f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(20f, root_child0.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_in_wrap_reverse_column_container_flex_end() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setWrap(YogaWrap.WRAP_REVERSE);
|
|
root.setWidth(100f);
|
|
root.setHeight(100f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setAlignSelf(YogaAlign.FLEX_END);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setWidth(20f);
|
|
root_child0.setHeight(20f);
|
|
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(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(20f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(20f, 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(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(80f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(20f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(20f, root_child0.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_in_wrap_reverse_row_container_flex_end() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setFlexDirection(YogaFlexDirection.ROW);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setWrap(YogaWrap.WRAP_REVERSE);
|
|
root.setWidth(100f);
|
|
root.setHeight(100f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setAlignSelf(YogaAlign.FLEX_END);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setWidth(20f);
|
|
root_child0.setHeight(20f);
|
|
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(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(20f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(20f, 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(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(80f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(20f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(20f, root_child0.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_percent_absolute_position_infinite_height() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setWidth(300f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setWidth(300f);
|
|
root.addChildAt(root_child0, 0);
|
|
|
|
final YogaNode root_child1 = createNode(config);
|
|
root_child1.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child1.setPositionPercent(YogaEdge.LEFT, 20f);
|
|
root_child1.setPositionPercent(YogaEdge.TOP, 20f);
|
|
root_child1.setWidthPercent(20f);
|
|
root_child1.setHeightPercent(20f);
|
|
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(300f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(0f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(300f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(0f, root_child0.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(60f, root_child1.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
|
|
assertEquals(60f, root_child1.getLayoutWidth(), 0.0f);
|
|
assertEquals(0f, 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(300f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(0f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(300f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(0f, root_child0.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(60f, root_child1.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
|
|
assertEquals(60f, root_child1.getLayoutWidth(), 0.0f);
|
|
assertEquals(0f, root_child1.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_percentage_height_based_on_padded_parent() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setPadding(YogaEdge.TOP, 10);
|
|
root.setBorder(YogaEdge.TOP, 10f);
|
|
root.setWidth(100f);
|
|
root.setHeight(100f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setWidth(100f);
|
|
root_child0.setHeightPercent(50f);
|
|
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(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(20f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(45f, 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(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(20f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(45f, root_child0.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_percentage_height_based_on_padded_parent_and_align_items_center() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setJustifyContent(YogaJustify.CENTER);
|
|
root.setAlignItems(YogaAlign.CENTER);
|
|
root.setPadding(YogaEdge.TOP, 20);
|
|
root.setPadding(YogaEdge.BOTTOM, 20);
|
|
root.setWidth(100f);
|
|
root.setHeight(100f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setWidth(100f);
|
|
root_child0.setHeightPercent(50f);
|
|
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(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(25f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(50f, 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(100f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(25f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_padding_left() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setPadding(YogaEdge.LEFT, 100);
|
|
root.setWidth(200f);
|
|
root.setHeight(200f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setWidth(50f);
|
|
root_child0.setHeight(50f);
|
|
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(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);
|
|
|
|
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);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_padding_right() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setPadding(YogaEdge.RIGHT, 100);
|
|
root.setWidth(200f);
|
|
root.setHeight(200f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setWidth(50f);
|
|
root_child0.setHeight(50f);
|
|
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(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);
|
|
|
|
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(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);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_padding_top() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setPadding(YogaEdge.TOP, 100);
|
|
root.setWidth(200f);
|
|
root.setHeight(200f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setWidth(50f);
|
|
root_child0.setHeight(50f);
|
|
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(200f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(0f, 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);
|
|
|
|
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(100f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_padding_bottom() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setPadding(YogaEdge.BOTTOM, 100);
|
|
root.setWidth(200f);
|
|
root.setHeight(200f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setWidth(50f);
|
|
root_child0.setHeight(50f);
|
|
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(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);
|
|
|
|
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);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_padding() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setMargin(YogaEdge.LEFT, 10f);
|
|
root_child0.setMargin(YogaEdge.TOP, 10f);
|
|
root_child0.setMargin(YogaEdge.RIGHT, 10f);
|
|
root_child0.setMargin(YogaEdge.BOTTOM, 10f);
|
|
root_child0.setWidth(200f);
|
|
root_child0.setHeight(200f);
|
|
root.addChildAt(root_child0, 0);
|
|
|
|
final YogaNode root_child0_child0 = createNode(config);
|
|
root_child0_child0.setPositionType(YogaPositionType.STATIC);
|
|
root_child0_child0.setPadding(YogaEdge.LEFT, 50);
|
|
root_child0_child0.setPadding(YogaEdge.TOP, 50);
|
|
root_child0_child0.setPadding(YogaEdge.RIGHT, 50);
|
|
root_child0_child0.setPadding(YogaEdge.BOTTOM, 50);
|
|
root_child0_child0.setWidth(200f);
|
|
root_child0_child0.setHeight(200f);
|
|
root_child0.addChildAt(root_child0_child0, 0);
|
|
|
|
final YogaNode root_child0_child0_child0 = createNode(config);
|
|
root_child0_child0_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0_child0_child0.setWidth(50f);
|
|
root_child0_child0_child0.setHeight(50f);
|
|
root_child0_child0.addChildAt(root_child0_child0_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(220f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(220f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(200f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(200f, root_child0.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
|
|
assertEquals(200f, root_child0_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(200f, root_child0_child0.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(50f, root_child0_child0_child0.getLayoutX(), 0.0f);
|
|
assertEquals(50f, root_child0_child0_child0.getLayoutY(), 0.0f);
|
|
assertEquals(50f, root_child0_child0_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(50f, root_child0_child0_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(220f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(220f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(200f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(200f, root_child0.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
|
|
assertEquals(200f, root_child0_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(200f, root_child0_child0.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(100f, root_child0_child0_child0.getLayoutX(), 0.0f);
|
|
assertEquals(50f, root_child0_child0_child0.getLayoutY(), 0.0f);
|
|
assertEquals(50f, root_child0_child0_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(50f, root_child0_child0_child0.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_border() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setMargin(YogaEdge.LEFT, 10f);
|
|
root_child0.setMargin(YogaEdge.TOP, 10f);
|
|
root_child0.setMargin(YogaEdge.RIGHT, 10f);
|
|
root_child0.setMargin(YogaEdge.BOTTOM, 10f);
|
|
root_child0.setWidth(200f);
|
|
root_child0.setHeight(200f);
|
|
root.addChildAt(root_child0, 0);
|
|
|
|
final YogaNode root_child0_child0 = createNode(config);
|
|
root_child0_child0.setPositionType(YogaPositionType.STATIC);
|
|
root_child0_child0.setBorder(YogaEdge.LEFT, 10f);
|
|
root_child0_child0.setBorder(YogaEdge.TOP, 10f);
|
|
root_child0_child0.setBorder(YogaEdge.RIGHT, 10f);
|
|
root_child0_child0.setBorder(YogaEdge.BOTTOM, 10f);
|
|
root_child0_child0.setWidth(200f);
|
|
root_child0_child0.setHeight(200f);
|
|
root_child0.addChildAt(root_child0_child0, 0);
|
|
|
|
final YogaNode root_child0_child0_child0 = createNode(config);
|
|
root_child0_child0_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0_child0_child0.setWidth(50f);
|
|
root_child0_child0_child0.setHeight(50f);
|
|
root_child0_child0.addChildAt(root_child0_child0_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(220f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(220f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(200f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(200f, root_child0.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
|
|
assertEquals(200f, root_child0_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(200f, root_child0_child0.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0_child0_child0.getLayoutX(), 0.0f);
|
|
assertEquals(10f, root_child0_child0_child0.getLayoutY(), 0.0f);
|
|
assertEquals(50f, root_child0_child0_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(50f, root_child0_child0_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(220f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(220f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(10f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(10f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(200f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(200f, root_child0.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
|
|
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
|
|
assertEquals(200f, root_child0_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(200f, root_child0_child0.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(140f, root_child0_child0_child0.getLayoutX(), 0.0f);
|
|
assertEquals(10f, root_child0_child0_child0.getLayoutY(), 0.0f);
|
|
assertEquals(50f, root_child0_child0_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(50f, root_child0_child0_child0.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
@Test
|
|
public void test_absolute_layout_column_reverse_margin_border() {
|
|
YogaConfig config = YogaConfigFactory.create();
|
|
|
|
final YogaNode root = createNode(config);
|
|
root.setFlexDirection(YogaFlexDirection.COLUMN_REVERSE);
|
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root.setWidth(200f);
|
|
root.setHeight(200f);
|
|
|
|
final YogaNode root_child0 = createNode(config);
|
|
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
|
root_child0.setPosition(YogaEdge.LEFT, 5f);
|
|
root_child0.setPosition(YogaEdge.RIGHT, 3f);
|
|
root_child0.setMargin(YogaEdge.LEFT, 3f);
|
|
root_child0.setMargin(YogaEdge.RIGHT, 4f);
|
|
root_child0.setBorder(YogaEdge.LEFT, 1f);
|
|
root_child0.setBorder(YogaEdge.RIGHT, 7f);
|
|
root_child0.setWidth(50f);
|
|
root_child0.setHeight(50f);
|
|
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(200f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(8f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(150f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(50f, 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(200f, root.getLayoutWidth(), 0.0f);
|
|
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
|
|
|
assertEquals(143f, root_child0.getLayoutX(), 0.0f);
|
|
assertEquals(150f, root_child0.getLayoutY(), 0.0f);
|
|
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
|
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
|
}
|
|
|
|
private YogaNode createNode(YogaConfig config) {
|
|
return mNodeFactory.create(config);
|
|
}
|
|
}
|