Imgui: Why do childs have _<id hash> appended in their name?

Created on 26 Mar 2018  路  7Comments  路  Source: ocornut/imgui

(not an issue, more of a question)

Just noticed named child windows are windows called "/_".

Why is the hexa representation of the id (window->GetID(str_id)) required at the child window name? Isn't parent_name/child_name enough? (Why?)

bug labeid and id stack

All 7 comments

(I get it on the anonymous child case)

Good question @franciscod, I looked into it and the commit history and couldn't find any valid reason for doing that, so I changed it. Thanks!

Wheeeee, glad I asked it :D You're welcome!

I think the ID hash might be necessary for child windows to respect the ID stack. Consider the following example:

for (int i = 0; i < 4; ++i)
{
    ImGui::PushID(i);
    ImGui::BeginChild("foo", ImVec2(100, 100), true);
    ImGui::Text("bar %d", i);
    ImGui::EndChild();
    ImGui::PopID();
}

I'd expect that to create four separate child windows, since although the child windows share a name they are each in their own ID scope. Instead, currently* the above code comes out like this:
image

If I revert 84fbc49 then it looks like I'd expect:
image

Is my expectation of how this code should behave wrong, or is the original code actually useful after all?

*I'm currently on revision d69b2a1 (v1.63 WIP from 1st August 2018), but I don't think this particular code has changed since then from a quick look.

Thanks @jadwallis.
You are right and this is indeed a breaking change.
I think the change _might_ be acceptable as is however, because you can always use BeginChild(GetID("blah")...); if you need the unique ID scope.

Additionally, there are two other documentation issues:

  • The change was documented as part of 1.53 where in reality it was part of 1.60 (it was a mistake when I added the line in the Changelog).
  • If it stays as such (give me some time to think about it and decide) it should be documented as a breaking change in 1.60.

@jadwallis I have now undoed the change done in 84fbc4940, it was an error on my part. Thanks for pointing it out. The change was explicitly introduced in 1.50 (see #894, #713) and accidentally reverted following the discussion on this thread. It should now be fixed again. My bad!

Thanks @ocornut! :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mnemode2 picture mnemode2  路  3Comments

spaderthomas picture spaderthomas  路  3Comments

BlackWatersInc picture BlackWatersInc  路  3Comments

bogdaNNNN1 picture bogdaNNNN1  路  3Comments

ghost picture ghost  路  3Comments