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

Docking windows that have a minimum size causes incorrect clipping rect #2690

Closed
Unit2Ed opened this issue Jul 24, 2019 · 2 comments
Closed

Comments

@Unit2Ed
Copy link

Unit2Ed commented Jul 24, 2019

Version/Branch of Dear ImGui:

Version: 1.72 WIP (17102)
Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_dx11.cpp + imgui_impl_win32.cpp
Compiler: Visual C++ 2017
Operating System: Windows 10

If you have a window that's set to have a minimum size, then dock the window and shrink it smaller than that minimum size, the content clip rect seems to be set to the minimum size, rather than the size enforced on the window by the dock node.

In the example project, I've created a simple window with a large button, and set a min/max constraint on it:

ImGui::SetNextWindowSizeConstraints(ImVec2(300, 300), ImVec2(800, 800));
ImGui::Begin("Constrained Window");
ImGui::Button("Button", ImVec2(600, 600));
ImGui::End();

Then used the demo window's Examples -> Dockspace menu to enable a full-screen dockspace, and dragged the window to the left edge, and shrunk the dock node's width to less than 300px. Notice that the button's text is visible outside the window, and the button's hover shading is too; clipping at around 300px from the edge of the screen.

WindowClipRect

I'm unsure whether there's a core problem that the dock node should respect the window's constraints and stop you from shrinking it so small, but it shouldn't be allowing the window to draw outside its bounds either way.

@ocornut
Copy link
Owner

ocornut commented Jul 24, 2019

Nice find, odd bug..
At the moment the Docking doesn't honor constraint. Ideally it would/should but that would require non-trivial work. Int he meanwhile I believe the suitable workaround would be explicitely disable them so they don't interfere:

in Begin() adding those two lines should fix it:

    if (first_begin_of_the_frame)
    {
        bool has_dock_node = (window->DockId != 0 || window->DockNode != NULL);
        bool new_auto_dock_node = !has_dock_node && GetWindowAlwaysWantOwnTabBar(window);
        if (has_dock_node || new_auto_dock_node)
        {
            BeginDocked(window, p_open);
            flags = window->Flags;

++          // Docking currently override constraints
++          g.NextWindowData.Flags &= ~ImGuiNextWindowDataFlags_HasSizeConstraint;
        }
    }

Would that be an acceptable fix short-term? (I don't have an ETA for docking handling constraint at window-level... it is kind of a hairy problem as windows with varied constraints may be docked in the same location.. toggling their visiblity would affect the docking tree every time..).

I think perhaps a healthier way of supporting them is that the constraints wouldn't affect the size of the docking node, but the space the window would be allowed to occupy within the space of that node would be affected by the constraint (so some space in the docking node may be unused).

ocornut added a commit that referenced this issue Jul 25, 2019
@Unit2Ed
Copy link
Author

Unit2Ed commented Jul 25, 2019

Thanks Omar, I've confirmed that your patch has fixed this for us.
I agree, there's no sensible solution to size-constrained docking; we'll just need to make sure our windows do the best they can.

@Unit2Ed Unit2Ed closed this as completed Jul 25, 2019
ocornut added a commit that referenced this issue Nov 26, 2019
, #2109, #2906)

In #2906 the zero input came from a minimized viewport, but even without it we cannot prevent DockNode size from eventually reaching zero as padding are taken from the starting size.
In a separate commit we'll however shortcut some of the existing codepath on zero-sized viewport to reduce the likehood of lossy side-effects (just like we don't call ClampWindowRect in Begin)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants