changeset 130:c5c38eaadb64

Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable. Ifaces.IParentWidget.SIZABILITY controlling parent sizability. TextWidget no longer vertically resizable (since multi-line editing is not supported).
author Diggory Hardy <diggory.hardy@gmail.com>
date Sat, 17 Jan 2009 16:11:26 +0000
parents ad91de8867a0
children 9cff74f68b84
files codeDoc/jobs.txt mde/gui/widget/Floating.d mde/gui/widget/Ifaces.d mde/gui/widget/TextWidget.d mde/gui/widget/Widget.d mde/gui/widget/layout.d mde/gui/widget/miscContent.d
diffstat 7 files changed, 104 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/codeDoc/jobs.txt	Thu Jan 15 16:52:46 2009 +0000
+++ b/codeDoc/jobs.txt	Sat Jan 17 16:11:26 2009 +0000
@@ -3,7 +3,7 @@
 
 
 In progress:
-Note: shared alignment sizableness not set very logically.
+Still a resizing issue (needs SIZABILITY = SIZABILITY_ENUM.ANY_SUBWIDGETS to make options window resizable): enlarge options box, change tab, shrink and change back.
 
 
 To do (importance 0-5: 0 pointless, 1 no obvious impact now, 2 todo sometime, 3 useful, 4 important, 5 urgent):
--- a/mde/gui/widget/Floating.d	Thu Jan 15 16:52:46 2009 +0000
+++ b/mde/gui/widget/Floating.d	Sat Jan 17 16:11:26 2009 +0000
@@ -104,8 +104,12 @@
         }
     }
     
-    override bool isWSizable () {    return true;    }
-    override bool isHSizable () {    return true;    }
+    override bool isWSizable () {
+        return true;
+    }
+    override bool isHSizable () {
+        return true;
+    }
     
     override void setPosition (wdim nx, wdim ny) {
         x = nx;
--- a/mde/gui/widget/Ifaces.d	Thu Jan 15 16:52:46 2009 +0000
+++ b/mde/gui/widget/Ifaces.d	Sat Jan 17 16:11:26 2009 +0000
@@ -15,6 +15,9 @@
 
 /*************************************************************************************************
  * Widget interfaces.
+ * 
+ * This module contains the primary documentation for the declared methods; also the Widget module
+ * has some brief comments and basic implementations.
  *
  * Widgets are connected as the nodes of a tree. Widgets know their parent as a IParentWidget
  * class and their children as IChildWidget classes. The gui manager is a special widget only
@@ -55,6 +58,24 @@
      *	mh	= New minimal height */
     void minWChange (IChildWidget widget, wdim mw);
     void minHChange (IChildWidget widget, wdim mh);	/// ditto
+    
+    /** Governor of parent widget resizability, where this is determined by sub-widgets
+     * (e.g. this doesn't apply to FloatingAreaWidget).
+     *
+     * NEVER and ALWAYS often don't result in usable GUIs, and aren't expected to be used except
+     * for debugging.
+     * 
+     * NOTE: ANY_SUBWIDGETS can cause problems like enlarging a menu bar containing a resizable
+     * blank instead of the main part of a window. */
+    enum SIZABILITY_ENUM {
+        NEVER		= 0,	/// Parents are never resizable
+        ALL_SUBWIDGETS	= 3,	/// Parents are only resizable if all sub-widgets are
+        ANY_SUBWIDGETS	= 2,	/// Parents are resizable if any sub-widgets are
+        ALWAYS		= 1,	/// Parents are always resizable
+        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
 }
 
 
@@ -212,10 +233,11 @@
 //BEGIN Size and position
     /** Is the width / height resizable?
      *
-     * This really means does the widget benifit from being enlarged? Any widget should occupy
-     * additional area when expanded.
-     *
-     * If not, the widget has fixed dimensions equal to it's minimal size. */
+     * Normally, this means does the widget benifit from being enlarged? If not, the widget has
+     * "fixed" dimensions equal to it's minimal size; however it $(I may) still be enlarged.
+     * 
+     * Parents normally take their resizability from sub-widgets; see SIZABILITY for how they do
+     * this. */
     bool isWSizable ();
     bool isHSizable (); /// ditto
     
--- a/mde/gui/widget/TextWidget.d	Thu Jan 15 16:52:46 2009 +0000
+++ b/mde/gui/widget/TextWidget.d	Sat Jan 17 16:11:26 2009 +0000
@@ -138,8 +138,12 @@
 	adapter.text = content.toString(0);
     }
     
