From 755a53f8211fd8f67426eacc7d5655a0cc137eaa Mon Sep 17 00:00:00 2001 From: paxcut <53811119+paxcut@users.noreply.github.com> Date: Fri, 20 Jun 2025 12:26:17 -0700 Subject: [PATCH] improv: ImGui test engine window can now be opened and closed from debug menu (#2310) --- lib/libimhex/include/hex/ui/imgui_imhex_extensions.h | 6 ++++++ lib/libimhex/source/ui/imgui_imhex_extensions.cpp | 10 ++++++++++ main/gui/source/window/window.cpp | 4 ++-- plugins/builtin/source/content/ui_items.cpp | 3 +++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h b/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h index d47ed98ce..5b3551441 100644 --- a/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h +++ b/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h @@ -362,6 +362,12 @@ namespace ImGuiExt { else static_assert(hex::always_false::value, "Invalid data type!"); } + struct ImGuiTestEngine { + ImGuiTestEngine() = delete; + + static void setEnabled(bool enabled); + [[nodiscard]] static bool isEnabled(); + }; } // these functions are exception because they just allow conversion from string to char*, they do not really add anything diff --git a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp index 044d56837..8493d9329 100644 --- a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp +++ b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp @@ -1443,6 +1443,16 @@ namespace ImGuiExt { // Return the button press state ImGui::PopClipRect(); } + + static bool s_imguiTestEngineEnabled = false; + + void ImGuiTestEngine::setEnabled(bool enabled) { + s_imguiTestEngineEnabled = enabled; + } + + bool ImGuiTestEngine::isEnabled() { + return s_imguiTestEngineEnabled; + } } namespace ImGui { diff --git a/main/gui/source/window/window.cpp b/main/gui/source/window/window.cpp index 14fe16f1d..d5959eb74 100644 --- a/main/gui/source/window/window.cpp +++ b/main/gui/source/window/window.cpp @@ -407,9 +407,9 @@ namespace hex { ImGui::NewFrame(); - #if defined(IMGUI_TEST_ENGINE) + if (ImGuiExt::ImGuiTestEngine::isEnabled()) ImGuiTestEngine_ShowTestEngineWindows(m_testEngine, nullptr); - #endif + TutorialManager::drawTutorial(); diff --git a/plugins/builtin/source/content/ui_items.cpp b/plugins/builtin/source/content/ui_items.cpp index 2a6a8761c..6e3b61749 100644 --- a/plugins/builtin/source/content/ui_items.cpp +++ b/plugins/builtin/source/content/ui_items.cpp @@ -88,6 +88,7 @@ namespace hex::plugin::builtin { static bool showImGuiDemo = false; static bool showImPlotDemo = false; static bool showImPlot3DDemo = false; + static bool showTestEngine = false; ImGui::SetNextWindowSize(scaled({ 300, 150 }), ImGuiCond_Always); if (ImGui::BeginPopup("DebugMenu")) { @@ -109,6 +110,7 @@ namespace hex::plugin::builtin { if (ImGui::BeginChild("Scrolling", ImGui::GetContentRegionAvail())) { auto ctx = ImGui::GetCurrentContext(); ImGui::Checkbox("Show ImGui Demo", &showImGuiDemo); + ImGui::Checkbox("Show ImGui Test Engine",&showTestEngine); ImGui::Checkbox("Show ImPlot Demo", &showImPlotDemo); ImGui::Checkbox("Show ImPlot3D Demo", &showImPlot3DDemo); @@ -158,6 +160,7 @@ namespace hex::plugin::builtin { if (showImGuiDemo) ImGui::ShowDemoWindow(&showImGuiDemo); + ImGuiExt::ImGuiTestEngine::setEnabled(showTestEngine); if (showImPlotDemo) ImPlot::ShowDemoWindow(&showImPlotDemo); if (showImPlot3DDemo)