Skip to content

Commit

Permalink
Merge pull request #1192 from Aergwyn/make-testcases-searchable
Browse files Browse the repository at this point in the history
Make test cases searchable in TestBrowser
  • Loading branch information
smoogipoo committed Dec 4, 2017
2 parents 8c16e62 + 06eee8e commit e21fc5e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 21 deletions.
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

0 comments on commit e21fc5e

Please sign in to comment.