A game framework written with osu! in mind.
at master 63 lines 2.5 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using NUnit.Framework; 5using osu.Framework.Graphics; 6using osu.Framework.Graphics.Containers; 7using osu.Framework.Graphics.Shapes; 8using osuTK; 9 10namespace osu.Framework.Tests.Visual.Layout 11{ 12 [TestFixture] 13 public class TestSceneFitInsideFlow : FrameworkTestScene 14 { 15 private const float container_width = 60; 16 17 private Box fitBox; 18 19 [SetUp] 20 public void SetUp() => Schedule(() => 21 { 22 Child = new FillFlowContainer 23 { 24 Anchor = Anchor.Centre, 25 Origin = Anchor.Centre, 26 AutoSizeAxes = Axes.Y, 27 Width = container_width, 28 Direction = FillDirection.Vertical, 29 Children = new Drawable[] 30 { 31 fitBox = new Box 32 { 33 RelativeSizeAxes = Axes.Both, 34 FillMode = FillMode.Fit 35 }, 36 // A box which forces the minimum dimension of the autosize flow container to be the horizontal dimension 37 new Box { Size = new Vector2(container_width, container_width * 2) } 38 } 39 }; 40 }); 41 42 /// <summary> 43 /// Tests that using <see cref="FillMode.Fit"/> inside a <see cref="FlowContainer{T}"/> that is autosizing in one axis doesn't result in autosize feedback loops. 44 /// Various sizes of the box are tested to ensure that non-one sizes also don't lead to erroneous sizes. 45 /// </summary> 46 /// <param name="value">The relative size of the box that is fitting.</param> 47 [TestCase(0f)] 48 [TestCase(0.5f)] 49 [TestCase(1f)] 50 public void TestFitInsideFlow(float value) 51 { 52 AddStep("Set size", () => fitBox.Size = new Vector2(value)); 53 54 var expectedSize = new Vector2(container_width * value); 55 56 AddAssert("Check size before invalidate (1/2)", () => fitBox.DrawSize == expectedSize); 57 AddAssert("Check size before invalidate (2/2)", () => fitBox.DrawSize == expectedSize); 58 AddStep("Invalidate", () => fitBox.Invalidate()); 59 AddAssert("Check size after invalidate (1/2)", () => fitBox.DrawSize == expectedSize); 60 AddAssert("Check size after invalidate (2/2)", () => fitBox.DrawSize == expectedSize); 61 } 62 } 63}