diff --git a/main.cpp b/main.cpp index b4f4f03..5069286 100644 --- a/main.cpp +++ b/main.cpp @@ -11,6 +11,7 @@ #include #include #include +#define DEBUG true // [Win32] Our example includes a copy of glfw3.lib pre-compiled with VS2010 to maximize ease of testing and compatibility with old VS compilers. // To link with VS2010-era libraries, VS2015+ requires linking with legacy_stdio_definitions.lib, which we do using this pragma. @@ -30,7 +31,6 @@ bool retrieveCurrentDirectory(char** currentPath){ return false; } - bool moveDirectory(char** currentPath){ if(SetCurrentDirectory(*currentPath)) return true; return false; @@ -197,33 +197,38 @@ int main(int, char**) { ImGui::Begin("File Picker in 4K"); + static bool renderListbox = true; //cursed C momento: necesario ptr en otra var para mandar a char** de firma - static bool renderList = true; static char currentPath[MAX_PATH]; static char* ptr = ¤tPath[0]; static int currentItemIdx = -1; static std::vector displayContents; std::vector directoryContents; - ImGui::Text("%s primir", currentPath); static int numFiles = 0; - if(renderList) { - renderList = false; - if(!retrieveCurrentDirectory(&ptr)) + if (DEBUG) ImGui::Text("%s primir", currentPath); + + if(renderListbox) { + if (DEBUG) std::cout << "renderiso"; + renderListbox = false; + if(!retrieveCurrentDirectory(&ptr)) { + if (DEBUG) std::cout << "pencaste"; goto filepickerFailure; + } // numFiles = (listDirectory(std::string(currentPath), &directoryContents)); //std::cout << numFiles; - if (numFiles < 0) + if (numFiles < 0) { + if (DEBUG) std::cout << "pencaste 2 el repencazo"; goto filepickerFailure; + } displayContents = std::move(directoryContents); } if(numFiles > 0){ ImGui::Text("Select a file:"); - //TODO quitar - ImGui::Text("%s %d", currentPath, currentItemIdx); + if (DEBUG) ImGui::Text("%s %d", currentPath, currentItemIdx); if (ImGui::BeginListBox("fpLb", ImVec2(-FLT_MIN, 25 * ImGui::GetTextLineHeightWithSpacing()))){ for (int i = 0; i < numFiles; i++) { // ImGui::Selectable(directoryContents.at(i), false); @@ -232,13 +237,12 @@ int main(int, char**) if (ImGui::Selectable(displayContents.at(i), isSelected)) currentItemIdx = i; - //Set the initial focus when opening the combo (scrolling + keyboard navigation focus) if (isSelected) { strcat(currentPath, "\\"); strcat(currentPath, displayContents.at(i)); moveDirectory(&ptr); currentItemIdx = -1; - renderList = true; + renderListbox = true; } //ImGui::SetItemDefaultFocus();