Move Editor UI into its own 'UI' folder
This commit is contained in:
@ -1,72 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <imgui.h>
|
||||
#include <nfd.h>
|
||||
#include <iostream>
|
||||
#include <functional>
|
||||
#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<void(std::string&)> 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;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user