365 int num_cols_expanding = 0; |
365 int num_cols_expanding = 0; |
366 int num_rows_expanding = 0; |
366 int num_rows_expanding = 0; |
367 int req_width = 0; |
367 int req_width = 0; |
368 int req_height = 0; |
368 int req_height = 0; |
369 |
369 |
370 for(int i=0;i<w->composite.num_children;i++) { |
370 // calculate the minimum size requirements for all columns and rows |
371 Widget child = w->composite.children[i]; |
371 // we need to run this 2 times: for widgets without colspan/rowspan first |
372 GridConstraintRec *constraints = child->core.constraints; |
372 // and then again for colspan/rowspan > 1 |
373 if(constraints->grid.x < ncols) { |
373 int span_max = 1; |
|
374 for(int r=0;r<2;r++) { |
|
375 for(int i=0;i<w->composite.num_children;i++) { |
|
376 Widget child = w->composite.children[i]; |
|
377 GridConstraintRec *constraints = child->core.constraints; |
|
378 |
|
379 if(constraints->grid.colspan > span_max || constraints->grid.rowspan > span_max) { |
|
380 continue; |
|
381 } |
|
382 |
|
383 int x = constraints->grid.x; |
|
384 int y = constraints->grid.y; |
|
385 // make sure ncols/nrows is correct |
|
386 // errors shouldn't happen, unless someone messes up the grid internals |
|
387 if(x >= ncols) { |
|
388 fprintf(stderr, "Error: widget x out of bounds\n"); |
|
389 continue; |
|
390 } |
|
391 if(y >= nrows) { |
|
392 fprintf(stderr, "Error: widget y out of bounds\n"); |
|
393 continue; |
|
394 } |
|
395 GridDef *col = &cols[x]; |
|
396 GridDef *row = &rows[y]; |
|
397 |
374 if(constraints->grid.hexpand) { |
398 if(constraints->grid.hexpand) { |
375 cols[constraints->grid.x].expand = TRUE; |
399 if(constraints->grid.colspan > 1) { |
376 } |
400 // check if any column in the span is expanding |
377 if(constraints->grid.pref_width > cols[constraints->grid.x].size) { |
401 // if not, make the last column expanding |
378 cols[constraints->grid.x].size = constraints->grid.pref_width; |
402 GridDef *last_col = col; |
379 } |
403 for(int c=x;c<ncols;c++) { |
380 } else { |
404 last_col = &cols[c]; |
381 fprintf(stderr, "Error: x >= ncols\n"); |
405 if(last_col->expand) { |
382 } |
406 break; |
383 if(constraints->grid.y < nrows) { |
407 } |
|
408 } |
|
409 last_col->expand = TRUE; |
|
410 } else { |
|
411 col->expand = TRUE; |
|
412 } |
|
413 } |
384 if(constraints->grid.vexpand) { |
414 if(constraints->grid.vexpand) { |
385 rows[constraints->grid.y].expand = TRUE; |
415 if(constraints->grid.rowspan > 1) { |
386 } |
416 GridDef *last_row = row; |
387 if(constraints->grid.pref_height > rows[constraints->grid.y].size) { |
417 for(int c=x;c<nrows;c++) { |
388 rows[constraints->grid.y].size = constraints->grid.pref_height; |
418 last_row = &rows[c]; |
389 } |
419 if(last_row->expand) { |
390 } else { |
420 break; |
391 fprintf(stderr, "Error: y >= nrows\n"); |
421 } |
392 } |
422 } |
393 } |
423 last_row->expand = TRUE; |
|
424 } else { |
|
425 row->expand = TRUE; |
|
426 } |
|
427 } |
|
428 |
|
429 // column size |
|
430 if(constraints->grid.colspan > 1) { |
|
431 // check size of all columns in span |
|
432 Dimension span_width = col->size; |
|
433 GridDef *last_col = col; |
|
434 for(int s=x+1;s<ncols;s++) { |
|
435 last_col = &cols[s]; |
|
436 span_width = last_col->size; |
|
437 |
|
438 } |
|
439 int diff = constraints->grid.pref_width - span_width; |
|
440 if(diff > 0) { |
|
441 last_col->size += diff; |
|
442 } |
|
443 } else if(constraints->grid.pref_width > col->size) { |
|
444 col->size = constraints->grid.pref_width; |
|
445 } |
|
446 // row size |
|
447 if(constraints->grid.rowspan > 1) { |
|
448 Dimension span_height = row->size; |
|
449 GridDef *last_row = row; |
|
450 for(int s=x+1;s<nrows;s++) { |
|
451 last_row = &rows[s]; |
|
452 span_height = last_row->size; |
|
453 |
|
454 } |
|
455 int diff = constraints->grid.pref_height - span_height; |
|
456 if(diff > 0) { |
|
457 last_row->size += diff; |
|
458 } |
|
459 } else if(constraints->grid.pref_height > row->size) { |
|
460 row->size = constraints->grid.pref_height; |
|
461 } |
|
462 } |
|
463 span_max = 50000; // not sure if this is unreasonable low or high |
|
464 } |
|
465 |
394 |
466 |
395 for(int i=0;i<ncols;i++) { |
467 for(int i=0;i<ncols;i++) { |
396 if(cols[i].expand) { |
468 if(cols[i].expand) { |
397 num_cols_expanding++; |
469 num_cols_expanding++; |
398 } |
470 } |