Skip to content

Commit ab335ef

Browse files
committed
[UPD] : update the doc in ImGuiFileDialog.h for the FileDialogConfig Api
1 parent 6ab200c commit ab335ef

2 files changed

Lines changed: 83 additions & 58 deletions

File tree

ImGuiFileDialog.h

Lines changed: 80 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ A filter is recognized only if he respects theses rules :
158158
1) a regex must be in (( and ))
159159
2) a , will separate filters except if between a ( and )
160160
3) name{filter1, filter2} is a special form for collection filters
161-
3.1) the name can be composed of what you want except { and }
162-
3.2) a filter can be a regex
161+
- the name can be composed of what you want except { and }
162+
- a filter can be a regex
163163
4) the filters cannot integrate these chars '(' ')' '{' '}' ' ' except for a regex with respect to rule 1)
164164
5) the filters cannot integrate a ','
165165
@@ -196,7 +196,9 @@ void drawGui()
196196
{
197197
// open Dialog Simple
198198
if (ImGui::Button("Open File Dialog"))
199-
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".cpp,.h,.hpp", ".");
199+
IGFD::FileDialogConfig config;
200+
config.path = ".";
201+
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".cpp,.h,.hpp", config);
200202
201203
// display
202204
if (ImGuiFileDialog::Instance()->Display("ChooseFileDlgKey"))
@@ -230,8 +232,11 @@ ImGuiFileDialogFlags_Modal
230232
you can use it like that :
231233
232234
```cpp
233-
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".cpp,.h,.hpp",
234-
".", 1, nullptr, ImGuiFileDialogFlags_Modal);
235+
IGFD::FileDialogConfig config;
236+
config.path = ".";
237+
config.countSelectionMax = 1;
238+
config.flags = ImGuiFileDialogFlags_Modal;
239+
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".cpp,.h,.hpp", config);
235240
```
236241
237242
################################################################
@@ -241,7 +246,9 @@ ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".cpp
241246
To have a directory chooser, set the file extension filter to nullptr:
242247
243248
```cpp
244-
ImGuiFileDialog::Instance()->OpenDialog("ChooseDirDlgKey", "Choose a Directory", nullptr, ".");
249+
IGFD::FileDialogConfig config;
250+
config.path = ".";
251+
ImGuiFileDialog::Instance()->OpenDialog("ChooseDirDlgKey", "Choose a Directory", nullptr, config);
245252
```
246253
247254
In this mode you can select any directory with one click and open a directory with a double-click.
@@ -285,10 +292,16 @@ the user cant validate the dialog
285292
void drawGui()
286293
{
287294
// open Dialog with Pane
288-
if (ImGui::Button("Open File Dialog with a custom pane"))
289-
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".cpp,.h,.hpp",
290-
".", "", std::bind(&InfosPane, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), 350, 1,
291-
UserDatas("InfosPane"));
295+
if (ImGui::Button("Open File Dialog with a custom pane")) {
296+
IGFD::FileDialogConfig config;
297+
config.path = ".";
298+
config.countSelectionMax = 1;
299+
config.sidePane = std::bind(&InfosPane, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
300+
config.sidePaneWidth = 350.0f;
301+
config.useDatas = UserDatas("InfosPane");
302+
config.flags = ImGuiFileDialogFlags_Modal;
303+
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".cpp,.h,.hpp", config);
304+
}
292305
293306
// display and action if ok
294307
if (ImGuiFileDialog::Instance()->Display("ChooseFileDlgKey"))
@@ -379,16 +392,13 @@ samples :
379392
380393
```cpp
381394
// define style by file extention and Add an icon for .png files
382-
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtention, ".png", ImVec4(0.0f, 1.0f, 1.0f, 0.9f),
383-
ICON_IGFD_FILE_PIC, font1); ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtention, ".gif",
384-
ImVec4(0.0f, 1.0f, 0.5f, 0.9f), "[GIF]");
395+
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtention, ".png", ImVec4(0.0f, 1.0f, 1.0f, 0.9f),,ICON_IGFD_FILE_PIC, font1);
396+
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtention, ".gif", ImVec4(0.0f, 1.0f, 0.5f, 0.9f), "[GIF]");
385397
386398
// define style for all directories
387-
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeDir, "", ImVec4(0.5f, 1.0f, 0.9f, 0.9f),
388-
ICON_IGFD_FOLDER);
399+
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeDir, "", ImVec4(0.5f, 1.0f, 0.9f, 0.9f), ICON_IGFD_FOLDER);
389400
// can be for a specific directory
390-
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeDir, ".git", ImVec4(0.5f, 1.0f, 0.9f, 0.9f),
391-
ICON_IGFD_FOLDER);
401+
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeDir, ".git", ImVec4(0.5f, 1.0f, 0.9f, 0.9f), ICON_IGFD_FOLDER);
392402
393403
// define style for all files
394404
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeFile, "", ImVec4(0.5f, 1.0f, 0.9f, 0.9f), ICON_IGFD_FILE);
@@ -470,11 +480,13 @@ for filter names.
470480
this code :
471481
472482
```cpp
473-
const char *filters = "Source files (*.cpp *.h *.hpp){.cpp,.h,.hpp},Image files (*.png *.gif *.jpg
474-
*.jpeg){.png,.gif,.jpg,.jpeg},.md"; ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", ICON_IMFDLG_FOLDER_OPEN
475-
" Choose a File", filters, ".");
483+
const char *filters = "Source files (*.cpp *.h *.hpp){.cpp,.h,.hpp},Image files (*.png *.gif *.jpg *.jpeg){.png,.gif,.jpg,.jpeg},.md";
484+
IGFD::FileDialogConfig config;
485+
config.path = ".";
486+
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", ICON_IMFDLG_FOLDER_OPEN " Choose a File", filters, config);
476487
```
477488
489+
478490
will produce :
479491
![alt text](https://github.com/aiekick/ImGuiFileDialog/blob/master/doc/filters.gif)
480492
@@ -491,13 +503,24 @@ You can define in OpenDialog call the count file you want to select :
491503
See the define at the end of these funcs after path.
492504
493505
```cpp
494-
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".*,.cpp,.h,.hpp", ".");
495-
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose 1 File", ".*,.cpp,.h,.hpp", ".", 1);
496-
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose 5 File", ".*,.cpp,.h,.hpp", ".", 5);
497-
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose many File", ".*,.cpp,.h,.hpp", ".", 0);
498-
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".png,.jpg",
499-
".", "", std::bind(&InfosPane, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), 350, 1,
500-
"SaveFile"); // 1 file
506+
IGFD::FileDialogConfig config; config.path = ".";
507+
508+
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".*,.cpp,.h,.hpp", config);
509+
510+
config.countSelectionMax = 1;
511+
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose 1 File", ".*,.cpp,.h,.hpp", config);
512+
513+
config.countSelectionMax = 5;
514+
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose 5 File", ".*,.cpp,.h,.hpp", config);
515+
516+
config.countSelectionMax = 0;
517+
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose many File", ".*,.cpp,.h,.hpp", config);
518+
519+
config.countSelectionMax = 1;
520+
config.sidePane = std::bind(&InfosPane, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
521+
config.sidePaneWidth = 350.0f;
522+
config.useDatas = UserDatas("SaveFile");
523+
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".png,.jpg", config); // 1 file
501524
```
502525
503526
![alt text](https://github.com/aiekick/ImGuiFileDialog/blob/master/doc/multiSelection.gif)
@@ -606,17 +629,20 @@ behavior. (by design! :) )
606629
Example code For Standard Dialog :
607630
608631
```cpp
632+
IGFD::FileDialogConfig config;
633+
config.path = ".";
634+
config.flags = ImGuiFileDialogFlags_ConfirmOverwrite;
609635
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey",
610-
ICON_IGFD_SAVE " Choose a File", filters,
611-
".", "", 1, nullptr, ImGuiFileDialogFlags_ConfirmOverwrite);
636+
ICON_IGFD_SAVE " Choose a File", filters, config);
612637
```
613638
614639
Example code For Modal Dialog :
615640
616641
```cpp
617-
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey",
618-
ICON_IGFD_SAVE " Choose a File", filters,
619-
".", "", 1, nullptr, ImGuiFileDialogFlags_Modal | ImGuiFileDialogFlags_ConfirmOverwrite);
642+
IGFD::FileDialogConfig config;
643+
config.path = ".";
644+
config.flags = ImGuiFileDialogFlags_Modal | ImGuiFileDialogFlags_ConfirmOverwrite;
645+
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", ICON_IGFD_SAVE " Choose a File", filters, config);
620646
```
621647
622648
This dialog will only verify the file in the file field, not with `GetSelection()`.
@@ -768,15 +794,18 @@ ex :
768794
ImGuiFileDialog fileDialog;
769795
770796
// open dialog; in this case, Bookmark, directory creation are disabled with, and also the file input field is readonly.
771-
// btw you can do what you want
772-
fileDialog.OpenDialog("embedded", "Select File", ".*", "", -1, nullptr,
773-
ImGuiFileDialogFlags_NoDialog |
797+
// btw you can od what you want
798+
IGFD::FileDialogConfig config;
799+
config.path = ".";
800+
config.countSelectionMax = -1;
801+
config.flags = ImGuiFileDialogFlags_NoDialog |
774802
ImGuiFileDialogFlags_DisableBookmarkMode |
775803
ImGuiFileDialogFlags_DisableCreateDirectoryButton |
776804
ImGuiFileDialogFlags_ReadOnlyFileNameField);
805+
fileDialog.OpenDialog("embedded", "Select File", ".*", config);
777806
// then display, here
778-
// to note, when embedded the ImVec2(0,0) (MinSize) do nothing, only the ImVec2(0,350) (MaxSize) can size the dialog
779-
frame fileDialog.Display("embedded", ImGuiWindowFlags_NoCollapse, ImVec2(0,0), ImVec2(0,350)))
807+
// to note, when embedded the ImVec2(0,0) (MinSize) do nothing, only the ImVec2(0,350) (MaxSize) can size the dialog frame
808+
fileDialog.Display("embedded", ImGuiWindowFlags_NoCollapse, ImVec2(0,0), ImVec2(0,350)))
780809
```
781810
the result :
782811
@@ -1040,20 +1069,15 @@ Sample code with cimgui :
10401069
ImGuiFileDialog *cfileDialog = IGFD_Create();
10411070
10421071
// open dialog
1043-
if (igButton("Open File", buttonSize))
1044-
{
1072+
if (igButton("Open File", buttonSize)) {
1073+
IGFD_FileDialog_Config config = IGFD_FileDialog_Config_Get();
1074+
config.path = ".";
1075+
config.flags = ImGuiFileDialogFlags_ConfirmOverwrite; // ImGuiFileDialogFlags
10451076
IGFD_OpenDialog(cfiledialog,
1046-
"filedlg", // dialog key (make it possible to have different treatment reagrding
1047-
the dialog key "Open a File", // dialog title "c files(*.c *.h){.c,.h}", // dialog
1048-
filter syntax : simple => .h,.c,.pp, etc and collections : text1{filter0,filter1,filter2},
1049-
text2{filter0,filter1,filter2}, etc..
1050-
".", // base directory for files scan
1051-
"", // base filename
1052-
0, // a fucntion for display a right pane if you want
1053-
0.0f, // base width of the pane
1054-
0, // count selection : 0 infinite, 1 one file (default), n (n files)
1055-
"User data !", // some user datas
1056-
ImGuiFileDialogFlags_ConfirmOverwrite); // ImGuiFileDialogFlags
1077+
"filedlg", // dialog key (make it possible to have different treatment reagrding the dialog key
1078+
"Open a File", // dialog title
1079+
"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..
1080+
config); // the file dialog config
10571081
}
10581082
10591083
ImGuiIO* ioptr = igGetIO();
@@ -2220,12 +2244,12 @@ typedef void (*IGFD_CreateThumbnailFun)(IGFD_Thumbnail_Info*); // callback fun
22202244
typedef void (*IGFD_DestroyThumbnailFun)(IGFD_Thumbnail_Info*); // callback fucntion for destroy thumbnail texture
22212245
#endif // USE_THUMBNAILS
22222246

