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
fix: Resolve dock panel drag-and-drop not working
esengine57b9e95dbb83
diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.jsonindex 8cf6a9392..6579b3692 100644--- a/.vscode/c_cpp_properties.json+++ b/.vscode/c_cpp_properties.json@@ -8,18 +8,20 @@"${workspaceFolder}/third_party/glm","${workspaceFolder}/third_party/glfw/include","${workspaceFolder}/third_party/glad/include",- "${workspaceFolder}/third_party/stb"+ "${workspaceFolder}/third_party/stb",+ "${workspaceFolder}/build/quickjs_headers"],"defines": ["_DEBUG","ES_PLATFORM_NATIVE","ES_PLATFORM_WINDOWS",- "ES_DEBUG"+ "ES_DEBUG",+ "ES_SCRIPTING_ENABLED"],"cStandard": "c17","cppStandard": "c++20",- "intelliSenseMode": "windows-msvc-x64",- "compilerPath": "cl.exe"+ "intelliSenseMode": "windows-gcc-x64",+ "compileCommands": "${workspaceFolder}/build/compile_commands.json"}],"version": 4diff --git a/src/esengine/ui/docking/DockArea.cpp b/src/esengine/ui/docking/DockArea.cppindex d25a4ade7..fb138470f 100644--- a/src/esengine/ui/docking/DockArea.cpp+++ b/src/esengine/ui/docking/DockArea.cpp@@ -126,8 +126,18 @@ void DockArea::movePanel(DockPanel* panel, const DockDropTarget& target) {if (!detachedPanel) return;if (target.zone == DockDropZone::Center) {- if (target.targetNode && target.targetNode->isTabs()) {- target.targetNode->addPanel(std::move(detachedPanel));+ if (target.targetNode) {+ if (target.targetNode->isTabs()) {+ target.targetNode->addPanel(std::move(detachedPanel));+ } else {+ DockNode* leaf = nullptr;+ target.targetNode->forEachLeaf([&](DockNode& node) {+ if (!leaf) leaf = &node;+ });+ if (leaf) {+ leaf->addPanel(std::move(detachedPanel));+ }+ }}} else if (isEdgeDropZone(target.zone)) {DockSplitDirection dir = dropZoneToSplitDirection(target.zone);@@ -404,8 +414,8 @@ bool DockArea::onMouseUp(const MouseButtonEvent& event) {if (event.button != MouseButton::Left) return false;if (zoneDetector_.isDragging()) {- DockDropTarget target = zoneDetector_.endDrag();DockPanel* panel = zoneDetector_.getDraggedPanel();+ DockDropTarget target = zoneDetector_.endDrag();if (panel && target.zone != DockDropZone::None) {movePanel(panel, target);}diff --git a/src/esengine/ui/docking/DockTabBar.cpp b/src/esengine/ui/docking/DockTabBar.cppindex 1085a428e..ecaa3da55 100644--- a/src/esengine/ui/docking/DockTabBar.cpp+++ b/src/esengine/ui/docking/DockTabBar.cpp@@ -128,7 +128,6 @@ void DockTabBar::renderTab(UIBatchRenderer& renderer, const DockTabInfo& tab, usif (!ctx) return;const Theme& theme = ctx->getTheme();- Font* font = ctx->getDefaultFont();glm::vec4 bgColor;if (tab.active) {@@ -151,23 +150,24 @@ void DockTabBar::renderTab(UIBatchRenderer& renderer, const DockTabInfo& tab, usrenderer.drawRect(indicator, theme.colors.accent);}- if (font) {- f32 textX = tab.bounds.x + tabPadding_;- f32 maxTextWidth = tab.bounds.width - tabPadding_ * 2.0f;+ f32 textX = tab.bounds.x + tabPadding_;+ f32 maxTextWidth = tab.bounds.width - tabPadding_ * 2.0f;- if (tab.closable) {- maxTextWidth -= closeButtonSize_ + 4.0f;- }+ if (tab.closable) {+ maxTextWidth -= closeButtonSize_ + 4.0f;+ }- glm::vec4 textColor = tab.active ? theme.colors.textPrimary : theme.colors.textSecondary;+ glm::vec4 textColor = tab.active ? theme.colors.textPrimary : theme.colors.textSecondary;- Rect textBounds{- textX,- tab.bounds.y,- maxTextWidth,- tab.bounds.height- };+ Rect textBounds{+ textX,+ tab.bounds.y,+ maxTextWidth,+ tab.bounds.height+ };+ Font* font = ctx->getDefaultFont();+ if (font) {renderer.drawTextInBounds(tab.title, textBounds, *font,theme.typography.fontSizeNormal, textColor,HAlign::Left, VAlign::Center);diff --git a/src/esengine/ui/rendering/UIBatchRenderer.cpp b/src/esengine/ui/rendering/UIBatchRenderer.cppindex 3de65ba72..b09b59a52 100644--- a/src/esengine/ui/rendering/UIBatchRenderer.cpp+++ b/src/esengine/ui/rendering/UIBatchRenderer.cpp@@ -60,6 +60,7 @@ struct UIVertex {f32 borderThickness;};+// =============================================================================// Shader Sources// =============================================================================diff --git a/src/esengine/ui/widgets/Button.cpp b/src/esengine/ui/widgets/Button.cppindex 7ec7cd5c2..e5af74f1a 100644--- a/src/esengine/ui/widgets/Button.cpp+++ b/src/esengine/ui/widgets/Button.cpp@@ -57,8 +57,8 @@ glm::vec2 Button::measure(f32 availableWidth, f32 availableHeight) {? ctx->getTheme().getPrimaryButtonStyle(): ctx->getTheme().getButtonStyle();+ // Use regular font for measurementFont* font = fontName_.empty() ? ctx->getDefaultFont() : ctx->getFont(fontName_);-if (font && textSizeDirty_) {cachedTextSize_ = font->measureText(text_, fontSize_);textSizeDirty_ = false;@@ -113,11 +113,12 @@ void Button::render(UIBatchRenderer& renderer) {}if (!text_.empty()) {+ glm::vec4 textColor = style.getTextColor(state);+ Rect textBounds = style.padding.shrink(bounds);++ // Use regular font for nowFont* font = fontName_.empty() ? ctx->getDefaultFont() : ctx->getFont(fontName_);if (font) {- glm::vec4 textColor = style.getTextColor(state);- Rect textBounds = style.padding.shrink(bounds);-renderer.drawTextInBounds(text_, textBounds, *font, fontSize_, textColor,HAlign::Center, VAlign::Center);}diff --git a/src/esengine/ui/widgets/Checkbox.cpp b/src/esengine/ui/widgets/Checkbox.cppindex 7233d5989..88f453fdc 100644--- a/src/esengine/ui/widgets/Checkbox.cpp+++ b/src/esengine/ui/widgets/Checkbox.cpp@@ -11,6 +11,7 @@#include "Checkbox.hpp"#include "../UIContext.hpp"+#include "../font/Font.hpp"#include "../rendering/UIBatchRenderer.hpp"#include "../../math/Math.hpp"@@ -75,13 +76,17 @@ glm::vec2 Checkbox::measure(f32 availableWidth, f32 availableHeight) {f32 width = checkboxSize_;f32 height = checkboxSize_;- if (!label_.empty() && getContext() && getContext()->getDefaultFont()) {- f32 fontSize = 14.0f;- if (getContext()) {- fontSize = getContext()->getTheme().typography.fontSizeNormal;- }+ if (!label_.empty() && getContext()) {+ f32 fontSize = getContext()->getTheme().typography.fontSizeNormal;- f32 labelWidth = static_cast<f32>(label_.length()) * fontSize * 0.6f;+ // Use regular font for measurement+ Font* font = getContext()->getDefaultFont();+ f32 labelWidth;+ if (font) {+ labelWidth = font->measureText(label_, fontSize).x;+ } else {+ labelWidth = static_cast<f32>(label_.length()) * fontSize * 0.6f;+ }width += LABEL_SPACING + labelWidth;height = glm::max(height, fontSize);}diff --git a/src/esengine/ui/widgets/Label.cpp b/src/esengine/ui/widgets/Label.cppindex b93099f71..5c14ea26c 100644--- a/src/esengine/ui/widgets/Label.cpp+++ b/src/esengine/ui/widgets/Label.cpp@@ -83,15 +83,14 @@ void Label::render(UIBatchRenderer& renderer) {UIContext* ctx = getContext();if (!ctx) return;- Font* font = fontName_.empty() ? ctx->getDefaultFont() : ctx->getFont(fontName_);- if (!font) return;-WidgetStyle style = ctx->getTheme().getLabelStyle();glm::vec4 textColor = customColor_ ? color_ : style.getTextColor(getState());-Rect contentBounds = getContentBounds();- renderer.drawTextInBounds(text_, contentBounds, *font, fontSize_, textColor, hAlign_, vAlign_);+ Font* font = fontName_.empty() ? ctx->getDefaultFont() : ctx->getFont(fontName_);+ if (font) {+ renderer.drawTextInBounds(text_, contentBounds, *font, fontSize_, textColor, hAlign_, vAlign_);+ }}} // namespace esengine::uidiff --git a/src/esengine/ui/widgets/TextField.cpp b/src/esengine/ui/widgets/TextField.cppindex fe0fd15d2..c5cf37c8e 100644--- a/src/esengine/ui/widgets/TextField.cpp+++ b/src/esengine/ui/widgets/TextField.cpp@@ -11,6 +11,7 @@#include "TextField.hpp"#include "../UIContext.hpp"+#include "../font/Font.hpp"#include "../rendering/UIBatchRenderer.hpp"#include "../../core/Log.hpp"#include "../../math/Math.hpp"@@ -499,7 +500,7 @@ void TextField::cutToClipboard() {}usize TextField::getCharIndexAtX(f32 x) const {- if (!getContext() || !getContext()->getDefaultFont()) {+ if (!getContext()) {return 0;}@@ -512,14 +513,19 @@ usize TextField::getCharIndexAtX(f32 x) const {return 0;}- f32 fontSize = 14.0f;- if (getContext()) {- fontSize = getContext()->getTheme().typography.fontSizeNormal;- }+ f32 fontSize = getContext()->getTheme().typography.fontSizeNormal;++ // Use regular font for character measurement+ Font* font = getContext()->getDefaultFont();f32 currentX = 0.0f;for (usize i = 0; i < text_.size(); ++i) {- f32 charWidth = fontSize * 0.6f;+ f32 charWidth;+ if (font) {+ charWidth = font->getCharWidth(static_cast<u32>(text_[i]), fontSize);+ } else {+ charWidth = fontSize * 0.6f;+ }if (relativeX < currentX + charWidth * 0.5f) {return i;@@ -536,9 +542,17 @@ f32 TextField::getXForCharIndex(usize index) const {return 0.0f;}- f32 fontSize = 14.0f;- if (getContext()) {- fontSize = getContext()->getTheme().typography.fontSizeNormal;+ f32 fontSize = getContext()->getTheme().typography.fontSizeNormal;++ // Use regular font for character measurement+ Font* font = getContext()->getDefaultFont();++ if (font) {+ f32 currentX = 0.0f;+ for (usize i = 0; i < index && i < text_.size(); ++i) {+ currentX += font->getCharWidth(static_cast<u32>(text_[i]), fontSize);+ }+ return currentX;}f32 charWidth = fontSize * 0.6f;diff --git a/src/esengine/ui/widgets/TreeView.cpp b/src/esengine/ui/widgets/TreeView.cppindex 967c6b5f2..e20c05c1a 100644--- a/src/esengine/ui/widgets/TreeView.cpp+++ b/src/esengine/ui/widgets/TreeView.cpp@@ -11,6 +11,7 @@#include "TreeView.hpp"#include "../UIContext.hpp"+#include "../font/Font.hpp"#include "../rendering/UIBatchRenderer.hpp"#include "../../core/Log.hpp"#include "../../math/Math.hpp"