Add ability to select directory through imgui file picker
This commit is contained in:
parent
5572f3aef4
commit
e15d1c68f8
2 changed files with 10 additions and 3 deletions
|
@ -47,9 +47,10 @@ namespace prism {
|
||||||
std::filesystem::path current_path;
|
std::filesystem::path current_path;
|
||||||
std::filesystem::path selected_path;
|
std::filesystem::path selected_path;
|
||||||
std::function<void(std::string)> return_function;
|
std::function<void(std::string)> return_function;
|
||||||
|
bool select_directory = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
dialog_data open_dialog_data;
|
dialog_data open_dialog_data;
|
||||||
dialog_data save_dialog_data;
|
dialog_data save_dialog_data;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -228,6 +228,11 @@ void imgui_backend::begin_frame(const float delta_time) {
|
||||||
if(ImGui::Selectable("..", false, ImGuiSelectableFlags_DontClosePopups))
|
if(ImGui::Selectable("..", false, ImGuiSelectableFlags_DontClosePopups))
|
||||||
data.current_path = data.current_path.parent_path();
|
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)) {
|
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(ImGui::Selectable(dir_ent.path().c_str(), data.selected_path == dir_ent.path(), ImGuiSelectableFlags_DontClosePopups)) {
|
||||||
if(dir_ent.is_directory())
|
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());
|
io.AddInputCharactersUTF8(string.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
void prism::imgui_backend::open_dialog(const bool, std::function<void(std::string)> returnFunction, bool) {
|
void prism::imgui_backend::open_dialog(const bool, std::function<void(std::string)> returnFunction, bool openDirectory) {
|
||||||
open_dialog_next_frame = true;
|
open_dialog_next_frame = true;
|
||||||
open_dialog_data.current_path = std::filesystem::current_path();
|
open_dialog_data.current_path = std::filesystem::current_path();
|
||||||
open_dialog_data.return_function = returnFunction;
|
open_dialog_data.return_function = returnFunction;
|
||||||
|
open_dialog_data.select_directory = openDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
void prism::imgui_backend::save_dialog(std::function<void(std::string)> returnFunction) {
|
void prism::imgui_backend::save_dialog(std::function<void(std::string)> returnFunction) {
|
||||||
save_dialog_next_frame = true;
|
save_dialog_next_frame = true;
|
||||||
save_dialog_data.current_path = std::filesystem::current_path();
|
save_dialog_data.current_path = std::filesystem::current_path();
|
||||||
save_dialog_data.return_function = returnFunction;
|
save_dialog_data.return_function = returnFunction;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue