Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Child-menus no longer attempt to fit inside the viewport #7287

Closed
ZingBallyhoo opened this issue Feb 2, 2024 · 2 comments
Closed

Child-menus no longer attempt to fit inside the viewport #7287

ZingBallyhoo opened this issue Feb 2, 2024 · 2 comments
Labels
bug menus menu bars, menu items

Comments

@ZingBallyhoo
Copy link

Version/Branch of Dear ImGui:

Version 1.90.2 WIP (19016), Branch: master

Back-ends:

imgui_impl_win32.cpp + imgui_impl_dx11.cpp

Compiler, OS:

Windows 10 + MSVC

Full config/build information:

Dear ImGui 1.90.2 WIP (19016)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: _WIN32
define: _WIN64
define: _MSC_VER=1938
define: _MSVC_LANG=201402
--------------------------------
io.BackendPlatformName: imgui_impl_win32
io.BackendRendererName: imgui_impl_dx11
io.ConfigFlags: 0x00000003
 NavEnableKeyboard
 NavEnableGamepad
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x0000000E
 HasMouseCursors
 HasSetMousePos
 RendererHasVtxOffset
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,64
io.DisplaySize: 1264.00,761.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

Details:

My Issue/Question:

As of 1.90.1 child menus no longer attempt to fit inside of the viewport. Root menus still work correctly.

Introduced in commit f37f6f6 (Related issue: #7063)

Screenshots/Video:

Previous behavior Current behavior
image image

Minimal, Complete and Verifiable Example code:

if (ImGui::BeginMainMenuBar())
{
    if (ImGui::BeginMenu("Menu"))
    {
        if (ImGui::BeginMenu("Submenu"))
        {
            for (int i = 0; i < 50; ++i)
            {
                ImGui::Text("hello!");
            }
            ImGui::EndMenu();
        }
        ImGui::EndMenu();
    }
    ImGui::EndMainMenuBar();
}

Can also be seen on the demo submenus (e.g Menu->Colors)

@ZingBallyhoo
Copy link
Author

Was this mis-triaged as multi-viewports? I feel like my title could have been misleading. What I really meant was "child-menus no longer attempt to fit inside the work rect of the viewport"

My very temporary fix is this: (master only)

Index: imgui.cpp
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/imgui.cpp b/imgui.cpp
--- a/imgui.cpp	(revision 536090303a8fca7d896f77d6d63dc59249bc87f4)
+++ b/imgui.cpp	(date 1707564068063)
@@ -5755,7 +5755,8 @@
     {
         // Maximum window size is determined by the viewport size or monitor size
         ImVec2 size_min = CalcWindowMinSize(window);
-        ImVec2 size_max = (window->Flags & ImGuiWindowFlags_ChildWindow) ? ImVec2(FLT_MAX, FLT_MAX) : ImGui::GetMainViewport()->WorkSize - style.DisplaySafeAreaPadding * 2.0f;
+        ImVec2 size_max = (window->Flags & ImGuiWindowFlags_ChildWindow && !(window->Flags & ImGuiWindowFlags_ChildMenu)) ? 
+            ImVec2(FLT_MAX, FLT_MAX) : ImGui::GetMainViewport()->WorkSize - style.DisplaySafeAreaPadding * 2.0f;
         ImVec2 size_auto_fit = ImClamp(size_desired, size_min, size_max);
 
         // When the window cannot fit all contents (either because of constraints, either because screen is too small),

@ocornut ocornut added bug menus menu bars, menu items and removed multi-viewports labels Feb 10, 2024
ocornut added a commit that referenced this issue Feb 12, 2024
…sly not displaying a scrollbar when contents is over parent viewport size. (#7287, #7063)

Amend f37f6f6
@ocornut
Copy link
Owner

ocornut commented Feb 12, 2024

You are right, I've pushed the fix 3af739a.
The right fix is to check for the _Popup flag rather than _ChildMenu one.
Alternative repro being:

if (ImGui::Button("OpenPopup"))
    ImGui::OpenPopup("Popup");
if (ImGui::BeginPopup("Popup", ImGuiWindowFlags_ChildWindow))
{
    for (int i = 0; i < 50; ++i)
    {
        ImGui::Text("hello!");
    }
    ImGui::EndPopup();
}

Using Popup+Child flags together is not well documented behavior but as various uses.

@ocornut ocornut closed this as completed Feb 12, 2024
ocornut added a commit that referenced this issue Feb 20, 2024
…ld erroneously close the window. (#7325, #7287, #7063)

Amend 76e09c4. Initial call to ClosePopupToLevel d31fe97 (#2880).
See "widgets_menu_reopen_2" in TestSuite.
ocornut added a commit that referenced this issue Feb 27, 2024
… successive frames would erroneously close the window. (#7325, #7287, #7063)

Amend 014e0ac
ocornut added a commit that referenced this issue Jun 27, 2024
…n viewport would be erroneously clamped to the size of main viewport. (#7730)

Amend #7287, #7063
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug menus menu bars, menu items
Projects
None yet
Development

No branches or pull requests

2 participants