Update C version

This commit is contained in:
Christopher Chedeau
2015-02-04 07:50:15 -08:00
parent 9ccb4b6c42
commit 5f8c3b0eb7
2 changed files with 53 additions and 7 deletions

View File

@@ -438,11 +438,12 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth) {
// We want to execute the next two loops one per line with flex-wrap // We want to execute the next two loops one per line with flex-wrap
int startLine = 0; int startLine = 0;
int endLine = 0; int endLine = 0;
int nextLine = 0; int nextOffset = 0;
int alreadyComputedNextLayout = 0;
// We aggregate the total dimensions of the container in those two variables // We aggregate the total dimensions of the container in those two variables
float linesCrossDim = 0; float linesCrossDim = 0;
float linesMainDim = 0; float linesMainDim = 0;
while (endLine != node->children_count) { while (endLine < node->children_count) {
// <Loop A> Layout non flexible children and count children by type // <Loop A> Layout non flexible children and count children by type
// mainContentDim is accumulation of the dimensions and margin of all the // mainContentDim is accumulation of the dimensions and margin of all the
@@ -486,7 +487,7 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth) {
} }
// This is the main recursive call. We layout non flexible children. // This is the main recursive call. We layout non flexible children.
if (nextLine == 0) { if (alreadyComputedNextLayout == 0) {
layoutNode(child, maxWidth); layoutNode(child, maxWidth);
} }
@@ -502,11 +503,14 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth) {
// The element we are about to add would make us go to the next line // The element we are about to add would make us go to the next line
if (isFlexWrap(node) && if (isFlexWrap(node) &&
!isUndefined(node->layout.dimensions[dim[mainAxis]]) && !isUndefined(node->layout.dimensions[dim[mainAxis]]) &&
mainContentDim + nextContentDim > definedMainDim) { mainContentDim + nextContentDim > definedMainDim &&
nextLine = i + 1; // If there's only one element, then it's bigger than the content
// and needs its own line
i != startLine) {
alreadyComputedNextLayout = 1;
break; break;
} }
nextLine = 0; alreadyComputedNextLayout = 0;
mainContentDim += nextContentDim; mainContentDim += nextContentDim;
endLine = i + 1; endLine = i + 1;
} }

View File

@@ -375,7 +375,7 @@ int main()
} }
} }
test("should layout node with flex", root_node, root_layout); test("should layout node with just flex", root_node, root_layout);
} }
{ {
@@ -3724,6 +3724,48 @@ int main()
test("should layout flex-wrap", root_node, root_layout); test("should layout flex-wrap", root_node, root_layout);
} }
{
css_node_t *root_node = new_test_css_node();
{
css_node_t *node_0 = root_node;
node_0->style.flex_wrap = CSS_WRAP;
node_0->style.dimensions[CSS_HEIGHT] = 100;
init_css_node_children(node_0, 2);
{
css_node_t *node_1;
node_1 = node_0->get_child(node_0->context, 0);
node_1->style.dimensions[CSS_HEIGHT] = 100;
node_1 = node_0->get_child(node_0->context, 1);
node_1->style.dimensions[CSS_HEIGHT] = 200;
}
}
css_node_t *root_layout = new_test_css_node();
{
css_node_t *node_0 = root_layout;
node_0->layout.position[CSS_TOP] = 0;
node_0->layout.position[CSS_LEFT] = 0;
node_0->layout.dimensions[CSS_WIDTH] = 0;
node_0->layout.dimensions[CSS_HEIGHT] = 100;
init_css_node_children(node_0, 2);
{
css_node_t *node_1;
node_1 = node_0->get_child(node_0->context, 0);
node_1->layout.position[CSS_TOP] = 0;
node_1->layout.position[CSS_LEFT] = 0;
node_1->layout.dimensions[CSS_WIDTH] = 0;
node_1->layout.dimensions[CSS_HEIGHT] = 100;
node_1 = node_0->get_child(node_0->context, 1);
node_1->layout.position[CSS_TOP] = 0;
node_1->layout.position[CSS_LEFT] = 0;
node_1->layout.dimensions[CSS_WIDTH] = 0;
node_1->layout.dimensions[CSS_HEIGHT] = 200;
}
}
test("should layout flex wrap with a line bigger than container", root_node, root_layout);
}
/** END_GENERATED **/ /** END_GENERATED **/
return tests_finished(); return tests_finished();
} }