-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First work / imgui test engine integration
- Loading branch information
Showing
12 changed files
with
532 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/hello_imgui_demos/hello_imgui_demo_test_engine/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
105 changes: 105 additions & 0 deletions
105
src/hello_imgui_demos/hello_imgui_demo_test_engine/hello_imgui_demo_test_engine.main.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TestVars2>(); | ||
t->GuiFunc = [](ImGuiTestContext* ctx) | ||
{ | ||
TestVars2& vars = ctx->GetVars<TestVars2>(); | ||
ImGui::Begin("Test Window", NULL, ImGuiWindowFlags_NoSavedSettings); | ||
ImGui::SliderInt("Slider", &vars.MyInt, 0, 1000); | ||
ImGui::End(); | ||
}; | ||
t->TestFunc = [](ImGuiTestContext* ctx) | ||
{ | ||
TestVars2& vars = ctx->GetVars<TestVars2>(); | ||
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; | ||
} |
40 changes: 40 additions & 0 deletions
40
src/hello_imgui_test_engine_integration/hello_imgui_test_engine_cmake.cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
Oops, something went wrong.