Revision: 4546 http://sourceforge.net/p/vexi/code/4546 Author: clrg Date: 2013-08-30 16:46:27 +0000 (Fri, 30 Aug 2013) Log Message: ----------- Change to align / packed children behaviour - before: packed children (where total_maxsize<parent.width) were spaced apart - before: align determined where each child appeared in it's individual space - now: packed child boxes are kept together instead of spaced out - now: align determines starting position of layout for the packed child boxes
Modified Paths: -------------- branches/vexi3/org.vexi-core.main/src/main/jpp/org/vexi/core/Box.jpp Modified: branches/vexi3/org.vexi-core.main/src/main/jpp/org/vexi/core/Box.jpp =================================================================== --- branches/vexi3/org.vexi-core.main/src/main/jpp/org/vexi/core/Box.jpp 2013-08-30 14:07:01 UTC (rev 4545) +++ branches/vexi3/org.vexi-core.main/src/main/jpp/org/vexi/core/Box.jpp 2013-08-30 16:46:27 UTC (rev 4546) @@ -759,7 +759,7 @@ // loop over the children attempting to set their width to // targetsize and adjust until it meets the parent width float targetsize = (float)width/(float)treeSize(); - float total = 0; + float totalsize = 0; int numactive = 0; for (int j=0; j<100; j++) { int min_minsize = MAX_DIMENSION; @@ -775,55 +775,59 @@ numactive++; if (child.test(HSHRINK) || child.maxwidth==child.contentwidth) { num_passive++; - total += child.contentwidth; + totalsize += child.contentwidth; } else if (child.contentwidth>targetsize) { min_minsize = min(min_minsize, child.contentwidth); num_minsize++; - total += (float)child.contentwidth; + totalsize += (float)child.contentwidth; } else if (child.maxwidth<targetsize) { max_maxsize = max(max_maxsize, child.maxwidth); num_maxsize++; - total += (float)child.maxwidth; + totalsize += (float)child.maxwidth; } else { numflexible++; - total += targetsize; + totalsize += targetsize; } } + if (numactive==0) { // no active children - nothing to do return; } + // test to see if targetsize produces a solution that rounds // to match the width, adjusting appropriatly if it does not - int itotal = (int)(total+0.5); - if (itotal > width) { + int totalsize_int = (int)(totalsize+0.5); + if (totalsize_int > width) { if (numflexible>0) { - targetsize -= (total-(float)width)/(float)numflexible; + targetsize -= (totalsize-(float)width)/(float)numflexible; } else { if (num_minsize+num_passive==numactive) { // no solution required - avaiable min-sizes over-consume width targetsize = width; break; } - targetsize = (float)max_maxsize - (total-(float)width)/(float)num_maxsize; + targetsize = (float)max_maxsize - (totalsize-(float)width)/(float)num_maxsize; } - } else if (itotal < width) { + } else if (totalsize_int < width) { if (numflexible>0) { - targetsize += ((float)width-total)/(float)numflexible; + targetsize += ((float)width-totalsize)/(float)numflexible; } else { if (num_maxsize+num_passive==numactive) { // no solution required - avaiable max-sizes do not consume width targetsize = width; break; } - targetsize = (float)min_minsize + ((float)width-total)/(float)num_minsize; + targetsize = (float)min_minsize + ((float)width-totalsize)/(float)num_minsize; } } else { break; } + // reset outer variables and try again numactive = 0; - total = 0; + totalsize = 0; + // REMARK: this is error / infinite loop prevention // giving a helpful report if no solution is found if (j>=99) { @@ -838,10 +842,13 @@ } } - float slack_x = (int)(total+0.5)>=width ? 0 : ((float)width-total)/(float)numactive; + // if there is 'slack' (child boxes do not consume parent width) then + // align determines whether we pack boxes to left, centre, or right + int offset_x = (int)(totalsize+0.5)>=width || left ? 0 : (int)(((float)width-totalsize)/(float)(right?1:2)); + // we use total (a float) to keep tabs on final layout totals // so we do not get stray pixel sized gaps caused by rounding - total = 0; + totalsize = 0; for (Box child = getChild(i=0); child != null; child = getChild(++i)) { if (!child.test(DISPLAY)) { continue; @@ -850,23 +857,17 @@ child_height = child.test(VSHRINK) ? child.contentheight : min(child.maxheight, height); child_y = top ? 0 : (bottom ? height-child_height : (height-child_height)/2); // width, x - if (slack_x > 0.0) { - child_x = (int)(total+0.5+(left ? 0 : (right ? slack_x : slack_x/2))); - child_width = child.test(HSHRINK) ? child.contentwidth : child.maxwidth; - total += slack_x + (float)child_width; + child_x = offset_x + (int)(totalsize+0.5); + if (child.test(HSHRINK) || child.contentwidth > targetsize) { + child_width = child.contentwidth; + totalsize += (float)child_width; + } else if (targetsize > child.maxwidth) { + child_width = child.maxwidth; + totalsize += (float)child_width; } else { - child_x = (int)(total+0.5); - if (child.test(HSHRINK) || child.contentwidth > targetsize) { - child_width = child.contentwidth; - total += (float)child_width; - } else if (targetsize > child.maxwidth) { - child_width = child.maxwidth; - total += (float)child_width; - } else { - // REMARK: this bit of float magic makes layout gapless - child_width = (int)(total+targetsize+0.5)-(int)(total+0.5); - total += targetsize; - } + // REMARK: this bit of float magic makes layout gapless + child_width = (int)(totalsize+targetsize+0.5)-(int)(totalsize+0.5); + totalsize += targetsize; } child.tryMoveAndResize(child_x, child_y, child_width, child_height, clean); } @@ -894,7 +895,7 @@ // loop over the children attempting to set their width to // targetsize and adjust until it meets the parent width float targetsize = (float)height/(float)treeSize(); - float total = 0; + float totalsize = 0; int numactive = 0; for (int j=0; j<100; j++) { int min_minsize = MAX_DIMENSION; @@ -910,55 +911,59 @@ numactive++; if (child.test(VSHRINK) || child.maxheight==child.contentheight) { num_passive++; - total += child.contentheight; + totalsize += child.contentheight; } else if (child.contentheight>targetsize) { min_minsize = min(min_minsize, child.contentheight); num_minsize++; - total += (float)child.contentheight; + totalsize += (float)child.contentheight; } else if (child.maxheight<targetsize) { max_maxsize = max(max_maxsize, child.maxheight); num_maxsize++; - total += (float)child.maxheight; + totalsize += (float)child.maxheight; } else { numflexible++; - total += targetsize; + totalsize += targetsize; } } + if (numactive==0) { // no active children - nothing to do return; } + // test to see if targetsize produces a solution that rounds // to match the height, adjusting appropriatly if it does not - int itotal = (int)(total+0.5); - if (itotal > height) { + int totalsize_int = (int)(totalsize+0.5); + if (totalsize_int > height) { if (numflexible>0) { - targetsize -= (total-(float)height)/(float)numflexible; + targetsize -= (totalsize-(float)height)/(float)numflexible; } else { if (num_minsize+num_passive==numactive) { // no solution required - avaiable min-sizes over-consume height targetsize = height; break; } - targetsize = (float)max_maxsize - (total-(float)height)/(float)num_maxsize; + targetsize = (float)max_maxsize - (totalsize-(float)height)/(float)num_maxsize; } - } else if (itotal < height) { + } else if (totalsize_int < height) { if (numflexible>0) { - targetsize += ((float)height-total)/(float)numflexible; + targetsize += ((float)height-totalsize)/(float)numflexible; } else { if (num_maxsize+num_passive==numactive) { // no solution required - avaiable max-sizes do not consume height targetsize = height; break; } - targetsize = (float)min_minsize + ((float)height-total)/(float)num_minsize; + targetsize = (float)min_minsize + ((float)height-totalsize)/(float)num_minsize; } } else { break; } + // reset outer variables and try again numactive = 0; - total = 0; + totalsize = 0; + // REMARK: this is error / infinite loop prevention // giving a helpful report if no solution is found if (j>=99) { @@ -973,10 +978,13 @@ } } - float slack_y = (int)(total+0.5)>=height ? 0 : ((float)height-total)/(float)numactive; + // if there is 'slack' (child boxes do not consume parent width) then + // align determines whether we pack boxes to left, centre, or right + int offset_y = (int)(totalsize+0.5)>=height || top ? 0 : (int)(((float)height-totalsize)/(float)(bottom?1:2)); + // we use total (a float) to keep tabs on final layout totals // so we do not get stray pixel sized gaps caused by rounding - total = 0; + totalsize = 0; for (Box child = getChild(i=0); child != null; child = getChild(++i)) { if (!child.test(DISPLAY)) { continue; @@ -985,23 +993,17 @@ child_width = child.test(HSHRINK) ? child.contentwidth : min(child.maxwidth, width); child_x = left ? 0 : (right ? width-child_width : (width-child_width)/2); // height, y - if (slack_y > 0.0) { - child_y = (int)(total+0.5+(top ? 0 : (bottom ? slack_y : slack_y/2))); - child_height = child.test(VSHRINK) ? child.contentheight : child.maxheight; - total += slack_y + child_height; + child_y = offset_y + (int)(totalsize+0.5); + if (child.test(VSHRINK) || child.contentheight > targetsize) { + child_height = child.contentheight; + totalsize += (float)child_height; + } else if (targetsize > child.maxheight) { + child_height = child.maxheight; + totalsize += (float)child_height; } else { - child_y = (int)(total+0.5); - if (child.test(VSHRINK) || child.contentheight > targetsize) { - child_height = child.contentheight; - total += (float)child_height; - } else if (targetsize > child.maxheight) { - child_height = child.maxheight; - total += (float)child_height; - } else { - // REMARK: this bit of float magic makes layout gapless - child_height = (int)(total+targetsize+0.5)-(int)(total+0.5); - total += targetsize; - } + // REMARK: this bit of float magic makes layout gapless + child_height = (int)(totalsize+targetsize+0.5)-(int)(totalsize+0.5); + totalsize += targetsize; } child.tryMoveAndResize(child_x, child_y, child_width, child_height, clean); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! Discover the easy way to master current and previous Microsoft technologies and advance your career. Get an incredible 1,500+ hours of step-by-step tutorial videos with LearnDevNow. Subscribe today and save! http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn