Merge pull request #38 from antopilo/feature/nk-102-generic-confirmation-popup

NK-102 - Generic Confirmation Popup
This commit is contained in:
émeryc
2023-07-21 21:24:37 -04:00
committed by GitHub
2 changed files with 41 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
#include "PopupHelper.h"
#include "imgui/imgui.h"
void PopupHelper::Confirmation(const std::string& id)
{
ImGui::TextWrapped(id.c_str());
ImGui::OpenPopup(id.c_str());
}
bool PopupHelper::DefineDialog(const std::string& id, const std::string& text)
{
bool result = false;
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
if (ImGui::BeginPopupModal(id.c_str(), NULL, ImGuiWindowFlags_AlwaysAutoResize))
{
ImGui::Text((text + "\n\n").c_str());
ImGui::Separator();
if (ImGui::Button("OK", ImVec2(120, 0))) { result = true; ImGui::CloseCurrentPopup(); }
ImGui::SetItemDefaultFocus();
ImGui::SameLine();
if (ImGui::Button("Cancel", ImVec2(120, 0))) { ImGui::CloseCurrentPopup(); }
ImGui::EndPopup();
}
return result;
}

View File

@@ -0,0 +1,9 @@
#pragma once
#include <string>
class PopupHelper
{
public:
static void Confirmation(const std::string& id);
static bool DefineDialog(const std::string& id, const std::string& text);
};