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

Question regarding using BeginChild() EndChild() to reenter windows context #3006

Closed
turmansky opened this issue Jan 29, 2020 · 5 comments
Closed

Comments

@turmansky
Copy link

Version/Branch of Dear ImGui:

Version:1.74
Branch: Master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_Opengl3.cpp + imgui_impl_glfw.cpp _
Compiler: VS2015
Operating System: Win7/10

Question
We are upgrading from v1.65 to v1.74 and ran into an issue re reentring child windows to append more UI elements as described in "tips - BeginChild()/ EndChild" to put ourselves into the window context at different parts of our app. We basically do a first pass where the splitters for our app are setup from a config file at startup and names/ paths of child windows are saved. Then on the second pass areas that have GUI controls are drawn by re-entering the context with the BeginChild/ EndChild method using the names from the first pass
The issue is that 1.74 has a name change in BeginChildEx() where a ImGuiId is now appended to the name so our technique of saving the name at the first pass breaks as the Id generated on second pass is different splitter setup as the hashing seed is probably different.
We see a comment in the Imgui.cpp file that says to use the BeginChild(Id) option with a stable value to append to same child from multiple locations in the stack.
So absolute name is just a hex code in this code and all the ID's are generated by us before calling any BeginChild() calls ?
Just wanted to verify that this is the preferred way consistent with your design philosophy

@turmansky
Copy link
Author

If we roll the naming convention back to the old way in BeginChildEx() everything works fine
if (name) {
//ImFormatString(title, IM_ARRAYSIZE(title), "%s/%s_%08X", parent_window->Name, name, id);
ImFormatString(title, IM_ARRAYSIZE(title), "%s/%s", parent_window->Name, name);
} else

@ocornut
Copy link
Owner

ocornut commented Jan 29, 2020

Hello,

If you need to be apprending from different ID stack locations, just compute your ID once with ImGui::GetID() and then call ImGui::BeginChild(ImGuiID id, ... instead of ImGui::BeginChild(const char* str_id ? I am not sure what is the problem here?

If we roll the naming convention back to the old way in BeginChildEx() everything works fine

But that was incorrect in the first place so we are not going to revert to that.

@turmansky
Copy link
Author

Thanks. We just wanted confirmation that we were going down the right path of generating the ID externally and modifying the code

@turmansky
Copy link
Author

Closed

@ocornut
Copy link
Owner

ocornut commented Jan 29, 2020

(To clarify, you should NOT modify imgui.cpp at all.)

The bug you accidentally relied on was fixed in 1.66:

BeginChild(): Fixed BeginChild(const char*, ...) variation erroneously not applying the ID stack to the provided string to uniquely identify the child window. This was undoing an intentional change introduced in 1.50 and broken in 1.60. (#1698, #894, #713).

Any const char* label or const char* str_id parameter is using top of the ID stack has a hashing seed and this was a bug introduced in 1.60.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants