changes for ImGui
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
#include "ecs_inspector_panel.hpp"
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
#include <sophia/components.hpp>
|
||||
|
||||
namespace sophia {
|
||||
|
||||
void EcsInspectorPanel::onUpdate(const FrameInfo&) {
|
||||
ImGui::Begin("ECS Inspector");
|
||||
|
||||
entityScratch.clear();
|
||||
for (entt::entity entity : registry.storage<entt::entity>()) {
|
||||
entityScratch.push_back(entity);
|
||||
}
|
||||
|
||||
ImGui::BeginChild("EntityList", ImVec2(0, 200), true);
|
||||
ImGuiListClipper clipper;
|
||||
clipper.Begin(static_cast<int>(entityScratch.size()));
|
||||
while (clipper.Step()) {
|
||||
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
|
||||
entt::entity entity = entityScratch[static_cast<size_t>(i)];
|
||||
const TagComponent* tag = registry.try_get<TagComponent>(entity);
|
||||
std::string label = tag ? tag->tag : "Entity";
|
||||
|
||||
ImGui::PushID(static_cast<int>(entt::to_integral(entity)));
|
||||
if (ImGui::Selectable(label.c_str(), selected == entity)) {
|
||||
selected = entity;
|
||||
}
|
||||
ImGui::PopID();
|
||||
}
|
||||
}
|
||||
ImGui::EndChild();
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
if (registry.valid(selected)) {
|
||||
if (auto* transform = registry.try_get<TransformComponent>(selected)) {
|
||||
ImGui::DragFloat3("Position", &transform->position.x, 0.1f);
|
||||
ImGui::DragFloat3("Scale", &transform->scale.x, 0.1f);
|
||||
ImGui::Text("Rotation: %.2f, %.2f, %.2f, %.2f", transform->rotation.w,
|
||||
transform->rotation.x, transform->rotation.y,
|
||||
transform->rotation.z);
|
||||
}
|
||||
|
||||
if (auto* mesh = registry.try_get<MeshComponent>(selected)) {
|
||||
ImGui::Text("Mesh: index=%u generation=%u", mesh->handle.index,
|
||||
mesh->handle.generation);
|
||||
}
|
||||
} else {
|
||||
ImGui::TextDisabled("No entity selected");
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
} // namespace sophia
|
||||
Reference in New Issue
Block a user