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

"Lock" current docked state of window #6780

Closed
paulsammut opened this issue Sep 3, 2023 · 5 comments
Closed

"Lock" current docked state of window #6780

paulsammut opened this issue Sep 3, 2023 · 5 comments
Labels

Comments

@paulsammut
Copy link

paulsammut commented Sep 3, 2023

Version/Branch of Dear ImGui:

Version: 1.89.5
Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp
Compiler:
Operating System: Ubuntu 22.04

My Issue/Question:

Context: I am creating an app that has many windows and I am letting the user figure out best way to dock them. Their docking status and window sizes saved in the imgui.ini file which works great.

The problem is that I'm trying to add a check box which locks the window sizes AND their ability to be undocked.

Q1. To prevent the user from easily/accidentally undocking a window, can I disable this little triangle (or tab bar)?
Q2. Is there a better way to approach this problem? Should I be creating a dockspace and programmatically arranging the windows?

Screenshots/Video
imgui_issue

  ImGui::Begin("Main Window");

  ImGuiDockNodeFlags dFlags = ImGuiDockNodeFlags_None;
  static bool lock = true;
  ImGui::Checkbox("lock panes", &lock);
  if (lock) {
    dFlags |= ImGuiDockNodeFlags_NoResize;
    // Is there a flag that will disable undocking while keeping the current docked state?
  }

  auto dockspaceID = ImGui::GetID("HUB_DockSpace");
  ImGui::DockSpace(dockspaceID, ImVec2(0.0f, 0.0f), dFlags | ImGuiDockNodeFlags_PassthruCentralNode);
  ImGui::SetNextWindowDockID(dockspaceID, ImGuiCond_FirstUseEver);
  ImGui::Begin("Some window 1");
  ImGui::End();
  ImGui::SetNextWindowDockID(dockspaceID, ImGuiCond_FirstUseEver);
  ImGui::Begin("Some window 2");
  ImGui::End();  
  ImGui::SetNextWindowDockID(dockspaceID, ImGuiCond_FirstUseEver);
  ImGui::Begin("Some window 3");
  ImGui::End();

  ImGui::End();
@ocornut ocornut added the docking label Sep 4, 2023
@ocornut
Copy link
Owner

ocornut commented Sep 4, 2023

This is an interesting question, which AFAIK hasn't been asked before in this form, and there's currently no single answer.

I am assuming given your (incomplete) pasted bit that you know of way to apply those dock node flags.
You can either set them inside dock node themselves, or set them via windows.

ImGuiWindowClass window_class;
window_class.DockNodeFlagsOverrideSet = xxxx;
ImGui::SetNextWindowClass(...);

Setting ImGuiDockNodeFlags_NoTabBar will hide the tab-bar which may what you want IF you only have one window at that given location.

However with multiple windows docked in the same spot, using ImGuiDockNodeFlags_NoTabBar would be problematic.

Setting ImGuIWindowFlags_NoMove on an individual window would also effectively prevent undocking.

I think we are missing:

  • A ImGuiDockNodeFlags_NoUndocking or ImGuiDockNodeFlags_LockDocking flag in dock node that would be inherited by their child.
  • Potentially a global toggle to disable user actions without undocking windows.

Also note the io.ConfigDockingWithShift = true option, in case your intention was to avoid accidental undock.
It's hard to know exactly what you need given lack of enough context/details

Should I be creating a dockspace and programmatically arranging the windows?

This would also work but tends to be more tedious and will prevent users from reconfiguring things.

@paulsammut
Copy link
Author

Thanks for the quick reply - I updated my code to be a little more complete.

I tried the io.ConfigDockingWithShift = true option but it does not prevent undocking unless I'm missing something. If it did I'd be more than happy with that solution.

@sonoro1234
Copy link

sonoro1234 commented Sep 13, 2023

Also note the io.ConfigDockingWithShift = true option, in case your intention was to avoid accidental undock.

Shift is necessary for docking but not for undocking with this option.
ImGuiWindowFlags_NoMove seems they way to go.

@ocornut
Copy link
Owner

ocornut commented Sep 18, 2023

I have now added a ImGuiDockNodeFlags_NoUndocking flag which may be used on e.g. a DockSpace() or a programmatically created node to lock its content.

@paulsammut
Copy link
Author

Having shift lock undocking solves my use case. Thank you!

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

3 participants