Skip to content

Commit d68c79d

Browse files
committed
适当添加注释
1 parent dc74edb commit d68c79d

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

imfilebrowser.h

+19-25
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ using ImGuiFileBrowserFlags = int;
1212

1313
enum ImGuiFileBrowserFlags_
1414
{
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
2020
};
2121

2222
namespace ImGui
@@ -25,36 +25,34 @@ namespace ImGui
2525
{
2626
public:
2727

28-
// 默认将pwd设置为当前工作目录,可通过SetPwd修改
28+
// pwd is set to current working directory by default
2929
explicit FileBrowser(ImGuiFileBrowserFlags flags = 0);
3030

31-
// 设置窗口标题文字,以utf-8编码
31+
// set the window title text
3232
void SetTitle(std::string title);
3333

34-
// 打开文件窗口
34+
// open the browsing window
3535
void Open();
3636

37-
// 关闭文件窗口
37+
// close the browsing window
3838
void Close();
3939

40-
// 是否处于打开状态
40+
// the browsing window is opened or not
4141
bool IsOpened() const noexcept;
4242

43-
// 显示文件窗口
44-
// 当遭遇非法访问等异常时,当前路径会被自动定向到程序工作目录,且上一个错误会被显示窗口底部的状态栏中。
45-
// 若定向到程序工作目录时再次发生异常,则该异常会被原样抛出。即使如此,imgui的状态始终是一致的。
43+
// display the browsing window if opened
4644
void Display();
4745

48-
// 是否选中了某个文件并已确认
46+
// returns true when there is a selected filename and the "ok" button was clicked
4947
bool HasSelected() const noexcept;
5048

51-
// 设置当前显示的路径
49+
// set current browsing directory
5250
bool SetPwd(const std::filesystem::path &pwd = std::filesystem::current_path());
5351

54-
// 取得当前选择的文件路径,仅在IsSelected返回true时有意义
52+
// returns selected filename. make sense only when HasSelected returns true
5553
std::string GetSelected() const;
5654

57-
// 清除当前选择的文件
55+
// set selected filename to empty
5856
void ClearSelected();
5957

6058
private:
@@ -143,7 +141,7 @@ inline void ImGui::FileBrowser::Display()
143141
OpenPopup(openLabel_.c_str());
144142
isOpened_ = false;
145143

146-
// 尝试打开窗口
144+
// open the popup window
147145

148146
if(openFlag_ && (flags_ & ImGuiFileBrowserFlags_NoModal))
149147
SetNextWindowSize(ImVec2(700, 450));
@@ -159,7 +157,7 @@ inline void ImGui::FileBrowser::Display()
159157
isOpened_ = true;
160158
ScopeGuard endPopup([] { EndPopup(); });
161159

162-
// 显示路径中的一系列section
160+
// display elements in pwd
163161

164162
int secIdx = 0, newPwdLastSecIdx = -1;
165163
for(auto &sec : pwd_)
@@ -197,7 +195,7 @@ inline void ImGui::FileBrowser::Display()
197195
SetPwd(newPwd);
198196
}
199197

200-
// 显示文件列表的子窗口
198+
// browse files in a child window
201199

202200
float reserveHeight = GetItemsLineHeightWithSpacing();
203201
if(!(flags_ & ImGuiFileBrowserFlags_SelectDirectory) && (flags_ & ImGuiFileBrowserFlags_EnterNewFilename))
@@ -220,7 +218,7 @@ inline void ImGui::FileBrowser::Display()
220218
else if(rsc.name != "..")
221219
{
222220
if((rsc.isDir && (flags_ & ImGuiFileBrowserFlags_SelectDirectory)) ||
223-
(!rsc.isDir && !(flags_ & ImGuiFileBrowserFlags_SelectDirectory)))
221+
(!rsc.isDir && !(flags_ & ImGuiFileBrowserFlags_SelectDirectory)))
224222
{
225223
selectedFilename_ = rsc.name;
226224
if(!(flags_ & ImGuiFileBrowserFlags_SelectDirectory))
@@ -234,10 +232,6 @@ inline void ImGui::FileBrowser::Display()
234232
}
235233
}
236234

237-
// 使用逻辑:
238-
// 选择文件时,input slot的内容始终是和selectedFilename一致的
239-
// 选择目录时,input slot无意义且不显示,只有在没有selectedFilename时才能ok,其他情况下都是open selected并进入其中
240-
241235
if(!(flags_ & ImGuiFileBrowserFlags_SelectDirectory) && (flags_ & ImGuiFileBrowserFlags_EnterNewFilename))
242236
{
243237
PushID(this);

0 commit comments

Comments
 (0)