Skip to content

Commit

Permalink
Allow making dropdown unsearchable with null search bar
Browse files Browse the repository at this point in the history
  • Loading branch information
frenzibyte committed Dec 29, 2023
1 parent 107bebe commit 0c023e4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
3 changes: 2 additions & 1 deletion osu.Framework/Graphics/UserInterface/Dropdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ protected Dropdown()
Header.ToggleMenu = Menu.Toggle;
Header.ChangeSelection += selectionKeyPressed;

Header.SearchTerm.ValueChanged += t => Menu.SearchTerm = t.NewValue;
if (Header.SearchTerm != null)
Header.SearchTerm.ValueChanged += t => Menu.SearchTerm = t.NewValue;

Menu.RelativeSizeAxes = Axes.X;
Menu.PreselectionConfirmed += preselectionConfirmed;
Expand Down
25 changes: 20 additions & 5 deletions osu.Framework/Graphics/UserInterface/DropdownHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using osuTK.Graphics;
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
Expand All @@ -26,15 +27,21 @@ public abstract partial class DropdownHeader : Container, IKeyBindingHandler<Pla

public bool AlwaysShowSearchBar
{
get => SearchBar.AlwaysDisplayOnFocus;
set => SearchBar.AlwaysDisplayOnFocus = value;
get => SearchBar?.AlwaysDisplayOnFocus ?? false;
set
{
if (SearchBar != null)
SearchBar.AlwaysDisplayOnFocus = value;
}
}

[CanBeNull]
protected internal DropdownSearchBar SearchBar { get; }

public Bindable<string> SearchTerm => SearchBar.SearchTerm;
[CanBeNull]
public Bindable<string> SearchTerm => SearchBar?.SearchTerm;

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

private Color4 backgroundColour = Color4.DarkGray;

Expand Down Expand Up @@ -98,10 +105,18 @@ protected DropdownHeader()
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y
},
SearchBar = CreateSearchBar(),
};

SearchBar = CreateSearchBar();

if (SearchBar != null)
AddInternal(SearchBar);
}

/// <summary>
/// Creates a <see cref="DropdownSearchBar"/> to attach to this dropdown, or <c>null</c> to not attach any (making this dropdown unsearchable).
/// </summary>
[CanBeNull]
protected abstract DropdownSearchBar CreateSearchBar();

protected override void LoadComplete()
Expand Down

0 comments on commit 0c023e4

Please sign in to comment.