From 6b40089e528e569cab14c60f6542d835d2b82e12 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Tue, 3 Jun 2008 23:35:34 +0000 Subject: [PATCH] Fixed some layout problems with _upping submenus. Also, the _fitting member variable was checked in submenu layout, but it could never get set to anything but null. So, now it just assumes that it should be fitting to the stage and does that (it would previously just put the menu wherever its broken math put it, and not checking against the bounds of anything). I have a slight inclination to bring back a method for supplying a fitting Rectangle so that it can be fitting these menus between the header bar and control bar. Maybe I'll just do that next. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@518 ed5b42cb-e716-0410-a449-f6a68f950b19 --- src/as/com/threerings/flex/CommandMenu.as | 42 +++++++++++------------ 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/as/com/threerings/flex/CommandMenu.as b/src/as/com/threerings/flex/CommandMenu.as index d18727f2..9d603b6b 100644 --- a/src/as/com/threerings/flex/CommandMenu.as +++ b/src/as/com/threerings/flex/CommandMenu.as @@ -125,7 +125,6 @@ public class CommandMenu extends Menu { _upping = popUpwards; _lefting = popLeftwards; - _fitting = null; var r :Rectangle = trigger.getBounds(trigger.stage); show(_lefting ? r.left : r.right, _upping ? r.top : r.bottom); } @@ -138,7 +137,6 @@ public class CommandMenu extends Menu { _upping = popUpwards; _lefting = popLeftwards; - _fitting = null; show(mx, my); } @@ -149,7 +147,6 @@ public class CommandMenu extends Menu { _upping = popUpwards; _lefting = popLeftwards; - _fitting = null; show(); // our show, with no args, pops at the mouse } @@ -247,30 +244,32 @@ public class CommandMenu extends Menu var submenu :Menu = IMenuItemRenderer(row).menu; var lefting :Boolean = _lefting; var upping :Boolean = _upping; - if (_fitting != null) { - if (submenu.x + submenu.getExplicitOrMeasuredWidth() > _fitting.right) { - lefting = true; - } - if (submenu.y + submenu.getExplicitOrMeasuredHeight() > _fitting.bottom) { - upping = true; - } + var fitting :Rectangle = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight); + if (submenu.x + submenu.getExplicitOrMeasuredWidth() > fitting.right) { + lefting = true; } + if (submenu.y + submenu.getExplicitOrMeasuredHeight() > fitting.bottom) { + upping = true; + } + if (lefting) { submenu.x -= submenu.getExplicitOrMeasuredWidth(); } if (upping) { - submenu.y -= (submenu.getExplicitOrMeasuredHeight() - DisplayObject(row).height); + var displayObj :DisplayObject = DisplayObject(row); + var rowLoc :Point = displayObj.localToGlobal(new Point(row.x, row.y)); + submenu.y = rowLoc.y - submenu.getExplicitOrMeasuredHeight() + displayObj.height; } - // if we've poped out of the boundaries, just snap it to the lower right corner - if (_fitting != null) { - if (submenu.x < _fitting.left) { - submenu.x = Math.max( - _fitting.right - submenu.getExplicitOrMeasuredWidth(), _fitting.left); - } - if (submenu.y < _fitting.top) { - submenu.y = Math.max( - _fitting.bottom - submenu.getExplicitOrMeasuredHeight(), _fitting.top); - } + + // if we've poped out of the boundaries, just snap it to the lower right corner, or upper + // if upping, left if lefting + if (submenu.x < fitting.left) { + submenu.x = lefting ? 0 : Math.max( + fitting.right - submenu.getExplicitOrMeasuredWidth(), fitting.left); + } + if (submenu.y < fitting.top) { + submenu.y = upping ? 0 : Math.max( + fitting.bottom - submenu.getExplicitOrMeasuredHeight(), fitting.top); } } @@ -322,7 +321,6 @@ public class CommandMenu extends Menu } protected var _dispatcher :IEventDispatcher; - protected var _fitting :Rectangle; protected var _lefting :Boolean = false; protected var _upping :Boolean = false; }