1

I would like to create a nested tree view ui component using ImGui. The result would look like this:

enter image description here

This is the code needed in order to create the nesting of Selectable() elements like so:

enter image description here

void imgui_nested_tree() {
    bool is_expanded = ImGui::TreeNodeExV( (void*)nullptr, ImGuiTreeNodeFlags_FramePadding, "", nullptr);
    ImGui::SameLine();
    ImGui::Selectable("outer selectable", false); 
    if (is_expanded) {
        bool is_expanded = ImGui::TreeNodeExV( (void*)nullptr, ImGuiTreeNodeFlags_FramePadding, "", nullptr);
        ImGui::SameLine();
        ImGui::Selectable("inner1 selectable", false);
        if (is_expanded) {
            // and so on...
        }
    }
}

This code also makes the little arrow and the Selectable independently clickable which is great. It means I can fire events when clicking on the Selectable next to the arrow:

enter image description here

Since it's easy to make a mistake when manually coding it this way, I figured I would use recursion to deal with creating those nesting elements. How would you do this?

tadman
  • 208,517
  • 23
  • 234
  • 262
mbl
  • 805
  • 11
  • 18
  • Please don't tag C++ code as C. – tadman Jun 23 '20 at 02:22
  • imgui has c bindings – mbl Jun 23 '20 at 02:23
  • 1
    Maybe it has Python and VB.Net bindings, too, that's irrelevant here. Your code is C++, that's all that matters. People looking for C++ questions to answer will find this and can help. People looking for C questions will find C++ code, which is a waste of their time. – tadman Jun 23 '20 at 02:23

0 Answers0