From 65e0f8015e467ae8e6dab24c2d40ac4324673329 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Wed, 4 Jun 2008 00:05:00 +0000 Subject: [PATCH] Allow the creator to specify their own bounds if they don't want submenus to be constrained by the stage. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@519 ed5b42cb-e716-0410-a449-f6a68f950b19 --- src/as/com/threerings/flex/CommandMenu.as | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/as/com/threerings/flex/CommandMenu.as b/src/as/com/threerings/flex/CommandMenu.as index 9d603b6b..0a8574ab 100644 --- a/src/as/com/threerings/flex/CommandMenu.as +++ b/src/as/com/threerings/flex/CommandMenu.as @@ -117,6 +117,17 @@ public class CommandMenu extends Menu _dispatcher = dispatcher; } + /** + * Sets a Rectangle (in stage coords) that the menu will attempt to keep submenus positioned + * within. If a submenu is too large to fit, it will position it in the lower right corner + * of this Rectangle (or top if popping upwards, or left if popping leftwards). This + * value defaults to the stage bounds. + */ + public function setBounds (fitting :Rectangle) :void + { + _fitting = fitting; + } + /** * Actually pop up the menu. This can be used instead of show(). */ @@ -244,7 +255,8 @@ public class CommandMenu extends Menu var submenu :Menu = IMenuItemRenderer(row).menu; var lefting :Boolean = _lefting; var upping :Boolean = _upping; - var fitting :Rectangle = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight); + var fitting :Rectangle = _fitting != null ? _fitting : + new Rectangle(0, 0, stage.stageWidth, stage.stageHeight); if (submenu.x + submenu.getExplicitOrMeasuredWidth() > fitting.right) { lefting = true; } @@ -264,11 +276,11 @@ public class CommandMenu extends Menu // 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( + submenu.x = lefting ? fitting.left : Math.max( fitting.right - submenu.getExplicitOrMeasuredWidth(), fitting.left); } if (submenu.y < fitting.top) { - submenu.y = upping ? 0 : Math.max( + submenu.y = upping ? fitting.top : Math.max( fitting.bottom - submenu.getExplicitOrMeasuredHeight(), fitting.top); } } @@ -323,5 +335,6 @@ public class CommandMenu extends Menu protected var _dispatcher :IEventDispatcher; protected var _lefting :Boolean = false; protected var _upping :Boolean = false; + protected var _fitting :Rectangle = null; } }