diff mde/gui/WidgetManager.d @ 152:c67d074a7111

Menu placement now takes into account left/right placement of parent menus.
author Diggory Hardy <diggory.hardy@gmail.com>
date Fri, 10 Apr 2009 15:19:46 +0200
parents 075705ad664a
children b06b04c75e86
line wrap: on
line diff
--- a/mde/gui/WidgetManager.d	Sat Apr 04 17:32:18 2009 +0200
+++ b/mde/gui/WidgetManager.d	Fri Apr 10 15:19:46 2009 +0200
@@ -308,21 +308,21 @@
         if (childIPPW !is ippw) return false;
         childIPPW.removedIPPW;
         childIPPW = null;
-        mAIPPW = false;
+        mAIPPW = MenuPosition.INACTIVE;
         requestRedraw;
         return false;
     }
     
-    override void menuActive (bool mA) {
+    override void menuActive (MenuPosition mA) {
         mAIPPW = mA;
         if (childIPPW)
             childIPPW.menuActive = mA;
     }
-    override bool menuActive () {
+    override MenuPosition menuActive () {
         return mAIPPW;
     }
-    override bool parentMenuActive () {
-        return false;
+    override MenuPosition parentMenuActive () {
+        return MenuPosition.INACTIVE;
     }
     
     // Don't do anything. E.g. can get called by non-popup buttons.
@@ -333,7 +333,8 @@
             if (popupContext.onSelf (cx, cy))
             	return popupContext;
             if (closePopup) {
-            	menuActive = (childIPPW !is null);
+            	if (childIPPW is null)
+		    menuActive = MenuPosition.INACTIVE;
             	popupContext = null;
                 requestRedraw;
             }
@@ -343,7 +344,7 @@
                     childIPPW.getPopupWidget (cx, cy, closePopup);
             if (ret) return ret;
             if (closePopup) {
-                menuActive = false;
+                menuActive = MenuPosition.INACTIVE;
                 removeChildIPPW (childIPPW);
             }
         }
@@ -409,26 +410,43 @@
         return rend;
     }
     
-    void positionPopup (IChildWidget parent, IChildWidget popup, int flags = 0) {
+    MenuPosition positionPopup (IChildWidget parent, IChildWidget popup, MenuPosition position = MenuPosition.INACTIVE) {
 	debug assert (parent && popup, "positionPopup: null widget");
         wdim w = popup.width,
              h = popup.height,
              x, y;
-        if (flags & 1) {
-            y = parent.yPos;			// height flush with top
+        if (position & MenuPosition.ACTIVE) {
+            y = parent.yPos;				// height flush with top
             if (y+h > this.h) y += parent.height - h;	// or bottom
-            x = parent.xPos + parent.width;		// on right
-            if (x+w > this.w) x = parent.xPos - w;	// or left edge
+	    if (position & MenuPosition.LEFT) {		// previously left
+		x = parent.xPos - w;			// on left
+		if (x < 0) {
+		    x = parent.xPos + parent.width;	// on right
+		    position = MenuPosition.RIGHT;
+		}
+	    } else {					// previously right or above/below
+		x = parent.xPos + parent.width;		// on right
+		position = MenuPosition.RIGHT;
+		if (x+w > this.w) {
+		    x = parent.xPos - w;		// or left
+		    position = MenuPosition.LEFT;
+		}
+	    }
         } else {
-            x = parent.xPos;				// align on left edge
-            if (x+w > this.w) x += parent.width - w;	// align on right edge
+	    wdim pw = parent.width;
+	    if (w < pw && popup.minWidth <= pw)
+		popup.setWidth (pw, -1);		// neatness
+	    x = parent.xPos;				// align on left edge
+            if (x+w > this.w) x += pw - w;		// align on right edge
             y = parent.yPos + parent.height;		// place below
             if (y+h > this.h) y = parent.yPos - h;	// or above
+	    position = MenuPosition.ACTIVE;
         }
         if (x < 0) x = 0;	// may be placed partially off-screen
         if (y < 0) y = 0;
         popup.setPosition (x, y);
         //debug logger.trace ("placed popup at {},{}; size: {},{}", x,y, w,h);
+	return position;
     }
 
     void requestRedraw () {
@@ -616,7 +634,7 @@
     scope IChildWidget child;		// The primary widget.
     uint setupN;			// n to pass to IChildWidget.setup
     
-    bool mAIPPW;			// IPPW variable
+    MenuPosition mAIPPW;		// IPPW variable
     IPopupParentWidget childIPPW;	// child IPPW, if any active
     
     // Popup(s) handled directly by AWidgetManager: