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

Demo Property Editor ID Conflict / Fix Separates Table #8266

Open
moritz-h opened this issue Dec 27, 2024 · 0 comments
Open

Demo Property Editor ID Conflict / Fix Separates Table #8266

moritz-h opened this issue Dec 27, 2024 · 0 comments
Labels

Comments

@moritz-h
Copy link
Contributor

Version/Branch of Dear ImGui:

v1.91.6-docking

Back-ends:

imgui_impl_opengl3.cpp + imgui_impl_glfw.cpp

Compiler, OS:

Windows 11 + MSVC 2022

Full config/build information:

No response

Details:

My Issue/Question:

This issue is about two things, but fixing the first leads to the second problem.

The first is, the demo property editor is maybe missing a PushID/PopID() call. This can be seen when adding a InputText to the example. The attached code adds a InputText to edit the name of the property.
Now changing the name in the InputText and then imediately clicking onto an other node changes also the name of the second node. I think this happens due to the InputText always having the exact same ID, so I would guess this could be seen as ID conflict.
To solve this I added PushID() / PopID() calls pushing the node pointer to the ID stack, so every property widget ID is unique across all nodes. (This is commented out in the example below).

But unfortunately this also creates a new ID for the table of every node, so state isn't shared anymore between the tables of each node. So, e.g., resizing the property editor table on one node is not global anymore but purely for that specific node. I have found other issues suggesting PushOverrideID to globally share table state, but then also the ID will be the same for all widgets inside the table and I'm back to the first issue above.

Is there some way to globally share table state (e.g. using PushOverrideID) only for the table itself but keep the original ID stack inside the table? Or as alternative, I only require the resize state, is the column width somehow bindable to an external variable to be shared between tables?

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

Patch for imgui_demo.cpp @ v1.91.6-docking

diff --git a/imgui_demo.cpp b/imgui_demo.cpp
index 3ec30279..27e7192b 100644
--- a/imgui_demo.cpp
+++ b/imgui_demo.cpp
@@ -303,6 +303,7 @@ struct ExampleMemberInfo
 // Metadata description of ExampleTreeNode struct.
 static const ExampleMemberInfo ExampleTreeNodeMemberInfos[]
 {
+    { "MyName",     -1,                    1, offsetof(ExampleTreeNode, Name) },
     { "MyBool",     ImGuiDataType_Bool,    1, offsetof(ExampleTreeNode, DataMyBool) },
     { "MyInt",      ImGuiDataType_S32,     1, offsetof(ExampleTreeNode, DataMyInt) },
     { "MyVec2",     ImGuiDataType_Float,   2, offsetof(ExampleTreeNode, DataMyVec2) },
@@ -9044,6 +9045,7 @@ struct ExampleAppPropertyEditor
         ImGui::BeginGroup(); // Lock X position
         if (ExampleTreeNode* node = VisibleNode)
         {
+            //ImGui::PushID(node); // Uncomment to fix
             ImGui::Text("%s", node->Name);
             ImGui::TextDisabled("UID: 0x%08X", node->UID);
             ImGui::Separator();
@@ -9087,12 +9089,17 @@ struct ExampleAppPropertyEditor
                             ImGui::SliderScalarN("##Editor", field_desc.DataType, field_ptr, field_desc.DataCount, &v_min, &v_max);
                             break;
                         }
+                        case -1:
+                        {
+                            ImGui::InputText("##Editor", reinterpret_cast<char*>(field_ptr), 28);
+                        }
                         }
                         ImGui::PopID();
                     }
                 }
                 ImGui::EndTable();
             }
+            //ImGui::PopID(); // Uncomment to fix
         }
         ImGui::EndGroup();
     }
@ocornut ocornut added the demo label Dec 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants