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

InputText can't keep focus #2116

Closed
TommyThree opened this issue Oct 5, 2018 · 2 comments
Closed

InputText can't keep focus #2116

TommyThree opened this issue Oct 5, 2018 · 2 comments
Labels
label/id and id stack implicit identifiers, pushid(), id stack

Comments

@TommyThree
Copy link

TommyThree commented Oct 5, 2018

I have the code below. I have to hold down the mouse button on the input box to be able to type in it. Otherwise it looks like it gets focus for a second then loses it. What do I do about this?

if (showGameObjects)
		{
			if (ImGui::Begin("Game Ojects", &showGameObjects))
			{
				static int selected = -1;
				for (int i = 0; i < meshList.size(); i++)
				{
					if (ImGui::Selectable(meshList[i].name.c_str(), selected == i))
					{
						selected = i;
						pickedTarget.index = i;

						XMVECTOR s, r, t;
						XMMatrixDecompose(&s, &r, &t, meshList[i].worldMat);
						XMVECTOR dist = XMVector3Length((cam.GetPositionXM() - t));
						XMFLOAT3 dis;
						XMStoreFloat3(&dis, dist);
						pickedTarget.distance = dis.x;
					}
				}


				
				static char buf[64] = "";

				ImGui::InputText("Rename", buf, 64);

				if (ImGui::Button("Rename", ImVec2(120, 30)))
				{
					if (strlen(buf) != 0)
						meshList[pickedTarget.index].name = buf;

				}
@ocornut
Copy link
Owner

ocornut commented Oct 5, 2018

As you have two widgets with the same identifier, maybe the Button() is overriding some properties of the InputText() call. Try to replace the button call with e.g. ImGui::Button("Rename##2", ImVec2(120,30)) and read the FAQ about identifiers and the ID stack.

@TommyThree
Copy link
Author

Yes this was the problem.

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