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

Multi-viewports / virtual viewports #1542

Open
ocornut opened this issue Jan 8, 2018 · 134 comments
Open

Multi-viewports / virtual viewports #1542

ocornut opened this issue Jan 8, 2018 · 134 comments

Comments

@ocornut
Copy link
Owner

ocornut commented Jan 8, 2018

*EDIT*

**Please prefer creating new issues (and referring to this one with a #1542 marker) when reporting bugs or asking questions. This thread is currently too big to be useful.

October 2020: Wiki page: https://github.com/ocornut/imgui/wiki/Multi-Viewports
MultiViewports


IF YOU SUBMIT/DISCUSS AN ISSUE RELATED TO MULTI_VIEWPORTS:

  • Always state which imgui_impl_xxx platform and renderer back-end files you are using.
  • If you are using imgui_impl_glfw.cpp, state which version of GLFW you are using. If you are using imgui_impl_sdl2.cpp, state which version of SDL2 you are using, etc.
  • Always state your OS type, OS version, window manager and extensions (in the case of Unix systems).
  • If the issue happens in your own application, always also tests in the examples/ application and state if you have the same problem with those applications.
  • Make sure to check how the main.cpp of the examples/ application is currently setup for the viewport branch.
  • Never state "there is a crash/assert" without providing an associated callstack and details.

January 2019: Viewport and Docking branches have been merged to simplify maintainance. Use the 'docking' branch to test multi-viewports.

December 2019: See Glossary: https://github.com/ocornut/imgui/wiki/Glossary#multi-viewports-terms

January 2020: If you want to implement multi-viewports in your custom engine, the easiest path is to read the comment around ImGuiPlatformIO along with the bottom sections of e.g. imgui_impl_glfw+imgui_impl_opengl3 to learn from it.

For Linux/Mac specific issues please post in #2117.


Creating this thread to discuss and tag commits related to an upcoming feature.

It somehow relates to Docking (#2109) in the sense that current work on docking created growing expectations to get this working. But it's also mostly separate code, and for various reasons I think this will probably go in master before Docking. It will need testing and feedback.

If you follow the Docking thread you may have seen this already: [...]
And more recently I improved transition and it's somewhat magical:
imgui_platform_20180108

What happens here essentially if that the code creates borderless (undecorated) windows with a dedicated DirectX/OpenGL context on the fly, create imgui viewport to cover this os window, and move the window there..

Basically it consist in two parts:

  • dear imgui will support a new concept called "viewport". A single imgui context can drive multiple virtualized regions, as shown in those GIF. Using a single context makes sharing state natural (things like settings, tree nodes state or cross windows drag and drop). There are still various problems to solve related to persistence, mouse position, etc. but overall it's not a crazily complex feature.

  • To support this feature the backend code (imgui_impl_xxxx files) needs to be reworked obviously. It puts additional complexity on that code and not all engine will support it. That part needs to be both optional and as out of the way possible. I suspect we will need to iterate on that a lot, both to get the functionalities right, and because I worry a lot about the imgui first-time user experience and impression, and the additional complexity is very undesirable there.
    I suspect I may end up re-factoring a lot of the examples/ code.

If you are interested I will be looking for feedback and early adopters, hopefully starting in January some of this can be in a branch.

@Pagghiu
Copy link
Contributor

Pagghiu commented Jan 8, 2018

This is pure magic @ocornut 🥇

@ebachard
Copy link

ebachard commented Jan 8, 2018

wow !

If you need people for tests (mostly Linux), I'm volunteer.

@JaapSuter
Copy link

JaapSuter commented Jan 9, 2018

Sign me up Ocornut, I'll gladly beta-test, and happy to provide feedback.

@itamago
Copy link

itamago commented Jan 10, 2018

I would be interested in testing it on Windows, and more specifically trying to port it on OSX to see if there are some limitations on this platform

ocornut added a commit that referenced this issue Jan 11, 2018
… window DrawList main clipping rectangle. Sane (and required for viewport code). (#822, #1542)
ocornut added a commit that referenced this issue Jan 11, 2018
…dle manual resize (grip, border, gamepad) before setting up window DrawList main clipping rectangle. Sane (and required for viewport code). (#822, #1542)
@JSandusky
Copy link

JSandusky commented Jan 12, 2018

Pants change inbound. This is awesome.

@gerryhernandez
Copy link
Contributor

gerryhernandez commented Feb 3, 2018

Just wanted to chime in and say this looks amazing. I’m in the planning stages for a green-field project and I’m considering being an early adopter for this. One constraint that we have, though, is that it must work in OS X. I would happily contribute where I can, but I have zero experience in this area. Could someone give me a “scientific wild guess” on the feasibility of making this work on OS X? Thanks!

@ocornut
Copy link
Owner Author

ocornut commented Feb 3, 2018

I have a GLFW backend with a few OS specific tweaks (currently implemented for Win32 only). I think we’ll aim to support OS X at minimum in the GLFW example, maybe also SDL if it has the functions we need.
EDIT edited for clarity.

@gerryhernandez
Copy link
Contributor

gerryhernandez commented Feb 5, 2018

Looking forward to the branch. I don't mind adopting early; my application isn't anything critical and I'll be able to tolerate bugs, frequent refactors, etc.

@eigenbom
Copy link

eigenbom commented Feb 8, 2018

I knew you were a wizard.

ocornut added a commit that referenced this issue May 25, 2020
@ocornut ocornut modified the milestones: v1.80, v1.90 Aug 28, 2020
ocornut added a commit that referenced this issue Nov 19, 2020
…orm z-check before merging in main host viewport. (#3511, #1542)

This should fix a good amount of "lost modal" problems, however it is still possible to loose a modal in a host viewport if secondary viewports are configured as children above the host.
ocornut added a commit that referenced this issue Feb 10, 2021
…nd work area of the host display. (#3789, #1542)

Viewports: Backport a few constructs from 'docking' branch.
Viewports: Added ImGuiViewportFlags_IsPlatformWindow, ImGuiViewportFlags_IsPlatformMonitor, ImGuiViewportFlags_OwnedByApp (none of them were in docking branch yet). ImGuiViewportFlags_IsPlatformMonitor is merely there to convey future intent, not yet used.
Reduce uses of io.DisplaySize.
MainMenuBar: Backport work area handling code from 'docking' branch.
Metrics: Backported "Viewports" debug visualizer from 'docking' branch.
Demo: Rework 'Examples->Fullscreen Window'.
Demo: 'Simple Overlay' demo now moves under main menu-bar (if any) using GetMainViewport()'s work area.
ocornut added a commit that referenced this issue Feb 10, 2021
…nd work area of the host display. (#3789, #1542)

Viewports: Backport a few constructs from 'docking' branch.
Viewports: Added ImGuiViewportFlags_IsPlatformWindow, ImGuiViewportFlags_IsPlatformMonitor, ImGuiViewportFlags_OwnedByApp (none of them were in docking branch yet). ImGuiViewportFlags_IsPlatformMonitor is merely there to convey future intent, not yet used.
Reduce uses of io.DisplaySize.
MainMenuBar: Backport work area handling code from 'docking' branch.
Metrics: Backported "Viewports" debug visualizer from 'docking' branch.
Demo: Rework 'Examples->Fullscreen Window'.
Demo: 'Simple Overlay' demo now moves under main menu-bar (if any) using GetMainViewport()'s work area.
ocornut added a commit that referenced this issue Mar 5, 2021
… flag in docking branch (ok in master), GLFW: Fix application of WantSetMousePos. (#1542, #787)

Shows how little this feature is used with nav (was designed for small devices and frankly may be dropped) - but the backend support itself we will make use of for other features.
@PatchByte
Copy link

PatchByte commented Aug 8, 2021

Hello i have a question how can i disable the viewport support for only one window?

@ocornut
Copy link
Owner Author

ocornut commented Aug 8, 2021

@Stanlyhalo
Copy link

Stanlyhalo commented Aug 27, 2021

So I tried this, and this doesn't work for me, I think I'm missing a step. I set io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; in the initialization of DearImGui docking, then I call ImGui::UpdatePlatformWindows(); after ImGui::Render();, but now whenever I drag a window so it's touching the border of the main window (imgui window is still inside main window), it turns invisible and only visible if I let go with it being inside the application not touching the border.

Fyi, I'm using the latest win10 version on docking branch 1.83.

@AidanSun05
Copy link

AidanSun05 commented Aug 27, 2021

@Stanlyhalo It sounds like you're missing a few render calls.
For example, here's the full rendering code for the GLFW+OpenGL 3 example:

// Rendering
ImGui::Render();
int display_w, display_h;
glfwGetFramebufferSize(window, &display_w, &display_h);
glViewport(0, 0, display_w, display_h);
glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
// Update and Render additional Platform Windows
// (Platform functions may change the current OpenGL context, so we save/restore it to make it easier to paste this code elsewhere.
// For this specific demo app we could also call glfwMakeContextCurrent(window) directly)
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
GLFWwindow* backup_current_context = glfwGetCurrentContext();
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
glfwMakeContextCurrent(backup_current_context);
}
glfwSwapBuffers(window);

Are you missing anything in the if statement that renders the additional platform windows (175-181)?

@Stanlyhalo
Copy link

Stanlyhalo commented Aug 27, 2021

Oh yay, it works now, however it's black, is that normal?

Even the tabs turn black (not text though), and if I have 2 tabs stacked together now outside the window, the background turns black, but if the tab is alone, the tab background is normal.

Also closing the application causes this error in the console and an error messagebox (error only appears when closing the application with a window outside of it): [vulkan] Error: VkResult = -1000000000. This is how I close my window:

glfwDestroyWindow(window);
glfwTerminate();

@AidanSun05
Copy link

AidanSun05 commented Aug 27, 2021

@Stanlyhalo From your message I presume you're using GLFW+Vulkan. In that case, there's a lot more cleanup you need to do.

// Cleanup
err = vkDeviceWaitIdle(g_Device);
check_vk_result(err);
ImGui_ImplVulkan_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
CleanupVulkanWindow();
CleanupVulkan();
glfwDestroyWindow(window);
glfwTerminate();

Not sure how to diagnose your "widgets turning black" issue, however. For questions like this, you're really better off submitting a new issue (and inserting the required info + a few shots/GIFs) rather than commenting on an existing one. This makes your question easier to find so we can come and answer, and it may also help future searchers.

Please prefer creating new issues (and referring to this one with a #1542 marker) when reporting bugs or asking questions. This thread is currently too big to be useful.

@saulthu
Copy link

saulthu commented Nov 8, 2021

Is the "Dear ImGui: Sandbox" demo program available? I'm interested in seeing how the 3D view was implemented. I mean the demo in the screenshot.

@ocornut
Copy link
Owner Author

ocornut commented Nov 9, 2021

@0x0015
Copy link

0x0015 commented Dec 6, 2021

Multi viewpoints question: can you get the HWND(or similar) for a sub window using this?

@PathogenDavid
Copy link
Contributor

PathogenDavid commented Dec 6, 2021

@0x0015 It depends on the backend you're using. Why do you want the handle?

@ocornut
Copy link
Owner Author

ocornut commented Dec 6, 2021

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