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

ImGui::SetItemKeyOwner does not work on images #8453

Open
nasiratif opened this issue Mar 3, 2025 · 1 comment
Open

ImGui::SetItemKeyOwner does not work on images #8453

nasiratif opened this issue Mar 3, 2025 · 1 comment
Labels

Comments

@nasiratif
Copy link

Version/Branch of Dear ImGui:

Version 1.91.8, Branch: master

Back-ends:

imgui_impl_win32.cpp + imgui_impl_dx9.cpp

Compiler, OS:

WIndows 11 + MSVC 2022

Full config/build information:

Dear ImGui 1.91.8 (19180)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: _WIN32
define: _WIN64
define: _MSC_VER=1941
define: _MSVC_LANG=201402
--------------------------------
io.BackendPlatformName: imgui_impl_win32
io.BackendRendererName: imgui_impl_dx9
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,64
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:

I haven't tested other keys, but If you use ImGui::SetItemKeyOwner(ImGuiKey_MouseWheelY) on Images, it doesn't work as you can still scroll on the window.

I needed to do this because in my project I'm writing a 2D animation editor where you can preview the image and zoom in/out, but I can't have the window scroll along with the image.

The only thing I've tried was calling SetItemKeyOwner before Image, but that of course did not fix the problem.

Screenshots/Video:

Image

Minimal, Complete and Verifiable Example code:

ImGui::Begin("Hello, world!");

ImGui::Button("Scrolling doesn't work on this button as expected:");
ImGui::SetItemKeyOwner(ImGuiKey_MouseWheelY);

ImGui::Text("But scrolling still works on this image:");
ImGui::Image(0, ImVec2(128, 128));
ImGui::SetItemKeyOwner(ImGuiKey_MouseWheelY);

ImGui::End();
@cfillion
Copy link
Contributor

cfillion commented Mar 3, 2025

Images, like text, don't have an item ID (0). You can use ImGui::ImageButton instead to create an interactive item for SetItemKeyOwner to act upon.

ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {0, 0});
ImGui::ImageButton("foo", 0, {128, 128});
ImGui::PopStyleVar();
ImGui::SetItemKeyOwner(ImGuiKey_MouseWheelY);

@ocornut ocornut added the inputs label Mar 3, 2025
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