ImGuiTreeNodeFlags_DefaultOpen=1<<5,// Default node to be open
ImGuiTreeNodeFlags_OpenOnDoubleClick=1<<6,// Need double-click to open node
ImGuiTreeNodeFlags_OpenOnArrow=1<<7,// Only open when clicking on the arrow part. If ImGuiTreeNodeFlags_OpenOnDoubleClick is also set, single-click arrow or double-click all box to open.
ImGuiTreeNodeFlags_AlwaysOpen=1<<8,// No collapsing, no arrow (use as a convenience for leaf nodes).
//ImGuiTreeNodeFlags_UnindentArrow = 1 << 9, // FIXME: TODO: Unindent tree so that Label is aligned to current X position
//ImGuITreeNodeFlags_SpanAllAvailWidth = 1 << 10, // FIXME: TODO: Extend hit box horizontally even if not framed
//ImGuiTreeNodeFlags_NoScrollOnOpen = 1 << 11, // FIXME: TODO: Automatically scroll on TreePop() if node got just open and contents is not visible
ImGuiTreeNodeFlags_Leaf=1<<8,// No collapsing, no arrow (use as a convenience for leaf nodes).
ImGuiTreeNodeFlags_Bullet=1<<9,// Display a bullet instead of arrow
//ImGuiTreeNodeFlags_UnindentArrow = 1 << 10, // FIXME: TODO: Unindent tree so that Label is aligned to current X position
//ImGuITreeNodeFlags_SpanAllAvailWidth = 1 << 11, // FIXME: TODO: Extend hit box horizontally even if not framed
//ImGuiTreeNodeFlags_NoScrollOnOpen = 1 << 12, // FIXME: TODO: Automatically scroll on TreePop() if node got just open and contents is not visible
ShowHelpMarker("Click to select, CTRL+Click to toggle, click on arrows to open");
staticintselection_mask=0x02;// Dumb representation of what may be user-side selection state. You may carry selection state inside or outside your objects in whatever format you see fit.
intnode_clicked=-1;
ShowHelpMarker("This is a more standard looking tree with selectable nodes.\nClick to select, CTRL+Click to toggle, click on arrows or double-click to open.");
ImGui::PushStyleVar(ImGuiStyleVar_IndentSpacing,ImGui::GetFontSize()*3);// Increase spacing to differentiate leaves from expanded contents.
staticintselection_mask=(1<<2);// Dumb representation of what may be user-side selection state. You may carry selection state inside or outside your objects in whatever format you see fit.
intnode_clicked=-1;// Temporary storage of what node we have clicked to process selection at the end of the loop. May be a pointer to your own node type, etc.
for(inti=0;i<6;i++)
{
// Disable the default open on single-click behavior and pass in Selected flag according to our selection state.
// Leaf: Here we use the ImGuiTreeNodeFlags_Leaf functionality + ImGuiTreeNodeFlags_NoTreePushOnOpen to avoid testing return value and doing a TreePop
// The only reason we have a TreeNode at all is to allow selection of the leaf. Otherwise we can use BulletText() or a simple Text() element offset by GetTreeNodeToLabelSpacing()
// Update selection state. Process outside of tree loop to avoid visual inconsistencies during the clicking-frame.
if(ImGui::GetIO().KeyCtrl)
selection_mask^=(1<<node_clicked);// CTRL+click to toggle
elseif(!(selection_mask&(1<<node_clicked)))// If there is already a selection don't replace we clicked node is part of it
else//if (!(selection_mask & (1 << node_clicked))) // Depending on selection behavior you want, this commented bit preserve selection when clicking on item that is part of the selection
selection_mask=(1<<node_clicked);// Click to single-select