PickerManager¶
Overview¶
-
class omdi::PickerManager¶
Manager for handling file/directory picker dialogs.
The
omdi::PickerManagerclass maintains a collection of ImGuiFileDialog (IGFD::FileDialog) instances along with per-dialog callbacks. It provides a simple interface to:open file or directory pickers with customizable titles, prompts, initial paths, and file filters,
render and manage all active dialogs in the main UI loop,
invoke user-provided callbacks when a dialog is accepted,
automatically clean up dialogs when they are closed.
Internally, dialogs are stored as pairs of:
std::unique_ptromdi::picker::callback_t(a callback called on success)
Logging is performed through
omdi::loggerwhen dialogs are opened, accepted, cancelled, and removed.
Usage example¶
Basic usage as a file picker with a succest toast notification:
auto pickerDialogManager = omdi::PickerManager();
auto toastManager = omdi::ToastManager();
// somewhere in the UI code:
pickerDialogManager.Add([&](IGFD::FileDialog* dialog) {
const auto fpath_name = dialog->GetFilePathName();
const auto fpath = dialog->GetCurrentPath();
toastManager.Add(omdi::toasts::Type::Success,
omdi::fmt::format("picked %s %s",
fpath_name.c_str(),
fpath.c_str()));
});
// don't forget to pass it with other managers:
auto managers = omdi::managers_t {
{ "toast_manager", &toastManager },
{ "picker_manager", &pickerDialogManager }
// ...
};
app.Init(&state, managers);
app.Render(&state, [&]() {
// render callback
// ...
// picker is handled automatically
},
components,
managers);
Public interface¶
-
void omdi::PickerManager::Add(omdi::picker::callback_t callback, const std::string &title = "PickerDialog", const std::string &prompt = "Pick a file or directory", const std::string &path = ".", const char *filter = nullptr)¶
Add a picker dialog to the manager.
- Parameters:
callback – Function to be called when the dialog is accepted (
IsOk() == true). The callback receives a pointer to theIGFD::FileDialoginstance, which can be queried for the selected file(s) or directory.title – Title of the dialog window (default:
"PickerDialog").prompt – Prompt message shown in the dialog (default:
"Pick a file or directory").path – Initial path shown when the dialog opens (default:
".").filter – File extension filter (default:
nullptr). If this isnullptr, the dialog behaves like a directory picker; otherwise, it filters files according to the given pattern.
This method:
constructs an
IGFD::FileDialog,configures it with the supplied path, title, prompt, and filter via
IGFD::FileDialog::OpenDialog(),stores the dialog and callback in the internal list,
logs the operation via
omdi::logger(e.g. dialog opened, total dialog count).
-
void omdi::PickerManager::render()¶
Render and manage all active picker dialogs.
This method should be called from the main ImGui rendering loop. For each active dialog, it:
configures file styles (e.g. special styling for
.ttffiles),displays the dialog via
IGFD::FileDialog::Display(),checks whether the dialog has been accepted or cancelled:
if accepted (
IsOk() == true):logs success via
omdi::logger,invokes the associated
omdi::picker::callback_twith the pointer toIGFD::FileDialog,closes the dialog and removes it from the manager;
if cancelled:
logs cancellation,
closes and removes the dialog from the manager.
The method iterates over all managed dialogs and removes them once they are closed, ensuring no stale dialogs remain in the list.
Notes¶
omdi::PickerManagerdoes not own or manage the global ImGui or ImGuiFileDialog state beyond the dialogs it creates.All dialogs are non-blocking and rendered as part of the normal ImGui frame;
omdi::PickerManager::render()must be called every frame while dialogs are active.The lifetime of the
IGFD::FileDialogpassed into the callback is limited to the callback invocation and the remainder of the current frame; the dialog is removed from the manager immediately after handling OK/Cancel.