From c5c42f211e8fe7862da8b69bdd890b695ef01b8e Mon Sep 17 00:00:00 2001 From: Pascal Thomet Date: Wed, 27 Sep 2023 09:05:10 +0200 Subject: [PATCH] First work / imgui test engine integration --- CMakeLists.txt | 26 ++- src/hello_imgui/hello_imgui_api.md | 11 +- .../backend_impls/abstract_runner.cpp | 13 ++ src/hello_imgui/runner_callbacks.h | 15 +- src/hello_imgui_demos/CMakeLists.txt | 1 + .../CMakeLists.txt | 2 + .../hello_imgui_demo_test_engine.main.cpp | 105 ++++++++++ .../hello_imgui_test_engine_cmake.cmake | 40 ++++ .../imconfig_with_test_engine.h | 197 ++++++++++++++++++ .../test_engine_integration.cpp | 90 ++++++++ .../test_engine_integration.h | 9 + .../todo_test.md | 29 +++ 12 files changed, 532 insertions(+), 6 deletions(-) create mode 100644 src/hello_imgui_demos/hello_imgui_demo_test_engine/CMakeLists.txt create mode 100644 src/hello_imgui_demos/hello_imgui_demo_test_engine/hello_imgui_demo_test_engine.main.cpp create mode 100644 src/hello_imgui_test_engine_integration/hello_imgui_test_engine_cmake.cmake create mode 100644 src/hello_imgui_test_engine_integration/imconfig_with_test_engine.h create mode 100644 src/hello_imgui_test_engine_integration/test_engine_integration.cpp create mode 100644 src/hello_imgui_test_engine_integration/test_engine_integration.h create mode 100644 src/hello_imgui_test_engine_integration/todo_test.md diff --git a/CMakeLists.txt b/CMakeLists.txt index 20202858..437e91b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ endif() project(HelloImGui LANGUAGES C CXX) set(CMAKE_CXX_STANDARD 17) + ############################################################################### # hello_imgui_add_app location ############################################################################### @@ -88,6 +89,12 @@ else() option(HELLOIMGUI_BUILD_TESTS "Build tests" OFF) endif() +#------------------------------------------------------------------------------ +# Options / ImGui Test Engine +#------------------------------------------------------------------------------ +option(HELLOIMGUI_WITH_TEST_ENGINE "Provide ImGui Test engine" OFF) +set(IMGUI_TEST_ENGINE_BASEPATH ${CMAKE_CURRENT_LIST_DIR}/../imgui_test_engine CACHE STRING "path to imgui_test_engine") + #------------------------------------------------------------------------------ # Esmcripten build options #------------------------------------------------------------------------------ @@ -136,7 +143,13 @@ option(HELLOIMGUI_USE_GLAD "Use Glad OpenGl loader" ${need_opengl_loader}) ############################################################################### +############################################################################### +# HelloImGui Build Actions +############################################################################### + +#------------------------------------------------------------------------------ # use SDL for emscripten +#------------------------------------------------------------------------------ if (EMSCRIPTEN AND NOT HELLOIMGUI_USE_SDL_OPENGL3 AND NOT HELLOIMGUI_USE_GLFW_OPENGL3) set(HELLOIMGUI_USE_SDL_OPENGL3 ON) endif() @@ -191,9 +204,10 @@ if (MSVC) endif() +#------------------------------------------------------------------------------ +# Main build actions +#------------------------------------------------------------------------------ set(HELLOIMGUI_BASEPATH ${CMAKE_CURRENT_LIST_DIR} CACHE STRING "Hello imgui base path" FORCE) - - include(cmake/StandardProjectSettings.cmake) include(cmake/StaticAnalyzers.cmake) include(msvc/msvc_target_group) @@ -207,6 +221,14 @@ endif() add_subdirectory(external) add_subdirectory(src) +#------------------------------------------------------------------------------ +# imgui_test_engine integration +#------------------------------------------------------------------------------ +if (HELLOIMGUI_WITH_TEST_ENGINE) + include(${CMAKE_CURRENT_LIST_DIR}/src/hello_imgui_test_engine_integration/hello_imgui_test_engine_cmake.cmake) + add_imgui_test_engine() +endif() + # Install if(PROJECT_IS_TOP_LEVEL) install(DIRECTORY hello_imgui_cmake DESTINATION .) diff --git a/src/hello_imgui/hello_imgui_api.md b/src/hello_imgui/hello_imgui_api.md index 822fb623..62346caa 100644 --- a/src/hello_imgui/hello_imgui_api.md +++ b/src/hello_imgui/hello_imgui_api.md @@ -208,14 +208,21 @@ See [runner_callbacks.h](runner_callbacks.h). You can here add a function that will be called once before exiting (when OpenGL and ImGui are still inited) - * `PreNewFrame`: *VoidFunction, default=empty*. +* `BeforeExit_PostCleanup`: *VoidFunction, default=empty*. + You can here add a function that will be called once before exiting (after OpenGL and ImGui have been deinited) + +* `PreNewFrame`: *VoidFunction, default=empty*. You can here add a function that will be called at each frame, and before the call to ImGui::NewFrame(). It is a good place to dynamically add new fonts, or dynamically add new dockable windows. - * `BeforeImGuiRender`: *VoidFunction, default=empty*. +* `BeforeImGuiRender`: *VoidFunction, default=empty*. You can here add a function that will be called at each frame, after the user Gui code, and just before the call to ImGui::Render() (which will also call ImGui::EndFrame()). +* `AfterSwap`: *VoidFunction, default=empty*. + You can here add a function that will be called at each frame, after the Gui was rendered + and swapped to the screen. + * `AnyBackendEventCallback`: *AnyBackendCallback, default=empty*. Callbacks for events from a specific backend. _Only implemented for SDL, where the event will be of type 'SDL_Event *'_ diff --git a/src/hello_imgui/internal/backend_impls/abstract_runner.cpp b/src/hello_imgui/internal/backend_impls/abstract_runner.cpp index e1525691..551654b1 100644 --- a/src/hello_imgui/internal/backend_impls/abstract_runner.cpp +++ b/src/hello_imgui/internal/backend_impls/abstract_runner.cpp @@ -10,6 +10,10 @@ #include "hello_imgui/internal/imgui_global_context.h" // must be included before imgui_internal.h #include "imgui_internal.h" +#ifdef HELLOIMGUI_WITH_TEST_ENGINE +#include "hello_imgui_test_engine_integration/test_engine_integration.h" +#endif + #include #include #include @@ -328,6 +332,10 @@ void AbstractRunner::LayoutSettings_Save() void AbstractRunner::Setup() { +#ifdef HELLOIMGUI_WITH_TEST_ENGINE + _AddTestEngineCallbacks(&this->params); +#endif + Impl_InitBackend(); Impl_Select_Gl_Version(); @@ -579,6 +587,9 @@ void AbstractRunner::CreateFramesAndRender() Impl_SwapBuffers(); + if (params.callbacks.AfterSwap) + params.callbacks.AfterSwap(); + if (foundPotentialFontLoadingError) ReloadFontIfFailed(); @@ -695,6 +706,8 @@ void AbstractRunner::TearDown(bool gotException) if (params.callbacks.BeforeExit) params.callbacks.BeforeExit(); Impl_Cleanup(); + if (params.callbacks.BeforeExit_PostCleanup) + params.callbacks.BeforeExit_PostCleanup(); } diff --git a/src/hello_imgui/runner_callbacks.h b/src/hello_imgui/runner_callbacks.h index c0cb22f2..878c47eb 100644 --- a/src/hello_imgui/runner_callbacks.h +++ b/src/hello_imgui/runner_callbacks.h @@ -102,14 +102,21 @@ struct MobileCallbacks You can here add a function that will be called once before exiting (when OpenGL and ImGui are still inited) - * `PreNewFrame`: *VoidFunction, default=empty*. +* `BeforeExit_PostCleanup`: *VoidFunction, default=empty*. + You can here add a function that will be called once before exiting (after OpenGL and ImGui have been deinited) + +* `PreNewFrame`: *VoidFunction, default=empty*. You can here add a function that will be called at each frame, and before the call to ImGui::NewFrame(). It is a good place to dynamically add new fonts, or dynamically add new dockable windows. - * `BeforeImGuiRender`: *VoidFunction, default=empty*. +* `BeforeImGuiRender`: *VoidFunction, default=empty*. You can here add a function that will be called at each frame, after the user Gui code, and just before the call to ImGui::Render() (which will also call ImGui::EndFrame()). +* `AfterSwap`: *VoidFunction, default=empty*. + You can here add a function that will be called at each frame, after the Gui was rendered + and swapped to the screen. + * `AnyBackendEventCallback`: *AnyBackendCallback, default=empty*. Callbacks for events from a specific backend. _Only implemented for SDL, where the event will be of type 'SDL_Event *'_ @@ -143,10 +150,14 @@ struct RunnerCallbacks VoidFunction ShowMenus = EmptyVoidFunction(); VoidFunction ShowAppMenuItems = EmptyVoidFunction(); VoidFunction ShowStatus = EmptyVoidFunction(); + VoidFunction PostInit = EmptyVoidFunction(); VoidFunction BeforeExit = EmptyVoidFunction(); + VoidFunction BeforeExit_PostCleanup = EmptyVoidFunction(); + VoidFunction PreNewFrame = EmptyVoidFunction(); VoidFunction BeforeImGuiRender = EmptyVoidFunction(); + VoidFunction AfterSwap = EmptyVoidFunction(); AnyEventCallback AnyBackendEventCallback = EmptyEventCallback(); diff --git a/src/hello_imgui_demos/CMakeLists.txt b/src/hello_imgui_demos/CMakeLists.txt index ee5b5437..9f09c223 100644 --- a/src/hello_imgui_demos/CMakeLists.txt +++ b/src/hello_imgui_demos/CMakeLists.txt @@ -6,6 +6,7 @@ set(subdirs hello_world hello_globe hello_idbfs + hello_imgui_demo_test_engine ) foreach(target_name ${subdirs}) add_subdirectory(${target_name}) diff --git a/src/hello_imgui_demos/hello_imgui_demo_test_engine/CMakeLists.txt b/src/hello_imgui_demos/hello_imgui_demo_test_engine/CMakeLists.txt new file mode 100644 index 00000000..43b8ec9b --- /dev/null +++ b/src/hello_imgui_demos/hello_imgui_demo_test_engine/CMakeLists.txt @@ -0,0 +1,2 @@ +include(hello_imgui_add_app) +hello_imgui_add_app(hello_imgui_demo_test_engine hello_imgui_demo_test_engine.main.cpp) diff --git a/src/hello_imgui_demos/hello_imgui_demo_test_engine/hello_imgui_demo_test_engine.main.cpp b/src/hello_imgui_demos/hello_imgui_demo_test_engine/hello_imgui_demo_test_engine.main.cpp new file mode 100644 index 00000000..7ab12428 --- /dev/null +++ b/src/hello_imgui_demos/hello_imgui_demo_test_engine/hello_imgui_demo_test_engine.main.cpp @@ -0,0 +1,105 @@ +#include "hello_imgui/hello_imgui.h" + +#ifdef HELLOIMGUI_WITH_TEST_ENGINE + +#include "imgui_test_engine/imgui_te_context.h" +#include "imgui_test_engine/imgui_te_ui.h" +#include "imgui_test_engine/imgui_capture_tool.h" +#include "hello_imgui_test_engine_integration/test_engine_integration.h" + + +void RegisterAppMinimalTests(ImGuiTestEngine* e) +{ + ImGuiTest* t = NULL; + + //----------------------------------------------------------------- + // ## Demo Test: Use variables to communicate data between GuiFunc and TestFunc + //----------------------------------------------------------------- + + t = IM_REGISTER_TEST(e, "demo_tests", "test2"); + struct TestVars2 { int MyInt = 42; }; + t->SetVarsDataType(); + t->GuiFunc = [](ImGuiTestContext* ctx) + { + TestVars2& vars = ctx->GetVars(); + ImGui::Begin("Test Window", NULL, ImGuiWindowFlags_NoSavedSettings); + ImGui::SliderInt("Slider", &vars.MyInt, 0, 1000); + ImGui::End(); + }; + t->TestFunc = [](ImGuiTestContext* ctx) + { + TestVars2& vars = ctx->GetVars(); + ctx->SetRef("Test Window"); + + IM_CHECK_EQ(vars.MyInt, 42); + ctx->ItemInputValue("Slider", 123); + IM_CHECK_EQ(vars.MyInt, 123); + }; + + //----------------------------------------------------------------- + // ## Open Metrics window + //----------------------------------------------------------------- + + t = IM_REGISTER_TEST(e, "demo_tests", "open_metrics"); + t->TestFunc = [](ImGuiTestContext* ctx) + { + ctx->SetRef("Dear ImGui Demo"); + ctx->MenuCheck("Tools/Metrics\\/Debugger"); + }; + + //----------------------------------------------------------------- + // ## Capture entire Dear ImGui Demo window. + //----------------------------------------------------------------- + + t = IM_REGISTER_TEST(e, "demo_tests", "capture_screenshot"); + t->TestFunc = [](ImGuiTestContext* ctx) + { + ctx->SetRef("Dear ImGui Demo"); + ctx->ItemOpen("Widgets"); // Open collapsing header + ctx->ItemOpenAll("Basic"); // Open tree node and all its descendant + ctx->CaptureScreenshotWindow("Dear ImGui Demo", ImGuiCaptureFlags_StitchAll | ImGuiCaptureFlags_HideMouseCursor); + }; + + t = IM_REGISTER_TEST(e, "demo_tests", "capture_video"); + t->TestFunc = [](ImGuiTestContext* ctx) + { + ctx->SetRef("Dear ImGui Demo"); + ctx->ItemCloseAll(""); + ctx->MouseTeleportToPos(ctx->GetWindowByRef("")->Pos); + + ctx->CaptureAddWindow("Dear ImGui Demo"); // Optional: Capture single window + ctx->CaptureBeginVideo(); + ctx->ItemOpen("Widgets"); + ctx->ItemInputValue("Basic/input text", "My first video!"); + ctx->CaptureEndVideo(); + }; + + +} + +#endif + + +void Gui() +{ + ImGui::Text("Hello"); + //ImGui::ShowDemoWindow(); + ImGuiTestEngine_ShowTestEngineWindows(HelloImGui::GetImGuiTestEngine(), NULL); + +} + + +int main(int, char *[]) +{ + HelloImGui::RunnerParams runnerParams; + runnerParams.callbacks.ShowGui = Gui; + +#ifdef HELLOIMGUI_WITH_TEST_ENGINE + runnerParams.callbacks.PostInit = [](){ + RegisterAppMinimalTests(HelloImGui::GetImGuiTestEngine()); + }; +#endif + + HelloImGui::Run(runnerParams); + return 0; +} diff --git a/src/hello_imgui_test_engine_integration/hello_imgui_test_engine_cmake.cmake b/src/hello_imgui_test_engine_integration/hello_imgui_test_engine_cmake.cmake new file mode 100644 index 00000000..2b8eebec --- /dev/null +++ b/src/hello_imgui_test_engine_integration/hello_imgui_test_engine_cmake.cmake @@ -0,0 +1,40 @@ +if(POLICY CMP0079) + cmake_policy(SET CMP0079 NEW) # target_link_libraries() allows use with targets in other directories. +endif() + + +# Add imgui_test_engine lib with sources in imgui_test_engine/imgui_test_engine +function(_add_imgui_test_engine_lib) + set(source_folder ${IMGUI_TEST_ENGINE_BASEPATH}/imgui_test_engine) + file(GLOB_RECURSE sources ${source_folder}/*.h ${source_folder}/*.cpp) + add_library(imgui_test_engine ${sources}) + target_include_directories(imgui_test_engine PUBLIC ${source_folder}/..) +endfunction() + + +# ImGui uses imconfig from imconfig_with_test_engine.h (with options for imgui_test_engine) +function(_configure_imgui_with_test_engine) + target_compile_definitions(imgui PUBLIC IMGUI_USER_CONFIG="${CMAKE_CURRENT_FUNCTION_LIST_DIR}/imconfig_with_test_engine.h") + # Link imgui_test_engine with imgui + target_link_libraries(imgui_test_engine PUBLIC imgui) + # any App built with ImGui should now also link with imgui_test_engine + target_link_libraries(imgui PUBLIC imgui_test_engine) +endfunction() + + +# Add integration into HelloImGui +function(_add_hello_imgui_test_engine_integration) + target_compile_definitions(hello_imgui PUBLIC HELLOIMGUI_WITH_TEST_ENGINE) + target_sources(hello_imgui PUBLIC + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/test_engine_integration.cpp + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/test_engine_integration.h + ) + target_include_directories(hello_imgui PUBLIC ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/..) +endfunction() + + +function(add_imgui_test_engine) + _add_imgui_test_engine_lib() + _configure_imgui_with_test_engine() + _add_hello_imgui_test_engine_integration() +endfunction() diff --git a/src/hello_imgui_test_engine_integration/imconfig_with_test_engine.h b/src/hello_imgui_test_engine_integration/imconfig_with_test_engine.h new file mode 100644 index 00000000..9310bd45 --- /dev/null +++ b/src/hello_imgui_test_engine_integration/imconfig_with_test_engine.h @@ -0,0 +1,197 @@ +#pragma once + +//----------------------------------------------------------------------------- +// DEAR IMGUI COMPILE-TIME OPTIONS for use with imgui_test_engine and HelloImGui +// `IMGUI_USER_CONFIG` is set to point to this file when HELLOIMGUI_WITH_TEST_ENGINE is ON +//----------------------------------------------------------------------------- + + + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +// Part 1: Test engine options +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +#define IMGUI_ENABLE_TEST_ENGINE + +// [Optional, default 0] Enable plotting of perflog data for comparing performance of different runs. +#define IMGUI_TEST_ENGINE_ENABLE_IMPLOT 0 + +// [Optional, default 1] Enable screen capture and PNG/GIF saving functionalities +#define IMGUI_TEST_ENGINE_ENABLE_CAPTURE 1 + +// [Optional, default 0] Using std::function and for function pointers such as ImGuiTest::TestFunc and ImGuiTest::GuiFunc +#define IMGUI_TEST_ENGINE_ENABLE_STD_FUNCTION 1 + +// [Optional, default 0] Automatically fill ImGuiTestEngineIO::CoroutineFuncs with a default implementation using std::thread +#define IMGUI_TEST_ENGINE_ENABLE_COROUTINE_STDTHREAD_IMPL 1 + +// Define IM_DEBUG_BREAK macros so it is accessible in imgui.h +// (this is a conveniance for app using test engine may define an IM_ASSERT() that uses this instead of an actual assert) +// (this is a copy of the block in imgui_internal.h. if the one in imgui_internal.h were to be defined at the top of imgui.h we wouldn't need this) +#ifndef IM_DEBUG_BREAK +#if defined (_MSC_VER) +#define IM_DEBUG_BREAK() __debugbreak() +#elif defined(__clang__) +#define IM_DEBUG_BREAK() __builtin_debugtrap() +#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) +#define IM_DEBUG_BREAK() __asm__ volatile("int $0x03") +#elif defined(__GNUC__) && defined(__thumb__) +#define IM_DEBUG_BREAK() __asm__ volatile(".inst 0xde01") +#elif defined(__GNUC__) && defined(__arm__) && !defined(__thumb__) +#define IM_DEBUG_BREAK() __asm__ volatile(".inst 0xe7f001f0"); +#else +#define IM_DEBUG_BREAK() IM_ASSERT(0) // It is expected that you define IM_DEBUG_BREAK() into something that will break nicely in a debugger! +#endif +#endif // #ifndef IMGUI_DEBUG_BREAK + +// [Options] We provide custom assert macro used by our our test suite, which you may use: +// - Calling IM_DEBUG_BREAK() instead of an actual assert, so we can easily recover and step over (compared to many assert implementations). +// - If a test is running, test name will be included in the log. +// - Macro is calling IM_DEBUG_BREAK() inline to get debugger to break in the calling function (instead of a deeper callstack level). +// - Macro is using comma operator instead of an if() to avoid "conditional expression is constant" warnings. +extern void ImGuiTestEngine_AssertLog(const char* expr, const char* file, const char* func, int line); +#define IM_TEST_ENGINE_ASSERT(_EXPR) do { if ((void)0, !(_EXPR)) { ImGuiTestEngine_AssertLog(#_EXPR, __FILE__, __func__, __LINE__); IM_DEBUG_BREAK(); } } while (0) +// V_ASSERT_CONTRACT, assertMacro:IM_ASSERT + + + + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +// Part 1: ImGui options +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// DEAR IMGUI COMPILE-TIME OPTIONS +// Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure. +// You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions. +//----------------------------------------------------------------------------- +// A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your modifications to it) +// B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own file without touching this template. +//----------------------------------------------------------------------------- +// You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the imgui*.cpp +// files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures. +// Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts. +// Call IMGUI_CHECKVERSION() from your .cpp file to verify that the data structures your files are using are matching the ones imgui.cpp is using. +//----------------------------------------------------------------------------- + + +//---- Define assertion handler. Defaults to calling assert(). +// If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement. +//#define IM_ASSERT(_EXPR) MyAssert(_EXPR) +//#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts + +//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows +// Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility. +// DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions() +// for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details. +//#define IMGUI_API __declspec( dllexport ) +//#define IMGUI_API __declspec( dllimport ) + +//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to clean your code of obsolete function/names. +//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS +//#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87: disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This will be folded into IMGUI_DISABLE_OBSOLETE_FUNCTIONS in a few versions. + +//---- Disable all of Dear ImGui or don't implement standard windows/tools. +// It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in day to day work. Please read comments in imgui_demo.cpp. +//#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty. +//#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. +//#define IMGUI_DISABLE_DEBUG_TOOLS // Disable metrics/debugger and other debug tools: ShowMetricsWindow(), ShowDebugLogWindow() and ShowStackToolWindow() will be empty (this was called IMGUI_DISABLE_METRICS_WINDOW before 1.88). + +//---- Don't implement some functions to reduce linkage requirements. +//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a) +//#define IMGUI_ENABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with Visual Studio] Implement default IME handler (require imm32.lib/.a, auto-link for Visual Studio, -limm32 on command-line for MinGW) +//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default IME handler (won't require imm32.lib/.a) +//#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, IME). +//#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default). +//#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf) +//#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself. +//#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies) +//#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function. +//#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions(). +//#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available + +//---- Include imgui_user.h at the end of imgui.h as a convenience +//#define IMGUI_INCLUDE_IMGUI_USER_H + +//---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another) +//#define IMGUI_USE_BGRA_PACKED_COLOR + +//---- Use 32-bit for ImWchar (default is 16-bit) to support unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...) +//#define IMGUI_USE_WCHAR32 + +//---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version +// By default the embedded implementations are declared static and not available outside of Dear ImGui sources files. +//#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h" +//#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h" +//#define IMGUI_STB_SPRINTF_FILENAME "my_folder/stb_sprintf.h" // only used if IMGUI_USE_STB_SPRINTF is defined. +//#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION +//#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION +//#define IMGUI_DISABLE_STB_SPRINTF_IMPLEMENTATION // only disabled if IMGUI_USE_STB_SPRINTF is defined. + +//---- Use stb_sprintf.h for a faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined) +// Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by stb_sprintf.h. +//#define IMGUI_USE_STB_SPRINTF + +//---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui) +// Requires FreeType headers to be available in the include path. Requires program to be compiled with 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided). +// On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'. +//#define IMGUI_ENABLE_FREETYPE + +//---- Use FreeType+lunasvg library to render OpenType SVG fonts (SVGinOT) +// Requires lunasvg headers to be available in the include path + program to be linked with the lunasvg library (not provided). +// Only works in combination with IMGUI_ENABLE_FREETYPE. +// (implementation is based on Freetype's rsvg-port.c which is licensed under CeCILL-C Free Software License Agreement) +//#define IMGUI_ENABLE_FREETYPE_LUNASVG + +//---- Use stb_truetype to build and rasterize the font atlas (default) +// The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend. +//#define IMGUI_ENABLE_STB_TRUETYPE + +//---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4. +// This will be inlined as part of ImVec2 and ImVec4 class declarations. +/* +#define IM_VEC2_CLASS_EXTRA \ + constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \ + operator MyVec2() const { return MyVec2(x,y); } + +#define IM_VEC4_CLASS_EXTRA \ + constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \ + operator MyVec4() const { return MyVec4(x,y,z,w); } +*/ +//---- ...Or use Dear ImGui's own very basic math operators. +//#define IMGUI_DEFINE_MATH_OPERATORS + +//---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices. +// Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices). +// Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer. +// Read about ImGuiBackendFlags_RendererHasVtxOffset for details. +//#define ImDrawIdx unsigned int + +//---- Override ImDrawCallback signature (will need to modify renderer backends accordingly) +//struct ImDrawList; +//struct ImDrawCmd; +//typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data); +//#define ImDrawCallback MyImDrawCallback + +//---- Debug Tools: Macro to break in Debugger (we provide a default implementation of this in the codebase) +// (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.) +//#define IM_DEBUG_BREAK IM_ASSERT(0) +//#define IM_DEBUG_BREAK __debugbreak() + +//---- Debug Tools: Enable slower asserts +//#define IMGUI_DEBUG_PARANOID + +//---- Tip: You can add extra functions within the ImGui:: namespace from anywhere (e.g. your own sources/header files) +/* +namespace ImGui +{ + void MyFunction(const char* name, MyMatrix44* mtx); +} +*/ diff --git a/src/hello_imgui_test_engine_integration/test_engine_integration.cpp b/src/hello_imgui_test_engine_integration/test_engine_integration.cpp new file mode 100644 index 00000000..239244e2 --- /dev/null +++ b/src/hello_imgui_test_engine_integration/test_engine_integration.cpp @@ -0,0 +1,90 @@ +// +// Created by Pascal Thomet on 26/09/2023. +// +#include "imgui_test_engine/imgui_te_engine.h" +#include "hello_imgui/runner_params.h" +#include "hello_imgui/internal/functional_utils.h" + +namespace HelloImGui +{ + struct TestEngineIntegration + { + ImGuiTestEngine *mTestEngine = nullptr; + + void _SetOptions() + { + ImGuiTestEngineIO& test_io = ImGuiTestEngine_GetIO(mTestEngine); + test_io.ConfigVerboseLevel = ImGuiTestVerboseLevel_Info; + test_io.ConfigVerboseLevelOnError = ImGuiTestVerboseLevel_Debug; + test_io.ConfigRunSpeed = ImGuiTestRunSpeed_Cinematic; // Default to slowest mode in this demo + + // test_io.ScreenCaptureFunc = ImGuiApp_ScreenCaptureFunc; + // test_io.ScreenCaptureUserData = (void*)app; + + // Optional: save test output in junit-compatible XML format. + //test_io.ExportResultsFile = "./results.xml"; + //test_io.ExportResultsFormat = ImGuiTestEngineExportFormat_JUnitXml; + } + + void Setup() + { + // Setup test engine + mTestEngine = ImGuiTestEngine_CreateContext(); + + _SetOptions(); + + // Start test engine + ImGuiTestEngine_Start(mTestEngine, ImGui::GetCurrentContext()); + ImGuiTestEngine_InstallDefaultCrashHandler(); + } + + void Shutdown_Before_ImGui_DestroyContext() + { + ImGuiTestEngine_Stop(mTestEngine); + } + void Shutdown_After_ImGui_DestroyContext() + { + // IMPORTANT: we need to destroy the Dear ImGui context BEFORE the test engine context, so .ini data may be saved. + ImGuiTestEngine_DestroyContext(mTestEngine); + } + + void PostSwap() + { + // Call after your rendering. This is mostly to support screen/video capturing features. + ImGuiTestEngine_PostSwap(mTestEngine); + } + }; + + TestEngineIntegration gTestEngineIntegration; + + + void _AddTestEngineCallbacks(RunnerParams* runnerParams) + { + auto &callbacks = runnerParams->callbacks; + + callbacks.PostInit = FunctionalUtils::sequence_functions( + []() { gTestEngineIntegration.Setup(); }, + callbacks.PostInit + ); + + callbacks.AfterSwap = FunctionalUtils::sequence_functions( + []() { gTestEngineIntegration.PostSwap(); }, + callbacks.AfterSwap + ); + + callbacks.BeforeExit = FunctionalUtils::sequence_functions( + []() { gTestEngineIntegration.Shutdown_Before_ImGui_DestroyContext(); }, + callbacks.BeforeExit + ); + + callbacks.BeforeExit_PostCleanup = FunctionalUtils::sequence_functions( + []() { gTestEngineIntegration.Shutdown_After_ImGui_DestroyContext(); }, + callbacks.BeforeExit_PostCleanup + ); + } + + ImGuiTestEngine* GetImGuiTestEngine() + { + return gTestEngineIntegration.mTestEngine; + } +} \ No newline at end of file diff --git a/src/hello_imgui_test_engine_integration/test_engine_integration.h b/src/hello_imgui_test_engine_integration/test_engine_integration.h new file mode 100644 index 00000000..3396c078 --- /dev/null +++ b/src/hello_imgui_test_engine_integration/test_engine_integration.h @@ -0,0 +1,9 @@ +#include "hello_imgui/runner_params.h" + +struct ImGuiTestEngine; + +namespace HelloImGui +{ + void _AddTestEngineCallbacks(RunnerParams* runnerParams); + ImGuiTestEngine* GetImGuiTestEngine(); +} diff --git a/src/hello_imgui_test_engine_integration/todo_test.md b/src/hello_imgui_test_engine_integration/todo_test.md new file mode 100644 index 00000000..86fbd018 --- /dev/null +++ b/src/hello_imgui_test_engine_integration/todo_test.md @@ -0,0 +1,29 @@ +submodule test_engine or not ? (warning; includes implot) / 9.8M (sur 126M) + +check uses of HELLOIMGUI_WITH_TEST_ENGINE vs IMGUI_ENABLE_TEST_ENGINE + +Config: + Study params + Reflechir / imconfig + +HelloImGui params: + param / enable tests + +callbacks: + struct / all callbacks + special callback / test registration? + PreNewFrame => BeforeNewFrame ? + +add namespace HelloImGui::TestEngine ? + +doc / license +capture function + +Démo dans imgui_manual + +Reduce demo size + + +CI + avec / sans + avec test app ?