X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2FBox.java;h=f680f20ff5b9a3531a2e9c5be2a40b5268ae7f53;hb=5de59cbabd2184a23380fee1bdf32e52c5bb44d7;hp=9489a8b3f29d6907b1287d48be04c426e900340a;hpb=a113d1f48d1c3db8aa08c550a925360d1d664b47;p=org.ibex.core.git diff --git a/src/org/ibex/Box.java b/src/org/ibex/Box.java index 9489a8b..f680f20 100644 --- a/src/org/ibex/Box.java +++ b/src/org/ibex/Box.java @@ -240,14 +240,21 @@ public final class Box extends JSScope implements Scheduler.Task { for(int i=0; i i)) + rowcontentwidth += child.contentwidth; + contentwidth = max(contentwidth, rowcontentwidth); + } contentwidth = bound(minwidth, max(font == null || text == null ? 0 : font.textwidth(text), contentwidth), maxwidth); //#end } @@ -287,57 +294,104 @@ public final class Box extends JSScope implements Scheduler.Task { } private static float[] coeff = null; + private static LinearProgramming.Simplex lp_h = new LinearProgramming.Simplex(100, 100, 300); + private static LinearProgramming.Simplex lp = new LinearProgramming.Simplex(100, 100, 300); + boolean[] breakpoints = new boolean[65535]; + int[] regions = new int[65535]; + int[] regions_v = new int[65535]; + void place_children() { int numkids = 0; for(Box c = firstPackedChild(); c != null; c = c.nextPackedSibling()) numkids++; - 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(); - LinearProgramming.Problem lpr_h = new LinearProgramming.Problem(nc, nc); - LinearProgramming.Simplex lp_v = new LinearProgramming.Simplex(); - LinearProgramming.Problem lpr_v = new LinearProgramming.Problem(nc, nc); - - //#repeat col/row colspan/rowspan contentwidth/contentheight width/height colMaxWidth/rowMaxHeight colWidth/rowHeight \ - // HSHRINK/VSHRINK maxwidth/maxheight cols/rows minwidth/minheight colWidth/rowHeight x_slack/y_slack lp_h/lp_v lpr_h/lpr_v - do { - // objective function - coeff[cols*2+numkids] = coeff[cols*2+numkids+1] = (float)-10000.0; // attempt to make sum of columns equal to parent width - for(int i=cols*2; i 1) do { + /* boolean easy_width = contentwidth >= width; */ + for(Box c = firstPackedChild(); c != null; c = c.nextPackedSibling()) { + breakpoints[c.col] = true; + breakpoints[min(cols, c.col+c.colspan)] = true; + } + numregions = 0; + // FIXME: depends on cols + for(int i=0; i i && c.maxwidth < Integer.MAX_VALUE) + good = false; + if (good) { easy_width = true; break; } + } + if (easy_width) break; + */ + int nc = numregions * 2 + numkids + 1; + if (coeff == null || nc+1>coeff.length) coeff = new float[nc+1]; + lp_h.init(nc); + + for(int i=0; i=child.col && i=child.col && i= child.col && regions[r+1] <= min(child.col+child.colspan,cols)) + coeff[r] = (float)(regions[r+1] - regions[r]); + lp_h.add_constraint(coeff, LinearProgramming.GE, (float)child.contentwidth); + + // priority 2: honor maxwidths + int child_maxwidth = child.test(HSHRINK) ? min(child.maxwidth, child.contentwidth) : child.maxwidth; + if (child_maxwidth < Integer.MAX_VALUE) { + for(int i=0; i= child.col && regions[r+1] <= min(child.col+child.colspan,cols)) + coeff[r] = (float)(regions[r+1] - regions[r]); + coeff[numregions*2+childnum] = (float)-1.0; + lp_h.add_constraint(coeff, LinearProgramming.LE, (float)child_maxwidth); } - for(int j=0; j= child.col && regions[r+1] <= min(child.col+child.colspan,cols)) { + child_width += Math.round(lp_h.solution[lp_h.rows+r+1] * (regions[r+1] - regions[r])); + } else if (regions[r+1] <= child.col) { + child_x += Math.round(lp_h.solution[lp_h.rows+r+1] * (regions[r+1] - regions[r])); + } + } + } + diff = (child_width - min(child_width, child.test(HSHRINK) ? child.contentwidth : child.maxwidth)); + child_x += (child.test(ALIGN_RIGHT) ? diff : child.test(ALIGN_LEFT) ? 0 : diff / 2); child_width = min(child_width, child.test(HSHRINK) ? child.contentwidth : child.maxwidth); //#end } @@ -579,6 +649,7 @@ public final class Box extends JSScope implements Scheduler.Task { case "Maximized": if (parent == null && getSurface() != null) getSurface().maximized = toBoolean(value); // FEATURE case "Close": if (parent == null && getSurface() != null) getSurface().dispose(true); case "redirect": + if (value == null) { redirect = null; return; } for(Box cur = (Box)value; cur != null; cur = cur.parent) if (cur == redirect) { redirect = (Box)value; @@ -718,6 +789,7 @@ public final class Box extends JSScope implements Scheduler.Task { fillcolor = newfillcolor; } else if(value instanceof JS) { texture = Picture.load((JS)value, this); + if (texture != null && texture.isLoaded) perform(); } else { throw new JSExn("fill must be null, a String, or a stream, not a " + value.getClass()); }