1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-27 07:53:06 +08:00
osu-lazer/osu.Game.Tests/Visual/UserInterface/TestSceneLabelledDrawable.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

137 lines
4.7 KiB
C#
Raw Normal View History

2019-09-20 17:35:15 +08: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.
2022-06-17 15:37:17 +08:00
#nullable disable
using System.Linq;
2019-09-20 17:35:15 +08:00
using NUnit.Framework;
using osu.Framework.Extensions.IEnumerableExtensions;
2019-09-20 17:35:15 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Testing;
2019-09-20 17:35:15 +08:00
using osu.Game.Graphics.Sprites;
2019-09-24 18:00:26 +08:00
using osu.Game.Graphics.UserInterfaceV2;
using osuTK;
2019-09-20 17:35:15 +08:00
using osuTK.Graphics;
namespace osu.Game.Tests.Visual.UserInterface
{
public class TestSceneLabelledDrawable : OsuTestScene
2019-09-20 17:35:15 +08:00
{
[TestCase(false)]
[TestCase(true)]
public void TestPadded(bool hasDescription) => createPaddedComponent(hasDescription);
[TestCase(false)]
[TestCase(true)]
public void TestNonPadded(bool hasDescription) => createPaddedComponent(hasDescription, false);
[Test]
public void TestFixedWidth()
{
const float label_width = 200;
AddStep("create components", () => Child = new FillFlowContainer
{
RelativeSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 10),
Children = new Drawable[]
{
new NonPaddedLabelledDrawable
{
Label = "short",
FixedLabelWidth = label_width
},
new NonPaddedLabelledDrawable
{
Label = "very very very very very very very very very very very long",
FixedLabelWidth = label_width
},
new PaddedLabelledDrawable
{
Label = "short",
FixedLabelWidth = label_width
},
new PaddedLabelledDrawable
{
Label = "very very very very very very very very very very very long",
FixedLabelWidth = label_width
}
}
});
AddStep("unset label width", () => this.ChildrenOfType<LabelledDrawable<Drawable>>().ForEach(d => d.FixedLabelWidth = null));
AddStep("reset label width", () => this.ChildrenOfType<LabelledDrawable<Drawable>>().ForEach(d => d.FixedLabelWidth = label_width));
}
2019-09-20 17:35:15 +08:00
private void createPaddedComponent(bool hasDescription = false, bool padded = true)
{
LabelledDrawable<Drawable> component = null;
2019-09-20 17:35:15 +08:00
AddStep("create component", () =>
{
Child = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Width = 500,
AutoSizeAxes = Axes.Y,
2022-06-24 13:48:43 +08:00
Child = component = padded ? new PaddedLabelledDrawable() : new NonPaddedLabelledDrawable(),
2019-09-20 17:35:15 +08:00
};
component.Label = "a sample component";
component.Description = hasDescription ? "this text describes the component" : string.Empty;
});
AddAssert($"description {(hasDescription ? "visible" : "hidden")}", () => component.ChildrenOfType<TextFlowContainer>().ElementAt(1).IsPresent == hasDescription);
2019-09-20 17:35:15 +08:00
}
private class PaddedLabelledDrawable : LabelledDrawable<Drawable>
2019-09-20 17:35:15 +08:00
{
public PaddedLabelledDrawable()
2019-09-20 17:35:15 +08:00
: base(true)
{
}
protected override Drawable CreateComponent() => new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Colour = Color4.Red,
Text = @"(( Component ))"
};
}
private class NonPaddedLabelledDrawable : LabelledDrawable<Drawable>
2019-09-20 17:35:15 +08:00
{
public NonPaddedLabelledDrawable()
2019-09-20 17:35:15 +08:00
: base(false)
{
}
protected override Drawable CreateComponent() => new Container
{
RelativeSizeAxes = Axes.X,
Height = 40,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.SlateGray
},
new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Colour = Color4.Red,
Text = @"(( Component ))"
}
}
};
}
}
}