Skip to content

Immediate mode searching, an extension for Dear ImGui

License

Notifications You must be signed in to change notification settings

GuusKemperman/imsearch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

96 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ImSearch

ImSearch is an immediate mode extension for Dear ImGui, allowing you to create searchbars for ImGui's buttons, trees, selectable, and every other widget you can imagine.

Just like ImGui, ImSearch's API does not burden the end user with state management, use STL containers or include any C++ headers, and has no public dependencies except for ImGui itself. This extension is compatible with C++11 and above.

Examples

Combos, previews and autocomplete

Hierarchies

Collapsing headers and nested search bars

Custom search bars

Real world examples from Coral Engine

World outliner, details panel, and asset selection

Content browser

Finding functions and types for easier scripting

Usage

You'll find that the API still feels very familiar to ImGui, albeit slightly different from what you might expect from an ImGui extension; because this extension also takes control over the order to display items in, the library uses callbacks for submitting your widgets. First, start a new search context by calling ImSearch::BeginSearch. Next, submit as many items as you want with the Push/PopSearchable functions, to which you provide callbacks to display your ImGui widget (e.g. Selectable, Button, TreeNode, etc). Finally, wrap things up with a call to ImSearch::EndSearch(). That's it!

static const char* selectedString = sImguiExtensions[0];

if (ImGui::BeginCombo("##Extensions", selectedString))
{
    if (ImSearch::BeginSearch())
    {
        ImSearch::SearchBar();

        for (const char* extension : sImguiExtensions)
        {
            ImSearch::SearchableItem(extension,
                [&](const char* name)
                {
                    const bool isSelected = name == selectedString;
                    if (ImGui::Selectable(name, isSelected))
                    {
                        selectedString = name;
                    }
                });
        }
        ImSearch::EndSearch();
    }
    ImGui::EndCombo();
}

Demos

More examples of ImSearch's features and usages can be found in imsearch_demo.cpp. Add this file to your sources and call ImSearch::ShowDemoWindow() somewhere in your update loop. You are encouraged to use this file as a reference whenever you need it. The demo is always updated to show new features as they are added, so check back with each release!

Integration

  1. Set up an ImGui environment if you don't already have one.
  2. Add imsearch.h, imsearch_internal.h, imsearch.cpp, and optionally imsearch_demo.cpp to your sources.
  3. Create and destroy an ImSearchContext wherever you do so for your ImGuiContext:
ImGui::CreateContext();
ImSearch::CreateContext();
...
ImSearch::DestroyContext();
ImGui::DestroyContext();

You should be good to go!

About

Immediate mode searching, an extension for Dear ImGui

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages