mirror of
https://github.com/SK-la/osu-framework.git
synced 2026-03-15 03:20:30 +00:00
Merge pull request #2994 from smoogipoo/context-menu-passthru
Implement context menu pass-through + blocking
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user