Mercurial > projects > mde
diff mde/gui/widget/layout.d @ 139:29a524e7c858
Fixed a resizing issue and added a popup menu for all content.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Sun, 08 Feb 2009 11:55:36 +0000 |
parents | 3468e9bfded1 |
children | c94ec5594449 |
line wrap: on
line diff
--- a/mde/gui/widget/layout.d Sat Feb 07 13:28:52 2009 +0000 +++ b/mde/gui/widget/layout.d Sun Feb 08 11:55:36 2009 +0000 @@ -627,12 +627,14 @@ /** Adjust total size with direction dir. * - * nw should be at least the minimal width. */ + * nw should be at least the minimal width. + * + * Returns: the final width */ wdim resizeWidth (wdim nw, int dir) { debug assert (width, "AlignColumns not initialized when resizeWidth called (code error)"); - if (nw < mw) { - debug logger.warn ("Widget dimension set below minimal"); - nw = mw; + debug if (nw < mw) { + logger.warn ("Widget dimension set below minimal (code error)"); + return w; } if (nw == w) return w; @@ -706,16 +708,18 @@ if (minWidth[col] < nmw) { // increase minimal minWidth[col] = nmw; nd = width[col] - nmw; // negative diff + if (nd > 0) + nd = 0; // don't decrease our width! } else if (minWidth[col] > nmw) { // potentially decrease minimal - nmw = 0; + nmw = 0; // set nmw to max of all cell min widths for (size_t r = 0; r < rows; ++r) { wdim mcw = minCellWidths[col+r*cols]; if (nmw < mcw) nmw = mcw; } minWidth[col] = nmw; - if (!sizable[col]) - nd = width[col] - nmw; + if (!sizable[col] && lastSizable >= 0) + nd = width[col] - nmw; // Not resizable but another column is } else return false; @@ -727,8 +731,10 @@ width[col] = nmw; foreach (cb; cbs) cb.setWidth (col, nmw, -1); - if (lastSizable >= 0) - adjustCellSizes (nd, lastSizable, -1); // doesn't necessarily resize exactly + if (lastSizable >= 0) { + if (nd != adjustCellSizes (nd, lastSizable, -1)) + logger.error ("New minimal size not applied correctly (code error): minWidth: {}, nmw: {}, col: {}, nd: {}", minWidth, nmw, col, nd); + } genPositions; } @@ -759,11 +765,12 @@ * Returns: * The amount adjusted. This may be larger than diff, since cellD is clamped by cellDMin. * - * Doesn't touch non-sizable columns (except start which is only assumed sizable). + * Will shrink non-sizable columns if they're over minimal size. + * Will increase column start, since it's assumed sizable. * - * Note: Check variable used for start is valid before calling! If a non-sizable column's - * index is passed, this should get increased (if diff > 0) but not decreased. - */ + * Note: Check variable used for start is valid before calling! If a non- + * sizable column's index is passed, this should get increased (if diff > 0) + * but not decreased. */ private wdim adjustCellSizes (wdim diff, ptrdiff_t start, int incr) in { assert (width.length == cols, "CellAlign.adjustCellSizes: width is invalid (code error)"); @@ -780,30 +787,26 @@ } else if (diff < 0) { // decrease wdim rd = diff; // running diff - aCSwhile: - while (true) { - width[i] += rd; // decrease this cell's size (but may be too much) - rd = width[i] - minWidth[i]; - if (rd >= 0) { // OK; we're done + while (i >= 0 && i < cols) { + if (width[i] > minWidth[i]) { + width[i] += rd; // decrease this cell's size (but may be too much) + rd = width[i] - minWidth[i]; + if (rd >= 0) { // OK; we're done + foreach (cb; cbs) + cb.setWidth (i, width[i], incr); + break; // we hit the mark exactly: diff is correct + } + + // else we decreased it too much! + width[i] = minWidth[i]; foreach (cb; cbs) - cb.setWidth (i, width[i], incr); - break; // we hit the mark exactly: diff is correct + cb.setWidth (i, width[i], incr); + // rd is remainder to decrease by } - // else we decreased it too much! - width[i] = minWidth[i]; - foreach (cb; cbs) - cb.setWidth (i, width[i], incr); - // rd is remainder to decrease by - - do { - i += incr; - if (i < 0 || i >= cols) { // run out of next cells - diff -= rd; // still had rd left to decrease - break aCSwhile; // exception: Array index out of bounds - } - } while (!sizable[i]) // iterate again if row/col isn't resizable + i += incr; } + diff -= rd; // still had rd left to decrease (may be 0) } // else no adjustment needed (diff == 0)