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
This commit is contained in:
Mark Johnson
2008-02-16 01:01:14 +00:00
parent ba7dadba97
commit 7e804e60c5
+18
View File
@@ -139,9 +139,16 @@ public class CommandMenu extends Menu
if (mx + getExplicitOrMeasuredWidth() > bounds.right) { if (mx + getExplicitOrMeasuredWidth() > bounds.right) {
mx -= getExplicitOrMeasuredWidth(); 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) { if (my + getExplicitOrMeasuredHeight() > bounds.bottom) {
my -= getExplicitOrMeasuredHeight(); my -= getExplicitOrMeasuredHeight();
} }
if (my < bounds.top) {
my = Math.max(bounds.bottom - getExplicitOrMeasuredHeight(), bounds.top);
}
// finally move it to the correct position // finally move it to the correct position
x = mx; x = mx;
@@ -265,6 +272,17 @@ public class CommandMenu extends Menu
if (upping) { if (upping) {
submenu.y -= (submenu.getExplicitOrMeasuredHeight() - DisplayObject(row).height); 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 // from List