I would like to create a nested tree view ui component using ImGui. The result would look like this:
This is the code needed in order to create the nesting of Selectable()
elements like so:
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:
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?