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

Need Official way to set/clear ImGuiViewportFlags_CanHostOtherWindows #4520

Open
ldsPatrick opened this issue Sep 8, 2021 · 6 comments
Open

Comments

@ldsPatrick
Copy link

Version/Branch of Dear ImGui:

Version: 1.83
Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: custom built from imgui_impl_Win32.cpp + imgui_impl_dx11.cpp
Operating System: Win10

My Issue/Question:

We want to prevent other windows from being able to merge with the main window. But we do want some known windows to always be merged in. There seems to be a flag to control this: ImGuiViewportFlags_CanHostOtherWindows. But this is always set on the main window, and there is no API for changing it.

Internally, we are now removing that flag from the call to AddUpdateViewport(NULL, IMGUI_VIEWPORT_DEFAULT_ID, ...) in imgui.cpp. We then set the flag manually on the main viewport when we add a window that we know we want merged with it, and re-clear it right after.

This does the trick, but it seems wrong to modify viewport flags directly. Ideally, there would be a setting to not have that flag always be set on the main window, and there would be another flag you can pass when creating a window to specifically allow merging with the main window even if the flag is not set on the main window.

@ocornut
Copy link
Owner

ocornut commented Sep 8, 2021

I think the solution would be:

@ocornut
Copy link
Owner

ocornut commented Sep 8, 2021

The opposite is you can force an individual window to always claim its own viewport. It's labelled as ImGuiViewportFlags_NoAutoMerge but since you can't set it on a viewport that doesn't already exist you have to set it via the ImGuiWindowClass structure.

ImGuiWindowClass window_class;
window_class.ViewportFlagsOverrideSet = ImGuiViewportFlags_NoAutoMerge;
ImGui::SetNextWindowClass(&window_class);
ImGui::Begin(...);

@ldsPatrick
Copy link
Author

We want to let other windows merge with each other as they wish, so NoAutoMerge won't work. It's really the main window that is special.

Calling SetNextWindowViewport does seem to give us the desired behaviour, where only the windows we want are merged into the main one, which is a lot nicer than changing viewport flags ! So that leaves the first part, of clearing that flag in the initialization...

Thanks!

@ocornut
Copy link
Owner

ocornut commented Sep 8, 2021

We want to let other windows merge with each other as they wish, so NoAutoMerge won't work. It's really the main window that is special.

I think there might a confusion. Windows don't "merge with other" unless you are talking about Docking features. A viewport (displayed in a platform window) can host multiple imgui windows.

(ImGuiViewportFlags_NoAutoMerge and ImGuiViewportFlags_CanHostOtherWindows are conceptually opposite of each others. The fact that 2 flags is an odd artifact of how they need to be used. Earlier is set from POV of a window, later is set from POV of a viewport. I suppose we could remove ImGuiViewportFlags_NoAutoMerge and request user to use window_class.ViewportFlagsOverrideClear = ImGuiViewportFlags_CanHostOtherWindows (note it is a Clear not a Set), but it would be more confusing/misleading since in neither of those case a viewport flag is actually altered since the intent is to create a viewport to host a single window.)

Consider reading https://github.com/ocornut/imgui/wiki/Glossary and patching all occurrence of "window" to use precise terms such as "platform window" or "imgui window" or "viewport", it tends to help for those threads where there can be ambiguities.

So that leaves the first part, of clearing that flag in the initialization...

Would ((ImGuiViewportP*)GetMainViewport())->Flags &= ~ImGuiViewportFlags_CanHostOtherWindows work?

@ocornut
Copy link
Owner

ocornut commented Sep 8, 2021

Actually the name of ImGuiViewportFlags_NoAutoMerge was derived from the io.ConfigViewportsNoAutoMerge config option. I think we'd need some renaming.

io.ConfigViewportsNoAutoMerge is conceptually almost "don't set ImGuiViewportFlags_CanHostOtherWindows on main viewport" which makes me realize io.ConfigViewportsNoAutoMerge could perhaps be simply implemented by clearing that flag, exactly like you wanted to do in NewFrame().

@ldsPatrick
Copy link
Author

Sorry for the confusion. Yes, we are using the docking branch, but this isn't about actually docking. It's about whether windows are allowed to use the main viewport when their rect is encompassed by it. ConfigViewportsNoAutoMerge is global, and makes each window always create their own viewport. We want to allow two imgui windows A and B that fully overlap use the same viewport. We just don't want them to try to use the main viewport.

That is, except for a few specific imgui windows that we deliberately place overlapping the main viewport, and we want those to use the main viewport and not create their own, because we want them to move with the main window. Calling SetNextWindowViewport() before each of those special windows does achieves that.

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