2022-01-21 15:39:58 +00:00
// 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.Bindables ;
using osu.Framework.Graphics ;
2022-02-14 08:51:39 +00:00
using osu.Game.Graphics.Containers ;
using osu.Game.Graphics.UserInterface ;
2022-01-21 15:39:58 +00:00
using osu.Game.Overlays ;
using osu.Game.Overlays.Settings.Sections ;
using osuTK ;
namespace osu.Game.Tests.Visual.UserInterface
{
2022-02-04 02:45:12 +00:00
public class TestSceneExpandingContainer : OsuManualInputManagerTestScene
2022-01-21 15:39:58 +00:00
{
private TestExpandingContainer container ;
private SettingsToolboxGroup toolboxGroup ;
2022-01-26 07:18:17 +00:00
private ExpandableSlider < float , SizeSlider > slider1 ;
private ExpandableSlider < double > slider2 ;
2022-01-21 15:39:58 +00:00
[SetUp]
public void SetUp ( ) = > Schedule ( ( ) = >
{
Child = container = new TestExpandingContainer
{
Anchor = Anchor . Centre ,
Origin = Anchor . Centre ,
Height = 0.33f ,
Child = toolboxGroup = new SettingsToolboxGroup ( "sliders" )
{
RelativeSizeAxes = Axes . X ,
Width = 1 ,
Children = new Drawable [ ]
{
2022-01-26 07:18:17 +00:00
slider1 = new ExpandableSlider < float , SizeSlider >
2022-01-21 15:39:58 +00:00
{
Current = new BindableFloat
{
Default = 1.0f ,
MinValue = 1.0f ,
MaxValue = 10.0f ,
Precision = 0.01f ,
} ,
} ,
2022-01-26 07:18:17 +00:00
slider2 = new ExpandableSlider < double >
2022-01-21 15:39:58 +00:00
{
Current = new BindableDouble
{
Default = 1.0 ,
MinValue = 1.0 ,
MaxValue = 10.0 ,
Precision = 0.01 ,
} ,
} ,
}
}
} ;
slider1 . Current . BindValueChanged ( v = >
{
2022-01-26 07:18:17 +00:00
slider1 . ExpandedLabelText = $"Slider One ({v.NewValue:0.##x})" ;
2022-01-21 15:39:58 +00:00
slider1 . ContractedLabelText = $"S. 1. ({v.NewValue:0.##x})" ;
} , true ) ;
slider2 . Current . BindValueChanged ( v = >
{
2022-01-26 07:18:17 +00:00
slider2 . ExpandedLabelText = $"Slider Two ({v.NewValue:N2})" ;
2022-01-21 15:39:58 +00:00
slider2 . ContractedLabelText = $"S. 2. ({v.NewValue:N2})" ;
} , true ) ;
} ) ;
[Test]
public void TestDisplay ( )
{
AddStep ( "switch to contracted" , ( ) = > container . Expanded . Value = false ) ;
AddStep ( "switch to expanded" , ( ) = > container . Expanded . Value = true ) ;
AddStep ( "set left origin" , ( ) = > container . Origin = Anchor . CentreLeft ) ;
AddStep ( "set centre origin" , ( ) = > container . Origin = Anchor . Centre ) ;
AddStep ( "set right origin" , ( ) = > container . Origin = Anchor . CentreRight ) ;
}
/// <summary>
2022-02-04 02:45:12 +00:00
/// Tests hovering expands the container and does not contract until hover is lost.
2022-01-21 15:39:58 +00:00
/// </summary>
[Test]
2022-02-04 02:45:12 +00:00
public void TestHoveringExpandsContainer ( )
2022-01-21 15:39:58 +00:00
{
AddAssert ( "ensure container contracted" , ( ) = > ! container . Expanded . Value ) ;
2022-02-04 02:45:12 +00:00
AddStep ( "hover container" , ( ) = > InputManager . MoveMouseTo ( container ) ) ;
2022-01-21 15:39:58 +00:00
AddAssert ( "container expanded" , ( ) = > container . Expanded . Value ) ;
AddAssert ( "controls expanded" , ( ) = > slider1 . Expanded . Value & & slider2 . Expanded . Value ) ;
AddStep ( "hover away" , ( ) = > InputManager . MoveMouseTo ( Vector2 . Zero ) ) ;
AddAssert ( "container contracted" , ( ) = > ! container . Expanded . Value ) ;
AddAssert ( "controls contracted" , ( ) = > ! slider1 . Expanded . Value & & ! slider2 . Expanded . Value ) ;
}
/// <summary>
/// Tests expanding a container will expand underlying groups if contracted.
/// </summary>
[Test]
public void TestExpandingContainerExpandsContractedGroup ( )
{
AddStep ( "contract group" , ( ) = > toolboxGroup . Expanded . Value = false ) ;
AddStep ( "expand container" , ( ) = > container . Expanded . Value = true ) ;
AddAssert ( "group expanded" , ( ) = > toolboxGroup . Expanded . Value ) ;
AddAssert ( "controls expanded" , ( ) = > slider1 . Expanded . Value & & slider2 . Expanded . Value ) ;
AddStep ( "contract container" , ( ) = > container . Expanded . Value = false ) ;
AddAssert ( "group contracted" , ( ) = > ! toolboxGroup . Expanded . Value ) ;
AddAssert ( "controls contracted" , ( ) = > ! slider1 . Expanded . Value & & ! slider2 . Expanded . Value ) ;
}
/// <summary>
/// Tests contracting a container does not contract underlying groups if expanded by user (i.e. by setting <see cref="SettingsToolboxGroup.Expanded"/> directly).
/// </summary>
[Test]
public void TestContractingContainerDoesntContractUserExpandedGroup ( )
{
AddAssert ( "ensure group expanded" , ( ) = > toolboxGroup . Expanded . Value ) ;
AddStep ( "expand container" , ( ) = > container . Expanded . Value = true ) ;
AddAssert ( "group still expanded" , ( ) = > toolboxGroup . Expanded . Value ) ;
AddAssert ( "controls expanded" , ( ) = > slider1 . Expanded . Value & & slider2 . Expanded . Value ) ;
AddStep ( "contract container" , ( ) = > container . Expanded . Value = false ) ;
AddAssert ( "group still expanded" , ( ) = > toolboxGroup . Expanded . Value ) ;
AddAssert ( "controls contracted" , ( ) = > ! slider1 . Expanded . Value & & ! slider2 . Expanded . Value ) ;
}
/// <summary>
2022-02-04 02:45:12 +00:00
/// Tests expanding a container via <see cref="ExpandingContainer.Expanded"/> does not get contracted by losing hover.
2022-01-21 15:39:58 +00:00
/// </summary>
[Test]
public void TestExpandingContainerDoesntGetContractedByHover ( )
{
AddStep ( "expand container" , ( ) = > container . Expanded . Value = true ) ;
2022-02-04 02:45:12 +00:00
AddStep ( "hover container" , ( ) = > InputManager . MoveMouseTo ( container ) ) ;
2022-01-21 15:39:58 +00:00
AddAssert ( "container still expanded" , ( ) = > container . Expanded . Value ) ;
AddStep ( "hover away" , ( ) = > InputManager . MoveMouseTo ( Vector2 . Zero ) ) ;
AddAssert ( "container still expanded" , ( ) = > container . Expanded . Value ) ;
}
2022-02-04 02:45:12 +00:00
private class TestExpandingContainer : ExpandingContainer
2022-01-21 15:39:58 +00:00
{
public TestExpandingContainer ( )
: base ( 120 , 250 )
{
}
}
}
}