Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make test cases searchable in TestBrowser #1192

Merged
merged 4 commits into from Dec 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 3 additions & 10 deletions osu.Framework.Tests/Visual/TestCaseSearchContainer.cs
Expand Up @@ -64,15 +64,15 @@ public TestCaseSearchContainer()
AutoSizeAxes = Axes.Both,
Children = new []
{
new KeywordText
new SpriteText
{
Text = "multi",
},
new KeywordText
new SpriteText
{
Text = "piece",
},
new KeywordText
new SpriteText
{
Text = "container",
},
Expand Down Expand Up @@ -160,11 +160,6 @@ public HeaderContainer(string headerText = "Header")
}
}

private class KeywordText : SpriteText, IHasFilterTerms
{
public IEnumerable<string> FilterTerms => new[] { Text };
}

private class FilterableFlowContainer : FillFlowContainer, IFilterable
{
public IEnumerable<string> FilterTerms => Children.OfType<IHasFilterTerms>().SelectMany(d => d.FilterTerms);
Expand All @@ -183,8 +178,6 @@ public bool MatchingFilter

private class SearchableText : SpriteText, IFilterable
{
public IEnumerable<string> FilterTerms => new[] { Text };

public bool MatchingFilter
{
set
Expand Down
4 changes: 3 additions & 1 deletion osu.Framework/Graphics/Sprites/SpriteText.cs
Expand Up @@ -20,8 +20,10 @@ namespace osu.Framework.Graphics.Sprites
/// <summary>
/// A container for simple text rendering purposes. If more complex text rendering is required, use <see cref="TextFlowContainer"/> instead.
/// </summary>
public class SpriteText : FillFlowContainer, IHasCurrentValue<string>, IHasLineBaseHeight, IHasText
public class SpriteText : FillFlowContainer, IHasCurrentValue<string>, IHasLineBaseHeight, IHasText, IHasFilterTerms
{
public IEnumerable<string> FilterTerms => new [] { Text };

private static readonly char[] default_fixed_width_exceptions = { '.', ':', ',' };

/// <summary>
Expand Down
17 changes: 16 additions & 1 deletion osu.Framework/Testing/Drawables/TestCaseButton.cs
Expand Up @@ -9,11 +9,26 @@
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input;
using OpenTK.Graphics;
using System.Collections.Generic;
using System.Linq;

namespace osu.Framework.Testing.Drawables
{
internal class TestCaseButton : ClickableContainer
internal class TestCaseButton : ClickableContainer, IFilterable
{
public IEnumerable<string> FilterTerms => text.Children.OfType<IHasFilterTerms>().SelectMany(c => c.FilterTerms);

public bool MatchingFilter
{
set
{
if (value)
Show();
else
Hide();
}
}

private readonly Box box;
private readonly TextFlowContainer text;

Expand Down
36 changes: 27 additions & 9 deletions osu.Framework/Testing/TestBrowser.cs
Expand Up @@ -28,7 +28,8 @@ public class TestBrowser : Screen
{
public TestCase CurrentTest { get; private set; }

private FillFlowContainer<TestCaseButton> leftFlowContainer;
private TextBox searchTextBox;
private SearchContainer<TestCaseButton> leftFlowContainer;
private Container testContentContainer;
private Container compilingNotice;

Expand Down Expand Up @@ -112,17 +113,32 @@ private void load(Storage storage, GameHost host)
Colour = Color4.DimGray,
RelativeSizeAxes = Axes.Both
},
new ScrollContainer
new FillFlowContainer
{
Direction = FillDirection.Vertical,
RelativeSizeAxes = Axes.Both,
ScrollbarOverlapsContent = false,
Child = leftFlowContainer = new FillFlowContainer<TestCaseButton>
Children = new Drawable[]
{
Padding = new MarginPadding(3),
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 5),
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
searchTextBox = new TextBox
{
Height = 25,
RelativeSizeAxes = Axes.X,
PlaceholderText = "search here"
},
new ScrollContainer
{
Padding = new MarginPadding{ Top = 3 },
RelativeSizeAxes = Axes.Both,
ScrollbarOverlapsContent = false,
Child = leftFlowContainer = new SearchContainer<TestCaseButton>
{
Padding = new MarginPadding(3),
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 5),
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
}
}
}
}
}
Expand Down Expand Up @@ -173,6 +189,8 @@ private void load(Storage storage, GameHost host)
}
};

searchTextBox.Current.ValueChanged += newValue => leftFlowContainer.SearchTerm = newValue;

backgroundCompiler = new DynamicClassCompiler<TestCase>
{
CompilationStarted = compileStarted,
Expand Down