Skip to content

Commit 298b92a

Browse files
committed
Fix menu items being clickable during fade out
Addresses concerns cited in ppy/osu#32735.
1 parent e828671 commit 298b92a

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

osu.Framework.Tests/Visual/UserInterface/TestSceneClosableMenu.cs

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using osu.Framework.Graphics.UserInterface;
1111
using osu.Framework.Input.Events;
1212
using osu.Framework.Testing;
13+
using osuTK;
1314
using osuTK.Input;
1415

1516
namespace osu.Framework.Tests.Visual.UserInterface
@@ -34,14 +35,7 @@ public void SetUpSteps()
3435
new MenuItem("Sub-item #2", () => { }),
3536
}
3637
},
37-
new MenuItem("Item #2")
38-
{
39-
Items = new[]
40-
{
41-
new MenuItem("Sub-item #1"),
42-
new MenuItem("Sub-item #2", () => { }),
43-
}
44-
},
38+
new MenuItem("Item #2"),
4539
}
4640
});
4741
}
@@ -131,6 +125,30 @@ public void TestMenuBlocksInputUnderneathIt()
131125
AddAssert("mouse handler not activated", () => !actionReceived);
132126
}
133127

128+
[Test]
129+
public void TestItemsNotClickableDuringFadeOut()
130+
{
131+
bool item1Clicked = false;
132+
bool item2Clicked = false;
133+
bool topLevelItemClicked = false;
134+
135+
AddStep("set item actions", () =>
136+
{
137+
Menus.GetSubMenu(0).Items[0].Items[0].Action.Value = () => item1Clicked = true;
138+
Menus.GetSubMenu(0).Items[0].Items[1].Action.Value = () => item2Clicked = true;
139+
Menus.GetSubMenu(0).Items[1].Action.Value = () => topLevelItemClicked = true;
140+
});
141+
142+
AddStep("click item", () => ClickItem(0, 0));
143+
AddStep("click item", () => ClickItem(1, 0));
144+
AddAssert("menu item 1 activated", () => item1Clicked);
145+
AddStep("click item", () => ClickItem(1, 1));
146+
AddAssert("menu item 2 not activated", () => !item2Clicked);
147+
148+
AddStep("click top level item", () => ClickItem(0, 1));
149+
AddAssert("top level item not activated", () => !topLevelItemClicked);
150+
}
151+
134152
private partial class MouseHandlingLayer : Drawable
135153
{
136154
public Action Action { get; set; }
@@ -161,9 +179,18 @@ protected override bool OnKeyDown(KeyDownEvent e)
161179
return PressBlocked = base.OnKeyDown(e);
162180
}
163181

182+
protected override void UpdateSize(Vector2 newSize)
183+
{
184+
Width = newSize.X;
185+
186+
// I don't know why menu size is reset to zero on closing, but let's just ignore it to make things work.
187+
if (newSize.Y > 0)
188+
this.ResizeHeightTo(newSize.Y, 300, Easing.OutQuint);
189+
}
190+
164191
protected override void AnimateOpen() => this.FadeIn(500);
165192

166-
protected override void AnimateClose() => this.FadeOut(5000); // Ensure escape is pressed while menu is still fading
193+
protected override void AnimateClose() => this.Delay(500).FadeOut(5000); // Ensure escape is pressed while menu is still fading
167194

168195
protected override Menu CreateSubMenu() => new AnimatedMenu(Direction);
169196
}

osu.Framework/Graphics/UserInterface/Menu.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ public abstract partial class Menu : CompositeDrawable, IStateful<MenuState>
8383
private readonly Container<Menu> submenuContainer;
8484
private readonly LayoutValue positionLayout = new LayoutValue(Invalidation.DrawInfo | Invalidation.RequiredParentSizeToFit);
8585

86+
public override bool PropagatePositionalInputSubTree => State == MenuState.Open;
87+
public override bool HandlePositionalInput => State == MenuState.Open;
88+
public override bool HandleNonPositionalInput => State == MenuState.Open;
89+
8690
/// <summary>
8791
/// Constructs a menu.
8892
/// </summary>
@@ -627,8 +631,6 @@ private void menuItemHovered(DrawableMenuItem item)
627631
}
628632
}
629633

630-
public override bool HandleNonPositionalInput => State == MenuState.Open;
631-
632634
protected override bool OnKeyDown(KeyDownEvent e)
633635
{
634636
if (e.Key == Key.Escape && !TopLevelMenu)

0 commit comments

Comments
 (0)