ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
59.86k stars 10.18k forks source link

Multiple ID Error on Button Behavior #8030

Open Zaryob opened 2 days ago

Zaryob commented 2 days ago

Version/Branch of Dear ImGui:

Branch: docking, Commit: 793773209bb0fdeb8ccb756052e770457193c9f2

Back-ends:

imgui_impl_opengl3.cpp

Compiler, OS:

macOS + Clang 12, GCC, Windows + MSVC

Full config/build information:

No response

Details:

My Issue/Question:

Hi,

I was getting the click behavior using two ButtonBehavior(), one left click (with ImGuiButtonFlags_MouseButtonLeft flag) and one right click (with ImGuiButtonFlags_MouseButtonRight flag).

bool mouseClicked = ImGui::ButtonBehavior(ImRect(fftAreaMin, wfMax), GetID("WaterfallID"), &mouseHovered, &mouseHeld,
                                                  ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_PressedOnClick);

        bool mouseRClicked = ImGui::ButtonBehavior(ImRect(fftAreaMin, wfMax), GetID("WaterfallID"), &mouseHovered, &mouseHeld,
                                                  ImGuiButtonFlags_MouseButtonRight | ImGuiButtonFlags_PressedOnClick);

However, I get the following image with the io.ConfigDebugDetectIdConflicts added since commit number d1ea03b872c1de31ab4c0167cf959dffe947cbeb.

Screenshot 2024-09-30 at 20 31 12

Here I have a basic situation and two questions.

I think the io.ConfigDebugDetectIdConflicts parameter is not implemented because it is still in development. Therefore I cannot close this error ("Unless I patch it manually"). Will it be added???

Secondly, I use two ButtonBehaviour's to achieve this behavior. I tried different ways:

So, how can I encourage with this issue?

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

It is fork of SDRPlusPlus of AlexandreRouma,

Code is on https://github.com/Zaryob/SDRPlusPlus

ocornut commented 2 days ago

bool mouseClicked = ImGui::ButtonBehavior(ImRect(fftAreaMin, wfMax), GetID("WaterfallID"), &mouseHovered, &mouseHeld, ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_PressedOnClick); bool mouseRClicked = ImGui::ButtonBehavior(ImRect(fftAreaMin, wfMax), GetID("WaterfallID"), &mouseHovered, &mouseHeld, ImGuiButtonFlags_MouseButtonRight | ImGuiButtonFlags_PressedOnClick);

That's an interesting use case. I think it this specific case indeed did work before (even if it should be illegal). I will investigate this.

I think you can use single button with both ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight and then checking which mouse button was clicked or released? This should work.

ocornut commented 2 days ago

You can surround this block of code with:

PushItemFlag(ImGuiItemFlags_AllowDuplicateId, true);
ButtonBehavior(...)
ButtonBehavior(...)
PopItemFlag();
Zaryob commented 2 days ago

bool mouseClicked = ImGui::ButtonBehavior(ImRect(fftAreaMin, wfMax), GetID("WaterfallID"), &mouseHovered, &mouseHeld, ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_PressedOnClick); bool mouseRClicked = ImGui::ButtonBehavior(ImRect(fftAreaMin, wfMax), GetID("WaterfallID"), &mouseHovered, &mouseHeld, ImGuiButtonFlags_MouseButtonRight | ImGuiButtonFlags_PressedOnClick);

That's an interesting use case. I think it this specific case indeed did work before (even if it should be illegal). I will investigate this.

I think you can use single button with both ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight and then checking which mouse button was clicked or released? This should work.

It legally fixed like this:

bool mouseClicked = ImGui::ButtonBehavior(ImRect(fftAreaMin, wfMax), GetID("WaterfallID"), &mouseHovered, &mouseHeld,
                                                  ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight | ImGuiButtonFlags_PressedOnClick);

It gathers if mouseClicked and then;

if (mouseClicked && !targetFound) {

    if (IsMouseClicked(ImGuiMouseButton_Right)) {
          ......
    }  
    else {
          ......
    }
}

It solved my problem but if you consider to investigate, Issue can be open remain.