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

Allow SearchContainer implementations to manually trigger a Filter operation #5772

Merged
merged 8 commits into from
May 26, 2023
31 changes: 24 additions & 7 deletions osu.Framework/Graphics/Containers/SearchContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,30 @@ protected override void Update()
{
base.Update();

if (!filterValid.IsValid)
{
canBeShownBindables.Clear();
performFilter();
filterValid.Validate();
FilterCompleted?.Invoke();
}
Filter();
}

/// <summary>
/// Immediately filter <see cref="IFilterable"/> children based on the current <see cref="SearchTerm"/>.
/// </summary>
/// <remarks>
/// Filtering is done automatically after a change to <see cref="SearchTerm"/>, on new drawables being added, and on certain changes to
/// searchable children (like <see cref="IConditionalFilterable.CanBeShown"/> changing).
///
/// However, if <see cref="SearchContainer{T}"/> or any of its parents are hidden this will not be run.
/// If an implementation relies on filtering to become present / visible, this method can be used to force a filter.
///
/// Note that this will only run if the current filter is not in an already valid state.
/// </remarks>
protected void Filter()
{
if (filterValid.IsValid)
return;

canBeShownBindables.Clear();
performFilter();
filterValid.Validate();
FilterCompleted?.Invoke();
}

private void performFilter()
Expand Down