comparison mde/gui/WidgetManager.d @ 92:085f2ca31914

Shared alignments supported in more complex cases.
author Diggory Hardy <diggory.hardy@gmail.com>
date Tue, 21 Oct 2008 09:57:19 +0100
parents 4d5d53e4f881
children 08a4ae11454b
comparison
equal deleted inserted replaced
91:4d5d53e4f881 92:085f2ca31914
60 super(file); 60 super(file);
61 61
62 Screen.addDrawable (this); 62 Screen.addDrawable (this);
63 } 63 }
64 64
65 // NOTE - temporarily here to allow CTOR to run safely during static this 65 // this() runs during static this(), when imde.input doesn't exist. init() runs later.
66 // called during init
67 void init () { 66 void init () {
68 // Doesn't need a lock - cannot conflict with other class functions. 67 // Doesn't need a lock - cannot conflict with other class functions.
69 // Events we want to know about: 68 // Events we want to know about:
70 imde.input.addMouseClickCallback(&clickEvent); 69 imde.input.addMouseClickCallback(&clickEvent);
71 imde.input.addMouseMotionCallback(&motionEvent); 70 imde.input.addMouseMotionCallback(&motionEvent);
168 // The renderer needs to be created on the first load, but not after this. 167 // The renderer needs to be created on the first load, but not after this.
169 if (rend is null) 168 if (rend is null)
170 rend = createRenderer (rendName); 169 rend = createRenderer (rendName);
171 170
172 child = makeWidget ("root"); 171 child = makeWidget ("root");
172 finalize;
173 173
174 mw = child.minWidth; 174 mw = child.minWidth;
175 mh = child.minHeight; 175 mh = child.minHeight;
176 176
177 if (w < mw || h < mh) 177 if (w < mw || h < mh)
382 382
383 383
384 /** Create a widget by ID. 384 /** Create a widget by ID.
385 * 385 *
386 * A widget instance is created from data found under ID. Multiple instances may be created. 386 * A widget instance is created from data found under ID. Multiple instances may be created.
387 * FIXME - data conflicts when saving? 387 * NOTE - data conflicts when saving?
388 * 388 *
389 * An IContent may be passed. This could contain many things, e.g. some basic data, a widget, 389 * An IContent may be passed. This could contain many things, e.g. some basic data, a widget,
390 * multiple sub-IContents. It is only passed to the widget by createWidget if it's enumeration 390 * multiple sub-IContents. It is only passed to the widget by createWidget if it's enumeration
391 * given in that module has the flag TAKES_CONTENT. */ 391 * given in that module has the flag TAKES_CONTENT. */
392 IChildWidget makeWidget (widgetID id, IContent content = null) { 392 IChildWidget makeWidget (widgetID id, IContent content = null) {
393 debug (mdeWidgets) logger.trace ("Creating widget \""~id~'"'); 393 debug (mdeWidgets) logger.trace ("Creating widget \""~id~'"');
394 return createWidget (this, id, curData[id], content); 394 return createWidget (this, id, curData[id], content);
395 } 395 }
396 396
397 /** Runs finalize for all descendants, in a deepest first order. */
398 /* NOTE: The way this function works may seem a little odd, but it's designed to allow
399 * shared alignments to be initialized properly:
400 * 1. all sharing members need to know their children's min size
401 * 2. all sharing members need to add their children's min size to the alignment
402 * 3. all sharing members can only then get their min size
403 * This method will fail if alignment members are not all of the same generation. An alternate
404 * method without this drawback would be to have shared alignments created with a list of
405 * pointers to their members, and once all members have been created the alignment could
406 * initialize itself, first making sure each members' children have been initialized. */
407 void finalize () {
408 IChildWidget[][] descendants; // first index: depth; is a list of widgets at each depth
409
410 void recurseChildren (size_t depth, IChildWidget widget) {
411 foreach (child; widget.children)
412 recurseChildren (depth+1, child);
413
414 if (descendants.length <= depth)
415 descendants.length = depth * 2 + 1;
416 descendants[depth] ~= widget;
417 }
418
419 recurseChildren (0, child);
420 foreach_reverse (generation; descendants) {
421 foreach (widget; generation)
422 widget.prefinalize;
423 foreach (widget; generation)
424 widget.finalize;
425 }
426 }
427
397 /** For making changes. */ 428 /** For making changes. */
398 void setData (widgetID id, WidgetData d) { 429 void setData (widgetID id, WidgetData d) {
399 changes[id] = d; // also updates WidgetDataSet in data. 430 changes[id] = d; // also updates WidgetDataSet in data.
400 } 431 }
401 432
403 * 434 *
404 * loadDesign handles the data; this method needs to: 435 * loadDesign handles the data; this method needs to:
405 * --- 436 * ---
406 * // 1. Create the root widget: 437 * // 1. Create the root widget:
407 * child = makeWidget ("root"); 438 * child = makeWidget ("root");
439 * finalize;
408 * // 2. Set the setSize, e.g.: 440 * // 2. Set the setSize, e.g.:
409 * child.setWidth (child.minWidth, 1); 441 * child.setWidth (child.minWidth, 1);
410 * child.setHeight (child.minHeight, 1); 442 * child.setHeight (child.minHeight, 1);
411 * --- 443 * ---
412 */ 444 */