Mercurial > projects > mde
comparison mde/gui/WidgetManager.d @ 152:c67d074a7111
Menu placement now takes into account left/right placement of parent menus.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Fri, 10 Apr 2009 15:19:46 +0200 |
parents | 075705ad664a |
children | b06b04c75e86 |
comparison
equal
deleted
inserted
replaced
151:e785e98d3b78 | 152:c67d074a7111 |
---|---|
306 } | 306 } |
307 override bool removeChildIPPW (IPopupParentWidget ippw) { | 307 override bool removeChildIPPW (IPopupParentWidget ippw) { |
308 if (childIPPW !is ippw) return false; | 308 if (childIPPW !is ippw) return false; |
309 childIPPW.removedIPPW; | 309 childIPPW.removedIPPW; |
310 childIPPW = null; | 310 childIPPW = null; |
311 mAIPPW = false; | 311 mAIPPW = MenuPosition.INACTIVE; |
312 requestRedraw; | 312 requestRedraw; |
313 return false; | 313 return false; |
314 } | 314 } |
315 | 315 |
316 override void menuActive (bool mA) { | 316 override void menuActive (MenuPosition mA) { |
317 mAIPPW = mA; | 317 mAIPPW = mA; |
318 if (childIPPW) | 318 if (childIPPW) |
319 childIPPW.menuActive = mA; | 319 childIPPW.menuActive = mA; |
320 } | 320 } |
321 override bool menuActive () { | 321 override MenuPosition menuActive () { |
322 return mAIPPW; | 322 return mAIPPW; |
323 } | 323 } |
324 override bool parentMenuActive () { | 324 override MenuPosition parentMenuActive () { |
325 return false; | 325 return MenuPosition.INACTIVE; |
326 } | 326 } |
327 | 327 |
328 // Don't do anything. E.g. can get called by non-popup buttons. | 328 // Don't do anything. E.g. can get called by non-popup buttons. |
329 override void menuDone () {} | 329 override void menuDone () {} |
330 | 330 |
331 override IChildWidget getPopupWidget (wdabs cx, wdabs cy, bool closePopup) { | 331 override IChildWidget getPopupWidget (wdabs cx, wdabs cy, bool closePopup) { |
332 if (popupContext) { | 332 if (popupContext) { |
333 if (popupContext.onSelf (cx, cy)) | 333 if (popupContext.onSelf (cx, cy)) |
334 return popupContext; | 334 return popupContext; |
335 if (closePopup) { | 335 if (closePopup) { |
336 menuActive = (childIPPW !is null); | 336 if (childIPPW is null) |
337 menuActive = MenuPosition.INACTIVE; | |
337 popupContext = null; | 338 popupContext = null; |
338 requestRedraw; | 339 requestRedraw; |
339 } | 340 } |
340 } | 341 } |
341 if (childIPPW) { | 342 if (childIPPW) { |
342 IChildWidget ret = | 343 IChildWidget ret = |
343 childIPPW.getPopupWidget (cx, cy, closePopup); | 344 childIPPW.getPopupWidget (cx, cy, closePopup); |
344 if (ret) return ret; | 345 if (ret) return ret; |
345 if (closePopup) { | 346 if (closePopup) { |
346 menuActive = false; | 347 menuActive = MenuPosition.INACTIVE; |
347 removeChildIPPW (childIPPW); | 348 removeChildIPPW (childIPPW); |
348 } | 349 } |
349 } | 350 } |
350 return null; | 351 return null; |
351 } | 352 } |
407 IRenderer renderer () { | 408 IRenderer renderer () { |
408 assert (rend !is null, "WidgetManager.renderer: rend is null"); | 409 assert (rend !is null, "WidgetManager.renderer: rend is null"); |
409 return rend; | 410 return rend; |
410 } | 411 } |
411 | 412 |
412 void positionPopup (IChildWidget parent, IChildWidget popup, int flags = 0) { | 413 MenuPosition positionPopup (IChildWidget parent, IChildWidget popup, MenuPosition position = MenuPosition.INACTIVE) { |
413 debug assert (parent && popup, "positionPopup: null widget"); | 414 debug assert (parent && popup, "positionPopup: null widget"); |
414 wdim w = popup.width, | 415 wdim w = popup.width, |
415 h = popup.height, | 416 h = popup.height, |
416 x, y; | 417 x, y; |
417 if (flags & 1) { | 418 if (position & MenuPosition.ACTIVE) { |
418 y = parent.yPos; // height flush with top | 419 y = parent.yPos; // height flush with top |
419 if (y+h > this.h) y += parent.height - h; // or bottom | 420 if (y+h > this.h) y += parent.height - h; // or bottom |
420 x = parent.xPos + parent.width; // on right | 421 if (position & MenuPosition.LEFT) { // previously left |
421 if (x+w > this.w) x = parent.xPos - w; // or left edge | 422 x = parent.xPos - w; // on left |
423 if (x < 0) { | |
424 x = parent.xPos + parent.width; // on right | |
425 position = MenuPosition.RIGHT; | |
426 } | |
427 } else { // previously right or above/below | |
428 x = parent.xPos + parent.width; // on right | |
429 position = MenuPosition.RIGHT; | |
430 if (x+w > this.w) { | |
431 x = parent.xPos - w; // or left | |
432 position = MenuPosition.LEFT; | |
433 } | |
434 } | |
422 } else { | 435 } else { |
423 x = parent.xPos; // align on left edge | 436 wdim pw = parent.width; |
424 if (x+w > this.w) x += parent.width - w; // align on right edge | 437 if (w < pw && popup.minWidth <= pw) |
438 popup.setWidth (pw, -1); // neatness | |
439 x = parent.xPos; // align on left edge | |
440 if (x+w > this.w) x += pw - w; // align on right edge | |
425 y = parent.yPos + parent.height; // place below | 441 y = parent.yPos + parent.height; // place below |
426 if (y+h > this.h) y = parent.yPos - h; // or above | 442 if (y+h > this.h) y = parent.yPos - h; // or above |
443 position = MenuPosition.ACTIVE; | |
427 } | 444 } |
428 if (x < 0) x = 0; // may be placed partially off-screen | 445 if (x < 0) x = 0; // may be placed partially off-screen |
429 if (y < 0) y = 0; | 446 if (y < 0) y = 0; |
430 popup.setPosition (x, y); | 447 popup.setPosition (x, y); |
431 //debug logger.trace ("placed popup at {},{}; size: {},{}", x,y, w,h); | 448 //debug logger.trace ("placed popup at {},{}; size: {},{}", x,y, w,h); |
449 return position; | |
432 } | 450 } |
433 | 451 |
434 void requestRedraw () { | 452 void requestRedraw () { |
435 imde.mainSchedule.request(imde.SCHEDULE.DRAW); | 453 imde.mainSchedule.request(imde.SCHEDULE.DRAW); |
436 } | 454 } |
614 wdim w,h; // current widget size; should be at least (mw,mh) even if not displayable | 632 wdim w,h; // current widget size; should be at least (mw,mh) even if not displayable |
615 wdim mw,mh; // minimal area required by widgets | 633 wdim mw,mh; // minimal area required by widgets |
616 scope IChildWidget child; // The primary widget. | 634 scope IChildWidget child; // The primary widget. |
617 uint setupN; // n to pass to IChildWidget.setup | 635 uint setupN; // n to pass to IChildWidget.setup |
618 | 636 |
619 bool mAIPPW; // IPPW variable | 637 MenuPosition mAIPPW; // IPPW variable |
620 IPopupParentWidget childIPPW; // child IPPW, if any active | 638 IPopupParentWidget childIPPW; // child IPPW, if any active |
621 | 639 |
622 // Popup(s) handled directly by AWidgetManager: | 640 // Popup(s) handled directly by AWidgetManager: |
623 IChildWidget popupContext; // context menu (active if not null) | 641 IChildWidget popupContext; // context menu (active if not null) |
624 | 642 |