diff --git a/osu.Game.Tests/Visual/Editing/TestSceneExpandingToolboxContainer.cs b/osu.Game.Tests/Visual/Editing/TestSceneExpandingToolboxContainer.cs new file mode 100644 index 000000000000..ad73c0dbc797 --- /dev/null +++ b/osu.Game.Tests/Visual/Editing/TestSceneExpandingToolboxContainer.cs @@ -0,0 +1,58 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using NUnit.Framework; +using osu.Framework.Graphics; +using osu.Framework.Testing; +using osu.Framework.Graphics.Shapes; +using osu.Game.Rulesets.Edit; +using osuTK.Input; + +namespace osu.Game.Tests.Visual.Editing +{ + [TestFixture] + public partial class TestSceneExpandingToolboxContainer : OsuManualInputManagerTestScene + { + private ExpandingToolboxContainer toolbox = null!; + + [SetUpSteps] + public void SetUpSteps() + { + AddStep("create toolbox", () => + { + toolbox = new ExpandingToolboxContainer(50, 200) + { + Child = new Box + { + RelativeSizeAxes = Axes.X, + Height = 1000, + Colour = Colour4.Red, + } + }; + Child = toolbox; + }); + } + + [Test] + public void TestExpandingToolbox() + { + AddStep("collapse toolbox", () => toolbox.Expanded.Value = false); + AddStep("click on toolbox", () => + { + InputManager.MoveMouseTo(toolbox.ScreenSpaceDrawQuad.Centre); + InputManager.Click(MouseButton.Left); + }); + AddUntilStep("toolbox expanded", () => toolbox.Expanded.Value); + + AddStep("collapse toolbox", () => toolbox.Expanded.Value = false); + AddStep("drag cursor inside", () => + { + InputManager.MoveMouseTo(toolbox.ScreenSpaceDrawQuad.TopLeft); + InputManager.PressButton(MouseButton.Left); + InputManager.MoveMouseTo(toolbox.ScreenSpaceDrawQuad.BottomRight); + InputManager.ReleaseButton(MouseButton.Left); + }); + AddAssert("toolbox remains collapsed", () => !toolbox.Expanded.Value); + } + } +} diff --git a/osu.Game/Graphics/Containers/ExpandingContainer.cs b/osu.Game/Graphics/Containers/ExpandingContainer.cs index 2abdb508aebf..baab7476e499 100644 --- a/osu.Game/Graphics/Containers/ExpandingContainer.cs +++ b/osu.Game/Graphics/Containers/ExpandingContainer.cs @@ -71,6 +71,16 @@ protected override bool OnHover(HoverEvent e) return true; } + protected override bool OnClick(ClickEvent e) + { + base.OnClick(e); + + if (!Expanded.Value) + Expanded.Value = true; + + return true; + } + protected override bool OnMouseMove(MouseMoveEvent e) { updateHoverExpansion(); diff --git a/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs b/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs index 8af795f8804d..d0164ceae24b 100644 --- a/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs +++ b/osu.Game/Rulesets/Edit/ExpandingToolboxContainer.cs @@ -62,7 +62,5 @@ protected override void Update() private bool anyToolboxHovered(Vector2 screenSpacePos) => FillFlow.ScreenSpaceDrawQuad.Contains(screenSpacePos); protected override bool OnMouseDown(MouseDownEvent e) => true; - - protected override bool OnClick(ClickEvent e) => true; } }