Skip to content

Commit a475347

Browse files
authored
Merge pull request #18 from macpete/improve-cancel
Improve cancel
2 parents 0d5faff + 9d3a5e1 commit a475347

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

ImFileDialog.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#endif
2525

2626
#define ICON_SIZE ImGui::GetFont()->FontSize + 3
27-
#define GUI_ELEMENT_SIZE 24
27+
#define GUI_ELEMENT_SIZE std::max(GImGui->FontSize + 10.f, 24.f)
2828
#define DEFAULT_ICON_SIZE 32
2929
#define PI 3.141592f
3030

@@ -1330,7 +1330,7 @@ namespace ifd {
13301330

13311331

13321332
/***** CONTENT *****/
1333-
float bottomBarHeight = (GImGui->FontSize + ImGui::GetStyle().FramePadding.y * 2.0f + ImGui::GetStyle().ItemSpacing.y * 2.0f) * 2;
1333+
float bottomBarHeight = (GImGui->FontSize + ImGui::GetStyle().FramePadding.y + ImGui::GetStyle().ItemSpacing.y * 2.0f) * 2;
13341334
if (ImGui::BeginTable("##table", 2, ImGuiTableFlags_Resizable, ImVec2(0, -bottomBarHeight))) {
13351335
ImGui::TableSetupColumn("##tree", ImGuiTableColumnFlags_WidthFixed, 125.0f);
13361336
ImGui::TableSetupColumn("##content", ImGuiTableColumnFlags_WidthStretch);
@@ -1384,8 +1384,9 @@ namespace ifd {
13841384
}
13851385

13861386
// buttons
1387-
ImGui::SetCursorPosX(ImGui::GetWindowWidth() - 250);
1388-
if (ImGui::Button(m_type == IFD_DIALOG_SAVE ? "Save" : "Open", ImVec2(250 / 2 - ImGui::GetStyle().ItemSpacing.x, 0.0f))) {
1387+
float ok_cancel_width = GUI_ELEMENT_SIZE * 7;
1388+
ImGui::SetCursorPosX(ImGui::GetWindowWidth() - ok_cancel_width);
1389+
if (ImGui::Button(m_type == IFD_DIALOG_SAVE ? "Save" : "Open", ImVec2(ok_cancel_width / 2 - ImGui::GetStyle().ItemSpacing.x, 0.0f))) {
13891390
std::string filename(m_inputTextbox);
13901391
bool success = false;
13911392
if (!filename.empty() || m_type == IFD_DIALOG_DIRECTORY)
@@ -1398,8 +1399,17 @@ namespace ifd {
13981399
#endif
13991400
}
14001401
ImGui::SameLine();
1401-
if (ImGui::Button("Cancel", ImVec2(-FLT_MIN, 0.0f)))
1402-
m_finalize();
1402+
if (ImGui::Button("Cancel", ImVec2(-FLT_MIN, 0.0f))) {
1403+
if (m_type == IFD_DIALOG_DIRECTORY)
1404+
m_isOpen = false;
1405+
else
1406+
m_finalize();
1407+
}
1408+
1409+
int escapeKey = ImGui::GetIO().KeyMap[ImGuiKey_Escape];
1410+
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) &&
1411+
escapeKey >= 0 && ImGui::IsKeyPressed(escapeKey))
1412+
m_isOpen = false;
14031413
}
14041414
}
14051415

0 commit comments

Comments
 (0)