17 static std::string searchFilter;
18 if (searchFilter.capacity() < 256)
19 searchFilter.reserve(256);
24 panel.
InputText(
"##HierarchySearch", &searchFilter);
31 auto GetEntityName = [&](entt::entity entity) -> std::string
41 if (searchFilter.empty())
44 return GetEntityName(entity).find(searchFilter) != std::string::npos;
47 static entt::entity entityContextTriggered = entt::null;
48 static bool openEntityContext =
false;
49 static bool openWorkspaceContext =
false;
50 bool anyItemHoveredThisFrame =
false;
52 auto DrawEntityNode = [&](
auto& self, entt::entity entity) ->
void
54 if (entity == entt::null || !registry.valid(entity))
59 entt::entity firstChild = hierarchy
63 bool hasChildren = firstChild != entt::null;
67 bool childMatches =
false;
68 entt::entity child = firstChild;
70 while (child != entt::null)
89 panel.
PushID(
static_cast<int>(entity));
91 bool selected = selectedEntityHandle == entity;
96 opened = panel.
TreeNode(GetEntityName(entity), selected);
99 selectedEntityHandle = entity;
104 if (panel.
Selectable(GetEntityName(entity), selected))
105 selectedEntityHandle = entity;
110 anyItemHoveredThisFrame =
true;
114 selectedEntityHandle = entity;
115 entityContextTriggered = entity;
116 openEntityContext =
true;
124 entt::entity child = firstChild;
125 while (child != entt::null)
142 if (hierarchy.Parent == entt::null)
143 DrawEntityNode(DrawEntityNode, entity);
149 DrawEntityNode(DrawEntityNode, entity);
154 openWorkspaceContext =
true;
157 if (openEntityContext)
159 panel.
OpenPopup(
"HierarchyEntityContext");
160 openEntityContext =
false;
163 if (openWorkspaceContext)
165 panel.
OpenPopup(
"HierarchyWorkspaceContext");
166 openWorkspaceContext =
false;
169 bool entityDestroyed =
false;
170 entt::entity entityToDestroy = entt::null;
172 if (panel.
BeginPopup(
"HierarchyEntityContext"))
174 if (panel.
MenuItem(
"Create Child Entity"))
179 if (panel.
MenuItem(
"Delete Entity"))
181 entityToDestroy = entityContextTriggered;
182 entityDestroyed =
true;
187 if (panel.
BeginPopup(
"HierarchyWorkspaceContext"))
189 if (panel.
MenuItem(
"Create Empty Entity"))
196 if (entityDestroyed && entityToDestroy != entt::null)
199 selectedEntityHandle = entt::null;
200 entityContextTriggered = entt::null;
205 selectedEntityHandle = entt::null;