From e15d1c68f8e81edcf0e496e4fe8c66a67936d403 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Tue, 1 Feb 2022 20:53:47 +0000 Subject: [PATCH] Add ability to select directory through imgui file picker --- engine/core/include/imgui_backend.hpp | 3 ++- engine/core/src/imgui_backend.cpp | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/engine/core/include/imgui_backend.hpp b/engine/core/include/imgui_backend.hpp index d885600..132fd06 100644 --- a/engine/core/include/imgui_backend.hpp +++ b/engine/core/include/imgui_backend.hpp @@ -47,9 +47,10 @@ namespace prism { std::filesystem::path current_path; std::filesystem::path selected_path; std::function return_function; + bool select_directory = false; }; dialog_data open_dialog_data; dialog_data save_dialog_data; }; -} \ No newline at end of file +} diff --git a/engine/core/src/imgui_backend.cpp b/engine/core/src/imgui_backend.cpp index 0440eeb..f83c312 100644 --- a/engine/core/src/imgui_backend.cpp +++ b/engine/core/src/imgui_backend.cpp @@ -228,6 +228,11 @@ void imgui_backend::begin_frame(const float delta_time) { if(ImGui::Selectable("..", false, ImGuiSelectableFlags_DontClosePopups)) data.current_path = data.current_path.parent_path(); + if(data.select_directory) { + if(ImGui::Selectable(".", false, ImGuiSelectableFlags_DontClosePopups)) + data.selected_path = data.current_path; + } + for(const auto& dir_ent : std::filesystem::directory_iterator(data.current_path)) { if(ImGui::Selectable(dir_ent.path().c_str(), data.selected_path == dir_ent.path(), ImGuiSelectableFlags_DontClosePopups)) { if(dir_ent.is_directory()) @@ -291,14 +296,15 @@ void prism::imgui_backend::process_text_input(const std::string_view string) { io.AddInputCharactersUTF8(string.data()); } -void prism::imgui_backend::open_dialog(const bool, std::function returnFunction, bool) { +void prism::imgui_backend::open_dialog(const bool, std::function returnFunction, bool openDirectory) { open_dialog_next_frame = true; open_dialog_data.current_path = std::filesystem::current_path(); open_dialog_data.return_function = returnFunction; + open_dialog_data.select_directory = openDirectory; } void prism::imgui_backend::save_dialog(std::function returnFunction) { save_dialog_next_frame = true; save_dialog_data.current_path = std::filesystem::current_path(); save_dialog_data.return_function = returnFunction; -} \ No newline at end of file +}