2026-04-15 22:47:42 +08:00
|
|
|
#include "ProjectPanelInternal.h"
|
2026-04-15 08:24:06 +08:00
|
|
|
|
2026-04-15 22:47:42 +08:00
|
|
|
namespace XCEngine::UI::Editor::App::ProjectPanelInternal {
|
2026-04-15 08:24:06 +08:00
|
|
|
|
|
|
|
|
using ::XCEngine::UI::UIInputEventType;
|
2026-04-15 22:47:42 +08:00
|
|
|
|
|
|
|
|
bool ContainsPoint(const UIRect& rect, const UIPoint& point) {
|
2026-04-15 08:24:06 +08:00
|
|
|
return point.x >= rect.x &&
|
|
|
|
|
point.x <= rect.x + rect.width &&
|
|
|
|
|
point.y >= rect.y &&
|
|
|
|
|
point.y <= rect.y + rect.height;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-15 22:47:42 +08:00
|
|
|
float ClampNonNegative(float value) {
|
2026-04-15 08:24:06 +08:00
|
|
|
return (std::max)(value, 0.0f);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-15 22:47:42 +08:00
|
|
|
float ResolveTextTop(float rectY, float rectHeight, float fontSize) {
|
2026-04-15 08:24:06 +08:00
|
|
|
const float lineHeight = fontSize * 1.6f;
|
|
|
|
|
return rectY + std::floor((rectHeight - lineHeight) * 0.5f);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-15 22:47:42 +08:00
|
|
|
float MeasureTextWidth(
|
2026-04-15 08:24:06 +08:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-15 22:47:42 +08:00
|
|
|
::XCEngine::UI::UITextureHandle ResolveFolderIcon(const BuiltInIcons* icons) {
|
2026-04-15 08:24:06 +08:00
|
|
|
return icons != nullptr
|
|
|
|
|
? icons->Resolve(BuiltInIconKind::Folder)
|
|
|
|
|
: ::XCEngine::UI::UITextureHandle {};
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-15 22:47:42 +08:00
|
|
|
float ClampNavigationWidth(float value, float totalWidth) {
|
2026-04-15 08:24:06 +08:00
|
|
|
const float maxWidth =
|
|
|
|
|
(std::max)(
|
|
|
|
|
kNavigationMinWidth,
|
|
|
|
|
totalWidth - kBrowserMinWidth - ResolveUIEditorDockHostMetrics().splitterMetrics.thickness);
|
|
|
|
|
return std::clamp(value, kNavigationMinWidth, maxWidth);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-15 22:47:42 +08:00
|
|
|
void AppendTilePreview(
|
2026-04-15 08:24:06 +08:00
|
|
|
UIDrawList& drawList,
|
|
|
|
|
const UIRect& previewRect,
|
|
|
|
|
bool directory) {
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-15 22:47:42 +08:00
|
|
|
} // namespace XCEngine::UI::Editor::App::ProjectPanelInternal
|