Mercurial > projects > mde
comparison mde/gui/widget/Ifaces.d @ 174:3d58adc17d20
Temporary commit to allow backup
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Mon, 31 Aug 2009 13:54:23 +0200 |
parents | 0dd49f333189 |
children | 1cbde9807293 |
comparison
equal
deleted
inserted
replaced
173:a1ba9157510e | 174:3d58adc17d20 |
---|---|
24 * manager is a special widget only implementing IParentWidget; all other | 24 * manager is a special widget only implementing IParentWidget; all other |
25 * widgets must implement IChildWidget and optionally IParentWidget. | 25 * widgets must implement IChildWidget and optionally IParentWidget. |
26 * | 26 * |
27 * It's recommended that widgets inherit one of the A*Widget classes rather | 27 * It's recommended that widgets inherit one of the A*Widget classes rather |
28 * than impement I*Widget directly. | 28 * than impement I*Widget directly. |
29 * | |
30 * Protection: please keep it as tight as possible. List it explicitly for | |
31 * every function in this module; then the compiler checks overridden functions | |
32 * have the correct protection attribute. | |
33 * BUG: currently it's a bit of a mess, because of a compiler bug. | |
29 *****************************************************************************/ | 34 *****************************************************************************/ |
30 module mde.gui.widget.Ifaces; | 35 module mde.gui.widget.Ifaces; |
31 | 36 |
32 public import mde.gui.types; | 37 public import mde.gui.types; |
33 public import mde.gui.renderer.IRenderer; | 38 public import mde.gui.renderer.IRenderer; |
47 * If the widget has subwidgets, it should also be recursively called on | 52 * If the widget has subwidgets, it should also be recursively called on |
48 * these, returning true if any data was saved. | 53 * these, returning true if any data was saved. |
49 * | 54 * |
50 * Actually the return value is ignored; I think widgets still return it | 55 * Actually the return value is ignored; I think widgets still return it |
51 * correctly though. */ | 56 * correctly though. */ |
52 bool saveChanges (); | 57 public bool saveChanges (); |
58 | |
59 /** Draw, using the stored values of x and y. | |
60 * | |
61 * Maybe later enforce clipping of all sub-widget drawing, particularly for cases where only | |
62 * part of the widget is visible: scroll bars or a hidden window. */ | |
63 public void draw (); | |
53 | 64 |
54 /** Called on a widget when something is dragged onto it. | 65 /** Called on a widget when something is dragged onto it. |
55 * | 66 * |
56 * Generally, content editing widgets should implement this as: | 67 * Generally, content editing widgets should implement this as: |
57 * --- | 68 * --- |
58 override bool dropContent (IContent content) { | 69 public override bool dropContent (IContent content) { |
59 if (content_.setContent (content)) | 70 if (content_.setContent (content)) |
60 return true; | 71 return true; |
61 return parent.dropContent (content); | 72 return parent.dropContent (content); |
62 } | 73 } |
63 * --- | 74 * --- |
66 * return parent.dropContent (content); | 77 * return parent.dropContent (content); |
67 * --- | 78 * --- |
68 * | 79 * |
69 * Returns: true if the content was received (false if it reaches the | 80 * Returns: true if the content was received (false if it reaches the |
70 * WidgetManager and is still not used). */ | 81 * WidgetManager and is still not used). */ |
71 bool dropContent (IContent content); | 82 public bool dropContent (IContent content); |
72 } | 83 } |
73 | 84 |
74 /****************************************************************************** | 85 /****************************************************************************** |
75 * Interface for parent widgets, including IWidgetManager. | 86 * Interface for parent widgets, including IWidgetManager. |
76 * | 87 * |
81 * Layout widget: a widget containing multiple sub-widges (which hence | 92 * Layout widget: a widget containing multiple sub-widges (which hence |
82 * controls how they are laid out). | 93 * controls how they are laid out). |
83 *****************************************************************************/ | 94 *****************************************************************************/ |
84 interface IParentWidget : IWidget | 95 interface IParentWidget : IWidget |
85 { | 96 { |
86 /** Checks for recursion of unsafe widgets to prevent infinite recursion. */ | 97 /** Checks for recursion of unsafe widgets to prevent infinite recursion. |
98 * | |
99 * Only called by makeWidget() when creating child widgets and recursively | |
100 * from the same method in a child widget. */ | |
87 void recursionCheck (widgetID, IContent); | 101 void recursionCheck (widgetID, IContent); |
88 | 102 |
89 /** IPPWs return self, other widgets recurse call on parent. */ | 103 /** IPPWs return self, other widgets recurse call on parent. */ |
90 IPopupParentWidget getParentIPPW (); | 104 IPopupParentWidget getParentIPPW (); |
91 | 105 |
92 /** Child widgets should call this on their parent if their minimal size | 106 /** Child widgets should call this on their parent if their minimal size |
93 * changes, since they cannot properly resize themselves. | 107 * changes, since they cannot properly resize themselves. |
94 * | 108 * |
95 * Parents $(I must) increase their child's size if the child is too small. | 109 * Parents $(I must) increase their child's size if the child is too small. |
96 * Parents $(I must not) decrease their own size, even if they are not | 110 * Parents $(I must not) change their own size, even if they are not |
97 * sizable; they may only decrease their childrens' sizes if it does not | 111 * sizable; they may only change their childrens' sizes if it does not |
98 * affect their own (i.e. WidgetManager and FloatingAreaWidget). | 112 * affect their own (i.e. WidgetManager and floating / popup widgets). |
113 * | |
114 * (Hence most parents need to call this function on their parents to change | |
115 * size. In this case they also must propegate setWidth/setHeight calls on | |
116 * the child originally calling min[WH]Change.) | |
99 * | 117 * |
100 * Child widgets may depend on setPosition being called afterwards. | 118 * Child widgets may depend on setPosition being called afterwards. |
101 * | 119 * |
102 * Params: | 120 * Params: |
103 * widget = The child widget calling the function | 121 * widget = The child widget calling the function |
112 * NEVER and ALWAYS often don't result in usable GUIs, and aren't expected to be used except | 130 * NEVER and ALWAYS often don't result in usable GUIs, and aren't expected to be used except |
113 * for debugging. | 131 * for debugging. |
114 * | 132 * |
115 * Note: ANY_SUBWIDGETS can cause problems like enlarging a menu bar containing a resizable | 133 * Note: ANY_SUBWIDGETS can cause problems like enlarging a menu bar containing a resizable |
116 * blank instead of the main part of a window. */ | 134 * blank instead of the main part of a window. */ |
117 enum SIZABILITY_ENUM { | 135 protected enum SIZABILITY_ENUM { |
118 NEVER = 0, /// Parents are never resizable | 136 NEVER = 0, /// Parents are never resizable |
119 ALL_SUBWIDGETS = 3, /// Parents are only resizable if all sub-widgets are | 137 ALL_SUBWIDGETS = 3, /// Parents are only resizable if all sub-widgets are |
120 ANY_SUBWIDGETS = 2, /// Parents are resizable if any sub-widgets are | 138 ANY_SUBWIDGETS = 2, /// Parents are resizable if any sub-widgets are |
121 ALWAYS = 1, /// Parents are always resizable | 139 ALWAYS = 1, /// Parents are always resizable |
122 START_TRUE = 1, /// Flag set by ALWAYS and ALL_SUBWIDGETS | 140 START_TRUE = 1, /// Flag set by ALWAYS and ALL_SUBWIDGETS |
123 SUBWIDGETS = 2, /// Flag set by ALL_SUBWIDGETS and ANY_SUBWIDGETS | 141 SUBWIDGETS = 2, /// Flag set by ALL_SUBWIDGETS and ANY_SUBWIDGETS |
124 } | 142 } |
125 static const SIZABILITY = SIZABILITY_ENUM.ANY_SUBWIDGETS; /// ditto | 143 protected static const SIZABILITY = SIZABILITY_ENUM.ANY_SUBWIDGETS; /// ditto |
126 } | 144 } |
127 | 145 |
128 /****************************************************************************** | 146 /****************************************************************************** |
129 * Interface for parents of popups and the widget manager. | 147 * Interface for parents of popups and the widget manager. |
130 * | 148 * |
330 * All widgets should set their own size in this() or setup() (must be setup() | 348 * All widgets should set their own size in this() or setup() (must be setup() |
331 * if it could change), although some parents may set child-widgets' size | 349 * if it could change), although some parents may set child-widgets' size |
332 * during their creation. | 350 * during their creation. |
333 *****************************************************************************/ | 351 *****************************************************************************/ |
334 //NOTE: add another this() without the data for default initialization, for the GUI editor? | 352 //NOTE: add another this() without the data for default initialization, for the GUI editor? |
335 interface IChildWidget : IWidget | 353 abstract class IChildWidget : IWidget |
336 { | 354 { |
337 //BEGIN Load and save | 355 //BEGIN Load and save |
338 /** 2nd stage of initialization for widgets; also called on some changes. | 356 /** 2nd stage of initialization for widgets; also called on some changes. |
339 * | 357 * |
340 * Widgets should call recursively on their children, redo anything | 358 * Widgets should call recursively on their children, redo anything |
349 * These flags are always true on first run. | 367 * These flags are always true on first run. |
350 * | 368 * |
351 * Returns: | 369 * Returns: |
352 * The method must return true on initial setup and if its dimensions | 370 * The method must return true on initial setup and if its dimensions |
353 * (may) have changed. */ | 371 * (may) have changed. */ |
354 bool setup (uint n, uint flags); | 372 bool setup (uint n, uint flags) {return 0;} |
355 | 373 |
356 /+ Use when widget editing is available? Requires widgets to know their parents. | 374 /+ Use when widget editing is available? Requires widgets to know their parents. |
357 /** Called when a child widget's size has changed. | 375 /** Called when a child widget's size has changed. |
358 * | 376 * |
359 * Should be propegated up to parents. */ | 377 * Should be propegated up to parents. */ |
367 * Normally, this means does the widget benifit from being enlarged? If not, the widget has | 385 * Normally, this means does the widget benifit from being enlarged? If not, the widget has |
368 * "fixed" dimensions equal to it's minimal size; however it $(I may) still be enlarged. | 386 * "fixed" dimensions equal to it's minimal size; however it $(I may) still be enlarged. |
369 * | 387 * |
370 * Parents normally take their resizability from sub-widgets; see SIZABILITY for how they do | 388 * Parents normally take their resizability from sub-widgets; see SIZABILITY for how they do |
371 * this. */ | 389 * this. */ |
372 bool isWSizable (); | 390 bool isWSizable () {return 0;} |
373 bool isHSizable (); /// ditto | 391 bool isHSizable () {return 0;} /// ditto |
374 | 392 |
375 /** The minimal size the widget could be shrunk to (or its fixed size). | 393 /** The minimal size the widget could be shrunk to (or its fixed size). |
376 * | 394 * |
377 * Takes into account child-widgets and any other contents. */ | 395 * Takes into account child-widgets and any other contents. */ |
378 wdim minWidth (); | 396 wdim minWidth () {return 0;} |
379 wdim minHeight (); /// ditto | 397 wdim minHeight() {return 0;} /// ditto |
380 | 398 |
381 /** Get the current size of the widget. */ | 399 /** Get the current size of the widget. */ |
382 wdim width (); | 400 wdim width () {return 0;} |
383 wdim height(); /// ditto | 401 wdim height() {return 0;} /// ditto |
384 | 402 |
385 /** (Smallest) coordinates of widget. */ | 403 /** (Smallest) coordinates of widget. */ |
386 wdabs xPos (); | 404 wdabs xPos () {return 0;} |
387 wdabs yPos (); /// ditto | 405 wdabs yPos () {return 0;} /// ditto |
388 | 406 |
389 /** Used to adjust the size. | 407 /** Used to adjust the size. |
390 * | 408 * |
391 * Params: | 409 * Params: |
392 * nw/nh = The new width/height | 410 * nw/nh = The new width/height |
398 * A widget should never be resized smaller than it's minimal size (if it is, it should assume | 416 * A widget should never be resized smaller than it's minimal size (if it is, it should assume |
399 * it's minimal size and print a warning when in debug mode). | 417 * it's minimal size and print a warning when in debug mode). |
400 * A "fixed" size widget should enlarge itself as requested. | 418 * A "fixed" size widget should enlarge itself as requested. |
401 * | 419 * |
402 * setPosition must be called after calling either setWidth or setHeight. */ | 420 * setPosition must be called after calling either setWidth or setHeight. */ |
403 void setWidth (wdim nw, int dir); | 421 void setWidth (wdim nw, int dir) {} |
404 void setHeight (wdim nh, int dir); /// ditto | 422 void setHeight (wdim nh, int dir) {} /// ditto |
405 | 423 |
406 /** Set the current position (called after setup and to move widget). */ | 424 /** Set the current position (called after setup and to move widget). */ |
407 void setPosition (wdim x, wdim y); | 425 void setPosition (wdim x, wdim y) {} |
408 //END Size and position | 426 //END Size and position |
409 | 427 |
410 //BEGIN Content | 428 //BEGIN Content |
411 /** Return the widget's content, or null. */ | 429 /** Return the widget's content, or null. */ |
412 IContent content (); | 430 IContent content () {return null;} |
413 | 431 |
414 /** Set the widget's content, if the widget takes content and changing it | 432 /** Set the widget's content, if the widget takes content and changing it |
415 * at this stage is feasible. (Also pass to sub-widgets, where the | 433 * at this stage is feasible. (Also pass to sub-widgets, where the |
416 * constructor normally does so.) */ | 434 * constructor normally does so.) */ |
417 void setContent (IContent); | 435 void setContent (IContent) {} |
418 //END Content | 436 //END Content |
419 | 437 |
420 //BEGIN Events | 438 //BEGIN Events |
421 /** Recursively scan the widget tree to find the widget under (cx,cy). | 439 /** Recursively scan the widget tree to find the widget under (cx,cy). |
422 * | 440 * |
425 * | 443 * |
426 * In the case of Window this may not be the case; it should check and return null if not under | 444 * In the case of Window this may not be the case; it should check and return null if not under |
427 * (cx,cy). | 445 * (cx,cy). |
428 * | 446 * |
429 * Note: use global coordinates (cx,cy) not coordinates relative to the widget. */ | 447 * Note: use global coordinates (cx,cy) not coordinates relative to the widget. */ |
430 IChildWidget getWidget (wdabs cx, wdabs cy); | 448 IChildWidget getWidget (wdabs cx, wdabs cy) {return null;} |
431 | 449 |
432 /** Return true if (cx,cy) is on self's box (doesn't matter if actually on a subwidget). */ | 450 /** Return true if (cx,cy) is on self's box (doesn't matter if actually on a subwidget). */ |
433 bool onSelf (wdabs cx, wdabs cy); | 451 bool onSelf (wdabs cx, wdabs cy) {return 0;} |
434 | 452 |
435 /** Receive a mouse click event at cx,cy from button b (1-5 correspond to L,M,B, wheel up,down) | 453 /** Receive a mouse click event at cx,cy from button b (1-5 correspond to L,M,B, wheel up,down) |
436 * which is a down-click if state is true. | 454 * which is a down-click if state is true. |
437 * | 455 * |
438 * Widget may assume coordinates are on the widget (caller must check). | 456 * Widget may assume coordinates are on the widget (caller must check). |
441 * $(TABLE | 459 * $(TABLE |
442 * $(TR $(TD 1) $(TD Request keyboard input)) | 460 * $(TR $(TD 1) $(TD Request keyboard input)) |
443 * $(TR $(TD 2) $(TD Request the functions dragMotion and dragRelease are called)) | 461 * $(TR $(TD 2) $(TD Request the functions dragMotion and dragRelease are called)) |
444 * $(TR $(TD 4) $(TD Display the widget's content while dragging (requires 2))) | 462 * $(TR $(TD 4) $(TD Display the widget's content while dragging (requires 2))) |
445 * ) */ | 463 * ) */ |
446 int clickEvent (wdabs cx, wdabs cy, ubyte b, bool state); | 464 int clickEvent (wdabs cx, wdabs cy, ubyte b, bool state) {return 0;} |
447 | 465 |
448 /** Called when dragging motion occurs, originating from this widget. | 466 /** Called when dragging motion occurs, originating from this widget. |
449 * | 467 * |
450 * Params: target = The widget under the mouse | 468 * Params: target = The widget under the mouse |
451 * | 469 * |
452 * Only called if requested by clickEvent. */ | 470 * Only called if requested by clickEvent. */ |
453 void dragMotion (wdabs cx, wdabs cy, IChildWidget target); | 471 void dragMotion (wdabs cx, wdabs cy, IChildWidget target) {} |
454 | 472 |
455 /** Called at the end of a drag which originated from this widget. | 473 /** Called at the end of a drag which originated from this widget. |
456 * | 474 * |
457 * Params: target = The widget under the mouse when the click was released | 475 * Params: target = The widget under the mouse when the click was released |
458 * | 476 * |
459 * Returns: true if the up-click event should not be passed to | 477 * Returns: true if the up-click event should not be passed to |
460 * clickEvent on the relevent widget. | 478 * clickEvent on the relevent widget. |
461 * | 479 * |
462 * Only called if requested by clickEvent. */ | 480 * Only called if requested by clickEvent. */ |
463 bool dragRelease (wdabs cx, wdabs cy, IChildWidget target); | 481 bool dragRelease (wdabs cx, wdabs cy, IChildWidget target) {return 0;} |
464 | 482 |
465 /** Receives keyboard events when requested. | 483 /** Receives keyboard events when requested. |
466 * | 484 * |
467 * Params: | 485 * Params: |
468 * sym SDLKey key sym, useful for keys with no character code such as arrow keys | 486 * sym SDLKey key sym, useful for keys with no character code such as arrow keys |
469 * letter The character input, in UTF-8 */ | 487 * letter The character input, in UTF-8 */ |
470 void keyEvent (ushort sym, char[] letter); | 488 public void keyEvent (ushort sym, char[] letter); |
471 | 489 |
472 /** Called when keyboard input focus is lost. */ | 490 /** Called when keyboard input focus is lost. */ |
473 void keyFocusLost (); | 491 public void keyFocusLost (); |
474 | 492 |
475 /** Called on all widgets when the mouse moves over it (state == true) and | 493 /** Called on all widgets when the mouse moves over it (state == true) and |
476 * when it leaves (state == false). */ | 494 * when it leaves (state == false). */ |
477 void underMouse (bool state); | 495 void underMouse (bool state) {} |
478 | 496 |
479 /** When a pop-up is closed the manager calls requestRedraw and this function on its parent. */ | 497 /** When a pop-up is closed the manager calls requestRedraw and this function on its parent. */ |
480 void popupClose (); | 498 protected void popupClose (); |
481 /** When a click is on the parent of a popup, this function is called instead of the usual | 499 /** When a click is on the parent of a popup, this function is called instead of the usual |
482 * clickEvent. | 500 * clickEvent. |
483 * | 501 * |
484 * Returns: | 502 * Returns: |
485 * true to close the popup. | 503 * true to close the popup. |
486 * | 504 * |
487 * Note: this means the parent can't receive text input without code changes. */ | 505 * Note: this means the parent can't receive text input without code changes. */ |
488 bool popupParentClick (); | 506 protected bool popupParentClick (); |
489 | 507 |
490 //END Events | 508 //END Events |
491 | 509 |
492 /** Draw, using the stored values of x and y. | |
493 * | |
494 * Maybe later enforce clipping of all sub-widget drawing, particularly for cases where only | |
495 * part of the widget is visible: scroll bars or a hidden window. */ | |
496 void draw (); | |
497 | |
498 /// Logs the current and minimal size of every widget. | 510 /// Logs the current and minimal size of every widget. |
499 debug void logWidgetSize (); | 511 debug public void logWidgetSize (); |
500 } | 512 } |