Skip to content

Commit e71087b

Browse files
committed
[URFR] : update the readme like in master branch
1 parent 333e535 commit e71087b

File tree

1 file changed

+90
-73
lines changed

1 file changed

+90
-73
lines changed

README.md

Lines changed: 90 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,43 @@
44

55
# ImGuiFileDialog
66

7-
## Why ?
7+
## Purpose
88

9-
this File Dialog is build on top of [Dear ImGui](https://github.com/ocornut/imgui)
9+
ImGuiFileDialog is a file selection dialog built for (and using only) [Dear ImGui](https://github.com/ocornut/imgui).
1010

11-
this filedialog was created principally for have custom pane with widgets according to file extention.
12-
it was not possible with native filedialog
11+
My primary goal was to have a custom pane with widgets according to file extension. This was not possible using other solutions.
1312

1413
## Structure of this repo
1514

16-
* The lib is in [Lib_Only branch](https://github.com/aiekick/ImGuiFileDialog/tree/Lib_Only)
15+
* The library is in [Lib_Only branch](https://github.com/aiekick/ImGuiFileDialog/tree/Lib_Only)
1716
* A demo app can be found the [master branch](https://github.com/aiekick/ImGuiFileDialog/tree/master)
1817

18+
This library is designed to be dropped into your source code rather than compiled separately.
19+
20+
From your project directory:
21+
22+
```
23+
mkdir lib
24+
cd lib
25+
git clone https://github.com/aiekick/ImGuiFileDialog.git
26+
git checkout Lib_Only
27+
```
28+
29+
These commands create a `lib` directory where you can store any third-party dependencies used in your
30+
project, downloads the ImGuiFileDialog git repository and checks out the Lib_Only branch where the
31+
actual library code is located.
32+
33+
Add `lib/ImGuiFileDialog/ImGuiFileDialog.cpp` to your build system and include
34+
`lib/ImGuiFileDialog/ImGuiFileDialog.h` in your source code. ImGuiFileLib will compile with and be
35+
included directly in your executable file.
36+
37+
If, for example, your project uses cmake, look for a line like `add_executable(my_project_name main.cpp)`
38+
and change it to `add_executable(my_project_name lib/ImGuiFileDialog/ImGuiFileDialog.cpp main.cpp)`.
39+
This tells the compiler where to find the source code declared in `ImGuiFileDialog.h` which you included in your own source code.
40+
41+
You must also, of course, have added [Dear ImGui](https://github.com/ocornut/imgui) to your project for this to work at all.
42+
43+
1944
## Features
2045

2146
- Separate system for call and display
@@ -40,23 +65,25 @@ it was not possible with native filedialog
4065
- Support of a 'Confirm to Overwrite" dialog if File Exist
4166
- A C Api is available (Succesfully testec with CimGui
4267

43-
## SingleTon / Multi-Instance
68+
## Singleton Pattern vs. Multiple Instances
4469

45-
you have many possiblities :
70+
### Single Dialog :
4671

47-
### Singleton :
72+
If you only need to display one file dialog at a time, use ImGuiFileDialog's singleton pattern to avoid explicitly declaring an object:
4873

49-
With a singleton, you can easily manage the dialog without the need to define an instance. but you can display only one dialog at a time
5074
```cpp
5175
ImGuiFileDialog::Instance()->method_of_your_choice();
5276
```
5377

54-
### Multi Instance :
78+
### Multiple Dialogs :
79+
80+
If you need to have multiple file dialogs open at once, declare each dialog explicity:
5581

56-
for have the ability to display at same time, many dialogs. you must define your own instance
5782
```cpp
58-
ImGuiFileDialog instance;
59-
instance.method_of_your_choice();
83+
ImGuiFileDialog instance_a;
84+
instance_a.method_of_your_choice();
85+
ImGuiFileDialog instance_b;
86+
instance_b.method_of_your_choice();
6087
```
6188

6289
## Simple Dialog :
@@ -85,20 +112,22 @@ void drawGui()
85112
```
86113
![alt text](https://github.com/aiekick/ImGuiFileDialog/blob/master/doc/dlg_simple.gif)
87114

115+
88116
## Directory Chooser :
89117

90-
For have only a directory chooser, you just need to specify a filter to null :
118+
To have a directory chooser, set the file extension filter to nullptr:
91119
```cpp
92120
ImGuiFileDialog::Instance()->OpenDialog("ChooseDirDlgKey", "Choose a Directory", nullptr, ".");
93121
```
94122
95-
In this mode you can select any directory with one click, and open directory with double click
123+
In this mode you can select any directory with one click and open a directory with a double-click.
96124
97125
![directoryChooser](https://github.com/aiekick/ImGuiFileDialog/blob/master/doc/directoryChooser.gif)
98126
127+
99128
## Dialog with Custom Pane :
100129
101-
the stamp of the custom pane callback is :
130+
The signature of the custom pane callback is:
102131
103132
### for C++ :
104133
```cpp
@@ -157,7 +186,7 @@ void drawGui()
157186
158187
## Filter Infos
159188
160-
You can define color for a filter type
189+
You can define a color for a filter type
161190
```cpp
162191
ImGuiFileDialog::Instance()->SetExtentionInfos(".cpp", ImVec4(1,1,0, 0.9));
163192
ImGuiFileDialog::Instance()->SetExtentionInfos(".h", ImVec4(0,1,0, 0.9));
@@ -167,7 +196,7 @@ ImGuiFileDialog::Instance()->SetExtentionInfos(".md", ImVec4(1,0,1, 0.9));
167196

168197
![alt text](https://github.com/aiekick/ImGuiFileDialog/blob/master/doc/color_filter.png)
169198

170-
and also specific icons (with icon font files) or file type names :
199+
ImGuiFileDialog accepts icon font macros as well as text tags for file types. See [IconFontCppHeaders](https://github.com/juliettef/IconFontCppHeaders) for a widely used Dear Imgui icon font helper or with [ImGuIFontStudio](https://github.com/aiekick/ImGuiFontStudio) (a gui tool for easily doing the same as IconFontCppHeaders)
171200

172201
```cpp
173202
// add an icon for png files
@@ -180,11 +209,11 @@ ImGuiFileDialog::Instance()->SetExtentionInfos(".gif", ImVec4(0, 1, 0.5, 0.9), "
180209
181210
## Filter Collections
182211
183-
you can define a custom filter name who correspond to a group of filter
212+
You can define a custom filter name that corresponds to a group of filters using this syntax:
213+
214+
```custom_name1{filter1,filter2,filter3},custom_name2{filter1,filter2},filter1```
184215
185-
you must use this syntax : custom_name1{filter1,filter2,filter3},custom_name2{filter1,filter2},filter1
186-
when you will select custom_name1, the gorup of filter 1 to 3 will be applied
187-
the reserved char are {}, you cant use them for define filter name.
216+
When you select custom_name1, filters 1 to 3 will be applied. The characters `{` and `}` are reserved. Don't use them for filter names.
188217
189218
this code :
190219
```cpp
@@ -216,16 +245,11 @@ ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".png
216245
217246
## File Dialog Constraints
218247
219-
you can define min/max size of the dialog when you display It
220-
221-
by ex :
222-
223-
* MaxSize is the full display size
224-
* MinSize in the half display size.
248+
You can set the minimum and/or maximum size of the dialog:
225249
226250
```cpp
227-
ImVec2 maxSize = ImVec2((float)display_w, (float)display_h);
228-
ImVec2 minSize = maxSize * 0.5f;
251+
ImVec2 maxSize = ImVec2((float)display_w, (float)display_h); // The full display area
252+
ImVec2 minSize = maxSize * 0.5f; // Half the display area
229253
ImGuiFileDialog::Instance()->Display("ChooseFileDlgKey", ImGuiWindowFlags_NoCollapse, minSize, maxSize);
230254
```
231255

@@ -291,26 +315,21 @@ Save => std::string bookmarkString = ImGuiFileDialog::Instance()->SerializeBookm
291315
292316
## Path Edition :
293317
294-
if you click right on one of any path button, you can input or modify the path pointed by this button.
295-
then press the validate key (Enter by default with GLFW) for validate the new path
296-
or press the escape key (Escape by default with GLFW) for quit the input path edition
297-
298-
see in this gif :
299-
1) button edition with mouse button right and escape key for quit the edition
300-
2) focus the input and press validation for set path
318+
Right clicking on any path element button allows the user to manually edit the path from that portion of the tree.
319+
Pressing the completion key (GLFW uses `enter` by default) validates the new path.
320+
Pressing the cancel key (GLFW uses`escape` by default) cancels the manual entry and restores the original path.
301321
322+
Here's the manual entry operation in action:
302323
![inputPathEdition.gif](https://github.com/aiekick/ImGuiFileDialog/blob/master/doc/inputPathEdition.gif)
303324
304-
## Confirm to OverWrite Dialog :
325+
## Confirm Overwrite Dialog :
305326
306-
If you want avoid OverWrite your files after confirmation,
307-
you can show a Dialog for confirm or cancel the OverWrite operation.
327+
If you want avoid overwriting files after selection, ImGuiFileDialog can show a dialog to confirm or cancel the operation.
308328
309-
You just need to define the flag ImGuiFileDialogFlags_ConfirmOverwrite
310-
in your call to OpenDialog/OpenModal
329+
To do so, define the flag ImGuiFileDialogFlags_ConfirmOverwrite in your call to OpenDialog/OpenModal.
311330
312-
By default this flag is not set, since there is no pre-defined way to
313-
define if a dialog will be for Open or Save behavior. (and its wanted :) )
331+
By default this flag is not set since there is no pre-defined way to
332+
define if a dialog will be for Open or Save behavior. (by design! :) )
314333
315334
Example code For Standard Dialog :
316335
```cpp
@@ -326,16 +345,14 @@ ImGuiFileDialog::Instance()->OpenModal("ChooseFileDlgKey",
326345
".", "", 1, nullptr, ImGuiFileDialogFlags_ConfirmOverwrite);
327346
```
328347
329-
This dialog will only verify the file in the file field.
330-
So Not to be used with GetSelection()
348+
This dialog will only verify the file in the file field, not with `GetSelection()`.
331349
332-
The Confirm dialog will be a forced Modal Dialog, not moveable, displayed
333-
in the center of the current FileDialog.
350+
The confirmation dialog will be a non-movable modal (input blocking) dialog displayed
351+
in the middle of the current ImGuiFileDialog window.
334352
335-
As usual you can customize the dialog,
336-
in you custom config file (CustomImGuiFileDialogConfig.h in this example)
353+
As usual, you can customize the dialog in your custom config file (CustomImGuiFileDialogConfig.h in this example)
337354
338-
you can uncomment the next lines for customize it :
355+
Uncomment these line for customization options:
339356
```cpp
340357
//#define OverWriteDialogTitleString "The file Already Exist !"
341358
//#define OverWriteDialogMessageString "Would you like to OverWrite it ?"
@@ -349,22 +366,26 @@ See the result :
349366

350367
## Open / Save dialog Behavior :
351368

352-
There is no way to distinguish the "open dialog" behavior than "save dialog" behavior.
353-
So you msut adapt the return according to your need :
369+
ImGuiFileDialog uses the same code internally for Open and Save dialogs. To distinguish between them access the
370+
various data return functions depending on what the dialog is doing.
354371

355-
if you want open file(s) or directory(s), you must use : GetSelection() method. you will obtain a std::map<FileName, FilePathName> of the selection
356-
if you want create a file, you must use : GetFilePathName()/GetCurrentFileName()
372+
When selecting an existing file (for example, a Load or Open dialog), use
357373

358-
the return method's and comments :
359374
```cpp
360-
std::map<std::string, std::string> GetSelection(); // Open File behavior : will return selection via a map<FileName, FilePathName>
361-
std::string GetFilePathName(); // Create File behavior : will always return the content of the field with current filter extention and current path
362-
std::string GetCurrentFileName(); // Create File behavior : will always return the content of the field with current filter extention
363-
std::string GetCurrentPath(); // will return current path
364-
std::string GetCurrentFilter(); // get selected filter
365-
UserDatas GetUserDatas(); // get user datas send with Open Dialog
375+
std::map<std::string, std::string> GetSelection(); // Returns selection via a map<FileName, FilePathName>
376+
UserDatas GetUserDatas(); // Get user data provided by the Open dialog
366377
```
367378

379+
To selecting a new file (for example, a Save As... dialog), use:
380+
381+
```cpp
382+
std::string GetFilePathName(); // Returns the content of the selection field with current file extension and current path
383+
std::string GetCurrentFileName(); // Returns the content of the selection field with current file extension but no path
384+
std::string GetCurrentPath(); // Returns current path only
385+
std::string GetCurrentFilter(); // The file extension
386+
```
387+
388+
368389
## How to Integrate ImGuiFileDialog in your project
369390

370391
### ImGuiFileDialog require :
@@ -374,18 +395,14 @@ UserDatas GetUserDatas(); // get user datas send with O
374395

375396
### Customize ImGuiFileDialog :
376397

377-
You just need to write your own config file by override the file : ImGuiFileDialog/ImGuiFileDialogConfig.h
378-
like i do here with CustomImGuiFileDialogConfig.h
379-
380-
After that, for let ImGuiFileDialog your own custom file,
381-
you must define the preprocessor directive CUSTOM_IMGUIFILEDIALOG_CONFIG with the path of you custom config file.
382-
This path must be relative to the directory where you put ImGuiFileDialog module.
398+
You can customize many aspects of ImGuiFileDialog by overriding `ImGuiFileDialogConfig.h`.
383399

384-
Thats all.
400+
To enable your customizations, define the preprocessor directive CUSTOM_IMGUIFILEDIALOG_CONFIG with the path of your custom config file.
401+
This path must be relative to the directory where you put the ImGuiFileDialog module.
385402

386-
You can check by example in this repo with the file CustomImGuiFileDialogConfig.h :
387-
- this trick was used for have custom icon font instead of labels for buttons or messages titles
388-
- you can also use your custom imgui button, the button call stamp must be same by the way :)
403+
This operation is demonstrated in `CustomImGuiFileDialog.h` in the example project to:
404+
* Have a custom icon font instead of labels for buttons or message titles
405+
* Customize the button text (the button call signature must be the same, by the way! :)
389406

390407
The Custom Icon Font (in [CustomFont.cpp](CustomFont.cpp) and [CustomFont.h](CustomFont.h)) was made with [ImGuiFontStudio](https://github.com/aiekick/ImGuiFontStudio) i wrote for that :)
391408
ImGuiFontStudio is using also ImGuiFileDialog.
@@ -738,4 +755,4 @@ feature : USE_BOOKMARK
738755
IMGUIFILEDIALOG_API void IGFD_DeserializeBookmarks( // deserialize bookmarks : load bookmar buffer to load in the dialog (saved from previous use with SerializeBookmarks())
739756
ImGuiFileDialog* vContext, // ImGuiFileDialog context
740757
const char* vBookmarks); // bookmark buffer to load
741-
```
758+
```

0 commit comments

Comments
 (0)