comparison mde/gui/widget/WidgetManager.d @ 179:1f9d00f392bd default tip

Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now. Optimised when ServiceContentList.opCall is called, I think without breaking anything.
author Diggory Hardy <diggory.hardy@gmail.com>
date Tue, 15 Sep 2009 20:09:59 +0200
parents af40e9679436
children
comparison
equal deleted inserted replaced
178:62aa8845edd2 179:1f9d00f392bd
143 if (widget.width < nmw) 143 if (widget.width < nmw)
144 widget.setWidth (nmw, -1); 144 widget.setWidth (nmw, -1);
145 return; 145 return;
146 } 146 }
147 mw = nmw; 147 mw = nmw;
148 if (w < nmw) { 148 matchMinimalSize ();
149 childRoot.setWidth (nmw, -1); 149 nmw = w; // reuse to see if width is changed
150 w = nmw; 150 w = mw > sW ? mw : sW;
151 } 151 if (w != nmw)
152 childRoot.setWidth (w, -1);
152 childRoot.setPosition (0,0); 153 childRoot.setPosition (0,0);
153 requestRedraw; 154 requestRedraw;
154 } 155 }
155 override void minHChange (IChildWidget widget, wdim nmh) { 156 override void minHChange (IChildWidget widget, wdim nmh) {
156 if (widget !is childRoot) { 157 if (widget !is childRoot) {
157 if (widget.height < nmh) 158 if (widget.height < nmh)
158 widget.setHeight (nmh, -1); 159 widget.setHeight (nmh, -1);
159 return; 160 return;
160 } 161 }
161 mh = nmh; 162 mh = nmh;
162 if (h < nmh) { 163 matchMinimalSize ();
163 childRoot.setHeight (nmh, -1); 164 nmh = h;
164 h = nmh; 165 h = mh > sH ? mh : sH;
165 } 166 if (h != nmh)
167 childRoot.setHeight (nmh, -1);
166 childRoot.setPosition (0,0); 168 childRoot.setPosition (0,0);
167 requestRedraw; 169 requestRedraw;
168 } 170 }
169 //END IParentWidget methods 171 //END IParentWidget methods
170 172
370 mw = childRoot.minWidth; 372 mw = childRoot.minWidth;
371 mh = childRoot.minHeight; 373 mh = childRoot.minHeight;
372 matchMinimalSize (); 374 matchMinimalSize ();
373 375
374 debug (mdeWidgets) logger.trace ("Setting size and position of root widget..."); 376 debug (mdeWidgets) logger.trace ("Setting size and position of root widget...");
375 childRoot.setWidth (w, -1); 377 w = mw > sW ? mw : sW;
378 h = mh > sH ? mh : sH;
379 childRoot.setWidth (w, -1);
376 childRoot.setHeight (h, -1); 380 childRoot.setHeight (h, -1);
377 childRoot.setPosition (0,0); 381 childRoot.setPosition (0,0);
378 debug (mdeWidgets) logger.trace ("Done creating root widget."); 382 debug (mdeWidgets) logger.trace ("Done creating root widget.");
379 383
380 childContext = new PopupHandlerWidget (this, this, "contextHandler", "context", serviceContent); 384 childContext = new PopupHandlerWidget (this, this, "contextHandler", "context", serviceContent);
383 387
384 underMouse = childRoot; // must be something 388 underMouse = childRoot; // must be something
385 } 389 }
386 390
387 final void wmSizeEvent (int nw, int nh) { 391 final void wmSizeEvent (int nw, int nh) {
388 w = cast(wdim) nw; 392 sW = cast(wdim) nw;
389 h = cast(wdim) nh; 393 sH = cast(wdim) nh;
390 matchMinimalSize; 394 matchMinimalSize;
391 395
392 if (!childRoot) return; // if not created yet. 396 if (!childRoot) return; // if not created yet.
393 childRoot.setWidth (w, -1); 397 if (sW != w && w != mw) {
394 childRoot.setHeight (h, -1); 398 w = mw > sW ? mw : sW;
399 childRoot.setWidth (w, -1);
400 }
401 if (sH != h && h != mh) {
402 h = mh > sH ? mh : sH;
403 childRoot.setHeight (h, -1);
404 }
395 childRoot.setPosition (0,0); 405 childRoot.setPosition (0,0);
396 debug logWidgetSize (null); 406 debug logWidgetSize (null);
397 } 407 }
398 408
399 /** For mouse click events. 409 /** For mouse click events.
473 // for internal use 483 // for internal use
474 private final void updateUnderMouse (wdabs cx, wdabs cy, bool closePopup) { 484 private final void updateUnderMouse (wdabs cx, wdabs cy, bool closePopup) {
475 auto oUM = underMouse; 485 auto oUM = underMouse;
476 underMouse = getPopupWidget (cx, cy, closePopup); 486 underMouse = getPopupWidget (cx, cy, closePopup);
477 if (underMouse is null) { 487 if (underMouse is null) {
478 debug assert (childRoot.onSelf (cx, cy), "WidgetManager: childRoot doesn't cover whole area"); 488 // Note: I'm surprised this never fails, since clicks outside the
489 // window are reported. If it does, better allow underMouse to be
490 // null.
491 debug assert (childRoot.onSelf (cx, cy), "WidgetManager: click not on childRoot");
479 underMouse = childRoot.getWidget (cx, cy); 492 underMouse = childRoot.getWidget (cx, cy);
480 } 493 }
481 debug assert (oUM && underMouse, "no widget under mouse: error"); 494 debug assert (oUM && underMouse, "no widget under mouse: error");
482 if (underMouse !is oUM) { 495 if (underMouse !is oUM) {
483 oUM.underMouse (false); 496 oUM.underMouse (false);
486 logger.trace ("Widget under mouse: {}", underMouse); 499 logger.trace ("Widget under mouse: {}", underMouse);
487 } 500 }
488 } 501 }
489 502
490 /** If possible, the screen-interaction derived class should override to 503 /** If possible, the screen-interaction derived class should override to
491 * make sure the window is at least (mw,mh) in size. In any case, this 504 * make sure the window is at least (mw,mh) in size (use sW, sH to store
492 * method MUST make sure w >= mw and h >= mh even if the window isn't this 505 * the actual size).
493 * big.
494 * 506 *
495 * A resize may not be required when this is called, however. */ 507 * A resize won't always be required when this is called. */
496 void matchMinimalSize () { 508 void matchMinimalSize () {
497 if (w < mw) { 509 if (sW < mw)
498 logger.warn ("Min width for gui, {}, not met: {}", mw, w); 510 logger.warn ("Min width for gui, {}, not met: {}", mw, sW);
499 w = mw; 511 if (sH < mh)
500 } 512 logger.warn ("Min height for gui, {}, not met: {}", mh, sH);
501 if (h < mh) {
502 logger.warn ("Min height for gui, {}, not met: {}", mh, h);
503 h = mh;
504 }
505 } 513 }
506 514
507 /// This should be overloaded to set a callback receiving keyboard input. 515 /// This should be overloaded to set a callback receiving keyboard input.
508 abstract void setLetterCallback(void delegate(ushort, char[])); 516 abstract void setLetterCallback(void delegate(ushort, char[]));
509 //END WidgetManagement methods 517 //END WidgetManagement methods
619 IChildWidget childRoot; // Root of the main GUI widget tree 627 IChildWidget childRoot; // Root of the main GUI widget tree
620 628
621 // Dimensions and child set-up data (fit to childRoot): 629 // Dimensions and child set-up data (fit to childRoot):
622 wdim w,h; // current widget size; should be at least (mw,mh) even if not displayable 630 wdim w,h; // current widget size; should be at least (mw,mh) even if not displayable
623 wdim mw,mh; // minimal area required by widgets 631 wdim mw,mh; // minimal area required by widgets
632 wdim sW,sH; // actual screen size; ideally equal to w,h
624 uint setupN; // n to pass to IChildWidget.setup 633 uint setupN; // n to pass to IChildWidget.setup
625 634
626 // IPopupParentWidget stuff for childRoot: 635 // IPopupParentWidget stuff for childRoot:
627 MenuPosition mAIPPW; // IPPW variable 636 MenuPosition mAIPPW; // IPPW variable
628 IPopupParentWidget childIPPW; // child IPPW, if any active 637 IPopupParentWidget childIPPW; // child IPPW, if any active