Last active
March 23, 2022 07:25
-
-
Save LAK132/d60001c02e4c3b5b80a2976bda6ac91a to your computer and use it in GitHub Desktop.
Revisions
-
LAK132 revised this gist
Aug 4, 2018 . 1 changed file with 7 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,15 +30,18 @@ void windowOpenPath(complete<fs::path>& dir, bool file = true) ImGui::EndChild(); ImGui::Separator(); ImGui::Text(dir.value.u8string().c_str()); if (file ? fs::is_regular_file(dir.value) : fs::is_directory(dir.value)) { dir.done |= ImGui::Button("Open"); ImGui::SameLine(); } else if (!file && hasParent) { if (ImGui::Button("Open")) { dir.value = dir.value.parent_path(); dir.done = true; } ImGui::SameLine(); } dir.good ^= ImGui::Button("Cancel"); -
LAK132 revised this gist
Aug 4, 2018 . 1 changed file with 5 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,8 +22,11 @@ void windowOpenPath(complete<fs::path>& dir, bool file = true) ImGui::Separator(); } for(auto& d : fs::directory_iterator(p)) { bool selected = dir.value == d.path(); if (ImGui::Selectable(d.path().filename().u8string().c_str(), &selected)) dir.value = d.path(); } ImGui::EndChild(); ImGui::Separator(); ImGui::Text(dir.value.u8string().c_str()); @@ -32,7 +35,7 @@ void windowOpenPath(complete<fs::path>& dir, bool file = true) dir.done |= ImGui::Button("Open"); ImGui::SameLine(); } else if (!file && hasParent) if (ImGui::Button("Open")) { dir.value = dir.value.parent_path(); dir.done = true; -
LAK132 revised this gist
Aug 4, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -29,7 +29,7 @@ void windowOpenPath(complete<fs::path>& dir, bool file = true) ImGui::Text(dir.value.u8string().c_str()); if ((file && fs::is_regular_file(dir.value)) || (!file && fs::is_directory(dir.value))) { dir.done |= ImGui::Button("Open"); ImGui::SameLine(); } else if (!file && hasParent && ImGui::Button("Open")) @@ -38,7 +38,7 @@ void windowOpenPath(complete<fs::path>& dir, bool file = true) dir.done = true; ImGui::SameLine(); } dir.good ^= ImGui::Button("Cancel"); } ImGui::End(); } -
LAK132 created this gist
Aug 3, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ template<typename T> struct complete { bool good = true, done = false; T value; complete() {} complete(const T& t, bool g = true, bool d = false) : value(t), good(g), done(d) {} complete(T&& t, bool g = true, bool d = false) : value(t), good(g), done(d) {} }; void windowOpenPath(complete<fs::path>& dir, bool file = true) { if (ImGui::Begin("Open File", &dir.good)) { bool hasParent = dir.value.has_parent_path(); bool isDir = fs::is_directory(dir.value); fs::path p = (isDir ? dir.value : (hasParent ? dir.value.parent_path() : fs::current_path())); const float footer = ImGui::GetStyle().ItemSpacing.y + (ImGui::GetFrameHeightWithSpacing() * 2); ImGui::BeginChild("Viewer", ImVec2(0, -footer)); if ((hasParent && isDir) || (hasParent && dir.value.parent_path().has_parent_path())) { if (ImGui::Button("<- Back")) dir.value = isDir ? dir.value.parent_path() : dir.value.parent_path().parent_path(); ImGui::Separator(); } for(auto& d : fs::directory_iterator(p)) if (ImGui::Button(d.path().filename().u8string().c_str())) dir.value = d.path(); ImGui::EndChild(); ImGui::Separator(); ImGui::Text(dir.value.u8string().c_str()); if ((file && fs::is_regular_file(dir.value)) || (!file && fs::is_directory(dir.value))) { ImGui::Button(&dir.done, "Open"); ImGui::SameLine(); } else if (!file && hasParent && ImGui::Button("Open")) { dir.value = dir.value.parent_path(); dir.done = true; ImGui::SameLine(); } ImGui::ButtonInv(&dir.good, "Cancel"); } ImGui::End(); }