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

Push/PopID() for PopUps? #747

Closed
adcox opened this issue Jul 22, 2016 · 14 comments
Closed

Push/PopID() for PopUps? #747

adcox opened this issue Jul 22, 2016 · 14 comments
Labels
enhancement label/id and id stack implicit identifiers, pushid(), id stack popups question

Comments

@adcox
Copy link

adcox commented Jul 22, 2016

Is there a way to specify a unique ID for a popup that isn't a child of a window, i.e., is not between Begin() and End()? In my application, I have several instances of a class that creates a popup window when clicked. Since there are multiple instances, I need to specify a unique ID for each; I tried using PushID(this) and PopID, but then a default window object is created... I can work around by creating a hidden window and then creating the popup "within" the hidden window, but I'm curious to know if there's another/better way uniquely identify widgets outside of windows.

@ocornut
Copy link
Owner

ocornut commented Jul 22, 2016

You can form a string with a unique identifier behind ## and use that. Awkward but works.

BeginChild() has a overload taking ImGuiID but not BeginPopup(). Also there's currently quite some confusion with the childs id which I would like to sort out before making any hasty change such as adding the equivalent overload in BeginPopup(). Also see #331

@ocornut
Copy link
Owner

ocornut commented Aug 16, 2017

@adcox I just came back to this and realized my answer wasn't really useful (as you already had figured out you could build up identifiers).

Two things:

  • There was no reason for PushID()/PopID() to mark parent window as written to, so I just fixed and it won't make the "Debug" window appear if you call it outside of a Begin/End block, so you can construct your unique string there.

  • As a workaround you could have directly used ImHash() from imgui_internal.h as well, or just made up any unique value (just hoping it wouldn't collide with the existing crc32 used!).

  • I am working on exposing a popup API that only uses ID (without strings) so it'll be easier to do that without creating unique strings. If you look at the current code for BeginPopup it is essentially mostly doing that:

    return BeginPopupEx(g.CurrentWindow->GetID(str_id), ImGuiWindowFlags_ShowBorders);

(But exposing those isn't as trivial as one would expect, because the popup code is reliant on the popup stack/order, and those underlying function always assume the ID is at the current popup stack level.)

@ocornut ocornut closed this as completed Aug 16, 2017
@Someguynamedpie
Copy link

Someguynamedpie commented Oct 6, 2017

I'd like this to be resolved; maybe have FindWindowByName()/CreateNewWindow use the ID stack? Or use the pointer provided as an additional source for calculating the window ID

@adcox
Copy link
Author

adcox commented Oct 6, 2017

@ocornut I'm no longer a developer on the project that was using imgui and it's been far too long... I can't make any intelligent comments on this issue anymore. Thanks for the additional feedback, though!

@Someguynamedpie
Copy link

I was going to create a new issue but just decided to bump this existing one since it was relevant to what I needed

@ocornut
Copy link
Owner

ocornut commented Oct 6, 2017

@Someguynamedpie Afaik the problem described by the original poster was fixed (see above). Could you describe your problem and use case? There's always a Debug window pushed in the stack and so you can always call GetID(). You can also use ImHash().

@Someguynamedpie
Copy link

Someguynamedpie commented Oct 6, 2017

It's possible I misunderstood the original question; I call Begin() twice with both windows having the same name, so it thinks I'm trying to use the existing window when in reality I'm trying to create a new window with the same name.
Edit: I've worked around the issue for now, but it'd still be a nice feature to have down the line (I'm currently combining the immediate mode philosophy with a class based system to get the best of both worlds)

@ocornut
Copy link
Owner

ocornut commented Oct 9, 2017

@Someguynamedpie: Calling Begin() twice with the same identifier appends to the window.
You can use the ## and ### operators (see FAQ and Examples: Manipulating Window Title) if you want to have multiple windows with a same "visible" title.

@Someguynamedpie
Copy link

I know about the ## operators, but I'd prefer not to do that for performance and extensibility reasons, hence why it'd be nice to have PushID work on them.

@ocornut
Copy link
Owner

ocornut commented Oct 9, 2017 via email

@Someguynamedpie
Copy link

Because I'd need to sprintf every frame for every unique window and know ahead of time the max buffer size to house the pointer to the object (or a unique ID nonetheless); what kind limitations would the id stack impose on Begin if you don't mind me asking?

@ocornut
Copy link
Owner

ocornut commented Oct 10, 2017 via email

@Someguynamedpie
Copy link

If I didn't have any user generated content it wouldn't be a big issue because yeah I could just use a static buffer.

@ocornut
Copy link
Owner

ocornut commented Oct 10, 2017

Just include the hash of your content after the ### marker.

@ocornut ocornut added the label/id and id stack implicit identifiers, pushid(), id stack label Apr 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement label/id and id stack implicit identifiers, pushid(), id stack popups question
Projects
None yet
Development

No branches or pull requests

3 participants