Skip to content

Implement search bar for PopupMenu#114236

Merged
Repiteo merged 1 commit into
godotengine:masterfrom
warriormaster12:san-popupmenu-search-bar
Mar 4, 2026
Merged

Implement search bar for PopupMenu#114236
Repiteo merged 1 commit into
godotengine:masterfrom
warriormaster12:san-popupmenu-search-bar

Conversation

@warriormaster12

@warriormaster12 warriormaster12 commented Dec 20, 2025

Copy link
Copy Markdown
Contributor

This adds an ability to search items inside PopupMenu. Currently the search bar is only visible if there are 10 or more items.

Implements proposal: godotengine/godot-proposals#13681

There are a couple of questions that I want feedback on:

  • Should the class provide methods for enabling/disabling search bar? Should there be an ability to configure how many items are required to have for visibility to change?
  • Do we still want to keep activated_by_keyboard option? Feels at least redundant in my eyes.
  • Should there be an option to edit search bar's placeholder text
Screencast_20251220_140018.webm
@Flynsarmy

Copy link
Copy Markdown
Contributor
Comment thread scene/gui/popup_menu.cpp Outdated
Comment thread scene/gui/popup_menu.cpp Outdated
@YeldhamDev

Copy link
Copy Markdown
Member

This feature should be optional, and disabled by default. Currently it always enables when there are at least 10 items.

@Flynsarmy

Copy link
Copy Markdown
Contributor

This feature should be optional, and disabled by default. Currently it always enables when there are at least 10 items.

I agree however the option should be toggled on in all areas of the editor.

@warriormaster12 warriormaster12 force-pushed the san-popupmenu-search-bar branch from 3e41bb3 to b07225b Compare December 22, 2025 18:17
@warriormaster12 warriormaster12 requested a review from a team December 22, 2025 18:17
Comment thread scene/gui/popup_menu.cpp Outdated
@warriormaster12

Copy link
Copy Markdown
Contributor Author

Managed to figure out how to add support for searching inside submenus. Probably not the most optimal implementation but it works (at least as much as I tested).

@warriormaster12

Copy link
Copy Markdown
Contributor Author
Screencast_20251222_213848.webm

Example

@YeldhamDev

YeldhamDev commented Dec 22, 2025

Copy link
Copy Markdown
Member

I can see a regression in your video: the submenu doesn't align with the item in the parent popup anymore.

Also, you need to fill in the documentation for the new functions (run the binary with --doctool, then fill the descriptions), and probably make them accessible via properties as well.

@warriormaster12 warriormaster12 force-pushed the san-popupmenu-search-bar branch 2 times, most recently from e861ea5 to f70fea7 Compare December 23, 2025 13:28
@warriormaster12 warriormaster12 requested a review from a team as a code owner December 23, 2025 13:28
@warriormaster12 warriormaster12 force-pushed the san-popupmenu-search-bar branch 3 times, most recently from b14fed3 to 8be0066 Compare December 23, 2025 22:24
@warriormaster12

Copy link
Copy Markdown
Contributor Author

@YeldhamDev regression solved and docs added.

@warriormaster12 warriormaster12 force-pushed the san-popupmenu-search-bar branch 2 times, most recently from 99f932c to b8f99ce Compare January 7, 2026 20:23
@warriormaster12

Copy link
Copy Markdown
Contributor Author

Noticed that caret jumps to the front when using up key which in this case is only desired if non of the items in scroll container are hovered over.

Comment thread scene/gui/popup_menu.h Outdated
Comment thread scene/gui/popup_menu.cpp Outdated
Comment thread scene/gui/popup_menu.cpp Outdated
Comment thread scene/gui/popup_menu.cpp Outdated
Comment thread scene/gui/popup_menu.cpp Outdated
Comment thread doc/classes/OptionButton.xml Outdated
Comment thread doc/classes/OptionButton.xml Outdated
Comment thread doc/classes/OptionButton.xml Outdated
Comment thread doc/classes/PopupMenu.xml Outdated
Comment thread doc/classes/PopupMenu.xml Outdated
@warriormaster12 warriormaster12 force-pushed the san-popupmenu-search-bar branch 2 times, most recently from 284d189 to 8a1125d Compare January 8, 2026 17:46
@warriormaster12 warriormaster12 force-pushed the san-popupmenu-search-bar branch from e8bba09 to 13da832 Compare March 3, 2026 19:51
@warriormaster12

