ocornut/imgui

Should the left or top side resizing be prohibited after the window position is locked?

Opened this issue · 2 comments

o-3-o commented

Version/Branch of Dear ImGui:

Version 1.XX, Branch: XXX (master/docking/etc.)

Back-ends:

imgui_impl_Win32.cpp + imgui_impl_Dx11.cpp

Compiler, OS:

win11+msvc2022

Full config/build information:

Dear ImGui 1.92.4 WIP (19236)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: _WIN32
define: _WIN64
define: _MSC_VER=1944
define: _MSVC_LANG=201402
--------------------------------
io.BackendPlatformName: imgui_impl_win32
io.BackendRendererName: imgui_impl_dx11
io.ConfigFlags: 0x00000003
 NavEnableKeyboard
 NavEnableGamepad
io.ConfigNavCaptureKeyboard
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x0000001E
 HasMouseCursors
 HasSetMousePos
 RendererHasVtxOffset
 RendererHasTextures
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,128
io.Fonts->FontLoaderName: stb_truetype
io.DisplaySize: 1264.00,761.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:

If the position is locked and then the left or upper edge is used to adjust the size, it becomes uncontrollable.

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

        const ImVec2& pos = ImGui::GetMainViewport()->Pos;
        ImGui::SetNextWindowPos(ImVec2{pos.x + 300, pos.y + 300}, ImGuiCond_Always);
        ImGui::Begin("Hello, world!");
        ImGui::End();

Image

But in your example code, the window position is not locked, you just move it back every frame. This creates a feedback loop since a resize in progress doesn't account for you moving the window at the same time. Maybe that could be handled better, f.e. by cancelling the resize if a move is detected or by having an offset to compensate for window movements.

If you want to lock a window into place, you can specify ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize. If you allow resizing, you can technically still move the window by resizing the top and left borders, but that is only because the top left corner is chosen as the (very common, bit still arbitrary) anchor point. One could argue that NoMove should imply NoResize since resizing the bottom or right border "moves" the bottom right corner.

Just out of curiosity: do you have an actual use case for resizable windows where the top left corner is locked into place? Or in general a use case for NoMove without NoResize?

We could pragmatically consider a SetNextWindowPos() to be locking position for the current frame tho, and handle _NoMove too.