@@ -2778,6 +2778,69 @@ void RegisterTests_Layout(ImGuiTestEngine* e)
27782778 ImGui::End ();
27792779 };
27802780
2781+ // ## Test how contents submitted in Menu Layer affect contents size.
2782+ t = IM_REGISTER_TEST (e, " layout" , " layout_menu_extents" );
2783+ struct LayoutMenuVars { bool MainOutButton = false ; ImVec2 MenuAvailSize; };
2784+ t->SetVarsDataType <LayoutMenuVars>();
2785+ t->GuiFunc = [](ImGuiTestContext* ctx)
2786+ {
2787+ auto & vars = ctx->GetVars <LayoutMenuVars>();
2788+ ImGui::Begin (" Test Window" , nullptr , ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_HorizontalScrollbar);
2789+
2790+ if (ImGui::BeginMenuBar ())
2791+ {
2792+ vars.MenuAvailSize = ImGui::GetContentRegionAvail ();
2793+ ImGui::Button (" Menu Button" , ImVec2 (400 .0f , 0 .0f ));
2794+ ImGui::EndMenuBar ();
2795+ }
2796+ ImGui::Text (" Hi" );
2797+ if (vars.MainOutButton )
2798+ ImGui::Button (" Main button" , ImVec2 (500 .f , 500 .f ));
2799+ ImGui::End ();
2800+ };
2801+ t->TestFunc = [](ImGuiTestContext* ctx)
2802+ {
2803+ auto & vars = ctx->GetVars <LayoutMenuVars>();
2804+
2805+ ctx->SetRef (" Test Window" );
2806+ ImGuiWindow* window = ctx->GetWindowByRef (" " );
2807+ ctx->ScrollToX (" " , 0 .0f );
2808+
2809+ // Auto-resize uses ContentSizeIdeal which is similar to ContentSize but doesn't affect scrolling range.
2810+ vars.MainOutButton = false ;
2811+ ctx->WindowResize (" " , ImVec2 (100 .0f , 100 .0f ));
2812+ ctx->WindowResize (" " , ImVec2 (-1 .0f , -1 .0f )); // Auto-resize up
2813+ IM_CHECK_EQ (window->Size .x , 400 .0f + ImGui::GetStyle ().WindowPadding .x * 2 .0f );
2814+
2815+ ctx->WindowResize (" " , ImVec2 (600 .0f , 100 .0f ));
2816+ ctx->WindowResize (" " , ImVec2 (-1 .0f , -1 .0f )); // Auto-resize down
2817+ IM_CHECK_EQ (window->Size .x , 400 .0f + ImGui::GetStyle ().WindowPadding .x * 2 .0f );
2818+ IM_CHECK_EQ (vars.MenuAvailSize .x , 400 .0f );
2819+
2820+ vars.MainOutButton = true ;
2821+ ctx->Yield (2 );
2822+ // ctx->WindowResize("", ImVec2(100.0f, 100.0f));
2823+ IM_CHECK_EQ (window->ContentSize .x , 500 .0f );
2824+ IM_CHECK_GE (window->ContentSize .y , 500 .0f );
2825+ IM_CHECK (window->ScrollbarX && window->ScrollbarY );
2826+
2827+ // Check that absolute position of menu contents doesn't interfere with main layer scrolling and contents size
2828+ float scroll_max_x = window->ScrollMax .x ;
2829+ ctx->ScrollToX (" " , window->ScrollMax .x );
2830+ IM_UNUSED (scroll_max_x);
2831+ #if IMGUI_VERSION_NUM >= 18991
2832+ IM_CHECK_EQ (window->ContentSize .x , 500 .0f );
2833+ IM_CHECK_EQ (window->ScrollMax .x , scroll_max_x);
2834+ #endif
2835+
2836+ ctx->WindowResize (" " , ImVec2 (-1 .0f , -1 .0f )); // Auto-resize up
2837+ #if IMGUI_VERSION_NUM >= 18991
2838+ IM_CHECK_EQ (window->Size .x , 500 .0f + ImGui::GetStyle ().WindowPadding .x * 2 .0f );
2839+ #endif
2840+
2841+ ctx->Yield (3 );
2842+ };
2843+
27812844 // ## Test SameLine() + SetCursorPos() mixup
27822845#if IMGUI_VERSION_NUM >= 18718
27832846 t = IM_REGISTER_TEST (e, " layout" , " layout_sameline_cursorpos" );
0 commit comments