Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat: Add InspectorPanel for entity component editing

esenginea144d2eff0b5
diff --git a/src/esengine/editor/CMakeLists.txt b/src/esengine/editor/CMakeLists.txt
index cd717bd02..d34486ed6 100644
--- a/src/esengine/editor/CMakeLists.txt
+++ b/src/esengine/editor/CMakeLists.txt
@@ -11,6 +11,7 @@ set(EDITOR_SOURCES
# Panels
panels/HierarchyPanel.cpp
+ panels/InspectorPanel.cpp
)
set(EDITOR_HEADERS
@@ -34,6 +35,7 @@ set(EDITOR_HEADERS
# Panels
panels/HierarchyPanel.hpp
+ panels/InspectorPanel.hpp
)
# Create editor executable
diff --git a/src/esengine/editor/panels/InspectorPanel.cpp b/src/esengine/editor/panels/InspectorPanel.cpp
new file mode 100644
index 000000000..0ca92cc99
--- /dev/null
+++ b/src/esengine/editor/panels/InspectorPanel.cpp
@@ -0,0 +1,194 @@
+/**
+ * @file InspectorPanel.cpp
+ * @brief Inspector panel implementation
+ *
+ * @author ESEngine Team
+ * @date 2026
+ *
+ * @copyright Copyright (c) 2026 ESEngine Team
+ * Licensed under the MIT License.
+ */
+
+#include "InspectorPanel.hpp"
+#include "../../ecs/components/Transform.hpp"
+#include "../../ecs/components/Common.hpp"
+#include "../../math/Math.hpp"
+#include "../../events/Sink.hpp"
+#include "../../core/Log.hpp"
+
+namespace esengine::editor {
+
+// =============================================================================
+// Constructor
+// =============================================================================
+
+InspectorPanel::InspectorPanel(ecs::Registry& registry,
+ EntitySelection& selection,
+ CommandHistory& history)
+ : DockPanel(ui::WidgetId("inspector_panel"), "Inspector"),
+ registry_(registry),
+ selection_(selection),
+ history_(history) {
+
+ auto scrollView = makeUnique<ui::ScrollView>(ui::WidgetId(getId().path + "_scroll"));
+ scrollView_ = scrollView.get();
+ addChild(std::move(scrollView));
+
+ auto content = makeUnique<ui::Panel>(ui::WidgetId(getId().path + "_content"));
+ contentPanel_ = content.get();
+ scrollView_->setContent(std::move(content));
+
+ selection_.addListener([this](const std::vector<Entity>&, const std::vector<Entity>&) {
+ refresh();
+ });
+
+ refresh();
+}
+
+// =============================================================================
+// Public Interface
+// =============================================================================
+
+void InspectorPanel::refresh() {
+ Entity selected = selection_.getFirst();
+
+ if (selected != currentEntity_) {
+ currentEntity_ = selected;
+ rebuildInspector();
+ }
+}
+
+// =============================================================================
+// Widget Interface
+// =============================================================================
+
+void InspectorPanel::render(ui::UIBatchRenderer& renderer) {
+ if (scrollView_) {
+ scrollView_->layout(getBounds());
+ scrollView_->renderTree(renderer);
+ }
+}
+
+// =============================================================================
+// Private Methods
+// =============================================================================
+
+void InspectorPanel::rebuildInspector() {
+ clearInspector();
+
+ if (currentEntity_ == INVALID_ENTITY || !registry_.valid(currentEntity_)) {
+ auto noSelectionLabel = makeUnique<ui::Label>(
+ ui::WidgetId(contentPanel_->getId().path + "_no_selection"));
+ noSelectionLabel->setText("No entity selected");
+ contentPanel_->addChild(std::move(noSelectionLabel));
+ return;
+ }
+
+ if (registry_.has<ecs::Name>(currentEntity_)) {
+ addNameEditor(currentEntity_);
+ }
+
+ if (registry_.has<ecs::LocalTransform>(currentEntity_)) {
+ addLocalTransformEditor(currentEntity_);
+ }
+}
+
+void InspectorPanel::clearInspector() {
+ if (contentPanel_) {
+ contentPanel_->clearChildren();
+ }
+}
+
+void InspectorPanel::addNameEditor(Entity entity) {
+ auto& name = registry_.get<ecs::Name>(entity);
+
+ auto headerLabel = makeUnique<ui::Label>(
+ ui::WidgetId(contentPanel_->getId().path + "_name_header"));
+ headerLabel->setText("Name");
+ contentPanel_->addChild(std::move(headerLabel));
+
+ auto valueLabel = makeUnique<ui::Label>(
+ ui::WidgetId(contentPanel_->getId().path + "_name_value"));
+ valueLabel->setText(name.value);
+ contentPanel_->addChild(std::move(valueLabel));
+}
+
+void InspectorPanel::addLocalTransformEditor(Entity entity) {
+ auto& transform = registry_.get<ecs::LocalTransform>(entity);
+
+ auto headerLabel = makeUnique<ui::Label>(
+ ui::WidgetId(contentPanel_->getId().path + "_transform_header"));
+ headerLabel->setText("Local Transform");
+ contentPanel_->addChild(std::move(headerLabel));
+
+ auto positionEditor = makeUnique<Vector3Editor>(
+ ui::WidgetId(contentPanel_->getId().path + "_position"),
+ "position");
+ positionEditor->setLabel("Position");
+ positionEditor->setValue(transform.position);
+ positionEditor->setCommandHistory(&history_);
+
+ sink(positionEditor->onValueChanged).connect(
+ [this, entity](const std::any& value) {
+ if (registry_.valid(entity) && registry_.has<ecs::LocalTransform>(entity)) {
+ auto& t = registry_.get<ecs::LocalTransform>(entity);
+ try {
+ t.position = std::any_cast<glm::vec3>(value);
+ } catch (const std::bad_any_cast&) {
+ ES_LOG_ERROR("Failed to cast position value");
+ }
+ }
+ }
+ );
+
+ contentPanel_->addChild(std::move(positionEditor));
+
+ glm::vec3 eulerAngles = math::quatToEulerDegrees(transform.rotation);
+
+ auto rotationEditor = makeUnique<Vector3Editor>(
+ ui::WidgetId(contentPanel_->getId().path + "_rotation"),
+ "rotation");
+ rotationEditor->setLabel("Rotation");
+ rotationEditor->setValue(eulerAngles);
+ rotationEditor->setCommandHistory(&history_);
+
+ sink(rotationEditor->onValueChanged).connect(
+ [this, entity](const std::any& value) {
+ if (registry_.valid(entity) && registry_.has<ecs::LocalTransform>(entity)) {
+ auto& t = registry_.get<ecs::LocalTransform>(entity);
+ try {
+ glm::vec3 euler = std::any_cast<glm::vec3>(value);
+ t.rotation = math::eulerDegreesToQuat(euler);
+ } catch (const std::bad_any_cast&) {
+ ES_LOG_ERROR("Failed to cast rotation value");
+ }
+ }
+ }
+ );
+
+ contentPanel_->addChild(std::move(rotationEditor));
+
+ auto scaleEditor = makeUnique<Vector3Editor>(
+ ui::WidgetId(contentPanel_->getId().path + "_scale"),
+ "scale");
+ scaleEditor->setLabel("Scale");
+ scaleEditor->setValue(transform.scale);
+ scaleEditor->setCommandHistory(&history_);
+
+ sink(scaleEditor->onValueChanged).connect(
+ [this, entity](const std::any& value) {
+ if (registry_.valid(entity) && registry_.has<ecs::LocalTransform>(entity)) {
+ auto& t = registry_.get<ecs::LocalTransform>(entity);
+ try {
+ t.scale = std::any_cast<glm::vec3>(value);
+ } catch (const std::bad_any_cast&) {
+ ES_LOG_ERROR("Failed to cast scale value");
+ }
+ }
+ }
+ );
+
+ contentPanel_->addChild(std::move(scaleEditor));
+}
+
+} // namespace esengine::editor
diff --git a/src/esengine/editor/panels/InspectorPanel.hpp b/src/esengine/editor/panels/InspectorPanel.hpp
new file mode 100644
index 000000000..1859260bd
--- /dev/null
+++ b/src/esengine/editor/panels/InspectorPanel.hpp
@@ -0,0 +1,91 @@
+/**
+ * @file InspectorPanel.hpp
+ * @brief Inspector panel for editing entity properties
+ * @details Displays and edits components of the selected entity with undo/redo support.
+ *
+ * @author ESEngine Team
+ * @date 2026
+ *
+ * @copyright Copyright (c) 2026 ESEngine Team
+ * Licensed under the MIT License.
+ */
+#pragma once
+
+// =============================================================================
+// Includes
+// =============================================================================
+
+#include "../../ui/docking/DockPanel.hpp"
+#include "../../ui/widgets/ScrollView.hpp"
+#include "../../ui/widgets/Label.hpp"
+#include "../../ui/widgets/Panel.hpp"
+#include "../../ecs/Registry.hpp"
+#include "../../ecs/Entity.hpp"
+#include "../core/Selection.hpp"
+#include "../command/CommandHistory.hpp"
+#include "../property/editors/Vector3Editor.hpp"
+#include "../../events/Connection.hpp"
+
+namespace esengine::editor {
+
+// =============================================================================
+// InspectorPanel Class
+// =============================================================================
+
+/**
+ * @brief Panel for inspecting and editing entity properties
+ *
+ * @details Shows all components of the selected entity and provides
+ * property editors for each component. Changes are tracked
+ * through CommandHistory for undo/redo support.
+ *
+ * @code
+ * InspectorPanel inspector(registry, selection, history);
+ * // Selection changes trigger automatic refresh
+ * @endcode
+ */
+class InspectorPanel : public ui::DockPanel {
+public:
+ /**
+ * @brief Constructs inspector panel
+ * @param registry Entity registry
+ * @param selection Entity selection manager
+ * @param history Command history for undo/redo
+ */
+ InspectorPanel(ecs::Registry& registry,
+ EntitySelection& selection,
+ CommandHistory& history);
+
+ ~InspectorPanel() override = default;
+
+ /**
+ * @brief Refreshes inspector to show selected entity's components
+ * @details Called automatically when selection changes
+ */
+ void refresh();
+
+ // =========================================================================
+ // Widget Interface
+ // =========================================================================
+
+ void render(ui::UIBatchRenderer& renderer) override;
+
+private:
+ void rebuildInspector();
+ void clearInspector();
+
+ // Component editors
+ void addLocalTransformEditor(Entity entity);
+ void addNameEditor(Entity entity);
+
+ ecs::Registry& registry_;
+ EntitySelection& selection_;
+ CommandHistory& history_;
+
+ ui::ScrollView* scrollView_ = nullptr;
+ ui::Panel* contentPanel_ = nullptr;
+
+ Entity currentEntity_ = INVALID_ENTITY;
+};
+
+} // namespace esengine::editor