From 695141fc76c6d57ef71b125552618de4b7b4a20b Mon Sep 17 00:00:00 2001 From: Maxime Cots <42718803+Ni-g-3l@users.noreply.github.com> Date: Tue, 25 Feb 2025 07:51:29 +0100 Subject: [PATCH] Center CheatSheet vertically (#1985) * Center cheatsheet vertically * Update tests * Add a new test --- application/testing/CMakeLists.txt | 4 ++++ .../TestInteractionCheatsheetAnimationName.png | 4 ++-- .../baselines/TestInteractionCheatsheetBlackBG.png | 4 ++-- .../baselines/TestInteractionCheatsheetCentered.png | 3 +++ .../TestInteractionCheatsheetConfigFile.png | 4 ++-- .../baselines/TestInteractionCheatsheetNoFile.png | 4 ++-- .../baselines/TestInteractionCheatsheetOpacity.png | 4 ++-- .../baselines/TestInteractionCheatsheetScalars.png | 4 ++-- .../baselines/TestInteractionCheatsheetWhiteBG.png | 4 ++-- .../TestInteractionCheatsheetCentered.log | 6 ++++++ vtkext/private/module/vtkF3DImguiActor.cxx | 13 +++++++++++-- 11 files changed, 38 insertions(+), 16 deletions(-) create mode 100644 testing/baselines/TestInteractionCheatsheetCentered.png create mode 100644 testing/recordings/TestInteractionCheatsheetCentered.log diff --git a/application/testing/CMakeLists.txt b/application/testing/CMakeLists.txt index d44d7bc8c9..1ec05c7049 100644 --- a/application/testing/CMakeLists.txt +++ b/application/testing/CMakeLists.txt @@ -442,6 +442,10 @@ f3d_test(NAME TestInteractionCheatsheetOpacity DATA cow.vtp INTERACTION UI ARGS f3d_test(NAME TestInteractionCheatsheetAnimationName DATA InterpolationTest.glb ARGS --animation-index=6 INTERACTION UI) #HWWW f3d_test(NAME TestInteractionCheatsheetConfigFile DATA dragon.vtu CONFIG ${F3D_SOURCE_DIR}/testing/configs/bindings.json INTERACTION UI) #H;ScrollDown +if(NOT F3D_MODULE_RAYTRACING) + f3d_test(NAME TestInteractionCheatsheetCentered DATA cow.vtp ARGS --resolution=500,1500 INTERACTION UI LONG_TIMEOUT) #H +endif() + f3d_test(NAME TestCameraPersp DATA Cameras.gltf ARGS --camera-index=0) f3d_test(NAME TestCameraOrtho DATA Cameras.gltf ARGS --camera-index=1) f3d_test(NAME TestCameraIndexConfiguration DATA Cameras.gltf ARGS --camera-index=0 --camera-azimuth-angle=15 --camera-position=0.7,0.5,3) diff --git a/testing/baselines/TestInteractionCheatsheetAnimationName.png b/testing/baselines/TestInteractionCheatsheetAnimationName.png index afc52d2a44..929104eb4e 100644 --- a/testing/baselines/TestInteractionCheatsheetAnimationName.png +++ b/testing/baselines/TestInteractionCheatsheetAnimationName.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5deaa2c893ce987ec29b868a772d418622ca5bc9c0dc7492778d768594a4d833 -size 42606 +oid sha256:45a7f592a0cacada696c2f2273ea4456583e46dee68ac736de5e529b45f99a8d +size 42744 diff --git a/testing/baselines/TestInteractionCheatsheetBlackBG.png b/testing/baselines/TestInteractionCheatsheetBlackBG.png index f9ce74e529..b30b4e9f3c 100644 --- a/testing/baselines/TestInteractionCheatsheetBlackBG.png +++ b/testing/baselines/TestInteractionCheatsheetBlackBG.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:793b0d9ac02b18cfd5d3e89eb0f4a799e3c37189ddc5b687c9e984d29bc8cc3b -size 50253 +oid sha256:732d9be01c1caff1f85ffffec64c31606bb728d967cd42ca0698fd988518444b +size 50185 diff --git a/testing/baselines/TestInteractionCheatsheetCentered.png b/testing/baselines/TestInteractionCheatsheetCentered.png new file mode 100644 index 0000000000..3b3288f515 --- /dev/null +++ b/testing/baselines/TestInteractionCheatsheetCentered.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:332f5993a90421012edbbc5ee80cc853c8c8eac12eecb71e98bbb61037a7f85a +size 205882 diff --git a/testing/baselines/TestInteractionCheatsheetConfigFile.png b/testing/baselines/TestInteractionCheatsheetConfigFile.png index 45d43e63bf..e9ac5dde76 100644 --- a/testing/baselines/TestInteractionCheatsheetConfigFile.png +++ b/testing/baselines/TestInteractionCheatsheetConfigFile.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:51949000f8437fe6dbe26461d642301ba494d330bfe97fc2e0f6f985fa36fdc7 -size 50643 +oid sha256:a6ddcfd932b601d98aa044acc3999f54f4dd4024640687f1edc7b3fe97687719 +size 50630 diff --git a/testing/baselines/TestInteractionCheatsheetNoFile.png b/testing/baselines/TestInteractionCheatsheetNoFile.png index 08175c8a09..308112d996 100644 --- a/testing/baselines/TestInteractionCheatsheetNoFile.png +++ b/testing/baselines/TestInteractionCheatsheetNoFile.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7f0b98792f9e8c7392a5896de14ac913e47a03e5b6fb7a00043a26ed9a5f7a7b -size 43078 +oid sha256:7e42391f5393daf716d580ee5d20b7721f40afa128543d644f7c0b5e308c6c3e +size 42724 diff --git a/testing/baselines/TestInteractionCheatsheetOpacity.png b/testing/baselines/TestInteractionCheatsheetOpacity.png index 2fc215ab4e..f93e467a7c 100644 --- a/testing/baselines/TestInteractionCheatsheetOpacity.png +++ b/testing/baselines/TestInteractionCheatsheetOpacity.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:739329d5593a9b6cd23c414a0663e510542b224f94d4982d313d94a75f04b5eb -size 84358 +oid sha256:c2981cdc213763109d9ff31dbbdecf9bcf5d3e16f5da486e9ad9219b30b73683 +size 84124 diff --git a/testing/baselines/TestInteractionCheatsheetScalars.png b/testing/baselines/TestInteractionCheatsheetScalars.png index 4a5b261b8e..3381079a9d 100644 --- a/testing/baselines/TestInteractionCheatsheetScalars.png +++ b/testing/baselines/TestInteractionCheatsheetScalars.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:28bb7095e93f12714b0ec4471567ecc94ac017ae2508fe966bd80a1dd022ce44 -size 54492 +oid sha256:5cb03f1c0abfb97edaca359132208ba76cd2a81e21183dd33c962afe400d16f3 +size 54384 diff --git a/testing/baselines/TestInteractionCheatsheetWhiteBG.png b/testing/baselines/TestInteractionCheatsheetWhiteBG.png index 4d75ad8576..08c4139e7f 100644 --- a/testing/baselines/TestInteractionCheatsheetWhiteBG.png +++ b/testing/baselines/TestInteractionCheatsheetWhiteBG.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8a7095c03adc16d6586b456a16d03ce4b01c1972599e8fb3520abfd6d1d3febd -size 46905 +oid sha256:ec6f4e181fbc7a03a058bb800ff1de63634445fdd92bd7f341afc5339ad6cac1 +size 46602 diff --git a/testing/recordings/TestInteractionCheatsheetCentered.log b/testing/recordings/TestInteractionCheatsheetCentered.log new file mode 100644 index 0000000000..661ec0f3fb --- /dev/null +++ b/testing/recordings/TestInteractionCheatsheetCentered.log @@ -0,0 +1,6 @@ +# StreamVersion 1.1 +ExposeEvent 0 599 0 0 0 0 +RenderEvent 0 599 0 0 0 0 +KeyPressEvent 738 539 0 104 1 h +CharEvent 738 539 0 104 1 h +KeyReleaseEvent 738 539 0 104 1 h diff --git a/vtkext/private/module/vtkF3DImguiActor.cxx b/vtkext/private/module/vtkF3DImguiActor.cxx index 133f9f1197..3b100dfc9f 100644 --- a/vtkext/private/module/vtkF3DImguiActor.cxx +++ b/vtkext/private/module/vtkF3DImguiActor.cxx @@ -344,9 +344,13 @@ void vtkF3DImguiActor::RenderCheatSheet() constexpr float marginLeft = 5.f; constexpr float marginTopBottom = 5.f; + float textHeight = 0.f; float winWidth = 0.f; + for (const auto& [group, content] : this->CheatSheet) { + textHeight += + ImGui::GetTextLineHeightWithSpacing() + 2 * ImGui::GetStyle().SeparatorTextPadding.y; for (const auto& [bind, desc, val] : content) { std::string line = bind; @@ -359,12 +363,17 @@ void vtkF3DImguiActor::RenderCheatSheet() ImVec2 currentLine = ImGui::CalcTextSize(line.c_str()); winWidth = std::max(winWidth, currentLine.x); + textHeight += ImGui::GetTextLineHeightWithSpacing(); } } + winWidth += 2.f * ImGui::GetStyle().WindowPadding.x + ImGui::GetStyle().ScrollbarSize; + textHeight += 2.f * ImGui::GetStyle().WindowPadding.y; + + const float winTop = std::max(marginTopBottom, (viewport->WorkSize.y - textHeight) * 0.5f); - ::SetupNextWindow(ImVec2(marginLeft, marginTopBottom), - ImVec2(winWidth, viewport->WorkSize.y - 2.f * marginTopBottom)); + ::SetupNextWindow(ImVec2(marginLeft, winTop), + ImVec2(winWidth, std::min(viewport->WorkSize.y - (2 * marginTopBottom), textHeight))); ImGui::SetNextWindowBgAlpha(0.35f); ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize |