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

ImageButton does not responds to click in certain situations #4471

Closed
alexgg-developer opened this issue Aug 24, 2021 · 3 comments
Closed

ImageButton does not responds to click in certain situations #4471

alexgg-developer opened this issue Aug 24, 2021 · 3 comments
Labels
label/id and id stack implicit identifiers, pushid(), id stack

Comments

@alexgg-developer
Copy link

Dear ImGui 1.84 WIP (18309)
--------------------------------
sizeof(size_t): 4, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: _WIN32
define: _MSC_VER=1916
define: _MSVC_LANG=201402
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_glfw
io.BackendRendererName: imgui_impl_vulkan
io.ConfigFlags: 0x00000441
 NavEnableKeyboard
 DockingEnable
 ViewportsEnable
io.ConfigViewportsNoDecoration
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x0000140E
 HasMouseCursors
 HasSetMousePos
 PlatformHasViewports
 RendererHasVtxOffset
 RendererHasViewports
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,64
io.DisplaySize: 1600.00,900.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

My Issue/Question:

We have an application to manage meshes and materials in scenes. We show the hirarchy of the scene in a docked window and a sort of tree widget we had using the old column system. We noticed that with scenes with several meshes (50+) sometimes buttons to hide/lock the mesh did not work in this docked window even though it did not happen anywhere else. I thought maybe it was time to upgrade so I passed the column system to the tree widget system in the new version but keeps happening. It's not a problem with code because it just simply that you click some buttons and it returns false. The buttons are Imgui::ImageButton.
I could not reproduce writing a simple example but I will upload it just in case you want to see the structure of the gui that is more or less the same.

While I was writing the example I remembered the ImGui::IsItemClicked function, and when I use it after the ImageButton it responds correctly to my click so that is the workaround I'm using right now, but I thought it would be useful to inform about the issue.

Screenshots/Video

2021-08-20.08-58-02.mp4

Standalone, minimal, complete and verifiable example: (see #2261)

imgui-docking.zip

@ocornut ocornut added the label/id and id stack implicit identifiers, pushid(), id stack label Aug 24, 2021
@ocornut
Copy link
Owner

ocornut commented Aug 24, 2021

sometimes buttons to hide/lock the mesh did not work in this docked window

You likely have an ID conflict.
https://github.com/ocornut/imgui/blob/master/docs/FAQ.md#q-why-is-my-widget-not-reacting-when-i-click-on-it

There is a known flaw with ImageButton(), it is using the provided ImTextureID an ID into the ID stack. I should have made that ID explicit. So it is possible that you simply have an ID conflict between your button.
In Metrics you can check the value for HoveredID and confirm what the ID is over your different buttons.

You can surround your ImageButton() calls with PushID/PopID() calls, or use ImageButtonEx()
See #2464

@alexgg-developer
Copy link
Author

Thank you for your answer.
I was already using PushID but I was appending my id wrongly to the string and it didn't make unique IDs as you pointed out, so it seems that was the problem.

ocornut added a commit that referenced this issue Aug 3, 2022
…d' parameter + removed 'int frame_padding = -1' parameter. (#5533, #4471, #2464, #1390).

Also removed frame_padding parameter from ImageButtonEx(), amend e0ec69d.
kjblanchard pushed a commit to kjblanchard/imgui that referenced this issue May 5, 2023
…d' parameter + removed 'int frame_padding = -1' parameter. (ocornut#5533, ocornut#4471, ocornut#2464, ocornut#1390).

Also removed frame_padding parameter from ImageButtonEx(), amend e0ec69d.
@ocornut
Copy link
Owner

ocornut commented Aug 22, 2024

FYI the old ImageButton() entry point which was made obsolete on Aug 3, 2022, has now been commented out.

For reference:

#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
// Legacy API obsoleted in 1.89. Two differences with new ImageButton()
// - old ImageButton() used ImTextureId as item id (created issue with multiple buttons with same image, transient texture id values, opaque computation of ID)
// - new ImageButton() requires an explicit 'const char* str_id'
// - old ImageButton() had frame_padding' override argument.
// - new ImageButton() always use style.FramePadding.
bool ImGui::ImageButton(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, int frame_padding, const ImVec4& bg_col, const ImVec4& tint_col)
{
    // Default to using texture ID as ID. User can still push string/integer prefixes.
    PushID((void*)(intptr_t)user_texture_id);
    if (frame_padding >= 0)
        PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2((float)frame_padding, (float)frame_padding));
    bool ret = ImageButton("", user_texture_id, size, uv0, uv1, bg_col, tint_col);
    if (frame_padding >= 0)
        PopStyleVar();
    PopID();
    return ret;
}
#endif // #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
label/id and id stack implicit identifiers, pushid(), id stack
Projects
None yet
Development

No branches or pull requests

2 participants