Reset child position/sizes before calculating layout

This commit is contained in:
Pieter De Baets
2016-03-25 22:37:00 +01:00
parent 8d5cdd4e6c
commit b157ab4a00
9 changed files with 334 additions and 14 deletions

View File

@@ -204,6 +204,10 @@ public class LayoutEngine {
node.lastLayout.parentMaxWidth = parentMaxWidth;
node.lastLayout.parentMaxHeight = parentMaxHeight;
for (int i = 0, childCount = node.getChildCount(); i < childCount; i++) {
node.getChildAt(i).layout.resetResult();
}
layoutNodeImpl(layoutContext, node, parentMaxWidth, parentMaxHeight, parentDirection);
node.lastLayout.copy(node.layout);
} else {
@@ -219,10 +223,6 @@ public class LayoutEngine {
float parentMaxWidth,
float parentMaxHeight,
CSSDirection parentDirection) {
for (int i = 0, childCount = node.getChildCount(); i < childCount; i++) {
node.getChildAt(i).layout.resetResult();
}
/** START_GENERATED **/
CSSDirection direction = resolveDirection(node, parentDirection);

View File

@@ -8390,6 +8390,96 @@ public class LayoutEngineTest {
@Test
public void testCase187()
{
TestCSSNode root_node = new TestCSSNode();
{
TestCSSNode node_0 = root_node;
node_0.style.flexDirection = CSSFlexDirection.ROW;
addChildren(node_0, 2);
{
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
addChildren(node_1, 1);
{
TestCSSNode node_2;
node_2 = node_1.getChildAt(0);
node_2.style.dimensions[DIMENSION_WIDTH] = 100;
node_2.style.dimensions[DIMENSION_HEIGHT] = 100;
}
node_1 = node_0.getChildAt(1);
node_1.style.dimensions[DIMENSION_WIDTH] = 100;
addChildren(node_1, 1);
{
TestCSSNode node_2;
node_2 = node_1.getChildAt(0);
node_2.style.flexDirection = CSSFlexDirection.COLUMN;
node_2.style.alignItems = CSSAlign.CENTER;
addChildren(node_2, 1);
{
TestCSSNode node_3;
node_3 = node_2.getChildAt(0);
node_3.style.dimensions[DIMENSION_WIDTH] = 50;
node_3.style.dimensions[DIMENSION_HEIGHT] = 50;
}
}
}
}
TestCSSNode root_layout = new TestCSSNode();
{
TestCSSNode node_0 = root_layout;
node_0.layout.position[POSITION_TOP] = 0;
node_0.layout.position[POSITION_LEFT] = 0;
node_0.layout.dimensions[DIMENSION_WIDTH] = 200;
node_0.layout.dimensions[DIMENSION_HEIGHT] = 100;
addChildren(node_0, 2);
{
TestCSSNode node_1;
node_1 = node_0.getChildAt(0);
node_1.layout.position[POSITION_TOP] = 0;
node_1.layout.position[POSITION_LEFT] = 0;
node_1.layout.dimensions[DIMENSION_WIDTH] = 100;
node_1.layout.dimensions[DIMENSION_HEIGHT] = 100;
addChildren(node_1, 1);
{
TestCSSNode node_2;
node_2 = node_1.getChildAt(0);
node_2.layout.position[POSITION_TOP] = 0;
node_2.layout.position[POSITION_LEFT] = 0;
node_2.layout.dimensions[DIMENSION_WIDTH] = 100;
node_2.layout.dimensions[DIMENSION_HEIGHT] = 100;
}
node_1 = node_0.getChildAt(1);
node_1.layout.position[POSITION_TOP] = 0;
node_1.layout.position[POSITION_LEFT] = 100;
node_1.layout.dimensions[DIMENSION_WIDTH] = 100;
node_1.layout.dimensions[DIMENSION_HEIGHT] = 100;
addChildren(node_1, 1);
{
TestCSSNode node_2;
node_2 = node_1.getChildAt(0);
node_2.layout.position[POSITION_TOP] = 0;
node_2.layout.position[POSITION_LEFT] = 0;
node_2.layout.dimensions[DIMENSION_WIDTH] = 100;
node_2.layout.dimensions[DIMENSION_HEIGHT] = 50;
addChildren(node_2, 1);
{
TestCSSNode node_3;
node_3 = node_2.getChildAt(0);
node_3.layout.position[POSITION_TOP] = 0;
node_3.layout.position[POSITION_LEFT] = 25;
node_3.layout.dimensions[DIMENSION_WIDTH] = 50;
node_3.layout.dimensions[DIMENSION_HEIGHT] = 50;
}
}
}
}
test("should center items correctly inside a stretched layout", root_node, root_layout);
}
@Test
public void testCase188()
{
TestCSSNode root_node = new TestCSSNode();
{