changeset 129:ad91de8867a0

Added a widget size printing debug function. Fixed a bug in SwitchWidget.
author Diggory Hardy <diggory.hardy@gmail.com>
date Thu, 15 Jan 2009 16:52:46 +0000
parents 41582439a42b
children c5c38eaadb64
files codeDoc/jobs.txt mde/content/miscContent.d mde/gui/WidgetManager.d mde/gui/widget/Ifaces.d mde/gui/widget/Widget.d mde/gui/widget/layout.d mde/gui/widget/miscContent.d
diffstat 7 files changed, 53 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/codeDoc/jobs.txt	Wed Jan 14 20:24:14 2009 +0000
+++ b/codeDoc/jobs.txt	Thu Jan 15 16:52:46 2009 +0000
@@ -3,13 +3,12 @@
 
 
 In progress:
-
+Note: shared alignment sizableness not set very logically.
 
 
 To do (importance 0-5: 0 pointless, 1 no obvious impact now, 2 todo sometime, 3 useful, 4 important, 5 urgent):
 Also see todo.txt and FIXME/NOTE comment marks.
 4   Close popup menu on button activation/click.
-3   Make EnumContent a derivative of BoolContent to use to solve callback problems.
 3   Synchronization of IContent with gui (e.g. multiple edit widgets): worth adding (temporary) callbacks?
 3   Widget saving: how to deal with modifier functions, esp. when they discard parameters? Remove feature except for dimdata and handle gui editing separately?
 3   Use of dtors - don't rely on them? Or what happens when init throws during creation - relying on undefined behaviour.
--- a/mde/content/miscContent.d	Wed Jan 14 20:24:14 2009 +0000
+++ b/mde/content/miscContent.d	Thu Jan 15 16:52:46 2009 +0000
@@ -47,6 +47,17 @@
 	return list_;
     }
     
+    ContentList append (Content x) {
+        size_t l = list_.length;
+        list_.length = l + 1;
+        list_[l] = x;
+        return this;
+    }
+    ContentList append (Content[] x) {
+        list_ ~= x;
+        return this;
+    }
+    
 protected:
     final Content[] list_;
 }
--- a/mde/gui/WidgetManager.d	Wed Jan 14 20:24:14 2009 +0000
+++ b/mde/gui/WidgetManager.d	Thu Jan 15 16:52:46 2009 +0000
@@ -29,6 +29,7 @@
 import mde.lookup.Options;	// miscOpts.L10n callback
 import mde.content.Content;
 import Items = mde.content.Items;	// loadTranslation
+debug import mde.content.miscContent;	// Debug menu
 
 import mde.file.mergetag.Reader;
 import mde.file.mergetag.Writer;
@@ -71,6 +72,12 @@
         
         clickCallbacks = new typeof(clickCallbacks);
         motionCallbacks = new typeof(motionCallbacks);
+        
+        debug {
+            auto lWS = new EventContent ("logWidgetSize");
+            lWS.addCallback (&logWidgetSize);
+            imde.menu.append (lWS);
+        }
     }
     
     /* Load the widgets' data from the file specified to the CTOR.
@@ -374,6 +381,11 @@
     }
     //END IWidgetManager methods
     
+    debug void logWidgetSize (Content) {
+        logger.trace ("Current size: {,4},{,4}; minimal: {,4},{,4} - WidgetManager", w,h, mw,mh);
+        child.logWidgetSize;
+    }
+    
 protected:
     /** Second stage of loading the widgets.
     * 
--- a/mde/gui/widget/Ifaces.d	Wed Jan 14 20:24:14 2009 +0000
+++ b/mde/gui/widget/Ifaces.d	Thu Jan 15 16:52:46 2009 +0000
@@ -309,4 +309,7 @@
      * Maybe later enforce clipping of all sub-widget drawing, particularly for cases where only
      * part of the widget is visible: scroll bars or a hidden window. */
     void draw ();
+    
+    /// Logs the current and minimal size of every widget.
+    debug void logWidgetSize ();
 }
--- a/mde/gui/widget/Widget.d	Wed Jan 14 20:24:14 2009 +0000
+++ b/mde/gui/widget/Widget.d	Thu Jan 15 16:52:46 2009 +0000
@@ -161,6 +161,11 @@
         mgr.renderer.drawWidgetBack (x,y, w,h);
     }
     
+    // 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);
+    }
+    
 protected:
     /**********************************************************************************************
      * Widgets may use W*Check as a utility to check for existance of data. Its use is encouraged,
@@ -245,6 +250,12 @@
         throw new GuiException ("getWidgetIndex: widget not found (code error)");
     }
     
+    debug override void logWidgetSize () {
+        super.logWidgetSize;
+        foreach (widg; subWidgets)
+            widg.logWidgetSize;
+    }
+    
 protected:
     IChildWidget[] subWidgets;
 }
@@ -264,6 +275,11 @@
     override bool saveChanges () {
 	return subWidget.saveChanges;
     }
+    
+    debug override void logWidgetSize () {
+        super.logWidgetSize;
+        subWidget.logWidgetSize;
+    }
 	
 protected:
     IChildWidget subWidget;
--- a/mde/gui/widget/layout.d	Wed Jan 14 20:24:14 2009 +0000
+++ b/mde/gui/widget/layout.d	Thu Jan 15 16:52:46 2009 +0000
@@ -691,7 +691,7 @@
         foreach (imw; minWidth)
             mw += imw;
         
-        if (nd < 0 || (nd > 0 && !sizable[col])) {	// needs enlarging or shrinking
+        if (nd != 0) {	// needs enlarging or shrinking
             width[col] = nmw;
             foreach (cb; cbs)
                 cb.setWidth (col, nmw, -1);
--- a/mde/gui/widget/miscContent.d	Wed Jan 14 20:24:14 2009 +0000
+++ b/mde/gui/widget/miscContent.d	Thu Jan 15 16:52:46 2009 +0000
@@ -134,7 +134,10 @@
 }
 
 /** A "tab" widget: it doesn't display the tabs, but shows one of a number of widgets dependant on
- * an EnumContent. */
+ * an EnumContent.
+ *
+ * Sizability is set once (currently true if any widget is sizable). Size is kept when switching
+ * widgets if allowed (if this is large enough and resizable). */
 class SwitchWidget : AParentWidget
 {
     this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) {
@@ -214,8 +217,11 @@
         mh = currentW.minHeight;
         parent.minWChange (this, mw);
         parent.minHChange (this, mh);
-        w = currentW.width;
-        h = currentW.height;
+        // If resizable and already large enough, don't resize; else do.
+        if (isWS && w > mw) currentW.setWidth (w, -1);
+        else w = currentW.width;
+        if (isHS && h > mh) currentW.setHeight (h, -1);
+        else h = currentW.height;
         currentW.setPosition (x,y);
     }