Refine inspector layout and fix header labels

This commit is contained in:
2026-03-26 15:26:46 +08:00
parent 733b573963
commit 491fef940d
2 changed files with 29 additions and 23 deletions

View File

@@ -44,7 +44,7 @@ void InspectorPanel::RenderEntity(Entity* entity) {
void InspectorPanel::RenderComponent(Component* component) {
if (!component) return;
const char* name = component->GetName().c_str();
const std::string name = component->GetName();
std::string headerId = name + std::string("##") + std::to_string(reinterpret_cast<uintptr_t>(component));

View File

@@ -30,7 +30,9 @@ void InspectorPanel::OnSelectionChanged(const SelectionChangedEvent& event) {
}
void InspectorPanel::Render() {
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
ImGui::Begin(m_name.c_str(), nullptr, ImGuiWindowFlags_None);
ImGui::PopStyleVar();
if (!m_selectionHandlerId && m_context) {
m_selectionHandlerId = m_context->GetEventBus().Subscribe<SelectionChangedEvent>(
@@ -48,41 +50,43 @@ void InspectorPanel::Render() {
if (gameObject) {
RenderGameObject(gameObject);
} else {
ImGui::SetCursorPos(ImVec2(10.0f, 10.0f));
ImGui::Text("Object not found");
}
} else {
ImGui::Text("No object selected");
ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 1.0f), "Select an object in Hierarchy");
ImGui::SetCursorPos(ImVec2(10.0f, 10.0f));
ImGui::Text("No Selection");
ImGui::SetCursorPos(ImVec2(10.0f, 30.0f));
ImGui::TextColored(ImVec4(0.55f, 0.55f, 0.55f, 1.0f), "Select an object in Hierarchy");
}
ImGui::End();
}
void InspectorPanel::RenderGameObject(::XCEngine::Components::GameObject* gameObject) {
char nameBuffer[256];
strcpy_s(nameBuffer, gameObject->GetName().c_str());
ImGui::InputText("##Name", nameBuffer, sizeof(nameBuffer));
if (ImGui::IsItemDeactivatedAfterEdit()) {
UndoUtils::ExecuteSceneCommand(*m_context, "Rename Entity", [&]() {
m_context->GetSceneManager().RenameEntity(gameObject->GetID(), nameBuffer);
});
}
ImGuiStyle& style = ImGui::GetStyle();
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10.0f, 0.0f));
ImGui::BeginChild("InspectorContent", ImVec2(0.0f, 0.0f), false, ImGuiWindowFlags_None);
ImGui::PopStyleVar();
ImGui::SameLine();
if (ImGui::Button("Add Component")) {
ImGui::OpenPopup("AddComponent");
}
RenderAddComponentPopup(gameObject);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(style.ItemSpacing.x, 0.0f));
auto components = gameObject->GetComponents<::XCEngine::Components::Component>();
for (auto* component : components) {
RenderComponent(component, gameObject);
}
if (ImGui::Button("Add Component", ImVec2(-1.0f, 0.0f))) {
ImGui::OpenPopup("AddComponent");
}
RenderAddComponentPopup(gameObject);
ImGui::PopStyleVar();
if (m_context->GetUndoManager().HasPendingInteractiveChange() && !ImGui::IsAnyItemActive()) {
m_context->GetUndoManager().FinalizeInteractiveChange();
}
ImGui::EndChild();
}
void InspectorPanel::RenderAddComponentPopup(::XCEngine::Components::GameObject* gameObject) {
@@ -136,10 +140,12 @@ void InspectorPanel::RenderComponent(::XCEngine::Components::Component* componen
if (!component) return;
IComponentEditor* editor = ComponentEditorRegistry::Get().FindEditor(component);
ImGuiStyle& style = ImGui::GetStyle();
const char* name = component->GetName().c_str();
const std::string name = component->GetName();
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{4, 2});
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{6, 4});
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(style.ItemSpacing.x, 0.0f));
ImGuiTreeNodeFlags flags =
ImGuiTreeNodeFlags_DefaultOpen |
@@ -148,9 +154,9 @@ void InspectorPanel::RenderComponent(::XCEngine::Components::Component* componen
ImGuiTreeNodeFlags_FramePadding |
ImGuiTreeNodeFlags_AllowOverlap;
bool open = ImGui::TreeNodeEx((void*)typeid(*component).hash_code(), flags, "%s", name);
bool open = ImGui::TreeNodeEx((void*)typeid(*component).hash_code(), flags, "%s", name.c_str());
ImGui::PopStyleVar();
ImGui::PopStyleVar(2);
bool removeComponent = false;
const bool canRemoveComponent = editor ? editor->CanRemove(component) : false;