A simple file-browser for dear-imgui.
- Add
imgui_filebrowser.cpp
to your source files. - Include
imgui_filebrowser.h
.
There are two functions:
bool ImGui::OpenFileBrowser(const std::string& InPath, FileBrowserOption InOption = FileBrowserOption::FILE, const std::set<std::string>& InExt = {});
bool ImGui::FetchFileBrowserResult(const std::string& InPath, std::string& OutSelectedPath);
There are some QOL tricks in the browser:
- Write ".." in the navigation-bar to go up one directory
- Press tab when editing the navigation-bar to auto-complete
- You can specify a base directory by changing the path in
GetRelative()
andGetLocal()
. It is currently set to..\\content\\
.
if (ImGui::Button("Pick file"))
ImGui::OpenFileBrowser(defaultPath);
std::string result;
if (ImGui::FetchFileBrowserResult(defaultPath, result))
{
// Do something with the result
}
- Using the standard library, specifically
std::string
,std::set
andstd::filesystem
. - The window size can be changed by changing
Width
andHeight
in theFileBrowser
class.
- Multi-file select
- Search / filters
- Currently relying on that
defaultPath
is different for eachFetchFileBrowserResult()
call