- void repack() {
- for(Box child = getChild(0); child != null; child = child.nextSibling()) child.repack();
- contentwidth = 0;
- contentheight = 0;
- if (treeSize() == 0) { constrain(); return; }
- //#repeat COLS/ROWS rows/cols cols/rows col/row row/col colspan/rowspan rowspan/colspan contentheight/contentwidth contentwidth/contentheight
- if (test(FIXED) == COLS) {
- 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
+ void pack() {
+ for(Box child = getChild(0); child != null; child = child.nextSibling()) child.pack();
+ int frontier_size = 0; contentwidth = 0; contentheight = 0;
+ //#repeat COLS/ROWS rows/cols cols/rows col/row row/col colspan/rowspan rowspan/colspan \
+ // contentheight/contentwidth contentwidth/contentheight
+ if (treeSize() > 0 && test(FIXED) == COLS) {
+ rows = 0;
+ for(Box child = getChild(0); child != null; child = child.nextSibling()) {
+ if (!child.test(PACKED) || !child.test(VISIBLE)) continue;
+ child.col = (short)(frontier_size <= 0 ? 0 : (frontier[frontier_size-1].col + frontier[frontier_size-1].colspan));
+ child.row = (short)(frontier_size <= 0 ? 0 : frontier[frontier_size-1].row);
+ if (child.col + min(cols,child.colspan) > cols) { child.col = 0; child.row++; }
+ for(int i=0; i<frontier_size; i++)
+ if (frontier[i].row + frontier[i].rowspan <= child.row) {
+ frontier[i--] = frontier[--frontier_size]; frontier[frontier_size] = null;
+ } else if (frontier[i].col<child.col+min(cols,child.colspan)&&frontier[i].col+frontier[i].colspan>child.col) {
+ child.col = (short)(frontier[i].col + frontier[i].colspan);
+ if (child.col + min(cols,child.colspan) > cols) {
+ child.row = (short)(frontier[i].row + frontier[i].rowspan);
+ for(i--; i>0; i--) child.row = (short)min(row, frontier[i].row + frontier[i].rowspan);
+ child.col = (short)0;
+ }