Files
sophia/editor/panels/scene_hierarchy_panel.cpp
T
2026-09-25 22:59:01 -07:00

33 lines
990 B
C++

#include "scene_hierarchy_panel.hpp"
#include <imgui.h>
#include <sophia/components.hpp>
void SceneHierarchyPanel::onUpdate(const sophia::FrameInfo&) {
if (ImGui::Button("+ Sprite")) {
selected = scene.createEntity("Sprite");
selected.addComponent<sophia::SpriteComponent>();
}
ImGui::Separator();
// Flat for now: there is no parent/child component yet.
scene.forEachEntity([this](sophia::Entity entity) {
ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_Leaf |
ImGuiTreeNodeFlags_NoTreePushOnOpen |
ImGuiTreeNodeFlags_SpanAvailWidth;
if (entity == selected) {
flags |= ImGuiTreeNodeFlags_Selected;
}
const std::string& name = entity.getComponent<sophia::TagComponent>().tag;
ImGui::PushID(static_cast<int>(static_cast<sophia::u32>(entity)));
ImGui::TreeNodeEx(name.c_str(), flags);
if (ImGui::IsItemClicked()) {
selected = entity;
}
ImGui::PopID();
});
}