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 osu.Framework.Graphics;
6using osu.Framework.Graphics.Containers;
7using System.Collections.Generic;
8using System.Linq;
9using osu.Framework.Extensions.IEnumerableExtensions;
10
11namespace osu.Framework.Testing.Drawables
12{
13 internal class TestGroupButton : VisibilityContainer, IHasFilterableChildren
14 {
15 public IEnumerable<string> FilterTerms => headerButton?.FilterTerms ?? Enumerable.Empty<string>();
16
17 public bool MatchingFilter
18 {
19 set => Alpha = value ? 1 : 0;
20 }
21
22 public bool FilteringActive { get; set; }
23
24 public IEnumerable<IFilterable> FilterableChildren => buttonFlow.Children;
25
26 private readonly FillFlowContainer<TestButtonBase> buttonFlow;
27 private readonly TestButton headerButton;
28
29 public readonly TestGroup Group;
30
31 public Type Current
32 {
33 set
34 {
35 bool contains = Group.TestTypes.Contains(value);
36 if (contains) Show();
37
38 buttonFlow.ForEach(btn => btn.Current = btn.TestType == value);
39 headerButton.Current = contains;
40 }
41 }
42
43 public TestGroupButton(Action<Type> loadTest, TestGroup group)
44 {
45 var tests = group.TestTypes;
46
47 if (tests.Length == 0)
48 throw new ArgumentOutOfRangeException(nameof(group), tests.Length, "Type array must not be empty!");
49
50 Group = group;
51
52 RelativeSizeAxes = Axes.X;
53 AutoSizeAxes = Axes.Y;
54
55 Child = buttonFlow = new FillFlowContainer<TestButtonBase>
56 {
57 Direction = FillDirection.Vertical,
58 AutoSizeAxes = Axes.Y,
59 RelativeSizeAxes = Axes.X
60 };
61
62 buttonFlow.Add(headerButton = new TestButton(group.Name)
63 {
64 Action = ToggleVisibility
65 });
66
67 foreach (var test in tests)
68 {
69 buttonFlow.Add(new TestSubButton(test, 1)
70 {
71 Action = () => loadTest(test)
72 });
73 }
74 }
75
76 public override bool PropagatePositionalInputSubTree => true;
77
78 protected override void PopIn() => buttonFlow.ForEach(b => b.Collapsed = false);
79
80 protected override void PopOut() => buttonFlow.ForEach(b => b.Collapsed = true);
81 }
82}