// Copyright (c) ppy Pty Ltd . 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.Bindables; using osu.Framework.Graphics; using osu.Framework.Testing; using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterfaceV2; using osuTK.Input; namespace osu.Game.Tests.Visual.UserInterface { public partial class TestSceneSliderWithTextBoxInput : OsuManualInputManagerTestScene { private SliderWithTextBoxInput sliderWithTextBoxInput = null!; private OsuSliderBar slider => sliderWithTextBoxInput.ChildrenOfType>().Single(); private Nub nub => sliderWithTextBoxInput.ChildrenOfType().Single(); private OsuTextBox textBox => sliderWithTextBoxInput.ChildrenOfType().Single(); [SetUpSteps] public void SetUpSteps() { AddStep("create slider", () => Child = sliderWithTextBoxInput = new SliderWithTextBoxInput("Test Slider") { Anchor = Anchor.Centre, Origin = Anchor.Centre, Width = 0.5f, Current = new BindableFloat { MinValue = -5, MaxValue = 5, Precision = 0.2f } }); } [Test] public void TestNonInstantaneousMode() { AddStep("focus textbox", () => InputManager.ChangeFocus(textBox)); AddStep("change text", () => textBox.Text = "3"); AddAssert("slider not moved", () => slider.Current.Value, () => Is.Zero); AddAssert("current not changed", () => sliderWithTextBoxInput.Current.Value, () => Is.Zero); AddStep("commit text", () => InputManager.Key(Key.Enter)); AddAssert("slider moved", () => slider.Current.Value, () => Is.EqualTo(3)); AddAssert("current changed", () => sliderWithTextBoxInput.Current.Value, () => Is.EqualTo(3)); AddStep("move mouse to nub", () => InputManager.MoveMouseTo(nub)); AddStep("hold left mouse", () => InputManager.PressButton(MouseButton.Left)); AddStep("move mouse to minimum", () => InputManager.MoveMouseTo(sliderWithTextBoxInput.ScreenSpaceDrawQuad.BottomLeft)); AddAssert("textbox not changed", () => textBox.Current.Value, () => Is.EqualTo("3")); AddAssert("current not changed", () => sliderWithTextBoxInput.Current.Value, () => Is.EqualTo(3)); AddStep("release left mouse", () => InputManager.ReleaseButton(MouseButton.Left)); AddAssert("textbox changed", () => textBox.Current.Value, () => Is.EqualTo("-5")); AddAssert("current changed", () => sliderWithTextBoxInput.Current.Value, () => Is.EqualTo(-5)); } } }