# HG changeset patch # User Diggory Hardy # Date 1234106411 0 # Node ID c94ec559444970425fe9f95d71afaac4c5df8b3d # Parent 29a524e7c8581fef1d4346b6a23da3b362c17c0e Fixed a bug with changing the minimal size and optimised it slightly. diff -r 29a524e7c858 -r c94ec5594449 codeDoc/jobs.txt --- a/codeDoc/jobs.txt Sun Feb 08 11:55:36 2009 +0000 +++ b/codeDoc/jobs.txt Sun Feb 08 15:20:11 2009 +0000 @@ -3,7 +3,6 @@ In progress: -Still a resizing issue (needs SIZABILITY = SIZABILITY_ENUM.ANY_SUBWIDGETS to make options window resizable): enlarge options box, change tab, shrink and change back. Changing content from menu. diff -r 29a524e7c858 -r c94ec5594449 mde/gui/widget/Ifaces.d --- a/mde/gui/widget/Ifaces.d Sun Feb 08 11:55:36 2009 +0000 +++ b/mde/gui/widget/Ifaces.d Sun Feb 08 15:20:11 2009 +0000 @@ -55,10 +55,12 @@ /** Child widgets should call this on their parent if their minimal size * changes, since they cannot properly resize themselves. * - * Children may depend on their parent resizing them if necessary to keep - * width valid. To ease adjustments with layouts, widgets $(I may) enlarge - * themselves, but shouldn't shrink themselves. Widgets may also depend on - * setPosition being called afterwards. + * Parents $(I must) increase their child's size if the child is too small. + * Parents $(I must not) decrease their own size, even if they are not + * sizable; they may only decrease their childrens' sizes if it does not + * affect their own (i.e. WidgetManager and FloatingAreaWidget). + * + * Child widgets may depend on setPosition being called afterwards. * * Params: * widget = The child widget calling the function @@ -83,7 +85,7 @@ START_TRUE = 1, /// Flag set by ALWAYS and ALL_SUBWIDGETS SUBWIDGETS = 2, /// Flag set by ALL_SUBWIDGETS and ANY_SUBWIDGETS } - static const SIZABILITY = SIZABILITY_ENUM.ALL_SUBWIDGETS; /// ditto + static const SIZABILITY = SIZABILITY_ENUM.ANY_SUBWIDGETS; /// ditto } /****************************************************************************** diff -r 29a524e7c858 -r c94ec5594449 mde/gui/widget/layout.d --- a/mde/gui/widget/layout.d Sun Feb 08 11:55:36 2009 +0000 +++ b/mde/gui/widget/layout.d Sun Feb 08 15:20:11 2009 +0000 @@ -262,12 +262,18 @@ // simply calling setWidth/setHeight wouldn't work. override void minWChange (IChildWidget widg, wdim nmw) { size_t i = getWidgetIndex(widg); - col.newMinWidth (i%cols, i/cols + colR, nmw); - // callbacks to all sharing layouts do the rest + if (!col.newMinWidth (i%cols, i/cols + colR, nmw)) { + // don't propegate call to parent; set position as required + widg.setPosition (x + col.pos[i % cols], y + row.pos[i / cols]); + mgr.requestRedraw; + } // else callbacks to all sharing layouts do the rest } override void minHChange (IChildWidget widg, wdim nmh) { size_t i = getWidgetIndex(widg); - row.newMinWidth (i/cols, i%cols + rowR, nmh); + if (!row.newMinWidth (i/cols, i%cols + rowR, nmh)) { + widg.setPosition (x + col.pos[i % cols], y + row.pos[i / cols]); + mgr.requestRedraw; + } } //END Size & position @@ -408,23 +414,13 @@ } } - void colNewMW (bool mwChange) { - if (mwChange) { - w = col.w; - parent.minWChange (this, col.mw); - } else { // don't propegate call to parent - setPosition (x,y); - mgr.requestRedraw; - } + void colNewMW () { + w = col.w; + parent.minWChange (this, col.mw); } - void rowNewMW (bool mwChange) { - if (mwChange) { - h = row.w; - parent.minHChange (this, row.mw); - } else { // don't propegate call to parent - setPosition (x,y); - mgr.requestRedraw; - } + void rowNewMW () { + h = row.w; + parent.minHChange (this, row.mw); } @@ -700,26 +696,32 @@ /** Called when one of the cells in column col now has minimal width nmw. * - * Enlarges column minimal width if necessary; tries to keep total width the same. */ - void newMinWidth (size_t col, size_t row, wdim nmw) { + * Enlarges column minimal width if necessary; tries to keep total width + * the same. + * + * Returns: true if min-width changes (callbacks do necessary work), + * false if no change to mw (position should still be reset). */ + bool newMinWidth (size_t col, size_t row, wdim nmw) { minCellWidths[col + row*cols] = nmw; wdim nd = 0; // negative diff to keep overall size constant if possible - wdim omw = minWidth[col]; // to check if mw actually changes 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! + nd = 0; // Don't decrease if already larger (mustn't shrink self) } else if (minWidth[col] > nmw) { // potentially decrease minimal - nmw = 0; // set nmw to max of all cell min widths + // set nmw to max of all cell min widths in col: for (size_t r = 0; r < rows; ++r) { wdim mcw = minCellWidths[col+r*cols]; if (nmw < mcw) nmw = mcw; } + if (minWidth[col] == nmw) // no change + return false; minWidth[col] = nmw; if (!sizable[col] && lastSizable >= 0) nd = width[col] - nmw; // Not resizable but another column is + // Else leave larger; mustn't shrink ourself } else return false; @@ -737,10 +739,11 @@ } genPositions; } - - bool mwChange = nmw != omw; // size only changes if true, presuming old size is valid + + debug logger.trace ("newMW for col: minWidth: {}, nmw: {}, col: {}, nd: {}, mw: {}, w: {}", minWidth, nmw, col, nd, mw, w); foreach (cb; cbs) - cb.newMW (mwChange); + cb.newMW (); + return true; } /* Generate position infomation for each column and set w. */ @@ -838,7 +841,7 @@ package struct CallbackStruct { void delegate (size_t,wdim,int) setWidth; // set width of a column, with resize direction void delegate (uint,uint) sADD; // setupAlignDimData dlgs - void delegate (bool) newMW; // propegate or finalize minimal width change + void delegate () newMW; // propegate or finalize minimal width change } CallbackStruct cbs[]; diff -r 29a524e7c858 -r c94ec5594449 mde/gui/widget/miscContent.d --- a/mde/gui/widget/miscContent.d Sun Feb 08 11:55:36 2009 +0000 +++ b/mde/gui/widget/miscContent.d Sun Feb 08 15:20:11 2009 +0000 @@ -183,11 +183,11 @@ mh = currentW.minHeight; parent.minWChange (this, mw); parent.minHChange (this, mh); - // If resizable and already large enough, don't resize; else do. - if (isWS && w > mw) currentW.setWidth (w, -1); - else w = currentW.width; - if (isHS && h > mh) currentW.setHeight (h, -1); - else h = currentW.height; + // Parent may change size. If it doesn't, we must set child's size. + // We can't tell if it did, so do it (call will be fast if size isn't + // changed anyway). + currentW.setWidth (w, -1); + currentW.setHeight (h, -1); currentW.setPosition (x,y); }