Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
gallickgunner authored Mar 13, 2020
1 parent 3b3a1d4 commit f6b0621
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@

[![Build Status](https://travis-ci.com/gallickgunner/ImGui-Addons.svg?branch=master)](https://travis-ci.com/gallickgunner/ImGui-Addons)

# ImGui-Addons
Addon widgets for GUI library Dear ImGui.

## File Dialog
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.
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**.

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.

Expand Down Expand Up @@ -40,24 +41,33 @@ void showMainMenu()
if(save)
ImGui::OpenPopup("Save File");
/* Optional third parameter. Support opening only compressed rar/zip files.
* Opening any other file will show error, return false and won't close the dialog.
*/
if(file_dialog.showOpenFileDialog("Open File", ImVec2(700, 310), ".rar,.zip,.7z"))
std::cout << file_dialog.selected_fn << std::endl;
if(file_dialog.showSaveFileDialog("Save File", ImVec2(700, 310), ".png,.jpg,.bmp"))
{
std::cout << file_dialog.selected_fn << std::endl; // Absolute path to file with extension
std::cout << file_dialog.ext << std::endl; // Access ext separately
//Do writing of files based on extension here
}
/* Optional third parameter. Support opening only compressed rar/zip files.
* Opening any other file will show error, return false and won't close the dialog.
*/
if(file_dialog.showFileDialog("Open File", imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, ImVec2(700, 310), ".rar,.zip,.7z"))
{
std::cout << file_dialog.selected_fn << std::endl; // The name of the selected file or directory in case of Select Directory dialog mode
std::cout << file_dialog.selected_path << std::endl; // The absolute path to the selected file
}
if(file_dialog.showFileDialog("Save File", imgui_addons::ImGuiFileBrowser::DialogMode::SAVE, ImVec2(700, 310), ".png,.jpg,.bmp"))
{
std::cout << file_dialog.selected_fn << std::endl; // The name of the selected file or directory in case of Select Directory dialog mode
std::cout << file_dialog.selected_path << std::endl; // The absolute path to the selected file
std::cout << file_dialog.ext << std::endl; // Access ext separately (For SAVE mode)
//Do writing of files based on extension here
}
}
```
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.
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.

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 )

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

# Update

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.

* 3 Different modes are supported currently. `OPEN` for opening files, `SAVE` for saving files an `SELECT` for selecting a directory.
* 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.
* The selected file/folder name and the absolute path can be accessed separately through `selected_fn` and `selected_path` respectively.

0 comments on commit f6b0621

Please sign in to comment.