- void resize_children() {
-
- int eligible;
- //#repeat col/row colspan/rowspan contentwidth/contentheight x/y width/height colMaxWidth/rowMaxHeight colWidth/rowHeight \
- // colMinWidth/rowMinHeight HSHRINK/VSHRINK maxwidth/maxheight cols/rows minwidth/minheight colWidth/rowHeight \
- // x_slack/y_slack
- // PHASE 1: compute column min/max sizes
- int x_slack = width;
- eligible = 0;
- for(int i=0; i<cols; i++) x_slack -= colWidth[i];
- for(Box child = firstPackedChild(); child != null; child = child.nextPackedSibling())
- for(int i=child.col; i < child.col + child.colspan; i++) {
- colMinWidth[i] = max(colWidth[i], child.contentwidth / child.colspan);
- colMaxWidth[i] = min(colMaxWidth[i], child.test(HSHRINK) ? child.contentwidth : child.maxwidth) / child.colspan;
- colWidth[i] = 0;
- eligible++;
+ private static float[] coeff = null;
+ void place_children() {
+ LinearProgramming.Problem lpr_h;
+ LinearProgramming.Problem lpr_v;
+ int numkids = 0; for(Box c = firstPackedChild(); c != null; c = c.nextPackedSibling()) numkids++;
+ //#repeat col/row colspan/rowspan contentwidth/contentheight width/height \
+ // maxwidth/maxheight cols/rows minwidth/minheight lp_h/lp_v lpr_h/lpr_v
+ do {
+ int nc = numkids * 2 + cols * 3 + 1 + 2;
+ if (coeff == null || nc+1>coeff.length) coeff = new float[nc+1];
+ LinearProgramming.Simplex lp_h = new LinearProgramming.Simplex();
+ lpr_h = new LinearProgramming.Problem(nc, nc);
+
+ // objective function
+ for(int i=0; i<coeff.length; i++) coeff[i] = (float)0.0;
+ coeff[cols*2+numkids] = (float)-100000.0; // priority 1: sum of columns equals parent
+ for(int i=cols*2; i<cols*2+numkids; i++) coeff[i] = (float)-1000.0; // priority 2: honor maxwidths
+ for(int i=cols; i<cols*2; i++) coeff[i] = (float)(-1.0); // priority 3: equalize columns
+ lp_h.set_obj_fn(lpr_h, coeff);
+ lp_h.set_maxim(lpr_h);
+
+ // priority 1: sum of columns at least as big as parent
+ for(int i=0; i<coeff.length; i++) coeff[i] = (i<cols) ? (float)1.0 : (float)0.0;
+ lp_h.add_constraint(lpr_h, coeff, LinearProgramming.GE, (float)width);
+ for(int i=0; i<coeff.length; i++) coeff[i] = (i<cols) ? (float)1.0 : (float)0.0;
+ coeff[cols*2+numkids] = (float)1.0;
+ lp_h.add_constraint(lpr_h, coeff, LinearProgramming.EQ, (float)width);
+
+ // priority 2: honor maxwidths
+ int childnum = 0;
+ for(Box child = firstPackedChild(); child != null; child = child.nextPackedSibling()) {
+ for(int i=0; i<coeff.length; i++)
+ coeff[i] = (i>=child.col && i<min(child.colspan+child.col, cols)) ? (float)1.0 : (float)0.0;
+ lp_h.add_constraint(lpr_h, coeff, LinearProgramming.GE, (float)child.contentwidth);
+ if (child.maxwidth < Integer.MAX_VALUE) {
+ for(int i=0; i<coeff.length; i++)
+ coeff[i] = (i>=child.col && i<min(child.colspan+child.col, cols)) ? (float)1.0 : (float)0.0;
+ coeff[cols*2+childnum] = (float)-1.0;
+ lp_h.add_constraint(lpr_h, coeff, LinearProgramming.EQ, (float)child.maxwidth);
+ }
+ for(int j=0; j<coeff.length; j++) coeff[j] = (float)0.0;
+ childnum++;