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

Multiple ID Error on Button Behavior #8030

Closed
Zaryob opened this issue Sep 30, 2024 · 4 comments
Closed

Multiple ID Error on Button Behavior #8030

Zaryob opened this issue Sep 30, 2024 · 4 comments
Labels
bug doc label/id and id stack implicit identifiers, pushid(), id stack overlap

Comments

@Zaryob
Copy link

Zaryob commented Sep 30, 2024

Version/Branch of Dear ImGui:

Branch: docking, Commit: 7937732

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 d1ea03b.
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:

  • When I assigned different IDs with GetID, right click did not work
  • I defined left click and right click simultaneously and then used IsMouseClicked to detect whether it is right or left, but it did not work)

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
Copy link
Owner

ocornut commented Sep 30, 2024

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 ocornut added the label/id and id stack implicit identifiers, pushid(), id stack label Sep 30, 2024
@ocornut
Copy link
Owner

ocornut commented Sep 30, 2024

You can surround this block of code with:

PushItemFlag(ImGuiItemFlags_AllowDuplicateId, true);
ButtonBehavior(...)
ButtonBehavior(...)
PopItemFlag();

@ocornut ocornut added the bug label Sep 30, 2024
@Zaryob
Copy link
Author

Zaryob commented Sep 30, 2024

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.

@ocornut
Copy link
Owner

ocornut commented Oct 3, 2024

I have investigated this and deemed that it was a legit case where a false positive would be emitted.
I have pushed various references to it in 3d399bc

@ocornut ocornut closed this as completed Oct 3, 2024
@ocornut ocornut added the doc label Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug doc label/id and id stack implicit identifiers, pushid(), id stack overlap
Projects
None yet
Development

No branches or pull requests

2 participants