Skip to content

Commit 709d54e

Browse files
committed
Add README
1 parent d68c79d commit 709d54e

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

README.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# imgui-filebrowser
2+
3+
[imgui-filebrowser](https://github.com/AirGuanZ/imgui-filebrowser) is a simple file browser implementation for [dear-imgui](https://github.com/ocornut/imgui).
4+
5+
![IMG](./screenshots/0.png)
6+
7+
## Getting Started
8+
9+
imgui-filebrowser is header-only and must be included after imgui.h:
10+
11+
```cpp
12+
#include <imgui.h>
13+
#include <imfilebrowser.h>
14+
```
15+
16+
It's hard for me to design interface for a stateless file browser. Thus, instead of creating a file dialog by a immediate function call, user needs to create a `ImGui::FileBrowser` instance, open it with member function `Open()`, and calls `Display()` in each rendering frame. Here is a simple example:
17+
18+
```cpp
19+
#include <imgui.h>
20+
#include <imfilebrowser.h>
21+
22+
int main()
23+
{
24+
//...initialize rendering window and imgui
25+
26+
// create a file browser instance
27+
ImGui::FileBrowser fileDialog(ImGuiFileBrowserFlags_EnterNewFilename);
28+
29+
// mainloop
30+
while(continueRendering)
31+
{
32+
//...do other stuff like ImGui::NewFrame();
33+
34+
// open file dialog when user clicks this button
35+
if(ImGui::Button("open file dialog"))
36+
fileDialog.Open();
37+
38+
fileDialog.Display();
39+
40+
if(fileDialog.HasSelected())
41+
{
42+
std::cout << "Selected filename" << fileDialog.GetSelected() << std::endl;
43+
fileDialog.ClearSelected();
44+
}
45+
46+
//...do other stuff like ImGui::Render();
47+
}
48+
49+
//...shutdown
50+
}
51+
```
52+

imfilebrowser.h

+2
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,15 @@ inline void ImGui::FileBrowser::SetTitle(std::string title)
116116
inline void ImGui::FileBrowser::Open()
117117
{
118118
ClearSelected();
119+
statusStr_ = std::string();
119120
openFlag_ = true;
120121
closeFlag_ = false;
121122
}
122123

123124
inline void ImGui::FileBrowser::Close()
124125
{
125126
ClearSelected();
127+
statusStr_ = std::string();
126128
closeFlag_ = true;
127129
openFlag_ = false;
128130
}

screenshots/0.png

24 KB
Loading

0 commit comments

Comments
 (0)