Mercurial > projects > mde
diff mde/gui/widget/layout.d @ 92:085f2ca31914
Shared alignments supported in more complex cases.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Tue, 21 Oct 2008 09:57:19 +0100 |
parents | 4d5d53e4f881 |
children | 08a4ae11454b |
line wrap: on
line diff
--- a/mde/gui/widget/layout.d Thu Oct 16 17:43:48 2008 +0100 +++ b/mde/gui/widget/layout.d Tue Oct 21 09:57:19 2008 +0100 @@ -114,17 +114,26 @@ OptionList optsList = OptionList.trial(); rows = optsList.list.length; cols = 1; + sWId = data.strings[0]; // Get all sub-widgets subWidgets.length = rows*cols; foreach (i, c; optsList.list) { - subWidgets[i] = mgr.makeWidget (data.strings[0], c); + subWidgets[i] = mgr.makeWidget (sWId, c); } super (mgr, id, data); } + bool saveChanges (widgetID id) { + // Since all sub-widgets have the same id, it only makes sense to call on one + if (subWidgets is null) + return false; + return subWidgets[0].saveChanges (sWId); + } + private: OptionList optsList; + widgetID sWId; // sub-widget's ID, for calling saveChanges FIXME no longer pass? } @@ -138,7 +147,7 @@ * * The grid has no border but has spacing between widgets. *************************************************************************************************/ -abstract class GridWidget : Widget +abstract class GridWidget : ParentWidget { //BEGIN Creation & saving /** Partial constructor for a grid layout widget. @@ -148,7 +157,10 @@ * the call to genCachedConstructionData can be moved to the derived this() methods.) * * Derived constructors may also set initWidths to the array of column widths followed by - * row heights used to initially set the row/column dimensions. */ + * row heights used to initially set the row/column dimensions. + * + * Sub-widgets are finalized here, so no methods should be called on sub-widgets before calling + * this super. */ protected this (IWidgetManager mgr, widgetID id, WidgetData data) { super (mgr, id, data); @@ -163,40 +175,39 @@ else row = (new AlignColumns (rows)); row.addSetCallback (&setRowHeight); - - // Calculate cached construction data - genCachedConstructionData; + } + + /** Prior to finalizing but after sub-widgets are finalized, some information needs to be + * passed to the AlignColumns. */ + void prefinalize () { + genCachedConstructionData; // min widths, sizableness } /** Responsible for calculating the minimal size and initializing some stuff. * * As such, this must be the first function called after this(). */ - wdim minWidth () { - if (!alignInit) { // assumes col & row.width are initialized simultaneously - alignInit = true; - if (initWidths) { - debug assert (initWidths.length == cols + rows, "initWidths provided but has bad length"); - col.setWidths (initWidths[0..cols]); - row.setWidths (initWidths[cols..$]); - initWidths = null; // free - } else { - col.setWidths; - row.setWidths; - } - - mw = col.mw; - mh = row.mw; - w = col.w; - h = row.w; - - // Tell subwidgets their new sizes. Positions are given by a later call to setPosition. - foreach (i,widget; subWidgets) { - // Resizing direction is arbitrarily set to negative: - widget.setWidth (col.width[i % cols], -1); - widget.setHeight (row.width[i / cols], -1); - } + void finalize () { + if (initWidths) { + debug assert (initWidths.length == cols + rows, "initWidths provided but has bad length"); + col.setWidths (initWidths[0..cols]); + row.setWidths (initWidths[cols..$]); + initWidths = null; // free + } else { + col.setWidths; + row.setWidths; } - return mw; + + mw = col.mw; + mh = row.mw; + w = col.w; + h = row.w; + + // Tell subwidgets their new sizes. Positions are given by a later call to setPosition. + foreach (i,widget; subWidgets) { + // Resizing direction is arbitrarily set to negative: + widget.setWidth (col.width[i % cols], -1); + widget.setHeight (row.width[i / cols], -1); + } } //END Creation & saving @@ -279,9 +290,10 @@ * Also need to be re-run if the renderer changes. * * rows, cols and subWidgets must be set before calling. Part of the set-up for AlignColumns - * (col and row). */ + * (col and row). subWidgets need to know their minimal size and resizability. */ void genCachedConstructionData () { // Will only change if renderer changes: + // NOTE shared AlignColumns get this set by all sharing GridWidgets col.spacing = row.spacing = mgr.renderer.layoutSpacing; // Calculate the minimal column and row sizes: @@ -361,11 +373,10 @@ myIt cols, rows; // number of cells in grid wdim[] initWidths; // see this / setInitialSize - bool alignInit; // have AlignColumns instances been initialized? /* All widgets in the grid, by row. Order: [ 0 1 ] * [ 2 3 ] */ - IChildWidget[] subWidgets; + //IChildWidget[] subWidgets; AlignColumns col, row; }