| 1 |
[](https://github.com/aiekick/ImGuiFileDialog/actions/workflows/Win.yml) |
| 2 |
[](https://github.com/aiekick/ImGuiFileDialog/actions/workflows/Linux.yml) |
| 3 |
[](https://github.com/aiekick/ImGuiFileDialog/actions/workflows/Osx.yml) |
| 4 |
[](https://github.com/ocornut/imgui) |
| 5 |
|
| 6 |
# ImGuiFileDialog |
| 7 |
|
| 8 |
## Purpose |
| 9 |
|
| 10 |
ImGuiFileDialog is a file selection dialog built for (and using only) [Dear ImGui](https://github.com/ocornut/imgui). |
| 11 |
|
| 12 |
My primary goal was to have a custom pane with widgets according to file extension. This was not possible using other |
| 13 |
solutions. |
| 14 |
|
| 15 |
## ImGui Supported Version |
| 16 |
|
| 17 |
ImGuiFileDialog follow the master and docking branch of ImGui . currently ImGui 1.90 |
| 18 |
|
| 19 |
## Structure |
| 20 |
|
| 21 |
* The library is in [Master branch](https://github.com/aiekick/ImGuiFileDialog/tree/master) |
| 22 |
* A demo app can be found in the [DemoApp branch](https://github.com/aiekick/ImGuiFileDialog/tree/DemoApp) |
| 23 |
|
| 24 |
This library is designed to be dropped into your source code rather than compiled separately. |
| 25 |
|
| 26 |
From your project directory: |
| 27 |
|
| 28 |
``` |
| 29 |
mkdir lib <or 3rdparty, or externals, etc.> |
| 30 |
cd lib |
| 31 |
git clone https://github.com/aiekick/ImGuiFileDialog.git |
| 32 |
git checkout master |
| 33 |
``` |
| 34 |
|
| 35 |
These commands create a `lib` directory where you can store any third-party dependencies used in your project, downloads |
| 36 |
the ImGuiFileDialog git repository and checks out the Lib_Only branch where the actual library code is located. |
| 37 |
|
| 38 |
Add `lib/ImGuiFileDialog/ImGuiFileDialog.cpp` to your build system and include |
| 39 |
`lib/ImGuiFileDialog/ImGuiFileDialog.h` in your source code. ImGuiFileLib will compile with and be included directly in |
| 40 |
your executable file. |
| 41 |
|
| 42 |
If, for example, your project uses cmake, look for a line like `add_executable(my_project_name main.cpp)` |
| 43 |
and change it to `add_executable(my_project_name lib/ImGuiFileDialog/ImGuiFileDialog.cpp main.cpp)`. This tells the |
| 44 |
compiler where to find the source code declared in `ImGuiFileDialog.h` which you included in your own source code. |
| 45 |
|
| 46 |
## Requirements: |
| 47 |
|
| 48 |
You must also, of course, have added [Dear ImGui](https://github.com/ocornut/imgui) to your project for this to work at |
| 49 |
all. |
| 50 |
|
| 51 |
[dirent v1.23](https://github.com/tronkko/dirent/tree/v1.23) is required to use ImGuiFileDialog under Windows. It is |
| 52 |
included in the Lib_Only branch for your convenience. |
| 53 |
|
| 54 |
Android Requirements : Api 21 mini |
| 55 |
|
| 56 |
## Features |
| 57 |
|
| 58 |
- C Api (succesfully tested with CimGui) |
| 59 |
- Separate system for call and display |
| 60 |
- Can have many function calls with different parameters for one display function, for example |
| 61 |
- Can create a custom pane with any widgets via function binding |
| 62 |
- This pane can block the validation of the dialog |
| 63 |
- Can also display different things according to current filter and UserDatas |
| 64 |
- Advanced file style for file/dir/link coloring / icons / font |
| 65 |
- predefined form or user custom form by lambda function (the lambda mode is not available for the C API) |
| 66 |
- Multi-selection (ctrl/shift + click) : |
| 67 |
- 0 => Infinite |
| 68 |
- 1 => One file (default) |
| 69 |
- n => n files |
| 70 |
- Compatible with MacOs, Linux, Windows |
| 71 |
- Windows version can list drives |
| 72 |
- Supports modal or standard dialog types |
| 73 |
- Select files or directories |
| 74 |
- Filter groups and custom filter names |
| 75 |
- can ignore filter Case for file searching |
| 76 |
- Keyboard navigation (arrows, backspace, enter) |
| 77 |
- Exploring by entering characters (case insensitive) |
| 78 |
- Directory bookmarks |
| 79 |
- Directory manual entry (right click on any path element) |
| 80 |
- Optional 'Confirm to Overwrite" dialog if file exists |
| 81 |
- Thumbnails Display (agnostic way for compatibility with any backend, sucessfully tested with OpenGl and Vulkan) |
| 82 |
- The dialog can be embedded in another user frame than the standard or modal dialog |
| 83 |
- Can tune validation buttons (placements, widths, inversion) |
| 84 |
- Can quick select a parrallel directory of a path, in the path composer (when you clikc on a / you have a popup) |
| 85 |
- regex support for filters, collection of filters and filestyle (the regex is recognized when between (( and )) in a filter) |
| 86 |
- multi layer extentions like : .a.b.c .json.cpp .vcxproj.filters etc.. |
| 87 |
- advanced behavior regarding asterisk based filter. like : .* .*.* .vcx.* .*.filters .vcs*.filt.* etc.. (internally regex is used) |
| 88 |
- result modes GetFilePathName, GetFileName and GetSelection (overwrite file ext, keep file, add ext if no user ext exist) |
| 89 |
|
| 90 |
### WARNINGS : |
| 91 |
- the nav system keyboard behavior is not working as expected, so maybe full of bug for ImGuiFileDialog |
| 92 |
|
| 93 |
### Filter format |
| 94 |
|
| 95 |
A filter is recognized only if it respects theses rules : |
| 96 |
|
| 97 |
0) a filter must have 2 chars mini and the first must be a . |
| 98 |
1) a regex must be in (( and )) |
| 99 |
2) a , will separate filters except if between a ( and ) |
| 100 |
3) name{filter1, filter2} is a special form for collection filters |
| 101 |
3.1) the name can be composed of what you want except { and } |
| 102 |
3.2) a filter can be a regex |
| 103 |
4) the filters cannot integrate these chars '(' ')' '{' '}' ' ' except for a regex with respect to rule 1) |
| 104 |
5) the filters cannot integrate a ',' |
| 105 |
|
| 106 |
<details open><summary><h2>Singleton Pattern vs. Multiple Instances :</h2></summary><blockquote> |
| 107 |
|
| 108 |
### Single Dialog : |
| 109 |
|
| 110 |
If you only need to display one file dialog at a time, use ImGuiFileDialog's singleton pattern to avoid explicitly |
| 111 |
declaring an object: |
| 112 |
|
| 113 |
```cpp |
| 114 |
ImGuiFileDialog::Instance()->method_of_your_choice(); |
| 115 |
``` |
| 116 |
|
| 117 |
### Multiple Dialogs : |
| 118 |
|
| 119 |
If you need to have multiple file dialogs open at once, declare each dialog explicity: |
| 120 |
|
| 121 |
```cpp |
| 122 |
ImGuiFileDialog instance_a; |
| 123 |
instance_a.method_of_your_choice(); |
| 124 |
ImGuiFileDialog instance_b; |
| 125 |
instance_b.method_of_your_choice(); |
| 126 |
``` |
| 127 |
|
| 128 |
</blockquote></details> |
| 129 |
|
| 130 |
<details open><summary><h2>Simple Dialog :</h2></summary><blockquote> |
| 131 |
|
| 132 |
```cpp |
| 133 |
void drawGui() |
| 134 |
{ |
| 135 |
// open Dialog Simple |
| 136 |
if (ImGui::Button("Open File Dialog")) |
| 137 |
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".cpp,.h,.hpp", "."); |
| 138 |
|
| 139 |
// display |
| 140 |
if (ImGuiFileDialog::Instance()->Display("ChooseFileDlgKey")) |
| 141 |
{ |
| 142 |
// action if OK |
| 143 |
if (ImGuiFileDialog::Instance()->IsOk()) |
| 144 |
{ |
| 145 |
std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName(); |
| 146 |
std::string filePath = ImGuiFileDialog::Instance()->GetCurrentPath(); |
| 147 |
// action |
| 148 |
} |
| 149 |
|
| 150 |
// close |
| 151 |
ImGuiFileDialog::Instance()->Close(); |
| 152 |
} |
| 153 |
} |
| 154 |
``` |
| 155 |
|
| 156 |
 |
