Mercurial > projects > mde
diff mde/gui/widget/layout.d @ 121:5b37d0400732
Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
WidgetManager code redistributed between classes; WMScreen class moved to WMScreen.d.
addContent function now calls makeWidget with another id.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Fri, 02 Jan 2009 18:07:10 +0000 |
parents | 9ac208b53582 |
children | d3b2cefd46c9 |
line wrap: on
line diff
--- a/mde/gui/widget/layout.d Thu Jan 01 15:16:00 2009 +0000 +++ b/mde/gui/widget/layout.d Fri Jan 02 18:07:10 2009 +0000 @@ -56,26 +56,25 @@ * list) for the widget in row i and column j. The number of parameters must be r*c + 3. * * The content parameter is passed on to all children accepting an IContent. */ - this (IWidgetManager mgr, widgetID id, WidgetData data, IContent content) { + this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent content) { // Get grid size and check data // Check sufficient data for type, align-flags, rows, cols, and possibly row/col widths. if (data.ints.length != 4) throw new WidgetDataException (this); rows = data.ints[2]; cols = data.ints[3]; - // Check: at least one sub-widget, ints length == 3, strings' length is correct: - if (rows < 1 || cols < 1 || data.ints.length != 4 || data.strings.length != rows * cols) + // Check: at least one sub-widget and strings's length is correct: + if (rows < 1 || cols < 1 || data.strings.length != rows * cols) throw new WidgetDataException (this); + super (mgr, parent, id, data); // Get all sub-widgets subWidgets.length = rows*cols; foreach (i, ref subWidget; subWidgets) { - subWidget = mgr.makeWidget (data.strings[i], content); + subWidget = mgr.makeWidget (this, data.strings[i], content); } initWidths = mgr.dimData (id); // may be null, tested later - - super (mgr, id, data); } // Save column/row sizes. Currently always do so. @@ -83,7 +82,7 @@ foreach (widget; subWidgets) // recurse on subwidgets widget.saveChanges (); - mgr.setDimData (id, col.width ~ row.width); + mgr.dimData (id, col.width ~ row.width); return true; } protected: @@ -98,25 +97,27 @@ *************************************************************************************************/ class ContentListWidget : GridWidget { - this (IWidgetManager mgr, widgetID id, WidgetData data, IContent content) { + this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent content) { cList = cast(IContentList) content; WDCCheck (data, 2, 1, cList); - + logger.trace ("Got data: {} and {}", data.ints, data.strings); cols = 1; - if ((rows = cList.list.length) > 0) { - subWidgets.length = rows; - foreach (i, c; cList.list) { - subWidgets[i] = mgr.makeWidget (data.strings[0], c); - } - } else { - rows = 1; - subWidgets = [mgr.makeWidget (data.strings[0], new ErrorContent ("<empty list>"))]; - } + rows = cList.list.length; + subWidgets.length = rows; if (data.ints[1] & 8) { // orient horizontally cols = rows; rows = 1; } - super (mgr, id, data); + super (mgr, parent, id, data); + + if (subWidgets) { // i.e. rows*cols > 0 + foreach (i, c; cList.list) { + subWidgets[i] = mgr.makeWidget (this, data.strings[0], c); + } + } else { + rows = cols = 1; + subWidgets = [mgr.makeWidget (this, data.strings[0], new ErrorContent ("<empty list>"))]; + } } override bool saveChanges () { @@ -146,14 +147,13 @@ //BEGIN Creation & saving /** Partial constructor for a grid layout widget. * - * Deriving classes should check data lengths, and set rows, cols, and the subWidgets array, - * before calling this super constructor. (If it's necessary to call super(...) first, - * the call to genCachedConstructionData can be moved to the derived this() methods.) + * Deriving classes should check data lengths, and set rows and cols + * before calling this super constructor. * * Derived constructors may also set initWidths to the array of column widths followed by * row heights used to initially set the row/column dimensions. */ - protected this (IWidgetManager mgr, widgetID id, WidgetData data) { - super (mgr, id, data); + protected this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data) { + super (mgr, parent, id); // Create cell aligners with appropriate col/row adjustment function if (data.ints[1] & 1) @@ -173,7 +173,8 @@ * * As such, this must be the first function called after this(). */ override bool setup (uint n, uint flags) { - // Run all internal calculations regardless of changes, then check dimensions for changes. + debug (mdeWidgets) logger.trace ("GridWidget.setup"); + // Run all internal calculations regardless of changes, then check dimensions for changes. // Don't try shortcutting internal calculations when there are no changes - I've tried, and // doing so adds enough overhead to make doing so almost(?) worthless (or at least large // increases in complexity). @@ -202,7 +203,7 @@ widget.setWidth (col.width[i % cols], -1); widget.setHeight (row.width[i / cols], -1); } - return (ow != w || oh != h); + return (ow != w || oh != h); } //END Creation & saving @@ -293,14 +294,16 @@ if (sADD_n == n) return; // cached data is current sADD_n = n; + debug (mdeWidgets) logger.trace ("GridWidget: setup on subWidgets..."); foreach (widg; subWidgets) { // make sure all subwidgets have been set up debug assert (widg); widg.setup (n,flags); } + debug (mdeWidgets) logger.trace ("GridWidget: setup on subWidgets...done"); // make sure both AlignColumns are set up (since first call to setup(n) calls reset): col.setup (n, flags); row.setup (n, flags); - + // Note: shared AlignColumns get this set by all sharing GridWidgets col.spacing = row.spacing = useSpacing ? mgr.renderer.layoutSpacing : 0;