mirror of
https://github.com/ppy/osu.git
synced 2024-11-15 17:57:29 +08:00
86c3e3e987
Rather than control the propagation of the value between the slider and the textbox, add a property that controls the propagation of the value between the bindables inside the form control to external bindables. This will help alleviate issues where the external bindable update incurs overheads due to having heavy change callbacks attached.
64 lines
2.2 KiB
C#
64 lines
2.2 KiB
C#
// 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 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.Game.Graphics.Sprites;
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
|
using osu.Game.Overlays;
|
|
using osuTK;
|
|
|
|
namespace osu.Game.Tests.Visual.UserInterface
|
|
{
|
|
public partial class TestSceneFormSliderBar : OsuTestScene
|
|
{
|
|
[Cached]
|
|
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Aquamarine);
|
|
|
|
[Test]
|
|
public void TestTransferValueOnCommit()
|
|
{
|
|
OsuSpriteText text;
|
|
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[]
|
|
{
|
|
text = new OsuSpriteText(),
|
|
slider = new FormSliderBar<float>
|
|
{
|
|
Caption = "Slider",
|
|
Current = new BindableFloat
|
|
{
|
|
MinValue = 0,
|
|
MaxValue = 10,
|
|
Precision = 0.1f,
|
|
Default = 5f,
|
|
}
|
|
},
|
|
}
|
|
};
|
|
slider.Current.BindValueChanged(_ => text.Text = $"Current value is: {slider.Current.Value}", true);
|
|
});
|
|
AddToggleStep("toggle transfer value on commit", b =>
|
|
{
|
|
if (slider.IsNotNull())
|
|
slider.TransferValueOnCommit = b;
|
|
});
|
|
}
|
|
}
|
|
}
|