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 Lucide icon system and fix UI layout issues

esengine288640273089
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 40aa6900a..eda673a89 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -111,6 +111,7 @@ set(ESENGINE_HEADERS
src/esengine/ui/layout/StackLayout.hpp
src/esengine/ui/rendering/UIBatchRenderer.hpp
src/esengine/ui/font/SDFFont.hpp
+ src/esengine/ui/icons/Icons.hpp
src/esengine/ui/widgets/Widget.hpp
src/esengine/ui/widgets/Panel.hpp
src/esengine/ui/widgets/Label.hpp
diff --git a/assets/fonts/lucide.ttf b/assets/fonts/lucide.ttf
new file mode 100644
index 000000000..72c0bf60b
Binary files /dev/null and b/assets/fonts/lucide.ttf differ
diff --git a/src/esengine/editor/EditorApplication.cpp b/src/esengine/editor/EditorApplication.cpp
index bba427827..24e776b70 100644
--- a/src/esengine/editor/EditorApplication.cpp
+++ b/src/esengine/editor/EditorApplication.cpp
@@ -92,6 +92,10 @@ void EditorApplication::onInit() {
ES_LOG_WARN("No font loaded, text will not render");
}
+ if (!uiContext_->loadFont("icons", "assets/fonts/lucide.ttf", 48.0f, 4.0f)) {
+ ES_LOG_WARN("Icon font not loaded, icons will not render");
+ }
+
// Wire up scroll events to UI system
getPlatform().setScrollCallback([this](f32 deltaX, f32 deltaY, f32 x, f32 y) {
if (uiContext_) {
diff --git a/src/esengine/editor/panels/AssetGridItem.cpp b/src/esengine/editor/panels/AssetGridItem.cpp
index e7c49849f..6f5dd4e73 100644
--- a/src/esengine/editor/panels/AssetGridItem.cpp
+++ b/src/esengine/editor/panels/AssetGridItem.cpp
@@ -12,6 +12,7 @@
#include "AssetGridItem.hpp"
#include "../../ui/UIContext.hpp"
#include "../../ui/font/SDFFont.hpp"
+#include "../../ui/icons/Icons.hpp"
#include "../../ui/rendering/UIBatchRenderer.hpp"
#include <chrono>
@@ -30,6 +31,21 @@ f64 getCurrentTimeSeconds() {
return std::chrono::duration<f64>(duration).count();
}
+const char* getAssetTypeIcon(AssetType type) {
+ using namespace ui::icons;
+ switch (type) {
+ case AssetType::Folder: return Folder;
+ case AssetType::Texture: return Image;
+ case AssetType::Audio: return Music;
+ case AssetType::Script: return FileCode;
+ case AssetType::Scene: return Layers;
+ case AssetType::Prefab: return Box;
+ case AssetType::Shader: return Code;
+ case AssetType::Font: return FileText;
+ default: return File;
+ }
+}
+
std::string truncateText(const std::string& text, ui::SDFFont& font, f32 fontSize, f32 maxWidth) {
glm::vec2 textSize = font.measureText(text, fontSize);
if (textSize.x <= maxWidth) {
@@ -145,8 +161,17 @@ void AssetGridItem::render(ui::UIBatchRenderer& renderer) {
f32 iconY = bounds.y + ICON_PADDING;
ui::Rect iconBounds{iconX, iconY, ICON_SIZE, ICON_SIZE};
- glm::vec4 iconColor = getAssetTypeColor(entry_.type);
- renderer.drawRoundedRect(iconBounds, iconColor, ui::CornerRadii::all(6.0f));
+ glm::vec4 bgColor = getAssetTypeColor(entry_.type);
+ bgColor.a = 0.15f;
+ renderer.drawRoundedRect(iconBounds, bgColor, ui::CornerRadii::all(6.0f));
+
+ ui::SDFFont* iconFont = ctx->getIconFont();
+ if (iconFont) {
+ glm::vec4 iconColor = getAssetTypeColor(entry_.type);
+ const char* icon = getAssetTypeIcon(entry_.type);
+ renderer.drawTextInBounds(icon, iconBounds, *iconFont, 28.0f, iconColor,
+ ui::HAlign::Center, ui::VAlign::Center);
+ }
ui::SDFFont* font = ctx->getDefaultFont();
if (font) {
diff --git a/src/esengine/ui/UIContext.cpp b/src/esengine/ui/UIContext.cpp
index 29c43402a..e8ad402ea 100644
--- a/src/esengine/ui/UIContext.cpp
+++ b/src/esengine/ui/UIContext.cpp
@@ -137,6 +137,10 @@ SDFFont* UIContext::getDefaultFont() {
return getFont(defaultFontName_);
}
+SDFFont* UIContext::getIconFont() {
+ return getFont("icons");
+}
+
// =============================================================================
// Update and Render
// =============================================================================
@@ -162,7 +166,7 @@ void UIContext::render() {
glm::mat4 projection = glm::ortho(0.0f, static_cast<f32>(viewportWidth_),
static_cast<f32>(viewportHeight_), 0.0f, -1.0f, 1.0f);
- renderer_->begin(projection);
+ renderer_->begin(projection, devicePixelRatio_);
root_->renderTree(*renderer_);
renderer_->end();
}
diff --git a/src/esengine/ui/UIContext.hpp b/src/esengine/ui/UIContext.hpp
index 94a376265..b7ad484d5 100644
--- a/src/esengine/ui/UIContext.hpp
+++ b/src/esengine/ui/UIContext.hpp
@@ -163,6 +163,12 @@ public:
*/
SDFFont* getDefaultFont();
+ /**
+ * @brief Gets the icon font (Lucide icons)
+ * @return Pointer to the icon font or nullptr
+ */
+ SDFFont* getIconFont();
+
/**
* @brief Sets the default font name
*/
diff --git a/src/esengine/ui/icons/Icons.hpp b/src/esengine/ui/icons/Icons.hpp
new file mode 100644
index 000000000..273bd0fb9
--- /dev/null
+++ b/src/esengine/ui/icons/Icons.hpp
@@ -0,0 +1,249 @@
+/**
+ * @file Icons.hpp
+ * @brief Lucide icon font Unicode constants
+ * @details Provides constants for rendering Lucide icons via icon font.
+ * Font file: assets/fonts/lucide.ttf
+ * Reference: https://lucide.dev/icons/
+ *
+ * @author ESEngine Team
+ * @date 2026
+ *
+ * @copyright Copyright (c) 2026 ESEngine Team
+ * Licensed under the MIT License.
+ */
+#pragma once
+
+namespace esengine::ui::icons {
+
+// =============================================================================
+// File & Folder Icons
+// =============================================================================
+
+constexpr const char* Folder = "\ue0ed";
+constexpr const char* FolderOpen = "\ue0f3";
+constexpr const char* FolderPlus = "\ue0f6";
+constexpr const char* FolderMinus = "\ue0f4";
+constexpr const char* FolderClosed = "\ue0ee";
+constexpr const char* File = "\ue0c6";
+constexpr const char* FileText = "\ue0e4";
+constexpr const char* FileCode = "\ue0cd";
+constexpr const char* FileImage = "\ue0d7";
+constexpr const char* FileAudio = "\ue0c8";
+constexpr const char* FileVideo = "\ue0e6";
+constexpr const char* FilePlus = "\ue0dd";
+constexpr const char* FileMinus = "\ue0d9";
+constexpr const char* FileX = "\ue0e7";
+constexpr const char* Files = "\ue0e8";
+
+// =============================================================================
+// Navigation & Arrows
+// =============================================================================
+
+constexpr const char* ArrowUp = "\ue04a";
+constexpr const char* ArrowDown = "\ue042";
+constexpr const char* ArrowLeft = "\ue048";
+constexpr const char* ArrowRight = "\ue049";
+constexpr const char* ChevronUp = "\ue089";
+constexpr const char* ChevronDown = "\ue086";
+constexpr const char* ChevronLeft = "\ue087";
+constexpr const char* ChevronRight = "\ue088";
+constexpr const char* ChevronsUp = "\ue08d";
+constexpr const char* ChevronsDown = "\ue08a";
+constexpr const char* ChevronsLeft = "\ue08b";
+constexpr const char* ChevronsRight = "\ue08c";
+constexpr const char* CornerDownLeft = "\ue0a0";
+constexpr const char* CornerDownRight = "\ue0a1";
+constexpr const char* CornerUpLeft = "\ue0a4";
+constexpr const char* CornerUpRight = "\ue0a5";
+
+// =============================================================================
+// Actions
+// =============================================================================
+
+constexpr const char* Plus = "\ue14c";
+constexpr const char* Minus = "\ue121";
+constexpr const char* X = "\ue1b4";
+constexpr const char* Check = "\ue07e";
+constexpr const char* Search = "\ue166";
+constexpr const char* Settings = "\ue169";
+constexpr const char* Trash = "\ue1a0";
+constexpr const char* Trash2 = "\ue1a1";
+constexpr const char* Edit = "\ue0b6";
+constexpr const char* Edit2 = "\ue0b7";
+constexpr const char* Edit3 = "\ue0b8";
+constexpr const char* Copy = "\ue09d";
+constexpr const char* Clipboard = "\ue091";
+constexpr const char* Save = "\ue163";
+constexpr const char* Download = "\ue0b2";
+constexpr const char* Upload = "\ue1ac";
+constexpr const char* Refresh = "\ue159";
+constexpr const char* RotateCw = "\ue15f";
+constexpr const char* RotateCcw = "\ue15e";
+constexpr const char* Undo = "\ue1a7";
+constexpr const char* Undo2 = "\ue1a8";
+constexpr const char* Redo = "\ue157";
+constexpr const char* Redo2 = "\ue158";
+
+// =============================================================================
+// Media Controls
+// =============================================================================
+
+constexpr const char* Play = "\ue147";
+constexpr const char* Pause = "\ue13c";
+constexpr const char* Stop = "\ue190";
+constexpr const char* SkipBack = "\ue17b";
+constexpr const char* SkipForward = "\ue17c";
+constexpr const char* FastForward = "\ue0c1";
+constexpr const char* Rewind = "\ue15c";
+constexpr const char* Volume = "\ue1b0";
+constexpr const char* Volume1 = "\ue1b1";
+constexpr const char* Volume2 = "\ue1b2";
+constexpr const char* VolumeX = "\ue1b3";
+
+// =============================================================================
+// UI Elements
+// =============================================================================
+
+constexpr const char* Menu = "\ue11e";
+constexpr const char* MoreHorizontal = "\ue128";
+constexpr const char* MoreVertical = "\ue129";
+constexpr const char* Grid = "\ue0fe";
+constexpr const char* List = "\ue110";
+constexpr const char* Layout = "\ue109";
+constexpr const char* Layers = "\ue106";
+constexpr const char* Maximize = "\ue11a";
+constexpr const char* Maximize2 = "\ue11b";
+constexpr const char* Minimize = "\ue122";
+constexpr const char* Minimize2 = "\ue123";
+constexpr const char* PanelLeft = "\ue4c2";
+constexpr const char* PanelRight = "\ue4c6";
+constexpr const char* PanelTop = "\ue4ca";
+constexpr const char* PanelBottom = "\ue4be";
+constexpr const char* SidebarLeft = "\ue172";
+constexpr const char* SidebarRight = "\ue173";
+constexpr const char* Columns = "\ue098";
+constexpr const char* Rows = "\ue161";
+
+// =============================================================================
+// Objects & Shapes
+// =============================================================================
+
+constexpr const char* Box = "\ue061";
+constexpr const char* Cube = "\ue0a6";
+constexpr const char* Circle = "\ue090";
+constexpr const char* Square = "\ue18d";
+constexpr const char* Triangle = "\ue1a4";
+constexpr const char* Star = "\ue18f";
+constexpr const char* Heart = "\ue100";
+constexpr const char* Image = "\ue101";
+constexpr const char* Camera = "\ue064";
+constexpr const char* Video = "\ue1ad";
+constexpr const char* Music = "\ue12c";
+constexpr const char* Mic = "\ue11f";
+
+// =============================================================================
+// Tools
+// =============================================================================
+
+constexpr const char* Move = "\ue12a";
+constexpr const char* Hand = "\ue0ff";
+constexpr const char* Pointer = "\ue14a";
+constexpr const char* MousePointer = "\ue12b";
+constexpr const char* Crosshair = "\ue0a7";
+constexpr const char* Target = "\ue197";
+constexpr const char* Zap = "\ue1b5";
+constexpr const char* Wand = "\ue4e1";
+constexpr const char* Paintbrush = "\ue135";
+constexpr const char* Eraser = "\ue0bc";
+constexpr const char* Scissors = "\ue165";
+constexpr const char* Crop = "\ue2e3";
+
+// =============================================================================
+// Development
+// =============================================================================
+
+constexpr const char* Code = "\ue095";
+constexpr const char* Code2 = "\ue096";
+constexpr const char* Terminal = "\ue19b";
+constexpr const char* Bug = "\ue20c";
+constexpr const char* GitBranch = "\ue0f7";
+constexpr const char* GitCommit = "\ue0f8";
+constexpr const char* GitMerge = "\ue0f9";
+constexpr const char* Braces = "\ue36a";
+constexpr const char* Brackets = "\ue443";
+constexpr const char* Database = "\ue0ab";
+constexpr const char* Server = "\ue16a";
+constexpr const char* Cpu = "\ue2e2";
+
+// =============================================================================
+// Status & Alerts
+// =============================================================================
+
+constexpr const char* Info = "\ue102";
+constexpr const char* AlertCircle = "\ue032";
+constexpr const char* AlertTriangle = "\ue033";
+constexpr const char* HelpCircle = "\ue238";
+constexpr const char* CheckCircle = "\ue07f";
+constexpr const char* CheckCircle2 = "\ue080";
+constexpr const char* XCircle = "\ue1ce";
+constexpr const char* Bell = "\ue059";
+constexpr const char* BellOff = "\ue05a";
+
+// =============================================================================
+// View & Visibility
+// =============================================================================
+
+constexpr const char* Eye = "\ue0bf";
+constexpr const char* EyeOff = "\ue0c0";
+constexpr const char* ZoomIn = "\ue1b6";
+constexpr const char* ZoomOut = "\ue1b7";
+constexpr const char* Focus = "\ue0eb";
+constexpr const char* Fullscreen = "\ue5a5";
+constexpr const char* ShrinkScreen = "\ue5af";
+
+// =============================================================================
+// Hierarchy & Structure
+// =============================================================================
+
+constexpr const char* Component = "\ue099";
+constexpr const char* Package = "\ue133";
+constexpr const char* Puzzle = "\ue152";
+constexpr const char* Workflow = "\ue1b1";
+constexpr const char* Network = "\ue130";
+constexpr const char* Share2 = "\ue16d";
+constexpr const char* Link = "\ue10d";
+constexpr const char* Unlink = "\ue1a9";
+constexpr const char* Lock = "\ue114";
+constexpr const char* Unlock = "\ue1aa";
+
+// =============================================================================
+// Transform
+// =============================================================================
+
+constexpr const char* Move3d = "\ue381";
+constexpr const char* Rotate3d = "\ue3d4";
+constexpr const char* Scale3d = "\ue3d5";
+constexpr const char* FlipHorizontal = "\ue0e9";
+constexpr const char* FlipVertical = "\ue0ea";
+constexpr const char* AlignLeft = "\ue034";
+constexpr const char* AlignCenter = "\ue035";
+constexpr const char* AlignRight = "\ue036";
+constexpr const char* AlignJustify = "\ue037";
+
+// =============================================================================
+// Misc
+// =============================================================================
+
+constexpr const char* Home = "\ue240";
+constexpr const char* User = "\ue1ab";
+constexpr const char* Users = "\ue1d0";
+constexpr const char* Cog = "\ue097";
+constexpr const char* Wrench = "\ue1cf";
+constexpr const char* Hammer = "\ue57f";
+constexpr const char* Globe = "\ue0fc";
+constexpr const char* Sun = "\ue193";
+constexpr const char* Moon = "\ue127";
+constexpr const char* Cloud = "\ue093";
+constexpr const char* Sparkles = "\ue18c";
+
+} // namespace esengine::ui::icons
diff --git a/src/esengine/ui/layout/StackLayout.cpp b/src/esengine/ui/layout/StackLayout.cpp
index c54f82a22..52df62236 100644
--- a/src/esengine/ui/layout/StackLayout.cpp
+++ b/src/esengine/ui/layout/StackLayout.cpp
@@ -77,11 +77,20 @@ void StackLayout::layout(Widget& container, const Rect& bounds) {
std::vector<Widget*> visibleChildren;
std::vector<glm::vec2> childSizes;
+ f32 usedMainSize = 0.0f;
for (const auto& child : children) {
if (child->isVisible()) {
visibleChildren.push_back(child.get());
- auto size = child->measure(bounds.width, bounds.height);
+
+ 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_;
}
}
diff --git a/src/esengine/ui/rendering/UIBatchRenderer.cpp b/src/esengine/ui/rendering/UIBatchRenderer.cpp
index 7255a3ea8..3eec60326 100644
--- a/src/esengine/ui/rendering/UIBatchRenderer.cpp
+++ b/src/esengine/ui/rendering/UIBatchRenderer.cpp
@@ -291,6 +291,7 @@ struct UIBatchRenderer::BatchData {
u32 textureSlotIndex = 1;
glm::mat4 projection{1.0f};
+ f32 devicePixelRatio = 1.0f;
std::vector<Rect> clipStack;
Rect currentClip;
@@ -388,8 +389,9 @@ bool UIBatchRenderer::isInitialized() const {
// Frame Management
// =============================================================================
-void UIBatchRenderer::begin(const glm::mat4& projection) {
+void UIBatchRenderer::begin(const glm::mat4& projection, f32 devicePixelRatio) {
data_->projection = projection;
+ data_->devicePixelRatio = devicePixelRatio > 0.0f ? devicePixelRatio : 1.0f;
data_->inFrame = true;
data_->stats.reset();
@@ -511,10 +513,11 @@ void UIBatchRenderer::applyScissor() {
glEnable(GL_SCISSOR_TEST);
- i32 x = static_cast<i32>(data_->currentClip.x);
- i32 y = static_cast<i32>(data_->currentClip.y);
- i32 w = static_cast<i32>(data_->currentClip.width);
- i32 h = static_cast<i32>(data_->currentClip.height);
+ f32 dpr = data_->devicePixelRatio;
+ i32 x = static_cast<i32>(data_->currentClip.x * dpr);
+ i32 y = static_cast<i32>(data_->currentClip.y * dpr);
+ i32 w = static_cast<i32>(data_->currentClip.width * dpr);
+ i32 h = static_cast<i32>(data_->currentClip.height * dpr);
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
diff --git a/src/esengine/ui/rendering/UIBatchRenderer.hpp b/src/esengine/ui/rendering/UIBatchRenderer.hpp
index 4a1cdf8dd..223a02572 100644
--- a/src/esengine/ui/rendering/UIBatchRenderer.hpp
+++ b/src/esengine/ui/rendering/UIBatchRenderer.hpp
@@ -115,8 +115,9 @@ public:
/**
* @brief Begins a UI rendering frame
* @param projection Orthographic projection matrix
+ * @param devicePixelRatio Scale factor for high-DPI displays (default 1.0)
*/
- void begin(const glm::mat4& projection);
+ void begin(const glm::mat4& projection, f32 devicePixelRatio = 1.0f);
/**
* @brief Ends the UI rendering frame and flushes all batches
diff --git a/src/esengine/ui/widgets/ScrollView.cpp b/src/esengine/ui/widgets/ScrollView.cpp
index f50c96d3a..ddea1cfdd 100644
--- a/src/esengine/ui/widgets/ScrollView.cpp
+++ b/src/esengine/ui/widgets/ScrollView.cpp
@@ -14,6 +14,8 @@
#include "../rendering/UIBatchRenderer.hpp"
#include "../../math/Math.hpp"
+#include <limits>
+
namespace esengine::ui {
// =============================================================================
@@ -350,6 +352,19 @@ void ScrollView::updateContentLayout() {
const Rect& bounds = getBounds();
const Insets& padding = getPadding();
+ f32 measureWidth = viewportSize_.x;
+ f32 measureHeight = std::numeric_limits<f32>::infinity();
+
+ if (scrollDirection_ == ScrollDirection::Horizontal) {
+ measureWidth = std::numeric_limits<f32>::infinity();
+ measureHeight = viewportSize_.y;
+ } else if (scrollDirection_ == ScrollDirection::Both) {
+ measureWidth = std::numeric_limits<f32>::infinity();
+ measureHeight = std::numeric_limits<f32>::infinity();
+ }
+
+ contentSize_ = content_->measure(measureWidth, measureHeight);
+
f32 contentWidth = contentSize_.x;
f32 contentHeight = contentSize_.y;
diff --git a/src/esengine/ui/widgets/TreeView.cpp b/src/esengine/ui/widgets/TreeView.cpp
index f5e984217..0efc7320b 100644
--- a/src/esengine/ui/widgets/TreeView.cpp
+++ b/src/esengine/ui/widgets/TreeView.cpp
@@ -12,6 +12,7 @@
#include "TreeView.hpp"
#include "../UIContext.hpp"
#include "../font/SDFFont.hpp"
+#include "../icons/Icons.hpp"
#include "../rendering/UIBatchRenderer.hpp"
#include "../../core/Log.hpp"
#include "../../math/Math.hpp"
@@ -297,25 +298,14 @@ void TreeView::renderNode(UIBatchRenderer& renderer, const TreeNode& node, f32 y
glm::vec4 iconColor = style.textColor;
if (getContext()) {
- iconColor = getContext()->getTheme().colors.textPrimary;
+ iconColor = getContext()->getTheme().colors.textSecondary;
}
- if (node.expanded) {
- // Draw expanded icon (▼)
- f32 cx = iconBounds.x + iconBounds.width * 0.5f;
- f32 cy = iconBounds.y + iconBounds.height * 0.5f;
- f32 size = iconSize_ * 0.3f;
-
- Rect arrowRect{cx - size, cy - size * 0.3f, size * 2.0f, size * 0.6f};
- renderer.drawRect(arrowRect, iconColor);
- } else {
- // Draw collapsed icon (▶)
- f32 cx = iconBounds.x + iconBounds.width * 0.5f;
- f32 cy = iconBounds.y + iconBounds.height * 0.5f;
- f32 size = iconSize_ * 0.3f;
-
- Rect arrowRect{cx - size * 0.3f, cy - size, size * 0.6f, size * 2.0f};
- renderer.drawRect(arrowRect, iconColor);
+ SDFFont* iconFont = getContext() ? getContext()->getIconFont() : nullptr;
+ if (iconFont) {
+ const char* icon = node.expanded ? icons::ChevronDown : icons::ChevronRight;
+ renderer.drawTextInBounds(icon, iconBounds, *iconFont, iconSize_, iconColor,
+ HAlign::Center, VAlign::Center);
}
x += iconSize_ + 4.0f;