diff mde/gui/widget/PopupMenu.d @ 138:3468e9bfded1

Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
author Diggory Hardy <diggory.hardy@gmail.com>
date Sat, 07 Feb 2009 13:28:52 +0000
parents 9f035cd139c6
children 6f69a9c111eb
line wrap: on
line diff
--- a/mde/gui/widget/PopupMenu.d	Sat Feb 07 12:46:03 2009 +0000
+++ b/mde/gui/widget/PopupMenu.d	Sat Feb 07 13:28:52 2009 +0000
@@ -20,6 +20,7 @@
 
 import mde.gui.widget.AParentWidget;
 
+import mde.gui.widget.layout;
 import mde.content.Content;
 import mde.gui.exception;
 
@@ -33,19 +34,27 @@
 
 /******************************************************************************
  * Widget which pops up a menu based on a content.
+ * 
+ * Is a button displaying a content string, just like DisplayContentWidget.
+ * 
+ * Popped up widget is a ContentListWidget created from the same creation data.
  *****************************************************************************/
 class PopupMenuWidget : APopupParentWidget
 {
     this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) {
-	content = c;
-	WDCMinCheck (data, 1,1, content);
+	content = cast(Content)c;
+	WDCMinCheck (data, 3,1, content);
         super (mgr, parent, id);
         
-        popup = mgr.makeWidget (this, data.strings[0], content);
+        //popup = mgr.makeWidget (this, data.strings[0], content);
+        popup = new ContentListWidget (mgr, this, id, data, c);
         subWidgets = [popup];
 	
-	adapter = mgr.renderer.getAdapter;
-	adapter.text = content.toString (1);
+        cIndex = data.ints[2];
+        if (cIndex == 0)
+            content.addCallback (&updateVal);
+        adapter = mgr.renderer.getAdapter;
+	adapter.text = content.toString (cIndex);
 	adapter.getDimensions (mw, mh);
 	w = mw;
 	h = mh;
@@ -92,7 +101,17 @@
     }
     
 protected:
+    void updateVal (Content) {	// callback
+        adapter.text = content.toString(cIndex);
+        wdim omw = mw, omh = mh;
+        adapter.getDimensions (mw, mh);
+        if (omw != mw)
+            parent.minWChange (this, mw);
+        if (omh != mh)
+            parent.minHChange (this, mh);
+    }
     bool pushed = false;
     IRenderer.TextAdapter adapter;
-    IContent content;
+    Content content;
+    int cIndex;
 }