-    override bool isWSizable () {    return true;    }
-    override bool isHSizable () {    return true;    }
+    override bool isWSizable () {
+        return true;
+    }
+    override bool isHSizable () {
+        return false;
+    }
     
     /** On click, request keyboard input. */
     override int clickEvent (wdabs cx, wdabs, ubyte, bool) {
--- a/mde/gui/widget/Widget.d	Thu Jan 15 16:52:46 2009 +0000
+++ b/mde/gui/widget/Widget.d	Sat Jan 17 16:11:26 2009 +0000
@@ -82,8 +82,13 @@
 //END Load and save
     
 //BEGIN Size and position
-    override bool isWSizable () {    return false;   }
-    override bool isHSizable () {    return false;   }
+    // default to not resizable
+    override bool isWSizable () {
+        return false;
+    }
+    override bool isHSizable () {
+        return false;
+    }
     
     /* Return minimal/fixed size. */
     override wdim minWidth () {
@@ -163,7 +168,7 @@
     
     // Debug function to print size info. Intended to be correct not optimal.
     debug override void logWidgetSize () {
-        logger.trace ("Current size: {,4},{,4}; minimal: {,4},{,4} - {,-50} {}", w,h, this.minWidth, this.minHeight, this, id);
+        logger.trace ("Current size: {,4},{,4}; minimal: {,4},{,4}; sizable: {,5},{,5} - {,-50} {}", this.width, this.height, this.minWidth, this.minHeight, this.isWSizable, this.isHSizable, this, id);
     }
     
 protected:
@@ -229,7 +234,7 @@
         debug (mdeWidgets) logger.trace ("AParentWidget.setup");
         bool c = false;
 	foreach (w; subWidgets) {
-	    debug assert (w);
+            debug assert (w, "AParentWidget: w is null");
 	    c |= w.setup (n,flags);
 	}
 	return c;
@@ -268,7 +273,7 @@
     
     override bool setup (uint n, uint flags) {
         debug (mdeWidgets) logger.trace ("AParentSingleWidget.setup");
-        debug assert (subWidget);
+        debug assert (subWidget, "AParentSingleWidget: subWidget is null");
 	return subWidget.setup (n,flags);
     }
     
@@ -308,8 +313,12 @@
         super (mgr, parent, id);
     }
     
-    override bool isWSizable () {    return true;    }
-    override bool isHSizable () {    return true;    }
+    override bool isWSizable () {
+        return true;
+    }
+    override bool isHSizable () {
+        return true;
+    }
 }
 
 /** For pressable buttons.
--- a/mde/gui/widget/layout.d	Thu Jan 15 16:52:46 2009 +0000
+++ b/mde/gui/widget/layout.d	Sat Jan 17 16:11:26 2009 +0000
@@ -350,23 +350,39 @@
         
         // Find which cols/rows are resizable:
         // AlignColumns initializes sizable, and sets first and last sizables.
+        static if (!(SIZABILITY & SIZABILITY_ENUM.SUBWIDGETS)) return;
         forCols:
         for (size_t i = 0; i < cols; ++i) {				// for each column
-            for (size_t j = 0; j < subWidgets.length; j += cols)	// for each row
-                if (!subWidgets[i+j].isWSizable)	// column not resizable
-                    continue forCols;			// continue the outer for loop
-            
-            // column is resizable if we get to here
-            col.sizable[i] = true;
+            for (size_t j = 0; j < subWidgets.length; j += cols) {	// for each row
+                static if (SIZABILITY == SIZABILITY_ENUM.ALL_SUBWIDGETS) {
+                    if (!subWidgets[i+j].isWSizable) {	// column not resizable
+                        col.sizable[i] = false;
+                        continue forCols;		// no point checking more
+                    }
+                } else {
+                    if (subWidgets[i+j].isWSizable) {	// column is resizable
+                        col.sizable[i] = true;
+                        continue forCols;
+                    }
+                }
+            }
         }
         
         forRows:
         for (size_t i = 0; i < subWidgets.length; i += cols) {	// for each row
-            for (size_t j = 0; j < cols; ++j)			// for each column
-                if (!subWidgets[i+j].isHSizable)
-                    continue forRows;
-            
-            row.sizable[i / cols] = true;
+            for (size_t j = 0; j < cols; ++j) {			// for each column
+                static if (SIZABILITY == SIZABILITY_ENUM.ALL_SUBWIDGETS) {
+                    if (!subWidgets[i+j].isHSizable) {
+                        row.sizable[i / cols] = false;
+                        continue forRows;
+                    }
+                } else {
+                    if (subWidgets[i+j].isHSizable) {
+                        row.sizable[i / cols] = true;
+                        continue forRows;
+                    }
+                }
+            }
         }
     }
     
@@ -485,6 +501,8 @@
 	    throw new GuiException("AlignColumns: created with <1 column (code error)");
 	minWidth.length = columns;
 	sizable.length = columns;
+        static if (SIZABILITY & SIZABILITY_ENUM.START_TRUE)
+            sizable[] = true;
         cols = columns;
     }
     
@@ -504,8 +522,12 @@
      *
      * Widths should be set after calling, as on creation. */
     void reset (size_t columns) {
+        assert (columns == cols, "no support for changing number of columns for now");
         minWidth[] = 0;
-        sizable[] = false;
+        static if (SIZABILITY & SIZABILITY_ENUM.START_TRUE)
+            sizable[] = true;
+        else
+            sizable[] = false;
         firstSizable = -1;
         lastSizable = -1;
     }
