Mercurial > projects > mde
comparison mde/gui/widget/Widget.d @ 113:9824bee909fd
Popup menu; works for simple menus except that clicking an item doesn't close it.
Revised popup support a bit; EnumContentWidget is broken and due to be replaced.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Fri, 19 Dec 2008 10:32:28 +0000 |
parents | fe061009029d |
children | b16a534f5302 |
comparison
equal
deleted
inserted
replaced
112:fe061009029d | 113:9824bee909fd |
---|---|
82 } | 82 } |
83 wdim height() { | 83 wdim height() { |
84 return h; | 84 return h; |
85 } | 85 } |
86 | 86 |
87 wdabs xPos () { | |
88 return x; | |
89 } | |
90 wdabs yPos () { | |
91 return y; | |
92 } | |
93 | |
87 deprecated void getCurrentSize (out wdim cw, out wdim ch) { | 94 deprecated void getCurrentSize (out wdim cw, out wdim ch) { |
88 cw = w; | 95 cw = w; |
89 ch = h; | 96 ch = h; |
90 } | 97 } |
91 | 98 |
120 } | 127 } |
121 | 128 |
122 /* Dummy functions: suitable for widgets with no text input. */ | 129 /* Dummy functions: suitable for widgets with no text input. */ |
123 void keyEvent (ushort, char[]) {} | 130 void keyEvent (ushort, char[]) {} |
124 void keyFocusLost () {} | 131 void keyFocusLost () {} |
132 | |
133 // Currently only applies to popup widgets. | |
134 void highlight (bool state) {} | |
135 | |
136 // Only useful to widgets creating popups. | |
137 void popupRemoved () {} | |
125 //END Events | 138 //END Events |
126 | 139 |
127 /* Basic draw method: draw the background (all widgets should do this). */ | 140 /* Basic draw method: draw the background (all widgets should do this). */ |
128 void draw () { | 141 void draw () { |
129 mgr.renderer.drawWidgetBack (x,y, w,h); | 142 mgr.renderer.drawWidgetBack (x,y, w,h); |
174 wdim mw = 0, mh = 0; // minimal or fixed size, depending on whether the widget is | 187 wdim mw = 0, mh = 0; // minimal or fixed size, depending on whether the widget is |
175 // resizible; both types of widgets should actually be expandable. | 188 // resizible; both types of widgets should actually be expandable. |
176 } | 189 } |
177 | 190 |
178 /************************************************************************************************* | 191 /************************************************************************************************* |
179 * An abstract base widget class for parent widgets (many parent widgets don't use these methods). | 192 * Abstract base widget classes to facilitate parent widgets. |
180 * | 193 * |
181 * Parent widgets probably need to overload these functions (from AWidget): | 194 * Parent widgets probably need to overload these functions (from AWidget): |
182 * setup, saveChanges, setPosition, getWidget, draw, setWidth and setHeight. | 195 * setup, saveChanges, setPosition, getWidget, draw, setWidth and setHeight. |
183 *************************************************************************************************/ | 196 *************************************************************************************************/ |
184 abstract class AParentWidget : AWidget | 197 abstract class AParentWidget : AWidget |
187 super (mgr, id, data); | 200 super (mgr, id, data); |
188 } | 201 } |
189 | 202 |
190 bool setup (uint n, uint flags) { | 203 bool setup (uint n, uint flags) { |
191 bool c = false; | 204 bool c = false; |
192 foreach (w; subWidgets) | 205 foreach (w; subWidgets) { |
206 debug assert (w); | |
193 c |= w.setup (n,flags); | 207 c |= w.setup (n,flags); |
208 } | |
194 return c; | 209 return c; |
195 } | 210 } |
196 | 211 |
197 bool saveChanges () { | 212 bool saveChanges () { |
198 bool c = false; | 213 bool c = false; |
201 return c; | 216 return c; |
202 } | 217 } |
203 | 218 |
204 protected: | 219 protected: |
205 IChildWidget[] subWidgets; | 220 IChildWidget[] subWidgets; |
221 } | |
222 /** ditto */ | |
223 abstract class AParentSingleWidget : AWidget | |
224 { | |
225 this (IWidgetManager mgr, widgetID id, WidgetData data) { | |
226 super (mgr, id, data); | |
227 } | |
228 | |
229 bool setup (uint n, uint flags) { | |
230 debug assert (subWidget); | |
231 return subWidget.setup (n,flags); | |
232 } | |
233 | |
234 bool saveChanges () { | |
235 return subWidget.saveChanges; | |
236 } | |
237 | |
238 protected: | |
239 IChildWidget subWidget; | |
206 } | 240 } |
207 | 241 |
208 /** A base for fixed-size widgets taking their size from the creation data. */ | 242 /** A base for fixed-size widgets taking their size from the creation data. */ |
209 class FixedWidget : AWidget { | 243 class FixedWidget : AWidget { |
210 // Check data.length is at least 3 before calling! | 244 // Check data.length is at least 3 before calling! |
284 void activated (); | 318 void activated (); |
285 | 319 |
286 protected: | 320 protected: |
287 bool pushed = false; /// True if button is pushed in (visually) | 321 bool pushed = false; /// True if button is pushed in (visually) |
288 } | 322 } |
289 | |
290 |