Copy link
Copy Markdown
Contributor Author

@YeldhamDev Changed

Comment thread scene/gui/popup_menu.cpp Outdated
@MarianoGnu

Copy link
Copy Markdown
Contributor

Everything seems to be working fine! But I personally think that the search bar should be cleared when the popup hides. Once that is done, it should be ready for an approval.

a public method for "clear_search_filter" should be enough, that way the user can connect on about to popup to this method

@YeldhamDev

Copy link
Copy Markdown
Member

I think it would be better for this to be the default behavior. Having the bar start with the old search will be more of a nuisance than useful.

@warriormaster12

Copy link
Copy Markdown
Contributor Author

a public method for "clear_search_filter" should be enough, that way the user can connect on about to popup to this method

Probably can be done in a follow up PR.

@warriormaster12 warriormaster12 force-pushed the san-popupmenu-search-bar branch from 13da832 to 18e989c Compare March 3, 2026 20:35
@Repiteo Repiteo modified the milestones: 4.x, 4.7 Mar 4, 2026
@Repiteo Repiteo merged commit 891069d into godotengine:master Mar 4, 2026
20 checks passed
@Repiteo

Repiteo commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

Thanks!

@JekSun97

Copy link
Copy Markdown
Contributor
@jinyangcruise

Copy link
Copy Markdown
Contributor

Excuse me, I’m wondering why the search bar not be displayed when the PopupMenu has a parent popup.

godot/scene/gui/popup_menu.cpp

Lines 3635 to 3643 in 6d6e822

if (p_visible) {
PopupMenu *parent_popup = Object::cast_to<PopupMenu>(get_parent());
if (!parent_popup) {
search_bar->set_visible(is_search_bar_enabled());
if (search_bar->is_visible()) {
search_bar->edit(true);
}
}
}

@warriormaster12

Copy link
Copy Markdown
Contributor Author

@jinyangcruise My reasoning was recursive search. Since you can search items inside submenus, there's no need to provide search bars for submenus.

@jinyangcruise

Copy link
Copy Markdown
Contributor

Got it. That sounds like a good idea. However, this behavior is governed by the search_bar_enabled_on_item_count setting of the parent popup. If the parent popup does not contain enough items to trigger the search bar, the search bar will not appear—even when the sub-popup menu has a large number of entries.

Additionally, your recursive search method checks the state of hidden sub-popups. However, the content within these sub-popups can be post-modified through the about_to_popup signal. This leaves developers using some workarounds, for instance, refresh submenu items via the parent menu’s about_to_popup callback, instead of using its own about_to_popup logic to handle item updates.

What if we let users decide? A new property such as search_behavior will be added. They can opt for :

  1. Recursive search when their popup menu items are static (It remains necessary to fix the issue where submenu search is governed by the search_bar_enabled_on_item_count setting of its parent menu).
  2. Enable the search bar for each individual popup menu based on its own item count.

There might be some better options out there.

@warriormaster12

Copy link
Copy Markdown
Contributor Author

Got it. That sounds like a good idea. However, this behavior is governed by the search_bar_enabled_on_item_count setting of the parent popup. If the parent popup does not contain enough items to trigger the search bar, the search bar will not appear—even when the sub-popup menu has a large number of entries.

Sounds like a bug to me. Probably submenu item count should be taken into consideration.

What if we let users decide? A new property such as search_behavior will be added. They can opt for...
Probably a good idea.

In any case. I'd suggest making a bug report about search_bar_enabled_on_item_count not taking into consideration submenu item count. As for search_behavior property, not sure what is the correct course of action. Proposal, PR or an issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment