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 osu.Framework.Graphics;
5using osu.Framework.Graphics.Containers;
6using osu.Framework.Graphics.Shapes;
7using osu.Framework.Utils;
8using osuTK;
9using osuTK.Graphics;
10
11namespace osu.Framework.Tests.Visual.Layout
12{
13 public class TestSceneScrollableFlow : FrameworkTestScene
14 {
15 private ScrollContainer<Drawable> scroll;
16 private FillFlowContainer flow;
17
18 private void createArea(Direction dir)
19 {
20 Axes scrollAxis = dir == Direction.Horizontal ? Axes.X : Axes.Y;
21
22 Children = new[]
23 {
24 scroll = new BasicScrollContainer(dir)
25 {
26 RelativeSizeAxes = Axes.Both,
27 Children = new[]
28 {
29 flow = new FillFlowContainer
30 {
31 LayoutDuration = 100,
32 LayoutEasing = Easing.Out,
33 Spacing = new Vector2(1, 1),
34 RelativeSizeAxes = Axes.Both & ~scrollAxis,
35 AutoSizeAxes = scrollAxis,
36 Padding = new MarginPadding(5)
37 }
38 },
39 },
40 };
41 }
42
43 private void createAreaBoth()
44 {
45 Children = new[]
46 {
47 new BasicScrollContainer(Direction.Horizontal)
48 {
49 RelativeSizeAxes = Axes.Both,
50 Padding = new MarginPadding { Left = 150 },
51 Children = new[]
52 {
53 scroll = new BasicScrollContainer
54 {
55 RelativeSizeAxes = Axes.Y,
56 AutoSizeAxes = Axes.X,
57 Children = new[]
58 {
59 flow = new FillFlowContainer
60 {
61 LayoutDuration = 100,
62 LayoutEasing = Easing.Out,
63 Spacing = new Vector2(1, 1),
64 Size = new Vector2(1000, 0),
65 AutoSizeAxes = Axes.Y,
66 Padding = new MarginPadding(5)
67 }
68 }
69 }
70 },
71 },
72 };
73
74 scroll.ScrollContent.AutoSizeAxes = Axes.None;
75 scroll.ScrollContent.RelativeSizeAxes = Axes.None;
76 scroll.ScrollContent.AutoSizeAxes = Axes.Both;
77 }
78
79 public TestSceneScrollableFlow()
80 {
81 Direction scrollDir;
82
83 createArea(scrollDir = Direction.Vertical);
84
85 AddStep("Vertical", delegate { createArea(scrollDir = Direction.Vertical); });
86 AddStep("Horizontal", delegate { createArea(scrollDir = Direction.Horizontal); });
87 AddStep("Both", createAreaBoth);
88
89 AddStep("Dragger Anchor 1", delegate { scroll.ScrollbarAnchor = scrollDir == Direction.Vertical ? Anchor.TopRight : Anchor.BottomLeft; });
90 AddStep("Dragger Anchor 2", delegate { scroll.ScrollbarAnchor = Anchor.TopLeft; });
91
92 AddStep("Dragger Visible", delegate { scroll.ScrollbarVisible = !scroll.ScrollbarVisible; });
93 AddStep("Dragger Overlap", delegate { scroll.ScrollbarOverlapsContent = !scroll.ScrollbarOverlapsContent; });
94
95 Scheduler.AddDelayed(delegate
96 {
97 if (Parent == null) return;
98
99 Box box;
100 Container container = new Container
101 {
102 Size = new Vector2(80, 80),
103 Children = new[]
104 {
105 box = new Box
106 {
107 RelativeSizeAxes = Axes.Both,
108 Anchor = Anchor.Centre,
109 Origin = Anchor.Centre,
110 Colour = new Color4(RNG.NextSingle(), RNG.NextSingle(), RNG.NextSingle(), 1)
111 }
112 }
113 };
114
115 flow.Add(container);
116
117 container.FadeInFromZero(1000);
118
119 double displayTime = RNG.Next(0, 20000);
120 box.Delay(displayTime).ScaleTo(0.5f, 4000).RotateTo((RNG.NextSingle() - 0.5f) * 90, 4000);
121 container.Delay(displayTime).FadeOut(4000).Expire();
122 }, 100, true);
123 }
124 }
125}