diff mde/gui/widget/Window.d @ 37:052df9b2fe07

Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions. Enabled widget resizing. Removed IRenderer's temporary drawBox method and added drawButton for ButtonWidget. Made the Widget class abstract and added FixedWidget and SizableWidget classes. Rewrote much of createWidget to use meta-code; changed widget IDs. Made Input catch callback exceptions and report error messages. committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Mon, 05 May 2008 14:47:25 +0100
parents 57d000574d75
children 8c4c96f04e7f
line wrap: on
line diff
--- a/mde/gui/widget/Window.d	Fri May 02 17:38:43 2008 +0100
+++ b/mde/gui/widget/Window.d	Mon May 05 14:47:25 2008 +0100
@@ -52,7 +52,8 @@
     
     /** Call after loading is finished to setup the window and confirm that it's valid.
      *
-     * Throws: WindowLoadException. Do not use the instance in this case! */
+     * Throws: WindowLoadException (or possibly other exceptions). Do not use the instance if an
+     * exception occurs! */
     void finalise (IGui gui)
     in {
         assert (gui !is null, "Window.finalise ("~name~"): gui is null");
@@ -64,17 +65,17 @@
         rend = gui.renderer;
         
         // Create the primary widget (and indirectly all sub-widgets), throwing on error:
-        widget = makeWidget (0, this);// primary widget always has ID 0.
-        
-        widgetData = null;          // data is no longer needed: allow GC to collect (cannot safely delete)
+        widget = makeWidget (0, this);  // primary widget always has ID 0.
+        widgetData = null;  // data is no longer needed: allow GC to collect (cannot safely delete)
         
-        widgetX = x + rend.windowBorder;  // widget position
-        widgetY = y + rend.windowBorder;  // must be updated if the window is moved
-        widget.setPosition (widgetX, widgetY);
+        widget.setSize (0,0);           // set the minimal size
+        widget.getCurrentSize (w,h);    // and get this size
+        w += rend.windowBorder * 2;     // Adjust for border
+        h += rend.windowBorder * 2;
         
-        widget.getCurrentSize (w,h);// Find the initial size
-        w += rend.windowBorder * 2;       // Adjust for border
-        h += rend.windowBorder * 2;
+        widgetX = x + rend.windowBorder;    // widget position
+        widgetY = y + rend.windowBorder;    // must be updated if the window is moved
+        widget.setPosition (widgetX, widgetY);
         
         xw = x+w;
         yh = y+h;
@@ -133,20 +134,35 @@
     //END IWindow methods
     
     //BEGIN IWidget methods
-    void getMinimumSize (out int w, out int h) {
-        widget.getMinimumSize (x,y);
-        w += rend.windowBorder * 2;       // Adjust for border
-        h += rend.windowBorder * 2;
+    bool isWSizable () {
+        return widget.isWSizable;
+    }
+    bool isHSizable () {
+        return widget.isHSizable;
+    }
+    
+    void getMinimalSize (out int mw, out int mh) {
+        mw = w + rend.windowBorder * 2;
+        mh = h + rend.windowBorder * 2;
     }
     void getCurrentSize (out int cw, out int ch) {
         cw = w;
         ch = h;
     }
     
-    void setPosition (int x, int y) {
-        // Currently only used internally
-        this.x = x;
-        this.y = y;
+    void setSize (int nw, int nh) {
+        w = nw;
+        h = nh;
+        
+        xw = x+w;
+        yh = y+h;
+        
+        widget.setSize (w - rend.windowBorder * 2, h - rend.windowBorder * 2);
+    }
+    
+    void setPosition (int nx, int ny) {
+        x = nx;
+        y = ny;
         
         xw = x+w;
         yh = y+h;