Add optional direction option to context menu
This commit is contained in:
@@ -355,14 +355,14 @@ namespace FlaxEditor.GUI.ContextMenu
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Show(Control parent, Float2 location)
|
||||
public override void Show(Control parent, Float2 location, ContextMenuDirection? direction = null)
|
||||
{
|
||||
// Remove last separator to make context menu look better
|
||||
int lastIndex = _panel.Children.Count - 1;
|
||||
if (lastIndex >= 0 && _panel.Children[lastIndex] is ContextMenuSeparator separator)
|
||||
separator.Dispose();
|
||||
|
||||
base.Show(parent, location);
|
||||
base.Show(parent, location, direction);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -134,7 +134,8 @@ namespace FlaxEditor.GUI.ContextMenu
|
||||
/// </summary>
|
||||
/// <param name="parent">Parent control to attach to it.</param>
|
||||
/// <param name="location">Popup menu origin location in parent control coordinates.</param>
|
||||
public virtual void Show(Control parent, Float2 location)
|
||||
/// <param name="direction">The custom popup direction. Null to use automatic direction.</param>
|
||||
public virtual void Show(Control parent, Float2 location, ContextMenuDirection? direction = null)
|
||||
{
|
||||
Assert.IsNotNull(parent);
|
||||
|
||||
@@ -166,7 +167,7 @@ namespace FlaxEditor.GUI.ContextMenu
|
||||
var monitorBounds = Platform.GetMonitorBounds(locationSS);
|
||||
var rightBottomLocationSS = locationSS + dpiSize;
|
||||
bool isUp = false, isLeft = false;
|
||||
if (UseAutomaticDirectionFix)
|
||||
if (UseAutomaticDirectionFix && direction == null)
|
||||
{
|
||||
var parentMenu = parent as ContextMenu;
|
||||
if (monitorBounds.Bottom < rightBottomLocationSS.Y)
|
||||
@@ -193,6 +194,26 @@ namespace FlaxEditor.GUI.ContextMenu
|
||||
locationSS.X -= dpiSize.X;
|
||||
}
|
||||
}
|
||||
else if (direction.HasValue)
|
||||
{
|
||||
switch (direction.Value)
|
||||
{
|
||||
case ContextMenuDirection.RightUp:
|
||||
isUp = true;
|
||||
break;
|
||||
case ContextMenuDirection.LeftDown:
|
||||
isLeft = true;
|
||||
break;
|
||||
case ContextMenuDirection.LeftUp:
|
||||
isLeft = true;
|
||||
isUp = true;
|
||||
break;
|
||||
}
|
||||
if (isLeft)
|
||||
locationSS.X -= dpiSize.X;
|
||||
if (isUp)
|
||||
locationSS.Y -= dpiSize.Y;
|
||||
}
|
||||
|
||||
// Update direction flag
|
||||
if (isUp)
|
||||
|
||||
@@ -759,7 +759,7 @@ namespace FlaxEditor.Surface.ContextMenu
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Show(Control parent, Float2 location)
|
||||
public override void Show(Control parent, Float2 location, ContextMenuDirection? direction = null)
|
||||
{
|
||||
Show(parent, location, null);
|
||||
}
|
||||
|
||||
@@ -155,9 +155,9 @@ namespace FlaxEditor.Windows.Search
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Show(Control parent, Float2 location)
|
||||
public override void Show(Control parent, Float2 location, ContextMenuDirection? direction = null)
|
||||
{
|
||||
base.Show(parent, location);
|
||||
base.Show(parent, location, direction);
|
||||
|
||||
// Setup
|
||||
_resultPanel.ScrollViewTo(Float2.Zero);
|
||||
|
||||
Reference in New Issue
Block a user