Skip to content

Commit bda85d7

Browse files
committed
fix: Resolve dock panel drag-and-drop not working
- Fix onMouseUp call order: get panel before calling endDrag() - Add fallback logic in movePanel for non-Tabs target nodes - Remove MSDF font rendering code (unused) - Clean up related includes and dependencies
1 parent 8525bde commit bda85d7

9 files changed

Lines changed: 78 additions & 45 deletions

File tree

.vscode/c_cpp_properties.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,20 @@
88
"${workspaceFolder}/third_party/glm",
99
"${workspaceFolder}/third_party/glfw/include",
1010
"${workspaceFolder}/third_party/glad/include",
11-
"${workspaceFolder}/third_party/stb"
11+
"${workspaceFolder}/third_party/stb",
12+
"${workspaceFolder}/build/quickjs_headers"
1213
],
1314
"defines": [
1415
"_DEBUG",
1516
"ES_PLATFORM_NATIVE",
1617
"ES_PLATFORM_WINDOWS",
17-
"ES_DEBUG"
18+
"ES_DEBUG",
19+
"ES_SCRIPTING_ENABLED"
1820
],
1921
"cStandard": "c17",
2022
"cppStandard": "c++20",
21-
"intelliSenseMode": "windows-msvc-x64",
22-
"compilerPath": "cl.exe"
23+
"intelliSenseMode": "windows-gcc-x64",
24+
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
2325
}
2426
],
2527
"version": 4

