From 4228fe554d18499cc218b9b6ccaedd563a4b5935 Mon Sep 17 00:00:00 2001 From: Patrick Wuttke Date: Tue, 4 Nov 2025 17:52:01 +0100 Subject: [PATCH] Added IDScope helper and c_Window/c_Dialog coroutines. --- public/raid/imraid.hpp | 95 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 2 deletions(-) diff --git a/public/raid/imraid.hpp b/public/raid/imraid.hpp index e7fc049..2bc41b2 100644 --- a/public/raid/imraid.hpp +++ b/public/raid/imraid.hpp @@ -81,6 +81,33 @@ inline void TextUnformatted(std::string_view stringView) ImGui::TextUnformatted(stringView.data(), stringView.data() + stringView.size()); } +class IDScope +{ +public: + explicit IDScope(int intId) + { + ImGui::PushID(intId); + } + explicit IDScope(const void* ptrId) + { + ImGui::PushID(ptrId); + } + explicit IDScope(const char* strId) + { + ImGui::PushID(strId); + } + IDScope(const char* strId, const char* strIdEnd) + { + ImGui::PushID(strId, strIdEnd); + } + IDScope(const IDScope&) = delete; + ~IDScope() + { + ImGui::PopID(); + } + IDScope& operator=(const IDScope&) = delete; +}; + struct DataTableState { std::vector sortedIndices; @@ -318,14 +345,78 @@ inline DataTableColumn MakeColumn(const char* header, const char* fmt, } template -mijin::Task<> c_MessageBox(const char* titleId, TFunc&& renderFunc) +mijin::Task<> c_Window(const char* titleId, bool& open, ImGuiWindowFlags flags, TFunc renderFunc) +{ + while (open) + { + if (ImGui::Begin(titleId, &open, flags)) { + std::invoke(renderFunc); + } + ImGui::End(); + co_await mijin::c_suspend(); + } +} + +template +mijin::Task<> c_Window(const char* titleId, bool& open, TFunc renderFunc) +{ + return c_Window(titleId, open, ImGuiWindowFlags_None, std::move(renderFunc)); +} + +template +mijin::Task<> c_Window(const char* titleId, ImGuiWindowFlags flags, TFunc renderFunc) +{ + bool open = true; + co_return co_await c_Window(titleId, open, flags, std::move(renderFunc)); +} + +template +mijin::Task<> c_Window(const char* titleId, TFunc renderFunc) +{ + return c_Window(titleId, ImGuiWindowFlags_None, std::move(renderFunc)); +} + +template +mijin::Task<> c_Dialog(const char* titleId, bool& open, ImGuiWindowFlags flags, TFunc renderFunc) +{ + ImGui::OpenPopup(titleId); + + while (ImGui::BeginPopupModal(titleId, &open, flags)) + { + std::invoke(renderFunc); + ImGui::EndPopup(); + co_await mijin::c_suspend(); + } +} + +template +mijin::Task<> c_Dialog(const char* titleId, bool& open, TFunc renderFunc) +{ + return c_Dialog(titleId, open, ImGuiWindowFlags_None, std::move(renderFunc)); +} + +template +mijin::Task<> c_Dialog(const char* titleId, ImGuiWindowFlags flags, TFunc renderFunc) +{ + bool open = true; + co_return co_await c_Dialog(titleId, open, flags, std::move(renderFunc)); +} + +template +mijin::Task<> c_Dialog(const char* titleId, TFunc renderFunc) +{ + return c_Dialog(titleId, ImGuiWindowFlags_None, std::move(renderFunc)); +} + +template +mijin::Task<> c_MessageBox(const char* titleId, TFunc renderFunc) { ImGui::OpenPopup(titleId); bool open = true; while (ImGui::BeginPopupModal(titleId, &open, ImGuiWindowFlags_NoResize)) { - std::invoke(std::forward(renderFunc)); + std::invoke(renderFunc); ImGui::EndPopup(); co_await mijin::c_suspend(); }