Merge pull request #25230 from bdach/double-click-disabled-slider

Do not revert to default value when double-clicking disabled slider
This commit is contained in:
Salman Ahmed 2023-10-26 17:43:47 +03:00 committed by GitHub
commit 3930e41759
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 26 deletions

View File

@ -18,26 +18,24 @@ namespace osu.Game.Tests.Visual.UserInterface
[Cached] [Cached]
private OverlayColourProvider colourProvider { get; set; } = new OverlayColourProvider(OverlayColourScheme.Purple); private OverlayColourProvider colourProvider { get; set; } = new OverlayColourProvider(OverlayColourScheme.Purple);
private readonly BindableDouble current = new BindableDouble(5)
{
Precision = 0.1f,
MinValue = 0,
MaxValue = 15
};
private RoundedSliderBar<double> slider = null!; private RoundedSliderBar<double> slider = null!;
[BackgroundDependencyLoader] [SetUpSteps]
private void load() public void SetUpSteps()
{ {
Child = slider = new RoundedSliderBar<double> AddStep("create slider", () => Child = slider = new RoundedSliderBar<double>
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Current = current, Current = new BindableDouble(5)
{
Precision = 0.1,
MinValue = 0,
MaxValue = 15
},
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Width = 0.4f Width = 0.4f
}; });
} }
[Test] [Test]
@ -55,5 +53,22 @@ namespace osu.Game.Tests.Visual.UserInterface
AddAssert("slider is default", () => slider.Current.IsDefault); AddAssert("slider is default", () => slider.Current.IsDefault);
} }
[Test]
public void TestNubDoubleClickOnDisabledSliderDoesNothing()
{
AddStep("set slider to 1", () => slider.Current.Value = 1);
AddStep("disable slider", () => slider.Current.Disabled = true);
AddStep("move mouse to nub", () => InputManager.MoveMouseTo(slider.ChildrenOfType<Nub>().Single()));
AddStep("double click nub", () =>
{
InputManager.Click(MouseButton.Left);
InputManager.Click(MouseButton.Left);
});
AddAssert("slider is still at 1", () => slider.Current.Value, () => Is.EqualTo(1));
}
} }
} }

View File

@ -18,26 +18,24 @@ namespace osu.Game.Tests.Visual.UserInterface
[Cached] [Cached]
private OverlayColourProvider colourProvider { get; set; } = new OverlayColourProvider(OverlayColourScheme.Purple); private OverlayColourProvider colourProvider { get; set; } = new OverlayColourProvider(OverlayColourScheme.Purple);
private readonly BindableDouble current = new BindableDouble(5)
{
Precision = 0.1f,
MinValue = 0,
MaxValue = 15
};
private ShearedSliderBar<double> slider = null!; private ShearedSliderBar<double> slider = null!;
[BackgroundDependencyLoader] [SetUpSteps]
private void load() public void SetUpSteps()
{ {
Child = slider = new ShearedSliderBar<double> AddStep("create slider", () => Child = slider = new ShearedSliderBar<double>
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Current = current, Current = new BindableDouble(5)
{
Precision = 0.1,
MinValue = 0,
MaxValue = 15
},
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Width = 0.4f Width = 0.4f
}; });
} }
[Test] [Test]
@ -55,5 +53,22 @@ namespace osu.Game.Tests.Visual.UserInterface
AddAssert("slider is default", () => slider.Current.IsDefault); AddAssert("slider is default", () => slider.Current.IsDefault);
} }
[Test]
public void TestNubDoubleClickOnDisabledSliderDoesNothing()
{
AddStep("set slider to 1", () => slider.Current.Value = 1);
AddStep("disable slider", () => slider.Current.Disabled = true);
AddStep("move mouse to nub", () => InputManager.MoveMouseTo(slider.ChildrenOfType<ShearedNub>().Single()));
AddStep("double click nub", () =>
{
InputManager.Click(MouseButton.Left);
InputManager.Click(MouseButton.Left);
});
AddAssert("slider is still at 1", () => slider.Current.Value, () => Is.EqualTo(1));
}
} }
} }

View File

@ -98,7 +98,11 @@ namespace osu.Game.Graphics.UserInterface
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
RelativePositionAxes = Axes.X, RelativePositionAxes = Axes.X,
Current = { Value = true }, Current = { Value = true },
OnDoubleClicked = () => Current.SetDefault(), OnDoubleClicked = () =>
{
if (!Current.Disabled)
Current.SetDefault();
},
}, },
}, },
hoverClickSounds = new HoverClickSounds() hoverClickSounds = new HoverClickSounds()

View File

@ -101,7 +101,11 @@ namespace osu.Game.Graphics.UserInterface
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
RelativePositionAxes = Axes.X, RelativePositionAxes = Axes.X,
Current = { Value = true }, Current = { Value = true },
OnDoubleClicked = () => Current.SetDefault(), OnDoubleClicked = () =>
{
if (!Current.Disabled)
Current.SetDefault();
},
}, },
}, },
hoverClickSounds = new HoverClickSounds() hoverClickSounds = new HoverClickSounds()