Skip to content

Commit

Permalink
Disable ability to search in tab control dropdowns
Browse files Browse the repository at this point in the history
  • Loading branch information
frenzibyte committed Dec 29, 2023
1 parent 107bebe commit 5f2acdd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
10 changes: 10 additions & 0 deletions osu.Framework/Graphics/UserInterface/Dropdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,18 @@ public abstract partial class Dropdown<T> : CompositeDrawable, IHasCurrentValue<

protected internal override IEnumerable<Drawable> AdditionalFocusTargets => new Drawable[] { Menu, Header };

/// <summary>
/// Whether this <see cref="Dropdown{T}"/> is searchable and a search bar should be present.
/// </summary>
public bool Searchable
{
get => Header.Searchable;
set => Header.Searchable = value;
}

/// <summary>
/// Whether this <see cref="Dropdown{T}"/> should always have a search bar displayed in the header when opened.
/// Requires <see cref="Searchable"/> to be true.
/// </summary>
public bool AlwaysShowSearchBar
{
Expand Down
23 changes: 21 additions & 2 deletions osu.Framework/Graphics/UserInterface/DropdownHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public bool AlwaysShowSearchBar

public Bindable<string> SearchTerm => SearchBar.SearchTerm;

protected internal override IEnumerable<Drawable> AdditionalFocusTargets => new Drawable[] { SearchBar };
protected internal override IEnumerable<Drawable> AdditionalFocusTargets => Searchable ? new Drawable[] { SearchBar } : Array.Empty<Drawable>();

private Color4 backgroundColour = Color4.DarkGray;

Expand Down Expand Up @@ -70,6 +70,25 @@ protected Color4 DisabledColour

public Action ToggleMenu;

private bool searchable = true;

public bool Searchable
{
get => searchable;
set
{
if (searchable == value)
return;

searchable = value;

if (searchable)
AddInternal(SearchBar);
else
RemoveInternal(SearchBar, false);
}
}

protected DropdownHeader()
{
Masking = true;
Expand Down Expand Up @@ -98,7 +117,7 @@ protected DropdownHeader()
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y
},
SearchBar = CreateSearchBar(),
SearchBar = CreateSearchBar().With(b => b.Depth = float.MinValue),
};
}

Expand Down
1 change: 1 addition & 0 deletions osu.Framework/Graphics/UserInterface/TabControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ protected TabControl()
Dropdown.Anchor = Anchor.TopRight;
Dropdown.Origin = Anchor.TopRight;
Dropdown.Current = Current;
Dropdown.Searchable = false;

AddInternal(Dropdown);

Expand Down

0 comments on commit 5f2acdd

Please sign in to comment.