Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion osu.Game.Tests/Visual/UserInterface/TestSceneFormSliderBar.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. 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);
Expand Down Expand Up @@ -59,5 +63,49 @@ public void TestTransferValueOnCommit()
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);
}
}
}
39 changes: 31 additions & 8 deletions osu.Game/Graphics/UserInterfaceV2/FormSliderBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ private partial class InnerSlider : OsuSliderBar<T>

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!;
Expand All @@ -335,7 +335,7 @@ private void load()
{
Height = 40;
RelativeSizeAxes = Axes.X;
RangePadding = nub_width / 2;
RangePadding = NUB_WIDTH / 2;

Children = new Drawable[]
{
Expand Down Expand Up @@ -364,12 +364,13 @@ private void load()
{
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()
Expand Down Expand Up @@ -452,5 +453,27 @@ protected override bool Commit()
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;
}
}
}
}
Loading