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

Add a flag to disable clamping windows to viewport bounds, for use with a pannable virtual space #8301

Open
bratpilz opened this issue Jan 9, 2025 · 0 comments

Comments

@bratpilz
Copy link

bratpilz commented Jan 9, 2025

Version/Branch of Dear ImGui:

Version v1.91.7 WIP, Branch: master

Back-ends:

imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp

Compiler, OS:

Linux + GCC 12

Full config/build information:

Dear ImGui 1.91.7 WIP (19164)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=201103
define: __linux__
define: __GNUC__=12
--------------------------------
io.BackendPlatformName: imgui_impl_glfw
io.BackendRendererName: imgui_impl_opengl3
io.ConfigFlags: 0x00000003
 NavEnableKeyboard
 NavEnableGamepad
io.ConfigNavCaptureKeyboard
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x0000000E
 HasMouseCursors
 HasSetMousePos
 RendererHasVtxOffset
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,128
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'm using a pannable virtual space for my application, basically being able to place windows within a larger virtual viewport than the viewport of the OS window and then being able to move the currently shown portion around with a minimap similar to the one under Viewports->Window Minimap in the metrics window. The way I have implemented this is to move the positions of all my windows when I change which part I'm viewing. This works nicely, the only trouble I've run into is that somewhere in Begin(), the position of each window gets clamped so that it is at least partially within the viewport bounds. This leads to any window not currently within the shown portion of my pannable space to have its position changed when I just need it to stay where it is for my use case.

I have currently added the new flag ImGuiConfigFlags_DoNotClampWindows to work around this. The full patch is as follows:

diff --git a/imgui.cpp b/imgui.cpp
index c783450c0..4db27d3ba 100644
--- a/imgui.cpp
+++ b/imgui.cpp
@@ -7843,7 +7843,10 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
         {
             if (!window->ViewportOwned && viewport_rect.GetWidth() > 0 && viewport_rect.GetHeight() > 0.0f)
             {
-                ClampWindowPos(window, visibility_rect);
+	      if (!(g.IO.ConfigFlags & ImGuiConfigFlags_DoNotClampWindows))
+	      {
+		  ClampWindowPos(window, visibility_rect);
+	      }
             }
             else if (window->ViewportOwned && g.PlatformIO.Monitors.Size > 0)
             {
diff --git a/imgui.h b/imgui.h
index ba5fd518c..1f2c26e6f 100644
--- a/imgui.h
+++ b/imgui.h
@@ -1659,6 +1659,9 @@ enum ImGuiConfigFlags_
     ImGuiConfigFlags_IsSRGB                 = 1 << 20,  // Application is SRGB-aware.
     ImGuiConfigFlags_IsTouchScreen          = 1 << 21,  // Application is using a touch screen instead of a mouse.
 
+    // Virtual area for window placement
+    ImGuiConfigFlags_DoNotClampWindows      = 1 << 30,  // Allow windows to be dragged out of viewport bounds.
+
 #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
     ImGuiConfigFlags_NavEnableSetMousePos   = 1 << 2,   // [moved/renamed in 1.91.4] -> use bool io.ConfigNavMoveSetMousePos
     ImGuiConfigFlags_NavNoCaptureKeyboard   = 1 << 3,   // [moved/renamed in 1.91.4] -> use bool io.ConfigNavCaptureKeyboard

If something like this could be merged into the code, that would make things easier for me. Of course the flag's value should probably not be 1 << 30 then.

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

No response

@ocornut ocornut changed the title Feature request: Add a flag to disable clamping windows to viewport bounds, for use with a pannable virtual space Add a flag to disable clamping windows to viewport bounds, for use with a pannable virtual space Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant