1
0
mirror of https://github.com/ppy/osu.git synced 2026-06-02 23:41:00 +08:00

Merge pull request #35783 from bdach/form-slider-bar-double-click-to-reset

Add double-click-nub-to-reset function to form slider bars
This commit is contained in:
Dean Herbert
2025-11-24 19:54:33 +09:00
committed by GitHub
Unverified
2 changed files with 80 additions and 9 deletions
@@ -1,20 +1,24 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Testing;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Overlays;
using osuTK;
using osuTK.Input;
namespace osu.Game.Tests.Visual.UserInterface
{
public partial class TestSceneFormSliderBar : OsuTestScene
public partial class TestSceneFormSliderBar : OsuManualInputManagerTestScene
{
[Cached]
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Aquamarine);
@@ -59,5 +63,49 @@ namespace osu.Game.Tests.Visual.UserInterface
slider.TransferValueOnCommit = b;
});
}
[Test]
public void TestNubDoubleClickRevertToDefault()
{
FormSliderBar<float> slider = null!;
AddStep("create content", () =>
{
Child = new FillFlowContainer
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Width = 0.5f,
Direction = FillDirection.Vertical,
Spacing = new Vector2(10),
Children = new Drawable[]
{
slider = new FormSliderBar<float>
{
Caption = "Slider",
Current = new BindableFloat
{
MinValue = 0,
MaxValue = 10,
Precision = 0.1f,
Default = 5f,
}
},
}
};
});
AddStep("set slider to 1", () => slider.Current.Value = 1);
AddStep("move mouse to nub", () => InputManager.MoveMouseTo(slider.ChildrenOfType<Circle>().Single()));
AddStep("double click nub", () =>
{
InputManager.Click(MouseButton.Left);
InputManager.Click(MouseButton.Left);
});
AddAssert("slider is default", () => slider.Current.IsDefault);
}
}
}
@@ -324,8 +324,8 @@ namespace osu.Game.Graphics.UserInterfaceV2
private Box leftBox = null!;
private Box rightBox = null!;
private Circle nub = null!;
private const float nub_width = 10;
private InnerSliderNub nub = null!;
public const float NUB_WIDTH = 10;
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;
@@ -335,7 +335,7 @@ namespace osu.Game.Graphics.UserInterfaceV2
{
Height = 40;
RelativeSizeAxes = Axes.X;
RangePadding = nub_width / 2;
RangePadding = NUB_WIDTH / 2;
Children = new Drawable[]
{
@@ -364,12 +364,13 @@ namespace osu.Game.Graphics.UserInterfaceV2
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Horizontal = RangePadding, },
Child = nub = new Circle
Child = nub = new InnerSliderNub
{
Width = nub_width,
RelativeSizeAxes = Axes.Y,
RelativePositionAxes = Axes.X,
Origin = Anchor.TopCentre,
ResetToDefault = () =>
{
if (!Current.Disabled)
Current.SetDefault();
}
}
},
new HoverClickSounds()
@@ -452,5 +453,27 @@ namespace osu.Game.Graphics.UserInterfaceV2
return result;
}
}
private partial class InnerSliderNub : Circle
{
public Action? ResetToDefault { get; set; }
[BackgroundDependencyLoader]
private void load()
{
Width = InnerSlider.NUB_WIDTH;
RelativeSizeAxes = Axes.Y;
RelativePositionAxes = Axes.X;
Origin = Anchor.TopCentre;
}
protected override bool OnClick(ClickEvent e) => true; // must be handled for double click handler to ever fire
protected override bool OnDoubleClick(DoubleClickEvent e)
{
ResetToDefault?.Invoke();
return true;
}
}
}
}