#pragma once #include #include #include #include #include #include "Project.h" struct DialogSpec { const std::string& id; const std::string& Title; const std::string& confirmText; DialogSpec() = default; }; //classes based on RAII class Dialog { public: Dialog( DialogSpec spec, std::function onConfirm) : path(nullptr), location() { if (ImGui::BeginPopupModal(spec.id.c_str(), NULL, ImGuiWindowFlags_NoMove)) { ImGui::Text(spec.Title.c_str()); ImGui::Separator(); ImGui::LabelText("##Directory", "Directory: %s", location.c_str()); if (ImGui::Button("...")) { nfdresult_t result = NFD_OpenDialog(NULL, NULL, &path); switch (result) { case (NFD_OKAY): location = std::string(path); break; case(NFD_CANCEL): std::cout << "NFD_CANCEL" << std::endl; case (NFD_ERROR): std::cout << "NFD_Error: " << NFD_GetError() << std::endl; break; }; } if (ImGui::Button(spec.confirmText.c_str(), ImVec2(120, 0))) { onConfirm(location); ImGui::CloseCurrentPopup(); } ImGui::SetItemDefaultFocus(); ImGui::SameLine(); if (ImGui::Button("Cancel", ImVec2(120, 0))) { ImGui::CloseCurrentPopup(); } ImGui::EndPopup(); } } ~Dialog() { delete path; } protected : char* path; std::string location; };