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

How to combine a fixed docking layout with floating windows and different WindowClassIDs? #8079

Open
magsell opened this issue Oct 20, 2024 · 0 comments
Labels

Comments

@magsell
Copy link

magsell commented Oct 20, 2024

Version/Branch of Dear ImGui:

Version 1.91.3, Branch: docking

Back-ends:

imgui_impl_opengl3.cpp + imgui_impl_glfw.cpp

Compiler, OS:

Linux + GCC

Full config/build information:

Dear ImGui 1.91.4 WIP (19131)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=201103
define: __linux__
define: __GNUC__=13
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_glfw
io.BackendRendererName: imgui_impl_opengl3
io.ConfigFlags: 0x00000083
 NavEnableKeyboard
 NavEnableGamepad
 DockingEnable
io.ConfigViewportsNoDecoration
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x00001C0E
 HasMouseCursors
 HasSetMousePos
 PlatformHasViewports
 HasMouseHoveredViewport
 RendererHasVtxOffset
 RendererHasViewports
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,64
io.DisplaySize: 1280.00,720.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
Dear ImGui 1.91.4 WIP (19131)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=201103
define: __linux__
define: __GNUC__=13
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_glfw
io.BackendRendererName: imgui_impl_opengl3
io.ConfigFlags: 0x00000083
 NavEnableKeyboard
 NavEnableGamepad
 DockingEnable
io.ConfigViewportsNoDecoration
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x00001C0E
 HasMouseCursors
 HasSetMousePos
 PlatformHasViewports
 HasMouseHoveredViewport
 RendererHasVtxOffset
 RendererHasViewports
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,64
io.DisplaySize: 1280.00,720.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:

I created a fixed window layout using the dock builder API
with three docking nodes and each docking node contains a
non-movable and non-collapsible window.
Screenshot from 2024-10-20 16-38-22

I want to use the WindowClassID because I read in another
issue that only windows with the same ID can be docked.

Each window belongs to its own window class:

  • ModelWindow: WindowClassID = 1
  • LogWindow: WindowClassID = 2
  • SceneWindow: WindowClassID = 3

I want docking to work only with windows that belong to the
same window class. For example, Window1 and Window2
have WindowClassID = 3 and docking should only work with
SceneWindow but I can only dock Window1 and Window2.

Thank you for your help!

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

    ImGuiViewport* viewport = ImGui::GetMainViewport();
    // ========================================================================
    // CREATE FIXED DOCKING LAYOUT
    // ========================================================================
    {
      constexpr ImGuiDockNodeFlags dock_space_flags = ImGuiDockNodeFlags_PassthruCentralNode;

      ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
      ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
      
      ImGuiWindowFlags dock_window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking |
                                           ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse |
                                           ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove |
                                           ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus |
                                           ImGuiWindowFlags_NoBackground;

      ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));

      ImGui::SetNextWindowPos(viewport->Pos);
      ImGui::SetNextWindowSize(viewport->Size);
      ImGui::SetNextWindowViewport(viewport->ID);
      if (ImGui::Begin("DockSpace", nullptr, dock_window_flags))
      {
        const ImGuiID dock_space_id = ImGui::GetID("MyDockSpace");
        ImGui::DockSpace(dock_space_id, ImVec2(0.0f, 0.0f), dock_space_flags);

        static bool dockspace_initialized = false;
        if (!dockspace_initialized)
        {
          ImGui::DockBuilderRemoveNode(dock_space_id);
          ImGui::DockBuilderAddNode(dock_space_id, dock_space_flags | ImGuiDockNodeFlags_DockSpace);
          ImGui::DockBuilderSetNodeSize(dock_space_id, viewport->Size);

          ImGuiID dock_scene_id = dock_space_id;
          const ImGuiID dock_model_id = ImGui::DockBuilderSplitNode(dock_scene_id, ImGuiDir_Left, 0.2f, nullptr, &dock_scene_id);
          const ImGuiID dock_log_id = ImGui::DockBuilderSplitNode(dock_scene_id, ImGuiDir_Down, 0.2f, nullptr, &dock_scene_id);

          ImGui::DockBuilderDockWindow("ModelWindow", dock_model_id);
          ImGui::DockBuilderDockWindow("SceneWindow", dock_scene_id);
          ImGui::DockBuilderDockWindow("LogWindow", dock_log_id);

          ImGui::DockBuilderFinish(dock_space_id);
          dockspace_initialized = true;
        }
      }
      ImGui::End();
      ImGui::PopStyleVar(3);
    }
    // ========================================================================
    // DRAW MODEL-WINDOW
    // ========================================================================
    {
      ImGui::SetNextWindowClass(&models_window_class);  // models_window_class is defined with  WindowClassID = 1
      const ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove;
      if (ImGui::Begin("ModelWindow", nullptr, window_flags)) {
        ...
      }
      ImGui::End();
    }
    // ========================================================================
    // DRAW LOG-WINDOW
    // ========================================================================
    {
      ImGui::SetNextWindowClass(&log_window_class);  // log_window_class is defined with  WindowClassID = 2
      const ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize |
                                            ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove;
      if (ImGui::Begin("LogWindow", nullptr, window_flags)) {
        ...
      }
      ImGui::End();
    }
    // ========================================================================
    // DRAW SCENE-WINDOW
    // ========================================================================
    {
      const ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse |
                                            ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove;
      ImGui::SetNextWindowClass(&scenes_window_class);  // scenes_window_class is defined with  WindowClassID = 3
      if (ImGui::Begin("SceneWindow", nullptr, window_flags)) {
        ...
      }
      ImGui::End();
    }
    // ========================================================================
    // DRAW WINDOW1
    // ========================================================================
    {
      ImGui::SetNextWindowClass(&scene_window_class);  // scene_window_class is defined with  WindowClassID = 3
      const ImGuiWindowFlags window_flags = 0;
      if (ImGui::Begin("Window1", nullptr, window_flags)) {
        ...
      }
      ImGui::End();
    }
    // ========================================================================
    // DRAW WINDOW2
    // ========================================================================
    {
      ImGui::SetNextWindowClass(&scene_window_class);
      const ImGuiWindowFlags window_flags = 0;
      if (ImGui::Begin("Window2", nullptr, window_flags)){
        ...
      }
      ImGui::End();
    }
@magsell magsell changed the title How to combine a fixed docking layout with floating windows and different window classes? How to combine a fixed docking layout with floating windows and different WindowClassIDs? Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants