Skip to main content
Tree nodes and selectables are used to display hierarchical data and allow users to make selections. These widgets are essential for file browsers, scene graphs, and selection lists.

Tree Nodes

TreeNode()

Create a collapsible tree node:
TreeNode() returns true when the node is open. Always call TreePop() after displaying the node contents, even if you early-out.

TreeNodeEx()

Tree node with advanced flags:

Tree Node Flags

Opening Behavior

Visual Flags

Leaf Nodes

Selection

Hierarchy Lines

Draw connecting lines between tree nodes:
flag
No hierarchy lines
flag
Draw lines for the full height
flag
Draw lines only to node labels

Collapsing Headers

CollapsingHeader()

A tree node that doesn’t require TreePop():

Tree Control

SetNextItemOpen()

Set the open state of the next tree node:

Selectables

Selectable()

Create a selectable item:
bool
Current selection state (read-only)
bool*
Selection state pointer (read-write, automatically toggled)

Selectable Flags

Selectables with Additional Content

Selectables in Tables

Complete Example

Best Practices

Always call TreePop() after TreeNode() returns true, even if you return early from the function.
Use CollapsingHeader() instead of TreeNode() when you don’t need to nest content and want cleaner code.
For large trees, consider using ImGuiListClipper to only display visible items and improve performance.