feat: update editor ui framework and assets

This commit is contained in:
2026-03-28 15:07:19 +08:00
parent 4a12e26860
commit 4717b595c4
45 changed files with 2434 additions and 461 deletions

View File

@@ -21,14 +21,15 @@ void DrawProjectFolderTreePrefix(const UI::TreeNodePrefixContext& context) {
return;
}
const float iconWidth = 14.0f;
const float iconHeight = 11.0f;
const float minX = context.min.x + ((context.max.x - context.min.x) - iconWidth) * 0.5f;
const float minY = context.min.y + ((context.max.y - context.min.y) - iconHeight) * 0.5f;
const float width = context.max.x - context.min.x;
const float height = context.max.y - context.min.y;
const float iconExtent = UI::NavigationTreeIconSize();
const float minX = context.min.x + (width - iconExtent) * 0.5f;
const float minY = context.min.y + (height - iconExtent) * 0.5f;
UI::DrawAssetIcon(
context.drawList,
ImVec2(minX, minY),
ImVec2(minX + iconWidth, minY + iconHeight),
ImVec2(minX + iconExtent, minY + iconExtent),
UI::AssetIconKind::Folder);
}
@@ -52,8 +53,10 @@ void ProjectPanel::Render() {
auto& manager = m_context->GetProjectManager();
RenderToolbar();
ImGui::PushStyleColor(ImGuiCol_ChildBg, UI::ProjectBrowserSurfaceColor());
UI::PanelContentScope content("ProjectContent", ImVec2(0.0f, 0.0f));
if (!content.IsOpen()) {
ImGui::PopStyleColor();
return;
}
@@ -63,7 +66,7 @@ void ProjectPanel::Render() {
const float clampedNavigationWidth = std::clamp(
m_navigationWidth,
UI::ProjectNavigationMinWidth(),
std::max(UI::ProjectNavigationMinWidth(), availableWidth - UI::ProjectBrowserMinWidth() - splitterWidth));
(std::max)(UI::ProjectNavigationMinWidth(), availableWidth - UI::ProjectBrowserMinWidth() - splitterWidth));
m_navigationWidth = clampedNavigationWidth;
RenderFolderTreePane(manager);
@@ -76,10 +79,18 @@ void ProjectPanel::Render() {
RenderBrowserPane(manager);
Actions::DrawProjectCreateFolderDialog(*m_context, m_createFolderDialog);
ImGui::PopStyleColor();
}
void ProjectPanel::RenderToolbar() {
UI::PanelToolbarScope toolbar("ProjectToolbar", UI::ProjectPanelToolbarHeight());
UI::PanelToolbarScope toolbar(
"ProjectToolbar",
UI::ProjectPanelToolbarHeight(),
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse,
true,
UI::ToolbarPadding(),
UI::ToolbarItemSpacing(),
UI::ProjectPanelToolbarBackgroundColor());
if (!toolbar.IsOpen()) {
return;
}
@@ -113,6 +124,7 @@ void ProjectPanel::RenderFolderTreePane(IProjectManager& manager) {
const AssetItemPtr rootFolder = manager.GetRootFolder();
const AssetItemPtr currentFolder = manager.GetCurrentFolder();
const std::string currentFolderPath = currentFolder ? currentFolder->fullPath : std::string();
UI::ResetTreeLayout();
if (rootFolder) {
RenderFolderTreeNode(manager, rootFolder, currentFolderPath);
} else {
@@ -143,6 +155,7 @@ void ProjectPanel::RenderFolderTreeNode(
nodeDefinition.options.leaf = !hasChildFolders;
nodeDefinition.options.defaultOpen = IsCurrentTreeBranch(currentFolderPath, folder->fullPath);
nodeDefinition.persistenceKey = folder->fullPath;
nodeDefinition.style = UI::ProjectFolderTreeStyle();
nodeDefinition.prefix.width = UI::NavigationTreePrefixWidth();
nodeDefinition.prefix.draw = DrawProjectFolderTreePrefix;
nodeDefinition.callbacks.onInteraction = [this, &manager, folder](const UI::TreeNodeResult& node) {
@@ -195,10 +208,12 @@ void ProjectPanel::RenderBrowserPane(IProjectManager& manager) {
RenderBrowserHeader(manager);
ImGui::PushStyleColor(ImGuiCol_ChildBg, UI::ProjectBrowserPaneBackgroundColor());
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, UI::ProjectBrowserPanePadding());
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, UI::AssetGridSpacing());
const bool bodyOpen = ImGui::BeginChild("ProjectBrowserBody", ImVec2(0.0f, 0.0f), false);
ImGui::PopStyleVar(2);
ImGui::PopStyleColor();
if (!bodyOpen) {
ImGui::EndChild();
ImGui::EndChild();
@@ -244,10 +259,10 @@ void ProjectPanel::RenderBrowserPane(IProjectManager& manager) {
}
}
if (visibleItems.empty()) {
if (visibleItems.empty() && !search.empty()) {
UI::DrawEmptyState(
search.empty() ? "No Assets" : "No Search Results",
search.empty() ? "Current folder is empty" : "No assets match the current search");
"No Search Results",
"No assets match the current search");
}
Actions::HandleProjectBackgroundPrimaryClick(manager);
@@ -286,21 +301,23 @@ void ProjectPanel::RenderBrowserHeader(IProjectManager& manager) {
return;
}
if (ImGui::BeginTable("##ProjectBrowserHeaderLayout", 1, ImGuiTableFlags_NoSavedSettings | ImGuiTableFlags_SizingStretchProp | ImGuiTableFlags_NoPadOuterX)) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
UI::DrawToolbarBreadcrumbs(
"Assets",
manager.GetPathDepth(),
[&](size_t index) { return manager.GetPathName(index); },
[&](size_t index) { manager.NavigateToIndex(index); });
ImGui::EndTable();
const float rowHeight = UI::BreadcrumbItemHeight();
const float startY = ImGui::GetCursorPosY();
const float availableHeight = ImGui::GetContentRegionAvail().y;
if (availableHeight > rowHeight) {
ImGui::SetCursorPosY(startY + (availableHeight - rowHeight) * 0.5f);
}
UI::DrawToolbarBreadcrumbs(
"Assets",
manager.GetPathDepth(),
[&](size_t index) { return manager.GetPathName(index); },
[&](size_t index) { manager.NavigateToIndex(index); });
ImDrawList* drawList = ImGui::GetWindowDrawList();
const ImVec2 min = ImGui::GetWindowPos();
const ImVec2 max(min.x + ImGui::GetWindowSize().x, min.y + ImGui::GetWindowSize().y);
UI::DrawHorizontalDivider(drawList, min.x, max.x, max.y - 0.5f);
const ImVec2 windowMin = ImGui::GetWindowPos();
const ImVec2 windowMax(windowMin.x + ImGui::GetWindowSize().x, windowMin.y + ImGui::GetWindowSize().y);
UI::DrawHorizontalDivider(drawList, windowMin.x, windowMax.x, windowMax.y - 0.5f);
ImGui::EndChild();
}
@@ -311,6 +328,13 @@ ProjectPanel::AssetItemInteraction ProjectPanel::RenderAssetItem(const AssetItem
ImGui::PushID(item ? item->fullPath.c_str() : "ProjectItem");
const bool isDraggingThisItem = Actions::IsProjectAssetBeingDragged(item);
const UI::AssetIconKind iconKind = item->isFolder ? UI::AssetIconKind::Folder : UI::AssetIconKind::File;
UI::AssetTileOptions tileOptions;
tileOptions.drawIdleFrame = false;
tileOptions.drawSelectionBorder = false;
if (item->isFolder) {
tileOptions.iconOffset = UI::FolderAssetTileIconOffset();
tileOptions.iconSize = UI::FolderAssetTileIconSize();
}
const UI::AssetTileResult tile = UI::DrawAssetTile(
item->name.c_str(),
@@ -318,7 +342,8 @@ ProjectPanel::AssetItemInteraction ProjectPanel::RenderAssetItem(const AssetItem
isDraggingThisItem,
[&](ImDrawList* drawList, const ImVec2& iconMin, const ImVec2& iconMax) {
UI::DrawAssetIcon(drawList, iconMin, iconMax, iconKind);
});
},
tileOptions);
if (tile.clicked) {
interaction.clicked = true;