Skip to content

Commit

Permalink
Center CheatSheet vertically (#1985)
Browse files Browse the repository at this point in the history
* Center cheatsheet vertically
* Update tests
* Add a new test
  • Loading branch information
Ni-g-3l authored Feb 25, 2025
1 parent c1c0058 commit 695141f
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 16 deletions.
4 changes: 4 additions & 0 deletions application/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions testing/baselines/TestInteractionCheatsheetAnimationName.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions testing/baselines/TestInteractionCheatsheetBlackBG.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions testing/baselines/TestInteractionCheatsheetCentered.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions testing/baselines/TestInteractionCheatsheetConfigFile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions testing/baselines/TestInteractionCheatsheetNoFile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions testing/baselines/TestInteractionCheatsheetOpacity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions testing/baselines/TestInteractionCheatsheetScalars.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions testing/baselines/TestInteractionCheatsheetWhiteBG.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions testing/recordings/TestInteractionCheatsheetCentered.log
Original file line number Diff line number Diff line change
@@ -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
13 changes: 11 additions & 2 deletions vtkext/private/module/vtkF3DImguiActor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 |
Expand Down

0 comments on commit 695141f

Please sign in to comment.