changeset 176:d5d5fe04ca6c

Fixes to CollapsibleWidget. Disabled AChildWidget.invariant.
author Diggory Hardy <diggory.hardy@gmail.com>
date Sat, 12 Sep 2009 09:14:43 +0200
parents 1cbde9807293
children af40e9679436
files codeDoc/jobs.txt data/conf/guiDemo.mtt mde/gui/widget/AChildWidget.d mde/gui/widget/ParentContent.d mde/gui/widget/layout.d mde/gui/widget/miscContent.d
diffstat 6 files changed, 64 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/codeDoc/jobs.txt	Fri Sep 11 20:56:53 2009 +0200
+++ b/codeDoc/jobs.txt	Sat Sep 12 09:14:43 2009 +0200
@@ -3,35 +3,19 @@
 
 
 In progress:
-Made context menus display again.
-TODO: investigate why menu items don't show up.
+Optional context menus don't always show/hide properly.
 Having setContent recusively call on subWidgets is not quite right: where the addContent function was used to pass a different content, the content should not be reset by a content() call propegated from a parent.
 Why is ServiceContent.opCall() called in addition to call from CollapsibleWidget?
 Why is ServiceContentList.opCall() not called? Probably because it's callbacks are never called.
 
-Protection and invariants:
-    /** TODO: in progess - design of invariants
-     *
-     * Ideally this wants to be called after minXChange has finished, but not
-     * before/during. minXChange is called in 2 cases:
-     * 	recursively from a child
-     * 	from a change of content (setContent, keyEvent, content callbacks) - these can all be public
-     * 
-     * So minXChange should not be public? But then the invariant is never called on
-     * parent widgets affected by the size change, including many parent widgets
-     * where invariants would be really useful.
-     */
-So make sure draw() and a few others are public, and invariants get called at these points. Thus a lot more must have at least package protection.
-
-Implement a RootWidget moving functionality out of AWidgetManager, etc., now, or later?
-RequestRedraw becomes a function of the renderer.
-
 
 
 To do (importance 0-5: 0 pointless, 1 no obvious impact now, 2 todo sometime, 3 useful, 4 important, 5 urgent):
 Also search for FIXME/NOTE/BUG/WARNING comment marks.
 4   Move createWidget code out of WidgetManager.
 4   GUI: up-clicks get passed as events and activate objects
+3   RequestRedraw should become a function of the renderer.
+3   Implement a RootWidget moving functionality out of AWidgetManager, etc., now, or later?
 3   May be useful to make all widgets override draw() to ensure the invariant runs locally.
 3   Closing menus when release-click is not on menu or parent (ordinary & context).
 3   Dragging and dropping of editable data: should content immediately appear as being dragged?
--- a/data/conf/guiDemo.mtt	Fri Sep 11 20:56:53 2009 +0200
+++ b/data/conf/guiDemo.mtt	Sat Sep 12 09:14:43 2009 +0200
@@ -1,6 +1,6 @@
 {MT01}
 <char[]|Renderer="Simple">
-<char[]|Design="Basic">
+<char[]|Design="Working">
 {Working}
 <WidgetData|root={0:[0x4100,0,2,1],1:["bar","float"]}>
 <WidgetData|float={0:[0x4200,14,14],1:["options","sliderCB"]}>
--- a/mde/gui/widget/AChildWidget.d	Fri Sep 11 20:56:53 2009 +0200
+++ b/mde/gui/widget/AChildWidget.d	Sat Sep 12 09:14:43 2009 +0200
@@ -25,12 +25,10 @@
 import mde.content.IContent;
 import mde.gui.exception;
 
-debug {
-    import tango.util.log.Log : Log, Logger;
-    private Logger logger;
-    static this () {
-        logger = Log.getLogger ("mde.gui.widget.AChildWidget");
-    }
+import tango.util.log.Log : Log, Logger;
+private Logger logger;
+static this () {
+    logger = Log.getLogger ("mde.gui.widget.AChildWidget");
 }
 
 /******************************************************************************
@@ -100,11 +98,11 @@
     /* Set size: minimal size is (mw,mh). Note that both resizable and fixed widgets should allow
      * enlarging, so in both cases this is a correct implementation. */
     override void setWidth (wdim nw, int) {
-        debug if (nw < mw) logger.warn ("Widget width set below minimal size");
+        debug if (nw < mw) logger.warn ("Widget width set below minimal size ({}: {})", id, this);
         w = (nw >= mw ? nw : mw);
     }
     override void setHeight (wdim nh, int) {
-        debug if (nh < mh) logger.warn ("Widget height set below minimal size");
+        debug if (nh < mh) logger.warn ("Widget height set below minimal size ({}: {})", id, this);
         h = (nh >= mh ? nh : mh);
     }
     
@@ -213,9 +211,23 @@
         mgr.requestRedraw;
     }
     
+    /** TODO: in progess - design of invariants
+     *
+     * Ideally this wants to be called after minXChange has finished, but not
+     * before/during. minXChange is called in 2 cases:
+     * 	recursively from a child
+     * 	from a change of content (setContent, keyEvent, content callbacks) - these can all be public
+     * 
+     * So minXChange should not be public. At least the draw() method should be
+     * public so the invariant gets called often. The only protection that can
+     * be used for minXChange is package, however there's compiler bugs
+     * preventing package functions from being virtual! */
     invariant {
+	scope (failure)
+	    logger.warn ("invariant failed ({}: {}; parent is {})", id, this, parent);
+	/+ FIXME - see comment above
 	assert (w >= mw);
-	assert (h >= mh);
+	assert (h >= mh); +/
     }
     
     IWidgetManager mgr;		// the enclosing window
