diff mde/gui/widget/layout.d @ 93:08a4ae11454b

Widgets now save dimensions without preventing structural changes in the base config file from applying. Widget dimensional data separated from other data in files, hence above change. Moved TextAdapter from TextWidget to IRenderer.
author Diggory Hardy <diggory.hardy@gmail.com>
date Tue, 21 Oct 2008 11:35:15 +0100
parents 085f2ca31914
children 9520cc0448e5
line wrap: on
line diff
--- a/mde/gui/widget/layout.d	Tue Oct 21 09:57:19 2008 +0100
+++ b/mde/gui/widget/layout.d	Tue Oct 21 11:35:15 2008 +0100
@@ -61,17 +61,13 @@
     this (IWidgetManager mgr, 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);
+        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 or also contains row & col widths,
-        // strings' length is correct:
-        if (rows < 1 || cols < 1 ||
-            (data.ints.length != 4 && data.ints.length != 4 + rows + cols) ||
-            data.strings.length != rows * cols)
+        // 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)
             throw new WidgetDataException (this);
-        this.data = data;
         
         // Get all sub-widgets
         subWidgets.length = rows*cols;
@@ -79,25 +75,20 @@
             subWidget = mgr.makeWidget (data.strings[i], content);
         }
         
-        if (data.ints.length == 4 + rows + cols)
-            initWidths = cast(wdim[]) data.ints[4..$];
+        initWidths = mgr.dimData (id);  // may be null, tested later
         
         super (mgr, id, data);
     }
     
     // Save column/row sizes. Currently always do so.
-    bool saveChanges (widgetID id) {
-        with (data) {
-            foreach (i, widget; subWidgets) // recurse on subwidgets
-                widget.saveChanges (strings[i]);
-            
-            ints = ints[0..4] ~ cast(int[])col.width ~ cast(int[])row.width;
-        }
-        mgr.setData (id, data);
+    bool saveChanges () {
+        foreach (widget; subWidgets) // recurse on subwidgets
+            widget.saveChanges ();
+        
+        mgr.setDimData (id, col.width ~ row.width);
         return true;
     }
 protected:
-    WidgetData data;
 }
 
 
@@ -114,26 +105,24 @@
         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 (sWId, c);
+            subWidgets[i] = mgr.makeWidget (data.strings[0], c);
         }
         super (mgr, id, data);
     }
     
-    bool saveChanges (widgetID id) {
+    bool saveChanges () {
         // 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);
+        return subWidgets[0].saveChanges;
     }
     
 private:
     OptionList optsList;
-    widgetID sWId;      // sub-widget's ID, for calling saveChanges FIXME no longer pass?
 }
 
 
@@ -187,15 +176,15 @@
      *
      * As such, this must be the first function called after this(). */
     void finalize () {
-        if (initWidths) {
-            debug assert (initWidths.length == cols + rows, "initWidths provided but has bad length");
+        logger.trace ("initWidths.length: {}", initWidths.length);
+        if (initWidths.length == cols + rows) {
             col.setWidths (initWidths[0..cols]);
             row.setWidths (initWidths[cols..$]);
-            initWidths = null;  // free
         } else {
             col.setWidths;
             row.setWidths;
         }
+        initWidths = null;  // free
         
         mw = col.mw;
         mh = row.mw;