Skip to content

Commit f091283

Browse files
authored
Update FAQ.md (#7581)
1 parent ac90e1b commit f091283

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

docs/FAQ.md

+31
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,37 @@ ctx->RSSetScissorRects(1, &r);
204204
### Q: How can I have multiple widgets with the same label?
205205
### Q: How can I have multiple windows with the same label?
206206

207+
**USING THE SAME LABEL+ID IS THE MOST COMMON USER MISTAKE:**
208+
<table>
209+
<tr>
210+
<td><img src="https://github.com/ocornut/imgui/assets/8225057/76eb9467-74d1-4e95-9f56-be81c6dd029d"></td>
211+
<td>
212+
<pre lang="cpp">
213+
ImGui::Begin("Incorrect!");
214+
ImGui::DragFloat2("My value", &objects[0]->pos.x);
215+
ImGui::DragFloat2("My value", &objects[1]->pos.x);
216+
ImGui::DragFloat2("My value", &objects[2]->pos.x);
217+
ImGui::End();
218+
&nbsp;
219+
ImGui::Begin("Correct!");
220+
ImGui::DragFloat2("My value", &objects[0]->pos.x);
221+
ImGui::DragFloat2("My value##2", &objects[1]->pos.x);
222+
ImGui::DragFloat2("My value##3", &objects[2]->pos.x);
223+
ImGui::End();
224+
&nbsp;
225+
ImGui::Begin("Also Correct!");
226+
for (int n = 0; n < 3; n++)
227+
{
228+
ImGui::PushID(n);
229+
ImGui::DragFloat2("My value", &objects[n]->pos.x);
230+
ImGui::PopID();
231+
}
232+
ImGui::End();
233+
</pre>
234+
</td>
235+
</tr>
236+
</table>
237+
207238
A primer on labels and the ID Stack...
208239

209240
Dear ImGui internally needs to uniquely identify UI elements.

0 commit comments

Comments
 (0)