diff --git a/core/src/gui/dialogs/dialog_box.h b/core/src/gui/dialogs/dialog_box.h new file mode 100644 index 00000000..8134810c --- /dev/null +++ b/core/src/gui/dialogs/dialog_box.h @@ -0,0 +1,51 @@ +#pragma once +#include "dialog_box.h" +#include +#include +#include + +#define GENERIC_DIALOG_BUTTONS_YES_NO "Yes\0No\0" +#define GENERIC_DIALOG_BUTTONS_APPLY_CANCEL "Apply\0Cancel\0" + +#define GENERIC_DIALOG_BUTTON_YES 0 +#define GENERIC_DIALOG_BUTTON_NO 1 +#define GENERIC_DIALOG_BUTTON_APPLY 0 +#define GENERIC_DIALOG_BUTTON_CANCE 1 + +namespace ImGui { + template + int GenericDialog(const char* id, bool& open, const char* buttons, Func draw) { + // If not open, return + if (!open) { return -1; } + + // Draw popup + gui::mainWindow.lockWaterfallControls = true; + std::string idstr = std::string("##") + std::string(id); + ImGui::OpenPopup(id); + if (ImGui::BeginPopup(id, ImGuiWindowFlags_NoResize)) { + // Draw widgets + draw(); + + // Draw buttons + int bid = 0; + while (buttons[0]) { + int len = strlen(buttons); + + // Draw button + if (bid) { ImGui::SameLine(); } + if (ImGui::Button((buttons + idstr).c_str())) { + open = false; + ImGui::EndPopup(); + return bid; + } + + buttons += len + 1; + bid++; + } + + ImGui::EndPopup(); + } + + return -1; + } +} \ No newline at end of file