File tree 1 file changed +31
-0
lines changed
1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -204,6 +204,37 @@ ctx->RSSetScissorRects(1, &r);
204
204
### Q: How can I have multiple widgets with the same label?
205
205
### Q: How can I have multiple windows with the same label?
206
206
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
+   ;
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
+   ;
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
+
207
238
A primer on labels and the ID Stack...
208
239
209
240
Dear ImGui internally needs to uniquely identify UI elements.
You can’t perform that action at this time.
0 commit comments