Skip to content

Commit f6b0621

Browse files
Update README.md
1 parent 3b3a1d4 commit f6b0621

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

README.md

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
12
[![Build Status](https://travis-ci.com/gallickgunner/ImGui-Addons.svg?branch=master)](https://travis-ci.com/gallickgunner/ImGui-Addons)
23

34
# ImGui-Addons
45
Addon widgets for GUI library Dear ImGui.
56

67
## File Dialog
7-
A simple cross-platform file dialog that uses [dirent](https://github.com/tronkko/dirent) interface for reading directories and files. It's present as a standard header file in Unix based systems afaik and is also contained in some compilers like MinGW but I have decided to use Toni Rönkkö's ported version so atleast the code remains compiler independent. Both Open and Save file dialogs are supported.
8+
A simple cross-platform file dialog that uses [dirent](https://github.com/tronkko/dirent) interface for reading directories and files. It's present as a standard header file in Unix based systems afaik and is also contained in some compilers like MinGW but I have decided to use Toni Rönkkö's ported version so atleast the code remains compiler independent. Both Open and Save file dialogs are supported. **C++11 is required**.
89

910
Code uses ported `dirent.h` provided by Toni on Windows and on UNIX code uses standard `dirent.h` header, but unfortunately the code hasn't been checked extensively on UNIX based systems especially MacOS. So if someone finds problems on other platforms do tell me or submit a pull request. Also I don't think the code will work with Unicode paths containing language specific or other special characters as I blatantly use normal `char*` and `std::string` everywhere. The ported `dirent.h` for Windows uses `wcstombs` function to convert widechars to multibyte sequences but according to the docs this also fails if a wide character that doesnt' correspond to a valid Mulitbyte char is encountered. Anyways Not an expert at this topic so you may find errors if your paths contain special characters outside the normal 0-255 range.
1011

@@ -40,24 +41,33 @@ void showMainMenu()
4041
if(save)
4142
ImGui::OpenPopup("Save File");
4243
43-
/* Optional third parameter. Support opening only compressed rar/zip files.
44-
* Opening any other file will show error, return false and won't close the dialog.
45-
*/
46-
if(file_dialog.showOpenFileDialog("Open File", ImVec2(700, 310), ".rar,.zip,.7z"))
47-
std::cout << file_dialog.selected_fn << std::endl;
48-
if(file_dialog.showSaveFileDialog("Save File", ImVec2(700, 310), ".png,.jpg,.bmp"))
49-
{
50-
std::cout << file_dialog.selected_fn << std::endl; // Absolute path to file with extension
51-
std::cout << file_dialog.ext << std::endl; // Access ext separately
52-
//Do writing of files based on extension here
53-
}
44+
/* Optional third parameter. Support opening only compressed rar/zip files.
45+
* Opening any other file will show error, return false and won't close the dialog.
46+
*/
47+
if(file_dialog.showFileDialog("Open File", imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, ImVec2(700, 310), ".rar,.zip,.7z"))
48+
{
49+
std::cout << file_dialog.selected_fn << std::endl; // The name of the selected file or directory in case of Select Directory dialog mode
50+
std::cout << file_dialog.selected_path << std::endl; // The absolute path to the selected file
51+
}
52+
if(file_dialog.showFileDialog("Save File", imgui_addons::ImGuiFileBrowser::DialogMode::SAVE, ImVec2(700, 310), ".png,.jpg,.bmp"))
53+
{
54+
std::cout << file_dialog.selected_fn << std::endl; // The name of the selected file or directory in case of Select Directory dialog mode
55+
std::cout << file_dialog.selected_path << std::endl; // The absolute path to the selected file
56+
std::cout << file_dialog.ext << std::endl; // Access ext separately (For SAVE mode)
57+
//Do writing of files based on extension here
58+
}
5459
}
5560
```
56-
I've also added the modified `imgui_demo.cpp` to include the file dialog in the menu bar so you can check how it's working there.
61+
Note that the Save file dialog just stores whatever name the user types in `selected_fn` The user may try to save with a different extension than one already selected in the *extension box* This is upto the programmer, whether to use the extension selected in the UI or the one typed in the file name by the user. I've also added the modified `imgui_demo.cpp` to include the file dialog in the menu bar so you can check how it's working there.
5762

5863
Enough chitchat, here's a gif in-action, click for full video (I hope you guys don't consider me a weeb after seeing the screensavers collection xD )
5964

60-
[![Demo](https://i.imgur.com/HcwKNmi.gif)](https://www.youtube.com/watch?v=cPyfgYFdiy0)
65+
[![Demo](https://i.imgur.com/kNOeYme.gif)](https://www.youtube.com/watch?v=cPyfgYFdiy0)
6166

67+
# Update
6268

69+
So the file dialog has been revamped to closely resemble the Windows file dialog. I've tried my best, and I'm happy with the results. Some internal workings have changed so gonna highlight them here.
6370

71+
* 3 Different modes are supported currently. `OPEN` for opening files, `SAVE` for saving files an `SELECT` for selecting a directory.
72+
* There is only a single function call now `showFileDialog()`. A `DialogMode` enum is exposed (with values defined above) publicly which allows switching between different modes.
73+
* The selected file/folder name and the absolute path can be accessed separately through `selected_fn` and `selected_path` respectively.

0 commit comments

Comments
 (0)