diff mde/gui/WidgetManager.d @ 111:1655693702fc

Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run. Removed prefinalize and finalize and added setup as the new second initialization phase, which can be re-run.
author Diggory Hardy <diggory.hardy@gmail.com>
date Sat, 06 Dec 2008 17:41:42 +0000
parents 6acd96f8685f
children fe061009029d
line wrap: on
line diff
--- a/mde/gui/WidgetManager.d	Fri Dec 05 11:29:39 2008 +0000
+++ b/mde/gui/WidgetManager.d	Sat Dec 06 17:41:42 2008 +0000
@@ -173,6 +173,10 @@
         return rend;
     }
     
+    /** Place a pop-up widget near px,py.
+     *
+     * WidgetManager sets its position, draws it, passes it click events and removes it; other
+     * functionality should be handled by the widget's parent. */
     void addPopup (wdabs px, wdabs py, IChildWidget widg) {
         ActivePopup popup;
         with (popup) {
@@ -214,7 +218,7 @@
 	popups = new CircularList!(ActivePopup);
         
         child = makeWidget ("root");
-        finalize;
+        child.setup (0, 3);
         
         mw = child.minWidth;
         mh = child.minHeight;
@@ -444,7 +448,8 @@
     /** Called when translation strings have been reloaded. */
     void reloadStrings (AContent c) {
 	Items.loadTranslation;
-	child.reloadStrings;	//FIXME : all widgets, resize
+	child.setup (++setupN, 2);
+	child.setPosition (0,0);
 	requestRedraw;
     }
     
@@ -455,45 +460,16 @@
     * ---
     * // 1. Create the root widget:
     * child = makeWidget ("root");
-    * finalize;
-    * // 2. Set the setSize, e.g.:
+    * child.setup (0, 3);
+    * // 2. Set the size:
     * child.setWidth  (child.minWidth,  1);
     * child.setHeight (child.minHeight, 1);
+    * // 3. Set the position (necessary part of initialization):
+    * child.setPosition (0,0);
     * ---
     */
     void createRootWidget();
     
-    /** Runs finalize for all descendants, in a deepest first order. */
-    /* NOTE: The way this function works may seem a little odd, but it's designed to allow
-    * shared alignments to be initialized properly:
-    * 1. all sharing members need to know their children's min size
-    * 2. all sharing members need to add their children's min size to the alignment
-    * 3. all sharing members can only then get their min size
-    * This method will fail if alignment members are not all of the same generation. An alternate
-    * method without this drawback would be to have shared alignments created with a list of
-    * pointers to their members, and once all members have been created the alignment could
-    * initialize itself, first making sure each members' children have been initialized. */
-    void finalize () {
-	IChildWidget[][] descendants;   // first index: depth; is a list of widgets at each depth
-	
-	void recurseChildren (size_t depth, IChildWidget widget) {
-	    foreach (child; widget.children)
-		recurseChildren (depth+1, child);
-	    
-	    if (descendants.length <= depth)
-		descendants.length = depth * 2 + 1;
-	    descendants[depth] ~= widget;
-	}
-	
-	recurseChildren (0, child);
-	foreach_reverse (generation; descendants) {
-	    foreach (widget; generation)
-		widget.prefinalize;
-	    foreach (widget; generation)
-		widget.finalize;
-	}
-    }
-    
     /** Called before saving (usually when the GUI is about to be destroyed, although not
     *  necessarily). */
     void preSave ();
@@ -534,6 +510,7 @@
     bool loadUserFile = true;		// still need to load user file for saving?
     
     scope IChildWidget child;		// The primary widget.
+    uint setupN;			// n to pass to IChildWidget.setup
     
     Mutex mutex;			// lock on methods for use outside the package.
 }