#53
How can I click a button in a table column easily
I can see that I have to access a child if the table has a scrollbar, and no child if there is no scrollbar. Is there maybe a helper to hide this fact that I've just not yet seen?
if (ImGui::BeginTable("##someid", 2, ImGuiTableFlags_Resizable | ImGuiTableFlags_NoSavedSettings | ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY)) {
ImGui::TableSetupColumn("Col1");
ImGui::TableSetupColumn("Col2");
ImGui::TableHeadersRow();
{ // here the for loop
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGuiTreeNodeFlags treeFlags = ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_SpanAllColumns | ImGuiTreeNodeFlags_SpanAvailWidth;
if (ImGui::TreeNodeEx("treenode", treeFlags)) {
if (ImGui::Button("Button1")) {
// do something
}
ImGui::TreePop();
}
}
ImGui::EndTable();
}I could use ctx->WindowInfo() - but as far as I can see this would only work if the table has the scrolling activated.
Activity
2FYI this is working and has always worked:
t = IM_REGISTER_TEST(e, "testengine", "testengine_ref_tables");
t->GuiFunc = [](ImGuiTestContext* ctx)
{
ImGui::Begin("Test Window", NULL, ImGuiWindowFlags_AlwaysAutoResize);
if (ImGui::BeginTable("Table1", 2, ImGuiTableFlags_NoSavedSettings | ImGuiTableFlags_Borders))
{
ImGui::TableNextColumn();
ImGui::Button("Button1");
ImGui::EndTable();
}
if (ImGui::BeginTable("Table2", 2, ImGuiTableFlags_NoSavedSettings | ImGuiTableFlags_Borders | ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY, ImVec2(0.0f, 100.0f)))
{
ImGui::TableNextColumn();
ImGui::Button("Button2");
ImGui::EndTable();
}
ImGui::End();
};
t->TestFunc = [](ImGuiTestContext* ctx)
{
ctx->SetRef("Test Window");
ctx->ItemClick("Table1/Button1");
ctx->ItemClick("Table2/Button2");
ctx->SetRef("Test Window/Table1");
ctx->ItemClick("Button1");
ctx->SetRef("Test Window/Table2");
ctx->ItemClick("Button2");
};The first table doesn't use a child window, the second one does. But as both push a same ID in the stack it works transparently.
So looking at this again I'm not sure I understand the problem. In fact, my answer misleadingly suggested there was a problem but I don't see it now.
I don't have a great solution to I would like to improve child name/id logic to facilitate this, toward a way where "parent/table" could be the same ID regardless of whether the table has a child window or not. That, or TestEngine would do iterative lookups on each item of a path.
Note that you can use the "**/Button1" syntax to find an item in child windows, which can be used as a workaround to infer the parent window.