diff mde/gui/widget/Widget.d @ 91:4d5d53e4f881

Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too. Some debugging improvements. When multiple .mtt files are read for merging, files with invalid headers are ignored and no error is thrown so long as at least one file os valid.
author Diggory Hardy <diggory.hardy@gmail.com>
date Thu, 16 Oct 2008 17:43:48 +0100
parents ea58f277f487
children 085f2ca31914
line wrap: on
line diff
--- a/mde/gui/widget/Widget.d	Wed Oct 01 23:37:51 2008 +0100
+++ b/mde/gui/widget/Widget.d	Thu Oct 16 17:43:48 2008 +0100
@@ -25,20 +25,12 @@
 public import mde.gui.widget.Ifaces;
 import mde.gui.exception;
 
-
-/*************************************************************************************************
- * Widgets may use WDCheck as a utility to check what data holds. Its use is encouraged, so that
- * the checks can easily be updated should WidgetData be changed.
- * 
- * Params:
- *  data    = the WidgetData to check lengths of
- *  n_ints  = number of integers wanted
- *  n_strings= number of strings (default 0 since not all widgets use strings)
- *************************************************************************************************/
-void WDCheck (WidgetData data, size_t n_ints, size_t n_strings = 0) {
-    if (data.ints.length    != n_ints ||
-        data.strings.length != n_strings)
-        throw new WidgetDataException;
+debug {
+    import tango.util.log.Log : Log, Logger;
+    private Logger logger;
+    static this () {
+        logger = Log.getLogger ("mde.gui.widget.Widget");
+    }
 }
 
 
@@ -53,7 +45,7 @@
 {
 //BEGIN Load and save
     // Base this() for child Widgets.
-    this (IWidgetManager mgr, WidgetData data) {
+    this (IWidgetManager mgr, widgetID, WidgetData) {
         this.mgr = mgr;
     }
     
@@ -80,6 +72,13 @@
         return mh;
     }
     
+    wdim width () {
+        return w;
+    }
+    wdim height() {
+        return h;
+    }
+    
     deprecated void getCurrentSize (out wdim cw, out wdim ch) {
         cw = w;
         ch = h;
@@ -88,9 +87,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. */
     void setWidth (wdim nw, int) {
+        debug if (nw < mw) logger.warn ("Widget width set below minimal size");
         w = (nw >= mw ? nw : mw);
     }
     void setHeight (wdim nh, int) {
+        debug if (nh < mh) logger.warn ("Widget height set below minimal size");
         h = (nh >= mh ? nh : mh);
     }
     
@@ -103,7 +104,8 @@
 //BEGIN Events
     /* This method is only called when the location is over this widget; hence for all widgets
      * without children this method is valid. */
-    IChildWidget getWidget (wdim,wdim) {
+    IChildWidget getWidget (wdim cx, wdim cy) {
+        debug assert (cx >= x && cx < x + w && cy >= y && cy < y + h, "getWidget: not on widget (code error)");
         return this;
     }
     
@@ -117,6 +119,21 @@
     }
     
 protected:
+    /**********************************************************************************************
+     * Widgets may use WDCheck as a utility to check what data holds. Its use is encouraged, so
+     * that the checks can easily be updated should WidgetData be changed.
+     * 
+     * Params:
+     *  data    = the WidgetData to check lengths of
+     *  n_ints  = number of integers wanted
+     *  n_strings= number of strings (default 0 since not all widgets use strings)
+     *********************************************************************************************/
+    void WDCheck (WidgetData data, size_t n_ints, size_t n_strings = 0) {
+    if (data.ints.length    != n_ints ||
+        data.strings.length != n_strings)
+        throw new WidgetDataException (this);
+    }
+    
     IWidgetManager mgr;		// the enclosing window
     wdim x, y;			// position
     wdim w, h;			// size
@@ -132,8 +149,8 @@
      * Widget uses the initialisation data:
      * [widgetID, w, h]
      * where w, h is the fixed size. */
-    this (IWidgetManager mgr, WidgetData data) {
-        super (mgr, data);
+    this (IWidgetManager mgr, widgetID id, WidgetData data) {
+        super (mgr, id, data);
         mw = cast(wdim) data.ints[1];
         mh = cast(wdim) data.ints[2];
         w = mw;
@@ -145,8 +162,8 @@
 class SizableWidget : Widget {
     // Check data.length is at least 1 before calling!
     /// Constructor for a completely resizable [blank] widget.
-    this (IWidgetManager mgr, WidgetData data) {
-        super (mgr, data);
+    this (IWidgetManager mgr, widgetID id, WidgetData data) {
+        super (mgr, id, data);
     }
     
     bool isWSizable () {    return true;    }