src/esengine/ui/docking/DockArea.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,18 @@ void DockArea::movePanel(DockPanel* panel, const DockDropTarget& target) {
126126
if (!detachedPanel) return;
127127

128128
if (target.zone == DockDropZone::Center) {
129-
if (target.targetNode && target.targetNode->isTabs()) {
130-
target.targetNode->addPanel(std::move(detachedPanel));
129+
if (target.targetNode) {
130+
if (target.targetNode->isTabs()) {
131+
target.targetNode->addPanel(std::move(detachedPanel));
132+
} else {
133+
DockNode* leaf = nullptr;
134+
target.targetNode->forEachLeaf([&](DockNode& node) {
135+
if (!leaf) leaf = &node;
136+
});
137+
if (leaf) {
138+
leaf->addPanel(std::move(detachedPanel));
139+
}
140+
}
131141
}
132142
} else if (isEdgeDropZone(target.zone)) {
133143
DockSplitDirection dir = dropZoneToSplitDirection(target.zone);
@@ -404,8 +414,8 @@ bool DockArea::onMouseUp(const MouseButtonEvent& event) {
404414
if (event.button != MouseButton::Left) return false;
405415

406416
if (zoneDetector_.isDragging()) {
407-
DockDropTarget target = zoneDetector_.endDrag();
408417
DockPanel* panel = zoneDetector_.getDraggedPanel();
418+
DockDropTarget target = zoneDetector_.endDrag();
409419
if (panel && target.zone != DockDropZone::None) {
410420
movePanel(panel, target);
411421
}

src/esengine/ui/docking/DockTabBar.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ void DockTabBar::renderTab(UIBatchRenderer& renderer, const DockTabInfo& tab, us
128128
if (!ctx) return;
129129

130130
const Theme& theme = ctx->getTheme();
131-
Font* font = ctx->getDefaultFont();
132131

133132
glm::vec4 bgColor;
134133
if (tab.active) {
@@ -151,23 +150,24 @@ void DockTabBar::renderTab(UIBatchRenderer& renderer, const DockTabInfo& tab, us
151150
renderer.drawRect(indicator, theme.colors.accent);
152151
}
153152

154-
if (font) {
155-
f32 textX = tab.bounds.x + tabPadding_;
156-
f32 maxTextWidth = tab.bounds.width - tabPadding_ * 2.0f;
153+
f32 textX = tab.bounds.x + tabPadding_;
154+
f32 maxTextWidth = tab.bounds.width - tabPadding_ * 2.0f;
157155

158-
if (tab.closable) {
159-
maxTextWidth -= closeButtonSize_ + 4.0f;
160-
}
156+
if (tab.closable) {
157+
maxTextWidth -= closeButtonSize_ + 4.0f;
158+
}
161159

162-
glm::vec4 textColor = tab.active ? theme.colors.textPrimary : theme.colors.textSecondary;
160+
glm::vec4 textColor = tab.active ? theme.colors.textPrimary : theme.colors.textSecondary;
163161

164-
Rect textBounds{
165-
textX,
166-
tab.bounds.y,
167-
maxTextWidth,
168-
tab.bounds.height
169-
};
162+
Rect textBounds{
163+
textX,
164+
tab.bounds.y,
165+
maxTextWidth,
166+
tab.bounds.height
167+
};
170168

169+
Font* font = ctx->getDefaultFont();
170+
if (font) {
171171
renderer.drawTextInBounds(tab.title, textBounds, *font,
172172
theme.typography.fontSizeNormal, textColor,
173173
HAlign::Left, VAlign::Center);

src/esengine/ui/rendering/UIBatchRenderer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct UIVertex {
6060
f32 borderThickness;
6161
};
6262

63+
6364
// =============================================================================
6465
// Shader Sources
6566
// =============================================================================

src/esengine/ui/widgets/Button.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ glm::vec2 Button::measure(f32 availableWidth, f32 availableHeight) {
5757
? ctx->getTheme().getPrimaryButtonStyle()
5858
: ctx->getTheme().getButtonStyle();
5959

60+
// Use regular font for measurement
6061
Font* font = fontName_.empty() ? ctx->getDefaultFont() : ctx->getFont(fontName_);
61-
6262
if (font && textSizeDirty_) {
6363
cachedTextSize_ = font->measureText(text_, fontSize_);
6464
textSizeDirty_ = false;
@@ -113,11 +113,12 @@ void Button::render(UIBatchRenderer& renderer) {
113113
}
114114

115115
if (!text_.empty()) {
116+
glm::vec4 textColor = style.getTextColor(state);
117+
Rect textBounds = style.padding.shrink(bounds);
118+
119+
// Use regular font for now
116120
Font* font = fontName_.empty() ? ctx->getDefaultFont() : ctx->getFont(fontName_);
117121
if (font) {
118-
glm::vec4 textColor = style.getTextColor(state);
119-
Rect textBounds = style.padding.shrink(bounds);
120-
121122
renderer.drawTextInBounds(text_, textBounds, *font, fontSize_, textColor,
122123
HAlign::Center, VAlign::Center);
123124
}

src/esengine/ui/widgets/Checkbox.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "Checkbox.hpp"
1313
#include "../UIContext.hpp"
14+
#include "../font/Font.hpp"
1415
#include "../rendering/UIBatchRenderer.hpp"
1516
#include "../../math/Math.hpp"
1617

@@ -75,13 +76,17 @@ glm::vec2 Checkbox::measure(f32 availableWidth, f32 availableHeight) {
7576
f32 width = checkboxSize_;
7677
f32 height = checkboxSize_;
7778

78-
if (!label_.empty() && getContext() && getContext()->getDefaultFont()) {
79-
f32 fontSize = 14.0f;
80-
if (getContext()) {
81-
fontSize = getContext()->getTheme().typography.fontSizeNormal;
82-
}
79+
if (!label_.empty() && getContext()) {
80+
f32 fontSize = getContext()->getTheme().typography.fontSizeNormal;
8381

84-
f32 labelWidth = static_cast<f32>(label_.length()) * fontSize * 0.6f;
82+
// Use regular font for measurement
83+
Font* font = getContext()->getDefaultFont();
84+
f32 labelWidth;
85+
if (font) {
86+
labelWidth = font->measureText(label_, fontSize).x;
87+
} else {
88+
labelWidth = static_cast<f32>(label_.length()) * fontSize * 0.6f;
89+
}
8590
width += LABEL_SPACING + labelWidth;
8691
height = glm::max(height, fontSize);
8792
}

src/esengine/ui/widgets/Label.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,14 @@ void Label::render(UIBatchRenderer& renderer) {
8383
UIContext* ctx = getContext();
8484
if (!ctx) return;
8585

86-
Font* font = fontName_.empty() ? ctx->getDefaultFont() : ctx->getFont(fontName_);
87-
if (!font) return;
88-
8986
WidgetStyle style = ctx->getTheme().getLabelStyle();
9087
glm::vec4 textColor = customColor_ ? color_ : style.getTextColor(getState());
91-
9288
Rect contentBounds = getContentBounds();
9389

94-
renderer.drawTextInBounds(text_, contentBounds, *font, fontSize_, textColor, hAlign_, vAlign_);
90+
Font* font = fontName_.empty() ? ctx->getDefaultFont() : ctx->getFont(fontName_);
91+
if (font) {
92+
renderer.drawTextInBounds(text_, contentBounds, *font, fontSize_, textColor, hAlign_, vAlign_);
93+
}
9594
}
9695

9796
} // namespace esengine::ui

src/esengine/ui/widgets/TextField.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "TextField.hpp"
1313
#include "../UIContext.hpp"
14+
#include "../font/Font.hpp"
1415
#include "../rendering/UIBatchRenderer.hpp"
1516
#include "../../core/Log.hpp"
1617
#include "../../math/Math.hpp"
@@ -499,7 +500,7 @@ void TextField::cutToClipboard() {
499500
}
500501

501502
usize TextField::getCharIndexAtX(f32 x) const {
502-
if (!getContext() || !getContext()->getDefaultFont()) {
503+
if (!getContext()) {
503504
return 0;
504505
}
505506

@@ -512,14 +513,19 @@ usize TextField::getCharIndexAtX(f32 x) const {
512513
return 0;
513514
}
514515

515-
f32 fontSize = 14.0f;
516-
if (getContext()) {
517-
fontSize = getContext()->getTheme().typography.fontSizeNormal;
518-
}
516+
f32 fontSize = getContext()->getTheme().typography.fontSizeNormal;
517+
518+
// Use regular font for character measurement
519+
Font* font = getContext()->getDefaultFont();
519520

520521
f32 currentX = 0.0f;
521522
for (usize i = 0; i < text_.size(); ++i) {
522-
f32 charWidth = fontSize * 0.6f;
523+
f32 charWidth;
524+
if (font) {
525+
charWidth = font->getCharWidth(static_cast<u32>(text_[i]), fontSize);
526+
} else {
527+
charWidth = fontSize * 0.6f;
528+
}
523529

524530
if (relativeX < currentX + charWidth * 0.5f) {
525531
return i;
@@ -536,9 +542,17 @@ f32 TextField::getXForCharIndex(usize index) const {
536542
return 0.0f;
537543
}
538544

539-
f32 fontSize = 14.0f;
540-
if (getContext()) {
541-
fontSize = getContext()->getTheme().typography.fontSizeNormal;
545+
f32 fontSize = getContext()->getTheme().typography.fontSizeNormal;
546+
547+
// Use regular font for character measurement
548+
Font* font = getContext()->getDefaultFont();
549+
550+
if (font) {
551+
f32 currentX = 0.0f;
552+
for (usize i = 0; i < index && i < text_.size(); ++i) {
553+
currentX += font->getCharWidth(static_cast<u32>(text_[i]), fontSize);
554+
}
555+
return currentX;
542556
}
543557

544558
f32 charWidth = fontSize * 0.6f;

src/esengine/ui/widgets/TreeView.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "TreeView.hpp"
1313
#include "../UIContext.hpp"
14+
#include "../font/Font.hpp"
1415
#include "../rendering/UIBatchRenderer.hpp"
1516
#include "../../core/Log.hpp"
1617
#include "../../math/Math.hpp"

0 commit comments

Comments
 (0)