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
This commit is contained in:
Nathan Curtis
2008-06-04 00:05:00 +00:00
parent 6b40089e52
commit 65e0f8015e
+16 -3
View File
@@ -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;
}
}