Merge pull request #2994 from smoogipoo/context-menu-passthru

Implement context menu pass-through + blocking
This commit is contained in:
Thomas Müller
2019-11-14 02:51:35 +01:00
committed by GitHub
3 changed files with 11 additions and 7 deletions

View File

@@ -167,8 +167,6 @@ namespace osu.Framework.Tests.Visual.UserInterface
assertMenuOnScreen(false);
}
// TODO: Fix test
[Ignore("needs to be fixed")]
[Test]
public void TestReturnNullInNestedDrawableOpensParentMenu()
{
@@ -182,8 +180,6 @@ namespace osu.Framework.Tests.Visual.UserInterface
assertMenuItems(2);
}
// TODO: Fix test
[Ignore("needs to be fixed")]
[Test]
public void TestReturnEmptyInNestedDrawableBlocksMenuOpening()
{

View File

@@ -67,16 +67,20 @@ namespace osu.Framework.Graphics.Cursor
switch (e.Button)
{
case MouseButton.Right:
menuTarget = FindTargets().FirstOrDefault();
var (target, items) = FindTargets()
.Select(t => (target: t, items: t.ContextMenuItems))
.FirstOrDefault(result => result.items != null);
if (menuTarget == null)
menuTarget = target;
if (menuTarget == null || items.Length == 0)
{
if (menu.State == MenuState.Open)
menu.Close();
return false;
}
menu.Items = menuTarget.ContextMenuItems;
menu.Items = items;
targetRelativePosition = menuTarget.ToLocalSpace(e.ScreenSpaceMousePosition);

View File

@@ -10,6 +10,10 @@ namespace osu.Framework.Graphics.Cursor
/// <summary>
/// Menu items that appear when the drawable is right-clicked.
/// </summary>
/// <remarks>
/// If empty, this <see cref="Drawable"/> will be picked as the menu target but a context menu will not be shown.
/// <para>If null, this <see cref="Drawable"/> will not be picked as the menu target and other <see cref="Drawable"/>s underneath may become the menu target.</para>
/// </remarks>
MenuItem[] ContextMenuItems { get; }
}
}