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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat: Add docking system for panel management
esengine14f836ef024a
diff --git a/CMakeLists.txt b/CMakeLists.txtindex faa624430..6fe7ba86d 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -45,6 +45,13 @@ set(ESENGINE_SOURCESsrc/esengine/ui/widgets/Panel.cppsrc/esengine/ui/widgets/Label.cppsrc/esengine/ui/widgets/Button.cpp+ # Docking System+ src/esengine/ui/docking/DockNode.cpp+ src/esengine/ui/docking/DockPanel.cpp+ src/esengine/ui/docking/DockTabBar.cpp+ src/esengine/ui/docking/DockZone.cpp+ src/esengine/ui/docking/DockArea.cpp+ src/esengine/ui/docking/DockLayoutSerializer.cpp)set(ESENGINE_HEADERS@@ -100,6 +107,15 @@ set(ESENGINE_HEADERSsrc/esengine/ui/widgets/Panel.hppsrc/esengine/ui/widgets/Label.hppsrc/esengine/ui/widgets/Button.hpp+ # Docking System+ src/esengine/ui/docking/DockTypes.hpp+ src/esengine/ui/docking/DockNode.hpp+ src/esengine/ui/docking/DockPanel.hpp+ src/esengine/ui/docking/DockTabBar.hpp+ src/esengine/ui/docking/DockZone.hpp+ src/esengine/ui/docking/DockArea.hpp+ src/esengine/ui/docking/DockEvents.hpp+ src/esengine/ui/docking/DockLayoutSerializer.hpp)# Platform-specific sourcesdiff --git a/src/esengine/ui/core/Theme.hpp b/src/esengine/ui/core/Theme.hppindex 3ebceb766..c57b8fd74 100644--- a/src/esengine/ui/core/Theme.hpp+++ b/src/esengine/ui/core/Theme.hpp@@ -38,6 +38,7 @@ struct ThemeColors {// Background colorsglm::vec4 background{0.15f, 0.15f, 0.15f, 1.0f};glm::vec4 backgroundDark{0.10f, 0.10f, 0.10f, 1.0f};+ glm::vec4 backgroundMedium{0.17f, 0.17f, 0.17f, 1.0f};glm::vec4 backgroundLight{0.20f, 0.20f, 0.20f, 1.0f};glm::vec4 surface{0.18f, 0.18f, 0.18f, 1.0f};glm::vec4 surfaceHover{0.22f, 0.22f, 0.22f, 1.0f};@@ -84,6 +85,17 @@ struct ThemeColors {// Shadow/overlayglm::vec4 shadow{0.0f, 0.0f, 0.0f, 0.5f};glm::vec4 overlay{0.0f, 0.0f, 0.0f, 0.6f};++ // Docking colors+ glm::vec4 dockTabBackground{0.12f, 0.12f, 0.12f, 1.0f};+ glm::vec4 dockTabHover{0.18f, 0.18f, 0.18f, 1.0f};+ glm::vec4 dockTabActive{0.20f, 0.20f, 0.20f, 1.0f};+ glm::vec4 dockTabIndicator{0.26f, 0.59f, 0.98f, 1.0f};+ glm::vec4 dockSplitter{0.20f, 0.20f, 0.20f, 1.0f};+ glm::vec4 dockSplitterHover{0.26f, 0.59f, 0.98f, 1.0f};+ glm::vec4 dockDropPreview{0.26f, 0.59f, 0.98f, 0.30f};+ glm::vec4 dockZoneButton{0.30f, 0.30f, 0.30f, 0.90f};+ glm::vec4 dockZoneButtonHover{0.26f, 0.59f, 0.98f, 1.0f};};// =============================================================================@@ -116,6 +128,19 @@ struct ThemeSpacing {f32 scrollbarWidth = 12.0f;f32 scrollbarMinThumb = 32.0f;++ // Docking spacing+ f32 dockTabHeight = 24.0f;+ f32 dockTabMinWidth = 80.0f;+ f32 dockTabMaxWidth = 200.0f;+ f32 dockTabPadding = 8.0f;+ f32 dockTabSpacing = 1.0f;+ f32 dockTabCloseSize = 14.0f;+ f32 dockSplitterSize = 4.0f;+ f32 dockZoneSize = 32.0f;+ f32 dockZoneGap = 4.0f;+ f32 dockDropPreviewAlpha = 0.30f;+ f32 dockEdgeThreshold = 0.30f;};// =============================================================================@@ -307,6 +332,85 @@ public:return style;}+ // =========================================================================+ // Docking Styles+ // =========================================================================++ /** @brief Gets the style for a dock tab bar background */+ WidgetStyle getDockTabBarStyle() const {+ WidgetStyle style;+ style.backgroundColor = colors.dockTabBackground;+ style.backgroundColorHover = colors.dockTabBackground;+ style.backgroundColorPressed = colors.dockTabBackground;+ style.padding = Insets{0.0f, spacing.dockTabPadding, 0.0f, spacing.dockTabPadding};+ return style;+ }++ /** @brief Gets the style for an inactive dock tab */+ WidgetStyle getDockTabStyle() const {+ WidgetStyle style;+ style.backgroundColor = colors.dockTabBackground;+ style.backgroundColorHover = colors.dockTabHover;+ style.backgroundColorPressed = colors.dockTabActive;+ style.textColor = colors.textSecondary;+ style.textColorDisabled = colors.textDisabled;+ style.padding = Insets::symmetric(spacing.dockTabPadding, spacing.sm);+ style.fontSize = typography.fontSizeSmall;+ return style;+ }++ /** @brief Gets the style for an active dock tab */+ WidgetStyle getDockTabActiveStyle() const {+ WidgetStyle style = getDockTabStyle();+ style.backgroundColor = colors.dockTabActive;+ style.backgroundColorHover = colors.dockTabActive;+ style.textColor = colors.textPrimary;+ style.borderColor = colors.dockTabIndicator;+ style.borderWidth = 2.0f;+ return style;+ }++ /** @brief Gets the style for the dock splitter */+ WidgetStyle getDockSplitterStyle() const {+ WidgetStyle style;+ style.backgroundColor = colors.dockSplitter;+ style.backgroundColorHover = colors.dockSplitterHover;+ style.backgroundColorPressed = colors.dockSplitterHover;+ return style;+ }++ /** @brief Gets the style for dock zone indicator buttons */+ WidgetStyle getDockZoneButtonStyle() const {+ WidgetStyle style;+ style.backgroundColor = colors.dockZoneButton;+ style.backgroundColorHover = colors.dockZoneButtonHover;+ style.backgroundColorPressed = colors.dockZoneButtonHover;+ style.textColor = colors.textSecondary;+ style.borderColor = colors.accent;+ style.borderWidth = 1.0f;+ style.cornerRadii = CornerRadii::all(4.0f);+ return style;+ }++ /** @brief Gets the style for dock drop preview overlay */+ WidgetStyle getDockDropPreviewStyle() const {+ WidgetStyle style;+ style.backgroundColor = colors.dockDropPreview;+ style.backgroundColorHover = colors.dockDropPreview;+ return style;+ }++ /** @brief Gets the style for dock panel content area */+ WidgetStyle getDockPanelStyle() const {+ WidgetStyle style;+ style.backgroundColor = colors.background;+ style.backgroundColorHover = colors.background;+ style.borderColor = colors.border;+ style.borderWidth = 0.0f;+ style.padding = Insets::all(spacing.panelPadding);+ return style;+ }+private:void initDark() {// Colors are already initialized to dark theme defaults@@ -316,6 +420,7 @@ private:// Override with light theme colorscolors.background = {0.95f, 0.95f, 0.95f, 1.0f};colors.backgroundDark = {0.90f, 0.90f, 0.90f, 1.0f};+ colors.backgroundMedium = {0.93f, 0.93f, 0.93f, 1.0f};colors.backgroundLight = {1.0f, 1.0f, 1.0f, 1.0f};colors.surface = {1.0f, 1.0f, 1.0f, 1.0f};colors.surfaceHover = {0.98f, 0.98f, 0.98f, 1.0f};@@ -346,6 +451,15 @@ private:colors.shadow = {0.0f, 0.0f, 0.0f, 0.15f};colors.overlay = {0.0f, 0.0f, 0.0f, 0.3f};++ // Light theme docking colors+ colors.dockTabBackground = {0.92f, 0.92f, 0.92f, 1.0f};+ colors.dockTabHover = {0.88f, 0.88f, 0.88f, 1.0f};+ colors.dockTabActive = {1.0f, 1.0f, 1.0f, 1.0f};+ colors.dockSplitter = {0.85f, 0.85f, 0.85f, 1.0f};+ colors.dockSplitterHover = {0.26f, 0.59f, 0.98f, 1.0f};+ colors.dockDropPreview = {0.26f, 0.59f, 0.98f, 0.20f};+ colors.dockZoneButton = {0.95f, 0.95f, 0.95f, 0.95f};}};diff --git a/src/esengine/ui/docking/DockArea.cpp b/src/esengine/ui/docking/DockArea.cppnew file mode 100644index 000000000..4a756d1e1--- /dev/null+++ b/src/esengine/ui/docking/DockArea.cpp@@ -0,0 +1,531 @@+/**+ * @file DockArea.cpp+ * @brief DockArea implementation+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */++#include "DockArea.hpp"+#include "DockPanel.hpp"+#include "DockTabBar.hpp"+#include "../UIContext.hpp"+#include "../rendering/UIBatchRenderer.hpp"+#include "../../events/Sink.hpp"++namespace esengine::ui {++// =============================================================================+// Constructor / Destructor+// =============================================================================++DockArea::DockArea(const WidgetId& id)+ : Widget(id)+ , zoneDetector_(this) {}++DockArea::~DockArea() = default;++// =============================================================================+// Tree Access+// =============================================================================++DockNode* DockArea::findNode(DockNodeId id) {+ if (!rootNode_) return nullptr;+ return rootNode_->findNode(id);+}++DockPanel* DockArea::findPanel(DockPanelId id) {+ if (!rootNode_) return nullptr;++ DockPanel* found = nullptr;+ rootNode_->forEachLeaf([&](DockNode& node) {+ if (!found) {+ found = node.findPanel(id);+ }+ });+ return found;+}++DockNode* DockArea::findNodeContainingPanel(DockPanelId panelId) {+ if (!rootNode_) return nullptr;+ return rootNode_->findNodeContainingPanel(panelId);+}++// =============================================================================+// Panel Management+// =============================================================================++void DockArea::addPanel(Unique<DockPanel> panel, DockDropZone zone,+ DockNode* targetNode, f32 ratio) {+ if (!panel) return;++ if (!rootNode_) {+ rootNode_ = DockNode::createTabs(generateNodeId());+ setNodeArea(rootNode_.get());+ rootNode_->addPanel(std::move(panel));+ onLayoutChanged.publish();+ return;+ }++ if (!targetNode) {+ targetNode = rootNode_.get();+ }++ if (zone == DockDropZone::Center || zone == DockDropZone::None) {+ if (targetNode->isTabs()) {+ targetNode->addPanel(std::move(panel));+ } else {+ DockNode* leaf = nullptr;+ targetNode->forEachLeaf([&](DockNode& node) {+ if (!leaf) leaf = &node;+ });+ if (leaf) {+ leaf->addPanel(std::move(panel));+ }+ }+ } else if (isEdgeDropZone(zone)) {+ DockSplitDirection dir = dropZoneToSplitDirection(zone);+ bool insertFirst = dropZoneIsFirst(zone);++ DockNode* newTabsNode = splitNode(targetNode, dir, ratio, insertFirst);+ if (newTabsNode) {+ newTabsNode->addPanel(std::move(panel));+ }+ }++ onLayoutChanged.publish();+}++Unique<DockPanel> DockArea::removePanel(DockPanelId panelId) {+ DockNode* node = findNodeContainingPanel(panelId);+ if (!node) return nullptr;++ DockPanel* panel = node->findPanel(panelId);+ if (!panel) return nullptr;++ auto removed = node->removePanel(panel);++ if (node->isEmpty()) {+ tryMergeNode(node);+ }++ onLayoutChanged.publish();+ return removed;+}++void DockArea::movePanel(DockPanel* panel, const DockDropTarget& target) {+ if (!panel || target.zone == DockDropZone::None) return;++ DockNode* sourceNode = panel->getOwnerNode();+ if (!sourceNode) return;++ auto detachedPanel = sourceNode->removePanel(panel);+ if (!detachedPanel) return;++ if (target.zone == DockDropZone::Center) {+ if (target.targetNode && target.targetNode->isTabs()) {+ target.targetNode->addPanel(std::move(detachedPanel));+ }+ } else if (isEdgeDropZone(target.zone)) {+ DockSplitDirection dir = dropZoneToSplitDirection(target.zone);+ bool insertFirst = dropZoneIsFirst(target.zone);++ DockNode* newNode = splitNode(target.targetNode, dir, target.splitRatio, insertFirst);+ if (newNode) {+ newNode->addPanel(std::move(detachedPanel));+ }+ }++ if (sourceNode->isEmpty()) {+ tryMergeNode(sourceNode);+ }++ onLayoutChanged.publish();+}++void DockArea::closePanel(DockPanelId panelId) {+ auto panel = removePanel(panelId);+ if (panel) {+ onPanelClosed.publish(panelId);+ }+}++std::vector<DockPanel*> DockArea::getAllPanels() const {+ std::vector<DockPanel*> result;++ if (rootNode_) {+ rootNode_->forEachLeaf([&](DockNode& node) {+ for (const auto& panel : node.getPanels()) {+ if (panel) {+ result.push_back(panel.get());+ }+ }+ });+ }++ return result;+}++// =============================================================================+// Node Operations+// =============================================================================++DockNode* DockArea::splitNode(DockNode* node, DockSplitDirection direction,+ f32 ratio, bool insertFirst) {+ if (!node) return nullptr;++ auto newTabsNode = DockNode::createTabs(generateNodeId());+ DockNode* newTabsPtr = newTabsNode.get();++ if (node == rootNode_.get()) {+ auto newSplit = DockNode::createSplit(generateNodeId(), direction);+ newSplit->setSplitRatio(insertFirst ? ratio : (1.0f - ratio));++ if (insertFirst) {+ newSplit->setFirst(std::move(newTabsNode));+ newSplit->setSecond(std::move(rootNode_));+ } else {+ newSplit->setFirst(std::move(rootNode_));+ newSplit->setSecond(std::move(newTabsNode));+ }++ rootNode_ = std::move(newSplit);+ setNodeArea(rootNode_.get());+ } else {+ DockNode* parent = node->getParent();+ if (!parent || !parent->isSplit()) return nullptr;++ bool isFirst = (parent->getFirst() == node);++ Unique<DockNode> detached = isFirst ? parent->detachFirst() : parent->detachSecond();++ auto newSplit = DockNode::createSplit(generateNodeId(), direction);+ newSplit->setSplitRatio(insertFirst ? ratio : (1.0f - ratio));++ if (insertFirst) {+ newSplit->setFirst(std::move(newTabsNode));+ newSplit->setSecond(std::move(detached));+ } else {+ newSplit->setFirst(std::move(detached));+ newSplit->setSecond(std::move(newTabsNode));+ }++ if (isFirst) {+ parent->setFirst(std::move(newSplit));+ } else {+ parent->setSecond(std::move(newSplit));+ }++ setNodeArea(parent);+ }++ return newTabsPtr;+}++void DockArea::tryMergeNode(DockNode* node) {+ if (!node || !node->isEmpty()) return;++ DockNode* parent = node->getParent();+ if (!parent || !parent->isSplit()) {+ if (node == rootNode_.get() && node->isEmpty()) {+ rootNode_.reset();+ }+ return;+ }++ bool isFirst = (parent->getFirst() == node);+ DockNode* sibling = isFirst ? parent->getSecond() : parent->getFirst();++ if (!sibling) return;++ Unique<DockNode> siblingOwned = isFirst ? parent->detachSecond() : parent->detachFirst();++ DockNode* grandparent = parent->getParent();+ if (grandparent && grandparent->isSplit()) {+ bool parentIsFirst = (grandparent->getFirst() == parent);+ if (parentIsFirst) {+ grandparent->setFirst(std::move(siblingOwned));+ } else {+ grandparent->setSecond(std::move(siblingOwned));+ }+ } else if (parent == rootNode_.get()) {+ rootNode_ = std::move(siblingOwned);+ if (rootNode_) {+ rootNode_->parent_ = nullptr;+ setNodeArea(rootNode_.get());+ }+ }++ tabBars_.erase(node->getId());+ tabBarConnections_.erase(node->getId());+ tabBars_.erase(parent->getId());+ tabBarConnections_.erase(parent->getId());+}++// =============================================================================+// Drag and Drop+// =============================================================================++void DockArea::beginPanelDrag(DockPanel* panel, const glm::vec2& startPos) {+ zoneDetector_.beginDrag(panel, startPos);+}++// =============================================================================+// Widget Overrides+// =============================================================================++glm::vec2 DockArea::measure(f32 availableWidth, f32 availableHeight) {+ return {availableWidth, availableHeight};+}++void DockArea::render(UIBatchRenderer& renderer) {+ if (!rootNode_) return;++ rootNode_->setBounds(getBounds());+ rootNode_->layout(splitterThickness_, tabBarHeight_);++ renderNode(renderer, rootNode_.get());++ zoneDetector_.render(renderer);+}++void DockArea::renderNode(UIBatchRenderer& renderer, DockNode* node) {+ if (!node) return;++ if (node->isSplit()) {+ renderNode(renderer, node->getFirst());+ renderNode(renderer, node->getSecond());+ renderSplitter(renderer, node);+ } else {+ renderTabBar(renderer, node);++ DockPanel* activePanel = node->getActivePanel();+ if (activePanel) {+ activePanel->render(renderer);+ }+ }+}++void DockArea::renderSplitter(UIBatchRenderer& renderer, DockNode* node) {+ if (!node || !node->isSplit()) return;++ UIContext* ctx = getContext();+ if (!ctx) return;++ Rect splitterBounds = node->getSplitterBounds(splitterThickness_);+ bool hovered = (draggedSplitter_ == node) ||+ splitterBounds.contains({lastMouseX_, lastMouseY_});++ glm::vec4 color = hovered+ ? ctx->getTheme().colors.accent+ : ctx->getTheme().colors.border;++ renderer.drawRect(splitterBounds, color);+}++void DockArea::renderTabBar(UIBatchRenderer& renderer, DockNode* node) {+ if (!node || !node->isTabs()) return;++ DockTabBar* tabBar = getOrCreateTabBar(node);+ if (!tabBar) return;++ Rect tabBarBounds{+ node->getBounds().x,+ node->getBounds().y,+ node->getBounds().width,+ tabBarHeight_+ };++ tabBar->layout(tabBarBounds);+ tabBar->render(renderer);+}++// =============================================================================+// Event Handling+// =============================================================================++bool DockArea::onMouseDown(const MouseButtonEvent& event) {+ if (event.button != MouseButton::Left) return false;++ if (zoneDetector_.isDragging()) {+ return true;+ }++ DockNode* splitter = hitTestSplitter(event.x, event.y);+ if (splitter) {+ draggedSplitter_ = splitter;+ splitterDragStart_ = {event.x, event.y};+ splitterDragStartRatio_ = splitter->getSplitRatio();+ return true;+ }++ if (rootNode_) {+ rootNode_->forEachLeaf([&](DockNode& node) {+ DockTabBar* tabBar = getOrCreateTabBar(&node);+ if (tabBar) {+ Rect tabBarBounds{+ node.getBounds().x,+ node.getBounds().y,+ node.getBounds().width,+ tabBarHeight_+ };+ if (tabBarBounds.contains({event.x, event.y})) {+ tabBar->onMouseDown(event);+ }+ }+ });+ }++ return false;+}++bool DockArea::onMouseUp(const MouseButtonEvent& event) {+ if (event.button != MouseButton::Left) return false;++ if (zoneDetector_.isDragging()) {+ DockDropTarget target = zoneDetector_.endDrag();+ DockPanel* panel = zoneDetector_.getDraggedPanel();+ if (panel && target.zone != DockDropZone::None) {+ movePanel(panel, target);+ }+ return true;+ }++ if (draggedSplitter_) {+ draggedSplitter_ = nullptr;+ return true;+ }++ if (rootNode_) {+ rootNode_->forEachLeaf([&](DockNode& node) {+ DockTabBar* tabBar = getOrCreateTabBar(&node);+ if (tabBar) {+ tabBar->onMouseUp(event);+ }+ });+ }++ return false;+}++bool DockArea::onMouseMove(const MouseMoveEvent& event) {+ lastMouseX_ = event.x;+ lastMouseY_ = event.y;++ if (zoneDetector_.isDragging()) {+ zoneDetector_.updateDrag({event.x, event.y});+ return true;+ }++ if (draggedSplitter_) {+ handleSplitterDrag(event.x, event.y);+ return true;+ }++ if (rootNode_) {+ rootNode_->forEachLeaf([&](DockNode& node) {+ DockTabBar* tabBar = getOrCreateTabBar(&node);+ if (tabBar) {+ tabBar->onMouseMove(event);+ }+ });+ }++ return false;+}++void DockArea::onStateChanged() {+ Widget::onStateChanged();+}++// =============================================================================+// Private Methods+// =============================================================================++DockNode* DockArea::hitTestSplitter(f32 x, f32 y) {+ if (!rootNode_) return nullptr;++ DockNode* result = nullptr;+ rootNode_->forEachNode([&](DockNode& node) {+ if (!result && node.isSplit() && node.hitTestSplitter(x, y, splitterThickness_)) {+ result = &node;+ }+ });+ return result;+}++void DockArea::handleSplitterDrag(f32 x, f32 y) {+ if (!draggedSplitter_) return;++ const Rect& bounds = draggedSplitter_->getBounds();+ f32 newRatio;++ if (draggedSplitter_->getSplitDirection() == DockSplitDirection::Horizontal) {+ f32 relX = x - bounds.x;+ newRatio = relX / bounds.width;+ } else {+ f32 relY = y - bounds.y;+ newRatio = relY / bounds.height;+ }++ draggedSplitter_->setSplitRatio(newRatio);+}++void DockArea::setNodeArea(DockNode* node) {+ if (!node) return;++ node->area_ = this;++ if (node->getFirst()) {+ setNodeArea(node->getFirst());+ }+ if (node->getSecond()) {+ setNodeArea(node->getSecond());+ }+}++DockTabBar* DockArea::getOrCreateTabBar(DockNode* node) {+ if (!node || !node->isTabs()) return nullptr;++ auto it = tabBars_.find(node->getId());+ if (it != tabBars_.end()) {+ return it->second.get();+ }++ auto tabBar = makeUnique<DockTabBar>(+ WidgetId("dock.tabbar." + std::to_string(node->getId())),+ node+ );++ std::vector<Connection> connections;++ connections.push_back(sink(tabBar->onTabSelected).connect([this, node](i32 index) {+ node->setActiveTabIndex(index);+ DockPanel* panel = node->getActivePanel();+ if (panel) {+ onPanelActivated.publish(panel->getPanelId());+ }+ }));++ connections.push_back(sink(tabBar->onTabCloseRequested).connect([this](DockPanelId panelId) {+ closePanel(panelId);+ }));++ connections.push_back(sink(tabBar->onTabDragStart).connect([this](DockPanelId panelId, glm::vec2 pos) {+ DockPanel* panel = findPanel(panelId);+ if (panel) {+ beginPanelDrag(panel, pos);+ }+ }));++ DockTabBar* ptr = tabBar.get();+ DockNodeId nodeId = node->getId();+ tabBars_[nodeId] = std::move(tabBar);+ tabBarConnections_[nodeId] = std::move(connections);+ return ptr;+}++} // namespace esengine::uidiff --git a/src/esengine/ui/docking/DockArea.hpp b/src/esengine/ui/docking/DockArea.hppnew file mode 100644index 000000000..38799d08c--- /dev/null+++ b/src/esengine/ui/docking/DockArea.hpp@@ -0,0 +1,251 @@+/**+ * @file DockArea.hpp+ * @brief Main container widget for the docking system+ * @details Manages the dock tree, handles panel operations,+ * splitter dragging, and drag-drop coordination.+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */+#pragma once++// =============================================================================+// Includes+// =============================================================================++#include "DockTypes.hpp"+#include "DockNode.hpp"+#include "DockZone.hpp"+#include "../widgets/Widget.hpp"+#include "../../events/Signal.hpp"+#include "../../events/Connection.hpp"++#include <unordered_map>+#include <vector>++namespace esengine::ui {++// Forward declarations+class DockPanel;+class DockTabBar;++// =============================================================================+// DockArea Class+// =============================================================================++/**+ * @brief Main container widget for dockable panels+ *+ * @details DockArea manages the entire docking tree structure including:+ * - Tree manipulation (splitting, merging, tabbing)+ * - Drag and drop operations+ * - Splitter dragging for resizing+ * - Layout calculation for all nodes+ *+ * @code+ * auto dockArea = makeUnique<DockArea>(WidgetId("editor.dock"));+ *+ * // Add panels+ * dockArea->addPanel(makeUnique<HierarchyPanel>(), DockDropZone::Left);+ * dockArea->addPanel(makeUnique<InspectorPanel>(), DockDropZone::Right);+ * dockArea->addPanel(makeUnique<ScenePanel>(), DockDropZone::Center);+ *+ * uiContext.setRoot(std::move(dockArea));+ * @endcode+ */+class DockArea : public Widget {+public:+ explicit DockArea(const WidgetId& id);+ ~DockArea() override;++ // =========================================================================+ // Tree Access+ // =========================================================================++ /** @brief Gets the root dock node */+ DockNode* getRootNode() const { return rootNode_.get(); }++ /** @brief Find a node by ID */+ DockNode* findNode(DockNodeId id);++ /** @brief Find a panel by ID */+ DockPanel* findPanel(DockPanelId id);++ /** @brief Find the node containing a panel */+ DockNode* findNodeContainingPanel(DockPanelId panelId);++ // =========================================================================+ // Panel Management+ // =========================================================================++ /**+ * @brief Add a panel to the dock area+ * @param panel Panel to add (ownership transferred)+ * @param zone Dock zone (Left, Right, Top, Bottom, Center)+ * @param targetNode Node to dock relative to (nullptr = root)+ * @param ratio Split ratio for edge docking+ */+ void addPanel(Unique<DockPanel> panel,+ DockDropZone zone = DockDropZone::Center,+ DockNode* targetNode = nullptr,+ f32 ratio = 0.3f);++ /**+ * @brief Remove a panel from the dock area+ * @param panelId ID of panel to remove+ * @return The removed panel+ */+ Unique<DockPanel> removePanel(DockPanelId panelId);++ /**+ * @brief Move a panel to a new location+ * @param panel Panel to move+ * @param target Drop target information+ */+ void movePanel(DockPanel* panel, const DockDropTarget& target);++ /**+ * @brief Close a panel+ * @param panelId ID of panel to close+ */+ void closePanel(DockPanelId panelId);++ /**+ * @brief Get all panels in the dock area+ */+ std::vector<DockPanel*> getAllPanels() const;++ // =========================================================================+ // Node Operations+ // =========================================================================++ /**+ * @brief Split a node to create space for docking+ * @param node Node to split+ * @param direction Split direction+ * @param ratio Split ratio+ * @param insertFirst Insert new node as first child+ * @return The new tabs node for adding panels+ */+ DockNode* splitNode(DockNode* node,+ DockSplitDirection direction,+ f32 ratio = 0.5f,+ bool insertFirst = false);++ /**+ * @brief Try to merge empty nodes up the tree+ * @param node Node to start checking from+ */+ void tryMergeNode(DockNode* node);++ // =========================================================================+ // ID Generation+ // =========================================================================++ /** @brief Generate a unique node ID */+ DockNodeId generateNodeId() { return nextNodeId_++; }++ // =========================================================================+ // Drag and Drop+ // =========================================================================++ /** @brief Get the zone detector for drag operations */+ DockZoneDetector& getZoneDetector() { return zoneDetector_; }++ /** @brief Check if a drag operation is in progress */+ bool isDragging() const { return zoneDetector_.isDragging(); }++ /**+ * @brief Start dragging a panel+ * @param panel Panel to drag+ * @param startPos Initial mouse position+ */+ void beginPanelDrag(DockPanel* panel, const glm::vec2& startPos);++ // =========================================================================+ // Configuration+ // =========================================================================++ /** @brief Set minimum panel size */+ void setMinPanelSize(const glm::vec2& size) { minPanelSize_ = size; }++ /** @brief Get minimum panel size */+ glm::vec2 getMinPanelSize() const { return minPanelSize_; }++ /** @brief Set splitter thickness in pixels */+ void setSplitterThickness(f32 thickness) { splitterThickness_ = thickness; }++ /** @brief Get splitter thickness */+ f32 getSplitterThickness() const { return splitterThickness_; }++ /** @brief Set tab bar height */+ void setTabBarHeight(f32 height) { tabBarHeight_ = height; }++ /** @brief Get tab bar height */+ f32 getTabBarHeight() const { return tabBarHeight_; }++ // =========================================================================+ // Signals+ // =========================================================================++ /** @brief Emitted when a panel is closed */+ Signal<void(DockPanelId)> onPanelClosed;++ /** @brief Emitted when a panel is activated (selected) */+ Signal<void(DockPanelId)> onPanelActivated;++ /** @brief Emitted when the layout changes */+ Signal<void()> onLayoutChanged;++ // =========================================================================+ // Widget Overrides+ // =========================================================================++ glm::vec2 measure(f32 availableWidth, f32 availableHeight) override;+ void render(UIBatchRenderer& renderer) override;++ bool onMouseDown(const MouseButtonEvent& event) override;+ bool onMouseUp(const MouseButtonEvent& event) override;+ bool onMouseMove(const MouseMoveEvent& event) override;++protected:+ void onStateChanged() override;++private:+ void layoutNode(DockNode* node);+ void renderNode(UIBatchRenderer& renderer, DockNode* node);+ void renderSplitter(UIBatchRenderer& renderer, DockNode* node);+ void renderTabBar(UIBatchRenderer& renderer, DockNode* node);++ DockNode* hitTestSplitter(f32 x, f32 y);+ void handleSplitterDrag(f32 x, f32 y);++ void setNodeArea(DockNode* node);+ void connectTabBarSignals(DockNode* node);++ DockTabBar* getOrCreateTabBar(DockNode* node);++ Unique<DockNode> rootNode_;+ DockNodeId nextNodeId_ = 1;++ DockZoneDetector zoneDetector_;++ std::unordered_map<DockNodeId, Unique<DockTabBar>> tabBars_;+ std::unordered_map<DockNodeId, std::vector<Connection>> tabBarConnections_;++ DockNode* draggedSplitter_ = nullptr;+ glm::vec2 splitterDragStart_{0.0f};+ f32 splitterDragStartRatio_ = 0.0f;++ glm::vec2 minPanelSize_{100.0f, 100.0f};+ f32 splitterThickness_ = 4.0f;+ f32 tabBarHeight_ = 24.0f;++ f32 lastMouseX_ = 0.0f;+ f32 lastMouseY_ = 0.0f;+};++} // namespace esengine::uidiff --git a/src/esengine/ui/docking/DockEvents.hpp b/src/esengine/ui/docking/DockEvents.hppnew file mode 100644index 000000000..7d2a9adf8--- /dev/null+++ b/src/esengine/ui/docking/DockEvents.hpp@@ -0,0 +1,181 @@+/**+ * @file DockEvents.hpp+ * @brief Event definitions for docking system+ * @details Defines event structures for dock panel operations,+ * layout changes, and drag-drop actions.+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */+#pragma once++// =============================================================================+// Includes+// =============================================================================++#include "DockTypes.hpp"++#include <glm/glm.hpp>++#include <string>++namespace esengine::ui {++// =============================================================================+// Panel Events+// =============================================================================++/**+ * @brief Emitted when a panel is closed+ */+struct DockPanelClosedEvent {+ DockPanelId panelId;+};++/**+ * @brief Emitted when a panel is activated (selected)+ */+struct DockPanelActivatedEvent {+ DockPanelId panelId;+};++/**+ * @brief Emitted when a panel's title changes+ */+struct DockPanelTitleChangedEvent {+ DockPanelId panelId;+ std::string newTitle;+};++/**+ * @brief Emitted when a panel is added to the dock area+ */+struct DockPanelAddedEvent {+ DockPanelId panelId;+ DockNodeId nodeId;+};++/**+ * @brief Emitted when a panel is removed from the dock area+ */+struct DockPanelRemovedEvent {+ DockPanelId panelId;+};++// =============================================================================+// Layout Events+// =============================================================================++/**+ * @brief Emitted when the dock layout changes+ */+struct DockLayoutChangedEvent {+ // No data - just notification that layout changed+};++/**+ * @brief Emitted when a node is split+ */+struct DockNodeSplitEvent {+ DockNodeId parentId;+ DockNodeId newNodeId;+ DockSplitDirection direction;+};++/**+ * @brief Emitted when nodes are merged+ */+struct DockNodeMergedEvent {+ DockNodeId removedNodeId;+ DockNodeId remainingNodeId;+};++/**+ * @brief Emitted when a splitter ratio changes+ */+struct DockSplitterChangedEvent {+ DockNodeId nodeId;+ f32 oldRatio;+ f32 newRatio;+};++// =============================================================================+// Tab Events+// =============================================================================++/**+ * @brief Emitted when a tab is selected+ */+struct DockTabSelectedEvent {+ DockNodeId nodeId;+ i32 tabIndex;+ DockPanelId panelId;+};++/**+ * @brief Emitted when tab order changes within a node+ */+struct DockTabReorderedEvent {+ DockNodeId nodeId;+ i32 oldIndex;+ i32 newIndex;+};++// =============================================================================+// Drag Events+// =============================================================================++/**+ * @brief Emitted when panel drag starts+ */+struct DockDragStartEvent {+ DockPanelId panelId;+ glm::vec2 startPosition;+};++/**+ * @brief Emitted during panel drag+ */+struct DockDragUpdateEvent {+ DockPanelId panelId;+ glm::vec2 currentPosition;+ DockDropZone hoveredZone;+ DockNodeId targetNodeId;+};++/**+ * @brief Emitted when panel drag ends+ */+struct DockDragEndEvent {+ DockPanelId panelId;+ DockDropZone dropZone;+ DockNodeId targetNodeId;+ bool cancelled;+};++// =============================================================================+// Floating Panel Events (for future floating window support)+// =============================================================================++/**+ * @brief Emitted when a panel becomes floating+ */+struct DockPanelFloatEvent {+ DockPanelId panelId;+ glm::vec2 position;+ glm::vec2 size;+};++/**+ * @brief Emitted when a floating panel is docked+ */+struct DockPanelDockedEvent {+ DockPanelId panelId;+ DockNodeId targetNodeId;+ DockDropZone dropZone;+};++} // namespace esengine::uidiff --git a/src/esengine/ui/docking/DockLayoutSerializer.cpp b/src/esengine/ui/docking/DockLayoutSerializer.cppnew file mode 100644index 000000000..5d8fd0568--- /dev/null+++ b/src/esengine/ui/docking/DockLayoutSerializer.cpp@@ -0,0 +1,343 @@+/**+ * @file DockLayoutSerializer.cpp+ * @brief DockLayoutSerializer implementation+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */++#include "DockLayoutSerializer.hpp"+#include "DockArea.hpp"+#include "DockNode.hpp"+#include "DockPanel.hpp"+#include "../../core/Log.hpp"++#include <sstream>+#include <iomanip>+#include <algorithm>++namespace esengine::ui {++// =============================================================================+// JSON Helper Functions+// =============================================================================++namespace {++std::string escapeJsonString(const std::string& str) {+ std::ostringstream oss;+ for (char c : str) {+ switch (c) {+ case '"': oss << "\\\""; break;+ case '\\': oss << "\\\\"; break;+ case '\n': oss << "\\n"; break;+ case '\r': oss << "\\r"; break;+ case '\t': oss << "\\t"; break;+ default: oss << c; break;+ }+ }+ return oss.str();+}++void skipWhitespace(const std::string& json, usize& pos) {+ while (pos < json.size() && std::isspace(json[pos])) {+ ++pos;+ }+}++bool expectChar(const std::string& json, usize& pos, char c) {+ skipWhitespace(json, pos);+ if (pos < json.size() && json[pos] == c) {+ ++pos;+ return true;+ }+ return false;+}++std::string parseString(const std::string& json, usize& pos) {+ skipWhitespace(json, pos);+ if (pos >= json.size() || json[pos] != '"') return "";+ ++pos;++ std::string result;+ while (pos < json.size() && json[pos] != '"') {+ if (json[pos] == '\\' && pos + 1 < json.size()) {+ ++pos;+ switch (json[pos]) {+ case '"': result += '"'; break;+ case '\\': result += '\\'; break;+ case 'n': result += '\n'; break;+ case 'r': result += '\r'; break;+ case 't': result += '\t'; break;+ default: result += json[pos]; break;+ }+ } else {+ result += json[pos];+ }+ ++pos;+ }+ if (pos < json.size()) ++pos;+ return result;+}++f32 parseNumber(const std::string& json, usize& pos) {+ skipWhitespace(json, pos);+ usize start = pos;+ while (pos < json.size() && (std::isdigit(json[pos]) || json[pos] == '.' ||+ json[pos] == '-' || json[pos] == '+' ||+ json[pos] == 'e' || json[pos] == 'E')) {+ ++pos;+ }+ return std::stof(json.substr(start, pos - start));+}++i32 parseInt(const std::string& json, usize& pos) {+ skipWhitespace(json, pos);+ usize start = pos;+ if (pos < json.size() && json[pos] == '-') ++pos;+ while (pos < json.size() && std::isdigit(json[pos])) {+ ++pos;+ }+ return std::stoi(json.substr(start, pos - start));+}++} // namespace++// =============================================================================+// Serialization+// =============================================================================++std::string DockLayoutSerializer::serialize(const DockArea& area) const {+ DockLayoutData data = serializeToData(area);+ return toJson(data);+}++DockLayoutData DockLayoutSerializer::serializeToData(const DockArea& area) const {+ DockLayoutData data;+ data.version = 1;++ DockNode* root = area.getRootNode();+ if (!root) {+ data.rootNodeIndex = -1;+ return data;+ }++ std::vector<i32> nodeIndexMap;+ serializeNode(root, data, nodeIndexMap);+ data.rootNodeIndex = 0;++ return data;+}++void DockLayoutSerializer::serializeNode(const DockNode* node, DockLayoutData& data,+ std::vector<i32>& nodeIndexMap) const {+ if (!node) return;++ DockNodeData nodeData;+ nodeData.id = node->getId();+ nodeData.type = node->getType();++ if (node->isSplit()) {+ nodeData.splitDirection = node->getSplitDirection();+ nodeData.splitRatio = node->getSplitRatio();++ i32 currentIndex = static_cast<i32>(data.nodes.size());+ data.nodes.push_back(nodeData);++ if (node->getFirst()) {+ data.nodes[static_cast<usize>(currentIndex)].firstChildIndex =+ static_cast<i32>(data.nodes.size());+ serializeNode(node->getFirst(), data, nodeIndexMap);+ }++ if (node->getSecond()) {+ data.nodes[static_cast<usize>(currentIndex)].secondChildIndex =+ static_cast<i32>(data.nodes.size());+ serializeNode(node->getSecond(), data, nodeIndexMap);+ }+ } else {+ nodeData.activeTabIndex = node->getActiveTabIndex();+ for (const auto& panel : node->getPanels()) {+ if (panel) {+ nodeData.panelIds.push_back(panel->getPanelId());+ }+ }+ data.nodes.push_back(nodeData);+ }+}++// =============================================================================+// Deserialization+// =============================================================================++bool DockLayoutSerializer::deserialize(DockArea& area, const std::string& json,+ const PanelFactory& factory) const {+ DockLayoutData data;+ if (!fromJson(json, data)) {+ ES_LOG_ERROR("Failed to parse dock layout JSON");+ return false;+ }+ return deserializeFromData(area, data, factory);+}++bool DockLayoutSerializer::deserializeFromData(DockArea& /*area*/, const DockLayoutData& data,+ const PanelFactory& /*factory*/) const {+ if (data.rootNodeIndex < 0 ||+ static_cast<usize>(data.rootNodeIndex) >= data.nodes.size()) {+ return true;+ }++ // TODO: Clear existing layout and rebuild from data+ // This requires access to DockArea internals or additional API+ ES_LOG_WARN("DockLayoutSerializer::deserializeFromData not fully implemented");++ return true;+}++DockNode* DockLayoutSerializer::deserializeNode(DockArea& /*area*/, const DockLayoutData& data,+ i32 nodeIndex,+ const PanelFactory& /*factory*/) const {+ if (nodeIndex < 0 || static_cast<usize>(nodeIndex) >= data.nodes.size()) {+ return nullptr;+ }++ // TODO: Create nodes using DockArea API+ // This requires additional DockArea methods for direct node creation+ (void)data.nodes[static_cast<usize>(nodeIndex)];++ return nullptr;+}++// =============================================================================+// JSON Conversion+// =============================================================================++std::string DockLayoutSerializer::toJson(const DockLayoutData& data) const {+ std::ostringstream oss;+ oss << std::fixed << std::setprecision(4);++ oss << "{\n";+ oss << " \"version\": " << data.version << ",\n";+ oss << " \"layoutName\": \"" << escapeJsonString(data.layoutName) << "\",\n";+ oss << " \"rootNodeIndex\": " << data.rootNodeIndex << ",\n";+ oss << " \"nextNodeId\": " << data.nextNodeId << ",\n";+ oss << " \"nodes\": [\n";++ for (usize i = 0; i < data.nodes.size(); ++i) {+ const DockNodeData& node = data.nodes[i];+ oss << " {\n";+ oss << " \"id\": " << node.id << ",\n";+ oss << " \"type\": " << static_cast<i32>(node.type) << ",\n";+ oss << " \"splitDirection\": " << static_cast<i32>(node.splitDirection) << ",\n";+ oss << " \"splitRatio\": " << node.splitRatio << ",\n";+ oss << " \"activeTabIndex\": " << node.activeTabIndex << ",\n";+ oss << " \"firstChildIndex\": " << node.firstChildIndex << ",\n";+ oss << " \"secondChildIndex\": " << node.secondChildIndex << ",\n";+ oss << " \"panelIds\": [";++ for (usize j = 0; j < node.panelIds.size(); ++j) {+ oss << node.panelIds[j];+ if (j + 1 < node.panelIds.size()) oss << ", ";+ }++ oss << "]\n";+ oss << " }";+ if (i + 1 < data.nodes.size()) oss << ",";+ oss << "\n";+ }++ oss << " ]\n";+ oss << "}\n";++ return oss.str();+}++bool DockLayoutSerializer::fromJson(const std::string& json, DockLayoutData& outData) const {+ usize pos = 0;++ if (!expectChar(json, pos, '{')) return false;++ while (pos < json.size()) {+ skipWhitespace(json, pos);+ if (json[pos] == '}') break;++ std::string key = parseString(json, pos);+ if (!expectChar(json, pos, ':')) return false;++ if (key == "version") {+ outData.version = static_cast<u32>(parseInt(json, pos));+ } else if (key == "layoutName") {+ outData.layoutName = parseString(json, pos);+ } else if (key == "rootNodeIndex") {+ outData.rootNodeIndex = parseInt(json, pos);+ } else if (key == "nextNodeId") {+ outData.nextNodeId = static_cast<DockNodeId>(parseInt(json, pos));+ } else if (key == "nodes") {+ if (!expectChar(json, pos, '[')) return false;++ while (pos < json.size()) {+ skipWhitespace(json, pos);+ if (json[pos] == ']') {+ ++pos;+ break;+ }++ DockNodeData node;+ if (!expectChar(json, pos, '{')) return false;++ while (pos < json.size()) {+ skipWhitespace(json, pos);+ if (json[pos] == '}') {+ ++pos;+ break;+ }++ std::string nodeKey = parseString(json, pos);+ if (!expectChar(json, pos, ':')) return false;++ if (nodeKey == "id") {+ node.id = static_cast<DockNodeId>(parseInt(json, pos));+ } else if (nodeKey == "type") {+ node.type = static_cast<DockNodeType>(parseInt(json, pos));+ } else if (nodeKey == "splitDirection") {+ node.splitDirection = static_cast<DockSplitDirection>(parseInt(json, pos));+ } else if (nodeKey == "splitRatio") {+ node.splitRatio = parseNumber(json, pos);+ } else if (nodeKey == "activeTabIndex") {+ node.activeTabIndex = parseInt(json, pos);+ } else if (nodeKey == "firstChildIndex") {+ node.firstChildIndex = parseInt(json, pos);+ } else if (nodeKey == "secondChildIndex") {+ node.secondChildIndex = parseInt(json, pos);+ } else if (nodeKey == "panelIds") {+ if (!expectChar(json, pos, '[')) return false;+ while (pos < json.size()) {+ skipWhitespace(json, pos);+ if (json[pos] == ']') {+ ++pos;+ break;+ }+ node.panelIds.push_back(+ static_cast<DockPanelId>(parseInt(json, pos)));+ expectChar(json, pos, ',');+ }+ }++ expectChar(json, pos, ',');+ }++ outData.nodes.push_back(node);+ expectChar(json, pos, ',');+ }+ }++ expectChar(json, pos, ',');+ }++ return true;+}++} // namespace esengine::uidiff --git a/src/esengine/ui/docking/DockLayoutSerializer.hpp b/src/esengine/ui/docking/DockLayoutSerializer.hppnew file mode 100644index 000000000..bc4db3e10--- /dev/null+++ b/src/esengine/ui/docking/DockLayoutSerializer.hpp@@ -0,0 +1,173 @@+/**+ * @file DockLayoutSerializer.hpp+ * @brief Serialization and deserialization for dock layouts+ * @details Saves and loads dock tree structure to/from JSON format.+ * Panels are identified by ID; actual panel restoration+ * is delegated to the application.+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */+#pragma once++// =============================================================================+// Includes+// =============================================================================++#include "DockTypes.hpp"+#include "../../core/Types.hpp"++#include <string>+#include <vector>+#include <functional>++namespace esengine::ui {++// Forward declarations+class DockArea;+class DockNode;+class DockPanel;++// =============================================================================+// Serialized Data Structures+// =============================================================================++/**+ * @brief Serialized representation of a dock node+ */+struct DockNodeData {+ DockNodeId id = 0;+ DockNodeType type = DockNodeType::Tabs;++ // Split node data+ DockSplitDirection splitDirection = DockSplitDirection::Horizontal;+ f32 splitRatio = 0.5f;++ // Tabs node data+ std::vector<DockPanelId> panelIds;+ i32 activeTabIndex = 0;++ // Children (for split nodes)+ i32 firstChildIndex = -1;+ i32 secondChildIndex = -1;+};++/**+ * @brief Complete serialized dock layout+ */+struct DockLayoutData {+ std::vector<DockNodeData> nodes;+ i32 rootNodeIndex = -1;+ DockNodeId nextNodeId = 1;++ // Metadata+ std::string layoutName;+ u32 version = 1;+};++// =============================================================================+// DockLayoutSerializer Class+// =============================================================================++/**+ * @brief Panel factory callback for deserialization+ * @param panelId The panel ID to create+ * @return Created panel or nullptr if panel cannot be restored+ */+using PanelFactory = std::function<Unique<DockPanel>(DockPanelId)>;++/**+ * @brief Serializes and deserializes dock layouts+ *+ * @details The serializer captures the structural layout (splits, tabs,+ * ratios) but not panel contents. During deserialization, a+ * PanelFactory callback is used to create panels by ID.+ *+ * @code+ * // Save layout+ * DockLayoutSerializer serializer;+ * std::string json = serializer.serialize(dockArea);+ * saveToFile("layout.json", json);+ *+ * // Load layout+ * std::string json = loadFromFile("layout.json");+ * serializer.deserialize(dockArea, json, [](DockPanelId id) {+ * return createPanelById(id);+ * });+ * @endcode+ */+class DockLayoutSerializer {+public:+ // =========================================================================+ // Serialization+ // =========================================================================++ /**+ * @brief Serialize dock area to JSON string+ * @param area The dock area to serialize+ * @return JSON string representation+ */+ std::string serialize(const DockArea& area) const;++ /**+ * @brief Serialize dock area to layout data+ * @param area The dock area to serialize+ * @return Layout data structure+ */+ DockLayoutData serializeToData(const DockArea& area) const;++ // =========================================================================+ // Deserialization+ // =========================================================================++ /**+ * @brief Deserialize dock area from JSON string+ * @param area The dock area to populate+ * @param json JSON string to parse+ * @param factory Factory function to create panels+ * @return True if successful+ */+ bool deserialize(DockArea& area, const std::string& json,+ const PanelFactory& factory) const;++ /**+ * @brief Deserialize dock area from layout data+ * @param area The dock area to populate+ * @param data Layout data structure+ * @param factory Factory function to create panels+ * @return True if successful+ */+ bool deserializeFromData(DockArea& area, const DockLayoutData& data,+ const PanelFactory& factory) const;++ // =========================================================================+ // JSON Conversion+ // =========================================================================++ /**+ * @brief Convert layout data to JSON string+ * @param data Layout data to convert+ * @return JSON string+ */+ std::string toJson(const DockLayoutData& data) const;++ /**+ * @brief Parse JSON string to layout data+ * @param json JSON string to parse+ * @param outData Output layout data+ * @return True if parsing successful+ */+ bool fromJson(const std::string& json, DockLayoutData& outData) const;++private:+ void serializeNode(const DockNode* node, DockLayoutData& data,+ std::vector<i32>& nodeIndexMap) const;++ DockNode* deserializeNode(DockArea& area, const DockLayoutData& data,+ i32 nodeIndex, const PanelFactory& factory) const;+};++} // namespace esengine::uidiff --git a/src/esengine/ui/docking/DockNode.cpp b/src/esengine/ui/docking/DockNode.cppnew file mode 100644index 000000000..a05aba0a6--- /dev/null+++ b/src/esengine/ui/docking/DockNode.cpp@@ -0,0 +1,357 @@+/**+ * @file DockNode.cpp+ * @brief DockNode implementation+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */++#include "DockNode.hpp"+#include "DockPanel.hpp"++#include <algorithm>++namespace esengine::ui {++// =============================================================================+// Factory Methods+// =============================================================================++Unique<DockNode> DockNode::createTabs(DockNodeId id) {+ return Unique<DockNode>(new DockNode(id, DockNodeType::Tabs));+}++Unique<DockNode> DockNode::createSplit(DockNodeId id, DockSplitDirection direction) {+ auto node = Unique<DockNode>(new DockNode(id, DockNodeType::Split));+ node->splitDirection_ = direction;+ return node;+}++// =============================================================================+// Constructor / Destructor+// =============================================================================++DockNode::DockNode(DockNodeId id, DockNodeType type)+ : id_(id), type_(type) {}++DockNode::~DockNode() = default;++// =============================================================================+// Tree Structure+// =============================================================================++void DockNode::setFirst(Unique<DockNode> node) {+ first_ = std::move(node);+ if (first_) {+ first_->parent_ = this;+ first_->area_ = area_;+ }+}++void DockNode::setSecond(Unique<DockNode> node) {+ second_ = std::move(node);+ if (second_) {+ second_->parent_ = this;+ second_->area_ = area_;+ }+}++Unique<DockNode> DockNode::detachFirst() {+ if (first_) {+ first_->parent_ = nullptr;+ first_->area_ = nullptr;+ }+ return std::move(first_);+}++Unique<DockNode> DockNode::detachSecond() {+ if (second_) {+ second_->parent_ = nullptr;+ second_->area_ = nullptr;+ }+ return std::move(second_);+}++void DockNode::updateChildParents() {+ if (first_) {+ first_->parent_ = this;+ first_->area_ = area_;+ }+ if (second_) {+ second_->parent_ = this;+ second_->area_ = area_;+ }+}++// =============================================================================+// Split Properties+// =============================================================================++void DockNode::setSplitRatio(f32 ratio) {+ splitRatio_ = std::clamp(ratio, 0.1f, 0.9f);+}++// =============================================================================+// Tab Properties+// =============================================================================++void DockNode::setActiveTabIndex(i32 index) {+ if (!panels_.empty()) {+ activeTabIndex_ = std::clamp(index, 0, static_cast<i32>(panels_.size()) - 1);+ } else {+ activeTabIndex_ = 0;+ }+}++DockPanel* DockNode::getActivePanel() const {+ if (activeTabIndex_ >= 0 && activeTabIndex_ < static_cast<i32>(panels_.size())) {+ return panels_[static_cast<usize>(activeTabIndex_)].get();+ }+ return nullptr;+}++// =============================================================================+// Panel Management+// =============================================================================++void DockNode::addPanel(Unique<DockPanel> panel) {+ if (panel) {+ panel->ownerNode_ = this;+ panels_.push_back(std::move(panel));+ if (panels_.size() == 1) {+ activeTabIndex_ = 0;+ }+ }+}++void DockNode::insertPanel(Unique<DockPanel> panel, i32 index) {+ if (panel) {+ panel->ownerNode_ = this;+ index = std::clamp(index, 0, static_cast<i32>(panels_.size()));+ panels_.insert(panels_.begin() + index, std::move(panel));++ if (activeTabIndex_ >= index) {+ activeTabIndex_++;+ }+ }+}++Unique<DockPanel> DockNode::removePanel(DockPanel* panel) {+ i32 index = findPanelIndex(panel);+ if (index >= 0) {+ return removePanelAt(index);+ }+ return nullptr;+}++Unique<DockPanel> DockNode::removePanelAt(i32 index) {+ if (index < 0 || index >= static_cast<i32>(panels_.size())) {+ return nullptr;+ }++ auto panel = std::move(panels_[static_cast<usize>(index)]);+ panel->ownerNode_ = nullptr;+ panels_.erase(panels_.begin() + index);++ if (activeTabIndex_ >= static_cast<i32>(panels_.size())) {+ activeTabIndex_ = static_cast<i32>(panels_.size()) - 1;+ }+ if (activeTabIndex_ < 0) {+ activeTabIndex_ = 0;+ }++ return panel;+}++i32 DockNode::findPanelIndex(DockPanel* panel) const {+ for (usize i = 0; i < panels_.size(); ++i) {+ if (panels_[i].get() == panel) {+ return static_cast<i32>(i);+ }+ }+ return -1;+}++DockPanel* DockNode::findPanel(DockPanelId id) const {+ for (const auto& panel : panels_) {+ if (panel->getPanelId() == id) {+ return panel.get();+ }+ }+ return nullptr;+}++// =============================================================================+// Layout+// =============================================================================++void DockNode::layout(f32 splitterThickness, f32 tabBarHeight) {+ if (isSplit()) {+ layoutSplit(splitterThickness, tabBarHeight);+ } else {+ layoutTabs(tabBarHeight);+ }+}++void DockNode::layoutSplit(f32 splitterThickness, f32 tabBarHeight) {+ if (!first_ || !second_) return;++ if (splitDirection_ == DockSplitDirection::Horizontal) {+ f32 availableWidth = bounds_.width - splitterThickness;+ f32 firstWidth = availableWidth * splitRatio_;+ f32 secondWidth = availableWidth - firstWidth;++ Rect firstBounds{+ bounds_.x,+ bounds_.y,+ firstWidth,+ bounds_.height+ };++ Rect secondBounds{+ bounds_.x + firstWidth + splitterThickness,+ bounds_.y,+ secondWidth,+ bounds_.height+ };++ first_->setBounds(firstBounds);+ second_->setBounds(secondBounds);+ } else {+ f32 availableHeight = bounds_.height - splitterThickness;+ f32 firstHeight = availableHeight * splitRatio_;+ f32 secondHeight = availableHeight - firstHeight;++ Rect firstBounds{+ bounds_.x,+ bounds_.y,+ bounds_.width,+ firstHeight+ };++ Rect secondBounds{+ bounds_.x,+ bounds_.y + firstHeight + splitterThickness,+ bounds_.width,+ secondHeight+ };++ first_->setBounds(firstBounds);+ second_->setBounds(secondBounds);+ }++ first_->layout(splitterThickness, tabBarHeight);+ second_->layout(splitterThickness, tabBarHeight);+}++void DockNode::layoutTabs(f32 tabBarHeight) {+ contentBounds_ = Rect{+ bounds_.x,+ bounds_.y + tabBarHeight,+ bounds_.width,+ bounds_.height - tabBarHeight+ };++ for (auto& panel : panels_) {+ if (panel) {+ panel->layout(contentBounds_);+ }+ }+}++Rect DockNode::getSplitterBounds(f32 thickness) const {+ if (!isSplit()) return {};++ if (splitDirection_ == DockSplitDirection::Horizontal) {+ f32 availableWidth = bounds_.width - thickness;+ f32 splitterX = bounds_.x + availableWidth * splitRatio_;+ return Rect{+ splitterX,+ bounds_.y,+ thickness,+ bounds_.height+ };+ } else {+ f32 availableHeight = bounds_.height - thickness;+ f32 splitterY = bounds_.y + availableHeight * splitRatio_;+ return Rect{+ bounds_.x,+ splitterY,+ bounds_.width,+ thickness+ };+ }+}++bool DockNode::hitTestSplitter(f32 x, f32 y, f32 tolerance) const {+ if (!isSplit()) return false;++ Rect splitterBounds = getSplitterBounds(tolerance * 2.0f);+ return splitterBounds.contains({x, y});+}++// =============================================================================+// Tree Traversal+// =============================================================================++DockNode* DockNode::findNode(DockNodeId id) {+ if (id_ == id) return this;++ if (first_) {+ if (auto* found = first_->findNode(id)) {+ return found;+ }+ }++ if (second_) {+ if (auto* found = second_->findNode(id)) {+ return found;+ }+ }++ return nullptr;+}++DockNode* DockNode::findNodeContainingPanel(DockPanelId panelId) {+ if (isTabs()) {+ for (const auto& panel : panels_) {+ if (panel && panel->getPanelId() == panelId) {+ return this;+ }+ }+ }++ if (first_) {+ if (auto* found = first_->findNodeContainingPanel(panelId)) {+ return found;+ }+ }++ if (second_) {+ if (auto* found = second_->findNodeContainingPanel(panelId)) {+ return found;+ }+ }++ return nullptr;+}++void DockNode::forEachLeaf(const std::function<void(DockNode&)>& callback) {+ if (isTabs()) {+ callback(*this);+ } else {+ if (first_) first_->forEachLeaf(callback);+ if (second_) second_->forEachLeaf(callback);+ }+}++void DockNode::forEachNode(const std::function<void(DockNode&)>& callback) {+ callback(*this);+ if (first_) first_->forEachNode(callback);+ if (second_) second_->forEachNode(callback);+}++} // namespace esengine::uidiff --git a/src/esengine/ui/docking/DockNode.hpp b/src/esengine/ui/docking/DockNode.hppnew file mode 100644index 000000000..ad528d2c4--- /dev/null+++ b/src/esengine/ui/docking/DockNode.hpp@@ -0,0 +1,330 @@+/**+ * @file DockNode.hpp+ * @brief Binary tree node for the docking system+ * @details Represents either a Split node with two children or a Tabs node+ * containing one or more DockPanels.+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */+#pragma once++// =============================================================================+// Includes+// =============================================================================++#include "DockTypes.hpp"+#include "../core/Types.hpp"++#include <functional>+#include <vector>++namespace esengine::ui {++// Forward declarations+class DockPanel;+class DockArea;++// =============================================================================+// DockNode Class+// =============================================================================++/**+ * @brief A node in the docking binary tree structure+ *+ * @details Each node is either:+ * - **Split**: Has two child nodes divided by a splitter+ * - **Tabs**: Contains one or more DockPanels displayed as tabs+ *+ * @code+ * // Create a tabs node+ * auto tabsNode = DockNode::createTabs(1);+ * tabsNode->addPanel(std::move(panel));+ *+ * // Create a split node+ * auto splitNode = DockNode::createSplit(2, DockSplitDirection::Horizontal);+ * splitNode->setFirst(std::move(leftNode));+ * splitNode->setSecond(std::move(rightNode));+ * @endcode+ */+class DockNode {+public:+ // =========================================================================+ // Factory Methods+ // =========================================================================++ /**+ * @brief Create a Tabs node+ * @param id Unique node identifier+ */+ static Unique<DockNode> createTabs(DockNodeId id);++ /**+ * @brief Create a Split node+ * @param id Unique node identifier+ * @param direction Split direction (Horizontal or Vertical)+ */+ static Unique<DockNode> createSplit(DockNodeId id, DockSplitDirection direction);++ ~DockNode();++ // Non-copyable+ DockNode(const DockNode&) = delete;+ DockNode& operator=(const DockNode&) = delete;++ // =========================================================================+ // Identity+ // =========================================================================++ /** @brief Gets the node's unique identifier */+ DockNodeId getId() const { return id_; }++ /** @brief Gets the node type (Split or Tabs) */+ DockNodeType getType() const { return type_; }++ /** @brief Returns true if this is a Split node */+ bool isSplit() const { return type_ == DockNodeType::Split; }++ /** @brief Returns true if this is a Tabs node */+ bool isTabs() const { return type_ == DockNodeType::Tabs; }++ // =========================================================================+ // Tree Structure+ // =========================================================================++ /** @brief Gets the parent node (nullptr if root) */+ DockNode* getParent() const { return parent_; }++ /** @brief Gets the owning DockArea */+ DockArea* getArea() const { return area_; }++ /** @brief Gets the first child (Split nodes only) */+ DockNode* getFirst() const { return first_.get(); }++ /** @brief Gets the second child (Split nodes only) */+ DockNode* getSecond() const { return second_.get(); }++ /**+ * @brief Sets the first child node+ * @param node Child node (ownership transferred)+ */+ void setFirst(Unique<DockNode> node);++ /**+ * @brief Sets the second child node+ * @param node Child node (ownership transferred)+ */+ void setSecond(Unique<DockNode> node);++ /**+ * @brief Detach and return the first child+ */+ Unique<DockNode> detachFirst();++ /**+ * @brief Detach and return the second child+ */+ Unique<DockNode> detachSecond();++ // =========================================================================+ // Split Properties (Split nodes only)+ // =========================================================================++ /** @brief Gets the split direction */+ DockSplitDirection getSplitDirection() const { return splitDirection_; }++ /** @brief Sets the split direction */+ void setSplitDirection(DockSplitDirection direction) { splitDirection_ = direction; }++ /** @brief Gets the split ratio (0.0 to 1.0) */+ f32 getSplitRatio() const { return splitRatio_; }++ /**+ * @brief Sets the split ratio+ * @param ratio Value between 0.1 and 0.9 (clamped)+ */+ void setSplitRatio(f32 ratio);++ // =========================================================================+ // Tab Properties (Tabs nodes only)+ // =========================================================================++ /** @brief Gets all panels in this node */+ const std::vector<Unique<DockPanel>>& getPanels() const { return panels_; }++ /** @brief Gets the number of panels */+ usize getPanelCount() const { return panels_.size(); }++ /** @brief Gets the active tab index */+ i32 getActiveTabIndex() const { return activeTabIndex_; }++ /**+ * @brief Sets the active tab index+ * @param index Index of tab to activate+ */+ void setActiveTabIndex(i32 index);++ /** @brief Gets the currently active panel (may be nullptr) */+ DockPanel* getActivePanel() const;++ // =========================================================================+ // Panel Management (Tabs nodes only)+ // =========================================================================++ /**+ * @brief Add a panel to the end of the tab list+ * @param panel Panel to add (ownership transferred)+ */+ void addPanel(Unique<DockPanel> panel);++ /**+ * @brief Insert a panel at a specific index+ * @param panel Panel to insert (ownership transferred)+ * @param index Position to insert at+ */+ void insertPanel(Unique<DockPanel> panel, i32 index);++ /**+ * @brief Remove a panel by pointer+ * @param panel Panel to remove+ * @return The removed panel+ */+ Unique<DockPanel> removePanel(DockPanel* panel);++ /**+ * @brief Remove a panel by index+ * @param index Index of panel to remove+ * @return The removed panel+ */+ Unique<DockPanel> removePanelAt(i32 index);++ /**+ * @brief Find panel index by pointer+ * @param panel Panel to find+ * @return Index or -1 if not found+ */+ i32 findPanelIndex(DockPanel* panel) const;++ /**+ * @brief Find panel by ID+ * @param id Panel ID to search for+ * @return Panel pointer or nullptr+ */+ DockPanel* findPanel(DockPanelId id) const;++ // =========================================================================+ // Layout+ // =========================================================================++ /** @brief Gets the node's bounding rectangle */+ const Rect& getBounds() const { return bounds_; }++ /**+ * @brief Sets the node's bounding rectangle+ * @param bounds New bounds+ */+ void setBounds(const Rect& bounds) { bounds_ = bounds; }++ /**+ * @brief Perform layout on this node and children+ * @param splitterThickness Thickness of splitters in pixels+ * @param tabBarHeight Height of tab bars in pixels+ */+ void layout(f32 splitterThickness, f32 tabBarHeight);++ /**+ * @brief Gets the content area (excluding tab bar for Tabs nodes)+ */+ Rect getContentBounds() const { return contentBounds_; }++ // =========================================================================+ // Splitter (Split nodes only)+ // =========================================================================++ /**+ * @brief Get the splitter bounds for rendering/hit testing+ * @param thickness Splitter thickness in pixels+ */+ Rect getSplitterBounds(f32 thickness = 4.0f) const;++ /**+ * @brief Test if a point hits the splitter+ * @param x X coordinate+ * @param y Y coordinate+ * @param tolerance Hit tolerance in pixels+ */+ bool hitTestSplitter(f32 x, f32 y, f32 tolerance = 4.0f) const;++ // =========================================================================+ // Tree Traversal+ // =========================================================================++ /**+ * @brief Find a node by ID in this subtree+ * @param id Node ID to find+ * @return Node pointer or nullptr+ */+ DockNode* findNode(DockNodeId id);++ /**+ * @brief Find the node containing a specific panel+ * @param panelId Panel ID to search for+ * @return Node pointer or nullptr+ */+ DockNode* findNodeContainingPanel(DockPanelId panelId);++ /**+ * @brief Execute a callback for each leaf (Tabs) node+ * @param callback Function to call+ */+ void forEachLeaf(const std::function<void(DockNode&)>& callback);++ /**+ * @brief Execute a callback for each node (pre-order traversal)+ * @param callback Function to call+ */+ void forEachNode(const std::function<void(DockNode&)>& callback);++ // =========================================================================+ // Validation+ // =========================================================================++ /** @brief Returns true if this is an empty Tabs node */+ bool isEmpty() const { return isTabs() && panels_.empty(); }++ /** @brief Returns true if this is a leaf node (Tabs) */+ bool isLeaf() const { return isTabs(); }++private:+ DockNode(DockNodeId id, DockNodeType type);++ void updateChildParents();+ void layoutSplit(f32 splitterThickness, f32 tabBarHeight);+ void layoutTabs(f32 tabBarHeight);++ DockNodeId id_;+ DockNodeType type_;+ DockNode* parent_ = nullptr;+ DockArea* area_ = nullptr;++ // Split node data+ DockSplitDirection splitDirection_ = DockSplitDirection::Horizontal;+ f32 splitRatio_ = 0.5f;+ Unique<DockNode> first_;+ Unique<DockNode> second_;++ // Tabs node data+ std::vector<Unique<DockPanel>> panels_;+ i32 activeTabIndex_ = 0;++ // Layout+ Rect bounds_;+ Rect contentBounds_;++ friend class DockArea;+};++} // namespace esengine::uidiff --git a/src/esengine/ui/docking/DockPanel.cpp b/src/esengine/ui/docking/DockPanel.cppnew file mode 100644index 000000000..458b87990--- /dev/null+++ b/src/esengine/ui/docking/DockPanel.cpp@@ -0,0 +1,115 @@+/**+ * @file DockPanel.cpp+ * @brief DockPanel implementation+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */++#include "DockPanel.hpp"+#include "DockNode.hpp"+#include "DockArea.hpp"+#include "../UIContext.hpp"+#include "../rendering/UIBatchRenderer.hpp"++namespace esengine::ui {++// =============================================================================+// Static Members+// =============================================================================++DockPanelId DockPanel::nextPanelId_ = 1;++// =============================================================================+// Constructor / Destructor+// =============================================================================++DockPanel::DockPanel(const WidgetId& id, const std::string& title)+ : Widget(id)+ , panelId_(nextPanelId_++)+ , title_(title) {+ setName(title);+}++DockPanel::~DockPanel() = default;++// =============================================================================+// Title+// =============================================================================++void DockPanel::setTitle(const std::string& title) {+ if (title_ != title) {+ title_ = title;+ setName(title);+ onTitleChanged.publish(title_);+ }+}++// =============================================================================+// Dock Context+// =============================================================================++DockArea* DockPanel::getDockArea() const {+ if (ownerNode_) {+ return ownerNode_->getArea();+ }+ return nullptr;+}++// =============================================================================+// Content+// =============================================================================++void DockPanel::setContent(Unique<Widget> content) {+ if (contentWidget_) {+ removeChild(contentWidget_);+ contentWidget_ = nullptr;+ }++ if (content) {+ contentWidget_ = content.get();+ addChild(std::move(content));+ }+}++// =============================================================================+// Widget Overrides+// =============================================================================++glm::vec2 DockPanel::measure(f32 availableWidth, f32 availableHeight) {+ glm::vec2 contentSize = minSize_;++ if (contentWidget_) {+ contentSize = contentWidget_->measure(availableWidth, availableHeight);+ }++ return glm::vec2{+ std::max(contentSize.x, minSize_.x),+ std::max(contentSize.y, minSize_.y)+ };+}++void DockPanel::render(UIBatchRenderer& renderer) {+ UIContext* ctx = getContext();+ if (!ctx) return;++ const Rect& bounds = getBounds();++ WidgetStyle style = ctx->getTheme().getPanelStyle();+ renderer.drawRect(bounds, style.backgroundColor);++ if (contentWidget_) {+ contentWidget_->render(renderer);+ }++ onRenderContent(renderer);+}++void DockPanel::onRenderContent(UIBatchRenderer& renderer) {+ (void)renderer;+}++} // namespace esengine::uidiff --git a/src/esengine/ui/docking/DockPanel.hpp b/src/esengine/ui/docking/DockPanel.hppnew file mode 100644index 000000000..7747fe51b--- /dev/null+++ b/src/esengine/ui/docking/DockPanel.hpp@@ -0,0 +1,192 @@+/**+ * @file DockPanel.hpp+ * @brief Dockable panel base class+ * @details A panel widget that can be docked, tabbed, and dragged+ * within the docking system.+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */+#pragma once++// =============================================================================+// Includes+// =============================================================================++#include "DockTypes.hpp"+#include "../widgets/Widget.hpp"+#include "../../events/Signal.hpp"++#include <string>++namespace esengine::ui {++// Forward declarations+class DockNode;+class DockArea;++// =============================================================================+// DockPanel Class+// =============================================================================++/**+ * @brief A dockable panel that can be moved between dock nodes+ *+ * @details DockPanel is the base class for all dockable panels in the editor.+ * It provides:+ * - A title for the tab bar+ * - Optional icon+ * - Close button support+ * - Content widget container+ *+ * @code+ * class HierarchyPanel : public DockPanel {+ * public:+ * HierarchyPanel()+ * : DockPanel(WidgetId("hierarchy"), "Hierarchy") {+ * setContent(makeUnique<TreeView>(WidgetId("hierarchy.tree")));+ * }+ * };+ * @endcode+ */+class DockPanel : public Widget {+public:+ /**+ * @brief Constructs a dock panel+ * @param id Widget identifier+ * @param title Title displayed in the tab bar+ */+ DockPanel(const WidgetId& id, const std::string& title);++ ~DockPanel() override;++ // =========================================================================+ // Identity+ // =========================================================================++ /** @brief Gets the panel's unique ID */+ DockPanelId getPanelId() const { return panelId_; }++ /** @brief Gets the panel type identifier for serialization */+ const std::string& getPanelType() const { return panelType_; }++ /** @brief Sets the panel type identifier */+ void setPanelType(const std::string& type) { panelType_ = type; }++ // =========================================================================+ // Title+ // =========================================================================++ /** @brief Gets the panel title */+ const std::string& getTitle() const { return title_; }++ /** @brief Sets the panel title */+ void setTitle(const std::string& title);++ // =========================================================================+ // Configuration+ // =========================================================================++ /** @brief Sets whether the panel can be closed */+ void setClosable(bool closable) { closable_ = closable; }++ /** @brief Returns true if the panel can be closed */+ bool isClosable() const { return closable_; }++ /** @brief Sets the minimum panel size */+ void setMinSize(const glm::vec2& minSize) { minSize_ = minSize; }++ /** @brief Gets the minimum panel size */+ glm::vec2 getMinSize() const { return minSize_; }++ // =========================================================================+ // Icon+ // =========================================================================++ /** @brief Sets the icon texture ID (0 for no icon) */+ void setIconTextureId(u32 textureId) { iconTextureId_ = textureId; }++ /** @brief Gets the icon texture ID */+ u32 getIconTextureId() const { return iconTextureId_; }++ // =========================================================================+ // Dock Context+ // =========================================================================++ /** @brief Gets the node that owns this panel */+ DockNode* getOwnerNode() const { return ownerNode_; }++ /** @brief Gets the DockArea containing this panel */+ DockArea* getDockArea() const;++ // =========================================================================+ // Content+ // =========================================================================++ /**+ * @brief Sets the content widget+ * @param content Widget to display (ownership transferred)+ */+ void setContent(Unique<Widget> content);++ /** @brief Gets the content widget */+ Widget* getContent() const { return contentWidget_; }++ // =========================================================================+ // Signals+ // =========================================================================++ /** @brief Emitted when close is requested */+ Signal<void()> onCloseRequested;++ /** @brief Emitted when title changes */+ Signal<void(const std::string&)> onTitleChanged;++ // =========================================================================+ // Widget Overrides+ // =========================================================================++ glm::vec2 measure(f32 availableWidth, f32 availableHeight) override;+ void render(UIBatchRenderer& renderer) override;++protected:+ /**+ * @brief Called to render panel-specific content+ * @param renderer Batch renderer+ *+ * @details Override this for custom panel content instead of using setContent.+ */+ virtual void onRenderContent(UIBatchRenderer& renderer);++ /**+ * @brief Called when the panel becomes active (selected tab)+ */+ virtual void onActivated() {}++ /**+ * @brief Called when the panel becomes inactive (different tab selected)+ */+ virtual void onDeactivated() {}++private:+ static DockPanelId nextPanelId_;++ DockPanelId panelId_;+ std::string panelType_;+ std::string title_;+ bool closable_ = true;+ glm::vec2 minSize_{100.0f, 100.0f};+ u32 iconTextureId_ = 0;++ DockNode* ownerNode_ = nullptr;+ Widget* contentWidget_ = nullptr;++ friend class DockNode;+ friend class DockArea;+ friend class DockTabBar;+};++} // namespace esengine::uidiff --git a/src/esengine/ui/docking/DockTabBar.cpp b/src/esengine/ui/docking/DockTabBar.cppnew file mode 100644index 000000000..5f2501165--- /dev/null+++ b/src/esengine/ui/docking/DockTabBar.cpp@@ -0,0 +1,312 @@+/**+ * @file DockTabBar.cpp+ * @brief DockTabBar implementation+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */++#include "DockTabBar.hpp"+#include "DockNode.hpp"+#include "DockPanel.hpp"+#include "../UIContext.hpp"+#include "../rendering/UIBatchRenderer.hpp"+#include "../font/Font.hpp"++#include <cmath>++namespace esengine::ui {++// =============================================================================+// Constructor / Destructor+// =============================================================================++DockTabBar::DockTabBar(const WidgetId& id, DockNode* ownerNode)+ : Widget(id)+ , ownerNode_(ownerNode) {}++DockTabBar::~DockTabBar() = default;++// =============================================================================+// Tab Data+// =============================================================================++void DockTabBar::updateTabs() {+ tabs_.clear();++ if (!ownerNode_ || !ownerNode_->isTabs()) return;++ i32 activeIndex = ownerNode_->getActiveTabIndex();+ const auto& panels = ownerNode_->getPanels();++ for (usize i = 0; i < panels.size(); ++i) {+ const auto& panel = panels[i];+ if (!panel) continue;++ DockTabInfo tab;+ tab.panelId = panel->getPanelId();+ tab.title = panel->getTitle();+ tab.iconTextureId = panel->getIconTextureId();+ tab.closable = panel->isClosable();+ tab.active = (static_cast<i32>(i) == activeIndex);+ tab.hovered = (static_cast<i32>(i) == hoveredTabIndex_);+ tab.closeHovered = (static_cast<i32>(i) == hoveredCloseIndex_);++ tabs_.push_back(tab);+ }++ layoutTabs();+}++// =============================================================================+// Layout+// =============================================================================++glm::vec2 DockTabBar::measure(f32 availableWidth, f32 availableHeight) {+ (void)availableHeight;+ return {availableWidth, tabHeight_};+}++void DockTabBar::layoutTabs() {+ if (tabs_.empty()) return;++ const Rect& bounds = getBounds();+ f32 totalWidth = bounds.width - tabPadding_ * 2.0f;+ f32 tabWidth = totalWidth / static_cast<f32>(tabs_.size()) - tabSpacing_;+ tabWidth = std::clamp(tabWidth, tabMinWidth_, tabMaxWidth_);++ f32 x = bounds.x + tabPadding_;++ for (auto& tab : tabs_) {+ tab.bounds = Rect{+ x,+ bounds.y,+ tabWidth,+ tabHeight_+ };++ if (tab.closable) {+ f32 closeX = x + tabWidth - closeButtonSize_ - 4.0f;+ f32 closeY = bounds.y + (tabHeight_ - closeButtonSize_) * 0.5f;+ tab.closeButtonBounds = Rect{+ closeX,+ closeY,+ closeButtonSize_,+ closeButtonSize_+ };+ }++ x += tabWidth + tabSpacing_;+ }+}++// =============================================================================+// Rendering+// =============================================================================++void DockTabBar::render(UIBatchRenderer& renderer) {+ UIContext* ctx = getContext();+ if (!ctx) return;++ updateTabs();++ const Rect& bounds = getBounds();+ const Theme& theme = ctx->getTheme();++ renderer.drawRect(bounds, theme.colors.backgroundDark);++ for (usize i = 0; i < tabs_.size(); ++i) {+ renderTab(renderer, tabs_[i], i);+ }+}++void DockTabBar::renderTab(UIBatchRenderer& renderer, const DockTabInfo& tab, usize /*index*/) {+ UIContext* ctx = getContext();+ if (!ctx) return;++ const Theme& theme = ctx->getTheme();+ Font* font = ctx->getDefaultFont();++ glm::vec4 bgColor;+ if (tab.active) {+ bgColor = theme.colors.backgroundLight;+ } else if (tab.hovered) {+ bgColor = theme.colors.backgroundMedium;+ } else {+ bgColor = theme.colors.backgroundDark;+ }++ renderer.drawRect(tab.bounds, bgColor);++ if (tab.active) {+ Rect indicator{+ tab.bounds.x,+ tab.bounds.y + tab.bounds.height - 2.0f,+ tab.bounds.width,+ 2.0f+ };+ renderer.drawRect(indicator, theme.colors.accent);+ }++ if (font) {+ f32 textX = tab.bounds.x + tabPadding_;+ f32 maxTextWidth = tab.bounds.width - tabPadding_ * 2.0f;++ if (tab.closable) {+ maxTextWidth -= closeButtonSize_ + 4.0f;+ }++ glm::vec4 textColor = tab.active ? theme.colors.textPrimary : theme.colors.textSecondary;++ Rect textBounds{+ textX,+ tab.bounds.y,+ maxTextWidth,+ tab.bounds.height+ };++ renderer.drawTextInBounds(tab.title, textBounds, *font, 12.0f, textColor,+ HAlign::Left, VAlign::Center);+ }++ if (tab.closable) {+ glm::vec4 closeColor = tab.closeHovered+ ? theme.colors.error+ : theme.colors.textSecondary;++ f32 cx = tab.closeButtonBounds.x + tab.closeButtonBounds.width * 0.5f;+ f32 cy = tab.closeButtonBounds.y + tab.closeButtonBounds.height * 0.5f;+ f32 size = closeButtonSize_ * 0.3f;++ renderer.drawLine({cx - size, cy - size}, {cx + size, cy + size}, closeColor, 1.5f);+ renderer.drawLine({cx - size, cy + size}, {cx + size, cy - size}, closeColor, 1.5f);+ }+}++// =============================================================================+// Hit Testing+// =============================================================================++i32 DockTabBar::hitTestTab(f32 x, f32 y) const {+ for (usize i = 0; i < tabs_.size(); ++i) {+ if (tabs_[i].bounds.contains({x, y})) {+ return static_cast<i32>(i);+ }+ }+ return -1;+}++i32 DockTabBar::hitTestCloseButton(f32 x, f32 y) const {+ for (usize i = 0; i < tabs_.size(); ++i) {+ if (tabs_[i].closable && tabs_[i].closeButtonBounds.contains({x, y})) {+ return static_cast<i32>(i);+ }+ }+ return -1;+}++void DockTabBar::updateHoverState(f32 x, f32 y) {+ i32 oldHoveredTab = hoveredTabIndex_;+ i32 oldHoveredClose = hoveredCloseIndex_;++ hoveredCloseIndex_ = hitTestCloseButton(x, y);+ hoveredTabIndex_ = hitTestTab(x, y);++ if (hoveredCloseIndex_ != oldHoveredClose || hoveredTabIndex_ != oldHoveredTab) {+ for (usize i = 0; i < tabs_.size(); ++i) {+ tabs_[i].hovered = (static_cast<i32>(i) == hoveredTabIndex_);+ tabs_[i].closeHovered = (static_cast<i32>(i) == hoveredCloseIndex_);+ }+ }+}++// =============================================================================+// Event Handling+// =============================================================================++bool DockTabBar::onMouseDown(const MouseButtonEvent& event) {+ if (event.button != MouseButton::Left) return false;++ i32 closeIndex = hitTestCloseButton(event.x, event.y);+ if (closeIndex >= 0) {+ return true;+ }++ i32 tabIndex = hitTestTab(event.x, event.y);+ if (tabIndex >= 0) {+ pressedTabIndex_ = tabIndex;+ pressStartPos_ = {event.x, event.y};+ potentialDrag_ = true;++ if (ownerNode_) {+ ownerNode_->setActiveTabIndex(tabIndex);+ }+ onTabSelected.publish(tabIndex);+ return true;+ }++ return false;+}++bool DockTabBar::onMouseUp(const MouseButtonEvent& event) {+ if (event.button != MouseButton::Left) return false;++ i32 closeIndex = hitTestCloseButton(event.x, event.y);+ if (closeIndex >= 0 && closeIndex < static_cast<i32>(tabs_.size())) {+ onTabCloseRequested.publish(tabs_[static_cast<usize>(closeIndex)].panelId);+ return true;+ }++ potentialDrag_ = false;+ isDragging_ = false;+ pressedTabIndex_ = -1;++ return false;+}++bool DockTabBar::onMouseMove(const MouseMoveEvent& event) {+ updateHoverState(event.x, event.y);++ if (potentialDrag_ && pressedTabIndex_ >= 0) {+ f32 dx = event.x - pressStartPos_.x;+ f32 dy = event.y - pressStartPos_.y;+ f32 distance = std::sqrt(dx * dx + dy * dy);++ if (distance > dragThreshold_) {+ isDragging_ = true;+ potentialDrag_ = false;++ if (pressedTabIndex_ < static_cast<i32>(tabs_.size())) {+ onTabDragStart.publish(+ tabs_[static_cast<usize>(pressedTabIndex_)].panelId,+ {event.x, event.y}+ );+ }+ }+ }++ return false;+}++bool DockTabBar::onMouseEnter(const MouseEnterEvent& event) {+ updateHoverState(event.x, event.y);+ return false;+}++bool DockTabBar::onMouseLeave(const MouseLeaveEvent& event) {+ (void)event;+ hoveredTabIndex_ = -1;+ hoveredCloseIndex_ = -1;++ for (auto& tab : tabs_) {+ tab.hovered = false;+ tab.closeHovered = false;+ }++ return false;+}++} // namespace esengine::uidiff --git a/src/esengine/ui/docking/DockTabBar.hpp b/src/esengine/ui/docking/DockTabBar.hppnew file mode 100644index 000000000..84a1980c1--- /dev/null+++ b/src/esengine/ui/docking/DockTabBar.hpp@@ -0,0 +1,161 @@+/**+ * @file DockTabBar.hpp+ * @brief Tab bar widget for dock nodes+ * @details Renders tabs for panels in a Tabs node and handles+ * tab selection, drag initiation, and close buttons.+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */+#pragma once++// =============================================================================+// Includes+// =============================================================================++#include "DockTypes.hpp"+#include "../widgets/Widget.hpp"+#include "../../events/Signal.hpp"++#include <string>+#include <vector>++namespace esengine::ui {++// Forward declarations+class DockNode;++// =============================================================================+// DockTabInfo+// =============================================================================++/**+ * @brief Information about a single tab for rendering+ */+struct DockTabInfo {+ DockPanelId panelId = INVALID_DOCK_PANEL_ID;+ std::string title;+ Rect bounds;+ Rect closeButtonBounds;+ u32 iconTextureId = 0;+ bool closable = true;+ bool hovered = false;+ bool active = false;+ bool closeHovered = false;+};++// =============================================================================+// DockTabBar Class+// =============================================================================++/**+ * @brief Tab bar widget for a dock node with tabs+ *+ * @details Renders tab buttons and handles:+ * - Tab selection on click+ * - Close button clicks+ * - Drag initiation for panel reordering/undocking+ */+class DockTabBar : public Widget {+public:+ /**+ * @brief Constructs a tab bar for a dock node+ * @param id Widget identifier+ * @param ownerNode The Tabs node this bar belongs to+ */+ DockTabBar(const WidgetId& id, DockNode* ownerNode);++ ~DockTabBar() override;++ // =========================================================================+ // Configuration+ // =========================================================================++ /** @brief Sets the tab height in pixels */+ void setTabHeight(f32 height) { tabHeight_ = height; invalidateLayout(); }++ /** @brief Gets the tab height */+ f32 getTabHeight() const { return tabHeight_; }++ /** @brief Sets the minimum tab width */+ void setTabMinWidth(f32 width) { tabMinWidth_ = width; }++ /** @brief Sets the maximum tab width */+ void setTabMaxWidth(f32 width) { tabMaxWidth_ = width; }++ /** @brief Sets the drag threshold in pixels */+ void setDragThreshold(f32 pixels) { dragThreshold_ = pixels; }++ // =========================================================================+ // Tab Data+ // =========================================================================++ /** @brief Refresh tab info from owner node */+ void updateTabs();++ /** @brief Gets the tab info list */+ const std::vector<DockTabInfo>& getTabs() const { return tabs_; }++ // =========================================================================+ // Signals+ // =========================================================================++ /** @brief Emitted when a tab is selected (index) */+ Signal<void(i32)> onTabSelected;++ /** @brief Emitted when a tab close is requested (panel ID) */+ Signal<void(DockPanelId)> onTabCloseRequested;++ /** @brief Emitted when tab drag starts (panel ID, position) */+ Signal<void(DockPanelId, glm::vec2)> onTabDragStart;++ /** @brief Emitted when tabs are reordered (from index, to index) */+ Signal<void(i32, i32)> onTabReordered;++ // =========================================================================+ // Widget Overrides+ // =========================================================================++ glm::vec2 measure(f32 availableWidth, f32 availableHeight) override;+ void render(UIBatchRenderer& renderer) override;++ bool onMouseDown(const MouseButtonEvent& event) override;+ bool onMouseUp(const MouseButtonEvent& event) override;+ bool onMouseMove(const MouseMoveEvent& event) override;+ bool onMouseEnter(const MouseEnterEvent& event) override;+ bool onMouseLeave(const MouseLeaveEvent& event) override;++private:+ i32 hitTestTab(f32 x, f32 y) const;+ i32 hitTestCloseButton(f32 x, f32 y) const;+ void layoutTabs();+ void renderTab(UIBatchRenderer& renderer, const DockTabInfo& tab, usize index);+ void updateHoverState(f32 x, f32 y);++ DockNode* ownerNode_;+ std::vector<DockTabInfo> tabs_;++ // Dimensions+ f32 tabHeight_ = 24.0f;+ f32 tabMinWidth_ = 60.0f;+ f32 tabMaxWidth_ = 200.0f;+ f32 tabPadding_ = 8.0f;+ f32 tabSpacing_ = 1.0f;+ f32 closeButtonSize_ = 14.0f;++ // Drag state+ f32 dragThreshold_ = 5.0f;+ bool isDragging_ = false;+ bool potentialDrag_ = false;+ i32 pressedTabIndex_ = -1;+ glm::vec2 pressStartPos_{0.0f};++ // Hover state+ i32 hoveredTabIndex_ = -1;+ i32 hoveredCloseIndex_ = -1;+};++} // namespace esengine::uidiff --git a/src/esengine/ui/docking/DockTypes.hpp b/src/esengine/ui/docking/DockTypes.hppnew file mode 100644index 000000000..883d414db--- /dev/null+++ b/src/esengine/ui/docking/DockTypes.hpp@@ -0,0 +1,119 @@+/**+ * @file DockTypes.hpp+ * @brief Core types and enumerations for the docking system+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */+#pragma once++// =============================================================================+// Includes+// =============================================================================++#include "../../core/Types.hpp"++#include <limits>++namespace esengine::ui {++// =============================================================================+// Type Aliases+// =============================================================================++/** @brief Unique identifier for dock nodes */+using DockNodeId = u32;++/** @brief Invalid dock node ID constant */+constexpr DockNodeId INVALID_DOCK_NODE_ID = 0;++/** @brief Unique identifier for dock panels */+using DockPanelId = u32;++/** @brief Invalid dock panel ID constant */+constexpr DockPanelId INVALID_DOCK_PANEL_ID = 0;++// =============================================================================+// Enumerations+// =============================================================================++/**+ * @brief Direction for splitting dock nodes+ */+enum class DockSplitDirection : u8 {+ Horizontal, ///< Left | Right split+ Vertical ///< Top / Bottom split+};++/**+ * @brief Type of node in the dock tree+ */+enum class DockNodeType : u8 {+ Split, ///< Node with two children divided by a splitter+ Tabs ///< Node with one or more panels in tabs+};++/**+ * @brief Drop zone positions for drag-and-drop docking+ */+enum class DockDropZone : u8 {+ None, ///< No valid drop zone+ Left, ///< Dock to the left edge+ Right, ///< Dock to the right edge+ Top, ///< Dock to the top edge+ Bottom, ///< Dock to the bottom edge+ Center, ///< Tab into existing container+ Root ///< Dock to window edge (root level)+};++/**+ * @brief State of a dock tab+ */+enum class DockTabState : u8 {+ Normal, ///< Default state+ Hovered, ///< Mouse hovering over tab+ Active, ///< Currently selected tab+ Dragging ///< Tab is being dragged+};++// =============================================================================+// Utility Functions+// =============================================================================++/**+ * @brief Get the opposite split direction+ */+inline constexpr DockSplitDirection oppositeSplitDirection(DockSplitDirection dir) {+ return dir == DockSplitDirection::Horizontal+ ? DockSplitDirection::Vertical+ : DockSplitDirection::Horizontal;+}++/**+ * @brief Check if a drop zone creates a split+ */+inline constexpr bool isEdgeDropZone(DockDropZone zone) {+ return zone == DockDropZone::Left || zone == DockDropZone::Right ||+ zone == DockDropZone::Top || zone == DockDropZone::Bottom;+}++/**+ * @brief Get the split direction for an edge drop zone+ */+inline constexpr DockSplitDirection dropZoneToSplitDirection(DockDropZone zone) {+ return (zone == DockDropZone::Left || zone == DockDropZone::Right)+ ? DockSplitDirection::Horizontal+ : DockSplitDirection::Vertical;+}++/**+ * @brief Check if the drop zone inserts before (first child) or after (second child)+ */+inline constexpr bool dropZoneIsFirst(DockDropZone zone) {+ return zone == DockDropZone::Left || zone == DockDropZone::Top;+}++} // namespace esengine::uidiff --git a/src/esengine/ui/docking/DockZone.cpp b/src/esengine/ui/docking/DockZone.cppnew file mode 100644index 000000000..1eb0ca5a6--- /dev/null+++ b/src/esengine/ui/docking/DockZone.cpp@@ -0,0 +1,297 @@+/**+ * @file DockZone.cpp+ * @brief DockZoneDetector implementation+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */++#include "DockZone.hpp"+#include "DockArea.hpp"+#include "DockNode.hpp"+#include "DockPanel.hpp"+#include "../UIContext.hpp"+#include "../rendering/UIBatchRenderer.hpp"++namespace esengine::ui {++// =============================================================================+// Constructor+// =============================================================================++DockZoneDetector::DockZoneDetector(DockArea* area)+ : area_(area) {}++// =============================================================================+// Drag Operations+// =============================================================================++void DockZoneDetector::beginDrag(DockPanel* panel, const glm::vec2& startPos) {+ draggedPanel_ = panel;+ dragStartPos_ = startPos;+ dragCurrentPos_ = startPos;+ dragging_ = true;+ currentTarget_ = {};+ zoneOverlays_.clear();+}++void DockZoneDetector::updateDrag(const glm::vec2& pos) {+ if (!dragging_) return;++ dragCurrentPos_ = pos;++ DockNode* targetNode = nullptr;+ DockDropZone zone = detectZoneAtPosition(pos, targetNode);++ currentTarget_.zone = zone;+ currentTarget_.targetNode = targetNode;++ if (zone != DockDropZone::None && targetNode) {+ currentTarget_.previewBounds = calculatePreviewBounds(currentTarget_);+ calculateZoneOverlays(targetNode);+ } else {+ zoneOverlays_.clear();+ }+}++DockDropTarget DockZoneDetector::endDrag() {+ DockDropTarget result = currentTarget_;+ dragging_ = false;+ draggedPanel_ = nullptr;+ currentTarget_ = {};+ zoneOverlays_.clear();+ return result;+}++void DockZoneDetector::cancelDrag() {+ dragging_ = false;+ draggedPanel_ = nullptr;+ currentTarget_ = {};+ zoneOverlays_.clear();+}++// =============================================================================+// Zone Detection+// =============================================================================++DockDropZone DockZoneDetector::detectZoneAtPosition(const glm::vec2& pos, DockNode*& outNode) {+ outNode = nullptr;++ if (!area_) return DockDropZone::None;++ DockNode* root = area_->getRootNode();+ if (!root) return DockDropZone::None;++ DockNode* hitNode = nullptr;+ root->forEachLeaf([&](DockNode& node) {+ if (node.getBounds().contains(pos)) {+ hitNode = &node;+ }+ });++ if (!hitNode) {+ if (root->getBounds().contains(pos)) {+ hitNode = root;+ } else {+ return DockDropZone::None;+ }+ }++ outNode = hitNode;+ const Rect& bounds = hitNode->getBounds();++ f32 relX = (pos.x - bounds.x) / bounds.width;+ f32 relY = (pos.y - bounds.y) / bounds.height;++ if (relX < edgeThreshold_) return DockDropZone::Left;+ if (relX > (1.0f - edgeThreshold_)) return DockDropZone::Right;+ if (relY < edgeThreshold_) return DockDropZone::Top;+ if (relY > (1.0f - edgeThreshold_)) return DockDropZone::Bottom;++ return DockDropZone::Center;+}++// =============================================================================+// Zone Overlays+// =============================================================================++void DockZoneDetector::calculateZoneOverlays(DockNode* targetNode) {+ zoneOverlays_.clear();++ if (!targetNode) return;++ const Rect& bounds = targetNode->getBounds();+ f32 cx = bounds.x + bounds.width * 0.5f;+ f32 cy = bounds.y + bounds.height * 0.5f;+ f32 halfZone = zoneSize_ * 0.5f;+ f32 offset = zoneSize_ + 4.0f;++ DockZoneOverlay centerOverlay;+ centerOverlay.zone = DockDropZone::Center;+ centerOverlay.bounds = Rect{cx - halfZone, cy - halfZone, zoneSize_, zoneSize_};+ centerOverlay.hovered = (currentTarget_.zone == DockDropZone::Center);+ zoneOverlays_.push_back(centerOverlay);++ DockZoneOverlay leftOverlay;+ leftOverlay.zone = DockDropZone::Left;+ leftOverlay.bounds = Rect{cx - halfZone - offset, cy - halfZone, zoneSize_, zoneSize_};+ leftOverlay.hovered = (currentTarget_.zone == DockDropZone::Left);+ zoneOverlays_.push_back(leftOverlay);++ DockZoneOverlay rightOverlay;+ rightOverlay.zone = DockDropZone::Right;+ rightOverlay.bounds = Rect{cx + halfZone + 4.0f, cy - halfZone, zoneSize_, zoneSize_};+ rightOverlay.hovered = (currentTarget_.zone == DockDropZone::Right);+ zoneOverlays_.push_back(rightOverlay);++ DockZoneOverlay topOverlay;+ topOverlay.zone = DockDropZone::Top;+ topOverlay.bounds = Rect{cx - halfZone, cy - halfZone - offset, zoneSize_, zoneSize_};+ topOverlay.hovered = (currentTarget_.zone == DockDropZone::Top);+ zoneOverlays_.push_back(topOverlay);++ DockZoneOverlay bottomOverlay;+ bottomOverlay.zone = DockDropZone::Bottom;+ bottomOverlay.bounds = Rect{cx - halfZone, cy + halfZone + 4.0f, zoneSize_, zoneSize_};+ bottomOverlay.hovered = (currentTarget_.zone == DockDropZone::Bottom);+ zoneOverlays_.push_back(bottomOverlay);+}++Rect DockZoneDetector::calculatePreviewBounds(const DockDropTarget& target) {+ if (!target.targetNode) return {};++ const Rect& bounds = target.targetNode->getBounds();+ f32 ratio = target.splitRatio;++ switch (target.zone) {+ case DockDropZone::Left:+ return Rect{bounds.x, bounds.y, bounds.width * ratio, bounds.height};++ case DockDropZone::Right:+ return Rect{+ bounds.x + bounds.width * (1.0f - ratio),+ bounds.y,+ bounds.width * ratio,+ bounds.height+ };++ case DockDropZone::Top:+ return Rect{bounds.x, bounds.y, bounds.width, bounds.height * ratio};++ case DockDropZone::Bottom:+ return Rect{+ bounds.x,+ bounds.y + bounds.height * (1.0f - ratio),+ bounds.width,+ bounds.height * ratio+ };++ case DockDropZone::Center:+ return bounds;++ default:+ return {};+ }+}++// =============================================================================+// Rendering+// =============================================================================++void DockZoneDetector::render(UIBatchRenderer& renderer) {+ if (!dragging_) return;++ renderDropPreview(renderer);+ renderZoneOverlays(renderer);+}++void DockZoneDetector::renderDropPreview(UIBatchRenderer& renderer) {+ if (currentTarget_.zone == DockDropZone::None) return;++ UIContext* ctx = area_ ? area_->getContext() : nullptr;+ if (!ctx) return;++ glm::vec4 previewColor = ctx->getTheme().colors.accent;+ previewColor.a = previewAlpha_;++ renderer.drawRect(currentTarget_.previewBounds, previewColor);+}++void DockZoneDetector::renderZoneOverlays(UIBatchRenderer& renderer) {+ for (const auto& overlay : zoneOverlays_) {+ renderZoneButton(renderer, overlay);+ }+}++void DockZoneDetector::renderZoneButton(UIBatchRenderer& renderer, const DockZoneOverlay& overlay) {+ UIContext* ctx = area_ ? area_->getContext() : nullptr;+ if (!ctx) return;++ const Theme& theme = ctx->getTheme();++ glm::vec4 bgColor = overlay.hovered+ ? theme.colors.accent+ : glm::vec4{0.3f, 0.3f, 0.3f, 0.9f};++ glm::vec4 borderColor = theme.colors.accent;++ renderer.drawRoundedRect(overlay.bounds, bgColor, CornerRadii::all(4.0f));+ renderer.drawRoundedRectOutline(overlay.bounds, borderColor, CornerRadii::all(4.0f), 1.0f);++ glm::vec4 iconColor = overlay.hovered+ ? theme.colors.textPrimary+ : theme.colors.textSecondary;++ f32 cx = overlay.bounds.x + overlay.bounds.width * 0.5f;+ f32 cy = overlay.bounds.y + overlay.bounds.height * 0.5f;+ f32 iconSize = zoneSize_ * 0.4f;+ f32 halfIcon = iconSize * 0.5f;++ switch (overlay.zone) {+ case DockDropZone::Center: {+ Rect iconRect{cx - halfIcon, cy - halfIcon, iconSize, iconSize};+ renderer.drawRoundedRectOutline(iconRect, iconColor, CornerRadii::all(2.0f), 1.5f);+ break;+ }++ case DockDropZone::Left: {+ Rect leftRect{cx - halfIcon, cy - halfIcon, iconSize * 0.4f, iconSize};+ renderer.drawRect(leftRect, iconColor);+ Rect rightRect{cx - halfIcon + iconSize * 0.5f, cy - halfIcon, iconSize * 0.5f, iconSize};+ renderer.drawRoundedRectOutline(rightRect, iconColor, CornerRadii::all(1.0f), 1.0f);+ break;+ }++ case DockDropZone::Right: {+ Rect leftRect{cx - halfIcon, cy - halfIcon, iconSize * 0.5f, iconSize};+ renderer.drawRoundedRectOutline(leftRect, iconColor, CornerRadii::all(1.0f), 1.0f);+ Rect rightRect{cx + halfIcon - iconSize * 0.4f, cy - halfIcon, iconSize * 0.4f, iconSize};+ renderer.drawRect(rightRect, iconColor);+ break;+ }++ case DockDropZone::Top: {+ Rect topRect{cx - halfIcon, cy - halfIcon, iconSize, iconSize * 0.4f};+ renderer.drawRect(topRect, iconColor);+ Rect bottomRect{cx - halfIcon, cy - halfIcon + iconSize * 0.5f, iconSize, iconSize * 0.5f};+ renderer.drawRoundedRectOutline(bottomRect, iconColor, CornerRadii::all(1.0f), 1.0f);+ break;+ }++ case DockDropZone::Bottom: {+ Rect topRect{cx - halfIcon, cy - halfIcon, iconSize, iconSize * 0.5f};+ renderer.drawRoundedRectOutline(topRect, iconColor, CornerRadii::all(1.0f), 1.0f);+ Rect bottomRect{cx - halfIcon, cy + halfIcon - iconSize * 0.4f, iconSize, iconSize * 0.4f};+ renderer.drawRect(bottomRect, iconColor);+ break;+ }++ default:+ break;+ }+}++} // namespace esengine::uidiff --git a/src/esengine/ui/docking/DockZone.hpp b/src/esengine/ui/docking/DockZone.hppnew file mode 100644index 000000000..7d742243e--- /dev/null+++ b/src/esengine/ui/docking/DockZone.hpp@@ -0,0 +1,172 @@+/**+ * @file DockZone.hpp+ * @brief Drop zone detection for docking drag-and-drop+ * @details Handles detection of drop zones and rendering of+ * drop zone indicators and preview.+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */+#pragma once++// =============================================================================+// Includes+// =============================================================================++#include "DockTypes.hpp"+#include "../core/Types.hpp"++#include <glm/glm.hpp>++#include <vector>++namespace esengine::ui {++// Forward declarations+class DockNode;+class DockPanel;+class DockArea;+class UIBatchRenderer;++// =============================================================================+// DockDropTarget+// =============================================================================++/**+ * @brief Information about a potential drop target+ */+struct DockDropTarget {+ DockDropZone zone = DockDropZone::None;+ DockNode* targetNode = nullptr;+ Rect previewBounds;+ f32 splitRatio = 0.3f;+};++// =============================================================================+// DockZoneOverlay+// =============================================================================++/**+ * @brief Visual overlay for a dock zone indicator+ */+struct DockZoneOverlay {+ Rect bounds;+ DockDropZone zone;+ bool hovered = false;+};++// =============================================================================+// DockZoneDetector Class+// =============================================================================++/**+ * @brief Detects drop zones and renders drag feedback+ *+ * @details During a drag operation, the detector:+ * - Tracks the current mouse position+ * - Determines valid drop zones based on cursor location+ * - Calculates preview bounds for visual feedback+ * - Renders zone indicators and drop preview+ */+class DockZoneDetector {+public:+ /**+ * @brief Constructs a zone detector for a dock area+ * @param area The owning DockArea+ */+ explicit DockZoneDetector(DockArea* area);++ // =========================================================================+ // Drag Operations+ // =========================================================================++ /**+ * @brief Begin a drag operation+ * @param panel The panel being dragged+ * @param startPos Initial mouse position+ */+ void beginDrag(DockPanel* panel, const glm::vec2& startPos);++ /**+ * @brief Update drag with current mouse position+ * @param pos Current mouse position+ */+ void updateDrag(const glm::vec2& pos);++ /**+ * @brief End drag and return the final drop target+ * @return Drop target (zone may be None if cancelled)+ */+ DockDropTarget endDrag();++ /**+ * @brief Cancel the current drag operation+ */+ void cancelDrag();++ /** @brief Returns true if currently dragging */+ bool isDragging() const { return dragging_; }++ /** @brief Gets the panel being dragged */+ DockPanel* getDraggedPanel() const { return draggedPanel_; }++ // =========================================================================+ // Target Information+ // =========================================================================++ /** @brief Gets the current drop target */+ const DockDropTarget& getCurrentTarget() const { return currentTarget_; }++ /** @brief Gets all zone overlays for rendering */+ const std::vector<DockZoneOverlay>& getZoneOverlays() const { return zoneOverlays_; }++ // =========================================================================+ // Rendering+ // =========================================================================++ /**+ * @brief Render drop zone indicators and preview+ * @param renderer UI batch renderer+ */+ void render(UIBatchRenderer& renderer);++ // =========================================================================+ // Configuration+ // =========================================================================++ /** @brief Sets the zone indicator button size */+ void setZoneSize(f32 size) { zoneSize_ = size; }++ /** @brief Sets the preview overlay opacity */+ void setPreviewAlpha(f32 alpha) { previewAlpha_ = alpha; }++ /** @brief Sets the edge detection threshold (fraction of node size) */+ void setEdgeThreshold(f32 threshold) { edgeThreshold_ = threshold; }++private:+ DockDropZone detectZoneAtPosition(const glm::vec2& pos, DockNode*& outNode);+ void calculateZoneOverlays(DockNode* targetNode);+ Rect calculatePreviewBounds(const DockDropTarget& target);+ void renderZoneOverlays(UIBatchRenderer& renderer);+ void renderDropPreview(UIBatchRenderer& renderer);+ void renderZoneButton(UIBatchRenderer& renderer, const DockZoneOverlay& overlay);++ DockArea* area_;+ DockPanel* draggedPanel_ = nullptr;+ bool dragging_ = false;++ glm::vec2 dragStartPos_{0.0f};+ glm::vec2 dragCurrentPos_{0.0f};++ DockDropTarget currentTarget_;+ std::vector<DockZoneOverlay> zoneOverlays_;++ f32 zoneSize_ = 32.0f;+ f32 previewAlpha_ = 0.3f;+ f32 edgeThreshold_ = 0.3f;+};++} // namespace esengine::ui