refactor(new_editor): snapshot hosted editor restructuring
This commit is contained in:
@@ -1,24 +1,225 @@
|
||||
#include "ProjectPanelInternal.h"
|
||||
|
||||
#include "ProjectPanel.h"
|
||||
#include "Rendering/Assets/BuiltInIcons.h"
|
||||
#include "Composition/EditorPanelIds.h"
|
||||
#include <XCEditor/Collections/UIEditorTreeView.h>
|
||||
#include <XCEditor/Foundation/UIEditorTheme.h>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <string_view>
|
||||
#include "Ports/SystemInteractionPort.h"
|
||||
#include "Project/EditorProjectRuntime.h"
|
||||
#include "State/EditorCommandFocusService.h"
|
||||
|
||||
#include <XCEditor/Collections/UIEditorTreePanelBehavior.h>
|
||||
#include <XCEditor/Fields/UIEditorFieldStyle.h>
|
||||
#include <XCEditor/Foundation/UIEditorPanelInputFilter.h>
|
||||
#include <XCEditor/Fields/UIEditorTextField.h>
|
||||
|
||||
#include <XCEngine/Input/InputTypes.h>
|
||||
#include <XCEngine/UI/Widgets/UIPopupOverlayModel.h>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
namespace XCEngine::UI::Editor::App {
|
||||
|
||||
using namespace ProjectPanelInternal;
|
||||
using ::XCEngine::UI::Editor::UIEditorTextMeasureRequest;
|
||||
using ::XCEngine::UI::Editor::UIEditorTextMeasurer;
|
||||
using ::XCEngine::UI::UIColor;
|
||||
using ::XCEngine::UI::UIDrawList;
|
||||
using ::XCEngine::UI::UIInputEvent;
|
||||
using ::XCEngine::UI::UIPoint;
|
||||
using ::XCEngine::UI::UIRect;
|
||||
using ::XCEngine::UI::UITextureHandle;
|
||||
|
||||
inline constexpr std::size_t kInvalidLayoutIndex = static_cast<std::size_t>(-1);
|
||||
|
||||
inline constexpr float kBrowserHeaderHeight = 24.0f;
|
||||
inline constexpr float kNavigationMinWidth = 180.0f;
|
||||
inline constexpr float kBrowserMinWidth = 260.0f;
|
||||
inline constexpr float kHeaderHorizontalPadding = 10.0f;
|
||||
inline constexpr float kHeaderBottomBorderThickness = 1.0f;
|
||||
inline constexpr float kBreadcrumbItemPaddingX = 4.0f;
|
||||
inline constexpr float kBreadcrumbItemPaddingY = 1.0f;
|
||||
inline constexpr float kBreadcrumbSpacing = 3.0f;
|
||||
inline constexpr float kTreeTopPadding = 0.0f;
|
||||
inline constexpr float kGridInsetX = 16.0f;
|
||||
inline constexpr float kGridInsetY = 12.0f;
|
||||
inline constexpr float kGridTileWidth = 92.0f;
|
||||
inline constexpr float kGridTileHeight = 92.0f;
|
||||
inline constexpr float kGridTileGapX = 12.0f;
|
||||
inline constexpr float kGridTileGapY = 12.0f;
|
||||
inline constexpr float kGridPreviewWidth = 68.0f;
|
||||
inline constexpr float kGridPreviewHeight = 54.0f;
|
||||
inline constexpr float kHeaderFontSize = 12.0f;
|
||||
inline constexpr float kTileLabelFontSize = 11.0f;
|
||||
|
||||
inline constexpr UIColor kSurfaceColor(0.10f, 0.10f, 0.10f, 1.0f);
|
||||
inline constexpr UIColor kPaneColor(0.10f, 0.10f, 0.10f, 1.0f);
|
||||
inline constexpr UIColor kHeaderColor(0.11f, 0.11f, 0.11f, 1.0f);
|
||||
inline constexpr UIColor kTextPrimary(0.880f, 0.880f, 0.880f, 1.0f);
|
||||
inline constexpr UIColor kTextStrong(0.930f, 0.930f, 0.930f, 1.0f);
|
||||
inline constexpr UIColor kTextMuted(0.640f, 0.640f, 0.640f, 1.0f);
|
||||
inline constexpr UIColor kTileHoverColor(0.14f, 0.14f, 0.14f, 1.0f);
|
||||
inline constexpr UIColor kTileSelectedColor(0.18f, 0.18f, 0.18f, 1.0f);
|
||||
inline constexpr UIColor kTilePreviewFillColor(0.15f, 0.15f, 0.15f, 1.0f);
|
||||
inline constexpr UIColor kTilePreviewShadeColor(0.12f, 0.12f, 0.12f, 1.0f);
|
||||
inline constexpr UIColor kTilePreviewOutlineColor(0.920f, 0.920f, 0.920f, 0.20f);
|
||||
inline constexpr UIColor kDropPreviewColor(0.92f, 0.92f, 0.92f, 0.42f);
|
||||
|
||||
bool ContainsPoint(const UIRect& rect, const UIPoint& point);
|
||||
float ClampNonNegative(float value);
|
||||
float ResolveTextTop(float rectY, float rectHeight, float fontSize);
|
||||
float MeasureTextWidth(
|
||||
const UIEditorTextMeasurer* textMeasurer,
|
||||
std::string_view text,
|
||||
float fontSize);
|
||||
::XCEngine::UI::UITextureHandle ResolveFolderIcon(const BuiltInIcons* icons);
|
||||
float ClampNavigationWidth(float value, float totalWidth);
|
||||
UIRect ComputeFittedTextureRect(
|
||||
const UIRect& bounds,
|
||||
const UITextureHandle& texture);
|
||||
void AppendTexturePreview(
|
||||
UIDrawList& drawList,
|
||||
const UIRect& bounds,
|
||||
const UITextureHandle& texture);
|
||||
void AppendTilePreview(
|
||||
UIDrawList& drawList,
|
||||
const UIRect& previewRect,
|
||||
bool directory,
|
||||
const UITextureHandle* texture);
|
||||
|
||||
} // namespace XCEngine::UI::Editor::App
|
||||
|
||||
namespace XCEngine::UI::Editor::App {
|
||||
|
||||
using ::XCEngine::UI::UIInputEventType;
|
||||
|
||||
bool ContainsPoint(const UIRect& rect, const UIPoint& point) {
|
||||
return point.x >= rect.x &&
|
||||
point.x <= rect.x + rect.width &&
|
||||
point.y >= rect.y &&
|
||||
point.y <= rect.y + rect.height;
|
||||
}
|
||||
|
||||
float ClampNonNegative(float value) {
|
||||
return (std::max)(value, 0.0f);
|
||||
}
|
||||
|
||||
float ResolveTextTop(float rectY, float rectHeight, float fontSize) {
|
||||
const float lineHeight = fontSize * 1.6f;
|
||||
return rectY + std::floor((rectHeight - lineHeight) * 0.5f);
|
||||
}
|
||||
|
||||
float MeasureTextWidth(
|
||||
const UIEditorTextMeasurer* textMeasurer,
|
||||
std::string_view text,
|
||||
float fontSize) {
|
||||
if (text.empty()) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
if (textMeasurer != nullptr) {
|
||||
const float measuredWidth =
|
||||
textMeasurer->MeasureTextWidth(UIEditorTextMeasureRequest{ text, fontSize });
|
||||
if (measuredWidth > 0.0f) {
|
||||
return measuredWidth;
|
||||
}
|
||||
}
|
||||
|
||||
return static_cast<float>(text.size()) * fontSize * 0.56f;
|
||||
}
|
||||
|
||||
::XCEngine::UI::UITextureHandle ResolveFolderIcon(const BuiltInIcons* icons) {
|
||||
return icons != nullptr
|
||||
? icons->Resolve(BuiltInIconKind::Folder)
|
||||
: ::XCEngine::UI::UITextureHandle {};
|
||||
}
|
||||
|
||||
float ClampNavigationWidth(float value, float totalWidth) {
|
||||
const float maxWidth =
|
||||
(std::max)(
|
||||
kNavigationMinWidth,
|
||||
totalWidth - kBrowserMinWidth - ResolveUIEditorDockHostMetrics().splitterMetrics.thickness);
|
||||
return std::clamp(value, kNavigationMinWidth, maxWidth);
|
||||
}
|
||||
|
||||
UIRect ComputeFittedTextureRect(
|
||||
const UIRect& bounds,
|
||||
const UITextureHandle& texture) {
|
||||
if (!texture.IsValid() ||
|
||||
bounds.width <= 0.0f ||
|
||||
bounds.height <= 0.0f) {
|
||||
return bounds;
|
||||
}
|
||||
|
||||
const float scale = (std::min)(
|
||||
bounds.width / static_cast<float>(texture.width),
|
||||
bounds.height / static_cast<float>(texture.height));
|
||||
const float width = static_cast<float>(texture.width) * scale;
|
||||
const float height = static_cast<float>(texture.height) * scale;
|
||||
return UIRect(
|
||||
bounds.x + (bounds.width - width) * 0.5f,
|
||||
bounds.y + (bounds.height - height) * 0.5f,
|
||||
width,
|
||||
height);
|
||||
}
|
||||
|
||||
void AppendTexturePreview(
|
||||
UIDrawList& drawList,
|
||||
const UIRect& bounds,
|
||||
const UITextureHandle& texture) {
|
||||
if (!texture.IsValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
drawList.AddImage(ComputeFittedTextureRect(bounds, texture), texture);
|
||||
}
|
||||
|
||||
void AppendTilePreview(
|
||||
UIDrawList& drawList,
|
||||
const UIRect& previewRect,
|
||||
bool directory,
|
||||
const UITextureHandle* texture) {
|
||||
if (texture != nullptr && texture->IsValid()) {
|
||||
AppendTexturePreview(drawList, previewRect, *texture);
|
||||
return;
|
||||
}
|
||||
|
||||
if (directory) {
|
||||
const UIRect tabRect(
|
||||
previewRect.x + 8.0f,
|
||||
previewRect.y + 7.0f,
|
||||
22.0f,
|
||||
7.0f);
|
||||
const UIRect bodyRect(
|
||||
previewRect.x + 4.0f,
|
||||
previewRect.y + 13.0f,
|
||||
previewRect.width - 8.0f,
|
||||
previewRect.height - 18.0f);
|
||||
drawList.AddFilledRect(tabRect, kTilePreviewShadeColor, 1.0f);
|
||||
drawList.AddFilledRect(bodyRect, kTilePreviewFillColor, 1.0f);
|
||||
drawList.AddRectOutline(bodyRect, kTilePreviewOutlineColor, 1.0f, 1.0f);
|
||||
return;
|
||||
}
|
||||
|
||||
const UIRect sheetRect(
|
||||
previewRect.x + 10.0f,
|
||||
previewRect.y + 4.0f,
|
||||
previewRect.width - 20.0f,
|
||||
previewRect.height - 8.0f);
|
||||
const UIRect accentRect(
|
||||
sheetRect.x,
|
||||
sheetRect.y,
|
||||
sheetRect.width,
|
||||
7.0f);
|
||||
drawList.AddFilledRect(sheetRect, kTilePreviewFillColor, 1.0f);
|
||||
drawList.AddFilledRect(accentRect, kTilePreviewShadeColor, 1.0f);
|
||||
drawList.AddRectOutline(sheetRect, kTilePreviewOutlineColor, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
} // namespace XCEngine::UI::Editor::App
|
||||
|
||||
namespace XCEngine::UI::Editor::App {
|
||||
|
||||
using ::XCEngine::Input::KeyCode;
|
||||
namespace GridDrag = XCEngine::UI::Editor::Collections::GridDragDrop;
|
||||
namespace TreeDrag = XCEngine::UI::Editor::Collections::TreeDragDrop;
|
||||
@@ -134,7 +335,7 @@ void ProjectPanel::SetSystemInteractionHost(
|
||||
m_systemInteractionHost = systemInteractionHost;
|
||||
}
|
||||
|
||||
void ProjectPanel::SetBuiltInIcons(const BuiltInIcons* icons) {
|
||||
void ProjectPanel::SetBuiltInIcons(BuiltInIcons* icons) {
|
||||
m_icons = icons;
|
||||
if (EditorProjectRuntime* runtime = ResolveProjectRuntime();
|
||||
runtime != nullptr) {
|
||||
@@ -1967,7 +2168,13 @@ void ProjectPanel::Append(UIDrawList& drawList) const {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& assetEntries = GetBrowserModel().GetAssetEntries();
|
||||
if (m_icons != nullptr) {
|
||||
m_icons->BeginFrame();
|
||||
}
|
||||
|
||||
const BrowserModel& browserModel = GetBrowserModel();
|
||||
const auto& assetEntries = browserModel.GetAssetEntries();
|
||||
const std::filesystem::path projectRootPath = browserModel.GetProjectRootPath();
|
||||
|
||||
drawList.AddFilledRect(m_layout.bounds, kSurfaceColor);
|
||||
drawList.AddFilledRect(m_layout.leftPaneRect, kPaneColor);
|
||||
@@ -2078,7 +2285,21 @@ void ProjectPanel::Append(UIDrawList& drawList) const {
|
||||
selected ? kTileSelectedColor : kTileHoverColor);
|
||||
}
|
||||
|
||||
AppendTilePreview(drawList, tile.previewRect, assetEntry.directory);
|
||||
const UITextureHandle* tileTexture = nullptr;
|
||||
if (assetEntry.directory) {
|
||||
tileTexture = m_icons != nullptr
|
||||
? &m_icons->Resolve(BuiltInIconKind::Folder)
|
||||
: nullptr;
|
||||
} else if (assetEntry.canPreview && m_icons != nullptr) {
|
||||
tileTexture =
|
||||
m_icons->ResolveAssetPreview(assetEntry.absolutePath, projectRootPath);
|
||||
}
|
||||
|
||||
AppendTilePreview(
|
||||
drawList,
|
||||
tile.previewRect,
|
||||
assetEntry.directory,
|
||||
tileTexture);
|
||||
|
||||
drawList.PushClipRect(tile.labelRect);
|
||||
const float textWidth =
|
||||
@@ -2151,3 +2372,6 @@ void ProjectPanel::Append(UIDrawList& drawList) const {
|
||||
}
|
||||
|
||||
} // namespace XCEngine::UI::Editor::App
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user