Fix Rename Popup direction near screen edges

#317
This commit is contained in:
Wojtek Figat
2021-03-18 16:48:07 +01:00
parent ac511cbadc
commit 759dc98737
2 changed files with 24 additions and 19 deletions

View File

@@ -47,6 +47,11 @@ namespace FlaxEditor.GUI.ContextMenu
private Window _window;
private Control _previouslyFocused;
/// <summary>
/// Gets a value indicating whether use automatic popup direction fix based on the screen dimensions.
/// </summary>
protected virtual bool UseAutomaticDirectionFix => true;
/// <summary>
/// Returns true if context menu is opened
/// </summary>
@@ -132,21 +137,24 @@ namespace FlaxEditor.GUI.ContextMenu
Rectangle monitorBounds = Platform.GetMonitorBounds(locationSS);
Vector2 rightBottomLocationSS = locationSS + dpiSize;
bool isUp = false, isLeft = false;
if (monitorBounds.Bottom < rightBottomLocationSS.Y)
if (UseAutomaticDirectionFix)
{
// Direction: up
isUp = true;
locationSS.Y -= dpiSize.Y;
if (monitorBounds.Bottom < rightBottomLocationSS.Y)
{
// Direction: up
isUp = true;
locationSS.Y -= dpiSize.Y;
// Offset to fix sub-menu location
if (parent is ContextMenu menu && menu._childCM != null)
locationSS.Y += 30.0f * dpiScale;
}
if (monitorBounds.Right < rightBottomLocationSS.X)
{
// Direction: left
isLeft = true;
locationSS.X -= dpiSize.X;
// Offset to fix sub-menu location
if (parent is ContextMenu menu && menu._childCM != null)
locationSS.Y += 30.0f * dpiScale;
}
if (monitorBounds.Right < rightBottomLocationSS.X)
{
// Direction: left
isLeft = true;
locationSS.X -= dpiSize.X;
}
}
// Update direction flag