mirror of
https://github.com/osukey/osukey.git
synced 2025-05-07 22:57:31 +09:00
Merge pull request #19345 from frenzibyte/fix-slider-bar-crash
Fix `OsuSliderBar` throwing on negative draw width
This commit is contained in:
commit
08024e70eb
@ -8,8 +8,10 @@ using System.Linq;
|
|||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Graphics.UserInterfaceV2;
|
using osu.Game.Graphics.UserInterfaceV2;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
|
|
||||||
@ -17,11 +19,26 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
{
|
{
|
||||||
public class TestSceneLabelledSliderBar : OsuTestScene
|
public class TestSceneLabelledSliderBar : OsuTestScene
|
||||||
{
|
{
|
||||||
[TestCase(false)]
|
[Test]
|
||||||
[TestCase(true)]
|
public void TestBasic() => createSliderBar();
|
||||||
public void TestSliderBar(bool hasDescription) => createSliderBar(hasDescription);
|
|
||||||
|
|
||||||
private void createSliderBar(bool hasDescription = false)
|
[Test]
|
||||||
|
public void TestDescription()
|
||||||
|
{
|
||||||
|
createSliderBar();
|
||||||
|
AddStep("set description", () => this.ChildrenOfType<LabelledSliderBar<double>>().ForEach(l => l.Description = "this text describes the component"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestSize()
|
||||||
|
{
|
||||||
|
createSliderBar();
|
||||||
|
AddStep("set zero width", () => this.ChildrenOfType<LabelledSliderBar<double>>().ForEach(l => l.ResizeWidthTo(0, 200, Easing.OutQuint)));
|
||||||
|
AddStep("set negative width", () => this.ChildrenOfType<LabelledSliderBar<double>>().ForEach(l => l.ResizeWidthTo(-1, 200, Easing.OutQuint)));
|
||||||
|
AddStep("revert back", () => this.ChildrenOfType<LabelledSliderBar<double>>().ForEach(l => l.ResizeWidthTo(1, 200, Easing.OutQuint)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createSliderBar()
|
||||||
{
|
{
|
||||||
AddStep("create component", () =>
|
AddStep("create component", () =>
|
||||||
{
|
{
|
||||||
@ -38,6 +55,8 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
{
|
{
|
||||||
new LabelledSliderBar<double>
|
new LabelledSliderBar<double>
|
||||||
{
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
Current = new BindableDouble(5)
|
Current = new BindableDouble(5)
|
||||||
{
|
{
|
||||||
MinValue = 0,
|
MinValue = 0,
|
||||||
@ -45,7 +64,6 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
Precision = 1,
|
Precision = 1,
|
||||||
},
|
},
|
||||||
Label = "a sample component",
|
Label = "a sample component",
|
||||||
Description = hasDescription ? "this text describes the component" : string.Empty,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -54,10 +72,14 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
{
|
{
|
||||||
flow.Add(new OverlayColourContainer(colour)
|
flow.Add(new OverlayColourContainer(colour)
|
||||||
{
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
Child = new LabelledSliderBar<double>
|
Child = new LabelledSliderBar<double>
|
||||||
{
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
Current = new BindableDouble(5)
|
Current = new BindableDouble(5)
|
||||||
{
|
{
|
||||||
MinValue = 0,
|
MinValue = 0,
|
||||||
@ -65,7 +87,6 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
Precision = 1,
|
Precision = 1,
|
||||||
},
|
},
|
||||||
Label = "a sample component",
|
Label = "a sample component",
|
||||||
Description = hasDescription ? "this text describes the component" : string.Empty,
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -228,10 +228,8 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
protected override void UpdateAfterChildren()
|
protected override void UpdateAfterChildren()
|
||||||
{
|
{
|
||||||
base.UpdateAfterChildren();
|
base.UpdateAfterChildren();
|
||||||
LeftBox.Scale = new Vector2(Math.Clamp(
|
LeftBox.Scale = new Vector2(Math.Clamp(RangePadding + Nub.DrawPosition.X - Nub.DrawWidth / 2, 0, Math.Max(0, DrawWidth)), 1);
|
||||||
RangePadding + Nub.DrawPosition.X - Nub.DrawWidth / 2, 0, DrawWidth), 1);
|
RightBox.Scale = new Vector2(Math.Clamp(DrawWidth - Nub.DrawPosition.X - RangePadding - Nub.DrawWidth / 2, 0, Math.Max(0, DrawWidth)), 1);
|
||||||
RightBox.Scale = new Vector2(Math.Clamp(
|
|
||||||
DrawWidth - Nub.DrawPosition.X - RangePadding - Nub.DrawWidth / 2, 0, DrawWidth), 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateValue(float value)
|
protected override void UpdateValue(float value)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user