@@ -12,11 +12,11 @@ using ImGuiFileBrowserFlags = int;
12
12
13
13
enum ImGuiFileBrowserFlags_
14
14
{
15
- ImGuiFileBrowserFlags_SelectDirectory = 1 << 1 ,
16
- ImGuiFileBrowserFlags_EnterNewFilename = 1 << 2 ,
17
- ImGuiFileBrowserFlags_NoModal = 1 << 3 ,
18
- ImGuiFileBrowserFlags_NoTitleBar = 1 << 4 ,
19
- ImGuiFileBrowserFlags_NoStatusBar = 1 << 5 ,
15
+ ImGuiFileBrowserFlags_SelectDirectory = 1 << 0 , // select directory instead of regular file
16
+ ImGuiFileBrowserFlags_EnterNewFilename = 1 << 1 , // allow user to enter new filename when selecting regular file
17
+ ImGuiFileBrowserFlags_NoModal = 1 << 2 , // file browsing window is modal by default. specify this to use a popup window
18
+ ImGuiFileBrowserFlags_NoTitleBar = 1 << 3 , // hide window title bar
19
+ ImGuiFileBrowserFlags_NoStatusBar = 1 << 4 , // hide status bar at the bottom of browsing window
20
20
};
21
21
22
22
namespace ImGui
@@ -25,36 +25,34 @@ namespace ImGui
25
25
{
26
26
public:
27
27
28
- // 默认将pwd设置为当前工作目录,可通过SetPwd修改
28
+ // pwd is set to current working directory by default
29
29
explicit FileBrowser (ImGuiFileBrowserFlags flags = 0 );
30
30
31
- // 设置窗口标题文字,以utf-8编码
31
+ // set the window title text
32
32
void SetTitle (std::string title);
33
33
34
- // 打开文件窗口
34
+ // open the browsing window
35
35
void Open ();
36
36
37
- // 关闭文件窗口
37
+ // close the browsing window
38
38
void Close ();
39
39
40
- // 是否处于打开状态
40
+ // the browsing window is opened or not
41
41
bool IsOpened () const noexcept ;
42
42
43
- // 显示文件窗口
44
- // 当遭遇非法访问等异常时,当前路径会被自动定向到程序工作目录,且上一个错误会被显示窗口底部的状态栏中。
45
- // 若定向到程序工作目录时再次发生异常,则该异常会被原样抛出。即使如此,imgui的状态始终是一致的。
43
+ // display the browsing window if opened
46
44
void Display ();
47
45
48
- // 是否选中了某个文件并已确认
46
+ // returns true when there is a selected filename and the "ok" button was clicked
49
47
bool HasSelected () const noexcept ;
50
48
51
- // 设置当前显示的路径
49
+ // set current browsing directory
52
50
bool SetPwd (const std::filesystem::path &pwd = std::filesystem::current_path());
53
51
54
- // 取得当前选择的文件路径,仅在IsSelected返回true时有意义
52
+ // returns selected filename. make sense only when HasSelected returns true
55
53
std::string GetSelected () const ;
56
54
57
- // 清除当前选择的文件
55
+ // set selected filename to empty
58
56
void ClearSelected ();
59
57
60
58
private:
@@ -143,7 +141,7 @@ inline void ImGui::FileBrowser::Display()
143
141
OpenPopup (openLabel_.c_str ());
144
142
isOpened_ = false ;
145
143
146
- // 尝试打开窗口
144
+ // open the popup window
147
145
148
146
if (openFlag_ && (flags_ & ImGuiFileBrowserFlags_NoModal))
149
147
SetNextWindowSize (ImVec2 (700 , 450 ));
@@ -159,7 +157,7 @@ inline void ImGui::FileBrowser::Display()
159
157
isOpened_ = true ;
160
158
ScopeGuard endPopup ([] { EndPopup (); });
161
159
162
- // 显示路径中的一系列section
160
+ // display elements in pwd
163
161
164
162
int secIdx = 0 , newPwdLastSecIdx = -1 ;
165
163
for (auto &sec : pwd_)
@@ -197,7 +195,7 @@ inline void ImGui::FileBrowser::Display()
197
195
SetPwd (newPwd);
198
196
}
199
197
200
- // 显示文件列表的子窗口
198
+ // browse files in a child window
201
199
202
200
float reserveHeight = GetItemsLineHeightWithSpacing ();
203
201
if (!(flags_ & ImGuiFileBrowserFlags_SelectDirectory) && (flags_ & ImGuiFileBrowserFlags_EnterNewFilename))
@@ -220,7 +218,7 @@ inline void ImGui::FileBrowser::Display()
220
218
else if (rsc.name != " .." )
221
219
{
222
220
if ((rsc.isDir && (flags_ & ImGuiFileBrowserFlags_SelectDirectory)) ||
223
- (!rsc.isDir && !(flags_ & ImGuiFileBrowserFlags_SelectDirectory)))
221
+ (!rsc.isDir && !(flags_ & ImGuiFileBrowserFlags_SelectDirectory)))
224
222
{
225
223
selectedFilename_ = rsc.name ;
226
224
if (!(flags_ & ImGuiFileBrowserFlags_SelectDirectory))
@@ -234,10 +232,6 @@ inline void ImGui::FileBrowser::Display()
234
232
}
235
233
}
236
234
237
- // 使用逻辑:
238
- // 选择文件时,input slot的内容始终是和selectedFilename一致的
239
- // 选择目录时,input slot无意义且不显示,只有在没有selectedFilename时才能ok,其他情况下都是open selected并进入其中
240
-
241
235
if (!(flags_ & ImGuiFileBrowserFlags_SelectDirectory) && (flags_ & ImGuiFileBrowserFlags_EnterNewFilename))
242
236
{
243
237
PushID (this );
0 commit comments