Skip to content

Accessing IDs in different states, and passing an explicit ID into ImageButton() #1390

@JaminGrey

Description

@JaminGrey

I have four ImageButtons(), and they popup a Modal popup when clicked.
It is possible for two or more four ImageButton()'s to share the same image.

Because the imageID is used as their ID, if they share the same image then they can't be clicked.
So I wrap them in a PushID() unique to each button.
But because they are now in an inner PushID(), they can't call the popup modal by ID, because it's in a different ID stack-frame.

My solution is to wrap them, but call outside of them:
ImGuiID backgroundSelectionPopup = ImGui::GetCurrentContext()->CurrentWindow->GetID(BackgroundSelectionPopup);

I then, in the inner PushID() stack-frame, call ImGui::OpenPopupEx(backgroundSelectionPopup, false); myself when the buttons are clicked.

This works fine, but feels hackish. Works fine for me in the present, though, so no complaints #here.

I think I read that you are already considering how to make IDs callable from different stack-frames, so I'm just presenting my scenario as a real-world use-case. I would also suggest making an overload of ImageButton() that takes an explicit ID.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions