ImGuiNET / ImGui.NET

An ImGui wrapper for .NET.
MIT License
1.85k stars 300 forks source link

Consecutive ImageButtons don't react as expected on mouse click #51

Closed monsieurmax closed 6 years ago

monsieurmax commented 6 years ago

Hello,

first, many thanks for providing us this great lib. second, a disclaimer. I'm not totally sure to know the origin of this issue and it could most likely be me.

I'm using ImGui.net 0.4.3 with Monogame 3.7, and compiled 1.53 versions of imgui and cimgui. I'm running an old 4.6.2 Mono, on Ubuntu.

I have an unexpected behavior with ImageButtons. If I add multiple buttons consecutively, in a child frame, only the first one actually return true when clicked. The other ones are actually showing imgui change of style when hovered and clicked, but they still return false when clicked.

I made a quick piece of code inside "SubmitImguiStuff()" to reproduce the issue and to ensure that it was not from my existing UIs , something like : `int imagecount = 4;

        for (int i = 0; i < imagecount; i++)

        {

            if (ImGui.ImageButton(new IntPtr(0), new SVector2(25,25), SVector2.Zero, SVector2.One,2, SVector4.Zero, SVector4.One ))

            {

                _pressImageCount += 1;

            }

            if(i<imagecount-1) ImGui.SameLine();

        }

        ImGui.Text($"Image Buttons pressed {_pressImageCount} times.", new SVector4(0, 1, 1, 1));`

( using font atlas as a texture image, Svectors are shortcuot for System.Numerics.Vectors )

Any idea would be greatly appreciated.

Thanks in advance. Best regards.

Jjagg commented 6 years ago

@monsieurmac See ocornut/imgui#813. This is a flaw in the Dear ImGui API, not a bug in the wrapper.

mellinoe commented 6 years ago

As mentioned in the linked issue, you can use PushID / PopID to force each image to have a unique ID.

Hi-ImKyle commented 5 years ago

PushID & PopID does not fix this issue

monsieurmax commented 5 years ago

It did work for me, using version 0.4.7.