diff mde/gui/widget/Ifaces.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 5132301e9ed7
line wrap: on
line diff
--- a/mde/gui/widget/Ifaces.d	Fri May 02 17:38:43 2008 +0100
+++ b/mde/gui/widget/Ifaces.d	Mon May 05 14:47:25 2008 +0100
@@ -65,22 +65,41 @@
 * Where window is the root window (the window to which the widget belongs), parent is the parent
 * widget, and data is an array of initialisation data. The method should throw a
 * WidgetDataException (created without parameters) if the data has wrong length or is otherwise
-* invalid. */
+* invalid.
+*
+* The widget's size should be set either by it's this() method or by the first call to
+* setSize(). setSize() is called on all widgets immediately after their creation, and throwing an
+* exception at this point (but not on later calls to setSize) is an acceptible method of failure.
+*/
+//NOTE: add another this() without the data for default initialization, for the GUI editor?
 interface IWidget
 {
-    /** Calculate the minimum size the widget could be shrunk to, taking into account
+    /** is the width / height resizable?
+     *
+     * If not, the widget has fixed dimensions equal the output of getMinimalSize. */
+    bool isWSizable ();
+    bool isHSizable (); /// ditto
+    
+    /** Calculate the minimal size the widget could be shrunk to, taking into account
      * child-widgets. */
-    void getMinimumSize (out int w, out int h);
+    void getMinimalSize (out int w, out int h);
     
-    /** Get the current size of the widget.
+    /** Get the current size of the widget. */
+    void getCurrentSize (out int w, out int h);
+    
+    /** Used to adjust the size.
      *
-     * On the first call (during loading), this may be a value saved as part of the config or
-     * something else (e.g. revert to getMinimumSize). */
-    void getCurrentSize (out int w, out int h);
+     * The size should be clamped to the widget's minimal size, i.e. the size set may be larger
+     * than that given by the parameters. Conversely, the size should not be reduced to the
+     * widget's maximal size (if any) but expanded as necessary (alignment to be implemented).
+     *
+     * If the actual size is needed, call getCurrentSize afterwards. */
+    void setSize (int w, int h);
     
     /** Set the current position (i.e. called on init and move). */
     void setPosition (int x, int y);
     
+    
     /** Recursively scan the widget tree to find the widget under (x,y).
      *
      * If called on a widget, that widget should assume the location is over itself, and so should
@@ -100,6 +119,7 @@
      * Widget may assume coordinates are on the widget (caller must check). */
     void clickEvent (ushort cx, ushort cy, ubyte b, bool state);
     
+    
     /** Draw, using the stored values of x and y.
      *
      * Maybe later enforce clipping of all sub-widget drawing, particularly for cases where only