Skip to content

Commit

Permalink
Merge pull request #17937 from frenzibyte/settings-filter-regression-…
Browse files Browse the repository at this point in the history
…fix-2

Fix settings overlay components not invalidating presence on filter change
  • Loading branch information
peppy authored Apr 24, 2022
2 parents 176d263 + 83970f0 commit 21665f6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
22 changes: 17 additions & 5 deletions osu.Game.Tests/Visual/Settings/TestSceneSettingsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,21 @@ public void SetUpSteps()
State = { Value = Visibility.Visible }
});
});

AddStep("reset mouse", () => InputManager.MoveMouseTo(settings));
}

[Test]
public void TestQuickFiltering()
public void TestFiltering([Values] bool beforeLoad)
{
AddStep("set filter", () =>
{
settings.SectionsContainer.ChildrenOfType<SearchTextBox>().First().Current.Value = "scaling";
});
if (beforeLoad)
AddStep("set filter", () => settings.SectionsContainer.ChildrenOfType<SearchTextBox>().First().Current.Value = "scaling");

AddUntilStep("wait for items to load", () => settings.SectionsContainer.ChildrenOfType<IFilterable>().Any());

if (!beforeLoad)
AddStep("set filter", () => settings.SectionsContainer.ChildrenOfType<SearchTextBox>().First().Current.Value = "scaling");

AddAssert("ensure all items match filter", () => settings.SectionsContainer
.ChildrenOfType<SettingsSection>().Where(f => f.IsPresent)
.All(section =>
Expand All @@ -56,6 +59,15 @@ public void TestQuickFiltering()
));

AddAssert("ensure section is current", () => settings.CurrentSection.Value is GraphicsSection);
AddAssert("ensure section is placed first", () => settings.CurrentSection.Value.Y == 0);
}

[Test]
public void TestFilterAfterLoad()
{
AddUntilStep("wait for items to load", () => settings.SectionsContainer.ChildrenOfType<IFilterable>().Any());

AddStep("set filter", () => settings.SectionsContainer.ChildrenOfType<SearchTextBox>().First().Current.Value = "scaling");
}

[Test]
Expand Down
7 changes: 2 additions & 5 deletions osu.Game/Graphics/Containers/SectionsContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,8 @@ protected override bool OnInvalidate(Invalidation invalidation, InvalidationSour

protected void InvalidateScrollPosition()
{
Schedule(() =>
{
lastKnownScroll = null;
lastClickedSection = null;
});
lastKnownScroll = null;
lastClickedSection = null;
}

protected override void UpdateAfterChildren()
Expand Down
18 changes: 16 additions & 2 deletions osu.Game/Overlays/Settings/SettingsItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,23 @@ public virtual Bindable<T> Current

public IEnumerable<string> Keywords { get; set; }

public override bool IsPresent => base.IsPresent && MatchingFilter;
private bool matchingFilter = true;

public bool MatchingFilter
{
get => matchingFilter;
set
{
bool wasPresent = IsPresent;

public bool MatchingFilter { get; set; } = true;
matchingFilter = value;

if (IsPresent != wasPresent)
Invalidate(Invalidation.Presence);
}
}

public override bool IsPresent => base.IsPresent && MatchingFilter;

public bool FilteringActive { get; set; }

Expand Down
20 changes: 17 additions & 3 deletions osu.Game/Overlays/Settings/SettingsSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public abstract class SettingsSection : Container, IHasFilterableChildren
protected FillFlowContainer FlowContent;
protected override Container<Drawable> Content => FlowContent;

public override bool IsPresent => base.IsPresent && MatchingFilter;

private IBindable<SettingsSection> selectedSection;

private Box dim;
Expand All @@ -40,7 +38,23 @@ public abstract class SettingsSection : Container, IHasFilterableChildren
private const int header_size = 24;
private const int border_size = 4;

public bool MatchingFilter { get; set; } = true;
private bool matchingFilter = true;

public bool MatchingFilter
{
get => matchingFilter;
set
{
bool wasPresent = IsPresent;

matchingFilter = value;

if (IsPresent != wasPresent)
Invalidate(Invalidation.Presence);
}
}

public override bool IsPresent => base.IsPresent && MatchingFilter;

public bool FilteringActive { get; set; }

Expand Down

0 comments on commit 21665f6

Please sign in to comment.