--- a/mde/gui/widget/ParentContent.d	Fri Sep 11 20:56:53 2009 +0200
+++ b/mde/gui/widget/ParentContent.d	Sat Sep 12 09:14:43 2009 +0200
@@ -291,7 +291,9 @@
             	mh = subWidgets[0].minHeight;
             	w = subWidgets[0].width;
             	h = subWidgets[0].height;
+		debug assert (w >= mw && h >= mh);
             }
+	    // else dims remain 0
         }
         return r;
     }
@@ -317,13 +319,19 @@
     
     override void minWChange (IChildWidget widget, wdim nmw) {
         debug assert (widget is subWidgets[0]);
-        mw = nmw;
-        parent.minWChange (this, nmw);
+	if (display) {
+	    mw = nmw;
+	    parent.minWChange (this, nmw);
+	} else	// update widget without affecting self
+	    super.minWChange (widget, nmw);
     }
     override void minHChange (IChildWidget widget, wdim nmh) {
         debug assert (widget is subWidgets[0]);
-        mh = nmh;
-        parent.minHChange (this, nmh);
+	if (display) {
+	    mh = nmh;
+	    parent.minHChange (this, nmh);
+	} else
+	    super.minHChange (widget, nmh);
     }
     
     // Doesn't change:
@@ -336,17 +344,20 @@
     
     override void setWidth (wdim nw, int dir) {
 	w = (nw >= mw ? nw : mw);
-        subWidgets[0].setWidth (w, dir);
+	if (display)
+	    subWidgets[0].setWidth (w, dir);
     }
     override void setHeight (wdim nh, int dir) {
         h = (nh >= mh ? nh : mh);
-        subWidgets[0].setHeight (h, dir);
+	if (display)
+	    subWidgets[0].setHeight (h, dir);
     }
     
     override void setPosition (wdim nx, wdim ny) {
         x = nx;
         y = ny;
-	if (display) subWidgets[0].setPosition (nx,ny);
+	if (display)
+	    subWidgets[0].setPosition (nx,ny);
     }
     
     override IChildWidget getWidget (wdim cx, wdim cy) {
@@ -356,7 +367,8 @@
     }
     
     override void draw () {
-        if (display) subWidgets[0].draw;
+        if (display)
+	    subWidgets[0].draw;
     }
     
 protected:
@@ -401,7 +413,8 @@
     }
     
     override bool setup (uint n, uint flags) {
-        if (!subWidgets[0].setup (n, flags) && !(flags & 1)) return false;
+	bool noChanges = !subWidgets[0].setup (n, flags);
+        if (noChanges && !(flags & 1)) return false;
         
         border = mgr.renderer.getBorder (borderType, false, false);
         mw = subWidgets[0].minWidth  + border.x1 + border.x2;
--- a/mde/gui/widget/layout.d	Fri Sep 11 20:56:53 2009 +0200
+++ b/mde/gui/widget/layout.d	Sat Sep 12 09:14:43 2009 +0200
@@ -470,7 +470,7 @@
      *                                          [ 2 3 ] */
     //IChildWidget[] subWidgets; (inherited from AParentWidget)
     
-    package AlignColumns col, row;	// aligners for cols and rows
+    AlignColumns col, row;	// aligners for cols and rows
 				// "rows" allocated in col and row; return value of *.addRows():
     size_t colR = size_t.max, rowR = size_t.max;
 }
@@ -488,7 +488,7 @@
  * Cells are not directly interacted with, but minimal widths for each column are passed, and
  * callback functions are used to adjust the width of any column.
  *************************************************************************************************/
-package class AlignColumns
+private class AlignColumns
 {
     /** Get an aligner.
      *
@@ -872,14 +872,14 @@
     wdim    spacing;            // used by genPositions (which cannot access the layout class's data)
     wdim    w,mw;               // current & minimal widths
     
-    package struct CallbackStruct {
+    private struct CallbackStruct {
         void delegate (size_t,wdim,int) setWidth; // set width of a column, with resize direction
     	void delegate (uint,uint) sADD;	// setupAlignDimData dlgs
         void delegate () newMW;	// propegate or finalize minimal width change
     }
     CallbackStruct cbs[];
     
-protected:
+private:
     /* Minimal width for each column.
      *
      * Set by setWidths. */
@@ -910,6 +910,17 @@
     {
         if (setupWidths) {
             assert (width.length == cols, "invariant: bad width length");
+	    assert (minCellWidths.length == rows * cols, "minCellWidths: bad length");
+	    wdim[] checkMinWidth = new wdim[cols];
+	    for (size_t c = 0; c < cols; ++c) {
+		for (size_t r = 0; r < rows; ++r) {
+		    wdim mcw = minCellWidths[c+r*cols];
+		    if (checkMinWidth[c] < mcw)
+			checkMinWidth[c] = mcw;
+		}
+	    }
+	    assert (checkMinWidth == minWidth);
+	    
             wdim x = 0;
             foreach (i,w; width) {
                 assert (minWidth[i] <= w, "invariant: min size not reached");	// even when "not sizable", cols may get enlarged
--- a/mde/gui/widget/miscContent.d	Fri Sep 11 20:56:53 2009 +0200
+++ b/mde/gui/widget/miscContent.d	Sat Sep 12 09:14:43 2009 +0200
@@ -89,10 +89,8 @@
 	if (!(flags & 3)) return false;	// string or renderer (and possibly font) changed
 	adapter.text = content_.toString(1);
 	adapter.getDimensions (mw, mh);
-	if (mw != w || mh != h) {
-	    w = mw;
-	    h = mh;
-	}
+	w = mw;
+	h = mh;
 	return true;
     }