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

Multiple different inputs are being selected and edited at the same time #5360

Closed
AlexGomezCortes opened this issue May 31, 2022 · 4 comments
Labels
label/id and id stack implicit identifiers, pushid(), id stack

Comments

@AlexGomezCortes
Copy link

Docking branch (but I recall having this issue some years ago as well, using the main branch).

VS compiler

Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp
Operating System: Windows

Multiple inputs are being selected and edited at the same time

First of all, thank you a lot for your time :). I have a vector of (pair <string, std::any>) and I am iterating it in order to draw some inputs (text, float, int, vec3, etc.), and when I try to edit one of them, every of the inputs drawn is selected and edited.

1

This is how it looks when I do not interact with it:

2
3

Code of the loop

// Here's some code anyone can copy and paste to reproduce your issue

for (auto& uniform : uniforms)
	{
		ImGui::SetNextItemWidth(ImGui::GetWindowWidth() / 4.0f);
		ImGui::InputText("", &uniform.first);
		ImGui::SameLine();
		
		if (uniform.second.type() == typeid(int))
		{
			auto& val = std::any_cast<int&>(uniform.second);
			ImGui::InputInt("Value", &val);
			continue;
		}

		if (uniform.second.type() == typeid(float))
		{
			auto& val = std::any_cast<float&>(uniform.second);
			ImGui::InputFloat("Value", &val);
			continue;
		}

		if (uniform.second.type() == typeid(glm::vec4))
		{
			auto& val = std::any_cast<glm::vec4&>(uniform.second);
			ImGui::InputFloat4("Value", &(val.x));
			continue;
		}

		if (uniform.second.type() == typeid(glm::vec3))
		{
			auto& val = std::any_cast<glm::vec3&>(uniform.second);
			ImGui::InputFloat3("Value", &(val.x));
			continue;
		}

		if (uniform.second.type() == typeid(glm::vec2))
		{
			auto& val = std::any_cast<glm::vec2&>(uniform.second);
			ImGui::InputFloat2("Value", &(val.x));
			continue;
		}
	}
@PathogenDavid
Copy link
Contributor

PathogenDavid commented May 31, 2022

Thanks for the detailed report and for filling out the template!

You have a widget ID collision, see this FAQ entry for details.

@ocornut ocornut added the label/id and id stack implicit identifiers, pushid(), id stack label May 31, 2022
@ocornut
Copy link
Owner

ocornut commented May 31, 2022

You'll probably want to use PushID()/PopID() in each loop iteration with the uniform name there (or index if you don't have a name).

@ocornut ocornut closed this as completed May 31, 2022
@AlexGomezCortes
Copy link
Author

Thanks for the detailed report and for filling out the template!

You have a widget ID collision, see this FAQ entry for details.

Thank you for the info!:) I proceeded with what Omar told me on the next comment!

@AlexGomezCortes
Copy link
Author

You'll probably want to use PushID()/PopID() in each loop iteration with the uniform name there (or index if you don't have a name).

Thanks a bunch!

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

3 participants