@@ -829,6 +851,9 @@
         instances = new HashMap!(widgetID,AlignColumns);
     }
     
+    alias IChildWidget.SIZABILITY SIZABILITY;
+    alias IChildWidget.SIZABILITY_ENUM SIZABILITY_ENUM;
+    
     debug invariant()
     {
         if (setupWidths) {
--- a/mde/gui/widget/miscContent.d	Thu Jan 15 16:52:46 2009 +0000
+++ b/mde/gui/widget/miscContent.d	Sat Jan 17 16:11:26 2009 +0000
@@ -147,11 +147,8 @@
             throw new ContentException (this);
         WDCheck (data, 1, subWidgets.length);
         
-        foreach (i,sc; content.list) {
+        foreach (i,sc; content.list)
             subWidgets[i] = mgr.makeWidget (this, data.strings[i], sc);
-            isWS |= subWidgets[i].isWSizable;
-            isHS |= subWidgets[i].isHSizable;
-        }
         currentW = subWidgets[content()];
         
         content.addCallback (&switchWidget);
@@ -164,6 +161,17 @@
             mh = currentW.minHeight;
             w = currentW.width;
             h = currentW.height;
+            static if (SIZABILITY & SIZABILITY_ENUM.START_TRUE)
+                    isWS = isHS = true;
+            foreach (i,sc; content.list) {
+                static if (SIZABILITY == SIZABILITY_ENUM.ANY_SUBWIDGETS) {
+                    isWS |= subWidgets[i].isWSizable;
+                    isHS |= subWidgets[i].isHSizable;
+                } else static if (SIZABILITY == SIZABILITY_ENUM.ALL_SUBWIDGETS) {
+                    isWS &= subWidgets[i].isWSizable;
+                    isHS &= subWidgets[i].isHSizable;
+                }
+            }
         }
         return r;
     }