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.

feat: Add OutputLogPanel and fix AssetBrowser click handling

esengine2c7559c84ea8
diff --git a/src/esengine/core/Log.cpp b/src/esengine/core/Log.cpp
index a69f860d5..bcc1abef9 100644
--- a/src/esengine/core/Log.cpp
+++ b/src/esengine/core/Log.cpp
@@ -12,9 +12,15 @@
#include "Log.hpp"
+#include <algorithm>
+#include <chrono>
+
namespace esengine {
LogLevel Log::level_ = LogLevel::Info;
+std::vector<std::pair<u32, LogSink>> Log::sinks_;
+std::mutex Log::sinkMutex_;
+u32 Log::nextSinkId_ = 1;
void Log::init() {
#ifdef ES_DEBUG
@@ -49,4 +55,33 @@ const char* Log::levelToString(LogLevel level) {
}
}
+u32 Log::addSink(LogSink sink) {
+ std::lock_guard<std::mutex> lock(sinkMutex_);
+ u32 id = nextSinkId_++;
+ sinks_.emplace_back(id, std::move(sink));
+ return id;
+}
+
+void Log::removeSink(u32 sinkId) {
+ std::lock_guard<std::mutex> lock(sinkMutex_);
+ sinks_.erase(
+ std::remove_if(sinks_.begin(), sinks_.end(),
+ [sinkId](const auto& pair) { return pair.first == sinkId; }),
+ sinks_.end());
+}
+
+void Log::notifySinks(LogLevel level, const std::string& message) {
+ std::lock_guard<std::mutex> lock(sinkMutex_);
+
+ auto now = std::chrono::system_clock::now();
+ auto duration = now.time_since_epoch();
+ auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
+
+ LogEntry entry{level, message, static_cast<u64>(millis)};
+
+ for (const auto& [id, sink] : sinks_) {
+ sink(entry);
+ }
+}
+
} // namespace esengine
diff --git a/src/esengine/core/Log.hpp b/src/esengine/core/Log.hpp
index 2809f8fe2..5c6222632 100644
--- a/src/esengine/core/Log.hpp
+++ b/src/esengine/core/Log.hpp
@@ -20,9 +20,12 @@
#include "Types.hpp"
// Standard library
+#include <functional>
#include <iostream>
+#include <mutex>
#include <sstream>
#include <string>
+#include <vector>
namespace esengine {
@@ -45,6 +48,14 @@ enum class LogLevel : u8 {
Fatal = 5 ///< Fatal errors (application cannot continue)
};
+struct LogEntry {
+ LogLevel level;
+ std::string message;
+ u64 timestamp;
+};
+
+using LogSink = std::function<void(const LogEntry&)>;
+
// =============================================================================
// Log Class
// =============================================================================
@@ -87,6 +98,19 @@ public:
*/
static LogLevel getLevel();
+ /**
+ * @brief Registers a log sink to receive log entries
+ * @param sink Callback function to receive log entries
+ * @return Sink ID for unregistration
+ */
+ static u32 addSink(LogSink sink);
+
+ /**
+ * @brief Unregisters a log sink
+ * @param sinkId ID returned from addSink
+ */
+ static void removeSink(u32 sinkId);
+
// =========================================================================
// Logging Methods
// =========================================================================
@@ -159,23 +183,31 @@ public:
private:
static LogLevel level_;
+ static std::vector<std::pair<u32, LogSink>> sinks_;
+ static std::mutex sinkMutex_;
+ static u32 nextSinkId_;
template<typename... Args>
static void log(LogLevel level, const char* fmt, Args&&... args) {
if (level < level_) return;
+ std::ostringstream msgOss;
+ formatTo(msgOss, fmt, std::forward<Args>(args)...);
+ std::string message = msgOss.str();
+
std::ostringstream oss;
- oss << "[" << levelToString(level) << "] ";
- formatTo(oss, fmt, std::forward<Args>(args)...);
- oss << "\n";
+ oss << "[" << levelToString(level) << "] " << message << "\n";
if (level >= LogLevel::Error) {
std::cerr << oss.str();
} else {
std::cout << oss.str();
}
+
+ notifySinks(level, message);
}
+ static void notifySinks(LogLevel level, const std::string& message);
static const char* levelToString(LogLevel level);
// Simple format implementation with {} placeholders
diff --git a/src/esengine/editor/CMakeLists.txt b/src/esengine/editor/CMakeLists.txt
index 917ff320d..b2e01038b 100644
--- a/src/esengine/editor/CMakeLists.txt
+++ b/src/esengine/editor/CMakeLists.txt
@@ -31,6 +31,7 @@ set(EDITOR_SOURCES
panels/AssetGridItem.cpp
panels/ProjectLauncherPanel.cpp
panels/NewProjectDialog.cpp
+ panels/OutputLogPanel.cpp
# Editor widgets
widgets/StatusBar.cpp
@@ -82,6 +83,7 @@ set(EDITOR_HEADERS
panels/AssetGridItem.hpp
panels/ProjectLauncherPanel.hpp
panels/NewProjectDialog.hpp
+ panels/OutputLogPanel.hpp
# Editor widgets
widgets/StatusBar.hpp
diff --git a/src/esengine/editor/EditorApplication.cpp b/src/esengine/editor/EditorApplication.cpp
index 4d25307ff..cea817f6e 100644
--- a/src/esengine/editor/EditorApplication.cpp
+++ b/src/esengine/editor/EditorApplication.cpp
@@ -30,6 +30,7 @@
#include "panels/AssetBrowserPanel.hpp"
#include "panels/ProjectLauncherPanel.hpp"
#include "panels/NewProjectDialog.hpp"
+#include "panels/OutputLogPanel.hpp"
#include "widgets/EditorRootContainer.hpp"
#include "../platform/FileDialog.hpp"
@@ -380,6 +381,10 @@ void EditorApplication::setupEditorLayout() {
editorRoot_->setAssetsDrawerContent(std::move(assetBrowserPanel));
+ ES_LOG_INFO("setupEditorLayout: Creating OutputLogPanel for drawer...");
+ auto outputLogPanel = makeUnique<OutputLogPanel>(ui::WidgetId("editor.output_log"));
+ editorRoot_->setOutputDrawerContent(std::move(outputLogPanel));
+
(void)sink(editorRoot_->getAssetsDrawer()->onDockRequested).connect([this]() {
dockAssetBrowser();
});
diff --git a/src/esengine/editor/panels/AssetBrowserPanel.cpp b/src/esengine/editor/panels/AssetBrowserPanel.cpp
index 8e5368ebf..df38145d7 100644
--- a/src/esengine/editor/panels/AssetBrowserPanel.cpp
+++ b/src/esengine/editor/panels/AssetBrowserPanel.cpp
@@ -259,6 +259,7 @@ void AssetBrowserPanel::refreshAssetList() {
currentAssets_.clear();
assetGridPanel_->clearChildren();
+ itemConnections_.disconnectAll();
if (!FileSystem::directoryExists(currentPath_)) {
ES_LOG_WARN("AssetBrowserPanel::refreshAssetList: directory not found: {}", currentPath_);
@@ -310,13 +311,13 @@ void AssetBrowserPanel::refreshAssetList() {
entry
);
- (void)sink(item->onClick).connect([this](const std::string& path) {
+ itemConnections_.add(sink(item->onClick).connect([this](const std::string& path) {
onAssetItemClicked(path);
- });
+ }));
- (void)sink(item->onDoubleClick).connect([this](const std::string& path) {
+ itemConnections_.add(sink(item->onDoubleClick).connect([this](const std::string& path) {
onAssetItemDoubleClicked(path);
- });
+ }));
assetGridPanel_->addChild(std::move(item));
}
diff --git a/src/esengine/editor/panels/AssetBrowserPanel.hpp b/src/esengine/editor/panels/AssetBrowserPanel.hpp
index 198fdf750..97cf08465 100644
--- a/src/esengine/editor/panels/AssetBrowserPanel.hpp
+++ b/src/esengine/editor/panels/AssetBrowserPanel.hpp
@@ -97,6 +97,7 @@ private:
Connection folderSelectedConnection_;
Connection searchChangedConnection_;
+ ConnectionHolder itemConnections_;
};
} // namespace esengine::editor
diff --git a/src/esengine/editor/panels/OutputLogPanel.cpp b/src/esengine/editor/panels/OutputLogPanel.cpp
new file mode 100644
index 000000000..75c2ef81a
--- /dev/null
+++ b/src/esengine/editor/panels/OutputLogPanel.cpp
@@ -0,0 +1,280 @@
+/**
+ * @file OutputLogPanel.cpp
+ * @brief Output log panel implementation
+ *
+ * @author ESEngine Team
+ * @date 2026
+ *
+ * @copyright Copyright (c) 2026 ESEngine Team
+ * Licensed under the MIT License.
+ */
+
+#include "OutputLogPanel.hpp"
+#include "../../ui/UIContext.hpp"
+#include "../../ui/rendering/UIBatchRenderer.hpp"
+#include "../../ui/icons/Icons.hpp"
+#include "../../math/Math.hpp"
+
+#if ES_FEATURE_SDF_FONT
+#include "../../ui/font/MSDFFont.hpp"
+#endif
+
+namespace esengine::editor {
+
+// =============================================================================
+// Constructor / Destructor
+// =============================================================================
+
+OutputLogPanel::OutputLogPanel(const ui::WidgetId& id)
+ : Widget(id) {
+
+ logSinkId_ = Log::addSink([this](const LogEntry& entry) {
+ onLogEntry(entry);
+ });
+}
+
+OutputLogPanel::~OutputLogPanel() {
+ if (logSinkId_ != 0) {
+ Log::removeSink(logSinkId_);
+ }
+}
+
+// =============================================================================
+// Public Methods
+// =============================================================================
+
+void OutputLogPanel::clear() {
+ std::lock_guard<std::mutex> lock(entriesMutex_);
+ entries_.clear();
+ scrollOffset_ = 0.0f;
+}
+
+// =============================================================================
+// Layout
+// =============================================================================
+
+glm::vec2 OutputLogPanel::measure(f32 availableWidth, f32 availableHeight) {
+ return {availableWidth, availableHeight};
+}
+
+void OutputLogPanel::layout(const ui::Rect& bounds) {
+ Widget::layout(bounds);
+
+ clearButtonBounds_ = ui::Rect{
+ bounds.x + bounds.width - 64.0f,
+ bounds.y + 4.0f,
+ 24.0f,
+ 24.0f
+ };
+
+ autoScrollButtonBounds_ = ui::Rect{
+ bounds.x + bounds.width - 36.0f,
+ bounds.y + 4.0f,
+ 24.0f,
+ 24.0f
+ };
+}
+
+// =============================================================================
+// Rendering
+// =============================================================================
+
+void OutputLogPanel::render(ui::UIBatchRenderer& renderer) {
+ ui::UIContext* ctx = getContext();
+ if (!ctx) return;
+
+ const ui::Rect& bounds = getBounds();
+
+ constexpr glm::vec4 bgColor{0.118f, 0.118f, 0.118f, 1.0f}; // #1e1e1e
+ constexpr glm::vec4 toolbarBg{0.145f, 0.145f, 0.149f, 1.0f}; // #252526
+ constexpr glm::vec4 borderColor{0.235f, 0.235f, 0.235f, 1.0f}; // #3c3c3c
+ constexpr glm::vec4 textColor{0.878f, 0.878f, 0.878f, 1.0f}; // #e0e0e0
+ constexpr glm::vec4 iconColor{0.533f, 0.533f, 0.533f, 1.0f}; // #888
+ constexpr glm::vec4 iconHoverColor{0.878f, 0.878f, 0.878f, 1.0f}; // #e0e0e0
+ constexpr glm::vec4 activeColor{0.231f, 0.510f, 0.965f, 1.0f}; // #3b82f6
+ constexpr glm::vec4 buttonHoverBg{0.235f, 0.235f, 0.235f, 1.0f}; // #3c3c3c
+
+ renderer.drawRect(bounds, bgColor);
+
+ ui::Rect toolbarBounds{bounds.x, bounds.y, bounds.width, TOOLBAR_HEIGHT};
+ renderer.drawRect(toolbarBounds, toolbarBg);
+
+ ui::Rect bottomBorder{bounds.x, bounds.y + TOOLBAR_HEIGHT - 1.0f, bounds.width, 1.0f};
+ renderer.drawRect(bottomBorder, borderColor);
+
+#if ES_FEATURE_SDF_FONT
+ ui::MSDFFont* iconFont = ctx->getIconMSDFFont();
+ ui::MSDFFont* textFont = ctx->getDefaultMSDFFont();
+
+ if (iconFont) {
+ if (clearHovered_) {
+ renderer.drawRoundedRect(clearButtonBounds_, buttonHoverBg, ui::CornerRadii::all(3.0f));
+ }
+ renderer.drawTextInBounds(ui::icons::Trash2, clearButtonBounds_, *iconFont, 14.0f,
+ clearHovered_ ? iconHoverColor : iconColor,
+ ui::HAlign::Center, ui::VAlign::Center);
+
+ if (autoScrollHovered_) {
+ renderer.drawRoundedRect(autoScrollButtonBounds_, buttonHoverBg, ui::CornerRadii::all(3.0f));
+ }
+ renderer.drawTextInBounds(ui::icons::ChevronsDown, autoScrollButtonBounds_, *iconFont, 14.0f,
+ autoScroll_ ? activeColor : (autoScrollHovered_ ? iconHoverColor : iconColor),
+ ui::HAlign::Center, ui::VAlign::Center);
+ }
+
+ if (textFont) {
+ ui::Rect logArea{
+ bounds.x,
+ bounds.y + TOOLBAR_HEIGHT,
+ bounds.width,
+ bounds.height - TOOLBAR_HEIGHT
+ };
+
+ renderer.pushClipRect(logArea);
+
+ std::lock_guard<std::mutex> lock(entriesMutex_);
+
+ f32 y = logArea.y - scrollOffset_;
+ usize visibleCount = 0;
+
+ for (const auto& entry : entries_) {
+ if (!shouldShowEntry(entry.level)) continue;
+
+ f32 lineY = y + visibleCount * LINE_HEIGHT;
+
+ if (lineY + LINE_HEIGHT < logArea.y) {
+ visibleCount++;
+ continue;
+ }
+ if (lineY > logArea.y + logArea.height) {
+ break;
+ }
+
+ glm::vec4 levelColor = getColorForLevel(entry.level);
+ const char* prefix = getLevelPrefix(entry.level);
+
+ ui::Rect prefixBounds{logArea.x + 8.0f, lineY, 60.0f, LINE_HEIGHT};
+ renderer.drawTextInBounds(prefix, prefixBounds, *textFont, 12.0f, levelColor,
+ ui::HAlign::Left, ui::VAlign::Center);
+
+ ui::Rect msgBounds{logArea.x + 72.0f, lineY, logArea.width - 80.0f, LINE_HEIGHT};
+ renderer.drawTextInBounds(entry.message, msgBounds, *textFont, 12.0f, textColor,
+ ui::HAlign::Left, ui::VAlign::Center);
+
+ visibleCount++;
+ }
+
+ f32 totalHeight = static_cast<f32>(visibleCount) * LINE_HEIGHT;
+ maxScroll_ = glm::max(0.0f, totalHeight - logArea.height);
+
+ renderer.popClipRect();
+ }
+#endif
+}
+
+// =============================================================================
+// Event Handling
+// =============================================================================
+
+bool OutputLogPanel::onScroll(const ui::ScrollEvent& event) {
+ const ui::Rect& bounds = getBounds();
+ if (!bounds.contains(event.x, event.y)) {
+ return false;
+ }
+
+ scrollOffset_ -= event.deltaY * 40.0f;
+ scrollOffset_ = glm::clamp(scrollOffset_, 0.0f, maxScroll_);
+ autoScroll_ = false;
+ return true;
+}
+
+bool OutputLogPanel::onMouseDown(const ui::MouseButtonEvent& event) {
+ if (event.button != ui::MouseButton::Left) {
+ return false;
+ }
+
+ if (clearButtonBounds_.contains(event.x, event.y)) {
+ clear();
+ return true;
+ }
+
+ if (autoScrollButtonBounds_.contains(event.x, event.y)) {
+ autoScroll_ = !autoScroll_;
+ if (autoScroll_) {
+ scrollOffset_ = maxScroll_;
+ }
+ return true;
+ }
+
+ return false;
+}
+
+bool OutputLogPanel::onMouseMove(const ui::MouseMoveEvent& event) {
+ clearHovered_ = clearButtonBounds_.contains(event.x, event.y);
+ autoScrollHovered_ = autoScrollButtonBounds_.contains(event.x, event.y);
+ return false;
+}
+
+// =============================================================================
+// Private Methods
+// =============================================================================
+
+void OutputLogPanel::onLogEntry(const LogEntry& entry) {
+ std::lock_guard<std::mutex> lock(entriesMutex_);
+
+ entries_.push_back(entry);
+
+ while (entries_.size() > MAX_LOG_ENTRIES) {
+ entries_.pop_front();
+ }
+
+ if (autoScroll_) {
+ usize visibleCount = 0;
+ for (const auto& e : entries_) {
+ if (shouldShowEntry(e.level)) visibleCount++;
+ }
+ f32 totalHeight = static_cast<f32>(visibleCount) * LINE_HEIGHT;
+ const ui::Rect& bounds = getBounds();
+ f32 logAreaHeight = bounds.height - TOOLBAR_HEIGHT;
+ maxScroll_ = glm::max(0.0f, totalHeight - logAreaHeight);
+ scrollOffset_ = maxScroll_;
+ }
+}
+
+bool OutputLogPanel::shouldShowEntry(LogLevel level) const {
+ switch (level) {
+ case LogLevel::Trace: return showTrace_;
+ case LogLevel::Debug: return showDebug_;
+ case LogLevel::Info: return showInfo_;
+ case LogLevel::Warn: return showWarn_;
+ case LogLevel::Error:
+ case LogLevel::Fatal: return showError_;
+ default: return true;
+ }
+}
+
+glm::vec4 OutputLogPanel::getColorForLevel(LogLevel level) const {
+ switch (level) {
+ case LogLevel::Trace: return {0.533f, 0.533f, 0.533f, 1.0f}; // gray
+ case LogLevel::Debug: return {0.533f, 0.533f, 0.533f, 1.0f}; // gray
+ case LogLevel::Info: return {0.231f, 0.510f, 0.965f, 1.0f}; // blue
+ case LogLevel::Warn: return {0.902f, 0.667f, 0.157f, 1.0f}; // yellow/orange
+ case LogLevel::Error:
+ case LogLevel::Fatal: return {0.937f, 0.325f, 0.314f, 1.0f}; // red
+ default: return {0.878f, 0.878f, 0.878f, 1.0f};
+ }
+}
+
+const char* OutputLogPanel::getLevelPrefix(LogLevel level) const {
+ switch (level) {
+ case LogLevel::Trace: return "[TRACE]";
+ case LogLevel::Debug: return "[DEBUG]";
+ case LogLevel::Info: return "[INFO]";
+ case LogLevel::Warn: return "[WARN]";
+ case LogLevel::Error: return "[ERROR]";
+ case LogLevel::Fatal: return "[FATAL]";
+ default: return "[???]";
+ }
+}
+
+} // namespace esengine::editor
diff --git a/src/esengine/editor/panels/OutputLogPanel.hpp b/src/esengine/editor/panels/OutputLogPanel.hpp
new file mode 100644
index 000000000..2e0e21b11
--- /dev/null
+++ b/src/esengine/editor/panels/OutputLogPanel.hpp
@@ -0,0 +1,85 @@
+/**
+ * @file OutputLogPanel.hpp
+ * @brief Output log panel for displaying engine log messages
+ *
+ * @author ESEngine Team
+ * @date 2026
+ *
+ * @copyright Copyright (c) 2026 ESEngine Team
+ * Licensed under the MIT License.
+ */
+#pragma once
+
+// =============================================================================
+// Includes
+// =============================================================================
+
+#include "../../ui/widgets/Widget.hpp"
+#include "../../core/Log.hpp"
+
+#include <deque>
+#include <mutex>
+
+namespace esengine::editor {
+
+// =============================================================================
+// OutputLogPanel Class
+// =============================================================================
+
+class OutputLogPanel : public ui::Widget {
+public:
+ static constexpr usize MAX_LOG_ENTRIES = 1000;
+ static constexpr f32 LINE_HEIGHT = 18.0f;
+ static constexpr f32 TOOLBAR_HEIGHT = 32.0f;
+
+ explicit OutputLogPanel(const ui::WidgetId& id);
+ ~OutputLogPanel() override;
+
+ void clear();
+
+ void setShowTrace(bool show) { showTrace_ = show; }
+ void setShowDebug(bool show) { showDebug_ = show; }
+ void setShowInfo(bool show) { showInfo_ = show; }
+ void setShowWarn(bool show) { showWarn_ = show; }
+ void setShowError(bool show) { showError_ = show; }
+
+ bool isShowTrace() const { return showTrace_; }
+ bool isShowDebug() const { return showDebug_; }
+ bool isShowInfo() const { return showInfo_; }
+ bool isShowWarn() const { return showWarn_; }
+ bool isShowError() const { return showError_; }
+
+ glm::vec2 measure(f32 availableWidth, f32 availableHeight) override;
+ void layout(const ui::Rect& bounds) override;
+ void render(ui::UIBatchRenderer& renderer) override;
+ bool onScroll(const ui::ScrollEvent& event) override;
+ bool onMouseDown(const ui::MouseButtonEvent& event) override;
+ bool onMouseMove(const ui::MouseMoveEvent& event) override;
+
+private:
+ void onLogEntry(const LogEntry& entry);
+ bool shouldShowEntry(LogLevel level) const;
+ glm::vec4 getColorForLevel(LogLevel level) const;
+ const char* getLevelPrefix(LogLevel level) const;
+
+ std::deque<LogEntry> entries_;
+ std::mutex entriesMutex_;
+ u32 logSinkId_ = 0;
+
+ f32 scrollOffset_ = 0.0f;
+ f32 maxScroll_ = 0.0f;
+ bool autoScroll_ = true;
+
+ bool showTrace_ = true;
+ bool showDebug_ = true;
+ bool showInfo_ = true;
+ bool showWarn_ = true;
+ bool showError_ = true;
+
+ ui::Rect clearButtonBounds_;
+ ui::Rect autoScrollButtonBounds_;
+ bool clearHovered_ = false;
+ bool autoScrollHovered_ = false;
+};
+
+} // namespace esengine::editor