- short r = 0;
- for(Box child = firstPackedChild(); child != null; r++) {
- for(short c=0, numclear=0; child != null && c < cols; c++) {
- if (numRowsInCol[c] > r) { numclear = 0; continue; }
- if (c != 0 && c + min(cols, child.colspan) - numclear > cols) break;
- if (++numclear < min(cols, child.colspan)) continue;
- for(int i=c - numclear + 1; i <= c; i++) numRowsInCol[i] += child.rowspan;
- child.col = (short)(c - numclear + 1); child.row = r;
- rows = (short)max(rows, child.row + child.rowspan);
- child = child.nextPackedSibling();
- numclear = 0;
+ int childnum = 0;
+ Box lastpacked = null;
+ int maxfront = 0;
+ int maxrow = 0;
+ int rowwidth = 0;
+ for(Box child = getChild(0); child != null; child = child.nextSibling(), childnum++) {
+ if (!(child.test(PACKED) && child.test(VISIBLE))) continue;
+ int col = lastpacked == null ? 0 : (lastpacked.col + lastpacked.colspan);
+ int row = lastpacked == null ? 0 : lastpacked.row;
+ int colspan = min(cols, child.colspan);
+ for(int i=0; i<maxfront; i++) {
+ if (col + colspan > cols) {
+ row++;
+ for(; i>0; i--) row = max(row, frontier[i].row + frontier[i].rowspan);
+ col = 0;
+ rowwidth = 0;
+ continue;
+ }
+ Box front = frontier[i]; // FIXME: O(nlgn)
+ if (front.row + front.rowspan <= row) {
+ frontier[i] = frontier[maxfront-1];
+ frontier_content[i] = frontier_content[maxfront-1];
+ maxfront--;
+ frontier[maxfront] = null;
+ frontier_content[maxfront] = 0;
+ i--;
+ continue;
+ }
+ if ((front.col <= col && front.col + front.colspan > col) ||
+ (front.col < (col+colspan) && front.col + front.colspan >= (col+colspan))) {
+ col = front.col + front.colspan;
+ rowwidth += front.contentwidth; // FIXME: suspect
+ i = -1;
+ continue;
+ }
+ break;
+ }
+ child.col = (short)col;
+ child.row = (short)row;
+ maxrow = max(maxrow, child.row + child.rowspan);
+ contentwidth = max(contentwidth, rowwidth);
+ rowwidth = 0;
+ lastpacked = child;
+ for(int i=0; i<maxfront; i++) {
+ frontier_content[maxfront] =
+ max(frontier_content[maxfront], frontier_content[i] + child.contentheight);
+ contentheight =
+ max(contentheight, frontier_content[i] + child.contentheight);