Skip to content

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

fix: Resolve ScrollView clipping and event propagation issues

esengine8ba85e1f0245
diff --git a/src/esengine/ui/UIContext.cpp b/src/esengine/ui/UIContext.cpp
index 9119abb87..11f69a0b6 100644
--- a/src/esengine/ui/UIContext.cpp
+++ b/src/esengine/ui/UIContext.cpp
@@ -287,7 +287,13 @@ void UIContext::processMouseScroll(f32 deltaX, f32 deltaY, f32 x, f32 y) {
event.x = x;
event.y = y;
- hoveredWidget_->onScroll(event);
+ Widget* target = hoveredWidget_;
+ while (target) {
+ if (target->onScroll(event)) {
+ break;
+ }
+ target = target->getParent();
+ }
}
}
diff --git a/src/esengine/ui/docking/DockArea.cpp b/src/esengine/ui/docking/DockArea.cpp
index fb138470f..2b3fda771 100644
--- a/src/esengine/ui/docking/DockArea.cpp
+++ b/src/esengine/ui/docking/DockArea.cpp
@@ -305,11 +305,41 @@ void DockArea::render(UIBatchRenderer& renderer) {
}
Widget* DockArea::hitTest(f32 x, f32 y) {
+ if (!containsPoint(x, y)) {
+ return nullptr;
+ }
+
if (hitTestSplitter(x, y)) {
return this;
}
- return Widget::hitTest(x, y);
+ if (rootNode_) {
+ DockNode* leafNode = rootNode_->findLeafAt(x, y);
+ if (leafNode) {
+ Rect tabBarBounds{
+ leafNode->getBounds().x,
+ leafNode->getBounds().y,
+ leafNode->getBounds().width,
+ tabBarHeight_
+ };
+ if (tabBarBounds.contains({x, y})) {
+ DockTabBar* tabBar = getOrCreateTabBar(leafNode);
+ if (tabBar) {
+ return tabBar;
+ }
+ }
+
+ DockPanel* activePanel = leafNode->getActivePanel();
+ if (activePanel) {
+ Widget* hit = activePanel->hitTest(x, y);
+ if (hit) {
+ return hit;
+ }
+ }
+ }
+ }
+
+ return this;
}
void DockArea::renderNode(UIBatchRenderer& renderer, DockNode* node) {
diff --git a/src/esengine/ui/docking/DockNode.cpp b/src/esengine/ui/docking/DockNode.cpp
index a05aba0a6..7d45c4b46 100644
--- a/src/esengine/ui/docking/DockNode.cpp
+++ b/src/esengine/ui/docking/DockNode.cpp
@@ -339,6 +339,30 @@ DockNode* DockNode::findNodeContainingPanel(DockPanelId panelId) {
return nullptr;
}
+DockNode* DockNode::findLeafAt(f32 x, f32 y) {
+ if (!bounds_.contains({x, y})) {
+ return nullptr;
+ }
+
+ if (isTabs()) {
+ return this;
+ }
+
+ if (first_) {
+ if (auto* found = first_->findLeafAt(x, y)) {
+ return found;
+ }
+ }
+
+ if (second_) {
+ if (auto* found = second_->findLeafAt(x, y)) {
+ return found;
+ }
+ }
+
+ return nullptr;
+}
+
void DockNode::forEachLeaf(const std::function<void(DockNode&)>& callback) {
if (isTabs()) {
callback(*this);
diff --git a/src/esengine/ui/docking/DockNode.hpp b/src/esengine/ui/docking/DockNode.hpp
index ad528d2c4..cad3b1589 100644
--- a/src/esengine/ui/docking/DockNode.hpp
+++ b/src/esengine/ui/docking/DockNode.hpp
@@ -276,6 +276,14 @@ public:
*/
DockNode* findNodeContainingPanel(DockPanelId panelId);
+ /**
+ * @brief Find the leaf node at a given point
+ * @param x X coordinate
+ * @param y Y coordinate
+ * @return Leaf node pointer or nullptr
+ */
+ DockNode* findLeafAt(f32 x, f32 y);
+
/**
* @brief Execute a callback for each leaf (Tabs) node
* @param callback Function to call
diff --git a/src/esengine/ui/docking/DockPanel.cpp b/src/esengine/ui/docking/DockPanel.cpp
index 458b87990..5057e083e 100644
--- a/src/esengine/ui/docking/DockPanel.cpp
+++ b/src/esengine/ui/docking/DockPanel.cpp
@@ -102,7 +102,7 @@ void DockPanel::render(UIBatchRenderer& renderer) {
renderer.drawRect(bounds, style.backgroundColor);
if (contentWidget_) {
- contentWidget_->render(renderer);
+ contentWidget_->renderTree(renderer);
}
onRenderContent(renderer);
diff --git a/src/esengine/ui/widgets/ScrollView.cpp b/src/esengine/ui/widgets/ScrollView.cpp
index a2cd9e58d..f50c96d3a 100644
--- a/src/esengine/ui/widgets/ScrollView.cpp
+++ b/src/esengine/ui/widgets/ScrollView.cpp
@@ -125,8 +125,19 @@ glm::vec2 ScrollView::measure(f32 availableWidth, f32 availableHeight) {
}
}
- contentSize_ = content_->measure(std::numeric_limits<f32>::infinity(),
- std::numeric_limits<f32>::infinity());
+ f32 measureWidth = contentAvailableWidth;
+ f32 measureHeight = contentAvailableHeight;
+
+ if (scrollDirection_ == ScrollDirection::Vertical) {
+ measureHeight = std::numeric_limits<f32>::infinity();
+ } else if (scrollDirection_ == ScrollDirection::Horizontal) {
+ measureWidth = std::numeric_limits<f32>::infinity();
+ } else if (scrollDirection_ == ScrollDirection::Both) {
+ measureWidth = std::numeric_limits<f32>::infinity();
+ measureHeight = std::numeric_limits<f32>::infinity();
+ }
+
+ contentSize_ = content_->measure(measureWidth, measureHeight);
}
return size;
@@ -158,6 +169,12 @@ void ScrollView::layout(const Rect& bounds) {
// Rendering
// =============================================================================
+void ScrollView::renderTree(UIBatchRenderer& renderer) {
+ if (!isVisible()) return;
+
+ render(renderer);
+}
+
void ScrollView::render(UIBatchRenderer& renderer) {
if (!content_) return;
@@ -333,11 +350,20 @@ void ScrollView::updateContentLayout() {
const Rect& bounds = getBounds();
const Insets& padding = getPadding();
+ f32 contentWidth = contentSize_.x;
+ f32 contentHeight = contentSize_.y;
+
+ if (scrollDirection_ == ScrollDirection::Vertical) {
+ contentWidth = viewportSize_.x;
+ } else if (scrollDirection_ == ScrollDirection::Horizontal) {
+ contentHeight = viewportSize_.y;
+ }
+
Rect contentBounds{
bounds.x + padding.left - scrollOffset_.x,
bounds.y + padding.top - scrollOffset_.y,
- contentSize_.x,
- contentSize_.y
+ contentWidth,
+ contentHeight
};
content_->layout(contentBounds);
diff --git a/src/esengine/ui/widgets/ScrollView.hpp b/src/esengine/ui/widgets/ScrollView.hpp
index eac99aaed..a7e6e91a2 100644
--- a/src/esengine/ui/widgets/ScrollView.hpp
+++ b/src/esengine/ui/widgets/ScrollView.hpp
@@ -178,6 +178,7 @@ public:
glm::vec2 measure(f32 availableWidth, f32 availableHeight) override;
void layout(const Rect& bounds) override;
void render(UIBatchRenderer& renderer) override;
+ void renderTree(UIBatchRenderer& renderer) override;
Widget* hitTest(f32 x, f32 y) override;
bool onScroll(const ScrollEvent& event) override;
diff --git a/src/esengine/ui/widgets/Widget.hpp b/src/esengine/ui/widgets/Widget.hpp
index 664ee3d53..e4730da0a 100644
--- a/src/esengine/ui/widgets/Widget.hpp
+++ b/src/esengine/ui/widgets/Widget.hpp
@@ -243,7 +243,7 @@ public:
* @brief Renders this widget and all children
* @param renderer The batch renderer to use
*/
- void renderTree(UIBatchRenderer& renderer);
+ virtual void renderTree(UIBatchRenderer& renderer);
// =========================================================================
// Event Handling