A game framework written with osu! in mind.
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 System;
5using NUnit.Framework;
6using osu.Framework.Graphics;
7using osu.Framework.Graphics.Containers;
8using osu.Framework.Graphics.Shapes;
9using osuTK;
10
11namespace osu.Framework.Tests.Visual.Containers
12{
13 public class TestSceneCircularContainerSizing : FrameworkTestScene
14 {
15 [Test]
16 public void TestLateSizing() => Schedule(() =>
17 {
18 HookedContainer container;
19 CircularContainer circular;
20
21 Child = container = new HookedContainer
22 {
23 Anchor = Anchor.Centre,
24 Origin = Anchor.Centre,
25 Child = circular = new CircularContainer
26 {
27 RelativeSizeAxes = Axes.Both,
28 Masking = true,
29 Child = new Box { RelativeSizeAxes = Axes.Both }
30 }
31 };
32
33 container.OnUpdate = () => onUpdate(container);
34 container.OnUpdateAfterChildren = () => onUpdateAfterChildren(container, circular);
35
36 bool hasCorrectCornerRadius = false;
37
38 AddAssert("has correct corner radius", () => hasCorrectCornerRadius);
39
40 static void onUpdate(Container parent)
41 {
42 // Suppose the parent has some arbitrary size prior to the child being updated...
43 parent.Size = Vector2.One;
44 }
45
46 void onUpdateAfterChildren(Container parent, CircularContainer nested)
47 {
48 // ... and the size of the parent is changed to the desired value after the child has been updated
49 // This could happen just by ordering of events in the hierarchy, regardless of auto or relative size
50 parent.Size = new Vector2(200);
51 hasCorrectCornerRadius = nested.CornerRadius == 100;
52 }
53 });
54
55 private class HookedContainer : Container
56 {
57 public new Action OnUpdate;
58 public Action OnUpdateAfterChildren;
59
60 protected override void Update()
61 {
62 base.Update();
63 OnUpdate?.Invoke();
64 }
65
66 protected override void UpdateAfterChildren()
67 {
68 OnUpdateAfterChildren?.Invoke();
69 base.UpdateAfterChildren();
70 }
71 }
72 }
73}