| 157 |
|
| 158 |
</blockquote></details> |
| 159 |
|
| 160 |
<details open><summary><h2>Modal Dialog :</h2></summary><blockquote> |
| 161 |
|
| 162 |
you have now a flag for open modal dialog : |
| 163 |
|
| 164 |
|
| 165 |
```cpp |
| 166 |
ImGuiFileDialogFlags_Modal |
| 167 |
``` |
| 168 |
|
| 169 |
you can use it like that : |
| 170 |
|
| 171 |
```cpp |
| 172 |
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".cpp,.h,.hpp", |
| 173 |
".", 1, nullptr, ImGuiFileDialogFlags_Modal); |
| 174 |
``` |
| 175 |
|
| 176 |
</blockquote></details> |
| 177 |
|
| 178 |
<details open><summary><h2>Directory Chooser :</h2></summary><blockquote> |
| 179 |
|
| 180 |
To have a directory chooser, set the file extension filter to nullptr: |
| 181 |
|
| 182 |
```cpp |
| 183 |
ImGuiFileDialog::Instance()->OpenDialog("ChooseDirDlgKey", "Choose a Directory", nullptr, "."); |
| 184 |
``` |
| 185 |
|
| 186 |
In this mode you can select any directory with one click and open a directory with a double-click. |
| 187 |
|
| 188 |
 |
| 189 |
|
| 190 |
</blockquote></details> |
| 191 |
|
| 192 |
<details open><summary><h2>Dialog with Custom Pane :</h2></summary><blockquote> |
| 193 |
|
| 194 |
The signature of the custom pane callback is: |
| 195 |
|
| 196 |
### for C++ : |
| 197 |
|
| 198 |
```cpp |
| 199 |
void(const char *vFilter, IGFDUserDatas vUserDatas, bool *vCantContinue) |
| 200 |
``` |
| 201 |
|
| 202 |
### for C : |
| 203 |
|
| 204 |
```c |
| 205 |
void(const char *vFilter, void* vUserDatas, bool *vCantContinue) |
| 206 |
``` |
| 207 |
|
| 208 |
### Example : |
| 209 |
|
| 210 |
```cpp |
| 211 |
static bool canValidateDialog = false; |
| 212 |
inline void InfosPane(cosnt char *vFilter, IGFDUserDatas vUserDatas, bool *vCantContinue) // if vCantContinue is false, the user cant validate the dialog |
| 213 |
{ |
| 214 |
ImGui::TextColored(ImVec4(0, 1, 1, 1), "Infos Pane"); |
| 215 |
ImGui::Text("Selected Filter : %s", vFilter.c_str()); |
| 216 |
if (vUserDatas) |
| 217 |
ImGui::Text("UserDatas : %s", vUserDatas); |
| 218 |
ImGui::Checkbox("if not checked you cant validate the dialog", &canValidateDialog); |
| 219 |
if (vCantContinue) |
| 220 |
*vCantContinue = canValidateDialog; |
| 221 |
} |
| 222 |
|
| 223 |
void drawGui() |
| 224 |
{ |
| 225 |
// open Dialog with Pane |
| 226 |
if (ImGui::Button("Open File Dialog with a custom pane")) |
| 227 |
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".cpp,.h,.hpp", |
| 228 |
".", "", std::bind(&InfosPane, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), 350, 1, UserDatas("InfosPane")); |
| 229 |
|
| 230 |
// display and action if ok |
| 231 |
if (ImGuiFileDialog::Instance()->Display("ChooseFileDlgKey")) |
| 232 |
{ |
| 233 |
if (ImGuiFileDialog::Instance()->IsOk()) |
| 234 |
{ |
| 235 |
std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName(); |
| 236 |
std::string filePath = ImGuiFileDialog::Instance()->GetCurrentPath(); |
| 237 |
std::string filter = ImGuiFileDialog::Instance()->GetCurrentFilter(); |
| 238 |
// here convert from string because a string was passed as a userDatas, but it can be what you want |
| 239 |
std::string userDatas; |
| 240 |
if (ImGuiFileDialog::Instance()->GetUserDatas()) |
| 241 |
userDatas = std::string((const char*)ImGuiFileDialog::Instance()->GetUserDatas()); |
| 242 |
auto selection = ImGuiFileDialog::Instance()->GetSelection(); // multiselection |
| 243 |
|
| 244 |
// action |
| 245 |
} |
| 246 |
// close |
| 247 |
ImGuiFileDialog::Instance()->Close(); |
| 248 |
} |
| 249 |
} |
| 250 |
``` |
| 251 |
|
| 252 |
 |
