- for(int startslack = 0; x_slack > 0 && cols > 0 && startslack != x_slack;) {
- int increment = max(1, x_slack / cols);
- startslack = x_slack;
- for(short col=0; col < cols; col++) {
- // FIXME: double check this
- int diff = min(min(colMaxWidth[col], colWidth[col] + increment) - colWidth[col], x_slack);
- x_slack -= diff;
+ int x_slack = width;
+ for(int i=0; i<cols; i++) x_slack -= colWidth[i];
+ // loop through until there are no more eligible children or all slack is handed out
+ for(int eligible = cols, slacklevel = 0; x_slack > 0 && eligible > 0;) {
+ int increment = max(1, x_slack / eligible);
+ eligible = 0;
+ for(short col=0, count=0; col < cols; col++) {
+ if (colMaxWidth[col] <= colWidth[col]) continue;
+ if (slacklevel + increment < colWidth[col]) { eligible++; continue; }
+ int diff = min(increment, min(colMaxWidth[col] - colWidth[col], slacklevel + increment - colWidth[col]));
+ eligible++;