Extract hierarchy and project drag semantics
This commit is contained in:
@@ -10,6 +10,10 @@ namespace XCEngine {
|
||||
namespace Editor {
|
||||
namespace Actions {
|
||||
|
||||
inline constexpr const char* ProjectAssetPayloadType() {
|
||||
return "ASSET_ITEM";
|
||||
}
|
||||
|
||||
inline int FindProjectItemIndex(IProjectManager& projectManager, const AssetItemPtr& item) {
|
||||
if (!item) {
|
||||
return -1;
|
||||
@@ -29,6 +33,50 @@ inline int FindProjectItemIndex(IProjectManager& projectManager, const AssetItem
|
||||
return -1;
|
||||
}
|
||||
|
||||
inline const char* GetDraggedProjectAssetPath() {
|
||||
const ImGuiPayload* payload = ImGui::GetDragDropPayload();
|
||||
if (!payload || !payload->IsDataType(ProjectAssetPayloadType())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return static_cast<const char*>(payload->Data);
|
||||
}
|
||||
|
||||
inline bool IsProjectAssetBeingDragged(const AssetItemPtr& item) {
|
||||
const char* draggedPath = GetDraggedProjectAssetPath();
|
||||
return item != nullptr && draggedPath != nullptr && item->fullPath == draggedPath;
|
||||
}
|
||||
|
||||
inline bool AcceptProjectAssetDrop(IProjectManager& projectManager, const AssetItemPtr& targetFolder) {
|
||||
if (!targetFolder || !targetFolder->isFolder || !ImGui::BeginDragDropTarget()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool accepted = false;
|
||||
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload(ProjectAssetPayloadType())) {
|
||||
const char* draggedPath = static_cast<const char*>(payload->Data);
|
||||
accepted = Commands::MoveAssetToFolder(projectManager, draggedPath, targetFolder);
|
||||
}
|
||||
ImGui::EndDragDropTarget();
|
||||
return accepted;
|
||||
}
|
||||
|
||||
inline bool BeginProjectAssetDrag(const AssetItemPtr& item, UI::AssetIconKind iconKind) {
|
||||
if (!item || item->fullPath.empty() || !ImGui::BeginDragDropSource(ImGuiDragDropFlags_None)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ImGui::SetDragDropPayload(ProjectAssetPayloadType(), item->fullPath.c_str(), item->fullPath.length() + 1);
|
||||
|
||||
ImVec2 previewMin = ImGui::GetMousePos();
|
||||
const ImVec2 previewSize = UI::AssetDragPreviewSize();
|
||||
ImVec2 previewMax = ImVec2(previewMin.x + previewSize.x, previewMin.y + previewSize.y);
|
||||
UI::DrawAssetIcon(ImGui::GetForegroundDrawList(), previewMin, previewMax, iconKind);
|
||||
|
||||
ImGui::EndDragDropSource();
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void DrawProjectAssetContextActions(IEditorContext& context, const AssetItemPtr& item) {
|
||||
auto& projectManager = context.GetProjectManager();
|
||||
const int itemIndex = FindProjectItemIndex(projectManager, item);
|
||||
|
||||
Reference in New Issue
Block a user