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

How can I use "PushID()" to identify different window ? #6046

Closed
ChivenZhang opened this issue Jan 5, 2023 · 1 comment
Closed

How can I use "PushID()" to identify different window ? #6046

ChivenZhang opened this issue Jan 5, 2023 · 1 comment
Labels
label/id and id stack implicit identifiers, pushid(), id stack

Comments

@ChivenZhang
Copy link

ChivenZhang commented Jan 5, 2023

Hello, I want to use PushID() instead of "##ID" label to identify different windows, but when I create two window in this way, there is only one window all the time. So how can I achieve this ? Thanks.
Codes below shows what I want to do.

{
	static bool visible1 = true;
	if (visible1)
	{
		ImGui::PushID(111);
		ImGui::SetNextWindowSize(ImVec2(500, 500), ImGuiCond_Appearing);
		if (ImGui::Begin("WIN", &visible1))
		{
		}
		ImGui::End();
		ImGui::PopID();
	}
}

{
	static bool visible1 = true;
	if (visible1)
	{
		ImGui::PushID(222);
		ImGui::SetNextWindowSize(ImVec2(500, 500), ImGuiCond_Appearing);
		if (ImGui::Begin("WIN", &visible1))
		{
		}
		ImGui::End();
		ImGui::PopID();
	}
}
@ocornut
Copy link
Owner

ocornut commented Jan 5, 2023

Window names are not affected by the ID stack.
You can generate a window name that include some hash/value derived from the ID stack though:

ImGui::PushID(111);
sprintf(“window_%08x”, ImGui::GetID(“”));
ImGui::PopID();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
label/id and id stack implicit identifiers, pushid(), id stack
Projects
None yet
Development

No branches or pull requests

2 participants