class mrpt::imgui::CImGuiFileDialog
Overview
Open/save/select-folder dialogs for ImGui applications.
Uses the native dialogs of the system (via portable-file-dialogs: zenity, kdialog, Windows or macOS dialogs) when available, and otherwise falls back to SimpleFileDialog, drawn with ImGui. Native dialogs run asynchronously, so the GUI keeps rendering while they are open.
The backend can be forced with backend, or with the environment variable MRPT_IMGUI_FILE_DIALOG=native|imgui.
mrpt::imgui::CImGuiFileDialog dlg; if (ImGui::MenuItem("Open...")) { dlg.open(CImGuiFileDialog::Mode::Open, "Open scene", {{"3D scenes", {"3Dscene"}}}); } // Every frame: if (auto files = dlg.poll(); files && !files->empty()) { load(files->front()); }
#include <mrpt/imgui/CImGuiFileDialog.h> class CImGuiFileDialog { public: // enums enum Backend; enum Mode; // structs struct NativeImpl; // fields std::string tag; Backend backend = Backend::Auto; // construction CImGuiFileDialog(); CImGuiFileDialog(const CImGuiFileDialog&); // methods CImGuiFileDialog& operator = (const CImGuiFileDialog&); void open( Mode mode, const std::string& title, const std::vector<FileDialogFilter>& filters = {}, const std::string& initialPath = "" ); std::optional<std::vector<std::string>> poll(); bool isOpen() const; Mode mode() const; const std::string& lastDirectory() const; static bool nativeAvailable(); };
Fields
std::string tag
A tag set by the caller in open() to know what the result is for.
Methods
void open( Mode mode, const std::string& title, const std::vector<FileDialogFilter>& filters = {}, const std::string& initialPath = "" )
Opens the dialog.
initialPath may be a directory or a file name. If a dialog is already open, it is abandoned.
std::optional<std::vector<std::string>> poll()
Must be called every frame (it draws the ImGui fallback, if used).
Returns the result exactly once when the dialog closes: the selected path(s), or an empty vector if it was cancelled. nullopt otherwise.
Mode mode() const
The mode of the last open() call (to tell results apart when one dialog object serves several commands).
const std::string& lastDirectory() const
Directory of the last selected path, used as the default next time.
static bool nativeAvailable()
Whether a native dialog helper is available on this system.