### Complete Example Configuration Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/configuration.md An example of a custom configuration header file that enables various features and customizes UI elements and behavior. ```cpp #pragma once // Filesystem #define USE_STD_FILESYSTEM // Features #define USE_EXPLORATION_BY_KEYS #define USE_THUMBNAILS #define USE_PLACES_FEATURE #define USE_PLACES_BOOKMARKS // UI Customization #define searchString "🔍 Search" #define fileNameString "📄 Filename: " #define createDirButtonString "📁 New Folder" #define okButtonString "✓ Open" #define cancelButtonString "✕ Cancel" // Sorting #define defaultSortField FIELD_FILENAME #define defaultSortOrderFilename true #define USE_CUSTOM_SORTING_ICON // Buffer sizes #define MAX_FILE_DIALOG_NAME_BUFFER 2048 #define MAX_PATH_BUFFER_SIZE 2048 // Date format #define DateTimeFormat "%d/%m/%Y %H:%M:%S" // Buttons #define okCancelButtonAlignement 1.0f #define okButtonWidth 100.0f #define cancelButtonWidth 100.0f ``` -------------------------------- ### Complete ImGuiFileDialog C Example Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/C-API.md A full C example demonstrating how to initialize, configure, open, display, and clean up ImGuiFileDialog. It shows file selection and basic configuration. ```c #include "ImGuiFileDialog.h" #include #include int main() { ImGuiFileDialog* pFileDialog = IGFD_Create(); // Configure and open IGFD_FileDialog_Config config = IGFD_FileDialog_Config_Get(); config.path = "."; config.countSelectionMax = 1; IGFD_OpenDialog( pFileDialog, "ChooseFile", "Select a File", ".txt,.cpp,.h", config); // In your render loop ImVec2 minSize = {400, 300}; ImVec2 maxSize = {1200, 800}; if (IGFD_DisplayDialog(pFileDialog, "ChooseFile", 0, minSize, maxSize)) { if (IGFD_IsOk(pFileDialog)) { char* path = IGFD_GetFilePathName(pFileDialog, IGFD_ResultMode_KeepInputFile); printf("Selected: %s\n", path); free(path); } IGFD_CloseDialog(pFileDialog); } // Cleanup IGFD_Destroy(pFileDialog); return 0; } ``` -------------------------------- ### Opening a File Dialog with Configuration Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/FileDialog.md Example of opening a file dialog with specific configurations, including a starting path, maximum selection count, and modal behavior with confirmation. ```cpp IGFD::FileDialogConfig config; config.path = "./assets"; config.countSelectionMax = 1; config.flags = ImGuiFileDialogFlags_Modal | ImGuiFileDialogFlags_ConfirmOverwrite; ImGuiFileDialog::Instance()->OpenDialog( "ChooseFile", "Select a C++ Source File", "C++ Source{.cpp,.cc,.cxx},C++ Header{.h,.hpp},.hpp", config); ``` -------------------------------- ### Run Example Programs Source: https://github.com/aiekick/imguifiledialog/blob/master/dirent/README.md Execute example programs (ls, find, updatedb, locate) from the command prompt after building the solution in Visual Studio. ```bash cd Debug ls . find . updatedb c:\\ locate cmd.exe ``` -------------------------------- ### FileStyle Examples Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/Utils-FileStyle.md Demonstrates creating FileStyle objects with custom colors, icons, and fonts. ```cpp // Yellow C++ icon with default font IGFD::FileStyle style(ImVec4(1.0f, 1.0f, 0.0f, 0.9f), "C++"); // Red file with custom font ImFont* boldFont = ImGui::GetIO().Fonts->Fonts[1]; IGFD::FileStyle errorStyle(ImVec4(1.0f, 0.0f, 0.0f, 0.9f), "!", boldFont); ``` -------------------------------- ### Example: Get Current Path Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/FileManager.md Demonstrates how to call the GetCurrentPath method and store the result in a string variable. ```cpp std::string currentDir = fileManager.GetCurrentPath(); ``` -------------------------------- ### Filter Examples Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/INDEX.md Provides concise examples of filter configurations for various scenarios. Use these as templates for defining file filtering rules in your dialogs. ```text ".cpp,.h,.hpp" ``` ```text "Source Code{.cpp,.cc,.cxx},Headers{.h,.hpp}" ``` ```text "C++ Files{.cpp,((.*\.cpp$))}" ``` ```text "All C++{.cpp,.h,(.cc),(.hpp)},Source{.cpp,.cc},Images{.png,.jpg,((.*\.jpg))},.*" ``` -------------------------------- ### Example: Configuring IGFD_FileDialog_Config Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/C-API.md Demonstrates how to initialize and set properties for the IGFD_FileDialog_Config structure, including path, maximum selection count, and dialog flags. ```c IGFD_FileDialog_Config config = IGFD_FileDialog_Config_Get(); config.path = "./documents"; config.countSelectionMax = 1; config.flags = ImGuiFileDialogFlags_Modal; ``` -------------------------------- ### File Tooltip Message Example Source: https://github.com/aiekick/imguifiledialog/blob/master/Documentation.md Set a tooltip message for files displayed in a dedicated column. This example shows how to display the decomposition of a glTF file's total size. ```cpp vFileInfosPtr->tooltipMessage = toStr("%s : %s\n%s : %s", // (vFileInfosPtr->fileNameLevels[0] + ".gltf").c_str(), // IGFD::Utils::FormatFileSize(vFileInfosPtr->fileSize).c_str(), // (vFileInfosPtr->fileNameLevels[0] + ".bin").c_str(), // IGFD::Utils::FormatFileSize((size_t)statInfos.st_size).c_str()); // vFileInfosPtr->tooltipColumn = 1; // column of file size ``` -------------------------------- ### Example: File Filtering Callback Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/types.md Shows an example of a UserFileAttributesFun lambda function that excludes files larger than 100MB from the dialog's file list. ```cpp auto filterFunc = [](IGFD::FileInfos* file, IGFD::UserDatas ctx) -> bool { if (file->fileSize > 100000000) return false; // Exclude files > 100MB return true; }; ``` -------------------------------- ### FileStyle Constructor Example Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/types.md Demonstrates how to create a FileStyle object with a specific color, icon, and default font. This is useful for applying custom styles to files. ```cpp IGFD::FileStyle style(ImVec4(1.0f, 0.0f, 0.0f, 0.9f), "📄", nullptr); ``` -------------------------------- ### Example: Custom Side Pane Rendering Function Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/types.md Provides an example implementation of a PaneFun callback. This function renders custom text and a checkbox, and optionally controls whether the dialog can continue based on the checkbox state. ```cpp void MyPane(const char* filter, IGFD::UserDatas userData, bool* canContinue) { ImGui::TextColored(ImVec4(0, 1, 1, 1), "Custom Pane"); ImGui::Text("Filter: %s", filter); ImGui::Checkbox("Can validate", &someBoolean); if (canContinue) *canContinue = someBoolean; } ``` -------------------------------- ### ReplaceString Example Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/Utils-FileStyle.md Demonstrates replacing all occurrences of 'hello' with 'hi' in a string. ```cpp std::string text = "hello world hello"; IGFD::Utils::ReplaceString(text, "hello", "hi"); // Result: "hi world hi" ``` -------------------------------- ### Example: Custom Side Pane Callback Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/C-API.md Provides an example implementation of the IGFD_PaneFun callback. This function renders custom UI elements in the side pane of the file dialog. ```c void my_side_pane(const char* filter, void* userDatas, bool* pCantContinue) { ImGui::TextColored(ImVec4(0, 1, 1, 1), "Custom Pane"); ImGui::Text("Filter: %s", filter); } ``` -------------------------------- ### Open File Dialog Configuration Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/INDEX.md Shows how to configure and open a file dialog for selecting a single text file or any file. This example sets the initial path and the maximum number of selections. ```cpp IGFD::FileDialogConfig config; config.path = "./documents"; config.countSelectionMax = 1; ImGuiFileDialog::Instance()->OpenDialog( "OpenFile", "Open Document", "Text{.txt,.md},All{.*}", config); ``` -------------------------------- ### Custom Filesystem - Defensive Programming Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/errors.md Create a custom filesystem implementation by inheriting from `IFileSystem`. This example demonstrates safe directory checking by catching exceptions and returning false on errors. ```cpp class SafeFileSystem : public IFileSystem { public: bool IsDirectoryCanBeOpened(const std::string& vName) override { try { return std::filesystem::is_directory(vName) && has_permission(vName, std::filesystem::perms::read_and_exec); } catch (...) { return false; // Fail safely } } }; ``` -------------------------------- ### Example: Creating ImGuiFileDialog Context Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/C-API.md Demonstrates the basic usage of IGFD_Create to obtain a pointer to a new ImGuiFileDialog context, which is necessary for all subsequent C API operations. ```c ImGuiFileDialog* pFileDialog = IGFD_Create(); ``` -------------------------------- ### Example: Using and Destroying IGFD_Selection_Pair Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/C-API.md Shows how to obtain a selection pair, potentially use it, and then properly free its allocated string content using IGFD_Selection_Pair_DestroyContent. ```c IGFD_Selection_Pair pair = IGFD_Selection_Pair_Get(); // ... use pair ... IGFD_Selection_Pair_DestroyContent(&pair); ``` -------------------------------- ### Scan Directory Example Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/FileManager.md Scans a specified directory to populate the file list within a given dialog context. Ensure the FileDialogInternal context and the directory path are correctly provided. ```cpp fileManager.ScanDir(internalDialog, "/home/user/documents"); ``` -------------------------------- ### Example: Using and Destroying IGFD_Selection Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/C-API.md Illustrates the process of obtaining a selection structure, using the selected file information, and then freeing all associated memory with IGFD_Selection_DestroyContent. ```c IGFD_Selection selection = IGFD_GetSelection(vContextPtr, IGFD_ResultMode_KeepInputFile); // ... use selection ... IGFD_Selection_DestroyContent(&selection); ``` -------------------------------- ### AppendToBuffer Example Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/Utils-FileStyle.md Appends 'World!' to a pre-initialized buffer containing 'Hello '. ```cpp char buffer[256] = "Hello "; IGFD::Utils::AppendToBuffer(buffer, sizeof(buffer), "World!"); // buffer now contains "Hello World!" ``` -------------------------------- ### Example: Using UserDatas for Context Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/types.md Demonstrates how to create and pass a custom context structure using UserDatas. The context can be retrieved within dialog callbacks to access application-specific state. ```cpp struct MyContext { int selectionMode; std::string lastPath; }; MyContext* ctx = new MyContext(); config.userDatas = ctx; // In side pane: MyContext* appCtx = (MyContext*)ImGuiFileDialog::Instance()->GetUserDatas(); ``` -------------------------------- ### Get Active FileSystem Name Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/FileManager.md Returns the name of the currently active filesystem implementation. ```cpp const std::string& GetFileSystemName() const ``` -------------------------------- ### Get FileSystem Instance Pointer Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/FileManager.md Retrieves a pointer to the IFileSystem implementation. Returns nullptr if the default filesystem is being used. ```cpp IFileSystem* GetFileSystemInstance() const ``` -------------------------------- ### Get Default IGFD_FileDialog_Config Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/C-API.md Retrieves a zero-initialized configuration structure with default values. Customize this structure before passing it to IGFD_OpenDialog. ```c struct IGFD_FileDialog_Config IGFD_FileDialog_Config_Get(void) ``` -------------------------------- ### Filter Syntax Examples Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/INDEX.md Illustrates different formats for defining file filters, including simple extensions, named groups, regex patterns, and mixed combinations. Choose the format that best suits your filtering needs. ```text ".cpp,.h,.hpp" ``` ```text "C++ Source{.cpp,.cc,.cxx},Headers{.h,.hpp}" ``` ```text "Source{.cpp,((.*\.cpp))}" ``` ```text "C++ Source{.cpp,.h},Images{.png,.jpg,((.*\.jpg))},.*" ``` -------------------------------- ### Multi-Layer Asterisk Filter Examples Source: https://github.com/aiekick/imguifiledialog/blob/master/Documentation.md Demonstrates multi-layer filtering using asterisks, allowing for flexible pattern matching like '.a.b.c' or '.*.filters'. These are internally converted to regex. ```cpp .a.b.c .json.cpp .vcxproj.filters .* .*.* .vcx.* .*.filters .vcx*.filt.* ``` -------------------------------- ### Enable Keyboard Navigation by Keys Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/configuration.md Enable file list navigation using arrow keys, Enter, Backspace, and character search. Allows jumping to files by typing their starting letter. ```cpp // #define USE_EXPLORATION_BY_KEYS ``` -------------------------------- ### Get Selected Files Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/FileDialog.md Retrieves all selected files in a multi-selection dialog. Returns a map where keys are filenames and values are their full paths. ```cpp std::map GetSelection(IGFD_ResultMode vFlag = IGFD_ResultMode_KeepInputFile) ``` ```cpp auto selection = ImGuiFileDialog::Instance()->GetSelection(); for (auto& file : selection) { std::cout << "Selected: " << file.first << " at " << file.second << std::endl; } ``` -------------------------------- ### Error Handling Examples Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/INDEX.md Illustrates error handling techniques using return values and state queries, avoiding exceptions. This includes checking dialog results, operation success, and managing C API memory. ```cpp // Check dialog result if (!ImGuiFileDialog::Instance()->IsOk()) { std::cout << "User cancelled dialog" << std::endl; return; } // Check operations if (!fileManager.CreateDir(path)) { std::cerr << "Failed to create directory" << std::endl; } // C API: free allocated strings char* path = IGFD_GetFilePathName(ctx, IGFD_ResultMode_KeepInputFile); if (path != NULL) { use_path(path); free(path); // IMPORTANT: must free } ``` -------------------------------- ### Open File Dialog with Custom Filters Source: https://github.com/aiekick/imguifiledialog/blob/master/Documentation.md Example of opening a file dialog with a custom filter string that includes named groups and regex patterns. The dialog is configured with a path and a key. ```cpp const char *filters = "Source files (*.cpp *.h *.hpp){.cpp,.h,.hpp},Image files (*.png *.gif *.jpg *.jpeg){.png,.gif,.jpg,.jpeg},.md"; IGFD::FileDialogConfig config; config.path = "."; ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", ICON_IMFDLG_FOLDER_OPEN " Choose a File", filters, config); ``` -------------------------------- ### Regex Filtering Example Source: https://github.com/aiekick/imguifiledialog/blob/master/Documentation.md Use regex patterns enclosed in double parentheses to filter files. This example shows filtering for files starting with 'Custom' and ending with '.h'. ```cpp ex : "((Custom.+[.]h))" ``` -------------------------------- ### Get Default IGFD_Selection Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/C-API.md Returns a zero-initialized IGFD_Selection structure. This is the starting point for managing multiple file selections. ```c IGFD_Selection IGFD_Selection_Get(void) ``` -------------------------------- ### Build Sample App with CMake Source: https://github.com/aiekick/imguifiledialog/blob/master/README.md Instructions for building the ImGuiFileDialog sample application using CMake on Windows, Linux, and macOS. Requires specifying a build directory and build type. ```bash cmake -B my_build_directory -DCMAKE_BUILD_TYPE=BuildMode cmake --build my_build_directory --config BuildMode ``` -------------------------------- ### Enable Quick Path Selection Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/configuration.md Enable clicking path separators (/) to open a popup showing sibling directories. ```cpp // #define USE_QUICK_PATH_SELECT ``` -------------------------------- ### Open and Display a Simple File Dialog Source: https://github.com/aiekick/imguifiledialog/blob/master/Documentation.md This snippet shows how to open a basic file selection dialog and handle user actions upon confirmation. Ensure ImGui is initialized before use. ```cpp void drawGui() { // open Dialog Simple if (ImGui::Begin("##OpenDialogCommand")) { if (ImGui::Button("Open File Dialog")) { IGFD::FileDialogConfig config; config.path = "."; ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".cpp,.h,.hpp", config); } ) ImGui::End(); // display if (ImGuiFileDialog::Instance()->Display("ChooseFileDlgKey")) { // => will show a dialog if (ImGuiFileDialog::Instance()->IsOk()) { // action if OK std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName(); std::string filePath = ImGuiFileDialog::Instance()->GetCurrentPath(); // action } // close ImGuiFileDialog::Instance()->Close(); } } ``` -------------------------------- ### FileStyle Constructor with Parameters Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/Utils-FileStyle.md Initializes a FileStyle object with specified color, icon, and font. ```cpp FileStyle(const ImVec4& vColor, const std::string& vIcon = "", ImFont* vFont = nullptr) ``` -------------------------------- ### Singleton Pattern Usage Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/INDEX.md Demonstrates the recommended way to use ImGuiFileDialog as a singleton instance for managing a single dialog. This pattern simplifies access and state management. ```cpp ImGuiFileDialog::Instance()->OpenDialog(...); if (ImGuiFileDialog::Instance()->Display(...)) { // Handle result } ``` -------------------------------- ### GetResultingFilePathName Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/FileManager.md Gets the full path including the filename. ```APIDOC ## GetResultingFilePathName ### Description Gets the full path with filename. ### Method std::string ### Parameters #### Path Parameters - **vFileDialogInternal** (FileDialogInternal&) - Required - Dialog context - **vFlag** (IGFD_ResultMode) - Required - Extension handling mode (AddIfNoFileExt, OverwriteFileExt, KeepInputFile) ### Returns Full file path with name ``` -------------------------------- ### Add ImGuiFileDialog to Project Source: https://github.com/aiekick/imguifiledialog/blob/master/README.md Integrate ImGuiFileDialog by cloning the repository into your project's library directory and adding its source file to your build system. ```bash mkdir lib cd lib git clone https://github.com/aiekick/ImGuiFileDialog.git git checkout master ``` -------------------------------- ### GetResultingFileName Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/FileManager.md Gets the filename with extension handling controlled by a specified flag. ```APIDOC ## GetResultingFileName ### Description Gets the filename with extension handling controlled by vFlag. ### Method std::string ### Parameters #### Path Parameters - **vFileDialogInternal** (FileDialogInternal&) - Required - Dialog context - **vFlag** (IGFD_ResultMode) - Required - Extension handling mode (AddIfNoFileExt, OverwriteFileExt, KeepInputFile) ### Returns Processed filename ``` -------------------------------- ### Styling Files by Extension and Size Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/INDEX.md Demonstrates how to style files based on their extension or size using predefined styles or lambda functions. Use this to visually differentiate file types or highlight large files. ```cpp // Method 1: Predefined style ImGuiFileDialog::Instance()->SetFileStyle( IGFD_FileStyleByExtention, ".cpp", ImVec4(1.0f, 1.0f, 0.0f, 0.9f), "C++"); // Method 2: Lambda function ImGuiFileDialog::Instance()->SetFileStyle( [](const IGFD::FileInfos& file, IGFD::FileStyle& style) { if (file.fileSize > 100000000) { style.color = ImVec4(1.0f, 0.0f, 0.0f, 0.9f); return true; } return false; }); ``` -------------------------------- ### C++ Usage Pattern for ImGuiFileDialog Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/INDEX.md Demonstrates the basic workflow for opening and displaying a file dialog in C++. Ensure the ImGuiFileDialog instance is managed correctly. ```cpp // 1. Open dialog IGFD::FileDialogConfig config; config.path = "."; ImGuiFileDialog::Instance()->OpenDialog("key", "Title", ".cpp,.h", config); // 2. Display in main loop if (ImGuiFileDialog::Instance()->Display("key")) { if (ImGuiFileDialog::Instance()->IsOk()) { std::string path = ImGuiFileDialog::Instance()->GetFilePathName(); // Process selection } ImGuiFileDialog::Instance()->Close(); } ``` -------------------------------- ### C Usage Pattern for ImGuiFileDialog Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/INDEX.md Illustrates the C API for creating, configuring, opening, and displaying a file dialog. Remember to free the returned path string and destroy the dialog instance when done. ```c // 1. Create and configure ImGuiFileDialog* pDialog = IGFD_Create(); IGFD_FileDialog_Config config = IGFD_FileDialog_Config_Get(); config.path = "."; IGFD_OpenDialog(pDialog, "key", "Title", ".cpp,.h", config); // 2. Display in main loop if (IGFD_DisplayDialog(pDialog, "key", 0, (ImVec2){400,300}, (ImVec2){1200,800})) { if (IGFD_IsOk(pDialog)) { char* path = IGFD_GetFilePathName(pDialog, IGFD_ResultMode_KeepInputFile); printf("Selected: %s\n", path); free(path); } IGFD_CloseDialog(pDialog); } // 3. Cleanup IGFD_Destroy(pDialog); ``` -------------------------------- ### GetFilterComboBoxWidth Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/FilterManager.md Gets the calculated width for the filter selection combobox. This is useful for layout purposes. ```cpp float GetFilterComboBoxWidth() const ``` -------------------------------- ### Include Custom Configuration Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/configuration.md Include the ImGuiFileDialog header after defining your custom configuration file path. ```cpp #define CUSTOM_IMGUIFILEDIALOG_CONFIG "CustomImGuiFileDialogConfig.h" #include "ImGuiFileDialog.h" ``` -------------------------------- ### Get Current Filter Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/C-API.md Retrieves the currently selected filter. The returned string must be freed by the caller. ```c char* IGFD_GetCurrentFilter(ImGuiFileDialog* vContextPtr) ``` -------------------------------- ### Get Current Filename Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/C-API.md Retrieves just the filename without the path. The returned string must be freed by the caller. ```c char* IGFD_GetCurrentFileName( ImGuiFileDialog* vContextPtr, IGFD_ResultMode vMode) ``` -------------------------------- ### Get Default IGFD_Selection_Pair Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/C-API.md Returns a zero-initialized IGFD_Selection_Pair structure. This is useful for creating new selection entries. ```c IGFD_Selection_Pair IGFD_Selection_Pair_Get(void) ``` -------------------------------- ### Core APIs Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/INDEX.md A quick overview of the main entry point APIs for interacting with the file dialog in both C++ and C. ```APIDOC ## Core APIs at a Glance ### Main Entry Points | API | Purpose | C++ Class | C Function | |---|---|---|---| | Open dialog | Create file selection | `FileDialog::OpenDialog()` | `IGFD_OpenDialog()` | | Display | Render dialog | `FileDialog::Display()` | `IGFD_DisplayDialog()` | | Check result | Dialog closed with OK | `FileDialog::IsOk()` | `IGFD_IsOk()` | | Get selection | Single or multiple files | `FileDialog::GetSelection()` | `IGFD_GetSelection()` | | Get path | Full path with filename | `FileDialog::GetFilePathName()` | `IGFD_GetFilePathName()` | | Close | Clean up dialog | `FileDialog::Close()` | `IGFD_CloseDialog()` | ``` -------------------------------- ### Get Current Directory Path Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/FileDialog.md Retrieves the path of the current working directory being displayed or used by the dialog. ```cpp std::string GetCurrentPath() ``` ```cpp std::string dir = ImGuiFileDialog::Instance()->GetCurrentPath(); // Result: "/home/user/documents" ``` -------------------------------- ### Open and Display File Dialog Source: https://github.com/aiekick/imguifiledialog/blob/master/README.md Demonstrates how to open a file dialog with specific filters and display it. Includes actions for when the dialog is confirmed or closed. ```cpp void drawGui() { // open Dialog Simple if (ImGui::Button("Open File Dialog")) { IGFD::FileDialogConfig config; config.path = "."; ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".cpp,.h,.hpp", config); } // display if (ImGuiFileDialog::Instance()->Display("ChooseFileDlgKey")) { if (ImGuiFileDialog::Instance()->IsOk()) { // action if OK std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName(); std::string filePath = ImGuiFileDialog::Instance()->GetCurrentPath(); // action } // close ImGuiFileDialog::Instance()->Close(); } } ``` -------------------------------- ### Get Current Path Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/C-API.md Retrieves the current working directory path. The returned string must be freed by the caller. ```c char* IGFD_GetCurrentPath(ImGuiFileDialog* vContextPtr) ``` -------------------------------- ### Get Current Filter Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/FileDialog.md Returns the currently selected file filter, such as an extension like ".cpp". ```cpp std::string GetCurrentFilter() ``` -------------------------------- ### Enable Custom Filesystem API Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/configuration.md Enable to use a custom IFileSystem implementation instead of built-in dirent/std::filesystem. Use when implementing custom filesystem backends. ```cpp // #define USE_CUSTOM_FILESYSTEM ``` -------------------------------- ### Enable Standard Filesystem API (C++17) Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/configuration.md Use std::filesystem (C++17) instead of the dirent API. Requires a C++17 compiler. ```cpp // #define USE_STD_FILESYSTEM ``` ```cpp #define USE_STD_FILESYSTEM #include "ImGuiFileDialog.h" ``` -------------------------------- ### Get Selected Files from Dialog Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/C-API.md Retrieves all selected files from a multi-selection dialog. Remember to free the content using `IGFD_Selection_DestroyContent`. ```c IGFD_Selection IGFD_GetSelection( ImGuiFileDialog* vContextPtr, IGFD_ResultMode vMode) ``` ```c IGFD_Selection selection = IGFD_GetSelection(pFileDialog, IGFD_ResultMode_KeepInputFile); for (size_t i = 0; i < selection.count; i++) { printf("File: %s\n", selection.table[i].fileName); printf("Path: %s\n", selection.table[i].filePathName); } IGFD_Selection_DestroyContent(&selection); ``` -------------------------------- ### Get User Data Pointer Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/C-API.md Retrieves the user data pointer from the dialog configuration. The returned pointer should be cast to the appropriate type. ```c void* IGFD_GetUserDatas(ImGuiFileDialog* vContextPtr) ``` ```c int* user_data = (int*)IGFD_GetUserDatas(pFileDialog); ``` -------------------------------- ### Get Current File Name Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/FileDialog.md Extracts and returns only the filename, excluding the path. The handling of file extensions is influenced by the vFlag parameter. ```cpp std::string GetCurrentFileName(IGFD_ResultMode vFlag = IGFD_ResultMode_AddIfNoFileExt) ``` -------------------------------- ### Multiple Instances Usage Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/INDEX.md Shows how to manage multiple independent file dialog instances. This is useful when you need to display several dialogs concurrently or with different configurations. ```cpp FileDialog dialog1, dialog2; dialog1.OpenDialog(...); dialog2.OpenDialog(...); if (dialog1.Display(...)) { /* handle */ } if (dialog2.Display(...)) { /* handle */ } ``` -------------------------------- ### Get Currently Open Dialog Key Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/FileDialog.md Retrieves the key of the dialog that is currently open. Returns an empty string if no dialog is active. ```cpp std::string GetOpenedKey() const ``` -------------------------------- ### Get Path Filtered List Size Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/FileManager.md Returns the count of directories that match the current filter criteria. Used when selecting directories. ```cpp size_t GetPathFilteredListSize() const ``` -------------------------------- ### FileStyle Default Constructor Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/Utils-FileStyle.md Creates a FileStyle object with default transparent color, empty icon, and default ImGui font. ```cpp FileStyle() ``` -------------------------------- ### Enable Thumbnails Feature Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/configuration.md Enable thumbnail image preview support. Requires stb_image.h and stb_image_resize.h. ```cpp // #define USE_THUMBNAILS ``` -------------------------------- ### C API: Create, Open, Display, and Process File Dialog Source: https://github.com/aiekick/imguifiledialog/blob/master/Documentation.md This snippet demonstrates the complete lifecycle of using ImGuiFileDialog in C. It covers creating the dialog, configuring its properties (like path and flags), opening it with a title and filter, displaying it within ImGui, and handling the results (file path, current path, filter, user data, and selections) when the dialog is confirmed or closed. Remember to free allocated strings and destroy the dialog instance. ```c // create ImGuiFileDialog ImGuiFileDialog *cfileDialog = IGFD_Create(); // open dialog if (igButton("Open File", buttonSize)) { IGFD_FileDialog_Config config = IGFD_FileDialog_Config_Get(); config.path = "."; config.flags = ImGuiFileDialogFlags_ConfirmOverwrite; // ImGuiFileDialogFlags IGFD_OpenDialog(cfiledialog, "filedlg", // dialog key (make it possible to have different treatment reagrding the dialog key "Open a File", // dialog title "c files(*.c *.h){.c,.h}", // dialog filter syntax : simple => .h,.c,.pp, etc and collections : text1{filter0,filter1,filter2}, text2{filter0,filter1,filter2}, etc.. config); * ImGuiFileDialogFlags_NaturalSorting: The supported number format is the same as [strtod](https://cplusplus.com/reference/cstdlib/strtod/) function. This flag enables natural sorting, which sorts files and directories in a more human-readable way (e.g., 'file10.txt' comes after 'file2.txt'). It is optional and can be enabled with the flag ImGuiFileDialogFlags_NaturalSorting. This sorting method is slower than the base sorting. ``` -------------------------------- ### Get Full Path with Filename Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/C-API.md Retrieves the full path including the filename for save dialogs. The returned string must be freed by the caller. ```c char* IGFD_GetFilePathName( ImGuiFileDialog* vContextPtr, IGFD_ResultMode vMode) ``` ```c char* path = IGFD_GetFilePathName(pFileDialog, IGFD_ResultMode_AddIfNoFileExt); printf("Save to: %s\n", path); free(path); ``` -------------------------------- ### Add Places and Separators to ImGuiFileDialog Source: https://github.com/aiekick/imguifiledialog/blob/master/Documentation.md Demonstrates how to add custom places with optional styles and separators to the ImGuiFileDialog interface. This allows users to quickly navigate to frequently used directories. ```cpp // for the moment the style support only the icon, can be extended if user needed in futur places_ptr->AddPlace(place_name, place_path, can_be_saved, style); // you can also add a separator places_ptr->AddPlaceSeparator(separator_thickness); ``` -------------------------------- ### Get User Data Pointer Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/FileDialog.md Retrieves the user-defined data pointer that was passed during the FileDialogConfig initialization. This allows for custom data association with the dialog. ```cpp UserDatas GetUserDatas() const ``` -------------------------------- ### Get Current Working Directory Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/FileManager.md Retrieves the current working directory path as a string. This is the base path from which file operations are often initiated. ```cpp std::string GetCurrentPath() ``` -------------------------------- ### Get Filtered List Size Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/FileManager.md Retrieves the number of files currently visible in the filtered or displayed list. This count is affected by active filters. ```cpp size_t GetFilteredListSize() const ``` -------------------------------- ### Styling Files and Directories in ImGuiFileDialog Source: https://github.com/aiekick/imguifiledialog/blob/master/Documentation.md Define styles for file extensions, directory types, and specific file names. This includes setting custom colors, icons, and text labels for different file types and directory patterns. It also shows how to combine different styling types. ```cpp ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtention, ".png", ImVec4(0.0f, 1.0f, 1.0f, 0.9f), ICON_IGFD_FILE_PIC, font1); ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtention, ".gif", ImVec4(0.0f, 1.0f, 0.5f, 0.9f), "[GIF]"); // define style for all directories ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeDir, "", ImVec4(0.5f, 1.0f, 0.9f, 0.9f), ICON_IGFD_FOLDER); // can be for a specific directory ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeDir, ".git", ImVec4(0.5f, 1.0f, 0.9f, 0.9f), ICON_IGFD_FOLDER); // define style for all files ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeFile, "", ImVec4(0.5f, 1.0f, 0.9f, 0.9f), ICON_IGFD_FILE); // can be for a specific file ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeFile, ".git", ImVec4(0.5f, 1.0f, 0.9f, 0.9f), ICON_IGFD_FILE); // define style for all links ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeLink, "", ImVec4(0.5f, 1.0f, 0.9f, 0.9f)); // can be for a specific link ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeLink, "Readme.md", ImVec4(0.5f, 1.0f, 0.9f, 0.9f)); // define style for any files/dirs/links by fullname ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByFullName, "doc", ImVec4(0.9f, 0.2f, 0.0f, 0.9f), ICON_IGFD_FILE_PIC); // define style by file who are containing this string ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByContainedInFullName, ".git", ImVec4(0.9f, 0.2f, 0.0f, 0.9f), ICON_IGFD_BOOKMARK); all of theses can be miwed with IGFD_FileStyleByTypeDir / IGFD_FileStyleByTypeFile / IGFD_FileStyleByTypeLink like theses by ex : ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeDir | IGFD_FileStyleByContainedInFullName, ".git", ImVec4(0.9f, 0.2f, 0.0f, 0.9f), ICON_IGFD_BOOKMARK); ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeFile | IGFD_FileStyleByFullName, "cmake", ImVec4(0.5f, 0.8f, 0.5f, 0.9f), ICON_IGFD_SAVE); // for all these,s you can use a regex // ex for color files like Custom*.h ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByFullName, "((Custom.+[.]h))", ImVec4(0.0f, 1.0f, 1.0f, 0.9f), ICON_IGFD_FILE_PIC, font1); // lambda function // set file style with a lambda function // return true is a file style was defined ImGuiFileDialog::Instance()->SetFileStyle([](const IGFD::FileInfos& vFile, IGFD::FileStyle &vOutStyle) -> bool { if (!vFile.fileNameExt.empty() && vFile.fileNameExt[0] == ".") { vOutStyle = IGFD::FileStyle(ImVec4(0.0f, 0.9f, 0.9f, 1.0f), ICON_IGFD_REMOVE); return true; } return false; }); ``` -------------------------------- ### Get Path Composer Size Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/FileManager.md Retrieves the number of path elements currently stored in the path composer. Indicates the depth of the current path. ```cpp size_t GetComposerSize() const ``` -------------------------------- ### Open Dialog with Regex Filter Source: https://github.com/aiekick/imguifiledialog/blob/master/Documentation.md Demonstrates opening a file dialog with a simple regex filter to select custom header files. ```cpp OpenDialog("toto", "Choose File", "((Custom.+[.]h))"); ``` -------------------------------- ### IGFD_FileDialog_Config_Get Function Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/C-API.md Retrieves a default, zero-initialized configuration structure for the file dialog. This is useful for setting custom configurations starting from a known state. ```APIDOC ## IGFD_FileDialog_Config_Get ### Description Returns a zero-initialized config structure with default values. ### Returns - Initialized config with defaults ### Example ```c IGFD_FileDialog_Config config = IGFD_FileDialog_Config_Get(); config.path = "./documents"; config.countSelectionMax = 1; config.flags = ImGuiFileDialogFlags_Modal; ``` ``` -------------------------------- ### Display Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/FileDialog.md Renders the file dialog window for a given key and handles user interactions. Returns true when the user has confirmed or cancelled the dialog. ```APIDOC ## Display ### Description Renders the file dialog UI for a specified key. This method should be called every frame to keep the dialog interactive. It returns `true` when the user has made a selection (OK) or cancelled the dialog, allowing for result processing. ### Method ```cpp bool Display( const std::string& vKey, ImGuiWindowFlags vFlags = ImGuiWindowFlags_NoCollapse, ImVec2 vMinSize = ImVec2(0, 0), ImVec2 vMaxSize = ImVec2(FLT_MAX, FLT_MAX) ) ``` ### Parameters #### Path Parameters - **vKey** (const std::string&) - Required - The unique identifier of the dialog to display. This must match the key provided when calling `OpenDialog`. - **vFlags** (ImGuiWindowFlags) - Optional - Flags to customize the appearance and behavior of the ImGui window. Defaults to `ImGuiWindowFlags_NoCollapse`. - **vMinSize** (ImVec2) - Optional - The minimum dimensions (width, height) for the dialog window. Defaults to (0, 0). - **vMaxSize** (ImVec2) - Optional - The maximum dimensions (width, height) for the dialog window. Defaults to (`FLT_MAX`, `FLT_MAX`). ### Returns - bool - `true` if the dialog received user input (OK or Cancel) this frame, `false` otherwise (dialog is still open and interactive). ### Example ```cpp if (ImGuiFileDialog::Instance()->Display("ChooseFile")) { if (ImGuiFileDialog::Instance()->IsOk()) { std::string path = ImGuiFileDialog::Instance()->GetFilePathName(); // Process selection } ImGuiFileDialog::Instance()->Close(); } ``` ``` -------------------------------- ### Get Directory from Filtered Path List Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/FileManager.md Retrieves a specific directory from the filtered path list using its index. Returns a shared pointer to FileInfos. ```cpp std::shared_ptr GetFilteredPathAt(size_t vIdx) ``` -------------------------------- ### Custom File System Interface Source: https://github.com/aiekick/imguifiledialog/blob/master/Documentation.md Implement a custom file system by overriding the IFileSystem interface and defining the FILE_SYSTEM_OVERRIDE macro. Specify the include path using CUSTOM_FILESYSTEM_INCLUDE. ```cpp #define FILE_SYSTEM_OVERRIDE FileSystemBoost #define CUSTOM_FILESYSTEM_INCLUDE "src/FileSystemBoost.hpp" ``` -------------------------------- ### C API Usage Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/INDEX.md Demonstrates the typical usage pattern for opening, displaying, and processing a file dialog using the C API. ```APIDOC ## C API Usage ### Description This snippet shows how to use the C API to create, configure, open, display, and handle the result of a file selection dialog. ### Usage Pattern ```c // 1. Create and configure ImGuiFileDialog* pDialog = IGFD_Create(); IGFD_FileDialog_Config config = IGFD_FileDialog_Config_Get(); config.path = "."; IGFD_OpenDialog(pDialog, "key", "Title", ".cpp,.h", config); // 2. Display in main loop if (IGFD_DisplayDialog(pDialog, "key", 0, (ImVec2){400,300}, (ImVec2){1200,800})) { if (IGFD_IsOk(pDialog)) { char* path = IGFD_GetFilePathName(pDialog, IGFD_ResultMode_KeepInputFile); printf("Selected: %s\n", path); free(path); } IGFD_CloseDialog(pDialog); } // 3. Cleanup IGFD_Destroy(pDialog); ``` ``` -------------------------------- ### Get File from Filtered List Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/FileManager.md Retrieves a specific file from the currently filtered or displayed list using its index. Returns a shared pointer to FileInfos. ```cpp std::shared_ptr GetFilteredFileAt(size_t vIdx) ``` -------------------------------- ### SelectDirectory Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/FileManager.md Opens or enters a specified directory. ```APIDOC ## SelectDirectory ### Description Opens/enters a directory. ### Method bool ### Parameters #### Path Parameters - **vInfos** (const std::shared_ptr&) - Required - Directory to enter ### Returns `true` if successful ``` -------------------------------- ### File Coloring with Regex Source: https://github.com/aiekick/imguifiledialog/blob/master/Documentation.md Applies a specific color (yellow) to files matching a regex pattern, here targeting files starting with 'Custom' and ending with '.h'. ```cpp SetFileStyle(IGFD_FileStyleByFullName, "((Custom.+[.]h))", ImVec4(1.0f, 1.0f, 0.0f, 0.9f)); ``` -------------------------------- ### Handling Non-Existent Paths During Navigation Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/errors.md Attempting to set or open a non-existent path can lead to an empty file list. It's crucial to check for directory existence before navigating. ```cpp fileManager.SetCurrentPath("/non/existent/path"); fileManager.OpenCurrentPath(internalDialog); // Handling: if (!fileSystem->IsDirectoryExist("/path")) { std::cerr << "Path does not exist" << std::endl; // Keep current path or navigate to home } ``` -------------------------------- ### Get OS-Specific Path Separator Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/Utils-FileStyle.md Retrieves the appropriate path separator for the current operating system. Use this to construct paths that are portable across different OS. ```cpp static std::string GetPathSeparator() std::string sep = IGFD::Utils::GetPathSeparator(); // "/" on Unix std::string path = "home" + sep + "user" + sep + "file.txt"; ``` -------------------------------- ### Get Full File List Size Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/api-reference/FileManager.md Returns the total count of files in the complete, unfiltered file list. This represents all files found in the current directory. ```cpp size_t GetFullFileListSize() const ``` -------------------------------- ### Custom Filesystem Interface Source: https://github.com/aiekick/imguifiledialog/blob/master/_autodocs/INDEX.md Defines the `IFileSystem` interface for implementing custom filesystem backends. This allows ImGuiFileDialog to interact with non-standard storage or access methods. ```cpp class MyFileSystem : public IGFD::IFileSystem { public: bool IsDirectoryExist(const std::string& vName) override { /* ... */ } bool IsFileExist(const std::string& vName) override { /* ... */ } bool CreateDirectoryIfNotExist(const std::string& vName) override { /* ... */ } bool IsDirectory(const std::string& vPath) override { /* ... */ } bool IsDirectoryCanBeOpened(const std::string& vName) override { /* ... */ } std::vector ScanDirectory(const std::string& vPath) override { /* ... */ } std::vector GetDevicesList() override { /* ... */ } IGFD::Utils::PathStruct ParsePathFileName(const std::string& vPath) override { /* ... */ } void GetFileDateAndSize(const std::string& vPath, const IGFD::FileType& vType, std::string& voDate, size_t& voSize) override { /* ... */ } }; ```