ocornut / imgui_test_engine

Dear ImGui Automation Engine & Test Suite
382 stars 39 forks source link

How can I click a button in a table column easily #53

Open mgerhardy opened 2 weeks ago

mgerhardy commented 2 weeks ago

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.

ocornut commented 4 days ago

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? I'll try work on something.

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.