| 253 |
|
| 254 |
</blockquote></details> |
| 255 |
|
| 256 |
<details open><summary><h2>File Style : Custom icons and colors by extension :</h2></summary><blockquote> |
| 257 |
|
| 258 |
You can define style for files/dirs/links in many ways : |
| 259 |
|
| 260 |
the style can be colors, icons and fonts |
| 261 |
|
| 262 |
the general form is : |
| 263 |
```cpp |
| 264 |
ImGuiFileDialog::Instance()->SetFileStyle(styleType, criteria, color, icon, font); |
| 265 |
``` |
| 266 |
|
| 267 |
### Predefined Form : |
| 268 |
|
| 269 |
styleType can be thoses : |
| 270 |
|
| 271 |
```cpp |
| 272 |
IGFD_FileStyleByTypeFile // define style for all files |
| 273 |
IGFD_FileStyleByTypeDir // define style for all dir |
| 274 |
IGFD_FileStyleByTypeLink // define style for all link |
| 275 |
IGFD_FileStyleByExtention // define style by extention, for files or links |
| 276 |
IGFD_FileStyleByFullName // define style for particular file/dir/link full name (filename + extention) |
| 277 |
IGFD_FileStyleByContainedInFullName // define style for file/dir/link when criteria is contained in full name |
| 278 |
``` |
| 279 |
|
| 280 |
### Lambda Function Form : |
| 281 |
|
| 282 |
You can define easily your own style include your own detection by using lambda function : |
| 283 |
|
| 284 |
** To note, this mode is not available with the C API ** |
| 285 |
|
| 286 |
this lamba will treat a file and return a shared pointer of your files style |
| 287 |
|
| 288 |
see in action a styling of all files and dir starting by a dot |
| 289 |
|
| 290 |
this lambda input a FileInfos and output a FileStyle |
| 291 |
return true if a FileStyle was defined |
| 292 |
|
| 293 |
```cpp |
| 294 |
ImGuiFileDialog::Instance()->SetFileStyle([](const IGFD::FileInfos& vFile, IGFD::FileStyle &vOutStyle) -> bool { |
| 295 |
if (!vFile.fileNameExt.empty() && vFile.fileNameExt[0] == '.') { |
| 296 |
vOutStyle = IGFD::FileStyle(ImVec4(0.0f, 0.9f, 0.9f, 1.0f), ICON_IGFD_REMOVE); |
| 297 |
return true; |
| 298 |
} |
| 299 |
return false; |
| 300 |
}); |
| 301 |
``` |
| 302 |
|
| 303 |
see sample app for the code in action |
| 304 |
|
| 305 |
### Samples : |
| 306 |
|
| 307 |
ImGuiFileDialog accepts icon font macros as well as text tags for file types. |
| 308 |
|
| 309 |
[ImGuIFontStudio](https://github.com/aiekick/ImGuiFontStudio) is useful here. I wrote it to make it easy to create |
| 310 |
custom icon sets for use with Dear ImGui. |
| 311 |
|
| 312 |
It is inspired by [IconFontCppHeaders](https://github.com/juliettef/IconFontCppHeaders), which can also be used with |
| 313 |
ImGuiFileDialog. |
| 314 |
|
| 315 |
samples : |
| 316 |
|
| 317 |
```cpp |
| 318 |
// define style by file extention and Add an icon for .png files |
| 319 |
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtention, ".png", ImVec4(0.0f, 1.0f, 1.0f, 0.9f), ICON_IGFD_FILE_PIC, font1); |
| 320 |
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtention, ".gif", ImVec4(0.0f, 1.0f, 0.5f, 0.9f), "[GIF]"); |
| 321 |
|
| 322 |
// define style for all directories |
| 323 |
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeDir, "", ImVec4(0.5f, 1.0f, 0.9f, 0.9f), ICON_IGFD_FOLDER); |
| 324 |
// can be for a specific directory |
| 325 |
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeDir, ".git", ImVec4(0.5f, 1.0f, 0.9f, 0.9f), ICON_IGFD_FOLDER); |
| 326 |
|
| 327 |
// define style for all files |
| 328 |
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeFile, "", ImVec4(0.5f, 1.0f, 0.9f, 0.9f), ICON_IGFD_FILE); |
| 329 |
// can be for a specific file |
| 330 |
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeFile, ".git", ImVec4(0.5f, 1.0f, 0.9f, 0.9f), ICON_IGFD_FILE); |
| 331 |
|
| 332 |
// define style for all links |
| 333 |
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeLink, "", ImVec4(0.5f, 1.0f, 0.9f, 0.9f)); |
| 334 |
// can be for a specific link |
| 335 |
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeLink, "Readme.md", ImVec4(0.5f, 1.0f, 0.9f, 0.9f)); |
| 336 |
|
| 337 |
// define style for any files/dirs/links by fullname |
| 338 |
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByFullName, "doc", ImVec4(0.9f, 0.2f, 0.0f, 0.9f), ICON_IGFD_FILE_PIC); |
| 339 |
|
| 340 |
// define style by file who are containing this string |
| 341 |
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByContainedInFullName, ".git", ImVec4(0.9f, 0.2f, 0.0f, 0.9f), ICON_IGFD_BOOKMARK); |
| 342 |
|
| 343 |
all of theses can be miwed with IGFD_FileStyleByTypeDir / IGFD_FileStyleByTypeFile / IGFD_FileStyleByTypeLink |
| 344 |
like theses by ex : |
| 345 |
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeDir | IGFD_FileStyleByContainedInFullName, ".git", ImVec4(0.9f, 0.2f, 0.0f, 0.9f), ICON_IGFD_BOOKMARK); |
| 346 |
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeFile | IGFD_FileStyleByFullName, "cmake", ImVec4(0.5f, 0.8f, 0.5f, 0.9f), ICON_IGFD_SAVE); |
| 347 |
|
| 348 |
// for all these,s you can use a regex |
| 349 |
// ex for color files like Custom*.h |
| 350 |
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByFullName, "((Custom.+[.]h))", ImVec4(0.0f, 1.0f, 1.0f, 0.9f), ICON_IGFD_FILE_PIC, font1); |
| 351 |
|
| 352 |
// lambda function |
| 353 |
// set file style with a lambda function |
| 354 |
// return true is a file style was defined |
| 355 |
ImGuiFileDialog::Instance()->SetFileStyle([](const IGFD::FileInfos& vFile, IGFD::FileStyle &vOutStyle) -> bool { |
| 356 |
if (!vFile.fileNameExt.empty() && vFile.fileNameExt[0] == '.') { |
| 357 |
vOutStyle = IGFD::FileStyle(ImVec4(0.0f, 0.9f, 0.9f, 1.0f), ICON_IGFD_REMOVE); |
| 358 |
return true; |
| 359 |
} |
| 360 |
return false; |
| 361 |
}); |
| 362 |
``` |
| 363 |
|
| 364 |
this sample code of [master/main.cpp](https://github.com/aiekick/ImGuiFileDialog/blob/DemoApp/main.cpp) produce the picture above : |
| 365 |
|
| 366 |
```cpp |
| 367 |
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtention, ".cpp", ImVec4(1.0f, 1.0f, 0.0f, 0.9f)); |
| 368 |
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtention, ".h", ImVec4(0.0f, 1.0f, 0.0f, 0.9f)); |
| 369 |
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtention, ".hpp", ImVec4(0.0f, 0.0f, 1.0f, 0.9f)); |
| 370 |
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtention, ".md", ImVec4(1.0f, 0.0f, 1.0f, 0.9f)); |
| 371 |
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtention, ".png", ImVec4(0.0f, 1.0f, 1.0f, 0.9f), ICON_IGFD_FILE_PIC); // add an icon for the filter type |
| 372 |
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtention, ".gif", ImVec4(0.0f, 1.0f, 0.5f, 0.9f), "[GIF]"); // add an text for a filter type |
| 373 |
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeDir, nullptr, ImVec4(0.5f, 1.0f, 0.9f, 0.9f), ICON_IGFD_FOLDER); // for all dirs |
| 374 |
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeFile, "CMakeLists.txt", ImVec4(0.1f, 0.5f, 0.5f, 0.9f), ICON_IGFD_ADD); |
| 375 |
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByFullName, "doc", ImVec4(0.9f, 0.2f, 0.0f, 0.9f), ICON_IGFD_FILE_PIC); |
| 376 |
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeDir | IGFD_FileStyleByContainedInFullName, ".git", ImVec4(0.9f, 0.2f, 0.0f, 0.9f), ICON_IGFD_BOOKMARK); |
| 377 |
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeFile | IGFD_FileStyleByContainedInFullName, ".git", ImVec4(0.5f, 0.8f, 0.5f, 0.9f), ICON_IGFD_SAVE); |
| 378 |
``` |
| 379 |
|
| 380 |
 |
| 381 |
|
| 382 |
</blockquote></details> |
| 383 |
|
| 384 |
<details open><summary><h2>Filter Collections :</h2></summary><blockquote> |
| 385 |
|
| 386 |
You can define a custom filter name that corresponds to a group of filters using this syntax: |
| 387 |
|
| 388 |
You can also use a regex for the filtering. the regex must be betwwen the ( and ) for be recognized as a regex |
| 389 |
|
| 390 |
|
| 391 |
```custom_name1{filter1,filter2,filter3,(regex0),(regex1)},custom_name2{filter1,filter2,(regex0)},filter1``` |
| 392 |
|
| 393 |
When you select custom_name1, filters 1 to 3 will be applied. The characters `{` and `}` are reserved. Don't use them |
| 394 |
for filter names. |
| 395 |
|
| 396 |
|
| 397 |
this code : |
| 398 |
|
| 399 |
```cpp |
| 400 |
const char *filters = "Source files (*.cpp *.h *.hpp){.cpp,.h,.hpp},Image files (*.png *.gif *.jpg *.jpeg){.png,.gif,.jpg,.jpeg},.md"; |
| 401 |
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", ICON_IMFDLG_FOLDER_OPEN " Choose a File", filters, "."); |
| 402 |
``` |
| 403 |
|
| 404 |
will produce : |
| 405 |
 |
| 406 |
|
| 407 |
</blockquote></details> |
| 408 |
|
| 409 |
<details open><summary><h2>Multi Selection :</h2></summary><blockquote> |
| 410 |
|
| 411 |
You can define in OpenDialog call the count file you want to select : |
| 412 |
|
| 413 |
- 0 => infinite |
| 414 |
- 1 => one file only (default) |
| 415 |
- n => n files only |
| 416 |
|
| 417 |
See the define at the end of these funcs after path. |
| 418 |
|
| 419 |
```cpp |
| 420 |
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".*,.cpp,.h,.hpp", "."); |
| 421 |
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose 1 File", ".*,.cpp,.h,.hpp", ".", 1); |
| 422 |
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose 5 File", ".*,.cpp,.h,.hpp", ".", 5); |
| 423 |
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose many File", ".*,.cpp,.h,.hpp", ".", 0); |
| 424 |
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".png,.jpg", |
| 425 |
".", "", std::bind(&InfosPane, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), 350, 1, "SaveFile"); // 1 file |
| 426 |
``` |
| 427 |
|
| 428 |
 |
| 429 |
|
| 430 |
</blockquote></details> |
| 431 |
|
| 432 |
<details open><summary><h2>File Dialog Constraints :</h2></summary><blockquote> |
| 433 |
|
| 434 |
You can set the minimum and/or maximum size of the dialog: |
| 435 |
|
| 436 |
```cpp |
| 437 |
ImVec2 maxSize = ImVec2((float)display_w, (float)display_h); // The full display area |
| 438 |
ImVec2 minSize = maxSize * 0.5f; // Half the display area |
| 439 |
ImGuiFileDialog::Instance()->Display("ChooseFileDlgKey", ImGuiWindowFlags_NoCollapse, minSize, maxSize); |
| 440 |
``` |
| 441 |
|
| 442 |
 |
| 443 |
|
| 444 |
</blockquote></details> |
| 445 |
|
| 446 |
<details open><summary><h2>Exploring by keys :</h2></summary><blockquote> |
| 447 |
|
| 448 |
You can activate this feature by uncommenting `#define USE_EXPLORATION_BY_KEYS` |
| 449 |
in your custom config file (CustomImGuiFileDialogConfig.h) |
| 450 |
|
| 451 |
You can also uncomment the next lines to define navigation keys: |
| 452 |
|
| 453 |
* IGFD_KEY_UP => Up key for explore to the top |
| 454 |
* IGFD_KEY_DOWN => Down key for explore to the bottom |
| 455 |
* IGFD_KEY_ENTER => Enter key for open directory |
| 456 |
* IGFD_KEY_BACKSPACE => BackSpace for comming back to the last directory |
| 457 |
|
| 458 |
You can also jump to a point in the file list by pressing the corresponding key of the first filename character. |
| 459 |
|
| 460 |
 |
| 461 |
|
| 462 |
As you see the current item is flashed by default for 1 second. You can define the flashing lifetime with the function |
| 463 |
|
| 464 |
```cpp |
| 465 |
ImGuiFileDialog::Instance()->SetFlashingAttenuationInSeconds(1.0f); |
| 466 |
``` |
| 467 |
|
| 468 |
</blockquote></details> |
| 469 |
|
| 470 |
<details open><summary><h2>Bookmarks :</h2></summary><blockquote> |
| 471 |
|
| 472 |
You can create/edit/call path bookmarks and load/save them. |
| 473 |
|
| 474 |
Activate this feature by uncommenting: `#define USE_BOOKMARK` in your custom config file (CustomImGuiFileDialogConfig.h) |
| 475 |
|
| 476 |
More customization options: |
| 477 |
|
| 478 |
```cpp |
| 479 |
#define bookmarkPaneWith 150.0f => width of the bookmark pane |
| 480 |
#define IMGUI_TOGGLE_BUTTON ToggleButton => customize the Toggled button (button stamp must be : (const char* label, bool *toggle) |
| 481 |
#define bookmarksButtonString "Bookmark" => the text in the toggle button |
| 482 |
#define bookmarksButtonHelpString "Bookmark" => the helper text when mouse over the button |
| 483 |
#define addBookmarkButtonString "+" => the button for add a bookmark |
| 484 |
#define removeBookmarkButtonString "-" => the button for remove the selected bookmark |
| 485 |
``` |
| 486 |
|
| 487 |
* You can select each bookmark to edit the displayed name corresponding to a path |
| 488 |
* Double-click on the label to apply the bookmark |
| 489 |
|
| 490 |
 |
| 491 |
|
| 492 |
You can also serialize/deserialize bookmarks (for example to load/save from/to a file): |
| 493 |
```cpp |
| 494 |
Load => ImGuiFileDialog::Instance()->DeserializeBookmarks(bookmarString); |
| 495 |
Save => std::string bookmarkString = ImGuiFileDialog::Instance()->SerializeBookmarks(); |
| 496 |
``` |
| 497 |
|
| 498 |
you can also add/remove bookmark by code : |
| 499 |
|
| 500 |
and in this case, you can also avoid serialization of code based bookmark |
| 501 |
|
| 502 |
```cpp |
| 503 |
Add => ImGuiFileDialog::Instance()->AddBookmark(bookmark_name, bookmark_path); |
| 504 |
Remove => ImGuiFileDialog::Instance()->RemoveBookmark(bookmark_name); |
| 505 |
|
| 506 |
// true for prevent serialization of code based bookmarks |
| 507 |
Save => std::string bookmarkString = ImGuiFileDialog::Instance()->SerializeBookmarks(true); |
| 508 |
``` |
| 509 |
|
| 510 |
(please see example code for details) |
| 511 |
|
| 512 |
</blockquote></details> |
| 513 |
|
| 514 |
<details open><summary><h2>Path Edition :</h2></summary><blockquote> |
| 515 |
|
| 516 |
Right clicking on any path element button allows the user to manually edit the path from that portion of the tree. |
| 517 |
Pressing the completion key (GLFW uses `enter` by default) validates the new path. Pressing the cancel key (GLFW |
| 518 |
uses`escape` by default) cancels the manual entry and restores the original path. |
| 519 |
|
| 520 |
Here's the manual entry operation in action: |
| 521 |
 |
| 522 |
|
| 523 |
</blockquote></details> |
| 524 |
|
| 525 |
<details open><summary><h2>Confirm Overwrite Dialog :</h2></summary><blockquote> |
| 526 |
|
| 527 |
If you want avoid overwriting files after selection, ImGuiFileDialog can show a dialog to confirm or cancel the |
| 528 |
operation. |
| 529 |
|
| 530 |
To do so, define the flag ImGuiFileDialogFlags_ConfirmOverwrite in your call to OpenDialog/OpenModal. |
| 531 |
|
| 532 |
By default this flag is not set since there is no pre-defined way to define if a dialog will be for Open or Save |
| 533 |
behavior. (by design! :) ) |
| 534 |
|
| 535 |
Example code For Standard Dialog : |
| 536 |
|
| 537 |
```cpp |
| 538 |
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", |
| 539 |
ICON_IGFD_SAVE " Choose a File", filters, |
| 540 |
".", "", 1, nullptr, ImGuiFileDialogFlags_ConfirmOverwrite); |
| 541 |
``` |
| 542 |
|
| 543 |
Example code For Modal Dialog : |
| 544 |
|
| 545 |
```cpp |
| 546 |
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", |
| 547 |
ICON_IGFD_SAVE " Choose a File", filters, |
| 548 |
".", "", 1, nullptr, ImGuiFileDialogFlags_Modal | ImGuiFileDialogFlags_ConfirmOverwrite); |
| 549 |
``` |
| 550 |
|
| 551 |
This dialog will only verify the file in the file field, not with `GetSelection()`. |
| 552 |
|
| 553 |
The confirmation dialog will be a non-movable modal (input blocking) dialog displayed in the middle of the current |
| 554 |
ImGuiFileDialog window. |
| 555 |
|
| 556 |
As usual, you can customize the dialog in your custom config file (CustomImGuiFileDialogConfig.h in this example) |
| 557 |
|
| 558 |
Uncomment these line for customization options: |
| 559 |
|
| 560 |
```cpp |
| 561 |
//#define OverWriteDialogTitleString "The file Already Exist !" |
| 562 |
//#define OverWriteDialogMessageString "Would you like to OverWrite it ?" |
| 563 |
//#define OverWriteDialogConfirmButtonString "Confirm" |
| 564 |
//#define OverWriteDialogCancelButtonString "Cancel" |
| 565 |
``` |
| 566 |
|
| 567 |
See the result : |
| 568 |
|
| 569 |
 |
| 570 |
|
| 571 |
</blockquote></details> |
| 572 |
|
| 573 |
<details open><summary><h2>Open / Save dialog Behavior :</h2></summary><blockquote> |
| 574 |
|
| 575 |
ImGuiFileDialog uses the same code internally for Open and Save dialogs. To distinguish between them access the various |
| 576 |
data return functions depending on what the dialog is doing. |
| 577 |
|
| 578 |
When selecting an existing file (for example, a Load or Open dialog), use |
| 579 |
|
| 580 |
```cpp |
| 581 |
std::map<std::string, std::string> GetSelection(); // Returns selection via a map<FileName, FilePathName> |
| 582 |
UserDatas GetUserDatas(); // Get user data provided by the Open dialog |
| 583 |
``` |
| 584 |
|
| 585 |
To selecting a new file (for example, a Save As... dialog), use: |
| 586 |
|
| 587 |
```cpp |
| 588 |
std::string GetFilePathName(); // Returns the content of the selection field with current file extension and current path |
| 589 |
std::string GetCurrentFileName(); // Returns the content of the selection field with current file extension but no path |
| 590 |
std::string GetCurrentPath(); // Returns current path only |
| 591 |
std::string GetCurrentFilter(); // The file extension |
| 592 |
``` |
| 593 |
|
| 594 |
</blockquote></details> |
| 595 |
|
| 596 |
<details open><summary><h2>Thumbnails Display :</h2></summary><blockquote> |
| 597 |
|
| 598 |
You can now, display thumbnails of pictures. |
| 599 |
|
| 600 |
 |
| 601 |
|
| 602 |
The file resize use stb/image so the following files extentions are supported : |
| 603 |
* .png (tested sucessfully) |
| 604 |
* .bmp (tested sucessfully) |
| 605 |
* .tga (tested sucessfully) |
| 606 |
* .jpg (tested sucessfully) |
| 607 |
* .jpeg (tested sucessfully) |
| 608 |
* .gif (tested sucessfully_ but not animation just first frame) |
| 609 |
* .psd (not tested) |
| 610 |
* .pic (not tested) |
| 611 |
* .ppm (not tested) |
| 612 |
* .pgm (not tested) |
| 613 |
|
| 614 |
Corresponding to your backend (ex : OpenGl) you need to define two callbacks : |
| 615 |
* the first is a callback who will be called by ImGuiFileDialog for create the backend texture |
| 616 |
* the second is a callback who will be called by ImGuiFileDialog for destroy the backend texture |
| 617 |
|
| 618 |
After that you need to call the function who is responsible to create / destroy the textures. |
| 619 |
this function must be called in your GPU Rendering zone for avoid destroying of used texture. |
| 620 |
if you do that at the same place of your imgui code, some backend can crash your app, by ex with vulkan. |
| 621 |
|
| 622 |
To Clarify : |
| 623 |
|
| 624 |
This feature is spliited in two zones : |
| 625 |
- CPU Zone : for load/destroy picture file |
| 626 |
- GPU Zone : for load/destroy gpu textures. |
| 627 |
This modern behavior for avoid destroying of used texture, |
| 628 |
was needed for vulkan. |
| 629 |
|
| 630 |
This feature was Successfully tested on my side with Opengl and Vulkan. |
| 631 |
But im sure is perfectly compatible with other modern apis like DirectX and Metal |
| 632 |
|
| 633 |
ex, for opengl : |
| 634 |
|
| 635 |
```cpp |
| 636 |
// Create thumbnails texture |
| 637 |
ImGuiFileDialog::Instance()->SetCreateThumbnailCallback([](IGFD_Thumbnail_Info *vThumbnail_Info) -> void |
| 638 |
{ |
| 639 |
if (vThumbnail_Info && |
| 640 |
vThumbnail_Info->isReadyToUpload && |
| 641 |
vThumbnail_Info->textureFileDatas) |
| 642 |
{ |
| 643 |
GLuint textureId = 0; |
| 644 |
glGenTextures(1, &textureId); |
| 645 |
vThumbnail_Info->textureID = (void*)textureId; |
| 646 |
|
| 647 |
glBindTexture(GL_TEXTURE_2D, textureId); |
| 648 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 649 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 650 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 651 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 652 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, |
| 653 |
(GLsizei)vThumbnail_Info->textureWidth, (GLsizei)vThumbnail_Info->textureHeight, |
| 654 |
0, GL_RGBA, GL_UNSIGNED_BYTE, vThumbnail_Info->textureFileDatas); |
| 655 |
glFinish(); |
| 656 |
glBindTexture(GL_TEXTURE_2D, 0); |
| 657 |
|
| 658 |
delete[] vThumbnail_Info->textureFileDatas; |
| 659 |
vThumbnail_Info->textureFileDatas = nullptr; |
| 660 |
|
| 661 |
vThumbnail_Info->isReadyToUpload = false; |
| 662 |
vThumbnail_Info->isReadyToDisplay = true; |
| 663 |
} |
| 664 |
}); |
| 665 |
``` |
| 666 |
|
| 667 |
```cpp |
| 668 |
// Destroy thumbnails texture |
| 669 |
ImGuiFileDialog::Instance()->SetDestroyThumbnailCallback([](IGFD_Thumbnail_Info* vThumbnail_Info) |
| 670 |
{ |
| 671 |
if (vThumbnail_Info) |
| 672 |
{ |
| 673 |
GLuint texID = (GLuint)vThumbnail_Info->textureID; |
| 674 |
glDeleteTextures(1, &texID); |
| 675 |
glFinish(); |
| 676 |
} |
| 677 |
}); |
| 678 |
``` |
| 679 |
|
| 680 |
```cpp |
| 681 |
// GPU Rendering Zone // To call for Create/ Destroy Textures |
| 682 |
ImGuiFileDialog::Instance()->ManageGPUThumbnails(); |
| 683 |
``` |
| 684 |
|
| 685 |
</blockquote></details> |
| 686 |
|
| 687 |
<details open><summary><h2>Embedded in other frames :</h2></summary><blockquote> |
| 688 |
|
| 689 |
The dialog can be embedded in another user frame than the standard or modal dialog |
| 690 |
|
| 691 |
You have to create a variable of type ImGuiFileDialog. (if you are suing the singleton, you will not have the possibility to open other dialog) |
| 692 |
|
| 693 |
ex : |
| 694 |
|
| 695 |
```cpp |
| 696 |
ImGuiFileDialog fileDialog; |
| 697 |
|
| 698 |
// open dialog; in this case, Bookmark, directory creation are disabled with, and also the file input field is readonly. |
| 699 |
// btw you can od what you want |
| 700 |
fileDialog.OpenDialog("embedded", "Select File", ".*", "", -1, nullptr, |
| 701 |
ImGuiFileDialogFlags_NoDialog | |
| 702 |
ImGuiFileDialogFlags_DisableBookmarkMode | |
| 703 |
ImGuiFileDialogFlags_DisableCreateDirectoryButton | |
| 704 |
ImGuiFileDialogFlags_ReadOnlyFileNameField); |
| 705 |
// then display, here |
| 706 |
// to note, when embedded the ImVec2(0,0) (MinSize) do nothing, only the ImVec2(0,350) (MaxSize) can size the dialog frame |
| 707 |
fileDialog.Display("embedded", ImGuiWindowFlags_NoCollapse, ImVec2(0,0), ImVec2(0,350))) |
| 708 |
``` |
| 709 |
the result : |
| 710 |
|
| 711 |
 |
| 712 |
|
| 713 |
</blockquote></details> |
| 714 |
|
| 715 |
<details open><summary><h2>Quick Parallel Path Selection in Path Composer :</h2></summary><blockquote> |
| 716 |
|
| 717 |
you have a separator between two directories in the path composer |
| 718 |
when you click on it you can explore a list of parrallels directories of this point |
| 719 |
|
| 720 |
this feature is disabled by default |
| 721 |
you can enable it with the compiler flag : #define USE_QUICK_PATH_SELECT |
| 722 |
|
| 723 |
you can also customize the spacing between path button's with and without this mode |
| 724 |
you can do that by define the compiler flag : #define CUSTOM_PATH_SPACING 2 |
| 725 |
if undefined the spacing is defined by the imgui theme |
| 726 |
|
| 727 |
 |
| 728 |
|
| 729 |
</blockquote></details> |
| 730 |
|
| 731 |
<details open><summary><h2>Case Insensitive Filtering :</h2></summary><blockquote> |
| 732 |
|
| 733 |
you can use this flag 'ImGuiFileDialogFlags_CaseInsensitiveExtention' when you call the open functions |
| 734 |
|
| 735 |
``` |
| 736 |
by ex : |
| 737 |
if the flag ImGuiFileDialogFlags_CaseInsensitiveExtention is used |
| 738 |
with filters like .jpg or .Jpg or .JPG |
| 739 |
all files with extentions by ex : .jpg and .JPG will be displayed |
| 740 |
``` |
| 741 |
|
| 742 |
</blockquote></details> |
| 743 |
|
| 744 |
<details open><summary><h2>How to Integrate ImGuiFileDialog in your project :</h2></summary><blockquote> |
| 745 |
|
| 746 |
### Customize ImGuiFileDialog : |
| 747 |
|
| 748 |
You can customize many aspects of ImGuiFileDialog by overriding `ImGuiFileDialogConfig.h`. |
| 749 |
|
| 750 |
To enable your customizations, define the preprocessor directive CUSTOM_IMGUIFILEDIALOG_CONFIG with the path of your |
| 751 |
custom config file. This path must be relative to the directory where you put the ImGuiFileDialog module. |
| 752 |
|
| 753 |
This operation is demonstrated in `CustomImGuiFileDialog.h` in the example project to: |
| 754 |
|
| 755 |
* Have a custom icon font instead of labels for buttons or message titles |
| 756 |
* Customize the button text (the button call signature must be the same, by the way! :) |
| 757 |
|
| 758 |
The custom icon font used in the example code ([CustomFont.cpp](CustomFont.cpp) and [CustomFont.h](CustomFont.h)) was made |
| 759 |
with [ImGuiFontStudio](https://github.com/aiekick/ImGuiFontStudio), which I wrote. :) |
| 760 |
|
| 761 |
ImGuiFontStudio uses ImGuiFileDialog! Check it out. |
| 762 |
|
| 763 |
### Overriding ImGuiFileDialog : |
| 764 |
|
| 765 |
You can also override it to draw differently or to add/remove widgets. |
| 766 |
|
| 767 |
Take a look at the example application where I show how to use it to display a read-only checkbox. |
| 768 |
|
| 769 |
see the 'CustomDrawReadOnlyCheckBoxFileDialog' class. |
| 770 |
|
| 771 |
</blockquote></details> |
| 772 |
|
| 773 |
<details open><summary><h2>Tune the validations button group :</h2></summary><blockquote> |
| 774 |
|
| 775 |
You can specify : |
| 776 |
- the width of "ok" and "cancel" buttons, by the set the defines "okButtonWidth" and "cancelButtonWidth" |
| 777 |
- the alignement of the button group (left, right, middle, etc..) by set the define "okCancelButtonAlignement" |
| 778 |
- if you want to have the ok button on the left and cancel button on the right or inverted by set the define "invertOkAndCancelButtons" |
| 779 |
|
| 780 |
just see theses defines in the config file |
| 781 |
```cpp |
| 782 |
//Validation buttons |
| 783 |
//#define okButtonString " OK" |
| 784 |
//#define okButtonWidth 0.0f |
| 785 |
//#define cancelButtonString " Cancel" |
| 786 |
//#define cancelButtonWidth 0.0f |
| 787 |
//alignement [0:1], 0.0 is left, 0.5 middle, 1.0 right, and other ratios |
| 788 |
//#define okCancelButtonAlignement 0.0f |
| 789 |
//#define invertOkAndCancelButtons false |
| 790 |
``` |
| 791 |
with Alignement 0.0 => left |
| 792 |
|
| 793 |
 |
| 794 |
|
| 795 |
with Alignement 1.0 => right |
| 796 |
|
| 797 |
 |
| 798 |
|
| 799 |
with Alignement 0.5 => middle |
| 800 |
|
| 801 |
 |
| 802 |
|
| 803 |
ok and cancel buttons inverted (cancel on the left and ok on the right) |
| 804 |
|
| 805 |
 |
| 806 |
|
| 807 |
</blockquote></details> |
| 808 |
|
| 809 |
<details open><summary><h2>Filtering by a regex :</h2></summary><blockquote> |
| 810 |
|
| 811 |
you can use a regex for filtering and file Styling |
| 812 |
|
| 813 |
for have a filter recognized as a regex, you must have it between a (( and a )) |
| 814 |
|
| 815 |
this one will filter files who start by the word "Common" and finish by ".h" |
| 816 |
```cpp |
| 817 |
ex : "((Custom.+[.]h))" |
| 818 |
``` |
| 819 |
|
| 820 |
use cases : |
| 821 |
|
| 822 |
* Simple filter : |
| 823 |
```cpp |
| 824 |
OpenDialog("toto", "Choose File", "((Custom.+[.]h))"); |
| 825 |
``` |
| 826 |
|
| 827 |
* Collections filter : |
| 828 |
for this one the filter is between "{" and "}", so you can use the "(" and ")" outside |
| 829 |
|
| 830 |
```cpp |
| 831 |
OpenDialog("toto", "Choose File", "Source files (*.cpp *.h *.hpp){((Custom.+[.]h)),.h,.hpp}"); |
| 832 |
``` |
| 833 |
|
| 834 |
* file coloring : |
| 835 |
this one will colorized all files who start by the word "Common" and finish by ".h" |
| 836 |
```cpp |
| 837 |
SetFileStyle(IGFD_FileStyleByFullName, "((Custom.+[.]h))", ImVec4(1.0f, 1.0f, 0.0f, 0.9f)); |
| 838 |
``` |
| 839 |
|
| 840 |
* with this feature you can by ex filter and colorize render frame pictures who have ext like .000, .001, .002, etc.. |
| 841 |
```cpp |
| 842 |
OpenDialog("toto", "Choose File", "(([.][0-9]{3}))"); |
| 843 |
SetFileStyle(IGFD_FileStyleByFullName, "(([.][0-9]{3}))", ImVec4(1.0f, 1.0f, 0.0f, 0.9f)); |
| 844 |
``` |
| 845 |
|
| 846 |
</blockquote></details> |
| 847 |
|
| 848 |
<details open><summary><h2>Multi Layer / asterisk based filter :</h2></summary><blockquote> |
| 849 |
|
| 850 |
you can add filter in the form : .a.b.c .json.cpp .vcxproj.filters |
| 851 |
|
| 852 |
you can also add filter in the form : .* .*.* .vcx.* .*.filters .vcx*.filt.* etc.. |
| 853 |
all the * based filter are internally using regex's |
| 854 |
|
| 855 |
</blockquote></details> |
| 856 |
|
| 857 |
<details open><summary><h2>Result Modes for GetFilePathName, getFileName and GetSelection :</h2></summary><blockquote> |
| 858 |
|
| 859 |
you can add have various behavior when you get the file results at dialog end |
| 860 |
|
| 861 |
you can specify a result mode to thoses function : |
| 862 |
|
| 863 |
```cpp |
| 864 |
GetFilePathName(IGFD_ResultMode = IGFD_ResultMode_AddIfNoFileExt) |
| 865 |
GetFileName(IGFD_ResultMode = IGFD_ResultMode_AddIfNoFileExt) |
| 866 |
GetFileSelection(IGFD_ResultMode = IGFD_ResultMode_KeepInputFile) |
| 867 |
``` |
| 868 |
You can see these function who their default modes. |
| 869 |
but you can modify them. |
| 870 |
|
| 871 |
There is 3 Modes : |
| 872 |
```cpp |
| 873 |
IGFD_ResultMode_AddIfNoFileExt [DEFAULT for |
| 874 |
This mode add the filter ext only if there is no file ext. (compatible multi layer) |
| 875 |
ex : |
| 876 |
filter {.cpp,.h} with file : |
| 877 |
toto.h => toto.h |
| 878 |
toto.a.h => toto.a.h |
| 879 |
toto.a. => toto.a.cpp |
| 880 |
toto. => toto.cpp |
| 881 |
toto => toto.cpp |
| 882 |
filter {.z,.a.b} with file : |
| 883 |
toto.a.h => toto.a.h |
| 884 |
toto. => toto.z |
| 885 |
toto => toto.z |
| 886 |
filter {.g.z,.a} with file : |
| 887 |
toto.a.h => toto.a.h |
| 888 |
toto. => toto.g.z |
| 889 |
toto => toto.g.z |
| 890 |
|
| 891 |
IGFD_ResultMode_OverwriteFileExt |
| 892 |
This mode Overwrite the file extention by the current filter |
| 893 |
This mode is the old behavior for imGuiFileDialog pre v0.6.6 |
| 894 |
ex : |
| 895 |
filter {.cpp,.h} with file : |
| 896 |
toto.h => toto.cpp |
| 897 |
toto.a.h => toto.a.cpp |
| 898 |
toto.a. => toto.a.cpp |
| 899 |
toto.a.h.t => toto.a.h.cpp |
| 900 |
toto. => toto.cpp |
| 901 |
toto => toto.cpp |
| 902 |
filter {.z,.a.b} with file : |
| 903 |
toto.a.h => toto.z |
| 904 |
toto.a.h.t => toto.a.z |
| 905 |
toto. => toto.z |
| 906 |
toto => toto.z |
| 907 |
filter {.g.z,.a} with file : |
| 908 |
toto.a.h => toto.g.z |
| 909 |
toto.a.h.y => toto.a.g.z |
| 910 |
toto.a. => toto.g.z |
| 911 |
toto. => toto.g.z |
| 912 |
toto => toto.g.z |
| 913 |
|
| 914 |
IGFD_ResultMode_KeepInputFile |
| 915 |
This mode keep the input file. no modification |
| 916 |
es : |
| 917 |
filter {.cpp,.h} with file : |
| 918 |
toto.h => toto.h |
| 919 |
toto. => toto. |
| 920 |
toto => toto |
| 921 |
filter {.z,.a.b} with file : |
| 922 |
toto.a.h => toto.a.h |
| 923 |
toto. => toto. |
| 924 |
toto => toto |
| 925 |
filter {.g.z,.a} with file : |
| 926 |
toto.a.h => toto.a.h |
| 927 |
toto. => toto. |
| 928 |
toto => toto |
| 929 |
``` |
| 930 |
|
| 931 |
to note : |
| 932 |
- in case of a collection of filter. the default filter will be the first. |
| 933 |
so in collection {.cpp,((.vcxproj.*)), .ft.*}, the default filter used for renaming will be .cpp |
| 934 |
- when you have multilayer filter in collection. |
| 935 |
we consider a filter to be replaced according to the max dot of filters for a whole collection |
| 936 |
a collection {.a, .b.z} is a two dots filter, so a file toto.g.z will be replaced by toto.a |
| 937 |
a collection {.z; .b} is a one dot filter, so a file toto.g.z will be replaced by toto.g.a |
| 938 |
|
| 939 |
</blockquote></details> |
| 940 |
|
| 941 |
<details open><summary><h2>Api's C/C++ :</h2></summary><blockquote> |
| 942 |
|
| 943 |
### the C Api |
| 944 |
|
| 945 |
this api was sucessfully tested with CImGui |
| 946 |
|
| 947 |
A C API is available let you include ImGuiFileDialog in your C project. |
| 948 |
btw, ImGuiFileDialog depend of ImGui and dirent (for windows) |
| 949 |
|
| 950 |
Sample code with cimgui : |
| 951 |
|
| 952 |
```cpp |
| 953 |
// create ImGuiFileDialog |
| 954 |
ImGuiFileDialog *cfileDialog = IGFD_Create(); |
| 955 |
|
| 956 |
// open dialog |
| 957 |
if (igButton("Open File", buttonSize)) |
| 958 |
{ |
| 959 |
IGFD_OpenDialog(cfiledialog, |
| 960 |
"filedlg", // dialog key (make it possible to have different treatment reagrding the dialog key |
| 961 |
"Open a File", // dialog title |
| 962 |
"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.. |
| 963 |
".", // base directory for files scan |
| 964 |
"", // base filename |
| 965 |
0, // a fucntion for display a right pane if you want |
| 966 |
0.0f, // base width of the pane |
| 967 |
0, // count selection : 0 infinite, 1 one file (default), n (n files) |
| 968 |
"User data !", // some user datas |
| 969 |
ImGuiFileDialogFlags_ConfirmOverwrite); // ImGuiFileDialogFlags |
| 970 |
} |
| 971 |
|
| 972 |
ImGuiIO* ioptr = igGetIO(); |
| 973 |
ImVec2 maxSize; |
| 974 |
maxSize.x = ioptr->DisplaySize.x * 0.8f; |
| 975 |
maxSize.y = ioptr->DisplaySize.y * 0.8f; |
| 976 |
ImVec2 minSize; |
| 977 |
minSize.x = maxSize.x * 0.25f; |
| 978 |
minSize.y = maxSize.y * 0.25f; |
| 979 |
|
| 980 |
// display dialog |
| 981 |
if (IGFD_DisplayDialog(cfiledialog, "filedlg", ImGuiWindowFlags_NoCollapse, minSize, maxSize)) |
| 982 |
{ |
| 983 |
if (IGFD_IsOk(cfiledialog)) // result ok |
| 984 |
{ |
| 985 |
char* cfilePathName = IGFD_GetFilePathName(cfiledialog); |
| 986 |
printf("GetFilePathName : %s\n", cfilePathName); |
| 987 |
char* cfilePath = IGFD_GetCurrentPath(cfiledialog); |
| 988 |
printf("GetCurrentPath : %s\n", cfilePath); |
| 989 |
char* cfilter = IGFD_GetCurrentFilter(cfiledialog); |
| 990 |
printf("GetCurrentFilter : %s\n", cfilter); |
| 991 |
// here convert from string because a string was passed as a userDatas, but it can be what you want |
| 992 |
void* cdatas = IGFD_GetUserDatas(cfiledialog); |
| 993 |
if (cdatas) |
| 994 |
printf("GetUserDatas : %s\n", (const char*)cdatas); |
| 995 |
struct IGFD_Selection csel = IGFD_GetSelection(cfiledialog); // multi selection |
| 996 |
printf("Selection :\n"); |
| 997 |
for (int i = 0; i < (int)csel.count; i++) |
| 998 |
{ |
| 999 |
printf("(%i) FileName %s => path %s\n", i, csel.table[i].fileName, csel.table[i].filePathName); |
| 1000 |
} |
| 1001 |
// action |
| 1002 |
|
| 1003 |
// destroy |
| 1004 |
if (cfilePathName) free(cfilePathName); |
| 1005 |
if (cfilePath) free(cfilePath); |
| 1006 |
if (cfilter) free(cfilter); |
| 1007 |
|
| 1008 |
IGFD_Selection_DestroyContent(&csel); |
| 1009 |
} |
| 1010 |
IGFD_CloseDialog(cfiledialog); |
| 1011 |
} |
| 1012 |
|
| 1013 |
// destroy ImGuiFileDialog |
| 1014 |
IGFD_Destroy(cfiledialog); |
| 1015 |
``` |
| 1016 |
|
| 1017 |
</blockquote></details> |
| 1018 |
|
| 1019 |
<details open><summary><h2>How to build the sample app :</h2></summary><blockquote> |
| 1020 |
|
| 1021 |
The sample app is [here in master branch]((https://github.com/aiekick/ImGuiFileDialog/tree/master) |
| 1022 |
|
| 1023 |
You need to use cMake. For the 3 Os (Win, Linux, MacOs), the cMake usage is exactly the same, |
| 1024 |
|
| 1025 |
Choose a build directory. (called here my_build_directory for instance) and |
| 1026 |
Choose a Build Mode : "Release" / "MinSizeRel" / "RelWithDebInfo" / "Debug" (called here BuildMode for instance) |
| 1027 |
Run cMake in console : (the first for generate cmake build files, the second for build the binary) |
| 1028 |
|
| 1029 |
cmake -B my_build_directory -DCMAKE_BUILD_TYPE=BuildMode |
| 1030 |
cmake --build my_build_directory --config BuildMode |
| 1031 |
|
| 1032 |
Some cMake version need Build mode define via the directive CMAKE_BUILD_TYPE or via --Config when we launch the build. This is why i put the boths possibilities |
| 1033 |
|
| 1034 |
By the way you need before, to make sure, you have needed dependencies. |
| 1035 |
|
| 1036 |
### On Windows : |
| 1037 |
|
| 1038 |
You need to have the opengl library installed |
| 1039 |
|
| 1040 |
### On Linux : |
| 1041 |
|
| 1042 |
You need many lib : (X11, xrandr, xinerama, xcursor, mesa) |
| 1043 |
|
| 1044 |
If you are on debian you can run : |
| 1045 |
|
| 1046 |
sudo apt-get update |
| 1047 |
sudo apt-get install libgl1-mesa-dev libx11-dev libxi-dev libxrandr-dev libxinerama-dev libxcursor-dev |
| 1048 |
|
| 1049 |
### On MacOs : |
| 1050 |
|
| 1051 |
you need many lib : opengl and cocoa framework |
| 1052 |
|
| 1053 |
</blockquote></details> |
| 1054 |
|
| 1055 |
## Thats all folks :-) |
| 1056 |
|
| 1057 |
You can check by example in this repo with the file CustomImGuiFileDialogConfig.h : |
| 1058 |
- this trick was used for have custom icon font instead of labels for buttons or messages titles |
| 1059 |
- you can also use your custom imgui button, the button call stamp must be same by the way :) |
| 1060 |
|
| 1061 |
The Custom Icon Font (in CustomFont.cpp and CustomFont.h) was made with ImGuiFontStudio (https://github.com/aiekick/ImGuiFontStudio) i wrote for that :) |
| 1062 |
ImGuiFontStudio is using also ImGuiFileDialog.$ |
| 1063 |
|
| 1064 |
 |