#How do I add a search bar for an item list?

1 messages · Page 1 of 1 (latest)

eternal cypress
#

I'm trying to create a search bar for my game using an item list, and I can't figure out how. I know about the built-in search feature, but I want the player to see what they're typing and to click on the search bar to start typing. I looked it up and found nothing. Does anyone know how to do this?

burnt flax
#

Let's say you have a scene sort of like this:

  • LineEdit: This is your search box
  • VBoxContainer: This contains the list you want to search through
    • Label: One for each item (you could have this be something other than Label as long as it has text in it somewhere)

As the user types into the LineEdit, it will emit the text_changedsignal. When that happens, go through each of the items in the list and show/hide them.

Something like this (I'm on my phone so I'm not actually testing it 😅)

func _on_text_changed(new_text: String):
   for item in container: 
      item.visible = item.text.containsn(new_text)
eternal cypress
burnt flax
#

Yeah I would create a scene with each item and then give it a function like get_text that would return whatever text is in the label

eternal cypress