Hi, I’ve tried several things to display my current directory recursively, but I can not understand how to use ImGui::TreeNode in a loop like this:
ImGui::Begin("Project", nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoCollapse);
for (shiva::fs::recursive_directory_iterator it(shiva::fs::current_path());
it != shiva::fs::recursive_directory_iterator();
++it) {
if (shiva::fs::is_directory(it->path())) {
for (int i = 0; i < it.depth(); ++i) {
ImGui::Indent();
}
if (ImGui::TreeNode(it->path().filename().string().c_str())) {
}
for (int i = 0; i < it.depth(); ++i) {
ImGui::Unindent();
}
} else {
for (int i = 0; i < it.depth(); ++i) {
ImGui::Indent();
}
ImGui::Text(it->path().filename().string().c_str());
for (int i = 0; i < it.depth(); ++i) {
ImGui::Unindent();
}
}
}
ImGui::End();
It’s not an easy problem. I think your V3 looks alright, you may just remove the Folder icon?
Not sure why you have the Indent/Unindent block. TreeNodeEx() probably could be improved to make that sort of things easier.
If you want to maintain a full selection you may need to carry e.g. a std::set keyed by the hash of the filename, so every selected folder/file in the folder has an entry in the std::set.