diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneExpandingControlContainer.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneExpandingContainer.cs similarity index 74% rename from osu.Game.Tests/Visual/UserInterface/TestSceneExpandingControlContainer.cs rename to osu.Game.Tests/Visual/UserInterface/TestSceneExpandingContainer.cs index 48089566cc..f63591311f 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneExpandingControlContainer.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneExpandingContainer.cs @@ -1,20 +1,16 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Linq; using NUnit.Framework; using osu.Framework.Bindables; using osu.Framework.Graphics; -using osu.Framework.Testing; -using osu.Game.Graphics.UserInterface; using osu.Game.Overlays; using osu.Game.Overlays.Settings.Sections; using osuTK; -using osuTK.Input; namespace osu.Game.Tests.Visual.UserInterface { - public class TestSceneExpandingControlContainer : OsuManualInputManagerTestScene + public class TestSceneExpandingContainer : OsuManualInputManagerTestScene { private TestExpandingContainer container; private SettingsToolboxGroup toolboxGroup; @@ -84,44 +80,22 @@ namespace osu.Game.Tests.Visual.UserInterface } /// - /// Tests hovering over controls expands the parenting container appropriately and does not contract until hover is lost from container. + /// Tests hovering expands the container and does not contract until hover is lost. /// [Test] - public void TestHoveringControlExpandsContainer() + public void TestHoveringExpandsContainer() { AddAssert("ensure container contracted", () => !container.Expanded.Value); - AddStep("hover slider", () => InputManager.MoveMouseTo(slider1)); + AddStep("hover container", () => InputManager.MoveMouseTo(container)); AddAssert("container expanded", () => container.Expanded.Value); AddAssert("controls expanded", () => slider1.Expanded.Value && slider2.Expanded.Value); - AddStep("hover group top", () => InputManager.MoveMouseTo(toolboxGroup.ScreenSpaceDrawQuad.TopLeft + new Vector2(5))); - AddAssert("container still expanded", () => container.Expanded.Value); - AddAssert("controls still expanded", () => slider1.Expanded.Value && slider2.Expanded.Value); - AddStep("hover away", () => InputManager.MoveMouseTo(Vector2.Zero)); AddAssert("container contracted", () => !container.Expanded.Value); AddAssert("controls contracted", () => !slider1.Expanded.Value && !slider2.Expanded.Value); } - /// - /// Tests dragging a UI control (e.g. ) outside its parenting container does not contract it until dragging is finished. - /// - [Test] - public void TestDraggingControlOutsideDoesntContractContainer() - { - AddStep("hover slider", () => InputManager.MoveMouseTo(slider1)); - AddAssert("container expanded", () => container.Expanded.Value); - - AddStep("hover slider nub", () => InputManager.MoveMouseTo(slider1.ChildrenOfType().Single())); - AddStep("hold slider nub", () => InputManager.PressButton(MouseButton.Left)); - AddStep("drag outside container", () => InputManager.MoveMouseTo(Vector2.Zero)); - AddAssert("container still expanded", () => container.Expanded.Value); - - AddStep("release slider nub", () => InputManager.ReleaseButton(MouseButton.Left)); - AddAssert("container contracted", () => !container.Expanded.Value); - } - /// /// Tests expanding a container will expand underlying groups if contracted. /// @@ -157,21 +131,21 @@ namespace osu.Game.Tests.Visual.UserInterface } /// - /// Tests expanding a container via does not get contracted by losing hover. + /// Tests expanding a container via does not get contracted by losing hover. /// [Test] public void TestExpandingContainerDoesntGetContractedByHover() { AddStep("expand container", () => container.Expanded.Value = true); - AddStep("hover control", () => InputManager.MoveMouseTo(slider1)); + AddStep("hover container", () => InputManager.MoveMouseTo(container)); AddAssert("container still expanded", () => container.Expanded.Value); AddStep("hover away", () => InputManager.MoveMouseTo(Vector2.Zero)); AddAssert("container still expanded", () => container.Expanded.Value); } - private class TestExpandingContainer : ExpandingControlContainer + private class TestExpandingContainer : ExpandingContainer { public TestExpandingContainer() : base(120, 250) diff --git a/osu.Game/Overlays/ExpandableSlider.cs b/osu.Game/Overlays/ExpandableSlider.cs index d346b9b22c..062de98659 100644 --- a/osu.Game/Overlays/ExpandableSlider.cs +++ b/osu.Game/Overlays/ExpandableSlider.cs @@ -17,7 +17,7 @@ namespace osu.Game.Overlays /// /// An implementation for the UI slider bar control. /// - public class ExpandableSlider : CompositeDrawable, IExpandableControl, IHasCurrentValue + public class ExpandableSlider : CompositeDrawable, IExpandable, IHasCurrentValue where T : struct, IEquatable, IComparable, IConvertible where TSlider : OsuSliderBar, new() { @@ -72,8 +72,6 @@ namespace osu.Game.Overlays public BindableBool Expanded { get; } = new BindableBool(); - bool IExpandable.ShouldBeExpanded => IsHovered || slider.IsDragged; - public override bool HandlePositionalInput => true; public ExpandableSlider() diff --git a/osu.Game/Overlays/ExpandingButtonContainer.cs b/osu.Game/Overlays/ExpandingButtonContainer.cs index d7ff285707..8fb3e1b550 100644 --- a/osu.Game/Overlays/ExpandingButtonContainer.cs +++ b/osu.Game/Overlays/ExpandingButtonContainer.cs @@ -1,17 +1,15 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using osu.Game.Graphics.UserInterface; - namespace osu.Game.Overlays { /// - /// An with a long hover expansion delay for buttons. + /// An with a long hover expansion delay. /// /// /// Mostly used for buttons with explanatory labels, in which the label would display after a "long hover". /// - public class ExpandingButtonContainer : ExpandingControlContainer + public class ExpandingButtonContainer : ExpandingContainer { protected ExpandingButtonContainer(float contractedWidth, float expandedWidth) : base(contractedWidth, expandedWidth) diff --git a/osu.Game/Overlays/ExpandingControlContainer.cs b/osu.Game/Overlays/ExpandingContainer.cs similarity index 54% rename from osu.Game/Overlays/ExpandingControlContainer.cs rename to osu.Game/Overlays/ExpandingContainer.cs index 859e4bcd25..ea3fffcb78 100644 --- a/osu.Game/Overlays/ExpandingControlContainer.cs +++ b/osu.Game/Overlays/ExpandingContainer.cs @@ -1,23 +1,19 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Linq; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Input.Events; -using osu.Framework.Testing; using osu.Framework.Threading; using osu.Game.Graphics.Containers; namespace osu.Game.Overlays { /// - /// Represents a with the ability to expand/contract when hovering the controls within it. + /// Represents a with the ability to expand/contract on hover. /// - /// The type of UI control to lookup for hover expansion. - public class ExpandingControlContainer : Container, IExpandingContainer - where TControl : class, IDrawable + public class ExpandingContainer : Container, IExpandingContainer { private readonly float contractedWidth; private readonly float expandedWidth; @@ -33,7 +29,7 @@ namespace osu.Game.Overlays protected FillFlowContainer FillFlow { get; } - protected ExpandingControlContainer(float contractedWidth, float expandedWidth) + protected ExpandingContainer(float contractedWidth, float expandedWidth) { this.contractedWidth = contractedWidth; this.expandedWidth = expandedWidth; @@ -57,7 +53,6 @@ namespace osu.Game.Overlays } private ScheduledDelegate hoverExpandEvent; - private TControl activeControl; protected override void LoadComplete() { @@ -69,61 +64,38 @@ namespace osu.Game.Overlays }, true); } - protected override void Update() - { - base.Update(); - - // if the container was expanded from hovering over a control, we have to check per-frame whether we can contract it back. - // that's because contracting the container depends not only on whether it's no longer hovered, - // but also on whether the hovered control is no longer in a dragged state (if it was). - if (hoverExpandEvent != null && !IsHovered && (activeControl == null || !isControlActive(activeControl))) - { - hoverExpandEvent?.Cancel(); - - Expanded.Value = false; - hoverExpandEvent = null; - activeControl = null; - } - } - protected override bool OnHover(HoverEvent e) { - queueExpandIfHovering(); + updateHoverExpansion(); return true; } protected override bool OnMouseMove(MouseMoveEvent e) { - queueExpandIfHovering(); + updateHoverExpansion(); return base.OnMouseMove(e); } - private void queueExpandIfHovering() + protected override void OnHoverLost(HoverLostEvent e) { - // if the same control is hovered or dragged, let the scheduled expand play out.. - if (activeControl != null && isControlActive(activeControl)) + if (hoverExpandEvent != null) + { + hoverExpandEvent?.Cancel(); + hoverExpandEvent = null; + + Expanded.Value = false; return; + } - // ..otherwise check whether a new control is hovered, and if so, queue a new hover operation. - hoverExpandEvent?.Cancel(); - - // usually we wouldn't use ChildrenOfType in implementations, but this is the simplest way - // to handle cases like the editor where the controls may be nested within a child hierarchy. - activeControl = FillFlow.ChildrenOfType().FirstOrDefault(isControlActive); - - if (activeControl != null && !Expanded.Value) - hoverExpandEvent = Scheduler.AddDelayed(() => Expanded.Value = true, HoverExpansionDelay); + base.OnHoverLost(e); } - /// - /// Whether the given control is currently active, by checking whether it's hovered or dragged. - /// - private bool isControlActive(TControl control) + private void updateHoverExpansion() { - if (control is IExpandable expandable) - return expandable.ShouldBeExpanded; + hoverExpandEvent?.Cancel(); - return control.IsHovered || control.IsDragged; + if (IsHovered && !Expanded.Value) + hoverExpandEvent = Scheduler.AddDelayed(() => Expanded.Value = true, HoverExpansionDelay); } } } diff --git a/osu.Game/Overlays/IExpandable.cs b/osu.Game/Overlays/IExpandable.cs index f998fc7b9f..770ac97847 100644 --- a/osu.Game/Overlays/IExpandable.cs +++ b/osu.Game/Overlays/IExpandable.cs @@ -3,7 +3,6 @@ using osu.Framework.Bindables; using osu.Framework.Graphics; -using osu.Game.Graphics.UserInterface; namespace osu.Game.Overlays { @@ -16,15 +15,5 @@ namespace osu.Game.Overlays /// Whether this drawable is in an expanded state. /// BindableBool Expanded { get; } - - /// - /// Whether this drawable should be/stay expanded by a parenting . - /// By default, this is when this drawable is in a hovered or dragged state. - /// - /// - /// This is defined for certain controls which may have a child handling dragging instead. - /// (e.g. in which dragging is handled by their underlying control). - /// - bool ShouldBeExpanded => IsHovered || IsDragged; } } diff --git a/osu.Game/Overlays/IExpandableControl.cs b/osu.Game/Overlays/IExpandableControl.cs deleted file mode 100644 index 2cda6f467b..0000000000 --- a/osu.Game/Overlays/IExpandableControl.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -namespace osu.Game.Overlays -{ - /// - /// An interface for UI controls with the ability to expand/contract. - /// - public interface IExpandableControl : IExpandable - { - } -}