// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osuTK; namespace osu.Framework.Tests.Visual.Layout { [TestFixture] public class TestSceneFitInsideFlow : FrameworkTestScene { private const float container_width = 60; private Box fitBox; [SetUp] public void SetUp() => Schedule(() => { Child = new FillFlowContainer { Anchor = Anchor.Centre, Origin = Anchor.Centre, AutoSizeAxes = Axes.Y, Width = container_width, Direction = FillDirection.Vertical, Children = new Drawable[] { fitBox = new Box { RelativeSizeAxes = Axes.Both, FillMode = FillMode.Fit }, // A box which forces the minimum dimension of the autosize flow container to be the horizontal dimension new Box { Size = new Vector2(container_width, container_width * 2) } } }; }); /// /// Tests that using inside a that is autosizing in one axis doesn't result in autosize feedback loops. /// Various sizes of the box are tested to ensure that non-one sizes also don't lead to erroneous sizes. /// /// The relative size of the box that is fitting. [TestCase(0f)] [TestCase(0.5f)] [TestCase(1f)] public void TestFitInsideFlow(float value) { AddStep("Set size", () => fitBox.Size = new Vector2(value)); var expectedSize = new Vector2(container_width * value); AddAssert("Check size before invalidate (1/2)", () => fitBox.DrawSize == expectedSize); AddAssert("Check size before invalidate (2/2)", () => fitBox.DrawSize == expectedSize); AddStep("Invalidate", () => fitBox.Invalidate()); AddAssert("Check size after invalidate (1/2)", () => fitBox.DrawSize == expectedSize); AddAssert("Check size after invalidate (2/2)", () => fitBox.DrawSize == expectedSize); } } }