comparison 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
comparison
equal deleted inserted replaced
137:9f035cd139c6 138:3468e9bfded1
18 *****************************************************************************/ 18 *****************************************************************************/
19 module mde.gui.widget.PopupMenu; 19 module mde.gui.widget.PopupMenu;
20 20
21 import mde.gui.widget.AParentWidget; 21 import mde.gui.widget.AParentWidget;
22 22
23 import mde.gui.widget.layout;
23 import mde.content.Content; 24 import mde.content.Content;
24 import mde.gui.exception; 25 import mde.gui.exception;
25 26
26 debug { 27 debug {
27 import tango.util.log.Log : Log, Logger; 28 import tango.util.log.Log : Log, Logger;
31 } 32 }
32 } 33 }
33 34
34 /****************************************************************************** 35 /******************************************************************************
35 * Widget which pops up a menu based on a content. 36 * Widget which pops up a menu based on a content.
37 *
38 * Is a button displaying a content string, just like DisplayContentWidget.
39 *
40 * Popped up widget is a ContentListWidget created from the same creation data.
36 *****************************************************************************/ 41 *****************************************************************************/
37 class PopupMenuWidget : APopupParentWidget 42 class PopupMenuWidget : APopupParentWidget
38 { 43 {
39 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) { 44 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) {
40 content = c; 45 content = cast(Content)c;
41 WDCMinCheck (data, 1,1, content); 46 WDCMinCheck (data, 3,1, content);
42 super (mgr, parent, id); 47 super (mgr, parent, id);
43 48
44 popup = mgr.makeWidget (this, data.strings[0], content); 49 //popup = mgr.makeWidget (this, data.strings[0], content);
50 popup = new ContentListWidget (mgr, this, id, data, c);
45 subWidgets = [popup]; 51 subWidgets = [popup];
46 52
47 adapter = mgr.renderer.getAdapter; 53 cIndex = data.ints[2];
48 adapter.text = content.toString (1); 54 if (cIndex == 0)
55 content.addCallback (&updateVal);
56 adapter = mgr.renderer.getAdapter;
57 adapter.text = content.toString (cIndex);
49 adapter.getDimensions (mw, mh); 58 adapter.getDimensions (mw, mh);
50 w = mw; 59 w = mw;
51 h = mh; 60 h = mh;
52 } 61 }
53 62
90 mgr.renderer.drawButton (x,y, w,h, pushed); 99 mgr.renderer.drawButton (x,y, w,h, pushed);
91 adapter.draw (x,y); 100 adapter.draw (x,y);
92 } 101 }
93 102
94 protected: 103 protected:
104 void updateVal (Content) { // callback
105 adapter.text = content.toString(cIndex);
106 wdim omw = mw, omh = mh;
107 adapter.getDimensions (mw, mh);
108 if (omw != mw)
109 parent.minWChange (this, mw);
110 if (omh != mh)
111 parent.minHChange (this, mh);
112 }
95 bool pushed = false; 113 bool pushed = false;
96 IRenderer.TextAdapter adapter; 114 IRenderer.TextAdapter adapter;
97 IContent content; 115 Content content;
116 int cIndex;
98 } 117 }