From f0912833ba92f7ee55582318d04935621995b68a Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 14 May 2024 14:09:46 +0200 Subject: [PATCH] Update FAQ.md (#7581) --- docs/FAQ.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/docs/FAQ.md b/docs/FAQ.md index 095cb2aa2..9c7df2334 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -204,6 +204,37 @@ ctx->RSSetScissorRects(1, &r); ### Q: How can I have multiple widgets with the same label? ### Q: How can I have multiple windows with the same label? +**USING THE SAME LABEL+ID IS THE MOST COMMON USER MISTAKE:** + + + + + +
+
+ImGui::Begin("Incorrect!");
+ImGui::DragFloat2("My value", &objects[0]->pos.x);
+ImGui::DragFloat2("My value", &objects[1]->pos.x);
+ImGui::DragFloat2("My value", &objects[2]->pos.x);
+ImGui::End();
+ 
+ImGui::Begin("Correct!");
+ImGui::DragFloat2("My value", &objects[0]->pos.x);
+ImGui::DragFloat2("My value##2", &objects[1]->pos.x);
+ImGui::DragFloat2("My value##3", &objects[2]->pos.x);
+ImGui::End();
+ 
+ImGui::Begin("Also Correct!");
+for (int n = 0; n < 3; n++)
+{
+    ImGui::PushID(n);
+    ImGui::DragFloat2("My value", &objects[n]->pos.x);
+    ImGui::PopID();
+}
+ImGui::End();
+
+
+ A primer on labels and the ID Stack... Dear ImGui internally needs to uniquely identify UI elements.