From 7e804e60c5b094d5d40dcf03dad434355dee990f Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Sat, 16 Feb 2008 01:01:14 +0000 Subject: [PATCH] Perform a better fitting for menu's in a bounded region, so they'll position themself for maximum visibility even if they can't fully pop up/down, left/right. (Menu's larger than the bounded area will still have some issues). git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@417 ed5b42cb-e716-0410-a449-f6a68f950b19 --- src/as/com/threerings/flex/CommandMenu.as | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/as/com/threerings/flex/CommandMenu.as b/src/as/com/threerings/flex/CommandMenu.as index d9d5ea6e..37900874 100644 --- a/src/as/com/threerings/flex/CommandMenu.as +++ b/src/as/com/threerings/flex/CommandMenu.as @@ -72,7 +72,7 @@ use namespace mx_internal; * ]; * * See "Defining menu structure and data" in the Flex manual for the full list. - */ + */ public class CommandMenu extends Menu { /** @@ -139,9 +139,16 @@ public class CommandMenu extends Menu if (mx + getExplicitOrMeasuredWidth() > bounds.right) { mx -= getExplicitOrMeasuredWidth(); } + if (mx < bounds.left) { + mx = Math.max(bounds.right - getExplicitOrMeasuredWidth(), bounds.left); + } + // if we've poped out of the boundaries, just snap it to the lower right corner if (my + getExplicitOrMeasuredHeight() > bounds.bottom) { my -= getExplicitOrMeasuredHeight(); } + if (my < bounds.top) { + my = Math.max(bounds.bottom - getExplicitOrMeasuredHeight(), bounds.top); + } // finally move it to the correct position x = mx; @@ -265,6 +272,17 @@ public class CommandMenu extends Menu if (upping) { submenu.y -= (submenu.getExplicitOrMeasuredHeight() - DisplayObject(row).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); + } + } } // from List