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(ui): fix StackLayout flex distribution and panel overlap
esengined27ed431dd67
diff --git a/src/esengine/editor/panels/AssetBrowserPanel.cpp b/src/esengine/editor/panels/AssetBrowserPanel.cppindex df38145d7..475efee9e 100644--- a/src/esengine/editor/panels/AssetBrowserPanel.cpp+++ b/src/esengine/editor/panels/AssetBrowserPanel.cpp@@ -182,6 +182,13 @@ void AssetBrowserPanel::buildUI() {statusBar->setBackgroundColor(panelBg);statusBar->setBorderColor(borderColor);statusBar->setBorderWidth(ui::BorderWidth(1.0f, 0.0f, 0.0f, 0.0f));++ auto statusLabel = makeUnique<ui::Label>(ui::WidgetId(getId().path + "_status_label"), "0 items");+ statusLabel->setFontSize(11.0f);+ statusLabel->setColor({0.6f, 0.6f, 0.6f, 1.0f});+ statusLabel_ = statusLabel.get();+ statusBar->addChild(std::move(statusLabel));+rightPanel->addChild(std::move(statusBar));rightPanel_ = rightPanel.get();@@ -323,6 +330,12 @@ void AssetBrowserPanel::refreshAssetList() {}ES_LOG_INFO("AssetBrowserPanel::refreshAssetList: added {} items to grid", currentAssets_.size());++ if (statusLabel_) {+ usize count = currentAssets_.size();+ std::string text = std::to_string(count) + (count == 1 ? " item" : " items");+ statusLabel_->setText(text);+ }}// =============================================================================diff --git a/src/esengine/editor/panels/AssetBrowserPanel.hpp b/src/esengine/editor/panels/AssetBrowserPanel.hppindex 97cf08465..8219e1531 100644--- a/src/esengine/editor/panels/AssetBrowserPanel.hpp+++ b/src/esengine/editor/panels/AssetBrowserPanel.hpp@@ -21,6 +21,7 @@#include "../../ui/widgets/ScrollView.hpp"#include "../../ui/widgets/TextField.hpp"#include "../../ui/widgets/Panel.hpp"+#include "../../ui/widgets/Label.hpp"#include "../../events/Connection.hpp"#include "AssetBrowserTypes.hpp"@@ -83,6 +84,7 @@ private:ui::TextField* searchField_ = nullptr;ui::ScrollView* assetScrollView_ = nullptr;ui::Panel* assetGridPanel_ = nullptr;+ ui::Label* statusLabel_ = nullptr;std::vector<AssetEntry> currentAssets_;std::unordered_map<ui::TreeNodeId, std::string> nodeToPath_;diff --git a/src/esengine/editor/widgets/EditorRootContainer.cpp b/src/esengine/editor/widgets/EditorRootContainer.cppindex d0b7e552a..c6fc0a928 100644--- a/src/esengine/editor/widgets/EditorRootContainer.cpp+++ b/src/esengine/editor/widgets/EditorRootContainer.cpp@@ -233,4 +233,34 @@ void EditorRootContainer::render(ui::UIBatchRenderer& renderer) {statusBar_->renderTree(renderer);}+ui::Widget* EditorRootContainer::hitTest(f32 x, f32 y) {+ if (!containsPoint(x, y)) {+ return nullptr;+ }++ if (auto* hit = statusBar_->hitTest(x, y)) {+ return hit;+ }++ if (outputDrawer_->isOpen()) {+ if (auto* hit = outputDrawer_->hitTest(x, y)) {+ return hit;+ }+ }++ if (assetsDrawer_->isOpen()) {+ if (auto* hit = assetsDrawer_->hitTest(x, y)) {+ return hit;+ }+ }++ if (mainContent_) {+ if (auto* hit = mainContent_->hitTest(x, y)) {+ return hit;+ }+ }++ return this;+}+} // namespace esengine::editordiff --git a/src/esengine/editor/widgets/EditorRootContainer.hpp b/src/esengine/editor/widgets/EditorRootContainer.hppindex cfcba6e98..ba162c328 100644--- a/src/esengine/editor/widgets/EditorRootContainer.hpp+++ b/src/esengine/editor/widgets/EditorRootContainer.hpp@@ -52,6 +52,7 @@ public:glm::vec2 measure(f32 availableWidth, f32 availableHeight) override;void layout(const ui::Rect& bounds) override;void render(ui::UIBatchRenderer& renderer) override;+ Widget* hitTest(f32 x, f32 y) override;private:void updateLayout();diff --git a/src/esengine/ui/layout/StackLayout.cpp b/src/esengine/ui/layout/StackLayout.cppindex 52df62236..8c8b9742d 100644--- a/src/esengine/ui/layout/StackLayout.cpp+++ b/src/esengine/ui/layout/StackLayout.cpp@@ -73,43 +73,77 @@ void StackLayout::layout(Widget& container, const Rect& bounds) {if (children.empty()) return;bool isVertical = (direction_ == StackDirection::Vertical);+ f32 mainAvailable = isVertical ? bounds.height : bounds.width;std::vector<Widget*> visibleChildren;- std::vector<glm::vec2> childSizes;+ std::vector<f32> flexWeights;+ f32 totalFixedSize = 0.0f;+ f32 totalFlexWeight = 0.0f;- f32 usedMainSize = 0.0f;for (const auto& child : children) {- if (child->isVisible()) {- visibleChildren.push_back(child.get());-- f32 childAvailW = isVertical ? bounds.width : (bounds.width - usedMainSize);- f32 childAvailH = isVertical ? (bounds.height - usedMainSize) : bounds.height;- auto size = child->measure(childAvailW, childAvailH);- childSizes.push_back(size);-- const auto& margin = child->getMargin();- f32 childMainSize = isVertical ? (size.y + margin.totalVertical())- : (size.x + margin.totalHorizontal());- usedMainSize += childMainSize + spacing_;+ if (!child->isVisible()) continue;++ visibleChildren.push_back(child.get());++ const SizeValue& mainSizeValue = isVertical ? child->getHeight()+ : child->getWidth();+ const auto& margin = child->getMargin();+ f32 marginMain = isVertical ? margin.totalVertical() : margin.totalHorizontal();++ if (mainSizeValue.isFlex()) {+ flexWeights.push_back(mainSizeValue.value);+ totalFlexWeight += mainSizeValue.value;+ totalFixedSize += marginMain;+ } else {+ flexWeights.push_back(0.0f);++ f32 childAvailW = isVertical ? bounds.width : mainAvailable;+ f32 childAvailH = isVertical ? mainAvailable : bounds.height;+ auto childSize = child->measure(childAvailW, childAvailH);++ f32 childMainSize = isVertical ? childSize.y : childSize.x;+ totalFixedSize += childMainSize + marginMain;}}if (visibleChildren.empty()) return;+ f32 totalSpacing = spacing_ * static_cast<f32>(visibleChildren.size() - 1);+ f32 flexSpace = mainAvailable - totalFixedSize - totalSpacing;+ if (flexSpace < 0.0f) flexSpace = 0.0f;++ std::vector<f32> childMainSizes;+ for (usize i = 0; i < visibleChildren.size(); ++i) {+ Widget* child = visibleChildren[i];++ if (flexWeights[i] > 0.0f && totalFlexWeight > 0.0f) {+ f32 flexPortion = (flexWeights[i] / totalFlexWeight) * flexSpace;+ childMainSizes.push_back(flexPortion);+ } else {+ f32 childAvailW = isVertical ? bounds.width : mainAvailable;+ f32 childAvailH = isVertical ? mainAvailable : bounds.height;+ auto childSize = child->measure(childAvailW, childAvailH);+ f32 childMainSize = isVertical ? childSize.y : childSize.x;+ childMainSizes.push_back(childMainSize);+ }+ }+if (reverse_) {std::reverse(visibleChildren.begin(), visibleChildren.end());- std::reverse(childSizes.begin(), childSizes.end());+ std::reverse(childMainSizes.begin(), childMainSizes.end());}f32 position = isVertical ? bounds.y : bounds.x;for (usize i = 0; i < visibleChildren.size(); ++i) {Widget* child = visibleChildren[i];- const auto& childSize = childSizes[i];+ f32 childMainSize = childMainSizes[i];const auto& margin = child->getMargin();- f32 childMainSize = isVertical ? childSize.y : childSize.x;- f32 childCrossSize = isVertical ? childSize.x : childSize.y;+ f32 childAvailW = isVertical ? bounds.width : childMainSize;+ f32 childAvailH = isVertical ? childMainSize : bounds.height;+ auto childMeasured = child->measure(childAvailW, childAvailH);+ f32 childCrossSize = isVertical ? childMeasured.x : childMeasured.y;f32 crossStart = isVertical ? bounds.x : bounds.y;f32 crossAvail = isVertical ? bounds.width : bounds.height;