2223-
IGFD_C_API void IGFD_OpenDialog( // open a standard dialog
2224-
ImGuiFileDialog* vContextPtr, // ImGuiFileDialog context
2225-
const char* vKey, // key dialog
2226-
const char* vTitle, // title
2227-
const char* vFilters, // filters/filter collections. set it to null for directory mode
2228-
const IGFD_FileDialog_Config vConfig); // path
2247+
IGFD_C_API void IGFD_OpenDialog( // open a standard dialog
2248+
ImGuiFileDialog* vContextPtr, // ImGuiFileDialog context
2249+
const char* vKey, // key dialog
2250+
const char* vTitle, // title
2251+
const char* vFilters, // filters/filter collections. set it to null for directory mode
2252+
const IGFD_FileDialog_Config vConfig = {}); // config
22292253

22302254
IGFD_C_API bool IGFD_DisplayDialog( // Display the dialog
22312255
ImGuiFileDialog* vContextPtr, // ImGuiFileDialog context

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,16 @@ inline void InfosPane(cosnt char *vFilter, IGFDUserDatas vUserDatas, bool *vCant
233233
void drawGui()
234234
{
235235
// open Dialog with Pane
236-
if (ImGui::Button("Open File Dialog with a custom pane"))
236+
if (ImGui::Button("Open File Dialog with a custom pane")) {
237237
IGFD::FileDialogConfig config;
238238
config.path = ".";
239239
config.countSelectionMax = 1;
240240
config.sidePane = std::bind(&InfosPane, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
241241
config.sidePaneWidth = 350.0f;
242242
config.useDatas = UserDatas("InfosPane");
243243
config.flags = ImGuiFileDialogFlags_Modal;
244-
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".cpp,.h,.hpp", config);
244+
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".cpp,.h,.hpp", config);
245+
}
245246

246247
// display and action if ok
247248
if (ImGuiFileDialog::Instance()->Display("ChooseFileDlgKey"))

0 commit comments

Comments
 (0)