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

Input fields do not keep focus when used in tables #5729

Closed
danbrown3 opened this issue Sep 28, 2022 · 4 comments
Closed

Input fields do not keep focus when used in tables #5729

danbrown3 opened this issue Sep 28, 2022 · 4 comments
Labels
label/id and id stack implicit identifiers, pushid(), id stack

Comments

@danbrown3
Copy link

Version/Branch of Dear ImGui:

Version: v1.85
Branch: Not sure

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_win32.cpp
Operating System: Windows

My Issue/Question:

When using inputs in a table (I tested with InputInt), the text field does not keep focus in between frames.

Standalone, minimal, complete and verifiable example: (see #2261)

const int numCols = 3;
static ImGuiTableFlags flags = ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg;
if (ImGui::BeginTable("TrackerTable", numCols, flags))
{
	ImGui::TableSetupColumn("Title", ImGuiTableColumnFlags_WidthFixed);
	ImGui::TableSetupColumn("Tracking Type", ImGuiTableColumnFlags_WidthFixed);
	ImGui::TableSetupColumn("Current Value", ImGuiTableColumnFlags_WidthFixed, 100);

	ImGui::TableHeadersRow();

	for (auto& myThing : m_myThings)
	{
		ImGui::TableNextRow();
		ImGui::TableNextColumn();

		//Title
		ImGui::Text("%s", myThing.title);
		ImGui::TableNextColumn();
		
		//Tracking Type
		ImGui::Text("Int");
		ImGui::TableNextColumn();

		//Current Value
		ImGui::InputInt("", &myThing.intVal);
		ImGui::TableNextColumn();
	}

	ImGui::EndTable();
}
@ocornut
Copy link
Owner

ocornut commented Sep 28, 2022

@ocornut ocornut closed this as completed Sep 28, 2022
@ocornut ocornut added the label/id and id stack implicit identifiers, pushid(), id stack label Sep 28, 2022
@danbrown3
Copy link
Author

Well, there's nothing in that FAQ about text field focus, but I'm guessing you are trying to imply that the focus bug is caused by an ID clash. Would have appreciated something better than RTFM, but I'll give that a try and get back to you.

@danbrown3
Copy link
Author

Yes, giving each input a custom ID does fix the problem.

@ocornut
Copy link
Owner

ocornut commented Sep 28, 2022

Generally speaking if you have a loop you’d want to use PushID(index) or another variant in your loop body, if you want to use same name.

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